dsh-agent-sdk-bridge 1.2.0 → 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
@@ -33,6 +33,12 @@
33
33
  读包自己的 `package.json`(`main`/`bin`),并把 Windows 的 `<node>/node_modules` 与 unix 的
34
34
  `<prefix>/lib/node_modules` 都当作全局根。只猜 `bundle/` 会把已安装的 CLI 判成未安装,
35
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
+ 避免旧账号的积分继续显示。
36
42
  - **卸载要清干净**:npm 只删包,会留下空的 `node_modules/@qoder-ai`(或 `@qodercn-ai`)目录和
37
43
  `qodercli.cmd`/`.ps1` 之类 shim,而 CLI 查找和页面的「已安装」徽标读的正是这些。两个
38
44
  `setup-*.bat` 的 `--uninstall` 会在 `npm uninstall -g` 之后删掉 shim 与空 scope 目录,
package/FAQ.md CHANGED
@@ -24,6 +24,11 @@ CLI 查找和页面徽标读的正是它们。现在 `--uninstall` 会在 `npm u
24
24
  scope 目录;页面上的「已安装」也改成每次现查机器,所以卸载后主按钮立刻变回「安装 CLI」,
25
25
  登录 / 卸载按钮只在已安装时出现。
26
26
 
27
+ **想换账号或退出登录?** Qoder 页面在已安装 CLI 时会显示「退出登录」。Qoder CLI 本身没有 `logout`
28
+ 子命令,插件改为删除该版本加密保存的凭据(国内版 `~/.qoder-cn/.auth/user`,国际版
29
+ `~/.qoder/.auth/user`;`machine_id` 保留),并在成功后关闭已打开的会话、清空额度缓存。因此旧账号
30
+ 不会继续作答,旧积分也不会挂在卡片上;CLI 保持安装,点「重新登录」即可换号。
31
+
27
32
  **点「重新登录」后关掉了浏览器,页面就一直转圈?** 已修复,并新增「取消」。`qodercli login`
28
33
  会一直等浏览器回调,关掉标签页就没有返回值。现在运行中会出现「取消」按钮:点它会终止这次
29
34
  脚本、把状态标记为已取消,按钮立刻恢复,可以重新登录。
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
@@ -91,6 +91,10 @@ window.__ModuleLoader__.load({
91
91
  cliCancel: '取消',
92
92
  cliCancelling: '正在取消…',
93
93
  cliCancelled: '已取消,可以重新操作',
94
+ cliLogout: '退出登录',
95
+ cliLogoutConfirm: '确定要退出当前 Qoder 账号吗?退出后会关闭已打开的会话并清空额度,需要重新登录才能继续使用;CLI 本身不会被卸载。',
96
+ cliLoggingOut: '正在退出登录…',
97
+ cliLogoutOk: '已退出登录',
94
98
  cliVersionMismatch: 'CLI 版本与插件不匹配:本机',
95
99
  cliVersionMismatchTail: ',插件需要',
96
100
  intlNav: 'Qoder 国际版',
@@ -121,6 +125,8 @@ window.__ModuleLoader__.load({
121
125
  usageUnknownPlan: '未知套餐',
122
126
  usageStale: '显示上次读数,刷新失败',
123
127
  usageCliMissing: '未检测到本机 CLI,安装并登录后才会显示额度。',
128
+ usageSignedOut: '已退出登录,重新登录后显示额度。',
129
+ modelsSignedOut: '已退出登录,重新登录后才会显示模型。',
124
130
  pluginOptionsTitle: '启用的版本',
125
131
  pluginOptionsHint: '关闭后,对应设置页、模型列表与模型分组都会移除;已保存的模型选择保留,重新打开即可恢复。',
126
132
  pluginOptionsOn: '显示中',
@@ -288,6 +294,10 @@ window.__ModuleLoader__.load({
288
294
  cliCancel: 'Cancel',
289
295
  cliCancelling: 'Cancelling…',
290
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',
291
301
  cliVersionMismatch: 'CLI version does not match the plugin: this machine has',
292
302
  cliVersionMismatchTail: 'but the plugin needs',
293
303
  intlNav: 'Qoder International',
@@ -318,6 +328,8 @@ window.__ModuleLoader__.load({
318
328
  usageUnknownPlan: 'Unknown plan',
319
329
  usageStale: 'Showing the last reading; refresh failed',
320
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.',
321
333
  pluginOptionsTitle: 'Enabled editions',
322
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.',
323
335
  pluginOptionsOn: 'Shown',
@@ -890,13 +902,16 @@ window.__ModuleLoader__.load({
890
902
  * upgrade/usage links. It is fetched from the host (which asks the CLI), not
891
903
  * from the provider directly, because only the CLI holds a usable token.
892
904
  */
893
- function UsageCard({ t, brand, refreshSignal }) {
905
+ function UsageCard({ t, brand, refreshSignal, resetSignal }) {
894
906
  const [snapshot, setSnapshot] = useState(() => readCache(brand.id, 'usage'))
895
907
  const [failure, setFailure] = useState(undefined)
896
908
  const [busy, setBusy] = useState(false)
897
909
  /** The CLI is not installed: show that, and never any cached numbers. */
898
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)
899
913
  const ticket = useRef(0)
914
+ const lastReset = useRef(resetSignal)
900
915
 
901
916
  const load = useCallback(async (fresh = false) => {
902
917
  const mine = ++ticket.current
@@ -913,6 +928,7 @@ window.__ModuleLoader__.load({
913
928
  clearCache(brand.id, 'usage')
914
929
  setSnapshot(undefined)
915
930
  setMissing(true)
931
+ setSignedOut(false)
916
932
  setFailure(String(payload.error ?? t('usageCliMissing')))
917
933
  return
918
934
  }
@@ -924,6 +940,7 @@ window.__ModuleLoader__.load({
924
940
  return
925
941
  }
926
942
  setMissing(false)
943
+ setSignedOut(false)
927
944
  setSnapshot(payload)
928
945
  writeCache(brand.id, 'usage', payload)
929
946
  } catch (err) {
@@ -938,6 +955,23 @@ window.__ModuleLoader__.load({
938
955
  // make the cached account reading describe a machine state that is gone.
939
956
  useEffect(() => { void load() }, [load, refreshSignal])
940
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
+
941
975
  const usage = snapshot?.usage
942
976
  const account = snapshot?.account
943
977
  const error = failure ?? (snapshot?.usage === undefined && snapshot?.error !== undefined ? String(snapshot.error) : undefined)
@@ -965,9 +999,11 @@ window.__ModuleLoader__.load({
965
999
  // state any more.
966
1000
  missing
967
1001
  ? h('div', { style: css.note }, error ?? t('usageCliMissing'))
968
- : error === undefined
969
- ? h('div', { style: css.note }, t('usageLoading'))
970
- : h('div', { style: css.err }, `${t('usageUnavailable')}:${error}`),
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}`),
971
1007
  error === undefined
972
1008
  ? null
973
1009
  : h('div', { style: css.bar },
@@ -1789,6 +1825,9 @@ window.__ModuleLoader__.load({
1789
1825
  const [onlyEnabled, setOnlyEnabled] = useState(false)
1790
1826
  const [showAdvanced, setShowAdvanced] = useState(false)
1791
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)
1792
1831
  const ticket = useRef(0)
1793
1832
  /** Separate from `ticket`: `load()` bumps that one, so sharing it would
1794
1833
  * make every write look stale the moment its own refresh landed. */
@@ -2168,9 +2207,21 @@ window.__ModuleLoader__.load({
2168
2207
  // and the host has already dropped its cached answers for that case.
2169
2208
  useEffect(() => {
2170
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
+ }
2171
2222
  void load(true)
2172
2223
  setUsageTick(value => value + 1)
2173
- }, [setupCode, setupFinishedAt, load])
2224
+ }, [setupCode, setupFinishedAt, setup?.mode, load, brand.id, modelsKind, regional, t])
2174
2225
 
2175
2226
  /** Ask before running the destructive CLI action. */
2176
2227
  const uninstallCli = useCallback(() => {
@@ -2179,6 +2230,13 @@ window.__ModuleLoader__.load({
2179
2230
  void startCliSetup('uninstall')
2180
2231
  }, [startCliSetup, t])
2181
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
+
2182
2240
  useEffect(() => {
2183
2241
  const node = logRef.current
2184
2242
  if (node !== null) node.scrollTop = node.scrollHeight
@@ -2327,7 +2385,7 @@ window.__ModuleLoader__.load({
2327
2385
  h('p', { style: css.intro }, t(brand.introKey)),
2328
2386
  regional
2329
2387
  ? authCard
2330
- : h(UsageCard, { t, brand, refreshSignal: usageTick }),
2388
+ : h(UsageCard, { t, brand, refreshSignal: usageTick, resetSignal: usageReset }),
2331
2389
 
2332
2390
  // Search row: the field grows, the checkbox sits beside it.
2333
2391
  h('div', { style: css.bar },
@@ -2391,6 +2449,9 @@ window.__ModuleLoader__.load({
2391
2449
  cliInstalled
2392
2450
  ? h('button', { style: css.btn, disabled: setupRunning, onClick: () => void startCliSetup('login') }, t('cliLogin'))
2393
2451
  : null,
2452
+ cliInstalled
2453
+ ? h('button', { style: css.btn, disabled: setupRunning, onClick: logoutCli }, t('cliLogout'))
2454
+ : null,
2394
2455
  cliInstalled
2395
2456
  ? h('button', { style: { ...css.btn, ...css.btnAlert }, disabled: setupRunning, onClick: uninstallCli }, t('cliUninstall'))
2396
2457
  : null,
@@ -2407,13 +2468,17 @@ window.__ModuleLoader__.load({
2407
2468
  ? h('button', { style: css.btn, onClick: () => setLogOpen(value => !value) }, logOpen ? t('cliHideLog') : t('cliShowLog'))
2408
2469
  : null,
2409
2470
  h('span', { style: css.count }, setupRunning
2410
- ? (setup?.mode === 'uninstall' ? t('cliUninstalling') : t('cliRunning'))
2471
+ ? (setup?.mode === 'uninstall'
2472
+ ? t('cliUninstalling')
2473
+ : setup?.mode === 'logout' ? t('cliLoggingOut') : t('cliRunning'))
2411
2474
  : setupError !== undefined
2412
2475
  ? setupError
2413
2476
  : setupCancelled
2414
2477
  ? t('cliCancelled')
2415
2478
  : setupCode === 0
2416
- ? (setup?.mode === 'uninstall' ? t('cliUninstallOk') : t('cliExitOk'))
2479
+ ? (setup?.mode === 'uninstall'
2480
+ ? t('cliUninstallOk')
2481
+ : setup?.mode === 'logout' ? t('cliLogoutOk') : t('cliExitOk'))
2417
2482
  : setupCode === undefined || setupCode === null
2418
2483
  ? ''
2419
2484
  : `${t('cliExitFail')} ${setupCode}`),
package/lib/index.js CHANGED
@@ -3501,6 +3501,17 @@ var QoderAdapter = class extends LlmAdapter {
3501
3501
  }
3502
3502
  return pixels === 0 ? content.map((block) => block.type === "text" ? block.text : "").join("\n\n") : content;
3503
3503
  }
3504
+ /**
3505
+ * Drop every warm inner session without unloading the plugin.
3506
+ *
3507
+ * Signing out has to invalidate them: each holds a CLI process that already
3508
+ * loaded its credentials, so it would keep answering as the account that was
3509
+ * just signed out. The next turn starts a fresh process, which then reports
3510
+ * the signed-out state honestly.
3511
+ */
3512
+ closeSessions() {
3513
+ this.sessions.closeAll();
3514
+ }
3504
3515
  /** Tear down every warm inner session (plugin dispose). */
3505
3516
  close() {
3506
3517
  this.sessions.closeAll();
@@ -8277,11 +8288,12 @@ function scriptNameOf(brand) {
8277
8288
  const FLAGS = {
8278
8289
  configure: "--gui",
8279
8290
  login: "--login",
8291
+ logout: "--logout",
8280
8292
  uninstall: "--uninstall"
8281
8293
  };
8282
8294
  /** Whether a value is one of the modes the page may request. */
8283
8295
  function isSetupMode(value) {
8284
- return value === "configure" || value === "login" || value === "uninstall";
8296
+ return value === "configure" || value === "login" || value === "logout" || value === "uninstall";
8285
8297
  }
8286
8298
  /** Cap on kept output, so a chatty `npm install` cannot grow without bound. */
8287
8299
  const MAX_LINES = 400;
@@ -8335,7 +8347,7 @@ function startSetup(brand, mode, onFinish) {
8335
8347
  return {
8336
8348
  started: false,
8337
8349
  reason: "unsupported",
8338
- error: `一键${mode === "uninstall" ? "卸载" : "配置"}只支持 Windows,请在 CLI 所在机器上手动处理 ${command}。`
8350
+ error: `一键${mode === "uninstall" ? "卸载" : mode === "logout" ? "退出登录" : mode === "login" ? "重新登录" : "配置"}只支持 Windows,请在 CLI 所在机器上手动处理 ${command}。`
8339
8351
  };
8340
8352
  }
8341
8353
  const script = setupScriptPath(brand);
@@ -8767,15 +8779,16 @@ async function handleApi(req, res, adapters) {
8767
8779
  return;
8768
8780
  }
8769
8781
  if (!isSetupMode(parsed.mode)) {
8770
- send(res, 400, { error: "mode 只接受 configure、login、uninstall 或 cancel" });
8782
+ send(res, 400, { error: "mode 只接受 configure、login、logout、uninstall 或 cancel" });
8771
8783
  return;
8772
8784
  }
8773
8785
  const qoder = adapters[postBrand];
8774
- const result = startSetup(postBrand, parsed.mode, (code) => {
8775
- if (code === 0) {
8776
- qoder.invalidateCatalog();
8777
- qoder.invalidateUsage();
8778
- }
8786
+ const mode = parsed.mode;
8787
+ const result = startSetup(postBrand, mode, (code) => {
8788
+ if (code !== 0) return;
8789
+ qoder.invalidateCatalog();
8790
+ qoder.invalidateUsage();
8791
+ if (mode === "logout") qoder.closeSessions();
8779
8792
  });
8780
8793
  if (!result.started) {
8781
8794
  send(res, result.reason === "busy" ? 409 : result.reason === "unsupported" ? 501 : 500, { error: result.error });
@@ -290,6 +290,15 @@ export declare class QoderAdapter extends LlmAdapter {
290
290
  * still knows the attachment was there.
291
291
  */
292
292
  private buildFeed;
293
+ /**
294
+ * Drop every warm inner session without unloading the plugin.
295
+ *
296
+ * Signing out has to invalidate them: each holds a CLI process that already
297
+ * loaded its credentials, so it would keep answering as the account that was
298
+ * just signed out. The next turn starts a fresh process, which then reports
299
+ * the signed-out state honestly.
300
+ */
301
+ closeSessions(): void;
293
302
  /** Tear down every warm inner session (plugin dispose). */
294
303
  close(): void;
295
304
  }
@@ -21,8 +21,8 @@ import type { QoderBrand } from './brand.ts';
21
21
  export declare const SCRIPT_NAME = "setup-qoderclicn.bat";
22
22
  /** The helper script for one edition. */
23
23
  export declare function scriptNameOf(brand: QoderBrand): string;
24
- /** What the page may ask for: install/sign in, only sign in, or uninstall. */
25
- export type SetupMode = 'configure' | 'login' | 'uninstall';
24
+ /** What the page may ask for: install/sign in, only sign in, sign out, uninstall. */
25
+ export type SetupMode = 'configure' | 'login' | 'logout' | 'uninstall';
26
26
  /** Whether a value is one of the modes the page may request. */
27
27
  export declare function isSetupMode(value: unknown): value is SetupMode;
28
28
  /** Snapshot the page polls. Always safe to render; empty before the first run. */
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-agent-sdk-bridge",
3
3
  "displayName": "Agent SDK Bridge",
4
4
  "description": "DeepSeek Harness LLM adapter bridge for Qoder CN, Qoder International, Tencent CodeBuddy and MiniMax Code subscriptions. It reuses each provider's own SDK or official ACP server and CLI login, shows available quota, and exposes per-provider settings pages with independent international and mainland login regions.",
5
- "version": "1.2.0",
5
+ "version": "1.2.1",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",
@@ -22,6 +22,7 @@ set "PKG=@qoder-ai/qodercli"
22
22
  set "MODE=setup"
23
23
  if /I "%~1"=="--check" set "MODE=check"
24
24
  if /I "%~1"=="--login" set "MODE=login"
25
+ if /I "%~1"=="--logout" set "MODE=logout"
25
26
  if /I "%~1"=="--uninstall" set "MODE=uninstall"
26
27
  if /I "%~1"=="/?" goto :usage
27
28
 
@@ -29,13 +30,16 @@ echo.
29
30
  echo ==============================================================
30
31
  if "%MODE%"=="check" echo Qoder CLI - check only, nothing installed or changed
31
32
  if "%MODE%"=="login" echo Qoder CLI - re-login only, nothing installed
33
+ if "%MODE%"=="logout" echo Qoder CLI - sign out, removing the saved credential
32
34
  if "%MODE%"=="setup" echo Qoder CLI - install and sign-in wizard
33
35
  if "%MODE%"=="uninstall" echo Qoder CLI - remove the global CLI package
34
36
  echo ==============================================================
35
37
 
36
38
  rem ---------------------------------------------------------------- 1 node
37
39
  echo.
38
- echo [1/5] Node.js and npm
40
+ if "%MODE%"=="logout" echo [1/3] Node.js and npm
41
+ if "%MODE%"=="uninstall" echo [1/3] Node.js and npm
42
+ if not "%MODE%"=="logout" if not "%MODE%"=="uninstall" echo [1/5] Node.js and npm
39
43
  where node >nul 2>nul
40
44
  if errorlevel 1 (
41
45
  echo [X] node not found. Install Node.js LTS first:
@@ -57,6 +61,7 @@ for /f "delims=" %%P in ('npm config get prefix 2^>nul') do set "NPREFIX=%%P"
57
61
  if defined NPREFIX set "PATH=%NPREFIX%;%PATH%"
58
62
 
59
63
  if "%MODE%"=="uninstall" goto :uninstall
64
+ if "%MODE%"=="logout" goto :logout
60
65
 
61
66
  rem ------------------------------------------------------------- 2 detect
62
67
  echo.
@@ -229,7 +234,7 @@ goto :done
229
234
 
230
235
  :uninstall
231
236
  echo.
232
- echo [1/2] Uninstall %PKG%
237
+ echo [2/3] Uninstall %PKG%
233
238
  call npm uninstall -g "%PKG%"
234
239
  if errorlevel 1 (
235
240
  echo [X] npm uninstall failed.
@@ -242,7 +247,7 @@ rem npm leaves the scope directory and the shims behind, and both the
242
247
  rem plugin's CLI lookup and the page's "installed?" badge read them. Clearing
243
248
  rem them here is what actually makes the page switch back to "install".
244
249
  echo.
245
- echo [2/2] Clean leftovers
250
+ echo [3/3] Clean leftovers
246
251
  if exist "%APPDATA%\npm\node_modules\@qoder-ai\qodercli" rd /s /q "%APPDATA%\npm\node_modules\@qoder-ai\qodercli" 2>nul
247
252
  dir /b "%APPDATA%\npm\node_modules\@qoder-ai" 2>nul | findstr /r "." >nul
248
253
  if errorlevel 1 rd /s /q "%APPDATA%\npm\node_modules\@qoder-ai" 2>nul
@@ -256,6 +261,54 @@ echo run this script again without --uninstall to reinstall and sign in.
256
261
  echo ==============================================================
257
262
  goto :done
258
263
 
264
+ :logout
265
+ echo.
266
+ echo [2/3] Find the CLI
267
+ set "QCMD="
268
+ for /f "delims=" %%P in ('where qodercli.cmd 2^>nul') do if not defined QCMD set "QCMD=%%P"
269
+ if not defined QCMD if exist "%APPDATA%\\npm\\qodercli.cmd" set "QCMD=%APPDATA%\\npm\\qodercli.cmd"
270
+ if not defined QCMD (
271
+ echo [X] qodercli is not installed, so there is no sign-in to clear.
272
+ echo Run this script without an argument to install it.
273
+ goto :fail
274
+ )
275
+ echo [OK] !QCMD!
276
+
277
+ rem The CLI has no logout subcommand: its only credential is the encrypted
278
+ rem ~/.qoder/.auth/user file, and a fresh process with that file gone reports
279
+ rem no Username. machine_id stays, because it identifies this machine rather
280
+ rem than the account.
281
+ echo.
282
+ echo [3/3] Remove the saved sign-in
283
+ set "AUTH=%USERPROFILE%\\.qoder\\.auth\\user"
284
+ if exist "%AUTH%" (
285
+ del /q "%AUTH%" 2>nul
286
+ if exist "%AUTH%" (
287
+ echo [X] could not remove %AUTH%
288
+ echo Close DSH and any running qodercli, then try again.
289
+ goto :fail
290
+ )
291
+ echo [OK] saved credential removed
292
+ ) else (
293
+ echo [--] no saved credential found; nothing to remove
294
+ )
295
+ set "ST=%TEMP%\\setup-qodercli-status.txt"
296
+ call "!QCMD!" status > "%ST%" 2>&1
297
+ findstr /I /C:"Username" "%ST%" >nul 2>nul
298
+ if not errorlevel 1 (
299
+ echo [X] the CLI still reports a signed-in user.
300
+ echo Close DSH and try again; if it persists, remove
301
+ echo %AUTH% by hand.
302
+ goto :fail
303
+ )
304
+ echo [OK] signed out; the next login asks for a fresh browser sign-in
305
+ echo.
306
+ echo ==============================================================
307
+ echo You are signed out of Qoder International. Quota is cleared
308
+ echo and open sessions were closed; sign in again to continue.
309
+ echo ==============================================================
310
+ goto :done
311
+
259
312
  rem Delete the npm shim trio for each name given, ignoring absent ones.
260
313
  :delshims
261
314
  if "%~1"=="" goto :eof
@@ -270,6 +323,7 @@ echo.
270
323
  echo setup-qodercli.bat install what is missing, then sign in
271
324
  echo setup-qodercli.bat --check verify only: version / sign-in / dirs / models
272
325
  echo setup-qodercli.bat --login re-open the browser sign-in, install nothing
326
+ echo setup-qodercli.bat --logout sign out, removing the saved credential
273
327
  echo setup-qodercli.bat --gui as above but never pauses, for the DSH page
274
328
  echo setup-qodercli.bat --uninstall remove the global CLI package
275
329
  echo setup-qodercli.bat /? this help
@@ -22,6 +22,7 @@ set "PKG=@qodercn-ai/qoderclicn"
22
22
  set "MODE=setup"
23
23
  if /I "%~1"=="--check" set "MODE=check"
24
24
  if /I "%~1"=="--login" set "MODE=login"
25
+ if /I "%~1"=="--logout" set "MODE=logout"
25
26
  if /I "%~1"=="--uninstall" set "MODE=uninstall"
26
27
  if /I "%~1"=="/?" goto :usage
27
28
 
@@ -29,13 +30,16 @@ echo.
29
30
  echo ==============================================================
30
31
  if "%MODE%"=="check" echo Qoder CN CLI - check only, nothing installed or changed
31
32
  if "%MODE%"=="login" echo Qoder CN CLI - re-login only, nothing installed
33
+ if "%MODE%"=="logout" echo Qoder CN CLI - sign out (removes the saved credential)
32
34
  if "%MODE%"=="setup" echo Qoder CN CLI - install and sign-in wizard
33
35
  if "%MODE%"=="uninstall" echo Qoder CN CLI - remove the global CLI package
34
36
  echo ==============================================================
35
37
 
36
38
  rem ---------------------------------------------------------------- 1 node
37
39
  echo.
38
- echo [1/5] Node.js and npm
40
+ if "%MODE%"=="logout" echo [1/3] Node.js and npm
41
+ if "%MODE%"=="uninstall" echo [1/3] Node.js and npm
42
+ if not "%MODE%"=="logout" if not "%MODE%"=="uninstall" echo [1/5] Node.js and npm
39
43
  where node >nul 2>nul
40
44
  if errorlevel 1 (
41
45
  echo [X] node not found. Install Node.js LTS first:
@@ -57,6 +61,7 @@ for /f "delims=" %%P in ('npm config get prefix 2^>nul') do set "NPREFIX=%%P"
57
61
  if defined NPREFIX set "PATH=%NPREFIX%;%PATH%"
58
62
 
59
63
  if "%MODE%"=="uninstall" goto :uninstall
64
+ if "%MODE%"=="logout" goto :logout
60
65
 
61
66
  rem ------------------------------------------------------------- 2 detect
62
67
  echo.
@@ -229,7 +234,7 @@ goto :done
229
234
 
230
235
  :uninstall
231
236
  echo.
232
- echo [1/2] Uninstall %PKG%
237
+ echo [2/3] Uninstall %PKG%
233
238
  call npm uninstall -g "%PKG%"
234
239
  if errorlevel 1 (
235
240
  echo [X] npm uninstall failed.
@@ -242,7 +247,7 @@ rem npm leaves the scope directory and the shims behind, and both the
242
247
  rem plugin's CLI lookup and the page's "installed?" badge read them. Clearing
243
248
  rem them here is what actually makes the page switch back to "install".
244
249
  echo.
245
- echo [2/2] Clean leftovers
250
+ echo [3/3] Clean leftovers
246
251
  if exist "%APPDATA%\npm\node_modules\@qodercn-ai\qoderclicn" rd /s /q "%APPDATA%\npm\node_modules\@qodercn-ai\qoderclicn" 2>nul
247
252
  dir /b "%APPDATA%\npm\node_modules\@qodercn-ai" 2>nul | findstr /r "." >nul
248
253
  if errorlevel 1 rd /s /q "%APPDATA%\npm\node_modules\@qodercn-ai" 2>nul
@@ -256,6 +261,54 @@ echo run this script again without --uninstall to reinstall and sign in.
256
261
  echo ==============================================================
257
262
  goto :done
258
263
 
264
+ :logout
265
+ echo.
266
+ echo [2/3] Find the CLI
267
+ set "QCMD="
268
+ for /f "delims=" %%P in ('where qoderclicn.cmd 2^>nul') do if not defined QCMD set "QCMD=%%P"
269
+ if not defined QCMD if exist "%APPDATA%\\npm\\qoderclicn.cmd" set "QCMD=%APPDATA%\\npm\\qoderclicn.cmd"
270
+ if not defined QCMD (
271
+ echo [X] qoderclicn is not installed, so there is no sign-in to clear.
272
+ echo Run this script without an argument to install it.
273
+ goto :fail
274
+ )
275
+ echo [OK] !QCMD!
276
+
277
+ rem The CLI has no logout subcommand: its only credential is the encrypted
278
+ rem ~/.qoder-cn/.auth/user file, and a fresh process with that file gone reports
279
+ rem no Username. machine_id stays, because it identifies this machine rather
280
+ rem than the account.
281
+ echo.
282
+ echo [3/3] Remove the saved sign-in
283
+ set "AUTH=%USERPROFILE%\\.qoder-cn\\.auth\\user"
284
+ if exist "%AUTH%" (
285
+ del /q "%AUTH%" 2>nul
286
+ if exist "%AUTH%" (
287
+ echo [X] could not remove %AUTH%
288
+ echo Close DSH and any running qoderclicn, then try again.
289
+ goto :fail
290
+ )
291
+ echo [OK] saved credential removed
292
+ ) else (
293
+ echo [--] no saved credential found; nothing to remove
294
+ )
295
+ set "ST=%TEMP%\\setup-qoderclicn-status.txt"
296
+ call "!QCMD!" status > "%ST%" 2>&1
297
+ findstr /I /C:"Username" "%ST%" >nul 2>nul
298
+ if not errorlevel 1 (
299
+ echo [X] the CLI still reports a signed-in user.
300
+ echo Close DSH and try again; if it persists, remove
301
+ echo %AUTH% by hand.
302
+ goto :fail
303
+ )
304
+ echo [OK] signed out; the next login asks for a fresh browser sign-in
305
+ echo.
306
+ echo ==============================================================
307
+ echo You are signed out of Qoder CN. Quota is cleared and open
308
+ echo sessions were closed; sign in again from the page to continue.
309
+ echo ==============================================================
310
+ goto :done
311
+
259
312
  rem Delete the npm shim trio for each name given, ignoring absent ones.
260
313
  :delshims
261
314
  if "%~1"=="" goto :eof
@@ -270,6 +323,7 @@ echo.
270
323
  echo setup-qoderclicn.bat install what is missing, then sign in
271
324
  echo setup-qoderclicn.bat --check verify only: version / sign-in / dirs / models
272
325
  echo setup-qoderclicn.bat --login re-open the browser sign-in, install nothing
326
+ echo setup-qoderclicn.bat --logout sign out, removing the saved credential
273
327
  echo setup-qoderclicn.bat --gui as above but never pauses, for the DSH page
274
328
  echo setup-qoderclicn.bat --uninstall remove the global CLI package
275
329
  echo setup-qoderclicn.bat /? this help
package/src/adapter.ts CHANGED
@@ -782,6 +782,18 @@ export class QoderAdapter extends LlmAdapter {
782
782
  return pixels === 0 ? content.map(block => block.type === 'text' ? block.text : '').join('\n\n') : content
783
783
  }
784
784
 
785
+ /**
786
+ * Drop every warm inner session without unloading the plugin.
787
+ *
788
+ * Signing out has to invalidate them: each holds a CLI process that already
789
+ * loaded its credentials, so it would keep answering as the account that was
790
+ * just signed out. The next turn starts a fresh process, which then reports
791
+ * the signed-out state honestly.
792
+ */
793
+ closeSessions(): void {
794
+ this.sessions.closeAll()
795
+ }
796
+
785
797
  /** Tear down every warm inner session (plugin dispose). */
786
798
  close(): void {
787
799
  this.sessions.closeAll()
package/src/api.ts CHANGED
@@ -400,15 +400,19 @@ export async function handleApi(
400
400
  return
401
401
  }
402
402
  if (!isSetupMode(parsed.mode)) {
403
- send(res, 400, { error: 'mode 只接受 configure、login、uninstall 或 cancel' })
403
+ send(res, 400, { error: 'mode 只接受 configure、login、logout、uninstall 或 cancel' })
404
404
  return
405
405
  }
406
406
  const qoder = adapters[postBrand] as QoderAdapter
407
- const result = startSetup(postBrand, parsed.mode, code => {
408
- if (code === 0) {
409
- qoder.invalidateCatalog()
410
- qoder.invalidateUsage()
411
- }
407
+ const mode = parsed.mode
408
+ const result = startSetup(postBrand, mode, code => {
409
+ if (code !== 0) return
410
+ qoder.invalidateCatalog()
411
+ qoder.invalidateUsage()
412
+ // A warm session owns a CLI process that loaded its credentials at
413
+ // start-up; after a sign-out it would keep answering as the account
414
+ // that just left. Dropping them makes the next turn start clean.
415
+ if (mode === 'logout') qoder.closeSessions()
412
416
  })
413
417
  if (!result.started) {
414
418
  const status = result.reason === 'busy' ? 409 : result.reason === 'unsupported' ? 501 : 500
package/src/setup.ts CHANGED
@@ -35,19 +35,20 @@ export function scriptNameOf(brand: QoderBrand): string {
35
35
  return brandProfile(brand).setupScript ?? SCRIPT_NAME
36
36
  }
37
37
 
38
- /** What the page may ask for: install/sign in, only sign in, or uninstall. */
39
- export type SetupMode = 'configure' | 'login' | 'uninstall'
38
+ /** What the page may ask for: install/sign in, only sign in, sign out, uninstall. */
39
+ export type SetupMode = 'configure' | 'login' | 'logout' | 'uninstall'
40
40
 
41
41
  /** The one command-line flag each mode maps to. Never a user-supplied string. */
42
42
  const FLAGS: Record<SetupMode, string> = {
43
43
  configure: '--gui',
44
44
  login: '--login',
45
+ logout: '--logout',
45
46
  uninstall: '--uninstall',
46
47
  }
47
48
 
48
49
  /** Whether a value is one of the modes the page may request. */
49
50
  export function isSetupMode(value: unknown): value is SetupMode {
50
- return value === 'configure' || value === 'login' || value === 'uninstall'
51
+ return value === 'configure' || value === 'login' || value === 'logout' || value === 'uninstall'
51
52
  }
52
53
 
53
54
  /** Cap on kept output, so a chatty `npm install` cannot grow without bound. */
@@ -165,7 +166,9 @@ export function startSetup(
165
166
  }
166
167
  if (process.platform !== 'win32') {
167
168
  const command = brandProfile(brand).cliCommands[0]
168
- const action = mode === 'uninstall' ? '卸载' : '配置'
169
+ const action = mode === 'uninstall'
170
+ ? '卸载'
171
+ : mode === 'logout' ? '退出登录' : mode === 'login' ? '重新登录' : '配置'
169
172
  return {
170
173
  started: false,
171
174
  reason: 'unsupported',