@agentxjs/types 0.0.9 → 1.1.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-BXUYGlWZ.d.cts +510 -0
- package/dist/Agent-CaSxMF_E.d.ts +510 -0
- package/dist/CommandEvent-CbXzPolX.d.ts +495 -0
- package/dist/CommandEvent-DCdk7lzX.d.cts +495 -0
- package/dist/Container-DR-1g44i.d.ts +641 -0
- package/dist/Container-dBDOcjhk.d.cts +641 -0
- package/dist/ContentPart-CqOh-rI1.d.ts +19 -0
- package/dist/ContentPart-DEFnYXCU.d.cts +19 -0
- package/dist/DriveableEvent-Bj7nn-Uk.d.ts +161 -0
- package/dist/DriveableEvent-CCMC1h_C.d.cts +161 -0
- package/dist/ErrorMessage-BoIh3MIO.d.cts +24 -0
- package/dist/ErrorMessage-BoIh3MIO.d.ts +24 -0
- package/dist/ImageRecord-Cn0VcJWk.d.cts +71 -0
- package/dist/ImageRecord-Cn0VcJWk.d.ts +71 -0
- package/dist/LoggerFactory-DZtw0M7U.d.cts +129 -0
- package/dist/LoggerFactory-DZtw0M7U.d.ts +129 -0
- package/dist/Message-Crh81uLL.d.cts +45 -0
- package/dist/Message-DWQUt647.d.ts +45 -0
- package/dist/Persistence-BQkdKomV.d.ts +230 -0
- package/dist/Persistence-Dr70FEBh.d.cts +230 -0
- package/dist/StopReason-D4DthB1h.d.cts +39 -0
- package/dist/StopReason-D4DthB1h.d.ts +39 -0
- package/dist/SystemEvent-CPvvxdMQ.d.cts +159 -0
- package/dist/SystemEvent-CPvvxdMQ.d.ts +159 -0
- package/dist/ToolResultMessage-CDG2L7Zv.d.ts +332 -0
- package/dist/ToolResultMessage-CRKMSf5d.d.cts +332 -0
- package/dist/agent-internal.cjs +19 -0
- package/dist/agent-internal.cjs.map +1 -0
- package/dist/agent-internal.d.cts +52 -0
- package/dist/agent-internal.d.ts +52 -0
- package/dist/agent-internal.js +1 -0
- package/dist/agent-internal.js.map +1 -0
- package/dist/agent.cjs +70 -0
- package/dist/agent.cjs.map +1 -0
- package/dist/agent.d.cts +229 -0
- package/dist/agent.d.ts +229 -0
- package/dist/agent.js +41 -0
- package/dist/agent.js.map +1 -0
- package/dist/agentx.cjs +38 -0
- package/dist/agentx.cjs.map +1 -0
- package/dist/agentx.d.cts +311 -0
- package/dist/agentx.d.ts +311 -0
- package/dist/agentx.js +12 -0
- package/dist/agentx.js.map +1 -0
- package/dist/chunk-2QHAIM3V.js +1 -0
- package/dist/chunk-2QHAIM3V.js.map +1 -0
- package/dist/common.cjs +19 -0
- package/dist/common.cjs.map +1 -0
- package/dist/common.d.cts +43 -0
- package/dist/common.d.ts +43 -0
- package/dist/common.js +2 -0
- package/dist/common.js.map +1 -0
- package/dist/event.cjs +184 -0
- package/dist/event.cjs.map +1 -0
- package/dist/event.d.cts +769 -0
- package/dist/event.d.ts +769 -0
- package/dist/event.js +134 -0
- package/dist/event.js.map +1 -0
- package/dist/index-CjFNcCxR.d.cts +299 -0
- package/dist/index-usKuk41S.d.ts +299 -0
- package/dist/index.cjs +2 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -5267
- package/dist/index.d.ts +8 -5267
- package/dist/index.js +1 -150
- package/dist/index.js.map +1 -1
- package/dist/network.cjs +19 -0
- package/dist/network.cjs.map +1 -0
- package/dist/network.d.cts +168 -0
- package/dist/network.d.ts +168 -0
- package/dist/network.js +1 -0
- package/dist/network.js.map +1 -0
- package/dist/runtime-internal.cjs +19 -0
- package/dist/runtime-internal.cjs.map +1 -0
- package/dist/runtime-internal.d.cts +943 -0
- package/dist/runtime-internal.d.ts +943 -0
- package/dist/runtime-internal.js +1 -0
- package/dist/runtime-internal.js.map +1 -0
- package/dist/runtime.cjs +19 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +217 -0
- package/dist/runtime.d.ts +217 -0
- package/dist/runtime.js +1 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +75 -3
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { h as AgentTurnEvent$1, i as TurnRequestEvent$1, j as TurnResponseEvent$1, U as UserMessage } from './ToolResultMessage-CRKMSf5d.cjs';
|
|
2
|
+
import { A as AgentStreamEvent, a as AgentMessageStartEvent, b as AgentMessageDeltaEvent, c as AgentMessageStopEvent, d as AgentTextDeltaEvent, e as AgentToolUseStartEvent, f as AgentInputJsonDeltaEvent, g as AgentToolUseStopEvent, h as AgentToolResultEvent, i as AgentStateEvent$1, C as ConversationQueuedEvent$1, j as ConversationStartEvent$1, k as ConversationThinkingEvent$1, l as ConversationRespondingEvent$1, m as ConversationEndEvent$1, n as ConversationInterruptedEvent$1, T as ToolPlannedEvent$1, o as ToolExecutingEvent$1, p as ToolCompletedEvent$1, q as ToolFailedEvent$1, E as ErrorOccurredEvent$1, r as AgentMessageEvent$1, U as UserMessageEvent$1, s as AssistantMessageEvent$1, t as ToolCallMessageEvent$1, u as ToolResultMessageEvent$1, v as ErrorMessageEvent$1 } from './index-CjFNcCxR.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* EngineEvent - Lightweight event base for AgentEngine domain
|
|
6
|
+
*
|
|
7
|
+
* EngineEvent is the simplified event structure used inside AgentEngine.
|
|
8
|
+
* It only contains: type, timestamp, data
|
|
9
|
+
*
|
|
10
|
+
* This is distinct from the full AgentEvent (in @agentxjs/types/event/agent)
|
|
11
|
+
* which extends SystemEvent with source, category, intent, context.
|
|
12
|
+
*
|
|
13
|
+
* ## Relationship
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* AgentEvent (Runtime domain) EngineEvent (Engine domain)
|
|
17
|
+
* ─────────────────────────────────────────────────────────────────
|
|
18
|
+
* { {
|
|
19
|
+
* type: "text_delta", type: "text_delta",
|
|
20
|
+
* timestamp: 123, timestamp: 123,
|
|
21
|
+
* data: { text: "Hi" }, data: { text: "Hi" },
|
|
22
|
+
* source: "agent", ←── not in Engine
|
|
23
|
+
* category: "stream", ←── not in Engine
|
|
24
|
+
* intent: "notification", ←── not in Engine
|
|
25
|
+
* context: { ... }, ←── not in Engine
|
|
26
|
+
* } }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Use `ToEngineEvent<T>` to convert AgentEvent to EngineEvent.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* EngineEvent - Lightweight event for Engine internal use
|
|
33
|
+
*
|
|
34
|
+
* Only contains the essential fields:
|
|
35
|
+
* - type: What happened
|
|
36
|
+
* - timestamp: When it happened
|
|
37
|
+
* - data: Event payload
|
|
38
|
+
*/
|
|
39
|
+
interface EngineEvent<T extends string = string, D = unknown> {
|
|
40
|
+
/**
|
|
41
|
+
* Event type identifier (e.g., "text_delta", "assistant_message")
|
|
42
|
+
*/
|
|
43
|
+
readonly type: T;
|
|
44
|
+
/**
|
|
45
|
+
* Event timestamp (Unix milliseconds)
|
|
46
|
+
*/
|
|
47
|
+
readonly timestamp: number;
|
|
48
|
+
/**
|
|
49
|
+
* Event payload data
|
|
50
|
+
*/
|
|
51
|
+
readonly data: D;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* ToEngineEvent - Extract lightweight event from full AgentEvent
|
|
55
|
+
*
|
|
56
|
+
* Picks only { type, timestamp, data } from the full SystemEvent structure.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import type { TextDeltaEvent as FullTextDeltaEvent } from "@agentxjs/types/event/agent";
|
|
61
|
+
* import type { ToEngineEvent } from "./EngineEvent";
|
|
62
|
+
*
|
|
63
|
+
* // FullTextDeltaEvent has: type, timestamp, data, source, category, intent, context
|
|
64
|
+
* // TextDeltaEvent only has: type, timestamp, data
|
|
65
|
+
* type TextDeltaEvent = ToEngineEvent<FullTextDeltaEvent>;
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
type ToEngineEvent<E> = E extends {
|
|
69
|
+
type: infer T;
|
|
70
|
+
timestamp: number;
|
|
71
|
+
data: infer D;
|
|
72
|
+
} ? EngineEvent<T extends string ? T : string, D> : never;
|
|
73
|
+
/**
|
|
74
|
+
* ToEngineEventUnion - Convert a union of AgentEvents to EngineEvents
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* type AgentStreamEvent = TextDeltaEvent | MessageStartEvent | ...;
|
|
79
|
+
* type StreamEvent = ToEngineEventUnion<AgentStreamEvent>;
|
|
80
|
+
* // StreamEvent is now the lightweight version of each event in the union
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
type ToEngineEventUnion<E> = E extends unknown ? ToEngineEvent<E> : never;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Engine Turn Events (Lightweight)
|
|
87
|
+
*
|
|
88
|
+
* Lightweight turn events for AgentEngine internal use.
|
|
89
|
+
* Derived from full AgentTurnEvent in @agentxjs/types/event/agent.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* TurnEvent - Base type for turn events
|
|
94
|
+
* @deprecated Use specific event types instead
|
|
95
|
+
*/
|
|
96
|
+
interface TurnEvent<T extends string = string, D = unknown> extends EngineEvent<T, D> {
|
|
97
|
+
}
|
|
98
|
+
type TurnRequestEvent = ToEngineEvent<TurnRequestEvent$1>;
|
|
99
|
+
type TurnResponseEvent = ToEngineEvent<TurnResponseEvent$1>;
|
|
100
|
+
/**
|
|
101
|
+
* AgentTurnEvent - All lightweight turn events
|
|
102
|
+
*/
|
|
103
|
+
type AgentTurnEvent = ToEngineEventUnion<AgentTurnEvent$1>;
|
|
104
|
+
/**
|
|
105
|
+
* Type guard: is this a turn event?
|
|
106
|
+
*/
|
|
107
|
+
declare function isTurnEvent(event: EngineEvent): event is AgentTurnEvent;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Engine Stream Events (Lightweight)
|
|
111
|
+
*
|
|
112
|
+
* Lightweight stream events for AgentEngine internal use.
|
|
113
|
+
* Derived from full AgentStreamEvent in @agentxjs/types/event/agent.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
type MessageStartEvent = ToEngineEvent<AgentMessageStartEvent>;
|
|
117
|
+
type MessageDeltaEvent = ToEngineEvent<AgentMessageDeltaEvent>;
|
|
118
|
+
type MessageStopEvent = ToEngineEvent<AgentMessageStopEvent>;
|
|
119
|
+
type TextDeltaEvent = ToEngineEvent<AgentTextDeltaEvent>;
|
|
120
|
+
type ToolUseStartEvent = ToEngineEvent<AgentToolUseStartEvent>;
|
|
121
|
+
type InputJsonDeltaEvent = ToEngineEvent<AgentInputJsonDeltaEvent>;
|
|
122
|
+
type ToolUseStopEvent = ToEngineEvent<AgentToolUseStopEvent>;
|
|
123
|
+
type ToolResultEvent = ToEngineEvent<AgentToolResultEvent>;
|
|
124
|
+
/**
|
|
125
|
+
* StreamEvent - All lightweight stream events
|
|
126
|
+
*/
|
|
127
|
+
type StreamEvent = ToEngineEventUnion<AgentStreamEvent>;
|
|
128
|
+
/**
|
|
129
|
+
* StreamEventType - String literal union
|
|
130
|
+
*/
|
|
131
|
+
type StreamEventType = StreamEvent["type"];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* AgentState
|
|
135
|
+
*
|
|
136
|
+
* Agent conversation states for fine-grained monitoring.
|
|
137
|
+
*
|
|
138
|
+
* State transitions:
|
|
139
|
+
* ```
|
|
140
|
+
* idle → thinking → responding → idle
|
|
141
|
+
* ↓
|
|
142
|
+
* planning_tool → awaiting_tool_result
|
|
143
|
+
* ↓
|
|
144
|
+
* thinking → responding → idle
|
|
145
|
+
*
|
|
146
|
+
* Any state can transition to error:
|
|
147
|
+
* thinking/responding/planning_tool/awaiting_tool_result → error → idle
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Agent state types
|
|
152
|
+
*/
|
|
153
|
+
type AgentState = "idle" | "thinking" | "responding" | "planning_tool" | "awaiting_tool_result" | "error";
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Engine State Events (Lightweight)
|
|
157
|
+
*
|
|
158
|
+
* Lightweight state events for AgentEngine internal use.
|
|
159
|
+
* Derived from full AgentStateEvent in @agentxjs/types/event/agent.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* StateEvent - Base type for state events
|
|
164
|
+
* @deprecated Use specific event types instead
|
|
165
|
+
*/
|
|
166
|
+
interface StateEvent<T extends string = string, D = unknown> extends EngineEvent<T, D> {
|
|
167
|
+
}
|
|
168
|
+
type ConversationQueuedEvent = ToEngineEvent<ConversationQueuedEvent$1>;
|
|
169
|
+
type ConversationStartEvent = ToEngineEvent<ConversationStartEvent$1>;
|
|
170
|
+
type ConversationThinkingEvent = ToEngineEvent<ConversationThinkingEvent$1>;
|
|
171
|
+
type ConversationRespondingEvent = ToEngineEvent<ConversationRespondingEvent$1>;
|
|
172
|
+
type ConversationEndEvent = ToEngineEvent<ConversationEndEvent$1>;
|
|
173
|
+
type ConversationInterruptedEvent = ToEngineEvent<ConversationInterruptedEvent$1>;
|
|
174
|
+
type ToolPlannedEvent = ToEngineEvent<ToolPlannedEvent$1>;
|
|
175
|
+
type ToolExecutingEvent = ToEngineEvent<ToolExecutingEvent$1>;
|
|
176
|
+
type ToolCompletedEvent = ToEngineEvent<ToolCompletedEvent$1>;
|
|
177
|
+
type ToolFailedEvent = ToEngineEvent<ToolFailedEvent$1>;
|
|
178
|
+
type ErrorOccurredEvent = ToEngineEvent<ErrorOccurredEvent$1>;
|
|
179
|
+
/**
|
|
180
|
+
* Alias for ErrorOccurredEvent (legacy compatibility)
|
|
181
|
+
*/
|
|
182
|
+
type AgentErrorOccurredEvent = ErrorOccurredEvent;
|
|
183
|
+
/**
|
|
184
|
+
* AgentStateEvent - All lightweight state events
|
|
185
|
+
*/
|
|
186
|
+
type AgentStateEvent = ToEngineEventUnion<AgentStateEvent$1>;
|
|
187
|
+
/**
|
|
188
|
+
* Type guard: is this a state event?
|
|
189
|
+
*/
|
|
190
|
+
declare function isStateEvent(event: EngineEvent): event is AgentStateEvent;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Engine Message Events (Lightweight)
|
|
194
|
+
*
|
|
195
|
+
* Lightweight message events for AgentEngine internal use.
|
|
196
|
+
* Derived from full AgentMessageEvent in @agentxjs/types/event/agent.
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* MessageEvent - Base type for message events
|
|
201
|
+
* @deprecated Use specific event types instead
|
|
202
|
+
*/
|
|
203
|
+
interface MessageEvent<T extends string = string, D = unknown> extends EngineEvent<T, D> {
|
|
204
|
+
}
|
|
205
|
+
type UserMessageEvent = ToEngineEvent<UserMessageEvent$1>;
|
|
206
|
+
type AssistantMessageEvent = ToEngineEvent<AssistantMessageEvent$1>;
|
|
207
|
+
type ToolCallMessageEvent = ToEngineEvent<ToolCallMessageEvent$1>;
|
|
208
|
+
type ToolResultMessageEvent = ToEngineEvent<ToolResultMessageEvent$1>;
|
|
209
|
+
type ErrorMessageEvent = ToEngineEvent<ErrorMessageEvent$1>;
|
|
210
|
+
/**
|
|
211
|
+
* AgentMessageEvent - All lightweight message events
|
|
212
|
+
*/
|
|
213
|
+
type AgentMessageEvent = ToEngineEventUnion<AgentMessageEvent$1>;
|
|
214
|
+
/**
|
|
215
|
+
* Type guard: is this a message event?
|
|
216
|
+
*/
|
|
217
|
+
declare function isMessageEvent(event: EngineEvent): event is AgentMessageEvent;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* AgentOutput - Union of all possible agent output events
|
|
221
|
+
*
|
|
222
|
+
* Includes all event layers:
|
|
223
|
+
* - Stream: Real-time streaming events from Driver
|
|
224
|
+
* - State: State machine transitions
|
|
225
|
+
* - Message: Assembled messages
|
|
226
|
+
* - Turn: Turn analytics
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* All possible output types from Agent
|
|
231
|
+
*/
|
|
232
|
+
type AgentOutput = StreamEvent | AgentStateEvent | AgentMessageEvent | AgentTurnEvent;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* AgentOutputCallback - Event subscription callback types
|
|
236
|
+
*
|
|
237
|
+
* Callback function types for subscribing to AgentOutput events.
|
|
238
|
+
* Renamed from AgentEventHandler to avoid confusion with Handler classes.
|
|
239
|
+
*/
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Unsubscribe function returned by on()
|
|
243
|
+
*/
|
|
244
|
+
type Unsubscribe = () => void;
|
|
245
|
+
/**
|
|
246
|
+
* Agent output event callback function type
|
|
247
|
+
*/
|
|
248
|
+
type AgentOutputCallback<T extends AgentOutput = AgentOutput> = (event: T) => void;
|
|
249
|
+
/**
|
|
250
|
+
* @deprecated Use AgentOutputCallback instead
|
|
251
|
+
*/
|
|
252
|
+
type AgentEventHandler<T extends AgentOutput = AgentOutput> = AgentOutputCallback<T>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* AgentMiddleware - Input-side interceptor for receive()
|
|
256
|
+
*
|
|
257
|
+
* Intercepts user messages before they are processed by the driver.
|
|
258
|
+
*
|
|
259
|
+
* Usage:
|
|
260
|
+
* ```typescript
|
|
261
|
+
* agent.use(async (message, next) => {
|
|
262
|
+
* console.log('[Before]', message.content);
|
|
263
|
+
* await next(message);
|
|
264
|
+
* console.log('[After]');
|
|
265
|
+
* });
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Next function to continue the middleware chain
|
|
271
|
+
*/
|
|
272
|
+
type AgentMiddlewareNext = (message: UserMessage) => Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Middleware function type
|
|
275
|
+
*
|
|
276
|
+
* @param message - The user message being processed
|
|
277
|
+
* @param next - Call to continue to next middleware or actual receive
|
|
278
|
+
*/
|
|
279
|
+
type AgentMiddleware = (message: UserMessage, next: AgentMiddlewareNext) => Promise<void>;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* AgentInterceptor - Output-side interceptor for events
|
|
283
|
+
*
|
|
284
|
+
* Intercepts events before they are dispatched to handlers.
|
|
285
|
+
*
|
|
286
|
+
* Usage:
|
|
287
|
+
* ```typescript
|
|
288
|
+
* agent.intercept((event, next) => {
|
|
289
|
+
* console.log('Event:', event.type);
|
|
290
|
+
*
|
|
291
|
+
* // Modify event
|
|
292
|
+
* if (event.type === 'text_delta') {
|
|
293
|
+
* event.data.text = maskSensitive(event.data.text);
|
|
294
|
+
* }
|
|
295
|
+
*
|
|
296
|
+
* // Continue to handlers (or skip by not calling next)
|
|
297
|
+
* next(event);
|
|
298
|
+
* });
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Next function to continue the interceptor chain
|
|
304
|
+
*/
|
|
305
|
+
type AgentInterceptorNext = (event: AgentOutput) => void;
|
|
306
|
+
/**
|
|
307
|
+
* Interceptor function type
|
|
308
|
+
*
|
|
309
|
+
* @param event - The event being dispatched
|
|
310
|
+
* @param next - Call to continue to next interceptor or actual dispatch
|
|
311
|
+
*/
|
|
312
|
+
type AgentInterceptor = (event: AgentOutput, next: AgentInterceptorNext) => void;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* MessageQueue - Pending message queue interface
|
|
316
|
+
*
|
|
317
|
+
* Exposes read-only queue state for observability.
|
|
318
|
+
* Queue operations (enqueue/dequeue) are internal to Agent implementation.
|
|
319
|
+
*/
|
|
320
|
+
/**
|
|
321
|
+
* MessageQueue interface
|
|
322
|
+
*
|
|
323
|
+
* Read-only view of the message queue state.
|
|
324
|
+
*/
|
|
325
|
+
interface MessageQueue {
|
|
326
|
+
/**
|
|
327
|
+
* Number of messages in queue
|
|
328
|
+
*/
|
|
329
|
+
readonly length: number;
|
|
330
|
+
/**
|
|
331
|
+
* Whether queue is empty
|
|
332
|
+
*/
|
|
333
|
+
readonly isEmpty: boolean;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* AgentEngine - Event Processing Unit
|
|
338
|
+
*
|
|
339
|
+
* AgentEngine is a logical processing unit that coordinates:
|
|
340
|
+
* - Driver: Event producer (LLM interaction)
|
|
341
|
+
* - MealyMachine: Event assembler (pure Mealy Machine)
|
|
342
|
+
* - Presenter: Event consumer (side effects)
|
|
343
|
+
*
|
|
344
|
+
* ```text
|
|
345
|
+
* Driver (event producer)
|
|
346
|
+
* ↓ Stream Events
|
|
347
|
+
* AgentEngine (logical processor)
|
|
348
|
+
* - MealyMachine: event assembly
|
|
349
|
+
* - State: state management
|
|
350
|
+
* ↓ Processed Events
|
|
351
|
+
* Presenter (event consumer)
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* AgentEngine is independent of Runtime system (Container, Session, Bus).
|
|
355
|
+
* It can be tested in isolation with mock Driver and Presenter.
|
|
356
|
+
*
|
|
357
|
+
* Note: This is distinct from runtime/Agent which is the complete runtime entity
|
|
358
|
+
* with LLM, Sandbox, Session, and lifecycle management (stop/resume).
|
|
359
|
+
*
|
|
360
|
+
* API:
|
|
361
|
+
* - receive(message): Send message to agent
|
|
362
|
+
* - on(handler): Subscribe to events
|
|
363
|
+
* - interrupt(): User-initiated stop
|
|
364
|
+
* - destroy(): Clean up resources
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* State change event payload
|
|
369
|
+
*/
|
|
370
|
+
interface StateChange {
|
|
371
|
+
prev: AgentState;
|
|
372
|
+
current: AgentState;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* State change handler type
|
|
376
|
+
*/
|
|
377
|
+
type StateChangeHandler = (change: StateChange) => void;
|
|
378
|
+
/**
|
|
379
|
+
* Event handler map for batch subscription
|
|
380
|
+
*
|
|
381
|
+
* Generic handler map - concrete event types are defined in runtime/event.
|
|
382
|
+
* AgentEngine package is independent of specific event type definitions.
|
|
383
|
+
*
|
|
384
|
+
* Usage:
|
|
385
|
+
* ```typescript
|
|
386
|
+
* engine.on({
|
|
387
|
+
* text_delta: (event) => console.log(event.data.text),
|
|
388
|
+
* assistant_message: (event) => setMessages(prev => [...prev, event.data]),
|
|
389
|
+
* });
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
type EventHandlerMap = Record<string, ((event: AgentOutput) => void) | undefined>;
|
|
393
|
+
/**
|
|
394
|
+
* React-style handler map for fluent event subscription
|
|
395
|
+
*
|
|
396
|
+
* Generic handler map - concrete event types are defined in runtime/event.
|
|
397
|
+
* AgentEngine package is independent of specific event type definitions.
|
|
398
|
+
*
|
|
399
|
+
* Usage:
|
|
400
|
+
* ```typescript
|
|
401
|
+
* engine.react({
|
|
402
|
+
* onTextDelta: (event) => console.log(event.data.text),
|
|
403
|
+
* onAssistantMessage: (event) => setMessages(prev => [...prev, event.data]),
|
|
404
|
+
* });
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
type ReactHandlerMap = Record<string, ((event: AgentOutput) => void) | undefined>;
|
|
408
|
+
/**
|
|
409
|
+
* AgentEngine interface - Event Processing Unit
|
|
410
|
+
*
|
|
411
|
+
* Core responsibilities:
|
|
412
|
+
* - State management (AgentState)
|
|
413
|
+
* - Event subscription and distribution
|
|
414
|
+
* - Middleware/Interceptor chain
|
|
415
|
+
*/
|
|
416
|
+
interface AgentEngine {
|
|
417
|
+
/**
|
|
418
|
+
* Unique agent instance ID
|
|
419
|
+
*/
|
|
420
|
+
readonly agentId: string;
|
|
421
|
+
/**
|
|
422
|
+
* Creation timestamp
|
|
423
|
+
*/
|
|
424
|
+
readonly createdAt: number;
|
|
425
|
+
/**
|
|
426
|
+
* Current conversation state
|
|
427
|
+
*/
|
|
428
|
+
readonly state: AgentState;
|
|
429
|
+
/**
|
|
430
|
+
* Message queue for pending messages
|
|
431
|
+
*/
|
|
432
|
+
readonly messageQueue: MessageQueue;
|
|
433
|
+
/**
|
|
434
|
+
* Receive a message from user
|
|
435
|
+
*
|
|
436
|
+
* @param message - String content or UserMessage object
|
|
437
|
+
* @deprecated Use handleStreamEvent for push-based event processing
|
|
438
|
+
*/
|
|
439
|
+
receive(message: string | UserMessage): Promise<void>;
|
|
440
|
+
/**
|
|
441
|
+
* Handle a stream event from the driver
|
|
442
|
+
*
|
|
443
|
+
* This is the push-based API for event processing.
|
|
444
|
+
* Events are pushed by BusDriver when DriveableEvents arrive.
|
|
445
|
+
*
|
|
446
|
+
* @param event - StreamEvent to process through MealyMachine
|
|
447
|
+
*/
|
|
448
|
+
handleStreamEvent(event: StreamEvent): void;
|
|
449
|
+
/**
|
|
450
|
+
* Subscribe to all events
|
|
451
|
+
*/
|
|
452
|
+
on(handler: AgentOutputCallback): Unsubscribe;
|
|
453
|
+
/**
|
|
454
|
+
* Batch subscribe to multiple event types
|
|
455
|
+
*/
|
|
456
|
+
on(handlers: EventHandlerMap): Unsubscribe;
|
|
457
|
+
/**
|
|
458
|
+
* Subscribe to specific event type by name
|
|
459
|
+
*/
|
|
460
|
+
on(type: string, handler: AgentOutputCallback): Unsubscribe;
|
|
461
|
+
/**
|
|
462
|
+
* Subscribe to multiple event types by name
|
|
463
|
+
*/
|
|
464
|
+
on(types: string[], handler: AgentOutputCallback): Unsubscribe;
|
|
465
|
+
/**
|
|
466
|
+
* Subscribe to state changes
|
|
467
|
+
*
|
|
468
|
+
* @param handler - Callback receiving { prev, current } state change
|
|
469
|
+
* @returns Unsubscribe function
|
|
470
|
+
*/
|
|
471
|
+
onStateChange(handler: StateChangeHandler): Unsubscribe;
|
|
472
|
+
/**
|
|
473
|
+
* React-style fluent event subscription
|
|
474
|
+
*/
|
|
475
|
+
react(handlers: ReactHandlerMap): Unsubscribe;
|
|
476
|
+
/**
|
|
477
|
+
* Subscribe to agent ready event
|
|
478
|
+
*
|
|
479
|
+
* Called when agent is ready to receive messages.
|
|
480
|
+
* If already ready, handler is called immediately.
|
|
481
|
+
*/
|
|
482
|
+
onReady(handler: () => void): Unsubscribe;
|
|
483
|
+
/**
|
|
484
|
+
* Subscribe to agent destroy event
|
|
485
|
+
*
|
|
486
|
+
* Called when agent is destroyed.
|
|
487
|
+
*/
|
|
488
|
+
onDestroy(handler: () => void): Unsubscribe;
|
|
489
|
+
/**
|
|
490
|
+
* Add middleware to intercept incoming messages (receive side)
|
|
491
|
+
*/
|
|
492
|
+
use(middleware: AgentMiddleware): Unsubscribe;
|
|
493
|
+
/**
|
|
494
|
+
* Add interceptor to intercept outgoing events (event side)
|
|
495
|
+
*/
|
|
496
|
+
intercept(interceptor: AgentInterceptor): Unsubscribe;
|
|
497
|
+
/**
|
|
498
|
+
* Interrupt - User-initiated stop
|
|
499
|
+
*
|
|
500
|
+
* Stops the current operation gracefully.
|
|
501
|
+
* The agent will return to idle state.
|
|
502
|
+
*/
|
|
503
|
+
interrupt(): void;
|
|
504
|
+
/**
|
|
505
|
+
* Destroy - Clean up resources
|
|
506
|
+
*/
|
|
507
|
+
destroy(): Promise<void>;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export { type TurnResponseEvent as $, type AgentState as A, type ToolPlannedEvent as B, type ConversationQueuedEvent as C, type ToolExecutingEvent as D, type EngineEvent as E, type ToolCompletedEvent as F, type ToolFailedEvent as G, type ErrorOccurredEvent as H, type InputJsonDeltaEvent as I, type AgentErrorOccurredEvent as J, type AgentStateEvent as K, isStateEvent as L, type MessageQueue as M, type MessageEvent as N, type UserMessageEvent as O, type AssistantMessageEvent as P, type ToolCallMessageEvent as Q, type ReactHandlerMap as R, type StateChangeHandler as S, type ToEngineEvent as T, type Unsubscribe as U, type ToolResultMessageEvent as V, type ErrorMessageEvent as W, type AgentMessageEvent as X, isMessageEvent as Y, type TurnEvent as Z, type TurnRequestEvent as _, type AgentOutput as a, type AgentTurnEvent as a0, isTurnEvent as a1, type AgentMiddleware as b, type AgentMiddlewareNext as c, type AgentInterceptor as d, type AgentInterceptorNext as e, type AgentOutputCallback as f, type AgentEventHandler as g, type StreamEvent as h, type AgentEngine as i, type StateChange as j, type EventHandlerMap as k, type ToEngineEventUnion as l, type MessageStartEvent as m, type MessageDeltaEvent as n, type MessageStopEvent as o, type TextDeltaEvent as p, type ToolUseStartEvent as q, type ToolUseStopEvent as r, type ToolResultEvent as s, type StreamEventType as t, type StateEvent as u, type ConversationStartEvent as v, type ConversationThinkingEvent as w, type ConversationRespondingEvent as x, type ConversationEndEvent as y, type ConversationInterruptedEvent as z };
|