- Add Usage type to protocol (turns, inputTokens, outputTokens, duration) - Add usage to StepRecord, StepNodePayload, StepEntry, STEP_NODE_SCHEMA - Thread usage through util-agent extract pipeline (writeStepNode → persistStep → createAgent) - All adapters return usage: null as placeholder (mock, hermes, claude-code, builtin) - 746 tests pass, no breaking changes (usage not in schema required array) Fixes #74 Refs #68
This commit is contained in:
@@ -27,6 +27,7 @@ describe("Protocol types for thread/edge location", () => {
|
||||
completedAtMs: Date.now() + 1000,
|
||||
assembledPrompt: null,
|
||||
cwd: "/home/user/project",
|
||||
usage: null,
|
||||
};
|
||||
|
||||
expect(record.cwd).toBe("/home/user/project");
|
||||
|
||||
@@ -44,6 +44,7 @@ export type {
|
||||
ThreadStatus,
|
||||
ThreadStepsOutput,
|
||||
ThreadsIndex,
|
||||
Usage,
|
||||
WorkflowConfig,
|
||||
WorkflowName,
|
||||
WorkflowPayload,
|
||||
|
||||
@@ -91,6 +91,22 @@ export const STEP_NODE_SCHEMA: JSONSchema = {
|
||||
assembledPrompt: {
|
||||
anyOf: [{ type: "string", format: "ocas_ref" }, { type: "null" }],
|
||||
},
|
||||
usage: {
|
||||
anyOf: [
|
||||
{
|
||||
type: "object",
|
||||
required: ["turns", "inputTokens", "outputTokens", "duration"],
|
||||
properties: {
|
||||
turns: { type: "integer" },
|
||||
inputTokens: { type: "integer" },
|
||||
outputTokens: { type: "integer" },
|
||||
duration: { type: "number" },
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
{ type: "null" },
|
||||
],
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
};
|
||||
|
||||
@@ -22,6 +22,17 @@ export type StepRecord = {
|
||||
cwd: string;
|
||||
/** CAS ref to the fully assembled prompt sent to the agent. null for legacy steps. */
|
||||
assembledPrompt: CasRef | null;
|
||||
/** Token usage statistics reported by the agent adapter. null for legacy steps. */
|
||||
usage: Usage | null;
|
||||
};
|
||||
|
||||
/** Token usage statistics reported by agent adapters. */
|
||||
export type Usage = {
|
||||
turns: number;
|
||||
inputTokens: number;
|
||||
outputTokens: number;
|
||||
/** Wall-clock duration in seconds. */
|
||||
duration: number;
|
||||
};
|
||||
|
||||
// ── 4.2 Workflow 定义 ───────────────────────────────────────────────
|
||||
@@ -131,6 +142,7 @@ export type StepEntry = {
|
||||
agent: string;
|
||||
timestamp: number;
|
||||
durationMs: number;
|
||||
usage: Usage | null;
|
||||
};
|
||||
|
||||
/** uwf thread steps — start entry */
|
||||
|
||||
Reference in New Issue
Block a user