feat: agent-claude-code reports real $usage from stream-json output
CI / check (pull_request) Successful in 1m40s
CI / check (pull_request) Successful in 1m40s
- Map parsed numTurns, inputTokens, outputTokens, durationMs to Usage type - Add @united-workforce/protocol dependency + tsconfig reference - 747 tests pass Fixes #77 Refs #68
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ocas/core": "^0.3.0",
|
"@ocas/core": "^0.3.0",
|
||||||
|
"@united-workforce/protocol": "workspace:^",
|
||||||
"@united-workforce/util": "workspace:^",
|
"@united-workforce/util": "workspace:^",
|
||||||
"@united-workforce/util-agent": "workspace:^"
|
"@united-workforce/util-agent": "workspace:^"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { spawn } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
import type { Store } from "@ocas/core";
|
import type { Store } from "@ocas/core";
|
||||||
|
import type { Usage } from "@united-workforce/protocol";
|
||||||
import { createLogger } from "@united-workforce/util";
|
import { createLogger } from "@united-workforce/util";
|
||||||
import {
|
import {
|
||||||
type AgentContext,
|
type AgentContext,
|
||||||
@@ -145,7 +146,14 @@ async function processClaudeOutput(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { output, detailHash, sessionId, assembledPrompt, usage: null };
|
const usage: Usage = {
|
||||||
|
turns: parsed.numTurns,
|
||||||
|
inputTokens: parsed.usage.inputTokens,
|
||||||
|
outputTokens: parsed.usage.outputTokens,
|
||||||
|
duration: Math.round(parsed.durationMs / 1000),
|
||||||
|
};
|
||||||
|
|
||||||
|
return { output, detailHash, sessionId, assembledPrompt, usage };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Truly unparseable output - provide enhanced error message
|
// Truly unparseable output - provide enhanced error message
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": { "rootDir": "src", "outDir": "dist" },
|
"compilerOptions": { "rootDir": "src", "outDir": "dist" },
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"references": [{ "path": "../util-agent" }]
|
"references": [{ "path": "../protocol" }, { "path": "../util-agent" }]
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+3
@@ -63,6 +63,9 @@ importers:
|
|||||||
'@ocas/core':
|
'@ocas/core':
|
||||||
specifier: ^0.3.0
|
specifier: ^0.3.0
|
||||||
version: 0.3.0
|
version: 0.3.0
|
||||||
|
'@united-workforce/protocol':
|
||||||
|
specifier: workspace:^
|
||||||
|
version: link:../protocol
|
||||||
'@united-workforce/util':
|
'@united-workforce/util':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../util
|
version: link:../util
|
||||||
|
|||||||
Reference in New Issue
Block a user