dsh-agent-sdk-bridge 1.1.5 → 1.1.6

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 CHANGED
@@ -49,6 +49,15 @@
49
49
  `CODEBUDDY_AUTH_TOKEN` + 该目录启动。页面在切区域时用 `fresh=1` 绕开宿主缓存,并校验
50
50
  `/models` 回显的 `region`。设置页的所有分支都渲染相同的 h2 / intro / 卡片前缀,避免切区时
51
51
  卡片因子节点下标变化被重建、把下拉框弹回配置里的旧区域。
52
+ - **CodeBuddy 的上下文窗口不可设**:目录里的 `contextWindow.supportedLengths` 才是可选项,
53
+ `maxInputTokens` 只是模型物理上限。实测当前目录**所有模型**都报 `supportedLengths: null`,
54
+ 此时 `set_config{contextWindow}` 会被 CLI 拒绝:
55
+ `Invalid context_window value: "200000". Allowed: <none>`。因此 `contextWindows` 只收集
56
+ `supportedLengths`,`contextWindowFor()` 在模型不支持时返回 `undefined`(旧的按区域保存的
57
+ 覆盖值也随之失效),`/models` 回传 `contextWindowSelectable`,页面把这类模型显示为
58
+ 「上游固定」而不是给一个无效下拉框。上游真的声明多档时,菜单与覆盖值会自动恢复。
59
+ 另注:`CBC_SESSION_CONFIG_SYNC=1` 时 `result._meta` 才带 `codebuddy.ai/contextWindow`,
60
+ 它反映的是模型物理窗口(如 1000000),不是用户选择。
52
61
  - **CodeBuddy 额度**:SDK 没有额度方法,`readQuotaWithToken()` 用登录 token 调
53
62
  `POST /v2/billing/meter/get-user-resource`(国内与国际同协议),按积分包汇总实时余额;
54
63
  额度读取优先用保存的 token,缺失时才静默 `authenticate`,不会拉起浏览器。卡片里的积分包
package/FAQ.md CHANGED
@@ -44,6 +44,15 @@ bearer token,只留在本机,请不要分享或提交到仓库。从旧版
44
44
  `tools: []` 禁用 CLI 内置工具,只保留宿主通过 MCP 挂入的工具;CodeBuddy 把 MCP server 名
45
45
  规范成 `dsh_host` 的写法也已兼容。升级后重启 DSH Web 即可。
46
46
 
47
+ **给 CodeBuddy 设了 1M 上下文,为什么对话里上下文环还是忽大忽小、有时突然变小?** 因为那个窗口
48
+ 设置**从未作用于上游**。CodeBuddy 只接受模型自己声明的档位(`contextWindow.supportedLengths`),
49
+ 而当前目录里所有模型都报 `null`;插件把物理上限(`maxInputTokens`)也塞进了可选档位,于是设置页
50
+ 出现了 200K / 1M 开关,实际下发时被 CLI 拒绝:
51
+ `Invalid context_window value: "200000". Allowed: <none>`。上游仍按模型物理窗口运行,而 DSH 却按
52
+ 你选的窗口算百分比,两者不一致,环就会跳。现在可选档位只来自 `supportedLengths`;模型没有档位时
53
+ 页面显示「上游固定 · 1M」而不给下拉框,已保存的无效覆盖值也不再生效。上游将来真提供多档时,
54
+ 选择器会自动出现。
55
+
47
56
  **点了「登录」却没有弹出浏览器,或者弹出了两个?** CodeBuddy 的 CLI 在登录流程里会自己打开
48
57
  浏览器,插件只把登录链接显示在卡片上作为兜底,不再额外打开,所以一次登录只会有一个标签页。
49
58
  每次点击还会先清除该区域在 CLI 中缓存的旧凭据,再启动全新的授权流程;SDK 的 `authenticate()`
package/client.js CHANGED
@@ -62,6 +62,8 @@ window.__ModuleLoader__.load({
62
62
  colEnabled: '启用',
63
63
  windowDefault: '默认',
64
64
  windowDefaultHint: '跟随上游声明的窗口',
65
+ windowFixed: '上游固定',
66
+ windowFixedHint: '该模型在上游只提供这一个上下文窗口,选择其它值会被上游拒绝,因此这里不提供下拉选择。',
65
67
  vision: '读图',
66
68
  free: '免费',
67
69
  advanced: '高级设置',
@@ -250,6 +252,8 @@ window.__ModuleLoader__.load({
250
252
  colEnabled: 'On',
251
253
  windowDefault: 'Default',
252
254
  windowDefaultHint: "Follow upstream's declared window",
255
+ windowFixed: 'fixed upstream',
256
+ windowFixedHint: 'This model offers exactly one context window upstream; any other value is rejected, so there is no selector here.',
253
257
  vision: 'Vision',
254
258
  free: 'Free',
255
259
  advanced: 'Advanced',
@@ -2136,6 +2140,10 @@ window.__ModuleLoader__.load({
2136
2140
 
2137
2141
  const rows = shown.map((m, index) => {
2138
2142
  const choices = Array.isArray(m.contextWindows) ? m.contextWindows : []
2143
+ // A model the provider pins to one window has nothing to choose: the
2144
+ // CLI rejects every other value, so a dropdown here would be a control
2145
+ // that never reaches the upstream. Show the value instead.
2146
+ const fixedWindow = m.contextWindowSelectable === false || choices.length === 0
2139
2147
  return h('div', {
2140
2148
  key: m.id,
2141
2149
  style: { ...css.row, ...(index === 0 ? css.rowFirst : {}), ...(m.enabled ? {} : css.rowOff) },
@@ -2158,19 +2166,24 @@ window.__ModuleLoader__.load({
2158
2166
  ),
2159
2167
  h('div', { style: css.id }, m.id),
2160
2168
  ),
2161
- h('select', {
2162
- style: css.select,
2163
- value: m.override === undefined ? '' : String(m.override),
2164
- disabled: busy,
2165
- title: t('windowDefaultHint'),
2166
- onChange: event => {
2167
- const value = event.target.value
2168
- void writeWindow(all, m.id, value === '' ? undefined : Number(value))
2169
- },
2170
- },
2171
- h('option', { key: 'default', value: '' }, `${t('windowDefault')} · ${windowLabel(m.defaultContextWindow)}`),
2172
- choices.map(n => h('option', { key: String(n), value: String(n) }, windowLabel(n))),
2173
- ),
2169
+ fixedWindow
2170
+ ? h('span', {
2171
+ style: { ...css.note, minWidth: '104px', textAlign: 'right' },
2172
+ title: t('windowFixedHint'),
2173
+ }, `${windowLabel(m.contextWindow ?? m.defaultContextWindow)} · ${t('windowFixed')}`)
2174
+ : h('select', {
2175
+ style: css.select,
2176
+ value: m.override === undefined ? '' : String(m.override),
2177
+ disabled: busy,
2178
+ title: t('windowDefaultHint'),
2179
+ onChange: event => {
2180
+ const value = event.target.value
2181
+ void writeWindow(all, m.id, value === '' ? undefined : Number(value))
2182
+ },
2183
+ },
2184
+ h('option', { key: 'default', value: '' }, `${t('windowDefault')} · ${windowLabel(m.defaultContextWindow)}`),
2185
+ choices.map(n => h('option', { key: String(n), value: String(n) }, windowLabel(n))),
2186
+ ),
2174
2187
  )
2175
2188
  })
2176
2189
 
package/lib/index.js CHANGED
@@ -3488,7 +3488,6 @@ function priceFactorOf$1(model) {
3488
3488
  function toCodeBuddyModel(model) {
3489
3489
  const windows = new Set(model.contextWindow?.supportedLengths ?? []);
3490
3490
  const declared = model.contextWindow?.defaultLength ?? model.maxInputTokens ?? model.maxAllowedSize ?? 2e5;
3491
- windows.add(declared);
3492
3491
  return {
3493
3492
  id: model.id,
3494
3493
  name: model.name ?? model.id,
@@ -3558,6 +3557,15 @@ var CodeBuddyCatalog = class {
3558
3557
  this.ttlMs = ttlMs;
3559
3558
  this.timeoutMs = timeoutMs;
3560
3559
  }
3560
+ /**
3561
+ * The last catalog read for a region, without fetching.
3562
+ *
3563
+ * Callers that must answer synchronously (deciding whether a model exposes a
3564
+ * context-budget choice) use this instead of awaiting a refresh.
3565
+ */
3566
+ snapshot(requested) {
3567
+ return this.snapshots.get(requested ?? readLive(this.region, "global"))?.models ?? [];
3568
+ }
3561
3569
  /** Models for one region; a failed refresh keeps the last good list. */
3562
3570
  async models(requested) {
3563
3571
  const region = requested ?? readLive(this.region, "global");
@@ -4921,8 +4929,30 @@ var CodeBuddyAdapter = class extends LlmAdapter {
4921
4929
  }
4922
4930
  return content;
4923
4931
  }
4932
+ /**
4933
+ * The window this model actually runs with.
4934
+ *
4935
+ * The user's override only applies where the provider accepts one. Every
4936
+ * model in the current catalog reports `supportedLengths: null`, so the CLI
4937
+ * answers a `set_config.contextWindow` with `Allowed: <none>`; a stored
4938
+ * override would then make DSH show a denominator the upstream never uses,
4939
+ * which is exactly how the context ring drifted.
4940
+ */
4924
4941
  contextWindowFor(id, region = this.region) {
4925
- return this.options.modelContextWindows?.(region)[id];
4942
+ const override = this.options.modelContextWindows?.(region)[id];
4943
+ if (override === void 0) return void 0;
4944
+ const live = this.models(region).find((entry) => entry.id === id);
4945
+ if (live === void 0) return override;
4946
+ return live.contextWindows.includes(override) ? override : void 0;
4947
+ }
4948
+ /** The catalog snapshot the adapter last read (empty before the first read). */
4949
+ models(region) {
4950
+ return this.catalog.snapshot(region);
4951
+ }
4952
+ /** Whether this model lets the user pick a context budget at all. */
4953
+ supportsContextWindowChoice(id, region = this.region) {
4954
+ const live = this.models(region).find((entry) => entry.id === id);
4955
+ return live !== void 0 && live.contextWindows.length > 0;
4926
4956
  }
4927
4957
  async listModels(provider) {
4928
4958
  const region = this.region;
@@ -8018,7 +8048,6 @@ async function buildCodeBuddyRows(adapter, region) {
8018
8048
  return (await adapter.describeCatalog(region)).map((entry) => {
8019
8049
  const override = adapter.contextWindowFor(entry.id, region);
8020
8050
  const choices = new Set(entry.contextWindows);
8021
- choices.add(entry.defaultContextWindow);
8022
8051
  if (override !== void 0) choices.add(override);
8023
8052
  return {
8024
8053
  id: entry.id,
@@ -8031,7 +8060,8 @@ async function buildCodeBuddyRows(adapter, region) {
8031
8060
  defaultContextWindow: entry.defaultContextWindow,
8032
8061
  ...override === void 0 ? {} : { override },
8033
8062
  ...entry.priceFactor === void 0 ? {} : { priceFactor: entry.priceFactor },
8034
- reasoning: (entry.reasoningEfforts?.length ?? 0) > 0
8063
+ reasoning: (entry.reasoningEfforts?.length ?? 0) > 0,
8064
+ contextWindowSelectable: entry.contextWindows.length > 0
8035
8065
  };
8036
8066
  });
8037
8067
  }
@@ -38,6 +38,13 @@ export interface ModelRow {
38
38
  override?: number;
39
39
  priceFactor?: number;
40
40
  reasoning: boolean;
41
+ /**
42
+ * Whether the provider accepts a context-budget choice for this model.
43
+ *
44
+ * Absent (Qoder, MiniMax) means the ordinary menu applies. `false` means the
45
+ * window is fixed upstream, so the page shows the value without a selector.
46
+ */
47
+ contextWindowSelectable?: boolean;
41
48
  }
42
49
  /** The adapters the API can reach, one per provider route. */
43
50
  export type AdapterMap = Readonly<Record<BrandId, QoderAdapter | CodeBuddyAdapter | MinimaxAdapter>>;
@@ -88,7 +88,20 @@ export declare class CodeBuddyAdapter extends LlmAdapter {
88
88
  * only shape the CLI sends to the model as pixels.
89
89
  */
90
90
  private buildFeed;
91
+ /**
92
+ * The window this model actually runs with.
93
+ *
94
+ * The user's override only applies where the provider accepts one. Every
95
+ * model in the current catalog reports `supportedLengths: null`, so the CLI
96
+ * answers a `set_config.contextWindow` with `Allowed: <none>`; a stored
97
+ * override would then make DSH show a denominator the upstream never uses,
98
+ * which is exactly how the context ring drifted.
99
+ */
91
100
  contextWindowFor(id: string, region?: CodeBuddyRegion): number | undefined;
101
+ /** The catalog snapshot the adapter last read (empty before the first read). */
102
+ private models;
103
+ /** Whether this model lets the user pick a context budget at all. */
104
+ supportsContextWindowChoice(id: string, region?: CodeBuddyRegion): boolean;
92
105
  listModels(provider: string): Promise<readonly LlmModelInfo[]>;
93
106
  resolveModel(provider: string, model: string): Promise<LlmResolvedModelInfo>;
94
107
  prepareCall(provider: string, model: string, signal?: AbortSignal): Promise<PreparedAdapterCall>;
@@ -32,7 +32,16 @@ export interface CodeBuddyModel {
32
32
  description?: string;
33
33
  maxInputTokens?: number;
34
34
  maxOutputTokens?: number;
35
+ /**
36
+ * Context budgets the provider actually accepts for this model.
37
+ *
38
+ * Empty means the model exposes no selectable window: CodeBuddy validates
39
+ * `set_config.contextWindow` against `contextWindow.supportedLengths` and
40
+ * rejects everything else with `Allowed: <none>`, so the settings page must
41
+ * not offer a choice the CLI will refuse.
42
+ */
35
43
  contextWindows: number[];
44
+ /** The window the model actually runs with (its physical input limit). */
36
45
  defaultContextWindow: number;
37
46
  vision: boolean;
38
47
  reasoningEfforts?: string[];
@@ -111,6 +120,13 @@ export declare class CodeBuddyCatalog {
111
120
  private readonly inflight;
112
121
  private readonly failures;
113
122
  constructor(region: Live<CodeBuddyRegion>, ttlMs?: Live<number>, timeoutMs?: Live<number>);
123
+ /**
124
+ * The last catalog read for a region, without fetching.
125
+ *
126
+ * Callers that must answer synchronously (deciding whether a model exposes a
127
+ * context-budget choice) use this instead of awaiting a refresh.
128
+ */
129
+ snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[];
114
130
  /** Models for one region; a failed refresh keeps the last good list. */
115
131
  models(requested?: CodeBuddyRegion): Promise<readonly CodeBuddyModel[]>;
116
132
  /** Why the last refresh failed, or undefined when it succeeded. */
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.5",
5
+ "version": "1.1.6",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "author": "k1-h2",
package/src/api.ts CHANGED
@@ -45,6 +45,13 @@ export interface ModelRow {
45
45
  override?: number
46
46
  priceFactor?: number
47
47
  reasoning: boolean
48
+ /**
49
+ * Whether the provider accepts a context-budget choice for this model.
50
+ *
51
+ * Absent (Qoder, MiniMax) means the ordinary menu applies. `false` means the
52
+ * window is fixed upstream, so the page shows the value without a selector.
53
+ */
54
+ contextWindowSelectable?: boolean
48
55
  }
49
56
 
50
57
  /** The adapters the API can reach, one per provider route. */
@@ -98,9 +105,12 @@ export async function buildCodeBuddyRows(
98
105
  ): Promise<ModelRow[]> {
99
106
  const live = await adapter.describeCatalog(region)
100
107
  return live.map(entry => {
108
+ // Only windows the provider accepts are offered. CodeBuddy validates
109
+ // `set_config.contextWindow` against `contextWindow.supportedLengths` and
110
+ // answers anything else with `Allowed: <none>`, so a menu entry the CLI
111
+ // refuses would be a switch that does nothing upstream.
101
112
  const override = adapter.contextWindowFor(entry.id, region)
102
113
  const choices = new Set<number>(entry.contextWindows)
103
- choices.add(entry.defaultContextWindow)
104
114
  if (override !== undefined) choices.add(override)
105
115
  return {
106
116
  id: entry.id,
@@ -114,6 +124,7 @@ export async function buildCodeBuddyRows(
114
124
  ...override === undefined ? {} : { override },
115
125
  ...entry.priceFactor === undefined ? {} : { priceFactor: entry.priceFactor },
116
126
  reasoning: (entry.reasoningEfforts?.length ?? 0) > 0,
127
+ contextWindowSelectable: entry.contextWindows.length > 0,
117
128
  }
118
129
  })
119
130
  }
@@ -259,8 +259,32 @@ export class CodeBuddyAdapter extends LlmAdapter {
259
259
  return content
260
260
  }
261
261
 
262
+ /**
263
+ * The window this model actually runs with.
264
+ *
265
+ * The user's override only applies where the provider accepts one. Every
266
+ * model in the current catalog reports `supportedLengths: null`, so the CLI
267
+ * answers a `set_config.contextWindow` with `Allowed: <none>`; a stored
268
+ * override would then make DSH show a denominator the upstream never uses,
269
+ * which is exactly how the context ring drifted.
270
+ */
262
271
  contextWindowFor(id: string, region: CodeBuddyRegion = this.region): number | undefined {
263
- return this.options.modelContextWindows?.(region)[id]
272
+ const override = this.options.modelContextWindows?.(region)[id]
273
+ if (override === undefined) return undefined
274
+ const live = this.models(region).find(entry => entry.id === id)
275
+ if (live === undefined) return override
276
+ return live.contextWindows.includes(override) ? override : undefined
277
+ }
278
+
279
+ /** The catalog snapshot the adapter last read (empty before the first read). */
280
+ private models(region: CodeBuddyRegion): readonly CodeBuddyModel[] {
281
+ return this.catalog.snapshot(region)
282
+ }
283
+
284
+ /** Whether this model lets the user pick a context budget at all. */
285
+ supportsContextWindowChoice(id: string, region: CodeBuddyRegion = this.region): boolean {
286
+ const live = this.models(region).find(entry => entry.id === id)
287
+ return live !== undefined && live.contextWindows.length > 0
264
288
  }
265
289
 
266
290
  override async listModels(provider: string): Promise<readonly LlmModelInfo[]> {
package/src/codebuddy.ts CHANGED
@@ -108,7 +108,16 @@ export interface CodeBuddyModel {
108
108
  description?: string
109
109
  maxInputTokens?: number
110
110
  maxOutputTokens?: number
111
+ /**
112
+ * Context budgets the provider actually accepts for this model.
113
+ *
114
+ * Empty means the model exposes no selectable window: CodeBuddy validates
115
+ * `set_config.contextWindow` against `contextWindow.supportedLengths` and
116
+ * rejects everything else with `Allowed: <none>`, so the settings page must
117
+ * not offer a choice the CLI will refuse.
118
+ */
111
119
  contextWindows: number[]
120
+ /** The window the model actually runs with (its physical input limit). */
112
121
  defaultContextWindow: number
113
122
  vision: boolean
114
123
  reasoningEfforts?: string[]
@@ -256,12 +265,15 @@ function priceFactorOf(model: RawLanguageModel): number | undefined {
256
265
 
257
266
  /** Turn one raw catalog entry into the model row this plugin uses. */
258
267
  export function toCodeBuddyModel(model: RawLanguageModel): CodeBuddyModel {
268
+ // Only what the provider declares as selectable is a choice. The physical
269
+ // `maxInputTokens` is the window the model runs with, not a menu entry:
270
+ // folding it into `contextWindows` offered 200K/1M switches that the CLI
271
+ // answered with `Invalid context_window value … Allowed: <none>`.
259
272
  const windows = new Set<number>(model.contextWindow?.supportedLengths ?? [])
260
273
  const declared = model.contextWindow?.defaultLength
261
274
  ?? model.maxInputTokens
262
275
  ?? model.maxAllowedSize
263
276
  ?? CODEBUDDY_DEFAULT_CONTEXT_WINDOW
264
- windows.add(declared)
265
277
  return {
266
278
  id: model.id,
267
279
  name: model.name ?? model.id,
@@ -334,6 +346,16 @@ export class CodeBuddyCatalog {
334
346
  private readonly timeoutMs: Live<number> = CODEBUDDY_FETCH_TIMEOUT_MS,
335
347
  ) {}
336
348
 
349
+ /**
350
+ * The last catalog read for a region, without fetching.
351
+ *
352
+ * Callers that must answer synchronously (deciding whether a model exposes a
353
+ * context-budget choice) use this instead of awaiting a refresh.
354
+ */
355
+ snapshot(requested?: CodeBuddyRegion): readonly CodeBuddyModel[] {
356
+ return this.snapshots.get(requested ?? readLive(this.region, 'global'))?.models ?? []
357
+ }
358
+
337
359
  /** Models for one region; a failed refresh keeps the last good list. */
338
360
  async models(requested?: CodeBuddyRegion): Promise<readonly CodeBuddyModel[]> {
339
361
  const region = requested ?? readLive(this.region, 'global')