agentfootprint 18.1.0 → 18.2.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/CAPABILITIES.md +7 -3
- package/README.md +3 -3
- package/dist/artifacts/fileArtifacts.js +1 -0
- package/dist/artifacts/fileArtifacts.js.map +1 -1
- package/dist/artifacts/gcsArtifacts.js +1 -0
- package/dist/artifacts/gcsArtifacts.js.map +1 -1
- package/dist/artifacts/inMemoryArtifacts.js +1 -0
- package/dist/artifacts/inMemoryArtifacts.js.map +1 -1
- package/dist/artifacts/index.js +4 -1
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/recordingArtifact.js +18 -1
- package/dist/artifacts/recordingArtifact.js.map +1 -1
- package/dist/artifacts/retention.js +23 -1
- package/dist/artifacts/retention.js.map +1 -1
- package/dist/artifacts/s3Artifacts.js +5 -6
- package/dist/artifacts/s3Artifacts.js.map +1 -1
- package/dist/artifacts/sqliteArtifacts.js +1 -0
- package/dist/artifacts/sqliteArtifacts.js.map +1 -1
- package/dist/artifacts/types.js +5 -0
- package/dist/artifacts/types.js.map +1 -1
- package/dist/context-bisect/trajectory.js +3 -0
- package/dist/context-bisect/trajectory.js.map +1 -1
- package/dist/core/agent/runtime/configuration/configure.js +2 -0
- package/dist/core/agent/runtime/configuration/configure.js.map +1 -1
- package/dist/core/agent/runtime/recording/recording.js +69 -17
- package/dist/core/agent/runtime/recording/recording.js.map +1 -1
- package/dist/esm/artifacts/conformance/types.d.ts +3 -2
- package/dist/esm/artifacts/fileArtifacts.js +2 -1
- package/dist/esm/artifacts/fileArtifacts.js.map +1 -1
- package/dist/esm/artifacts/gcsArtifacts.js +2 -1
- package/dist/esm/artifacts/gcsArtifacts.js.map +1 -1
- package/dist/esm/artifacts/inMemoryArtifacts.js +2 -1
- package/dist/esm/artifacts/inMemoryArtifacts.js.map +1 -1
- package/dist/esm/artifacts/index.d.ts +2 -2
- package/dist/esm/artifacts/index.js +1 -1
- package/dist/esm/artifacts/index.js.map +1 -1
- package/dist/esm/artifacts/recordingArtifact.d.ts +17 -0
- package/dist/esm/artifacts/recordingArtifact.js +17 -0
- package/dist/esm/artifacts/recordingArtifact.js.map +1 -1
- package/dist/esm/artifacts/retention.d.ts +9 -1
- package/dist/esm/artifacts/retention.js +20 -0
- package/dist/esm/artifacts/retention.js.map +1 -1
- package/dist/esm/artifacts/s3Artifacts.js +6 -7
- package/dist/esm/artifacts/s3Artifacts.js.map +1 -1
- package/dist/esm/artifacts/sqliteArtifacts.js +2 -1
- package/dist/esm/artifacts/sqliteArtifacts.js.map +1 -1
- package/dist/esm/artifacts/types.d.ts +19 -0
- package/dist/esm/artifacts/types.js +5 -0
- package/dist/esm/artifacts/types.js.map +1 -1
- package/dist/esm/context-bisect/trajectory.d.ts +3 -0
- package/dist/esm/context-bisect/trajectory.js +3 -0
- package/dist/esm/context-bisect/trajectory.js.map +1 -1
- package/dist/esm/context-ledger/types.d.ts +3 -1
- package/dist/esm/core/agent/runtime/configuration/configure.js +2 -0
- package/dist/esm/core/agent/runtime/configuration/configure.js.map +1 -1
- package/dist/esm/core/agent/runtime/recording/recording.js +69 -17
- package/dist/esm/core/agent/runtime/recording/recording.js.map +1 -1
- package/dist/esm/core/agent/types/artifacts.d.ts +38 -0
- package/dist/esm/hosting/answerAccounts.d.ts +2 -0
- package/dist/esm/hosting/answerAccounts.js +3 -0
- package/dist/esm/hosting/answerAccounts.js.map +1 -1
- package/dist/esm/hosting/standingAgent/artifacts/accountParts.d.ts +64 -0
- package/dist/esm/hosting/standingAgent/artifacts/accountParts.js +88 -0
- package/dist/esm/hosting/standingAgent/artifacts/accountParts.js.map +1 -0
- package/dist/esm/hosting/standingAgent/artifacts/wire.js +18 -2
- package/dist/esm/hosting/standingAgent/artifacts/wire.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/observe.d.ts +1 -0
- package/dist/esm/observe.js +3 -0
- package/dist/esm/observe.js.map +1 -1
- package/dist/esm/recorders/observability/recordingParts/file.d.ts +74 -0
- package/dist/esm/recorders/observability/recordingParts/file.js +215 -0
- package/dist/esm/recorders/observability/recordingParts/file.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/format.d.ts +124 -0
- package/dist/esm/recorders/observability/recordingParts/format.js +294 -0
- package/dist/esm/recorders/observability/recordingParts/format.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/invocations.d.ts +55 -0
- package/dist/esm/recorders/observability/recordingParts/invocations.js +226 -0
- package/dist/esm/recorders/observability/recordingParts/invocations.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/open.d.ts +170 -0
- package/dist/esm/recorders/observability/recordingParts/open.js +275 -0
- package/dist/esm/recorders/observability/recordingParts/open.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/packing.d.ts +18 -0
- package/dist/esm/recorders/observability/recordingParts/packing.js +23 -0
- package/dist/esm/recorders/observability/recordingParts/packing.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/partReader.d.ts +45 -0
- package/dist/esm/recorders/observability/recordingParts/partReader.js +188 -0
- package/dist/esm/recorders/observability/recordingParts/partReader.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/source.d.ts +58 -0
- package/dist/esm/recorders/observability/recordingParts/source.js +120 -0
- package/dist/esm/recorders/observability/recordingParts/source.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/split.d.ts +74 -0
- package/dist/esm/recorders/observability/recordingParts/split.js +316 -0
- package/dist/esm/recorders/observability/recordingParts/split.js.map +1 -0
- package/dist/esm/recorders/observability/recordingParts/splitError.d.ts +17 -0
- package/dist/esm/recorders/observability/recordingParts/splitError.js +27 -0
- package/dist/esm/recorders/observability/recordingParts/splitError.js.map +1 -0
- package/dist/esm/time/convert/bounds.js +18 -2
- package/dist/esm/time/convert/bounds.js.map +1 -1
- package/dist/esm/time/convert/exact.js +26 -1
- package/dist/esm/time/convert/exact.js.map +1 -1
- package/dist/esm/time/convert.d.ts +2 -2
- package/dist/esm/time/convert.js +2 -2
- package/dist/esm/time-travel/epochs.d.ts +3 -0
- package/dist/esm/time-travel/epochs.js +3 -0
- package/dist/esm/time-travel/epochs.js.map +1 -1
- package/dist/esm/trace-toolpack/openRecording.d.ts +3 -0
- package/dist/esm/trace-toolpack/openRecording.js +3 -0
- package/dist/esm/trace-toolpack/openRecording.js.map +1 -1
- package/dist/hosting/answerAccounts.js +3 -0
- package/dist/hosting/answerAccounts.js.map +1 -1
- package/dist/hosting/standingAgent/artifacts/accountParts.js +92 -0
- package/dist/hosting/standingAgent/artifacts/accountParts.js.map +1 -0
- package/dist/hosting/standingAgent/artifacts/wire.js +17 -1
- package/dist/hosting/standingAgent/artifacts/wire.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/observe.js +6 -2
- package/dist/observe.js.map +1 -1
- package/dist/recorders/observability/recordingParts/file.js +219 -0
- package/dist/recorders/observability/recordingParts/file.js.map +1 -0
- package/dist/recorders/observability/recordingParts/format.js +304 -0
- package/dist/recorders/observability/recordingParts/format.js.map +1 -0
- package/dist/recorders/observability/recordingParts/invocations.js +230 -0
- package/dist/recorders/observability/recordingParts/invocations.js.map +1 -0
- package/dist/recorders/observability/recordingParts/open.js +279 -0
- package/dist/recorders/observability/recordingParts/open.js.map +1 -0
- package/dist/recorders/observability/recordingParts/packing.js +28 -0
- package/dist/recorders/observability/recordingParts/packing.js.map +1 -0
- package/dist/recorders/observability/recordingParts/partReader.js +192 -0
- package/dist/recorders/observability/recordingParts/partReader.js.map +1 -0
- package/dist/recorders/observability/recordingParts/source.js +126 -0
- package/dist/recorders/observability/recordingParts/source.js.map +1 -0
- package/dist/recorders/observability/recordingParts/split.js +322 -0
- package/dist/recorders/observability/recordingParts/split.js.map +1 -0
- package/dist/recorders/observability/recordingParts/splitError.js +31 -0
- package/dist/recorders/observability/recordingParts/splitError.js.map +1 -0
- package/dist/time/convert/bounds.js +18 -2
- package/dist/time/convert/bounds.js.map +1 -1
- package/dist/time/convert/exact.js +26 -1
- package/dist/time/convert/exact.js.map +1 -1
- package/dist/time/convert.js +2 -2
- package/dist/time-travel/epochs.js +3 -0
- package/dist/time-travel/epochs.js.map +1 -1
- package/dist/trace-toolpack/openRecording.js +3 -0
- package/dist/trace-toolpack/openRecording.js.map +1 -1
- package/dist/types/artifacts/conformance/types.d.ts +3 -2
- package/dist/types/artifacts/conformance/types.d.ts.map +1 -1
- package/dist/types/artifacts/fileArtifacts.d.ts.map +1 -1
- package/dist/types/artifacts/gcsArtifacts.d.ts.map +1 -1
- package/dist/types/artifacts/inMemoryArtifacts.d.ts.map +1 -1
- package/dist/types/artifacts/index.d.ts +2 -2
- package/dist/types/artifacts/index.d.ts.map +1 -1
- package/dist/types/artifacts/recordingArtifact.d.ts +17 -0
- package/dist/types/artifacts/recordingArtifact.d.ts.map +1 -1
- package/dist/types/artifacts/retention.d.ts +9 -1
- package/dist/types/artifacts/retention.d.ts.map +1 -1
- package/dist/types/artifacts/s3Artifacts.d.ts.map +1 -1
- package/dist/types/artifacts/sqliteArtifacts.d.ts.map +1 -1
- package/dist/types/artifacts/types.d.ts +19 -0
- package/dist/types/artifacts/types.d.ts.map +1 -1
- package/dist/types/context-bisect/trajectory.d.ts +3 -0
- package/dist/types/context-bisect/trajectory.d.ts.map +1 -1
- package/dist/types/context-ledger/types.d.ts +3 -1
- package/dist/types/context-ledger/types.d.ts.map +1 -1
- package/dist/types/core/agent/runtime/configuration/configure.d.ts.map +1 -1
- package/dist/types/core/agent/runtime/recording/recording.d.ts.map +1 -1
- package/dist/types/core/agent/types/artifacts.d.ts +38 -0
- package/dist/types/core/agent/types/artifacts.d.ts.map +1 -1
- package/dist/types/hosting/answerAccounts.d.ts +2 -0
- package/dist/types/hosting/answerAccounts.d.ts.map +1 -1
- package/dist/types/hosting/standingAgent/artifacts/accountParts.d.ts +65 -0
- package/dist/types/hosting/standingAgent/artifacts/accountParts.d.ts.map +1 -0
- package/dist/types/hosting/standingAgent/artifacts/wire.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/observe.d.ts +1 -0
- package/dist/types/observe.d.ts.map +1 -1
- package/dist/types/recorders/observability/recordingParts/file.d.ts +75 -0
- package/dist/types/recorders/observability/recordingParts/file.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/format.d.ts +125 -0
- package/dist/types/recorders/observability/recordingParts/format.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/invocations.d.ts +56 -0
- package/dist/types/recorders/observability/recordingParts/invocations.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/open.d.ts +171 -0
- package/dist/types/recorders/observability/recordingParts/open.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/packing.d.ts +19 -0
- package/dist/types/recorders/observability/recordingParts/packing.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/partReader.d.ts +46 -0
- package/dist/types/recorders/observability/recordingParts/partReader.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/source.d.ts +59 -0
- package/dist/types/recorders/observability/recordingParts/source.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/split.d.ts +75 -0
- package/dist/types/recorders/observability/recordingParts/split.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordingParts/splitError.d.ts +18 -0
- package/dist/types/recorders/observability/recordingParts/splitError.d.ts.map +1 -0
- package/dist/types/time/convert/bounds.d.ts.map +1 -1
- package/dist/types/time/convert/exact.d.ts.map +1 -1
- package/dist/types/time/convert.d.ts +2 -2
- package/dist/types/time-travel/epochs.d.ts +3 -0
- package/dist/types/time-travel/epochs.d.ts.map +1 -1
- package/dist/types/trace-toolpack/openRecording.d.ts +3 -0
- package/dist/types/trace-toolpack/openRecording.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* recordingParts/partReader — read one part named by an admitted index, and
|
|
4
|
+
* prove it holds exactly what the index says before handing anything on.
|
|
5
|
+
*
|
|
6
|
+
* Role: Lens. The one place a part's bytes become values: the size cap
|
|
7
|
+
* before any store call, the source's metadata and digest checks,
|
|
8
|
+
* bounded unpacking, then the payload's own fields — its format, its
|
|
9
|
+
* run, its position and its exact key set.
|
|
10
|
+
* Reads: the part source it is handed.
|
|
11
|
+
* Emits: N/A.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.partReader = void 0;
|
|
15
|
+
const utf8_js_1 = require("../../../lib/utf8.js");
|
|
16
|
+
const wireJson_js_1 = require("../../../lib/wireJson.js");
|
|
17
|
+
const recordingPack_js_1 = require("../recordingPack.js");
|
|
18
|
+
const format_js_1 = require("./format.js");
|
|
19
|
+
const packing_js_1 = require("./packing.js");
|
|
20
|
+
function unavailable(reason) {
|
|
21
|
+
return Object.freeze({ status: 'unavailable', reason });
|
|
22
|
+
}
|
|
23
|
+
/** The exact own keys of a payload object, the run's `runId` among them iff the index has one. */
|
|
24
|
+
function exactKeys(value, keys, runId) {
|
|
25
|
+
const expected = runId === undefined ? keys : [...keys, 'runId'];
|
|
26
|
+
const own = Object.keys(value);
|
|
27
|
+
return (own.length === expected.length &&
|
|
28
|
+
expected.every((key) => own.includes(key)) &&
|
|
29
|
+
(0, format_js_1.ownValue)(value, 'format') === format_js_1.RECORDING_PART_FORMAT &&
|
|
30
|
+
(0, format_js_1.ownValue)(value, 'runId') === runId);
|
|
31
|
+
}
|
|
32
|
+
/** The object's own keys equal `expected` exactly; returns its entries. */
|
|
33
|
+
function keyed(value, expected) {
|
|
34
|
+
if (!(0, format_js_1.isPlainObject)(value))
|
|
35
|
+
return undefined;
|
|
36
|
+
const own = Object.keys(value);
|
|
37
|
+
if (own.length !== expected.size || !own.every((key) => expected.has(key)))
|
|
38
|
+
return undefined;
|
|
39
|
+
return new Map(own.map((key) => [key, (0, format_js_1.ownValue)(value, key)]));
|
|
40
|
+
}
|
|
41
|
+
/** Reads the parts of one admitted index through one source. */
|
|
42
|
+
function partReader(index, source, caps) {
|
|
43
|
+
const results = index.parts.map(() => new Set());
|
|
44
|
+
const aliases = index.parts.map(() => new Set());
|
|
45
|
+
for (const invocation of index.invocations) {
|
|
46
|
+
if (invocation.part !== null)
|
|
47
|
+
results[invocation.part]?.add(invocation.key);
|
|
48
|
+
}
|
|
49
|
+
for (const { key, part } of index.unmounted)
|
|
50
|
+
results[part]?.add(key);
|
|
51
|
+
for (const alias of index.aliases)
|
|
52
|
+
if ('part' in alias)
|
|
53
|
+
aliases[alias.part]?.add(alias.name);
|
|
54
|
+
/**
|
|
55
|
+
* Cap, fetch, parse, unpack: a payload object, or why there is none. `limit`
|
|
56
|
+
* bounds the stored bytes before any store call and the PLAIN bytes a packed
|
|
57
|
+
* part may expand to, refused before it expands.
|
|
58
|
+
*/
|
|
59
|
+
async function load(entry, limit, signal, budgeted) {
|
|
60
|
+
// Decided from the index alone: no store call for a part over the cap.
|
|
61
|
+
if (entry.bytes > limit)
|
|
62
|
+
return unavailable('too-large');
|
|
63
|
+
const fetched = await source.fetch(entry, signal);
|
|
64
|
+
if ('refused' in fetched) {
|
|
65
|
+
return unavailable(fetched.refused === 'missing' ? 'part-missing' : 'part-changed');
|
|
66
|
+
}
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = JSON.parse(fetched.text);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return unavailable('part-changed');
|
|
73
|
+
}
|
|
74
|
+
if ((0, recordingPack_js_1.isPackedRecording)(parsed) !== index.packed)
|
|
75
|
+
return unavailable('part-changed');
|
|
76
|
+
if (index.packed) {
|
|
77
|
+
try {
|
|
78
|
+
parsed = (0, packing_js_1.unpackPart)(parsed, limit);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err instanceof recordingPack_js_1.PackedRecordingTooLargeError)
|
|
82
|
+
return unavailable('too-large');
|
|
83
|
+
if (err instanceof recordingPack_js_1.PackedRecordingError)
|
|
84
|
+
return unavailable('part-changed');
|
|
85
|
+
// Verified bytes too deep to expand on this runtime's stack: a resource
|
|
86
|
+
// bound of this reader, not a change to the part.
|
|
87
|
+
if (err instanceof RangeError)
|
|
88
|
+
return unavailable('too-large');
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
signal?.throwIfAborted();
|
|
93
|
+
if (!(0, format_js_1.isPlainObject)(parsed))
|
|
94
|
+
return unavailable('part-changed');
|
|
95
|
+
// A plain part's plain bytes are its text. A packed one is measured after its bounded
|
|
96
|
+
// expansion, and only when a budget asks: a single read pays no second serialisation.
|
|
97
|
+
const plainBytes = !budgeted
|
|
98
|
+
? 0
|
|
99
|
+
: index.packed
|
|
100
|
+
? (0, utf8_js_1.utf8Length)((0, wireJson_js_1.toWireJson)(parsed))
|
|
101
|
+
: (0, utf8_js_1.utf8Length)(fetched.text);
|
|
102
|
+
return { payload: parsed, plainBytes };
|
|
103
|
+
}
|
|
104
|
+
async function base(signal, budget = Number.POSITIVE_INFINITY) {
|
|
105
|
+
const loaded = await load(index.base, Math.min(caps.root, budget), signal, budget !== Number.POSITIVE_INFINITY);
|
|
106
|
+
if (!('payload' in loaded))
|
|
107
|
+
return loaded;
|
|
108
|
+
const { payload } = loaded;
|
|
109
|
+
if (!exactKeys(payload, ['format', 'part', 'recording'], index.runId)) {
|
|
110
|
+
return unavailable('part-changed');
|
|
111
|
+
}
|
|
112
|
+
const recording = (0, format_js_1.ownValue)(payload, 'recording');
|
|
113
|
+
if ((0, format_js_1.ownValue)(payload, 'part') !== 'base' || !(0, format_js_1.isPlainObject)(recording)) {
|
|
114
|
+
return unavailable('part-changed');
|
|
115
|
+
}
|
|
116
|
+
if (!Array.isArray((0, format_js_1.ownValue)(recording, 'events')))
|
|
117
|
+
return unavailable('part-changed');
|
|
118
|
+
const snapshot = (0, format_js_1.ownValue)(recording, 'snapshot');
|
|
119
|
+
if ((0, format_js_1.isPlainObject)(snapshot) &&
|
|
120
|
+
Object.prototype.hasOwnProperty.call(snapshot, 'subflowResults')) {
|
|
121
|
+
return unavailable('part-changed');
|
|
122
|
+
}
|
|
123
|
+
if (index.hasSubflowResults && !(0, format_js_1.isPlainObject)(snapshot))
|
|
124
|
+
return unavailable('part-changed');
|
|
125
|
+
return { recording: recording, plainBytes: loaded.plainBytes };
|
|
126
|
+
}
|
|
127
|
+
async function invocations(part, signal, budget = Number.POSITIVE_INFINITY) {
|
|
128
|
+
const entry = index.parts[part];
|
|
129
|
+
if (entry === undefined)
|
|
130
|
+
return unavailable('not-recorded');
|
|
131
|
+
const loaded = await load(entry, Math.min(caps.part, budget), signal, budget !== Number.POSITIVE_INFINITY);
|
|
132
|
+
if (!('payload' in loaded))
|
|
133
|
+
return loaded;
|
|
134
|
+
const { payload } = loaded;
|
|
135
|
+
if (!exactKeys(payload, ['format', 'part', 'results', 'aliases'], index.runId) ||
|
|
136
|
+
(0, format_js_1.ownValue)(payload, 'part') !== part) {
|
|
137
|
+
return unavailable('part-changed');
|
|
138
|
+
}
|
|
139
|
+
const held = keyed((0, format_js_1.ownValue)(payload, 'results'), results[part]);
|
|
140
|
+
const named = keyed((0, format_js_1.ownValue)(payload, 'aliases'), aliases[part]);
|
|
141
|
+
if (held === undefined || named === undefined)
|
|
142
|
+
return unavailable('part-changed');
|
|
143
|
+
return { results: held, aliases: named, plainBytes: loaded.plainBytes };
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Every part, in order; the first one that is unavailable makes the whole
|
|
147
|
+
* unavailable. `maxBytes` bounds the PLAIN total: each part may take only
|
|
148
|
+
* what the parts before it left, so a packed part that would expand past
|
|
149
|
+
* the rest of the budget is refused before it expands.
|
|
150
|
+
*/
|
|
151
|
+
async function whole(signal, maxBytes) {
|
|
152
|
+
let remaining = maxBytes;
|
|
153
|
+
const root = await base(signal, remaining);
|
|
154
|
+
if ('reason' in root)
|
|
155
|
+
return root;
|
|
156
|
+
remaining -= root.plainBytes;
|
|
157
|
+
const found = {};
|
|
158
|
+
for (let at = 0; at < index.parts.length; at++) {
|
|
159
|
+
const contents = await invocations(at, signal, remaining);
|
|
160
|
+
if ('reason' in contents)
|
|
161
|
+
return contents;
|
|
162
|
+
remaining -= contents.plainBytes;
|
|
163
|
+
for (const [key, value] of contents.results)
|
|
164
|
+
(0, format_js_1.assign)(found, key, value);
|
|
165
|
+
for (const [name, value] of contents.aliases)
|
|
166
|
+
(0, format_js_1.assign)(found, name, value);
|
|
167
|
+
}
|
|
168
|
+
for (const alias of index.aliases) {
|
|
169
|
+
if ('key' in alias)
|
|
170
|
+
(0, format_js_1.assign)(found, alias.name, (0, format_js_1.ownValue)(found, alias.key));
|
|
171
|
+
}
|
|
172
|
+
const recording = root.recording;
|
|
173
|
+
const snapshot = (0, format_js_1.ownValue)(recording, 'snapshot');
|
|
174
|
+
if (index.hasSubflowResults && (0, format_js_1.isPlainObject)(snapshot)) {
|
|
175
|
+
(0, format_js_1.assign)(snapshot, 'subflowResults', found);
|
|
176
|
+
}
|
|
177
|
+
return Object.freeze({ status: 'ready', recording: root.recording });
|
|
178
|
+
}
|
|
179
|
+
/** Every stored part's ticket, in order, checked against the index: no bytes are read. */
|
|
180
|
+
async function check(signal) {
|
|
181
|
+
for (const entry of [index.base, ...index.parts]) {
|
|
182
|
+
const checked = await source.check(entry, signal);
|
|
183
|
+
if ('refused' in checked) {
|
|
184
|
+
return unavailable(checked.refused === 'missing' ? 'part-missing' : 'part-changed');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return Object.freeze({ status: 'ready' });
|
|
188
|
+
}
|
|
189
|
+
return { base, invocations, whole, check };
|
|
190
|
+
}
|
|
191
|
+
exports.partReader = partReader;
|
|
192
|
+
//# sourceMappingURL=partReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"partReader.js","sourceRoot":"","sources":["../../../../src/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AAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC;AAtKD,gCAsKC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* recordingParts/source — where a part's text comes from, checked against its
|
|
4
|
+
* index entry before it is handed on.
|
|
5
|
+
*
|
|
6
|
+
* Role: Adapter. Two sources behind one shape: a STORE (a scope-bound
|
|
7
|
+
* `head`/`get`) and MEMORY (the parts a whole recording was cut into on
|
|
8
|
+
* the reader's side). Both answer a part's JSON text or a fixed reason.
|
|
9
|
+
* Reads: the store, through the two verbs it is handed.
|
|
10
|
+
* Emits: N/A.
|
|
11
|
+
*
|
|
12
|
+
* ── Metadata before bytes ───────────────────────────────────────────────────
|
|
13
|
+
* The store source asks `head` first and refuses a part whose kind, media
|
|
14
|
+
* type, byte count, digest or run disagrees with the index before any `get`.
|
|
15
|
+
* After `get` it checks the ticket again, the byte count of the text, and its
|
|
16
|
+
* OWN SHA-256 of the text against the index: a store adapter that does not
|
|
17
|
+
* verify its digests cannot pass a changed part. A store failure that is not
|
|
18
|
+
* a fact about the part (busy, revoked, aborted) is thrown, never renamed.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.memorySource = exports.storeSource = exports.fetchPayload = void 0;
|
|
22
|
+
const payload_js_1 = require("../../../artifacts/payload.js");
|
|
23
|
+
const recordingArtifact_js_1 = require("../../../artifacts/recordingArtifact.js");
|
|
24
|
+
const types_js_1 = require("../../../artifacts/types.js");
|
|
25
|
+
const utf8_js_1 = require("../../../lib/utf8.js");
|
|
26
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
27
|
+
/**
|
|
28
|
+
* `get` the artifact `head` described, and refuse it as `changed` when the
|
|
29
|
+
* ticket `get` returns is not the one `head` returned.
|
|
30
|
+
*/
|
|
31
|
+
async function fetchPayload(artifacts, meta, signal) {
|
|
32
|
+
let record;
|
|
33
|
+
try {
|
|
34
|
+
record = await artifacts.get(meta.ref);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
if (err instanceof types_js_1.ArtifactIntegrityError)
|
|
38
|
+
return { refused: 'changed' };
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
signal?.throwIfAborted();
|
|
42
|
+
if (record === null)
|
|
43
|
+
return { refused: 'missing' };
|
|
44
|
+
const got = record.meta;
|
|
45
|
+
if (got.ref !== meta.ref ||
|
|
46
|
+
got.kind !== meta.kind ||
|
|
47
|
+
got.mediaType !== meta.mediaType ||
|
|
48
|
+
got.bytes !== meta.bytes ||
|
|
49
|
+
got.digest !== meta.digest) {
|
|
50
|
+
return { refused: 'changed' };
|
|
51
|
+
}
|
|
52
|
+
const { data } = record;
|
|
53
|
+
if (typeof data === 'string')
|
|
54
|
+
return { text: data };
|
|
55
|
+
if (data instanceof Uint8Array) {
|
|
56
|
+
try {
|
|
57
|
+
return { text: decoder.decode(data) };
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return { refused: 'changed' };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { data };
|
|
64
|
+
}
|
|
65
|
+
exports.fetchPayload = fetchPayload;
|
|
66
|
+
/** Parts held by a store, each bound to its index entry and the index's run. */
|
|
67
|
+
function storeSource(artifacts, runId) {
|
|
68
|
+
/** `head` the entry's ref and check its ticket against the entry, before any `get`. */
|
|
69
|
+
const ticket = async (entry, signal) => {
|
|
70
|
+
signal?.throwIfAborted();
|
|
71
|
+
const meta = await artifacts.head(entry.ref);
|
|
72
|
+
signal?.throwIfAborted();
|
|
73
|
+
if (meta === null)
|
|
74
|
+
return { refused: 'missing' };
|
|
75
|
+
if (meta.ref !== entry.ref ||
|
|
76
|
+
meta.kind !== recordingArtifact_js_1.RECORDING_PART_ARTIFACT_KIND ||
|
|
77
|
+
meta.mediaType !== recordingArtifact_js_1.RECORDING_MEDIA_TYPE ||
|
|
78
|
+
meta.bytes !== entry.bytes ||
|
|
79
|
+
(meta.digest !== undefined && meta.digest !== entry.digest) ||
|
|
80
|
+
meta.origin?.runId !== runId) {
|
|
81
|
+
return { refused: 'changed' };
|
|
82
|
+
}
|
|
83
|
+
return meta;
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
async check(entry, signal) {
|
|
87
|
+
const meta = await ticket(entry, signal);
|
|
88
|
+
return 'refused' in meta ? meta : { present: true };
|
|
89
|
+
},
|
|
90
|
+
async fetch(entry, signal) {
|
|
91
|
+
const meta = await ticket(entry, signal);
|
|
92
|
+
if ('refused' in meta)
|
|
93
|
+
return meta;
|
|
94
|
+
const got = await fetchPayload(artifacts, meta, signal);
|
|
95
|
+
if ('refused' in got)
|
|
96
|
+
return got;
|
|
97
|
+
if (!('text' in got))
|
|
98
|
+
return { refused: 'changed' };
|
|
99
|
+
if ((0, utf8_js_1.utf8Length)(got.text) !== entry.bytes)
|
|
100
|
+
return { refused: 'changed' };
|
|
101
|
+
if ((await (0, payload_js_1.computeArtifactDigest)(got.text)) !== entry.digest)
|
|
102
|
+
return { refused: 'changed' };
|
|
103
|
+
signal?.throwIfAborted();
|
|
104
|
+
return { text: got.text };
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
exports.storeSource = storeSource;
|
|
109
|
+
/** Parts cut in memory from a whole recording this reader already read and checked. */
|
|
110
|
+
function memorySource(texts) {
|
|
111
|
+
return {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
113
|
+
async fetch(entry, signal) {
|
|
114
|
+
signal?.throwIfAborted();
|
|
115
|
+
const text = texts.get(entry.digest);
|
|
116
|
+
return text === undefined ? { refused: 'missing' } : { text };
|
|
117
|
+
},
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
119
|
+
async check(entry, signal) {
|
|
120
|
+
signal?.throwIfAborted();
|
|
121
|
+
return texts.has(entry.digest) ? { present: true } : { refused: 'missing' };
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
exports.memorySource = memorySource;
|
|
126
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../../../src/recorders/observability/recordingParts/source.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAGH,8DAAsE;AACtE,kFAGiD;AACjD,0DAAwF;AACxF,kDAAkD;AA4BlD,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE1D;;;GAGG;AACI,KAAK,UAAU,YAAY,CAChC,SAAkC,EAClC,IAAkB,EAClB,MAA+B;IAE/B,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,iCAAsB;YAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;QACzE,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IACnD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;IACxB,IACE,GAAG,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG;QACpB,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;QACtB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS;QAChC,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK;QACxB,GAAG,CAAC,MAA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,YAAY,CAAC,KAAkC;IAC7D,OAAO;QACL,4DAA4D;QAC5D,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM;YACvB,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QAChE,CAAC;QACD,4DAA4D;QAC5D,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM;YACvB,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC;AAdD,oCAcC"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* recordingParts/split — one recording, cut into a base part and invocation
|
|
4
|
+
* parts of about 1 MiB, plus the index that names them.
|
|
5
|
+
*
|
|
6
|
+
* Role: Codec. Pure: no store, no events. Returns each part's JSON text with
|
|
7
|
+
* its byte count and SHA-256, and the index without the refs a store
|
|
8
|
+
* mints. The writer puts the parts first and the index last; the
|
|
9
|
+
* reader of a whole recording runs this same split in memory, so both
|
|
10
|
+
* layouts are served by one cut.
|
|
11
|
+
* Reads: its argument.
|
|
12
|
+
* Emits: N/A.
|
|
13
|
+
*
|
|
14
|
+
* ── The cut ─────────────────────────────────────────────────────────────────
|
|
15
|
+
* • The BASE part is the recording with `snapshot.subflowResults` removed
|
|
16
|
+
* (the key itself, so a reader cannot mistake it for an empty map).
|
|
17
|
+
* • Each recorded invocation's result goes into an invocation part, in the
|
|
18
|
+
* viewer's order (`invocations.ts`). A part takes results while it stays
|
|
19
|
+
* within the target; a result larger than the target is a part of its own.
|
|
20
|
+
* Results no mount reaches follow, then path aliases that are not proven.
|
|
21
|
+
* • A path alias whose JSON text equals one stored result's text is stored
|
|
22
|
+
* only as `{ name, key }`: byte equality is the proof, so nothing the
|
|
23
|
+
* whole recording held is lost.
|
|
24
|
+
*
|
|
25
|
+
* ── Determinism ─────────────────────────────────────────────────────────────
|
|
26
|
+
* Every part's text is a function of the recording, the run id and `packed`
|
|
27
|
+
* alone: fixed key order, compact JSON, the wire rule for Errors
|
|
28
|
+
* (`lib/wireJson.ts · toWireJson`). Two equal recordings give equal parts and
|
|
29
|
+
* equal digests; their indexes differ only in the refs the store mints.
|
|
30
|
+
*/
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.recordingIndexText = exports.splitRecordingData = exports.splitRecording = void 0;
|
|
33
|
+
const payload_js_1 = require("../../../artifacts/payload.js");
|
|
34
|
+
const utf8_js_1 = require("../../../lib/utf8.js");
|
|
35
|
+
const wireJson_js_1 = require("../../../lib/wireJson.js");
|
|
36
|
+
const format_js_1 = require("./format.js");
|
|
37
|
+
const invocations_js_1 = require("./invocations.js");
|
|
38
|
+
const packing_js_1 = require("./packing.js");
|
|
39
|
+
const splitError_js_1 = require("./splitError.js");
|
|
40
|
+
/** A placeholder ref of the minted length, to measure an index before refs exist. */
|
|
41
|
+
const PLACEHOLDER_REF = `art_${'0'.repeat(22)}`;
|
|
42
|
+
/**
|
|
43
|
+
* Cut a live recording (`recordRun` · `toRecording()`), through the wire rule
|
|
44
|
+
* first, so the parts hold exactly the bytes the whole recording would.
|
|
45
|
+
*
|
|
46
|
+
* @throws RecordingSplitError — `unserializable`, `not-a-recording`, `over-limit`.
|
|
47
|
+
*/
|
|
48
|
+
async function splitRecording(recording, options = {}) {
|
|
49
|
+
// The bounds first, from the iterative walk's counts, before anything
|
|
50
|
+
// recursive runs: serializing a deep tree overflows the stack at a depth that
|
|
51
|
+
// depends on the runtime, so a recording past a bound would otherwise be
|
|
52
|
+
// `unserializable` on one Node and `over-limit` on another.
|
|
53
|
+
refuseOverLimit(recording);
|
|
54
|
+
let text;
|
|
55
|
+
try {
|
|
56
|
+
text = (0, wireJson_js_1.toWireJson)(recording);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw new splitError_js_1.RecordingSplitError('unserializable');
|
|
60
|
+
}
|
|
61
|
+
if (text === undefined)
|
|
62
|
+
throw new splitError_js_1.RecordingSplitError('unserializable');
|
|
63
|
+
return splitRecordingData(JSON.parse(text), options);
|
|
64
|
+
}
|
|
65
|
+
exports.splitRecording = splitRecording;
|
|
66
|
+
/**
|
|
67
|
+
* Cut a recording that is already plain JSON data (parsed from its text).
|
|
68
|
+
*
|
|
69
|
+
* @throws RecordingSplitError — `not-a-recording`, `over-limit`.
|
|
70
|
+
*/
|
|
71
|
+
async function splitRecordingData(data, options = {}) {
|
|
72
|
+
const { runId, packed = false } = options;
|
|
73
|
+
const target = options.targetBytes ?? format_js_1.RECORDING_PART_TARGET_BYTES;
|
|
74
|
+
if (runId !== undefined && !(0, format_js_1.isName)(runId)) {
|
|
75
|
+
throw new TypeError('splitRecording: runId must be a non-empty name of at most 4096 characters.');
|
|
76
|
+
}
|
|
77
|
+
if (!Number.isSafeInteger(target) || target < 1) {
|
|
78
|
+
throw new TypeError('splitRecording: targetBytes must be a positive whole number of bytes.');
|
|
79
|
+
}
|
|
80
|
+
if (!(0, format_js_1.isPlainObject)(data) || !Array.isArray((0, format_js_1.ownValue)(data, 'events'))) {
|
|
81
|
+
throw new splitError_js_1.RecordingSplitError('not-a-recording');
|
|
82
|
+
}
|
|
83
|
+
const snapshot = (0, format_js_1.ownValue)(data, 'snapshot');
|
|
84
|
+
const walk = (0, invocations_js_1.walkRecordedInvocations)(snapshot);
|
|
85
|
+
const entry = (slot, key, value) => {
|
|
86
|
+
const text = serialize(() => (0, wireJson_js_1.toWireJson)(value));
|
|
87
|
+
return { slot, key, value, text, bytes: (0, utf8_js_1.utf8Length)(text) };
|
|
88
|
+
};
|
|
89
|
+
const results = [];
|
|
90
|
+
for (const invocation of walk.invocations) {
|
|
91
|
+
if ('result' in invocation)
|
|
92
|
+
results.push(entry('results', invocation.key, invocation.result));
|
|
93
|
+
}
|
|
94
|
+
for (const { key, result } of walk.unmounted)
|
|
95
|
+
results.push(entry('results', key, result));
|
|
96
|
+
const byText = new Map();
|
|
97
|
+
for (const result of results)
|
|
98
|
+
if (!byText.has(result.text))
|
|
99
|
+
byText.set(result.text, result.key);
|
|
100
|
+
const proven = new Map();
|
|
101
|
+
const stored = [...results];
|
|
102
|
+
for (const { name, value } of walk.aliases) {
|
|
103
|
+
const candidate = entry('aliases', name, value);
|
|
104
|
+
const key = byText.get(candidate.text);
|
|
105
|
+
if (key !== undefined)
|
|
106
|
+
proven.set(name, key);
|
|
107
|
+
else
|
|
108
|
+
stored.push(candidate);
|
|
109
|
+
}
|
|
110
|
+
// Group: whole entries only, in order, each part within the target unless one entry is larger.
|
|
111
|
+
const groups = [];
|
|
112
|
+
let current = [];
|
|
113
|
+
let size = 0;
|
|
114
|
+
for (const item of stored) {
|
|
115
|
+
const cost = (0, utf8_js_1.utf8Length)((0, wireJson_js_1.toWireJson)(item.key)) + item.bytes + 2;
|
|
116
|
+
if (current.length > 0 && size + cost > target) {
|
|
117
|
+
groups.push(current);
|
|
118
|
+
current = [];
|
|
119
|
+
size = 0;
|
|
120
|
+
}
|
|
121
|
+
current.push(item);
|
|
122
|
+
size += cost;
|
|
123
|
+
}
|
|
124
|
+
if (current.length > 0)
|
|
125
|
+
groups.push(current);
|
|
126
|
+
if (groups.length > format_js_1.RECORDING_PARTS_LIMITS.parts) {
|
|
127
|
+
throw new splitError_js_1.RecordingSplitError('over-limit', 'parts');
|
|
128
|
+
}
|
|
129
|
+
const partOf = new Map();
|
|
130
|
+
groups.forEach((group, at) => {
|
|
131
|
+
for (const item of group)
|
|
132
|
+
if (item.slot === 'results')
|
|
133
|
+
partOf.set(item.key, at);
|
|
134
|
+
});
|
|
135
|
+
const aliasPart = new Map();
|
|
136
|
+
groups.forEach((group, at) => {
|
|
137
|
+
for (const item of group)
|
|
138
|
+
if (item.slot === 'aliases')
|
|
139
|
+
aliasPart.set(item.key, at);
|
|
140
|
+
});
|
|
141
|
+
const resultBytes = new Map(results.map((item) => [item.key, item.bytes]));
|
|
142
|
+
const head = (part) => `{"format":${(0, wireJson_js_1.toWireJson)(format_js_1.RECORDING_PART_FORMAT)}` +
|
|
143
|
+
(runId !== undefined ? `,"runId":${(0, wireJson_js_1.toWireJson)(runId)}` : '') +
|
|
144
|
+
`,"part":${(0, wireJson_js_1.toWireJson)(part)}`;
|
|
145
|
+
const partTexts = groups.map((group, at) => {
|
|
146
|
+
const slot = (name) => group.filter((item) => item.slot === name);
|
|
147
|
+
if (packed) {
|
|
148
|
+
const fold = (items) => {
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const item of items)
|
|
151
|
+
(0, format_js_1.assign)(out, item.key, item.value);
|
|
152
|
+
return out;
|
|
153
|
+
};
|
|
154
|
+
return serialize(() => (0, wireJson_js_1.toWireJson)((0, packing_js_1.packPart)({
|
|
155
|
+
format: format_js_1.RECORDING_PART_FORMAT,
|
|
156
|
+
...(runId !== undefined && { runId }),
|
|
157
|
+
part: at,
|
|
158
|
+
results: fold(slot('results')),
|
|
159
|
+
aliases: fold(slot('aliases')),
|
|
160
|
+
})));
|
|
161
|
+
}
|
|
162
|
+
const members = (items) => items.map((item) => `${(0, wireJson_js_1.toWireJson)(item.key)}:${item.text}`).join(',');
|
|
163
|
+
return `${head(at)},"results":{${members(slot('results'))}},"aliases":{${members(slot('aliases'))}}}`;
|
|
164
|
+
});
|
|
165
|
+
const basePayload = {
|
|
166
|
+
format: format_js_1.RECORDING_PART_FORMAT,
|
|
167
|
+
...(runId !== undefined && { runId }),
|
|
168
|
+
part: 'base',
|
|
169
|
+
recording: withoutResults(data, snapshot),
|
|
170
|
+
};
|
|
171
|
+
const baseText = serialize(() => (0, wireJson_js_1.toWireJson)(packed ? (0, packing_js_1.packPart)(basePayload) : basePayload));
|
|
172
|
+
const withDigest = async (text) => ({
|
|
173
|
+
text,
|
|
174
|
+
bytes: (0, utf8_js_1.utf8Length)(text),
|
|
175
|
+
digest: await (0, payload_js_1.computeArtifactDigest)(text),
|
|
176
|
+
});
|
|
177
|
+
const base = await withDigest(baseText);
|
|
178
|
+
const parts = [];
|
|
179
|
+
for (const text of partTexts)
|
|
180
|
+
parts.push(await withDigest(text));
|
|
181
|
+
const invocations = walk.invocations.map((invocation) => {
|
|
182
|
+
const part = partOf.get(invocation.key);
|
|
183
|
+
return part === undefined
|
|
184
|
+
? { key: invocation.key, path: invocation.path, subflowId: invocation.subflowId, part: null }
|
|
185
|
+
: {
|
|
186
|
+
key: invocation.key,
|
|
187
|
+
path: invocation.path,
|
|
188
|
+
subflowId: invocation.subflowId,
|
|
189
|
+
part,
|
|
190
|
+
bytes: resultBytes.get(invocation.key),
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
const unmounted = walk.unmounted.map(({ key }) => ({
|
|
194
|
+
key,
|
|
195
|
+
part: partOf.get(key),
|
|
196
|
+
}));
|
|
197
|
+
const aliases = walk.aliases.map(({ name }) => {
|
|
198
|
+
const key = proven.get(name);
|
|
199
|
+
return key !== undefined ? { name, key } : { name, part: aliasPart.get(name) };
|
|
200
|
+
});
|
|
201
|
+
const draft = {
|
|
202
|
+
...(runId !== undefined && { runId }),
|
|
203
|
+
...(walk.snapshotRunId !== undefined && { snapshotRunId: walk.snapshotRunId }),
|
|
204
|
+
packed,
|
|
205
|
+
complete: walk.complete,
|
|
206
|
+
hasSubflowResults: walk.hasSubflowResults,
|
|
207
|
+
base: { bytes: base.bytes, digest: base.digest },
|
|
208
|
+
parts: parts.map((part, at) => ({
|
|
209
|
+
bytes: part.bytes,
|
|
210
|
+
digest: part.digest,
|
|
211
|
+
results: groups[at].filter((item) => item.slot === 'results').length,
|
|
212
|
+
})),
|
|
213
|
+
invocations,
|
|
214
|
+
aliases,
|
|
215
|
+
unmounted,
|
|
216
|
+
};
|
|
217
|
+
const measured = recordingIndexText(draft, {
|
|
218
|
+
base: PLACEHOLDER_REF,
|
|
219
|
+
parts: parts.map(() => PLACEHOLDER_REF),
|
|
220
|
+
});
|
|
221
|
+
if ((0, utf8_js_1.utf8Length)(measured) > format_js_1.RECORDING_PARTS_LIMITS.indexBytes) {
|
|
222
|
+
throw new splitError_js_1.RecordingSplitError('over-limit', 'index');
|
|
223
|
+
}
|
|
224
|
+
return { base, parts, draft };
|
|
225
|
+
}
|
|
226
|
+
exports.splitRecordingData = splitRecordingData;
|
|
227
|
+
/**
|
|
228
|
+
* The index's JSON text once the store has minted every ref: `refs.parts[i]`
|
|
229
|
+
* is the ref of `split.parts[i]`. Fixed key order, compact JSON.
|
|
230
|
+
*/
|
|
231
|
+
function recordingIndexText(draft, refs) {
|
|
232
|
+
if (refs.parts.length !== draft.parts.length) {
|
|
233
|
+
throw new TypeError('recordingIndexText: one ref per part is required.');
|
|
234
|
+
}
|
|
235
|
+
const index = {
|
|
236
|
+
format: format_js_1.RECORDING_INDEX_FORMAT,
|
|
237
|
+
...(draft.runId !== undefined && { runId: draft.runId }),
|
|
238
|
+
...(draft.snapshotRunId !== undefined && { snapshotRunId: draft.snapshotRunId }),
|
|
239
|
+
packed: draft.packed,
|
|
240
|
+
complete: draft.complete,
|
|
241
|
+
hasSubflowResults: draft.hasSubflowResults,
|
|
242
|
+
base: { ref: refs.base, bytes: draft.base.bytes, digest: draft.base.digest },
|
|
243
|
+
parts: draft.parts.map((part, at) => ({
|
|
244
|
+
ref: refs.parts[at],
|
|
245
|
+
bytes: part.bytes,
|
|
246
|
+
digest: part.digest,
|
|
247
|
+
results: part.results,
|
|
248
|
+
})),
|
|
249
|
+
invocations: draft.invocations.map((invocation) => invocation.part === null
|
|
250
|
+
? {
|
|
251
|
+
key: invocation.key,
|
|
252
|
+
path: invocation.path,
|
|
253
|
+
subflowId: invocation.subflowId,
|
|
254
|
+
part: null,
|
|
255
|
+
}
|
|
256
|
+
: {
|
|
257
|
+
key: invocation.key,
|
|
258
|
+
path: invocation.path,
|
|
259
|
+
subflowId: invocation.subflowId,
|
|
260
|
+
part: invocation.part,
|
|
261
|
+
bytes: invocation.bytes,
|
|
262
|
+
}),
|
|
263
|
+
aliases: draft.aliases.map((alias) => 'key' in alias
|
|
264
|
+
? { name: alias.name, key: alias.key }
|
|
265
|
+
: { name: alias.name, part: alias.part }),
|
|
266
|
+
unmounted: draft.unmounted.map(({ key, part }) => ({ key, part })),
|
|
267
|
+
};
|
|
268
|
+
return (0, wireJson_js_1.toWireJson)(index);
|
|
269
|
+
}
|
|
270
|
+
exports.recordingIndexText = recordingIndexText;
|
|
271
|
+
/** The recording with the snapshot's `subflowResults` key removed; every other key in place. */
|
|
272
|
+
function withoutResults(data, snapshot) {
|
|
273
|
+
const out = {};
|
|
274
|
+
for (const key of Object.keys(data)) {
|
|
275
|
+
const value = (0, format_js_1.ownValue)(data, key);
|
|
276
|
+
if (key === 'snapshot' && (0, format_js_1.isPlainObject)(snapshot)) {
|
|
277
|
+
const stripped = {};
|
|
278
|
+
for (const field of Object.keys(snapshot)) {
|
|
279
|
+
if (field !== 'subflowResults')
|
|
280
|
+
(0, format_js_1.assign)(stripped, field, (0, format_js_1.ownValue)(snapshot, field));
|
|
281
|
+
}
|
|
282
|
+
(0, format_js_1.assign)(out, key, stripped);
|
|
283
|
+
}
|
|
284
|
+
else
|
|
285
|
+
(0, format_js_1.assign)(out, key, value);
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Write one value as JSON, or refuse the recording as `unserializable`: the one
|
|
291
|
+
* boundary where a value too deep for the serializer's stack (a `RangeError`)
|
|
292
|
+
* or one JSON cannot carry becomes a reason instead of an escaping error.
|
|
293
|
+
*/
|
|
294
|
+
function serialize(write) {
|
|
295
|
+
let text;
|
|
296
|
+
try {
|
|
297
|
+
text = write();
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
throw new splitError_js_1.RecordingSplitError('unserializable');
|
|
301
|
+
}
|
|
302
|
+
if (text === undefined)
|
|
303
|
+
throw new splitError_js_1.RecordingSplitError('unserializable');
|
|
304
|
+
return text;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Throw the walk's `over-limit` refusal for the live recording, if it has one.
|
|
308
|
+
* Only the bounds are decided here: any other verdict (a shape the walk cannot
|
|
309
|
+
* read before the wire rule has run) is left to the walk over the wire form.
|
|
310
|
+
*/
|
|
311
|
+
function refuseOverLimit(recording) {
|
|
312
|
+
if (!(0, format_js_1.isPlainObject)(recording))
|
|
313
|
+
return;
|
|
314
|
+
try {
|
|
315
|
+
(0, invocations_js_1.walkRecordedInvocations)((0, format_js_1.ownValue)(recording, 'snapshot'));
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
if (err instanceof splitError_js_1.RecordingSplitError && err.code === 'over-limit')
|
|
319
|
+
throw err;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=split.js.map
|