Files
meida_backend/scripts
xsl c97f8ae3e1
CI / lint / typecheck / import-linter / tests / secrets (push) Canceled after 0s
feat(cost): persist reasoning tokens and the peak/off-peak tier
ob_ai_call is the only input to V2 pricing, and it was dropping the two
numbers needed to interpret its own cost column.

tokens_reasoning was captured from the provider response but never written to
the table, so the cost of thinking mode was invisible once it left the
process. Folding it into tokens_out was not an option either -- it is billed
at the output rate, and mixing the two hides exactly the difference we now
have to watch.

rate_tier records which price list applied. Without it a row's cost_cents
cannot be rechecked: DeepSeek's peak rate is double off-peak from 2026-08-17,
so recomputing an old row at "the current rate" silently produces a different
answer than what was actually billed.

Migration 0002 adds both columns. tokens_reasoning defaults to 0 rather than
NULL so cost aggregates do not collapse to NULL on historical rows;
rate_tier stays nullable because rows written before this change genuinely
have an unknown tier, and NULL says that more honestly than a guessed 'flat'.

The smoke script now asserts both: reasoning tokens must be 0 (a non-zero
value means a provider default re-enabled thinking mode behind our backs) and
rate_tier must be present. Verified against the real API -- tokens_reasoning=0,
rate_tier=off_peak, 3.9s round trip.
2026-08-14 01:02:13 +08:00
..

scripts/

脚本 用途
smoke.sh 端到端验证:compose up → migrate → 起 API → 发 dev token → 调 真实 DeepSeek → 打印 ob_ai_call 与 bl_ledger
make smoke      # 或 bash scripts/smoke.sh

注意

  • smoke.sh 会真的调用 DeepSeek,产生真实费用。 这是仓库里唯一会花钱的 入口;make test 全程离线。
  • 需要 .env 里有可用的 DEEPSEEK_API_KEY。
  • 它在 8010 端口起一个临时 API 进程,结束时自动清理;日志留在 .smoke/api.log。

写新脚本的规矩

  • set -Eeuo pipefail,并且失败要给出可操作的错误信息,不要只是退出码。
  • 不要把密钥写进脚本或 echo 出来。从 .env / 环境变量读。
  • 任何会改数据或花钱的脚本,在文件头第一行注释里写清楚。