dsh-agent-sdk-bridge 1.1.7 → 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.
- package/DEVELOPMENT.md +46 -1
- package/FAQ.md +40 -5
- package/client.js +103 -13
- package/lib/index.js +332 -39
- package/lib/types/adapter.d.ts +21 -2
- package/lib/types/cli.d.ts +65 -5
- package/lib/types/codebuddy.d.ts +1 -1
- package/lib/types/live.d.ts +2 -2
- package/lib/types/minimax.d.ts +7 -0
- package/lib/types/model-cache.d.ts +27 -0
- package/lib/types/models.d.ts +10 -0
- package/lib/types/setup.d.ts +33 -0
- package/lib/types/usage.d.ts +12 -0
- package/package.json +3 -3
- package/scripts/setup-qodercli.bat +53 -6
- package/scripts/setup-qoderclicn.bat +53 -6
- package/src/adapter.ts +63 -8
- package/src/api.ts +7 -2
- package/src/cli.ts +183 -16
- package/src/codebuddy-adapter.ts +9 -4
- package/src/codebuddy.ts +2 -2
- package/src/config.ts +1 -1
- package/src/live.ts +2 -2
- package/src/minimax-adapter.ts +5 -2
- package/src/minimax.ts +10 -0
- package/src/model-cache.ts +39 -0
- package/src/models.ts +42 -3
- package/src/session.ts +2 -2
- package/src/setup.ts +69 -1
- package/src/usage.ts +33 -3
package/lib/types/cli.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
93
|
+
* Why this edition has no usable CLI, when `QODERCLI_PATH` explains it.
|
|
94
94
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* edition's
|
|
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;
|
package/lib/types/codebuddy.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ export declare class CodeBuddyCatalog {
|
|
|
126
126
|
* Callers that must answer synchronously (deciding whether a model exposes a
|
|
127
127
|
* context-budget choice) use this instead of awaiting a refresh.
|
|
128
128
|
*/
|
|
129
|
-
snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[];
|
|
129
|
+
snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[] | undefined;
|
|
130
130
|
/** Models for one region; a failed refresh keeps the last good list. */
|
|
131
131
|
models(requested?: CodeBuddyRegion): Promise<readonly CodeBuddyModel[]>;
|
|
132
132
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
package/lib/types/live.d.ts
CHANGED
|
@@ -41,8 +41,8 @@ export declare function readLive<T>(value: Live<T> | undefined, fallback: T): T;
|
|
|
41
41
|
* Resolve one {@link Live} option that may legitimately be undefined.
|
|
42
42
|
*
|
|
43
43
|
* Separate from {@link readLive} because an option whose "unset" state is
|
|
44
|
-
* itself meaningful (`defaultReasoningEffort`: empty means "
|
|
45
|
-
* has no fallback to apply.
|
|
44
|
+
* itself meaningful (`defaultReasoningEffort`: empty means "use the model's
|
|
45
|
+
* strongest level") has no fallback to apply.
|
|
46
46
|
*
|
|
47
47
|
* @param value - the plain value or thunk, possibly undefined.
|
|
48
48
|
* @returns the option's current value, or undefined when it is unset.
|
package/lib/types/minimax.d.ts
CHANGED
|
@@ -345,6 +345,13 @@ export declare class MinimaxCatalog {
|
|
|
345
345
|
constructor(region: Live<MinimaxRegion>, ttlMs?: Live<number>, timeoutMs?: Live<number>);
|
|
346
346
|
/** Models for one region; a failed refresh keeps the last good list. */
|
|
347
347
|
models(requested?: MinimaxRegion): Promise<readonly MinimaxModel[]>;
|
|
348
|
+
/**
|
|
349
|
+
* The last successful list for a region, without probing.
|
|
350
|
+
*
|
|
351
|
+
* The picker resolves a route on every switch; awaiting an ACP probe there
|
|
352
|
+
* cost a process round-trip whenever the TTL had just expired.
|
|
353
|
+
*/
|
|
354
|
+
snapshot(requested?: MinimaxRegion): readonly MinimaxModel[] | undefined;
|
|
348
355
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
349
356
|
error(requested?: MinimaxRegion): string | undefined;
|
|
350
357
|
invalidate(region?: MinimaxRegion): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache-first catalogue reads for the model picker.
|
|
3
|
+
*
|
|
4
|
+
* The harness resolves a route every time the user switches model or reasoning
|
|
5
|
+
* level, and each of the three providers answers that resolution from a
|
|
6
|
+
* catalogue whose fetch is expensive: Qoder cold-starts its CLI (up to the
|
|
7
|
+
* fetch timeout), CodeBuddy boots a process, MiniMax probes over ACP. Awaiting
|
|
8
|
+
* that fetch inside a resolution made the picker freeze for seconds whenever
|
|
9
|
+
* the cache had just expired.
|
|
10
|
+
*
|
|
11
|
+
* So a resolution reads the last successful snapshot when there is one and lets
|
|
12
|
+
* the catalogue refresh behind it; only the very first resolution, where there
|
|
13
|
+
* is nothing to show, waits. A snapshot that is merely stale still describes
|
|
14
|
+
* the same account's models, so answering from it is no less correct than the
|
|
15
|
+
* previous behaviour of answering from a failed fetch's fallback.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-agent-sdk-bridge/model-cache
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The cached list when one exists, otherwise the awaited fetch.
|
|
21
|
+
*
|
|
22
|
+
* @param snapshot - last successful catalogue, or undefined before the first.
|
|
23
|
+
* @param fetch - the catalogue's normal (TTL-aware, in-flight-sharing) read.
|
|
24
|
+
* @returns the entries to resolve against, never empty-by-surprise when a
|
|
25
|
+
* snapshot exists.
|
|
26
|
+
*/
|
|
27
|
+
export declare function cachedModels<T>(snapshot: readonly T[] | undefined, fetch: () => Promise<readonly T[]>): Promise<readonly T[]>;
|
package/lib/types/models.d.ts
CHANGED
|
@@ -43,6 +43,16 @@ export declare class QoderModelCatalog {
|
|
|
43
43
|
* settings page cannot disagree about what the account has.
|
|
44
44
|
*/
|
|
45
45
|
liveModels(): Promise<readonly ModelInfo[]>;
|
|
46
|
+
/**
|
|
47
|
+
* The last successful live list, without fetching.
|
|
48
|
+
*
|
|
49
|
+
* The model picker resolves a route on every switch, and a switch must not
|
|
50
|
+
* wait on a CLI cold start (up to the fetch timeout). Callers that need an
|
|
51
|
+
* immediate answer read this and let {@link liveModels} refresh behind them;
|
|
52
|
+
* `undefined` means nothing has been read yet, which only the first switch
|
|
53
|
+
* has to wait for.
|
|
54
|
+
*/
|
|
55
|
+
snapshot(): readonly ModelInfo[] | undefined;
|
|
46
56
|
/** Why the last refresh failed, or undefined when it succeeded. */
|
|
47
57
|
get error(): string | undefined;
|
|
48
58
|
/**
|
package/lib/types/setup.d.ts
CHANGED
|
@@ -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
|
*
|
package/lib/types/usage.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
89
|
-
"@qodercn-ai/qodercn-agent-sdk": "^1.0.
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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 [
|
|
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;
|
|
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
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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 [
|
|
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;
|
|
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/adapter.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { ResolvedConfig } from './config.ts'
|
|
|
23
23
|
import type { Live } from './live.ts'
|
|
24
24
|
import { readLive, readLiveOptional } from './live.ts'
|
|
25
25
|
import { DEFAULT_MODEL_CACHE_TTL_MS, DEFAULT_FETCH_TIMEOUT_MS, QoderModelCatalog } from './models.ts'
|
|
26
|
+
import { cachedModels } from './model-cache.ts'
|
|
26
27
|
import { feedImageRefs, feedToText, imageRefText, imageRefs, joinFeeds, renderInitialFeed, renderRefreshed, renderUserTurn } from './render.ts'
|
|
27
28
|
import type { Feed, ImagePathResolver } from './render.ts'
|
|
28
29
|
import { QoderSession, QoderSessionManager, DEFAULT_MAX_SESSIONS } from './session.ts'
|
|
@@ -216,31 +217,77 @@ const EFFORT_NAMES: Readonly<Record<string, string>> = {
|
|
|
216
217
|
max: 'Max',
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Strength order used to pick a model's starting level.
|
|
222
|
+
*
|
|
223
|
+
* The three providers spell their levels differently (Qoder publishes
|
|
224
|
+
* `low|medium|high|max`, MiniMax `low|high`, CodeBuddy whatever its catalog
|
|
225
|
+
* declares), so the ranking is by name rather than by position in any one
|
|
226
|
+
* upstream list. An id outside this table ranks below every known one, which is
|
|
227
|
+
* what several sources agreeing on an unfamiliar spelling should do.
|
|
228
|
+
*/
|
|
229
|
+
const EFFORT_ORDER: readonly string[] = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The strongest level a model offers.
|
|
233
|
+
*
|
|
234
|
+
* Switching model or level must start at the most capable setting the route
|
|
235
|
+
* accepts, the same rule the sibling adapter plugin uses; the previous
|
|
236
|
+
* behaviour of following upstream's own default meant some models silently
|
|
237
|
+
* started one or two steps down (`CodeBuddy` advertises `high` as its default
|
|
238
|
+
* even when `max` is selectable).
|
|
239
|
+
*
|
|
240
|
+
* @param efforts - the levels the route accepts, in upstream order.
|
|
241
|
+
* @returns the strongest id, or undefined for a non-reasoning model.
|
|
242
|
+
*/
|
|
243
|
+
export function strongestEffort(efforts: readonly string[]): string | undefined {
|
|
244
|
+
if (efforts.length === 0) return undefined
|
|
245
|
+
let best: string | undefined
|
|
246
|
+
let bestRank = -1
|
|
247
|
+
for (const effort of efforts) {
|
|
248
|
+
// First occurrence wins a tie, which keeps an upstream-ordered list stable
|
|
249
|
+
// when it repeats a level.
|
|
250
|
+
const rank = EFFORT_ORDER.indexOf(effort)
|
|
251
|
+
if (best === undefined || rank > bestRank) {
|
|
252
|
+
best = effort
|
|
253
|
+
bestRank = rank
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return best
|
|
257
|
+
}
|
|
258
|
+
|
|
219
259
|
/**
|
|
220
260
|
* Build the `reasoning` metadata block for a resolved model, or undefined
|
|
221
261
|
* when the model does not support reasoning.
|
|
262
|
+
*
|
|
263
|
+
* The starting level is the strongest one the model accepts, not the level
|
|
264
|
+
* upstream happens to name as its default: the user's explicit choice in the
|
|
265
|
+
* sibling plugin, applied here too. An explicit configuration value still wins
|
|
266
|
+
* when the model accepts it.
|
|
267
|
+
*
|
|
222
268
|
* @param efforts - CLI-reported effort ids (absent for reasoning-less models).
|
|
223
|
-
* @param
|
|
269
|
+
* @param configuredEffort - user-configured starting level, when any.
|
|
224
270
|
* @param isReasoning - whether the model supports reasoning per the CLI.
|
|
225
271
|
* @returns the harness reasoning metadata, or undefined to omit it.
|
|
226
272
|
*/
|
|
227
273
|
export function reasoningInfo(
|
|
228
274
|
efforts: readonly string[] | undefined,
|
|
229
|
-
|
|
275
|
+
configuredEffort: string | undefined,
|
|
230
276
|
isReasoning: boolean | undefined,
|
|
231
277
|
): LlmModelReasoningInfo | undefined {
|
|
232
278
|
if (efforts === undefined && isReasoning === false) return undefined
|
|
233
279
|
const ids = efforts !== undefined && efforts.length > 0
|
|
234
280
|
? efforts
|
|
235
281
|
: DEFAULT_REASONING_EFFORTS
|
|
282
|
+
const defaultEffort = configuredEffort !== undefined && ids.includes(configuredEffort)
|
|
283
|
+
? configuredEffort
|
|
284
|
+
: strongestEffort(ids)
|
|
236
285
|
return {
|
|
237
286
|
efforts: ids.map(id => ({
|
|
238
287
|
id: ReasoningEffortId(id),
|
|
239
288
|
name: EFFORT_NAMES[id] ?? id,
|
|
240
289
|
})),
|
|
241
|
-
...defaultEffort
|
|
242
|
-
? { defaultEffort: ReasoningEffortId(defaultEffort) }
|
|
243
|
-
: {},
|
|
290
|
+
...defaultEffort === undefined ? {} : { defaultEffort: ReasoningEffortId(defaultEffort) },
|
|
244
291
|
}
|
|
245
292
|
}
|
|
246
293
|
|
|
@@ -492,11 +539,16 @@ export class QoderAdapter extends LlmAdapter {
|
|
|
492
539
|
// address to find the metadata, but echo the requested id back: the seam
|
|
493
540
|
// rejects an exact-model result whose id differs from the one asked for.
|
|
494
541
|
const target = resolveQoderModelId(model, this.modelAliases)
|
|
495
|
-
|
|
542
|
+
// The picker resolves on every switch and every level change. Awaiting the
|
|
543
|
+
// CLI catalogue here (a cold start, up to the fetch timeout) froze the menu
|
|
544
|
+
// whenever the cache had just expired, so a snapshot answers immediately and
|
|
545
|
+
// the refresh runs behind it.
|
|
546
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels()))
|
|
547
|
+
.find(entry => entry.value === target)
|
|
496
548
|
if (live !== undefined) {
|
|
497
549
|
const vision = live.isVl === true
|
|
498
550
|
this.knownVision.set(target, vision)
|
|
499
|
-
const reasoning = reasoningInfo(live.efforts,
|
|
551
|
+
const reasoning = reasoningInfo(live.efforts, this.defaultReasoningEffort, live.isReasoning)
|
|
500
552
|
return {
|
|
501
553
|
provider,
|
|
502
554
|
id: model,
|
|
@@ -566,7 +618,10 @@ export class QoderAdapter extends LlmAdapter {
|
|
|
566
618
|
private async capture(provider: string, model: string, signal?: AbortSignal): Promise<CallGeneration> {
|
|
567
619
|
const info = await this.resolveModel(provider, model, signal)
|
|
568
620
|
const target = resolveQoderModelId(model, this.modelAliases)
|
|
569
|
-
|
|
621
|
+
// Same cache-first rule as the resolution above: a dispatch may not stall
|
|
622
|
+
// on a catalogue fetch to learn window facts a snapshot already carries.
|
|
623
|
+
const live = (await cachedModels(this.catalog.snapshot(), () => this.catalog.liveModels()))
|
|
624
|
+
.find(entry => entry.value === target)
|
|
570
625
|
const declared = info.context?.contextWindow
|
|
571
626
|
return {
|
|
572
627
|
info,
|
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 或
|
|
403
|
+
send(res, 400, { error: 'mode 只接受 configure、login、uninstall 或 cancel' })
|
|
399
404
|
return
|
|
400
405
|
}
|
|
401
406
|
const qoder = adapters[postBrand] as QoderAdapter
|