dsh-agent-sdk-bridge 1.1.8 → 1.2.1

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/DEVELOPMENT.md CHANGED
@@ -8,7 +8,45 @@
8
8
  登录区域),其余代码按 brand 参数化。CN Qoder SDK 静态引入;另两个 SDK 按需 `import()`,
9
9
  没装时只有对应页面报错,插件照常加载。
10
10
  - **品牌隔离**:各 provider 的 CLI 查找、模型目录缓存、会话池、账户读取、模型开关全部按 brand
11
- 分开。`QODERCLI_PATH` 若指向另一 Qoder 版本,对应版本会明确报错而不是借用那个 CLI 的账号。
11
+ 分开。`QODERCLI_PATH` 是机器级变量,不少 CN 安装会全局导出它;两个 SDK 又都在读到我们传的
12
+ 选项之前就先读它,所以 `cliChildEnv()` 会从**子进程环境**里删掉指向另一版本的 `QODERCLI_PATH`
13
+ (中立路径保留)。查找本身也永远不把另一版本的路径当作本版本候选。`foreignCliOverride()`
14
+ 现在只作诊断:本版本完全没有自己的 CLI 时才指出「那个变量属于另一版本」,绝不会因为它的存在
15
+ 而让本版本拒绝启动——旧代码把它当致命错误,于是一台只装了国际版(或只装了 CN)的机器,
16
+ 另一个页面即使装好 CLI 也登不进去。
17
+ - **SDK 与 CLI 的版本是绑定的**:每个 SDK 发布版在 `dist/runtime-manifest.json` 里钉住一个
18
+ `qoderCliVersion`,两边说的是同一条 wire protocol。CLI 1.1.81 移除了旧 SDK 的 worker 会话握手,
19
+ 于是 SDK 1.0.51 的每次查询都以 `Qoder CLI process exited with code 42` 结束,CLI 自己的日志写的
20
+ 是 `sdk_worker_removed: … Upgrade to the latest Qoder SDK version, or roll back the CLI`。
21
+ 因此:`dependencies` 里的两个 Qoder SDK 锁在同一个大版本(1.0.58 ↔ CLI 1.1.81);
22
+ 两个 `setup-*.bat` 从 SDK 清单读出 `qoderCliVersion` 并安装**那个精确版本**(不是 latest);
23
+ `requiredCliVersion()` / `installedCliVersion()` 都从磁盘读(后者读 npm 包的 manifest,不 spawn),
24
+ `/setup` 据此回传 `requiredCliVersion` / `cliVersion` / `versionMismatch`,页面在登录前就红字提示;
25
+ `cliFailureText()` 把 code 42 翻译成「点一键配置装配套版本」,并把原始信息附在后面。
26
+ 另注:`sdkDir()` 要剥掉 `dist` 这一层——`resolve()` 返回的是包内入口,直接 `dirname` 得到的是
27
+ `dist`,再拼 `dist/runtime-manifest.json` 就成了 `dist/dist/…`,两个探测都会静默失败。
28
+ - **Qoder 目录要先读账号**:SDK 1.0.58 里,在 `accountInfo()` 之前调 `getAvailableModels()` 会返回
29
+ 空数组(CLI 的 `--list-models` 同账号却能打出 11 条)。先在同一个 session 里取账号、再带 `uid`
30
+ 查目录才稳定;空答案时再依次回落 `fetchStrategy: 'cache'` → `'live'`。否则设置页显示 0/0,
31
+ 看起来像「没装 CLI」,实际只是读序不对。
32
+ - **CLI 查找要认包清单**:`bundle/<name>.js` 是常见布局,不是唯一布局。`packageEntries()` 还会
33
+ 读包自己的 `package.json`(`main`/`bin`),并把 Windows 的 `<node>/node_modules` 与 unix 的
34
+ `<prefix>/lib/node_modules` 都当作全局根。只猜 `bundle/` 会把已安装的 CLI 判成未安装,
35
+ 页面就一直要你「再装一次」。
36
+ - **退出登录要清凭据并关会话**:Qoder CLI 没有 `logout` 子命令,登录态只保存在加密的
37
+ `~/.qoder-cn/.auth/user`(国际版 `~/.qoder/.auth/user`);`machine_id` 属于机器而不是账号,保留。
38
+ 两个 `setup-*.bat` 的 `--logout` 删除该文件后再跑一次 `status`,确认不再打印 `Username`;
39
+ `POST /setup {mode:'logout'}` 成功后调用 `closeSessions()`,因为热会话里的 CLI 进程在启动时
40
+ 已加载旧凭据,不关掉就会继续以刚退出的账号作答。页面同时清空额度缓存(`resetSignal`),
41
+ 避免旧账号的积分继续显示。
42
+ - **卸载要清干净**:npm 只删包,会留下空的 `node_modules/@qoder-ai`(或 `@qodercn-ai`)目录和
43
+ `qodercli.cmd`/`.ps1` 之类 shim,而 CLI 查找和页面的「已安装」徽标读的正是这些。两个
44
+ `setup-*.bat` 的 `--uninstall` 会在 `npm uninstall -g` 之后删掉 shim 与空 scope 目录,
45
+ 页面的「已安装」状态则来自 `readSetupStatus().installed`(每次现查 `resolveQoderCli()`),
46
+ 所以卸载后主按钮会变回「安装 CLI」,而不是继续显示「卸载」。
47
+ - **登录可取消**:`qodercli login` 会一直等浏览器回调,用户关掉标签页后旧代码只能空转。
48
+ `POST /setup {mode:'cancel'}` → `cancelSetup()` 杀掉子进程并把这次 run 标记为已结束
49
+ (`code: null`、`cancelled: true`),页面每 1.2 秒轮询一次状态,因此按钮会立刻回来。
12
50
  - **Qoder 的声明窗口必须稳定**:Qoder 的 `context_usage_ratio` 是「按 CLI 实际运行的窗口」算的,
13
51
  而 DSH 又用适配器上报的 `contextWindow` 当分母。两者一变,环就会跳。实测目录里 `dfmodel`
14
52
  等模型声明 `availableContextWindows: [200000, 400000, 1000000]`、默认 200000,用户选 1M 是
package/FAQ.md CHANGED
@@ -2,11 +2,40 @@
2
2
 
3
3
  使用中遇到的问题与历史修复记录。返回 [README](./README.md)。
4
4
 
5
- **国际版页面提示「QODERCLI_PATH 指向了另一版本的 CLI」?** 这是有意的隔离。部分 CN 安装会在
6
- 环境里设置 `QODERCLI_PATH`,而两个官方 SDK 都会在读取任何参数之前先看这个变量。如果放行,国际版
7
- 会话会启动 `qoderclicn`、拿 CN 账号作答——模型目录和额度都会串台。插件因此只在它不指向另一版本
8
- 时采用;国际版自己的覆盖变量是 `QODER_CLI_PATH`。要么装好 `qodercli`(插件会优先用它),要么把
9
- 该变量指向国际版 CLI。
5
+ **登录后对话直接报 `Qoder CLI process exited with code 42`?** 这是 CLI 与插件 SDK 的版本不匹配:
6
+ 每个 SDK 发布版都钉住一个 CLI 版本,两边说的是同一条协议。CLI 1.1.81 移除了旧 SDK 的会话握手,
7
+ 旧 SDK 每次查询都会被 CLI 以退出码 42 结束(CLI 日志原文 `sdk_worker_removed: … Upgrade to the
8
+ latest Qoder SDK version, or roll back the CLI`)。插件已把两个 SDK 升到 1.0.58(对应 CLI 1.1.81),
9
+ 并且「一键配置」现在按 SDK 清单安装**精确版本**而不是 latest。升级插件后:设置页会直接显示
10
+ 「CLI 版本与插件不匹配:本机 x,插件需要 y」,点「安装 CLI」重装即可;如果版本已经一致还报 42,
11
+ 重启 DSH Web 让新版 SDK 生效。
12
+
13
+ **只启用国内版 / 只启用国际版,另一个版本没装,会不会互相影响?** 不会(这是修过的 bug)。
14
+ `QODERCLI_PATH` 是机器级变量,不少 CN 安装会全局导出它;两个官方 SDK 又都在读到插件传的参数
15
+ 之前先看它。旧代码一旦发现它指向另一版本就判为致命错误,于是一台只装了国际版的机器,国内版
16
+ 页面即使后来装好了 `qoderclicn` 也登不进去——两个版本被这个变量绑在一起。现在查找各自只认
17
+ 自己的包与状态目录,并且会把指向另一版本的 `QODERCLI_PATH` 从**子进程环境**里删掉(中立路径
18
+ 保留);只有本版本完全没有自己的 CLI 时,页面才会提示「那个变量属于另一版本」。两个版本的
19
+ 安装、登录、卸载因此完全独立。
20
+
21
+ **卸载了 CLI,页面上还是「卸载」按钮、目录里还有残留?** 已修复。npm 只删包,会留下空的
22
+ `node_modules/@qoder-ai`(或 `@qodercn-ai`)目录和 `qodercli.cmd` / `.ps1` 这些 shim,而插件的
23
+ CLI 查找和页面徽标读的正是它们。现在 `--uninstall` 会在 `npm uninstall -g` 之后删掉 shim 与空
24
+ scope 目录;页面上的「已安装」也改成每次现查机器,所以卸载后主按钮立刻变回「安装 CLI」,
25
+ 登录 / 卸载按钮只在已安装时出现。
26
+
27
+ **想换账号或退出登录?** Qoder 页面在已安装 CLI 时会显示「退出登录」。Qoder CLI 本身没有 `logout`
28
+ 子命令,插件改为删除该版本加密保存的凭据(国内版 `~/.qoder-cn/.auth/user`,国际版
29
+ `~/.qoder/.auth/user`;`machine_id` 保留),并在成功后关闭已打开的会话、清空额度缓存。因此旧账号
30
+ 不会继续作答,旧积分也不会挂在卡片上;CLI 保持安装,点「重新登录」即可换号。
31
+
32
+ **点「重新登录」后关掉了浏览器,页面就一直转圈?** 已修复,并新增「取消」。`qodercli login`
33
+ 会一直等浏览器回调,关掉标签页就没有返回值。现在运行中会出现「取消」按钮:点它会终止这次
34
+ 脚本、把状态标记为已取消,按钮立刻恢复,可以重新登录。
35
+
36
+ **国际版页面提示「QODERCLI_PATH 指向了另一版本的 CLI」?** 只有在国际版本机完全没有自己的
37
+ `qodercli` 时才会这样提示,属于诊断而非拦截。装好 `qodercli`(或把 `QODER_CLI_PATH` 指向它)
38
+ 即可;插件绝不会把 CN 的 CLI 借给国际版会话,因为那会拿 CN 账号作答。
10
39
 
11
40
  **额度卡片显示「无法读取额度」?** 卡片里的文字就是原因:CLI 未安装 / 未登录 / 额度接口暂时
12
41
  不可用。额度读取走的是 CLI 自己的凭证,所以先确认对应版本的 `status` 能列出用户名;点「刷新额度」
package/README.md CHANGED
@@ -93,8 +93,8 @@ npm install -g @qoder-ai/qodercli && qodercli login # 国际版
93
93
  剩余积分,以及 Token Plan 的 5 小时 / 每周剩余百分比、重置时间与进度条(与官网控制台同源)。
94
94
  - **模型清单**:来自账号实时目录,逐个启用 / 关闭、指定上下文窗口;倍率取自上游报价。
95
95
  - **高级设置**:并发会话数、目录缓存、超时、默认思考档位、模型别名、分组名称等,可折叠。
96
- - **CLI 分组**:Qoder 页面有一键配置 / 重新登录 / 卸载 CLI;MiniMax Code 页面有安装 / 更新 /
97
- 卸载 CLI(卸载前确认,保留登录凭证),均附实时输出。
96
+ - **CLI 分组**:Qoder 页面有一键配置 / 重新登录 / 退出登录 / 卸载 CLI;MiniMax Code 页面有安装 /
97
+ 更新 / 卸载 CLI(卸载前确认,保留登录凭证),均附实时输出。
98
98
  - 再次打开页面时**先显示上次快照**,模型与账户在后台更新,不再每次都停在「正在读取」。
99
99
 
100
100
  每个 provider 只注册一条路由(`qoder-cn` / `qoder-intl` / `codebuddy` / `minimax-acp`),只服务
package/client.js CHANGED
@@ -86,6 +86,17 @@ window.__ModuleLoader__.load({
86
86
  cliUninstallConfirm: '确定要卸载本机的 Qoder CLI 吗?卸载后需要重新安装才能继续使用,登录凭证会保留。',
87
87
  cliUninstalling: '正在卸载…',
88
88
  cliUninstallOk: 'CLI 已卸载',
89
+ cliInstall: '安装 CLI',
90
+ cliInstalled: '已安装',
91
+ cliCancel: '取消',
92
+ cliCancelling: '正在取消…',
93
+ cliCancelled: '已取消,可以重新操作',
94
+ cliLogout: '退出登录',
95
+ cliLogoutConfirm: '确定要退出当前 Qoder 账号吗?退出后会关闭已打开的会话并清空额度,需要重新登录才能继续使用;CLI 本身不会被卸载。',
96
+ cliLoggingOut: '正在退出登录…',
97
+ cliLogoutOk: '已退出登录',
98
+ cliVersionMismatch: 'CLI 版本与插件不匹配:本机',
99
+ cliVersionMismatchTail: ',插件需要',
89
100
  intlNav: 'Qoder 国际版',
90
101
  intlTitle: 'Qoder 国际版',
91
102
  intlIntro: '国际版账户(qoder.com)的模型与额度。勾选要启用的模型,并为需要的模型指定上下文窗口。改动即时生效,无需重启。',
@@ -113,6 +124,9 @@ window.__ModuleLoader__.load({
113
124
  usageUpdated: '更新于',
114
125
  usageUnknownPlan: '未知套餐',
115
126
  usageStale: '显示上次读数,刷新失败',
127
+ usageCliMissing: '未检测到本机 CLI,安装并登录后才会显示额度。',
128
+ usageSignedOut: '已退出登录,重新登录后显示额度。',
129
+ modelsSignedOut: '已退出登录,重新登录后才会显示模型。',
116
130
  pluginOptionsTitle: '启用的版本',
117
131
  pluginOptionsHint: '关闭后,对应设置页、模型列表与模型分组都会移除;已保存的模型选择保留,重新打开即可恢复。',
118
132
  pluginOptionsOn: '显示中',
@@ -275,6 +289,17 @@ window.__ModuleLoader__.load({
275
289
  cliUninstallConfirm: 'Uninstall the Qoder CLI from this machine? It must be installed again to keep using this edition. Sign-in files are kept.',
276
290
  cliUninstalling: 'Uninstalling…',
277
291
  cliUninstallOk: 'CLI uninstalled',
292
+ cliInstall: 'Install CLI',
293
+ cliInstalled: 'Installed',
294
+ cliCancel: 'Cancel',
295
+ cliCancelling: 'Cancelling…',
296
+ cliCancelled: 'Cancelled — you can start again',
297
+ cliLogout: 'Sign out',
298
+ cliLogoutConfirm: 'Sign out of the current Qoder account? Open sessions will be closed and quota cleared; you will need to sign in again. The CLI itself stays installed.',
299
+ cliLoggingOut: 'Signing out…',
300
+ cliLogoutOk: 'Signed out',
301
+ cliVersionMismatch: 'CLI version does not match the plugin: this machine has',
302
+ cliVersionMismatchTail: 'but the plugin needs',
278
303
  intlNav: 'Qoder International',
279
304
  intlTitle: 'Qoder International',
280
305
  intlIntro: 'Models and quota for the international account (qoder.com). Tick the models you want available and set a context window where needed. Changes apply immediately.',
@@ -302,6 +327,9 @@ window.__ModuleLoader__.load({
302
327
  usageUpdated: 'Updated',
303
328
  usageUnknownPlan: 'Unknown plan',
304
329
  usageStale: 'Showing the last reading; refresh failed',
330
+ usageCliMissing: 'This machine has no CLI for this edition; quota appears after it is installed and signed in.',
331
+ usageSignedOut: 'Signed out. Sign in again to see quota.',
332
+ modelsSignedOut: 'Signed out. Sign in again to see the models.',
305
333
  pluginOptionsTitle: 'Enabled editions',
306
334
  pluginOptionsHint: 'Turning one off removes its settings page, model list, and model group. Saved model choices are kept, so turning it back on restores them.',
307
335
  pluginOptionsOn: 'Shown',
@@ -644,6 +672,24 @@ window.__ModuleLoader__.load({
644
672
  }
645
673
  }
646
674
 
675
+ /**
676
+ * Forget one cached answer.
677
+ *
678
+ * Needed when the cache has become wrong rather than merely old: after an
679
+ * uninstall the stored quota describes an account read through a CLI that
680
+ * is no longer on the machine, and painting it again on the next render
681
+ * would keep showing numbers nobody can reproduce.
682
+ */
683
+ function clearCache(brand, kind) {
684
+ const key = cacheKey(brand, kind)
685
+ cacheMemory.delete(key)
686
+ try {
687
+ window.localStorage.removeItem(key)
688
+ } catch {
689
+ /* storage unavailable: the in-memory copy is already gone */
690
+ }
691
+ }
692
+
647
693
  /** Call the plugin's model API. */
648
694
  async function api(path, options) {
649
695
  const { timeout = 30_000, ...rest } = options ?? {}
@@ -856,11 +902,16 @@ window.__ModuleLoader__.load({
856
902
  * upgrade/usage links. It is fetched from the host (which asks the CLI), not
857
903
  * from the provider directly, because only the CLI holds a usable token.
858
904
  */
859
- function UsageCard({ t, brand, refreshSignal }) {
905
+ function UsageCard({ t, brand, refreshSignal, resetSignal }) {
860
906
  const [snapshot, setSnapshot] = useState(() => readCache(brand.id, 'usage'))
861
907
  const [failure, setFailure] = useState(undefined)
862
908
  const [busy, setBusy] = useState(false)
909
+ /** The CLI is not installed: show that, and never any cached numbers. */
910
+ const [missing, setMissing] = useState(false)
911
+ /** The user just signed out from this page: no reading is expected. */
912
+ const [signedOut, setSignedOut] = useState(false)
863
913
  const ticket = useRef(0)
914
+ const lastReset = useRef(resetSignal)
864
915
 
865
916
  const load = useCallback(async (fresh = false) => {
866
917
  const mine = ++ticket.current
@@ -869,12 +920,27 @@ window.__ModuleLoader__.load({
869
920
  try {
870
921
  const payload = await api(`/usage?brand=${brand.id}${fresh ? '&fresh=1' : ''}`, { timeout: 45_000 })
871
922
  if (mine !== ticket.current) return
872
- // A failed account lookup (signed out, endpoint down) must not replace
923
+ // The CLI is gone: the stored reading describes an installation that
924
+ // no longer exists, so drop it (memory and storage) instead of
925
+ // labelling old credits "last reading". This is what makes the card
926
+ // empty out after an uninstall.
927
+ if (payload?.cliMissing === true) {
928
+ clearCache(brand.id, 'usage')
929
+ setSnapshot(undefined)
930
+ setMissing(true)
931
+ setSignedOut(false)
932
+ setFailure(String(payload.error ?? t('usageCliMissing')))
933
+ return
934
+ }
935
+ // Any other failed lookup (signed out, endpoint down) must not replace
873
936
  // the last good reading with an empty card: keep it and say so.
874
937
  if (payload?.usage === undefined && payload?.error !== undefined) {
938
+ setMissing(false)
875
939
  setFailure(String(payload.error))
876
940
  return
877
941
  }
942
+ setMissing(false)
943
+ setSignedOut(false)
878
944
  setSnapshot(payload)
879
945
  writeCache(brand.id, 'usage', payload)
880
946
  } catch (err) {
@@ -889,6 +955,23 @@ window.__ModuleLoader__.load({
889
955
  // make the cached account reading describe a machine state that is gone.
890
956
  useEffect(() => { void load() }, [load, refreshSignal])
891
957
 
958
+ // A sign-out makes the stored reading describe an account that is no
959
+ // longer signed in — the same lie the uninstall case told. `resetSignal`
960
+ // changes only for that action, so an ordinary refresh keeps its
961
+ // stale-while-revalidate behaviour.
962
+ useEffect(() => {
963
+ if (lastReset.current === resetSignal) return
964
+ lastReset.current = resetSignal
965
+ clearCache(brand.id, 'usage')
966
+ setSnapshot(undefined)
967
+ setMissing(false)
968
+ setFailure(undefined)
969
+ // Do not fetch: the CLI has just been signed out, so a read would only
970
+ // produce an authentication error that looks like a malfunction. The
971
+ // refresh button and the next sign-in both still work.
972
+ setSignedOut(true)
973
+ }, [resetSignal, brand.id])
974
+
892
975
  const usage = snapshot?.usage
893
976
  const account = snapshot?.account
894
977
  const error = failure ?? (snapshot?.usage === undefined && snapshot?.error !== undefined ? String(snapshot.error) : undefined)
@@ -911,9 +994,16 @@ window.__ModuleLoader__.load({
911
994
  if (snapshot === undefined || usage === undefined) {
912
995
  return h('div', { style: css.usageCard },
913
996
  head,
914
- error === undefined
915
- ? h('div', { style: css.note }, t('usageLoading'))
916
- : h('div', { style: css.err }, `${t('usageUnavailable')}:${error}`),
997
+ // Nothing is shown for a missing CLI beyond the reason: the account,
998
+ // plan and credits a previous install reported are not this machine's
999
+ // state any more.
1000
+ missing
1001
+ ? h('div', { style: css.note }, error ?? t('usageCliMissing'))
1002
+ : signedOut
1003
+ ? h('div', { style: css.note }, t('usageSignedOut'))
1004
+ : error === undefined
1005
+ ? h('div', { style: css.note }, t('usageLoading'))
1006
+ : h('div', { style: css.err }, `${t('usageUnavailable')}:${error}`),
917
1007
  error === undefined
918
1008
  ? null
919
1009
  : h('div', { style: css.bar },
@@ -1735,6 +1825,9 @@ window.__ModuleLoader__.load({
1735
1825
  const [onlyEnabled, setOnlyEnabled] = useState(false)
1736
1826
  const [showAdvanced, setShowAdvanced] = useState(false)
1737
1827
  const [usageTick, setUsageTick] = useState(0)
1828
+ // Bumped only by a successful sign-out: the quota card must drop its
1829
+ // stored account rather than label it "last reading".
1830
+ const [usageReset, setUsageReset] = useState(0)
1738
1831
  const ticket = useRef(0)
1739
1832
  /** Separate from `ticket`: `load()` bumps that one, so sharing it would
1740
1833
  * make every write look stale the moment its own refresh landed. */
@@ -2077,6 +2170,14 @@ window.__ModuleLoader__.load({
2077
2170
  const setupCode = setup !== undefined && setup.running === false ? setup.code : undefined
2078
2171
  const setupFinishedAt = setup?.finishedAt
2079
2172
  const setupLines = Array.isArray(setup?.lines) ? setup.lines : []
2173
+ // `installed` is read from the host's own CLI lookup, so the button
2174
+ // follows the machine rather than the last run: after an uninstall it
2175
+ // reads false even though that run exited 0, and the page offers
2176
+ // "install" again instead of a dead "uninstall". Until the first status
2177
+ // arrives the old layout is kept, so opening the page does not flash an
2178
+ // "install" button on a machine that already has the CLI.
2179
+ const cliInstalled = setup === undefined ? true : setup.installed === true
2180
+ const setupCancelled = setup?.cancelled === true
2080
2181
 
2081
2182
  useEffect(() => { void pollSetup() }, [pollSetup])
2082
2183
  useEffect(() => {
@@ -2106,9 +2207,21 @@ window.__ModuleLoader__.load({
2106
2207
  // and the host has already dropped its cached answers for that case.
2107
2208
  useEffect(() => {
2108
2209
  if (setupCode !== 0) return
2210
+ if (setup?.mode === 'logout') {
2211
+ // Signing out invalidates the account itself, not just its freshness:
2212
+ // the stored catalog and quota were read through credentials that no
2213
+ // longer exist. Drop both instead of refetching — a read now would
2214
+ // only fail with an authentication error that looks like a fault.
2215
+ clearCache(brand.id, modelsKind)
2216
+ setModels([])
2217
+ setCatalogNotice(t('modelsSignedOut'))
2218
+ setSignedIn(regional ? false : undefined)
2219
+ setUsageReset(value => value + 1)
2220
+ return
2221
+ }
2109
2222
  void load(true)
2110
2223
  setUsageTick(value => value + 1)
2111
- }, [setupCode, setupFinishedAt, load])
2224
+ }, [setupCode, setupFinishedAt, setup?.mode, load, brand.id, modelsKind, regional, t])
2112
2225
 
2113
2226
  /** Ask before running the destructive CLI action. */
2114
2227
  const uninstallCli = useCallback(() => {
@@ -2117,6 +2230,13 @@ window.__ModuleLoader__.load({
2117
2230
  void startCliSetup('uninstall')
2118
2231
  }, [startCliSetup, t])
2119
2232
 
2233
+ /** Signing out is reversible, but it clears the account and quota. */
2234
+ const logoutCli = useCallback(() => {
2235
+ if (typeof window.confirm !== 'function') return
2236
+ if (!window.confirm(t('cliLogoutConfirm'))) return
2237
+ void startCliSetup('logout')
2238
+ }, [startCliSetup, t])
2239
+
2120
2240
  useEffect(() => {
2121
2241
  const node = logRef.current
2122
2242
  if (node !== null) node.scrollTop = node.scrollHeight
@@ -2265,7 +2385,7 @@ window.__ModuleLoader__.load({
2265
2385
  h('p', { style: css.intro }, t(brand.introKey)),
2266
2386
  regional
2267
2387
  ? authCard
2268
- : h(UsageCard, { t, brand, refreshSignal: usageTick }),
2388
+ : h(UsageCard, { t, brand, refreshSignal: usageTick, resetSignal: usageReset }),
2269
2389
 
2270
2390
  // Search row: the field grows, the checkbox sits beside it.
2271
2391
  h('div', { style: css.bar },
@@ -2311,25 +2431,60 @@ window.__ModuleLoader__.load({
2311
2431
  brand.kind !== 'qoder' ? null : h('div', { style: css.group },
2312
2432
  h('h3', { style: css.h3 }, t(brand.cliGroupKey)),
2313
2433
  h('div', { style: css.note }, t(brand.cliHintKey)),
2434
+ // Each SDK release pins one CLI build; a mismatch kills every session
2435
+ // with a bare exit code, so warn before the user signs in or chats.
2436
+ setup?.versionMismatch === true
2437
+ ? h('div', { style: { ...css.err, marginTop: '6px' } },
2438
+ `${t('cliVersionMismatch')} ${setup.cliVersion ?? '?'} ${t('cliVersionMismatchTail')} ${setup.requiredCliVersion ?? '?'}`)
2439
+ : null,
2314
2440
  h('div', { style: { ...css.bar, flexWrap: 'nowrap' } },
2315
- h('button', { style: css.btn, disabled: setupRunning, onClick: () => void startCliSetup('configure') }, t('cliRun')),
2316
- h('button', { style: css.btn, disabled: setupRunning, onClick: () => void startCliSetup('login') }, t('cliLogin')),
2317
- h('button', { style: { ...css.btn, ...css.btnAlert }, disabled: setupRunning, onClick: uninstallCli }, t('cliUninstall')),
2441
+ // The primary action follows the machine: install when the CLI is
2442
+ // gone, configure/re-login when it is there. Offering "uninstall"
2443
+ // on a machine that has none was the confusing half of the old
2444
+ // fixed trio.
2445
+ cliInstalled
2446
+ ? h('button', { style: css.btn, disabled: setupRunning, onClick: () => void startCliSetup('configure') },
2447
+ setup?.versionMismatch === true ? t('cliInstall') : t('cliRun'))
2448
+ : h('button', { style: css.btn, disabled: setupRunning, onClick: () => void startCliSetup('configure') }, t('cliInstall')),
2449
+ cliInstalled
2450
+ ? h('button', { style: css.btn, disabled: setupRunning, onClick: () => void startCliSetup('login') }, t('cliLogin'))
2451
+ : null,
2452
+ cliInstalled
2453
+ ? h('button', { style: css.btn, disabled: setupRunning, onClick: logoutCli }, t('cliLogout'))
2454
+ : null,
2455
+ cliInstalled
2456
+ ? h('button', { style: { ...css.btn, ...css.btnAlert }, disabled: setupRunning, onClick: uninstallCli }, t('cliUninstall'))
2457
+ : null,
2458
+ // The login step waits for a browser callback; closing that tab
2459
+ // used to leave this row spinning forever. Cancelling settles the
2460
+ // run so the buttons come back.
2461
+ setupRunning
2462
+ ? h('button', {
2463
+ style: { ...css.btn, ...css.btnAlert },
2464
+ onClick: () => void startCliSetup('cancel'),
2465
+ }, t('cliCancel'))
2466
+ : null,
2318
2467
  setupLines.length > 0 && !setupRunning
2319
2468
  ? h('button', { style: css.btn, onClick: () => setLogOpen(value => !value) }, logOpen ? t('cliHideLog') : t('cliShowLog'))
2320
2469
  : null,
2321
2470
  h('span', { style: css.count }, setupRunning
2322
- ? (setup?.mode === 'uninstall' ? t('cliUninstalling') : t('cliRunning'))
2471
+ ? (setup?.mode === 'uninstall'
2472
+ ? t('cliUninstalling')
2473
+ : setup?.mode === 'logout' ? t('cliLoggingOut') : t('cliRunning'))
2323
2474
  : setupError !== undefined
2324
2475
  ? setupError
2325
- : setupCode === 0
2326
- ? (setup?.mode === 'uninstall' ? t('cliUninstallOk') : t('cliExitOk'))
2327
- : setupCode === undefined || setupCode === null
2328
- ? ''
2329
- : `${t('cliExitFail')} ${setupCode}`),
2476
+ : setupCancelled
2477
+ ? t('cliCancelled')
2478
+ : setupCode === 0
2479
+ ? (setup?.mode === 'uninstall'
2480
+ ? t('cliUninstallOk')
2481
+ : setup?.mode === 'logout' ? t('cliLogoutOk') : t('cliExitOk'))
2482
+ : setupCode === undefined || setupCode === null
2483
+ ? ''
2484
+ : `${t('cliExitFail')} ${setupCode}`),
2330
2485
  ),
2331
2486
  logOpen && setupLines.length > 0
2332
- ? h('pre', { ref: logRef, style: css.log }, setupLines.join('\n'))
2487
+ ? h('pre', { ref: logRef, style: css.log }, setupLines.join('\\n'))
2333
2488
  : null,
2334
2489
  ),
2335
2490