dsh-agent-sdk-bridge 1.0.0 → 1.1.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/src/api.ts CHANGED
@@ -22,10 +22,12 @@
22
22
  import type { IncomingMessage, ServerResponse } from 'node:http'
23
23
  import type { QoderAdapter } from './adapter.ts'
24
24
  import type { CodeBuddyAdapter } from './codebuddy-adapter.ts'
25
- import type { BrandId, CodeBuddyRegion } from './brand.ts'
25
+ import type { MinimaxAdapter } from './minimax-adapter.ts'
26
+ import type { BrandId, CodeBuddyRegion, MinimaxRegion } from './brand.ts'
26
27
  import { isBrandId, isCodeBuddyRegion } from './brand.ts'
27
28
  import { priceFactorOf } from './models.ts'
28
29
  import { isSetupMode, readSetupStatus, startSetup } from './setup.ts'
30
+ import { isMinimaxSetupMode, readMinimaxSetupStatus, startMinimaxSetup } from './minimax-cli.ts'
29
31
 
30
32
  /** Route prefix this plugin owns; the client resolves it relative to the page. */
31
33
  export const API_PREFIX = '/api/llm-qoder-cn'
@@ -46,7 +48,7 @@ export interface ModelRow {
46
48
  }
47
49
 
48
50
  /** The adapters the API can reach, one per provider route. */
49
- export type AdapterMap = Readonly<Record<BrandId, QoderAdapter | CodeBuddyAdapter>>
51
+ export type AdapterMap = Readonly<Record<BrandId, QoderAdapter | CodeBuddyAdapter | MinimaxAdapter>>
50
52
 
51
53
  /** Answer one request with JSON. */
52
54
  function send(res: ServerResponse, status: number, payload: unknown): void {
@@ -116,6 +118,32 @@ export async function buildCodeBuddyRows(
116
118
  })
117
119
  }
118
120
 
121
+ /** Build model rows for the MiniMax adapter, for one login region. */
122
+ export async function buildMinimaxRows(
123
+ adapter: MinimaxAdapter,
124
+ region?: MinimaxRegion,
125
+ ): Promise<ModelRow[]> {
126
+ const live = await adapter.describeCatalog(region)
127
+ return live.map(entry => {
128
+ const override = adapter.contextWindowFor(entry.id, region)
129
+ const choices = new Set<number>(entry.contextWindows)
130
+ choices.add(entry.defaultContextWindow)
131
+ if (override !== undefined) choices.add(override)
132
+ return {
133
+ id: entry.id,
134
+ name: entry.name,
135
+ ...entry.description === undefined ? {} : { description: entry.description },
136
+ enabled: !adapter.isModelDisabled(entry.id, region),
137
+ vision: entry.vision,
138
+ contextWindow: override ?? entry.defaultContextWindow,
139
+ contextWindows: [...choices].sort((a, b) => a - b),
140
+ defaultContextWindow: entry.defaultContextWindow,
141
+ ...override === undefined ? {} : { override },
142
+ reasoning: entry.reasoning,
143
+ }
144
+ })
145
+ }
146
+
119
147
  /** Largest request body this route accepts. */
120
148
  const MAX_BODY_BYTES = 2048
121
149
 
@@ -159,31 +187,38 @@ export async function handleApi(
159
187
  const queryBrand = brandFrom(url.searchParams.get('brand'))
160
188
 
161
189
  if (queryBrand === undefined) {
162
- send(res, 400, { error: 'brand 只接受 cn、global 或 codebuddy' })
190
+ send(res, 400, { error: 'brand 只接受 cn、global、codebuddy 或 minimax' })
163
191
  return
164
192
  }
165
193
  const adapter = adapters[queryBrand]
166
194
  const codebuddy = queryBrand === 'codebuddy' ? adapter as CodeBuddyAdapter : undefined
195
+ const minimax = queryBrand === 'minimax' ? adapter as MinimaxAdapter : undefined
196
+ const regional = codebuddy !== undefined || minimax !== undefined
167
197
 
168
198
  if (path === '/models' && method === 'GET') {
169
199
  const requestedRegion = url.searchParams.get('region')
170
200
  const region = requestedRegion === null || requestedRegion === ''
171
201
  ? undefined
172
202
  : regionFrom(requestedRegion)
173
- if (codebuddy !== undefined && region === undefined && requestedRegion !== null && requestedRegion !== '') {
203
+ if (regional && region === undefined && requestedRegion !== null && requestedRegion !== '') {
174
204
  send(res, 400, { error: 'region 只接受 global 或 cn' })
175
205
  return
176
206
  }
177
207
  if (url.searchParams.get('fresh') === '1') {
178
208
  if (codebuddy !== undefined) codebuddy.invalidateCatalog(region)
209
+ else if (minimax !== undefined) minimax.invalidateCatalog(region)
179
210
  else adapter.invalidateCatalog()
180
211
  }
181
- const signedIn = codebuddy?.isSignedIn(region)
212
+ const signedIn = codebuddy?.isSignedIn(region) ?? minimax?.isSignedIn(region)
182
213
  const rows = codebuddy !== undefined
183
214
  ? signedIn === false ? [] : await buildCodeBuddyRows(codebuddy, region)
184
- : await buildRows(adapter as QoderAdapter)
215
+ : minimax !== undefined
216
+ ? signedIn === false ? [] : await buildMinimaxRows(minimax, region)
217
+ : await buildRows(adapter as QoderAdapter)
185
218
  const notice = rows.length === 0
186
- ? codebuddy === undefined ? adapter.catalogError() : codebuddy.catalogError(region)
219
+ ? codebuddy !== undefined
220
+ ? codebuddy.catalogError(region)
221
+ : minimax !== undefined ? minimax.catalogError(region) : adapter.catalogError()
187
222
  : undefined
188
223
  send(res, 200, {
189
224
  brand: queryBrand,
@@ -192,6 +227,7 @@ export async function handleApi(
192
227
  // the other login: a harmless extra field for the Qoder brands.
193
228
  ...region === undefined ? {} : { region },
194
229
  ...signedIn === undefined ? {} : { signedIn },
230
+ ...minimax === undefined ? {} : { regionBlocked: minimax.regionBlocked(region) },
195
231
  ...notice === undefined ? {} : { notice },
196
232
  })
197
233
  return
@@ -200,25 +236,30 @@ export async function handleApi(
200
236
  if (path === '/usage' && method === 'GET') {
201
237
  const requested = url.searchParams.get('region')
202
238
  const region = requested === null || requested === '' ? undefined : regionFrom(requested)
203
- if (codebuddy !== undefined && region === undefined && requested !== null && requested !== '') {
239
+ if (regional && region === undefined && requested !== null && requested !== '') {
204
240
  send(res, 400, { error: 'region 只接受 global 或 cn' })
205
241
  return
206
242
  }
243
+ const fresh = url.searchParams.get('fresh') === '1'
207
244
  const snapshot = codebuddy !== undefined
208
- ? await codebuddy.usageInfo(url.searchParams.get('fresh') === '1', region)
209
- : await adapter.usageInfo(url.searchParams.get('fresh') === '1')
245
+ ? await codebuddy.usageInfo(fresh, region)
246
+ : minimax !== undefined
247
+ ? await minimax.usageInfo(fresh, region)
248
+ : await adapter.usageInfo(fresh)
210
249
  send(res, 200, {
211
250
  brand: queryBrand,
212
251
  ...snapshot,
213
- ...codebuddy === undefined ? {} : { signedIn: codebuddy.isSignedIn(region) },
252
+ ...codebuddy === undefined && minimax === undefined
253
+ ? {}
254
+ : { signedIn: (codebuddy ?? minimax)!.isSignedIn(region) },
214
255
  })
215
256
  return
216
257
  }
217
258
 
218
259
  if (path === '/auth') {
219
260
  if (method === 'GET') {
220
- if (codebuddy === undefined) {
221
- send(res, 404, { error: '该 provider 没有 CodeBuddy 登录流程' })
261
+ if (codebuddy === undefined && minimax === undefined) {
262
+ send(res, 404, { error: '该 provider 没有浏览器登录流程' })
222
263
  return
223
264
  }
224
265
  const region = regionFrom(url.searchParams.get('region'))
@@ -226,7 +267,9 @@ export async function handleApi(
226
267
  send(res, 400, { error: 'region 只接受 global 或 cn' })
227
268
  return
228
269
  }
229
- send(res, 200, { brand: 'codebuddy', ...codebuddy.authStatus(region) })
270
+ send(res, 200, codebuddy !== undefined
271
+ ? { brand: 'codebuddy', ...codebuddy.authStatus(region) }
272
+ : { brand: 'minimax', ...minimax!.authStatus(region) })
230
273
  return
231
274
  }
232
275
  if (method === 'POST') {
@@ -239,46 +282,64 @@ export async function handleApi(
239
282
  }
240
283
  // A POST selects its provider in the body: the page never puts the
241
284
  // brand in the URL for writes.
242
- if (brandFrom(body.brand) !== 'codebuddy') {
243
- send(res, 400, { error: '该 provider 没有 CodeBuddy 登录流程' })
285
+ const postBrand = brandFrom(body.brand)
286
+ if (postBrand !== 'codebuddy' && postBrand !== 'minimax') {
287
+ send(res, 400, { error: '该 provider 没有浏览器登录流程' })
244
288
  return
245
289
  }
246
- const cb = adapters.codebuddy as CodeBuddyAdapter
247
290
  const region = regionFrom(body.region)
248
291
  if (region === undefined) {
249
292
  send(res, 400, { error: 'region 只接受 global 或 cn' })
250
293
  return
251
294
  }
252
- if (body.action === 'logout') {
253
- const result = await cb.logout(region)
254
- if (!result.ok) {
255
- send(res, 500, { error: result.error })
295
+ if (body.action !== 'login' && body.action !== 'logout') {
296
+ send(res, 400, { error: 'action 只接受 login 或 logout' })
297
+ return
298
+ }
299
+ if (postBrand === 'codebuddy') {
300
+ const cb = adapters.codebuddy as CodeBuddyAdapter
301
+ if (body.action === 'logout') {
302
+ const result = await cb.logout(region)
303
+ if (!result.ok) {
304
+ send(res, 500, { error: result.error })
305
+ return
306
+ }
307
+ send(res, 200, { brand: 'codebuddy', ...cb.authStatus(region) })
308
+ return
309
+ }
310
+ const started = cb.startLogin(region)
311
+ if (started.started === false) {
312
+ send(res, 409, { error: started.error })
256
313
  return
257
314
  }
258
315
  send(res, 200, { brand: 'codebuddy', ...cb.authStatus(region) })
259
316
  return
260
317
  }
261
- if (body.action !== 'login') {
262
- send(res, 400, { error: 'action 只接受 login 或 logout' })
318
+ const mm = adapters.minimax as MinimaxAdapter
319
+ if (body.action === 'logout') {
320
+ send(res, 200, { brand: 'minimax', ...await mm.logout(region) })
263
321
  return
264
322
  }
265
- const started = cb.startLogin(region)
323
+ const started = mm.startLogin(region)
266
324
  if (started.started === false) {
267
325
  send(res, 409, { error: started.error })
268
326
  return
269
327
  }
270
- send(res, 200, { brand: 'codebuddy', ...cb.authStatus(region) })
328
+ send(res, 200, { brand: 'minimax', ...mm.authStatus(region) })
271
329
  return
272
330
  }
273
331
  }
274
332
 
275
333
  if (path === '/setup') {
276
- if (codebuddy !== undefined) {
277
- send(res, 400, { error: 'CodeBuddy 不需要安装 CLI,请在页面中登录' })
278
- return
279
- }
280
- const qoder = adapter as QoderAdapter
281
334
  if (method === 'GET') {
335
+ if (codebuddy !== undefined) {
336
+ send(res, 400, { error: 'CodeBuddy 不需要安装 CLI,请在页面中登录' })
337
+ return
338
+ }
339
+ if (minimax !== undefined) {
340
+ send(res, 200, readMinimaxSetupStatus())
341
+ return
342
+ }
282
343
  send(res, 200, readSetupStatus(queryBrand as 'cn' | 'global'))
283
344
  return
284
345
  }
@@ -290,15 +351,40 @@ export async function handleApi(
290
351
  send(res, 400, { error: `请求体无法解析:${error instanceof Error ? error.message : String(error)}` })
291
352
  return
292
353
  }
354
+ // A POST selects its provider in the body; the query string may name
355
+ // none at all, which is why this cannot reuse the GET's brand.
293
356
  const postBrand = brandFrom(parsed.brand)
294
- if (postBrand === undefined || postBrand === 'codebuddy') {
295
- send(res, 400, { error: '该 brand 没有 CLI 安装脚本' })
357
+ if (postBrand === undefined) {
358
+ send(res, 400, { error: 'brand 只接受 cn、global、codebuddy 或 minimax' })
359
+ return
360
+ }
361
+ if (postBrand === 'codebuddy') {
362
+ send(res, 400, { error: 'CodeBuddy 不需要安装 CLI,请在页面中登录' })
363
+ return
364
+ }
365
+ if (postBrand === 'minimax') {
366
+ if (!isMinimaxSetupMode(parsed.mode)) {
367
+ send(res, 400, { error: 'mode 只接受 install 或 uninstall' })
368
+ return
369
+ }
370
+ const mm = adapters.minimax as MinimaxAdapter
371
+ const result = startMinimaxSetup(parsed.mode, code => {
372
+ if (code !== 0) return
373
+ mm.invalidateCatalog()
374
+ mm.invalidateUsage()
375
+ })
376
+ if (!result.started) {
377
+ send(res, result.reason === 'busy' ? 409 : 501, { error: result.error })
378
+ return
379
+ }
380
+ send(res, 200, readMinimaxSetupStatus())
296
381
  return
297
382
  }
298
383
  if (!isSetupMode(parsed.mode)) {
299
384
  send(res, 400, { error: 'mode 只接受 configure、login 或 uninstall' })
300
385
  return
301
386
  }
387
+ const qoder = adapters[postBrand] as QoderAdapter
302
388
  const result = startSetup(postBrand, parsed.mode, code => {
303
389
  if (code === 0) {
304
390
  qoder.invalidateCatalog()
@@ -313,6 +399,8 @@ export async function handleApi(
313
399
  send(res, 200, readSetupStatus(postBrand))
314
400
  return
315
401
  }
402
+ send(res, 405, { error: '不支持的写入路径' })
403
+ return
316
404
  }
317
405
 
318
406
  send(res, method === 'GET' ? 404 : 405, { error: method === 'GET' ? 'not found' : '不支持的写入路径' })
package/src/brand.ts CHANGED
@@ -14,15 +14,20 @@
14
14
  export type QoderBrand = 'cn' | 'global'
15
15
  /** The CodeBuddy integration. Its login region is a config choice, not a brand. */
16
16
  export type CodeBuddyBrandId = 'codebuddy'
17
+ /** The MiniMax Code integration, spoken over ACP. */
18
+ export type MinimaxBrandId = 'minimax'
17
19
  /** Every provider route this plugin registers. */
18
- export type BrandId = QoderBrand | CodeBuddyBrandId
20
+ export type BrandId = QoderBrand | CodeBuddyBrandId | MinimaxBrandId
19
21
 
20
22
  /** Which SDK family a brand belongs to. */
21
- export type BrandFamily = 'qoder' | 'codebuddy'
23
+ export type BrandFamily = 'qoder' | 'codebuddy' | 'minimax'
22
24
 
23
25
  /** CodeBuddy's two public login regions. Enterprise domains are out of scope. */
24
26
  export type CodeBuddyRegion = 'global' | 'cn'
25
27
 
28
+ /** MiniMax Code's two public login regions. */
29
+ export type MinimaxRegion = 'global' | 'cn'
30
+
26
31
  /** Everything that differs between provider brands. */
27
32
  export interface BrandProfile {
28
33
  id: BrandId
@@ -32,7 +37,7 @@ export interface BrandProfile {
32
37
  /** Display name used when the config leaves it empty. */
33
38
  defaultDisplayName: string
34
39
  /** Config field that switches this brand on or off. */
35
- enabledKey: 'cnEnabled' | 'intlEnabled' | 'codebuddyEnabled'
40
+ enabledKey: 'cnEnabled' | 'intlEnabled' | 'codebuddyEnabled' | 'minimaxEnabled'
36
41
  /** SDK package that speaks this brand's protocol. */
37
42
  sdkPackage: string
38
43
  /** npm packages the CLI can be installed as, most specific first. */
@@ -105,8 +110,30 @@ export const CODEBUDDY_BRAND: BrandProfile = {
105
110
  staticCatalog: false,
106
111
  }
107
112
 
113
+ /**
114
+ * MiniMax Code, spoken over the Agent Client Protocol.
115
+ *
116
+ * `mcode acp` runs as a stdio ACP server. Unlike CodeBuddy, there is no SDK
117
+ * package to import: the plugin speaks the protocol directly and the CLI owns
118
+ * login, model selection and the upstream account. The login region is a
119
+ * config choice (`MAVIS_REGION` pins each process), not a brand.
120
+ */
121
+ export const MINIMAX_BRAND: BrandProfile = {
122
+ id: 'minimax',
123
+ family: 'minimax',
124
+ provider: 'minimax-acp',
125
+ defaultDisplayName: 'MiniMax Code',
126
+ enabledKey: 'minimaxEnabled',
127
+ sdkPackage: '@agentclientprotocol/sdk',
128
+ cliPackages: [{ scope: '@minimax-ai', name: 'code' }],
129
+ cliCommands: ['mcode'],
130
+ configDirName: '.minimax',
131
+ setupScript: null,
132
+ staticCatalog: false,
133
+ }
134
+
108
135
  /** Every brand, in the order the settings pages list them. */
109
- export const BRANDS: readonly BrandProfile[] = [CN_BRAND, GLOBAL_BRAND, CODEBUDDY_BRAND]
136
+ export const BRANDS: readonly BrandProfile[] = [CN_BRAND, GLOBAL_BRAND, CODEBUDDY_BRAND, MINIMAX_BRAND]
110
137
 
111
138
  /** Whether a value names a Qoder edition. */
112
139
  export function isQoderBrand(value: unknown): value is QoderBrand {
@@ -115,7 +142,7 @@ export function isQoderBrand(value: unknown): value is QoderBrand {
115
142
 
116
143
  /** Whether a value names one of the provider brands. */
117
144
  export function isBrandId(value: unknown): value is BrandId {
118
- return isQoderBrand(value) || value === 'codebuddy'
145
+ return isQoderBrand(value) || value === 'codebuddy' || value === 'minimax'
119
146
  }
120
147
 
121
148
  /** Whether a value names a CodeBuddy login region. */
@@ -123,12 +150,29 @@ export function isCodeBuddyRegion(value: unknown): value is CodeBuddyRegion {
123
150
  return value === 'global' || value === 'cn'
124
151
  }
125
152
 
153
+ /** Whether a value names a MiniMax Code login region. */
154
+ export function isMinimaxRegion(value: unknown): value is MinimaxRegion {
155
+ return value === 'global' || value === 'cn'
156
+ }
157
+
126
158
  /** The profile for one brand. */
127
159
  export function brandProfile(brand: BrandId): BrandProfile {
128
160
  if (brand === 'codebuddy') return CODEBUDDY_BRAND
161
+ if (brand === 'minimax') return MINIMAX_BRAND
129
162
  return brand === 'global' ? GLOBAL_BRAND : CN_BRAND
130
163
  }
131
164
 
165
+ /**
166
+ * The region name the MiniMax CLI uses internally.
167
+ *
168
+ * The CLI calls the mainland site `cn` and the international one `en`; its
169
+ * login command accepts `global` and maps it to `en`. Processes are pinned
170
+ * with `MAVIS_REGION`, which also expects `cn`/`en`.
171
+ */
172
+ export function minimaxCliRegion(region: MinimaxRegion): 'cn' | 'en' {
173
+ return region === 'cn' ? 'cn' : 'en'
174
+ }
175
+
132
176
  /** The SDK environment a CodeBuddy region logs into. */
133
177
  export function codeBuddyEnvironment(region: CodeBuddyRegion): 'external' | 'internal' {
134
178
  return region === 'cn' ? 'internal' : 'external'
package/src/codebuddy.ts CHANGED
@@ -48,6 +48,28 @@ const LOGOUT_TIMEOUT_MS = 20_000
48
48
  type SessionImpl = ReturnType<typeof import('@tencent-ai/agent-sdk').unstable_v2_createSession>
49
49
 
50
50
  const MCP_TOOL_PREFIX = `mcp__${MCP_SERVER_NAME}__`
51
+ /**
52
+ * The same namespace after the CLI normalises the server name.
53
+ *
54
+ * CodeBuddy rewrites every non-alphanumeric character in an MCP server name to
55
+ * `_`, so a server registered as `dsh-host` is exposed to the model as
56
+ * `mcp__dsh_host__<tool>`. Matching only the registered spelling rejected the
57
+ * host's own tools as "built-ins", which is exactly why the model fell back to
58
+ * `Bash`. The Qoder CLI keeps the hyphen, so both spellings are accepted.
59
+ */
60
+ const MCP_TOOL_PREFIX_SANITIZED = `mcp__${MCP_SERVER_NAME.replace(/[^a-zA-Z0-9]/g, '_')}__`
61
+
62
+ /** Whether a CLI tool name belongs to this plugin's MCP server. */
63
+ function isHostTool(toolName: string): boolean {
64
+ return toolName.startsWith(MCP_TOOL_PREFIX) || toolName.startsWith(MCP_TOOL_PREFIX_SANITIZED)
65
+ }
66
+
67
+ /** The host-side tool name, with the MCP namespace removed. */
68
+ function hostToolName(toolName: string): string {
69
+ if (toolName.startsWith(MCP_TOOL_PREFIX)) return toolName.slice(MCP_TOOL_PREFIX.length)
70
+ if (toolName.startsWith(MCP_TOOL_PREFIX_SANITIZED)) return toolName.slice(MCP_TOOL_PREFIX_SANITIZED.length)
71
+ return toolName
72
+ }
51
73
 
52
74
  /** One model as the settings page and the adapter see it. */
53
75
  export interface CodeBuddyModel {
@@ -785,6 +807,7 @@ export class CodeBuddySession {
785
807
  private mcp: ReturnType<typeof import('@tencent-ai/agent-sdk').createSdkMcpServer> | null = null
786
808
  private readonly pairing = new ToolResultPairing()
787
809
  private readonly registered = new Map<string, string>()
810
+ private toolSchemas: readonly { name: string, description: string, parameters?: unknown }[] = []
788
811
  private queue: TurnQueue | null = null
789
812
  private disposed = false
790
813
  private abortPending = false
@@ -831,10 +854,24 @@ export class CodeBuddySession {
831
854
  if (options.cwd !== undefined) this.cwd = options.cwd
832
855
  }
833
856
 
834
- /** Register any host tools whose schema this session's MCP server lacks. */
857
+ /**
858
+ * Remember the host tools and register them with this session's MCP server.
859
+ *
860
+ * Registration must happen before the CLI connects: the MCP SDK refuses a
861
+ * tool added afterwards. The first turn calls this before the session — and
862
+ * therefore its MCP server — exists, so the schemas are kept and replayed by
863
+ * {@link ensureStarted}. Returning early there left the model with no host
864
+ * tools at all, and it fell back to CodeBuddy's built-in `Bash`, which the
865
+ * host could only answer with "unknown tool".
866
+ */
835
867
  ensureTools(tools: readonly { name: string, description: string, parameters?: unknown }[]): void {
868
+ this.toolSchemas = tools
869
+ this.registerTools()
870
+ }
871
+
872
+ private registerTools(): void {
836
873
  if (this.mcp === null) return
837
- for (const schema of tools) {
874
+ for (const schema of this.toolSchemas) {
838
875
  const hash = JSON.stringify(schema.parameters ?? {})
839
876
  if (this.registered.get(schema.name) === hash) continue
840
877
  const shape = jsonSchemaToShape((schema.parameters ?? {}) as Record<string, unknown>)
@@ -929,12 +966,17 @@ export class CodeBuddySession {
929
966
  if (this.session !== null) return this.session
930
967
  const sdk = await loadCodeBuddySdk()
931
968
  this.mcp ??= sdk.createSdkMcpServer({ name: MCP_SERVER_NAME, tools: [] })
969
+ // Host tools must exist in the MCP server before the CLI lists them.
970
+ this.registerTools()
932
971
  const session = sdk.unstable_v2_createSession({
933
972
  environment: codeBuddyEnvironment(this.region),
934
973
  sessionId: randomUUID(),
935
974
  model: this.model,
936
975
  mcpServers: { [MCP_SERVER_NAME]: this.mcp },
937
976
  canUseTool: this.canUseTool as CanUseTool,
977
+ // Only the host's MCP tools may run: the CLI's own Bash/Read/Edit have no
978
+ // host-side counterpart, and the permission gate denies them anyway.
979
+ tools: [],
938
980
  ...cliEnv(this.region),
939
981
  settingSources: [],
940
982
  includePartialMessages: true,
@@ -948,7 +990,7 @@ export class CodeBuddySession {
948
990
  }
949
991
 
950
992
  private canUseTool = (toolName: string, _input: Record<string, unknown>, options: { toolUseID?: string }) => {
951
- if (toolName.startsWith(MCP_TOOL_PREFIX)) {
993
+ if (isHostTool(toolName)) {
952
994
  if (options.toolUseID !== undefined) this.pairing.announce(options.toolUseID)
953
995
  return Promise.resolve({ behavior: 'allow', ...options.toolUseID === undefined ? {} : { toolUseID: options.toolUseID } })
954
996
  }
@@ -985,13 +1027,20 @@ export class CodeBuddySession {
985
1027
  if (event.type === 'content_block_start') {
986
1028
  const block = event.content_block as { type?: string, id?: string, name?: string, input?: unknown }
987
1029
  if (block?.type === 'tool_use') {
1030
+ // A built-in CLI tool (Bash, Read, ToolSearch…) has no host
1031
+ // counterpart; forwarding it made the host answer "unknown tool" and
1032
+ // stop the turn. `tools: []` stops them being offered at all, and
1033
+ // this guard covers anything the CLI still emits. The permission
1034
+ // gate denies the call, so the inner model sees the denial and can
1035
+ // retry with a host tool.
1036
+ if (!isHostTool(block.name ?? '')) return
988
1037
  const callId = `cb-${this.callNonce}-${++this.callCounter}`
989
1038
  if (typeof block.id === 'string' && block.id.length > 0) this.pairing.mapHostCall(callId, block.id)
990
1039
  const chunkIndex = this.blockIndex++
991
1040
  const initial = block.input !== undefined && block.input !== null && Object.keys(block.input as object).length > 0
992
1041
  ? JSON.stringify(block.input)
993
1042
  : ''
994
- this.openTool = { chunkIndex, callId, name: (block.name ?? '').replace(MCP_TOOL_PREFIX, ''), arguments: initial }
1043
+ this.openTool = { chunkIndex, callId, name: hostToolName(block.name ?? ''), arguments: initial }
995
1044
  this.countOutput(this.openTool.name)
996
1045
  this.countOutput(initial)
997
1046
  this.emit({ type: 'block-start', index: chunkIndex, blockType: 'tool-call' })
@@ -1229,6 +1278,8 @@ export async function codeBuddyColdStream(
1229
1278
  sessionId: randomUUID(),
1230
1279
  ...model === undefined ? {} : { model },
1231
1280
  ...cliEnv(region),
1281
+ // Titles and compaction must never run a tool.
1282
+ tools: [],
1232
1283
  settingSources: [],
1233
1284
  persistSession: false,
1234
1285
  })
package/src/config.ts CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  import { isVolatile } from '@deepseek-ai/cosmokit'
19
19
  import z from '@deepseek-ai/schemastery'
20
- import type { CodeBuddyRegion } from './brand.ts'
20
+ import type { CodeBuddyRegion, MinimaxRegion } from './brand.ts'
21
21
 
22
22
  /**
23
23
  * The plugin configuration as authored in a profile patch.
@@ -110,6 +110,24 @@ export interface Config {
110
110
  /** Extra model aliases for CodeBuddy, shared by both regions. */
111
111
  codebuddyModelAliases?: Record<string, string>
112
112
 
113
+ // ── MiniMax Code ────────────────────────────────────────────────────────
114
+ /** Whether MiniMax Code is served; same semantics as {@link cnEnabled}. */
115
+ minimaxEnabled?: boolean
116
+ /** Which MiniMax Code login region the sessions use. */
117
+ minimaxRegion?: MinimaxRegion
118
+ /** Display name of the MiniMax Code provider group in the picker. */
119
+ minimaxDisplayName?: string
120
+ /** Model ids the user switched OFF for the international region. */
121
+ minimaxGlobalDisabledModels?: string[]
122
+ /** Model ids the user switched OFF for the mainland region. */
123
+ minimaxCnDisabledModels?: string[]
124
+ /** Per-model context window for the international region, keyed by model id. */
125
+ minimaxGlobalModelContextWindows?: Record<string, number>
126
+ /** Per-model context window for the mainland region, keyed by model id. */
127
+ minimaxCnModelContextWindows?: Record<string, number>
128
+ /** Extra model aliases for MiniMax Code, shared by both regions. */
129
+ minimaxModelAliases?: Record<string, string>
130
+
113
131
  // ── Advanced: sensible defaults, rarely changed ─────────────────────────
114
132
  /**
115
133
  * Display name of the primary provider group in the model picker.
@@ -214,6 +232,16 @@ export const Config = z.object({
214
232
  codebuddyCnModelContextWindows: z.dict(z.number()).default({}).description('CodeBuddy 国内版按模型指定的上下文窗口(token 数)。').volatile(),
215
233
  codebuddyModelAliases: z.dict(z.string()).default({}).description('CodeBuddy 额外的模型别名映射:DSH 侧名称 → CodeBuddy 模型 ID。').volatile(),
216
234
 
235
+ // ── MiniMax Code:ACP 接入,两种登录区域 ───────────────────────────────
236
+ minimaxEnabled: z.boolean().default(true).description('启用 MiniMax Code(ACP)。关闭后该设置页、模型列表与 provider 路由都会移除;登录态与模型选择会保留。').volatile(),
237
+ minimaxRegion: z.string().default('cn').description('MiniMax Code 登录区域:cn(国内站 account.minimax.cn)或 global(国际站 account.minimax.io)。').volatile(),
238
+ minimaxDisplayName: z.string().default('MiniMax Code').description('模型选择器里 MiniMax Code 分组的名称。').volatile(),
239
+ minimaxGlobalDisabledModels: z.array(z.string()).default([]).description('MiniMax Code 国际站已关闭的模型 ID 列表。').volatile(),
240
+ minimaxCnDisabledModels: z.array(z.string()).default([]).description('MiniMax Code 国内站已关闭的模型 ID 列表。').volatile(),
241
+ minimaxGlobalModelContextWindows: z.dict(z.number()).default({}).description('MiniMax Code 国际站按模型指定的上下文窗口(token 数)。').volatile(),
242
+ minimaxCnModelContextWindows: z.dict(z.number()).default({}).description('MiniMax Code 国内站按模型指定的上下文窗口(token 数)。').volatile(),
243
+ minimaxModelAliases: z.dict(z.string()).default({}).description('MiniMax Code 额外的模型别名映射:DSH 侧名称 → ACP 模型值。').volatile(),
244
+
217
245
  // ── 高级:一般无需改动 ─────────────────────────────────────────────────
218
246
  displayName: z.string().default('Qoder CN').description('模型选择器里主分组的名称。同时使用多个 Qoder 账号时可区分。').volatile(),
219
247
  maxSessions: z.number().step(1).min(1).max(64).default(8).description('同时保持的内层会话数上限,超出后按最久未使用关闭。每个会话是一个子进程。').volatile(),
@@ -255,6 +283,14 @@ export interface ResolvedConfig {
255
283
  codebuddyGlobalModelContextWindows: Readonly<Record<string, number>>
256
284
  codebuddyCnModelContextWindows: Readonly<Record<string, number>>
257
285
  codebuddyModelAliases: Readonly<Record<string, string>>
286
+ minimaxEnabled: boolean
287
+ minimaxRegion: MinimaxRegion
288
+ minimaxDisplayName: string
289
+ minimaxGlobalDisabledModels: readonly string[]
290
+ minimaxCnDisabledModels: readonly string[]
291
+ minimaxGlobalModelContextWindows: Readonly<Record<string, number>>
292
+ minimaxCnModelContextWindows: Readonly<Record<string, number>>
293
+ minimaxModelAliases: Readonly<Record<string, string>>
258
294
  }
259
295
 
260
296
  /**
@@ -333,6 +369,14 @@ export function liveConfig(config: ParsedConfig | undefined): LiveConfig {
333
369
  codebuddyGlobalModelContextWindows: () => numberMap(field('codebuddyGlobalModelContextWindows')),
334
370
  codebuddyCnModelContextWindows: () => numberMap(field('codebuddyCnModelContextWindows')),
335
371
  codebuddyModelAliases: () => stringMap(field('codebuddyModelAliases')),
372
+ minimaxEnabled: () => bool(field('minimaxEnabled'), true),
373
+ minimaxRegion: () => field('minimaxRegion') === 'global' ? 'global' : 'cn',
374
+ minimaxDisplayName: () => nonEmpty(field('minimaxDisplayName'), 'MiniMax Code'),
375
+ minimaxGlobalDisabledModels: () => stringList(field('minimaxGlobalDisabledModels')),
376
+ minimaxCnDisabledModels: () => stringList(field('minimaxCnDisabledModels')),
377
+ minimaxGlobalModelContextWindows: () => numberMap(field('minimaxGlobalModelContextWindows')),
378
+ minimaxCnModelContextWindows: () => numberMap(field('minimaxCnModelContextWindows')),
379
+ minimaxModelAliases: () => stringMap(field('minimaxModelAliases')),
336
380
  }
337
381
  }
338
382
 
@@ -376,6 +420,14 @@ export function resolveConfig(config: ParsedConfig | undefined): ResolvedConfig
376
420
  codebuddyGlobalModelContextWindows: live.codebuddyGlobalModelContextWindows(),
377
421
  codebuddyCnModelContextWindows: live.codebuddyCnModelContextWindows(),
378
422
  codebuddyModelAliases: live.codebuddyModelAliases(),
423
+ minimaxEnabled: live.minimaxEnabled(),
424
+ minimaxRegion: live.minimaxRegion(),
425
+ minimaxDisplayName: live.minimaxDisplayName(),
426
+ minimaxGlobalDisabledModels: live.minimaxGlobalDisabledModels(),
427
+ minimaxCnDisabledModels: live.minimaxCnDisabledModels(),
428
+ minimaxGlobalModelContextWindows: live.minimaxGlobalModelContextWindows(),
429
+ minimaxCnModelContextWindows: live.minimaxCnModelContextWindows(),
430
+ minimaxModelAliases: live.minimaxModelAliases(),
379
431
  }
380
432
  }
381
433