@synergenius/flow-weaver 0.26.2 → 0.26.4
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.
- package/dist/agent/agent-loop.js +13 -6
- package/dist/agent/cli-session.js +7 -6
- package/dist/agent/streaming.js +3 -0
- package/dist/agent/types.d.ts +6 -0
- package/dist/cli/flow-weaver.mjs +2 -2
- package/dist/generated-version.d.ts +1 -1
- package/dist/generated-version.js +1 -1
- package/package.json +1 -1
package/dist/agent/agent-loop.js
CHANGED
|
@@ -15,10 +15,13 @@ export async function runAgentLoop(provider, tools, executor, messages, options)
|
|
|
15
15
|
const conversation = [...messages];
|
|
16
16
|
let totalPromptTokens = 0;
|
|
17
17
|
let totalCompletionTokens = 0;
|
|
18
|
+
let totalCacheReadTokens = 0;
|
|
19
|
+
let totalCacheCreationTokens = 0;
|
|
20
|
+
let totalCostUsd = 0;
|
|
18
21
|
let toolCallCount = 0;
|
|
19
22
|
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
|
20
23
|
if (signal?.aborted) {
|
|
21
|
-
return buildResult(false, 'Aborted', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
|
|
24
|
+
return buildResult(false, 'Aborted', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens, totalCacheReadTokens, totalCacheCreationTokens, totalCostUsd);
|
|
22
25
|
}
|
|
23
26
|
// Stream from provider
|
|
24
27
|
let text = '';
|
|
@@ -60,6 +63,10 @@ export async function runAgentLoop(provider, tools, executor, messages, options)
|
|
|
60
63
|
case 'usage':
|
|
61
64
|
totalPromptTokens += event.promptTokens;
|
|
62
65
|
totalCompletionTokens += event.completionTokens;
|
|
66
|
+
totalCacheReadTokens += event.cacheReadTokens ?? 0;
|
|
67
|
+
totalCacheCreationTokens += event.cacheCreationTokens ?? 0;
|
|
68
|
+
if (event.costUsd != null)
|
|
69
|
+
totalCostUsd = event.costUsd; // last value = cumulative from CLI
|
|
63
70
|
break;
|
|
64
71
|
case 'message_stop':
|
|
65
72
|
finishReason = event.finishReason;
|
|
@@ -90,7 +97,7 @@ export async function runAgentLoop(provider, tools, executor, messages, options)
|
|
|
90
97
|
isFinalTurn: true,
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
|
-
return buildResult(finishReason !== 'error', text || 'Task completed', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
|
|
100
|
+
return buildResult(finishReason !== 'error', text || 'Task completed', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens, totalCacheReadTokens, totalCacheCreationTokens, totalCostUsd);
|
|
94
101
|
}
|
|
95
102
|
// Execute tool calls and add results to conversation
|
|
96
103
|
for (const tc of collectedToolCalls) {
|
|
@@ -128,22 +135,22 @@ export async function runAgentLoop(provider, tools, executor, messages, options)
|
|
|
128
135
|
isFinalTurn: false,
|
|
129
136
|
});
|
|
130
137
|
if (turnResult?.continue === false) {
|
|
131
|
-
return buildResult(true, turnResult.injectMessage ?? 'Stopped by hook', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
|
|
138
|
+
return buildResult(true, turnResult.injectMessage ?? 'Stopped by hook', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens, totalCacheReadTokens, totalCacheCreationTokens, totalCostUsd);
|
|
132
139
|
}
|
|
133
140
|
if (turnResult?.injectMessage) {
|
|
134
141
|
conversation.push({ role: 'user', content: turnResult.injectMessage });
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
|
-
return buildResult(false, `Reached max iterations (${maxIterations})`, conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
|
|
145
|
+
return buildResult(false, `Reached max iterations (${maxIterations})`, conversation, toolCallCount, totalPromptTokens, totalCompletionTokens, totalCacheReadTokens, totalCacheCreationTokens, totalCostUsd);
|
|
139
146
|
}
|
|
140
|
-
function buildResult(success, summary, messages, toolCallCount, promptTokens, completionTokens) {
|
|
147
|
+
function buildResult(success, summary, messages, toolCallCount, promptTokens, completionTokens, cacheReadTokens = 0, cacheCreationTokens = 0, costUsd = 0) {
|
|
141
148
|
return {
|
|
142
149
|
success,
|
|
143
150
|
summary,
|
|
144
151
|
messages,
|
|
145
152
|
toolCallCount,
|
|
146
|
-
usage: { promptTokens, completionTokens },
|
|
153
|
+
usage: { promptTokens, completionTokens, cacheReadTokens, cacheCreationTokens, costUsd },
|
|
147
154
|
};
|
|
148
155
|
}
|
|
149
156
|
//# sourceMappingURL=agent-loop.js.map
|
|
@@ -173,15 +173,16 @@ export class CliSession {
|
|
|
173
173
|
}) + '\n';
|
|
174
174
|
// Track whether this turn saw a 'result' event (definitive turn end)
|
|
175
175
|
let sawResult = false;
|
|
176
|
-
// Wrap pushEvent to
|
|
176
|
+
// Wrap pushEvent to suppress intermediate message_stop events.
|
|
177
|
+
// The CLI emits message_stop for each API turn, but the session's turn
|
|
178
|
+
// boundary is the `result` event. Intermediate message_stop events would
|
|
179
|
+
// cause runAgentLoop to exit early (thinking the model stopped), missing
|
|
180
|
+
// later events including the result's usage with total_cost_usd.
|
|
177
181
|
const originalPush = this.pushEvent.bind(this);
|
|
178
182
|
this.parser = new StreamJsonParser((event) => {
|
|
179
|
-
// The result event emits message_stop — but in session mode,
|
|
180
|
-
// we need to detect it as the turn boundary
|
|
181
183
|
if (event.type === 'message_stop' && !sawResult) {
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
originalPush(event);
|
|
184
|
+
// Suppress — not the real turn end. The result event will emit
|
|
185
|
+
// the final message_stop after all usage data is captured.
|
|
185
186
|
return;
|
|
186
187
|
}
|
|
187
188
|
originalPush(event);
|
package/dist/agent/streaming.js
CHANGED
|
@@ -167,6 +167,9 @@ export class StreamJsonParser {
|
|
|
167
167
|
type: 'usage',
|
|
168
168
|
promptTokens: usage.input_tokens ?? 0,
|
|
169
169
|
completionTokens: usage.output_tokens ?? 0,
|
|
170
|
+
cacheReadTokens: usage.cache_read_input_tokens ?? undefined,
|
|
171
|
+
cacheCreationTokens: usage.cache_creation_input_tokens ?? undefined,
|
|
172
|
+
costUsd: typeof event.total_cost_usd === 'number' ? event.total_cost_usd : undefined,
|
|
170
173
|
});
|
|
171
174
|
}
|
|
172
175
|
this.pushEvent({ type: 'message_stop', finishReason: 'stop' });
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ export type StreamEvent = {
|
|
|
34
34
|
type: 'usage';
|
|
35
35
|
promptTokens: number;
|
|
36
36
|
completionTokens: number;
|
|
37
|
+
cacheReadTokens?: number;
|
|
38
|
+
cacheCreationTokens?: number;
|
|
39
|
+
costUsd?: number;
|
|
37
40
|
};
|
|
38
41
|
export interface AgentMessage {
|
|
39
42
|
role: 'user' | 'assistant' | 'tool';
|
|
@@ -156,6 +159,9 @@ export interface AgentLoopResult {
|
|
|
156
159
|
usage: {
|
|
157
160
|
promptTokens: number;
|
|
158
161
|
completionTokens: number;
|
|
162
|
+
cacheReadTokens: number;
|
|
163
|
+
cacheCreationTokens: number;
|
|
164
|
+
costUsd: number;
|
|
159
165
|
};
|
|
160
166
|
}
|
|
161
167
|
export type SpawnFn = (command: string, args: string[], options: {
|
package/dist/cli/flow-weaver.mjs
CHANGED
|
@@ -9886,7 +9886,7 @@ var VERSION;
|
|
|
9886
9886
|
var init_generated_version = __esm({
|
|
9887
9887
|
"src/generated-version.ts"() {
|
|
9888
9888
|
"use strict";
|
|
9889
|
-
VERSION = "0.26.
|
|
9889
|
+
VERSION = "0.26.4";
|
|
9890
9890
|
}
|
|
9891
9891
|
});
|
|
9892
9892
|
|
|
@@ -95973,7 +95973,7 @@ function parseIntStrict(value) {
|
|
|
95973
95973
|
// src/cli/index.ts
|
|
95974
95974
|
init_logger();
|
|
95975
95975
|
init_error_utils();
|
|
95976
|
-
var version2 = true ? "0.26.
|
|
95976
|
+
var version2 = true ? "0.26.4" : "0.0.0-dev";
|
|
95977
95977
|
var program2 = new Command();
|
|
95978
95978
|
program2.name("fw").description("Flow Weaver Annotations - Compile and validate workflow files").option("-v, --version", "Output the current version").option("--no-color", "Disable colors").option("--color", "Force colors").on("option:version", () => {
|
|
95979
95979
|
logger.banner(version2);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.26.
|
|
1
|
+
export declare const VERSION = "0.26.4";
|
|
2
2
|
//# sourceMappingURL=generated-version.d.ts.map
|
package/package.json
CHANGED