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.
@@ -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.
@@ -74,6 +79,18 @@ if defined CLIV (
74
79
  echo [--] qodercli not found
75
80
  )
76
81
 
82
+ rem The SDK speaks a wire protocol that is pinned to one CLI release. CLI
83
+ rem 1.1.81 dropped the old SDK session handshake and exits 42 on it, which the
84
+ rem settings page could only report as "process exited with code 42". Reading
85
+ rem the requirement from the installed SDK keeps this helper on a version the
86
+ rem plugin can actually talk to, instead of whatever latest happens to be.
87
+ set "WANTV="
88
+ set "MANIFEST=%~dp0..\node_modules\@qoder-ai\qoder-agent-sdk\dist\runtime-manifest.json"
89
+ if exist "%MANIFEST%" for /f "usebackq delims=" %%V in (`node -e "try{process.stdout.write(require(process.argv[1]).qoderCliVersion||'')}catch(e){}" "%MANIFEST%"`) do set "WANTV=%%V"
90
+ set "PKGSPEC=%PKG%"
91
+ if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
92
+ if defined WANTV echo [--] this plugin needs CLI !WANTV!
93
+
77
94
  rem ------------------------------------------------------------- 3 install
78
95
  echo.
79
96
  echo [3/5] Install the CLI
@@ -83,16 +100,29 @@ if not "%MODE%"=="setup" (
83
100
  echo Run this script without an argument to install it.
84
101
  goto :fail
85
102
  )
103
+ if defined WANTV if not "!CLIV!"=="!WANTV!" (
104
+ echo [X] installed !CLIV!, but this plugin needs !WANTV!.
105
+ echo Run this script without an argument to install it.
106
+ goto :fail
107
+ )
86
108
  echo [--] %MODE% mode, skipping install
87
109
  goto :login
88
110
  )
89
111
  if defined QCMD (
90
- echo [--] already on %CLIV%, skipping install.
112
+ if not defined WANTV goto :skipinstall
113
+ if "!CLIV!"=="!WANTV!" goto :skipinstall
114
+ echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
115
+ goto :doinstall
116
+ )
117
+ :skipinstall
118
+ if defined QCMD (
119
+ echo [--] already on !CLIV!, skipping install.
91
120
  echo latest version: qodercli update
92
121
  goto :login
93
122
  )
94
- echo running npm install -g %PKG% ... needs network, please wait
95
- call npm install -g "%PKG%"
123
+ :doinstall
124
+ echo running npm install -g %PKGSPEC% ... needs network, please wait
125
+ call npm install -g "%PKGSPEC%"
96
126
  if not errorlevel 1 goto :installed
97
127
  echo [X] npm install failed. Usual causes:
98
128
  echo 1 DEPTH_ZERO_SELF_SIGNED_CERT
@@ -105,6 +135,7 @@ goto :fail
105
135
 
106
136
  :installed
107
137
  set "QCMD="
138
+ set "CLIV="
108
139
  for /f "delims=" %%P in ('where qodercli.cmd 2^>nul') do if not defined QCMD set "QCMD=%%P"
109
140
  if not defined QCMD if exist "%APPDATA%\npm\qodercli.cmd" set "QCMD=%APPDATA%\npm\qodercli.cmd"
110
141
  if not defined QCMD (
@@ -203,7 +234,7 @@ goto :done
203
234
 
204
235
  :uninstall
205
236
  echo.
206
- echo [2/2] Uninstall %PKG%
237
+ echo [2/3] Uninstall %PKG%
207
238
  call npm uninstall -g "%PKG%"
208
239
  if errorlevel 1 (
209
240
  echo [X] npm uninstall failed.
@@ -211,18 +242,88 @@ if errorlevel 1 (
211
242
  goto :fail
212
243
  )
213
244
  echo [OK] %PKG% removed
245
+
246
+ rem npm leaves the scope directory and the shims behind, and both the
247
+ rem plugin's CLI lookup and the page's "installed?" badge read them. Clearing
248
+ rem them here is what actually makes the page switch back to "install".
249
+ echo.
250
+ echo [3/3] Clean leftovers
251
+ if exist "%APPDATA%\npm\node_modules\@qoder-ai\qodercli" rd /s /q "%APPDATA%\npm\node_modules\@qoder-ai\qodercli" 2>nul
252
+ dir /b "%APPDATA%\npm\node_modules\@qoder-ai" 2>nul | findstr /r "." >nul
253
+ if errorlevel 1 rd /s /q "%APPDATA%\npm\node_modules\@qoder-ai" 2>nul
254
+ call :delshims qodercli qoder
255
+ echo [OK] shims and empty scope dir cleared
256
+
257
+ echo.
258
+ echo ==============================================================
259
+ echo Uninstalled. Sign-in files under %USERPROFILE%\.qoder are kept;
260
+ echo run this script again without --uninstall to reinstall and sign in.
261
+ echo ==============================================================
262
+ goto :done
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
214
305
  echo.
215
306
  echo ==============================================================
216
- echo Uninstalled. Sign-in files are kept; run this script again
217
- echo without --uninstall to reinstall and sign in.
307
+ echo You are signed out of Qoder International. Quota is cleared
308
+ echo and open sessions were closed; sign in again to continue.
218
309
  echo ==============================================================
219
310
  goto :done
220
311
 
312
+ rem Delete the npm shim trio for each name given, ignoring absent ones.
313
+ :delshims
314
+ if "%~1"=="" goto :eof
315
+ if exist "%APPDATA%\npm\%~1.cmd" del /q "%APPDATA%\npm\%~1.cmd" 2>nul
316
+ if exist "%APPDATA%\npm\%~1.ps1" del /q "%APPDATA%\npm\%~1.ps1" 2>nul
317
+ if exist "%APPDATA%\npm\%~1" del /q "%APPDATA%\npm\%~1" 2>nul
318
+ shift
319
+ goto :delshims
320
+
221
321
  :usage
222
322
  echo.
223
323
  echo setup-qodercli.bat install what is missing, then sign in
224
324
  echo setup-qodercli.bat --check verify only: version / sign-in / dirs / models
225
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
226
327
  echo setup-qodercli.bat --gui as above but never pauses, for the DSH page
227
328
  echo setup-qodercli.bat --uninstall remove the global CLI package
228
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.
@@ -74,6 +79,18 @@ if defined CLIV (
74
79
  echo [--] qoderclicn not found
75
80
  )
76
81
 
82
+ rem The SDK speaks a wire protocol that is pinned to one CLI release. CLI
83
+ rem 1.1.81 dropped the old SDK session handshake and exits 42 on it, which the
84
+ rem settings page could only report as "process exited with code 42". Reading
85
+ rem the requirement from the installed SDK keeps this helper on a version the
86
+ rem plugin can actually talk to, instead of whatever latest happens to be.
87
+ set "WANTV="
88
+ set "MANIFEST=%~dp0..\node_modules\@qodercn-ai\qodercn-agent-sdk\dist\runtime-manifest.json"
89
+ if exist "%MANIFEST%" for /f "usebackq delims=" %%V in (`node -e "try{process.stdout.write(require(process.argv[1]).qoderCliVersion||'')}catch(e){}" "%MANIFEST%"`) do set "WANTV=%%V"
90
+ set "PKGSPEC=%PKG%"
91
+ if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
92
+ if defined WANTV echo [--] this plugin needs CLI !WANTV!
93
+
77
94
  rem ------------------------------------------------------------- 3 install
78
95
  echo.
79
96
  echo [3/5] Install the CLI
@@ -83,16 +100,29 @@ if not "%MODE%"=="setup" (
83
100
  echo Run this script without an argument to install it.
84
101
  goto :fail
85
102
  )
103
+ if defined WANTV if not "!CLIV!"=="!WANTV!" (
104
+ echo [X] installed !CLIV!, but this plugin needs !WANTV!.
105
+ echo Run this script without an argument to install it.
106
+ goto :fail
107
+ )
86
108
  echo [--] %MODE% mode, skipping install
87
109
  goto :login
88
110
  )
89
111
  if defined QCMD (
90
- echo [--] already on %CLIV%, skipping install.
112
+ if not defined WANTV goto :skipinstall
113
+ if "!CLIV!"=="!WANTV!" goto :skipinstall
114
+ echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
115
+ goto :doinstall
116
+ )
117
+ :skipinstall
118
+ if defined QCMD (
119
+ echo [--] already on !CLIV!, skipping install.
91
120
  echo latest version: qoderclicn update
92
121
  goto :login
93
122
  )
94
- echo running npm install -g %PKG% ... needs network, please wait
95
- call npm install -g "%PKG%"
123
+ :doinstall
124
+ echo running npm install -g %PKGSPEC% ... needs network, please wait
125
+ call npm install -g "%PKGSPEC%"
96
126
  if not errorlevel 1 goto :installed
97
127
  echo [X] npm install failed. Usual causes:
98
128
  echo 1 DEPTH_ZERO_SELF_SIGNED_CERT
@@ -105,6 +135,7 @@ goto :fail
105
135
 
106
136
  :installed
107
137
  set "QCMD="
138
+ set "CLIV="
108
139
  for /f "delims=" %%P in ('where qoderclicn.cmd 2^>nul') do if not defined QCMD set "QCMD=%%P"
109
140
  if not defined QCMD if exist "%APPDATA%\npm\qoderclicn.cmd" set "QCMD=%APPDATA%\npm\qoderclicn.cmd"
110
141
  if not defined QCMD (
@@ -203,7 +234,7 @@ goto :done
203
234
 
204
235
  :uninstall
205
236
  echo.
206
- echo [2/2] Uninstall %PKG%
237
+ echo [2/3] Uninstall %PKG%
207
238
  call npm uninstall -g "%PKG%"
208
239
  if errorlevel 1 (
209
240
  echo [X] npm uninstall failed.
@@ -211,18 +242,88 @@ if errorlevel 1 (
211
242
  goto :fail
212
243
  )
213
244
  echo [OK] %PKG% removed
245
+
246
+ rem npm leaves the scope directory and the shims behind, and both the
247
+ rem plugin's CLI lookup and the page's "installed?" badge read them. Clearing
248
+ rem them here is what actually makes the page switch back to "install".
249
+ echo.
250
+ echo [3/3] Clean leftovers
251
+ if exist "%APPDATA%\npm\node_modules\@qodercn-ai\qoderclicn" rd /s /q "%APPDATA%\npm\node_modules\@qodercn-ai\qoderclicn" 2>nul
252
+ dir /b "%APPDATA%\npm\node_modules\@qodercn-ai" 2>nul | findstr /r "." >nul
253
+ if errorlevel 1 rd /s /q "%APPDATA%\npm\node_modules\@qodercn-ai" 2>nul
254
+ call :delshims qoderclicn qodercn
255
+ echo [OK] shims and empty scope dir cleared
256
+
257
+ echo.
258
+ echo ==============================================================
259
+ echo Uninstalled. Sign-in files under %USERPROFILE%\.qoder-cn are kept;
260
+ echo run this script again without --uninstall to reinstall and sign in.
261
+ echo ==============================================================
262
+ goto :done
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
214
305
  echo.
215
306
  echo ==============================================================
216
- echo Uninstalled. Sign-in files are kept; run this script again
217
- echo without --uninstall to reinstall and sign in.
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.
218
309
  echo ==============================================================
219
310
  goto :done
220
311
 
312
+ rem Delete the npm shim trio for each name given, ignoring absent ones.
313
+ :delshims
314
+ if "%~1"=="" goto :eof
315
+ if exist "%APPDATA%\npm\%~1.cmd" del /q "%APPDATA%\npm\%~1.cmd" 2>nul
316
+ if exist "%APPDATA%\npm\%~1.ps1" del /q "%APPDATA%\npm\%~1.ps1" 2>nul
317
+ if exist "%APPDATA%\npm\%~1" del /q "%APPDATA%\npm\%~1" 2>nul
318
+ shift
319
+ goto :delshims
320
+
221
321
  :usage
222
322
  echo.
223
323
  echo setup-qoderclicn.bat install what is missing, then sign in
224
324
  echo setup-qoderclicn.bat --check verify only: version / sign-in / dirs / models
225
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
226
327
  echo setup-qoderclicn.bat --gui as above but never pauses, for the DSH page
227
328
  echo setup-qoderclicn.bat --uninstall remove the global CLI package
228
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
@@ -26,7 +26,7 @@ import type { MinimaxAdapter } from './minimax-adapter.ts'
26
26
  import type { BrandId, CodeBuddyRegion, MinimaxRegion } from './brand.ts'
27
27
  import { isBrandId, isCodeBuddyRegion } from './brand.ts'
28
28
  import { priceFactorOf } from './models.ts'
29
- import { isSetupMode, readSetupStatus, startSetup } from './setup.ts'
29
+ import { cancelSetup, isSetupMode, readSetupStatus, startSetup } from './setup.ts'
30
30
  import { isMinimaxSetupMode, readMinimaxSetupStatus, startMinimaxSetup } from './minimax-cli.ts'
31
31
 
32
32
  /** Route prefix this plugin owns; the client resolves it relative to the page. */
@@ -394,16 +394,25 @@ export async function handleApi(
394
394
  send(res, 200, readMinimaxSetupStatus())
395
395
  return
396
396
  }
397
+ if (parsed.mode === 'cancel') {
398
+ cancelSetup(postBrand)
399
+ send(res, 200, readSetupStatus(postBrand))
400
+ return
401
+ }
397
402
  if (!isSetupMode(parsed.mode)) {
398
- send(res, 400, { error: 'mode 只接受 configure、login 或 uninstall' })
403
+ send(res, 400, { error: 'mode 只接受 configure、login、logout、uninstall 或 cancel' })
399
404
  return
400
405
  }
401
406
  const qoder = adapters[postBrand] as QoderAdapter
402
- const result = startSetup(postBrand, parsed.mode, code => {
403
- if (code === 0) {
404
- qoder.invalidateCatalog()
405
- qoder.invalidateUsage()
406
- }
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()
407
416
  })
408
417
  if (!result.started) {
409
418
  const status = result.reason === 'busy' ? 409 : result.reason === 'unsupported' ? 501 : 500