@synergenius/flow-weaver 0.26.1 → 0.26.3
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/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/streaming.js +3 -0
- package/dist/agent/types.d.ts +12 -0
- package/dist/agent/types.js +8 -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
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Built-in providers: Anthropic API, Claude CLI, OpenAI-compatible (GPT-4o, Groq, Ollama, etc).
|
|
6
6
|
*/
|
|
7
7
|
export type { SplitPrompt, TurnEndContext, TurnEndResult, StreamEvent, AgentMessage, AgentProvider, ToolDefinition, ToolExecutor, ToolEvent, McpBridge, AgentLoopOptions, AgentLoopResult, StreamOptions, SpawnFn, ClaudeCliProviderOptions, CliSessionOptions, Logger, } from './types.js';
|
|
8
|
-
export { joinSplitPrompt } from './types.js';
|
|
8
|
+
export { joinSplitPrompt, stripMcpToolPrefix } from './types.js';
|
|
9
9
|
export { runAgentLoop } from './agent-loop.js';
|
|
10
10
|
export { AnthropicProvider, createAnthropicProvider } from './providers/anthropic.js';
|
|
11
11
|
export type { AnthropicProviderOptions } from './providers/anthropic.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Built-in providers: Anthropic API, Claude CLI, OpenAI-compatible (GPT-4o, Groq, Ollama, etc).
|
|
6
6
|
*/
|
|
7
7
|
// Prompt utilities
|
|
8
|
-
export { joinSplitPrompt } from './types.js';
|
|
8
|
+
export { joinSplitPrompt, stripMcpToolPrefix } from './types.js';
|
|
9
9
|
// Agent loop
|
|
10
10
|
export { runAgentLoop } from './agent-loop.js';
|
|
11
11
|
// Providers
|
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';
|
|
@@ -82,6 +85,12 @@ export interface SplitPrompt {
|
|
|
82
85
|
}
|
|
83
86
|
/** Convert a SplitPrompt to a single string (for providers that don't support blocks). */
|
|
84
87
|
export declare function joinSplitPrompt(prompt: SplitPrompt): string;
|
|
88
|
+
/**
|
|
89
|
+
* Strip MCP server prefix from a tool name.
|
|
90
|
+
* The CLI registers MCP tools as mcp__<server>__<tool> but internal code
|
|
91
|
+
* uses unprefixed names. Call this before any tool name comparison.
|
|
92
|
+
*/
|
|
93
|
+
export declare function stripMcpToolPrefix(name: string): string;
|
|
85
94
|
export interface StreamOptions {
|
|
86
95
|
systemPrompt?: SplitPrompt;
|
|
87
96
|
model?: string;
|
|
@@ -150,6 +159,9 @@ export interface AgentLoopResult {
|
|
|
150
159
|
usage: {
|
|
151
160
|
promptTokens: number;
|
|
152
161
|
completionTokens: number;
|
|
162
|
+
cacheReadTokens: number;
|
|
163
|
+
cacheCreationTokens: number;
|
|
164
|
+
costUsd: number;
|
|
153
165
|
};
|
|
154
166
|
}
|
|
155
167
|
export type SpawnFn = (command: string, args: string[], options: {
|
package/dist/agent/types.js
CHANGED
|
@@ -9,4 +9,12 @@ export function joinSplitPrompt(prompt) {
|
|
|
9
9
|
return prompt.prefix;
|
|
10
10
|
return prompt.prefix + '\n\n' + prompt.suffix;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Strip MCP server prefix from a tool name.
|
|
14
|
+
* The CLI registers MCP tools as mcp__<server>__<tool> but internal code
|
|
15
|
+
* uses unprefixed names. Call this before any tool name comparison.
|
|
16
|
+
*/
|
|
17
|
+
export function stripMcpToolPrefix(name) {
|
|
18
|
+
return name.replace(/^mcp__[a-zA-Z0-9_-]+__/, '');
|
|
19
|
+
}
|
|
12
20
|
//# sourceMappingURL=types.js.map
|
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.3";
|
|
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.3" : "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.3";
|
|
2
2
|
//# sourceMappingURL=generated-version.d.ts.map
|
package/package.json
CHANGED