zeitlich 0.2.51 → 0.2.53

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.
Files changed (45) hide show
  1. package/dist/adapters/thread/anthropic/index.d.cts +5 -5
  2. package/dist/adapters/thread/anthropic/index.d.ts +5 -5
  3. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  4. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  5. package/dist/adapters/thread/google-genai/index.d.cts +3 -3
  6. package/dist/adapters/thread/google-genai/index.d.ts +3 -3
  7. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
  8. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
  9. package/dist/adapters/thread/langchain/index.d.cts +5 -5
  10. package/dist/adapters/thread/langchain/index.d.ts +5 -5
  11. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  12. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  13. package/dist/{cold-store-DyHodfAB.d.ts → cold-store-BbvJLhXJ.d.ts} +1 -1
  14. package/dist/{cold-store-YOx9nmgR.d.cts → cold-store-Ki_U0jyd.d.cts} +1 -1
  15. package/dist/index.cjs +38 -3
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +8 -8
  18. package/dist/index.d.ts +8 -8
  19. package/dist/index.js +38 -3
  20. package/dist/index.js.map +1 -1
  21. package/dist/{proxy-CmiTP4pp.d.ts → proxy-CwniAm8W.d.ts} +1 -1
  22. package/dist/{proxy-2htgGQrc.d.cts → proxy-wsNrEh2u.d.cts} +1 -1
  23. package/dist/{thread-manager-CcvltOuq.d.ts → thread-manager-D1zfZnxi.d.ts} +2 -2
  24. package/dist/{thread-manager-DHAbncHX.d.ts → thread-manager-DCXkMqHH.d.ts} +2 -2
  25. package/dist/{thread-manager-BQAbrYXH.d.cts → thread-manager-DW7FqMdN.d.cts} +2 -2
  26. package/dist/{thread-manager-BJ5pz5Cx.d.cts → thread-manager-DhvA5oDL.d.cts} +2 -2
  27. package/dist/{types-DiI7mZhI.d.ts → types-DQQKF5FQ.d.ts} +24 -2
  28. package/dist/{types-BjdqxKYp.d.cts → types-DpHBKA8c.d.cts} +24 -2
  29. package/dist/{types-N_LTWe4b.d.cts → types-tJ9Or7u_.d.cts} +1 -1
  30. package/dist/{types-DEbkLA06.d.ts → types-ziu6HZPh.d.ts} +1 -1
  31. package/dist/{workflow-DBjPOKBr.d.ts → workflow-BeMiPEq4.d.ts} +2 -1
  32. package/dist/{workflow-CcgD6EUB.d.cts → workflow-CNTNwEnj.d.cts} +2 -1
  33. package/dist/workflow.cjs +38 -3
  34. package/dist/workflow.cjs.map +1 -1
  35. package/dist/workflow.d.cts +2 -2
  36. package/dist/workflow.d.ts +2 -2
  37. package/dist/workflow.js +38 -3
  38. package/dist/workflow.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/lib/hooks/index.ts +2 -0
  41. package/src/lib/hooks/types.ts +26 -1
  42. package/src/lib/observability/hooks.ts +17 -2
  43. package/src/lib/session/session.ts +31 -3
  44. package/src/lib/state/types.ts +9 -11
  45. package/src/workflow.ts +2 -0
@@ -1,5 +1,5 @@
1
1
  import { ActivityOptions, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-DiI7mZhI.js';
2
+ import { T as ThreadOps } from './types-DQQKF5FQ.js';
3
3
 
4
4
  /**
5
5
  * Shared proxy helper for thread operations.
@@ -1,5 +1,5 @@
1
1
  import { ActivityOptions, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-BjdqxKYp.cjs';
2
+ import { T as ThreadOps } from './types-DpHBKA8c.cjs';
3
3
 
4
4
  /**
5
5
  * Shared proxy helper for thread operations.
@@ -1,7 +1,7 @@
1
1
  import { RedisClientType } from 'redis';
2
- import { J as JsonValue } from './types-DiI7mZhI.js';
2
+ import { J as JsonValue } from './types-DQQKF5FQ.js';
3
3
  import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DEbkLA06.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-ziu6HZPh.js';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -1,7 +1,7 @@
1
1
  import { RedisClientType } from 'redis';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-DiI7mZhI.js';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-DEbkLA06.js';
3
+ import { J as JsonValue } from './types-DQQKF5FQ.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-ziu6HZPh.js';
5
5
 
6
6
  /** SDK-native content type for Anthropic human messages */
7
7
  type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
@@ -1,7 +1,7 @@
1
1
  import { RedisClientType } from 'redis';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-BjdqxKYp.cjs';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-N_LTWe4b.cjs';
3
+ import { J as JsonValue } from './types-DpHBKA8c.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-tJ9Or7u_.cjs';
5
5
 
6
6
  /** SDK-native content type for Anthropic human messages */
7
7
  type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
@@ -1,7 +1,7 @@
1
1
  import { RedisClientType } from 'redis';
2
- import { J as JsonValue } from './types-BjdqxKYp.cjs';
2
+ import { J as JsonValue } from './types-DpHBKA8c.cjs';
3
3
  import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-N_LTWe4b.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-tJ9Or7u_.cjs';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -21,8 +21,9 @@ type JsonValue = JsonPrimitive | JsonValue[] | {
21
21
  * Rejects: functions, symbols, undefined, class instances with methods
22
22
  */
23
23
  type JsonSerializable<T> = {
24
- [K in keyof T]: T[K] extends JsonValue ? T[K] : T[K] extends JsonPrimitive ? T[K] : T[K] extends (infer U)[] ? U extends JsonValue ? T[K] : JsonSerializable<U>[] : T[K] extends object ? JsonSerializable<T[K]> : never;
24
+ [K in keyof T]: JsonSerializableValue<T[K]>;
25
25
  };
26
+ type JsonSerializableValue<V> = V extends JsonValue ? V : V extends (infer U)[] ? JsonSerializableValue<U>[] : V extends object ? JsonSerializable<V> : never;
26
27
  /**
27
28
  * Full state type combining base state with custom state
28
29
  */
@@ -877,12 +878,31 @@ interface SessionEndHookContext {
877
878
  agentName: string;
878
879
  exitReason: SessionExitReason;
879
880
  turns: number;
881
+ usage: TokenUsage;
880
882
  metadata: Record<string, unknown>;
881
883
  }
882
884
  /**
883
885
  * SessionEnd hook - called when session ends
884
886
  */
885
887
  type SessionEndHook = (ctx: SessionEndHookContext) => void | Promise<void>;
888
+ /**
889
+ * Context for TurnComplete hook - called after each agent turn commits
890
+ * (i.e. once per model invocation, excluding rewound turns)
891
+ */
892
+ interface TurnCompleteHookContext {
893
+ threadId: string;
894
+ agentName: string;
895
+ /** 1-based turn number that just completed */
896
+ turn: number;
897
+ /** Number of tool calls the model requested this turn */
898
+ toolCallCount: number;
899
+ /** Token usage reported by the model for this turn, if available */
900
+ usage?: TokenUsage;
901
+ }
902
+ /**
903
+ * TurnComplete hook - called after each agent turn commits
904
+ */
905
+ type TurnCompleteHook = (ctx: TurnCompleteHookContext) => void | Promise<void>;
886
906
  /**
887
907
  * Context for PreHumanMessageAppend hook - called before each human message is appended to the thread
888
908
  */
@@ -919,6 +939,8 @@ interface Hooks<T extends ToolMap, TResult = unknown, TContent = unknown> extend
919
939
  onSessionStart?: SessionStartHook;
920
940
  /** Called when session ends */
921
941
  onSessionEnd?: SessionEndHook;
942
+ /** Called after each agent turn commits (excludes rewound turns) */
943
+ onTurnComplete?: TurnCompleteHook;
922
944
  }
923
945
 
924
946
  /**
@@ -1866,4 +1888,4 @@ interface ZeitlichSession<M = unknown, HasSandbox extends boolean = boolean> {
1866
1888
  }): Promise<SessionResult<M, T, HasSandbox>>;
1867
1889
  }
1868
1890
 
1869
- export { type SandboxShutdown as $, type ActivityToolHandler as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvoker as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type PrefixedThreadOps as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, VirtualFileSystem as aA, type VirtualFileTree as aB, type VirtualFsOps as aC, type VirtualFsState as aD, type WorkflowTask as aE, type ZeitlichSession as aF, isTerminalStatus as aG, type ToolRouterOptions as aH, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type ToolHandlerResponse as b, type ModelInvokerConfig as c, type AgentResponse as d, type RunAgentConfig as e, type ToolResultConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
1891
+ export { type SandboxShutdown as $, type ActivityToolHandler as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvoker as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type PrefixedThreadOps as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, type TurnCompleteHook as aA, type TurnCompleteHookContext as aB, VirtualFileSystem as aC, type VirtualFileTree as aD, type VirtualFsOps as aE, type VirtualFsState as aF, type WorkflowTask as aG, type ZeitlichSession as aH, isTerminalStatus as aI, type ToolRouterOptions as aJ, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type ToolHandlerResponse as b, type ModelInvokerConfig as c, type AgentResponse as d, type RunAgentConfig as e, type ToolResultConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
@@ -21,8 +21,9 @@ type JsonValue = JsonPrimitive | JsonValue[] | {
21
21
  * Rejects: functions, symbols, undefined, class instances with methods
22
22
  */
23
23
  type JsonSerializable<T> = {
24
- [K in keyof T]: T[K] extends JsonValue ? T[K] : T[K] extends JsonPrimitive ? T[K] : T[K] extends (infer U)[] ? U extends JsonValue ? T[K] : JsonSerializable<U>[] : T[K] extends object ? JsonSerializable<T[K]> : never;
24
+ [K in keyof T]: JsonSerializableValue<T[K]>;
25
25
  };
26
+ type JsonSerializableValue<V> = V extends JsonValue ? V : V extends (infer U)[] ? JsonSerializableValue<U>[] : V extends object ? JsonSerializable<V> : never;
26
27
  /**
27
28
  * Full state type combining base state with custom state
28
29
  */
@@ -877,12 +878,31 @@ interface SessionEndHookContext {
877
878
  agentName: string;
878
879
  exitReason: SessionExitReason;
879
880
  turns: number;
881
+ usage: TokenUsage;
880
882
  metadata: Record<string, unknown>;
881
883
  }
882
884
  /**
883
885
  * SessionEnd hook - called when session ends
884
886
  */
885
887
  type SessionEndHook = (ctx: SessionEndHookContext) => void | Promise<void>;
888
+ /**
889
+ * Context for TurnComplete hook - called after each agent turn commits
890
+ * (i.e. once per model invocation, excluding rewound turns)
891
+ */
892
+ interface TurnCompleteHookContext {
893
+ threadId: string;
894
+ agentName: string;
895
+ /** 1-based turn number that just completed */
896
+ turn: number;
897
+ /** Number of tool calls the model requested this turn */
898
+ toolCallCount: number;
899
+ /** Token usage reported by the model for this turn, if available */
900
+ usage?: TokenUsage;
901
+ }
902
+ /**
903
+ * TurnComplete hook - called after each agent turn commits
904
+ */
905
+ type TurnCompleteHook = (ctx: TurnCompleteHookContext) => void | Promise<void>;
886
906
  /**
887
907
  * Context for PreHumanMessageAppend hook - called before each human message is appended to the thread
888
908
  */
@@ -919,6 +939,8 @@ interface Hooks<T extends ToolMap, TResult = unknown, TContent = unknown> extend
919
939
  onSessionStart?: SessionStartHook;
920
940
  /** Called when session ends */
921
941
  onSessionEnd?: SessionEndHook;
942
+ /** Called after each agent turn commits (excludes rewound turns) */
943
+ onTurnComplete?: TurnCompleteHook;
922
944
  }
923
945
 
924
946
  /**
@@ -1866,4 +1888,4 @@ interface ZeitlichSession<M = unknown, HasSandbox extends boolean = boolean> {
1866
1888
  }): Promise<SessionResult<M, T, HasSandbox>>;
1867
1889
  }
1868
1890
 
1869
- export { type SandboxShutdown as $, type ActivityToolHandler as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvoker as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type PrefixedThreadOps as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, VirtualFileSystem as aA, type VirtualFileTree as aB, type VirtualFsOps as aC, type VirtualFsState as aD, type WorkflowTask as aE, type ZeitlichSession as aF, isTerminalStatus as aG, type ToolRouterOptions as aH, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type ToolHandlerResponse as b, type ModelInvokerConfig as c, type AgentResponse as d, type RunAgentConfig as e, type ToolResultConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
1891
+ export { type SandboxShutdown as $, type ActivityToolHandler as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvoker as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type PrefixedThreadOps as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, type TurnCompleteHook as aA, type TurnCompleteHookContext as aB, VirtualFileSystem as aC, type VirtualFileTree as aD, type VirtualFsOps as aE, type VirtualFsState as aF, type WorkflowTask as aG, type ZeitlichSession as aH, isTerminalStatus as aI, type ToolRouterOptions as aJ, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type ToolHandlerResponse as b, type ModelInvokerConfig as c, type AgentResponse as d, type RunAgentConfig as e, type ToolResultConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
@@ -1,5 +1,5 @@
1
1
  import { RedisClientType } from 'redis';
2
- import { J as JsonValue, P as PersistedThreadState } from './types-BjdqxKYp.cjs';
2
+ import { J as JsonValue, P as PersistedThreadState } from './types-DpHBKA8c.cjs';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: RedisClientType;
@@ -1,5 +1,5 @@
1
1
  import { RedisClientType } from 'redis';
2
- import { J as JsonValue, P as PersistedThreadState } from './types-DiI7mZhI.js';
2
+ import { J as JsonValue, P as PersistedThreadState } from './types-DQQKF5FQ.js';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: RedisClientType;
@@ -1,4 +1,4 @@
1
- import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aF as ZeitlichSession, $ as SandboxShutdown, an as TokenUsage, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aH as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, e as RunAgentConfig, d as AgentResponse, F as FileEntryMetadata, aB as VirtualFileTree, k as TreeMutation, s as FileEntry, aC as VirtualFsOps, h as SkillMetadata, i as Skill, b as ToolHandlerResponse, as as ToolHandler, aE as WorkflowTask, A as ActivityToolHandler } from './types-DiI7mZhI.js';
1
+ import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aH as ZeitlichSession, $ as SandboxShutdown, an as TokenUsage, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aJ as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, aA as TurnCompleteHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, e as RunAgentConfig, d as AgentResponse, F as FileEntryMetadata, aD as VirtualFileTree, k as TreeMutation, s as FileEntry, aE as VirtualFsOps, h as SkillMetadata, i as Skill, b as ToolHandlerResponse, as as ToolHandler, aG as WorkflowTask, A as ActivityToolHandler } from './types-DQQKF5FQ.js';
2
2
  import { g as SandboxSnapshot } from './types-D8W5TnSa.js';
3
3
  import z$1, { z } from 'zod';
4
4
  import { Duration } from '@temporalio/common';
@@ -433,6 +433,7 @@ declare function defineSubagentWorkflow<TResult extends z.ZodType, TSandboxShutd
433
433
  interface ObservabilityHooks {
434
434
  onSessionStart: SessionStartHook;
435
435
  onSessionEnd: SessionEndHook;
436
+ onTurnComplete: TurnCompleteHook;
436
437
  onPostToolUse: PostToolUseHook<any, any>;
437
438
  onPostToolUseFailure: PostToolUseFailureHook<any>;
438
439
  }
@@ -1,4 +1,4 @@
1
- import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aF as ZeitlichSession, $ as SandboxShutdown, an as TokenUsage, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aH as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, e as RunAgentConfig, d as AgentResponse, F as FileEntryMetadata, aB as VirtualFileTree, k as TreeMutation, s as FileEntry, aC as VirtualFsOps, h as SkillMetadata, i as Skill, b as ToolHandlerResponse, as as ToolHandler, aE as WorkflowTask, A as ActivityToolHandler } from './types-BjdqxKYp.cjs';
1
+ import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aH as ZeitlichSession, $ as SandboxShutdown, an as TokenUsage, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aJ as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, aA as TurnCompleteHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, e as RunAgentConfig, d as AgentResponse, F as FileEntryMetadata, aD as VirtualFileTree, k as TreeMutation, s as FileEntry, aE as VirtualFsOps, h as SkillMetadata, i as Skill, b as ToolHandlerResponse, as as ToolHandler, aG as WorkflowTask, A as ActivityToolHandler } from './types-DpHBKA8c.cjs';
2
2
  import { g as SandboxSnapshot } from './types-D8W5TnSa.cjs';
3
3
  import z$1, { z } from 'zod';
4
4
  import { Duration } from '@temporalio/common';
@@ -433,6 +433,7 @@ declare function defineSubagentWorkflow<TResult extends z.ZodType, TSandboxShutd
433
433
  interface ObservabilityHooks {
434
434
  onSessionStart: SessionStartHook;
435
435
  onSessionEnd: SessionEndHook;
436
+ onTurnComplete: TurnCompleteHook;
436
437
  onPostToolUse: PostToolUseHook<any, any>;
437
438
  onPostToolUseFailure: PostToolUseFailureHook<any>;
438
439
  }
package/dist/workflow.cjs CHANGED
@@ -15703,13 +15703,14 @@ async function createSession(config2) {
15703
15703
  plugins,
15704
15704
  parallel: processToolsInParallel
15705
15705
  });
15706
- const callSessionEnd = async (exitReason, turns) => {
15706
+ const callSessionEnd = async (exitReason, turns, usage) => {
15707
15707
  if (hooks.onSessionEnd) {
15708
15708
  await hooks.onSessionEnd({
15709
15709
  threadId,
15710
15710
  agentName,
15711
15711
  exitReason,
15712
15712
  turns,
15713
+ usage,
15713
15714
  metadata
15714
15715
  });
15715
15716
  }
@@ -15931,6 +15932,15 @@ async function createSession(config2) {
15931
15932
  ...usage && { usage }
15932
15933
  });
15933
15934
  if (!toolRouter.hasTools() || rawToolCalls.length === 0) {
15935
+ if (hooks.onTurnComplete) {
15936
+ await hooks.onTurnComplete({
15937
+ threadId,
15938
+ agentName,
15939
+ turn: currentTurn,
15940
+ toolCallCount: rawToolCalls.length,
15941
+ ...usage && { usage }
15942
+ });
15943
+ }
15934
15944
  stateManager.complete();
15935
15945
  exitReason = "completed";
15936
15946
  finalMessage = message;
@@ -15989,6 +15999,15 @@ async function createSession(config2) {
15989
15999
  continue;
15990
16000
  }
15991
16001
  assistantId = void 0;
16002
+ if (hooks.onTurnComplete) {
16003
+ await hooks.onTurnComplete({
16004
+ threadId,
16005
+ agentName,
16006
+ turn: currentTurn,
16007
+ toolCallCount: rawToolCalls.length,
16008
+ ...usage && { usage }
16009
+ });
16010
+ }
15992
16011
  }
15993
16012
  if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
15994
16013
  exitReason = "max_turns";
@@ -16034,7 +16053,14 @@ async function createSession(config2) {
16034
16053
  error: flushError instanceof Error ? flushError.message : String(flushError)
16035
16054
  });
16036
16055
  }
16037
- await callSessionEnd(exitReason, stateManager.getTurns());
16056
+ const totals = stateManager.getTotalUsage();
16057
+ await callSessionEnd(exitReason, totals.turns, {
16058
+ inputTokens: totals.totalInputTokens,
16059
+ outputTokens: totals.totalOutputTokens,
16060
+ cachedWriteTokens: totals.totalCachedWriteTokens,
16061
+ cachedReadTokens: totals.totalCachedReadTokens,
16062
+ reasonTokens: totals.totalReasonTokens
16063
+ });
16038
16064
  if (sandboxOwned && sandboxId && sandboxOps) {
16039
16065
  switch (resolvedShutdown) {
16040
16066
  case "destroy":
@@ -16449,10 +16475,19 @@ function createObservabilityHooks(agentName) {
16449
16475
  threadId: ctx.threadId,
16450
16476
  exitReason: ctx.exitReason,
16451
16477
  turns: ctx.turns,
16452
- usage: {},
16478
+ usage: ctx.usage,
16453
16479
  durationMs: Date.now() - sessionStartMs
16454
16480
  });
16455
16481
  },
16482
+ onTurnComplete: (ctx) => {
16483
+ zeitlichMetrics.turnCompleted({
16484
+ agentName,
16485
+ threadId: ctx.threadId,
16486
+ turn: ctx.turn,
16487
+ toolCallCount: ctx.toolCallCount,
16488
+ ...ctx.usage && { usage: ctx.usage }
16489
+ });
16490
+ },
16456
16491
  onPostToolUse: (ctx) => {
16457
16492
  zeitlichMetrics.toolExecuted({
16458
16493
  agentName,