n8n-nodes-engram 0.8.1 → 0.8.2

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.
Files changed (36) hide show
  1. package/README.md +18 -1
  2. package/dist/extraction/AutonomousPersonalQualifiedClaimV4.d.ts +10 -0
  3. package/dist/extraction/AutonomousPersonalQualifiedClaimV4.js +502 -18
  4. package/dist/extraction/AutonomousPersonalQualifiedClaimV4.js.map +1 -1
  5. package/dist/extraction/CompositionalSnapshotIndexV3.js +8 -3
  6. package/dist/extraction/CompositionalSnapshotIndexV3.js.map +1 -1
  7. package/dist/schemas/AutonomousPersonalProviderV1.schema.d.ts +10 -10
  8. package/dist/schemas/CompositionalCompletionStageV3.schema.d.ts +4 -4
  9. package/dist/schemas/CompositionalMaterializationV3.schema.d.ts +2 -2
  10. package/dist/schemas/GraphDataMigration.d.ts +1 -0
  11. package/dist/schemas/GraphDataMigration.js +26 -0
  12. package/dist/schemas/GraphDataMigration.js.map +1 -1
  13. package/dist/storage/AutonomousPersonalAssistantFinalPlanV4.js +3 -1
  14. package/dist/storage/AutonomousPersonalAssistantFinalPlanV4.js.map +1 -1
  15. package/dist/storage/AutonomousPersonalCaptureBeginV4.js +8 -4
  16. package/dist/storage/AutonomousPersonalCaptureBeginV4.js.map +1 -1
  17. package/dist/storage/AutonomousPersonalCaptureHandlesV4.d.ts +9 -9
  18. package/dist/storage/AutonomousPersonalCompletionGraphV4.js +13 -6
  19. package/dist/storage/AutonomousPersonalCompletionGraphV4.js.map +1 -1
  20. package/dist/storage/AutonomousPersonalCompletionPlanV4.js +24 -9
  21. package/dist/storage/AutonomousPersonalCompletionPlanV4.js.map +1 -1
  22. package/dist/storage/AutonomousPersonalRecordIntegrityV4.d.ts +1 -9
  23. package/dist/storage/AutonomousPersonalRecordIntegrityV4.js +8 -444
  24. package/dist/storage/AutonomousPersonalRecordIntegrityV4.js.map +1 -1
  25. package/dist/storage/BoundedAutomaticCaptureJson.js +1 -6
  26. package/dist/storage/BoundedAutomaticCaptureJson.js.map +1 -1
  27. package/dist/storage/GraphologyStorage.d.ts +9 -0
  28. package/dist/storage/GraphologyStorage.js +403 -106
  29. package/dist/storage/GraphologyStorage.js.map +1 -1
  30. package/dist/storage/ImmutableGraphSnapshot.d.ts +4 -0
  31. package/dist/storage/ImmutableGraphSnapshot.js +79 -0
  32. package/dist/storage/ImmutableGraphSnapshot.js.map +1 -0
  33. package/dist/storage/LosslessAutomaticCaptureGraph.d.ts +4 -0
  34. package/dist/storage/LosslessAutomaticCaptureGraph.js +188 -5
  35. package/dist/storage/LosslessAutomaticCaptureGraph.js.map +1 -1
  36. package/package.json +1 -1
package/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  <p align="center">
27
27
  <a href="#installation">Installation</a> &middot;
28
- <a href="#upgrading-to-v081">Upgrade</a> &middot;
28
+ <a href="#upgrading-to-v082">Upgrade</a> &middot;
29
29
  <a href="#node-reference">Nodes</a> &middot;
30
30
  <a href="#storage-backends">Storage</a> &middot;
31
31
  <a href="#knowledge-extraction">Extraction</a> &middot;
@@ -101,6 +101,23 @@ npm install n8n-nodes-engram
101
101
 
102
102
  ---
103
103
 
104
+ ## Upgrading to v0.8.2
105
+
106
+ This patch reduces embedded-store processing overhead during automatic capture, memory retrieval and conversation saves. Existing node versions, saved defaults, namespaces and memory policies are preserved. The performance changes require no new setting or node-version upgrade. Installing the package does not enable an automatic-memory profile or start a background worker.
107
+
108
+ 1. Take fresh, consistent workflow and backend-native backups. Preserve complete embedded files or the Neo4j database, producer workflow mapping, storage paths, logical store identity, namespaces, bindings and aliases. Include queue-aware recovery data where durable jobs already exist.
109
+ 2. Install `n8n-nodes-engram@0.8.2`, restart n8n and refresh the editor. Begin with an inactive workflow copy and a separately restored store with its logical ownership mapping preserved. Moving an enrolled store to another producer path is not an activation step.
110
+ 3. Keep the current model, route, temperature, source mappings and stable event IDs. Verify cold startup, recent conversation, accepted graph-only recall, capture receipts, duplicate events and a conversation with multiple tool calls. Confirm that tool audits remain separate and final turns are saved once.
111
+ 4. Expand only after the selected workflow passes. Review passive writers separately. If enabling Autonomous Personal Memory for the first time, the existing [v0.8.0 profile setup](#upgrading-to-v080) and [v0.8.1 configured-budget instructions](#upgrading-to-v081) still apply.
112
+
113
+ After embedded-store initialization fails, cached-memory reads now report that failure instead of returning empty or stale data. Correct the backing file and retry initialization or restart the workflow; no memory reset is required. A failed initialization must not be treated as successful recall.
114
+
115
+ Monitor n8n memory use during rollout, particularly with large embedded stores or several active workflows. Faster repeated reads can retain more data in memory between writes. Provider-request latency remains separate from local storage work; this patch does not guarantee a particular response time.
116
+
117
+ No reset, purge, re-enrollment or bulk re-extraction is required. Prefer reverting explicit workflow/policy settings on the supported binary while preserving newly appended memory. Existing downgrade and mixed-version writer/worker restrictions remain in force. Never restore an old snapshot over newer conversations as routine rollback.
118
+
119
+ ---
120
+
104
121
  ## Upgrading to v0.8.1
105
122
 
106
123
  This patch adds configurable capture budgets and fixes Memory continuation across tool rounds. Existing node versions, saved defaults, namespaces and memory are preserved. Autonomous Personal Memory uses AI Agent **v3.1** with n8n **2.12.3 / Node.js 22** or **2.44.6 / Node.js 24**.
@@ -1,5 +1,6 @@
1
1
  import { type AutonomousPersonalQualifiedClaimResultV4 } from '../schemas/AutonomousPersonalQualifiedClaimV4.schema';
2
2
  import { type AutonomousPersonalTypedSyntaxWorkV1 } from '../schemas/AutonomousPersonalTypedSyntaxV1.schema';
3
+ import { type AutonomousPersonalRecordIntegrityV4FailureReason } from '../schemas/AutonomousPersonalRecordIntegrityV4.schema';
3
4
  import type { GraphData } from '../schemas/GraphData.schema';
4
5
  import type { AutonomousPersonalClaimIndexCandidateRowsV4 } from '../schemas/AutonomousPersonalClaimIndexCandidateRowsV4.schema';
5
6
  declare const indexBrand: unique symbol;
@@ -13,7 +14,16 @@ export declare class AutonomousPersonalClaimIndexV4Error extends Error {
13
14
  }
14
15
  export declare function createAutonomousPersonalClaimIndexV4(graphValue: unknown, typedSyntaxWork: AutonomousPersonalTypedSyntaxWorkV1, codeOwnedCheck: () => void): AutonomousPersonalClaimIndexV4;
15
16
  export declare function getAutonomousPersonalClaimIndexGraphV4(index: AutonomousPersonalClaimIndexV4): GraphData;
17
+ export declare function getRegisteredAutonomousPersonalClaimIndexGraphV4(value: unknown): GraphData | undefined;
16
18
  export declare function getAutonomousPersonalClaimIndexCandidateRowsV4(indexValue: unknown, edgeIdValue: unknown): AutonomousPersonalClaimIndexCandidateRowsV4 | null;
17
19
  export declare function inspectAutonomousPersonalClaimCreatorV4(indexValue: unknown, edgeIdValue: unknown): AutonomousPersonalQualifiedClaimResultV4;
18
20
  export declare function qualifyAutonomousPersonalClaimCreatorV4(indexValue: unknown, requestValue: unknown): AutonomousPersonalQualifiedClaimResultV4;
21
+ export declare class AutonomousPersonalRecordIntegrityV4Error extends Error {
22
+ readonly reason: AutonomousPersonalRecordIntegrityV4FailureReason;
23
+ constructor(reason: AutonomousPersonalRecordIntegrityV4FailureReason);
24
+ }
25
+ export declare function assertAutonomousPersonalRecordIntegrityV4(graphValue: unknown, typedSyntaxWork: AutonomousPersonalTypedSyntaxWorkV1, codeOwnedCheck: () => void): void;
26
+ export declare function validateOwnedAutonomousPersonalRecordGraphV4(graphValue: unknown, typedSyntaxWork: AutonomousPersonalTypedSyntaxWorkV1, codeOwnedCheck: () => void): GraphData | undefined;
27
+ export declare function createIntegrityCheckedAutonomousPersonalClaimIndexV4(graphValue: unknown, typedSyntaxWork: AutonomousPersonalTypedSyntaxWorkV1, codeOwnedCheck: () => void): AutonomousPersonalClaimIndexV4;
28
+ export declare function parseIntegrityCheckedAutonomousPersonalGraphV4(graphValue: unknown, typedSyntaxWork: AutonomousPersonalTypedSyntaxWorkV1, codeOwnedCheck: () => void): GraphData;
19
29
  export {};
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AutonomousPersonalClaimIndexV4Error = void 0;
4
+ exports.AutonomousPersonalRecordIntegrityV4Error = exports.AutonomousPersonalClaimIndexV4Error = void 0;
5
5
  exports.createAutonomousPersonalClaimIndexV4 = createAutonomousPersonalClaimIndexV4;
6
6
  exports.getAutonomousPersonalClaimIndexGraphV4 = getAutonomousPersonalClaimIndexGraphV4;
7
+ exports.getRegisteredAutonomousPersonalClaimIndexGraphV4 = getRegisteredAutonomousPersonalClaimIndexGraphV4;
7
8
  exports.getAutonomousPersonalClaimIndexCandidateRowsV4 = getAutonomousPersonalClaimIndexCandidateRowsV4;
8
9
  exports.inspectAutonomousPersonalClaimCreatorV4 = inspectAutonomousPersonalClaimCreatorV4;
9
10
  exports.qualifyAutonomousPersonalClaimCreatorV4 = qualifyAutonomousPersonalClaimCreatorV4;
11
+ exports.assertAutonomousPersonalRecordIntegrityV4 = assertAutonomousPersonalRecordIntegrityV4;
12
+ exports.validateOwnedAutonomousPersonalRecordGraphV4 = validateOwnedAutonomousPersonalRecordGraphV4;
13
+ exports.createIntegrityCheckedAutonomousPersonalClaimIndexV4 = createIntegrityCheckedAutonomousPersonalClaimIndexV4;
14
+ exports.parseIntegrityCheckedAutonomousPersonalGraphV4 = parseIntegrityCheckedAutonomousPersonalGraphV4;
10
15
  const node_perf_hooks_1 = require("node:perf_hooks");
11
16
  const node_util_1 = require("node:util");
12
17
  const AutomaticCapture_schema_1 = require("../schemas/AutomaticCapture.schema");
@@ -18,13 +23,16 @@ const AutonomousPersonalSourceScanV1_schema_1 = require("../schemas/AutonomousPe
18
23
  const AutonomousSourceGeometryV3_schema_1 = require("../schemas/AutonomousSourceGeometryV3.schema");
19
24
  const AutonomousPersonalOperationV4_schema_1 = require("../schemas/AutonomousPersonalOperationV4.schema");
20
25
  const AutonomousPersonalDescriptorV4_schema_1 = require("../schemas/AutonomousPersonalDescriptorV4.schema");
26
+ const AutonomousPersonalRecordIntegrityV4_schema_1 = require("../schemas/AutonomousPersonalRecordIntegrityV4.schema");
21
27
  const ExtractionMetadata_schema_1 = require("../schemas/ExtractionMetadata.schema");
22
28
  const AutonomousPersonalRecordIdsV1_1 = require("../storage/AutonomousPersonalRecordIdsV1");
23
29
  const AutonomousPersonalClaimCandidateV1_1 = require("./AutonomousPersonalClaimCandidateV1");
24
30
  const AutonomousPersonalTypedSyntaxV1_1 = require("./AutonomousPersonalTypedSyntaxV1");
25
31
  const LosslessAutomaticCaptureGraph_1 = require("../storage/LosslessAutomaticCaptureGraph");
32
+ const ImmutableGraphSnapshot_1 = require("../storage/ImmutableGraphSnapshot");
26
33
  const BoundedAutomaticCaptureJson_1 = require("../storage/BoundedAutomaticCaptureJson");
27
34
  const AutomaticIdentity_1 = require("../storage/AutomaticIdentity");
35
+ const AutonomousPersonalExecutionScopeV1_1 = require("../storage/AutonomousPersonalExecutionScopeV1");
28
36
  const AutonomousPersonalTypedSyntaxV1_2 = require("./AutonomousPersonalTypedSyntaxV1");
29
37
  const EDGE_CLAIM_ATTRIBUTE = 'engram_claim_v1';
30
38
  const VALUE_LITERAL_ATTRIBUTE = 'engram_literal_v1';
@@ -78,7 +86,10 @@ function readWorkContext(value) {
78
86
  throw new AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1('internal');
79
87
  }
80
88
  nativeAbortSignalAbortedGetter.call(signalProperty.value);
81
- return { deadline: deadlineProperty.value, signal: signalProperty.value };
89
+ return {
90
+ deadline: deadlineProperty.value,
91
+ signal: signalProperty.value,
92
+ };
82
93
  }
83
94
  catch (error) {
84
95
  if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
@@ -221,13 +232,44 @@ function operationSourceId(operation) {
221
232
  return operation.identity.sourceId;
222
233
  }
223
234
  function createAutonomousPersonalClaimIndexV4(graphValue, typedSyntaxWork, codeOwnedCheck) {
224
- var _a, _b;
235
+ var _a;
225
236
  const sticky = stickyCheck(codeOwnedCheck, typedSyntaxWork);
226
237
  const { check } = sticky;
238
+ const registered = getRegisteredAutonomousPersonalClaimIndexGraphV4(graphValue);
227
239
  try {
228
240
  check();
229
- const graph = (0, LosslessAutomaticCaptureGraph_1.parseLosslessAutomaticCaptureGraph)(graphValue);
241
+ const graph = (_a = registered !== null && registered !== void 0 ? registered : (0, ImmutableGraphSnapshot_1.getOwnedImmutableGraphData)(graphValue)) !== null && _a !== void 0 ? _a : (0, LosslessAutomaticCaptureGraph_1.parseLosslessAutomaticCaptureGraph)(graphValue);
230
242
  check();
243
+ return indexOwnedParsedGraph(graph, sticky, true);
244
+ }
245
+ catch (error) {
246
+ mapClaimIndexFailure(error, sticky);
247
+ }
248
+ }
249
+ function indexParsedGraphV4(graph, typedSyntaxWork, codeOwnedCheck, freezeGraph) {
250
+ const sticky = stickyCheck(codeOwnedCheck, typedSyntaxWork);
251
+ try {
252
+ sticky.check();
253
+ sticky.check();
254
+ return indexOwnedParsedGraph(graph, sticky, freezeGraph);
255
+ }
256
+ catch (error) {
257
+ mapClaimIndexFailure(error, sticky);
258
+ }
259
+ }
260
+ function mapClaimIndexFailure(error, sticky) {
261
+ sticky.rethrowFailure();
262
+ if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
263
+ throw error;
264
+ if (error instanceof BoundedAutomaticCaptureJson_1.BoundedAutomaticCaptureJsonError && error.reason !== 'invalid_json') {
265
+ snapshotFailure('snapshot_capacity');
266
+ }
267
+ snapshotFailure('invalid_snapshot');
268
+ }
269
+ function indexOwnedParsedGraph(graph, sticky, freezeGraph) {
270
+ var _a, _b;
271
+ const { check } = sticky;
272
+ {
231
273
  ensureGlobalIdsUnique(graph, check);
232
274
  const entities = indexRows(graph.entities, check);
233
275
  const edges = indexRows(graph.edges, check);
@@ -244,7 +286,8 @@ function createAutonomousPersonalClaimIndexV4(graphValue, typedSyntaxWork, codeO
244
286
  for (const rows of operationsBySource.values())
245
287
  Object.freeze(rows);
246
288
  const bindingIndex = indexBindings(graph, check);
247
- freeze(graph, check);
289
+ if (freezeGraph)
290
+ freeze(graph, check);
248
291
  const root = {
249
292
  graph,
250
293
  entities,
@@ -263,15 +306,6 @@ function createAutonomousPersonalClaimIndexV4(graphValue, typedSyntaxWork, codeO
263
306
  indices.set(token, root);
264
307
  return token;
265
308
  }
266
- catch (error) {
267
- sticky.rethrowFailure();
268
- if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
269
- throw error;
270
- if (error instanceof BoundedAutomaticCaptureJson_1.BoundedAutomaticCaptureJsonError && error.reason !== 'invalid_json') {
271
- snapshotFailure('snapshot_capacity');
272
- }
273
- snapshotFailure('invalid_snapshot');
274
- }
275
309
  }
276
310
  function rootFor(index) {
277
311
  if (index === null || typeof index !== 'object')
@@ -290,6 +324,11 @@ function getAutonomousPersonalClaimIndexGraphV4(index) {
290
324
  root.check();
291
325
  return graph;
292
326
  }
327
+ function getRegisteredAutonomousPersonalClaimIndexGraphV4(value) {
328
+ if (value === null || typeof value !== 'object' || !indices.has(value))
329
+ return undefined;
330
+ return getAutonomousPersonalClaimIndexGraphV4(value);
331
+ }
293
332
  function getAutonomousPersonalClaimIndexCandidateRowsV4(indexValue, edgeIdValue) {
294
333
  var _a, _b, _c, _d, _e;
295
334
  const root = rootFor(indexValue);
@@ -393,7 +432,10 @@ function invalid(root, reason) {
393
432
  return resultData(root, { status: 'invalid', reason });
394
433
  }
395
434
  function uncommitted(root) {
396
- return resultData(root, { status: 'uncommitted', reason: 'capture_not_committed' });
435
+ return resultData(root, {
436
+ status: 'uncommitted',
437
+ reason: 'capture_not_committed',
438
+ });
397
439
  }
398
440
  function capacity(root) {
399
441
  return resultData(root, { status: 'capacity', reason: 'proof_capacity' });
@@ -431,7 +473,10 @@ function getSourceEvidence(root, source, descriptor) {
431
473
  }
432
474
  root.check();
433
475
  try {
434
- const stored = (0, AutonomousPersonalSourceV4_schema_1.reconstructAutonomousPersonalStoredSourceIdentityV4)({ source, descriptor });
476
+ const stored = (0, AutonomousPersonalSourceV4_schema_1.reconstructAutonomousPersonalStoredSourceIdentityV4)({
477
+ source,
478
+ descriptor,
479
+ });
435
480
  if (!AutonomousPersonalSourceV4_schema_1.AutonomousPersonalStoredSourceIdentityV4OwnedDataSchema.safeParse(stored).success) {
436
481
  root.check();
437
482
  root.sourceEvidence.set(source.uuid, { kind: 'invalid' });
@@ -843,7 +888,10 @@ function qualifyAutonomousPersonalClaimCreatorV4(indexValue, requestValue) {
843
888
  if (request.storeHash !== proof.storeHash)
844
889
  return resultData(root, { status: 'inactive', reason: 'store_mismatch' });
845
890
  if (request.namespace !== proof.namespace)
846
- return resultData(root, { status: 'inactive', reason: 'namespace_mismatch' });
891
+ return resultData(root, {
892
+ status: 'inactive',
893
+ reason: 'namespace_mismatch',
894
+ });
847
895
  const edgeRows = (_a = root.edges.get(proof.claimId)) !== null && _a !== void 0 ? _a : [];
848
896
  const sourceRows = (_b = root.episodes.get(proof.sourceId)) !== null && _b !== void 0 ? _b : [];
849
897
  const opRows = (_c = root.operationsById.get(proof.operationId)) !== null && _c !== void 0 ? _c : [];
@@ -863,7 +911,10 @@ function qualifyAutonomousPersonalClaimCreatorV4(indexValue, requestValue) {
863
911
  actorReference: operation.data.identity.actorReference,
864
912
  binding: operation.data.identity.binding,
865
913
  })) {
866
- return resultData(root, { status: 'inactive', reason: 'authority_inactive' });
914
+ return resultData(root, {
915
+ status: 'inactive',
916
+ reason: 'authority_inactive',
917
+ });
867
918
  }
868
919
  if (source.review_status !== 'accepted' ||
869
920
  source.trust_level !== operation.data.descriptor.requestedTrustLevel) {
@@ -892,4 +943,437 @@ function qualifyAutonomousPersonalClaimCreatorV4(indexValue, requestValue) {
892
943
  root.check();
893
944
  return resultData(root, { status: 'qualified', proof });
894
945
  }
946
+ const CLAIM_ATTRIBUTE = 'engram_claim_v1';
947
+ const VALUE_MARKER_ATTRIBUTE = 'engram_literal_v1';
948
+ const PERSONAL_VALUE_TYPE = 'autonomous_personal_value';
949
+ const PERSONAL_FAMILY = 'autonomous-personal-v1';
950
+ class AutonomousPersonalRecordIntegrityV4Error extends Error {
951
+ constructor(reason) {
952
+ const parsedReason = AutonomousPersonalRecordIntegrityV4_schema_1.AutonomousPersonalRecordIntegrityV4FailureReasonSchema.safeParse(reason);
953
+ super('Engram autonomous personal record integrity failed');
954
+ this.name = 'AutonomousPersonalRecordIntegrityV4Error';
955
+ this.reason = parsedReason.success ? parsedReason.data : 'invalid_snapshot';
956
+ Object.freeze(this);
957
+ }
958
+ }
959
+ exports.AutonomousPersonalRecordIntegrityV4Error = AutonomousPersonalRecordIntegrityV4Error;
960
+ function fail(reason) {
961
+ throw new AutonomousPersonalRecordIntegrityV4Error(reason);
962
+ }
963
+ function stickyTrustedCheck(callback) {
964
+ let failed = false;
965
+ let failure;
966
+ const check = () => {
967
+ if (failed)
968
+ throw failure;
969
+ try {
970
+ callback();
971
+ }
972
+ catch (error) {
973
+ failed = true;
974
+ failure = error;
975
+ throw error;
976
+ }
977
+ };
978
+ return {
979
+ check,
980
+ rethrowFailure: () => {
981
+ if (failed)
982
+ throw failure;
983
+ },
984
+ };
985
+ }
986
+ function stickyWorkCheck(work, trusted) {
987
+ const supplied = readWorkContext(work);
988
+ const abortedGetter = nativeAbortSignalAbortedGetter;
989
+ if (abortedGetter === undefined)
990
+ throw new AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1('internal');
991
+ let failed = false;
992
+ let failure;
993
+ const latch = (error) => {
994
+ if (!failed) {
995
+ failed = true;
996
+ failure = error;
997
+ }
998
+ throw failure;
999
+ };
1000
+ const checkWork = () => {
1001
+ try {
1002
+ if (abortedGetter.call(supplied.signal)) {
1003
+ throw new AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1('cancelled');
1004
+ }
1005
+ const now = node_perf_hooks_1.performance.now();
1006
+ if (!Number.isFinite(now))
1007
+ throw new AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1('internal');
1008
+ if (now >= supplied.deadline)
1009
+ throw new AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1('deadline');
1010
+ }
1011
+ catch (error) {
1012
+ if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
1013
+ throw error;
1014
+ throw new AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1('internal');
1015
+ }
1016
+ };
1017
+ const check = () => {
1018
+ if (failed)
1019
+ throw failure;
1020
+ try {
1021
+ checkWork();
1022
+ trusted.check();
1023
+ checkWork();
1024
+ }
1025
+ catch (error) {
1026
+ latch(error);
1027
+ }
1028
+ };
1029
+ return {
1030
+ check,
1031
+ rethrowFailure: () => {
1032
+ if (failed)
1033
+ throw failure;
1034
+ trusted.rethrowFailure();
1035
+ },
1036
+ };
1037
+ }
1038
+ function isFamilyFourTag(value) {
1039
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
1040
+ return false;
1041
+ const record = value;
1042
+ return ((typeof record.version === 'number' && record.version >= 3) || record.family === PERSONAL_FAMILY);
1043
+ }
1044
+ function collectFootprints(graph, check) {
1045
+ var _a, _b;
1046
+ const edgeIds = new Set();
1047
+ const valueIds = new Set();
1048
+ const positiveOccurrences = [];
1049
+ check();
1050
+ for (const edge of graph.edges) {
1051
+ check();
1052
+ if (isFamilyFourTag(edge.attributes[CLAIM_ATTRIBUTE]))
1053
+ edgeIds.add(edge.uuid);
1054
+ }
1055
+ check();
1056
+ for (const entity of graph.entities) {
1057
+ check();
1058
+ if (isFamilyFourTag(entity.attributes[VALUE_MARKER_ATTRIBUTE]) ||
1059
+ entity.entity_type === PERSONAL_VALUE_TYPE) {
1060
+ valueIds.add(entity.uuid);
1061
+ }
1062
+ }
1063
+ check();
1064
+ for (const storedOperation of (_b = (_a = graph.automatic_operations_v1) === null || _a === void 0 ? void 0 : _a.operations) !== null && _b !== void 0 ? _b : []) {
1065
+ check();
1066
+ if (storedOperation.version !== 4 || storedOperation.state !== 'committed')
1067
+ continue;
1068
+ const operation = storedOperation;
1069
+ const receipt = operation.terminalReceipt;
1070
+ if (receipt.kind !== 'human_autonomous_capture_committed')
1071
+ continue;
1072
+ if (receipt.selection.kind !== 'occurrences')
1073
+ continue;
1074
+ for (const item of receipt.selection.items) {
1075
+ check();
1076
+ if (item.effect === 'created' || item.effect === 'reference') {
1077
+ positiveOccurrences.push({ operation, item });
1078
+ }
1079
+ }
1080
+ }
1081
+ check();
1082
+ return { edgeIds, valueIds, positiveOccurrences };
1083
+ }
1084
+ function mapOwnershipFailure(error) {
1085
+ if (error instanceof BoundedAutomaticCaptureJson_1.BoundedAutomaticCaptureJsonError && error.reason !== 'invalid_json') {
1086
+ fail('snapshot_capacity');
1087
+ }
1088
+ fail('invalid_snapshot');
1089
+ }
1090
+ function mapIndexFailure(error) {
1091
+ if (error instanceof AutonomousPersonalClaimIndexV4Error) {
1092
+ fail(error.reason === 'snapshot_capacity' ? 'snapshot_capacity' : 'invalid_snapshot');
1093
+ }
1094
+ if (error instanceof BoundedAutomaticCaptureJson_1.BoundedAutomaticCaptureJsonError && error.reason !== 'invalid_json') {
1095
+ fail('snapshot_capacity');
1096
+ }
1097
+ if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
1098
+ throw error;
1099
+ fail('inspection_incomplete');
1100
+ }
1101
+ function equalData(left, right) {
1102
+ return (0, AutomaticCapture_schema_1.canonicalAutomaticCaptureV2)(left) === (0, AutomaticCapture_schema_1.canonicalAutomaticCaptureV2)(right);
1103
+ }
1104
+ function required(value, reason, check) {
1105
+ if (value === null || value === undefined) {
1106
+ check();
1107
+ fail(reason);
1108
+ }
1109
+ return value;
1110
+ }
1111
+ function inspectFailureReason(result) {
1112
+ if (result.status === 'capacity') {
1113
+ return result.reason === 'snapshot_capacity' ? 'snapshot_capacity' : 'inspection_incomplete';
1114
+ }
1115
+ if (result.status === 'uncommitted')
1116
+ return 'orphan_record';
1117
+ if (result.status !== 'invalid')
1118
+ return 'inspection_incomplete';
1119
+ if (result.reason === 'missing_record')
1120
+ return 'orphan_record';
1121
+ if (result.reason === 'invalid_operation' ||
1122
+ result.reason === 'invalid_creator' ||
1123
+ result.reason === 'unsupported_generation' ||
1124
+ result.reason === 'ambiguous_record') {
1125
+ return 'invalid_creator';
1126
+ }
1127
+ return 'invalid_pair';
1128
+ }
1129
+ function validatePositiveOccurrences(occurrences, proofs, check) {
1130
+ var _a;
1131
+ const creatorsByClaim = new Map();
1132
+ for (const occurrence of occurrences) {
1133
+ check();
1134
+ const claimId = required(occurrence.item.claimId, 'invalid_creator', check);
1135
+ if (occurrence.item.effect !== 'created')
1136
+ continue;
1137
+ const rows = (_a = creatorsByClaim.get(claimId)) !== null && _a !== void 0 ? _a : [];
1138
+ rows.push(occurrence);
1139
+ creatorsByClaim.set(claimId, rows);
1140
+ }
1141
+ check();
1142
+ for (const [claimId, creators] of creatorsByClaim) {
1143
+ check();
1144
+ if (creators.length !== 1) {
1145
+ check();
1146
+ fail('invalid_creator');
1147
+ }
1148
+ const proof = required(proofs.get(claimId), 'orphan_record', check);
1149
+ const creator = creators[0];
1150
+ const receipt = creator.operation.terminalReceipt;
1151
+ const item = creator.item;
1152
+ if (proof.operationId !== creator.operation.operationId ||
1153
+ proof.operationId !== receipt.operationId ||
1154
+ proof.sourceId !== creator.operation.identity.sourceId ||
1155
+ proof.sourceId !== receipt.sourceId ||
1156
+ proof.claimId !== claimId ||
1157
+ proof.kind !== item.kind ||
1158
+ proof.evidenceHash !== item.evidenceHash ||
1159
+ proof.meaningHash !== item.meaningHash ||
1160
+ !equalData(proof.dependencies, item.dependencies)) {
1161
+ check();
1162
+ fail('invalid_creator');
1163
+ }
1164
+ }
1165
+ check();
1166
+ for (const occurrence of occurrences) {
1167
+ check();
1168
+ const item = occurrence.item;
1169
+ const claimId = required(item.claimId, 'invalid_creator', check);
1170
+ const proof = required(proofs.get(claimId), 'orphan_record', check);
1171
+ const identityMatches = proof.storeHash === occurrence.operation.identity.storeHash &&
1172
+ proof.namespace === occurrence.operation.identity.namespace &&
1173
+ proof.subjectId === occurrence.operation.identity.binding.subjectId;
1174
+ if (!identityMatches) {
1175
+ check();
1176
+ fail(item.effect === 'reference' ? 'invalid_pair' : 'invalid_creator');
1177
+ }
1178
+ if (proof.claimId !== claimId ||
1179
+ proof.kind !== item.kind ||
1180
+ proof.meaningHash !== item.meaningHash) {
1181
+ check();
1182
+ fail(item.effect === 'created' ? 'invalid_creator' : 'invalid_pair');
1183
+ }
1184
+ }
1185
+ check();
1186
+ }
1187
+ function validateFootprints(graph, footprints, index, check) {
1188
+ var _a;
1189
+ const edgeRowsById = new Map();
1190
+ check();
1191
+ for (const edge of graph.edges) {
1192
+ check();
1193
+ edgeRowsById.set(edge.uuid, edge);
1194
+ }
1195
+ check();
1196
+ const candidateEdgeIds = new Set(footprints.edgeIds);
1197
+ const creatorCounts = new Map();
1198
+ for (const occurrence of footprints.positiveOccurrences) {
1199
+ check();
1200
+ const claimId = required(occurrence.item.claimId, 'invalid_creator', check);
1201
+ candidateEdgeIds.add(claimId);
1202
+ if (occurrence.item.effect === 'created') {
1203
+ creatorCounts.set(claimId, ((_a = creatorCounts.get(claimId)) !== null && _a !== void 0 ? _a : 0) + 1);
1204
+ }
1205
+ }
1206
+ check();
1207
+ for (const count of creatorCounts.values()) {
1208
+ check();
1209
+ if (count !== 1) {
1210
+ check();
1211
+ fail('invalid_creator');
1212
+ }
1213
+ }
1214
+ check();
1215
+ const proofs = new Map();
1216
+ for (const claimId of candidateEdgeIds) {
1217
+ check();
1218
+ if (!edgeRowsById.has(claimId)) {
1219
+ check();
1220
+ fail('orphan_record');
1221
+ }
1222
+ let result;
1223
+ try {
1224
+ result = inspectAutonomousPersonalClaimCreatorV4(index, claimId);
1225
+ }
1226
+ catch (error) {
1227
+ if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
1228
+ throw error;
1229
+ check();
1230
+ fail('inspection_incomplete');
1231
+ }
1232
+ check();
1233
+ if (result.status !== 'structural') {
1234
+ check();
1235
+ fail(inspectFailureReason(result));
1236
+ }
1237
+ proofs.set(claimId, result.proof);
1238
+ }
1239
+ check();
1240
+ for (const edgeId of footprints.edgeIds) {
1241
+ check();
1242
+ const proof = proofs.get(edgeId);
1243
+ if (!proof || proof.claimId !== edgeId) {
1244
+ check();
1245
+ fail('orphan_record');
1246
+ }
1247
+ }
1248
+ check();
1249
+ for (const valueId of footprints.valueIds) {
1250
+ check();
1251
+ let matchingProofCount = 0;
1252
+ for (const proof of proofs.values()) {
1253
+ check();
1254
+ if (proof.valueId === valueId)
1255
+ matchingProofCount += 1;
1256
+ }
1257
+ if (matchingProofCount === 0) {
1258
+ check();
1259
+ fail('orphan_record');
1260
+ }
1261
+ if (matchingProofCount !== 1) {
1262
+ check();
1263
+ fail('invalid_pair');
1264
+ }
1265
+ }
1266
+ check();
1267
+ validatePositiveOccurrences(footprints.positiveOccurrences, proofs, check);
1268
+ check();
1269
+ }
1270
+ function checkAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck, requireIndex) {
1271
+ return checkOwnedAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck, requireIndex).index;
1272
+ }
1273
+ function checkOwnedAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck, requireIndex) {
1274
+ var _a;
1275
+ const trusted = stickyTrustedCheck(codeOwnedCheck);
1276
+ trusted.check();
1277
+ const registered = getRegisteredAutonomousPersonalClaimIndexGraphV4(graphValue);
1278
+ if (registered) {
1279
+ trusted.check();
1280
+ return {
1281
+ index: checkParsedAutonomousPersonalRecordIntegrityV4(registered, typedSyntaxWork, trusted, requireIndex),
1282
+ };
1283
+ }
1284
+ let graph;
1285
+ let ownershipFailure;
1286
+ try {
1287
+ graph =
1288
+ (_a = (0, ImmutableGraphSnapshot_1.getOwnedImmutableGraphData)(graphValue)) !== null && _a !== void 0 ? _a : (0, LosslessAutomaticCaptureGraph_1.parseLosslessAutomaticCaptureGraph)(graphValue);
1289
+ }
1290
+ catch (error) {
1291
+ ownershipFailure = error;
1292
+ }
1293
+ trusted.check();
1294
+ if (ownershipFailure !== undefined) {
1295
+ trusted.rethrowFailure();
1296
+ mapOwnershipFailure(ownershipFailure);
1297
+ }
1298
+ if (!graph)
1299
+ fail('invalid_snapshot');
1300
+ const index = checkParsedAutonomousPersonalRecordIntegrityV4(graph, typedSyntaxWork, trusted, requireIndex);
1301
+ return requireIndex ? { index } : { index, owned: graph };
1302
+ }
1303
+ function checkParsedAutonomousPersonalRecordIntegrityV4(graph, typedSyntaxWork, trusted, requireIndex) {
1304
+ const footprints = collectFootprints(graph, trusted.check);
1305
+ trusted.check();
1306
+ if (footprints.edgeIds.size === 0 &&
1307
+ footprints.valueIds.size === 0 &&
1308
+ footprints.positiveOccurrences.length === 0) {
1309
+ trusted.check();
1310
+ if (!requireIndex)
1311
+ return undefined;
1312
+ }
1313
+ const workCheck = stickyWorkCheck(typedSyntaxWork, trusted);
1314
+ let index;
1315
+ let indexedGraph = graph;
1316
+ try {
1317
+ workCheck.check();
1318
+ index = indexParsedGraphV4(graph, typedSyntaxWork, workCheck.check, requireIndex);
1319
+ workCheck.check();
1320
+ if (requireIndex) {
1321
+ indexedGraph = getAutonomousPersonalClaimIndexGraphV4(index);
1322
+ workCheck.check();
1323
+ }
1324
+ }
1325
+ catch (error) {
1326
+ workCheck.rethrowFailure();
1327
+ if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
1328
+ throw error;
1329
+ mapIndexFailure(error);
1330
+ }
1331
+ try {
1332
+ validateFootprints(requireIndex ? indexedGraph : graph, footprints, index, workCheck.check);
1333
+ workCheck.check();
1334
+ }
1335
+ catch (error) {
1336
+ workCheck.rethrowFailure();
1337
+ if (error instanceof AutonomousPersonalTypedSyntaxV1_2.AutonomousPersonalTypedSyntaxFailureV1)
1338
+ throw error;
1339
+ if (error instanceof AutonomousPersonalRecordIntegrityV4Error)
1340
+ throw error;
1341
+ mapIndexFailure(error);
1342
+ }
1343
+ workCheck.check();
1344
+ return requireIndex ? index : undefined;
1345
+ }
1346
+ function assertAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck) {
1347
+ checkAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck, false);
1348
+ }
1349
+ function validateOwnedAutonomousPersonalRecordGraphV4(graphValue, typedSyntaxWork, codeOwnedCheck) {
1350
+ return checkOwnedAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck, false).owned;
1351
+ }
1352
+ function createIntegrityCheckedAutonomousPersonalClaimIndexV4(graphValue, typedSyntaxWork, codeOwnedCheck) {
1353
+ const index = checkAutonomousPersonalRecordIntegrityV4(graphValue, typedSyntaxWork, codeOwnedCheck, true);
1354
+ if (!index)
1355
+ fail('invalid_snapshot');
1356
+ return index;
1357
+ }
1358
+ function meteredV4(operation, work = (0, AutonomousPersonalExecutionScopeV1_1.currentAutonomousPersonalExecutionScopeWorkV1)()) {
1359
+ return work === undefined
1360
+ ? operation()
1361
+ : (0, AutonomousPersonalExecutionScopeV1_1.runCurrentAutonomousPersonalExecutionScopeSyntaxSpanV1)(work, operation);
1362
+ }
1363
+ function parseIntegrityCheckedAutonomousPersonalGraphV4(graphValue, typedSyntaxWork, codeOwnedCheck) {
1364
+ const graph = meteredV4(() => (0, LosslessAutomaticCaptureGraph_1.parseLosslessAutomaticCaptureGraph)(graphValue));
1365
+ meteredV4(() => {
1366
+ codeOwnedCheck();
1367
+ (0, AutomaticIdentity_1.assertAutomaticLedgerSourceIntegrity)(graph);
1368
+ codeOwnedCheck();
1369
+ meteredV4(() => {
1370
+ const trusted = stickyTrustedCheck(codeOwnedCheck);
1371
+ trusted.check();
1372
+ trusted.check();
1373
+ checkParsedAutonomousPersonalRecordIntegrityV4(graph, typedSyntaxWork, trusted, false);
1374
+ });
1375
+ codeOwnedCheck();
1376
+ }, typedSyntaxWork);
1377
+ return graph;
1378
+ }
895
1379
  //# sourceMappingURL=AutonomousPersonalQualifiedClaimV4.js.map