@opengeni/contracts 0.15.0 → 0.19.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/dist/index.d.ts +2633 -102
- package/dist/index.js +4026 -2135
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/codex-fleet-policy.ts +1405 -0
- package/src/event-preview.ts +25 -8
- package/src/index.ts +1206 -66
- package/src/retained-output.ts +339 -0
package/src/event-preview.ts
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* realtime transports, SDK/React, and tests can share one wire contract.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import {
|
|
11
|
+
retainedOutputUnavailable,
|
|
12
|
+
validateRetainedOutputEvidence,
|
|
13
|
+
type RetainedOutputEvidence,
|
|
14
|
+
} from "./retained-output";
|
|
15
|
+
|
|
10
16
|
export const SESSION_EVENT_PAYLOAD_MAX_BYTES = 64 * 1024;
|
|
11
17
|
|
|
12
18
|
const TARGET_PAYLOAD_BYTES = 60 * 1024;
|
|
@@ -62,10 +68,7 @@ export type SessionEventPayloadTruncation = {
|
|
|
62
68
|
omittedBytes: number | null;
|
|
63
69
|
estimatedOriginalTokens: number | null;
|
|
64
70
|
estimatedDeliveredTokens: number;
|
|
65
|
-
fullEvidence:
|
|
66
|
-
available: false;
|
|
67
|
-
reason: "not_retained";
|
|
68
|
-
};
|
|
71
|
+
fullEvidence: RetainedOutputEvidence;
|
|
69
72
|
details: Array<{
|
|
70
73
|
path: string;
|
|
71
74
|
kind:
|
|
@@ -87,6 +90,11 @@ export type SessionEventPayloadTruncation = {
|
|
|
87
90
|
export type BoundSessionEventPayloadOptions = {
|
|
88
91
|
surface?: SessionEventBoundarySurface;
|
|
89
92
|
maxBytes?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Separately trusted durable receipt. Producer payload fields never populate
|
|
95
|
+
* this slot; invalid values fail closed to not_retained.
|
|
96
|
+
*/
|
|
97
|
+
fullEvidence?: unknown;
|
|
90
98
|
};
|
|
91
99
|
|
|
92
100
|
export type SessionEventJsonMeasurement =
|
|
@@ -187,6 +195,8 @@ export function boundSessionEventPayload<T>(
|
|
|
187
195
|
): T {
|
|
188
196
|
const maxBytes = Math.max(1024, Math.floor(options.maxBytes ?? SESSION_EVENT_PAYLOAD_MAX_BYTES));
|
|
189
197
|
const surface = options.surface ?? "durable_audit";
|
|
198
|
+
const fullEvidence =
|
|
199
|
+
validateRetainedOutputEvidence(options.fullEvidence) ?? retainedOutputUnavailable();
|
|
190
200
|
const originalMeasurement = measureJsonBytes(payload);
|
|
191
201
|
const originalBytes = originalMeasurement.bytes;
|
|
192
202
|
|
|
@@ -197,13 +207,19 @@ export function boundSessionEventPayload<T>(
|
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
let reason = payloadTruncationReason(originalMeasurement, state);
|
|
200
|
-
let bounded = attachTruncation(
|
|
210
|
+
let bounded = attachTruncation(
|
|
211
|
+
preview,
|
|
212
|
+
boundaryMetadata(surface, reason, originalBytes, state, fullEvidence),
|
|
213
|
+
);
|
|
201
214
|
|
|
202
215
|
if (sessionEventJsonBytes(bounded) > Math.min(maxBytes, TARGET_PAYLOAD_BYTES)) {
|
|
203
216
|
state = previewState(RETRY_STRING_BYTES, RETRY_ARRAY_ENTRIES, RETRY_OBJECT_FIELDS);
|
|
204
217
|
preview = previewValue(payload, state, "$", 0);
|
|
205
218
|
reason = payloadTruncationReason(originalMeasurement, state);
|
|
206
|
-
bounded = attachTruncation(
|
|
219
|
+
bounded = attachTruncation(
|
|
220
|
+
preview,
|
|
221
|
+
boundaryMetadata(surface, reason, originalBytes, state, fullEvidence),
|
|
222
|
+
);
|
|
207
223
|
}
|
|
208
224
|
|
|
209
225
|
if (sessionEventJsonBytes(bounded) > maxBytes) {
|
|
@@ -219,7 +235,7 @@ export function boundSessionEventPayload<T>(
|
|
|
219
235
|
...identity,
|
|
220
236
|
preview: "[event payload omitted: bounded audit preview exceeded the storage envelope]",
|
|
221
237
|
},
|
|
222
|
-
boundaryMetadata(surface, reason, originalBytes, state),
|
|
238
|
+
boundaryMetadata(surface, reason, originalBytes, state, fullEvidence),
|
|
223
239
|
);
|
|
224
240
|
}
|
|
225
241
|
|
|
@@ -464,6 +480,7 @@ function boundaryMetadata(
|
|
|
464
480
|
reason: SessionEventPayloadTruncation["reason"],
|
|
465
481
|
originalBytes: number | null,
|
|
466
482
|
state: PreviewState,
|
|
483
|
+
fullEvidence: RetainedOutputEvidence,
|
|
467
484
|
): SessionEventPayloadTruncation {
|
|
468
485
|
return {
|
|
469
486
|
truncated: true,
|
|
@@ -475,7 +492,7 @@ function boundaryMetadata(
|
|
|
475
492
|
estimatedOriginalTokens:
|
|
476
493
|
originalBytes === null ? null : approximateSessionEventTokens(originalBytes),
|
|
477
494
|
estimatedDeliveredTokens: 0,
|
|
478
|
-
fullEvidence
|
|
495
|
+
fullEvidence,
|
|
479
496
|
details: state.details,
|
|
480
497
|
};
|
|
481
498
|
}
|