# OpenCode CodeBuddy External Auth Plugin

OpenCode 插件，用于 CodeBuddy External (IOA) 认证。

## 安装

```bash
npm install opencode-codebuddy-external-auth
```

## 配置

编辑 `~/.config/opencode/opencode.json`：

```json
{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["opencode-codebuddy-external-auth"],
  "provider": {
    "codebuddy-external": {
      "npm": "@ai-sdk/anthropic",
      "name": "CodeBuddy External (IOA)",
      "models": {
        "claude-4.5": { "name": "Claude Sonnet 4.5 (x2.20)", "contextLength": 176000 },
        "claude-opus-4.5": { "name": "Claude Opus 4.5 (x3.33)", "contextLength": 176000 },
        "claude-haiku-4.5": { "name": "Claude Haiku 4.5 (x0.67)", "contextLength": 176000 },
        "gemini-3.0-pro": { "name": "Gemini 3.0 Pro (x1.33)", "contextLength": 400000 },
        "gemini-3.0-flash": { "name": "Gemini 3.0 Flash (x0.33)", "contextLength": 400000 },
        "gemini-2.5-pro": { "name": "Gemini 2.5 Pro (x0.95)", "contextLength": 400000 },
        "gpt-5.2": { "name": "GPT-5.2 (x1.33)", "contextLength": 272000 },
        "gpt-5.2-codex": { "name": "GPT-5.2-Codex (x1.33)", "contextLength": 272000 },
        "gpt-5.1": { "name": "GPT-5.1 (x0.95)", "contextLength": 272000 },
        "gpt-5.1-codex": { "name": "GPT-5.1-Codex (x0.95)", "contextLength": 272000 },
        "gpt-5.1-codex-max": { "name": "GPT-5.1-Codex-Max (x0.95)", "contextLength": 272000 },
        "gpt-5.1-codex-mini": { "name": "GPT-5.1-Codex-Mini (x0.19)", "contextLength": 272000 },
        "kimi-k2-thinking": { "name": "Kimi-K2-Thinking (x0.46)", "contextLength": 256000 },
        "glm-4.7-ioa": { "name": "GLM-4.7 [免费]", "contextLength": 200000 },
        "glm-4.6-ioa": { "name": "GLM-4.6 [免费]", "contextLength": 168000 },
        "glm-4.6v-ioa": { "name": "GLM-4.6V [免费]", "contextLength": 128000 },
        "deepseek-v3-2-volc-ioa": { "name": "DeepSeek-V3.2 [免费]", "contextLength": 96000 }
      }
    }
  },
  "model": "codebuddy-external/claude-4.5"
}
```

## 使用

1. 启动 OpenCode: `opencode`
2. 选择 CodeBuddy External 模型
3. 选择 "IOA 登录 (浏览器)" 认证方式
4. 在浏览器中完成 IOA 登录
5. 返回终端开始使用

## 支持的模型

根据 CodeBuddy IOA 版本配置（2026-01-24）：

### Claude 系列
| 模型 ID | 名称 | Credits | Context |
|---------|------|---------|---------|
| `claude-4.5` | Claude Sonnet 4.5 | x2.20 | 176K |
| `claude-opus-4.5` | Claude Opus 4.5 | x3.33 | 176K |
| `claude-haiku-4.5` | Claude Haiku 4.5 | x0.67 | 176K |

### Gemini 系列
| 模型 ID | 名称 | Credits | Context |
|---------|------|---------|---------|
| `gemini-3.0-pro` | Gemini 3.0 Pro | x1.33 | 400K |
| `gemini-3.0-flash` | Gemini 3.0 Flash | x0.33 | 400K |
| `gemini-2.5-pro` | Gemini 2.5 Pro | x0.95 | 400K |

### GPT 系列
| 模型 ID | 名称 | Credits | Context |
|---------|------|---------|---------|
| `gpt-5.2` | GPT-5.2 | x1.33 | 272K |
| `gpt-5.2-codex` | GPT-5.2-Codex | x1.33 | 272K |
| `gpt-5.1` | GPT-5.1 | x0.95 | 272K |
| `gpt-5.1-codex` | GPT-5.1-Codex | x0.95 | 272K |
| `gpt-5.1-codex-max` | GPT-5.1-Codex-Max | x0.95 | 272K |
| `gpt-5.1-codex-mini` | GPT-5.1-Codex-Mini | x0.19 | 272K |

### 其他模型
| 模型 ID | 名称 | Credits | Context |
|---------|------|---------|---------|
| `kimi-k2-thinking` | Kimi-K2-Thinking | x0.46 | 256K |

### 免费模型 (x0.00)
| 模型 ID | 名称 | Context |
|---------|------|---------|
| `glm-4.7-ioa` | GLM-4.7 | 200K |
| `glm-4.6-ioa` | GLM-4.6 | 168K |
| `glm-4.6v-ioa` | GLM-4.6V (多模态) | 128K |
| `deepseek-v3-2-volc-ioa` | DeepSeek-V3.2 | 96K |

## 认证流程

1. 插件请求 `/plugin/auth/state` 获取认证状态和 URL
2. 用户在浏览器中打开 URL 完成 IOA 登录
3. 插件轮询 `/plugin/auth/token` 获取访问令牌
4. Token 到期前自动通过 `/plugin/auth/token/refresh` 刷新

## License

MIT
