dsh-agent-sdk-bridge 1.2.0 → 1.2.2

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.
@@ -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
  }
@@ -67,6 +67,7 @@ export declare class QoderModelCatalog {
67
67
  /** dsh catalog entries: the enabled live list, or the static fallback. */
68
68
  models(): Promise<readonly QoderCatalogModel[]>;
69
69
  private fetch;
70
+ private read;
70
71
  }
71
72
  /**
72
73
  * The credit multiplier upstream quotes for one model.
@@ -3,17 +3,35 @@
3
3
  *
4
4
  * The Qoder editions publish the same API under different scopes, so the rest
5
5
  * of the plugin imports this module instead of a package name. The CN SDK is a
6
- * real dependency and is loaded statically; the international one is optional
7
- * at runtime — a deployment that only has a CN account may not have it
8
- * installed — so it is imported on demand and its absence is reported to the
9
- * settings page as a plain error instead of failing the plugin's mount.
6
+ * real dependency and is loaded eagerly; the international one is optional at
7
+ * runtime — a deployment that only has a CN account may not have it installed —
8
+ * so it is imported on demand and its absence is reported to the settings page
9
+ * as a plain error instead of failing the plugin's mount.
10
10
  *
11
11
  * CodeBuddy has its own, unrelated API and is loaded dynamically for the same
12
12
  * reason: an account may never use it, and its package carries a large CLI.
13
13
  *
14
- * The Qoder module is typed against the CN package because the two are
15
- * API-compatible: every Qoder call site is shared, and the only thing that
16
- * changes is which process the protocol is spoken to.
14
+ * ## Why modules are reloaded
15
+ *
16
+ * Every Qoder SDK routes all queries through one **process-wide daemon** that
17
+ * is initialized with the first query's launch configuration (CLI path,
18
+ * interpreter, environment, proxy) and then refuses any different one for the
19
+ * life of the process:
20
+ *
21
+ * DaemonConfigurationConflictError:
22
+ * Global daemon is already initialized with different options
23
+ *
24
+ * The host is long-lived, so its configuration is not: a CLI can be
25
+ * reinstalled, an edition can appear, an installer can change the machine
26
+ * environment. When that happens the ready daemon no longer matches and every
27
+ * later query fails until the process restarts — a state the settings page
28
+ * cannot recover from on its own.
29
+ *
30
+ * So the module tracks the configuration signature it loaded under and takes a
31
+ * fresh instance whenever the signature changes; {@link resetSdk} does the same
32
+ * after a conflict is observed. A new instance has an empty daemon registry, so
33
+ * it initializes against the current configuration instead of arguing with the
34
+ * old one.
17
35
  *
18
36
  * @module dsh-agent-sdk-bridge/sdk
19
37
  */
@@ -26,12 +44,60 @@ export type QoderSdkModule = typeof QoderSdk;
26
44
  /** The CodeBuddy SDK module, typed from its declarations. */
27
45
  export type CodeBuddySdkModule = typeof CodeBuddySdk;
28
46
  /**
29
- * Load the SDK for one Qoder edition.
47
+ * The launch configuration a Qoder query would use, as a comparable string.
48
+ *
49
+ * Mirrors the fields the SDK's own daemon compares before reusing itself. The
50
+ * environment is included because the SDK hands it to the CLI verbatim, and a
51
+ * difference there is enough to make the daemon reject a query.
52
+ *
53
+ * @param brand - which edition's configuration to describe.
54
+ * @returns a stable string that changes exactly when the configuration does.
55
+ */
56
+ export declare function configurationSignature(brand: QoderBrand): string;
57
+ /**
58
+ * Load the SDK for one Qoder edition, under its current configuration.
30
59
  *
31
60
  * @param brand - which edition's SDK to load.
32
61
  * @returns the SDK module.
33
62
  */
34
63
  export declare function loadSdk(brand: QoderBrand): Promise<QoderSdkModule>;
64
+ /**
65
+ * Drop the loaded instance so the next {@link loadSdk} starts a new daemon.
66
+ *
67
+ * @param brand - which edition to reset.
68
+ */
69
+ export declare function resetSdk(brand: QoderBrand): void;
70
+ /**
71
+ * Whether an error is the SDK's daemon refusing a different configuration.
72
+ *
73
+ * @param error - whatever a query threw.
74
+ */
75
+ export declare function isDaemonConflict(error: unknown): boolean;
76
+ /**
77
+ * Run one idempotent SDK operation, recovering from a daemon conflict once.
78
+ *
79
+ * A conflict means the daemon was initialized under a configuration that no
80
+ * longer applies. A fresh module instance starts an empty daemon with the
81
+ * current one, so the retry succeeds without a restart. Only use this for
82
+ * operations that can be repeated without side effects (reads), never for a
83
+ * turn that may already have emitted output.
84
+ *
85
+ * @param brand - which edition to query.
86
+ * @param run - the operation, given the module to use.
87
+ */
88
+ export declare function withSdk<T>(brand: QoderBrand, run: (sdk: QoderSdkModule) => Promise<T>): Promise<T>;
89
+ /**
90
+ * Open one cheap control query so a stale daemon is discovered before a turn
91
+ * starts streaming.
92
+ *
93
+ * A turn cannot be retried once it has emitted output, so the session path has
94
+ * to find out about a configuration conflict first. `getUsageInfo` is a
95
+ * control request: it initializes the daemon and reads the account without
96
+ * running a model turn.
97
+ *
98
+ * @param brand - which edition to probe.
99
+ */
100
+ export declare function probeDaemon(brand: QoderBrand): Promise<void>;
35
101
  /**
36
102
  * Load the CodeBuddy Agent SDK.
37
103
  *
@@ -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. */
@@ -67,4 +67,5 @@ export declare class QoderUsage {
67
67
  /** The reading for a machine whose CLI is not installed. */
68
68
  private missingCli;
69
69
  private fetch;
70
+ private readSnapshot;
70
71
  }
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.2",
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/cli.ts CHANGED
@@ -245,6 +245,17 @@ export function cliConflictMessage(brand: QoderBrand): string {
245
245
  * @returns the original detail, prefixed with the actionable explanation.
246
246
  */
247
247
  export function cliFailureText(detail: string, brand: QoderBrand): string {
248
+ // The SDK routes every query through one process-wide daemon pinned to the
249
+ // first launch configuration it saw. When the machine changes under it (a
250
+ // reinstall, a new edition, a different environment) every query is rejected
251
+ // with this message until the process restarts. The plugin now drops the SDK
252
+ // instance at that point, so the next request recovers; say that instead of
253
+ // echoing an English internal error into the page.
254
+ if (/DaemonConfigurationConflict|Global daemon is already initialized with different options/i.test(detail)) {
255
+ const command = brandProfile(brand).cliCommands[0]
256
+ return `本机 ${command} 的运行配置在本次会话期间发生了变化,SDK 的本地守护进程仍按旧配置运行。`
257
+ + `插件已重置这部分运行时,请重试一次;若仍失败,重启 DSH Web。原始信息:${detail}`
258
+ }
248
259
  if (!/exit(?:ed)?(?: with)? code 42|sdk_worker_removed/i.test(detail)) return detail
249
260
  const profile = brandProfile(brand)
250
261
  const pkg = profile.cliPackages[0]
package/src/models.ts CHANGED
@@ -17,10 +17,11 @@ import type { QoderBrand } from './brand.ts'
17
17
  import { brandProfile } from './brand.ts'
18
18
  import type { QoderCatalogModel } from './catalog.ts'
19
19
  import { QODER_MODELS } from './catalog.ts'
20
- import { cliConflictMessage, cliFailureText, foreignCliOverride, qoderCliOptions } from './cli.ts'
20
+ import { cliConflictMessage, cliFailureText, foreignCliOverride, qoderCliOptions, resolveQoderCli } from './cli.ts'
21
21
  import type { Live } from './live.ts'
22
22
  import { readLive } from './live.ts'
23
- import { loadSdk } from './sdk.ts'
23
+ import type { QoderSdkModule } from './sdk.ts'
24
+ import { withSdk } from './sdk.ts'
24
25
 
25
26
  /** How long a fetched catalog stays fresh by default. */
26
27
  export const DEFAULT_MODEL_CACHE_TTL_MS = 5 * 60_000
@@ -152,7 +153,15 @@ export class QoderModelCatalog {
152
153
  private async fetch(): Promise<readonly ModelInfo[]> {
153
154
  const conflict = foreignCliOverride(this.brand)
154
155
  if (conflict !== undefined) throw new Error(cliConflictMessage(this.brand))
155
- const sdk = await loadSdk(this.brand)
156
+ // Without a CLI of our own there is no configuration to initialize the
157
+ // SDK's daemon with. Asking anyway pinned it to the SDK's defaults, and the
158
+ // first query after the CLI was installed then conflicted with it for the
159
+ // rest of the process's life (see `sdk.ts`).
160
+ if (resolveQoderCli(this.brand) === undefined) throw new Error(cliConflictMessage(this.brand))
161
+ return withSdk(this.brand, sdk => this.read(sdk))
162
+ }
163
+
164
+ private async read(sdk: QoderSdkModule): Promise<readonly ModelInfo[]> {
156
165
  const q = sdk.query({
157
166
  prompt: inertInput(),
158
167
  options: {