🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(model-select): fix empty permission tooltip and compact stale-model popup (#17754)
YuTengjing41abca226157
diff --git a/locales/en-US/components.json b/locales/en-US/components.jsonindex 45da192861f..09426d34178 100644--- a/locales/en-US/components.json+++ b/locales/en-US/components.json@@ -124,9 +124,9 @@"ModelSelect.staleModel.current": "Current selection","ModelSelect.staleModel.notEnabled.action": "Enable this model","ModelSelect.staleModel.notEnabled.actionFailed": "Failed to enable the model. Please try again.",- "ModelSelect.staleModel.notEnabled.hint": "This model is not enabled. Features using it keep working; you can enable it or choose another model.",+ "ModelSelect.staleModel.notEnabled.hint": "This model is not enabled. Features using it keep working; switch it on here or choose another model.","ModelSelect.staleModel.notEnabled.tag": "Not enabled",- "ModelSelect.staleModel.notEnabled.tooltip": "This model is not enabled in its provider. Features using it keep working; enable it below or choose another model.",+ "ModelSelect.staleModel.notEnabled.tooltip": "This model is not enabled in its provider. Features using it keep working; switch it on in the list or choose another model.","ModelSelect.staleModel.redirected.action": "Update to {{successorName}}","ModelSelect.staleModel.redirected.hint": "Requests are actually served by {{successorName}}. Update to it, or choose another model.","ModelSelect.staleModel.redirected.tag": "Redirected",diff --git a/locales/zh-CN/components.json b/locales/zh-CN/components.jsonindex de81b64e864..abe7f61b6c2 100644--- a/locales/zh-CN/components.json+++ b/locales/zh-CN/components.json@@ -124,9 +124,9 @@"ModelSelect.staleModel.current": "当前配置","ModelSelect.staleModel.notEnabled.action": "启用此模型","ModelSelect.staleModel.notEnabled.actionFailed": "启用模型失败,请重试",- "ModelSelect.staleModel.notEnabled.hint": "该模型未启用,使用它的功能仍可正常工作;可启用它或更换其他模型",+ "ModelSelect.staleModel.notEnabled.hint": "该模型未启用,使用它的功能仍可正常工作;可打开右侧开关启用,或更换其他模型","ModelSelect.staleModel.notEnabled.tag": "未启用",- "ModelSelect.staleModel.notEnabled.tooltip": "该模型未在服务商中启用,使用它的功能仍可正常工作;可在下方启用或更换其他模型",+ "ModelSelect.staleModel.notEnabled.tooltip": "该模型未在服务商中启用,使用它的功能仍可正常工作;可在列表中打开开关启用或更换其他模型","ModelSelect.staleModel.redirected.action": "更新为 {{successorName}}","ModelSelect.staleModel.redirected.hint": "请求实际由 {{successorName}} 处理,可一键更新或更换其他模型","ModelSelect.staleModel.redirected.tag": "已重定向",diff --git a/packages/locales/src/default/components.ts b/packages/locales/src/default/components.tsindex a469adb4823..2cc4d607b27 100644--- a/packages/locales/src/default/components.ts+++ b/packages/locales/src/default/components.ts@@ -148,10 +148,10 @@ export default {'ModelSelect.staleModel.notEnabled.action': 'Enable this model','ModelSelect.staleModel.notEnabled.actionFailed': 'Failed to enable the model. Please try again.','ModelSelect.staleModel.notEnabled.hint':- 'This model is not enabled. Features using it keep working; you can enable it or choose another model.',+ 'This model is not enabled. Features using it keep working; switch it on here or choose another model.','ModelSelect.staleModel.notEnabled.tag': 'Not enabled','ModelSelect.staleModel.notEnabled.tooltip':- 'This model is not enabled in its provider. Features using it keep working; enable it below or choose another model.',+ 'This model is not enabled in its provider. Features using it keep working; switch it on in the list or choose another model.','ModelSelect.staleModel.redirected.action': 'Update to {{successorName}}','ModelSelect.staleModel.redirected.hint':'Requests are actually served by {{successorName}}. Update to it, or choose another model.',diff --git a/src/features/ModelSelect/index.tsx b/src/features/ModelSelect/index.tsxindex fbe7b457145..6933577cded 100644--- a/src/features/ModelSelect/index.tsx+++ b/src/features/ModelSelect/index.tsx@@ -1,10 +1,9 @@import { ModelIcon } from '@lobehub/icons';-import { Flexbox, Icon, Tag, Text, Tooltip, TooltipGroup } from '@lobehub/ui';-import { Select, type SelectProps } from '@lobehub/ui/base-ui';+import { Flexbox, Tag, Text, Tooltip, TooltipGroup } from '@lobehub/ui';+import { Button, Select, type SelectProps, Switch } from '@lobehub/ui/base-ui';import { createStaticStyles } from 'antd-style';-import { Replace, SquarePower } from 'lucide-react';import { type ReactNode } from 'react';-import { memo, useMemo, useState } from 'react';+import { memo, useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';import { message } from '@/components/AntdStaticMethods';@@ -23,22 +22,32 @@ const prefixCls = 'ant';const STALE_EXTRA_CLASSNAME = 'lobe-model-select-stale-extra';/**- * Sentinel option value for the stale-model remedy row ("enable this model" /- * "update to successor"). Intercepted in onChange so selecting it triggers the- * remedy instead of a value change.+ * Marks the stale-status Tag so the popup can hide it — inside the open list the+ * status is conveyed by the enable toggle (notEnabled) or the remedy row+ * (redirected), while the closed trigger keeps showing the Tag.+ */+const STALE_TAG_CLASSNAME = 'lobe-model-select-stale-tag';++/**+ * Sentinel option value for the redirected-model remedy row ("update to+ * successor"). Intercepted in onChange so selecting it triggers the remedy+ * instead of a value change.*/const STALE_ACTION_VALUE = '__lobe_model_select_stale_action__';const styles = createStaticStyles(({ css, cssVar }) => ({- actionOption: css`- color: ${cssVar.colorInfo};- `,popup: css`width: max(360px, var(--anchor-width));&.${prefixCls}-select-dropdown .${prefixCls}-select-item-option-grouped {padding-inline-start: 12px;}++ /* !important: the Tag's own class rule wins the cascade over this+ * descendant selector, so a plain display: none never applies. */+ .${STALE_TAG_CLASSNAME} {+ display: none !important;+ }`,select: css`/* The base-ui Select applies className to the trigger root while the popup is@@ -175,6 +184,52 @@ const ModelSelect = memo<ModelSelectProps>(value,]);+ const handleEnable = useCallback(async () => {+ // Prefer the provider the selection is persisted under so every surface+ // referencing `${provider}/${model}` recovers at once; the builtin-bank+ // provider is only a fallback for a persisted provider that no longer exists.+ const providerId = resolveEnableTargetProviderId(value, {+ enabledAiProviders,+ enabledList,+ metaProviderId: staleState?.meta?.providerId,+ });+ if (!providerId || !value) return;++ setEnabling(true);+ try {+ // Enabling only the model row is a silent no-op when the owning provider is+ // disabled — the picker keeps building options from enabled providers. Enable+ // the provider first so the remedy actually makes the selection resolvable+ // (idempotent when the provider is enabled but absent from this typed list).+ if (!enabledList.some((provider) => provider.id === providerId)) {+ await toggleProviderEnabled(providerId, true);+ }+ await toggleProviderModelEnabled({+ enabled: true,+ id: value.model,+ providerId,+ type: modelType,+ });+ // Realign the selection when it pointed at a different provider, so the now+ // enabled model resolves as a valid option instead of staying stale.+ if (providerId !== value.provider) onChange?.({ model: value.model, provider: providerId });+ } catch {+ message.error(t('ModelSelect.staleModel.notEnabled.actionFailed'));+ } finally {+ setEnabling(false);+ }+ }, [+ enabledAiProviders,+ enabledList,+ modelType,+ onChange,+ staleState,+ t,+ toggleProviderEnabled,+ toggleProviderModelEnabled,+ value,+ ]);+const finalOptions = useMemo<SelectProps['options']>(() => {if (!staleState || !value) return options;@@ -193,6 +248,7 @@ const ModelSelect = memo<ModelSelectProps>(</Text><Tooltip title={t(`ModelSelect.staleModel.${status}.tooltip`, { successorName })}><Tag+ className={STALE_TAG_CLASSNAME}color={status === 'removed' ? 'warning' : undefined}size={'small'}style={{ cursor: 'default', flex: 'none' }}@@ -200,6 +256,36 @@ const ModelSelect = memo<ModelSelectProps>({t(`ModelSelect.staleModel.${status}.tag`)}</Tag></Tooltip>+ {status === 'notEnabled' && (+ <>+ <span className={STALE_EXTRA_CLASSNAME} style={{ flex: 1 }} />+ {/* The wrapper re-enables pointer events (the disabled option row+ * suppresses them) and stops propagation so toggling never counts+ * as selecting the row. */}+ <span+ className={STALE_EXTRA_CLASSNAME}+ style={{ flex: 'none', pointerEvents: 'auto' }}+ onClick={(e) => {+ e.stopPropagation();+ e.preventDefault();+ }}+ onMouseDown={(e) => {+ e.stopPropagation();+ e.preventDefault();+ }}+ >+ <Switch+ aria-label={t('ModelSelect.staleModel.notEnabled.action')}+ checked={false}+ loading={enabling}+ size={'small'}+ onChange={() => {+ void handleEnable();+ }}+ />+ </span>+ </>+ )}</Flexbox><span className={`${STALE_EXTRA_CLASSNAME} ${styles.staleHint}`}>{t(`ModelSelect.staleModel.${status}.hint`, { successorName })}@@ -209,20 +295,23 @@ const ModelSelect = memo<ModelSelectProps>(value: `${value.provider}/${value.model}`,};+ // notEnabled recovers via the inline toggle above; only the redirected+ // remedy ("update to successor") still needs a dedicated action row.const actionLabel =- status === 'notEnabled'- ? t('ModelSelect.staleModel.notEnabled.action')- : status === 'redirected'- ? t('ModelSelect.staleModel.redirected.action', { successorName })- : undefined;+ status === 'redirected'+ ? t('ModelSelect.staleModel.redirected.action', { successorName })+ : undefined;const actionOption = actionLabel? {__stale: true,label: (- <Flexbox horizontal align={'center'} className={styles.actionOption} gap={8}>- <Icon icon={status === 'redirected' ? Replace : SquarePower} size={16} />- {actionLabel}+ <Flexbox horizontal>+ {/* Visual-only button: the sentinel option row owns the click (via+ * onChange), so pointer events are disabled to keep one hit target. */}+ <Button size={'small'} style={{ pointerEvents: 'none' }}>+ {actionLabel}+ </Button></Flexbox>),value: STALE_ACTION_VALUE,@@ -236,43 +325,7 @@ const ModelSelect = memo<ModelSelectProps>(},...(options ?? []),] as SelectProps['options'];- }, [options, staleState, t, value]);-- const handleEnable = async () => {- // Prefer the provider the selection is persisted under so every surface- // referencing `${provider}/${model}` recovers at once; the builtin-bank- // provider is only a fallback for a persisted provider that no longer exists.- const providerId = resolveEnableTargetProviderId(value, {- enabledAiProviders,- enabledList,- metaProviderId: staleState?.meta?.providerId,- });- if (!providerId || !value) return;-- setEnabling(true);- try {- // Enabling only the model row is a silent no-op when the owning provider is- // disabled — the picker keeps building options from enabled providers. Enable- // the provider first so the remedy actually makes the selection resolvable- // (idempotent when the provider is enabled but absent from this typed list).- if (!enabledList.some((provider) => provider.id === providerId)) {- await toggleProviderEnabled(providerId, true);- }- await toggleProviderModelEnabled({- enabled: true,- id: value.model,- providerId,- type: modelType,- });- // Realign the selection when it pointed at a different provider, so the now- // enabled model resolves as a valid option instead of staying stale.- if (providerId !== value.provider) onChange?.({ model: value.model, provider: providerId });- } catch {- message.error(t('ModelSelect.staleModel.notEnabled.actionFailed'));- } finally {- setEnabling(false);- }- };+ }, [enabling, handleEnable, options, staleState, t, value]);return (<TooltipGroup>@@ -311,8 +364,6 @@ const ModelSelect = memo<ModelSelectProps>(value?.provider) {onChange?.({ model: staleState.successorId, provider: value.provider });- } else {- void handleEnable();}return;}diff --git a/src/hooks/usePermission.ts b/src/hooks/usePermission.tsindex 079260a9c15..5c0bea30f5a 100644--- a/src/hooks/usePermission.ts+++ b/src/hooks/usePermission.ts@@ -1,9 +1,15 @@export interface Permission {allowed: boolean;- reason: string;+ /**+ * Localised tooltip text explaining why the action is blocked. `undefined`+ * when allowed, so unconditional `<Tooltip title={reason}>` wrappers render+ * nothing instead of an empty tooltip bubble (Tooltip only skips nullish+ * titles, not empty strings).+ */+ reason?: string;}export const usePermission = (_action: string): Permission => ({allowed: true,- reason: '',+ reason: undefined,});