@yeaft/webchat-agent 0.0.149 → 0.0.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/crew.js +5 -2
  2. package/package.json +1 -1
package/crew.js CHANGED
@@ -978,6 +978,7 @@ async function createRoleQuery(session, roleName) {
978
978
  accumulatedText: '',
979
979
  turnActive: false,
980
980
  claudeSessionId: savedSessionId,
981
+ lastCostUsd: 0,
981
982
  lastInputTokens: 0,
982
983
  lastOutputTokens: 0
983
984
  };
@@ -1244,9 +1245,11 @@ async function processRoleOutput(session, roleName, roleQuery, roleState) {
1244
1245
  // ★ 修复2: 反向搜索该角色最后一条 streaming 消息并结束
1245
1246
  endRoleStreaming(session, roleName);
1246
1247
 
1247
- // 更新费用(total_cost_usd 是全局进程级累计值,直接赋值)
1248
+ // 更新费用(差值计算:每个角色独立进程,total_cost_usd 是该角色的累计值)
1248
1249
  if (message.total_cost_usd != null) {
1249
- session.costUsd = message.total_cost_usd;
1250
+ const costDelta = message.total_cost_usd - roleState.lastCostUsd;
1251
+ if (costDelta > 0) session.costUsd += costDelta;
1252
+ roleState.lastCostUsd = message.total_cost_usd;
1250
1253
  }
1251
1254
  // 更新 token 用量(差值计算:usage 是 query 实例级累计值)
1252
1255
  if (message.usage) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.149",
3
+ "version": "0.0.151",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",