@agentxjs/types 0.0.9 → 0.2.0
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 +82 -10
- package/LICENSE +0 -21
package/dist/agent.d.cts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { h as StreamEvent, a as AgentOutput, i as AgentEngine, E as EngineEvent } from './Agent-BXUYGlWZ.cjs';
|
|
2
|
+
export { J as AgentErrorOccurredEvent, g as AgentEventHandler, X as AgentMessageEvent, f as AgentOutputCallback, A as AgentState, K as AgentStateEvent, a0 as AgentTurnEvent, P as AssistantMessageEvent, y as ConversationEndEvent, z as ConversationInterruptedEvent, C as ConversationQueuedEvent, x as ConversationRespondingEvent, v as ConversationStartEvent, w as ConversationThinkingEvent, W as ErrorMessageEvent, H as ErrorOccurredEvent, k as EventHandlerMap, I as InputJsonDeltaEvent, n as MessageDeltaEvent, N as MessageEvent, M as MessageQueue, m as MessageStartEvent, o as MessageStopEvent, R as ReactHandlerMap, j as StateChange, S as StateChangeHandler, u as StateEvent, t as StreamEventType, p as TextDeltaEvent, T as ToEngineEvent, l as ToEngineEventUnion, Q as ToolCallMessageEvent, F as ToolCompletedEvent, D as ToolExecutingEvent, G as ToolFailedEvent, B as ToolPlannedEvent, s as ToolResultEvent, V as ToolResultMessageEvent, q as ToolUseStartEvent, r as ToolUseStopEvent, Z as TurnEvent, _ as TurnRequestEvent, $ as TurnResponseEvent, U as Unsubscribe, O as UserMessageEvent, Y as isMessageEvent, L as isStateEvent, a1 as isTurnEvent } from './Agent-BXUYGlWZ.cjs';
|
|
3
|
+
import { U as UserMessage } from './ToolResultMessage-CRKMSf5d.cjs';
|
|
4
|
+
export { A as AssistantMessage, F as FilePart, I as ImagePart, b as TextPart, c as ThinkingPart, g as TokenUsage, T as ToolCallMessage, d as ToolCallPart, a as ToolResultMessage, f as ToolResultOutput, e as ToolResultPart } from './ToolResultMessage-CRKMSf5d.cjs';
|
|
5
|
+
export { M as Message, a as MessageSubtype } from './Message-Crh81uLL.cjs';
|
|
6
|
+
export { E as ErrorMessage } from './ErrorMessage-BoIh3MIO.cjs';
|
|
7
|
+
export { C as ContentPart, M as MessageRole } from './ContentPart-DEFnYXCU.cjs';
|
|
8
|
+
export { S as StopReason } from './index-CjFNcCxR.cjs';
|
|
9
|
+
import './SystemEvent-CPvvxdMQ.cjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* AgentError - Error types for Agent layer
|
|
13
|
+
*
|
|
14
|
+
* Standardized error structure for agent operations.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Error category
|
|
18
|
+
*/
|
|
19
|
+
type AgentErrorCategory = "network" | "validation" | "system" | "business";
|
|
20
|
+
/**
|
|
21
|
+
* AgentError - Standardized error structure
|
|
22
|
+
*/
|
|
23
|
+
interface AgentError {
|
|
24
|
+
/**
|
|
25
|
+
* Error category
|
|
26
|
+
*/
|
|
27
|
+
category: AgentErrorCategory;
|
|
28
|
+
/**
|
|
29
|
+
* Error code (e.g., "NETWORK_TIMEOUT", "INVALID_INPUT")
|
|
30
|
+
*/
|
|
31
|
+
code: string;
|
|
32
|
+
/**
|
|
33
|
+
* Human-readable error message
|
|
34
|
+
*/
|
|
35
|
+
message: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the error is recoverable
|
|
38
|
+
*/
|
|
39
|
+
recoverable: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Original error (if any)
|
|
42
|
+
*/
|
|
43
|
+
cause?: Error;
|
|
44
|
+
/**
|
|
45
|
+
* Additional context
|
|
46
|
+
*/
|
|
47
|
+
context?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* AgentDriver - Message Processing Interface
|
|
52
|
+
*
|
|
53
|
+
* AgentDriver is a pure message processor.
|
|
54
|
+
* It receives user messages and yields StreamEvents.
|
|
55
|
+
*
|
|
56
|
+
* Key Design:
|
|
57
|
+
* - One Agent = One Driver instance
|
|
58
|
+
* - Driver only handles message processing
|
|
59
|
+
* - Lifecycle management is Container's responsibility
|
|
60
|
+
* - Resume/history is Container's responsibility
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* class ClaudeDriver implements AgentDriver {
|
|
65
|
+
* readonly name = "ClaudeDriver";
|
|
66
|
+
*
|
|
67
|
+
* async *receive(message: UserMessage) {
|
|
68
|
+
* const stream = this.client.messages.stream({
|
|
69
|
+
* model: "claude-sonnet-4-20250514",
|
|
70
|
+
* messages: [{ role: "user", content: message.content }],
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* for await (const chunk of stream) {
|
|
74
|
+
* yield transformToStreamEvent(chunk);
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* interrupt() {
|
|
79
|
+
* this.abortController.abort();
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* AgentDriver interface
|
|
87
|
+
*
|
|
88
|
+
* A message processor that receives user messages and yields StreamEvents.
|
|
89
|
+
* Lifecycle (creation, resume, destruction) is managed by Container.
|
|
90
|
+
*/
|
|
91
|
+
interface AgentDriver {
|
|
92
|
+
/**
|
|
93
|
+
* Driver name (for identification and logging)
|
|
94
|
+
*/
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/**
|
|
97
|
+
* Optional description
|
|
98
|
+
*/
|
|
99
|
+
readonly description?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Receive a user message and yield stream events
|
|
102
|
+
*
|
|
103
|
+
* @param message - User message to process
|
|
104
|
+
* @returns AsyncIterable of StreamEvent
|
|
105
|
+
*/
|
|
106
|
+
receive(message: UserMessage): AsyncIterable<StreamEvent>;
|
|
107
|
+
/**
|
|
108
|
+
* Interrupt the current operation
|
|
109
|
+
*
|
|
110
|
+
* Stops the current receive() operation gracefully.
|
|
111
|
+
* Driver should abort any ongoing requests.
|
|
112
|
+
*/
|
|
113
|
+
interrupt(): void;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* AgentPresenter - Output adapter interface
|
|
118
|
+
*
|
|
119
|
+
* AgentPresenter receives agent outputs and presents them to external systems.
|
|
120
|
+
* Examples: SSE streaming, WebSocket, logging, persistence.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const ssePresenter: AgentPresenter = {
|
|
125
|
+
* name: "SSEPresenter",
|
|
126
|
+
* description: "Forwards stream events via Server-Sent Events",
|
|
127
|
+
*
|
|
128
|
+
* present(agentId, output) {
|
|
129
|
+
* if (output.type === "text_delta") {
|
|
130
|
+
* sseConnection.send(agentId, output);
|
|
131
|
+
* }
|
|
132
|
+
* },
|
|
133
|
+
* };
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* AgentPresenter interface
|
|
139
|
+
*
|
|
140
|
+
* A named, self-describing presenter that receives agent outputs
|
|
141
|
+
* and presents them to external systems.
|
|
142
|
+
*/
|
|
143
|
+
interface AgentPresenter {
|
|
144
|
+
/**
|
|
145
|
+
* Presenter name (for identification and logging)
|
|
146
|
+
*/
|
|
147
|
+
readonly name: string;
|
|
148
|
+
/**
|
|
149
|
+
* Optional description
|
|
150
|
+
*/
|
|
151
|
+
readonly description?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Present an agent output
|
|
154
|
+
*
|
|
155
|
+
* @param agentId - The agent ID
|
|
156
|
+
* @param output - The output to present
|
|
157
|
+
*/
|
|
158
|
+
present(agentId: string, output: AgentOutput): void | Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* CreateAgentOptions - Factory options for creating an AgentEngine
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Options for creating an AgentEngine
|
|
167
|
+
*/
|
|
168
|
+
interface CreateAgentOptions {
|
|
169
|
+
/**
|
|
170
|
+
* Driver - Event producer (LLM interaction)
|
|
171
|
+
*/
|
|
172
|
+
driver: AgentDriver;
|
|
173
|
+
/**
|
|
174
|
+
* Presenter - Event consumer (side effects)
|
|
175
|
+
*/
|
|
176
|
+
presenter: AgentPresenter;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Factory function to create an AgentEngine
|
|
180
|
+
*
|
|
181
|
+
* AgentEngine is a logical processing unit that coordinates:
|
|
182
|
+
* - Driver: produces stream events from LLM
|
|
183
|
+
* - MealyMachine: assembles events (internal, created automatically)
|
|
184
|
+
* - Presenter: consumes processed events
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const engine = createAgent({
|
|
189
|
+
* driver: new ClaudeDriver(config),
|
|
190
|
+
* presenter: new SSEPresenter(connection),
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* engine.on("text_delta", (e) => console.log(e.data.text));
|
|
194
|
+
* await engine.receive("Hello!");
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare function createAgent(options: CreateAgentOptions): AgentEngine;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Engine Event Types (Lightweight)
|
|
201
|
+
*
|
|
202
|
+
* Lightweight event types for AgentEngine internal use.
|
|
203
|
+
* These only contain: type, timestamp, data
|
|
204
|
+
*
|
|
205
|
+
* Full events (with source, category, intent, context) are in:
|
|
206
|
+
* @agentxjs/types/event/agent
|
|
207
|
+
*
|
|
208
|
+
* ## Relationship
|
|
209
|
+
*
|
|
210
|
+
* ```
|
|
211
|
+
* @agentxjs/types/event/agent @agentxjs/types/agent/event
|
|
212
|
+
* (Runtime domain - Full) (Engine domain - Lightweight)
|
|
213
|
+
* ────────────────────────────────────────────────────────────────
|
|
214
|
+
* AgentEvent (SystemEvent) EngineEvent
|
|
215
|
+
* type, timestamp, data type, timestamp, data
|
|
216
|
+
* source, category, intent
|
|
217
|
+
* context
|
|
218
|
+
*
|
|
219
|
+
* TextDeltaEvent TextDeltaEvent
|
|
220
|
+
* (full SystemEvent) = ToEngineEvent<Full>
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @deprecated Use EngineEvent instead
|
|
226
|
+
*/
|
|
227
|
+
type AgentEvent<T extends string = string, D = unknown> = EngineEvent<T, D>;
|
|
228
|
+
|
|
229
|
+
export { type AgentDriver, AgentEngine, type AgentError, type AgentErrorCategory, type AgentEvent, AgentOutput, type AgentPresenter, type CreateAgentOptions, EngineEvent, StreamEvent, UserMessage, createAgent };
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { h as StreamEvent, a as AgentOutput, i as AgentEngine, E as EngineEvent } from './Agent-CaSxMF_E.js';
|
|
2
|
+
export { J as AgentErrorOccurredEvent, g as AgentEventHandler, X as AgentMessageEvent, f as AgentOutputCallback, A as AgentState, K as AgentStateEvent, a0 as AgentTurnEvent, P as AssistantMessageEvent, y as ConversationEndEvent, z as ConversationInterruptedEvent, C as ConversationQueuedEvent, x as ConversationRespondingEvent, v as ConversationStartEvent, w as ConversationThinkingEvent, W as ErrorMessageEvent, H as ErrorOccurredEvent, k as EventHandlerMap, I as InputJsonDeltaEvent, n as MessageDeltaEvent, N as MessageEvent, M as MessageQueue, m as MessageStartEvent, o as MessageStopEvent, R as ReactHandlerMap, j as StateChange, S as StateChangeHandler, u as StateEvent, t as StreamEventType, p as TextDeltaEvent, T as ToEngineEvent, l as ToEngineEventUnion, Q as ToolCallMessageEvent, F as ToolCompletedEvent, D as ToolExecutingEvent, G as ToolFailedEvent, B as ToolPlannedEvent, s as ToolResultEvent, V as ToolResultMessageEvent, q as ToolUseStartEvent, r as ToolUseStopEvent, Z as TurnEvent, _ as TurnRequestEvent, $ as TurnResponseEvent, U as Unsubscribe, O as UserMessageEvent, Y as isMessageEvent, L as isStateEvent, a1 as isTurnEvent } from './Agent-CaSxMF_E.js';
|
|
3
|
+
import { U as UserMessage } from './ToolResultMessage-CDG2L7Zv.js';
|
|
4
|
+
export { A as AssistantMessage, F as FilePart, I as ImagePart, b as TextPart, c as ThinkingPart, g as TokenUsage, T as ToolCallMessage, d as ToolCallPart, a as ToolResultMessage, f as ToolResultOutput, e as ToolResultPart } from './ToolResultMessage-CDG2L7Zv.js';
|
|
5
|
+
export { M as Message, a as MessageSubtype } from './Message-DWQUt647.js';
|
|
6
|
+
export { E as ErrorMessage } from './ErrorMessage-BoIh3MIO.js';
|
|
7
|
+
export { C as ContentPart, M as MessageRole } from './ContentPart-CqOh-rI1.js';
|
|
8
|
+
export { S as StopReason } from './index-usKuk41S.js';
|
|
9
|
+
import './SystemEvent-CPvvxdMQ.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* AgentError - Error types for Agent layer
|
|
13
|
+
*
|
|
14
|
+
* Standardized error structure for agent operations.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Error category
|
|
18
|
+
*/
|
|
19
|
+
type AgentErrorCategory = "network" | "validation" | "system" | "business";
|
|
20
|
+
/**
|
|
21
|
+
* AgentError - Standardized error structure
|
|
22
|
+
*/
|
|
23
|
+
interface AgentError {
|
|
24
|
+
/**
|
|
25
|
+
* Error category
|
|
26
|
+
*/
|
|
27
|
+
category: AgentErrorCategory;
|
|
28
|
+
/**
|
|
29
|
+
* Error code (e.g., "NETWORK_TIMEOUT", "INVALID_INPUT")
|
|
30
|
+
*/
|
|
31
|
+
code: string;
|
|
32
|
+
/**
|
|
33
|
+
* Human-readable error message
|
|
34
|
+
*/
|
|
35
|
+
message: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the error is recoverable
|
|
38
|
+
*/
|
|
39
|
+
recoverable: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Original error (if any)
|
|
42
|
+
*/
|
|
43
|
+
cause?: Error;
|
|
44
|
+
/**
|
|
45
|
+
* Additional context
|
|
46
|
+
*/
|
|
47
|
+
context?: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* AgentDriver - Message Processing Interface
|
|
52
|
+
*
|
|
53
|
+
* AgentDriver is a pure message processor.
|
|
54
|
+
* It receives user messages and yields StreamEvents.
|
|
55
|
+
*
|
|
56
|
+
* Key Design:
|
|
57
|
+
* - One Agent = One Driver instance
|
|
58
|
+
* - Driver only handles message processing
|
|
59
|
+
* - Lifecycle management is Container's responsibility
|
|
60
|
+
* - Resume/history is Container's responsibility
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* class ClaudeDriver implements AgentDriver {
|
|
65
|
+
* readonly name = "ClaudeDriver";
|
|
66
|
+
*
|
|
67
|
+
* async *receive(message: UserMessage) {
|
|
68
|
+
* const stream = this.client.messages.stream({
|
|
69
|
+
* model: "claude-sonnet-4-20250514",
|
|
70
|
+
* messages: [{ role: "user", content: message.content }],
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* for await (const chunk of stream) {
|
|
74
|
+
* yield transformToStreamEvent(chunk);
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* interrupt() {
|
|
79
|
+
* this.abortController.abort();
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* AgentDriver interface
|
|
87
|
+
*
|
|
88
|
+
* A message processor that receives user messages and yields StreamEvents.
|
|
89
|
+
* Lifecycle (creation, resume, destruction) is managed by Container.
|
|
90
|
+
*/
|
|
91
|
+
interface AgentDriver {
|
|
92
|
+
/**
|
|
93
|
+
* Driver name (for identification and logging)
|
|
94
|
+
*/
|
|
95
|
+
readonly name: string;
|
|
96
|
+
/**
|
|
97
|
+
* Optional description
|
|
98
|
+
*/
|
|
99
|
+
readonly description?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Receive a user message and yield stream events
|
|
102
|
+
*
|
|
103
|
+
* @param message - User message to process
|
|
104
|
+
* @returns AsyncIterable of StreamEvent
|
|
105
|
+
*/
|
|
106
|
+
receive(message: UserMessage): AsyncIterable<StreamEvent>;
|
|
107
|
+
/**
|
|
108
|
+
* Interrupt the current operation
|
|
109
|
+
*
|
|
110
|
+
* Stops the current receive() operation gracefully.
|
|
111
|
+
* Driver should abort any ongoing requests.
|
|
112
|
+
*/
|
|
113
|
+
interrupt(): void;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* AgentPresenter - Output adapter interface
|
|
118
|
+
*
|
|
119
|
+
* AgentPresenter receives agent outputs and presents them to external systems.
|
|
120
|
+
* Examples: SSE streaming, WebSocket, logging, persistence.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const ssePresenter: AgentPresenter = {
|
|
125
|
+
* name: "SSEPresenter",
|
|
126
|
+
* description: "Forwards stream events via Server-Sent Events",
|
|
127
|
+
*
|
|
128
|
+
* present(agentId, output) {
|
|
129
|
+
* if (output.type === "text_delta") {
|
|
130
|
+
* sseConnection.send(agentId, output);
|
|
131
|
+
* }
|
|
132
|
+
* },
|
|
133
|
+
* };
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* AgentPresenter interface
|
|
139
|
+
*
|
|
140
|
+
* A named, self-describing presenter that receives agent outputs
|
|
141
|
+
* and presents them to external systems.
|
|
142
|
+
*/
|
|
143
|
+
interface AgentPresenter {
|
|
144
|
+
/**
|
|
145
|
+
* Presenter name (for identification and logging)
|
|
146
|
+
*/
|
|
147
|
+
readonly name: string;
|
|
148
|
+
/**
|
|
149
|
+
* Optional description
|
|
150
|
+
*/
|
|
151
|
+
readonly description?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Present an agent output
|
|
154
|
+
*
|
|
155
|
+
* @param agentId - The agent ID
|
|
156
|
+
* @param output - The output to present
|
|
157
|
+
*/
|
|
158
|
+
present(agentId: string, output: AgentOutput): void | Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* CreateAgentOptions - Factory options for creating an AgentEngine
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Options for creating an AgentEngine
|
|
167
|
+
*/
|
|
168
|
+
interface CreateAgentOptions {
|
|
169
|
+
/**
|
|
170
|
+
* Driver - Event producer (LLM interaction)
|
|
171
|
+
*/
|
|
172
|
+
driver: AgentDriver;
|
|
173
|
+
/**
|
|
174
|
+
* Presenter - Event consumer (side effects)
|
|
175
|
+
*/
|
|
176
|
+
presenter: AgentPresenter;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Factory function to create an AgentEngine
|
|
180
|
+
*
|
|
181
|
+
* AgentEngine is a logical processing unit that coordinates:
|
|
182
|
+
* - Driver: produces stream events from LLM
|
|
183
|
+
* - MealyMachine: assembles events (internal, created automatically)
|
|
184
|
+
* - Presenter: consumes processed events
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const engine = createAgent({
|
|
189
|
+
* driver: new ClaudeDriver(config),
|
|
190
|
+
* presenter: new SSEPresenter(connection),
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* engine.on("text_delta", (e) => console.log(e.data.text));
|
|
194
|
+
* await engine.receive("Hello!");
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare function createAgent(options: CreateAgentOptions): AgentEngine;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Engine Event Types (Lightweight)
|
|
201
|
+
*
|
|
202
|
+
* Lightweight event types for AgentEngine internal use.
|
|
203
|
+
* These only contain: type, timestamp, data
|
|
204
|
+
*
|
|
205
|
+
* Full events (with source, category, intent, context) are in:
|
|
206
|
+
* @agentxjs/types/event/agent
|
|
207
|
+
*
|
|
208
|
+
* ## Relationship
|
|
209
|
+
*
|
|
210
|
+
* ```
|
|
211
|
+
* @agentxjs/types/event/agent @agentxjs/types/agent/event
|
|
212
|
+
* (Runtime domain - Full) (Engine domain - Lightweight)
|
|
213
|
+
* ────────────────────────────────────────────────────────────────
|
|
214
|
+
* AgentEvent (SystemEvent) EngineEvent
|
|
215
|
+
* type, timestamp, data type, timestamp, data
|
|
216
|
+
* source, category, intent
|
|
217
|
+
* context
|
|
218
|
+
*
|
|
219
|
+
* TextDeltaEvent TextDeltaEvent
|
|
220
|
+
* (full SystemEvent) = ToEngineEvent<Full>
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @deprecated Use EngineEvent instead
|
|
226
|
+
*/
|
|
227
|
+
type AgentEvent<T extends string = string, D = unknown> = EngineEvent<T, D>;
|
|
228
|
+
|
|
229
|
+
export { type AgentDriver, AgentEngine, type AgentError, type AgentErrorCategory, type AgentEvent, AgentOutput, type AgentPresenter, type CreateAgentOptions, EngineEvent, StreamEvent, UserMessage, createAgent };
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/agent/event/state/index.ts
|
|
2
|
+
function isStateEvent(event) {
|
|
3
|
+
const stateTypes = [
|
|
4
|
+
"conversation_queued",
|
|
5
|
+
"conversation_start",
|
|
6
|
+
"conversation_thinking",
|
|
7
|
+
"conversation_responding",
|
|
8
|
+
"conversation_end",
|
|
9
|
+
"conversation_interrupted",
|
|
10
|
+
"tool_planned",
|
|
11
|
+
"tool_executing",
|
|
12
|
+
"tool_completed",
|
|
13
|
+
"tool_failed",
|
|
14
|
+
"error_occurred"
|
|
15
|
+
];
|
|
16
|
+
return stateTypes.includes(event.type);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/agent/event/message/index.ts
|
|
20
|
+
function isMessageEvent(event) {
|
|
21
|
+
const messageTypes = [
|
|
22
|
+
"user_message",
|
|
23
|
+
"assistant_message",
|
|
24
|
+
"tool_call_message",
|
|
25
|
+
"tool_result_message",
|
|
26
|
+
"error_message"
|
|
27
|
+
];
|
|
28
|
+
return messageTypes.includes(event.type);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/agent/event/turn/index.ts
|
|
32
|
+
function isTurnEvent(event) {
|
|
33
|
+
const turnTypes = ["turn_request", "turn_response"];
|
|
34
|
+
return turnTypes.includes(event.type);
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
isMessageEvent,
|
|
38
|
+
isStateEvent,
|
|
39
|
+
isTurnEvent
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agent/event/state/index.ts","../src/agent/event/message/index.ts","../src/agent/event/turn/index.ts"],"sourcesContent":["/**\n * Engine State Events (Lightweight)\n *\n * Lightweight state events for AgentEngine internal use.\n * Derived from full AgentStateEvent in @agentxjs/types/event/agent.\n */\n\nimport type {\n AgentStateEvent as FullAgentStateEvent,\n ConversationQueuedEvent as FullConversationQueuedEvent,\n ConversationStartEvent as FullConversationStartEvent,\n ConversationThinkingEvent as FullConversationThinkingEvent,\n ConversationRespondingEvent as FullConversationRespondingEvent,\n ConversationEndEvent as FullConversationEndEvent,\n ConversationInterruptedEvent as FullConversationInterruptedEvent,\n ToolPlannedEvent as FullToolPlannedEvent,\n ToolExecutingEvent as FullToolExecutingEvent,\n ToolCompletedEvent as FullToolCompletedEvent,\n ToolFailedEvent as FullToolFailedEvent,\n ErrorOccurredEvent as FullErrorOccurredEvent,\n} from \"~/event/agent/state\";\nimport type { EngineEvent, ToEngineEvent, ToEngineEventUnion } from \"../EngineEvent\";\n\n// ============================================================================\n// Base Type (for backward compatibility)\n// ============================================================================\n\n/**\n * StateEvent - Base type for state events\n * @deprecated Use specific event types instead\n */\nexport interface StateEvent<T extends string = string, D = unknown> extends EngineEvent<T, D> {}\n\n// ============================================================================\n// Lightweight Event Types\n// ============================================================================\n\nexport type ConversationQueuedEvent = ToEngineEvent<FullConversationQueuedEvent>;\nexport type ConversationStartEvent = ToEngineEvent<FullConversationStartEvent>;\nexport type ConversationThinkingEvent = ToEngineEvent<FullConversationThinkingEvent>;\nexport type ConversationRespondingEvent = ToEngineEvent<FullConversationRespondingEvent>;\nexport type ConversationEndEvent = ToEngineEvent<FullConversationEndEvent>;\nexport type ConversationInterruptedEvent = ToEngineEvent<FullConversationInterruptedEvent>;\nexport type ToolPlannedEvent = ToEngineEvent<FullToolPlannedEvent>;\nexport type ToolExecutingEvent = ToEngineEvent<FullToolExecutingEvent>;\nexport type ToolCompletedEvent = ToEngineEvent<FullToolCompletedEvent>;\nexport type ToolFailedEvent = ToEngineEvent<FullToolFailedEvent>;\nexport type ErrorOccurredEvent = ToEngineEvent<FullErrorOccurredEvent>;\n\n/**\n * Alias for ErrorOccurredEvent (legacy compatibility)\n */\nexport type AgentErrorOccurredEvent = ErrorOccurredEvent;\n\n/**\n * AgentStateEvent - All lightweight state events\n */\nexport type AgentStateEvent = ToEngineEventUnion<FullAgentStateEvent>;\n\n/**\n * Type guard: is this a state event?\n */\nexport function isStateEvent(event: EngineEvent): event is AgentStateEvent {\n const stateTypes = [\n \"conversation_queued\",\n \"conversation_start\",\n \"conversation_thinking\",\n \"conversation_responding\",\n \"conversation_end\",\n \"conversation_interrupted\",\n \"tool_planned\",\n \"tool_executing\",\n \"tool_completed\",\n \"tool_failed\",\n \"error_occurred\",\n ];\n return stateTypes.includes(event.type);\n}\n","/**\n * Engine Message Events (Lightweight)\n *\n * Lightweight message events for AgentEngine internal use.\n * Derived from full AgentMessageEvent in @agentxjs/types/event/agent.\n */\n\nimport type {\n AgentMessageEvent as FullAgentMessageEvent,\n UserMessageEvent as FullUserMessageEvent,\n AssistantMessageEvent as FullAssistantMessageEvent,\n ToolCallMessageEvent as FullToolCallMessageEvent,\n ToolResultMessageEvent as FullToolResultMessageEvent,\n ErrorMessageEvent as FullErrorMessageEvent,\n} from \"~/event/agent/message\";\nimport type { EngineEvent, ToEngineEvent, ToEngineEventUnion } from \"../EngineEvent\";\n\n// Re-export parts (they're not events, just types)\nexport type { ContentPart, ToolCallPart, ToolResultPart } from \"../../message/parts\";\n\n// ============================================================================\n// Base Type (for backward compatibility)\n// ============================================================================\n\n/**\n * MessageEvent - Base type for message events\n * @deprecated Use specific event types instead\n */\nexport interface MessageEvent<T extends string = string, D = unknown> extends EngineEvent<T, D> {}\n\n// ============================================================================\n// Lightweight Event Types\n// ============================================================================\n\nexport type UserMessageEvent = ToEngineEvent<FullUserMessageEvent>;\nexport type AssistantMessageEvent = ToEngineEvent<FullAssistantMessageEvent>;\nexport type ToolCallMessageEvent = ToEngineEvent<FullToolCallMessageEvent>;\nexport type ToolResultMessageEvent = ToEngineEvent<FullToolResultMessageEvent>;\nexport type ErrorMessageEvent = ToEngineEvent<FullErrorMessageEvent>;\n\n/**\n * AgentMessageEvent - All lightweight message events\n */\nexport type AgentMessageEvent = ToEngineEventUnion<FullAgentMessageEvent>;\n\n/**\n * Type guard: is this a message event?\n */\nexport function isMessageEvent(event: EngineEvent): event is AgentMessageEvent {\n const messageTypes = [\n \"user_message\",\n \"assistant_message\",\n \"tool_call_message\",\n \"tool_result_message\",\n \"error_message\",\n ];\n return messageTypes.includes(event.type);\n}\n","/**\n * Engine Turn Events (Lightweight)\n *\n * Lightweight turn events for AgentEngine internal use.\n * Derived from full AgentTurnEvent in @agentxjs/types/event/agent.\n */\n\nimport type {\n AgentTurnEvent as FullAgentTurnEvent,\n TurnRequestEvent as FullTurnRequestEvent,\n TurnResponseEvent as FullTurnResponseEvent,\n TokenUsage,\n} from \"~/event/agent/turn\";\nimport type { EngineEvent, ToEngineEvent, ToEngineEventUnion } from \"../EngineEvent\";\n\n// Re-export TokenUsage (it's not an event, just a type)\nexport type { TokenUsage };\n\n// ============================================================================\n// Base Type (for backward compatibility)\n// ============================================================================\n\n/**\n * TurnEvent - Base type for turn events\n * @deprecated Use specific event types instead\n */\nexport interface TurnEvent<T extends string = string, D = unknown> extends EngineEvent<T, D> {}\n\n// ============================================================================\n// Lightweight Event Types\n// ============================================================================\n\nexport type TurnRequestEvent = ToEngineEvent<FullTurnRequestEvent>;\nexport type TurnResponseEvent = ToEngineEvent<FullTurnResponseEvent>;\n\n/**\n * AgentTurnEvent - All lightweight turn events\n */\nexport type AgentTurnEvent = ToEngineEventUnion<FullAgentTurnEvent>;\n\n/**\n * Type guard: is this a turn event?\n */\nexport function isTurnEvent(event: EngineEvent): event is AgentTurnEvent {\n const turnTypes = [\"turn_request\", \"turn_response\"];\n return turnTypes.includes(event.type);\n}\n"],"mappings":";AA8DO,SAAS,aAAa,OAA8C;AACzE,QAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,WAAW,SAAS,MAAM,IAAI;AACvC;;;AC7BO,SAAS,eAAe,OAAgD;AAC7E,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,aAAa,SAAS,MAAM,IAAI;AACzC;;;ACdO,SAAS,YAAY,OAA6C;AACvE,QAAM,YAAY,CAAC,gBAAgB,eAAe;AAClD,SAAO,UAAU,SAAS,MAAM,IAAI;AACtC;","names":[]}
|
package/dist/agentx.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/agentx/index.ts
|
|
21
|
+
var agentx_exports = {};
|
|
22
|
+
__export(agentx_exports, {
|
|
23
|
+
isLocalConfig: () => isLocalConfig,
|
|
24
|
+
isRemoteConfig: () => isRemoteConfig
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(agentx_exports);
|
|
27
|
+
function isRemoteConfig(config) {
|
|
28
|
+
return "serverUrl" in config && typeof config.serverUrl === "string";
|
|
29
|
+
}
|
|
30
|
+
function isLocalConfig(config) {
|
|
31
|
+
return !isRemoteConfig(config);
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
isLocalConfig,
|
|
36
|
+
isRemoteConfig
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=agentx.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agentx/index.ts"],"sourcesContent":["/**\n * AgentX - Unified High-Level API for AI Agents\n *\n * AgentX provides a simple, consistent API for both local and remote modes.\n * It wraps Runtime and provides the same interface regardless of deployment.\n *\n * ## Two Modes\n *\n * ```\n * Local Mode Remote Mode\n * ─────────────────────────────────────────────────────────\n * AgentX AgentX\n * │ │\n * └── Runtime (embedded) └── WebSocket ──→ Server\n * │ │\n * └── LLM, Storage └── Runtime\n * ```\n *\n * ## API Design\n *\n * All operations use CommandEvent pattern:\n * - `request(type, data)` - Send request, wait for response\n * - `on(type, handler)` - Subscribe to events\n * - `onCommand(type, handler)` - Type-safe command subscription\n *\n * ## Usage\n *\n * ```typescript\n * // Local mode (default)\n * const agentx = await createAgentX();\n *\n * // Local mode with custom LLM and storage\n * const agentx = await createAgentX({\n * llm: { apiKey: \"sk-...\", model: \"claude-opus-4-20250514\" },\n * storage: { driver: \"postgresql\", url: \"postgres://...\" },\n * });\n *\n * // Remote mode\n * const agentx = await createAgentX({ server: \"ws://localhost:5200\" });\n *\n * // Same API for both modes!\n * const res = await agentx.request(\"container_create_request\", {\n * containerId: \"my-container\"\n * });\n *\n * agentx.on(\"text_delta\", (e) => console.log(e.data.text));\n *\n * await agentx.dispose();\n * ```\n *\n * @packageDocumentation\n */\n\nimport type { SystemEvent } from \"~/event/base\";\nimport type {\n CommandEventMap,\n CommandRequestType,\n ResponseEventFor,\n RequestDataFor,\n} from \"~/event/command\";\nimport type { LogLevel, LoggerFactory } from \"~/common/logger\";\n\n// ============================================================================\n// Configuration - Local Mode\n// ============================================================================\n\n/**\n * LLM configuration\n */\nexport interface LLMConfig {\n /**\n * Anthropic API key (required)\n */\n apiKey: string;\n\n /**\n * API base URL\n * @default \"https://api.anthropic.com\"\n */\n baseUrl?: string;\n\n /**\n * Model name\n * @default \"claude-sonnet-4-20250514\"\n */\n model?: string;\n}\n\n/**\n * Storage driver type\n */\nexport type StorageDriver =\n | \"memory\"\n | \"fs\"\n | \"redis\"\n | \"mongodb\"\n | \"sqlite\"\n | \"mysql\"\n | \"postgresql\";\n\n/**\n * Storage configuration\n */\nexport interface StorageConfig {\n /**\n * Storage driver\n * @default \"memory\"\n */\n driver?: StorageDriver;\n\n /**\n * File path (for sqlite, fs drivers)\n * @example \"./data.db\" for sqlite\n * @example \"./data\" for fs\n */\n path?: string;\n\n /**\n * Connection URL (for redis, mongodb, mysql, postgresql)\n * @example \"redis://localhost:6379\"\n * @example \"mongodb://localhost:27017/agentx\"\n * @example \"mysql://user:pass@localhost:3306/agentx\"\n * @example \"postgres://user:pass@localhost:5432/agentx\"\n */\n url?: string;\n}\n\n/**\n * Logger configuration\n */\nexport interface LoggerConfig {\n /**\n * Log level\n * @default LogLevel.INFO\n */\n level?: LogLevel;\n\n /**\n * Custom logger factory implementation\n * If provided, this factory will be used to create all logger instances.\n * If not provided, uses ConsoleLogger with console options.\n */\n factory?: LoggerFactory;\n\n /**\n * Console logger options (only used when factory is not provided)\n */\n console?: {\n /**\n * Enable colored output\n * @default true (Node.js), false (browser)\n */\n colors?: boolean;\n\n /**\n * Include timestamps in log output\n * @default true\n */\n timestamps?: boolean;\n };\n}\n\n/**\n * Local mode configuration\n *\n * Runs AgentX with local runtime, connecting directly to LLM API.\n */\nexport interface LocalConfig {\n /**\n * LLM configuration\n */\n llm?: LLMConfig;\n\n /**\n * Logger configuration\n */\n logger?: LoggerConfig;\n\n /**\n * AgentX base directory for runtime data (containers, workdirs, storage, logs)\n * @default \"~/.agentx\" (user's home directory)\n * @example \"/var/lib/agentx\"\n * @example \"/Users/john/.agentx\"\n *\n * Directory structure:\n * - {agentxDir}/data/agentx.db - SQLite database (auto-configured)\n * - {agentxDir}/logs/ - Log files (if configured)\n * - {agentxDir}/containers/ - Agent workdirs\n */\n agentxDir?: string;\n\n /**\n * HTTP server to attach WebSocket to.\n * If provided, WebSocket upgrade will be handled on the same port.\n * The server should handle authentication before upgrading.\n *\n * @example\n * ```typescript\n * import { createServer } from \"http\";\n * import { Hono } from \"hono\";\n *\n * const app = new Hono();\n * // ... add auth middleware\n *\n * const server = createServer(app.fetch);\n * const agentx = await createAgentX({ server });\n *\n * server.listen(5200);\n * ```\n */\n server?: {\n on(\n event: \"upgrade\",\n listener: (\n request: { url?: string; headers: { host?: string } },\n socket: unknown,\n head: unknown\n ) => void\n ): void;\n };\n}\n\n// ============================================================================\n// Configuration - Remote Mode\n// ============================================================================\n\n/**\n * Remote mode configuration\n *\n * Connects to a remote AgentX server via WebSocket.\n */\nexport interface RemoteConfig {\n /**\n * Remote server URL (WebSocket)\n * @example \"ws://localhost:5200\"\n */\n serverUrl: string;\n}\n\n// ============================================================================\n// Union Type\n// ============================================================================\n\n/**\n * AgentX configuration\n *\n * - LocalConfig: Run with local runtime (default)\n * - RemoteConfig: Connect to remote server\n */\nexport type AgentXConfig = LocalConfig | RemoteConfig;\n\n/**\n * Type guard: is this a remote config?\n */\nexport function isRemoteConfig(config: AgentXConfig): config is RemoteConfig {\n return \"serverUrl\" in config && typeof config.serverUrl === \"string\";\n}\n\n/**\n * Type guard: is this a local config?\n */\nexport function isLocalConfig(config: AgentXConfig): config is LocalConfig {\n return !isRemoteConfig(config);\n}\n\n// ============================================================================\n// Unsubscribe\n// ============================================================================\n\n/**\n * Unsubscribe function\n */\nexport type Unsubscribe = () => void;\n\n// ============================================================================\n// AgentX Interface\n// ============================================================================\n\n/**\n * AgentX - Main API interface\n *\n * Unified API for both local and remote modes.\n */\nexport interface AgentX {\n // ==================== Core API ====================\n\n /**\n * Send a command request and wait for response.\n *\n * @example\n * ```typescript\n * const res = await agentx.request(\"container_create_request\", {\n * containerId: \"my-container\"\n * });\n * console.log(res.data.containerId);\n * ```\n */\n request<T extends CommandRequestType>(\n type: T,\n data: RequestDataFor<T>,\n timeout?: number\n ): Promise<ResponseEventFor<T>>;\n\n /**\n * Subscribe to events.\n *\n * @example\n * ```typescript\n * agentx.on(\"text_delta\", (e) => {\n * process.stdout.write(e.data.text);\n * });\n * ```\n */\n on<T extends string>(type: T, handler: (event: SystemEvent & { type: T }) => void): Unsubscribe;\n\n /**\n * Subscribe to command events with full type safety.\n *\n * @example\n * ```typescript\n * agentx.onCommand(\"container_create_response\", (e) => {\n * console.log(e.data.containerId);\n * });\n * ```\n */\n onCommand<T extends keyof CommandEventMap>(\n type: T,\n handler: (event: CommandEventMap[T]) => void\n ): Unsubscribe;\n\n /**\n * Emit a command event.\n *\n * For fine-grained control. Usually prefer `request()`.\n */\n emitCommand<T extends keyof CommandEventMap>(type: T, data: CommandEventMap[T][\"data\"]): void;\n\n // ==================== Server API (local mode only) ====================\n\n /**\n * Start listening for remote connections.\n *\n * Only available in local mode.\n *\n * @example\n * ```typescript\n * await agentx.listen(5200);\n * console.log(\"Server running on ws://localhost:5200\");\n * ```\n */\n listen(port: number, host?: string): Promise<void>;\n\n /**\n * Stop listening for remote connections.\n */\n close(): Promise<void>;\n\n // ==================== Lifecycle ====================\n\n /**\n * Dispose AgentX and release all resources.\n */\n dispose(): Promise<void>;\n}\n\n// ============================================================================\n// Factory Function\n// ============================================================================\n\n/**\n * Create AgentX instance\n *\n * @example\n * ```typescript\n * // Local mode (default)\n * const agentx = await createAgentX();\n *\n * // Local mode with config\n * const agentx = await createAgentX({\n * llm: { apiKey: \"sk-...\" },\n * storage: { driver: \"sqlite\", path: \"./data.db\" },\n * });\n *\n * // Remote mode\n * const agentx = await createAgentX({ server: \"ws://localhost:5200\" });\n * ```\n */\nexport declare function createAgentX(config?: AgentXConfig): Promise<AgentX>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8PO,SAAS,eAAe,QAA8C;AAC3E,SAAO,eAAe,UAAU,OAAO,OAAO,cAAc;AAC9D;AAKO,SAAS,cAAc,QAA6C;AACzE,SAAO,CAAC,eAAe,MAAM;AAC/B;","names":[]}
|