@fluxpointstudios/orynq-sdk-flight-recorder 0.1.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/LICENSE +21 -0
- package/dist/crypto/compression.d.ts +37 -0
- package/dist/crypto/compression.d.ts.map +1 -0
- package/dist/crypto/compression.js +84 -0
- package/dist/crypto/compression.js.map +1 -0
- package/dist/crypto/encryption.d.ts +44 -0
- package/dist/crypto/encryption.d.ts.map +1 -0
- package/dist/crypto/encryption.js +129 -0
- package/dist/crypto/encryption.js.map +1 -0
- package/dist/crypto/hashing.d.ts +63 -0
- package/dist/crypto/hashing.d.ts.map +1 -0
- package/dist/crypto/hashing.js +182 -0
- package/dist/crypto/hashing.js.map +1 -0
- package/dist/crypto/index.d.ts +4 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +4 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/integration/index.d.ts +2 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/index.js +2 -0
- package/dist/integration/index.js.map +1 -0
- package/dist/integration/openclaw-adapter.d.ts +64 -0
- package/dist/integration/openclaw-adapter.d.ts.map +1 -0
- package/dist/integration/openclaw-adapter.js +137 -0
- package/dist/integration/openclaw-adapter.js.map +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +2 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manifest-builder.d.ts +72 -0
- package/dist/manifest/manifest-builder.d.ts.map +1 -0
- package/dist/manifest/manifest-builder.js +84 -0
- package/dist/manifest/manifest-builder.js.map +1 -0
- package/dist/recorder/chunk-manager.d.ts +56 -0
- package/dist/recorder/chunk-manager.d.ts.map +1 -0
- package/dist/recorder/chunk-manager.js +172 -0
- package/dist/recorder/chunk-manager.js.map +1 -0
- package/dist/recorder/event-buffer.d.ts +61 -0
- package/dist/recorder/event-buffer.d.ts.map +1 -0
- package/dist/recorder/event-buffer.js +101 -0
- package/dist/recorder/event-buffer.js.map +1 -0
- package/dist/recorder/index.d.ts +4 -0
- package/dist/recorder/index.d.ts.map +1 -0
- package/dist/recorder/index.js +4 -0
- package/dist/recorder/index.js.map +1 -0
- package/dist/recorder/stream-recorder.d.ts +66 -0
- package/dist/recorder/stream-recorder.d.ts.map +1 -0
- package/dist/recorder/stream-recorder.js +329 -0
- package/dist/recorder/stream-recorder.js.map +1 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/local-adapter.d.ts +65 -0
- package/dist/storage/local-adapter.d.ts.map +1 -0
- package/dist/storage/local-adapter.js +152 -0
- package/dist/storage/local-adapter.js.map +1 -0
- package/dist/types.d.ts +284 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
- package/src/__tests__/flight-recorder.test.ts +211 -0
- package/src/crypto/compression.ts +105 -0
- package/src/crypto/encryption.ts +210 -0
- package/src/crypto/hashing.ts +225 -0
- package/src/crypto/index.ts +3 -0
- package/src/index.ts +96 -0
- package/src/integration/index.ts +1 -0
- package/src/integration/openclaw-adapter.ts +206 -0
- package/src/manifest/index.ts +1 -0
- package/src/manifest/manifest-builder.ts +152 -0
- package/src/recorder/chunk-manager.ts +224 -0
- package/src/recorder/event-buffer.ts +124 -0
- package/src/recorder/index.ts +3 -0
- package/src/recorder/stream-recorder.ts +427 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/local-adapter.ts +181 -0
- package/src/types.ts +347 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the PoI Flight Recorder.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// === TEE Types ===
|
|
6
|
+
|
|
7
|
+
export type TeeType = "sev-snp" | "tdx" | "sgx" | "nitro" | "gpu-cc";
|
|
8
|
+
|
|
9
|
+
// === Visibility ===
|
|
10
|
+
|
|
11
|
+
export type Visibility = "public" | "private" | "redacted";
|
|
12
|
+
|
|
13
|
+
// === Encryption Configuration ===
|
|
14
|
+
|
|
15
|
+
export interface EncryptionConfig {
|
|
16
|
+
algorithm: "aes-256-gcm" | "chacha20-poly1305";
|
|
17
|
+
keyDerivation: "hkdf-sha256";
|
|
18
|
+
keyMode:
|
|
19
|
+
| { type: "ephemeral" }
|
|
20
|
+
| { type: "sealed"; teeType: TeeType }
|
|
21
|
+
| { type: "wrapped"; pubkeys: string[] };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// === Recorder Configuration ===
|
|
25
|
+
|
|
26
|
+
export interface RecorderConfig {
|
|
27
|
+
agentId: string;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
chunkSizeBytes: number;
|
|
30
|
+
chunkTimeoutMs?: number;
|
|
31
|
+
encryption: EncryptionConfig;
|
|
32
|
+
storage: StorageAdapter;
|
|
33
|
+
attestor?: Attestor;
|
|
34
|
+
captureRuntime?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// === Storage Adapter Interface ===
|
|
38
|
+
|
|
39
|
+
export interface StorageAdapter {
|
|
40
|
+
readonly type: "local" | "ipfs" | "s3" | "arweave";
|
|
41
|
+
store(data: Uint8Array): Promise<StorageRef>;
|
|
42
|
+
storeManifest(manifest: ManifestV2): Promise<StorageRef>;
|
|
43
|
+
fetch(ref: StorageRef): Promise<Uint8Array>;
|
|
44
|
+
fetchManifest(ref: StorageRef): Promise<ManifestV2>;
|
|
45
|
+
verify(ref: StorageRef): Promise<boolean>;
|
|
46
|
+
delete?(ref: StorageRef): Promise<void>;
|
|
47
|
+
pin?(ref: StorageRef): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface StorageRef {
|
|
51
|
+
type: "local" | "ipfs" | "s3" | "arweave";
|
|
52
|
+
uri: string;
|
|
53
|
+
hash: string;
|
|
54
|
+
size: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// === Attestor Interface ===
|
|
58
|
+
|
|
59
|
+
export interface Attestor {
|
|
60
|
+
readonly teeType: TeeType;
|
|
61
|
+
attest(hashToSign: string): Promise<AttestationBundle>;
|
|
62
|
+
getMeasurements(): Promise<Measurements>;
|
|
63
|
+
isAttested(): boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface AttestationBundle {
|
|
67
|
+
teeType: TeeType;
|
|
68
|
+
teeVersion: string;
|
|
69
|
+
evidence: {
|
|
70
|
+
format: "raw" | "base64" | "cbor";
|
|
71
|
+
data?: string;
|
|
72
|
+
hash?: string;
|
|
73
|
+
storageUri?: string;
|
|
74
|
+
};
|
|
75
|
+
binding: {
|
|
76
|
+
hash: string;
|
|
77
|
+
hashType: "rootHash" | "manifestHash" | "merkleRoot";
|
|
78
|
+
timestamp: string;
|
|
79
|
+
};
|
|
80
|
+
verifierPolicy: VerifierPolicy;
|
|
81
|
+
attestorId: string;
|
|
82
|
+
attestorPubkey?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface VerifierPolicy {
|
|
86
|
+
expectedMeasurements?: string[];
|
|
87
|
+
allowedSignerKeys?: string[];
|
|
88
|
+
minFirmwareVersion?: string;
|
|
89
|
+
minSvn?: number;
|
|
90
|
+
checkRevocation?: boolean;
|
|
91
|
+
revocationListUri?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface Measurements {
|
|
95
|
+
firmwareVersion?: string;
|
|
96
|
+
sevSnp?: { launchMeasurement: string; guestPolicy: string };
|
|
97
|
+
tdx?: { mrTd: string; mrConfigId: string; tdAttributes: string };
|
|
98
|
+
sgx?: { mrEnclave: string; mrSigner: string; isvProdId: number; isvSvn: number };
|
|
99
|
+
nitro?: { pcrs: Record<number, string>; moduleId: string };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// === Event Types ===
|
|
103
|
+
|
|
104
|
+
export type RecorderEvent =
|
|
105
|
+
| InferenceStartEvent
|
|
106
|
+
| InferenceEndEvent
|
|
107
|
+
| ToolCallEvent
|
|
108
|
+
| ToolResultEvent
|
|
109
|
+
| StreamChunkEvent
|
|
110
|
+
| DecisionEvent
|
|
111
|
+
| ErrorEvent
|
|
112
|
+
| CustomEvent;
|
|
113
|
+
|
|
114
|
+
export interface BaseEvent {
|
|
115
|
+
seq: number;
|
|
116
|
+
ts: string;
|
|
117
|
+
spanId?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface InferenceStartEvent extends BaseEvent {
|
|
121
|
+
kind: "inference:start";
|
|
122
|
+
requestId: string;
|
|
123
|
+
model: string;
|
|
124
|
+
promptHash: string;
|
|
125
|
+
systemPromptHash?: string;
|
|
126
|
+
params: InferenceParams;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface InferenceEndEvent extends BaseEvent {
|
|
130
|
+
kind: "inference:end";
|
|
131
|
+
requestId: string;
|
|
132
|
+
outputHash: string;
|
|
133
|
+
tokenCounts: {
|
|
134
|
+
prompt: number;
|
|
135
|
+
completion: number;
|
|
136
|
+
};
|
|
137
|
+
durationMs: number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface ToolCallEvent extends BaseEvent {
|
|
141
|
+
kind: "tool:call";
|
|
142
|
+
toolName: string;
|
|
143
|
+
argsHash: string;
|
|
144
|
+
visibility: Visibility;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface ToolResultEvent extends BaseEvent {
|
|
148
|
+
kind: "tool:result";
|
|
149
|
+
toolName: string;
|
|
150
|
+
resultHash: string;
|
|
151
|
+
success: boolean;
|
|
152
|
+
visibility: Visibility;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface StreamChunkEvent extends BaseEvent {
|
|
156
|
+
kind: "stream:chunk";
|
|
157
|
+
chunkHash: string;
|
|
158
|
+
index: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface DecisionEvent extends BaseEvent {
|
|
162
|
+
kind: "decision";
|
|
163
|
+
decisionType: string;
|
|
164
|
+
choiceHash: string;
|
|
165
|
+
rationale?: string;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface ErrorEvent extends BaseEvent {
|
|
169
|
+
kind: "error";
|
|
170
|
+
errorType: string;
|
|
171
|
+
message: string;
|
|
172
|
+
recoverable: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface CustomEvent extends BaseEvent {
|
|
176
|
+
kind: "custom";
|
|
177
|
+
eventType: string;
|
|
178
|
+
dataHash: string;
|
|
179
|
+
metadata?: Record<string, unknown>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface InferenceParams {
|
|
183
|
+
temperature?: number;
|
|
184
|
+
topP?: number;
|
|
185
|
+
topK?: number;
|
|
186
|
+
maxTokens?: number;
|
|
187
|
+
stopStrings?: string[];
|
|
188
|
+
frequencyPenalty?: number;
|
|
189
|
+
presencePenalty?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// === Chunk Types ===
|
|
193
|
+
|
|
194
|
+
export interface ChunkRef {
|
|
195
|
+
id: string;
|
|
196
|
+
hash: string;
|
|
197
|
+
size: number;
|
|
198
|
+
storageUri: string;
|
|
199
|
+
encryptionKeyId: string;
|
|
200
|
+
compression: "zstd" | "gzip" | "none";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface ChunkData {
|
|
204
|
+
ciphertext: Uint8Array;
|
|
205
|
+
nonce: Uint8Array;
|
|
206
|
+
tag: Uint8Array;
|
|
207
|
+
meta: {
|
|
208
|
+
index: number;
|
|
209
|
+
eventRange: [number, number];
|
|
210
|
+
spanIds: string[];
|
|
211
|
+
createdAt: string;
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// === ManifestV2 ===
|
|
216
|
+
|
|
217
|
+
export interface ManifestV2 {
|
|
218
|
+
formatVersion: "2.0";
|
|
219
|
+
|
|
220
|
+
// Identity
|
|
221
|
+
agentId: string;
|
|
222
|
+
sessionId: string;
|
|
223
|
+
|
|
224
|
+
// Cryptographic commitments
|
|
225
|
+
rootHash: string;
|
|
226
|
+
merkleRoot: string;
|
|
227
|
+
manifestHash: string;
|
|
228
|
+
|
|
229
|
+
// Input commitments
|
|
230
|
+
inputs: {
|
|
231
|
+
promptHash: string;
|
|
232
|
+
systemPromptHash?: string;
|
|
233
|
+
toolContextHash?: string;
|
|
234
|
+
encryptedCiphertextHashes?: string[];
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Inference parameters
|
|
238
|
+
params: {
|
|
239
|
+
model: string;
|
|
240
|
+
modelWeightDigest?: string;
|
|
241
|
+
tokenizerDigest?: string;
|
|
242
|
+
temperature?: number;
|
|
243
|
+
topP?: number;
|
|
244
|
+
topK?: number;
|
|
245
|
+
maxTokens?: number;
|
|
246
|
+
stopStrings?: string[];
|
|
247
|
+
frequencyPenalty?: number;
|
|
248
|
+
presencePenalty?: number;
|
|
249
|
+
toolPolicy?: Record<string, unknown>;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// Runtime identity
|
|
253
|
+
runtime: {
|
|
254
|
+
recorderVersion: string;
|
|
255
|
+
containerDigest?: string;
|
|
256
|
+
gitCommit?: string;
|
|
257
|
+
dependencies?: Record<string, string>;
|
|
258
|
+
gpuDriver?: string;
|
|
259
|
+
nodeVersion?: string;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Chunk references
|
|
263
|
+
chunks: ChunkRef[];
|
|
264
|
+
|
|
265
|
+
// Output summary
|
|
266
|
+
outputs: {
|
|
267
|
+
transcriptRollingHash: string;
|
|
268
|
+
toolCallCount: number;
|
|
269
|
+
totalTokens: number;
|
|
270
|
+
completionTokens: number;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Attestation (optional)
|
|
274
|
+
attestation?: {
|
|
275
|
+
teeType: TeeType;
|
|
276
|
+
evidenceHash: string;
|
|
277
|
+
evidenceUri?: string;
|
|
278
|
+
verifierPolicy: VerifierPolicy;
|
|
279
|
+
boundHash: "rootHash" | "manifestHash" | "merkleRoot";
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// Timestamps
|
|
283
|
+
createdAt: string;
|
|
284
|
+
startedAt: string;
|
|
285
|
+
endedAt: string;
|
|
286
|
+
durationMs: number;
|
|
287
|
+
|
|
288
|
+
// Statistics
|
|
289
|
+
totalEvents: number;
|
|
290
|
+
totalSpans: number;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// === Recording Session ===
|
|
294
|
+
|
|
295
|
+
export interface RecordingSession {
|
|
296
|
+
sessionId: string;
|
|
297
|
+
agentId: string;
|
|
298
|
+
startedAt: string;
|
|
299
|
+
status: "recording" | "finalizing" | "finalized" | "aborted";
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface RecordingResult {
|
|
303
|
+
rootHash: string;
|
|
304
|
+
merkleRoot: string;
|
|
305
|
+
manifestHash: string;
|
|
306
|
+
manifest: ManifestV2;
|
|
307
|
+
chunkRefs: ChunkRef[];
|
|
308
|
+
attestation?: AttestationBundle;
|
|
309
|
+
anchorEntry: AnchorEntry;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface AnchorEntry {
|
|
313
|
+
schema: "poi-anchor-v2";
|
|
314
|
+
rootHash: string;
|
|
315
|
+
merkleRoot: string;
|
|
316
|
+
manifestHash: string;
|
|
317
|
+
storageUri: string;
|
|
318
|
+
agentId: string;
|
|
319
|
+
sessionId: string;
|
|
320
|
+
timestamp: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// === Errors ===
|
|
324
|
+
|
|
325
|
+
export enum FlightRecorderError {
|
|
326
|
+
RECORDING_NOT_STARTED = 1001,
|
|
327
|
+
RECORDING_ALREADY_FINALIZED = 1002,
|
|
328
|
+
CHUNK_CREATION_FAILED = 1003,
|
|
329
|
+
ENCRYPTION_FAILED = 1004,
|
|
330
|
+
COMPRESSION_FAILED = 1005,
|
|
331
|
+
STORAGE_WRITE_FAILED = 2001,
|
|
332
|
+
STORAGE_READ_FAILED = 2002,
|
|
333
|
+
STORAGE_NOT_FOUND = 2003,
|
|
334
|
+
ATTESTATION_NOT_AVAILABLE = 3001,
|
|
335
|
+
ATTESTATION_FAILED = 3002,
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export class FlightRecorderException extends Error {
|
|
339
|
+
constructor(
|
|
340
|
+
public readonly code: FlightRecorderError,
|
|
341
|
+
message: string,
|
|
342
|
+
public readonly cause?: Error
|
|
343
|
+
) {
|
|
344
|
+
super(message);
|
|
345
|
+
this.name = "FlightRecorderException";
|
|
346
|
+
}
|
|
347
|
+
}
|