@synergenius/flow-weaver 0.24.2 → 0.24.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.
@@ -79,6 +79,17 @@ export async function runAgentLoop(provider, tools, executor, messages, options)
79
79
  }
80
80
  // If no tool calls, we're done
81
81
  if (finishReason !== 'tool_calls' || collectedToolCalls.length === 0) {
82
+ // Final turn hook
83
+ if (options?.onTurnEnd) {
84
+ await options.onTurnEnd({
85
+ iteration,
86
+ maxIterations,
87
+ messages: conversation,
88
+ toolCallCount,
89
+ usage: { promptTokens: totalPromptTokens, completionTokens: totalCompletionTokens },
90
+ isFinalTurn: true,
91
+ });
92
+ }
82
93
  return buildResult(finishReason !== 'error', text || 'Task completed', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
83
94
  }
84
95
  // Execute tool calls and add results to conversation
@@ -106,6 +117,23 @@ export async function runAgentLoop(provider, tools, executor, messages, options)
106
117
  toolCallId: tc.id,
107
118
  });
108
119
  }
120
+ // Between-turns hook — runs after tool execution, before next LLM call
121
+ if (options?.onTurnEnd) {
122
+ const turnResult = await options.onTurnEnd({
123
+ iteration,
124
+ maxIterations,
125
+ messages: conversation,
126
+ toolCallCount,
127
+ usage: { promptTokens: totalPromptTokens, completionTokens: totalCompletionTokens },
128
+ isFinalTurn: false,
129
+ });
130
+ if (turnResult?.continue === false) {
131
+ return buildResult(true, turnResult.injectMessage ?? 'Stopped by hook', conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
132
+ }
133
+ if (turnResult?.injectMessage) {
134
+ conversation.push({ role: 'user', content: turnResult.injectMessage });
135
+ }
136
+ }
109
137
  }
110
138
  return buildResult(false, `Reached max iterations (${maxIterations})`, conversation, toolCallCount, totalPromptTokens, totalCompletionTokens);
111
139
  }
@@ -4,7 +4,7 @@
4
4
  * Provider-agnostic agent loop with MCP bridge for tool execution.
5
5
  * Built-in providers: Anthropic API, Claude CLI, OpenAI-compatible (GPT-4o, Groq, Ollama, etc).
6
6
  */
7
- export type { SplitPrompt, StreamEvent, AgentMessage, AgentProvider, ToolDefinition, ToolExecutor, ToolEvent, McpBridge, AgentLoopOptions, AgentLoopResult, StreamOptions, SpawnFn, ClaudeCliProviderOptions, CliSessionOptions, Logger, } from './types.js';
7
+ export type { SplitPrompt, TurnEndContext, TurnEndResult, StreamEvent, AgentMessage, AgentProvider, ToolDefinition, ToolExecutor, ToolEvent, McpBridge, AgentLoopOptions, AgentLoopResult, StreamOptions, SpawnFn, ClaudeCliProviderOptions, CliSessionOptions, Logger, } from './types.js';
8
8
  export { joinSplitPrompt } from './types.js';
9
9
  export { runAgentLoop } from './agent-loop.js';
10
10
  export { AnthropicProvider, createAnthropicProvider } from './providers/anthropic.js';
@@ -105,6 +105,31 @@ export interface McpBridge {
105
105
  /** Tear down the socket server and remove temp files */
106
106
  cleanup: () => void;
107
107
  }
108
+ /** Context passed to the onTurnEnd callback after each agent loop iteration. */
109
+ export interface TurnEndContext {
110
+ /** Current iteration number (0-based). */
111
+ iteration: number;
112
+ /** Maximum iterations configured. */
113
+ maxIterations: number;
114
+ /** Full conversation history up to this point. */
115
+ messages: ReadonlyArray<AgentMessage>;
116
+ /** Total tool calls executed so far. */
117
+ toolCallCount: number;
118
+ /** Cumulative token usage. */
119
+ usage: {
120
+ promptTokens: number;
121
+ completionTokens: number;
122
+ };
123
+ /** true if the model stopped calling tools (final turn). */
124
+ isFinalTurn: boolean;
125
+ }
126
+ /** Result from the onTurnEnd callback. */
127
+ export interface TurnEndResult {
128
+ /** If false, abort the agent loop early. */
129
+ continue?: boolean;
130
+ /** Optional message to inject into the conversation (steering nudge). */
131
+ injectMessage?: string;
132
+ }
108
133
  export interface AgentLoopOptions {
109
134
  systemPrompt?: SplitPrompt;
110
135
  maxIterations?: number;
@@ -113,6 +138,8 @@ export interface AgentLoopOptions {
113
138
  signal?: AbortSignal;
114
139
  onToolEvent?: (event: ToolEvent) => void;
115
140
  onStreamEvent?: (event: StreamEvent) => void;
141
+ /** Called after each agent loop iteration (between turns and on final turn). */
142
+ onTurnEnd?: (context: TurnEndContext) => Promise<TurnEndResult | void>;
116
143
  logger?: Logger;
117
144
  }
118
145
  export interface AgentLoopResult {
@@ -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.24.2";
9889
+ VERSION = "0.24.3";
9890
9890
  }
9891
9891
  });
9892
9892
 
@@ -95960,7 +95960,7 @@ function parseIntStrict(value) {
95960
95960
  // src/cli/index.ts
95961
95961
  init_logger();
95962
95962
  init_error_utils();
95963
- var version2 = true ? "0.24.2" : "0.0.0-dev";
95963
+ var version2 = true ? "0.24.3" : "0.0.0-dev";
95964
95964
  var program2 = new Command();
95965
95965
  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", () => {
95966
95966
  logger.banner(version2);
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.24.2";
1
+ export declare const VERSION = "0.24.3";
2
2
  //# sourceMappingURL=generated-version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Auto-generated by scripts/generate-version.ts — do not edit manually
2
- export const VERSION = '0.24.2';
2
+ export const VERSION = '0.24.3';
3
3
  //# sourceMappingURL=generated-version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synergenius/flow-weaver",
3
- "version": "0.24.2",
3
+ "version": "0.24.3",
4
4
  "description": "Deterministic workflow compiler for AI agents. Compiles to standalone TypeScript, no runtime dependencies.",
5
5
  "private": false,
6
6
  "type": "module",