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

@laoyuehanni/dsh-minimax-oauth

v0.1.2

Published

DSH plugin: MiniMax Code OAuth sign-in and Anthropic Messages provider

Readme

dsh-minimax-oauth

Awesome DSH Plugin

English | 简体中文

一个 DSH 插件:在模型页的供应商下拉里选 minimax-code-cn,卡片上点登录,用 OAuth 设备码流程 把 MiniMax Code 的 agent.minimax.cn Anthropic Messages 网关接成一个 provider 路由,并提供两个模型。

做这个插件的初衷,是在 DSH 中使用 MiniMax Code(mcode),消耗签到获得的积分,并享受 mcode 中的一些限时免费福利。

之所以需要它:该网关只认一种凭证形态 —— Authorization: Bearer <token> —— 而 harness 自带的 pi-ai 路由最终是以 x-api-key 发出请求的。因此本插件自己构造一个带真实 OAuthAuth 的 pi-ai Provider,交给 harness 已导出的 PiAiAdapter;其后的 SSE 投影、图片限额、空闲看门狗、 abort 传播、请求归属头,全部仍由 adapter 负责。

仓库:https://github.com/LaoYueHanNi/dsh-minimax-oauth

功能

  • 设备码 OAuth 登录,直接在供应商卡片上完成——不用粘贴 API Key。令牌保存在本机, 向配置的账号服务与网关发送,用于认证。
  • 两个模型的目录,经网关的 Anthropic Messages 路由提供,每一项各自声明上下文窗口、输出上限、 图片支持与思考等级。
  • 点击卡片的“编辑”勾选启用模型——使用宿主原生控件,点击“保存”写回路由的 models 列表并收起;“取消”放弃草稿并收起。
  • Bearer 凭证传输——插件自建 pi-ai Provider,其 OAuthAuth 产出网关要求、而自带 pi-ai 路由 不会发送的 Authorization: Bearer 头。
  • 载入期校验——非 https:// 的 URL、空或重复的模型 id、非正数容量、未知思考等级,都在插件 载入时报错,而不是等到第一次请求。
  • 路由自有的重试策略,与 dsh-llm-retry 同一 schema,可在路由配置中调整。

安装

前置条件:DSH 0.2.0-rc.2 或兼容且导出 PiAiAdapter 的版本、带 Web 界面的 profile (下文以 web 为例),以及 Node ≥ 22.19。

npm 包名为 @laoyuehanni/dsh-minimax-oauth:

dsh plugin --profile web add @laoyuehanni/dsh-minimax-oauth

包声明了 dsh.bundle,插件管理器会安装 bundle 并添加供应商配置项。安装后重启 Web 宿主(dsh --profile web)。 桌面版请将 web 换成 desktop,安装后完全退出并重新打开 App。

更新

dsh plugin --profile web update @laoyuehanni/dsh-minimax-oauth

重启宿主后加载新版插件。旧模型 ID 会被忽略并提示删除;在卡片上勾选 MiniMax-M3 或 MiniMax-M3.1-Flash 即可保存有效选择。

移除

dsh plugin --profile web remove @laoyuehanni/dsh-minimax-oauth

移除后重启宿主。移除插件不会撤销 MiniMax 授权,也不会删除已保存的凭据;需要清理登录时,请先在模型页展开本插件卡片并点击“退出登录”。

登录

  1. 打开模型页,在供应商下拉里选 minimax-code-cn。
  2. 点击“登录 MiniMax Code”,复制卡片中的验证码,再点击“打开授权页面”。
  3. 在浏览器里输入验证码并确认授权,宿主确认添加后自动关闭添加表单,供应商出现在已添加列表。
  4. 点击供应商卡片的“编辑”打开编辑器:卡片上显示账号状态,点“退出登录”可清除已保存的授权。
  5. 勾选要启用的模型,再点击“保存”:立即生效并收起,无需重启;“取消”放弃草稿并收起。模型右侧的箭头可展开容量和输入类型。

凭据存放在 credential scope minimax-oauth、id mcode 下。access token 有效期 1 小时,pi-ai 会在凭据存储的锁内、于请求发现其距过期不足五分钟时自动刷新,跨过整个有效期无需重启。

登录成功后插件会在自己的配置命名空间写入 signedIn: true。模型页按该字段是否存在决定是否列入 “已配置”列表。退出登录后写入 false,保留供应商行与模型选择,方便再次登录。宿主行上的“删除” 只移除这个标记,不会删除已保存的凭据。

在已登录卡片中点击“退出登录”,插件会取消正在进行的设备码登录,尝试撤销当前 refresh token, 然后删除本插件在 DSH 中保存的凭据。远程撤销最多等待 10 秒;撤销失败仍会清理本机凭据并显示提示, 本机删除失败则显示错误并保留重试入口。该操作不读写 MiniMax Code CLI 的凭据文件。

配置

插件的 Config 可以完全省略,默认值就是在 CN 生产环境实测过的取值。需要覆盖时,在 ~/.dsh/profiles/web/cordis.patch.yml 中配置对应的 bundle 条目:

- id: minimax-oauth
  name: "@laoyuehanni/dsh-minimax-oauth"
  config:
    displayName: minimax-code-cn
    accountBaseUrl: https://account.minimax.cn
    gatewayBaseUrl: https://agent.minimax.cn/mavis/api/v1/llm
    models:
      - id: MiniMax-M3
        name: MiniMax-M3
        contextWindow: 512000
        maxTokens: 128000
        input: [text, image]
        reasoningEfforts:
          off: disabled
          low: low
          medium: medium
          high: high
          xhigh: xhigh
          max: max

| 字段 | 默认值 | 含义 | |---|---|---| | displayName | minimax-code-cn | 模型选择器与供应商卡片上的名字。 | | accountBaseUrl | https://account.minimax.cn | 账号服务主机,提供 /oauth2/device/code、/oauth2/token、/oauth2/revoke。 | | gatewayBaseUrl | https://agent.minimax.cn/mavis/api/v1/llm | Anthropic Messages 网关基址。不要加 /v1/messages,SDK 会补。 | | models | 下列两个模型 | 本路由提供的模型表;在卡片里勾选并保存后写入此处。 | | streamIdleTimeoutMs | 300000 | 单次流式读取允许的空闲间隔。 | | maxRequestImageBytes | 20971520 | 单请求 base64 图片载荷上限。 | | requestImagePixelBudget | 4194304 | 单请求版本的像素总预算。 | | requestImageMaxBytes | 1048576 | base64 展开前的原始字节目标。 | | retryPolicy | harness 默认 | provider 自有重试策略,schema 与 dsh-llm-retry 相同。 |

models 每项接受:

| 字段 | 含义 | |---|---| | id | 网关认得的模型 id,必填且唯一。 | | name | 展示名,缺省与 id 相同。 | | contextWindow / maxTokens | 上下文与单次输出上限,必须为正数。 | | input | text / image。默认按下方表格。 | | reasoningEfforts | 思考级别到网关 effort 取值的映射;false 表示该模型不声明思考。 |

配置不合法(URL 不是 https://、模型 id 为空或重复、容量非正数、级别名不在 off/minimal/low/medium/high/xhigh/max 里、值留空)会在加载时失败,而不是等到第一次请求。

两个模型的默认能力

| 模型 | 上下文 | 输入 | 思考级别 | |---|---|---|---| | MiniMax-M3 | 512K | 文本 + 图片 | off, low, medium, high, xhigh, max | | MiniMax-M3.1-Flash | 512K | 文本 + 图片 | low, medium, high, xhigh, max |

请求未指定思考级别时默认走 max —— MiniMax 官方推荐值,两个模型都接受。

reasoningEfforts 里没写的级别等于"钉死为不可用",这正是 Flash 没有 off 的原因: 上游将它的思考模式声明为强制开启。网关在 adaptive 模式下只认 effort 参数、不看 budget_tokens。

关于模型表

仅支持 MiniMax-M3 和 MiniMax-M3.1-Flash。配置里的其他模型(包括 Flash Preview 与 M2.7) 会被忽略,不做别名映射或回退;供应商卡片和宿主日志会提示删除老旧模型。若配置中全部是旧模型, 插件仍可加载,但没有已启用的模型;在卡片上勾选支持的模型即可保存并清理旧配置。

模型 ID、默认容量与思考模式参考 MiniMax Code 模型目录。 本插件默认提供文本与图片输入、512K 上下文和 128K 输出;上游的视频输入和可选 1M 上下文选择器未接入。

网关不提供模型列表,并且对不认识的 id 会静默回退到 MiniMax-M3,因此模型表只能由配置给出。 核对方式是看响应的 model 字段,而不是"没有报错"。卡片里的勾选框以这份表为准,取消勾选 的模型不会从下拉里消失 —— 它只是不再被本路由提供,随时可以再勾回来。

工作原理

  • oauth.ts 针对 MiniMax Code 账号服务实现 RFC 8628 设备码流程,兼容该服务实际返回的两种形态: 标准形态(device_code、expires_in 秒、interval 秒)与私有形态(只有 user_code、 expired_in 为绝对毫秒时间戳、interval 为毫秒)。
  • auth.ts 把该流程包装成 pi-ai 的 OAuthAuth,其 toAuth() 返回 { headers: { authorization: 'Bearer …' } } —— 这是该网关唯一接受的形态。
  • provider.ts 构造 pi-ai 的 Provider 与模型表。pi-ai 自身的 provider catalog 是生成的硬编码 列表、没有运行时注册入口,因此它不提供的路由只能以字面量对象构造。reasoningEfforts 映射到 pi-ai 的 thinkingLevelMap + compat.forceAdaptiveThinking,让思考级别真正发到网关上。
  • store.ts 把 harness 的凭据记录适配成 pi-ai 需要的 CredentialStore / AuthContext 一对。 OAuth 授权以 grant 记录存放、payload 逐字保留,且写在本插件自己的 scope 下 —— 这正是它能被 本插件读懂、又不会被别的插件误读的原因。
  • session.ts / route.ts 登录、退出登录和模型选择的状态控制与三条 HTTP 路由。授权 seam 没有 @Remote 面, 所以浏览器侧只能经由插件自己的路由与服务端对话。
  • models.ts 模型勾选控制器:写入走 settings 服务,模型表因此随配置重载而持久化。
  • flow.ts 另向授权 seam 注册一份登录流,供能渲染登录流(而非登录卡片)的界面使用。
  • index.ts 挂载路由:为 mcode 注册 PiAiAdapter,其中 resolveApiKey 故意返回 undefined。返回任何字符串都会变成请求级 apiKey 覆盖,把请求推到 SDK 的 x-api-key 分支, 而那个分支只会拿到 401。
  • src/client/ 浏览器侧:往 settings.models.provider-card 槽位注册登录卡片,键就是本插件的 settings 命名空间,因此只会命中自己的那一行。

已知限制

  • 非官方端点。 agent.minimax.cn/mavis/... 是产品内部网关,没有公开契约,也没有支持渠道, 可能随时变更或关闭;所有端点因此都可配置。
  • EN 主机未验证。 account.minimax.io / agent.minimax.io 作为可配置项提供,但只实测过 CN。
  • 不映射额度耗尽。 余额耗尽会以网关自身的错误上抛,不做专用映射。
  • 独立集成。 本项目与 MiniMax 无隶属关系,也不代表获得其官方认可。插件使用 MiniMax Code 的 公开 OAuth client id 与 scope 取得独立授权,不收集账号密码。OAuth 与网关访问受 MiniMax 的 服务政策约束;MIT 许可证覆盖本插件代码,不代表取得相关服务的访问权。
  • 旋转式刷新令牌。 MiniMax Code 的 refresh token 每次使用都会轮换,且只能被消费一次。插件 只消费自己登录签发的 refresh token,绝不读写 MiniMax Code CLI 的凭证文件 —— 指向那些文件会让 CLI 退出登录。
  • 冷重启。 链接安装的插件在 HMR 的忽略范围内,改动宿主侧代码后必须完全退出 App 再打开。

开发

# 可选:复制 .npmrc.example 为 .npmrc,配置个人镜像;该文件不入库。
# pnpm 的 peer 安装与依赖构建策略已统一放在 pnpm-workspace.yaml。
pnpm install --frozen-lockfile

pnpm test        # vitest:协议、凭据适配、provider 形态、登录接线、模型勾选
pnpm typecheck   # 对 src、tests 与浏览器侧跑 tsc
pnpm run build   # tsc → lib/
pnpm run build:all   # 上面这一步 + tsdown → lib/client.js
pnpm run watch:client   # 监听浏览器侧代码并重建
pnpm run check       # 类型检查、测试和决策记录校验

本地开发时,将构建后的检出目录安装到 profile:

dsh plugin --profile web add link:/absolute/path/to/dsh-minimax-oauth

修改后重新构建并重启宿主。构建产物不进入 Git;prepack 在生成压缩包前构建宿主与浏览器产物, prepublishOnly 在发布前运行检查。用户安装已发布的包时不会执行这两个钩子。

以下验证脚本仅供已安装开发依赖的源码检出目录使用,不随 npm 包分发。

登录完成后,scripts/verify-models.mjs 会对照真实网关复核验收条件:读取插件存入的 access token,对配置中的每个模型各发一次最小请求,并比对响应 model 字段与请求的 id。它不会刷新 令牌,因此不会轮换或作废已存的授权。

node scripts/verify-models.mjs