@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.
Files changed (86) hide show
  1. package/dist/Agent-BXUYGlWZ.d.cts +510 -0
  2. package/dist/Agent-CaSxMF_E.d.ts +510 -0
  3. package/dist/CommandEvent-CbXzPolX.d.ts +495 -0
  4. package/dist/CommandEvent-DCdk7lzX.d.cts +495 -0
  5. package/dist/Container-DR-1g44i.d.ts +641 -0
  6. package/dist/Container-dBDOcjhk.d.cts +641 -0
  7. package/dist/ContentPart-CqOh-rI1.d.ts +19 -0
  8. package/dist/ContentPart-DEFnYXCU.d.cts +19 -0
  9. package/dist/DriveableEvent-Bj7nn-Uk.d.ts +161 -0
  10. package/dist/DriveableEvent-CCMC1h_C.d.cts +161 -0
  11. package/dist/ErrorMessage-BoIh3MIO.d.cts +24 -0
  12. package/dist/ErrorMessage-BoIh3MIO.d.ts +24 -0
  13. package/dist/ImageRecord-Cn0VcJWk.d.cts +71 -0
  14. package/dist/ImageRecord-Cn0VcJWk.d.ts +71 -0
  15. package/dist/LoggerFactory-DZtw0M7U.d.cts +129 -0
  16. package/dist/LoggerFactory-DZtw0M7U.d.ts +129 -0
  17. package/dist/Message-Crh81uLL.d.cts +45 -0
  18. package/dist/Message-DWQUt647.d.ts +45 -0
  19. package/dist/Persistence-BQkdKomV.d.ts +230 -0
  20. package/dist/Persistence-Dr70FEBh.d.cts +230 -0
  21. package/dist/StopReason-D4DthB1h.d.cts +39 -0
  22. package/dist/StopReason-D4DthB1h.d.ts +39 -0
  23. package/dist/SystemEvent-CPvvxdMQ.d.cts +159 -0
  24. package/dist/SystemEvent-CPvvxdMQ.d.ts +159 -0
  25. package/dist/ToolResultMessage-CDG2L7Zv.d.ts +332 -0
  26. package/dist/ToolResultMessage-CRKMSf5d.d.cts +332 -0
  27. package/dist/agent-internal.cjs +19 -0
  28. package/dist/agent-internal.cjs.map +1 -0
  29. package/dist/agent-internal.d.cts +52 -0
  30. package/dist/agent-internal.d.ts +52 -0
  31. package/dist/agent-internal.js +1 -0
  32. package/dist/agent-internal.js.map +1 -0
  33. package/dist/agent.cjs +70 -0
  34. package/dist/agent.cjs.map +1 -0
  35. package/dist/agent.d.cts +229 -0
  36. package/dist/agent.d.ts +229 -0
  37. package/dist/agent.js +41 -0
  38. package/dist/agent.js.map +1 -0
  39. package/dist/agentx.cjs +38 -0
  40. package/dist/agentx.cjs.map +1 -0
  41. package/dist/agentx.d.cts +311 -0
  42. package/dist/agentx.d.ts +311 -0
  43. package/dist/agentx.js +12 -0
  44. package/dist/agentx.js.map +1 -0
  45. package/dist/chunk-2QHAIM3V.js +1 -0
  46. package/dist/chunk-2QHAIM3V.js.map +1 -0
  47. package/dist/common.cjs +19 -0
  48. package/dist/common.cjs.map +1 -0
  49. package/dist/common.d.cts +43 -0
  50. package/dist/common.d.ts +43 -0
  51. package/dist/common.js +2 -0
  52. package/dist/common.js.map +1 -0
  53. package/dist/event.cjs +184 -0
  54. package/dist/event.cjs.map +1 -0
  55. package/dist/event.d.cts +769 -0
  56. package/dist/event.d.ts +769 -0
  57. package/dist/event.js +134 -0
  58. package/dist/event.js.map +1 -0
  59. package/dist/index-CjFNcCxR.d.cts +299 -0
  60. package/dist/index-usKuk41S.d.ts +299 -0
  61. package/dist/index.cjs +2 -185
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +8 -5267
  64. package/dist/index.d.ts +8 -5267
  65. package/dist/index.js +1 -150
  66. package/dist/index.js.map +1 -1
  67. package/dist/network.cjs +19 -0
  68. package/dist/network.cjs.map +1 -0
  69. package/dist/network.d.cts +168 -0
  70. package/dist/network.d.ts +168 -0
  71. package/dist/network.js +1 -0
  72. package/dist/network.js.map +1 -0
  73. package/dist/runtime-internal.cjs +19 -0
  74. package/dist/runtime-internal.cjs.map +1 -0
  75. package/dist/runtime-internal.d.cts +943 -0
  76. package/dist/runtime-internal.d.ts +943 -0
  77. package/dist/runtime-internal.js +1 -0
  78. package/dist/runtime-internal.js.map +1 -0
  79. package/dist/runtime.cjs +19 -0
  80. package/dist/runtime.cjs.map +1 -0
  81. package/dist/runtime.d.cts +217 -0
  82. package/dist/runtime.d.ts +217 -0
  83. package/dist/runtime.js +1 -0
  84. package/dist/runtime.js.map +1 -0
  85. package/package.json +82 -10
  86. package/LICENSE +0 -21
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Reason why the LLM stopped generating
3
+ *
4
+ * Based on common stop reasons across multiple LLM providers:
5
+ * - Anthropic Claude: end_turn, max_tokens, tool_use, stop_sequence
6
+ * - OpenAI: stop, length, tool_calls, content_filter
7
+ * - Vercel AI SDK: stop, length, tool-calls, content-filter, error, other
8
+ */
9
+ type StopReason =
10
+ /**
11
+ * Natural completion - model decided to stop
12
+ */
13
+ "end_turn"
14
+ /**
15
+ * Reached maximum token limit
16
+ */
17
+ | "max_tokens"
18
+ /**
19
+ * Model requested tool usage
20
+ */
21
+ | "tool_use"
22
+ /**
23
+ * Encountered a custom stop sequence
24
+ */
25
+ | "stop_sequence"
26
+ /**
27
+ * Content filter triggered
28
+ */
29
+ | "content_filter"
30
+ /**
31
+ * Error occurred during generation
32
+ */
33
+ | "error"
34
+ /**
35
+ * Other/unknown reason
36
+ */
37
+ | "other";
38
+
39
+ export type { StopReason as S };
@@ -0,0 +1,159 @@
1
+ /**
2
+ * SystemEvent - Base interface for all events in the system
3
+ *
4
+ * Unified Event Structure:
5
+ * ```
6
+ * SystemEvent
7
+ * │
8
+ * │ All events have: type, timestamp, data, source, category, intent
9
+ * │
10
+ * ├── source: "command" ← API operations (request/response)
11
+ * │ ├── category: "request" → container_create_request, agent_run_request...
12
+ * │ └── category: "response" → container_create_response, agent_run_response...
13
+ * │
14
+ * ├── source: "environment" ← External world (Claude API, Network)
15
+ * │ ├── category: "stream" → message_start, text_delta, message_stop, tool_call...
16
+ * │ └── category: "connection"→ connected, disconnected, reconnecting
17
+ * │
18
+ * ├── source: "container" ← Container operations
19
+ * │ └── category: "lifecycle" → container_created, container_destroyed, agent_registered...
20
+ * │
21
+ * ├── source: "session" ← Session operations
22
+ * │ ├── category: "lifecycle" → session_created, session_destroyed
23
+ * │ ├── category: "persist" → session_saved, message_persisted
24
+ * │ └── category: "action" → session_resumed, session_forked
25
+ * │
26
+ * ├── source: "sandbox" ← Sandbox resources
27
+ * │ ├── category: "workdir" → file_read, file_written
28
+ * │ └── category: "mcp" → tool_execute, mcp_server_connected
29
+ * │
30
+ * └── source: "agent" ← Agent internal
31
+ * ├── category: "stream" → (forwarded from environment)
32
+ * ├── category: "state" → state transitions
33
+ * ├── category: "message" → complete messages
34
+ * └── category: "turn" → conversation turns
35
+ * ```
36
+ *
37
+ * Design Principles:
38
+ * - Unified: All events share the same base structure
39
+ * - Self-describing: source/category/intent tell you everything
40
+ * - Filterable: Easy to subscribe by source, category, or type
41
+ */
42
+ /**
43
+ * Event source - where the event originated
44
+ */
45
+ type EventSource = "environment" | "agent" | "session" | "container" | "sandbox" | "command";
46
+ /**
47
+ * Event intent - what the event represents
48
+ */
49
+ type EventIntent = "request" | "result" | "notification";
50
+ /**
51
+ * Event category - fine-grained classification within source
52
+ */
53
+ type EventCategory = "stream" | "connection" | "state" | "message" | "turn" | "error" | "lifecycle" | "persist" | "action" | "workdir" | "mcp" | "request" | "response";
54
+ /**
55
+ * EventContext - Scope information attached to events
56
+ */
57
+ interface EventContext {
58
+ /**
59
+ * Container ID (isolation boundary)
60
+ */
61
+ containerId?: string;
62
+ /**
63
+ * Image ID (persistent conversation identity)
64
+ */
65
+ imageId?: string;
66
+ /**
67
+ * Agent ID (if event is agent-scoped)
68
+ */
69
+ agentId?: string;
70
+ /**
71
+ * Session ID (if event is session-scoped)
72
+ */
73
+ sessionId?: string;
74
+ /**
75
+ * Turn ID (for correlating events within a single turn)
76
+ * A turn = one user message + assistant response cycle
77
+ */
78
+ turnId?: string;
79
+ /**
80
+ * Correlation ID (for request-response tracking)
81
+ */
82
+ correlationId?: string;
83
+ }
84
+ /**
85
+ * SystemEvent - Base interface for ALL events in the system
86
+ *
87
+ * Every event has:
88
+ * - type: What happened (e.g., "text_delta", "session_saved")
89
+ * - timestamp: When it happened
90
+ * - data: Event payload
91
+ * - source: Where it came from
92
+ * - category: What kind of event
93
+ * - intent: What it means (notification/request/result)
94
+ * - context: Optional scope information
95
+ * - broadcastable: Whether to broadcast to external clients (default: true)
96
+ */
97
+ interface SystemEvent<T extends string = string, D = unknown, S extends EventSource = EventSource, C extends EventCategory = EventCategory, I extends EventIntent = EventIntent> {
98
+ /**
99
+ * Event type identifier (e.g., "text_delta", "session_saved")
100
+ */
101
+ readonly type: T;
102
+ /**
103
+ * Event timestamp (Unix milliseconds)
104
+ */
105
+ readonly timestamp: number;
106
+ /**
107
+ * Event payload data
108
+ */
109
+ readonly data: D;
110
+ /**
111
+ * Event source - where the event originated
112
+ */
113
+ readonly source: S;
114
+ /**
115
+ * Event category - fine-grained classification
116
+ */
117
+ readonly category: C;
118
+ /**
119
+ * Event intent - what the event represents
120
+ */
121
+ readonly intent: I;
122
+ /**
123
+ * Event context - scope information (optional)
124
+ */
125
+ readonly context?: EventContext;
126
+ /**
127
+ * Whether to broadcast this event to external clients (SSE/WebSocket)
128
+ *
129
+ * - true or undefined: Broadcast to all external clients
130
+ * - false: Only consumed internally, not broadcast
131
+ *
132
+ * Used for internal events like DriveableEvent that should be
133
+ * processed by the engine but not sent directly to clients.
134
+ * @default true
135
+ */
136
+ readonly broadcastable?: boolean;
137
+ }
138
+ /**
139
+ * Check if event is from a specific source
140
+ */
141
+ declare function isFromSource<S extends EventSource>(event: SystemEvent, source: S): event is SystemEvent<string, unknown, S>;
142
+ /**
143
+ * Check if event has a specific intent
144
+ */
145
+ declare function hasIntent<I extends EventIntent>(event: SystemEvent, intent: I): event is SystemEvent<string, unknown, EventSource, EventCategory, I>;
146
+ /**
147
+ * Check if event is a request
148
+ */
149
+ declare function isRequest(event: SystemEvent): boolean;
150
+ /**
151
+ * Check if event is a result
152
+ */
153
+ declare function isResult(event: SystemEvent): boolean;
154
+ /**
155
+ * Check if event is a notification
156
+ */
157
+ declare function isNotification(event: SystemEvent): boolean;
158
+
159
+ export { type EventSource as E, type SystemEvent as S, type EventIntent as a, type EventCategory as b, type EventContext as c, isRequest as d, isResult as e, isNotification as f, hasIntent as h, isFromSource as i };
@@ -0,0 +1,159 @@
1
+ /**
2
+ * SystemEvent - Base interface for all events in the system
3
+ *
4
+ * Unified Event Structure:
5
+ * ```
6
+ * SystemEvent
7
+ * │
8
+ * │ All events have: type, timestamp, data, source, category, intent
9
+ * │
10
+ * ├── source: "command" ← API operations (request/response)
11
+ * │ ├── category: "request" → container_create_request, agent_run_request...
12
+ * │ └── category: "response" → container_create_response, agent_run_response...
13
+ * │
14
+ * ├── source: "environment" ← External world (Claude API, Network)
15
+ * │ ├── category: "stream" → message_start, text_delta, message_stop, tool_call...
16
+ * │ └── category: "connection"→ connected, disconnected, reconnecting
17
+ * │
18
+ * ├── source: "container" ← Container operations
19
+ * │ └── category: "lifecycle" → container_created, container_destroyed, agent_registered...
20
+ * │
21
+ * ├── source: "session" ← Session operations
22
+ * │ ├── category: "lifecycle" → session_created, session_destroyed
23
+ * │ ├── category: "persist" → session_saved, message_persisted
24
+ * │ └── category: "action" → session_resumed, session_forked
25
+ * │
26
+ * ├── source: "sandbox" ← Sandbox resources
27
+ * │ ├── category: "workdir" → file_read, file_written
28
+ * │ └── category: "mcp" → tool_execute, mcp_server_connected
29
+ * │
30
+ * └── source: "agent" ← Agent internal
31
+ * ├── category: "stream" → (forwarded from environment)
32
+ * ├── category: "state" → state transitions
33
+ * ├── category: "message" → complete messages
34
+ * └── category: "turn" → conversation turns
35
+ * ```
36
+ *
37
+ * Design Principles:
38
+ * - Unified: All events share the same base structure
39
+ * - Self-describing: source/category/intent tell you everything
40
+ * - Filterable: Easy to subscribe by source, category, or type
41
+ */
42
+ /**
43
+ * Event source - where the event originated
44
+ */
45
+ type EventSource = "environment" | "agent" | "session" | "container" | "sandbox" | "command";
46
+ /**
47
+ * Event intent - what the event represents
48
+ */
49
+ type EventIntent = "request" | "result" | "notification";
50
+ /**
51
+ * Event category - fine-grained classification within source
52
+ */
53
+ type EventCategory = "stream" | "connection" | "state" | "message" | "turn" | "error" | "lifecycle" | "persist" | "action" | "workdir" | "mcp" | "request" | "response";
54
+ /**
55
+ * EventContext - Scope information attached to events
56
+ */
57
+ interface EventContext {
58
+ /**
59
+ * Container ID (isolation boundary)
60
+ */
61
+ containerId?: string;
62
+ /**
63
+ * Image ID (persistent conversation identity)
64
+ */
65
+ imageId?: string;
66
+ /**
67
+ * Agent ID (if event is agent-scoped)
68
+ */
69
+ agentId?: string;
70
+ /**
71
+ * Session ID (if event is session-scoped)
72
+ */
73
+ sessionId?: string;
74
+ /**
75
+ * Turn ID (for correlating events within a single turn)
76
+ * A turn = one user message + assistant response cycle
77
+ */
78
+ turnId?: string;
79
+ /**
80
+ * Correlation ID (for request-response tracking)
81
+ */
82
+ correlationId?: string;
83
+ }
84
+ /**
85
+ * SystemEvent - Base interface for ALL events in the system
86
+ *
87
+ * Every event has:
88
+ * - type: What happened (e.g., "text_delta", "session_saved")
89
+ * - timestamp: When it happened
90
+ * - data: Event payload
91
+ * - source: Where it came from
92
+ * - category: What kind of event
93
+ * - intent: What it means (notification/request/result)
94
+ * - context: Optional scope information
95
+ * - broadcastable: Whether to broadcast to external clients (default: true)
96
+ */
97
+ interface SystemEvent<T extends string = string, D = unknown, S extends EventSource = EventSource, C extends EventCategory = EventCategory, I extends EventIntent = EventIntent> {
98
+ /**
99
+ * Event type identifier (e.g., "text_delta", "session_saved")
100
+ */
101
+ readonly type: T;
102
+ /**
103
+ * Event timestamp (Unix milliseconds)
104
+ */
105
+ readonly timestamp: number;
106
+ /**
107
+ * Event payload data
108
+ */
109
+ readonly data: D;
110
+ /**
111
+ * Event source - where the event originated
112
+ */
113
+ readonly source: S;
114
+ /**
115
+ * Event category - fine-grained classification
116
+ */
117
+ readonly category: C;
118
+ /**
119
+ * Event intent - what the event represents
120
+ */
121
+ readonly intent: I;
122
+ /**
123
+ * Event context - scope information (optional)
124
+ */
125
+ readonly context?: EventContext;
126
+ /**
127
+ * Whether to broadcast this event to external clients (SSE/WebSocket)
128
+ *
129
+ * - true or undefined: Broadcast to all external clients
130
+ * - false: Only consumed internally, not broadcast
131
+ *
132
+ * Used for internal events like DriveableEvent that should be
133
+ * processed by the engine but not sent directly to clients.
134
+ * @default true
135
+ */
136
+ readonly broadcastable?: boolean;
137
+ }
138
+ /**
139
+ * Check if event is from a specific source
140
+ */
141
+ declare function isFromSource<S extends EventSource>(event: SystemEvent, source: S): event is SystemEvent<string, unknown, S>;
142
+ /**
143
+ * Check if event has a specific intent
144
+ */
145
+ declare function hasIntent<I extends EventIntent>(event: SystemEvent, intent: I): event is SystemEvent<string, unknown, EventSource, EventCategory, I>;
146
+ /**
147
+ * Check if event is a request
148
+ */
149
+ declare function isRequest(event: SystemEvent): boolean;
150
+ /**
151
+ * Check if event is a result
152
+ */
153
+ declare function isResult(event: SystemEvent): boolean;
154
+ /**
155
+ * Check if event is a notification
156
+ */
157
+ declare function isNotification(event: SystemEvent): boolean;
158
+
159
+ export { type EventSource as E, type SystemEvent as S, type EventIntent as a, type EventCategory as b, type EventContext as c, isRequest as d, isResult as e, isNotification as f, hasIntent as h, isFromSource as i };
@@ -0,0 +1,332 @@
1
+ import { S as SystemEvent, c as EventContext } from './SystemEvent-CPvvxdMQ.js';
2
+
3
+ /**
4
+ * Text Part
5
+ *
6
+ * Plain text content in a message.
7
+ */
8
+ interface TextPart {
9
+ /** Content type discriminator */
10
+ type: "text";
11
+ /** The text content (supports Markdown) */
12
+ text: string;
13
+ }
14
+
15
+ /**
16
+ * Image Part
17
+ *
18
+ * Image content in a message.
19
+ */
20
+ interface ImagePart {
21
+ /** Content type discriminator */
22
+ type: "image";
23
+ /** Image data (base64-encoded string or URL) */
24
+ data: string;
25
+ /** Image MIME type */
26
+ mediaType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
27
+ /** Optional image name/filename */
28
+ name?: string;
29
+ }
30
+
31
+ /**
32
+ * File Part
33
+ *
34
+ * File attachment in a message (PDF, documents, etc.).
35
+ */
36
+ interface FilePart {
37
+ /** Content type discriminator */
38
+ type: "file";
39
+ /** File data (base64-encoded string or URL) */
40
+ data: string;
41
+ /** File MIME type (IANA media type) */
42
+ mediaType: string;
43
+ /** Optional filename */
44
+ filename?: string;
45
+ }
46
+
47
+ /**
48
+ * User Message
49
+ *
50
+ * Message sent by the user.
51
+ * Can contain simple text or rich content (text, images, files).
52
+ */
53
+ interface UserMessage {
54
+ /** Unique identifier */
55
+ id: string;
56
+ /** Message role */
57
+ role: "user";
58
+ /** Message subtype for serialization */
59
+ subtype: "user";
60
+ /** Message content - can be simple string or array of parts */
61
+ content: string | Array<TextPart | ImagePart | FilePart>;
62
+ /** When this message was created (Unix timestamp in milliseconds) */
63
+ timestamp: number;
64
+ /** Parent message ID for threading (optional) */
65
+ parentId?: string;
66
+ }
67
+
68
+ /**
69
+ * Thinking Part
70
+ *
71
+ * AI's reasoning/thinking process (extended thinking).
72
+ */
73
+ interface ThinkingPart {
74
+ /** Content type discriminator */
75
+ type: "thinking";
76
+ /** The reasoning text */
77
+ reasoning: string;
78
+ /** Tokens used for thinking (optional) */
79
+ tokenCount?: number;
80
+ }
81
+
82
+ /**
83
+ * BaseAgentEvent - Base type for all Agent domain events
84
+ *
85
+ * All Agent events have:
86
+ * - source: "agent"
87
+ * - category: stream | state | message | turn
88
+ * - intent: "notification"
89
+ */
90
+
91
+ /**
92
+ * Agent event categories
93
+ */
94
+ type AgentEventCategory = "stream" | "state" | "message" | "turn";
95
+ /**
96
+ * BaseAgentEvent - Base interface for all Agent events
97
+ *
98
+ * Extends SystemEvent with fixed source and intent.
99
+ */
100
+ interface BaseAgentEvent<T extends string, D, C extends AgentEventCategory> extends SystemEvent<T, D, "agent", C, "notification"> {
101
+ /**
102
+ * Runtime context (optional, added by Presenter)
103
+ */
104
+ readonly context?: EventContext;
105
+ }
106
+
107
+ /**
108
+ * Agent Turn Events
109
+ *
110
+ * Turn-level events for analytics and billing.
111
+ * A turn = one user message + assistant response cycle.
112
+ * - source: "agent"
113
+ * - category: "turn"
114
+ * - intent: "notification"
115
+ */
116
+
117
+ /**
118
+ * Base type for turn events
119
+ */
120
+ interface AgentTurnEventBase<T extends string, D> extends BaseAgentEvent<T, D, "turn"> {
121
+ }
122
+ /**
123
+ * Token usage information
124
+ */
125
+ interface TokenUsage {
126
+ inputTokens: number;
127
+ outputTokens: number;
128
+ totalTokens?: number;
129
+ }
130
+ /**
131
+ * TurnRequestEvent - Turn started (user message received)
132
+ */
133
+ interface TurnRequestEvent extends AgentTurnEventBase<"turn_request", {
134
+ turnId: string;
135
+ messageId: string;
136
+ content: string;
137
+ timestamp: number;
138
+ }> {
139
+ }
140
+ /**
141
+ * TurnResponseEvent - Turn completed (assistant response finished)
142
+ */
143
+ interface TurnResponseEvent extends AgentTurnEventBase<"turn_response", {
144
+ turnId: string;
145
+ messageId: string;
146
+ duration: number;
147
+ usage?: TokenUsage;
148
+ model?: string;
149
+ stopReason?: string;
150
+ timestamp: number;
151
+ }> {
152
+ }
153
+ /**
154
+ * AgentTurnEvent - All turn events
155
+ */
156
+ type AgentTurnEvent = TurnRequestEvent | TurnResponseEvent;
157
+ /**
158
+ * AgentTurnEventType - String literal union
159
+ */
160
+ type AgentTurnEventType = AgentTurnEvent["type"];
161
+ /**
162
+ * Type guard: is this a turn event?
163
+ */
164
+ declare function isAgentTurnEvent(event: {
165
+ source?: string;
166
+ category?: string;
167
+ }): event is AgentTurnEvent;
168
+
169
+ /**
170
+ * Assistant Message
171
+ *
172
+ * Message generated by the AI assistant.
173
+ * Contains text, thinking process, or files.
174
+ *
175
+ * Note: Tool calls are separate - use ToolCallMessage for tool invocations.
176
+ */
177
+ interface AssistantMessage {
178
+ /** Unique identifier */
179
+ id: string;
180
+ /** Message role */
181
+ role: "assistant";
182
+ /** Message subtype for serialization */
183
+ subtype: "assistant";
184
+ /** Message content - can be simple string or array of parts */
185
+ content: string | Array<TextPart | ThinkingPart | FilePart>;
186
+ /** When this message was created (Unix timestamp in milliseconds) */
187
+ timestamp: number;
188
+ /** Parent message ID for threading (optional) */
189
+ parentId?: string;
190
+ /** Token usage for this AI response (optional) */
191
+ usage?: TokenUsage;
192
+ }
193
+
194
+ /**
195
+ * Tool Call Part
196
+ *
197
+ * AI's request to invoke a tool.
198
+ */
199
+ interface ToolCallPart {
200
+ /** Content type discriminator */
201
+ type: "tool-call";
202
+ /** Unique identifier for this tool call */
203
+ id: string;
204
+ /** Tool name */
205
+ name: string;
206
+ /** Tool input parameters */
207
+ input: Record<string, unknown>;
208
+ }
209
+
210
+ /**
211
+ * Tool Call Message
212
+ *
213
+ * Represents AI's request to invoke a tool.
214
+ * Emitted when tool call parameters are fully assembled.
215
+ *
216
+ * Subject: Assistant (AI decided to call a tool)
217
+ * Timing: At tool_use_content_block_stop
218
+ */
219
+
220
+ /**
221
+ * Tool Call Message
222
+ */
223
+ interface ToolCallMessage {
224
+ /** Unique message identifier */
225
+ id: string;
226
+ /** Message role - assistant initiates tool calls */
227
+ role: "assistant";
228
+ /** Message subtype for serialization */
229
+ subtype: "tool-call";
230
+ /** Tool call details */
231
+ toolCall: ToolCallPart;
232
+ /** When this message was created (Unix timestamp in milliseconds) */
233
+ timestamp: number;
234
+ /** Parent message ID (the assistant message that triggered this) */
235
+ parentId?: string;
236
+ }
237
+
238
+ /**
239
+ * Tool Result Output
240
+ *
241
+ * Enhanced tool result format supporting multiple output types.
242
+ * Based on Vercel AI SDK and industry best practices.
243
+ */
244
+ type ToolResultOutput =
245
+ /**
246
+ * Plain text result
247
+ */
248
+ {
249
+ type: "text";
250
+ value: string;
251
+ }
252
+ /**
253
+ * JSON result
254
+ */
255
+ | {
256
+ type: "json";
257
+ value: unknown;
258
+ }
259
+ /**
260
+ * Text error
261
+ */
262
+ | {
263
+ type: "error-text";
264
+ value: string;
265
+ }
266
+ /**
267
+ * JSON error
268
+ */
269
+ | {
270
+ type: "error-json";
271
+ value: unknown;
272
+ }
273
+ /**
274
+ * User denied tool execution
275
+ */
276
+ | {
277
+ type: "execution-denied";
278
+ reason?: string;
279
+ }
280
+ /**
281
+ * Rich content (multiple parts)
282
+ */
283
+ | {
284
+ type: "content";
285
+ value: Array<TextPart | ImagePart | FilePart>;
286
+ };
287
+
288
+ /**
289
+ * Tool Result Part
290
+ *
291
+ * Result of tool execution.
292
+ */
293
+ interface ToolResultPart {
294
+ /** Content type discriminator */
295
+ type: "tool-result";
296
+ /** Tool call ID this result corresponds to */
297
+ id: string;
298
+ /** Tool name */
299
+ name: string;
300
+ /** Tool execution output */
301
+ output: ToolResultOutput;
302
+ }
303
+
304
+ /**
305
+ * Tool Result Message
306
+ *
307
+ * Represents the result of tool execution.
308
+ * Emitted after tool execution completes.
309
+ *
310
+ * Subject: Tool (execution completed with result)
311
+ * Timing: At tool_result event
312
+ */
313
+
314
+ /**
315
+ * Tool Result Message
316
+ */
317
+ interface ToolResultMessage {
318
+ /** Unique message identifier */
319
+ id: string;
320
+ /** Message role - tool returns results */
321
+ role: "tool";
322
+ /** Message subtype for serialization */
323
+ subtype: "tool-result";
324
+ /** Tool result details */
325
+ toolResult: ToolResultPart;
326
+ /** ID of the corresponding tool call */
327
+ toolCallId: string;
328
+ /** When this message was created (Unix timestamp in milliseconds) */
329
+ timestamp: number;
330
+ }
331
+
332
+ export { type AssistantMessage as A, type BaseAgentEvent as B, type FilePart as F, type ImagePart as I, type ToolCallMessage as T, type UserMessage as U, type ToolResultMessage as a, type TextPart as b, type ThinkingPart as c, type ToolCallPart as d, type ToolResultPart as e, type ToolResultOutput as f, type TokenUsage as g, type AgentTurnEvent as h, type TurnRequestEvent as i, type TurnResponseEvent as j, type AgentEventCategory as k, type AgentTurnEventBase as l, type AgentTurnEventType as m, isAgentTurnEvent as n };