dsh-agent-sdk-bridge 1.1.6 → 1.1.8

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.
@@ -13,7 +13,7 @@ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
13
13
  import type { QoderBrand } from './brand.ts';
14
14
  import type { Live } from './live.ts';
15
15
  import { QoderModelCatalog } from './models.ts';
16
- import type { Feed } from './render.ts';
16
+ import type { Feed, ImagePathResolver } from './render.ts';
17
17
  import type { UsageSnapshot } from './usage.ts';
18
18
  /**
19
19
  * Read one durable image occurrence into the bytes a request sends.
@@ -40,6 +40,11 @@ export interface QoderAdapterOptions {
40
40
  modelCacheTtlMs?: Live<number>;
41
41
  /** Request-image reader; absent → images are never forwarded as pixels. */
42
42
  readImage?: ImageRequestReader;
43
+ /**
44
+ * The tool-world path of one image, for the handle text that lets the model
45
+ * edit it. Absent → an unreadable image keeps the harness placeholder.
46
+ */
47
+ imagePath?: ImagePathResolver;
43
48
  /** How long an unpaired MCP tool handler waits before failing its call. */
44
49
  toolResultTimeoutMs?: Live<number>;
45
50
  /** How long the inner process gets to acknowledge an abort. */
@@ -72,6 +77,12 @@ export interface QoderAdapterOptions {
72
77
  export declare const QODER_PROVIDER = "qoder-cn";
73
78
  /** The international edition's route; a second adapter instance serves it. */
74
79
  export declare const QODER_INTL_PROVIDER = "qoder-intl";
80
+ /** The window facts one live catalog entry carries. */
81
+ export type WindowFacts = {
82
+ maxInputTokens?: number;
83
+ defaultContextWindow?: number;
84
+ availableContextWindows?: readonly number[];
85
+ };
75
86
  /**
76
87
  * Decide the context window to report for one live model.
77
88
  *
@@ -80,17 +91,15 @@ export declare const QODER_INTL_PROVIDER = "qoder-intl";
80
91
  * actually runs with. `maxInputTokens` is NOT a substitute — it is the ceiling
81
92
  * for a single request and is often lower than the session window (e.g. 180 000
82
93
  * against a 200 000 session), so falling back to it would understate capacity.
94
+ * Callers that accept a user override should validate it against
95
+ * `availableContextWindows` first — see {@link resolveDeclaredWindow}.
83
96
  *
84
97
  * @param live - the live catalog entry, when the CLI answered.
85
98
  * @param override - the user's chosen window for this model, if any.
86
99
  * @param fallback - window used when the catalog has nothing for this model.
87
100
  * @returns the window in tokens.
88
101
  */
89
- export declare function pickContextWindow(live: {
90
- maxInputTokens?: number;
91
- defaultContextWindow?: number;
92
- availableContextWindows?: readonly number[];
93
- } | undefined, override: number | undefined, fallback: number): number;
102
+ export declare function pickContextWindow(live: WindowFacts | undefined, override: number | undefined, fallback: number): number;
94
103
  /**
95
104
  * The window the CLI will actually run this route with.
96
105
  *
@@ -107,20 +116,49 @@ export declare function pickContextWindow(live: {
107
116
  * @param declared - the window this route publishes to the harness.
108
117
  * @returns the window the CLI runs with, or undefined when unknown.
109
118
  */
110
- export declare function cliContextWindow(live: {
111
- maxInputTokens?: number;
112
- defaultContextWindow?: number;
113
- availableContextWindows?: readonly number[];
114
- } | undefined, declared: number): number | undefined;
119
+ export declare function cliContextWindow(live: WindowFacts | undefined, declared: number): number | undefined;
120
+ /**
121
+ * The window to publish for one route, which is also the one the CLI is told
122
+ * to run with.
123
+ *
124
+ * A live entry is authoritative: the user's override counts only when the
125
+ * model advertises it. The CLI silently ignores anything else (a 1M choice on
126
+ * a 200K-only route), and dividing by it would understate every reading
127
+ * fivefold. When the catalog is momentarily unavailable, the last successful
128
+ * answer is reused instead of the static 200K default — that fallback used to
129
+ * change the denominator, and the compaction budget, mid-session: a 1M
130
+ * conversation read 1M one turn and 200K the next, and then compacted at what
131
+ * looked like 10%.
132
+ */
133
+ export declare function resolveDeclaredWindow(live: WindowFacts | undefined, override: number | undefined, remembered: number | undefined, fallback: number): number;
134
+ /**
135
+ * The strongest level a model offers.
136
+ *
137
+ * Switching model or level must start at the most capable setting the route
138
+ * accepts, the same rule the sibling adapter plugin uses; the previous
139
+ * behaviour of following upstream's own default meant some models silently
140
+ * started one or two steps down (`CodeBuddy` advertises `high` as its default
141
+ * even when `max` is selectable).
142
+ *
143
+ * @param efforts - the levels the route accepts, in upstream order.
144
+ * @returns the strongest id, or undefined for a non-reasoning model.
145
+ */
146
+ export declare function strongestEffort(efforts: readonly string[]): string | undefined;
115
147
  /**
116
148
  * Build the `reasoning` metadata block for a resolved model, or undefined
117
149
  * when the model does not support reasoning.
150
+ *
151
+ * The starting level is the strongest one the model accepts, not the level
152
+ * upstream happens to name as its default: the user's explicit choice in the
153
+ * sibling plugin, applied here too. An explicit configuration value still wins
154
+ * when the model accepts it.
155
+ *
118
156
  * @param efforts - CLI-reported effort ids (absent for reasoning-less models).
119
- * @param defaultEffort - CLI-reported default effort id.
157
+ * @param configuredEffort - user-configured starting level, when any.
120
158
  * @param isReasoning - whether the model supports reasoning per the CLI.
121
159
  * @returns the harness reasoning metadata, or undefined to omit it.
122
160
  */
123
- export declare function reasoningInfo(efforts: readonly string[] | undefined, defaultEffort: string | undefined, isReasoning: boolean | undefined): LlmModelReasoningInfo | undefined;
161
+ export declare function reasoningInfo(efforts: readonly string[] | undefined, configuredEffort: string | undefined, isReasoning: boolean | undefined): LlmModelReasoningInfo | undefined;
124
162
  /**
125
163
  * The Qoder-backed adapter. Session continuity, tool parking, and feed
126
164
  * planning live here; chunk synthesis lives in the session's consumer.
@@ -138,6 +176,7 @@ export declare class QoderAdapter extends LlmAdapter {
138
176
  private readonly catalog;
139
177
  private readonly usage;
140
178
  private readonly readImage;
179
+ private readonly imagePath;
141
180
  private readonly brand;
142
181
  /**
143
182
  * Memoized `Set` view of the disabled-model list.
@@ -147,6 +186,24 @@ export declare class QoderAdapter extends LlmAdapter {
147
186
  * hash probe instead of rebuilding a set per call, with no staleness.
148
187
  */
149
188
  private disabledCache;
189
+ /**
190
+ * The last window each route resolved to, plus what the model advertised.
191
+ *
192
+ * Reused only when a live entry is missing. Without it a failed refresh fell
193
+ * back to the static 200K, so a 1M session suddenly declared 200K: the ring
194
+ * denominator changed and the compaction engine budgeted against 200K,
195
+ * compacting a history that was still only ~10% of the real window.
196
+ */
197
+ private readonly knownWindows;
198
+ /**
199
+ * Last verified image capability per route.
200
+ *
201
+ * A missed catalog refresh used to fall back to text-only, and DSH then
202
+ * stripped the pixels before this adapter ran: a vision model silently lost
203
+ * the image for that turn. Remembering the last answer keeps the declared
204
+ * capability stable across a transient miss.
205
+ */
206
+ private readonly knownVision;
150
207
  constructor(options?: QoderAdapterOptions);
151
208
  private get defaultMaxTokens();
152
209
  private get modelContextWindows();
@@ -195,8 +252,17 @@ export declare class QoderAdapter extends LlmAdapter {
195
252
  isModelDisabled(id: string): boolean;
196
253
  /** The stored disabled-model set, as a list for rewriting the field. */
197
254
  disabledModelIds(): readonly string[];
198
- /** The user's window for one model, or undefined when following upstream. */
255
+ /**
256
+ * The user's window for one model, when the provider accepts it.
257
+ *
258
+ * A stored choice the model does not advertise is not a real choice: the CLI
259
+ * ignores it and keeps its own window, so publishing it would only make the
260
+ * meter divide by a capacity the route never runs with. Until the catalog
261
+ * has answered once the choice is trusted (there is nothing to check yet).
262
+ */
199
263
  contextWindowFor(id: string): number | undefined;
264
+ /** The window this route publishes, remembering it for catalog misses. */
265
+ private declaredWindow;
200
266
  /** The stored per-model window map, for rewriting the field. */
201
267
  modelWindowChoices(): Readonly<Record<string, number>>;
202
268
  listModels(provider: string): Promise<readonly LlmModelInfo[]>;
@@ -15,6 +15,7 @@ import { CodeBuddyAuth } from './codebuddy.ts';
15
15
  import type { CodeBuddyModel, CodeBuddyUsageSnapshot } from './codebuddy.ts';
16
16
  import type { ImageRequestReader } from './adapter.ts';
17
17
  import type { Live } from './live.ts';
18
+ import type { ImagePathResolver } from './render.ts';
18
19
  /** The CodeBuddy provider route. */
19
20
  export declare const CODEBUDDY_PROVIDER = "codebuddy";
20
21
  /** Everything the adapter reads lazily from the plugin config. */
@@ -38,6 +39,11 @@ export interface CodeBuddyAdapterOptions {
38
39
  * store) → images degrade to their handle text instead of failing the turn.
39
40
  */
40
41
  readImage?: ImageRequestReader;
42
+ /**
43
+ * The tool-world path of one image, for the handle text that lets the model
44
+ * edit it. Absent → an unreadable image keeps the harness placeholder.
45
+ */
46
+ imagePath?: ImagePathResolver;
41
47
  }
42
48
  /** Map a harness-side id onto a CodeBuddy model value. */
43
49
  export declare function resolveCodeBuddyModelId(model: string, aliases?: Readonly<Record<string, string>>): string;
@@ -49,6 +55,8 @@ export declare class CodeBuddyAdapter extends LlmAdapter {
49
55
  private readonly accounts;
50
56
  private readonly auth;
51
57
  private readonly disabledCache;
58
+ /** Last verified image capability, keyed `${region}:${model}`. */
59
+ private readonly knownVision;
52
60
  constructor(options?: CodeBuddyAdapterOptions);
53
61
  private get region();
54
62
  private disabledFor;
@@ -108,6 +116,18 @@ export declare class CodeBuddyAdapter extends LlmAdapter {
108
116
  stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
109
117
  private dispatch;
110
118
  private firstTurn;
119
+ /**
120
+ * The context window the host and the inner session must agree on.
121
+ *
122
+ * Only a model that offers selectable budgets is configured: one fixed
123
+ * window rejects every value, so the CLI's own default already matches what
124
+ * the host shows. For a model with choices the adapter sends the picked
125
+ * value; returning to "default" sends the model's own default budget, since
126
+ * the CLI rejects a null clear (`contextWindow must be a positive safe
127
+ * integer`). The override lives for the life of the CLI process, so the
128
+ * default has to be sent explicitly to drop a previous choice.
129
+ */
130
+ private windowOption;
111
131
  private cwdOf;
112
132
  close(): void;
113
133
  }
@@ -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. */
@@ -253,6 +253,10 @@ export declare class CodeBuddySession {
253
253
  private effort;
254
254
  private systemPrompt;
255
255
  private cwd;
256
+ /** Context budget the host shows for this session, when a model offers one. */
257
+ private contextWindow;
258
+ /** Budget already pushed to the CLI, keyed by model and value. */
259
+ private appliedWindow;
256
260
  /** Host messages already fed to the inner session, for continuation planning. */
257
261
  fedMessages: readonly import('@deepseek-ai/dsh-llm').RequestMessage[] | undefined;
258
262
  /** Host system prompt last applied; informational for the adapter. */
@@ -266,7 +270,26 @@ export declare class CodeBuddySession {
266
270
  effort?: string;
267
271
  system?: string;
268
272
  cwd?: string;
273
+ contextWindow?: number;
269
274
  }): void;
275
+ /**
276
+ * Push the host-visible context window into the inner session.
277
+ *
278
+ * The CLI resolves its own budget (`override > model default > physical
279
+ * limit`) and both its compaction trigger and the upstream gateway enforce
280
+ * that budget. A global-catalog model such as `deepseek-v4.1-flash` declares
281
+ * `supportedLengths [300K, 1M]` with a 300K default, so a session left alone
282
+ * compacts (and the gateway rejects) anything past 276K — while the host,
283
+ * told 1M, keeps showing and feeding a larger history. Replaying that history
284
+ * then collapses to a summary. Applying the same number the host divides by
285
+ * keeps the two in step; models that expose no choice reject it and keep
286
+ * their default.
287
+ *
288
+ * The CLI refuses to clear the override (`contextWindow must be a positive
289
+ * safe integer`), so the adapter sends the model's default instead when the
290
+ * page returns to "default".
291
+ */
292
+ private applyContextWindow;
270
293
  /**
271
294
  * Remember the host tools and register them with this session's MCP server.
272
295
  *
@@ -41,10 +41,20 @@ interface WebServerService {
41
41
  handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
42
42
  }): () => void;
43
43
  }
44
+ /**
45
+ * The mounted filesystem provider, used only to translate a host path into
46
+ * the execution world the host tools run in. Declared minimally so the plugin
47
+ * keeps only the peer dependencies it actually needs.
48
+ */
49
+ interface FileSystemService {
50
+ processPathFromHostPath?(hostPath: string): string | undefined;
51
+ }
44
52
  declare module '@deepseek-ai/cordis' {
45
53
  interface Context {
46
54
  /** Present only in web compositions; reached through a nested inject. */
47
55
  webServer?: WebServerService;
56
+ /** Present when a filesystem provider is mounted; reached by inject. */
57
+ fs?: FileSystemService;
48
58
  }
49
59
  interface Events {
50
60
  /**
@@ -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 "follow upstream")
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.
@@ -15,6 +15,7 @@ import { MinimaxAuth } from './minimax.ts';
15
15
  import type { MinimaxModel, MinimaxUsageSnapshot } from './minimax.ts';
16
16
  import type { ImageRequestReader } from './adapter.ts';
17
17
  import type { Live } from './live.ts';
18
+ import type { ImagePathResolver } from './render.ts';
18
19
  /** The MiniMax Code provider route. */
19
20
  export declare const MINIMAX_PROVIDER = "minimax-acp";
20
21
  /** Everything the adapter reads lazily from the plugin config. */
@@ -38,6 +39,11 @@ export interface MinimaxAdapterOptions {
38
39
  * store) → images degrade to their handle text instead of failing the turn.
39
40
  */
40
41
  readImage?: ImageRequestReader;
42
+ /**
43
+ * The tool-world path of one image, for the handle text that lets the model
44
+ * edit it. Absent → an unreadable image keeps the harness placeholder.
45
+ */
46
+ imagePath?: ImagePathResolver;
41
47
  }
42
48
  /** Map a harness-side id onto an ACP model value. */
43
49
  export declare function resolveMinimaxModelId(model: string, aliases?: Readonly<Record<string, string>>): string;
@@ -49,6 +55,8 @@ export declare class MinimaxAdapter extends LlmAdapter {
49
55
  private readonly auth;
50
56
  private readonly mcpServer;
51
57
  private readonly disabledCache;
58
+ /** Last verified image capability, keyed `${region}:${model}`. */
59
+ private readonly knownVision;
52
60
  constructor(options?: MinimaxAdapterOptions);
53
61
  private get region();
54
62
  private disabledFor;
@@ -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[]>;
@@ -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
  /**
@@ -22,6 +22,18 @@ export type FeedPart = {
22
22
  type: 'image';
23
23
  attachment: ImageAttachmentRef;
24
24
  };
25
+ /** Resolve the tool-world path of one durable image attachment. */
26
+ export type ImagePathResolver = (ref: ImageAttachmentRef) => string | undefined;
27
+ /**
28
+ * Model-facing handle for one image.
29
+ *
30
+ * The host's native adapters use the same text: it names the attachment, its
31
+ * pixel size and media type, and the read-only normalized copy on disk, and it
32
+ * tells the model to copy that file to a writable path before editing. Pixels
33
+ * alone let a model describe an image but not process it — without this path
34
+ * the model goes looking through the workspace for a file that was never there.
35
+ */
36
+ export declare function imageRefText(ref: ImageAttachmentRef, path: string | undefined): string;
25
37
  /** What one inner turn receives: text (the historical shape) or text + images. */
26
38
  export type Feed = string | FeedPart[];
27
39
  /**
@@ -31,12 +43,12 @@ export type Feed = string | FeedPart[];
31
43
  */
32
44
  export declare function imageRefs(blocks: readonly ContentBlock[]): ImageAttachmentRef[];
33
45
  /** Render one content-block list as plain text; non-text blocks get handles. */
34
- export declare function renderBlocks(blocks: readonly ContentBlock[]): string;
46
+ export declare function renderBlocks(blocks: readonly ContentBlock[], imagePath?: ImagePathResolver): string;
35
47
  /**
36
48
  * Render one request message with its role tag. A request-only user input has
37
49
  * no durable identity or source, so it reads exactly like a user message.
38
50
  */
39
- export declare function renderMessage(message: RequestMessage): string;
51
+ export declare function renderMessage(message: RequestMessage, imagePath?: ImagePathResolver): string;
40
52
  /**
41
53
  * Join feed sections into one feed. While no section carries an image the
42
54
  * result is the historical text shape, sections separated by a blank line;
@@ -55,13 +67,14 @@ export declare function currentTurnStart(messages: readonly RequestMessage[]): n
55
67
  /** Image references carried by a feed, in order. */
56
68
  export declare function feedImageRefs(feed: Feed): ImageAttachmentRef[];
57
69
  /** Flatten a feed back to text, replacing images with the harness handle text. */
58
- export declare function feedToText(feed: Feed): string;
70
+ export declare function feedToText(feed: Feed, imagePath?: ImagePathResolver): string;
59
71
  /** One feed element after image bytes have been resolved (base64). */
60
72
  export type ResolvedFeedPart = {
61
73
  type: 'text';
62
74
  text: string;
63
75
  } | {
64
76
  type: 'image';
77
+ attachment: ImageAttachmentRef;
65
78
  data: string;
66
79
  mediaType: string;
67
80
  } | {
@@ -95,7 +108,7 @@ export declare function feedWideCharCount(feed: Feed): number;
95
108
  * prompt, and the existing conversation as compact context. Messages of the
96
109
  * current turn keep their image references; earlier ones are handles.
97
110
  */
98
- export declare function renderInitialFeed(system: string | undefined, messages: readonly RequestMessage[]): Feed;
111
+ export declare function renderInitialFeed(system: string | undefined, messages: readonly RequestMessage[], imagePath?: ImagePathResolver): Feed;
99
112
  /** Render a brand-new host user turn; images stay references, text-only stays a string. */
100
113
  export declare function renderUserTurn(blocks: readonly ContentBlock[]): Feed;
101
114
  /** Render an in-place-updated message (runtime-context snapshots and the like). */
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.6",
5
+ "version": "1.1.8",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",