dsh-agent-sdk-bridge 1.0.1 → 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/DEVELOPMENT.md +54 -3
- package/FAQ.md +52 -0
- package/README.md +53 -24
- package/client.js +2411 -1802
- package/cordis.patch.yml +4 -3
- package/lib/index.js +3115 -252
- package/lib/types/api.d.ts +5 -2
- package/lib/types/brand.d.ts +26 -3
- package/lib/types/config.d.ts +41 -1
- package/lib/types/index.d.ts +21 -0
- package/lib/types/minimax-adapter.d.ts +86 -0
- package/lib/types/minimax-cli.d.ts +69 -0
- package/lib/types/minimax.d.ts +493 -0
- package/package.json +7 -2
- package/src/api.ts +120 -32
- package/src/brand.ts +49 -5
- package/src/config.ts +53 -1
- package/src/index.ts +50 -4
- package/src/minimax-adapter.ts +370 -0
- package/src/minimax-cli.ts +276 -0
- package/src/minimax.ts +2413 -0
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 {
|
|
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 或
|
|
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 (
|
|
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
|
-
:
|
|
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
|
|
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 (
|
|
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(
|
|
209
|
-
:
|
|
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
|
|
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
|
|
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,
|
|
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
|
-
|
|
243
|
-
|
|
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
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
262
|
-
|
|
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 =
|
|
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: '
|
|
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
|
|
295
|
-
send(res, 400, { error: '
|
|
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/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
|
|
package/src/index.ts
CHANGED
|
@@ -29,10 +29,12 @@ import type { ServerResponse, IncomingMessage } from 'node:http'
|
|
|
29
29
|
import type { AttachmentStore, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment'
|
|
30
30
|
import { QoderAdapter, QODER_PROVIDER, QODER_INTL_PROVIDER } from './adapter.ts'
|
|
31
31
|
import { CodeBuddyAdapter, CODEBUDDY_PROVIDER } from './codebuddy-adapter.ts'
|
|
32
|
+
import { MinimaxAdapter, MINIMAX_PROVIDER } from './minimax-adapter.ts'
|
|
32
33
|
import { API_PREFIX, handleApi } from './api.ts'
|
|
33
34
|
import type { BrandId } from './brand.ts'
|
|
34
35
|
import { BRANDS } from './brand.ts'
|
|
35
36
|
import { stopSetup } from './setup.ts'
|
|
37
|
+
import { stopMinimaxSetup } from './minimax-cli.ts'
|
|
36
38
|
import type { LiveConfig, ParsedConfig } from './config.ts'
|
|
37
39
|
import { Config as ConfigSchema, liveConfig } from './config.ts'
|
|
38
40
|
|
|
@@ -77,6 +79,24 @@ declare module '@deepseek-ai/cordis' {
|
|
|
77
79
|
export { QoderAdapter, QODER_PROVIDER, QODER_INTL_PROVIDER, cliContextWindow, pickContextWindow } from './adapter.ts'
|
|
78
80
|
export type { ImageRequestReader, QoderAdapterOptions } from './adapter.ts'
|
|
79
81
|
export { CodeBuddyAdapter, CODEBUDDY_PROVIDER, resolveCodeBuddyModelId } from './codebuddy-adapter.ts'
|
|
82
|
+
export { MinimaxAdapter, MINIMAX_PROVIDER, resolveMinimaxModelId } from './minimax-adapter.ts'
|
|
83
|
+
export {
|
|
84
|
+
MinimaxAcp, MinimaxAuth, MinimaxCatalog, MinimaxSession, MinimaxSessionManager,
|
|
85
|
+
minimaxColdStream, minimaxDataDir, minimaxAuthStatePath, minimaxCliCommand,
|
|
86
|
+
isHostMcpTool, hostMcpToolName, minimaxModelsFromConfigOptions,
|
|
87
|
+
minimaxUsage, minimaxUsageFromParts, invalidateMinimaxUsage,
|
|
88
|
+
minimaxRegionBlocked, minimaxRegionBlockedCached, minimaxRegionBlockMessage,
|
|
89
|
+
minimaxHostBelongsToOtherRegion, invalidateMinimaxRegionAccess, MinimaxRegionBlockedError,
|
|
90
|
+
MINIMAX_DEFAULT_CONTEXT_WINDOW, MINIMAX_DEFAULT_MAX_TOKENS, MINIMAX_USAGE_CACHE_TTL_MS,
|
|
91
|
+
} from './minimax.ts'
|
|
92
|
+
export type {
|
|
93
|
+
MinimaxAccountInfo, MinimaxAuthStatus, MinimaxCreditInfo, MinimaxMcpToolResult,
|
|
94
|
+
MinimaxModel, MinimaxPlanInfo, MinimaxQuotaWindow, MinimaxUsageSnapshot,
|
|
95
|
+
} from './minimax.ts'
|
|
96
|
+
export {
|
|
97
|
+
MinimaxCliSetup, readMinimaxSetupStatus, resolveMinimaxCli, startMinimaxSetup, stopMinimaxSetup,
|
|
98
|
+
} from './minimax-cli.ts'
|
|
99
|
+
export type { MinimaxSetupMode, MinimaxSetupStatus, MinimaxCliSpec } from './minimax-cli.ts'
|
|
80
100
|
export type { CodeBuddyAdapterOptions } from './codebuddy-adapter.ts'
|
|
81
101
|
export {
|
|
82
102
|
CodeBuddyAuth, CodeBuddyAccountReader, CodeBuddyCatalog, CodeBuddySession, CodeBuddySessionManager,
|
|
@@ -135,8 +155,8 @@ const REQUEST_IMAGE_MAX_BYTES = 1_048_576
|
|
|
135
155
|
* used, so a change to these fields is the only thing that needs a republish.
|
|
136
156
|
*/
|
|
137
157
|
const STRUCTURAL_FIELDS: ReadonlySet<string> = new Set([
|
|
138
|
-
'cnEnabled', 'intlEnabled', 'codebuddyEnabled',
|
|
139
|
-
'displayName', 'intlDisplayName', 'codebuddyDisplayName',
|
|
158
|
+
'cnEnabled', 'intlEnabled', 'codebuddyEnabled', 'minimaxEnabled',
|
|
159
|
+
'displayName', 'intlDisplayName', 'codebuddyDisplayName', 'minimaxDisplayName',
|
|
140
160
|
])
|
|
141
161
|
|
|
142
162
|
/** The configurable-provider directory rows for the enabled editions. */
|
|
@@ -156,6 +176,9 @@ function directoryFor(live: LiveConfig): {
|
|
|
156
176
|
if (live.codebuddyEnabled()) {
|
|
157
177
|
rows.push({ provider: CODEBUDDY_PROVIDER, displayName: live.codebuddyDisplayName(), settingsNs: NS, settingsPath: [] })
|
|
158
178
|
}
|
|
179
|
+
if (live.minimaxEnabled()) {
|
|
180
|
+
rows.push({ provider: MINIMAX_PROVIDER, displayName: live.minimaxDisplayName(), settingsNs: NS, settingsPath: [] })
|
|
181
|
+
}
|
|
159
182
|
return rows
|
|
160
183
|
}
|
|
161
184
|
|
|
@@ -221,7 +244,7 @@ export function apply(ctx: Context, config: ParsedConfig): void {
|
|
|
221
244
|
* own catalog, warm sessions, account reading and user choices, so a request
|
|
222
245
|
* can never be resolved against another provider's catalog.
|
|
223
246
|
*/
|
|
224
|
-
const adapters: Record<BrandId, QoderAdapter | CodeBuddyAdapter> = {
|
|
247
|
+
const adapters: Record<BrandId, QoderAdapter | CodeBuddyAdapter | MinimaxAdapter> = {
|
|
225
248
|
cn: new QoderAdapter({
|
|
226
249
|
...shared,
|
|
227
250
|
brand: 'cn',
|
|
@@ -256,6 +279,24 @@ export function apply(ctx: Context, config: ParsedConfig): void {
|
|
|
256
279
|
: live.codebuddyGlobalModelContextWindows(),
|
|
257
280
|
modelAliases: live.codebuddyModelAliases,
|
|
258
281
|
}),
|
|
282
|
+
minimax: new MinimaxAdapter({
|
|
283
|
+
maxSessions: live.maxSessions,
|
|
284
|
+
modelCacheTtlMs: live.modelCacheTtlMs,
|
|
285
|
+
catalogFetchTimeoutMs: live.catalogFetchTimeoutMs,
|
|
286
|
+
toolResultTimeoutMs: live.toolResultTimeoutMs,
|
|
287
|
+
abortGraceMs: live.abortGraceMs,
|
|
288
|
+
defaultMaxTokens: live.defaultMaxTokens,
|
|
289
|
+
defaultReasoningEffort: live.defaultReasoningEffort,
|
|
290
|
+
displayName: live.minimaxDisplayName,
|
|
291
|
+
region: live.minimaxRegion,
|
|
292
|
+
disabledModels: region => region === 'cn'
|
|
293
|
+
? live.minimaxCnDisabledModels()
|
|
294
|
+
: live.minimaxGlobalDisabledModels(),
|
|
295
|
+
modelContextWindows: region => region === 'cn'
|
|
296
|
+
? live.minimaxCnModelContextWindows()
|
|
297
|
+
: live.minimaxGlobalModelContextWindows(),
|
|
298
|
+
modelAliases: live.minimaxModelAliases,
|
|
299
|
+
}),
|
|
259
300
|
}
|
|
260
301
|
|
|
261
302
|
ctx.inject(['attachments'], (scope) => {
|
|
@@ -273,6 +314,7 @@ export function apply(ctx: Context, config: ParsedConfig): void {
|
|
|
273
314
|
const enabled = (id: BrandId): boolean => {
|
|
274
315
|
if (id === 'cn') return live.cnEnabled()
|
|
275
316
|
if (id === 'global') return live.intlEnabled()
|
|
317
|
+
if (id === 'minimax') return live.minimaxEnabled()
|
|
276
318
|
return live.codebuddyEnabled()
|
|
277
319
|
}
|
|
278
320
|
|
|
@@ -329,11 +371,15 @@ export function apply(ctx: Context, config: ParsedConfig): void {
|
|
|
329
371
|
adapters.cn.close()
|
|
330
372
|
adapters.global.close()
|
|
331
373
|
;(adapters.codebuddy as CodeBuddyAdapter).close()
|
|
374
|
+
;(adapters.minimax as MinimaxAdapter).close()
|
|
332
375
|
}, 'llm-qoder-cn.sessions')
|
|
333
376
|
|
|
334
377
|
// A CLI helper still running when this plugin is reloaded or removed would
|
|
335
378
|
// otherwise keep writing into a page that can no longer read it.
|
|
336
|
-
ctx.effect(() => () =>
|
|
379
|
+
ctx.effect(() => () => {
|
|
380
|
+
stopSetup()
|
|
381
|
+
stopMinimaxSetup()
|
|
382
|
+
}, 'llm-qoder-cn.setup')
|
|
337
383
|
|
|
338
384
|
// The settings page's data source: the live catalog joined with the user's
|
|
339
385
|
// on/off and window choices. Served from its own route because the catalog
|