dsh-agent-sdk-bridge 1.2.3 → 1.3.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.
@@ -248,6 +248,16 @@ export declare class QoderAdapter extends LlmAdapter {
248
248
  usageInfo(fresh?: boolean): Promise<UsageSnapshot>;
249
249
  /** Forget the cached quota reading; the next read asks the CLI again. */
250
250
  invalidateUsage(): void;
251
+ /**
252
+ * Forget everything that was read under the account that just left.
253
+ *
254
+ * Signing in or out replaces the credentials on disk, but the SDK daemon and
255
+ * every warm session loaded the old ones when they started, and the catalog
256
+ * and quota caches describe that same old account. Signing out has to drop
257
+ * the sessions; signing in has to drop all four, or the page keeps showing
258
+ * the previous account until the process restarts.
259
+ */
260
+ resetAccount(): void;
251
261
  /** Whether the user switched one model off. */
252
262
  isModelDisabled(id: string): boolean;
253
263
  /** The stored disabled-model set, as a list for rewriting the field. */
@@ -25,6 +25,19 @@ export declare const CODEBUDDY_DEFAULT_MAX_TOKENS = 32000;
25
25
  export declare const CODEBUDDY_CACHE_TTL_MS = 300000;
26
26
  /** Give up on one CodeBuddy control round trip after this long. */
27
27
  export declare const CODEBUDDY_FETCH_TIMEOUT_MS = 30000;
28
+ /** Whether a CLI tool name belongs to this plugin's MCP server. */
29
+ export declare function isHostTool(toolName: string): boolean;
30
+ /**
31
+ * The host-side tool name, with every MCP namespace layer removed.
32
+ *
33
+ * CodeBuddy qualifies an already-qualified name again, so the handler can be
34
+ * handed `mcp__dsh_host__mcp__dsh_host__edit`. Stripping one layer produced
35
+ * `mcp__dsh_host__edit`, a name the host does not have (its tool is `edit`), and
36
+ * DSH answered `unknown tool "mcp__dsh_host__edit"`; the model retried the
37
+ * doubled spelling next round and the CLI rejected it with `does not exist in
38
+ * the current tool set`. See {@link stripMcpNamespace}.
39
+ */
40
+ export declare function hostToolName(toolName: string): string;
28
41
  /** One model as the settings page and the adapter see it. */
29
42
  export interface CodeBuddyModel {
30
43
  id: string;
@@ -210,8 +223,18 @@ export declare class CodeBuddySession {
210
223
  private session;
211
224
  private mcp;
212
225
  private readonly pairing;
213
- private readonly registered;
214
226
  private toolSchemas;
227
+ /**
228
+ * Reconciles the live host tool list into {@link mcp}.
229
+ *
230
+ * Created with the MCP server, because that is what it installs into. Owned
231
+ * here rather than inline so a tool that the host adds or withdraws during a
232
+ * conversation is actually added or withdrawn: the MCP SDK refuses a second
233
+ * `registerTool` for a name it already holds, so the previous
234
+ * name→hash replay could never replace a changed schema, and `Tool "…" does
235
+ * not exist in the current tool set.` was what the model got for its trouble.
236
+ */
237
+ private registry;
215
238
  private queue;
216
239
  private disposed;
217
240
  private abortPending;
@@ -307,6 +330,15 @@ export declare class CodeBuddySession {
307
330
  description: string;
308
331
  parameters?: unknown;
309
332
  }[]): void;
333
+ /**
334
+ * Reconcile this session's MCP tool set with the host's live list.
335
+ *
336
+ * Add, update in place, and remove: the host withdraws tools when a mode
337
+ * changes and adds them when `ops_discover_tools` resolves a deferred one, and
338
+ * a tool the model can still name but the server no longer holds is answered
339
+ * with `Tool "…" does not exist in the current tool set.` — the CLI never
340
+ * forwards it to the host, so no tool result ever comes back.
341
+ */
310
342
  private registerTools;
311
343
  /** Hand the host's tool results to parked or buffered handlers. */
312
344
  deliverToolResults(tail: readonly {
@@ -0,0 +1,43 @@
1
+ /**
2
+ * MCP tool-name namespacing, shared by every CLI backend this bridge drives.
3
+ *
4
+ * Each backend reaches the host's tools over an in-process MCP server, so the
5
+ * name a model emits is namespaced (`mcp__dsh-host__ops_bash`) while the host
6
+ * dispatches on the bare name (`ops_bash`). Two things make that translation
7
+ * less trivial than it looks, and both are the same bug in different clothes:
8
+ *
9
+ * - **Spelling.** CodeBuddy rewrites a server name's non-alphanumeric characters
10
+ * to `_`, so `dsh-host` is exposed as `mcp__dsh_host__…`; the Qoder CLI keeps
11
+ * the hyphen. A handler must accept both.
12
+ * - **Depth.** A model occasionally emits an already-qualified name, and the CLI
13
+ * then qualifies it again. Peeling exactly one layer handed the host
14
+ * `mcp__dsh_host__edit` — a name it does not have — so DSH answered
15
+ * `unknown tool "mcp__dsh_host__edit"`; the model then retried the doubled
16
+ * spelling and the CLI refused it with its own
17
+ * `does not exist in the current tool set.` Two error messages, one cause:
18
+ * a prefix peeled once instead of exhaustively.
19
+ *
20
+ * This module exists so all three backends peel the same way, rather than each
21
+ * carrying its own one-layer `slice`.
22
+ *
23
+ * @module dsh-agent-sdk-bridge/mcp-naming
24
+ */
25
+ /**
26
+ * Peel every matching namespace layer off a tool name.
27
+ *
28
+ * @param name - the tool name as the CLI's `tool_use` block carried it.
29
+ * @param prefixes - the namespaced spellings that belong to one server, in
30
+ * either spelling the backends produce. Longest first is not required; the
31
+ * walk re-checks the whole list after each peel.
32
+ * @returns the bare host tool name, or null when no prefix matched at all (or
33
+ * the name was nothing but namespaces).
34
+ */
35
+ export declare function stripMcpNamespace(name: string, prefixes: readonly string[]): string | null;
36
+ /**
37
+ * The two spellings one MCP server name is exposed under by the backends.
38
+ *
39
+ * @param serverName - the name the server was registered with, e.g. `dsh-host`.
40
+ * @returns the registered spelling followed by the CLI-sanitised one; the two
41
+ * collapse to a single entry when the name is already alphanumeric.
42
+ */
43
+ export declare function mcpToolPrefixes(serverName: string): string[];
@@ -142,7 +142,14 @@ export declare function minimaxAuthStatePath(region: MinimaxRegion): string;
142
142
  export declare function minimaxCliCommand(): string;
143
143
  /** Whether a CLI tool name belongs to this plugin's MCP server. */
144
144
  export declare function isHostMcpTool(name: string): boolean;
145
- /** The host-side name of an MCP tool, without the namespace. */
145
+ /**
146
+ * The host-side name of an MCP tool, without any namespace layer.
147
+ *
148
+ * Every layer is peeled, not just one: a model that emits an already-qualified
149
+ * name has it qualified again by the CLI, and handing the host
150
+ * `mcp__dsh-host__edit` made DSH answer `unknown tool` even though the tool was
151
+ * registered under `edit`. See {@link stripMcpNamespace}.
152
+ */
146
153
  export declare function hostMcpToolName(name: string): string;
147
154
  /** The model config option's values as rows. */
148
155
  export declare function minimaxModelsFromConfigOptions(options: readonly any[] | null | undefined): MinimaxModel[];
@@ -2,8 +2,9 @@
2
2
  * Live model catalog retrieval from one edition's local Qoder CLI. One
3
3
  * short-lived inner session sends the SDK's `get_models` control request; the
4
4
  * response (including account-custom models) stays fresh for a TTL, concurrent
5
- * callers share one in-flight fetch, and the static CN catalog is the fallback
6
- * while that edition's CLI is unreachable.
5
+ * callers share one in-flight fetch, and the static CN catalog is a fallback
6
+ * only while that edition's CLI is installed but cannot answer — never for an
7
+ * account that answered with an empty list (see {@link emptyCatalogFallback}).
7
8
  *
8
9
  * The CN and international editions publish different catalogs, so cache and
9
10
  * fallback are kept per brand: a list fetched from one account must never be
@@ -28,6 +29,12 @@ export declare class QoderModelCatalog {
28
29
  private inflight;
29
30
  /** Why the last refresh failed, for the settings page's guidance. */
30
31
  private failure;
32
+ /**
33
+ * Bumped by {@link invalidate}. A fetch that started before a sign-in carries
34
+ * the previous account's entries, so it must not republish them after the
35
+ * cache was dropped for that account change.
36
+ */
37
+ private epoch;
31
38
  /**
32
39
  * @param brand - which edition's CLI answers.
33
40
  * @param ttlMs - how long a fetched catalog stays fresh before a re-fetch.
@@ -62,13 +69,40 @@ export declare class QoderModelCatalog {
62
69
  * is installed at all, and which account is signed in — and an empty answer is
63
70
  * cached like any other. So after the setup helper has run, the page's next
64
71
  * read must not be served from a snapshot taken before that login existed.
72
+ *
73
+ * The remembered empty answer is deliberately kept: it says the account has
74
+ * nothing, which a later failed read must not turn back into the static plan.
65
75
  */
66
76
  invalidate(): void;
67
- /** dsh catalog entries: the enabled live list, or the static fallback. */
77
+ /** dsh catalog entries: the enabled live list, or the fallback {@link emptyCatalogFallback} allows. */
68
78
  models(): Promise<readonly QoderCatalogModel[]>;
69
79
  private fetch;
70
80
  private read;
71
81
  }
82
+ /**
83
+ * What the picker may show when the live catalogue came back empty.
84
+ *
85
+ * The captured CN plan is a stand-in for exactly one situation: this edition's
86
+ * CLI is installed, and the catalogue could not be read because the CLI or the
87
+ * network was unavailable. Two cases must stay empty:
88
+ *
89
+ * - The CLI answered. That is the account speaking — signed out, or a plan
90
+ * with no official models — and publishing the plan here is what put every
91
+ * Qoder CN model back into the picker after a sign-out, where selecting one
92
+ * could only fail. `getAvailableModels()` answers a *successful* empty list
93
+ * while signed out (its `cache` and `live` strategies included, even with a
94
+ * populated `~/.qoder-cn/.models`), so this is the ordinary sign-out path,
95
+ * not an edge case.
96
+ * - The CLI is not installed at all, so none of those models could run.
97
+ *
98
+ * @param brand - which edition's catalogue is empty.
99
+ * @param state - whether that edition's CLI is on the machine, and whether a
100
+ * successful read has ever produced an answer.
101
+ */
102
+ export declare function emptyCatalogFallback(brand: QoderBrand, state: {
103
+ cliInstalled: boolean;
104
+ answered: boolean;
105
+ }): readonly QoderCatalogModel[];
72
106
  /**
73
107
  * The credit multiplier upstream quotes for one model.
74
108
  *
@@ -103,6 +103,17 @@ export declare function feedTextLength(feed: Feed): number;
103
103
  * character count is not enough to price a feed that mixes Chinese and code.
104
104
  */
105
105
  export declare function feedWideCharCount(feed: Feed): number;
106
+ /**
107
+ * Compose the feed for a one-shot side-channel request (compaction, a session
108
+ * title): its last user message is the instruction to carry out, not a turn to
109
+ * continue.
110
+ *
111
+ * The history is still rendered, because compaction must see the conversation
112
+ * it is condensing, but the role preamble and the closing line both name the
113
+ * trailing instruction as the task. See {@link SIDE_CHANNEL_ROLE} for the
114
+ * misread this replaces.
115
+ */
116
+ export declare function renderSideChannelFeed(system: string | undefined, messages: readonly RequestMessage[], imagePath?: ImagePathResolver): Feed;
106
117
  /**
107
118
  * Compose the first feed for a fresh session: backend role, the host system
108
119
  * prompt, and the existing conversation as compact context. Messages of the
@@ -67,6 +67,22 @@ export declare function loadSdk(brand: QoderBrand): Promise<QoderSdkModule>;
67
67
  * @param brand - which edition to reset.
68
68
  */
69
69
  export declare function resetSdk(brand: QoderBrand): void;
70
+ /**
71
+ * Drop the loaded generation and stop the daemon it started.
72
+ *
73
+ * A daemon loads the CLI's credentials when it initializes, and those
74
+ * credentials are not part of the configuration signature: signing in as
75
+ * another account leaves the daemon answering as the account it started with.
76
+ * Shutting it down and forcing a new instance makes the next query read the
77
+ * credentials that are on disk now.
78
+ *
79
+ * The generation is dropped synchronously, so a read that starts as soon as the
80
+ * sign-in helper exits already gets the new instance; the old daemon is stopped
81
+ * in the background because no caller can wait on the shutdown.
82
+ *
83
+ * @param brand - which edition's daemon to replace.
84
+ */
85
+ export declare function discardSdk(brand: QoderBrand): void;
70
86
  /**
71
87
  * Whether an error is the SDK's daemon refusing a different configuration.
72
88
  *
@@ -86,6 +86,126 @@ export type ResolvedImages = ReadonlyMap<string, {
86
86
  data: string;
87
87
  mediaType: string;
88
88
  }>;
89
+ /** The handle the MCP SDK returns from (and exposes on) `registerTool`. */
90
+ export interface RegisteredToolHandle {
91
+ /**
92
+ * Replace this tool's definition in place.
93
+ *
94
+ * The SDK also toggles `enabled`, which is what lets a tool the host withdrew
95
+ * actually disappear from `tools/list` instead of only stopping its handler.
96
+ */
97
+ update(updates: {
98
+ description?: string;
99
+ paramsSchema?: Record<string, unknown>;
100
+ enabled?: boolean;
101
+ }): void;
102
+ /** Unregister this tool, so the next `registerTool` on the name succeeds. */
103
+ remove(): void;
104
+ }
105
+ /** What this module needs from the SDK's MCP server instance. */
106
+ export interface ToolRegistryHost {
107
+ registerTool(name: string, config: {
108
+ description: string;
109
+ inputSchema: Record<string, unknown>;
110
+ }, handler: (args: unknown) => Promise<{
111
+ content: McpContent[];
112
+ isError?: boolean;
113
+ }>): RegisteredToolHandle;
114
+ /** `markdown|json` — the tool list changed, so a client must re-read it. */
115
+ sendToolListChanged?(): void;
116
+ /**
117
+ * Declare the tools capability now, before any transport is connected.
118
+ *
119
+ * The MCP SDK (`McpServer`) only installs its `tools/list` + `tools/call`
120
+ * request handlers — and only registers the `tools` capability, with
121
+ * `listChanged` — the first time a tool is registered. A server created with
122
+ * an empty tool list therefore connects with **no tools capability at all**,
123
+ * and every later `registerTool` throws `Cannot register capabilities after
124
+ * connecting to transport`. The client then answers `tools/list` with
125
+ * `Method not found (-32601)`.
126
+ *
127
+ * That is exactly this bridge's first turn: `ensureTools()` runs when the host
128
+ * has not published its tools yet, so the server connects empty. The next turn
129
+ * brings `ops_bash` and friends, the registration throws, the tool never
130
+ * appears in `tools/list`, and the model — which the host's own prompt and
131
+ * `tool-addition` blocks say does have those tools — calls one anyway and is
132
+ * told `Tool "…" does not exist in the current tool set.` Calling this before
133
+ * `connect()` fixes it: the capability is declared up front, so tools can be
134
+ * added and removed for the life of the session.
135
+ */
136
+ setToolRequestHandlers?(): void;
137
+ }
138
+ /**
139
+ * Keeps one in-process MCP server's tool set equal to the host's live set.
140
+ *
141
+ * The host's tool list is not fixed for a session's lifetime: `dsh-ops` adds
142
+ * and withdraws tools as a session's mode changes and as `ops_discover_tools`
143
+ * pulls a deferred capability in, and DSH republishes that change to the model
144
+ * as `tool-addition` / `tool-removal` blocks. The MCP SDK, however, refuses a
145
+ * second `registerTool` for a name it already holds ("Tool X is already
146
+ * registered") and offers no unregister of its own, so a naive replay leaves a
147
+ * changed schema at its old definition and can never take a withdrawn tool back
148
+ * out. The model then calls a name the server does not have, and CodeBuddy
149
+ * answers it with `Tool "…" does not exist in the current tool set.` instead of
150
+ * a host result — the "tool went missing mid-conversation" symptom.
151
+ *
152
+ * This wrapper therefore reconciles by name: register what is new, `update()`
153
+ * what changed, and `remove()` what the host withdrew. The call handler is built
154
+ * per registered tool and answers through the session's tool-result pairing, so
155
+ * a tool re-registered after a mode change still collects its own result.
156
+ */
157
+ export declare class HostToolRegistry {
158
+ /** The MCP server the tools are installed into. */
159
+ private readonly host;
160
+ /**
161
+ * The call handler handed to the SDK for one tool.
162
+ *
163
+ * Built per registered tool and given the tool's name; the session's pairing
164
+ * answers on the tool-use id it announced, not on the name.
165
+ */
166
+ private readonly handlerFor;
167
+ /** Receives anything the SDK refuses, so a silent gap never reaches the model. */
168
+ private readonly onProblem;
169
+ /** What this registry has actually installed, by tool name, with its schema hash. */
170
+ private readonly installed;
171
+ constructor(
172
+ /** The MCP server the tools are installed into. */
173
+ host: ToolRegistryHost,
174
+ /**
175
+ * The call handler handed to the SDK for one tool.
176
+ *
177
+ * Built per registered tool and given the tool's name; the session's pairing
178
+ * answers on the tool-use id it announced, not on the name.
179
+ */
180
+ handlerFor: (name: string) => ((args: unknown) => Promise<{
181
+ content: McpContent[];
182
+ isError?: boolean;
183
+ }>),
184
+ /** Receives anything the SDK refuses, so a silent gap never reaches the model. */
185
+ onProblem?: (message: string) => void);
186
+ /**
187
+ * Declare the tools capability before the transport connects.
188
+ *
189
+ * Must run before `connect()`, because the SDK refuses a capability change
190
+ * afterwards. Without it a session whose first turn published no host tools
191
+ * connects with no tools capability, and every tool the host offers later can
192
+ * only throw — see {@link ToolRegistryHost.setToolRequestHandlers}.
193
+ */
194
+ prepare(): void;
195
+ /**
196
+ * Make the installed tool set match `tools` exactly.
197
+ *
198
+ * @param tools - the host's live tool schemas, in the order the host published them.
199
+ * @returns whether anything was added, changed or removed.
200
+ */
201
+ reconcile(tools: readonly {
202
+ name: string;
203
+ description: string;
204
+ parameters?: unknown;
205
+ }[]): boolean;
206
+ /** Names currently installed, for diagnostics and tests. */
207
+ names(): string[];
208
+ }
89
209
  export type QueueItem = {
90
210
  kind: 'chunk';
91
211
  chunk: StreamChunk;
@@ -205,7 +325,8 @@ export declare function meteredUsage(real: SdkUsage | undefined, reasoning: (met
205
325
  }): TokenUsage | undefined;
206
326
  /**
207
327
  * The host tool runtime dispatches by the bare host name; the inner model
208
- * only ever sees the namespaced MCP form, so strip the prefix on the way out.
328
+ * only ever sees the namespaced MCP form, so strip every prefix layer on the
329
+ * way out. See {@link stripMcpNamespace} for why one layer is not enough.
209
330
  */
210
331
  export declare function hostToolName(name: string): string;
211
332
  /** Deny native tools, allow this adapter's MCP tools. */
@@ -428,7 +549,16 @@ export declare class QoderSession {
428
549
  */
429
550
  private readonly pairing;
430
551
  private readonly mcp;
431
- private readonly registered;
552
+ /**
553
+ * Reconciles the live host tool list into {@link mcp}.
554
+ *
555
+ * The session outlives the host's tool list: `dsh-ops` publishes a different
556
+ * set per mode and `ops_discover_tools` adds capabilities mid-conversation.
557
+ * Installing only what is new left the server unable to ever replace a
558
+ * changed schema (the MCP SDK refuses a duplicate name), so this owns the
559
+ * add/update/remove bookkeeping instead of a name→hash map.
560
+ */
561
+ private readonly registry;
432
562
  private queue;
433
563
  private model;
434
564
  private reasoningEffort;
@@ -530,7 +660,17 @@ export declare class QoderSession {
530
660
  * per call, in execution order, before dispatching the MCP message).
531
661
  */
532
662
  private canUseTool;
533
- /** Register any host tools whose schema this session's MCP server lacks. */
663
+ /**
664
+ * Make this session's MCP tool set match the host's live tool list.
665
+ *
666
+ * The host adds and withdraws tools during a conversation (`dsh-ops` mode
667
+ * switches, `ops_discover_tools`), so this reconciles rather than only adds:
668
+ * a tool that appears mid-session is registered, a changed schema is updated
669
+ * in place, and a withdrawn tool is removed. See {@link HostToolRegistry} for
670
+ * the failure this prevents — the model calling a name the MCP server no
671
+ * longer had, which the CLI answers with `Tool "…" does not exist in the
672
+ * current tool set.` instead of a host result.
673
+ */
534
674
  ensureTools(tools: readonly ToolSchema[]): void;
535
675
  /**
536
676
  * Deliver host tool results to parked or buffered handlers, keyed by call id,
@@ -49,6 +49,12 @@ export declare class QoderUsage {
49
49
  private readonly timeoutMs;
50
50
  private cached;
51
51
  private inflight;
52
+ /**
53
+ * Bumped by {@link invalidate}. A fetch that started before a sign-in may
54
+ * still resolve with the previous account's numbers, so it must neither be
55
+ * shared with later readers nor written back to the cache.
56
+ */
57
+ private epoch;
52
58
  /**
53
59
  * @param brand - which edition's CLI answers.
54
60
  * @param ttlMs - how long a reading stays fresh; read per use.
@@ -62,7 +68,7 @@ export declare class QoderUsage {
62
68
  * @returns the reading; `error` carries a failed lookup instead of throwing.
63
69
  */
64
70
  read(fresh?: boolean): Promise<UsageSnapshot>;
65
- /** Drop the cached reading. */
71
+ /** Drop the cached reading, including any fetch that started before now. */
66
72
  invalidate(): void;
67
73
  /** The reading for a machine whose CLI is not installed. */
68
74
  private missingCli;
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.3",
5
+ "version": "1.3.0",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",
package/src/adapter.ts CHANGED
@@ -24,10 +24,11 @@ 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
26
  import { cachedModels } from './model-cache.ts'
27
- import { feedImageRefs, feedToText, imageRefText, imageRefs, joinFeeds, renderInitialFeed, renderRefreshed, renderUserTurn } from './render.ts'
27
+ import { feedImageRefs, feedToText, imageRefText, imageRefs, joinFeeds, renderInitialFeed, renderRefreshed, renderSideChannelFeed, renderUserTurn } from './render.ts'
28
28
  import type { Feed, ImagePathResolver } from './render.ts'
29
29
  import { QoderSession, QoderSessionManager, DEFAULT_MAX_SESSIONS } from './session.ts'
30
30
  import type { ChannelContent, ResolvedImages, SessionModelPolicy } from './session.ts'
31
+ import { discardSdk } from './sdk.ts'
31
32
  import type { UsageSnapshot } from './usage.ts'
32
33
  import { QoderUsage } from './usage.ts'
33
34
 
@@ -476,6 +477,22 @@ export class QoderAdapter extends LlmAdapter {
476
477
  this.usage.invalidate()
477
478
  }
478
479
 
480
+ /**
481
+ * Forget everything that was read under the account that just left.
482
+ *
483
+ * Signing in or out replaces the credentials on disk, but the SDK daemon and
484
+ * every warm session loaded the old ones when they started, and the catalog
485
+ * and quota caches describe that same old account. Signing out has to drop
486
+ * the sessions; signing in has to drop all four, or the page keeps showing
487
+ * the previous account until the process restarts.
488
+ */
489
+ resetAccount(): void {
490
+ this.catalog.invalidate()
491
+ this.usage.invalidate()
492
+ this.sessions.closeAll()
493
+ discardSdk(this.brand)
494
+ }
495
+
479
496
  /** Whether the user switched one model off. */
480
497
  isModelDisabled(id: string): boolean {
481
498
  return this.disabledModels.has(id)
@@ -634,8 +651,10 @@ export class QoderAdapter extends LlmAdapter {
634
651
  const model = resolveQoderModelId(options.model, this.modelAliases)
635
652
  if (options.sessionId === undefined || options.purpose !== undefined) {
636
653
  // Side channels summarise text; pixels would only cost them context.
637
- const prompt = feedToText(renderInitialFeed(options.system, options.messages, this.imagePath), this.imagePath)
638
- + '\n(这是一次性旁路请求,直接输出下一条助手回复。)'
654
+ // A side-channel request carries its instruction as the last user message
655
+ // (compaction appends one), so it is rendered as the task rather than as a
656
+ // turn to continue. See renderSideChannelFeed.
657
+ const prompt = feedToText(renderSideChannelFeed(options.system, options.messages, this.imagePath), this.imagePath)
639
658
  // Side channels (titles, compaction summaries) reuse the main session's
640
659
  // model so dsh's recorded summarization target matches what qodercli
641
660
  // actually runs — a different default route could have different
package/src/api.ts CHANGED
@@ -407,12 +407,12 @@ export async function handleApi(
407
407
  const mode = parsed.mode
408
408
  const result = startSetup(postBrand, mode, code => {
409
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()
410
+ // The helper may have installed, signed in, signed out, or removed
411
+ // the CLI. Every one of those changes whose credentials are on disk,
412
+ // while the SDK daemon and warm sessions still hold the ones they
413
+ // loaded at start-up — a sign-in after switching accounts would keep
414
+ // answering as the account that just left until the process restart.
415
+ qoder.resetAccount()
416
416
  })
417
417
  if (!result.started) {
418
418
  const status = result.reason === 'busy' ? 409 : result.reason === 'unsupported' ? 501 : 500
@@ -23,7 +23,7 @@ import type { ImageRequestReader } from './adapter.ts'
23
23
  import type { Live } from './live.ts'
24
24
  import { readLive, readLiveOptional } from './live.ts'
25
25
  import type { Feed, ImagePathResolver } from './render.ts'
26
- import { feedImageRefs, feedToText, imageRefText, renderInitialFeed, resolvedFeedParts } from './render.ts'
26
+ import { feedImageRefs, feedToText, imageRefText, renderInitialFeed, renderSideChannelFeed, resolvedFeedParts } from './render.ts'
27
27
  import type { ChannelContent } from './session.ts'
28
28
 
29
29
  /** The CodeBuddy provider route. */
@@ -375,8 +375,10 @@ export class CodeBuddyAdapter extends LlmAdapter {
375
375
  }
376
376
  const model = resolveCodeBuddyModelId(options.model, this.aliases)
377
377
  if (options.sessionId === undefined || options.purpose !== undefined) {
378
- const prompt = feedToText(renderInitialFeed(options.system, options.messages, this.options.imagePath), this.options.imagePath)
379
- + '\n(这是一次性旁路请求,直接输出下一条助手回复。)'
378
+ // A side-channel request (compaction, a session title) carries its
379
+ // instruction as the last user message, so it is rendered as the task to
380
+ // carry out rather than as a turn to continue. See renderSideChannelFeed.
381
+ const prompt = feedToText(renderSideChannelFeed(options.system, options.messages, this.options.imagePath), this.options.imagePath)
380
382
  for (const chunk of await codeBuddyColdStream(region, prompt, model, options)) yield chunk
381
383
  return
382
384
  }