Skip to content

Auth 凭证语义

本文定义了以下功能所共用的凭证资质判断与解析语义规范:

  • resolveAuthProfileOrder
  • resolveApiKeyForProfile
  • models status --probe
  • doctor-auth

目标是保持选择时与运行时的行为一致。

稳定错误码

  • ok
  • missing_credential
  • invalid_expires
  • expired
  • unresolved_ref

Token 凭证

Token 凭证(type: "token")支持内联 token 和/或 tokenRef

资质判断规则

  1. tokentokenRef 均缺失时,该 profile 不可用。
  2. expires 为可选字段。
  3. expires 存在,必须是大于 0 的有限数值。
  4. expires 无效(NaN0、负数、非有限值或类型错误),该 profile 不可用,错误码为 invalid_expires
  5. expires 已过期,该 profile 不可用,错误码为 expired
  6. tokenRef 不能绕过 expires 校验。

解析规则

  1. 解析器对 expires 的处理与资质判断语义一致。
  2. 对于可用的 profile,token 内容可从内联值或 tokenRef 解析。
  3. 无法解析的引用会在 models status --probe 输出中产生 unresolved_ref

兼容旧脚本的报错格式

为保持脚本兼容性,probe 错误的第一行保持不变:

Auth profile credentials are missing or expired.

后续行可添加人性化说明和稳定错误码。