Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a8fcab0
增加和修复部分问题
koangel Jan 7, 2026
f949f9e
Merge branch 'master' of https://github.com/luluxiuxiu/kiro.rs
koangel Jan 7, 2026
5ca98a5
修复重试BUG
koangel Jan 8, 2026
41754a5
Merge updates and improve Admin UI
koangel Jan 8, 2026
7eda090
升级功能,增加完整的读取内容
koangel Jan 8, 2026
6ad5c7a
增加和修复部分问题
koangel Jan 8, 2026
729bd4d
Merge branch 'master' of https://github.com/hank9999/kiro.rs
koangel Jan 9, 2026
8a24af0
修复特殊用量问题
koangel Jan 9, 2026
e04b9b5
增加特殊的发布脚本
koangel Jan 9, 2026
7941690
fix(.gitignore): 添加 public/ 目录到忽略列表
koangel Jan 9, 2026
1b3a8df
feat: 添加自定义反序列化器以处理 CBOR 时间戳
koangel Jan 9, 2026
fb040f4
feat: 添加自定义反序列化器以处理 CBOR 整数和浮点数
koangel Jan 9, 2026
a708b18
feat: 添加用户ID到凭据状态项和相关组件
koangel Jan 9, 2026
a542b03
feat: 修改余额响应中的 nextResetAt 类型为字符串
koangel Jan 9, 2026
d6c01ae
修复问题
koangel Jan 9, 2026
fc845a1
fix: 402 MONTHLY_REQUEST_COUNT 时禁用凭据并故障转移
Gaoyukun Jan 10, 2026
328343a
fix: 合并冲突,保留现有功能
koangel Jan 10, 2026
8bce32d
feat: 更新 README,添加 Admin UI 和账号信息查询功能说明
koangel Jan 10, 2026
652e186
feat: 修复write failed 增强工具使用事件处理,添加工具名称缓存和输入检查
koangel Jan 10, 2026
7d1ce18
Merge branch 'master' of https://github.com/hank9999/kiro.rs
koangel Jan 10, 2026
b3bdda5
feat: 添加凭据余额查询功能,支持自动刷新和错误处理
koangel Jan 10, 2026
d3d5983
feat: 优化凭据操作按钮布局,增强用户体验
koangel Jan 10, 2026
6af88bd
feat: 添加 IdC Token 刷新功能测试,支持从外部凭据文件加载
koangel Jan 11, 2026
2db63cc
feat: 添加 ListAvailableProfiles API 数据模型及相关逻辑
koangel Jan 11, 2026
27a469d
feat: 添加凭据余额对话框的查询失效处理及自动刷新功能
koangel Jan 11, 2026
21baec3
feat: 添加 IdC 凭据发送请求的测试,支持调试 403 错误
koangel Jan 11, 2026
dfe5056
feat: 更新 IdC Token 刷新逻辑,确保有效期默认设置为 1 小时
koangel Jan 11, 2026
ccc94cd
feat: 添加 IdC 403 错误诊断测试,确保请求体中动态注入 profileArn
koangel Jan 11, 2026
7722f04
feat: 更新 Social Token 刷新逻辑,确保默认有效期为 1 小时并修复过期判断
koangel Jan 11, 2026
629916a
feat: 支持凭据级 region/machineId 配置及自动认证方式检测
Gaoyukun Jan 11, 2026
648430e
Merge branch 'hank9999:master' into master
Gaoyukun Jan 11, 2026
896be2e
Merge branch 'master' of https://github.com/Gaoyukun/kiro.rs
Gaoyukun Jan 11, 2026
0c16f2a
feat: 启动时自动补全 machineId 并切换 rustls-tls
Gaoyukun Jan 11, 2026
d75ec6e
Merge branch 'master' of https://github.com/hank9999/kiro.rs
koangel Jan 12, 2026
bb4318a
Merge branch 'master' of https://github.com/hank9999/kiro.rs
koangel Jan 13, 2026
93118c3
Merge branch 'pr-25'
koangel Jan 13, 2026
dff4161
fix: 将默认身份提供者从 Github 更改为 Google
koangel Jan 13, 2026
32547f8
Merge: resolve conflicts and add web search feature
koangel Jan 13, 2026
3c797eb
Merge: resolve conflicts in converter.rs and usage_limits.rs
koangel Jan 16, 2026
fb40242
feat(anthropic): Add automatic stream retry on interruption
koangel Jan 16, 2026
b666dfc
Merge https://github.com/hank9999/kiro.rs
koangel Jan 21, 2026
ed79b6e
feat(凭据管理): 支持按凭据配置启用模型列表
koangel Jan 21, 2026
d3d1eac
feat(anthropic): Handle content length exceeded errors gracefully
koangel Jan 21, 2026
c84fa3a
feat(凭据管理): 添加诊断日志和profileArn字段支持
koangel Jan 21, 2026
e102d93
feat(anthropic): Add session-level token consistency and context mana…
koangel Jan 22, 2026
27e4ad2
fix(anthropic): Correct content length exceeded error handling response
koangel Jan 22, 2026
7ffeea0
feat(anthropic): Add conversation history management and truncation r…
koangel Jan 22, 2026
8d2426c
feat(admin): Add summary model configuration management
koangel Jan 22, 2026
17ac2d6
refactor(common): Add safe UTF-8 string truncation utilities
koangel Jan 22, 2026
bc5dd32
feat(anthropic): Add upstream error detection and retry handling
koangel Jan 22, 2026
921223a
feat(anthropic): Simplify token update logic and add real-time usage …
koangel Jan 23, 2026
1cbe9e4
Merge https://github.com/hank9999/kiro.rs
koangel Jan 29, 2026
8aa5231
feat(anthropic): Add session tracking and improve non-stream request …
koangel Jan 29, 2026
8aa3bb0
chore(main): Remove redundant logging initialization
koangel Jan 29, 2026
50c70ad
feat(anthropic): Add statistics tracking to buffered stream handler
koangel Feb 3, 2026
66c38c1
Merge https://github.com/hank9999/kiro.rs
koangel Feb 6, 2026
d66054d
chore: 解决合并冲突并保留功能修改
koangel Feb 20, 2026
a2f7073
chore: 将 public/ 目录添加到 .gitignore
koangel Feb 20, 2026
81d1b6c
fix(admin-ui): 修复构建错误
koangel Feb 20, 2026
dfa5eab
Resolve merge conflicts (preserve streaming/non-stream retry + creden…
koangel Feb 23, 2026
f728484
Merge https://github.com/hank9999/kiro.rs
koangel Mar 2, 2026
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
/credentials.*
/kiro_balance_cache.json
/kiro_stats.json
/.ai_workflow/
public/
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2" # 按天滚动 + 异步写日志
anyhow = "1.0"
http = "1.0"
futures = "0.3"
Expand All @@ -25,10 +26,13 @@ sha2 = "0.10"
hex = "0.4"
crc = "3" # CRC32C 计算
bytes = "1" # 高效的字节缓冲区
base64 = "0.22" # base64 编码/解码(用于图片 data URL 解析与校验)
tower-http = { version = "0.6", features = ["cors"] }
clap = { version = "4.5", features = ["derive"] }
urlencoding = "2"
parking_lot = "0.12" # 高性能同步原语
subtle = "2.6" # 常量时间比较(防止时序攻击)
rust-embed = "8" # 嵌入静态文件
mime_guess = "2" # MIME 类型推断
ciborium = "0.2" # Kiro Web Portal API (rpc-v2-cbor) 编解码(替代已弃用的 serde_cbor)
async-trait = "0.1" # 异步 trait 支持
146 changes: 144 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
- **WebSearch**: 内置 WebSearch 工具转换逻辑
- **多模型支持**: 支持 Sonnet、Opus、Haiku 系列模型
- **Admin 管理**: 可选的 Web 管理界面和 API,支持凭据管理、余额查询等
- **Admin UI**: 内置管理面板,支持凭据管理和账号信息查询
- **账号信息**: 通过 Kiro Web Portal API 获取套餐、用量等详细信息
- **多级 Region 配置**: 支持全局和凭据级别的 Auth Region / API Region 配置
- **凭据级代理**: 支持为每个凭据单独配置 HTTP/SOCKS5 代理,优先级:凭据代理 > 全局代理 > 无代理

---

- [开始](#开始)
- [1. 编译](#1-编译)
- [2. 最小配置](#2-最小配置)
Expand All @@ -72,8 +72,12 @@
- [License](#license)
- [致谢](#致谢)

---

## 开始

## 快速开始

### 1. 编译

> PS: 如果不想编辑可以直接前往 Release 下载二进制文件
Expand Down Expand Up @@ -386,6 +390,144 @@ RUST_LOG=debug ./target/release/kiro-rs
> - `/cc/v1/messages`:缓冲模式,等待上游流完成后,用从 `contextUsageEvent` 计算的准确 `input_tokens` 更正 `message_start`,然后一次性返回所有事件
> - 等待期间会每 25 秒发送 `ping` 事件保活

### config.json

| 字段 | 类型 | 默认值 | 描述 |
|------|------|--------|-------------------------|
| `host` | string | `127.0.0.1` | 服务监听地址 |
| `port` | number | `8080` | 服务监听端口 |
| `apiKey` | string | - | 自定义 API Key(用于客户端认证,必配) |
| `region` | string | `us-east-1` | AWS 区域 |
| `kiroVersion` | string | `0.8.0` | Kiro 版本号 |
| `machineId` | string | - | 自定义机器码(64位十六进制)不定义则自动生成 |
| `systemVersion` | string | 随机 | 系统版本标识 |
| `nodeVersion` | string | `22.21.1` | Node.js 版本标识 |
| `tlsBackend` | string | `rustls` | TLS 后端:`rustls` 或 `native-tls` |
| `countTokensApiUrl` | string | - | 外部 count_tokens API 地址(可选) |
| `countTokensApiKey` | string | - | 外部 count_tokens API 密钥(可选) |
| `countTokensAuthType` | string | `x-api-key` | 外部 API 认证类型:`x-api-key` 或 `bearer` |
| `proxyUrl` | string | - | HTTP/SOCKS5 代理地址(可选) |
| `proxyUsername` | string | - | 代理用户名(可选) |
| `proxyPassword` | string | - | 代理密码(可选) |
| `adminApiKey` | string | - | Admin API 密钥,配置后启用凭据管理 API, 填写后才会启用web管理(可选) |

### credentials.json

支持单对象格式(向后兼容)或数组格式(多凭据)。

| 字段 | 类型 | 描述 |
|------|------|-------------------------|
| `id` | number | 凭据唯一 ID(可选,仅用于 Admin API 管理;手写文件可不填) |
| `accessToken` | string | OAuth 访问令牌(可选,可自动刷新) |
| `refreshToken` | string | OAuth 刷新令牌 |
| `profileArn` | string | AWS Profile ARN(可选,登录时返回) |
| `expiresAt` | string | Token 过期时间 (RFC3339) |
| `authMethod` | string | 认证方式(`social` / `idc`) |
| `clientId` | string | IdC 登录的客户端 ID(可选) |
| `clientSecret` | string | IdC 登录的客户端密钥(可选) |
| `priority` | number | 凭据优先级,数字越小越优先,默认为 0(多凭据格式时有效)|
| `region` | string | 凭据级 region(可选),用于 OIDC token 刷新时指定 endpoint 的区域。未配置时回退到 config.json 的 region。注意:API 调用始终使用 config.json 的 region |
| `machineId` | string | 凭据级机器码(可选,64位十六进制)。未配置时回退到 config.json 的 machineId;都未配置时由 refreshToken 派生 |

说明:
- IdC / Builder-ID / IAM 在本项目里属于同一种登录方式,配置时统一使用 `authMethod: "idc"`
- 为兼容旧配置,`builder-id` / `iam` 仍可被识别,但会按 `idc` 处理

## 模型映射

| Anthropic 模型 | Kiro 模型 |
|----------------|-----------|
| `*sonnet*` | `claude-sonnet-4.5` |
| `*opus*` | `claude-opus-4.5` |
| `*haiku*` | `claude-haiku-4.5` |

## 项目结构

```
kiro-rs/
├── src/
│ ├── main.rs # 程序入口
│ ├── model/ # 配置和参数模型
│ │ ├── config.rs # 应用配置
│ │ └── arg.rs # 命令行参数
│ ├── anthropic/ # Anthropic API 兼容层
│ │ ├── router.rs # 路由配置
│ │ ├── handlers.rs # 请求处理器
│ │ ├── middleware.rs # 认证中间件
│ │ ├── types.rs # 类型定义
│ │ ├── converter.rs # 协议转换器
│ │ ├── stream.rs # 流式响应处理
│ │ └── token.rs # Token 估算
│ ├── admin/ # Admin API 模块
│ │ ├── router.rs # 路由配置
│ │ ├── handlers.rs # 请求处理器
│ │ ├── middleware.rs # 认证中间件
│ │ ├── service.rs # 业务逻辑
│ │ ├── types.rs # 类型定义
│ │ └── error.rs # 错误处理
│ └── kiro/ # Kiro API 客户端
│ ├── provider.rs # API 提供者
│ ├── token_manager.rs # Token 管理(单/多凭据)
│ ├── web_portal.rs # Kiro Web Portal API(账号信息)
│ ├── machine_id.rs # 设备指纹生成
│ ├── model/ # 数据模型
│ │ ├── credentials.rs # OAuth 凭证
│ │ ├── events/ # 响应事件类型
│ │ ├── requests/ # 请求类型
│ │ └── common/ # 共享类型
│ └── parser/ # AWS Event Stream 解析器
│ ├── decoder.rs # 流式解码器
│ ├── frame.rs # 帧解析
│ ├── header.rs # 头部解析
│ └── crc.rs # CRC 校验
├── Cargo.toml # 项目配置
├── admin-ui/ # 管理面板前端(Vue 3 + Vite)
├── config.example.json # 配置示例
├── admin-ui/ # Admin UI 前端工程(构建产物会嵌入二进制)
├── tools/ # 辅助工具
└── Dockerfile # Docker 构建文件
```

## 技术栈

- **Web 框架**: [Axum](https://github.com/tokio-rs/axum) 0.8
- **异步运行时**: [Tokio](https://tokio.rs/)
- **HTTP 客户端**: [Reqwest](https://github.com/seanmonstar/reqwest)
- **序列化**: [Serde](https://serde.rs/)
- **日志**: [tracing](https://github.com/tokio-rs/tracing)
- **命令行**: [Clap](https://github.com/clap-rs/clap)

## 高级功能

### Admin UI(管理面板)

配置 `adminApiKey` 后,访问 `http://127.0.0.1:8990/` 即可打开管理面板。

功能包括:
- 查看所有凭据状态(优先级、禁用状态、失败次数、过期时间)
- 添加/删除凭据
- 设置凭据优先级和禁用状态
- 查看账号详细信息(邮箱、套餐类型、用量明细)
- 查看凭据余额和统计信息
- 重置失败计数

### 账号信息查询

通过 Kiro Web Portal API(app.kiro.dev)获取账号详细信息:

```bash
# 获取指定凭据的账号信息
curl http://127.0.0.1:8990/api/admin/credentials/1/account \
-H "x-api-key: sk-admin-your-secret-key"
```

返回信息包括:
- 账户邮箱和用户 ID
- 订阅类型(Free/Pro/Enterprise/Teams)
- Credits 用量明细(基础额度、免费试用、奖励额度)
- 下次重置时间
- 超额配置状态

### Thinking 模式

支持 Claude 的 extended thinking 功能:
Expand Down
72 changes: 69 additions & 3 deletions admin-ui/src/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import type {
SuccessResponse,
SetDisabledRequest,
SetPriorityRequest,
SetEnabledModelsRequest,
AddCredentialRequest,
AddCredentialResponse,
CredentialStatsResponse,
CredentialAccountInfoResponse,
} from '@/types/api'

// 创建 axios 实例
Expand All @@ -33,6 +36,12 @@ export async function getCredentials(): Promise<CredentialsStatusResponse> {
return data
}

// 删除指定凭据
export async function deleteCredential(id: number): Promise<SuccessResponse> {
const { data } = await api.delete<SuccessResponse>(`/credentials/${id}`)
return data
}

// 设置凭据禁用状态
export async function setCredentialDisabled(
id: number,
Expand All @@ -57,6 +66,18 @@ export async function setCredentialPriority(
return data
}

// 设置凭据启用模型列表
export async function setCredentialEnabledModels(
id: number,
enabledModels: string[]
): Promise<SuccessResponse> {
const { data } = await api.post<SuccessResponse>(
`/credentials/${id}/models`,
{ enabledModels } as SetEnabledModelsRequest
)
return data
}

// 重置失败计数
export async function resetCredentialFailure(
id: number
Expand All @@ -71,6 +92,14 @@ export async function getCredentialBalance(id: number): Promise<BalanceResponse>
return data
}

// 获取凭据账号信息(套餐/用量/邮箱等)
export async function getCredentialAccountInfo(
id: number
): Promise<CredentialAccountInfoResponse> {
const { data } = await api.get<CredentialAccountInfoResponse>(`/credentials/${id}/account`)
return data
}

// 添加新凭据
export async function addCredential(
req: AddCredentialRequest
Expand All @@ -79,9 +108,46 @@ export async function addCredential(
return data
}

// 删除凭据
export async function deleteCredential(id: number): Promise<SuccessResponse> {
const { data } = await api.delete<SuccessResponse>(`/credentials/${id}`)
// 获取指定凭据统计
export async function getCredentialStats(id: number): Promise<CredentialStatsResponse> {
const { data } = await api.get<CredentialStatsResponse>(`/credentials/${id}/stats`)
return data
}

// 清空指定凭据统计
export async function resetCredentialStats(id: number): Promise<SuccessResponse> {
const { data } = await api.post<SuccessResponse>(`/credentials/${id}/stats/reset`)
return data
}

// 清空全部统计
export async function resetAllStats(): Promise<SuccessResponse> {
const { data } = await api.post<SuccessResponse>('/stats/reset')
return data
}

// ===== 摘要模型设置 =====

export interface SummaryModelResponse {
currentModel: string
availableModels: string[]
}

export interface SetSummaryModelRequest {
model: string
}

// 获取摘要模型设置
export async function getSummaryModel(): Promise<SummaryModelResponse> {
const { data } = await api.get<SummaryModelResponse>('/settings/summary-model')
return data
}

// 设置摘要模型
export async function setSummaryModel(model: string): Promise<SuccessResponse> {
const { data } = await api.post<SuccessResponse>('/settings/summary-model', {
model,
} as SetSummaryModelRequest)
return data
}

Expand Down
Loading