DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(model-config): 恢复思考模式/Developer 角色,并修好取数通道与网格布局
hairyf417c0799fad3
diff --git a/packages/dsh-tauri-model-config/src/client/constants/index.ts b/packages/dsh-tauri-model-config/src/client/constants/index.tsindex 2b05d310..e2c9fb4a 100644--- a/packages/dsh-tauri-model-config/src/client/constants/index.ts+++ b/packages/dsh-tauri-model-config/src/client/constants/index.ts@@ -8,3 +8,6 @@ export const MODELS_PAGE_EFFECT = `${PLUGIN_ID}: models page`/** 面板样式标签 id,避免热更新重复挂载同一条样式。 */export const STYLES_ID = `${PLUGIN_ID}-models-styles`++/** 布局覆盖样式的标签 id,与逐字对应上游的生成样式分开挂载。 */+export const OVERRIDES_STYLE_ID = `${PLUGIN_ID}-models-style-overrides`diff --git a/packages/dsh-tauri-model-config/src/client/models/ModelListEditor.tsx b/packages/dsh-tauri-model-config/src/client/models/ModelListEditor.tsxindex 9437082e..15064cc6 100644--- a/packages/dsh-tauri-model-config/src/client/models/ModelListEditor.tsx+++ b/packages/dsh-tauri-model-config/src/client/models/ModelListEditor.tsx@@ -4,7 +4,7 @@ import type { DeepSeekModelDraft } from './DeepSeekModelsEditor.tsx'import type { en } from './locales.ts'import type { ModelsOperations } from './operations.ts'import { Button, Modal } from '@deepseek-ai/dsh-client-ui-primitives'-import { AutoConfigAllButton, modelExtrasTranslate, ModelFetchConfigButton, Plus } from 'dsh-tauri-ui/client'+import { AutoConfigAllButton, ModelCompatFields, modelExtrasTranslate, ModelFetchConfigButton, Plus, TEMPLATE_COMPAT_PROTOCOL } from 'dsh-tauri-ui/client'import { useEffect, useMemo, useState } from 'react'import { formatCapacity, parseCapacity } from './DeepSeekModelsEditor.tsx'import { ModelRow } from './ModelRow.tsx'@@ -130,7 +130,7 @@ export function ModelListEditor(props: ModelListEditorProps): ReactNode {})}- const patch = (index: number, next: Record<string, string | number | undefined>): void => {+ const patch = (index: number, next: Record<string, unknown>): void => {onChange(models.map((model, at) => {if (at !== index)return model@@ -279,6 +279,7 @@ export function ModelListEditor(props: ModelListEditorProps): ReactNode {t={modelExtrasTranslate}models={models}probe={target}+ operations={operations}disabled={disabled}onApply={(next) => { onChange([...next]) }}/>@@ -315,10 +316,21 @@ export function ModelListEditor(props: ModelListEditorProps): ReactNode {modelId={typeof model.id === 'string' ? model.id : ''}models={models}probe={target}+ operations={operations}disabled={disabled}onApply={(next) => { onChange([...next]) }}/>)}+ advanced={(+ <ModelCompatFields+ t={modelExtrasTranslate}+ model={model}+ index={index}+ disabled={disabled}+ templateCompat={probe.api === TEMPLATE_COMPAT_PROTOCOL}+ onPatch={(next) => { patch(index, next) }}+ />+ )}onRemove={() => {onChange(models.filter((_model, at) => at !== index))setExpanded((current) => {diff --git a/packages/dsh-tauri-model-config/src/client/models/ModelRow.tsx b/packages/dsh-tauri-model-config/src/client/models/ModelRow.tsxindex df285c39..ade18d2d 100644--- a/packages/dsh-tauri-model-config/src/client/models/ModelRow.tsx+++ b/packages/dsh-tauri-model-config/src/client/models/ModelRow.tsx@@ -29,6 +29,7 @@ interface ModelRowProps {onToggle: () => voidonRemove: () => voidtrailing?: ReactNode+ advanced?: ReactNode}export function ModelRow(props: ModelRowProps): ReactNode {@@ -102,6 +103,7 @@ export function ModelRow(props: ModelRowProps): ReactNode {t={t}onChange={props.onChange}/>+ {props.advanced}</div>): null}diff --git a/packages/dsh-tauri-model-config/src/client/models/ModelsSection.tsx b/packages/dsh-tauri-model-config/src/client/models/ModelsSection.tsxindex 4074a20b..1f39f4e8 100644--- a/packages/dsh-tauri-model-config/src/client/models/ModelsSection.tsx+++ b/packages/dsh-tauri-model-config/src/client/models/ModelsSection.tsx@@ -297,16 +297,18 @@ function Loaded({ injected, renderSlot }: { injected: ModelsSectionFace, renderSreturn (<div className={styles.section}>- <h2 className={styles.title}>{t('title')}</h2>- <ModelConfigToolbar- t={modelExtrasTranslate}- editor={editor}- onEditorChange={(next) => {- setEditor(next)- void saveEditor(next)- }}- onOpenConfig={() => { void openConfigFile() }}- />+ <div className="dshp-models-title-row">+ <h2 className={styles.title}>{t('title')}</h2>+ <ModelConfigToolbar+ t={modelExtrasTranslate}+ editor={editor}+ onEditorChange={(next) => {+ setEditor(next)+ void saveEditor(next)+ }}+ onOpenConfig={() => { void openConfigFile() }}+ />+ </div><p className={styles.intro}>{t('intro')}</p>{!state.writable && state.status === 'ready' ? <p className={styles.notice}>{t('readOnly')}</p> : null}{savedIdentity === undefineddiff --git a/packages/dsh-tauri-model-config/src/client/models/styles.overrides.ts b/packages/dsh-tauri-model-config/src/client/models/styles.overrides.tsnew file mode 100644index 00000000..66d0d75e--- /dev/null+++ b/packages/dsh-tauri-model-config/src/client/models/styles.overrides.ts@@ -0,0 +1,39 @@+import { cssr } from 'dsh-tauri-ui/client'+import { modelStyles } from './styles'++const { c } = cssr++/**+ * 归档布局所需的本地覆盖。+ *+ * `styles.ts` 逐字对应上游样式,这里只放我们的偏离。+ *+ * 类名重复一次用于提高优先级:css-render 在 `head: true` 挂载时执行+ * `insertBefore(target, parent.querySelector('style, link'))`,后挂载的样式反而排在前面,+ * 同优先级下生成样式会盖掉本文件。重复类名让覆盖不依赖挂载顺序。+ */+export const modelsOverridesNode = c([`+.${modelStyles.modelListHead}.${modelStyles.modelListHead} {+ flex-wrap: wrap;+}++.${modelStyles.modelCatalogHeading}.${modelStyles.modelCatalogHeading} {+ flex: 1 0 auto;+}++.${modelStyles.modelRow}.${modelStyles.modelRow} {+ grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, auto) auto auto;+}++.${modelStyles.modelInputTypes}.${modelStyles.modelInputTypes} {+ grid-column: auto;+ order: 2;+}++.dshp-models-title-row {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+}+`])diff --git a/packages/dsh-tauri-model-config/src/client/register/styles.ts b/packages/dsh-tauri-model-config/src/client/register/styles.tsindex 4e61f84a..38500a00 100644--- a/packages/dsh-tauri-model-config/src/client/register/styles.ts+++ b/packages/dsh-tauri-model-config/src/client/register/styles.ts@@ -1,8 +1,10 @@import { mountStyle } from 'dsh-tauri-ui/client'import { defineRegister } from 'dsh-tauri/client'-import { STYLES_ID } from '../constants'+import { OVERRIDES_STYLE_ID, STYLES_ID } from '../constants'import { modelsStylesNode } from '../models/styles'+import { modelsOverridesNode } from '../models/styles.overrides'export const registerStyles = defineRegister((controller) => {controller.add(mountStyle(modelsStylesNode, STYLES_ID))+ controller.add(mountStyle(modelsOverridesNode, OVERRIDES_STYLE_ID))})diff --git a/packages/dsh-tauri-ui/src/client/components/checkbox.tsx b/packages/dsh-tauri-ui/src/client/components/checkbox.tsxindex a5456539..4dab916a 100644--- a/packages/dsh-tauri-ui/src/client/components/checkbox.tsx+++ b/packages/dsh-tauri-ui/src/client/components/checkbox.tsx@@ -4,10 +4,10 @@ import { CHECKBOX_STYLE_ID } from '../constants'import { useMountStyle } from '../hooks/use-mount-style'import checkboxStyle from './checkbox.cssr'-export function Checkbox({ checked, disabled, onChange, children, 'aria-label': ariaLabel }: CheckboxProps): ReactElement {+export function Checkbox({ checked, disabled, onChange, children, 'aria-label': ariaLabel, title }: CheckboxProps): ReactElement {useMountStyle(checkboxStyle, CHECKBOX_STYLE_ID)return (- <label className="dshp-checkbox">+ <label className="dshp-checkbox" title={title}><inputclassName="dshp-checkbox__input"type="checkbox"diff --git a/packages/dsh-tauri-ui/src/client/components/checkbox.types.ts b/packages/dsh-tauri-ui/src/client/components/checkbox.types.tsindex 956470b9..bb1f3b9e 100644--- a/packages/dsh-tauri-ui/src/client/components/checkbox.types.ts+++ b/packages/dsh-tauri-ui/src/client/components/checkbox.types.ts@@ -6,4 +6,5 @@ export interface CheckboxProps {'onChange': (next: boolean) => void'children'?: ReactNode'aria-label'?: string+ 'title'?: string}diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.tsx b/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.tsxindex 7ed665a7..52080837 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.tsx+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.tsx@@ -5,9 +5,9 @@ import { useMountStyle } from '../../hooks/use-mount-style'import modelExtrasStyle from './model-extras.cssr'import { useModelConfigFetch } from './use-model-config-fetch'-export function AutoConfigAllButton({ t, models, probe, disabled, onApply }: AutoConfigAllButtonProps): ReactElement {+export function AutoConfigAllButton({ t, models, probe, operations, disabled, onApply }: AutoConfigAllButtonProps): ReactElement {useMountStyle(modelExtrasStyle, MODEL_EXTRAS_STYLE_ID)- const { busy, failure, notice, run } = useModelConfigFetch({ t, models, probe, onApply })+ const { busy, failure, notice, run } = useModelConfigFetch({ t, models, probe, operations, onApply })return (<>diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.types.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.types.tsindex 8c7db194..a6f9e91f 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.types.ts+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/auto-config-all-button.types.ts@@ -1,3 +1,4 @@+import type { ModelDiscoveryChannel } from '../../service/model-config'import type { ModelDraft, ModelProbeTarget } from './model-config-toolbar.types'import type { Translate } from './types'@@ -5,6 +6,7 @@ export interface AutoConfigAllButtonProps {t: Translatemodels: readonly ModelDraft[]probe: ModelProbeTarget+ operations?: ModelDiscoveryChanneldisabled?: booleanonApply?: (models: ModelDraft[], applied: number, undisclosed: string[]) => void}diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/index.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/index.tsindex 4181df3a..b6f9aea5 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/index.ts+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/index.ts@@ -1,5 +1,7 @@export { AutoConfigAllButton } from './auto-config-all-button'export type { AutoConfigAllButtonProps } from './auto-config-all-button.types'+export { ModelCompatFields } from './model-compat-fields'+export type { ModelCompatFieldsProps } from './model-compat-fields.types'export { ModelConfigToolbar } from './model-config-toolbar'export type { ModelConfigToolbarProps, ModelDraft, ModelProbeTarget } from './model-config-toolbar.types'export { ModelFetchConfigButton } from './model-fetch-config-button'diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.cssr.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.cssr.tsnew file mode 100644index 00000000..25815682--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.cssr.ts@@ -0,0 +1,68 @@+import { styles as sharedStyles } from '../../constants/theme'+import { cssr } from '../../utils/cssr'++const { c } = cssr+const { secondary, tertiary, borderL3, brand, focusRing } = sharedStyles++export default c([+ c('.dshp-model-compat', {+ order: '1',+ minWidth: '0',+ margin: '0',+ padding: '0',+ border: 'none',+ }),+ c('.dshp-model-compat__label', {+ display: 'block',+ marginBottom: '4px',+ padding: '0',+ color: tertiary,+ fontSize: '12px',+ lineHeight: '18px',+ }),+ c('.dshp-model-compat__choices', {+ display: 'flex',+ flexWrap: 'wrap',+ gap: '16px',+ minHeight: '32px',+ alignItems: 'center',+ }),+ c('.dshp-model-compat__levels', {+ order: '3',+ gridColumn: '1 / -1',+ display: 'flex',+ flexDirection: 'column',+ gap: '4px',+ marginTop: '8px',+ }),+ c('.dshp-model-compat__chips', {+ display: 'flex',+ flexWrap: 'wrap',+ gap: '6px',+ }),+ c('.dshp-model-compat__chip', {+ display: 'inline-flex',+ alignItems: 'center',+ gap: '4px',+ height: '24px',+ padding: '0 8px',+ border: `0.5px solid ${borderL3}`,+ borderRadius: '6px',+ fontSize: '12px',+ lineHeight: '18px',+ color: secondary,+ cursor: 'pointer',+ }, [+ c('&:has(input:disabled)', {+ opacity: '0.6',+ cursor: 'default',+ }),+ c('input', {+ width: '12px',+ height: '12px',+ margin: '0',+ accentColor: brand,+ }),+ c('input:focus-visible', focusRing),+ ]),+])diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.test.tsx b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.test.tsxnew file mode 100644index 00000000..a82b4881--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.test.tsx@@ -0,0 +1,117 @@+import type { Translate } from './types'+import { renderToStaticMarkup } from 'react-dom/server'+import { describe, expect, it, vi } from 'vitest'+import { ModelCompatFields } from './model-compat-fields'++vi.mock('dsh-tauri/client', () => ({+ defineLocale: (_namespace: string, dicts: unknown) => ({+ NS: _namespace,+ text: (key: string) => key,+ dicts,+ activeLocale: () => 'en',+ isEnglishLocale: () => true,+ useLocale: () => 'en',+ registerLocale: () => () => {},+ }),+}))++const t: Translate = (key, params) => {+ const dict: Record<string, string> = {+ modelConfig: 'Model config',+ thinkingMode: 'Thinking mode',+ thinkingLevels: 'Thinking levels',+ thinkingModeHint: 'Declare whether this model thinks',+ developerRole: 'Disable developer role',+ developerRoleHint: 'Turn this on for an endpoint that rejects the developer role',+ }+ const template = dict[key] ?? key+ if (params === undefined)+ return template+ return template.replace(/\{(\w+)\}/g, (match, name: string) => name in params ? String(params[name]) : match)+}++function markup(model: Record<string, unknown>, templateCompat: boolean, disabled?: boolean): string {+ return renderToStaticMarkup(+ <ModelCompatFields+ t={t}+ model={model}+ index={0}+ templateCompat={templateCompat}+ disabled={disabled}+ onPatch={() => {}}+ />,+ )+}++interface Choice {+ checked: boolean+ disabled: boolean+ label: string+ ariaLabel: string+ title: string+}++function choices(html: string): Choice[] {+ const pattern = /<label class="dshp-checkbox"([^>]*)><input class="dshp-checkbox__input" type="checkbox"([^>]*)><span class="dshp-checkbox__label">([^<]*)<\/span><\/label>/g+ return [...html.matchAll(pattern)].map((match) => {+ const input = match[2] ?? ''+ return {+ title: /title="([^"]*)"/.exec(match[1] ?? '')?.[1] ?? '',+ checked: input.includes('checked=""'),+ disabled: input.includes('disabled=""'),+ ariaLabel: /aria-label="([^"]*)"/.exec(input)?.[1] ?? '',+ label: match[3] ?? '',+ }+ })+}++function chips(html: string): { checked: boolean, disabled: boolean, level: string }[] {+ return [...html.matchAll(/<label class="dshp-model-compat__chip"><input type="checkbox"([^>]*)>([a-z]+)<\/label>/g)]+ .map(match => ({+ checked: (match[1] ?? '').includes('checked'),+ disabled: (match[1] ?? '').includes('disabled'),+ level: match[2] ?? '',+ }))+}++describe('modelCompatFields', () => {+ it('labels the row and offers an ungraded thinking choice while thinking stays off', () => {+ const html = markup({}, false)+ expect(html).toContain('<fieldset class="dshp-model-compat" aria-label="Model config 1">')+ expect(html).toContain('<legend class="dshp-model-compat__label">Model config</legend>')+ expect(html).toContain('<div class="dshp-model-compat__choices">')+ expect(choices(html)).toHaveLength(1)+ expect(choices(html)[0]).toMatchObject({+ label: 'Thinking mode',+ ariaLabel: 'Thinking mode 1',+ title: 'Declare whether this model thinks',+ checked: false,+ })+ expect(html).not.toContain('Thinking levels')+ })++ it('renders the seven level chips once a graded level is declared', () => {+ const html = markup({ reasoningEfforts: { off: null, low: 'low' } }, false)+ expect(choices(html)[0]?.checked).toBe(true)+ expect(chips(html).map(chip => chip.level)).toEqual(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'])+ expect(chips(html).filter(chip => chip.checked).map(chip => chip.level)).toEqual(['off', 'low'])+ expect(html).toContain('aria-label="Thinking levels 1"')+ })++ it('gates the developer-role choice on the caller protocol decision', () => {+ const model = { compat: { thinkingFormat: 'chat-template', supportsDeveloperRole: false } }+ expect(choices(markup(model, true)).map(choice => choice.label)).toEqual(['Thinking mode', 'Disable developer role'])+ expect(choices(markup(model, true))[1]).toMatchObject({+ ariaLabel: 'Disable developer role 1',+ title: 'Turn this on for an endpoint that rejects the developer role',+ checked: true,+ })+ expect(markup(model, false)).not.toContain('Disable developer role')+ })++ it('disables every control while the editor is read-only', () => {+ const html = markup({ reasoningEfforts: { low: 'low' } }, true, true)+ expect(choices(html).every(choice => choice.disabled)).toBe(true)+ expect(chips(html).every(chip => chip.disabled)).toBe(true)+ })+})diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.tsx b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.tsxnew file mode 100644index 00000000..ffc0db19--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.tsx@@ -0,0 +1,87 @@+import type { ReactElement } from 'react'+import type { ModelCompatFieldsProps } from './model-compat-fields.types'+import { MODEL_COMPAT_FIELDS_STYLE_ID } from '../../constants'+import { useMountStyle } from '../../hooks/use-mount-style'+import {+ declaredThinkingLevels,+ enableThinking,+ supportsTemplateThinking,+ supportsThinking,+ templateThinkingCompat,+ THINKING_LEVELS,+ thinkingEffortsOf,+ toggleThinkingLevel,+} from '../../service/model-compat'+import { Checkbox } from '../checkbox'+import modelCompatFieldsStyle from './model-compat-fields.cssr'++export function ModelCompatFields({+ t,+ model,+ index,+ templateCompat,+ onPatch,+ disabled,+}: ModelCompatFieldsProps): ReactElement {+ useMountStyle(modelCompatFieldsStyle, MODEL_COMPAT_FIELDS_STYLE_ID)+ const position = index + 1+ return (+ <>+ <fieldset className="dshp-model-compat" aria-label={`${t('modelConfig')} ${String(position)}`}>+ <legend className="dshp-model-compat__label">{t('modelConfig')}</legend>+ <div className="dshp-model-compat__choices">+ <Checkbox+ checked={supportsThinking(model)}+ disabled={disabled}+ aria-label={`${t('thinkingMode')} ${String(position)}`}+ title={t('thinkingModeHint')}+ onChange={(next) => { onPatch({ reasoningEfforts: next ? enableThinking(model) : false }) }}+ >+ {t('thinkingMode')}+ </Checkbox>+ {templateCompat+ ? (+ <Checkbox+ checked={supportsTemplateThinking(model)}+ disabled={disabled}+ aria-label={`${t('developerRole')} ${String(position)}`}+ title={t('developerRoleHint')}+ onChange={(next) => { onPatch({ compat: templateThinkingCompat(model, next) }) }}+ >+ {t('developerRole')}+ </Checkbox>+ )+ : null}+ </div>+ </fieldset>+ {supportsThinking(model)+ ? (+ <div className="dshp-model-compat__levels" role="group" aria-label={`${t('thinkingLevels')} ${String(position)}`}>+ <span className="dshp-model-compat__label">{t('thinkingLevels')}</span>+ <div className="dshp-model-compat__chips">+ {THINKING_LEVELS.map(level => (+ <label key={level} className="dshp-model-compat__chip">+ <input+ type="checkbox"+ checked={declaredThinkingLevels(model).includes(level)}+ disabled={disabled}+ onChange={(event) => {+ onPatch({+ reasoningEfforts: toggleThinkingLevel(+ thinkingEffortsOf(model),+ level,+ event.target.checked,+ ),+ })+ }}+ />+ {level}+ </label>+ ))}+ </div>+ </div>+ )+ : null}+ </>+ )+}diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.types.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.types.tsnew file mode 100644index 00000000..2178976c--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-compat-fields.types.ts@@ -0,0 +1,11 @@+import type { Translate } from './types'++export interface ModelCompatFieldsProps {+ t: Translate+ model: Record<string, unknown>+ index: number+ /** 协议是 chat completions 时才渲染「关闭 Developer 角色」开关,由调用方按自己的路由判断。 */+ templateCompat: boolean+ onPatch: (patch: Record<string, unknown>) => void+ disabled?: boolean | undefined+}diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-extras.cssr.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/model-extras.cssr.tsindex 983a89b9..150d10b5 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/model-extras.cssr.ts+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-extras.cssr.ts@@ -1,60 +1,70 @@import { styles as sharedStyles } from '../../constants/theme'import { cssr } from '../../utils/cssr'-const { c, bem: { b, e, m } } = cssr+const { c } = cssrconst { primary, secondary, tertiary, error, success, hover, borderL4, layer1, modulePlatform, focusRing } = sharedStyles-export default b('model-extras', [- e('row', {+export default c([+ c('.dshp-model-extras__row', {display: 'flex',alignItems: 'center',flexWrap: 'wrap',gap: '8px',+ minWidth: '0',}),- e('link', {+ c('.dshp-model-extras__link', {+ boxSizing: 'border-box',display: 'inline-flex',alignItems: 'center',gap: '5px',- padding: '0',+ height: '28px',+ padding: '0 10px',border: 'none',- background: 'none',- color: secondary,+ borderRadius: '14px',+ background: 'transparent',+ color: tertiary,cursor: 'pointer',font: 'inherit',- fontSize: '13px',- lineHeight: '20px',+ fontSize: '12px',+ lineHeight: '18px',whiteSpace: 'nowrap',}, [- c('&:hover:not(:disabled)', { color: primary }),+ c('&:hover:not(:disabled)', {+ background: hover,+ color: secondary,+ }),c('&:focus-visible', focusRing),c('&:disabled', {cursor: 'not-allowed',opacity: '0.5',}),- m('open', {+ c('&.dshp-model-extras__link--open', {color: secondary,}),]),- e('notice', {+ c('.dshp-model-extras__notice', {+ flex: '1 1 100%',+ minWidth: '0',margin: '0',fontSize: '12px',lineHeight: '18px',color: tertiary,+ overflowWrap: 'anywhere',}, [- m('failed', { color: error }),- m('done', { color: success }),+ c('&.dshp-model-extras__notice--failed', { color: error }),+ c('&.dshp-model-extras__notice--done', { color: success }),]),- e('dialog-field', {+ c('.dshp-model-extras__dialog-field', {display: 'flex',flexDirection: 'column',gap: '6px',}),- e('dialog-label', {+ c('.dshp-model-extras__dialog-label', {fontSize: '12px',lineHeight: '18px',color: secondary,}),- e('input', {+ c('.dshp-model-extras__input', {boxSizing: 'border-box',width: '100%',height: '32px',@@ -74,21 +84,19 @@ export default b('model-extras', [opacity: '0.5',}),]),- e('dialog-hint', {+ c('.dshp-model-extras__dialog-hint', {fontSize: '12px',lineHeight: '18px',color: tertiary,}),- e('dialog-error', {+ c('.dshp-model-extras__dialog-error', {margin: '0',fontSize: '13px',lineHeight: '20px',color: error,}),- e('busy', {+ c('.dshp-model-extras__busy', {background: modulePlatform,color: tertiary,}),- c('&:hover .dshp-model-extras__link:not(:disabled)', { color: primary }),- c('.dshp-model-extras__link:hover', { background: hover }),])diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.tsx b/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.tsxindex 679c1a77..5e8f2bb1 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.tsx+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.tsx@@ -11,17 +11,18 @@ export function ModelFetchConfigButton({modelId,models,probe,+ operations,disabled,onApply,}: ModelFetchConfigButtonProps): ReactElement | null {useMountStyle(modelExtrasStyle, MODEL_EXTRAS_STYLE_ID)- const { busy, failure, run } = useModelConfigFetch({ t, models, probe, onApply })+ const { busy, failure, run } = useModelConfigFetch({ t, models, probe, operations, onApply })const row = models.find(model => model.id === modelId)if (row !== undefined && hasModelConfig(row))return nullreturn (- <>+ <div className="dshp-model-extras__row"><buttontype="button"className="dshp-model-extras__link"@@ -33,6 +34,6 @@ export function ModelFetchConfigButton({{busy ? t('fetchingConfig') : t('fetchModelConfig')}</button>{failure === undefined ? null : <p className="dshp-model-extras__notice dshp-model-extras__notice--failed" role="alert">{failure}</p>}- </>+ </div>)}diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.types.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.types.tsindex 5fc559b3..4898af41 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.types.ts+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/model-fetch-config-button.types.ts@@ -1,3 +1,4 @@+import type { ModelDiscoveryChannel } from '../../service/model-config'import type { ModelDraft, ModelProbeTarget } from './model-config-toolbar.types'import type { Translate } from './types'@@ -6,6 +7,7 @@ export interface ModelFetchConfigButtonProps {modelId: stringmodels: readonly ModelDraft[]probe: ModelProbeTarget+ operations?: ModelDiscoveryChanneldisabled?: booleanonApply?: (models: ModelDraft[], applied: number, undisclosed: string[]) => void}diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/translate.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/translate.tsindex b3651037..31ebdf31 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/translate.ts+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/translate.ts@@ -28,6 +28,12 @@ export const MODEL_EXTRAS_KEYS = ['configNoneApplied','configApplied','configUndisclosed',+ 'modelConfig',+ 'thinkingMode',+ 'thinkingLevels',+ 'thinkingModeHint',+ 'developerRole',+ 'developerRoleHint',] as constexport const modelExtrasTranslate: Translate = (key, params) => (locale.text as Translate)(key, params)diff --git a/packages/dsh-tauri-ui/src/client/components/model-extras/use-model-config-fetch.ts b/packages/dsh-tauri-ui/src/client/components/model-extras/use-model-config-fetch.tsindex ba1eef58..2453c802 100644--- a/packages/dsh-tauri-ui/src/client/components/model-extras/use-model-config-fetch.ts+++ b/packages/dsh-tauri-ui/src/client/components/model-extras/use-model-config-fetch.ts@@ -1,3 +1,4 @@+import type { ModelDiscoveryChannel } from '../../service/model-config'import type { ModelDraft, ModelProbeTarget } from './model-config-toolbar.types'import type { Translate } from './types'import { useCallback, useState } from 'react'@@ -23,6 +24,7 @@ export interface UseModelConfigFetchOptions {t: Translatemodels: readonly ModelDraft[]probe: ModelProbeTarget+ operations?: ModelDiscoveryChannelonApply?: (models: ModelDraft[], applied: number, undisclosed: string[]) => void}@@ -43,7 +45,7 @@ export function useModelConfigFetch(options: UseModelConfigFetchOptions): UseMod...options.probe.baseURL === undefined ? {} : { baseURL: options.probe.baseURL },...options.probe.api === undefined ? {} : { api: options.probe.api },...options.probe.apiKey === undefined ? {} : { apiKey: options.probe.apiKey },- }),+ }, options.operations),ensurePresets(),])setBusy(false)diff --git a/packages/dsh-tauri-ui/src/client/constants/index.ts b/packages/dsh-tauri-ui/src/client/constants/index.tsindex a542d8dd..b7f975ee 100644--- a/packages/dsh-tauri-ui/src/client/constants/index.ts+++ b/packages/dsh-tauri-ui/src/client/constants/index.ts@@ -24,6 +24,7 @@ export const SEGMENTED_CONTROL_STYLE_ID = 'dsh-tauri-ui-segmented-control-stylesexport const CHECKBOX_STYLE_ID = 'dsh-tauri-ui-checkbox-styles'export const MODEL_EXTRAS_STYLE_ID = 'dsh-tauri-ui-model-extras-styles'export const MODEL_CONFIG_TOOLBAR_STYLE_ID = 'dsh-tauri-ui-model-config-toolbar-styles'+export const MODEL_COMPAT_FIELDS_STYLE_ID = 'dsh-tauri-ui-model-compat-fields-styles'/** 接管后的英雄区工作区选择控件(官方 chip 由样式隐藏,见 `components/hero-workspace.cssr.ts`)。 */export const HERO_WORKSPACE_CHIP_CLASS = 'dshp-hero-workspace'diff --git a/packages/dsh-tauri-ui/src/client/index.ts b/packages/dsh-tauri-ui/src/client/index.tsindex e2df9185..69967d13 100644--- a/packages/dsh-tauri-ui/src/client/index.ts+++ b/packages/dsh-tauri-ui/src/client/index.ts@@ -20,6 +20,7 @@ export type * from './components/trigger.types'export * from './constants/theme'export * from './hooks/use-mount-style'export * from './service/editor'+export * from './service/model-compat'export * from './service/model-config'export { hasModelConfig, mergeModelCards, modelConfigNotice, withCount, withDetail, withPath } from './service/model-config.utils'export type { ModelConfigMerge, ModelConfigMergeOptions } from './service/model-config.utils'diff --git a/packages/dsh-tauri-ui/src/client/locales/index.ts b/packages/dsh-tauri-ui/src/client/locales/index.tsindex ba106360..39b85e81 100644--- a/packages/dsh-tauri-ui/src/client/locales/index.ts+++ b/packages/dsh-tauri-ui/src/client/locales/index.ts@@ -43,6 +43,12 @@ export const locale = defineLocale(PLUGIN_ID, {configNoneApplied: '端点与模型能力表都没有为这些模型提供可写入的配置。',configApplied: '已配置 {n} 个模型。',configUndisclosed: '{n} 个模型未被端点披露。',+ modelConfig: '模型开关',+ thinkingMode: '思考模式',+ thinkingLevels: '思考深度',+ thinkingModeHint: '声明该模型是否支持思考,并勾选它提供的档位',+ developerRole: '关闭 Developer 角色',+ developerRoleHint: '端点是本地部署这类不认 developer 角色时打开:系统提示保持 system,思考档位改从 chat_template_kwargs 下发;开启后写入 compat:supportsDeveloperRole=false、thinkingFormat=chat-template、chatTemplateKwargs.reasoning_effort={$var: thinking.effort}',},en: {back: 'Back to app',@@ -85,5 +91,11 @@ export const locale = defineLocale(PLUGIN_ID, {configNoneApplied: 'Neither the endpoint nor the capability table had anything to write for these models.',configApplied: 'Configured {n} model(s).',configUndisclosed: '{n} model(s) were not disclosed by the endpoint.',+ modelConfig: 'Model switches',+ thinkingMode: 'Thinking mode',+ thinkingLevels: 'Thinking depth',+ thinkingModeHint: 'Declare whether this model thinks, then tick the levels it offers',+ developerRole: 'Disable developer role',+ developerRoleHint: 'Turn this on for an endpoint that rejects the developer role: system prompts stay system, and the effort travels through chat_template_kwargs; writes compat supportsDeveloperRole=false, thinkingFormat=chat-template and chatTemplateKwargs.reasoning_effort={$var: thinking.effort}',},})diff --git a/packages/dsh-tauri-ui/src/client/register/styles.ts b/packages/dsh-tauri-ui/src/client/register/styles.tsindex 80be637e..4659b4cf 100644--- a/packages/dsh-tauri-ui/src/client/register/styles.ts+++ b/packages/dsh-tauri-ui/src/client/register/styles.ts@@ -1,6 +1,19 @@import type { ClientContext } from 'dsh-tauri/client'import { defineRegister } from 'dsh-tauri/client'-import { GLOBAL_STYLE_ID, TURN_NAVIGATION_STYLE_ID } from '../constants'+import checkboxStyle from '../components/checkbox.cssr'+import { configEditorStyle } from '../components/model-extras/config-editor.cssr'+import modelCompatFieldsStyle from '../components/model-extras/model-compat-fields.cssr'+import modelExtrasStyle from '../components/model-extras/model-extras.cssr'+import segmentedControlStyle from '../components/segmented-control.cssr'+import {+ CHECKBOX_STYLE_ID,+ GLOBAL_STYLE_ID,+ MODEL_COMPAT_FIELDS_STYLE_ID,+ MODEL_CONFIG_TOOLBAR_STYLE_ID,+ MODEL_EXTRAS_STYLE_ID,+ SEGMENTED_CONTROL_STYLE_ID,+ TURN_NAVIGATION_STYLE_ID,+} from '../constants'import globalStyle from '../styles/global.cssr'import turnNavigationStyle from '../styles/index.cssr'import { mountStyle } from '../utils/style'@@ -8,4 +21,9 @@ import { mountStyle } from '../utils/style'export const registerStyles = defineRegister<ClientContext>((controller) => {controller.add(mountStyle(globalStyle, GLOBAL_STYLE_ID))controller.add(mountStyle(turnNavigationStyle, TURN_NAVIGATION_STYLE_ID))+ controller.add(mountStyle(modelExtrasStyle, MODEL_EXTRAS_STYLE_ID))+ controller.add(mountStyle(configEditorStyle, MODEL_CONFIG_TOOLBAR_STYLE_ID))+ controller.add(mountStyle(modelCompatFieldsStyle, MODEL_COMPAT_FIELDS_STYLE_ID))+ controller.add(mountStyle(segmentedControlStyle, SEGMENTED_CONTROL_STYLE_ID))+ controller.add(mountStyle(checkboxStyle, CHECKBOX_STYLE_ID))})diff --git a/packages/dsh-tauri-ui/src/client/service/model-compat.test.ts b/packages/dsh-tauri-ui/src/client/service/model-compat.test.tsnew file mode 100644index 00000000..2c8896c4--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/service/model-compat.test.ts@@ -0,0 +1,138 @@+import { describe, expect, it } from 'vitest'+import {+ declaredThinkingLevels,+ DEFAULT_THINKING_EFFORTS,+ enableThinking,+ supportsTemplateThinking,+ supportsThinking,+ templateThinkingCompat,+ THINKING_LEVELS,+ thinkingEffortsOf,+ toggleThinkingLevel,+} from './model-compat'++describe('thinkingEffortsOf', () => {+ it('reads a declared effort table', () => {+ expect(thinkingEffortsOf({ reasoningEfforts: { off: null, high: 'high' } })).toEqual({ off: null, high: 'high' })+ })++ it('treats a missing, disabled or malformed declaration as empty', () => {+ expect(thinkingEffortsOf({})).toEqual({})+ expect(thinkingEffortsOf({ reasoningEfforts: false })).toEqual({})+ expect(thinkingEffortsOf({ reasoningEfforts: ['high'] })).toEqual({})+ expect(thinkingEffortsOf({ reasoningEfforts: null })).toEqual({})+ expect(thinkingEffortsOf({ reasoningEfforts: 'high' })).toEqual({})+ })++ it('covers every level the model editor offers', () => {+ expect([...THINKING_LEVELS]).toEqual(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'])+ })+})++describe('declaredThinkingLevels / supportsThinking', () => {+ it('lists declared levels', () => {+ expect(declaredThinkingLevels({ reasoningEfforts: { off: null, low: 'low' } })).toEqual(['off', 'low'])+ })++ it('only counts a graded level as thinking support', () => {+ expect(supportsThinking({})).toBe(false)+ expect(supportsThinking({ reasoningEfforts: false })).toBe(false)+ expect(supportsThinking({ reasoningEfforts: { off: null } })).toBe(false)+ expect(supportsThinking({ reasoningEfforts: { off: null, minimal: 'minimal' } })).toBe(true)+ })+})++describe('enableThinking', () => {+ it('falls back to the default graded table when nothing is declared', () => {+ expect(enableThinking({})).toEqual(DEFAULT_THINKING_EFFORTS)+ expect(enableThinking({ reasoningEfforts: { off: null } })).toEqual(DEFAULT_THINKING_EFFORTS)+ })++ it('keeps an existing declaration untouched', () => {+ const declared = { off: null, minimal: 'minimal' }+ expect(enableThinking({ reasoningEfforts: declared })).toEqual(declared)+ })+})++describe('toggleThinkingLevel', () => {+ it('adds a level with its own value, and maps off to null', () => {+ expect(toggleThinkingLevel({}, 'high', true)).toEqual({ high: 'high' })+ expect(toggleThinkingLevel({ high: 'high' }, 'off', true)).toEqual({ high: 'high', off: null })+ })++ it('removes a level and reports an empty table as false', () => {+ expect(toggleThinkingLevel({ off: null, high: 'high' }, 'off', false)).toEqual({ high: 'high' })+ expect(toggleThinkingLevel({ high: 'high' }, 'high', false)).toBe(false)+ })++ it('never mutates its input', () => {+ const efforts = { high: 'high' }+ toggleThinkingLevel(efforts, 'off', true)+ expect(efforts).toEqual({ high: 'high' })+ })+})++describe('supportsTemplateThinking', () => {+ it('requires both the chat template format and the developer-role opt-out', () => {+ expect(supportsTemplateThinking({})).toBe(false)+ expect(supportsTemplateThinking({ compat: { thinkingFormat: 'chat-template' } })).toBe(false)+ expect(supportsTemplateThinking({ compat: { supportsDeveloperRole: false } })).toBe(false)+ expect(supportsTemplateThinking({+ compat: { thinkingFormat: 'chat-template', supportsDeveloperRole: false },+ })).toBe(true)+ })+})++describe('templateThinkingCompat', () => {+ it('writes the three facts and routes the effort through the template kwarg', () => {+ expect(templateThinkingCompat({}, true)).toEqual({+ chatTemplateKwargs: { reasoning_effort: { $var: 'thinking.effort' } },+ thinkingFormat: 'chat-template',+ supportsDeveloperRole: false,+ })+ })++ it('preserves unrelated compat keys and chat template kwargs', () => {+ expect(templateThinkingCompat({+ compat: {+ supportsReasoningEffort: true,+ chatTemplateKwargs: { enable_thinking: true, reasoning_effort: 'low' },+ },+ }, true)).toEqual({+ supportsReasoningEffort: true,+ chatTemplateKwargs: {+ enable_thinking: true,+ reasoning_effort: { $var: 'thinking.effort' },+ },+ thinkingFormat: 'chat-template',+ supportsDeveloperRole: false,+ })+ })++ it('removes the three facts and drops the kwarg when turning off', () => {+ expect(templateThinkingCompat({+ compat: {+ supportsReasoningEffort: true,+ thinkingFormat: 'chat-template',+ supportsDeveloperRole: false,+ chatTemplateKwargs: { reasoning_effort: { $var: 'thinking.effort' } },+ },+ }, false)).toEqual({ supportsReasoningEffort: true })+ })++ it('keeps leftover chat template kwargs when turning off', () => {+ expect(templateThinkingCompat({+ compat: {+ thinkingFormat: 'chat-template',+ supportsDeveloperRole: false,+ chatTemplateKwargs: { enable_thinking: true, reasoning_effort: { $var: 'thinking.effort' } },+ },+ }, false)).toEqual({ chatTemplateKwargs: { enable_thinking: true } })+ })++ it('erases the whole compat field when nothing else is configured', () => {+ expect(templateThinkingCompat({+ compat: { thinkingFormat: 'chat-template', supportsDeveloperRole: false },+ }, false)).toBeUndefined()+ })+})diff --git a/packages/dsh-tauri-ui/src/client/service/model-compat.ts b/packages/dsh-tauri-ui/src/client/service/model-compat.tsnew file mode 100644index 00000000..8622fc62--- /dev/null+++ b/packages/dsh-tauri-ui/src/client/service/model-compat.ts@@ -0,0 +1,101 @@+export type ModelCompatDraft = Record<string, unknown>++export const THINKING_LEVELS = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'] as const++export const DEFAULT_THINKING_EFFORTS: Readonly<Record<string, string | null>> = {+ off: null,+ low: 'low',+ medium: 'medium',+ high: 'high',+}++export const TEMPLATE_THINKING_FORMAT = 'chat-template'+export const TEMPLATE_THINKING_KWARG = 'reasoning_effort'+export const TEMPLATE_THINKING_EFFORT_VAR = 'thinking.effort'++/**+ * 「关闭 Developer 角色」只对 chat completions 协议有意义:pi-ai 的 compat 逐协议校验,+ * `thinkingFormat` 与 `chatTemplateKwargs` 写到 Responses/Anthropic 路由上会让配置解析失败。+ * 路由没有显式协议时无法判断,因此调用方用 `api === TEMPLATE_COMPAT_PROTOCOL` 决定是否渲染。+ */+export const TEMPLATE_COMPAT_PROTOCOL = 'openai-completions'++function recordOf(value: unknown): Record<string, unknown> {+ if (typeof value !== 'object' || value === null || Array.isArray(value))+ return {}+ return value as Record<string, unknown>+}++function compatOf(model: ModelCompatDraft): Record<string, unknown> {+ return recordOf(model.compat)+}++export function thinkingEffortsOf(model: ModelCompatDraft): Record<string, string | null> {+ const efforts = model.reasoningEfforts+ if (typeof efforts !== 'object' || efforts === null || Array.isArray(efforts))+ return {}+ return efforts as Record<string, string | null>+}++export function declaredThinkingLevels(model: ModelCompatDraft): string[] {+ return Object.keys(thinkingEffortsOf(model))+}++export function supportsThinking(model: ModelCompatDraft): boolean {+ return Object.keys(thinkingEffortsOf(model)).some(level => level !== 'off')+}++export function enableThinking(model: ModelCompatDraft): Record<string, string | null> {+ const current = thinkingEffortsOf(model)+ const graded = Object.keys(current).filter(level => level !== 'off')+ return graded.length === 0 ? { ...DEFAULT_THINKING_EFFORTS } : current+}++/**+ * 取消到空表时写 `false`(显式「不支持思考」)而不是空对象:空表会被 schema 判为非法声明。+ */+export function toggleThinkingLevel(+ efforts: Readonly<Record<string, string | null>>,+ level: string,+ enabled: boolean,+): Record<string, string | null> | false {+ const next = { ...efforts }+ if (enabled)+ next[level] = level === 'off' ? null : level+ else+ delete next[level]+ return Object.keys(next).length === 0 ? false : next+}++export function supportsTemplateThinking(model: ModelCompatDraft): boolean {+ const compat = compatOf(model)+ return compat.thinkingFormat === TEMPLATE_THINKING_FORMAT && compat.supportsDeveloperRole === false+}++/**+ * 打开时写入 vLLM 这类端点需要的三项事实(思考参数走 chat_template_kwargs、档位由下拉框动态填入、+ * 系统提示保持 system 角色);关闭只摘掉这三项,条目里其它 compat 键与 chat template 参数原样保留。+ * compat 被摘空时返回 undefined,让调用方删掉整个字段。+ */+export function templateThinkingCompat(+ model: ModelCompatDraft,+ next: boolean,+): Record<string, unknown> | undefined {+ const compat = { ...compatOf(model) }+ const kwargs = { ...recordOf(compat.chatTemplateKwargs) }+ delete kwargs[TEMPLATE_THINKING_KWARG]+ if (next) {+ compat.chatTemplateKwargs = { ...kwargs, [TEMPLATE_THINKING_KWARG]: { $var: TEMPLATE_THINKING_EFFORT_VAR } }+ compat.thinkingFormat = TEMPLATE_THINKING_FORMAT+ compat.supportsDeveloperRole = false+ }+ else {+ delete compat.thinkingFormat+ delete compat.supportsDeveloperRole+ if (Object.keys(kwargs).length === 0)+ delete compat.chatTemplateKwargs+ else+ compat.chatTemplateKwargs = kwargs+ }+ return Object.keys(compat).length === 0 ? undefined : compat+}