@enclave-vm/types 0.0.1 → 2.9.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/src/encryption.js DELETED
@@ -1,108 +0,0 @@
1
- "use strict";
2
- /**
3
- * @enclave-vm/types - Encryption types
4
- *
5
- * Types for per-hop encryption using ECDH + AES-GCM.
6
- * Encryption is optional but recommended to prevent intermediaries from reading payloads.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MAX_MESSAGES_PER_KEY = exports.AES_256_KEY_SIZE = exports.AES_GCM_TAG_SIZE = exports.AES_GCM_NONCE_SIZE = exports.HkdfInfo = exports.EncryptionErrorCode = exports.EncryptionMode = exports.KeyDerivation = exports.EncryptionAlgorithm = exports.SupportedCurve = void 0;
10
- exports.isEncryptedEnvelope = isEncryptedEnvelope;
11
- /**
12
- * Supported elliptic curves for ECDH key exchange.
13
- * Using P-256 for broad browser compatibility via Web Crypto API.
14
- */
15
- exports.SupportedCurve = {
16
- P256: 'P-256',
17
- };
18
- /**
19
- * Encryption algorithm identifiers.
20
- */
21
- exports.EncryptionAlgorithm = {
22
- /** AES-GCM with 256-bit key */
23
- AES_GCM_256: 'AES-GCM-256',
24
- };
25
- /**
26
- * Key derivation function identifiers.
27
- */
28
- exports.KeyDerivation = {
29
- /** HKDF with SHA-256 */
30
- HKDF_SHA256: 'HKDF-SHA-256',
31
- };
32
- /**
33
- * Encryption mode for session creation request.
34
- */
35
- exports.EncryptionMode = {
36
- /** Encryption is disabled */
37
- Disabled: 'disabled',
38
- /** Encryption is optional (server decides) */
39
- Optional: 'optional',
40
- /** Encryption is required */
41
- Required: 'required',
42
- };
43
- // ============================================================================
44
- // Encryption Errors
45
- // ============================================================================
46
- /**
47
- * Encryption-specific error codes.
48
- */
49
- exports.EncryptionErrorCode = {
50
- /** Handshake failed */
51
- HandshakeFailed: 'ENCRYPTION_HANDSHAKE_FAILED',
52
- /** Key derivation failed */
53
- KeyDerivationFailed: 'ENCRYPTION_KEY_DERIVATION_FAILED',
54
- /** Decryption failed (invalid ciphertext or authentication) */
55
- DecryptionFailed: 'ENCRYPTION_DECRYPTION_FAILED',
56
- /** Nonce reuse detected */
57
- NonceReuse: 'ENCRYPTION_NONCE_REUSE',
58
- /** Key expired or needs rotation */
59
- KeyExpired: 'ENCRYPTION_KEY_EXPIRED',
60
- /** Unsupported algorithm */
61
- UnsupportedAlgorithm: 'ENCRYPTION_UNSUPPORTED_ALGORITHM',
62
- /** Invalid public key */
63
- InvalidPublicKey: 'ENCRYPTION_INVALID_PUBLIC_KEY',
64
- /** Signature verification failed */
65
- SignatureVerificationFailed: 'ENCRYPTION_SIGNATURE_VERIFICATION_FAILED',
66
- };
67
- /**
68
- * Check if a value is an encrypted envelope.
69
- */
70
- function isEncryptedEnvelope(value) {
71
- return (typeof value === 'object' &&
72
- value !== null &&
73
- 'type' in value &&
74
- value.type === 'enc' &&
75
- 'payload' in value &&
76
- typeof value.payload === 'object' &&
77
- value.payload !== null &&
78
- 'kid' in value.payload &&
79
- 'nonceB64' in value.payload &&
80
- 'ciphertextB64' in value.payload);
81
- }
82
- /**
83
- * HKDF info strings for different key purposes.
84
- */
85
- exports.HkdfInfo = {
86
- /** Client -> Server encryption key */
87
- ClientToServer: 'enclavejs-c2s-enc',
88
- /** Server -> Client encryption key */
89
- ServerToClient: 'enclavejs-s2c-enc',
90
- };
91
- /**
92
- * Nonce/IV size in bytes for AES-GCM.
93
- */
94
- exports.AES_GCM_NONCE_SIZE = 12;
95
- /**
96
- * Authentication tag size in bytes for AES-GCM.
97
- */
98
- exports.AES_GCM_TAG_SIZE = 16;
99
- /**
100
- * Key size in bytes for AES-256.
101
- */
102
- exports.AES_256_KEY_SIZE = 32;
103
- /**
104
- * Maximum number of messages with one key (2^32 for AES-GCM with random nonces).
105
- * We use a lower limit (2^30) to be safe.
106
- */
107
- exports.MAX_MESSAGES_PER_KEY = 1073741824n; // 2^30
108
- //# sourceMappingURL=encryption.js.map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vD,KAA2B,CAAC,OAAO,KAAK,IAAI;QAC7C,KAAK,IAAK,KAA2B,CAAC,OAAO;QAC7C,UAAU,IAAK,KAA2B,CAAC,OAAO;QAClD,eAAe,IAAK,KAA2B,CAAC,OAAO,CACxD,CAAC;AACJ,CAAC;AAED;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,sCAAsC;IACtC,cAAc,EAAE,mBAAmB;IACnC,sCAAsC;IACtC,cAAc,EAAE,mBAAmB;CAC3B,CAAC;AAIX;;GAEG;AACU,QAAA,kBAAkB,GAAG,EAAE,CAAC;AAErC;;GAEG;AACU,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;GAEG;AACU,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;;GAGG;AACU,QAAA,oBAAoB,GAAG,WAAW,CAAC,CAAC,OAAO","sourcesContent":["/**\n * @enclave-vm/types - Encryption types\n *\n * Types for per-hop encryption using ECDH + AES-GCM.\n * Encryption is optional but recommended to prevent intermediaries from reading payloads.\n */\n\nimport type { ProtocolVersion, SessionId } from './protocol.js';\nimport type { EventType } from './events.js';\n\n/**\n * Supported elliptic curves for ECDH key exchange.\n * Using P-256 for broad browser compatibility via Web Crypto API.\n */\nexport const SupportedCurve = {\n P256: 'P-256',\n} as const;\n\nexport type SupportedCurve = (typeof SupportedCurve)[keyof typeof SupportedCurve];\n\n/**\n * Encryption algorithm identifiers.\n */\nexport const EncryptionAlgorithm = {\n /** AES-GCM with 256-bit key */\n AES_GCM_256: 'AES-GCM-256',\n} as const;\n\nexport type EncryptionAlgorithm = (typeof EncryptionAlgorithm)[keyof typeof EncryptionAlgorithm];\n\n/**\n * Key derivation function identifiers.\n */\nexport const KeyDerivation = {\n /** HKDF with SHA-256 */\n HKDF_SHA256: 'HKDF-SHA-256',\n} as const;\n\nexport type KeyDerivation = (typeof KeyDerivation)[keyof typeof KeyDerivation];\n\n// ============================================================================\n// Encrypted Envelope\n// ============================================================================\n\n/**\n * Encrypted envelope payload.\n * Contains the encrypted inner event.\n */\nexport interface EncryptedEnvelopePayload {\n /** Key ID identifying which session key to use */\n kid: string;\n /** Base64-encoded nonce/IV (12 bytes for AES-GCM) */\n nonceB64: string;\n /** Base64-encoded ciphertext (encrypted JSON of inner event) */\n ciphertextB64: string;\n /** Base64-encoded authentication tag (16 bytes for AES-GCM) */\n tagB64?: string;\n}\n\n/**\n * Encrypted envelope event.\n * Wraps any other event type when encryption is enabled.\n */\nexport interface EncryptedEnvelope {\n protocolVersion: ProtocolVersion;\n sessionId: SessionId;\n /** Sequence number (visible even when encrypted for ordering) */\n seq: number;\n type: typeof EventType.Encrypted;\n payload: EncryptedEnvelopePayload;\n}\n\n// ============================================================================\n// Key Exchange (Handshake)\n// ============================================================================\n\n/**\n * Client hello - first message in handshake.\n * Sent by client with session creation request.\n */\nexport interface ClientHello {\n /** Protocol version */\n protocolVersion: ProtocolVersion;\n /** Client's ephemeral public key (base64 encoded) */\n clientEphemeralPubKeyB64: string;\n /** Elliptic curve used */\n curve: SupportedCurve;\n /** Encryption algorithms the client supports */\n supportedAlgorithms: EncryptionAlgorithm[];\n}\n\n/**\n * Server hello - response to client hello.\n * Included in session_init event when encryption is negotiated.\n */\nexport interface ServerHello {\n /** Protocol version */\n protocolVersion: ProtocolVersion;\n /** Server's ephemeral public key (base64 encoded) */\n serverEphemeralPubKeyB64: string;\n /** Elliptic curve used */\n curve: SupportedCurve;\n /** Selected encryption algorithm */\n selectedAlgorithm: EncryptionAlgorithm;\n /** Key derivation function used */\n kdf: KeyDerivation;\n /** Key ID for the derived session key */\n keyId: string;\n /**\n * Signature over the handshake transcript (base64 encoded).\n * Allows client to verify server identity if server has a pinned key.\n */\n signatureB64?: string;\n}\n\n/**\n * Encryption mode for session creation request.\n */\nexport const EncryptionMode = {\n /** Encryption is disabled */\n Disabled: 'disabled',\n /** Encryption is optional (server decides) */\n Optional: 'optional',\n /** Encryption is required */\n Required: 'required',\n} as const;\n\nexport type EncryptionMode = (typeof EncryptionMode)[keyof typeof EncryptionMode];\n\n/**\n * Encryption request in session creation.\n */\nexport interface EncryptionRequest {\n /** Requested encryption mode */\n mode: EncryptionMode;\n /** Client hello (required if mode is not 'disabled') */\n clientHello?: ClientHello;\n}\n\n// ============================================================================\n// Session Key Info\n// ============================================================================\n\n/**\n * Session encryption key information.\n * Used internally by both client and server.\n */\nexport interface SessionKeyInfo {\n /** Key ID */\n keyId: string;\n /** Encryption algorithm */\n algorithm: EncryptionAlgorithm;\n /** Raw key bytes (32 bytes for AES-256) */\n keyBytes: Uint8Array;\n /** Counter for nonce generation (to avoid nonce reuse) */\n nonceCounter: bigint;\n /** Maximum nonces before key rotation required */\n maxNonces: bigint;\n /** Timestamp when key was derived */\n createdAt: number;\n}\n\n// ============================================================================\n// Encryption Errors\n// ============================================================================\n\n/**\n * Encryption-specific error codes.\n */\nexport const EncryptionErrorCode = {\n /** Handshake failed */\n HandshakeFailed: 'ENCRYPTION_HANDSHAKE_FAILED',\n /** Key derivation failed */\n KeyDerivationFailed: 'ENCRYPTION_KEY_DERIVATION_FAILED',\n /** Decryption failed (invalid ciphertext or authentication) */\n DecryptionFailed: 'ENCRYPTION_DECRYPTION_FAILED',\n /** Nonce reuse detected */\n NonceReuse: 'ENCRYPTION_NONCE_REUSE',\n /** Key expired or needs rotation */\n KeyExpired: 'ENCRYPTION_KEY_EXPIRED',\n /** Unsupported algorithm */\n UnsupportedAlgorithm: 'ENCRYPTION_UNSUPPORTED_ALGORITHM',\n /** Invalid public key */\n InvalidPublicKey: 'ENCRYPTION_INVALID_PUBLIC_KEY',\n /** Signature verification failed */\n SignatureVerificationFailed: 'ENCRYPTION_SIGNATURE_VERIFICATION_FAILED',\n} as const;\n\nexport type EncryptionErrorCode = (typeof EncryptionErrorCode)[keyof typeof EncryptionErrorCode];\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\n/**\n * Input or output that can be either plaintext or encrypted.\n */\nexport type MaybeEncrypted<T> = T | EncryptedEnvelope;\n\n/**\n * Check if a value is an encrypted envelope.\n */\nexport function isEncryptedEnvelope(value: unknown): value is EncryptedEnvelope {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n (value as { type: unknown }).type === 'enc' &&\n 'payload' in value &&\n typeof (value as EncryptedEnvelope).payload === 'object' &&\n (value as EncryptedEnvelope).payload !== null &&\n 'kid' in (value as EncryptedEnvelope).payload &&\n 'nonceB64' in (value as EncryptedEnvelope).payload &&\n 'ciphertextB64' in (value as EncryptedEnvelope).payload\n );\n}\n\n/**\n * HKDF info strings for different key purposes.\n */\nexport const HkdfInfo = {\n /** Client -> Server encryption key */\n ClientToServer: 'enclavejs-c2s-enc',\n /** Server -> Client encryption key */\n ServerToClient: 'enclavejs-s2c-enc',\n} as const;\n\nexport type HkdfInfo = (typeof HkdfInfo)[keyof typeof HkdfInfo];\n\n/**\n * Nonce/IV size in bytes for AES-GCM.\n */\nexport const AES_GCM_NONCE_SIZE = 12;\n\n/**\n * Authentication tag size in bytes for AES-GCM.\n */\nexport const AES_GCM_TAG_SIZE = 16;\n\n/**\n * Key size in bytes for AES-256.\n */\nexport const AES_256_KEY_SIZE = 32;\n\n/**\n * Maximum number of messages with one key (2^32 for AES-GCM with random nonces).\n * We use a lower limit (2^30) to be safe.\n */\nexport const MAX_MESSAGES_PER_KEY = 1073741824n; // 2^30\n"]}
package/src/events.js DELETED
@@ -1,107 +0,0 @@
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
package/src/events.js.map DELETED
@@ -1 +0,0 @@
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"]}
package/src/filter.js DELETED
@@ -1,37 +0,0 @@
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
package/src/filter.js.map DELETED
@@ -1 +0,0 @@
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.js DELETED
@@ -1,119 +0,0 @@
1
- "use strict";
2
- /**
3
- * @enclave-vm/types
4
- *
5
- * Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol.
6
- *
7
- * @packageDocumentation
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SessionInitPayloadSchema = exports.EncryptionConfigSchema = exports.BaseEventSchema = exports.ToolConfigSchema = exports.SessionLimitsSchema = exports.RefTokenSchema = exports.ErrorInfoSchema = exports.SessionStateSchema = exports.LogLevelSchema = exports.RefIdSchema = exports.CallIdSchema = exports.SessionIdSchema = exports.ProtocolVersionSchema = exports.isEncryptedEnvelope = exports.MAX_MESSAGES_PER_KEY = exports.AES_256_KEY_SIZE = exports.AES_GCM_TAG_SIZE = exports.AES_GCM_NONCE_SIZE = exports.HkdfInfo = exports.EncryptionErrorCode = exports.EncryptionMode = exports.KeyDerivation = exports.EncryptionAlgorithm = exports.SupportedCurve = exports.isErrorEvent = exports.isHeartbeatEvent = exports.isFinalEvent = exports.isToolResultAppliedEvent = exports.isToolCallEvent = exports.isLogEvent = exports.isStdoutEvent = exports.isSessionInitEvent = exports.getEventType = exports.RuntimeChannelMessageType = exports.EventType = exports.createRefToken = exports.isRefToken = exports.LogLevel = exports.SessionState = exports.DEFAULT_SESSION_LIMITS = exports.isRefId = exports.isCallId = exports.isSessionId = exports.generateRefId = exports.generateCallId = exports.generateSessionId = exports.REF_ID_PREFIX = exports.CALL_ID_PREFIX = exports.SESSION_ID_PREFIX = exports.PROTOCOL_VERSION = void 0;
11
- exports.DEFAULT_ALWAYS_ALLOW = exports.PatternType = exports.FilterMode = exports.parseStreamEventOrEncrypted = exports.parseCreateSessionRequest = exports.parseRuntimeChannelMessage = exports.parseEncryptedEnvelope = exports.parseStreamEvent = exports.CreateSessionRequestSchema = exports.RuntimeChannelMessageSchema = exports.CancelMessageSchema = exports.CancelPayloadSchema = exports.ToolResultSubmitMessageSchema = exports.ToolResultSubmitPayloadSchema = exports.EncryptionRequestSchema = exports.ServerHelloSchema = exports.ClientHelloSchema = exports.EncryptedEnvelopeSchema = exports.EncryptedEnvelopePayloadSchema = exports.EncryptionModeSchema = exports.KeyDerivationSchema = exports.EncryptionAlgorithmSchema = exports.SupportedCurveSchema = exports.StreamEventSchema = exports.ErrorEventSchema = exports.HeartbeatEventSchema = exports.FinalEventSchema = exports.ToolResultAppliedEventSchema = exports.ToolCallEventSchema = exports.LogEventSchema = exports.StdoutEventSchema = exports.SessionInitEventSchema = exports.ErrorEventPayloadSchema = exports.HeartbeatPayloadSchema = exports.FinalPayloadSchema = exports.SessionStatsSchema = exports.ToolResultAppliedPayloadSchema = exports.ToolCallPayloadSchema = exports.LogPayloadSchema = exports.StdoutPayloadSchema = void 0;
12
- // Protocol exports
13
- var protocol_js_1 = require("./protocol.js");
14
- Object.defineProperty(exports, "PROTOCOL_VERSION", { enumerable: true, get: function () { return protocol_js_1.PROTOCOL_VERSION; } });
15
- Object.defineProperty(exports, "SESSION_ID_PREFIX", { enumerable: true, get: function () { return protocol_js_1.SESSION_ID_PREFIX; } });
16
- Object.defineProperty(exports, "CALL_ID_PREFIX", { enumerable: true, get: function () { return protocol_js_1.CALL_ID_PREFIX; } });
17
- Object.defineProperty(exports, "REF_ID_PREFIX", { enumerable: true, get: function () { return protocol_js_1.REF_ID_PREFIX; } });
18
- Object.defineProperty(exports, "generateSessionId", { enumerable: true, get: function () { return protocol_js_1.generateSessionId; } });
19
- Object.defineProperty(exports, "generateCallId", { enumerable: true, get: function () { return protocol_js_1.generateCallId; } });
20
- Object.defineProperty(exports, "generateRefId", { enumerable: true, get: function () { return protocol_js_1.generateRefId; } });
21
- Object.defineProperty(exports, "isSessionId", { enumerable: true, get: function () { return protocol_js_1.isSessionId; } });
22
- Object.defineProperty(exports, "isCallId", { enumerable: true, get: function () { return protocol_js_1.isCallId; } });
23
- Object.defineProperty(exports, "isRefId", { enumerable: true, get: function () { return protocol_js_1.isRefId; } });
24
- Object.defineProperty(exports, "DEFAULT_SESSION_LIMITS", { enumerable: true, get: function () { return protocol_js_1.DEFAULT_SESSION_LIMITS; } });
25
- Object.defineProperty(exports, "SessionState", { enumerable: true, get: function () { return protocol_js_1.SessionState; } });
26
- Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return protocol_js_1.LogLevel; } });
27
- Object.defineProperty(exports, "isRefToken", { enumerable: true, get: function () { return protocol_js_1.isRefToken; } });
28
- Object.defineProperty(exports, "createRefToken", { enumerable: true, get: function () { return protocol_js_1.createRefToken; } });
29
- // Event exports
30
- var events_js_1 = require("./events.js");
31
- Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return events_js_1.EventType; } });
32
- Object.defineProperty(exports, "RuntimeChannelMessageType", { enumerable: true, get: function () { return events_js_1.RuntimeChannelMessageType; } });
33
- Object.defineProperty(exports, "getEventType", { enumerable: true, get: function () { return events_js_1.getEventType; } });
34
- Object.defineProperty(exports, "isSessionInitEvent", { enumerable: true, get: function () { return events_js_1.isSessionInitEvent; } });
35
- Object.defineProperty(exports, "isStdoutEvent", { enumerable: true, get: function () { return events_js_1.isStdoutEvent; } });
36
- Object.defineProperty(exports, "isLogEvent", { enumerable: true, get: function () { return events_js_1.isLogEvent; } });
37
- Object.defineProperty(exports, "isToolCallEvent", { enumerable: true, get: function () { return events_js_1.isToolCallEvent; } });
38
- Object.defineProperty(exports, "isToolResultAppliedEvent", { enumerable: true, get: function () { return events_js_1.isToolResultAppliedEvent; } });
39
- Object.defineProperty(exports, "isFinalEvent", { enumerable: true, get: function () { return events_js_1.isFinalEvent; } });
40
- Object.defineProperty(exports, "isHeartbeatEvent", { enumerable: true, get: function () { return events_js_1.isHeartbeatEvent; } });
41
- Object.defineProperty(exports, "isErrorEvent", { enumerable: true, get: function () { return events_js_1.isErrorEvent; } });
42
- // Encryption exports
43
- var encryption_js_1 = require("./encryption.js");
44
- Object.defineProperty(exports, "SupportedCurve", { enumerable: true, get: function () { return encryption_js_1.SupportedCurve; } });
45
- Object.defineProperty(exports, "EncryptionAlgorithm", { enumerable: true, get: function () { return encryption_js_1.EncryptionAlgorithm; } });
46
- Object.defineProperty(exports, "KeyDerivation", { enumerable: true, get: function () { return encryption_js_1.KeyDerivation; } });
47
- Object.defineProperty(exports, "EncryptionMode", { enumerable: true, get: function () { return encryption_js_1.EncryptionMode; } });
48
- Object.defineProperty(exports, "EncryptionErrorCode", { enumerable: true, get: function () { return encryption_js_1.EncryptionErrorCode; } });
49
- Object.defineProperty(exports, "HkdfInfo", { enumerable: true, get: function () { return encryption_js_1.HkdfInfo; } });
50
- Object.defineProperty(exports, "AES_GCM_NONCE_SIZE", { enumerable: true, get: function () { return encryption_js_1.AES_GCM_NONCE_SIZE; } });
51
- Object.defineProperty(exports, "AES_GCM_TAG_SIZE", { enumerable: true, get: function () { return encryption_js_1.AES_GCM_TAG_SIZE; } });
52
- Object.defineProperty(exports, "AES_256_KEY_SIZE", { enumerable: true, get: function () { return encryption_js_1.AES_256_KEY_SIZE; } });
53
- Object.defineProperty(exports, "MAX_MESSAGES_PER_KEY", { enumerable: true, get: function () { return encryption_js_1.MAX_MESSAGES_PER_KEY; } });
54
- Object.defineProperty(exports, "isEncryptedEnvelope", { enumerable: true, get: function () { return encryption_js_1.isEncryptedEnvelope; } });
55
- // Schema exports
56
- var schemas_js_1 = require("./schemas.js");
57
- // Base schemas
58
- Object.defineProperty(exports, "ProtocolVersionSchema", { enumerable: true, get: function () { return schemas_js_1.ProtocolVersionSchema; } });
59
- Object.defineProperty(exports, "SessionIdSchema", { enumerable: true, get: function () { return schemas_js_1.SessionIdSchema; } });
60
- Object.defineProperty(exports, "CallIdSchema", { enumerable: true, get: function () { return schemas_js_1.CallIdSchema; } });
61
- Object.defineProperty(exports, "RefIdSchema", { enumerable: true, get: function () { return schemas_js_1.RefIdSchema; } });
62
- Object.defineProperty(exports, "LogLevelSchema", { enumerable: true, get: function () { return schemas_js_1.LogLevelSchema; } });
63
- Object.defineProperty(exports, "SessionStateSchema", { enumerable: true, get: function () { return schemas_js_1.SessionStateSchema; } });
64
- Object.defineProperty(exports, "ErrorInfoSchema", { enumerable: true, get: function () { return schemas_js_1.ErrorInfoSchema; } });
65
- Object.defineProperty(exports, "RefTokenSchema", { enumerable: true, get: function () { return schemas_js_1.RefTokenSchema; } });
66
- Object.defineProperty(exports, "SessionLimitsSchema", { enumerable: true, get: function () { return schemas_js_1.SessionLimitsSchema; } });
67
- Object.defineProperty(exports, "ToolConfigSchema", { enumerable: true, get: function () { return schemas_js_1.ToolConfigSchema; } });
68
- Object.defineProperty(exports, "BaseEventSchema", { enumerable: true, get: function () { return schemas_js_1.BaseEventSchema; } });
69
- // Event payload schemas
70
- Object.defineProperty(exports, "EncryptionConfigSchema", { enumerable: true, get: function () { return schemas_js_1.EncryptionConfigSchema; } });
71
- Object.defineProperty(exports, "SessionInitPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.SessionInitPayloadSchema; } });
72
- Object.defineProperty(exports, "StdoutPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.StdoutPayloadSchema; } });
73
- Object.defineProperty(exports, "LogPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.LogPayloadSchema; } });
74
- Object.defineProperty(exports, "ToolCallPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.ToolCallPayloadSchema; } });
75
- Object.defineProperty(exports, "ToolResultAppliedPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.ToolResultAppliedPayloadSchema; } });
76
- Object.defineProperty(exports, "SessionStatsSchema", { enumerable: true, get: function () { return schemas_js_1.SessionStatsSchema; } });
77
- Object.defineProperty(exports, "FinalPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.FinalPayloadSchema; } });
78
- Object.defineProperty(exports, "HeartbeatPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.HeartbeatPayloadSchema; } });
79
- Object.defineProperty(exports, "ErrorEventPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.ErrorEventPayloadSchema; } });
80
- // Event schemas
81
- Object.defineProperty(exports, "SessionInitEventSchema", { enumerable: true, get: function () { return schemas_js_1.SessionInitEventSchema; } });
82
- Object.defineProperty(exports, "StdoutEventSchema", { enumerable: true, get: function () { return schemas_js_1.StdoutEventSchema; } });
83
- Object.defineProperty(exports, "LogEventSchema", { enumerable: true, get: function () { return schemas_js_1.LogEventSchema; } });
84
- Object.defineProperty(exports, "ToolCallEventSchema", { enumerable: true, get: function () { return schemas_js_1.ToolCallEventSchema; } });
85
- Object.defineProperty(exports, "ToolResultAppliedEventSchema", { enumerable: true, get: function () { return schemas_js_1.ToolResultAppliedEventSchema; } });
86
- Object.defineProperty(exports, "FinalEventSchema", { enumerable: true, get: function () { return schemas_js_1.FinalEventSchema; } });
87
- Object.defineProperty(exports, "HeartbeatEventSchema", { enumerable: true, get: function () { return schemas_js_1.HeartbeatEventSchema; } });
88
- Object.defineProperty(exports, "ErrorEventSchema", { enumerable: true, get: function () { return schemas_js_1.ErrorEventSchema; } });
89
- Object.defineProperty(exports, "StreamEventSchema", { enumerable: true, get: function () { return schemas_js_1.StreamEventSchema; } });
90
- // Encryption schemas
91
- Object.defineProperty(exports, "SupportedCurveSchema", { enumerable: true, get: function () { return schemas_js_1.SupportedCurveSchema; } });
92
- Object.defineProperty(exports, "EncryptionAlgorithmSchema", { enumerable: true, get: function () { return schemas_js_1.EncryptionAlgorithmSchema; } });
93
- Object.defineProperty(exports, "KeyDerivationSchema", { enumerable: true, get: function () { return schemas_js_1.KeyDerivationSchema; } });
94
- Object.defineProperty(exports, "EncryptionModeSchema", { enumerable: true, get: function () { return schemas_js_1.EncryptionModeSchema; } });
95
- Object.defineProperty(exports, "EncryptedEnvelopePayloadSchema", { enumerable: true, get: function () { return schemas_js_1.EncryptedEnvelopePayloadSchema; } });
96
- Object.defineProperty(exports, "EncryptedEnvelopeSchema", { enumerable: true, get: function () { return schemas_js_1.EncryptedEnvelopeSchema; } });
97
- Object.defineProperty(exports, "ClientHelloSchema", { enumerable: true, get: function () { return schemas_js_1.ClientHelloSchema; } });
98
- Object.defineProperty(exports, "ServerHelloSchema", { enumerable: true, get: function () { return schemas_js_1.ServerHelloSchema; } });
99
- Object.defineProperty(exports, "EncryptionRequestSchema", { enumerable: true, get: function () { return schemas_js_1.EncryptionRequestSchema; } });
100
- // Runtime channel schemas
101
- Object.defineProperty(exports, "ToolResultSubmitPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.ToolResultSubmitPayloadSchema; } });
102
- Object.defineProperty(exports, "ToolResultSubmitMessageSchema", { enumerable: true, get: function () { return schemas_js_1.ToolResultSubmitMessageSchema; } });
103
- Object.defineProperty(exports, "CancelPayloadSchema", { enumerable: true, get: function () { return schemas_js_1.CancelPayloadSchema; } });
104
- Object.defineProperty(exports, "CancelMessageSchema", { enumerable: true, get: function () { return schemas_js_1.CancelMessageSchema; } });
105
- Object.defineProperty(exports, "RuntimeChannelMessageSchema", { enumerable: true, get: function () { return schemas_js_1.RuntimeChannelMessageSchema; } });
106
- // Session request schemas
107
- Object.defineProperty(exports, "CreateSessionRequestSchema", { enumerable: true, get: function () { return schemas_js_1.CreateSessionRequestSchema; } });
108
- // Validation helpers
109
- Object.defineProperty(exports, "parseStreamEvent", { enumerable: true, get: function () { return schemas_js_1.parseStreamEvent; } });
110
- Object.defineProperty(exports, "parseEncryptedEnvelope", { enumerable: true, get: function () { return schemas_js_1.parseEncryptedEnvelope; } });
111
- Object.defineProperty(exports, "parseRuntimeChannelMessage", { enumerable: true, get: function () { return schemas_js_1.parseRuntimeChannelMessage; } });
112
- Object.defineProperty(exports, "parseCreateSessionRequest", { enumerable: true, get: function () { return schemas_js_1.parseCreateSessionRequest; } });
113
- Object.defineProperty(exports, "parseStreamEventOrEncrypted", { enumerable: true, get: function () { return schemas_js_1.parseStreamEventOrEncrypted; } });
114
- // Filter exports
115
- var filter_js_1 = require("./filter.js");
116
- Object.defineProperty(exports, "FilterMode", { enumerable: true, get: function () { return filter_js_1.FilterMode; } });
117
- Object.defineProperty(exports, "PatternType", { enumerable: true, get: function () { return filter_js_1.PatternType; } });
118
- Object.defineProperty(exports, "DEFAULT_ALWAYS_ALLOW", { enumerable: true, get: function () { return filter_js_1.DEFAULT_ALWAYS_ALLOW; } });
119
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;AAEH,mBAAmB;AACnB,6CAgBuB;AAfrB,+GAAA,gBAAgB,OAAA;AAChB,gHAAA,iBAAiB,OAAA;AACjB,6GAAA,cAAc,OAAA;AACd,4GAAA,aAAa,OAAA;AACb,gHAAA,iBAAiB,OAAA;AACjB,6G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HAAA,oBAAoB,OAAA","sourcesContent":["/**\n * @enclave-vm/types\n *\n * Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol.\n *\n * @packageDocumentation\n */\n\n// Protocol exports\nexport {\n PROTOCOL_VERSION,\n SESSION_ID_PREFIX,\n CALL_ID_PREFIX,\n REF_ID_PREFIX,\n generateSessionId,\n generateCallId,\n generateRefId,\n isSessionId,\n isCallId,\n isRefId,\n DEFAULT_SESSION_LIMITS,\n SessionState,\n LogLevel,\n isRefToken,\n createRefToken,\n} from './protocol.js';\n\nexport type {\n ProtocolVersion,\n SessionId,\n CallId,\n RefId,\n SessionLimits,\n ToolConfig,\n RefToken,\n ErrorInfo,\n} from './protocol.js';\n\n// Event exports\nexport {\n EventType,\n RuntimeChannelMessageType,\n getEventType,\n isSessionInitEvent,\n isStdoutEvent,\n isLogEvent,\n isToolCallEvent,\n isToolResultAppliedEvent,\n isFinalEvent,\n isHeartbeatEvent,\n isErrorEvent,\n} from './events.js';\n\nexport type {\n BaseEvent,\n EncryptionConfig,\n SessionInitPayload,\n SessionInitEvent,\n StdoutPayload,\n StdoutEvent,\n LogPayload,\n LogEvent,\n ToolCallPayload,\n ToolCallEvent,\n ToolResultAppliedPayload,\n ToolResultAppliedEvent,\n FinalPayload,\n SessionStats,\n FinalEvent,\n HeartbeatPayload,\n HeartbeatEvent,\n ErrorEventPayload,\n ErrorEvent,\n StreamEvent,\n ToolResultSubmitPayload,\n ToolResultSubmitMessage,\n CancelPayload,\n CancelMessage,\n RuntimeChannelMessage,\n} from './events.js';\n\n// Encryption exports\nexport {\n SupportedCurve,\n EncryptionAlgorithm,\n KeyDerivation,\n EncryptionMode,\n EncryptionErrorCode,\n HkdfInfo,\n AES_GCM_NONCE_SIZE,\n AES_GCM_TAG_SIZE,\n AES_256_KEY_SIZE,\n MAX_MESSAGES_PER_KEY,\n isEncryptedEnvelope,\n} from './encryption.js';\n\nexport type {\n EncryptedEnvelopePayload,\n EncryptedEnvelope,\n ClientHello,\n ServerHello,\n EncryptionRequest,\n SessionKeyInfo,\n MaybeEncrypted,\n} from './encryption.js';\n\n// Schema exports\nexport {\n // Base schemas\n ProtocolVersionSchema,\n SessionIdSchema,\n CallIdSchema,\n RefIdSchema,\n LogLevelSchema,\n SessionStateSchema,\n ErrorInfoSchema,\n RefTokenSchema,\n SessionLimitsSchema,\n ToolConfigSchema,\n BaseEventSchema,\n // Event payload schemas\n EncryptionConfigSchema,\n SessionInitPayloadSchema,\n StdoutPayloadSchema,\n LogPayloadSchema,\n ToolCallPayloadSchema,\n ToolResultAppliedPayloadSchema,\n SessionStatsSchema,\n FinalPayloadSchema,\n HeartbeatPayloadSchema,\n ErrorEventPayloadSchema,\n // Event schemas\n SessionInitEventSchema,\n StdoutEventSchema,\n LogEventSchema,\n ToolCallEventSchema,\n ToolResultAppliedEventSchema,\n FinalEventSchema,\n HeartbeatEventSchema,\n ErrorEventSchema,\n StreamEventSchema,\n // Encryption schemas\n SupportedCurveSchema,\n EncryptionAlgorithmSchema,\n KeyDerivationSchema,\n EncryptionModeSchema,\n EncryptedEnvelopePayloadSchema,\n EncryptedEnvelopeSchema,\n ClientHelloSchema,\n ServerHelloSchema,\n EncryptionRequestSchema,\n // Runtime channel schemas\n ToolResultSubmitPayloadSchema,\n ToolResultSubmitMessageSchema,\n CancelPayloadSchema,\n CancelMessageSchema,\n RuntimeChannelMessageSchema,\n // Session request schemas\n CreateSessionRequestSchema,\n // Validation helpers\n parseStreamEvent,\n parseEncryptedEnvelope,\n parseRuntimeChannelMessage,\n parseCreateSessionRequest,\n parseStreamEventOrEncrypted,\n} from './schemas.js';\n\nexport type {\n ParsedStreamEvent,\n ParsedEncryptedEnvelope,\n ParsedRuntimeChannelMessage,\n ParsedCreateSessionRequest,\n} from './schemas.js';\n\n// Filter exports\nexport { FilterMode, PatternType, DEFAULT_ALWAYS_ALLOW } from './filter.js';\n\nexport type { ContentPattern, TypeFilter, ContentFilter, FilterRule, EventFilterConfig } from './filter.js';\n"]}
package/src/protocol.js DELETED
@@ -1,126 +0,0 @@
1
- "use strict";
2
- /**
3
- * @enclave-vm/types - Protocol definitions
4
- *
5
- * Core protocol constants and base types for the EnclaveJS streaming runtime.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.LogLevel = exports.SessionState = exports.DEFAULT_SESSION_LIMITS = exports.REF_ID_PREFIX = exports.CALL_ID_PREFIX = exports.SESSION_ID_PREFIX = exports.PROTOCOL_VERSION = void 0;
9
- exports.generateSessionId = generateSessionId;
10
- exports.generateCallId = generateCallId;
11
- exports.generateRefId = generateRefId;
12
- exports.isSessionId = isSessionId;
13
- exports.isCallId = isCallId;
14
- exports.isRefId = isRefId;
15
- exports.isRefToken = isRefToken;
16
- exports.createRefToken = createRefToken;
17
- /**
18
- * Current protocol version.
19
- * Increment when making breaking changes to the wire format.
20
- */
21
- exports.PROTOCOL_VERSION = 1;
22
- /**
23
- * Session ID prefix for identification and debugging.
24
- */
25
- exports.SESSION_ID_PREFIX = 's_';
26
- /**
27
- * Call ID prefix for tool call identification.
28
- */
29
- exports.CALL_ID_PREFIX = 'c_';
30
- /**
31
- * Reference ID prefix for sidecar references.
32
- */
33
- exports.REF_ID_PREFIX = 'ref_';
34
- /**
35
- * Generate a unique session ID.
36
- */
37
- function generateSessionId() {
38
- return `${exports.SESSION_ID_PREFIX}${crypto.randomUUID()}`;
39
- }
40
- /**
41
- * Generate a unique call ID.
42
- */
43
- function generateCallId() {
44
- return `${exports.CALL_ID_PREFIX}${crypto.randomUUID()}`;
45
- }
46
- /**
47
- * Generate a unique reference ID.
48
- */
49
- function generateRefId() {
50
- return `${exports.REF_ID_PREFIX}${crypto.randomUUID()}`;
51
- }
52
- /**
53
- * Check if a string is a valid session ID.
54
- */
55
- function isSessionId(value) {
56
- return value.startsWith(exports.SESSION_ID_PREFIX);
57
- }
58
- /**
59
- * Check if a string is a valid call ID.
60
- */
61
- function isCallId(value) {
62
- return value.startsWith(exports.CALL_ID_PREFIX);
63
- }
64
- /**
65
- * Check if a string is a valid reference ID.
66
- */
67
- function isRefId(value) {
68
- return value.startsWith(exports.REF_ID_PREFIX);
69
- }
70
- /**
71
- * Default session limits.
72
- */
73
- exports.DEFAULT_SESSION_LIMITS = {
74
- sessionTtlMs: 60000,
75
- maxToolCalls: 50,
76
- maxStdoutBytes: 262144,
77
- maxToolResultBytes: 5242880,
78
- toolTimeoutMs: 30000,
79
- heartbeatIntervalMs: 15000,
80
- };
81
- /**
82
- * Session state enumeration.
83
- */
84
- exports.SessionState = {
85
- /** Session is starting up */
86
- Starting: 'starting',
87
- /** Session is actively running code */
88
- Running: 'running',
89
- /** Session is waiting for a tool result */
90
- WaitingForTool: 'waiting_for_tool',
91
- /** Session completed successfully */
92
- Completed: 'completed',
93
- /** Session was cancelled */
94
- Cancelled: 'cancelled',
95
- /** Session failed with an error */
96
- Failed: 'failed',
97
- };
98
- /**
99
- * Check if a value is a reference token.
100
- */
101
- function isRefToken(value) {
102
- return (typeof value === 'object' &&
103
- value !== null &&
104
- '$ref' in value &&
105
- typeof value.$ref === 'object' &&
106
- value.$ref !== null &&
107
- 'id' in value.$ref &&
108
- typeof value.$ref.id === 'string' &&
109
- isRefId(value.$ref.id));
110
- }
111
- /**
112
- * Create a reference token from a ref ID.
113
- */
114
- function createRefToken(id) {
115
- return { $ref: { id } };
116
- }
117
- /**
118
- * Log levels for session logging.
119
- */
120
- exports.LogLevel = {
121
- Debug: 'debug',
122
- Info: 'info',
123
- Warn: 'warn',
124
- Error: 'error',
125
- };
126
- //# sourceMappingURL=protocol.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA8CH,8CAEC;AAKD,wCAEC;AAKD,sCAEC;AAKD,kCAEC;AAKD,4BAEC;AAKD,0BAEC;AAsHD,gCAWC;AAKD,wCAEC;AAzND;;;GAGG;AACU,QAAA,gBAAgB,GAAG,CAAU,CAAC;AAO3C;;GAE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5B,SAAS,EAAE,WAAW;IACtB,mCAAmC;IACnC,MAAM,EAAE,QAAQ;CACR,CAAC;AA4CX;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAAkB,CAAC,IAAI,KAAK,QAAQ;QAC3C,KAAkB,CAAC,IAAI,KAAK,IAAI;QACjC,IAAI,IAAK,KAAkB,CAAC,IAAI;QAChC,OAAQ,KAAkB,CAAC,IAAI,CAAC,EAAE,KAAK,QAAQ;QAC/C,OAAO,CAAE,KAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CACrC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,EAAS;IACtC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AAC1B,CAAC;AAcD;;GAEG;AACU,QAAA,QAAQ,GAAG;IACtB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACN,CAAC","sourcesContent":["/**\n * @enclave-vm/types - Protocol definitions\n *\n * Core protocol constants and base types for the EnclaveJS streaming runtime.\n */\n\n/**\n * Current protocol version.\n * Increment when making breaking changes to the wire format.\n */\nexport const PROTOCOL_VERSION = 1 as const;\n\n/**\n * Protocol version type for type-safe versioning.\n */\nexport type ProtocolVersion = typeof PROTOCOL_VERSION;\n\n/**\n * Session ID prefix for identification and debugging.\n */\nexport const SESSION_ID_PREFIX = 's_' as const;\n\n/**\n * Call ID prefix for tool call identification.\n */\nexport const CALL_ID_PREFIX = 'c_' as const;\n\n/**\n * Reference ID prefix for sidecar references.\n */\nexport const REF_ID_PREFIX = 'ref_' as const;\n\n/**\n * Session identifier type.\n */\nexport type SessionId = `${typeof SESSION_ID_PREFIX}${string}`;\n\n/**\n * Tool call identifier type.\n */\nexport type CallId = `${typeof CALL_ID_PREFIX}${string}`;\n\n/**\n * Reference identifier type.\n */\nexport type RefId = `${typeof REF_ID_PREFIX}${string}`;\n\n/**\n * Generate a unique session ID.\n */\nexport function generateSessionId(): SessionId {\n return `${SESSION_ID_PREFIX}${crypto.randomUUID()}`;\n}\n\n/**\n * Generate a unique call ID.\n */\nexport function generateCallId(): CallId {\n return `${CALL_ID_PREFIX}${crypto.randomUUID()}`;\n}\n\n/**\n * Generate a unique reference ID.\n */\nexport function generateRefId(): RefId {\n return `${REF_ID_PREFIX}${crypto.randomUUID()}`;\n}\n\n/**\n * Check if a string is a valid session ID.\n */\nexport function isSessionId(value: string): value is SessionId {\n return value.startsWith(SESSION_ID_PREFIX);\n}\n\n/**\n * Check if a string is a valid call ID.\n */\nexport function isCallId(value: string): value is CallId {\n return value.startsWith(CALL_ID_PREFIX);\n}\n\n/**\n * Check if a string is a valid reference ID.\n */\nexport function isRefId(value: string): value is RefId {\n return value.startsWith(REF_ID_PREFIX);\n}\n\n/**\n * Session limits configuration.\n */\nexport interface SessionLimits {\n /**\n * Maximum session duration in milliseconds.\n * @default 60000 (1 minute)\n */\n sessionTtlMs?: number;\n\n /**\n * Maximum number of tool calls allowed in a session.\n * @default 50\n */\n maxToolCalls?: number;\n\n /**\n * Maximum stdout/output bytes.\n * @default 262144 (256KB)\n */\n maxStdoutBytes?: number;\n\n /**\n * Maximum size of a single tool result in bytes.\n * @default 5242880 (5MB)\n */\n maxToolResultBytes?: number;\n\n /**\n * Individual tool execution timeout in milliseconds.\n * @default 30000 (30 seconds)\n */\n toolTimeoutMs?: number;\n\n /**\n * Heartbeat interval in milliseconds.\n * @default 15000 (15 seconds)\n */\n heartbeatIntervalMs?: number;\n}\n\n/**\n * Default session limits.\n */\nexport const DEFAULT_SESSION_LIMITS: Required<SessionLimits> = {\n sessionTtlMs: 60000,\n maxToolCalls: 50,\n maxStdoutBytes: 262144,\n maxToolResultBytes: 5242880,\n toolTimeoutMs: 30000,\n heartbeatIntervalMs: 15000,\n};\n\n/**\n * Session state enumeration.\n */\nexport const SessionState = {\n /** Session is starting up */\n Starting: 'starting',\n /** Session is actively running code */\n Running: 'running',\n /** Session is waiting for a tool result */\n WaitingForTool: 'waiting_for_tool',\n /** Session completed successfully */\n Completed: 'completed',\n /** Session was cancelled */\n Cancelled: 'cancelled',\n /** Session failed with an error */\n Failed: 'failed',\n} as const;\n\nexport type SessionState = (typeof SessionState)[keyof typeof SessionState];\n\n/**\n * Tool configuration for timeout and retry behavior.\n */\nexport interface ToolConfig {\n /**\n * Tool execution timeout in milliseconds.\n * Overrides session-level toolTimeoutMs.\n */\n timeout?: number;\n\n /**\n * Whether the tool can be retried on failure.\n * @default false\n */\n retryable?: boolean;\n\n /**\n * Maximum number of retries if retryable is true.\n * @default 3\n */\n maxRetries?: number;\n\n /**\n * Whether the tool result can be read by runtime code.\n * If false, result is always stored as a reference.\n * @default true\n */\n runtimeReadable?: boolean;\n}\n\n/**\n * Reference token for pass-by-reference values.\n * Used to avoid transmitting large/sensitive values through the runtime.\n */\nexport interface RefToken {\n $ref: {\n id: RefId;\n };\n}\n\n/**\n * Check if a value is a reference token.\n */\nexport function isRefToken(value: unknown): value is RefToken {\n return (\n typeof value === 'object' &&\n value !== null &&\n '$ref' in value &&\n typeof (value as RefToken).$ref === 'object' &&\n (value as RefToken).$ref !== null &&\n 'id' in (value as RefToken).$ref &&\n typeof (value as RefToken).$ref.id === 'string' &&\n isRefId((value as RefToken).$ref.id)\n );\n}\n\n/**\n * Create a reference token from a ref ID.\n */\nexport function createRefToken(id: RefId): RefToken {\n return { $ref: { id } };\n}\n\n/**\n * Error information structure.\n */\nexport interface ErrorInfo {\n /** Human-readable error message */\n message: string;\n /** Machine-readable error code */\n code?: string;\n /** Stack trace (only in development/debug mode) */\n stack?: string;\n}\n\n/**\n * Log levels for session logging.\n */\nexport const LogLevel = {\n Debug: 'debug',\n Info: 'info',\n Warn: 'warn',\n Error: 'error',\n} as const;\n\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n"]}