@deepseek-harness-tui/dsh-tui 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/cli/adapters/dsh/index.mjs +2 -2
- package/guide/dsh-tui-guide/cli.en.md +1 -1
- package/guide/dsh-tui-guide/cli.md +1 -1
- package/guide/dsh-tui-guide/configuration.en.md +3 -2
- package/guide/dsh-tui-guide/configuration.md +3 -2
- package/guide/dsh-tui-guide/getting-started.en.md +6 -2
- package/guide/dsh-tui-guide/getting-started.md +4 -1
- package/guide/dsh-tui-guide/interaction.en.md +28 -7
- package/guide/dsh-tui-guide/interaction.md +17 -5
- package/guide/dsh-tui-guide/plugins.en.md +28 -7
- package/guide/dsh-tui-guide/plugins.md +18 -5
- package/guide/dsh-tui-guide/user-guide.en.md +29 -15
- package/guide/dsh-tui-guide/user-guide.md +20 -10
- package/lib/settings.json +3 -3
- package/lib/types/adapter/channel/ui-policy.d.ts +1 -0
- package/lib/types/adapter/channel/ui-policy.d.ts.map +1 -1
- package/lib/types/adapter/channel/ui-policy.js +1 -0
- package/lib/types/adapter/ports/channel-ui.d.ts +5 -0
- package/lib/types/adapter/ports/channel-ui.d.ts.map +1 -1
- package/lib/types/adapter/ports/channel-view.d.ts +3 -0
- package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
- package/lib/types/adapter/standard/grants.d.ts +60 -0
- package/lib/types/adapter/standard/grants.d.ts.map +1 -1
- package/lib/types/adapter/standard/grants.js +74 -0
- package/lib/types/agent/events.d.ts +7 -1
- package/lib/types/agent/events.d.ts.map +1 -1
- package/lib/types/commands.js +1 -1
- package/lib/types/components/GoalTodoPanel.d.ts +71 -6
- package/lib/types/components/GoalTodoPanel.d.ts.map +1 -1
- package/lib/types/components/GoalTodoPanel.js +165 -17
- package/lib/types/components/MessageList.d.ts.map +1 -1
- package/lib/types/components/MessageList.js +3 -2
- package/lib/types/components/PluginGrantList.d.ts +45 -0
- package/lib/types/components/PluginGrantList.d.ts.map +1 -0
- package/lib/types/components/PluginGrantList.js +126 -0
- package/lib/types/components/PluginInstallPane.d.ts.map +1 -1
- package/lib/types/components/PluginInstallPane.js +35 -6
- package/lib/types/components/PluginManagePane.d.ts.map +1 -1
- package/lib/types/components/PluginManagePane.js +65 -8
- package/lib/types/components/PromptInput.js +2 -2
- package/lib/types/components/SubagentDashboard.d.ts.map +1 -1
- package/lib/types/components/SubagentDashboard.js +10 -0
- package/lib/types/components/SubagentDetailScene.d.ts.map +1 -1
- package/lib/types/components/SubagentDetailScene.js +12 -0
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts +2 -1
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.js +11 -5
- package/lib/types/components/onboardingModel.d.ts +2 -2
- package/lib/types/components/onboardingModel.js +3 -3
- package/lib/types/components/onboardingProviderPlan.d.ts +110 -0
- package/lib/types/components/onboardingProviderPlan.d.ts.map +1 -0
- package/lib/types/components/onboardingProviderPlan.js +78 -0
- package/lib/types/components/sidePanel/btw/BtwComposer.d.ts +7 -0
- package/lib/types/components/sidePanel/btw/BtwComposer.d.ts.map +1 -1
- package/lib/types/components/sidePanel/btw/BtwComposer.js +16 -0
- package/lib/types/components/sidePanel/btw/BtwPanelAdapter.d.ts.map +1 -1
- package/lib/types/components/sidePanel/btw/BtwPanelAdapter.js +8 -1
- package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts +7 -1
- package/lib/types/components/sidePanel/btw/BtwThreadScene.d.ts.map +1 -1
- package/lib/types/components/sidePanel/btw/BtwThreadScene.js +8 -1
- package/lib/types/components/sidePanel/btw/useBtwComposerPaste.d.ts +30 -0
- package/lib/types/components/sidePanel/btw/useBtwComposerPaste.d.ts.map +1 -0
- package/lib/types/components/sidePanel/btw/useBtwComposerPaste.js +94 -0
- package/lib/types/components/sidePanel/builtinPanels.d.ts.map +1 -1
- package/lib/types/components/sidePanel/builtinPanels.js +14 -2
- package/lib/types/components/sidePanel/types.d.ts +2 -0
- package/lib/types/components/sidePanel/types.d.ts.map +1 -1
- package/lib/types/components/sidePanel/useSidePanel.d.ts.map +1 -1
- package/lib/types/components/sidePanel/useSidePanel.js +15 -1
- package/lib/types/dsh-adapter/backend/session.d.ts +7 -1
- package/lib/types/dsh-adapter/backend/session.d.ts.map +1 -1
- package/lib/types/dsh-adapter/backend/session.js +62 -6
- package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
- package/lib/types/dsh-adapter/backend/translate.js +9 -5
- package/lib/types/dsh-adapter/channel/agent-view-projection.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/agent-view-projection.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/agent-view-projection.js +3 -1
- package/lib/types/dsh-adapter/channel/composer-images.d.ts +2 -0
- package/lib/types/dsh-adapter/channel/composer-images.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/composer-images.js +10 -2
- package/lib/types/dsh-adapter/channel/composer-mentions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/composer-mentions.js +22 -7
- package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/context-bookkeeping.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/context-bookkeeping.js +9 -5
- package/lib/types/dsh-adapter/channel/core/binding-feed.d.ts +6 -0
- package/lib/types/dsh-adapter/channel/core/binding-feed.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/core/binding-feed.js +35 -1
- package/lib/types/dsh-adapter/channel/core/compose.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/core/compose.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/core/compose.js +5 -0
- package/lib/types/dsh-adapter/channel/input-actions.d.ts +2 -2
- package/lib/types/dsh-adapter/channel/input-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/input-actions.js +30 -0
- package/lib/types/dsh-adapter/channel/input-delivery.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/input-delivery.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/input-delivery.js +8 -4
- package/lib/types/dsh-adapter/channel/mentions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/mentions.js +21 -7
- package/lib/types/dsh-adapter/channel/paths.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/paths.js +11 -9
- package/lib/types/dsh-adapter/channel/session-live-adoption.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/session-live-adoption.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-live-adoption.js +6 -1
- package/lib/types/dsh-adapter/channel/session-reset.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-reset.js +3 -1
- package/lib/types/dsh-adapter/channel/session-resume.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/session-resume.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-resume.js +10 -3
- package/lib/types/dsh-adapter/channel/session-rewind.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/session-rewind.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-rewind.js +3 -1
- package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/session-tree-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/session-tree-actions.js +3 -1
- package/lib/types/dsh-adapter/contract.d.ts +4 -3
- package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
- package/lib/types/dsh-adapter/contract.js +6 -3
- package/lib/types/dsh-adapter/entry-slot.d.ts +6 -0
- package/lib/types/dsh-adapter/entry-slot.d.ts.map +1 -1
- package/lib/types/dsh-adapter/experimental-bundles.d.ts +3 -0
- package/lib/types/dsh-adapter/experimental-bundles.d.ts.map +1 -1
- package/lib/types/dsh-adapter/experimental-bundles.js +4 -0
- package/lib/types/dsh-adapter/grant-file.d.ts +70 -0
- package/lib/types/dsh-adapter/grant-file.d.ts.map +1 -0
- package/lib/types/dsh-adapter/grant-file.js +178 -0
- package/lib/types/dsh-adapter/host-access.d.ts +4 -0
- package/lib/types/dsh-adapter/host-access.d.ts.map +1 -1
- package/lib/types/dsh-adapter/host-access.js +54 -4
- package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
- package/lib/types/dsh-adapter/host-contract.js +2 -2
- package/lib/types/dsh-adapter/host-dsh.js +3 -3
- package/lib/types/dsh-adapter/index.d.ts.map +1 -1
- package/lib/types/dsh-adapter/index.js +8 -5
- package/lib/types/dsh-adapter/panels.d.ts +7 -1
- package/lib/types/dsh-adapter/panels.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin-declaration.d.ts +28 -0
- package/lib/types/dsh-adapter/plugin-declaration.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin-declaration.js +43 -1
- package/lib/types/dsh-adapter/plugin-install.d.ts +28 -1
- package/lib/types/dsh-adapter/plugin-install.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin-install.js +160 -13
- package/lib/types/dsh-adapter/plugin-manage.d.ts +53 -10
- package/lib/types/dsh-adapter/plugin-manage.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin-manage.js +240 -51
- package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin.js +64 -18
- package/lib/types/dsh-adapter/plugins-info.d.ts +6 -7
- package/lib/types/dsh-adapter/plugins-info.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugins-info.js +34 -21
- package/lib/types/dsh-adapter/presets.d.ts +6 -2
- package/lib/types/dsh-adapter/presets.d.ts.map +1 -1
- package/lib/types/dsh-adapter/presets.js +23 -5
- package/lib/types/dsh-adapter/process-exit.d.ts +1 -1
- package/lib/types/dsh-adapter/process-exit.js +1 -1
- package/lib/types/dsh-adapter/providerWizard.d.ts +2 -0
- package/lib/types/dsh-adapter/providerWizard.d.ts.map +1 -1
- package/lib/types/dsh-adapter/providerWizard.js +11 -5
- package/lib/types/dsh-adapter/row-attachment.d.ts +30 -0
- package/lib/types/dsh-adapter/row-attachment.d.ts.map +1 -0
- package/lib/types/dsh-adapter/row-attachment.js +29 -0
- package/lib/types/dsh-adapter/worktree-tool.d.ts +27 -0
- package/lib/types/dsh-adapter/worktree-tool.d.ts.map +1 -0
- package/lib/types/dsh-adapter/worktree-tool.js +87 -0
- package/lib/types/heldInputs.d.ts +36 -0
- package/lib/types/heldInputs.d.ts.map +1 -0
- package/lib/types/heldInputs.js +173 -0
- package/lib/types/i18n.d.ts +352 -25
- package/lib/types/i18n.d.ts.map +1 -1
- package/lib/types/i18n.js +171 -18
- package/lib/types/onboardingDraft.d.ts +143 -0
- package/lib/types/onboardingDraft.d.ts.map +1 -0
- package/lib/types/onboardingDraft.js +71 -0
- package/lib/types/screens/Chat.d.ts.map +1 -1
- package/lib/types/screens/Chat.js +90 -30
- package/lib/types/screens/Onboarding.d.ts +22 -3
- package/lib/types/screens/Onboarding.d.ts.map +1 -1
- package/lib/types/screens/Onboarding.js +606 -36
- package/lib/types/settings/definitions.js +2 -2
- package/lib/types/utils/paths.d.ts +15 -0
- package/lib/types/utils/paths.d.ts.map +1 -1
- package/lib/types/utils/paths.js +25 -0
- package/package.json +111 -108
- package/tui-profile/feed/README.md +1 -1
- package/tui-profile/feed/first-party.json +1 -1
|
@@ -15,6 +15,8 @@ import { t, getLang, LANGS } from '../i18n.js';
|
|
|
15
15
|
import { isPlainReturn } from '../utils/modifiers.js';
|
|
16
16
|
import { LoadingState } from '../components/design-system/LoadingState.js';
|
|
17
17
|
import { ONBOARDING_STEPS, STEP_BAR_MIN_COLUMNS, STEP_BAR_MIN_ROWS, TUTORIAL_CARDS, connFailText, credentialSourceText, formatBalance, modelGroupsOf, stepDescKey, stepTitleKey, } from '../components/onboardingModel.js';
|
|
18
|
+
import { addedProviderOrder, modelRefKey, modelRefsOf, planModelAdoption, } from '../components/onboardingProviderPlan.js';
|
|
19
|
+
import { clearOnboardingDraft, nextOnboardingActionId, readOnboardingDraft, subscribeOnboardingDraft, writeOnboardingDraft, } from '../onboardingDraft.js';
|
|
18
20
|
/**
|
|
19
21
|
* 打断类键位卡上显示的键。
|
|
20
22
|
*
|
|
@@ -31,6 +33,42 @@ function modelRowCount(models, group, providers) {
|
|
|
31
33
|
return modelGroupsOf(listed, providers).length;
|
|
32
34
|
return listed.filter(model => model.provider === group).length;
|
|
33
35
|
}
|
|
36
|
+
/** 登录状态的一句话(复用 /login 的四条既有文案,不另造一套词)。 */
|
|
37
|
+
function oauthStateText(row) {
|
|
38
|
+
if (row.signedIn) {
|
|
39
|
+
return row.expiresAt === undefined
|
|
40
|
+
? t('login-oauth-in-no-expiry')
|
|
41
|
+
: t('login-oauth-in', { time: new Date(row.expiresAt).toISOString() });
|
|
42
|
+
}
|
|
43
|
+
return row.expired ? t('login-oauth-expired') : t('login-oauth-signed-out');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 底部提示行:子层有子层自己的键位(选账号 / 选默认 / 返回),别拿骨架那句
|
|
47
|
+
* "←/→ 换步骤"去糊弄一个正在子层里的人。
|
|
48
|
+
*/
|
|
49
|
+
function hintKeyFor(step, phase, onLast) {
|
|
50
|
+
if (step === 'access' && phase === 'signin')
|
|
51
|
+
return 'onboarding-access-signin-hint';
|
|
52
|
+
if (step === 'access' && phase === 'adopt')
|
|
53
|
+
return 'onboarding-access-adopt-hint';
|
|
54
|
+
return onLast ? 'onboarding-hint-last' : 'onboarding-hint';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* `/provider` 配好、key 也真的在的路由 id。`DEEPSEEK_API_KEY` 那一条跳过:它由
|
|
58
|
+
* 第一步自己的凭证行报。只问"有没有"(`describeCredential` 不含秘密),不读值。
|
|
59
|
+
*/
|
|
60
|
+
async function configuredKeyRoutes(channel) {
|
|
61
|
+
let configured;
|
|
62
|
+
try {
|
|
63
|
+
configured = channel.providerSetup?.()?.listConfiguredProviders() ?? [];
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const candidates = configured.filter(row => row.ref !== '' && row.ref !== 'DEEPSEEK_API_KEY');
|
|
69
|
+
const present = await Promise.all(candidates.map(row => channel.describeCredential(row.ref).then(status => status?.configured === true).catch(() => false)));
|
|
70
|
+
return candidates.filter((_, index) => present[index]).map(row => row.route);
|
|
71
|
+
}
|
|
34
72
|
/**
|
|
35
73
|
* Onboarding —— 首次运行的引导向导(`~/.dsh-tui/onboarding.json` 走一次性记账)。
|
|
36
74
|
*
|
|
@@ -44,17 +82,123 @@ function modelRowCount(models, group, providers) {
|
|
|
44
82
|
*
|
|
45
83
|
* **凭证永远只报"有没有",不报值**:`describeCredential` 回的是不含秘密的
|
|
46
84
|
* 元数据,界面上也照它的原样画。
|
|
85
|
+
*
|
|
86
|
+
* 第一步(账号与模型接入)会把**动作**交给 Chat 执行:订阅登录与 `/provider`
|
|
87
|
+
* 的 key 流程都要用共享问答面板(设备码、授权 URL、密钥输入),而那套面板
|
|
88
|
+
* 归 Chat 的 `questionStore`。面板挂起时本屏会被卸载、回答后重挂,所以进度
|
|
89
|
+
* 落在 `src/onboardingDraft.ts`(模块级,不是 React state)——挂载时读回,
|
|
90
|
+
* 动作回来时按"动作前的目录基线"做差分:订阅登录按 0/1/N 决定是否问默认模型,
|
|
91
|
+
* 加 key 只报结果(向导已经问过)。
|
|
47
92
|
*/
|
|
48
|
-
export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyLang,
|
|
93
|
+
export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyLang, onProviderSignIn, onProviderAddProvider, initialStep, externalNotice, }) {
|
|
49
94
|
const { columns, rows } = useTerminalSize();
|
|
50
|
-
|
|
95
|
+
// 面板接管会把这一屏卸载再重挂:step/focus 先看 draft,只有显式传了
|
|
96
|
+
// `initialStep`(测试缝)才由参数决定。
|
|
97
|
+
const [restored] = React.useState(() => readOnboardingDraft());
|
|
98
|
+
const [stepIndex, setStepIndex] = React.useState(() => {
|
|
99
|
+
const seed = initialStep ?? restored?.step ?? 0;
|
|
100
|
+
return Math.max(0, Math.min(seed, ONBOARDING_STEPS.length - 1));
|
|
101
|
+
});
|
|
51
102
|
const step = ONBOARDING_STEPS[stepIndex];
|
|
52
|
-
const [focusIndex, setFocusIndex] = React.useState(0);
|
|
53
|
-
|
|
54
|
-
|
|
103
|
+
const [focusIndex, setFocusIndex] = React.useState(initialStep === undefined ? restored?.focus ?? 0 : 0);
|
|
104
|
+
// 提示行带语气:失败 / 取消不能用成功色画(重挂后从 draft 读回也一样)。
|
|
105
|
+
const [notice, setNoticeState] = React.useState(externalNotice === undefined
|
|
106
|
+
? (initialStep === undefined ? restored?.notice : undefined)
|
|
107
|
+
: { text: externalNotice, tone: 'success' });
|
|
108
|
+
const setNotice = React.useCallback((text, tone = 'success') => {
|
|
109
|
+
const next = text === undefined ? undefined : { text, tone };
|
|
110
|
+
setNoticeState(next);
|
|
111
|
+
return next;
|
|
112
|
+
}, []);
|
|
113
|
+
const aliveRef = React.useRef(true);
|
|
114
|
+
/**
|
|
115
|
+
* 当前在跑的那一单接入动作的归属 id。
|
|
116
|
+
*
|
|
117
|
+
* 异步准备(读目录)先于 draft 落盘:这段窗口里用户可能关屏、本屏被卸载,
|
|
118
|
+
* 也可能又发起一单。归属登记在 `runProviderAction` 的 await 之前,`finish()`、
|
|
119
|
+
* 卸载、发起新一单都会作废它;目录回来先验归属,作废了就不许写 draft、也不许
|
|
120
|
+
* `start()`——否则迟到的回调会把已清空的 draft 复活,并替一个已经离开的用户
|
|
121
|
+
* 跑完登录。
|
|
122
|
+
*/
|
|
123
|
+
const actionOwnerRef = React.useRef(undefined);
|
|
124
|
+
React.useEffect(() => () => {
|
|
125
|
+
aliveRef.current = false;
|
|
126
|
+
actionOwnerRef.current = undefined;
|
|
127
|
+
}, []);
|
|
128
|
+
// ── 第一步:凭证 + 连通性 + 账号/模型接入 ────────────────────────────
|
|
55
129
|
const [credential, setCredential] = React.useState(undefined);
|
|
56
130
|
const [conn, setConn] = React.useState({ kind: 'idle' });
|
|
57
131
|
const [checkNonce, setCheckNonce] = React.useState(0);
|
|
132
|
+
/** dsh-auth 的登录状态;`undefined` = 本组合没挂这个插件。 */
|
|
133
|
+
const [oauth, setOauth] = React.useState(undefined);
|
|
134
|
+
/** 打开选账号层时重读登录状态的阀门(不连带重跑余额检查)。 */
|
|
135
|
+
const [oauthNonce, setOauthNonce] = React.useState(0);
|
|
136
|
+
/**
|
|
137
|
+
* 用 `/provider` 配好、key 也在的路由(不含 `DEEPSEEK_API_KEY` 那一条)。
|
|
138
|
+
* 第一步的余额检查只认 DeepSeek 官方 key:有了这些路由,缺 DeepSeek key
|
|
139
|
+
* 就不再是"没有可用的凭证"。
|
|
140
|
+
*/
|
|
141
|
+
const [keyRoutes, setKeyRoutes] = React.useState([]);
|
|
142
|
+
const [accessPhase, setAccessPhase] = React.useState('actions');
|
|
143
|
+
const [signinIndex, setSigninIndex] = React.useState(0);
|
|
144
|
+
const [adopt, setAdopt] = React.useState(undefined);
|
|
145
|
+
/**
|
|
146
|
+
* 有一单接入动作在跑(draft 里有 `pending`)。问答面板会在两次提问之间关掉、
|
|
147
|
+
* 本屏重挂回动作列表;这时登录 / 加 key 两行再发起一单,会和在跑的那一单
|
|
148
|
+
* 并发提问、并发写盘,还会顶掉它的 `pending`,让它的结果无处结算。所以在跑
|
|
149
|
+
* 期间这两行不接 Enter / 点击,并说一句"配置进行中"。
|
|
150
|
+
*/
|
|
151
|
+
const [inFlight, setInFlight] = React.useState(() => readOnboardingDraft()?.pending !== undefined);
|
|
152
|
+
/** 目录刷新阀门:接入成功后让第三步重读模型/提供方。 */
|
|
153
|
+
const [catalogNonce, setCatalogNonce] = React.useState(0);
|
|
154
|
+
/**
|
|
155
|
+
* 第一步的动作清单在挂载后**会长出来**(`oauthProviderStatuses` / `providerSetup`
|
|
156
|
+
* 是异步/懒解析的):前几帧可能只有"重新检查 / 跳过",之后"登录订阅账号 / 添加
|
|
157
|
+
* 模型提供方"插到最前面。焦点因此按**动作 id**记,不按下标——否则用户的焦点
|
|
158
|
+
* 会在清单变长的瞬间从"重新检查"静默变成"登录",一次回车就点错东西。
|
|
159
|
+
*/
|
|
160
|
+
// 每次渲染现读:channel 对象本身不换,按它 memo 会把"挂载时还没解析出来"的
|
|
161
|
+
// 结果冻结在整个引导期间。
|
|
162
|
+
const setupHost = channel.providerSetup?.();
|
|
163
|
+
// 登录行的可见性与执行走**同一个**接缝:Chat 的 `onboardingSignIn` 取的是
|
|
164
|
+
// `providerSetup()?.oauth`,而 `oauthProviderStatuses()` 只要求 dsh-auth——
|
|
165
|
+
// 只看后者,"有 dsh-auth、没有 /provider 宿主服务"的组合会画出一行点了就报未挂载的死入口。
|
|
166
|
+
const oauthMounted = setupHost?.oauth !== undefined;
|
|
167
|
+
const canSignIn = onProviderSignIn !== undefined && oauthMounted && (oauth?.length ?? 0) > 0;
|
|
168
|
+
const canConfigure = onProviderAddProvider !== undefined && setupHost !== undefined;
|
|
169
|
+
const accessActionIds = React.useMemo(() => [
|
|
170
|
+
...(canSignIn ? ['signin'] : []),
|
|
171
|
+
...(canConfigure ? ['add'] : []),
|
|
172
|
+
'recheck',
|
|
173
|
+
'next',
|
|
174
|
+
], [canConfigure, canSignIn]);
|
|
175
|
+
const [accessFocusId, setAccessFocusId] = React.useState(() => {
|
|
176
|
+
// 焦点按**动作 id**恢复,不按下标:清单是异步长出来的(先有"重新检查/跳过",
|
|
177
|
+
// 几帧后才长出"登录/加 key"),下标在清单变长后会指向另一个动作。
|
|
178
|
+
// id 暂时不在清单里也没关系——`accessIndex` 会先落在第 0 行,等清单长出来
|
|
179
|
+
// 再回到同一个动作上。
|
|
180
|
+
const seed = restored?.focusId;
|
|
181
|
+
return seed === 'signin' || seed === 'add' || seed === 'recheck' || seed === 'next'
|
|
182
|
+
? seed
|
|
183
|
+
: undefined;
|
|
184
|
+
});
|
|
185
|
+
const accessIndex = accessFocusId === undefined
|
|
186
|
+
? 0
|
|
187
|
+
: Math.max(0, accessActionIds.indexOf(accessFocusId));
|
|
188
|
+
/**
|
|
189
|
+
* DeepSeek 官方 key 之外已经能用的接入:已登录的订阅账号 + 配好 key 的路由。
|
|
190
|
+
* 第一步的凭证行与余额检查都只针对 DeepSeek 官方 API,有这些接入时它们只是
|
|
191
|
+
* 一条中性说明,不是失败。
|
|
192
|
+
*/
|
|
193
|
+
const otherAccess = React.useMemo(() => [
|
|
194
|
+
...(oauth ?? []).filter(row => row.signedIn).map(row => row.provider),
|
|
195
|
+
...keyRoutes,
|
|
196
|
+
].filter((id, index, all) => all.indexOf(id) === index), [keyRoutes, oauth]);
|
|
197
|
+
/**
|
|
198
|
+
* 已经有能用的东西了吗(DeepSeek 凭证已配置,或有别的接入)?有就不再往屏幕上
|
|
199
|
+
* 堆"手工设置"的兜底文案——那是"这台机器现在什么都没有"时才需要的出路。
|
|
200
|
+
*/
|
|
201
|
+
const accessReady = credential?.configured === true || otherAccess.length > 0;
|
|
58
202
|
React.useEffect(() => {
|
|
59
203
|
let alive = true;
|
|
60
204
|
setCredential(undefined);
|
|
@@ -64,12 +208,14 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
64
208
|
if (!alive)
|
|
65
209
|
return;
|
|
66
210
|
setCredential(status);
|
|
67
|
-
const [models, balance] = await Promise.all([
|
|
211
|
+
const [models, balance, routes] = await Promise.all([
|
|
68
212
|
channel.listModels().catch(() => []),
|
|
69
213
|
channel.balanceInfo().catch(() => ({ ok: false, reason: 'network' })),
|
|
214
|
+
configuredKeyRoutes(channel),
|
|
70
215
|
]);
|
|
71
216
|
if (!alive)
|
|
72
217
|
return;
|
|
218
|
+
setKeyRoutes(routes);
|
|
73
219
|
// 连通性的判定口径:余额接口是唯一一次真的打服务端的调用,所以以它
|
|
74
220
|
// 为准;模型列表只用来给成功态添一个数字(某些 provider 会走缓存)。
|
|
75
221
|
setConn(balance.ok
|
|
@@ -84,6 +230,19 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
84
230
|
alive = false;
|
|
85
231
|
};
|
|
86
232
|
}, [channel, checkNonce]);
|
|
233
|
+
// 登录状态单独读:重新检查、打开选账号层都会重读;`oauthMounted` 也在依赖里——
|
|
234
|
+
// dsh-auth 晚于首帧组合进来时,登录行不必等用户点"重新检查"才出现。
|
|
235
|
+
React.useEffect(() => {
|
|
236
|
+
let alive = true;
|
|
237
|
+
void (channel.oauthProviderStatuses?.().catch(() => undefined) ?? Promise.resolve(undefined))
|
|
238
|
+
.then((rows) => {
|
|
239
|
+
if (alive)
|
|
240
|
+
setOauth(rows);
|
|
241
|
+
});
|
|
242
|
+
return () => {
|
|
243
|
+
alive = false;
|
|
244
|
+
};
|
|
245
|
+
}, [channel, checkNonce, oauthMounted, oauthNonce]);
|
|
87
246
|
// ── 第二步:语言 + 主题 ──────────────────────────────────────────────
|
|
88
247
|
const [themeName, setTheme] = useTheme();
|
|
89
248
|
const [lookPane, setLookPane] = React.useState('lang');
|
|
@@ -122,10 +281,16 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
122
281
|
return () => {
|
|
123
282
|
alive = false;
|
|
124
283
|
};
|
|
125
|
-
}, [channel]);
|
|
284
|
+
}, [channel, catalogNonce]);
|
|
126
285
|
// ── 第四步:招式卡 ──────────────────────────────────────────────────
|
|
127
286
|
const [tried, setTried] = React.useState(() => new Set());
|
|
128
287
|
const finish = React.useCallback((outcome) => {
|
|
288
|
+
// 关屏即作废在跑的那一单:目录读取可能还在路上,它的迟到回调不许复活
|
|
289
|
+
// draft、也不许再 `start()`。
|
|
290
|
+
actionOwnerRef.current = undefined;
|
|
291
|
+
// 两条出口都收掉进度:跳过的下一次启动还要从第一步重问,完成的更不该
|
|
292
|
+
// 留着旧的 draft 去影响 `/setup`。
|
|
293
|
+
clearOnboardingDraft();
|
|
129
294
|
onClose(outcome);
|
|
130
295
|
}, [onClose]);
|
|
131
296
|
const goToStep = React.useCallback((next) => {
|
|
@@ -168,14 +333,284 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
168
333
|
setTried(previous => new Set(previous).add(card.id));
|
|
169
334
|
onRunCommand(card.command);
|
|
170
335
|
}, [onRunCommand]);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
336
|
+
// ── 第一步的接入动作(订阅登录 / API key / 接入模型)──────────────────
|
|
337
|
+
/** provider 显示名:注册表 → 登录状态 → 原始 id。 */
|
|
338
|
+
const providerLabel = React.useCallback((id) => {
|
|
339
|
+
if (id === undefined)
|
|
340
|
+
return '';
|
|
341
|
+
return providers.find(entry => entry.id === id)?.name
|
|
342
|
+
?? oauth?.find(row => row.provider === id)?.label
|
|
343
|
+
?? id;
|
|
344
|
+
}, [oauth, providers]);
|
|
345
|
+
/**
|
|
346
|
+
* 动作行的文案(登录行带上"已登录几 / 共几"的实况)。清单本身(`accessActionIds`)
|
|
347
|
+
* 与"能不能用"(`accessReady`)在第一步的状态区上方算,那里要先于焦点状态。
|
|
348
|
+
*/
|
|
349
|
+
const accessRows = React.useMemo(() => {
|
|
350
|
+
const total = oauth?.length ?? 0;
|
|
351
|
+
const signedIn = (oauth ?? []).filter(row => row.signedIn).length;
|
|
352
|
+
const describe = (id) => {
|
|
353
|
+
switch (id) {
|
|
354
|
+
case 'signin':
|
|
355
|
+
return {
|
|
356
|
+
label: t('onboarding-access-action-signin'),
|
|
357
|
+
desc: inFlight
|
|
358
|
+
? t('onboarding-access-action-busy-desc')
|
|
359
|
+
: t('onboarding-access-action-signin-desc', { signed: signedIn, total }),
|
|
360
|
+
};
|
|
361
|
+
case 'add':
|
|
362
|
+
return {
|
|
363
|
+
label: t('onboarding-access-action-add'),
|
|
364
|
+
desc: inFlight ? t('onboarding-access-action-busy-desc') : t('onboarding-access-action-add-desc'),
|
|
365
|
+
};
|
|
366
|
+
case 'recheck':
|
|
367
|
+
return {
|
|
368
|
+
label: t('onboarding-access-action-recheck'),
|
|
369
|
+
desc: t('onboarding-access-action-recheck-desc'),
|
|
370
|
+
};
|
|
371
|
+
case 'next':
|
|
372
|
+
return {
|
|
373
|
+
label: t('onboarding-access-action-next'),
|
|
374
|
+
desc: t('onboarding-access-action-next-desc'),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
return accessActionIds.map(id => ({ id, ...describe(id) }));
|
|
379
|
+
}, [accessActionIds, inFlight, oauth]);
|
|
380
|
+
/**
|
|
381
|
+
* 动作结束之后的唯一收口:读回动作前的目录基线 → 差分 → 0/1/N 决策(加 key 只报结果)。
|
|
382
|
+
* 前提是 draft 里已经有 `completed`(动作真的跑完了),并且本实例还在挂;
|
|
383
|
+
* `pending`/`completed` 同时清空,保证重挂、订阅回调、Promise 回调三条路
|
|
384
|
+
* 径加起来只结算一次。
|
|
385
|
+
*/
|
|
386
|
+
const settlePendingAction = React.useCallback(async () => {
|
|
387
|
+
const draft = readOnboardingDraft();
|
|
388
|
+
const completion = draft?.completed;
|
|
389
|
+
// **动作跑完之前不结算**:问答面板可以在两次提问之间关闭(模型探测、profile
|
|
390
|
+
// 写入都在提问之间),那时本屏会被重挂,而目录还没变——早结算就会读到旧
|
|
391
|
+
// 目录、把结果丢掉。`completed` 由跑动作的那个实例在结束时写入(它同时把
|
|
392
|
+
// `pending` 清掉,所以这里只认 `completed`)。
|
|
393
|
+
if (draft === undefined || completion === undefined)
|
|
394
|
+
return;
|
|
395
|
+
// 已经卸载的实例不许把这一单"吃掉":面板挂起时本屏被卸载,重挂(或在挂)
|
|
396
|
+
// 的那个实例才是该结算的人。这里先退出去,把 draft 原样留给它。
|
|
397
|
+
if (!aliveRef.current)
|
|
398
|
+
return;
|
|
399
|
+
writeOnboardingDraft({ pending: undefined, completed: undefined });
|
|
400
|
+
// 取消/失败没有目录变化。具体原因只在流程自己的通知里,而整屏盖着时外面的
|
|
401
|
+
// 通知条看不见,所以跑动作的实例把那一句带进了 completion,这里接着显示。
|
|
402
|
+
if (completion.status === 'cancelled' || completion.status === 'failed') {
|
|
403
|
+
const text = completion.status === 'cancelled'
|
|
404
|
+
? t('onboarding-access-cancelled')
|
|
405
|
+
: completion.notice === undefined
|
|
406
|
+
? t('onboarding-access-action-failed')
|
|
407
|
+
: t('onboarding-access-action-failed-reason', { reason: completion.notice });
|
|
408
|
+
setAccessPhase('actions');
|
|
409
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(text, completion.status === 'cancelled' ? 'warning' : 'error') });
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const models = await channel.listModels().catch(() => []);
|
|
413
|
+
if (!aliveRef.current)
|
|
414
|
+
return;
|
|
415
|
+
setCatalogNonce(nonce => nonce + 1);
|
|
416
|
+
// 登录状态也可能刚变了:重跑一次状态读取(凭证 + 已登录账号 + 连通性)。
|
|
417
|
+
setCheckNonce(nonce => nonce + 1);
|
|
418
|
+
const plan = planModelAdoption({
|
|
419
|
+
baseline: draft.baseline,
|
|
420
|
+
current: modelRefsOf(models),
|
|
421
|
+
...(completion.kind === 'sign-in' && completion.provider !== undefined ? { provider: completion.provider } : {}),
|
|
422
|
+
...(channel.provider !== undefined && channel.model !== undefined
|
|
423
|
+
? { currentRoute: { provider: channel.provider, id: channel.model } }
|
|
424
|
+
: {}),
|
|
425
|
+
});
|
|
426
|
+
const label = providerLabel(plan.provider ?? (completion.kind === 'sign-in' ? completion.provider : undefined));
|
|
427
|
+
// 登出、改路由、删路由本来就不为新增:报流程自己的那一句(已登出 / 已删除…),
|
|
428
|
+
// 不拿"没有新增模型"去描述它。目录与状态在上面已经重读。
|
|
429
|
+
if (completion.status === 'changed' && plan.added.length === 0) {
|
|
430
|
+
const text = completion.notice ?? t('onboarding-access-changed');
|
|
431
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(text) });
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (plan.decision === 'none') {
|
|
435
|
+
const text = label === ''
|
|
436
|
+
? t('onboarding-access-added-none')
|
|
437
|
+
: t('onboarding-access-added-none-for', { provider: label });
|
|
438
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(text, 'warning') });
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (completion.kind === 'add-provider') {
|
|
442
|
+
// 加 key 跑的是 `/provider` 向导:启用哪些模型(模型多选)、要不要切过去
|
|
443
|
+
// (provider-q-switch),向导自己已经问过并落了盘。这里只报结果——再走
|
|
444
|
+
// auto / 接入层,会推翻用户在向导里选的「保持当前模型」,还把同一批模型再问一遍。
|
|
445
|
+
const live = models.find(model => model.provider === channel.provider && model.id === channel.model);
|
|
446
|
+
const text = t('onboarding-access-added-provider', {
|
|
447
|
+
provider: label,
|
|
448
|
+
n: plan.added.length,
|
|
449
|
+
model: live?.name ?? channel.model,
|
|
450
|
+
});
|
|
451
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(text) });
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (plan.decision === 'auto') {
|
|
455
|
+
const pick = plan.added[0];
|
|
456
|
+
const ok = await channel.switchModel(pick.provider, pick.id).catch(() => false);
|
|
457
|
+
if (!aliveRef.current)
|
|
458
|
+
return;
|
|
459
|
+
const text = ok
|
|
460
|
+
? t('onboarding-access-added-auto', { name: pick.name, provider: providerLabel(pick.provider) })
|
|
461
|
+
: t('onboarding-model-switch-failed', { name: pick.name });
|
|
462
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(text, ok ? 'success' : 'error') });
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
// 焦点先落在预选上(当前路由在新增里就是它,否则第一个新增模型)。
|
|
466
|
+
const preferred = plan.defaultPick === undefined
|
|
467
|
+
? 0
|
|
468
|
+
: Math.max(0, plan.added.findIndex(row => modelRefKey(row) === modelRefKey(plan.defaultPick)));
|
|
469
|
+
setAdopt({ plan, index: preferred });
|
|
470
|
+
setAccessPhase('adopt');
|
|
471
|
+
}, [channel, providerLabel, setNotice]);
|
|
472
|
+
/**
|
|
473
|
+
* 跑一个接入动作:**先**把基线 + 意图写进 draft,再交给 Chat 的面板。
|
|
474
|
+
* 顺序是关键——面板一挂起这一屏就卸载了,晚写的上下文没人接得住。
|
|
475
|
+
* 读目录(`channel.listModels()`)是这段窗口里最慢的一步,所以归属在 await
|
|
476
|
+
* 之前登记,目录回来先验归属:晚了就会先复活 draft、再替已经离开的用户跑登录。
|
|
477
|
+
*/
|
|
478
|
+
const runProviderAction = React.useCallback(async (intent, start,
|
|
479
|
+
/** 发起这一单的动作 id:重挂后按它把焦点放回同一行(不是按当时的行号)。 */
|
|
480
|
+
focusId) => {
|
|
481
|
+
// 一次只跑一单(见 `inFlight`)。这里现读 draft 再拦一次:同一帧里连按两下时,
|
|
482
|
+
// 第二下赶在重画之前,`inFlight` 还是旧值。
|
|
483
|
+
if (readOnboardingDraft()?.pending !== undefined)
|
|
484
|
+
return;
|
|
485
|
+
// 每单一个 id:引导关掉再开、又发起新动作时,上一单迟到的回调不能把
|
|
486
|
+
// 新一单的 `pending` 覆盖成它自己的完成态。
|
|
487
|
+
const pending = { ...intent, id: nextOnboardingActionId() };
|
|
488
|
+
// 归属先立、异步准备后行:读目录可能很慢,这段窗口里关屏/卸载/新一单都会
|
|
489
|
+
// 作废这一单(见 `actionOwnerRef`)。校验点放在目录返回处,而不是等登录
|
|
490
|
+
// 结束——晚一步就会先复活 draft、再替已经离开的用户跑一次 `start()`。
|
|
491
|
+
actionOwnerRef.current = pending.id;
|
|
492
|
+
const baseline = modelRefsOf(await channel.listModels().catch(() => []));
|
|
493
|
+
if (!aliveRef.current || actionOwnerRef.current !== pending.id)
|
|
494
|
+
return;
|
|
495
|
+
// 动作前的上下文先落盘:面板一挂起这一屏就卸载了,晚写的没人接得住。
|
|
496
|
+
// `pending` 会一直留到动作结束——中途的重挂靠它知道"还有一单在跑"。
|
|
497
|
+
writeOnboardingDraft({
|
|
498
|
+
step: stepIndex,
|
|
499
|
+
focus: accessIndex,
|
|
500
|
+
focusId,
|
|
501
|
+
baseline,
|
|
502
|
+
pending,
|
|
503
|
+
completed: undefined,
|
|
504
|
+
notice: undefined,
|
|
505
|
+
});
|
|
506
|
+
// 流程的反馈(失败原因、登出/删除的结果)只走通知条:记下开跑前最后一条的
|
|
507
|
+
// id,结束后取它之后最新的那一条带进 completion。
|
|
508
|
+
const noticeMark = channel.notifications.at(-1)?.id;
|
|
509
|
+
const outcome = await start().catch(() => 'failed');
|
|
510
|
+
const status = outcome === 'cancelled' || outcome === 'failed' || outcome === 'added' ? outcome : 'changed';
|
|
511
|
+
const latest = channel.notifications.at(-1);
|
|
512
|
+
const notice = latest !== undefined && (noticeMark === undefined || latest.id > noticeMark) ? latest.text : undefined;
|
|
513
|
+
// 只有"桌上还是我这一单"才写完成态:引导已经被关掉(draft 清空),或者
|
|
514
|
+
// 用户又发起了一单(pending.id 变了)时,这一单的结果没有归属,丢掉。
|
|
515
|
+
if (readOnboardingDraft()?.pending?.id === pending.id) {
|
|
516
|
+
writeOnboardingDraft({ completed: { ...pending, status, notice }, pending: undefined });
|
|
517
|
+
}
|
|
518
|
+
// 在挂的实例(可能是重挂出来的那一个)在这里结算;这里的实例已经卸载时,
|
|
519
|
+
// settle 会早退,由订阅到 completed 的在挂实例接手。
|
|
520
|
+
await settlePendingAction();
|
|
521
|
+
}, [accessIndex, channel, settlePendingAction, stepIndex]);
|
|
522
|
+
/** 打开选账号层,顺手重读登录状态(账号可能在引导外刚登录/登出过)。 */
|
|
523
|
+
const openSignIn = React.useCallback(() => {
|
|
524
|
+
setAccessPhase('signin');
|
|
525
|
+
setOauthNonce(nonce => nonce + 1);
|
|
526
|
+
}, []);
|
|
527
|
+
const startSignIn = React.useCallback((provider) => {
|
|
528
|
+
if (onProviderSignIn === undefined)
|
|
529
|
+
return;
|
|
530
|
+
setAccessPhase('actions');
|
|
531
|
+
void runProviderAction({ kind: 'sign-in', provider }, () => onProviderSignIn(provider), 'signin');
|
|
532
|
+
}, [onProviderSignIn, runProviderAction]);
|
|
533
|
+
const startAddProvider = React.useCallback(() => {
|
|
534
|
+
if (onProviderAddProvider === undefined)
|
|
535
|
+
return;
|
|
536
|
+
void runProviderAction({ kind: 'add-provider' }, onProviderAddProvider, 'add');
|
|
537
|
+
}, [onProviderAddProvider, runProviderAction]);
|
|
538
|
+
/** 动作行的落点(键盘 Enter 与鼠标点击共用)。在跑期间登录 / 加 key 不接。 */
|
|
539
|
+
const runAccessAction = (id) => {
|
|
540
|
+
if (id === 'signin') {
|
|
541
|
+
if (!inFlight)
|
|
542
|
+
openSignIn();
|
|
543
|
+
}
|
|
544
|
+
else if (id === 'add') {
|
|
545
|
+
if (!inFlight)
|
|
546
|
+
startAddProvider();
|
|
547
|
+
}
|
|
548
|
+
else if (id === 'recheck')
|
|
549
|
+
setCheckNonce(nonce => nonce + 1);
|
|
550
|
+
else
|
|
551
|
+
advance();
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* 选默认层的落点:`pick` 落成默认模型(`switchModel` 与第三步同一条路,写
|
|
555
|
+
* model.json);`undefined` = 保持当前模型。两条路都不撤回已经登录的东西——
|
|
556
|
+
* 新模型本来就都可用了,这里只决定默认。
|
|
557
|
+
*/
|
|
558
|
+
const applyAdoption = React.useCallback((pick) => {
|
|
559
|
+
if (pick === undefined) {
|
|
560
|
+
setAdopt(undefined);
|
|
561
|
+
setAccessPhase('actions');
|
|
562
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(t('onboarding-access-adopt-cancelled')) });
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
void channel.switchModel(pick.provider, pick.id).then((ok) => {
|
|
566
|
+
const text = ok
|
|
567
|
+
? t('onboarding-access-added-auto', { name: pick.name, provider: providerLabel(pick.provider) })
|
|
568
|
+
: t('onboarding-model-switch-failed', { name: pick.name });
|
|
569
|
+
// 落地判断先看还在不在:用户可能在 `switchModel` 解析前就退出了引导,
|
|
570
|
+
// 那时既不该改状态,也不该给下一次 `/setup` 留一条过期提示。
|
|
571
|
+
if (!aliveRef.current)
|
|
572
|
+
return;
|
|
573
|
+
writeOnboardingDraft({ baseline: [], notice: setNotice(text, ok ? 'success' : 'error') });
|
|
574
|
+
setCheckNonce(nonce => nonce + 1);
|
|
575
|
+
}).catch(() => undefined).finally(() => {
|
|
576
|
+
if (!aliveRef.current)
|
|
577
|
+
return;
|
|
578
|
+
setAdopt(undefined);
|
|
579
|
+
setAccessPhase('actions');
|
|
580
|
+
});
|
|
581
|
+
}, [channel, providerLabel, setNotice]);
|
|
582
|
+
/**
|
|
583
|
+
* 结算入口。三种时序都要覆盖:
|
|
584
|
+
* 1. 挂载时动作已经结束(面板在结束前关掉、或上一次挂载已卸载)→ 立刻结算;
|
|
585
|
+
* 2. 动作还在跑(只有 pending)→ 什么都不做,等 completed;
|
|
586
|
+
* 3. 动作在本实例在挂期间结束 → 订阅回调里结算。
|
|
587
|
+
*/
|
|
588
|
+
React.useEffect(() => {
|
|
589
|
+
const settleIfReady = () => {
|
|
590
|
+
const draft = readOnboardingDraft();
|
|
591
|
+
// "在跑"跟着 draft 走:开跑时写入 `pending`、结束时清掉,重挂的实例也看得到。
|
|
592
|
+
setInFlight(draft?.pending !== undefined);
|
|
593
|
+
if (draft?.completed === undefined)
|
|
594
|
+
return;
|
|
595
|
+
setAccessPhase('actions');
|
|
596
|
+
void settlePendingAction();
|
|
597
|
+
};
|
|
598
|
+
settleIfReady();
|
|
599
|
+
return subscribeOnboardingDraft(settleIfReady);
|
|
600
|
+
}, [settlePendingAction]);
|
|
601
|
+
// 进度(步骤 / 焦点)随变随存,卸载-重挂后从 draft 读回。
|
|
602
|
+
React.useEffect(() => {
|
|
603
|
+
writeOnboardingDraft({ step: stepIndex, focus: focusIndex, focusId: accessFocusId });
|
|
604
|
+
}, [accessFocusId, focusIndex, stepIndex]);
|
|
605
|
+
/**
|
|
606
|
+
* 第三步模型区的行数(分组层 = provider 数;列表层 = 该 provider 的模型数)。
|
|
607
|
+
* 第一步的动作列表与选默认层各有自己的行数(`accessActionIds` / `adopt.plan.added`),不走这里。
|
|
608
|
+
*/
|
|
609
|
+
const rowCount = step === 'look'
|
|
610
|
+
? (lookPane === 'lang' ? LANGS.length : themeOptions.length)
|
|
611
|
+
: step === 'model'
|
|
612
|
+
? (zone === 'model' ? modelRowCount(models, modelGroup, providers) : zone === 'effort' ? efforts.length : 1)
|
|
613
|
+
: TUTORIAL_CARDS.length;
|
|
179
614
|
useInput((input, key, event) => {
|
|
180
615
|
// 工作区选择是引导内部的模态层:开着的时候键盘全归它。
|
|
181
616
|
if (workspaceOpen) {
|
|
@@ -197,7 +632,7 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
197
632
|
setWorkspaces(null);
|
|
198
633
|
setNotice(ok
|
|
199
634
|
? t('onboarding-workspace-switched', { name: target.label })
|
|
200
|
-
: t('onboarding-workspace-failed', { name: target.label }));
|
|
635
|
+
: t('onboarding-workspace-failed', { name: target.label }), ok ? 'success' : 'error');
|
|
201
636
|
});
|
|
202
637
|
}
|
|
203
638
|
return;
|
|
@@ -207,6 +642,51 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
207
642
|
event.stopImmediatePropagation();
|
|
208
643
|
return;
|
|
209
644
|
}
|
|
645
|
+
// 第一步的接入子层(选账号 / 选默认模型):Esc 只退一层,不跳过整个引导。
|
|
646
|
+
if (step === 'access' && accessPhase !== 'actions') {
|
|
647
|
+
if (key.escape) {
|
|
648
|
+
// 退出选默认层 = 保持当前模型:已经登录/写入的东西不撤回(它们本来就生效了),
|
|
649
|
+
// 只是不再替用户选默认模型。
|
|
650
|
+
if (accessPhase === 'signin')
|
|
651
|
+
setAccessPhase('actions');
|
|
652
|
+
else
|
|
653
|
+
applyAdoption(undefined);
|
|
654
|
+
event.stopImmediatePropagation();
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
if (accessPhase === 'signin') {
|
|
658
|
+
const count = (oauth?.length ?? 0) + 1;
|
|
659
|
+
if (key.upArrow || key.downArrow) {
|
|
660
|
+
setSigninIndex(previous => Math.max(0, Math.min(previous + (key.upArrow ? -1 : 1), count - 1)));
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (isPlainReturn(key)) {
|
|
664
|
+
const row = oauth?.[signinIndex];
|
|
665
|
+
if (row === undefined)
|
|
666
|
+
setAccessPhase('actions');
|
|
667
|
+
else
|
|
668
|
+
startSignIn(row.provider);
|
|
669
|
+
event.stopImmediatePropagation();
|
|
670
|
+
}
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
// 选默认层:单选,Enter 落点;末尾一行是"保持当前模型"。
|
|
674
|
+
if (adopt === undefined)
|
|
675
|
+
return;
|
|
676
|
+
if (key.upArrow || key.downArrow) {
|
|
677
|
+
const last = adopt.plan.added.length;
|
|
678
|
+
setAdopt(previous => previous === undefined ? previous : ({
|
|
679
|
+
...previous,
|
|
680
|
+
index: Math.max(0, Math.min(previous.index + (key.upArrow ? -1 : 1), last)),
|
|
681
|
+
}));
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (isPlainReturn(key)) {
|
|
685
|
+
applyAdoption(adopt.plan.added[adopt.index]);
|
|
686
|
+
event.stopImmediatePropagation();
|
|
687
|
+
}
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
210
690
|
if (key.escape) {
|
|
211
691
|
// 模型分组钻进去之后,Esc 先退一层。这条判定必须排在"跳过整个向导"**之前**:
|
|
212
692
|
// 它原来写在 model 分支里(在全局 Esc 之后)永远轮不到,钻进去就成了单向门。
|
|
@@ -228,7 +708,9 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
228
708
|
// 注册 `useInput`,`onPick` 收的是 ClickEvent),把 ←/→ 让出去只会让它们
|
|
229
709
|
// 变成死键——而底部提示写的是「←/→ 换步骤」。
|
|
230
710
|
const horizontalOwnedByChild = (step === 'model' && zone === 'effort')
|
|
231
|
-
|| (step === 'model' && zone === 'model' && modelGroup !== undefined)
|
|
711
|
+
|| (step === 'model' && zone === 'model' && modelGroup !== undefined)
|
|
712
|
+
// 接入子层自己吃 ↑/↓/Tab/Esc;←/→ 在这里没有意义,别把层级换掉。
|
|
713
|
+
|| (step === 'access' && accessPhase !== 'actions');
|
|
232
714
|
if (!horizontalOwnedByChild && (key.leftArrow || key.rightArrow)) {
|
|
233
715
|
goToStep(stepIndex + (key.leftArrow ? -1 : 1));
|
|
234
716
|
event.stopImmediatePropagation();
|
|
@@ -321,7 +803,7 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
321
803
|
void channel.switchModel(model.provider, model.id).then((ok) => {
|
|
322
804
|
setNotice(ok
|
|
323
805
|
? t('onboarding-model-switched', { name: model.name })
|
|
324
|
-
: t('onboarding-model-switch-failed', { name: model.name }));
|
|
806
|
+
: t('onboarding-model-switch-failed', { name: model.name }), ok ? 'success' : 'error');
|
|
325
807
|
});
|
|
326
808
|
return;
|
|
327
809
|
}
|
|
@@ -346,15 +828,47 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
346
828
|
}
|
|
347
829
|
return;
|
|
348
830
|
}
|
|
349
|
-
//
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
831
|
+
// 第一步(动作列表):↑/↓ 移焦点,Enter 落在动作上。动作本身是异步的,
|
|
832
|
+
// 面板一起就把这一屏交出去(进度在 draft 里,回来接着走)。
|
|
833
|
+
if (step === 'access') {
|
|
834
|
+
if (key.upArrow || key.downArrow) {
|
|
835
|
+
const next = Math.max(0, Math.min(accessIndex + (key.upArrow ? -1 : 1), Math.max(0, accessActionIds.length - 1)));
|
|
836
|
+
const id = accessActionIds[next];
|
|
837
|
+
if (id !== undefined)
|
|
838
|
+
setAccessFocusId(id);
|
|
839
|
+
// 焦点也进 draft:面板挂起回来时停在同一行动作上。
|
|
840
|
+
setFocusIndex(next);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
if (isPlainReturn(key)) {
|
|
844
|
+
const action = accessActionIds[accessIndex];
|
|
845
|
+
if (action !== undefined)
|
|
846
|
+
runAccessAction(action);
|
|
847
|
+
event.stopImmediatePropagation();
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
353
850
|
}
|
|
354
851
|
});
|
|
355
852
|
const onLast = stepIndex >= ONBOARDING_STEPS.length - 1;
|
|
356
853
|
const showSteps = rows >= STEP_BAR_MIN_ROWS && columns >= STEP_BAR_MIN_COLUMNS;
|
|
357
|
-
return (_jsxs(Box, { flexDirection: "column", width: columns, height: rows, children: [_jsx(Box, { height: 1, flexShrink: 0, overflow: "hidden", children: _jsxs(Box, { flexGrow: 1, flexShrink: 1, overflow: "hidden", children: [_jsx(Text, { color: "remember", bold: true, children: t('onboarding-title') }), _jsx(Text, { dimColor: true, children: ' ' + t('onboarding-step-progress', { n: stepIndex + 1, total: ONBOARDING_STEPS.length }) })] }) }), _jsx(Divider, { bleed: true }), showSteps && (_jsx(Box, { flexShrink: 0, overflow: "hidden", children: ONBOARDING_STEPS.map((entry, index) => (_jsx(Box, { flexShrink: 0, children: _jsx(Text, { color: index === stepIndex ? 'suggestion' : index < stepIndex ? 'success' : undefined, dimColor: index > stepIndex, children: ' ' + (index < stepIndex ? '✓' : index === stepIndex ? '❯' : '·') + ' ' + t(stepTitleKey(entry)) }) }, entry))) })), _jsxs(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1, paddingX: 2, paddingTop: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: t(stepDescKey(step)) }) }), step === '
|
|
854
|
+
return (_jsxs(Box, { flexDirection: "column", width: columns, height: rows, children: [_jsx(Box, { height: 1, flexShrink: 0, overflow: "hidden", children: _jsxs(Box, { flexGrow: 1, flexShrink: 1, overflow: "hidden", children: [_jsx(Text, { color: "remember", bold: true, children: t('onboarding-title') }), _jsx(Text, { dimColor: true, children: ' ' + t('onboarding-step-progress', { n: stepIndex + 1, total: ONBOARDING_STEPS.length }) })] }) }), _jsx(Divider, { bleed: true }), showSteps && (_jsx(Box, { flexShrink: 0, overflow: "hidden", children: ONBOARDING_STEPS.map((entry, index) => (_jsx(Box, { flexShrink: 0, children: _jsx(Text, { color: index === stepIndex ? 'suggestion' : index < stepIndex ? 'success' : undefined, dimColor: index > stepIndex, children: ' ' + (index < stepIndex ? '✓' : index === stepIndex ? '❯' : '·') + ' ' + t(stepTitleKey(entry)) }) }, entry))) })), _jsxs(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1, paddingX: 2, paddingTop: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: t(stepDescKey(step)) }) }), step === 'access' && accessPhase === 'actions' && (_jsx(AccessStatus, { credential: credential, conn: conn, oauth: oauth, otherAccess: otherAccess, providerLabel: providerLabel })), step === 'access' && accessPhase === 'actions' && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [inFlight && (_jsx(Box, { marginBottom: 1, children: _jsx(LoadingState, { message: t('onboarding-access-in-flight'), dimColor: true }) })), accessRows.map((row, index) => (_jsxs(Box, { flexDirection: "column", onMouseEnter: () => setAccessFocusId(row.id), children: [_jsx(ListItem, { isFocused: accessIndex === index, declareCursor: false, onClick: (event) => {
|
|
855
|
+
event.stopImmediatePropagation();
|
|
856
|
+
setAccessFocusId(row.id);
|
|
857
|
+
runAccessAction(row.id);
|
|
858
|
+
}, children: row.label }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' ' + row.desc })] }, row.id))), (!canSignIn || !canConfigure) && !accessReady && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' ' + t('onboarding-access-fallback') }), !canSignIn && (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' · ' + t('onboarding-access-fallback-signin') })), !canConfigure && (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' · ' + t('onboarding-access-fallback-provider') })), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' ' + t('onboarding-access-fallback-env') }), _jsx(Text, { children: ' ' + t('onboarding-access-fallback-powershell') }), _jsx(Text, { children: ' ' + t('onboarding-access-fallback-cmd') }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' ' + t('onboarding-access-fallback-store') }), _jsx(Text, { children: ' ' + t('onboarding-access-fallback-store-path') })] }))] })), step === 'access' && accessPhase === 'signin' && (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: t('onboarding-access-signin-title') }) }), (oauth ?? []).map((row, index) => (_jsx(Box, { flexDirection: "column", onMouseEnter: () => setSigninIndex(index), children: _jsx(ListItem, { isFocused: signinIndex === index, declareCursor: false, onClick: (event) => {
|
|
859
|
+
event.stopImmediatePropagation();
|
|
860
|
+
setSigninIndex(index);
|
|
861
|
+
startSignIn(row.provider);
|
|
862
|
+
}, children: t('onboarding-access-oauth-row', { provider: row.provider, state: oauthStateText(row) }) }) }, row.provider))), _jsx(Box, { onMouseEnter: () => setSigninIndex((oauth ?? []).length), children: _jsx(ListItem, { isFocused: signinIndex === (oauth ?? []).length, declareCursor: false, onClick: (event) => {
|
|
863
|
+
event.stopImmediatePropagation();
|
|
864
|
+
setAccessPhase('actions');
|
|
865
|
+
}, children: t('onboarding-access-back') }) })] })), step === 'access' && accessPhase === 'adopt' && adopt !== undefined && (_jsx(AdoptPanel, { adopt: adopt, providerLabel: providerLabel, currentModel: (models ?? []).find(model => model.provider === channel.provider && model.id === channel.model)?.name
|
|
866
|
+
?? channel.model,
|
|
867
|
+
// 行预算 = 终端高 − 引导骨架 8 行(标题/两条 Divider/步进条/
|
|
868
|
+
// paddingTop/步骤描述+其 marginBottom/提示行)− 面板框架 5 行
|
|
869
|
+
// (marginTop/标题与说明各带 1 行 marginBottom)− 1 行余量;含末尾
|
|
870
|
+
// 3 行操作区(marginTop + "保持当前模型" + 当前模型说明),80×24 下为 10 行。
|
|
871
|
+
windowRows: Math.max(4, rows - 14), onHover: (index) => setAdopt(previous => previous === undefined ? previous : ({ ...previous, index })), onPick: applyAdoption })), step === 'look' && (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { flexDirection: "row", gap: 4, marginBottom: 1, children: [_jsx(PaneTab, { label: t('lang-picker-title'), active: lookPane === 'lang', onClick: (event) => {
|
|
358
872
|
event.stopImmediatePropagation();
|
|
359
873
|
setLookPane('lang');
|
|
360
874
|
} }), _jsx(PaneTab, { label: t('picker-title-theme'), active: lookPane === 'theme', onClick: (event) => {
|
|
@@ -378,7 +892,7 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
378
892
|
void channel.switchModel(model.provider, model.id).then((ok) => {
|
|
379
893
|
setNotice(ok
|
|
380
894
|
? t('onboarding-model-switched', { name: model.name })
|
|
381
|
-
: t('onboarding-model-switch-failed', { name: model.name }));
|
|
895
|
+
: t('onboarding-model-switch-failed', { name: model.name }), ok ? 'success' : 'error');
|
|
382
896
|
});
|
|
383
897
|
}, onEffort: (index) => {
|
|
384
898
|
setEffortIndex(index);
|
|
@@ -397,9 +911,9 @@ export function Onboarding({ channel, themeHost, onClose, onRunCommand, onApplyL
|
|
|
397
911
|
setWorkspaces(null);
|
|
398
912
|
setNotice(ok
|
|
399
913
|
? t('onboarding-workspace-switched', { name: target.label })
|
|
400
|
-
: t('onboarding-workspace-failed', { name: target.label }));
|
|
914
|
+
: t('onboarding-workspace-failed', { name: target.label }), ok ? 'success' : 'error');
|
|
401
915
|
});
|
|
402
|
-
} }) })), notice !== undefined && (_jsx(Box, { paddingX: 2, children: _jsx(Text, { color:
|
|
916
|
+
} }) })), notice !== undefined && (_jsx(Box, { paddingX: 2, children: _jsx(Text, { color: notice.tone, wrap: "truncate-end", children: notice.text }) })), _jsx(Divider, { bleed: true, color: "subtle" }), _jsx(Box, { flexShrink: 0, height: 1, paddingX: 2, children: _jsx(Text, { dimColor: true, italic: true, children: _jsx(HintLine, { text: t(hintKeyFor(step, accessPhase, onLast)) }) }) })] }));
|
|
403
917
|
}
|
|
404
918
|
/**
|
|
405
919
|
* 第二步顶部的面板标签("[ 界面语言 ]" / "[ 颜色主题 ]")。
|
|
@@ -416,17 +930,73 @@ function PaneTab({ label, active, onClick, }) {
|
|
|
416
930
|
const [hovered, setHovered] = React.useState(false);
|
|
417
931
|
return (_jsx(Box, { onClick: onClick, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), backgroundColor: hovered ? 'userMessageBackgroundHover' : undefined, children: _jsx(Text, { color: active ? 'suggestion' : undefined, children: '[ ' + label + ' ]' }) }));
|
|
418
932
|
}
|
|
419
|
-
/**
|
|
420
|
-
|
|
933
|
+
/**
|
|
934
|
+
* 第一步的状态块:凭证 + 订阅登录 + 真连通性检查。
|
|
935
|
+
*
|
|
936
|
+
* 这里**只读**——动作在下面的动作行里,由 Chat 交给既有的登录/`/provider`
|
|
937
|
+
* 流程执行。凭证只报"有没有"(`describeCredential` 不含秘密);登录行只画
|
|
938
|
+
* 掩码状态(provider + 已登录/过期/未登录)。
|
|
939
|
+
*
|
|
940
|
+
* 凭证行与余额检查只针对 DeepSeek 官方 API(`balanceInfo` 只认
|
|
941
|
+
* `DEEPSEEK_API_KEY`)。已经有别的接入(`otherAccess`)时,缺这把 key 只是一条
|
|
942
|
+
* 中性说明:刚登录 / 刚配好的人不该看到"没有可用的凭证"。
|
|
943
|
+
*
|
|
944
|
+
* 缺凭证时的文字兜底写的是**真实**的两条路:`$DSH_HOME/.credentials.yaml`
|
|
945
|
+
* 的 `refs:` 段,以及平台各自的环境变量写法(PowerShell 的用户级持久化与
|
|
946
|
+
* cmd 的 setx——一键安装包写的就是前者)。这里不再出现 v1 那条
|
|
947
|
+
* `~/.deepseek/config.json`:DSH 没有读取方,写了也不生效。
|
|
948
|
+
*/
|
|
949
|
+
function AccessStatus({ credential, conn, oauth, otherAccess, providerLabel, }) {
|
|
421
950
|
const configured = credential?.configured === true;
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
951
|
+
const signedIn = (oauth ?? []).filter(row => row.signedIn);
|
|
952
|
+
const covered = otherAccess.length > 0;
|
|
953
|
+
const others = otherAccess.map(id => providerLabel(id)).join(', ');
|
|
954
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: credential === undefined
|
|
955
|
+
? _jsx(Text, { dimColor: true, children: t('onboarding-key-checking') })
|
|
956
|
+
: configured
|
|
957
|
+
? _jsx(Text, { color: "success", children: '✓ ' + t('onboarding-key-configured') })
|
|
958
|
+
: covered
|
|
959
|
+
? _jsx(Text, { dimColor: true, children: '· ' + t('onboarding-key-optional') })
|
|
960
|
+
: _jsx(Text, { color: "warning", children: '✗ ' + t('onboarding-key-missing') }) }), credential !== undefined && configured && (_jsx(Text, { dimColor: true, children: ' ' + credentialSourceText(credential.source) })), oauth !== undefined && (signedIn.length > 0
|
|
961
|
+
? _jsx(Text, { color: "success", children: '✓ ' + t('onboarding-access-oauth-in', { n: signedIn.length, providers: signedIn.map(row => row.provider).join(', ') }) })
|
|
962
|
+
: _jsx(Text, { dimColor: true, children: '· ' + t('onboarding-access-oauth-none') })), credential !== undefined && !configured && !covered && (_jsx(Text, { dimColor: true, children: ' ' + t('onboarding-key-shape') }))] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [conn.kind === 'running' && _jsx(LoadingState, { message: t('onboarding-conn-running'), dimColor: true }), conn.kind === 'ok' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsx(Text, { color: "success", children: '✓ ' + t('onboarding-conn-ok') }) }), _jsx(Text, { dimColor: true, children: ' ' + t('onboarding-conn-models', { count: conn.models }) }), _jsx(Text, { dimColor: true, children: ' ' + (conn.balance === null ? t('onboarding-conn-balance-none') : t('onboarding-conn-balance', { amount: conn.balance })) })] })), conn.kind === 'fail' && (conn.reason === 'no-key' && covered
|
|
963
|
+
? _jsx(Box, { children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: '· ' + t('onboarding-conn-skipped', { providers: others }) }) })
|
|
964
|
+
: _jsx(Box, { children: _jsx(Text, { color: "error", children: '✗ ' + connFailText(conn.reason, conn.status) }) }))] })] }));
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* 选默认层:订阅登录之后新出现的模型里,哪一个当默认。
|
|
968
|
+
*
|
|
969
|
+
* 只有 N>1 才会走到这里(0 不问、1 直接落默认)。这些模型登录后已经全部可用
|
|
970
|
+
* (凭据门控目录),所以这一层是**单选**,不问"接入哪些"——没有任何地方会保存
|
|
971
|
+
* 那个子集。末尾一行是"保持当前模型";Esc 同义。两条路都不撤回已经登录的东西。
|
|
972
|
+
*/
|
|
973
|
+
function AdoptPanel({ adopt, providerLabel, currentModel, windowRows, onHover, onPick, }) {
|
|
974
|
+
const { plan } = adopt;
|
|
975
|
+
const label = providerLabel(plan.provider);
|
|
976
|
+
// 一批跨多个 provider 时按 provider 数报数(标题里点名单个 provider 是假的)。
|
|
977
|
+
const title = plan.multiProvider || label === ''
|
|
978
|
+
? t('onboarding-access-adopt-title-multi', {
|
|
979
|
+
n: plan.added.length,
|
|
980
|
+
providers: addedProviderOrder(plan.added).length,
|
|
981
|
+
})
|
|
982
|
+
: t('onboarding-access-adopt-title', { provider: label, n: plan.added.length });
|
|
983
|
+
// 列表窗口化:模型可能几十个,全量渲染会把焦点行挤出屏幕(80×24 下 30 个
|
|
984
|
+
// 模型时实测焦点行不可见),而 ↑/↓、Enter 仍作用在 `adopt.index` 上。末尾
|
|
985
|
+
// "保持当前模型"是操作区,固定在窗口之外(marginTop + 行 + 说明,占 3 行)。
|
|
986
|
+
const keepIndex = plan.added.length;
|
|
987
|
+
const { start, end } = listWindow(plan.added.map(() => 1), Math.min(adopt.index, Math.max(0, keepIndex - 1)), Math.max(1, windowRows - 3));
|
|
988
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: title }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: t('onboarding-access-adopt-note') }) }), plan.added.slice(start, end).map((row, offset) => {
|
|
989
|
+
const index = start + offset;
|
|
990
|
+
return (_jsx(Box, { flexDirection: "column", onMouseEnter: () => onHover(index), children: _jsx(ListItem, { isFocused: adopt.index === index, declareCursor: false, showScrollUp: index === start && start > 0, showScrollDown: index === end - 1 && end < plan.added.length, onClick: (event) => {
|
|
991
|
+
event.stopImmediatePropagation();
|
|
992
|
+
onHover(index);
|
|
993
|
+
onPick(row);
|
|
994
|
+
}, children: row.name + ' ' + row.provider }) }, modelRefKey(row)));
|
|
995
|
+
}), _jsxs(Box, { flexDirection: "column", marginTop: 1, onMouseEnter: () => onHover(keepIndex), children: [_jsx(ListItem, { isFocused: adopt.index === keepIndex, declareCursor: false, onClick: (event) => {
|
|
996
|
+
event.stopImmediatePropagation();
|
|
997
|
+
onHover(keepIndex);
|
|
998
|
+
onPick(undefined);
|
|
999
|
+
}, children: t('provider-opt-switch-keep') }), _jsx(Text, { dimColor: true, wrap: "truncate-end", children: ' ' + (currentModel === undefined ? '' : t('provider-opt-switch-keep-desc', { model: currentModel })) })] })] }));
|
|
430
1000
|
}
|
|
431
1001
|
/** 第三步:模型 / 强度 / 工作区三块,Tab 换焦点区。 */
|
|
432
1002
|
function ModelStep({ channel, models, providers, modelGroup, zone, focusIndex, efforts, effortIndex, workspaceLabel, onFocus, onZone, onDrill, onBack, onModel, onEffort, onOpenWorkspace, }) {
|