DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(model): 模型页接入官方 open-in-app,打开配置文件可选择应用
hairyf5e0b4f962a63
diff --git a/packages/dsh-tauri-model/src/client/index.ts b/packages/dsh-tauri-model/src/client/index.tsindex da851832..f880dd33 100644--- a/packages/dsh-tauri-model/src/client/index.ts+++ b/packages/dsh-tauri-model/src/client/index.ts@@ -4,6 +4,7 @@ import { LOCALE_EFFECT, MODELS_PAGE_EFFECT, STYLES_EFFECT } from './constants'import { locale } from './locales'import { registerModelsPage } from './register/models'import { registerStyles } from './register/styles'+import { configureOpenInApp } from './service/open-in-app'export type { ModelsKey } from './models/locales.ts'export type { ModelsSectionInjected, ModelsSectionProps } from './models/ModelsSection.tsx'@@ -25,6 +26,7 @@ export const inject = []export function apply(ctx: ClientContext): void {+ configureOpenInApp(ctx)ctx.effect(locale.registerLocale, LOCALE_EFFECT)ctx.effect(registerStyles, STYLES_EFFECT)let started = falsediff --git a/packages/dsh-tauri-model/src/client/models/locales.ts b/packages/dsh-tauri-model/src/client/models/locales.tsindex 3d7cc697..c5b8024f 100644--- a/packages/dsh-tauri-model/src/client/models/locales.ts+++ b/packages/dsh-tauri-model/src/client/models/locales.ts@@ -113,6 +113,7 @@ export const en = {onboardingSaving: 'Saving…',keyRequired: 'Enter an API key to continue.',openConfigFile: 'Open config file',+ defaultApplication: 'System default app',autoConfigureModels: 'Configure all models',autoConfigureModelsHint: 'Fill in limits from the endpoint and image/thinking capabilities from the model capability table for every listed model',fetchModelConfig: 'Fetch config',@@ -246,6 +247,7 @@ export const zh: { [Key in keyof typeof en]: string } = {onboardingSaving: '保存中…',keyRequired: '请输入 API 密钥后继续。',openConfigFile: '打开配置文件',+ defaultApplication: '系统默认应用',autoConfigureModels: '自动配置所有模型',autoConfigureModelsHint: '为列表中每个模型从端点读取上限,并按模型能力表补齐图片与思考档位',fetchModelConfig: '获取配置',diff --git a/packages/dsh-tauri-model/src/client/service/open-in-app.test.ts b/packages/dsh-tauri-model/src/client/service/open-in-app.test.tsnew file mode 100644index 00000000..2f11f806--- /dev/null+++ b/packages/dsh-tauri-model/src/client/service/open-in-app.test.ts@@ -0,0 +1,88 @@+import type { ServiceLookup } from '../models/remote.ts'+import { ofetch } from 'dsh-tauri/client'+import { beforeEach, describe, expect, it, vi } from 'vitest'+import { postConfigOpen } from '../apis'+import { configureOpenInApp, listConfigApplications, openConfigInApp } from './open-in-app'++vi.mock('../apis', () => ({+ postConfigOpen: vi.fn(),+ getEndpointModels: vi.fn(),+ getPresets: vi.fn(),+}))++vi.mock('dsh-tauri/client', () => ({+ ofetch: vi.fn(),+}))++interface SessionStub {+ modelCatalog?: () => Promise<unknown>+ canOpenWorkspacePath?: () => Promise<unknown>+ openWorkspacePath?: (request: unknown) => Promise<unknown>+ workspacePathApplications?: (request: unknown) => Promise<unknown>+}++function withSession(session: SessionStub): void {+ const lookup: ServiceLookup = { get: name => name === 'remote' ? { session } : undefined }+ configureOpenInApp(lookup)+}++function desktopSession(overrides: SessionStub = {}): SessionStub {+ return {+ openWorkspacePath: async () => ({ ok: true, value: {} }),+ ...overrides,+ }+}++const postConfigOpenMock = vi.mocked(postConfigOpen)+const ofetchMock = vi.mocked(ofetch)++beforeEach(() => {+ vi.clearAllMocks()+ postConfigOpenMock.mockResolvedValue({ ok: true, path: '/home/u/.dsh/settings.yaml' } as never)+})++describe('官方 open-in-app 接入', () => {+ it('低版本核心缺打开方法时不列表,也不发起任何请求', async () => {+ withSession({ modelCatalog: async () => ({ ok: true, value: {} }) })++ await expect(listConfigApplications()).resolves.toEqual([])+ expect(postConfigOpenMock).not.toHaveBeenCalled()+ expect(ofetchMock).not.toHaveBeenCalled()+ })++ it('目录返回已安装应用的 id 时,补齐显示名与官方图标地址', async () => {+ ofetchMock.mockResolvedValue({ apps: ['vscode', 'cursor'] })+ withSession(desktopSession())++ await expect(listConfigApplications()).resolves.toEqual([+ { id: 'vscode', name: 'Visual Studio Code', default: false, icon: '/open-in-app/icon/vscode' },+ { id: 'cursor', name: 'Cursor', default: false, icon: '/open-in-app/icon/cursor' },+ ])+ expect(postConfigOpenMock).toHaveBeenCalledWith(expect.objectContaining({ params: { dry: '1' } }))+ })++ it('目录响应异常或没有应用时不列表', async () => {+ ofetchMock.mockResolvedValue({})+ withSession(desktopSession())+ await expect(listConfigApplications()).resolves.toEqual([])++ ofetchMock.mockResolvedValue({ apps: [] })+ withSession(desktopSession())+ await expect(listConfigApplications()).resolves.toEqual([])+ })++ it('目录请求失败(低版本缺路由)时不列表', async () => {+ ofetchMock.mockRejectedValue(new Error('404'))+ withSession(desktopSession())++ await expect(listConfigApplications()).resolves.toEqual([])+ })++ it('按应用 id 打开配置文件', async () => {+ const openWorkspacePath = vi.fn(async () => ({ ok: true, value: {} }))+ withSession(desktopSession({ openWorkspacePath }))++ await expect(openConfigInApp('vscode')).resolves.toBe(true)+ expect(openWorkspacePath).toHaveBeenCalledWith({ path: '/home/u/.dsh/settings.yaml', application: 'vscode' })+ })+})diff --git a/packages/dsh-tauri-model/src/client/service/open-in-app.ts b/packages/dsh-tauri-model/src/client/service/open-in-app.tsnew file mode 100644index 00000000..499351d4--- /dev/null+++ b/packages/dsh-tauri-model/src/client/service/open-in-app.ts@@ -0,0 +1,107 @@+import type { ServiceLookup } from '../models/remote.ts'+import type { SessionRemote, WorkspacePathApplication } from '../types/remotes.ts'+import { ofetch } from 'dsh-tauri/client'+import { postConfigOpen } from '../apis'+import { resolveRemote } from '../models/remote.ts'++/** 官方 `dsh-host-open-in-app` 的目录与图标路由(浏览器相对路径,与官方客户端同法)。 */+const CATALOG_PATH = '/open-in-app/apps'+const ICON_PREFIX = '/open-in-app/icon'++/**+ * 官方目录 id 的显示名。目录只返回已安装的 id,未知 id 直接显示 id 本身;+ * 名称沿用官方词典的品牌写法,避免把裸 id 暴露成菜单项。+ */+const APPLICATION_NAMES: Record<string, string | undefined> = {+ finder: 'Finder',+ explorer: 'File Explorer',+ filemanager: 'File Manager',+ cursor: 'Cursor',+ vscode: 'Visual Studio Code',+ vscodeinsiders: 'VS Code Insiders',+ windsurf: 'Windsurf',+ zed: 'Zed',+ sublimetext: 'Sublime Text',+ xcode: 'Xcode',+ androidstudio: 'Android Studio',+ intellij: 'IntelliJ IDEA',+ pycharm: 'PyCharm',+ webstorm: 'WebStorm',+ phpstorm: 'PhpStorm',+ goland: 'GoLand',+ rider: 'Rider',+ rustrover: 'RustRover',+ fork: 'Fork',+ sourcetree: 'Sourcetree',+}++let lookup: ServiceLookup | undefined++export function configureOpenInApp(next: ServiceLookup): void {+ lookup = next+}++type OpenInAppSession = SessionRemote & Required<Pick<SessionRemote, 'openWorkspacePath'>>++/** 打开某个应用所需的会话远端;低版本核心缺它即返回 undefined,选择器据此隐藏。 */+function openInAppSession(): OpenInAppSession | undefined {+ const session = lookup === undefined ? undefined : resolveRemote(lookup)?.session+ if (session?.openWorkspacePath === undefined)+ return undefined+ return session as OpenInAppSession+}++async function configPath(): Promise<string | undefined> {+ try {+ const response = await postConfigOpen({ params: { dry: '1' }, ignoreResponseError: true })+ return response.ok === true && typeof response.path === 'string' && response.path.length > 0 ? response.path : undefined+ }+ catch {+ return undefined+ }+}++/**+ * 选择器候选:官方 catalog(与官方会话头部同一来源,只含主机验证过的已安装应用)。+ * 主机没有这套路由(低版本核心)、没有桌面、或设置文件不存在时都为空。+ */+export async function listConfigApplications(): Promise<readonly WorkspacePathApplication[]> {+ const session = openInAppSession()+ if (session === undefined)+ return []+ const path = await configPath()+ if (path === undefined)+ return []+ try {+ const payload = await ofetch<{ apps?: unknown }>(CATALOG_PATH)+ if (!Array.isArray(payload.apps))+ return []+ return payload.apps+ .filter((id): id is string => typeof id === 'string' && id.length > 0)+ .map(id => ({+ id,+ name: APPLICATION_NAMES[id] ?? id,+ default: false,+ icon: `${ICON_PREFIX}/${id}`,+ }))+ }+ catch {+ return []+ }+}++export async function openConfigInApp(application: string): Promise<boolean> {+ const session = openInAppSession()+ if (session === undefined)+ return false+ const path = await configPath()+ if (path === undefined)+ return false+ try {+ const result = await session.openWorkspacePath({ path, application })+ return result.ok+ }+ catch {+ return false+ }+}diff --git a/packages/dsh-tauri-model/src/client/types/remotes.ts b/packages/dsh-tauri-model/src/client/types/remotes.tsindex 87122856..716cc803 100644--- a/packages/dsh-tauri-model/src/client/types/remotes.ts+++ b/packages/dsh-tauri-model/src/client/types/remotes.ts@@ -98,8 +98,19 @@ export interface LlmRemote {discoverModels: (settingsNs: string, request: LlmModelDiscoveryRequest) => Promise<RemoteResult<LlmDiscoveredModel[]>>}+export interface WorkspacePathApplication {+ id: string+ name: string+ default: boolean+ icon: string | null+}+export interface SessionRemote {modelCatalog: () => Promise<RemoteResult<LlmModelCatalog>>+ /** 官方 open-in-app 会话远端(低版本核心没有这三项,据此隐藏入口)。 */+ canOpenWorkspacePath?: () => Promise<RemoteResult<boolean>>+ openWorkspacePath?: (request: { path: string, action?: 'reveal', application?: string }) => Promise<RemoteResult<unknown>>+ workspacePathApplications?: (request: { path: string }) => Promise<RemoteResult<WorkspacePathApplication[]>>}export type RemoteEventName = 'settings/document-updated' | 'credentials/reference-updated' | 'credentials/record-updated' | 'llm/adapters-updated'diff --git a/packages/dsh-tauri-model/src/client/ui/model-extras/model-config-toolbar.tsx b/packages/dsh-tauri-model/src/client/ui/model-extras/model-config-toolbar.tsxindex 5e3f1bbf..a457e7f1 100644--- a/packages/dsh-tauri-model/src/client/ui/model-extras/model-config-toolbar.tsx+++ b/packages/dsh-tauri-model/src/client/ui/model-extras/model-config-toolbar.tsx@@ -1,6 +1,9 @@import type { ReactElement } from 'react'+import type { WorkspacePathApplication } from '../../types/remotes.ts'import type { Translate } from './types'-import { Action } from 'dsh-tauri-ui/client'+import { Action, Select } from 'dsh-tauri-ui/client'+import { useEffect, useState } from 'react'+import { listConfigApplications, openConfigInApp } from '../../service/open-in-app'export type ModelDraft = Record<string, unknown>@@ -19,29 +22,93 @@ export interface ModelConfigToolbarProps {disabled?: boolean}+const DEFAULT_APPLICATION = ''+const APPLICATION_CHOICE_KEY = 'dsh-tauri-model.open-in-app.choice'+/**- * 模型页工具条:只保留「打开配置文件」。- * 文本编辑器选择器已删除——官方 `dsh-client-ui-open-in-app` 已独占「用哪个应用打开」这件事- * (自带应用目录与记忆选择,且不对外 provide 客户端服务),本包不再重复实现。+ * 模型页工具条:左侧用哪个应用打开(复用 ui 的 `Select`),右侧「打开配置文件」。+ * 候选来自官方 open-in-app 的主机目录,低版本核心或非桌面环境为空,此时只剩右侧按钮。*/export function ModelConfigToolbar({t,onOpenConfig,disabled,}: ModelConfigToolbarProps): ReactElement {+ const [applications, setApplications] = useState<readonly WorkspacePathApplication[]>([])+ const [choice, setChoice] = useState<string>(readChoice)++ useEffect(() => {+ let active = true+ void listConfigApplications().then((next) => {+ if (active)+ setApplications(next)+ })+ return () => {+ active = false+ }+ }, [])++ if (onOpenConfig === undefined)+ return <div className="flex items-center flex-wrap gap-[8px] min-w-0" />++ const selected = applications.find(application => application.id === choice)+ const openConfig = (): void => {+ if (selected === undefined)+ onOpenConfig()+ else+ void openConfigInApp(selected.id)+ }+return (<div className="flex items-center flex-wrap gap-[8px] min-w-0">- {onOpenConfig === undefined+ {applications.length === 0? null: (- <Action- variant="link"+ <Select+ className="max-w-[200px]"disabled={disabled}- onClick={onOpenConfig}- >- {t('openConfigFile')}- </Action>+ variant="composerTrigger"+ options={[+ { value: DEFAULT_APPLICATION, label: t('defaultApplication') },+ ...applications.map(application => ({+ value: application.id,+ label: application.name,+ icon: <ApplicationIcon application={application} />,+ })),+ ]}+ value={selected === undefined ? DEFAULT_APPLICATION : choice}+ icon={selected === undefined ? undefined : <ApplicationIcon application={selected} />}+ onChange={(id) => {+ setChoice(id)+ writeChoice(id)+ }}+ />)}+ <Action className='text-[13px] text-secondary rounded-[14px]' variant="link" disabled={disabled} onClick={openConfig}>+ {t('openConfigFile')}+ </Action></div>)}++function ApplicationIcon({ application }: { application: WorkspacePathApplication }): ReactElement {+ return <img src={application.icon ?? ''} alt="" className="w-[14px] h-[14px] rounded-[3px] flex-none" />+}++function readChoice(): string {+ try {+ return localStorage.getItem(APPLICATION_CHOICE_KEY) ?? DEFAULT_APPLICATION+ }+ catch {+ return DEFAULT_APPLICATION+ }+}++function writeChoice(id: string): void {+ try {+ localStorage.setItem(APPLICATION_CHOICE_KEY, id)+ }+ catch {++ }+}diff --git a/packages/dsh-tauri-model/src/client/ui/model-extras/translate.ts b/packages/dsh-tauri-model/src/client/ui/model-extras/translate.tsindex 795c4662..6f9e2625 100644--- a/packages/dsh-tauri-model/src/client/ui/model-extras/translate.ts+++ b/packages/dsh-tauri-model/src/client/ui/model-extras/translate.ts@@ -3,6 +3,7 @@ import { locale } from '../../locales'export const MODEL_EXTRAS_KEYS = ['openConfigFile',+ 'defaultApplication','autoConfigureModels','autoConfigureModelsHint','fetchModelConfig',diff --git a/packages/dsh-tauri-model/src/host/routes/config/open/post.ts b/packages/dsh-tauri-model/src/host/routes/config/open/post.tsindex eaa69dc3..4da2b0fc 100644--- a/packages/dsh-tauri-model/src/host/routes/config/open/post.ts+++ b/packages/dsh-tauri-model/src/host/routes/config/open/post.ts@@ -1,9 +1,14 @@import type { EventHandlerRequest } from 'dsh-tauri'import type { OpenModelsConfigResponse } from '../../index.types'-import { defineEventHandler } from 'dsh-tauri'+import { defineEventHandler, getQuery } from 'dsh-tauri'import { configFile } from '../../../service/config-file'export default defineEventHandler<EventHandlerRequest, Promise<OpenModelsConfigResponse>>(async (event) => {+ const query = getQuery<{ dry?: string }>(event)+ if (query.dry === '1') {+ const resolved = await configFile.resolve()+ return { ok: true, path: resolved.path }+ }const result = await configFile.open()if (!result.ok) {event.res.status = 500diff --git a/packages/dsh-tauri-model/src/host/service/config-file.ts b/packages/dsh-tauri-model/src/host/service/config-file.tsindex 69eb6b8e..8c66bce8 100644--- a/packages/dsh-tauri-model/src/host/service/config-file.ts+++ b/packages/dsh-tauri-model/src/host/service/config-file.ts@@ -6,6 +6,10 @@ import { resolveSettingsFilePath } from '../utils/paths'/** 设置文件:存在就用系统默认应用打开,未创建则退到所在目录(编辑器选择交给官方 open-in-app)。 */export const configFile = defineService({+ async resolve(): Promise<ConfigOpenResult> {+ const path = resolveSettingsFilePath()+ return { ok: true, path, opened: 'file' }+ },async open(): Promise<ConfigOpenResult> {const path = resolveSettingsFilePath()try {diff --git a/packages/dsh-tauri-ui/src/client/components/select.tsx b/packages/dsh-tauri-ui/src/client/components/select.tsxindex 35e4ff55..aaa6341c 100644--- a/packages/dsh-tauri-ui/src/client/components/select.tsx+++ b/packages/dsh-tauri-ui/src/client/components/select.tsx@@ -10,6 +10,8 @@ import { ChevronDown } from './icons'export interface SelectOption {value: stringlabel: string+ /** 逐项图标(菜单行与触发器共用同一套 chips 排版)。 */+ icon?: ReactNode}export interface SelectProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onChange' | 'value'> {@@ -46,7 +48,7 @@ export function Select({setOpen(false)onChange(id)}}- items={options.map(option => ({ id: option.value, label: option.label }))}+ items={options.map(option => ({ id: option.value, label: option.label, icon: option.icon }))}selectedId={value}portalalign="end"diff --git a/packages/dsh-tauri-ui/src/client/styles/index.ts b/packages/dsh-tauri-ui/src/client/styles/index.tsindex a5ebac49..1f500182 100644--- a/packages/dsh-tauri-ui/src/client/styles/index.ts+++ b/packages/dsh-tauri-ui/src/client/styles/index.ts@@ -195,6 +195,9 @@ const TAILWINDCSS_GENERATED = `.table {display: table;}+ .h-\\[14px\\] {+ height: 14px;+ }.h-\\[16px\\] {height: 16px;}@@ -279,6 +282,9 @@ const TAILWINDCSS_GENERATED = `.w-\\[8px\\] {width: 8px;}+ .w-\\[14px\\] {+ width: 14px;+ }.w-\\[16px\\] {width: 16px;}@@ -333,6 +339,9 @@ const TAILWINDCSS_GENERATED = `.w-full\\! {width: 100% !important;}+ .max-w-\\[200px\\] {+ max-width: 200px;+ }.max-w-\\[220px\\] {max-width: 220px;}@@ -510,6 +519,9 @@ const TAILWINDCSS_GENERATED = `.rounded {border-radius: 0.25rem;}+ .rounded-\\[3px\\] {+ border-radius: 3px;+ }.rounded-\\[4px\\] {border-radius: 4px;}