npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ww-komi/kiro-opencode-auth

v0.2.8

Published

OpenCode 插件:通过 AWS Kiro(CodeWhisperer)使用 Claude 等模型

Readme

功能

  • 多种认证方式:支持 AWS Builder ID(IDC)、IAM Identity Center(自定义 Start URL)以及 Kiro Desktop(基于 CLI)登录。
  • 自动同步 Kiro CLI:从本机 kiro-cli 的 SQLite 数据库自动导入并同步当前会话。
  • 渐进式上下文截断:在重试时动态缩小上下文,智能避免 400 错误。
  • 智能账号轮换:按剩余额度优先使用多账号。
  • 高性能存储:使用 Bun 原生 SQLite 高效管理账号与用量。
  • 原生思考模式:通过虚拟模型映射完整支持 Claude 推理能力。
  • 自动恢复:针对限流采用指数退避,并自动刷新令牌。

安装

当前仓库更适合以本地插件方式加载。先构建:

npm run build

然后把一个本地插件文件放到项目级 .opencode/plugins/ 或全局 ~/.config/opencode/plugins/ 目录中,例如:

export { KiroOAuthPlugin } from "/absolute/path/to/kiro-opencode-auth/dist/index.js"

再在 opencode.jsonopencode.jsonc 中加入 provider.kiro 的模型定义:

{
  "provider": {
    "kiro": {
      "models": {
        "auto": {
          "name": "Auto(实验性)",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
        },
        "claude-sonnet-4.5": {
          "name": "Claude Sonnet 4.5",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text", "image", "pdf"], "output": ["text"] }
        },
        "claude-haiku-4.5": {
          "name": "Claude Haiku 4.5",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text", "image"], "output": ["text"] }
        },
        "deepseek-3.2": {
          "name": "DeepSeek 3.2",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "minimax-m2.5": {
          "name": "MiniMax M2.5",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "minimax-m2.1": {
          "name": "MiniMax M2.1",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "glm-5": {
          "name": "GLM 5",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        },
        "qwen3-coder-next": {
          "name": "Qwen3 Coder Next",
          "limit": { "context": 200000, "output": 64000 },
          "modalities": { "input": ["text"], "output": ["text"] }
        }
      }
    }
  }
}

auto 会将 modelId: "auto" 原样透传给 Kiro/CodeWhisperer 接口。这一能力来自实际抓包行为,不是官方文档明确承诺的稳定接口;如果后端策略调整,auto 可能失效,届时请改回显式模型。

插件现在对模型名采用“宽松解析”:

  • 命中内置 MODEL_MAPPING 时,仍按映射转换为后端 modelId
  • 未命中时,不再报错,而是直接将传入的模型名透传给 Kiro 接口

这意味着当 Kiro 新增模型、而插件还未更新映射表时,你可以先直接在 provider.kiro.models 里填写新模型名试用。

说明:

  • 当前 README 里旧的 "plugin": ["@ww-komi/kiro-opencode-auth"] 示例并不适用于这个仓库当前状态,因为该包目前未发布到 npm。
  • 如果未来发布到 npm,再改回 npm 包方式即可。

设置

  1. 通过 Kiro CLI 认证(推荐)
    • 在终端中直接执行 kiro-cli login 完成登录。
    • 插件在启动时会自动检测并导入你的会话。
    • 若使用 AWS IAM Identity Center(SSO/IDC),插件会从 kiro-cli 数据库同时导入令牌与设备注册信息(OIDC 客户端凭据)。
  2. 直接认证
    • 运行 opencode auth login
    • 选择 Other,输入 kiro 后回车。
    • 按提示填写 IAM Identity Center Start URLIAM Identity Center 区域sso_region)。
      • 留空则使用 AWS Builder ID 登录。
      • 填写公司 Start URL(例如 https://your-company.awsapps.com/start)则使用 IAM Identity Center(SSO)
    • 说明:当前 TUI 的 /connect 流程不会执行插件的 OAuth 提示(Start URL / 区域),因此 Identity Center 登录可能回退到 Builder ID,除非你使用 opencode auth login(或在 ~/.config/opencode/kiro/kiro.json 中预先写好默认值)。
    • 使用 IAM Identity Center 时,可能还需要 profile ARNprofileArn)。
      • 若已安装 kiro-cli 且曾选择过配置文件(kiro-cli profile),插件会自动检测。
      • 否则在 ~/.config/opencode/kiro/kiro.json 中设置 idc_profile_arn
    • 浏览器会直接打开 AWS 验证页(无本地认证服务器)。若未自动打开,请复制终端中的链接并输入 OpenCode 打印的验证码。
    • 也可在 ~/.config/opencode/kiro/kiro.json 中通过 idc_start_urlidc_region 预先配置默认值。
  3. 配置默认会写入并维护在 ~/.config/opencode/kiro/kiro.db;若设置了 KIRO_ROOT_DIR,则改为写入该根目录下。

自定义插件数据根目录

插件自己的文件默认写到 OpenCode 配置目录下:

  • kiro.json
  • kiro.db
  • kiro-logs/

现在可以通过环境变量 KIRO_ROOT_DIR 统一覆盖这三个路径的根目录。例如:

export KIRO_ROOT_DIR=/absolute/path/to/kiro-data

设置后,插件会改为使用:

  • /absolute/path/to/kiro-data/kiro.json
  • /absolute/path/to/kiro-data/kiro.db
  • /absolute/path/to/kiro-data/kiro-logs/

说明:

  • 该变量只影响插件自己的文件。
  • kiro-cli 原始数据库路径不受影响;如需覆盖,继续使用 KIROCLI_DB_PATH

本地插件开发

OpenCode 会把插件安装到缓存目录(一般为 ~/.cache/opencode/node_modules)。

在不发布到 npm 的情况下测试本地改动的最简单做法是:先构建本仓库,再热替换缓存里插件的 dist/ 目录:

  1. 在本仓库执行:bun run build(或 npm run build
  2. 热替换 dist/(会生成带时间戳的备份):
PLUGIN_DIR="$HOME/.cache/opencode/node_modules/@ww-komi/kiro-opencode-auth"
TS=$(date +%Y%m%d-%H%M%S)
cp -a "$PLUGIN_DIR/dist" "$PLUGIN_DIR/dist.bak.$TS"
rm -rf "$PLUGIN_DIR/dist"
cp -a "/absolute/path/to/kiro-opencode-auth/dist" "$PLUGIN_DIR/dist"
echo "备份目录: $PLUGIN_DIR/dist.bak.$TS"

还原:

PLUGIN_DIR="$HOME/.cache/opencode/node_modules/@ww-komi/kiro-opencode-auth"
rm -rf "$PLUGIN_DIR/dist"
mv "$PLUGIN_DIR/dist.bak.YYYYMMDD-HHMMSS" "$PLUGIN_DIR/dist"

故障排除

错误:Status: 403(AccessDeniedException / User is not authorized)

若使用 IAM Identity Center(自定义 Start URL),Q Developer / CodeWhisperer API 通常需要 profile ARN

本插件会从本机 kiro-cli 数据库读取当前 profile ARN(state.key = api.codewhisperer.profile),并以 profileArn 发送。

处理办法:

  1. 运行 kiro-cli profile 并选择一个配置文件(例如 QDevProfile-us-east-1)。
  2. 再次执行 opencode auth login(或重启 OpenCode 以重新同步)。

错误:No accounts

表示插件在 ~/.config/opencode/kiro/kiro.db 中没有任何记录。

  1. 确认 kiro-cli login 成功。
  2. 确认 ~/.config/opencode/kiro/kiro.jsonauto_sync_kiro_clitrue
  3. 重试请求;插件在检测到零账号时会尝试从 Kiro CLI 同步。

说明:/connectopencode auth login

若 OAuth 登录需要填写提供商相关字段(如 IAM Identity Center 的 Start URL / 区域),请使用 opencode auth login。当前 TUI 的 /connect 可能不会展示插件的 OAuth 提示,因而无法收集这些输入。

IDC/SSO(OIDC)说明:若在同步阶段暂时无法取到真实邮箱(例如离线),插件可能先创建一个占位邮箱的账号;一旦用量/邮箱查询成功,会替换为真实邮箱。

说明:opencode auth login -> Other -> kiro 直接要求输入 API key

这通常表示 OpenCode 没有成功加载本插件的 auth hook,因此 kiro 没有被注册为带 OAuth 流程的 provider,只能回退到默认的 API key 登录分支。

排查方式:

  1. 确认插件文件确实位于 .opencode/plugins/~/.config/opencode/plugins/
  2. 运行 opencode auth login --print-logs -p kiro 检查日志中是否有 failed to load pluginUnknown provider "kiro"
  3. 若使用的是旧构建,先重新执行 npm run build,再让 OpenCode 重新加载最新的 dist/

Kiro CLI(Google/GitHub OAuth)用户:插件同步始终不触发

若通过 kiro-cli login 使用 Google 或 GitHub OAuth(而非 AWS Builder ID 或 IAM Identity Center),插件同步可能永远不会触发。原因是 OpenCode 在发起 API 请求前要求 auth.json 中存在 kiro 条目,而插件加载器仅在发起请求时才会运行。

变通做法:~/.local/share/opencode/auth.json 中加入最小占位条目:

{
  "kiro": {
    "type": "api",
    "key": "placeholder"
  }
}

加入后,OpenCode 会认为提供商已连接,从而触发插件加载器,kiro-cli 同步会把真实令牌写入 kiro.db。占位值不会用于实际 API 调用。

重要: 请确认 ~/.config/opencode/kiro/kiro.jsonauto_sync_kiro_clitrue,且在使用此变通前 kiro-cli login 已成功。

错误:ERR_INVALID_URL

TypeError [ERR_INVALID_URL]: "undefined/chat/completions" cannot be parsed as a URL

若出现此错误,请检查 .local/share/opencode 下的 auth.json。示例:

{
  "kiro": {
    "type": "api",
    "key": "whatever"
  }
}

配置

插件支持较多配置项。默认编辑 ~/.config/opencode/kiro/kiro.json;若设置了 KIRO_ROOT_DIR,则编辑 ${KIRO_ROOT_DIR}/kiro.json

{
  "auto_sync_kiro_cli": true,
  "account_selection_strategy": "lowest-usage",
  "default_region": "us-east-1",
  "idc_start_url": "https://your-company.awsapps.com/start",
  "idc_region": "us-east-1",
  "rate_limit_retry_delay_ms": 5000,
  "rate_limit_max_retries": 3,
  "max_request_iterations": 20,
  "request_timeout_ms": 120000,
  "token_expiry_buffer_ms": 120000,
  "usage_sync_max_retries": 3,
  "usage_tracking_enabled": true,
  "enable_log_api_request": false
}

配置项说明

  • auto_sync_kiro_cli:是否自动从 Kiro CLI 同步会话(默认:true)。
  • account_selection_strategy:账号轮换策略(stickyround-robinlowest-usage)。
  • default_region:AWS 区域(如 us-east-1us-west-2)。
  • idc_start_url:默认 IAM Identity Center Start URL(例如 https://your-company.awsapps.com/start)。不设置或留空则默认走 AWS Builder ID。
  • idc_region:IAM Identity Center(SSO OIDC)区域(sso_region)。默认 us-east-1
  • rate_limit_retry_delay_ms:限流重试间隔(1000–60000 毫秒)。
  • rate_limit_max_retries:限流最大重试次数(0–10)。
  • max_request_iterations:防止卡死的最大循环次数(10–1000)。
  • request_timeout_ms:请求超时(60000–600000 毫秒)。
  • token_expiry_buffer_ms:令牌刷新提前量(30000–300000 毫秒)。
  • usage_sync_max_retries:用量同步重试次数(0–5)。
  • auth_server_port_start:遗留项/已忽略(无本地认证服务器)。
  • auth_server_port_range:遗留项/已忽略(无本地认证服务器)。
  • usage_tracking_enabled:是否启用用量追踪与 Toast 通知。
  • enable_log_api_request:是否启用详细 API 请求日志。

存储位置

Linux / macOS:

  • SQLite 数据库:~/.config/opencode/kiro/kiro.db
  • 插件配置:~/.config/opencode/kiro/kiro.json

Windows:

  • SQLite 数据库:%APPDATA%\opencode\kiro\kiro.db
  • 插件配置:%APPDATA%\opencode\kiro\kiro.json

致谢

感谢 AIClient-2-API 提供 Kiro 认证逻辑与请求模式的基础实现。

免责声明

本插件仅供学习与教育用途,为独立实现,与 Amazon Web Services(AWS)或 Anthropic 无关联、未获背书或支持。使用本插件的风险由使用者自行承担。

欢迎提交 PR 继续改进本插件。