@enclave-vm/types 0.0.1

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.
@@ -0,0 +1,299 @@
1
+ /**
2
+ * @enclave-vm/types - Stream event definitions
3
+ *
4
+ * All event types that can be sent over the streaming protocol.
5
+ */
6
+ import type { ProtocolVersion, SessionId, CallId, ErrorInfo, LogLevel } from './protocol.js';
7
+ /**
8
+ * Base event structure shared by all stream events.
9
+ */
10
+ export interface BaseEvent {
11
+ /** Protocol version for compatibility checking */
12
+ protocolVersion: ProtocolVersion;
13
+ /** Session identifier */
14
+ sessionId: SessionId;
15
+ /** Monotonically increasing sequence number */
16
+ seq: number;
17
+ }
18
+ /**
19
+ * Event type discriminator.
20
+ */
21
+ export declare const EventType: {
22
+ /** Session initialization */
23
+ readonly SessionInit: "session_init";
24
+ /** Standard output chunk */
25
+ readonly Stdout: "stdout";
26
+ /** Log message */
27
+ readonly Log: "log";
28
+ /** Tool call request from runtime */
29
+ readonly ToolCall: "tool_call";
30
+ /** Tool result acknowledgment */
31
+ readonly ToolResultApplied: "tool_result_applied";
32
+ /** Session completed */
33
+ readonly Final: "final";
34
+ /** Keep-alive heartbeat */
35
+ readonly Heartbeat: "heartbeat";
36
+ /** Error event */
37
+ readonly Error: "error";
38
+ /** Encrypted envelope (wraps other events) */
39
+ readonly Encrypted: "enc";
40
+ };
41
+ export type EventType = (typeof EventType)[keyof typeof EventType];
42
+ /**
43
+ * Encryption configuration in session init.
44
+ */
45
+ export interface EncryptionConfig {
46
+ /** Whether encryption is enabled for this session */
47
+ enabled: boolean;
48
+ /** Key ID for the session encryption key */
49
+ keyId?: string;
50
+ }
51
+ /**
52
+ * Session initialization event payload.
53
+ */
54
+ export interface SessionInitPayload {
55
+ /** URL to cancel the session */
56
+ cancelUrl: string;
57
+ /** Session expiration timestamp (ISO 8601) */
58
+ expiresAt: string;
59
+ /** Encryption configuration */
60
+ encryption: EncryptionConfig;
61
+ /** Optional replay URL for reconnection */
62
+ replayUrl?: string;
63
+ }
64
+ /**
65
+ * Session initialization event.
66
+ * First event sent after session creation.
67
+ */
68
+ export interface SessionInitEvent extends BaseEvent {
69
+ type: typeof EventType.SessionInit;
70
+ payload: SessionInitPayload;
71
+ }
72
+ /**
73
+ * Stdout event payload.
74
+ */
75
+ export interface StdoutPayload {
76
+ /** Output chunk (text) */
77
+ chunk: string;
78
+ }
79
+ /**
80
+ * Standard output event.
81
+ * Emitted when runtime code writes to stdout.
82
+ */
83
+ export interface StdoutEvent extends BaseEvent {
84
+ type: typeof EventType.Stdout;
85
+ payload: StdoutPayload;
86
+ }
87
+ /**
88
+ * Log event payload.
89
+ */
90
+ export interface LogPayload {
91
+ /** Log level */
92
+ level: LogLevel;
93
+ /** Log message */
94
+ message: string;
95
+ /** Additional structured data */
96
+ data?: Record<string, unknown>;
97
+ }
98
+ /**
99
+ * Log event.
100
+ * Emitted for console.log/warn/error calls.
101
+ */
102
+ export interface LogEvent extends BaseEvent {
103
+ type: typeof EventType.Log;
104
+ payload: LogPayload;
105
+ }
106
+ /**
107
+ * Tool call event payload.
108
+ */
109
+ export interface ToolCallPayload {
110
+ /** Unique identifier for this tool call */
111
+ callId: CallId;
112
+ /** Name of the tool to invoke */
113
+ toolName: string;
114
+ /** Arguments to pass to the tool */
115
+ args: unknown;
116
+ }
117
+ /**
118
+ * Tool call event.
119
+ * Emitted when runtime code calls `callTool()`.
120
+ */
121
+ export interface ToolCallEvent extends BaseEvent {
122
+ type: typeof EventType.ToolCall;
123
+ payload: ToolCallPayload;
124
+ }
125
+ /**
126
+ * Tool result applied event payload.
127
+ */
128
+ export interface ToolResultAppliedPayload {
129
+ /** Call ID of the completed tool call */
130
+ callId: CallId;
131
+ }
132
+ /**
133
+ * Tool result applied event.
134
+ * Acknowledgment that a tool result was received and applied.
135
+ */
136
+ export interface ToolResultAppliedEvent extends BaseEvent {
137
+ type: typeof EventType.ToolResultApplied;
138
+ payload: ToolResultAppliedPayload;
139
+ }
140
+ /**
141
+ * Final event payload.
142
+ */
143
+ export interface FinalPayload {
144
+ /** Whether execution completed successfully */
145
+ ok: boolean;
146
+ /** Execution result (if ok is true) */
147
+ result?: unknown;
148
+ /** Error information (if ok is false) */
149
+ error?: ErrorInfo;
150
+ /** Execution statistics */
151
+ stats?: SessionStats;
152
+ }
153
+ /**
154
+ * Session statistics included in final event.
155
+ */
156
+ export interface SessionStats {
157
+ /** Total execution time in milliseconds */
158
+ durationMs: number;
159
+ /** Number of tool calls made */
160
+ toolCallCount: number;
161
+ /** Total bytes output to stdout */
162
+ stdoutBytes: number;
163
+ }
164
+ /**
165
+ * Final event.
166
+ * Last event sent when session completes (success or failure).
167
+ */
168
+ export interface FinalEvent extends BaseEvent {
169
+ type: typeof EventType.Final;
170
+ payload: FinalPayload;
171
+ }
172
+ /**
173
+ * Heartbeat event payload.
174
+ */
175
+ export interface HeartbeatPayload {
176
+ /** Timestamp of the heartbeat (ISO 8601) */
177
+ ts: string;
178
+ }
179
+ /**
180
+ * Heartbeat event.
181
+ * Sent periodically to keep connection alive and detect stale sessions.
182
+ */
183
+ export interface HeartbeatEvent extends BaseEvent {
184
+ type: typeof EventType.Heartbeat;
185
+ payload: HeartbeatPayload;
186
+ }
187
+ /**
188
+ * Error event payload.
189
+ */
190
+ export interface ErrorEventPayload {
191
+ /** Error message */
192
+ message: string;
193
+ /** Error code */
194
+ code?: string;
195
+ /** Whether the error is recoverable */
196
+ recoverable?: boolean;
197
+ }
198
+ /**
199
+ * Error event.
200
+ * Emitted for non-fatal errors during session execution.
201
+ */
202
+ export interface ErrorEvent extends BaseEvent {
203
+ type: typeof EventType.Error;
204
+ payload: ErrorEventPayload;
205
+ }
206
+ /**
207
+ * Union of all stream event types (excluding encrypted envelope).
208
+ */
209
+ export type StreamEvent = SessionInitEvent | StdoutEvent | LogEvent | ToolCallEvent | ToolResultAppliedEvent | FinalEvent | HeartbeatEvent | ErrorEvent;
210
+ /**
211
+ * Get the event type from a stream event.
212
+ */
213
+ export declare function getEventType(event: StreamEvent): EventType;
214
+ /**
215
+ * Type guard for session init event.
216
+ */
217
+ export declare function isSessionInitEvent(event: StreamEvent): event is SessionInitEvent;
218
+ /**
219
+ * Type guard for stdout event.
220
+ */
221
+ export declare function isStdoutEvent(event: StreamEvent): event is StdoutEvent;
222
+ /**
223
+ * Type guard for log event.
224
+ */
225
+ export declare function isLogEvent(event: StreamEvent): event is LogEvent;
226
+ /**
227
+ * Type guard for tool call event.
228
+ */
229
+ export declare function isToolCallEvent(event: StreamEvent): event is ToolCallEvent;
230
+ /**
231
+ * Type guard for tool result applied event.
232
+ */
233
+ export declare function isToolResultAppliedEvent(event: StreamEvent): event is ToolResultAppliedEvent;
234
+ /**
235
+ * Type guard for final event.
236
+ */
237
+ export declare function isFinalEvent(event: StreamEvent): event is FinalEvent;
238
+ /**
239
+ * Type guard for heartbeat event.
240
+ */
241
+ export declare function isHeartbeatEvent(event: StreamEvent): event is HeartbeatEvent;
242
+ /**
243
+ * Type guard for error event.
244
+ */
245
+ export declare function isErrorEvent(event: StreamEvent): event is ErrorEvent;
246
+ /**
247
+ * Message types for the internal middleware <-> runtime channel.
248
+ */
249
+ export declare const RuntimeChannelMessageType: {
250
+ /** Tool result submission from broker to runtime */
251
+ readonly ToolResultSubmit: "tool_result_submit";
252
+ /** Cancel session request */
253
+ readonly Cancel: "cancel";
254
+ };
255
+ export type RuntimeChannelMessageType = (typeof RuntimeChannelMessageType)[keyof typeof RuntimeChannelMessageType];
256
+ /**
257
+ * Tool result submit message payload.
258
+ */
259
+ export interface ToolResultSubmitPayload {
260
+ /** Call ID this result is for */
261
+ callId: CallId;
262
+ /** Whether the tool execution succeeded */
263
+ ok: boolean;
264
+ /** Tool result (if ok is true) */
265
+ result?: unknown;
266
+ /** Error information (if ok is false) */
267
+ error?: ErrorInfo;
268
+ }
269
+ /**
270
+ * Tool result submit message.
271
+ * Sent from middleware/broker to runtime.
272
+ */
273
+ export interface ToolResultSubmitMessage {
274
+ protocolVersion: ProtocolVersion;
275
+ sessionId: SessionId;
276
+ type: typeof RuntimeChannelMessageType.ToolResultSubmit;
277
+ payload: ToolResultSubmitPayload;
278
+ }
279
+ /**
280
+ * Cancel message payload.
281
+ */
282
+ export interface CancelPayload {
283
+ /** Reason for cancellation */
284
+ reason?: string;
285
+ }
286
+ /**
287
+ * Cancel message.
288
+ * Sent to terminate a running session.
289
+ */
290
+ export interface CancelMessage {
291
+ protocolVersion: ProtocolVersion;
292
+ sessionId: SessionId;
293
+ type: typeof RuntimeChannelMessageType.Cancel;
294
+ payload: CancelPayload;
295
+ }
296
+ /**
297
+ * Union of runtime channel messages.
298
+ */
299
+ export type RuntimeChannelMessage = ToolResultSubmitMessage | CancelMessage;
package/src/events.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * @enclave-vm/types - Stream event definitions
4
+ *
5
+ * All event types that can be sent over the streaming protocol.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.RuntimeChannelMessageType = exports.EventType = void 0;
9
+ exports.getEventType = getEventType;
10
+ exports.isSessionInitEvent = isSessionInitEvent;
11
+ exports.isStdoutEvent = isStdoutEvent;
12
+ exports.isLogEvent = isLogEvent;
13
+ exports.isToolCallEvent = isToolCallEvent;
14
+ exports.isToolResultAppliedEvent = isToolResultAppliedEvent;
15
+ exports.isFinalEvent = isFinalEvent;
16
+ exports.isHeartbeatEvent = isHeartbeatEvent;
17
+ exports.isErrorEvent = isErrorEvent;
18
+ /**
19
+ * Event type discriminator.
20
+ */
21
+ exports.EventType = {
22
+ /** Session initialization */
23
+ SessionInit: 'session_init',
24
+ /** Standard output chunk */
25
+ Stdout: 'stdout',
26
+ /** Log message */
27
+ Log: 'log',
28
+ /** Tool call request from runtime */
29
+ ToolCall: 'tool_call',
30
+ /** Tool result acknowledgment */
31
+ ToolResultApplied: 'tool_result_applied',
32
+ /** Session completed */
33
+ Final: 'final',
34
+ /** Keep-alive heartbeat */
35
+ Heartbeat: 'heartbeat',
36
+ /** Error event */
37
+ Error: 'error',
38
+ /** Encrypted envelope (wraps other events) */
39
+ Encrypted: 'enc',
40
+ };
41
+ /**
42
+ * Get the event type from a stream event.
43
+ */
44
+ function getEventType(event) {
45
+ return event.type;
46
+ }
47
+ /**
48
+ * Type guard for session init event.
49
+ */
50
+ function isSessionInitEvent(event) {
51
+ return event.type === exports.EventType.SessionInit;
52
+ }
53
+ /**
54
+ * Type guard for stdout event.
55
+ */
56
+ function isStdoutEvent(event) {
57
+ return event.type === exports.EventType.Stdout;
58
+ }
59
+ /**
60
+ * Type guard for log event.
61
+ */
62
+ function isLogEvent(event) {
63
+ return event.type === exports.EventType.Log;
64
+ }
65
+ /**
66
+ * Type guard for tool call event.
67
+ */
68
+ function isToolCallEvent(event) {
69
+ return event.type === exports.EventType.ToolCall;
70
+ }
71
+ /**
72
+ * Type guard for tool result applied event.
73
+ */
74
+ function isToolResultAppliedEvent(event) {
75
+ return event.type === exports.EventType.ToolResultApplied;
76
+ }
77
+ /**
78
+ * Type guard for final event.
79
+ */
80
+ function isFinalEvent(event) {
81
+ return event.type === exports.EventType.Final;
82
+ }
83
+ /**
84
+ * Type guard for heartbeat event.
85
+ */
86
+ function isHeartbeatEvent(event) {
87
+ return event.type === exports.EventType.Heartbeat;
88
+ }
89
+ /**
90
+ * Type guard for error event.
91
+ */
92
+ function isErrorEvent(event) {
93
+ return event.type === exports.EventType.Error;
94
+ }
95
+ // ============================================================================
96
+ // Runtime Channel Messages (Middleware <-> Runtime)
97
+ // ============================================================================
98
+ /**
99
+ * Message types for the internal middleware <-> runtime channel.
100
+ */
101
+ exports.RuntimeChannelMessageType = {
102
+ /** Tool result submission from broker to runtime */
103
+ ToolResultSubmit: 'tool_result_submit',
104
+ /** Cancel session request */
105
+ Cancel: 'cancel',
106
+ };
107
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAoRH,oCAEC;AAKD,gDAEC;AAKD,sCAEC;AAKD,gCAEC;AAKD,0CAEC;AAKD,4DAEC;AAKD,oCAEC;AAKD,4CAEC;AAKD,oCAEC;AA9TD;;GAEG;AACU,QAAA,SAAS,GAAG;IACvB,6BAA6B;IAC7B,WAAW,EAAE,cAAc;IAC3B,4BAA4B;IAC5B,MAAM,EAAE,QAAQ;IAChB,kBAAkB;IAClB,GAAG,EAAE,KAAK;IACV,qCAAqC;IACrC,QAAQ,EAAE,WAAW;IACrB,iCAAiC;IACjC,iBAAiB,EAAE,qBAAqB;IACxC,wBAAwB;IACxB,KAAK,EAAE,OAAO;IACd,2BAA2B;IAC3B,SAAS,EAAE,WAAW;IACtB,kBAAkB;IAClB,KAAK,EAAE,OAAO;IACd,8CAA8C;IAC9C,SAAS,EAAE,KAAK;CACR,CAAC;AA2OX;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAkB;IAC7C,OAAO,KAAK,CAAC,IAAI,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAAkB;IACnD,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,WAAW,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAkB;IAC9C,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,MAAM,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAkB;IAC3C,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,GAAG,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAkB;IAChD,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,QAAQ,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CAAC,KAAkB;IACzD,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,iBAAiB,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAkB;IAC7C,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,KAAK,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,SAAS,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAkB;IAC7C,OAAO,KAAK,CAAC,IAAI,KAAK,iBAAS,CAAC,KAAK,CAAC;AACxC,CAAC;AAED,+EAA+E;AAC/E,oDAAoD;AACpD,+EAA+E;AAE/E;;GAEG;AACU,QAAA,yBAAyB,GAAG;IACvC,oDAAoD;IACpD,gBAAgB,EAAE,oBAAoB;IACtC,6BAA6B;IAC7B,MAAM,EAAE,QAAQ;CACR,CAAC","sourcesContent":["/**\n * @enclave-vm/types - Stream event definitions\n *\n * All event types that can be sent over the streaming protocol.\n */\n\nimport type { ProtocolVersion, SessionId, CallId, ErrorInfo, LogLevel } from './protocol.js';\n\n/**\n * Base event structure shared by all stream events.\n */\nexport interface BaseEvent {\n /** Protocol version for compatibility checking */\n protocolVersion: ProtocolVersion;\n /** Session identifier */\n sessionId: SessionId;\n /** Monotonically increasing sequence number */\n seq: number;\n}\n\n/**\n * Event type discriminator.\n */\nexport const EventType = {\n /** Session initialization */\n SessionInit: 'session_init',\n /** Standard output chunk */\n Stdout: 'stdout',\n /** Log message */\n Log: 'log',\n /** Tool call request from runtime */\n ToolCall: 'tool_call',\n /** Tool result acknowledgment */\n ToolResultApplied: 'tool_result_applied',\n /** Session completed */\n Final: 'final',\n /** Keep-alive heartbeat */\n Heartbeat: 'heartbeat',\n /** Error event */\n Error: 'error',\n /** Encrypted envelope (wraps other events) */\n Encrypted: 'enc',\n} as const;\n\nexport type EventType = (typeof EventType)[keyof typeof EventType];\n\n// ============================================================================\n// Session Init Event\n// ============================================================================\n\n/**\n * Encryption configuration in session init.\n */\nexport interface EncryptionConfig {\n /** Whether encryption is enabled for this session */\n enabled: boolean;\n /** Key ID for the session encryption key */\n keyId?: string;\n}\n\n/**\n * Session initialization event payload.\n */\nexport interface SessionInitPayload {\n /** URL to cancel the session */\n cancelUrl: string;\n /** Session expiration timestamp (ISO 8601) */\n expiresAt: string;\n /** Encryption configuration */\n encryption: EncryptionConfig;\n /** Optional replay URL for reconnection */\n replayUrl?: string;\n}\n\n/**\n * Session initialization event.\n * First event sent after session creation.\n */\nexport interface SessionInitEvent extends BaseEvent {\n type: typeof EventType.SessionInit;\n payload: SessionInitPayload;\n}\n\n// ============================================================================\n// Stdout Event\n// ============================================================================\n\n/**\n * Stdout event payload.\n */\nexport interface StdoutPayload {\n /** Output chunk (text) */\n chunk: string;\n}\n\n/**\n * Standard output event.\n * Emitted when runtime code writes to stdout.\n */\nexport interface StdoutEvent extends BaseEvent {\n type: typeof EventType.Stdout;\n payload: StdoutPayload;\n}\n\n// ============================================================================\n// Log Event\n// ============================================================================\n\n/**\n * Log event payload.\n */\nexport interface LogPayload {\n /** Log level */\n level: LogLevel;\n /** Log message */\n message: string;\n /** Additional structured data */\n data?: Record<string, unknown>;\n}\n\n/**\n * Log event.\n * Emitted for console.log/warn/error calls.\n */\nexport interface LogEvent extends BaseEvent {\n type: typeof EventType.Log;\n payload: LogPayload;\n}\n\n// ============================================================================\n// Tool Call Event\n// ============================================================================\n\n/**\n * Tool call event payload.\n */\nexport interface ToolCallPayload {\n /** Unique identifier for this tool call */\n callId: CallId;\n /** Name of the tool to invoke */\n toolName: string;\n /** Arguments to pass to the tool */\n args: unknown;\n}\n\n/**\n * Tool call event.\n * Emitted when runtime code calls `callTool()`.\n */\nexport interface ToolCallEvent extends BaseEvent {\n type: typeof EventType.ToolCall;\n payload: ToolCallPayload;\n}\n\n// ============================================================================\n// Tool Result Applied Event\n// ============================================================================\n\n/**\n * Tool result applied event payload.\n */\nexport interface ToolResultAppliedPayload {\n /** Call ID of the completed tool call */\n callId: CallId;\n}\n\n/**\n * Tool result applied event.\n * Acknowledgment that a tool result was received and applied.\n */\nexport interface ToolResultAppliedEvent extends BaseEvent {\n type: typeof EventType.ToolResultApplied;\n payload: ToolResultAppliedPayload;\n}\n\n// ============================================================================\n// Final Event\n// ============================================================================\n\n/**\n * Final event payload.\n */\nexport interface FinalPayload {\n /** Whether execution completed successfully */\n ok: boolean;\n /** Execution result (if ok is true) */\n result?: unknown;\n /** Error information (if ok is false) */\n error?: ErrorInfo;\n /** Execution statistics */\n stats?: SessionStats;\n}\n\n/**\n * Session statistics included in final event.\n */\nexport interface SessionStats {\n /** Total execution time in milliseconds */\n durationMs: number;\n /** Number of tool calls made */\n toolCallCount: number;\n /** Total bytes output to stdout */\n stdoutBytes: number;\n}\n\n/**\n * Final event.\n * Last event sent when session completes (success or failure).\n */\nexport interface FinalEvent extends BaseEvent {\n type: typeof EventType.Final;\n payload: FinalPayload;\n}\n\n// ============================================================================\n// Heartbeat Event\n// ============================================================================\n\n/**\n * Heartbeat event payload.\n */\nexport interface HeartbeatPayload {\n /** Timestamp of the heartbeat (ISO 8601) */\n ts: string;\n}\n\n/**\n * Heartbeat event.\n * Sent periodically to keep connection alive and detect stale sessions.\n */\nexport interface HeartbeatEvent extends BaseEvent {\n type: typeof EventType.Heartbeat;\n payload: HeartbeatPayload;\n}\n\n// ============================================================================\n// Error Event\n// ============================================================================\n\n/**\n * Error event payload.\n */\nexport interface ErrorEventPayload {\n /** Error message */\n message: string;\n /** Error code */\n code?: string;\n /** Whether the error is recoverable */\n recoverable?: boolean;\n}\n\n/**\n * Error event.\n * Emitted for non-fatal errors during session execution.\n */\nexport interface ErrorEvent extends BaseEvent {\n type: typeof EventType.Error;\n payload: ErrorEventPayload;\n}\n\n// ============================================================================\n// Stream Event Union\n// ============================================================================\n\n/**\n * Union of all stream event types (excluding encrypted envelope).\n */\nexport type StreamEvent =\n | SessionInitEvent\n | StdoutEvent\n | LogEvent\n | ToolCallEvent\n | ToolResultAppliedEvent\n | FinalEvent\n | HeartbeatEvent\n | ErrorEvent;\n\n/**\n * Get the event type from a stream event.\n */\nexport function getEventType(event: StreamEvent): EventType {\n return event.type;\n}\n\n/**\n * Type guard for session init event.\n */\nexport function isSessionInitEvent(event: StreamEvent): event is SessionInitEvent {\n return event.type === EventType.SessionInit;\n}\n\n/**\n * Type guard for stdout event.\n */\nexport function isStdoutEvent(event: StreamEvent): event is StdoutEvent {\n return event.type === EventType.Stdout;\n}\n\n/**\n * Type guard for log event.\n */\nexport function isLogEvent(event: StreamEvent): event is LogEvent {\n return event.type === EventType.Log;\n}\n\n/**\n * Type guard for tool call event.\n */\nexport function isToolCallEvent(event: StreamEvent): event is ToolCallEvent {\n return event.type === EventType.ToolCall;\n}\n\n/**\n * Type guard for tool result applied event.\n */\nexport function isToolResultAppliedEvent(event: StreamEvent): event is ToolResultAppliedEvent {\n return event.type === EventType.ToolResultApplied;\n}\n\n/**\n * Type guard for final event.\n */\nexport function isFinalEvent(event: StreamEvent): event is FinalEvent {\n return event.type === EventType.Final;\n}\n\n/**\n * Type guard for heartbeat event.\n */\nexport function isHeartbeatEvent(event: StreamEvent): event is HeartbeatEvent {\n return event.type === EventType.Heartbeat;\n}\n\n/**\n * Type guard for error event.\n */\nexport function isErrorEvent(event: StreamEvent): event is ErrorEvent {\n return event.type === EventType.Error;\n}\n\n// ============================================================================\n// Runtime Channel Messages (Middleware <-> Runtime)\n// ============================================================================\n\n/**\n * Message types for the internal middleware <-> runtime channel.\n */\nexport const RuntimeChannelMessageType = {\n /** Tool result submission from broker to runtime */\n ToolResultSubmit: 'tool_result_submit',\n /** Cancel session request */\n Cancel: 'cancel',\n} as const;\n\nexport type RuntimeChannelMessageType = (typeof RuntimeChannelMessageType)[keyof typeof RuntimeChannelMessageType];\n\n/**\n * Tool result submit message payload.\n */\nexport interface ToolResultSubmitPayload {\n /** Call ID this result is for */\n callId: CallId;\n /** Whether the tool execution succeeded */\n ok: boolean;\n /** Tool result (if ok is true) */\n result?: unknown;\n /** Error information (if ok is false) */\n error?: ErrorInfo;\n}\n\n/**\n * Tool result submit message.\n * Sent from middleware/broker to runtime.\n */\nexport interface ToolResultSubmitMessage {\n protocolVersion: ProtocolVersion;\n sessionId: SessionId;\n type: typeof RuntimeChannelMessageType.ToolResultSubmit;\n payload: ToolResultSubmitPayload;\n}\n\n/**\n * Cancel message payload.\n */\nexport interface CancelPayload {\n /** Reason for cancellation */\n reason?: string;\n}\n\n/**\n * Cancel message.\n * Sent to terminate a running session.\n */\nexport interface CancelMessage {\n protocolVersion: ProtocolVersion;\n sessionId: SessionId;\n type: typeof RuntimeChannelMessageType.Cancel;\n payload: CancelPayload;\n}\n\n/**\n * Union of runtime channel messages.\n */\nexport type RuntimeChannelMessage = ToolResultSubmitMessage | CancelMessage;\n"]}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @enclave-vm/types - Event filter definitions
3
+ *
4
+ * Types for server-side event filtering configuration.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { EventType } from './events.js';
9
+ /**
10
+ * Filter mode - how filters should be applied.
11
+ */
12
+ export declare const FilterMode: {
13
+ /** Include only events matching the filter (whitelist) */
14
+ readonly Include: "include";
15
+ /** Exclude events matching the filter (blacklist) */
16
+ readonly Exclude: "exclude";
17
+ };
18
+ export type FilterMode = (typeof FilterMode)[keyof typeof FilterMode];
19
+ /**
20
+ * Pattern type for content matching.
21
+ */
22
+ export declare const PatternType: {
23
+ /** Exact string match */
24
+ readonly Exact: "exact";
25
+ /** Prefix match (startsWith) */
26
+ readonly Prefix: "prefix";
27
+ /** Regular expression */
28
+ readonly Regex: "regex";
29
+ /** Glob pattern (supports * and **) */
30
+ readonly Glob: "glob";
31
+ };
32
+ export type PatternType = (typeof PatternType)[keyof typeof PatternType];
33
+ /**
34
+ * Content pattern for payload filtering.
35
+ */
36
+ export interface ContentPattern {
37
+ /** Pattern type */
38
+ type: PatternType;
39
+ /** Pattern value */
40
+ pattern: string;
41
+ /** Field path to match against (dot notation, e.g., "payload.message") */
42
+ field?: string;
43
+ /** Case insensitive matching (default: false) */
44
+ caseInsensitive?: boolean;
45
+ }
46
+ /**
47
+ * Type-based filter rule.
48
+ */
49
+ export interface TypeFilter {
50
+ /** Event types to match */
51
+ types: EventType[];
52
+ }
53
+ /**
54
+ * Content-based filter rule.
55
+ */
56
+ export interface ContentFilter {
57
+ /** Content patterns to match */
58
+ patterns: ContentPattern[];
59
+ /** Match mode: 'any' (OR) or 'all' (AND). Default: 'any' */
60
+ match?: 'any' | 'all';
61
+ }
62
+ /**
63
+ * Combined filter rule.
64
+ * If both types and content are specified, both must match (AND).
65
+ * Multiple rules are combined with OR.
66
+ */
67
+ export interface FilterRule {
68
+ /** Type-based filter (optional) */
69
+ types?: TypeFilter;
70
+ /** Content-based filter (optional) */
71
+ content?: ContentFilter;
72
+ }
73
+ /**
74
+ * Complete event filter configuration.
75
+ */
76
+ export interface EventFilterConfig {
77
+ /** Filter mode: include (whitelist) or exclude (blacklist) */
78
+ mode: FilterMode;
79
+ /** Filter rules - multiple rules are combined with OR */
80
+ rules: FilterRule[];
81
+ /**
82
+ * Events that should always be sent regardless of filter.
83
+ * Default: ['session_init', 'final']
84
+ */
85
+ alwaysAllow?: EventType[];
86
+ /**
87
+ * Maximum regex execution time in milliseconds.
88
+ * Default: 100
89
+ */
90
+ regexTimeoutMs?: number;
91
+ }
92
+ /**
93
+ * Default events that bypass filtering.
94
+ */
95
+ export declare const DEFAULT_ALWAYS_ALLOW: EventType[];
package/src/filter.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * @enclave-vm/types - Event filter definitions
4
+ *
5
+ * Types for server-side event filtering configuration.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DEFAULT_ALWAYS_ALLOW = exports.PatternType = exports.FilterMode = void 0;
11
+ /**
12
+ * Filter mode - how filters should be applied.
13
+ */
14
+ exports.FilterMode = {
15
+ /** Include only events matching the filter (whitelist) */
16
+ Include: 'include',
17
+ /** Exclude events matching the filter (blacklist) */
18
+ Exclude: 'exclude',
19
+ };
20
+ /**
21
+ * Pattern type for content matching.
22
+ */
23
+ exports.PatternType = {
24
+ /** Exact string match */
25
+ Exact: 'exact',
26
+ /** Prefix match (startsWith) */
27
+ Prefix: 'prefix',
28
+ /** Regular expression */
29
+ Regex: 'regex',
30
+ /** Glob pattern (supports * and **) */
31
+ Glob: 'glob',
32
+ };
33
+ /**
34
+ * Default events that bypass filtering.
35
+ */
36
+ exports.DEFAULT_ALWAYS_ALLOW = ['session_init', 'final'];
37
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/filter.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH;;GAEG;AACU,QAAA,UAAU,GAAG;IACxB,0DAA0D;IAC1D,OAAO,EAAE,SAAS;IAClB,qDAAqD;IACrD,OAAO,EAAE,SAAS;CACV,CAAC;AAIX;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,yBAAyB;IACzB,KAAK,EAAE,OAAO;IACd,gCAAgC;IAChC,MAAM,EAAE,QAAQ;IAChB,yBAAyB;IACzB,KAAK,EAAE,OAAO;IACd,uCAAuC;IACvC,IAAI,EAAE,MAAM;CACJ,CAAC;AAoEX;;GAEG;AACU,QAAA,oBAAoB,GAAgB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/**\n * @enclave-vm/types - Event filter definitions\n *\n * Types for server-side event filtering configuration.\n *\n * @packageDocumentation\n */\n\nimport type { EventType } from './events.js';\n\n/**\n * Filter mode - how filters should be applied.\n */\nexport const FilterMode = {\n /** Include only events matching the filter (whitelist) */\n Include: 'include',\n /** Exclude events matching the filter (blacklist) */\n Exclude: 'exclude',\n} as const;\n\nexport type FilterMode = (typeof FilterMode)[keyof typeof FilterMode];\n\n/**\n * Pattern type for content matching.\n */\nexport const PatternType = {\n /** Exact string match */\n Exact: 'exact',\n /** Prefix match (startsWith) */\n Prefix: 'prefix',\n /** Regular expression */\n Regex: 'regex',\n /** Glob pattern (supports * and **) */\n Glob: 'glob',\n} as const;\n\nexport type PatternType = (typeof PatternType)[keyof typeof PatternType];\n\n/**\n * Content pattern for payload filtering.\n */\nexport interface ContentPattern {\n /** Pattern type */\n type: PatternType;\n /** Pattern value */\n pattern: string;\n /** Field path to match against (dot notation, e.g., \"payload.message\") */\n field?: string;\n /** Case insensitive matching (default: false) */\n caseInsensitive?: boolean;\n}\n\n/**\n * Type-based filter rule.\n */\nexport interface TypeFilter {\n /** Event types to match */\n types: EventType[];\n}\n\n/**\n * Content-based filter rule.\n */\nexport interface ContentFilter {\n /** Content patterns to match */\n patterns: ContentPattern[];\n /** Match mode: 'any' (OR) or 'all' (AND). Default: 'any' */\n match?: 'any' | 'all';\n}\n\n/**\n * Combined filter rule.\n * If both types and content are specified, both must match (AND).\n * Multiple rules are combined with OR.\n */\nexport interface FilterRule {\n /** Type-based filter (optional) */\n types?: TypeFilter;\n /** Content-based filter (optional) */\n content?: ContentFilter;\n}\n\n/**\n * Complete event filter configuration.\n */\nexport interface EventFilterConfig {\n /** Filter mode: include (whitelist) or exclude (blacklist) */\n mode: FilterMode;\n /** Filter rules - multiple rules are combined with OR */\n rules: FilterRule[];\n /**\n * Events that should always be sent regardless of filter.\n * Default: ['session_init', 'final']\n */\n alwaysAllow?: EventType[];\n /**\n * Maximum regex execution time in milliseconds.\n * Default: 100\n */\n regexTimeoutMs?: number;\n}\n\n/**\n * Default events that bypass filtering.\n */\nexport const DEFAULT_ALWAYS_ALLOW: EventType[] = ['session_init', 'final'];\n"]}
package/src/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @enclave-vm/types
3
+ *
4
+ * Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export { PROTOCOL_VERSION, SESSION_ID_PREFIX, CALL_ID_PREFIX, REF_ID_PREFIX, generateSessionId, generateCallId, generateRefId, isSessionId, isCallId, isRefId, DEFAULT_SESSION_LIMITS, SessionState, LogLevel, isRefToken, createRefToken, } from './protocol.js';
9
+ export type { ProtocolVersion, SessionId, CallId, RefId, SessionLimits, ToolConfig, RefToken, ErrorInfo, } from './protocol.js';
10
+ export { EventType, RuntimeChannelMessageType, getEventType, isSessionInitEvent, isStdoutEvent, isLogEvent, isToolCallEvent, isToolResultAppliedEvent, isFinalEvent, isHeartbeatEvent, isErrorEvent, } from './events.js';
11
+ export type { BaseEvent, EncryptionConfig, SessionInitPayload, SessionInitEvent, StdoutPayload, StdoutEvent, LogPayload, LogEvent, ToolCallPayload, ToolCallEvent, ToolResultAppliedPayload, ToolResultAppliedEvent, FinalPayload, SessionStats, FinalEvent, HeartbeatPayload, HeartbeatEvent, ErrorEventPayload, ErrorEvent, StreamEvent, ToolResultSubmitPayload, ToolResultSubmitMessage, CancelPayload, CancelMessage, RuntimeChannelMessage, } from './events.js';
12
+ export { SupportedCurve, EncryptionAlgorithm, KeyDerivation, EncryptionMode, EncryptionErrorCode, HkdfInfo, AES_GCM_NONCE_SIZE, AES_GCM_TAG_SIZE, AES_256_KEY_SIZE, MAX_MESSAGES_PER_KEY, isEncryptedEnvelope, } from './encryption.js';
13
+ export type { EncryptedEnvelopePayload, EncryptedEnvelope, ClientHello, ServerHello, EncryptionRequest, SessionKeyInfo, MaybeEncrypted, } from './encryption.js';
14
+ export { ProtocolVersionSchema, SessionIdSchema, CallIdSchema, RefIdSchema, LogLevelSchema, SessionStateSchema, ErrorInfoSchema, RefTokenSchema, SessionLimitsSchema, ToolConfigSchema, BaseEventSchema, EncryptionConfigSchema, SessionInitPayloadSchema, StdoutPayloadSchema, LogPayloadSchema, ToolCallPayloadSchema, ToolResultAppliedPayloadSchema, SessionStatsSchema, FinalPayloadSchema, HeartbeatPayloadSchema, ErrorEventPayloadSchema, SessionInitEventSchema, StdoutEventSchema, LogEventSchema, ToolCallEventSchema, ToolResultAppliedEventSchema, FinalEventSchema, HeartbeatEventSchema, ErrorEventSchema, StreamEventSchema, SupportedCurveSchema, EncryptionAlgorithmSchema, KeyDerivationSchema, EncryptionModeSchema, EncryptedEnvelopePayloadSchema, EncryptedEnvelopeSchema, ClientHelloSchema, ServerHelloSchema, EncryptionRequestSchema, ToolResultSubmitPayloadSchema, ToolResultSubmitMessageSchema, CancelPayloadSchema, CancelMessageSchema, RuntimeChannelMessageSchema, CreateSessionRequestSchema, parseStreamEvent, parseEncryptedEnvelope, parseRuntimeChannelMessage, parseCreateSessionRequest, parseStreamEventOrEncrypted, } from './schemas.js';
15
+ export type { ParsedStreamEvent, ParsedEncryptedEnvelope, ParsedRuntimeChannelMessage, ParsedCreateSessionRequest, } from './schemas.js';
16
+ export { FilterMode, PatternType, DEFAULT_ALWAYS_ALLOW } from './filter.js';
17
+ export type { ContentPattern, TypeFilter, ContentFilter, FilterRule, EventFilterConfig } from './filter.js';