@jeik/usage-counter
v1.0.0
Published
统计 agent 的调用次数,存入 SQLite,并提供查询 / 排行 / 导出工具。
Readme
usage-counter
统计 agent 的调用次数,存入 SQLite,并提供查询 / 排行 / 导出工具。
每次"发给模型之前"(before_agent_run 钩子)记一条,写入本地 SQLite;再注册查询工具,让 agent 一键查统计。
安装
方式一:npm(推荐)
插件已发布到 npm。用自带的安装向导,一条命令完成「装插件 + 开启所需 hook 权限」:
npx -y @jeik/usage-counter install向导会确认开启 allowConversationAccess(统计要读对话上下文:agentId / 会话 / 时间),然后提示重启。
只想装、之后自己配权限:
openclaw plugins install @jeik/usage-counter --force
--force即为覆盖更新,升级时同样用它,无需先卸载。
方式二:本地构建产物(开发 / 离线)
npm install && npm run build && npm pack # → jeik-usage-counter-1.0.0.tgz
openclaw plugins install ./jeik-usage-counter-1.0.0.tgz --force之后
openclaw gateway restart必须的配置(否则计数不生效)
before_agent_run 是对话敏感钩子,非内置插件必须在 openclaw 主配置里显式放行:
openclaw config set plugins.entries.usage-counter.hooks.allowConversationAccess true --strict-json用上面的安装向导会自动帮你设置这一项。 排错时若日志出现
... blocked because non-bundled plugins must set ... allowConversationAccess=true,就是这里没配。
开发
npm install
npm run build # esbuild → dist/index.js
npm pack # → jeik-usage-counter-1.0.0.tgz源码:
- index.ts —— 钩子注册(记录)+ 查询工具注册
- src/db.ts —— SQLite 读写
- src/tools.ts —— 查询 / 排行 / 导出工具
