@agentxjs/core 1.9.3-dev → 1.9.6-dev

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 (80) hide show
  1. package/dist/Processor-DT0N1qI6.d.ts +64 -0
  2. package/dist/agent/engine/internal/index.d.ts +223 -0
  3. package/dist/agent/engine/internal/index.js +24 -0
  4. package/dist/agent/engine/internal/index.js.map +1 -0
  5. package/dist/agent/engine/mealy/index.d.ts +157 -0
  6. package/dist/agent/engine/mealy/index.js +26 -0
  7. package/dist/agent/engine/mealy/index.js.map +1 -0
  8. package/dist/agent/index.d.ts +244 -0
  9. package/dist/agent/index.js +66 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/agent/types/index.d.ts +322 -0
  12. package/dist/agent/types/index.js +12 -0
  13. package/dist/agent/types/index.js.map +1 -0
  14. package/dist/base-m40r3Qgu.d.ts +157 -0
  15. package/dist/bus-uF1DM2ox.d.ts +906 -0
  16. package/dist/chunk-7D4SUZUM.js +38 -0
  17. package/dist/chunk-7D4SUZUM.js.map +1 -0
  18. package/dist/chunk-7ZDX3O6I.js +173 -0
  19. package/dist/chunk-7ZDX3O6I.js.map +1 -0
  20. package/dist/chunk-AT5P47YA.js +543 -0
  21. package/dist/chunk-AT5P47YA.js.map +1 -0
  22. package/dist/chunk-E5FPOAPO.js +123 -0
  23. package/dist/chunk-E5FPOAPO.js.map +1 -0
  24. package/dist/chunk-EKHT54KN.js +272 -0
  25. package/dist/chunk-EKHT54KN.js.map +1 -0
  26. package/dist/chunk-I7GYR3MN.js +502 -0
  27. package/dist/chunk-I7GYR3MN.js.map +1 -0
  28. package/dist/chunk-K6WXQ2RW.js +38 -0
  29. package/dist/chunk-K6WXQ2RW.js.map +1 -0
  30. package/dist/chunk-RL3JRNXM.js +3 -0
  31. package/dist/chunk-RL3JRNXM.js.map +1 -0
  32. package/dist/combinators-nEa5dD0T.d.ts +271 -0
  33. package/dist/common/index.d.ts +1 -0
  34. package/dist/common/index.js +2 -0
  35. package/dist/common/index.js.map +1 -0
  36. package/dist/common/logger/index.d.ts +163 -0
  37. package/dist/common/logger/index.js +184 -0
  38. package/dist/common/logger/index.js.map +1 -0
  39. package/dist/container/index.d.ts +110 -0
  40. package/dist/container/index.js +127 -0
  41. package/dist/container/index.js.map +1 -0
  42. package/dist/driver/index.d.ts +266 -0
  43. package/dist/driver/index.js +1 -0
  44. package/dist/driver/index.js.map +1 -0
  45. package/dist/event/index.d.ts +55 -0
  46. package/dist/event/index.js +60 -0
  47. package/dist/event/index.js.map +1 -0
  48. package/dist/event/types/index.d.ts +1149 -0
  49. package/dist/event/types/index.js +56 -0
  50. package/dist/event/types/index.js.map +1 -0
  51. package/dist/event-CDuTzs__.d.ts +296 -0
  52. package/dist/image/index.d.ts +112 -0
  53. package/dist/image/index.js +151 -0
  54. package/dist/image/index.js.map +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.js +67 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/message-BMrMm1pq.d.ts +305 -0
  59. package/dist/mq/index.d.ts +165 -0
  60. package/dist/mq/index.js +37 -0
  61. package/dist/mq/index.js.map +1 -0
  62. package/dist/network/index.d.ts +567 -0
  63. package/dist/network/index.js +435 -0
  64. package/dist/network/index.js.map +1 -0
  65. package/dist/persistence/index.d.ts +155 -0
  66. package/dist/persistence/index.js +1 -0
  67. package/dist/persistence/index.js.map +1 -0
  68. package/dist/runtime/index.d.ts +240 -0
  69. package/dist/runtime/index.js +347 -0
  70. package/dist/runtime/index.js.map +1 -0
  71. package/dist/session/index.d.ts +92 -0
  72. package/dist/session/index.js +56 -0
  73. package/dist/session/index.js.map +1 -0
  74. package/dist/workspace/index.d.ts +111 -0
  75. package/dist/workspace/index.js +1 -0
  76. package/dist/workspace/index.js.map +1 -0
  77. package/dist/wrapper-Y3UTVU2E.js +3635 -0
  78. package/dist/wrapper-Y3UTVU2E.js.map +1 -0
  79. package/package.json +74 -14
  80. package/tsconfig.json +0 -10
@@ -0,0 +1,244 @@
1
+ export { A as AssistantMessage, C as ContentPart, E as ErrorMessage, F as FilePart, I as ImagePart, M as Message, i as MessageRole, j as MessageSubtype, d as TextPart, e as ThinkingPart, b as TokenUsage, T as ToolCallMessage, f as ToolCallPart, a as ToolResultMessage, g as ToolResultOutput, h as ToolResultPart, c as UserContentPart, U as UserMessage } from '../message-BMrMm1pq.js';
2
+ import { a as AgentState, A as AgentOutput, U as Unsubscribe, S as StreamEvent } from '../event-CDuTzs__.js';
3
+ export { e as AgentError, d as AgentErrorCategory, _ as AgentErrorOccurredEvent, c as AgentEvent, ad as AgentEventHandler, a6 as AgentMessageEvent, b as AgentOutputCallback, $ as AgentStateEvent, ac as AgentTurnEvent, a2 as AssistantMessageEvent, z as ConversationEndData, Q as ConversationEndEvent, B as ConversationInterruptedData, R as ConversationInterruptedEvent, C as ConversationQueuedData, L as ConversationQueuedEvent, y as ConversationRespondingData, P as ConversationRespondingEvent, w as ConversationStartData, N as ConversationStartEvent, x as ConversationThinkingData, O as ConversationThinkingEvent, E as EngineEvent, a5 as ErrorMessageEvent, J as ErrorOccurredData, Z as ErrorOccurredEvent, l as ErrorReceivedData, u as ErrorReceivedEvent, I as InputJsonDeltaData, r as InputJsonDeltaEvent, g as MessageDeltaData, n as MessageDeltaEvent, a0 as MessageEvent, M as MessageStartData, m as MessageStartEvent, h as MessageStopData, o as MessageStopEvent, K as StateEvent, f as StopReason, v as StreamEventType, T as TextDeltaData, p as TextDeltaEvent, a3 as ToolCallMessageEvent, G as ToolCompletedData, X as ToolCompletedEvent, F as ToolExecutingData, W as ToolExecutingEvent, H as ToolFailedData, Y as ToolFailedEvent, D as ToolPlannedData, V as ToolPlannedEvent, k as ToolResultData, t as ToolResultEvent, a4 as ToolResultMessageEvent, i as ToolUseStartData, q as ToolUseStartEvent, j as ToolUseStopData, s as ToolUseStopEvent, a9 as TurnEvent, a7 as TurnRequestData, aa as TurnRequestEvent, a8 as TurnResponseData, ab as TurnResponseEvent, a1 as UserMessageEvent, af as isMessageEvent, ae as isStateEvent, ag as isTurnEvent } from '../event-CDuTzs__.js';
4
+ import { CreateAgentOptions, AgentEngine, StateChangeHandler } from './types/index.js';
5
+ export { AgentEventBus, AgentInterceptor, AgentInterceptorNext, AgentMiddleware, AgentMiddlewareNext, AgentPresenter, AgentSource, AgentStateMachineInterface, EventHandlerMap, MessageQueue, ReactHandlerMap, StateChange } from './types/index.js';
6
+ import { MessageAssemblerState, StateEventProcessorContext, TurnTrackerState, MessageAssemblerOutput, StateEventProcessorOutput, TurnTrackerOutput } from './engine/internal/index.js';
7
+ export { MessageAssemblerInput, PendingContent, PendingTurn, StateEventProcessorInput, TurnTrackerInput, createInitialMessageAssemblerState, createInitialStateEventProcessorContext, createInitialTurnTrackerState, messageAssemblerProcessor, messageAssemblerProcessorDef, stateEventProcessor, stateEventProcessorDef, turnTrackerProcessor, turnTrackerProcessorDef } from './engine/internal/index.js';
8
+ export { M as MemoryStore, a as Sink, b as SinkDefinition, c as Source, d as SourceDefinition, S as Store, g as chainProcessors, f as combineInitialStates, e as combineProcessors, h as filterProcessor, i as identityProcessor, m as mapOutput, w as withLogging } from '../combinators-nEa5dD0T.js';
9
+ import { P as Processor } from '../Processor-DT0N1qI6.js';
10
+ export { b as ProcessorDefinition, a as ProcessorResult } from '../Processor-DT0N1qI6.js';
11
+ import 'commonxjs/logger';
12
+
13
+ /**
14
+ * createAgent - Factory function to create an AgentEngine
15
+ *
16
+ * Creates an AgentEngine connected to EventBus:
17
+ * - receive() emits user_message to EventBus
18
+ * - Source subscribes to StreamEvent from EventBus
19
+ * - Presenter emits AgentOutput to EventBus
20
+ *
21
+ * ```
22
+ * EventBus
23
+ * ↗ ↘
24
+ * emit │ │ emit
25
+ * user_message │ │ AgentOutput
26
+ * ↑ │ │ ↑
27
+ * ┌─────────────────────────────────────────────────────────────┐
28
+ * │ AgentEngine │
29
+ * │ │
30
+ * │ receive() ──► Source ──► MealyMachine ──► Presenter │
31
+ * │ (sub) (pub) │
32
+ * └─────────────────────────────────────────────────────────────┘
33
+ * ```
34
+ */
35
+
36
+ /**
37
+ * Create an AgentEngine instance connected to EventBus
38
+ */
39
+ declare function createAgent(options: CreateAgentOptions): AgentEngine;
40
+
41
+ /**
42
+ * AgentStateMachine - State management driven by StateEvents
43
+ *
44
+ * Manages agent state transitions driven by StateEvents.
45
+ * Single source of truth for agent state in AgentEngine.
46
+ *
47
+ * Flow:
48
+ * StreamEvent → MealyMachine → StateEvent → AgentStateMachine → state update
49
+ *
50
+ * Responsibilities:
51
+ * - Process StateEvents
52
+ * - Maintain current AgentState
53
+ * - Notify state change subscribers
54
+ */
55
+
56
+ /**
57
+ * AgentStateMachine implementation
58
+ */
59
+ declare class AgentStateMachine {
60
+ private _state;
61
+ private readonly handlers;
62
+ /**
63
+ * Current agent state
64
+ */
65
+ get state(): AgentState;
66
+ /**
67
+ * Process an event and update internal state if it's a StateEvent
68
+ *
69
+ * @param event - Event from MealyMachine (could be any AgentOutput)
70
+ */
71
+ process(event: AgentOutput): void;
72
+ /**
73
+ * Subscribe to state changes
74
+ *
75
+ * @param handler - Callback receiving { prev, current } state change
76
+ * @returns Unsubscribe function
77
+ */
78
+ onStateChange(handler: StateChangeHandler): Unsubscribe;
79
+ /**
80
+ * Reset state machine (used on destroy)
81
+ */
82
+ reset(): void;
83
+ /**
84
+ * Map StateEvent type to AgentState
85
+ *
86
+ * @param event - StateEvent from MealyMachine
87
+ * @returns New AgentState or null if no transition needed
88
+ */
89
+ private mapEventToState;
90
+ /**
91
+ * Notify all registered handlers of state change
92
+ */
93
+ private notifyHandlers;
94
+ }
95
+
96
+ /**
97
+ * MealyMachine - Pure Mealy Machine Event Processor
98
+ *
99
+ * MealyMachine is a stateless event processor that transforms StreamEvents
100
+ * into higher-level events (state, message, turn events).
101
+ *
102
+ * Key Design:
103
+ * - Engine is a pure Mealy Machine: process(agentId, event) → outputs
104
+ * - Engine does NOT hold driver or presenters (those belong to AgentEngine layer)
105
+ * - Engine manages intermediate processing state per agentId
106
+ * - Multiple agents can share the same MealyMachine instance
107
+ *
108
+ * Type Relationship:
109
+ * ```
110
+ * StreamEvent (from Driver)
111
+ * │
112
+ * └── message_start, text_delta, tool_use_start, message_stop...
113
+ * ↓ MealyMachine processes
114
+ * AgentOutput (to AgentEngine/Presenter)
115
+ * │
116
+ * ├── StateEvent (conversation_start, conversation_end...)
117
+ * ├── MessageEvent (assistant_message, tool_call_message...)
118
+ * └── TurnEvent (turn_request, turn_response)
119
+ * ```
120
+ *
121
+ * State Management:
122
+ * - Processing state (pendingContents, etc.) is managed internally per agentId
123
+ * - Business data persistence is NOT handled here - that's AgentEngine layer's job
124
+ *
125
+ * Usage:
126
+ * ```typescript
127
+ * const machine = new MealyMachine();
128
+ *
129
+ * // AgentEngine layer coordinates:
130
+ * // 1. Driver produces StreamEvents
131
+ * // 2. MealyMachine processes events
132
+ * // 3. Presenters handle outputs
133
+ *
134
+ * for await (const streamEvent of driver.receive(message)) {
135
+ * const outputs = machine.process(agentId, streamEvent);
136
+ * for (const output of outputs) {
137
+ * presenters.forEach(p => p.present(agentId, output));
138
+ * }
139
+ * }
140
+ * ```
141
+ */
142
+
143
+ /**
144
+ * MealyMachine - Pure Mealy Machine for event processing
145
+ *
146
+ * - Input: StreamEvent (from Driver)
147
+ * - Output: AgentOutput[] (state, message, turn events)
148
+ * - State: Managed internally per agentId
149
+ */
150
+ declare class MealyMachine {
151
+ private readonly store;
152
+ constructor();
153
+ /**
154
+ * Process a single driveable event and return output events
155
+ *
156
+ * This is the core Mealy Machine operation:
157
+ * process(agentId, event) → outputs[]
158
+ *
159
+ * @param agentId - The agent identifier (for state isolation)
160
+ * @param event - StreamEvent to process
161
+ * @returns Array of output events (state, message, turn events)
162
+ */
163
+ process(agentId: string, event: StreamEvent): AgentOutput[];
164
+ /**
165
+ * Process chained events recursively
166
+ *
167
+ * Some processors produce events that trigger other processors:
168
+ * - MessageAssembler produces MessageEvents
169
+ * - TurnTracker consumes MessageEvents to produce TurnEvents
170
+ */
171
+ private processChained;
172
+ /**
173
+ * Clear state for an agent
174
+ *
175
+ * Call this when an agent is destroyed to free memory.
176
+ */
177
+ clearState(agentId: string): void;
178
+ /**
179
+ * Check if state exists for an agent
180
+ */
181
+ hasState(agentId: string): boolean;
182
+ }
183
+ /**
184
+ * Factory function to create MealyMachine
185
+ */
186
+ declare function createMealyMachine(): MealyMachine;
187
+
188
+ /**
189
+ * AgentProcessor
190
+ *
191
+ * Combined Mealy processor for the full AgentX engine.
192
+ * Composes MessageAssembler, StateMachine, and TurnTracker processors.
193
+ */
194
+
195
+ /**
196
+ * Combined state type for the full agent engine
197
+ */
198
+ type AgentEngineState = {
199
+ messageAssembler: MessageAssemblerState;
200
+ stateEventProcessor: StateEventProcessorContext;
201
+ turnTracker: TurnTrackerState;
202
+ };
203
+ /**
204
+ * Input event type for AgentProcessor
205
+ *
206
+ * Accepts:
207
+ * - StreamEventType: Raw stream events from Driver
208
+ * - MessageEventType: Re-injected message events (for TurnTracker)
209
+ *
210
+ * Note: AgentOutput is used because re-injected events can be any output type
211
+ */
212
+ type AgentProcessorInput = AgentOutput;
213
+ /**
214
+ * Output event type from AgentProcessor
215
+ *
216
+ * Produces:
217
+ * - MessageAssemblerOutput: Assembled message events
218
+ * - StateEventProcessorOutput: State transition events
219
+ * - TurnTrackerOutput: Turn analytics events
220
+ *
221
+ * Note: StreamEventType is NOT in output - it's passed through by AgentEngine
222
+ */
223
+ type AgentProcessorOutput = MessageAssemblerOutput | StateEventProcessorOutput | TurnTrackerOutput;
224
+ /**
225
+ * Combined processor for the full agent engine
226
+ *
227
+ * This combines:
228
+ * - MessageAssembler: Stream → Message events
229
+ * - StateEventProcessor: Stream → State events
230
+ * - TurnTracker: Message → Turn events
231
+ *
232
+ * Pattern: (state, input) => [newState, outputs]
233
+ * Key insight: State is means, outputs are the goal (Mealy Machine)
234
+ *
235
+ * Note: Raw StreamEvents are NOT output by this processor.
236
+ * The AgentEngine handles pass-through of original events.
237
+ */
238
+ declare const agentProcessor: Processor<AgentEngineState, AgentProcessorInput, AgentProcessorOutput>;
239
+ /**
240
+ * Initial state factory for the full agent engine
241
+ */
242
+ declare const createInitialAgentEngineState: () => AgentEngineState;
243
+
244
+ export { AgentEngine, type AgentEngineState, AgentOutput, type AgentProcessorInput, type AgentProcessorOutput, AgentState, AgentStateMachine, CreateAgentOptions, MealyMachine, MessageAssemblerOutput, MessageAssemblerState, Processor, StateChangeHandler, StateEventProcessorContext, StateEventProcessorOutput, StreamEvent, TurnTrackerOutput, TurnTrackerState, Unsubscribe, agentProcessor, createAgent, createInitialAgentEngineState, createMealyMachine };
@@ -0,0 +1,66 @@
1
+ import {
2
+ AgentStateMachine,
3
+ MealyMachine,
4
+ agentProcessor,
5
+ createAgent,
6
+ createInitialAgentEngineState,
7
+ createMealyMachine
8
+ } from "../chunk-AT5P47YA.js";
9
+ import {
10
+ MemoryStore,
11
+ chainProcessors,
12
+ combineInitialStates,
13
+ combineProcessors,
14
+ filterProcessor,
15
+ identityProcessor,
16
+ mapOutput,
17
+ withLogging
18
+ } from "../chunk-EKHT54KN.js";
19
+ import {
20
+ createInitialMessageAssemblerState,
21
+ createInitialStateEventProcessorContext,
22
+ createInitialTurnTrackerState,
23
+ messageAssemblerProcessor,
24
+ messageAssemblerProcessorDef,
25
+ stateEventProcessor,
26
+ stateEventProcessorDef,
27
+ turnTrackerProcessor,
28
+ turnTrackerProcessorDef
29
+ } from "../chunk-I7GYR3MN.js";
30
+ import "../chunk-7ZDX3O6I.js";
31
+ import {
32
+ isMessageEvent,
33
+ isStateEvent,
34
+ isTurnEvent
35
+ } from "../chunk-K6WXQ2RW.js";
36
+ import "../chunk-E5FPOAPO.js";
37
+ import "../chunk-7D4SUZUM.js";
38
+ export {
39
+ AgentStateMachine,
40
+ MealyMachine,
41
+ MemoryStore,
42
+ agentProcessor,
43
+ chainProcessors,
44
+ combineInitialStates,
45
+ combineProcessors,
46
+ createAgent,
47
+ createInitialAgentEngineState,
48
+ createInitialMessageAssemblerState,
49
+ createInitialStateEventProcessorContext,
50
+ createInitialTurnTrackerState,
51
+ createMealyMachine,
52
+ filterProcessor,
53
+ identityProcessor,
54
+ isMessageEvent,
55
+ isStateEvent,
56
+ isTurnEvent,
57
+ mapOutput,
58
+ messageAssemblerProcessor,
59
+ messageAssemblerProcessorDef,
60
+ stateEventProcessor,
61
+ stateEventProcessorDef,
62
+ turnTrackerProcessor,
63
+ turnTrackerProcessorDef,
64
+ withLogging
65
+ };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,322 @@
1
+ import { U as UserMessage } from '../../message-BMrMm1pq.js';
2
+ export { A as AssistantMessage, C as ContentPart, E as ErrorMessage, F as FilePart, I as ImagePart, M as Message, i as MessageRole, j as MessageSubtype, d as TextPart, e as ThinkingPart, b as TokenUsage, T as ToolCallMessage, f as ToolCallPart, a as ToolResultMessage, g as ToolResultOutput, h as ToolResultPart, c as UserContentPart } from '../../message-BMrMm1pq.js';
3
+ import { S as StreamEvent, A as AgentOutput, a as AgentState, b as AgentOutputCallback, U as Unsubscribe } from '../../event-CDuTzs__.js';
4
+ export { e as AgentError, d as AgentErrorCategory, _ as AgentErrorOccurredEvent, c as AgentEvent, ad as AgentEventHandler, a6 as AgentMessageEvent, $ as AgentStateEvent, ac as AgentTurnEvent, a2 as AssistantMessageEvent, z as ConversationEndData, Q as ConversationEndEvent, B as ConversationInterruptedData, R as ConversationInterruptedEvent, C as ConversationQueuedData, L as ConversationQueuedEvent, y as ConversationRespondingData, P as ConversationRespondingEvent, w as ConversationStartData, N as ConversationStartEvent, x as ConversationThinkingData, O as ConversationThinkingEvent, E as EngineEvent, a5 as ErrorMessageEvent, J as ErrorOccurredData, Z as ErrorOccurredEvent, l as ErrorReceivedData, u as ErrorReceivedEvent, I as InputJsonDeltaData, r as InputJsonDeltaEvent, g as MessageDeltaData, n as MessageDeltaEvent, a0 as MessageEvent, M as MessageStartData, m as MessageStartEvent, h as MessageStopData, o as MessageStopEvent, K as StateEvent, f as StopReason, v as StreamEventType, T as TextDeltaData, p as TextDeltaEvent, a3 as ToolCallMessageEvent, G as ToolCompletedData, X as ToolCompletedEvent, F as ToolExecutingData, W as ToolExecutingEvent, H as ToolFailedData, Y as ToolFailedEvent, D as ToolPlannedData, V as ToolPlannedEvent, k as ToolResultData, t as ToolResultEvent, a4 as ToolResultMessageEvent, i as ToolUseStartData, q as ToolUseStartEvent, j as ToolUseStopData, s as ToolUseStopEvent, a9 as TurnEvent, a7 as TurnRequestData, aa as TurnRequestEvent, a8 as TurnResponseData, ab as TurnResponseEvent, a1 as UserMessageEvent, af as isMessageEvent, ae as isStateEvent, ag as isTurnEvent } from '../../event-CDuTzs__.js';
5
+
6
+ /**
7
+ * Engine Types - AgentEngine, Driver, Presenter, and related infrastructure
8
+ *
9
+ * This file defines:
10
+ * - MessageQueue: Read-only view of message queue state
11
+ * - AgentEngine: Event processing unit interface
12
+ * - AgentDriver: Input adapter for external events
13
+ * - AgentPresenter: Output adapter for external systems
14
+ * - Middleware and Interceptor types
15
+ * - StateMachine interface
16
+ * - CreateAgentOptions: Factory options
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+
21
+ /**
22
+ * MessageQueue interface
23
+ *
24
+ * Read-only view of the message queue state.
25
+ */
26
+ interface MessageQueue {
27
+ /**
28
+ * Number of messages in queue
29
+ */
30
+ readonly length: number;
31
+ /**
32
+ * Whether queue is empty
33
+ */
34
+ readonly isEmpty: boolean;
35
+ }
36
+ /**
37
+ * Next function to continue the middleware chain
38
+ */
39
+ type AgentMiddlewareNext = (message: UserMessage) => Promise<void>;
40
+ /**
41
+ * Middleware function type
42
+ *
43
+ * @param message - The user message being processed
44
+ * @param next - Call to continue to next middleware or actual receive
45
+ */
46
+ type AgentMiddleware = (message: UserMessage, next: AgentMiddlewareNext) => Promise<void>;
47
+ /**
48
+ * Next function to continue the interceptor chain
49
+ */
50
+ type AgentInterceptorNext = (event: AgentOutput) => void;
51
+ /**
52
+ * Interceptor function type
53
+ *
54
+ * @param event - The event being dispatched
55
+ * @param next - Call to continue to next interceptor or actual dispatch
56
+ */
57
+ type AgentInterceptor = (event: AgentOutput, next: AgentInterceptorNext) => void;
58
+ /**
59
+ * State change event payload
60
+ */
61
+ interface StateChange {
62
+ prev: AgentState;
63
+ current: AgentState;
64
+ }
65
+ /**
66
+ * State change handler type
67
+ */
68
+ type StateChangeHandler = (change: StateChange) => void;
69
+ /**
70
+ * AgentStateMachine interface
71
+ *
72
+ * Processes StateEvents to update internal agent state and notify subscribers.
73
+ */
74
+ interface AgentStateMachineInterface {
75
+ /**
76
+ * Current agent state
77
+ */
78
+ readonly state: AgentState;
79
+ /**
80
+ * Process a StateEvent and update internal state
81
+ *
82
+ * @param event - StateEvent from MealyMachine
83
+ */
84
+ process(event: AgentOutput): void;
85
+ /**
86
+ * Subscribe to state changes
87
+ *
88
+ * @param handler - Callback receiving { prev, current } state change
89
+ * @returns Unsubscribe function
90
+ */
91
+ onStateChange(handler: StateChangeHandler): Unsubscribe;
92
+ /**
93
+ * Reset state machine (used on destroy)
94
+ */
95
+ reset(): void;
96
+ }
97
+ /**
98
+ * Event handler map for batch subscription
99
+ *
100
+ * Generic handler map - concrete event types are defined in runtime/event.
101
+ * AgentEngine package is independent of specific event type definitions.
102
+ *
103
+ * Usage:
104
+ * ```typescript
105
+ * engine.on({
106
+ * text_delta: (event) => console.log(event.data.text),
107
+ * assistant_message: (event) => setMessages(prev => [...prev, event.data]),
108
+ * });
109
+ * ```
110
+ */
111
+ type EventHandlerMap = Record<string, ((event: AgentOutput) => void) | undefined>;
112
+ /**
113
+ * React-style handler map for fluent event subscription
114
+ *
115
+ * Generic handler map - concrete event types are defined in runtime/event.
116
+ * AgentEngine package is independent of specific event type definitions.
117
+ *
118
+ * Usage:
119
+ * ```typescript
120
+ * engine.react({
121
+ * onTextDelta: (event) => console.log(event.data.text),
122
+ * onAssistantMessage: (event) => setMessages(prev => [...prev, event.data]),
123
+ * });
124
+ * ```
125
+ */
126
+ type ReactHandlerMap = Record<string, ((event: AgentOutput) => void) | undefined>;
127
+ /**
128
+ * AgentEngine interface - Event Processing Unit
129
+ *
130
+ * Core responsibilities:
131
+ * - State management (AgentState)
132
+ * - Event subscription and distribution
133
+ * - Middleware/Interceptor chain
134
+ */
135
+ interface AgentEngine {
136
+ /**
137
+ * Unique agent instance ID
138
+ */
139
+ readonly agentId: string;
140
+ /**
141
+ * Creation timestamp
142
+ */
143
+ readonly createdAt: number;
144
+ /**
145
+ * Current conversation state
146
+ */
147
+ readonly state: AgentState;
148
+ /**
149
+ * Message queue for pending messages
150
+ */
151
+ readonly messageQueue: MessageQueue;
152
+ /**
153
+ * Receive a message from user
154
+ *
155
+ * @param message - String content or UserMessage object
156
+ * @deprecated Use handleStreamEvent for push-based event processing
157
+ */
158
+ receive(message: string | UserMessage): Promise<void>;
159
+ /**
160
+ * Handle a stream event from the driver
161
+ *
162
+ * This is the push-based API for event processing.
163
+ * Events are pushed by BusDriver when DriveableEvents arrive.
164
+ *
165
+ * @param event - StreamEvent to process through MealyMachine
166
+ */
167
+ handleStreamEvent(event: StreamEvent): void;
168
+ /**
169
+ * Subscribe to all events
170
+ */
171
+ on(handler: AgentOutputCallback): Unsubscribe;
172
+ /**
173
+ * Batch subscribe to multiple event types
174
+ */
175
+ on(handlers: EventHandlerMap): Unsubscribe;
176
+ /**
177
+ * Subscribe to specific event type by name
178
+ */
179
+ on(type: string, handler: AgentOutputCallback): Unsubscribe;
180
+ /**
181
+ * Subscribe to multiple event types by name
182
+ */
183
+ on(types: string[], handler: AgentOutputCallback): Unsubscribe;
184
+ /**
185
+ * Subscribe to state changes
186
+ *
187
+ * @param handler - Callback receiving { prev, current } state change
188
+ * @returns Unsubscribe function
189
+ */
190
+ onStateChange(handler: StateChangeHandler): Unsubscribe;
191
+ /**
192
+ * React-style fluent event subscription
193
+ */
194
+ react(handlers: ReactHandlerMap): Unsubscribe;
195
+ /**
196
+ * Subscribe to agent ready event
197
+ *
198
+ * Called when agent is ready to receive messages.
199
+ * If already ready, handler is called immediately.
200
+ */
201
+ onReady(handler: () => void): Unsubscribe;
202
+ /**
203
+ * Subscribe to agent destroy event
204
+ *
205
+ * Called when agent is destroyed.
206
+ */
207
+ onDestroy(handler: () => void): Unsubscribe;
208
+ /**
209
+ * Add middleware to intercept incoming messages (receive side)
210
+ */
211
+ use(middleware: AgentMiddleware): Unsubscribe;
212
+ /**
213
+ * Add interceptor to intercept outgoing events (event side)
214
+ */
215
+ intercept(interceptor: AgentInterceptor): Unsubscribe;
216
+ /**
217
+ * Interrupt - User-initiated stop
218
+ *
219
+ * Stops the current operation gracefully.
220
+ * The agent will return to idle state.
221
+ */
222
+ interrupt(): void;
223
+ /**
224
+ * Destroy - Clean up resources
225
+ */
226
+ destroy(): Promise<void>;
227
+ }
228
+ /**
229
+ * AgentSource interface
230
+ *
231
+ * Subscribes to EventBus for StreamEvents and forwards them to AgentEngine.
232
+ * This is the input adapter: EventBus → AgentEngine
233
+ *
234
+ * ```
235
+ * EventBus ──subscribe──► Source ──handleStreamEvent──► AgentEngine
236
+ * ```
237
+ */
238
+ interface AgentSource {
239
+ /**
240
+ * Source name (for identification and logging)
241
+ */
242
+ readonly name: string;
243
+ /**
244
+ * Connect to EventBus and start forwarding StreamEvents
245
+ *
246
+ * @param onEvent - Callback to invoke when StreamEvent is received
247
+ */
248
+ connect(onEvent: (event: StreamEvent) => void): void;
249
+ /**
250
+ * Disconnect from EventBus
251
+ */
252
+ disconnect(): void;
253
+ }
254
+ /**
255
+ * AgentPresenter interface
256
+ *
257
+ * Publishes AgentOutput to EventBus.
258
+ * This is the output adapter: AgentEngine → EventBus
259
+ *
260
+ * ```
261
+ * AgentEngine ──present──► Presenter ──emit──► EventBus
262
+ * ```
263
+ */
264
+ interface AgentPresenter {
265
+ /**
266
+ * Presenter name (for identification and logging)
267
+ */
268
+ readonly name: string;
269
+ /**
270
+ * Publish an agent output to EventBus
271
+ *
272
+ * @param agentId - The agent ID
273
+ * @param output - The output to publish
274
+ */
275
+ present(agentId: string, output: AgentOutput): void;
276
+ }
277
+ /**
278
+ * EventBus interface (minimal subset needed by AgentEngine)
279
+ */
280
+ interface AgentEventBus {
281
+ /**
282
+ * Emit an event to the bus
283
+ */
284
+ emit(event: unknown): void;
285
+ /**
286
+ * Subscribe to events
287
+ */
288
+ on(type: string, handler: (event: unknown) => void): () => void;
289
+ /**
290
+ * Subscribe to all events
291
+ */
292
+ onAny(handler: (event: unknown) => void): () => void;
293
+ }
294
+ /**
295
+ * Options for creating an AgentEngine
296
+ */
297
+ interface CreateAgentOptions {
298
+ /**
299
+ * Agent ID (optional, auto-generated if not provided)
300
+ */
301
+ agentId?: string;
302
+ /**
303
+ * EventBus connection
304
+ * AgentEngine uses this to:
305
+ * - emit user_message when receive() is called
306
+ * - Source subscribes to StreamEvent
307
+ * - Presenter emits AgentOutput
308
+ */
309
+ bus: AgentEventBus;
310
+ /**
311
+ * Source - Subscribes to EventBus, forwards StreamEvent to AgentEngine
312
+ * Optional: default implementation subscribes to StreamEvent types
313
+ */
314
+ source?: AgentSource;
315
+ /**
316
+ * Presenter - Publishes AgentOutput to EventBus
317
+ * Optional: default implementation emits to bus
318
+ */
319
+ presenter?: AgentPresenter;
320
+ }
321
+
322
+ export { type AgentEngine, type AgentEventBus, type AgentInterceptor, type AgentInterceptorNext, type AgentMiddleware, type AgentMiddlewareNext, AgentOutput, AgentOutputCallback, type AgentPresenter, type AgentSource, AgentState, type AgentStateMachineInterface, type CreateAgentOptions, type EventHandlerMap, type MessageQueue, type ReactHandlerMap, type StateChange, type StateChangeHandler, StreamEvent, Unsubscribe, UserMessage };
@@ -0,0 +1,12 @@
1
+ import {
2
+ isMessageEvent,
3
+ isStateEvent,
4
+ isTurnEvent
5
+ } from "../../chunk-K6WXQ2RW.js";
6
+ import "../../chunk-7D4SUZUM.js";
7
+ export {
8
+ isMessageEvent,
9
+ isStateEvent,
10
+ isTurnEvent
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}