dsh-agent-sdk-bridge 1.1.8 → 1.2.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.
@@ -90,17 +90,38 @@ export declare function qoderCliOptions(brand?: QoderBrand, lookup?: CliLookup):
90
90
  */
91
91
  export declare function isForeignCliPath(brand: QoderBrand, candidate: string): boolean;
92
92
  /**
93
- * A `QODERCLI_PATH` that names the other edition, when this one has no CLI.
93
+ * Why this edition has no usable CLI, when `QODERCLI_PATH` explains it.
94
94
  *
95
- * The SDKs read that variable from the parent process before any option this
96
- * plugin can pass, so when it is foreign and this edition has nothing of its
97
- * own, the only honest answer is a configuration error — spawning the other
98
- * edition's CLI would answer with the other edition's account.
95
+ * `QODERCLI_PATH` predates the international edition and some installers
96
+ * export it machine-wide. Both SDKs read it from the parent process before any
97
+ * option this plugin can pass, so a value naming the *other* edition would
98
+ * hand this edition's session the other account. The lookup therefore never
99
+ * offers it ({@link isForeignCliPath}), and this reports the case where it is
100
+ * all the machine has, so the page can ask for the right CLI to be installed.
101
+ *
102
+ * This is a diagnosis, not a second rule: an edition that finds its own CLI is
103
+ * unaffected by the variable. That is what keeps one edition's install from
104
+ * blocking the other's sign-in — the earlier code treated any foreign value as
105
+ * fatal, so a machine that had only the intl CLI installed could not sign in
106
+ * to CN even after installing it if the lookup missed the new package.
99
107
  *
100
108
  * @param brand - the edition the caller is about to start.
101
109
  * @param lookup - the machine to inspect; defaults to this process's.
110
+ * @returns the foreign override when this edition has nothing of its own.
102
111
  */
103
112
  export declare function foreignCliOverride(brand: QoderBrand, lookup?: CliLookup): string | undefined;
113
+ /**
114
+ * The environment one session's child process receives.
115
+ *
116
+ * `QODERCLI_PATH` is stripped when it names the other edition: both SDKs read
117
+ * it from the parent before honouring any option, so leaving it in place would
118
+ * hand the intl session the CN CLI (and the CN account). Every other variable
119
+ * is inherited untouched — the CLI keeps its state in `PATH`-relative dirs.
120
+ *
121
+ * @param brand - which edition's child is being started.
122
+ * @param env - the environment to derive from; defaults to this process's.
123
+ */
124
+ export declare function cliChildEnv(brand: QoderBrand, env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
104
125
  /**
105
126
  * The error text for {@link foreignCliOverride}.
106
127
  *
@@ -109,3 +130,42 @@ export declare function foreignCliOverride(brand: QoderBrand, lookup?: CliLookup
109
130
  * plugin's environment plumbing. The technical reason stays in the lookup.
110
131
  */
111
132
  export declare function cliConflictMessage(brand: QoderBrand): string;
133
+ /**
134
+ * Turn a CLI failure into something a user can act on.
135
+ *
136
+ * The SDK reports an outdated CLI as `Qoder CLI process exited with code 42`,
137
+ * which says nothing about the cause: CLI 1.1.81 removed the worker-session
138
+ * handshake the older SDK spoke, and its own log says so
139
+ * (`sdk_worker_removed: … Upgrade to the latest Qoder SDK version, or roll back
140
+ * the CLI`). The only fix available to a user is reinstalling the pair through
141
+ * the bundled helper, so say that instead of echoing the number.
142
+ *
143
+ * @param detail - the error text as the SDK reported it.
144
+ * @param brand - which edition's helper the message should name.
145
+ * @returns the original detail, prefixed with the actionable explanation.
146
+ */
147
+ export declare function cliFailureText(detail: string, brand: QoderBrand): string;
148
+ /**
149
+ * The CLI version the installed SDK expects, read from its runtime manifest.
150
+ *
151
+ * Each SDK release pins one CLI build: the two speak a wire protocol that
152
+ * changes between them, and a mismatch fails every session with a bare exit
153
+ * code. The bundled helper reads the same file, so the page and the helper
154
+ * agree on which build to install.
155
+ *
156
+ * @param brand - which edition's SDK to inspect.
157
+ * @returns the pinned version, or undefined when the manifest is unreadable.
158
+ */
159
+ export declare function requiredCliVersion(brand: QoderBrand): string | undefined;
160
+ /**
161
+ * The version of the installed CLI, read from its own package manifest.
162
+ *
163
+ * Read from disk rather than by running `--version`: a settings-page poll must
164
+ * not spawn a process every second, and the npm package always ships a
165
+ * manifest next to its entry. A native build without one answers undefined,
166
+ * which callers treat as "unknown" and never as a mismatch.
167
+ *
168
+ * @param brand - which edition's CLI to inspect.
169
+ * @returns the installed version, or undefined when it cannot be read.
170
+ */
171
+ export declare function installedCliVersion(brand: QoderBrand): string | undefined;
@@ -35,6 +35,27 @@ export interface SetupStatus {
35
35
  code?: number | null;
36
36
  lines: string[];
37
37
  truncated: boolean;
38
+ /**
39
+ * Whether this edition's CLI is on the machine right now.
40
+ *
41
+ * Read from the same lookup a session uses, not from the last run's exit
42
+ * code: after an uninstall the page must offer "install" again, and a run
43
+ * that ended successfully months ago says nothing about today's machine.
44
+ */
45
+ installed: boolean;
46
+ /** Version of the installed CLI, when its package manifest could be read. */
47
+ cliVersion?: string;
48
+ /** Version this plugin's SDK speaks; the helper installs exactly this one. */
49
+ requiredCliVersion?: string;
50
+ /**
51
+ * The installed CLI speaks a different protocol build than the SDK.
52
+ *
53
+ * Sessions then die with a bare exit code, so the page warns here — before a
54
+ * sign-in — instead of letting the user log in and hit the failure in chat.
55
+ */
56
+ versionMismatch?: boolean;
57
+ /** Whether the last run was stopped from the page rather than finishing. */
58
+ cancelled?: boolean;
38
59
  }
39
60
  /**
40
61
  * Locate one edition's helper inside this package.
@@ -69,6 +90,18 @@ export declare function startSetup(brand: QoderBrand, mode: SetupMode, onFinish?
69
90
  * @param brand - which edition's run to report.
70
91
  */
71
92
  export declare function readSetupStatus(brand?: QoderBrand): SetupStatus;
93
+ /**
94
+ * Abandon the running helper for one edition.
95
+ *
96
+ * `qodercli login` waits for the browser to finish the callback, so closing
97
+ * that tab left the page polling a process that would never return. Killing
98
+ * the run turns it into a finished one (`code` null) so the page can offer the
99
+ * buttons again instead of showing a spinner forever.
100
+ *
101
+ * @param brand - which edition's run to stop.
102
+ * @returns whether a run was actually in flight.
103
+ */
104
+ export declare function cancelSetup(brand: QoderBrand): boolean;
72
105
  /**
73
106
  * Abandon the running helper, if any.
74
107
  *
@@ -31,6 +31,16 @@ export interface UsageSnapshot {
31
31
  account?: AccountInfo;
32
32
  /** Why the quota is missing, in the CLI's own words. */
33
33
  error?: string;
34
+ /**
35
+ * Whether this edition's CLI is absent from the machine right now.
36
+ *
37
+ * The page keeps its last good reading visible while a refresh fails, which
38
+ * is right for a dropped network — but not after an uninstall: the account,
39
+ * plan and credits it shows belong to a CLI that is no longer installed.
40
+ * This flag tells the page to drop that reading instead of labelling it
41
+ * "last reading".
42
+ */
43
+ cliMissing?: boolean;
34
44
  }
35
45
  /** Cached quota reader for one brand. */
36
46
  export declare class QoderUsage {
@@ -54,5 +64,7 @@ export declare class QoderUsage {
54
64
  read(fresh?: boolean): Promise<UsageSnapshot>;
55
65
  /** Drop the cached reading. */
56
66
  invalidate(): void;
67
+ /** The reading for a machine whose CLI is not installed. */
68
+ private missingCli;
57
69
  private fetch;
58
70
  }
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.1.8",
5
+ "version": "1.2.0",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",
@@ -85,8 +85,8 @@
85
85
  },
86
86
  "dependencies": {
87
87
  "@agentclientprotocol/sdk": "^1.9.0",
88
- "@qoder-ai/qoder-agent-sdk": "^1.0.56",
89
- "@qodercn-ai/qodercn-agent-sdk": "^1.0.51",
88
+ "@qoder-ai/qoder-agent-sdk": "^1.0.58",
89
+ "@qodercn-ai/qodercn-agent-sdk": "^1.0.58",
90
90
  "@tencent-ai/agent-sdk": "^0.3.289",
91
91
  "zod": "^4.4.3"
92
92
  },
@@ -74,6 +74,18 @@ if defined CLIV (
74
74
  echo [--] qodercli not found
75
75
  )
76
76
 
77
+ rem The SDK speaks a wire protocol that is pinned to one CLI release. CLI
78
+ rem 1.1.81 dropped the old SDK session handshake and exits 42 on it, which the
79
+ rem settings page could only report as "process exited with code 42". Reading
80
+ rem the requirement from the installed SDK keeps this helper on a version the
81
+ rem plugin can actually talk to, instead of whatever latest happens to be.
82
+ set "WANTV="
83
+ set "MANIFEST=%~dp0..\node_modules\@qoder-ai\qoder-agent-sdk\dist\runtime-manifest.json"
84
+ 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"
85
+ set "PKGSPEC=%PKG%"
86
+ if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
87
+ if defined WANTV echo [--] this plugin needs CLI !WANTV!
88
+
77
89
  rem ------------------------------------------------------------- 3 install
78
90
  echo.
79
91
  echo [3/5] Install the CLI
@@ -83,16 +95,29 @@ if not "%MODE%"=="setup" (
83
95
  echo Run this script without an argument to install it.
84
96
  goto :fail
85
97
  )
98
+ if defined WANTV if not "!CLIV!"=="!WANTV!" (
99
+ echo [X] installed !CLIV!, but this plugin needs !WANTV!.
100
+ echo Run this script without an argument to install it.
101
+ goto :fail
102
+ )
86
103
  echo [--] %MODE% mode, skipping install
87
104
  goto :login
88
105
  )
89
106
  if defined QCMD (
90
- echo [--] already on %CLIV%, skipping install.
107
+ if not defined WANTV goto :skipinstall
108
+ if "!CLIV!"=="!WANTV!" goto :skipinstall
109
+ echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
110
+ goto :doinstall
111
+ )
112
+ :skipinstall
113
+ if defined QCMD (
114
+ echo [--] already on !CLIV!, skipping install.
91
115
  echo latest version: qodercli update
92
116
  goto :login
93
117
  )
94
- echo running npm install -g %PKG% ... needs network, please wait
95
- call npm install -g "%PKG%"
118
+ :doinstall
119
+ echo running npm install -g %PKGSPEC% ... needs network, please wait
120
+ call npm install -g "%PKGSPEC%"
96
121
  if not errorlevel 1 goto :installed
97
122
  echo [X] npm install failed. Usual causes:
98
123
  echo 1 DEPTH_ZERO_SELF_SIGNED_CERT
@@ -105,6 +130,7 @@ goto :fail
105
130
 
106
131
  :installed
107
132
  set "QCMD="
133
+ set "CLIV="
108
134
  for /f "delims=" %%P in ('where qodercli.cmd 2^>nul') do if not defined QCMD set "QCMD=%%P"
109
135
  if not defined QCMD if exist "%APPDATA%\npm\qodercli.cmd" set "QCMD=%APPDATA%\npm\qodercli.cmd"
110
136
  if not defined QCMD (
@@ -203,7 +229,7 @@ goto :done
203
229
 
204
230
  :uninstall
205
231
  echo.
206
- echo [2/2] Uninstall %PKG%
232
+ echo [1/2] Uninstall %PKG%
207
233
  call npm uninstall -g "%PKG%"
208
234
  if errorlevel 1 (
209
235
  echo [X] npm uninstall failed.
@@ -211,13 +237,34 @@ if errorlevel 1 (
211
237
  goto :fail
212
238
  )
213
239
  echo [OK] %PKG% removed
240
+
241
+ rem npm leaves the scope directory and the shims behind, and both the
242
+ rem plugin's CLI lookup and the page's "installed?" badge read them. Clearing
243
+ rem them here is what actually makes the page switch back to "install".
244
+ echo.
245
+ echo [2/2] Clean leftovers
246
+ if exist "%APPDATA%\npm\node_modules\@qoder-ai\qodercli" rd /s /q "%APPDATA%\npm\node_modules\@qoder-ai\qodercli" 2>nul
247
+ dir /b "%APPDATA%\npm\node_modules\@qoder-ai" 2>nul | findstr /r "." >nul
248
+ if errorlevel 1 rd /s /q "%APPDATA%\npm\node_modules\@qoder-ai" 2>nul
249
+ call :delshims qodercli qoder
250
+ echo [OK] shims and empty scope dir cleared
251
+
214
252
  echo.
215
253
  echo ==============================================================
216
- echo Uninstalled. Sign-in files are kept; run this script again
217
- echo without --uninstall to reinstall and sign in.
254
+ echo Uninstalled. Sign-in files under %USERPROFILE%\.qoder are kept;
255
+ echo run this script again without --uninstall to reinstall and sign in.
218
256
  echo ==============================================================
219
257
  goto :done
220
258
 
259
+ rem Delete the npm shim trio for each name given, ignoring absent ones.
260
+ :delshims
261
+ if "%~1"=="" goto :eof
262
+ if exist "%APPDATA%\npm\%~1.cmd" del /q "%APPDATA%\npm\%~1.cmd" 2>nul
263
+ if exist "%APPDATA%\npm\%~1.ps1" del /q "%APPDATA%\npm\%~1.ps1" 2>nul
264
+ if exist "%APPDATA%\npm\%~1" del /q "%APPDATA%\npm\%~1" 2>nul
265
+ shift
266
+ goto :delshims
267
+
221
268
  :usage
222
269
  echo.
223
270
  echo setup-qodercli.bat install what is missing, then sign in
@@ -74,6 +74,18 @@ if defined CLIV (
74
74
  echo [--] qoderclicn not found
75
75
  )
76
76
 
77
+ rem The SDK speaks a wire protocol that is pinned to one CLI release. CLI
78
+ rem 1.1.81 dropped the old SDK session handshake and exits 42 on it, which the
79
+ rem settings page could only report as "process exited with code 42". Reading
80
+ rem the requirement from the installed SDK keeps this helper on a version the
81
+ rem plugin can actually talk to, instead of whatever latest happens to be.
82
+ set "WANTV="
83
+ set "MANIFEST=%~dp0..\node_modules\@qodercn-ai\qodercn-agent-sdk\dist\runtime-manifest.json"
84
+ 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"
85
+ set "PKGSPEC=%PKG%"
86
+ if defined WANTV set "PKGSPEC=%PKG%@%WANTV%"
87
+ if defined WANTV echo [--] this plugin needs CLI !WANTV!
88
+
77
89
  rem ------------------------------------------------------------- 3 install
78
90
  echo.
79
91
  echo [3/5] Install the CLI
@@ -83,16 +95,29 @@ if not "%MODE%"=="setup" (
83
95
  echo Run this script without an argument to install it.
84
96
  goto :fail
85
97
  )
98
+ if defined WANTV if not "!CLIV!"=="!WANTV!" (
99
+ echo [X] installed !CLIV!, but this plugin needs !WANTV!.
100
+ echo Run this script without an argument to install it.
101
+ goto :fail
102
+ )
86
103
  echo [--] %MODE% mode, skipping install
87
104
  goto :login
88
105
  )
89
106
  if defined QCMD (
90
- echo [--] already on %CLIV%, skipping install.
107
+ if not defined WANTV goto :skipinstall
108
+ if "!CLIV!"=="!WANTV!" goto :skipinstall
109
+ echo [--] installed !CLIV!, this plugin needs !WANTV! - reinstalling
110
+ goto :doinstall
111
+ )
112
+ :skipinstall
113
+ if defined QCMD (
114
+ echo [--] already on !CLIV!, skipping install.
91
115
  echo latest version: qoderclicn update
92
116
  goto :login
93
117
  )
94
- echo running npm install -g %PKG% ... needs network, please wait
95
- call npm install -g "%PKG%"
118
+ :doinstall
119
+ echo running npm install -g %PKGSPEC% ... needs network, please wait
120
+ call npm install -g "%PKGSPEC%"
96
121
  if not errorlevel 1 goto :installed
97
122
  echo [X] npm install failed. Usual causes:
98
123
  echo 1 DEPTH_ZERO_SELF_SIGNED_CERT
@@ -105,6 +130,7 @@ goto :fail
105
130
 
106
131
  :installed
107
132
  set "QCMD="
133
+ set "CLIV="
108
134
  for /f "delims=" %%P in ('where qoderclicn.cmd 2^>nul') do if not defined QCMD set "QCMD=%%P"
109
135
  if not defined QCMD if exist "%APPDATA%\npm\qoderclicn.cmd" set "QCMD=%APPDATA%\npm\qoderclicn.cmd"
110
136
  if not defined QCMD (
@@ -203,7 +229,7 @@ goto :done
203
229
 
204
230
  :uninstall
205
231
  echo.
206
- echo [2/2] Uninstall %PKG%
232
+ echo [1/2] Uninstall %PKG%
207
233
  call npm uninstall -g "%PKG%"
208
234
  if errorlevel 1 (
209
235
  echo [X] npm uninstall failed.
@@ -211,13 +237,34 @@ if errorlevel 1 (
211
237
  goto :fail
212
238
  )
213
239
  echo [OK] %PKG% removed
240
+
241
+ rem npm leaves the scope directory and the shims behind, and both the
242
+ rem plugin's CLI lookup and the page's "installed?" badge read them. Clearing
243
+ rem them here is what actually makes the page switch back to "install".
244
+ echo.
245
+ echo [2/2] Clean leftovers
246
+ if exist "%APPDATA%\npm\node_modules\@qodercn-ai\qoderclicn" rd /s /q "%APPDATA%\npm\node_modules\@qodercn-ai\qoderclicn" 2>nul
247
+ dir /b "%APPDATA%\npm\node_modules\@qodercn-ai" 2>nul | findstr /r "." >nul
248
+ if errorlevel 1 rd /s /q "%APPDATA%\npm\node_modules\@qodercn-ai" 2>nul
249
+ call :delshims qoderclicn qodercn
250
+ echo [OK] shims and empty scope dir cleared
251
+
214
252
  echo.
215
253
  echo ==============================================================
216
- echo Uninstalled. Sign-in files are kept; run this script again
217
- echo without --uninstall to reinstall and sign in.
254
+ echo Uninstalled. Sign-in files under %USERPROFILE%\.qoder-cn are kept;
255
+ echo run this script again without --uninstall to reinstall and sign in.
218
256
  echo ==============================================================
219
257
  goto :done
220
258
 
259
+ rem Delete the npm shim trio for each name given, ignoring absent ones.
260
+ :delshims
261
+ if "%~1"=="" goto :eof
262
+ if exist "%APPDATA%\npm\%~1.cmd" del /q "%APPDATA%\npm\%~1.cmd" 2>nul
263
+ if exist "%APPDATA%\npm\%~1.ps1" del /q "%APPDATA%\npm\%~1.ps1" 2>nul
264
+ if exist "%APPDATA%\npm\%~1" del /q "%APPDATA%\npm\%~1" 2>nul
265
+ shift
266
+ goto :delshims
267
+
221
268
  :usage
222
269
  echo.
223
270
  echo setup-qoderclicn.bat install what is missing, then sign in
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,8 +394,13 @@ 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、uninstall 或 cancel' })
399
404
  return
400
405
  }
401
406
  const qoder = adapters[postBrand] as QoderAdapter