Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/minimaxcode-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### English

- Added a MiniMax Code provider (`minimaxcode/`) with official OAuth device-code sign-in (PKCE S256), CN and global regions, the 10-style work-mode model catalog with a static fallback, streaming/non-streaming chat through the Anthropic Messages gateway, tool calling, and status-only quota display. Route with the `minimaxcode/` model prefix.

### 中文

- 新增 MiniMax Code 供应商(`minimaxcode/`):使用官方 OAuth 设备码登录(PKCE S256),支持国内/国际站点、工作模式模型目录(含静态兜底)、通过 Anthropic Messages 网关的流式/非流式对话、工具调用和状态额度展示,可用 `minimaxcode/` 模型前缀指定路由。
Binary file added frontend/src/assets/minimaxcode-mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/components/AddAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const labelKeys: Record<string, string> = {
'kiro-us-east-1': 'accountTypeKiroUS',
'kiro-eu-central-1': 'accountTypeKiroEU',
'meta-global': 'accountTypeMetaGlobal',
'minimaxcode-cn': 'accountTypeMiniMaxCodeCN',
'minimaxcode-global': 'accountTypeMiniMaxCodeGlobal',
}

const hintKeys: Record<string, string> = {
Expand All @@ -93,6 +95,8 @@ const hintKeys: Record<string, string> = {
'kiro-us-east-1': 'accountTypeKiroUSHint',
'kiro-eu-central-1': 'accountTypeKiroEUHint',
'meta-global': 'accountTypeMetaGlobalHint',
'minimaxcode-cn': 'accountTypeMiniMaxCodeCNHint',
'minimaxcode-global': 'accountTypeMiniMaxCodeGlobalHint',
}

async function loadProviderOptions(): Promise<ProviderOption[]> {
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/components/MiniMaxCodeMark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import miniMaxCodeMark from '@/assets/minimaxcode-mark.png'

type Props = {
size?: number
className?: string
}

// MiniMax Code brand mark.
export function MiniMaxCodeMark({ size = 16, className = '' }: Props) {
return (
<img
src={miniMaxCodeMark}
alt=""
width={size}
height={size}
className={`block shrink-0 rounded-[22%] ${className}`.trim()}
draggable={false}
/>
)
}
4 changes: 4 additions & 0 deletions frontend/src/components/ProviderMark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DevinMark } from '@/components/DevinMark'
import { DoubaoworkMark } from '@/components/DoubaoworkMark'
import { KiroMark } from '@/components/KiroMark'
import { KimiMark } from '@/components/KimiMark'
import { MiniMaxCodeMark } from '@/components/MiniMaxCodeMark'
import { MuseMark } from '@/components/MuseMark'
import { QoderMark } from '@/components/QoderMark'
import { QwenworkMark } from '@/components/QwenworkMark'
Expand Down Expand Up @@ -57,5 +58,8 @@ export function ProviderMark({ provider, size = 16, className = '' }: Props) {
if (id === 'doubaowork') {
return <DoubaoworkMark size={size} className={className} />
}
if (id === 'minimaxcode') {
return <MiniMaxCodeMark size={size} className={className} />
}
return <QoderMark size={size} className={className} />
}
8 changes: 8 additions & 0 deletions frontend/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ export const messages: Record<Lang, Dict> = {
accountTypeKiroEUHint: 'Personal Kiro login for the eu-central-1 runtime. Same credential shapes as US East. Experimental.',
accountTypeMetaGlobal: 'Muse (Meta)',
accountTypeMetaGlobalHint: 'Meta Muse Code subscription via device-code sign-in against auth.meta.com. After approval the console mints an LLM API key at api.meta.ai. You can also paste a Meta Model API key on the PAT tab.',
accountTypeMiniMaxCodeCN: 'MiniMax Code (CN)',
accountTypeMiniMaxCodeCNHint: 'MiniMax Code subscription via its official device-code sign-in. Routes through the CN agent gateway and consumes your MiniMax Code credits.',
accountTypeMiniMaxCodeGlobal: 'MiniMax Code (Global)',
accountTypeMiniMaxCodeGlobalHint: 'MiniMax Code subscription via its official device-code sign-in. Routes through the global agent gateway and consumes your MiniMax Code credits.',
providerGroupSubscriptions: 'Subscriptions',
providerGroupSubscriptionsHint: 'stable account logins',
providerGroupExperimental: 'Experimental',
Expand Down Expand Up @@ -1837,6 +1841,10 @@ export const messages: Record<Lang, Dict> = {
accountTypeKiroEUHint: '个人 Kiro 登录,走 eu-central-1 运行时。凭证格式与美东相同。实验性接入。',
accountTypeMetaGlobal: 'Muse (Meta)',
accountTypeMetaGlobalHint: 'Meta Muse Code 订阅,走 auth.meta.com 的设备码授权;批准后控制台会在 api.meta.ai 兑换 LLM API Key。也可在 PAT 页粘贴 Meta Model API Key。',
accountTypeMiniMaxCodeCN: 'MiniMax Code(国内)',
accountTypeMiniMaxCodeCNHint: '通过 MiniMax Code 官方设备码登录,走国内 agent 网关,消耗你的 MiniMax Code 额度。',
accountTypeMiniMaxCodeGlobal: 'MiniMax Code(国际)',
accountTypeMiniMaxCodeGlobalHint: '通过 MiniMax Code 官方设备码登录,走国际 agent 网关,消耗你的 MiniMax Code 额度。',
providerGroupSubscriptions: '稳定订阅',
providerGroupSubscriptionsHint: '稳定的账号登录源',
providerGroupExperimental: '实验性',
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export function isDoubaoworkProvider(provider?: string) {
return String(provider || '').toLowerCase() === 'doubaowork'
}

export function isMiniMaxCodeProvider(provider?: string) {
return String(provider || '').toLowerCase() === 'minimaxcode'
}

export function isMetaProvider(provider?: string) {
const value = String(provider || '').toLowerCase()
return value === 'meta' || value === 'muse'
Expand All @@ -58,6 +62,7 @@ export function accountProviderFamilyLabel(
if (isKimiProvider(providerID)) return 'Kimi Code'
if (isCodeArtsProvider(providerID)) return 'CodeArts'
if (isDoubaoworkProvider(providerID)) return 'Doubao Work'
if (isMiniMaxCodeProvider(providerID)) return 'MiniMax Code'
if (isMetaProvider(providerID)) return 'Muse (Meta)'
if (isQoderProvider(providerID)) return 'Qoder'
return provider || t('account')
Expand Down Expand Up @@ -97,6 +102,9 @@ export function accountProviderLabel(
if (isDoubaoworkProvider(providerID)) {
return t('accountTypeDoubaoworkCN')
}
if (isMiniMaxCodeProvider(providerID)) {
return regionID === 'global' ? t('accountTypeMiniMaxCodeGlobal') : t('accountTypeMiniMaxCodeCN')
}
if (isMetaProvider(providerID)) {
return t('accountTypeMetaGlobal')
}
Expand Down
2 changes: 1 addition & 1 deletion internal/accounts/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func DefaultDropSystemPrompt(provider string, value *bool) bool {
return *value
}
switch strings.ToLower(strings.TrimSpace(provider)) {
case "trae", "kimi", "codearts":
case "trae", "kimi", "codearts", "minimaxcode":
return false
default:
return true
Expand Down
2 changes: 2 additions & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/caigee-cmd/cli2api/internal/providers/kimi"
"github.com/caigee-cmd/cli2api/internal/providers/kiro"
"github.com/caigee-cmd/cli2api/internal/providers/meta"
"github.com/caigee-cmd/cli2api/internal/providers/minimaxcode"
"github.com/caigee-cmd/cli2api/internal/providers/qoder"
"github.com/caigee-cmd/cli2api/internal/providers/qwenwork"
"github.com/caigee-cmd/cli2api/internal/providers/trae"
Expand Down Expand Up @@ -128,6 +129,7 @@ func New(cfg config.Config) *App {
providerReg.Register(zhipu.NewClient(store).Adapter())
providerReg.Register(qwenwork.NewClient(store).Adapter())
providerReg.Register(kimi.NewClient(store).Adapter())
providerReg.Register(minimaxcode.NewClient(store).Adapter())
providerReg.Register(codearts.NewClient(store).Adapter())
providerReg.Register(kiro.NewClient(store).Adapter())
providerReg.Register(meta.NewClient(store).Adapter())
Expand Down
2 changes: 1 addition & 1 deletion internal/console/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func splitModelSettingPath(raw, queryProvider string) (provider, modelKey string) {
raw = strings.TrimPrefix(raw, "/api/models/")
provider = strings.ToLower(strings.TrimSpace(queryProvider))
for _, prefix := range []string{"trae/", "workbuddy/", "qoder/", "devin/", "command/", "codex/", "zhipu/", "qwenwork/", "kimi/", "codearts/", "kiro/"} {
for _, prefix := range []string{"trae/", "workbuddy/", "qoder/", "devin/", "command/", "codex/", "zhipu/", "qwenwork/", "kimi/", "codearts/", "kiro/", "minimaxcode/"} {
if strings.HasPrefix(strings.ToLower(raw), prefix) {
provider = strings.TrimSuffix(prefix, "/")
raw = raw[len(prefix):]
Expand Down
2 changes: 1 addition & 1 deletion internal/executor/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (e ChatExecutor) Prepare(in PrepareInput) (PreparedRequest, error) {
// "<provider>/" model id. Command Code's own model ids are org-namespaced
// ("deepseek/…", "moonshotai/…"), so its provider prefix sits in front of an
// already-namespaced id ("command/deepseek/…").
var providerPrefixes = []string{"qoder/", "workbuddy/", "trae/", "devin/", "command/", "codex/", "zhipu/", "qwenwork/", "kimi/", "codearts/", "kiro/", "doubaowork/"}
var providerPrefixes = []string{"qoder/", "workbuddy/", "trae/", "devin/", "command/", "codex/", "zhipu/", "qwenwork/", "kimi/", "codearts/", "kiro/", "doubaowork/", "minimaxcode/"}

// regionDashSuffixes are the region qualifiers that may be appended to a
// provider prefix with a dash: "workbuddy-cn/", "workbuddy-gl/",
Expand Down
135 changes: 135 additions & 0 deletions internal/providers/minimaxcode/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package minimaxcode

import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"

"github.com/caigee-cmd/cli2api/internal/providers"
)

func (c *Client) Models(ctx context.Context, accountID string) ([]providers.ModelInfo, error) {
c.mu.Lock()
cached, ok := c.catalogs[accountID]
c.mu.Unlock()
if ok && c.now().Sub(cached.at) < catalogTTL && len(cached.models) > 0 {
return cached.models, nil
}
models, err := c.fetchCatalogModels(ctx, accountID)
if err != nil || len(models) == 0 {
models = staticModels()
err = nil
}
c.mu.Lock()
c.catalogs[accountID] = catalogCache{models: models, at: c.now()}
c.mu.Unlock()
return models, err
}

func (c *Client) fetchCatalogModels(ctx context.Context, accountID string) ([]providers.ModelInfo, error) {
credential, err := c.credential(ctx, accountID)
if err != nil {
return nil, err
}
endpoint := credential.agentBase() + modelsPath + "?region=" + urlQueryEscape(credential.region()) + "&buildEnv=prod"
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+credential.AccessToken)
req.Header.Set("User-Agent", UserAgent)
req.Header.Set("X-Mavis-Agent-Id", AgentID)
req.Header.Set("Accept", "application/json")
client, err := c.httpClient(ctx, accountID)
if err != nil {
return nil, err
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode >= 300 {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
return nil, fmt.Errorf("minimaxcode model catalog failed (HTTP %d): %s", resp.StatusCode, truncate(string(body), 200))
}
raw, _ := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
return parseModels(raw)
}

func parseModels(raw []byte) ([]providers.ModelInfo, error) {
var payload map[string]any
if json.Unmarshal(raw, &payload) != nil {
return nil, fmt.Errorf("minimaxcode model catalog is not valid json")
}
var entries []any
if providersList, ok := payload["providers"].([]any); ok {
for _, rawProvider := range providersList {
provider, _ := rawProvider.(map[string]any)
config, _ := provider["config"].(map[string]any)
if models, ok := config["models"].([]any); ok {
entries = append(entries, models...)
}
}
}
if len(entries) == 0 {
if models, ok := payload["models"].([]any); ok {
entries = models
}
}
if len(entries) == 0 {
if data, ok := payload["data"].([]any); ok {
entries = data
}
}
models := make([]providers.ModelInfo, 0, len(entries))
for _, rawModel := range entries {
model, ok := rawModel.(map[string]any)
if !ok {
continue
}
id := first(jsonStr(model, "model"), jsonStr(model, "id"), jsonStr(model, "model_name"), jsonStr(model, "name"))
if id == "" {
continue
}
name := first(jsonStr(model, "display_name"), jsonStr(model, "name"), id)
models = append(models, providers.ModelInfo{NativeModel: id, PublicModel: id, DisplayName: name, Capabilities: providers.ModelCapabilities{Tools: true}})
}
return models, nil
}

func staticModels() []providers.ModelInfo {
models := make([]providers.ModelInfo, 0, len(knownModels))
for _, id := range knownModels {
models = append(models, providers.ModelInfo{NativeModel: id, PublicModel: id, DisplayName: id, Capabilities: providers.ModelCapabilities{Tools: true}})
}
return models
}

func normalizedModelKey(snapshot []providers.ModelInfo, requested string) (string, bool) {
want := strings.ToLower(strings.TrimPrefix(strings.TrimSpace(requested), ProviderID+"/"))
if want == "" {
return "", false
}
for _, info := range snapshot {
if strings.ToLower(info.NativeModel) == want || strings.ToLower(info.PublicModel) == want {
return info.NativeModel, true
}
}
return "", false
}

func jsonStr(payload map[string]any, key string) string {
value, _ := payload[key].(string)
return strings.TrimSpace(value)
}

func urlQueryEscape(value string) string {
return strings.ReplaceAll(strings.ReplaceAll(value, " ", "%20"), "/", "%2F")
}

var _ = time.Second
Loading
Loading