@enclave-vm/types 0.0.1 → 2.8.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/README.md +121 -0
- package/esm/index.mjs +492 -0
- package/esm/package.json +6 -0
- package/index.js +608 -0
- package/package.json +9 -8
- package/src/encryption.js +0 -108
- package/src/encryption.js.map +0 -1
- package/src/events.js +0 -107
- package/src/events.js.map +0 -1
- package/src/filter.js +0 -37
- package/src/filter.js.map +0 -1
- package/src/index.js +0 -119
- package/src/index.js.map +0 -1
- package/src/protocol.js +0 -126
- package/src/protocol.js.map +0 -1
- package/src/schemas.js +0 -420
- package/src/schemas.js.map +0 -1
- /package/{src/encryption.d.ts → encryption.d.ts} +0 -0
- /package/{src/events.d.ts → events.d.ts} +0 -0
- /package/{src/filter.d.ts → filter.d.ts} +0 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/protocol.d.ts → protocol.d.ts} +0 -0
- /package/{src/schemas.d.ts → schemas.d.ts} +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// libs/enclavejs-types/src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AES_256_KEY_SIZE: () => AES_256_KEY_SIZE,
|
|
24
|
+
AES_GCM_NONCE_SIZE: () => AES_GCM_NONCE_SIZE,
|
|
25
|
+
AES_GCM_TAG_SIZE: () => AES_GCM_TAG_SIZE,
|
|
26
|
+
BaseEventSchema: () => BaseEventSchema,
|
|
27
|
+
CALL_ID_PREFIX: () => CALL_ID_PREFIX,
|
|
28
|
+
CallIdSchema: () => CallIdSchema,
|
|
29
|
+
CancelMessageSchema: () => CancelMessageSchema,
|
|
30
|
+
CancelPayloadSchema: () => CancelPayloadSchema,
|
|
31
|
+
ClientHelloSchema: () => ClientHelloSchema,
|
|
32
|
+
CreateSessionRequestSchema: () => CreateSessionRequestSchema,
|
|
33
|
+
DEFAULT_ALWAYS_ALLOW: () => DEFAULT_ALWAYS_ALLOW,
|
|
34
|
+
DEFAULT_SESSION_LIMITS: () => DEFAULT_SESSION_LIMITS,
|
|
35
|
+
EncryptedEnvelopePayloadSchema: () => EncryptedEnvelopePayloadSchema,
|
|
36
|
+
EncryptedEnvelopeSchema: () => EncryptedEnvelopeSchema,
|
|
37
|
+
EncryptionAlgorithm: () => EncryptionAlgorithm,
|
|
38
|
+
EncryptionAlgorithmSchema: () => EncryptionAlgorithmSchema,
|
|
39
|
+
EncryptionConfigSchema: () => EncryptionConfigSchema,
|
|
40
|
+
EncryptionErrorCode: () => EncryptionErrorCode,
|
|
41
|
+
EncryptionMode: () => EncryptionMode,
|
|
42
|
+
EncryptionModeSchema: () => EncryptionModeSchema,
|
|
43
|
+
EncryptionRequestSchema: () => EncryptionRequestSchema,
|
|
44
|
+
ErrorEventPayloadSchema: () => ErrorEventPayloadSchema,
|
|
45
|
+
ErrorEventSchema: () => ErrorEventSchema,
|
|
46
|
+
ErrorInfoSchema: () => ErrorInfoSchema,
|
|
47
|
+
EventType: () => EventType,
|
|
48
|
+
FilterMode: () => FilterMode,
|
|
49
|
+
FinalEventSchema: () => FinalEventSchema,
|
|
50
|
+
FinalPayloadSchema: () => FinalPayloadSchema,
|
|
51
|
+
HeartbeatEventSchema: () => HeartbeatEventSchema,
|
|
52
|
+
HeartbeatPayloadSchema: () => HeartbeatPayloadSchema,
|
|
53
|
+
HkdfInfo: () => HkdfInfo,
|
|
54
|
+
KeyDerivation: () => KeyDerivation,
|
|
55
|
+
KeyDerivationSchema: () => KeyDerivationSchema,
|
|
56
|
+
LogEventSchema: () => LogEventSchema,
|
|
57
|
+
LogLevel: () => LogLevel,
|
|
58
|
+
LogLevelSchema: () => LogLevelSchema,
|
|
59
|
+
LogPayloadSchema: () => LogPayloadSchema,
|
|
60
|
+
MAX_MESSAGES_PER_KEY: () => MAX_MESSAGES_PER_KEY,
|
|
61
|
+
PROTOCOL_VERSION: () => PROTOCOL_VERSION,
|
|
62
|
+
PatternType: () => PatternType,
|
|
63
|
+
ProtocolVersionSchema: () => ProtocolVersionSchema,
|
|
64
|
+
REF_ID_PREFIX: () => REF_ID_PREFIX,
|
|
65
|
+
RefIdSchema: () => RefIdSchema,
|
|
66
|
+
RefTokenSchema: () => RefTokenSchema,
|
|
67
|
+
RuntimeChannelMessageSchema: () => RuntimeChannelMessageSchema,
|
|
68
|
+
RuntimeChannelMessageType: () => RuntimeChannelMessageType,
|
|
69
|
+
SESSION_ID_PREFIX: () => SESSION_ID_PREFIX,
|
|
70
|
+
ServerHelloSchema: () => ServerHelloSchema,
|
|
71
|
+
SessionIdSchema: () => SessionIdSchema,
|
|
72
|
+
SessionInitEventSchema: () => SessionInitEventSchema,
|
|
73
|
+
SessionInitPayloadSchema: () => SessionInitPayloadSchema,
|
|
74
|
+
SessionLimitsSchema: () => SessionLimitsSchema,
|
|
75
|
+
SessionState: () => SessionState,
|
|
76
|
+
SessionStateSchema: () => SessionStateSchema,
|
|
77
|
+
SessionStatsSchema: () => SessionStatsSchema,
|
|
78
|
+
StdoutEventSchema: () => StdoutEventSchema,
|
|
79
|
+
StdoutPayloadSchema: () => StdoutPayloadSchema,
|
|
80
|
+
StreamEventSchema: () => StreamEventSchema,
|
|
81
|
+
SupportedCurve: () => SupportedCurve,
|
|
82
|
+
SupportedCurveSchema: () => SupportedCurveSchema,
|
|
83
|
+
ToolCallEventSchema: () => ToolCallEventSchema,
|
|
84
|
+
ToolCallPayloadSchema: () => ToolCallPayloadSchema,
|
|
85
|
+
ToolConfigSchema: () => ToolConfigSchema,
|
|
86
|
+
ToolResultAppliedEventSchema: () => ToolResultAppliedEventSchema,
|
|
87
|
+
ToolResultAppliedPayloadSchema: () => ToolResultAppliedPayloadSchema,
|
|
88
|
+
ToolResultSubmitMessageSchema: () => ToolResultSubmitMessageSchema,
|
|
89
|
+
ToolResultSubmitPayloadSchema: () => ToolResultSubmitPayloadSchema,
|
|
90
|
+
createRefToken: () => createRefToken,
|
|
91
|
+
generateCallId: () => generateCallId,
|
|
92
|
+
generateRefId: () => generateRefId,
|
|
93
|
+
generateSessionId: () => generateSessionId,
|
|
94
|
+
getEventType: () => getEventType,
|
|
95
|
+
isCallId: () => isCallId,
|
|
96
|
+
isEncryptedEnvelope: () => isEncryptedEnvelope,
|
|
97
|
+
isErrorEvent: () => isErrorEvent,
|
|
98
|
+
isFinalEvent: () => isFinalEvent,
|
|
99
|
+
isHeartbeatEvent: () => isHeartbeatEvent,
|
|
100
|
+
isLogEvent: () => isLogEvent,
|
|
101
|
+
isRefId: () => isRefId,
|
|
102
|
+
isRefToken: () => isRefToken,
|
|
103
|
+
isSessionId: () => isSessionId,
|
|
104
|
+
isSessionInitEvent: () => isSessionInitEvent,
|
|
105
|
+
isStdoutEvent: () => isStdoutEvent,
|
|
106
|
+
isToolCallEvent: () => isToolCallEvent,
|
|
107
|
+
isToolResultAppliedEvent: () => isToolResultAppliedEvent,
|
|
108
|
+
parseCreateSessionRequest: () => parseCreateSessionRequest,
|
|
109
|
+
parseEncryptedEnvelope: () => parseEncryptedEnvelope,
|
|
110
|
+
parseRuntimeChannelMessage: () => parseRuntimeChannelMessage,
|
|
111
|
+
parseStreamEvent: () => parseStreamEvent,
|
|
112
|
+
parseStreamEventOrEncrypted: () => parseStreamEventOrEncrypted
|
|
113
|
+
});
|
|
114
|
+
module.exports = __toCommonJS(index_exports);
|
|
115
|
+
|
|
116
|
+
// libs/enclavejs-types/src/protocol.ts
|
|
117
|
+
var PROTOCOL_VERSION = 1;
|
|
118
|
+
var SESSION_ID_PREFIX = "s_";
|
|
119
|
+
var CALL_ID_PREFIX = "c_";
|
|
120
|
+
var REF_ID_PREFIX = "ref_";
|
|
121
|
+
function generateSessionId() {
|
|
122
|
+
return `${SESSION_ID_PREFIX}${crypto.randomUUID()}`;
|
|
123
|
+
}
|
|
124
|
+
function generateCallId() {
|
|
125
|
+
return `${CALL_ID_PREFIX}${crypto.randomUUID()}`;
|
|
126
|
+
}
|
|
127
|
+
function generateRefId() {
|
|
128
|
+
return `${REF_ID_PREFIX}${crypto.randomUUID()}`;
|
|
129
|
+
}
|
|
130
|
+
function isSessionId(value) {
|
|
131
|
+
return value.startsWith(SESSION_ID_PREFIX);
|
|
132
|
+
}
|
|
133
|
+
function isCallId(value) {
|
|
134
|
+
return value.startsWith(CALL_ID_PREFIX);
|
|
135
|
+
}
|
|
136
|
+
function isRefId(value) {
|
|
137
|
+
return value.startsWith(REF_ID_PREFIX);
|
|
138
|
+
}
|
|
139
|
+
var DEFAULT_SESSION_LIMITS = {
|
|
140
|
+
sessionTtlMs: 6e4,
|
|
141
|
+
maxToolCalls: 50,
|
|
142
|
+
maxStdoutBytes: 262144,
|
|
143
|
+
maxToolResultBytes: 5242880,
|
|
144
|
+
toolTimeoutMs: 3e4,
|
|
145
|
+
heartbeatIntervalMs: 15e3
|
|
146
|
+
};
|
|
147
|
+
var SessionState = {
|
|
148
|
+
/** Session is starting up */
|
|
149
|
+
Starting: "starting",
|
|
150
|
+
/** Session is actively running code */
|
|
151
|
+
Running: "running",
|
|
152
|
+
/** Session is waiting for a tool result */
|
|
153
|
+
WaitingForTool: "waiting_for_tool",
|
|
154
|
+
/** Session completed successfully */
|
|
155
|
+
Completed: "completed",
|
|
156
|
+
/** Session was cancelled */
|
|
157
|
+
Cancelled: "cancelled",
|
|
158
|
+
/** Session failed with an error */
|
|
159
|
+
Failed: "failed"
|
|
160
|
+
};
|
|
161
|
+
function isRefToken(value) {
|
|
162
|
+
return typeof value === "object" && value !== null && "$ref" in value && typeof value.$ref === "object" && value.$ref !== null && "id" in value.$ref && typeof value.$ref.id === "string" && isRefId(value.$ref.id);
|
|
163
|
+
}
|
|
164
|
+
function createRefToken(id) {
|
|
165
|
+
return { $ref: { id } };
|
|
166
|
+
}
|
|
167
|
+
var LogLevel = {
|
|
168
|
+
Debug: "debug",
|
|
169
|
+
Info: "info",
|
|
170
|
+
Warn: "warn",
|
|
171
|
+
Error: "error"
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// libs/enclavejs-types/src/events.ts
|
|
175
|
+
var EventType = {
|
|
176
|
+
/** Session initialization */
|
|
177
|
+
SessionInit: "session_init",
|
|
178
|
+
/** Standard output chunk */
|
|
179
|
+
Stdout: "stdout",
|
|
180
|
+
/** Log message */
|
|
181
|
+
Log: "log",
|
|
182
|
+
/** Tool call request from runtime */
|
|
183
|
+
ToolCall: "tool_call",
|
|
184
|
+
/** Tool result acknowledgment */
|
|
185
|
+
ToolResultApplied: "tool_result_applied",
|
|
186
|
+
/** Session completed */
|
|
187
|
+
Final: "final",
|
|
188
|
+
/** Keep-alive heartbeat */
|
|
189
|
+
Heartbeat: "heartbeat",
|
|
190
|
+
/** Error event */
|
|
191
|
+
Error: "error",
|
|
192
|
+
/** Encrypted envelope (wraps other events) */
|
|
193
|
+
Encrypted: "enc"
|
|
194
|
+
};
|
|
195
|
+
function getEventType(event) {
|
|
196
|
+
return event.type;
|
|
197
|
+
}
|
|
198
|
+
function isSessionInitEvent(event) {
|
|
199
|
+
return event.type === EventType.SessionInit;
|
|
200
|
+
}
|
|
201
|
+
function isStdoutEvent(event) {
|
|
202
|
+
return event.type === EventType.Stdout;
|
|
203
|
+
}
|
|
204
|
+
function isLogEvent(event) {
|
|
205
|
+
return event.type === EventType.Log;
|
|
206
|
+
}
|
|
207
|
+
function isToolCallEvent(event) {
|
|
208
|
+
return event.type === EventType.ToolCall;
|
|
209
|
+
}
|
|
210
|
+
function isToolResultAppliedEvent(event) {
|
|
211
|
+
return event.type === EventType.ToolResultApplied;
|
|
212
|
+
}
|
|
213
|
+
function isFinalEvent(event) {
|
|
214
|
+
return event.type === EventType.Final;
|
|
215
|
+
}
|
|
216
|
+
function isHeartbeatEvent(event) {
|
|
217
|
+
return event.type === EventType.Heartbeat;
|
|
218
|
+
}
|
|
219
|
+
function isErrorEvent(event) {
|
|
220
|
+
return event.type === EventType.Error;
|
|
221
|
+
}
|
|
222
|
+
var RuntimeChannelMessageType = {
|
|
223
|
+
/** Tool result submission from broker to runtime */
|
|
224
|
+
ToolResultSubmit: "tool_result_submit",
|
|
225
|
+
/** Cancel session request */
|
|
226
|
+
Cancel: "cancel"
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// libs/enclavejs-types/src/encryption.ts
|
|
230
|
+
var SupportedCurve = {
|
|
231
|
+
P256: "P-256"
|
|
232
|
+
};
|
|
233
|
+
var EncryptionAlgorithm = {
|
|
234
|
+
/** AES-GCM with 256-bit key */
|
|
235
|
+
AES_GCM_256: "AES-GCM-256"
|
|
236
|
+
};
|
|
237
|
+
var KeyDerivation = {
|
|
238
|
+
/** HKDF with SHA-256 */
|
|
239
|
+
HKDF_SHA256: "HKDF-SHA-256"
|
|
240
|
+
};
|
|
241
|
+
var EncryptionMode = {
|
|
242
|
+
/** Encryption is disabled */
|
|
243
|
+
Disabled: "disabled",
|
|
244
|
+
/** Encryption is optional (server decides) */
|
|
245
|
+
Optional: "optional",
|
|
246
|
+
/** Encryption is required */
|
|
247
|
+
Required: "required"
|
|
248
|
+
};
|
|
249
|
+
var EncryptionErrorCode = {
|
|
250
|
+
/** Handshake failed */
|
|
251
|
+
HandshakeFailed: "ENCRYPTION_HANDSHAKE_FAILED",
|
|
252
|
+
/** Key derivation failed */
|
|
253
|
+
KeyDerivationFailed: "ENCRYPTION_KEY_DERIVATION_FAILED",
|
|
254
|
+
/** Decryption failed (invalid ciphertext or authentication) */
|
|
255
|
+
DecryptionFailed: "ENCRYPTION_DECRYPTION_FAILED",
|
|
256
|
+
/** Nonce reuse detected */
|
|
257
|
+
NonceReuse: "ENCRYPTION_NONCE_REUSE",
|
|
258
|
+
/** Key expired or needs rotation */
|
|
259
|
+
KeyExpired: "ENCRYPTION_KEY_EXPIRED",
|
|
260
|
+
/** Unsupported algorithm */
|
|
261
|
+
UnsupportedAlgorithm: "ENCRYPTION_UNSUPPORTED_ALGORITHM",
|
|
262
|
+
/** Invalid public key */
|
|
263
|
+
InvalidPublicKey: "ENCRYPTION_INVALID_PUBLIC_KEY",
|
|
264
|
+
/** Signature verification failed */
|
|
265
|
+
SignatureVerificationFailed: "ENCRYPTION_SIGNATURE_VERIFICATION_FAILED"
|
|
266
|
+
};
|
|
267
|
+
function isEncryptedEnvelope(value) {
|
|
268
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "enc" && "payload" in value && typeof value.payload === "object" && value.payload !== null && "kid" in value.payload && "nonceB64" in value.payload && "ciphertextB64" in value.payload;
|
|
269
|
+
}
|
|
270
|
+
var HkdfInfo = {
|
|
271
|
+
/** Client -> Server encryption key */
|
|
272
|
+
ClientToServer: "enclavejs-c2s-enc",
|
|
273
|
+
/** Server -> Client encryption key */
|
|
274
|
+
ServerToClient: "enclavejs-s2c-enc"
|
|
275
|
+
};
|
|
276
|
+
var AES_GCM_NONCE_SIZE = 12;
|
|
277
|
+
var AES_GCM_TAG_SIZE = 16;
|
|
278
|
+
var AES_256_KEY_SIZE = 32;
|
|
279
|
+
var MAX_MESSAGES_PER_KEY = 1073741824n;
|
|
280
|
+
|
|
281
|
+
// libs/enclavejs-types/src/schemas.ts
|
|
282
|
+
var import_zod = require("zod");
|
|
283
|
+
var ProtocolVersionSchema = import_zod.z.literal(PROTOCOL_VERSION);
|
|
284
|
+
var SessionIdSchema = import_zod.z.string().startsWith(SESSION_ID_PREFIX).min(SESSION_ID_PREFIX.length + 1);
|
|
285
|
+
var CallIdSchema = import_zod.z.string().startsWith(CALL_ID_PREFIX).min(CALL_ID_PREFIX.length + 1);
|
|
286
|
+
var RefIdSchema = import_zod.z.string().startsWith(REF_ID_PREFIX).min(REF_ID_PREFIX.length + 1);
|
|
287
|
+
var LogLevelSchema = import_zod.z.enum([LogLevel.Debug, LogLevel.Info, LogLevel.Warn, LogLevel.Error]);
|
|
288
|
+
var SessionStateSchema = import_zod.z.enum([
|
|
289
|
+
SessionState.Starting,
|
|
290
|
+
SessionState.Running,
|
|
291
|
+
SessionState.WaitingForTool,
|
|
292
|
+
SessionState.Completed,
|
|
293
|
+
SessionState.Cancelled,
|
|
294
|
+
SessionState.Failed
|
|
295
|
+
]);
|
|
296
|
+
var ErrorInfoSchema = import_zod.z.object({
|
|
297
|
+
message: import_zod.z.string(),
|
|
298
|
+
code: import_zod.z.string().optional(),
|
|
299
|
+
stack: import_zod.z.string().optional()
|
|
300
|
+
});
|
|
301
|
+
var RefTokenSchema = import_zod.z.object({
|
|
302
|
+
$ref: import_zod.z.object({
|
|
303
|
+
id: RefIdSchema
|
|
304
|
+
})
|
|
305
|
+
});
|
|
306
|
+
var SessionLimitsSchema = import_zod.z.object({
|
|
307
|
+
sessionTtlMs: import_zod.z.number().int().positive().optional(),
|
|
308
|
+
maxToolCalls: import_zod.z.number().int().positive().optional(),
|
|
309
|
+
maxStdoutBytes: import_zod.z.number().int().positive().optional(),
|
|
310
|
+
maxToolResultBytes: import_zod.z.number().int().positive().optional(),
|
|
311
|
+
toolTimeoutMs: import_zod.z.number().int().positive().optional(),
|
|
312
|
+
heartbeatIntervalMs: import_zod.z.number().int().positive().optional()
|
|
313
|
+
});
|
|
314
|
+
var ToolConfigSchema = import_zod.z.object({
|
|
315
|
+
timeout: import_zod.z.number().int().positive().optional(),
|
|
316
|
+
retryable: import_zod.z.boolean().optional(),
|
|
317
|
+
maxRetries: import_zod.z.number().int().nonnegative().optional(),
|
|
318
|
+
runtimeReadable: import_zod.z.boolean().optional()
|
|
319
|
+
});
|
|
320
|
+
var BaseEventSchema = import_zod.z.object({
|
|
321
|
+
protocolVersion: ProtocolVersionSchema,
|
|
322
|
+
sessionId: SessionIdSchema,
|
|
323
|
+
seq: import_zod.z.number().int().nonnegative()
|
|
324
|
+
});
|
|
325
|
+
var EncryptionConfigSchema = import_zod.z.object({
|
|
326
|
+
enabled: import_zod.z.boolean(),
|
|
327
|
+
keyId: import_zod.z.string().optional()
|
|
328
|
+
});
|
|
329
|
+
var SessionInitPayloadSchema = import_zod.z.object({
|
|
330
|
+
cancelUrl: import_zod.z.string(),
|
|
331
|
+
expiresAt: import_zod.z.string().datetime(),
|
|
332
|
+
encryption: EncryptionConfigSchema,
|
|
333
|
+
replayUrl: import_zod.z.string().optional()
|
|
334
|
+
});
|
|
335
|
+
var StdoutPayloadSchema = import_zod.z.object({
|
|
336
|
+
chunk: import_zod.z.string()
|
|
337
|
+
});
|
|
338
|
+
var LogPayloadSchema = import_zod.z.object({
|
|
339
|
+
level: LogLevelSchema,
|
|
340
|
+
message: import_zod.z.string(),
|
|
341
|
+
data: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
342
|
+
});
|
|
343
|
+
var ToolCallPayloadSchema = import_zod.z.object({
|
|
344
|
+
callId: CallIdSchema,
|
|
345
|
+
toolName: import_zod.z.string().min(1),
|
|
346
|
+
args: import_zod.z.unknown()
|
|
347
|
+
});
|
|
348
|
+
var ToolResultAppliedPayloadSchema = import_zod.z.object({
|
|
349
|
+
callId: CallIdSchema
|
|
350
|
+
});
|
|
351
|
+
var SessionStatsSchema = import_zod.z.object({
|
|
352
|
+
durationMs: import_zod.z.number().nonnegative(),
|
|
353
|
+
toolCallCount: import_zod.z.number().int().nonnegative(),
|
|
354
|
+
stdoutBytes: import_zod.z.number().int().nonnegative()
|
|
355
|
+
});
|
|
356
|
+
var FinalPayloadSchema = import_zod.z.object({
|
|
357
|
+
ok: import_zod.z.boolean(),
|
|
358
|
+
result: import_zod.z.unknown().optional(),
|
|
359
|
+
error: ErrorInfoSchema.optional(),
|
|
360
|
+
stats: SessionStatsSchema.optional()
|
|
361
|
+
});
|
|
362
|
+
var HeartbeatPayloadSchema = import_zod.z.object({
|
|
363
|
+
ts: import_zod.z.string().datetime()
|
|
364
|
+
});
|
|
365
|
+
var ErrorEventPayloadSchema = import_zod.z.object({
|
|
366
|
+
message: import_zod.z.string(),
|
|
367
|
+
code: import_zod.z.string().optional(),
|
|
368
|
+
recoverable: import_zod.z.boolean().optional()
|
|
369
|
+
});
|
|
370
|
+
var SessionInitEventSchema = BaseEventSchema.extend({
|
|
371
|
+
type: import_zod.z.literal(EventType.SessionInit),
|
|
372
|
+
payload: SessionInitPayloadSchema
|
|
373
|
+
});
|
|
374
|
+
var StdoutEventSchema = BaseEventSchema.extend({
|
|
375
|
+
type: import_zod.z.literal(EventType.Stdout),
|
|
376
|
+
payload: StdoutPayloadSchema
|
|
377
|
+
});
|
|
378
|
+
var LogEventSchema = BaseEventSchema.extend({
|
|
379
|
+
type: import_zod.z.literal(EventType.Log),
|
|
380
|
+
payload: LogPayloadSchema
|
|
381
|
+
});
|
|
382
|
+
var ToolCallEventSchema = BaseEventSchema.extend({
|
|
383
|
+
type: import_zod.z.literal(EventType.ToolCall),
|
|
384
|
+
payload: ToolCallPayloadSchema
|
|
385
|
+
});
|
|
386
|
+
var ToolResultAppliedEventSchema = BaseEventSchema.extend({
|
|
387
|
+
type: import_zod.z.literal(EventType.ToolResultApplied),
|
|
388
|
+
payload: ToolResultAppliedPayloadSchema
|
|
389
|
+
});
|
|
390
|
+
var FinalEventSchema = BaseEventSchema.extend({
|
|
391
|
+
type: import_zod.z.literal(EventType.Final),
|
|
392
|
+
payload: FinalPayloadSchema
|
|
393
|
+
});
|
|
394
|
+
var HeartbeatEventSchema = BaseEventSchema.extend({
|
|
395
|
+
type: import_zod.z.literal(EventType.Heartbeat),
|
|
396
|
+
payload: HeartbeatPayloadSchema
|
|
397
|
+
});
|
|
398
|
+
var ErrorEventSchema = BaseEventSchema.extend({
|
|
399
|
+
type: import_zod.z.literal(EventType.Error),
|
|
400
|
+
payload: ErrorEventPayloadSchema
|
|
401
|
+
});
|
|
402
|
+
var StreamEventSchema = import_zod.z.discriminatedUnion("type", [
|
|
403
|
+
SessionInitEventSchema,
|
|
404
|
+
StdoutEventSchema,
|
|
405
|
+
LogEventSchema,
|
|
406
|
+
ToolCallEventSchema,
|
|
407
|
+
ToolResultAppliedEventSchema,
|
|
408
|
+
FinalEventSchema,
|
|
409
|
+
HeartbeatEventSchema,
|
|
410
|
+
ErrorEventSchema
|
|
411
|
+
]);
|
|
412
|
+
var SupportedCurveSchema = import_zod.z.enum([SupportedCurve.P256]);
|
|
413
|
+
var EncryptionAlgorithmSchema = import_zod.z.enum([EncryptionAlgorithm.AES_GCM_256]);
|
|
414
|
+
var KeyDerivationSchema = import_zod.z.enum([KeyDerivation.HKDF_SHA256]);
|
|
415
|
+
var EncryptionModeSchema = import_zod.z.enum([EncryptionMode.Disabled, EncryptionMode.Optional, EncryptionMode.Required]);
|
|
416
|
+
var EncryptedEnvelopePayloadSchema = import_zod.z.object({
|
|
417
|
+
kid: import_zod.z.string().min(1),
|
|
418
|
+
nonceB64: import_zod.z.string().min(1),
|
|
419
|
+
ciphertextB64: import_zod.z.string().min(1),
|
|
420
|
+
tagB64: import_zod.z.string().optional()
|
|
421
|
+
});
|
|
422
|
+
var EncryptedEnvelopeSchema = import_zod.z.object({
|
|
423
|
+
protocolVersion: ProtocolVersionSchema,
|
|
424
|
+
sessionId: SessionIdSchema,
|
|
425
|
+
seq: import_zod.z.number().int().nonnegative(),
|
|
426
|
+
type: import_zod.z.literal(EventType.Encrypted),
|
|
427
|
+
payload: EncryptedEnvelopePayloadSchema
|
|
428
|
+
});
|
|
429
|
+
var ClientHelloSchema = import_zod.z.object({
|
|
430
|
+
protocolVersion: ProtocolVersionSchema,
|
|
431
|
+
clientEphemeralPubKeyB64: import_zod.z.string().min(1),
|
|
432
|
+
curve: SupportedCurveSchema,
|
|
433
|
+
supportedAlgorithms: import_zod.z.array(EncryptionAlgorithmSchema).min(1)
|
|
434
|
+
});
|
|
435
|
+
var ServerHelloSchema = import_zod.z.object({
|
|
436
|
+
protocolVersion: ProtocolVersionSchema,
|
|
437
|
+
serverEphemeralPubKeyB64: import_zod.z.string().min(1),
|
|
438
|
+
curve: SupportedCurveSchema,
|
|
439
|
+
selectedAlgorithm: EncryptionAlgorithmSchema,
|
|
440
|
+
kdf: KeyDerivationSchema,
|
|
441
|
+
keyId: import_zod.z.string().min(1),
|
|
442
|
+
signatureB64: import_zod.z.string().optional()
|
|
443
|
+
});
|
|
444
|
+
var EncryptionRequestSchema = import_zod.z.object({
|
|
445
|
+
mode: EncryptionModeSchema,
|
|
446
|
+
clientHello: ClientHelloSchema.optional()
|
|
447
|
+
});
|
|
448
|
+
var ToolResultSubmitPayloadSchema = import_zod.z.object({
|
|
449
|
+
callId: CallIdSchema,
|
|
450
|
+
ok: import_zod.z.boolean(),
|
|
451
|
+
result: import_zod.z.unknown().optional(),
|
|
452
|
+
error: ErrorInfoSchema.optional()
|
|
453
|
+
});
|
|
454
|
+
var ToolResultSubmitMessageSchema = import_zod.z.object({
|
|
455
|
+
protocolVersion: ProtocolVersionSchema,
|
|
456
|
+
sessionId: SessionIdSchema,
|
|
457
|
+
type: import_zod.z.literal(RuntimeChannelMessageType.ToolResultSubmit),
|
|
458
|
+
payload: ToolResultSubmitPayloadSchema
|
|
459
|
+
});
|
|
460
|
+
var CancelPayloadSchema = import_zod.z.object({
|
|
461
|
+
reason: import_zod.z.string().optional()
|
|
462
|
+
});
|
|
463
|
+
var CancelMessageSchema = import_zod.z.object({
|
|
464
|
+
protocolVersion: ProtocolVersionSchema,
|
|
465
|
+
sessionId: SessionIdSchema,
|
|
466
|
+
type: import_zod.z.literal(RuntimeChannelMessageType.Cancel),
|
|
467
|
+
payload: CancelPayloadSchema
|
|
468
|
+
});
|
|
469
|
+
var RuntimeChannelMessageSchema = import_zod.z.discriminatedUnion("type", [
|
|
470
|
+
ToolResultSubmitMessageSchema,
|
|
471
|
+
CancelMessageSchema
|
|
472
|
+
]);
|
|
473
|
+
var CreateSessionRequestSchema = import_zod.z.object({
|
|
474
|
+
protocolVersion: ProtocolVersionSchema,
|
|
475
|
+
code: import_zod.z.string().min(1),
|
|
476
|
+
limits: SessionLimitsSchema.optional(),
|
|
477
|
+
encryption: EncryptionRequestSchema.optional()
|
|
478
|
+
});
|
|
479
|
+
function parseStreamEvent(data) {
|
|
480
|
+
return StreamEventSchema.safeParse(data);
|
|
481
|
+
}
|
|
482
|
+
function parseEncryptedEnvelope(data) {
|
|
483
|
+
return EncryptedEnvelopeSchema.safeParse(data);
|
|
484
|
+
}
|
|
485
|
+
function parseRuntimeChannelMessage(data) {
|
|
486
|
+
return RuntimeChannelMessageSchema.safeParse(data);
|
|
487
|
+
}
|
|
488
|
+
function parseCreateSessionRequest(data) {
|
|
489
|
+
return CreateSessionRequestSchema.safeParse(data);
|
|
490
|
+
}
|
|
491
|
+
function parseStreamEventOrEncrypted(data) {
|
|
492
|
+
if (typeof data === "object" && data !== null && "type" in data && data.type === EventType.Encrypted) {
|
|
493
|
+
return EncryptedEnvelopeSchema.safeParse(data);
|
|
494
|
+
}
|
|
495
|
+
return StreamEventSchema.safeParse(data);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// libs/enclavejs-types/src/filter.ts
|
|
499
|
+
var FilterMode = {
|
|
500
|
+
/** Include only events matching the filter (whitelist) */
|
|
501
|
+
Include: "include",
|
|
502
|
+
/** Exclude events matching the filter (blacklist) */
|
|
503
|
+
Exclude: "exclude"
|
|
504
|
+
};
|
|
505
|
+
var PatternType = {
|
|
506
|
+
/** Exact string match */
|
|
507
|
+
Exact: "exact",
|
|
508
|
+
/** Prefix match (startsWith) */
|
|
509
|
+
Prefix: "prefix",
|
|
510
|
+
/** Regular expression */
|
|
511
|
+
Regex: "regex",
|
|
512
|
+
/** Glob pattern (supports * and **) */
|
|
513
|
+
Glob: "glob"
|
|
514
|
+
};
|
|
515
|
+
var DEFAULT_ALWAYS_ALLOW = ["session_init", "final"];
|
|
516
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
517
|
+
0 && (module.exports = {
|
|
518
|
+
AES_256_KEY_SIZE,
|
|
519
|
+
AES_GCM_NONCE_SIZE,
|
|
520
|
+
AES_GCM_TAG_SIZE,
|
|
521
|
+
BaseEventSchema,
|
|
522
|
+
CALL_ID_PREFIX,
|
|
523
|
+
CallIdSchema,
|
|
524
|
+
CancelMessageSchema,
|
|
525
|
+
CancelPayloadSchema,
|
|
526
|
+
ClientHelloSchema,
|
|
527
|
+
CreateSessionRequestSchema,
|
|
528
|
+
DEFAULT_ALWAYS_ALLOW,
|
|
529
|
+
DEFAULT_SESSION_LIMITS,
|
|
530
|
+
EncryptedEnvelopePayloadSchema,
|
|
531
|
+
EncryptedEnvelopeSchema,
|
|
532
|
+
EncryptionAlgorithm,
|
|
533
|
+
EncryptionAlgorithmSchema,
|
|
534
|
+
EncryptionConfigSchema,
|
|
535
|
+
EncryptionErrorCode,
|
|
536
|
+
EncryptionMode,
|
|
537
|
+
EncryptionModeSchema,
|
|
538
|
+
EncryptionRequestSchema,
|
|
539
|
+
ErrorEventPayloadSchema,
|
|
540
|
+
ErrorEventSchema,
|
|
541
|
+
ErrorInfoSchema,
|
|
542
|
+
EventType,
|
|
543
|
+
FilterMode,
|
|
544
|
+
FinalEventSchema,
|
|
545
|
+
FinalPayloadSchema,
|
|
546
|
+
HeartbeatEventSchema,
|
|
547
|
+
HeartbeatPayloadSchema,
|
|
548
|
+
HkdfInfo,
|
|
549
|
+
KeyDerivation,
|
|
550
|
+
KeyDerivationSchema,
|
|
551
|
+
LogEventSchema,
|
|
552
|
+
LogLevel,
|
|
553
|
+
LogLevelSchema,
|
|
554
|
+
LogPayloadSchema,
|
|
555
|
+
MAX_MESSAGES_PER_KEY,
|
|
556
|
+
PROTOCOL_VERSION,
|
|
557
|
+
PatternType,
|
|
558
|
+
ProtocolVersionSchema,
|
|
559
|
+
REF_ID_PREFIX,
|
|
560
|
+
RefIdSchema,
|
|
561
|
+
RefTokenSchema,
|
|
562
|
+
RuntimeChannelMessageSchema,
|
|
563
|
+
RuntimeChannelMessageType,
|
|
564
|
+
SESSION_ID_PREFIX,
|
|
565
|
+
ServerHelloSchema,
|
|
566
|
+
SessionIdSchema,
|
|
567
|
+
SessionInitEventSchema,
|
|
568
|
+
SessionInitPayloadSchema,
|
|
569
|
+
SessionLimitsSchema,
|
|
570
|
+
SessionState,
|
|
571
|
+
SessionStateSchema,
|
|
572
|
+
SessionStatsSchema,
|
|
573
|
+
StdoutEventSchema,
|
|
574
|
+
StdoutPayloadSchema,
|
|
575
|
+
StreamEventSchema,
|
|
576
|
+
SupportedCurve,
|
|
577
|
+
SupportedCurveSchema,
|
|
578
|
+
ToolCallEventSchema,
|
|
579
|
+
ToolCallPayloadSchema,
|
|
580
|
+
ToolConfigSchema,
|
|
581
|
+
ToolResultAppliedEventSchema,
|
|
582
|
+
ToolResultAppliedPayloadSchema,
|
|
583
|
+
ToolResultSubmitMessageSchema,
|
|
584
|
+
ToolResultSubmitPayloadSchema,
|
|
585
|
+
createRefToken,
|
|
586
|
+
generateCallId,
|
|
587
|
+
generateRefId,
|
|
588
|
+
generateSessionId,
|
|
589
|
+
getEventType,
|
|
590
|
+
isCallId,
|
|
591
|
+
isEncryptedEnvelope,
|
|
592
|
+
isErrorEvent,
|
|
593
|
+
isFinalEvent,
|
|
594
|
+
isHeartbeatEvent,
|
|
595
|
+
isLogEvent,
|
|
596
|
+
isRefId,
|
|
597
|
+
isRefToken,
|
|
598
|
+
isSessionId,
|
|
599
|
+
isSessionInitEvent,
|
|
600
|
+
isStdoutEvent,
|
|
601
|
+
isToolCallEvent,
|
|
602
|
+
isToolResultAppliedEvent,
|
|
603
|
+
parseCreateSessionRequest,
|
|
604
|
+
parseEncryptedEnvelope,
|
|
605
|
+
parseRuntimeChannelMessage,
|
|
606
|
+
parseStreamEvent,
|
|
607
|
+
parseStreamEventOrEncrypted
|
|
608
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enclave-vm/types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Type definitions and Zod schemas for the EnclaveJS streaming runtime protocol",
|
|
5
5
|
"author": "AgentFront <info@agentfront.dev>",
|
|
6
6
|
"homepage": "https://github.com/agentfront/enclave",
|
|
@@ -21,18 +21,19 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/agentfront/enclave/issues"
|
|
23
23
|
},
|
|
24
|
-
"main": "./
|
|
25
|
-
"
|
|
24
|
+
"main": "./index.js",
|
|
25
|
+
"module": "./esm/index.mjs",
|
|
26
|
+
"types": "./index.d.ts",
|
|
26
27
|
"exports": {
|
|
27
28
|
"./package.json": "./package.json",
|
|
28
29
|
".": {
|
|
29
|
-
"types": "./
|
|
30
|
-
"import": "./
|
|
31
|
-
"
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"import": "./esm/index.mjs",
|
|
32
|
+
"require": "./index.js",
|
|
33
|
+
"default": "./index.js"
|
|
32
34
|
}
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"zod": "^4.1.13"
|
|
36
|
-
}
|
|
37
|
-
"type": "commonjs"
|
|
38
|
+
}
|
|
38
39
|
}
|