@jungjaehoon/mama-core 1.4.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -10
- package/db/migrations/026-create-canonical-entity-tables.sql +99 -0
- package/db/migrations/027-create-entity-review-support.sql +44 -0
- package/db/migrations/028-create-entity-audit-tables.sql +45 -0
- package/db/migrations/029-extend-entity-observations-observation-type.sql +60 -0
- package/db/migrations/030-case-first-memory-substrate.sql +901 -0
- package/db/migrations/031-wiki-page-index-provenance-columns.sql +2 -0
- package/db/migrations/032-add-memory-provenance-columns.sql +21 -0
- package/db/migrations/033-create-model-runs-and-tool-traces.sql +53 -0
- package/db/migrations/034-add-connector-event-scope-columns.sql +14 -0
- package/db/migrations/035-create-twin-edges.sql +63 -0
- package/db/migrations/036-create-agent-situation-packets.sql +61 -0
- package/dist/agent-graph/alias-write.d.ts +3 -0
- package/dist/agent-graph/alias-write.js +231 -0
- package/dist/agent-graph/entity-resolve.d.ts +3 -0
- package/dist/agent-graph/entity-resolve.js +275 -0
- package/dist/agent-graph/errors.d.ts +4 -0
- package/dist/agent-graph/errors.js +11 -0
- package/dist/agent-graph/graph-query.d.ts +5 -0
- package/dist/agent-graph/graph-query.js +359 -0
- package/dist/agent-graph/index.d.ts +6 -0
- package/dist/agent-graph/index.js +22 -0
- package/dist/agent-graph/types.d.ts +162 -0
- package/dist/agent-graph/types.js +3 -0
- package/dist/agent-situation/builder.d.ts +8 -0
- package/dist/agent-situation/builder.js +239 -0
- package/dist/agent-situation/cache-key.d.ts +4 -0
- package/dist/agent-situation/cache-key.js +64 -0
- package/dist/agent-situation/index.d.ts +7 -0
- package/dist/agent-situation/index.js +28 -0
- package/dist/agent-situation/packet-store.d.ts +27 -0
- package/dist/agent-situation/packet-store.js +228 -0
- package/dist/agent-situation/ranking-policy.d.ts +18 -0
- package/dist/agent-situation/ranking-policy.js +75 -0
- package/dist/agent-situation/source-readers.d.ts +52 -0
- package/dist/agent-situation/source-readers.js +300 -0
- package/dist/agent-situation/types.d.ts +195 -0
- package/dist/agent-situation/types.js +3 -0
- package/dist/canonicalize.d.ts +38 -0
- package/dist/canonicalize.js +106 -0
- package/dist/cases/case-links.d.ts +116 -0
- package/dist/cases/case-links.js +794 -0
- package/dist/cases/composition-overrides.d.ts +90 -0
- package/dist/cases/composition-overrides.js +724 -0
- package/dist/cases/corrections.d.ts +156 -0
- package/dist/cases/corrections.js +1045 -0
- package/dist/cases/freshness.d.ts +57 -0
- package/dist/cases/freshness.js +283 -0
- package/dist/cases/live-state.d.ts +48 -0
- package/dist/cases/live-state.js +256 -0
- package/dist/cases/membership-explain.d.ts +56 -0
- package/dist/cases/membership-explain.js +140 -0
- package/dist/cases/membership-matcher.d.ts +23 -0
- package/dist/cases/membership-matcher.js +193 -0
- package/dist/cases/merge-split.d.ts +61 -0
- package/dist/cases/merge-split.js +368 -0
- package/dist/cases/role-inference.d.ts +10 -0
- package/dist/cases/role-inference.js +85 -0
- package/dist/cases/search-rollup.d.ts +27 -0
- package/dist/cases/search-rollup.js +309 -0
- package/dist/cases/sqlite-transaction.d.ts +10 -0
- package/dist/cases/sqlite-transaction.js +62 -0
- package/dist/cases/store.d.ts +74 -0
- package/dist/cases/store.js +816 -0
- package/dist/cases/target-ref.d.ts +25 -0
- package/dist/cases/target-ref.js +22 -0
- package/dist/cases/timeline-range.d.ts +6 -0
- package/dist/cases/timeline-range.js +322 -0
- package/dist/cases/tombstone-sweeper.d.ts +13 -0
- package/dist/cases/tombstone-sweeper.js +128 -0
- package/dist/cases/types.d.ts +244 -0
- package/dist/cases/types.js +47 -0
- package/dist/cases/wiki-page-index.d.ts +50 -0
- package/dist/cases/wiki-page-index.js +350 -0
- package/dist/connectors/event-index.d.ts +45 -0
- package/dist/connectors/event-index.js +381 -0
- package/dist/connectors/raw-query.d.ts +18 -0
- package/dist/connectors/raw-query.js +305 -0
- package/dist/connectors/types.d.ts +109 -0
- package/dist/connectors/types.js +3 -0
- package/dist/db-adapter/node-sqlite-adapter.d.ts +6 -0
- package/dist/db-adapter/node-sqlite-adapter.js +131 -0
- package/dist/db-manager.d.ts +12 -1
- package/dist/db-manager.js +60 -5
- package/dist/decision-formatter.d.ts +2 -0
- package/dist/decision-formatter.js +11 -8
- package/dist/edges/ref-validation.d.ts +8 -0
- package/dist/edges/ref-validation.js +262 -0
- package/dist/edges/store.d.ts +10 -0
- package/dist/edges/store.js +343 -0
- package/dist/edges/types.d.ts +86 -0
- package/dist/edges/types.js +18 -0
- package/dist/embedding-server/mobile/daemon.d.ts +1 -0
- package/dist/embedding-server/mobile/daemon.js +11 -1
- package/dist/embeddings.js +13 -0
- package/dist/entities/audit-metrics.d.ts +73 -0
- package/dist/entities/audit-metrics.js +128 -0
- package/dist/entities/candidate-generator.d.ts +9 -0
- package/dist/entities/candidate-generator.js +436 -0
- package/dist/entities/entity-impact.d.ts +41 -0
- package/dist/entities/entity-impact.js +140 -0
- package/dist/entities/entity-linked-decision-counts.d.ts +2 -0
- package/dist/entities/entity-linked-decision-counts.js +29 -0
- package/dist/entities/entity-list.d.ts +23 -0
- package/dist/entities/entity-list.js +99 -0
- package/dist/entities/entity-orphan-list.d.ts +26 -0
- package/dist/entities/entity-orphan-list.js +91 -0
- package/dist/entities/entity-search.d.ts +21 -0
- package/dist/entities/entity-search.js +150 -0
- package/dist/entities/errors.d.ts +65 -0
- package/dist/entities/errors.js +124 -0
- package/dist/entities/exact-merge-backfill.d.ts +11 -0
- package/dist/entities/exact-merge-backfill.js +161 -0
- package/dist/entities/lineage-backfill.d.ts +12 -0
- package/dist/entities/lineage-backfill.js +101 -0
- package/dist/entities/lineage-store.d.ts +51 -0
- package/dist/entities/lineage-store.js +308 -0
- package/dist/entities/normalization.d.ts +14 -0
- package/dist/entities/normalization.js +63 -0
- package/dist/entities/policy-store.d.ts +17 -0
- package/dist/entities/policy-store.js +263 -0
- package/dist/entities/policy-types.d.ts +72 -0
- package/dist/entities/policy-types.js +59 -0
- package/dist/entities/projection.d.ts +8 -0
- package/dist/entities/projection.js +82 -0
- package/dist/entities/provenance-query.d.ts +33 -0
- package/dist/entities/provenance-query.js +167 -0
- package/dist/entities/read-identity.d.ts +31 -0
- package/dist/entities/read-identity.js +264 -0
- package/dist/entities/recall-bridge.d.ts +5 -0
- package/dist/entities/recall-bridge.js +171 -0
- package/dist/entities/resolution-engine.d.ts +15 -0
- package/dist/entities/resolution-engine.js +69 -0
- package/dist/entities/rollback-preview.d.ts +39 -0
- package/dist/entities/rollback-preview.js +235 -0
- package/dist/entities/source-locator.d.ts +3 -0
- package/dist/entities/source-locator.js +32 -0
- package/dist/entities/store.d.ts +75 -0
- package/dist/entities/store.js +465 -0
- package/dist/entities/types.d.ts +162 -0
- package/dist/entities/types.js +30 -0
- package/dist/index.d.ts +62 -3
- package/dist/index.js +116 -26
- package/dist/mama-api.d.ts +53 -35
- package/dist/mama-api.js +437 -78
- package/dist/memory/api.d.ts +26 -38
- package/dist/memory/api.js +772 -68
- package/dist/memory/event-store.d.ts +3 -0
- package/dist/memory/event-store.js +21 -2
- package/dist/memory/provenance-audit.d.ts +22 -0
- package/dist/memory/provenance-audit.js +112 -0
- package/dist/memory/provenance-query.d.ts +11 -0
- package/dist/memory/provenance-query.js +193 -0
- package/dist/memory/provenance.d.ts +29 -0
- package/dist/memory/provenance.js +136 -0
- package/dist/memory/scope-backfill.d.ts +17 -0
- package/dist/memory/scope-backfill.js +77 -0
- package/dist/memory/types.d.ts +97 -16
- package/dist/model-runs/store.d.ts +13 -0
- package/dist/model-runs/store.js +457 -0
- package/dist/model-runs/tool-trace-store.d.ts +4 -0
- package/dist/model-runs/tool-trace-store.js +114 -0
- package/dist/model-runs/types.d.ts +69 -0
- package/dist/model-runs/types.js +5 -0
- package/dist/runtime/trusted-provenance.d.ts +3 -0
- package/dist/runtime/trusted-provenance.js +6 -0
- package/dist/search/feedback-store.d.ts +59 -0
- package/dist/search/feedback-store.js +211 -0
- package/dist/search/question-type.d.ts +5 -0
- package/dist/search/question-type.js +41 -0
- package/dist/search/ranker-features.d.ts +23 -0
- package/dist/search/ranker-features.js +104 -0
- package/dist/search/ranker-rescore.d.ts +31 -0
- package/dist/search/ranker-rescore.js +226 -0
- package/dist/search/ranker-trainer.d.ts +94 -0
- package/dist/search/ranker-trainer.js +860 -0
- package/dist/search/search-quality.d.ts +36 -0
- package/dist/search/search-quality.js +29 -0
- package/dist/test-utils.d.ts +14 -0
- package/dist/test-utils.js +52 -0
- package/package.json +28 -3
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.previewEntityRollback = previewEntityRollback;
|
|
4
|
+
const db_manager_js_1 = require("../db-manager.js");
|
|
5
|
+
const projection_js_1 = require("./projection.js");
|
|
6
|
+
const store_js_1 = require("./store.js");
|
|
7
|
+
const lineage_store_js_1 = require("./lineage-store.js");
|
|
8
|
+
function unavailableResult(entityId, mergeActionId, historyIncomplete) {
|
|
9
|
+
return {
|
|
10
|
+
entity_id: entityId,
|
|
11
|
+
merge_action_id: mergeActionId,
|
|
12
|
+
preview_unavailable: true,
|
|
13
|
+
history_incomplete: historyIncomplete,
|
|
14
|
+
truncated: false,
|
|
15
|
+
changed_entities: [],
|
|
16
|
+
changed_memories: [],
|
|
17
|
+
metric_movement: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function uniqueStrings(values) {
|
|
21
|
+
return Array.from(new Set(values.filter((value) => Boolean(value))));
|
|
22
|
+
}
|
|
23
|
+
function getLatestTimeline(adapter, entityId) {
|
|
24
|
+
const row = adapter
|
|
25
|
+
.prepare(`
|
|
26
|
+
SELECT *
|
|
27
|
+
FROM entity_timeline_events
|
|
28
|
+
WHERE entity_id = ?
|
|
29
|
+
ORDER BY COALESCE(observed_at, created_at) DESC
|
|
30
|
+
LIMIT 1
|
|
31
|
+
`)
|
|
32
|
+
.get(entityId);
|
|
33
|
+
if (!row) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
id: String(row.id),
|
|
38
|
+
entity_id: String(row.entity_id),
|
|
39
|
+
event_type: row.event_type,
|
|
40
|
+
role: typeof row.role === 'string' ? row.role : null,
|
|
41
|
+
valid_from: typeof row.valid_from === 'number' ? row.valid_from : null,
|
|
42
|
+
valid_to: typeof row.valid_to === 'number' ? row.valid_to : null,
|
|
43
|
+
observed_at: typeof row.observed_at === 'number' ? row.observed_at : null,
|
|
44
|
+
source_ref: typeof row.source_ref === 'string' ? row.source_ref : null,
|
|
45
|
+
summary: String(row.summary ?? ''),
|
|
46
|
+
details: typeof row.details === 'string' ? row.details : null,
|
|
47
|
+
created_at: Number(row.created_at),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const DEFAULT_MAX_AFFECTED_ROWS = 50;
|
|
51
|
+
function normalizeMaxAffectedRows(input) {
|
|
52
|
+
return Math.max(1, input.maxAffectedRows ?? DEFAULT_MAX_AFFECTED_ROWS);
|
|
53
|
+
}
|
|
54
|
+
function projectLabel(adapter, node) {
|
|
55
|
+
const summary = (0, projection_js_1.projectEntityToRecallSummary)(node, (0, store_js_1.listEntityAliases)(node.id, adapter), getLatestTimeline(adapter, node.id), { nodeLookup: { [node.id]: node } });
|
|
56
|
+
return summary.summary;
|
|
57
|
+
}
|
|
58
|
+
function loadMergeAction(adapter, entityId, mergeActionId) {
|
|
59
|
+
const sql = mergeActionId
|
|
60
|
+
? `
|
|
61
|
+
SELECT id, source_entity_id, target_entity_id, created_at
|
|
62
|
+
FROM entity_merge_actions
|
|
63
|
+
WHERE id = ?
|
|
64
|
+
AND (source_entity_id = ? OR target_entity_id = ?)
|
|
65
|
+
LIMIT 1
|
|
66
|
+
`
|
|
67
|
+
: `
|
|
68
|
+
SELECT id, source_entity_id, target_entity_id, created_at
|
|
69
|
+
FROM entity_merge_actions
|
|
70
|
+
WHERE target_entity_id = ?
|
|
71
|
+
ORDER BY created_at DESC
|
|
72
|
+
LIMIT 1
|
|
73
|
+
`;
|
|
74
|
+
const row = (mergeActionId
|
|
75
|
+
? adapter.prepare(sql).get(mergeActionId, entityId, entityId)
|
|
76
|
+
: adapter.prepare(sql).get(entityId));
|
|
77
|
+
return row ?? null;
|
|
78
|
+
}
|
|
79
|
+
function resolveMergePreviewRows(input) {
|
|
80
|
+
let removedRows = input.targetActive.filter((row) => row.source_entity_id === input.sourceEntityId &&
|
|
81
|
+
(!input.mergeActionId || row.review_action_id === input.mergeActionId));
|
|
82
|
+
const removedObservationIds = new Set(removedRows.map((row) => row.entity_observation_id));
|
|
83
|
+
const restoredRows = input.sourceHistory.filter((row) => row.status === 'superseded' &&
|
|
84
|
+
(!input.mergeActionId ||
|
|
85
|
+
row.review_action_id === input.mergeActionId ||
|
|
86
|
+
removedObservationIds.has(row.entity_observation_id)));
|
|
87
|
+
if (removedRows.length === 0 && restoredRows.length > 0) {
|
|
88
|
+
const restorableObservationIds = new Set(restoredRows.map((row) => row.entity_observation_id));
|
|
89
|
+
removedRows = input.targetActive.filter((row) => restorableObservationIds.has(row.entity_observation_id) &&
|
|
90
|
+
(!input.mergeActionId || row.review_action_id === input.mergeActionId));
|
|
91
|
+
}
|
|
92
|
+
return { restoredRows, removedRows };
|
|
93
|
+
}
|
|
94
|
+
function loadChangedMemories(adapter, observationIds) {
|
|
95
|
+
if (observationIds.length === 0) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const placeholders = observationIds.map(() => '?').join(', ');
|
|
99
|
+
const rows = adapter
|
|
100
|
+
.prepare(`
|
|
101
|
+
SELECT DISTINCT d.id, d.topic, d.summary, d.created_at
|
|
102
|
+
FROM decision_entity_sources des
|
|
103
|
+
JOIN decisions d ON d.id = des.decision_id
|
|
104
|
+
WHERE des.entity_observation_id IN (${placeholders})
|
|
105
|
+
ORDER BY d.created_at DESC
|
|
106
|
+
`)
|
|
107
|
+
.all(...observationIds);
|
|
108
|
+
return rows.map((row) => ({
|
|
109
|
+
id: row.id,
|
|
110
|
+
topic: row.topic,
|
|
111
|
+
summary: row.summary ?? row.topic,
|
|
112
|
+
created_at: row.created_at,
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
function buildMetricMovement(sourceLabel) {
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
metric: 'false_merge_rate',
|
|
119
|
+
direction: 'decrease',
|
|
120
|
+
reason: `Splitting ${sourceLabel} back out would likely reduce false merge pressure.`,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
metric: 'projection_fragmentation_rate',
|
|
124
|
+
direction: 'increase',
|
|
125
|
+
reason: `Reactivating a second canonical entity likely increases projection fragmentation.`,
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
async function previewMergeRollback(adapter, input, mergeAction) {
|
|
130
|
+
const sourceNode = (0, store_js_1.getEntityNode)(mergeAction.source_entity_id, adapter);
|
|
131
|
+
const targetNode = (0, store_js_1.getEntityNode)(mergeAction.target_entity_id, adapter);
|
|
132
|
+
if (!sourceNode || !targetNode) {
|
|
133
|
+
return unavailableResult(input.entityId, mergeAction.id, true);
|
|
134
|
+
}
|
|
135
|
+
const sourceHistory = await (0, lineage_store_js_1.listEntityLineageHistory)(sourceNode.id, adapter);
|
|
136
|
+
const targetActive = await (0, lineage_store_js_1.listActiveEntityLineage)(targetNode.id, adapter);
|
|
137
|
+
const { restoredRows, removedRows } = resolveMergePreviewRows({
|
|
138
|
+
sourceHistory,
|
|
139
|
+
targetActive,
|
|
140
|
+
sourceEntityId: sourceNode.id,
|
|
141
|
+
mergeActionId: input.mergeActionId,
|
|
142
|
+
});
|
|
143
|
+
if (restoredRows.length === 0 || removedRows.length === 0) {
|
|
144
|
+
return unavailableResult(input.entityId, mergeAction.id, true);
|
|
145
|
+
}
|
|
146
|
+
const affectedObservationIds = uniqueStrings([
|
|
147
|
+
...restoredRows.map((row) => row.entity_observation_id),
|
|
148
|
+
...removedRows.map((row) => row.entity_observation_id),
|
|
149
|
+
]);
|
|
150
|
+
const allChangedMemories = loadChangedMemories(adapter, affectedObservationIds);
|
|
151
|
+
const maxAffectedRows = normalizeMaxAffectedRows(input);
|
|
152
|
+
const truncated = allChangedMemories.length > maxAffectedRows;
|
|
153
|
+
return {
|
|
154
|
+
entity_id: input.entityId,
|
|
155
|
+
merge_action_id: mergeAction.id,
|
|
156
|
+
preview_unavailable: false,
|
|
157
|
+
history_incomplete: false,
|
|
158
|
+
truncated,
|
|
159
|
+
changed_entities: [
|
|
160
|
+
{
|
|
161
|
+
entity_id: sourceNode.id,
|
|
162
|
+
label: sourceNode.preferred_label,
|
|
163
|
+
status_after: 'active',
|
|
164
|
+
active_lineage_after: restoredRows.length,
|
|
165
|
+
summary: projectLabel(adapter, { ...sourceNode, status: 'active', merged_into: null }),
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
entity_id: targetNode.id,
|
|
169
|
+
label: targetNode.preferred_label,
|
|
170
|
+
status_after: 'active',
|
|
171
|
+
active_lineage_after: Math.max(0, targetActive.length - removedRows.length),
|
|
172
|
+
summary: projectLabel(adapter, targetNode),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
changed_memories: allChangedMemories.slice(0, maxAffectedRows),
|
|
176
|
+
metric_movement: buildMetricMovement(sourceNode.preferred_label),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
async function previewObservationDetach(adapter, input) {
|
|
180
|
+
const activeTarget = await (0, lineage_store_js_1.listActiveEntityLineage)(input.entityId, adapter);
|
|
181
|
+
const targetNode = (0, store_js_1.getEntityNode)(input.entityId, adapter);
|
|
182
|
+
if (!targetNode) {
|
|
183
|
+
return unavailableResult(input.entityId, null, false);
|
|
184
|
+
}
|
|
185
|
+
const row = activeTarget.find((candidate) => candidate.entity_observation_id === input.observationId);
|
|
186
|
+
if (!row) {
|
|
187
|
+
return unavailableResult(input.entityId, null, false);
|
|
188
|
+
}
|
|
189
|
+
const changedMemories = loadChangedMemories(adapter, [row.entity_observation_id]);
|
|
190
|
+
const maxAffectedRows = normalizeMaxAffectedRows(input);
|
|
191
|
+
return {
|
|
192
|
+
entity_id: input.entityId,
|
|
193
|
+
merge_action_id: null,
|
|
194
|
+
preview_unavailable: false,
|
|
195
|
+
history_incomplete: false,
|
|
196
|
+
truncated: changedMemories.length > maxAffectedRows,
|
|
197
|
+
changed_entities: [
|
|
198
|
+
{
|
|
199
|
+
entity_id: targetNode.id,
|
|
200
|
+
label: targetNode.preferred_label,
|
|
201
|
+
status_after: 'active',
|
|
202
|
+
active_lineage_after: Math.max(0, activeTarget.length - 1),
|
|
203
|
+
summary: projectLabel(adapter, targetNode),
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
changed_memories: changedMemories.slice(0, maxAffectedRows),
|
|
207
|
+
metric_movement: [
|
|
208
|
+
{
|
|
209
|
+
metric: 'false_merge_rate',
|
|
210
|
+
direction: 'decrease',
|
|
211
|
+
reason: 'Removing one supporting observation may reduce merge confidence for the current entity.',
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
metric: 'projection_fragmentation_rate',
|
|
215
|
+
direction: 'increase',
|
|
216
|
+
reason: 'Detaching one observation may increase fragmentation if it needs a separate entity later.',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
async function previewEntityRollback(input, options = {}) {
|
|
222
|
+
if (!options.adapter) {
|
|
223
|
+
await (0, db_manager_js_1.initDB)();
|
|
224
|
+
}
|
|
225
|
+
const adapter = options.adapter ?? (0, db_manager_js_1.getAdapter)();
|
|
226
|
+
if (input.observationId) {
|
|
227
|
+
return previewObservationDetach(adapter, input);
|
|
228
|
+
}
|
|
229
|
+
const mergeAction = loadMergeAction(adapter, input.entityId, input.mergeActionId);
|
|
230
|
+
if (!mergeAction) {
|
|
231
|
+
return unavailableResult(input.entityId, input.mergeActionId ?? null, false);
|
|
232
|
+
}
|
|
233
|
+
return previewMergeRollback(adapter, input, mergeAction);
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=rollback-preview.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectSourceLocatorKind = detectSourceLocatorKind;
|
|
4
|
+
function detectSourceLocatorKind(locator) {
|
|
5
|
+
if (typeof locator !== 'string' || locator.trim().length === 0) {
|
|
6
|
+
return 'unknown';
|
|
7
|
+
}
|
|
8
|
+
const trimmed = locator.trim();
|
|
9
|
+
const normalized = trimmed.toLowerCase();
|
|
10
|
+
if (normalized.startsWith('http://') || normalized.startsWith('https://')) {
|
|
11
|
+
return 'url';
|
|
12
|
+
}
|
|
13
|
+
if (normalized.startsWith('file://')) {
|
|
14
|
+
return 'file';
|
|
15
|
+
}
|
|
16
|
+
if (normalized.startsWith('drive://') ||
|
|
17
|
+
normalized.startsWith('gmail://') ||
|
|
18
|
+
normalized.startsWith('calendar://') ||
|
|
19
|
+
normalized.startsWith('sheets://')) {
|
|
20
|
+
return 'connector';
|
|
21
|
+
}
|
|
22
|
+
if (normalized.endsWith('.db') ||
|
|
23
|
+
normalized.includes('/raw.db') ||
|
|
24
|
+
normalized.includes('\\raw.db')) {
|
|
25
|
+
return 'db';
|
|
26
|
+
}
|
|
27
|
+
if (trimmed.startsWith('/') || trimmed.startsWith('~/') || /^[A-Za-z]:[\\/]/.test(trimmed)) {
|
|
28
|
+
return 'file';
|
|
29
|
+
}
|
|
30
|
+
return 'unknown';
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=source-locator.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type EntityAlias, type EntityNode, type EntityObservation, type EntityTimelineEvent } from './types.js';
|
|
2
|
+
export interface EntityStoreAdapter {
|
|
3
|
+
prepare(sql: string): {
|
|
4
|
+
run(...params: unknown[]): {
|
|
5
|
+
changes: number;
|
|
6
|
+
lastInsertRowid: number | bigint;
|
|
7
|
+
};
|
|
8
|
+
get(...params: unknown[]): unknown;
|
|
9
|
+
all(...params: unknown[]): unknown[];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare class EntityMergeError extends Error {
|
|
13
|
+
readonly code: string;
|
|
14
|
+
constructor(code: string, message: string);
|
|
15
|
+
}
|
|
16
|
+
type CreateEntityNodeInput = Omit<EntityNode, 'created_at' | 'updated_at'>;
|
|
17
|
+
type AttachEntityAliasInput = Omit<EntityAlias, 'created_at'>;
|
|
18
|
+
type UpsertEntityObservationInput = Omit<EntityObservation, 'created_at'>;
|
|
19
|
+
type AppendEntityTimelineEventInput = {
|
|
20
|
+
event: Omit<EntityTimelineEvent, 'id' | 'created_at'> & {
|
|
21
|
+
id?: string;
|
|
22
|
+
created_at?: number;
|
|
23
|
+
};
|
|
24
|
+
adapter?: EntityStoreAdapter;
|
|
25
|
+
};
|
|
26
|
+
export interface UpsertEntityObservationResult {
|
|
27
|
+
id: string;
|
|
28
|
+
created: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function parseObservationRow(row: Record<string, unknown>): EntityObservation;
|
|
31
|
+
export declare function createEntityNode(input: CreateEntityNodeInput): Promise<EntityNode>;
|
|
32
|
+
export declare function getEntityNode(id: string, adapter?: EntityStoreAdapter): EntityNode | null;
|
|
33
|
+
export declare function listEntityNodes(): EntityNode[];
|
|
34
|
+
export declare function attachEntityAlias(input: AttachEntityAliasInput): Promise<EntityAlias>;
|
|
35
|
+
export declare function listEntityAliases(entityId: string, adapter?: EntityStoreAdapter): EntityAlias[];
|
|
36
|
+
export declare function upsertEntityObservation(input: UpsertEntityObservationInput): Promise<EntityObservation>;
|
|
37
|
+
export declare function upsertEntityObservations(inputs: UpsertEntityObservationInput[]): Promise<UpsertEntityObservationResult[]>;
|
|
38
|
+
export declare function appendEntityTimelineEvent(input: AppendEntityTimelineEventInput): Promise<EntityTimelineEvent>;
|
|
39
|
+
/**
|
|
40
|
+
* Walks the `entity_nodes.merged_into` chain from the given id and returns the
|
|
41
|
+
* terminal (unmerged) entity id. Detects cycles and caps depth. Read-only.
|
|
42
|
+
*
|
|
43
|
+
* Matches the read-time chain-walking approach described in the canonical
|
|
44
|
+
* entity ontology implementation plan.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveCanonicalEntityId(adapter: EntityStoreAdapter, id: string): string;
|
|
47
|
+
export interface MergeEntityNodesInput {
|
|
48
|
+
adapter: EntityStoreAdapter;
|
|
49
|
+
source_id: string;
|
|
50
|
+
target_id: string;
|
|
51
|
+
actor_type: 'system' | 'user' | 'agent';
|
|
52
|
+
actor_id: string;
|
|
53
|
+
reason: string;
|
|
54
|
+
candidate_id: string | null;
|
|
55
|
+
evidence_json: string;
|
|
56
|
+
}
|
|
57
|
+
export interface MergeEntityNodesResult {
|
|
58
|
+
merge_action_id: string;
|
|
59
|
+
timeline_event_id: string;
|
|
60
|
+
merged_at: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Marks `source_id` as merged into `target_id`, emits a timeline event, and
|
|
64
|
+
* inserts the entity_merge_actions audit row with both entity IDs populated.
|
|
65
|
+
*
|
|
66
|
+
* Intentionally NOT wrapped in its own transaction — the caller is expected
|
|
67
|
+
* to wrap the call in `adapter.transaction(...)` so the candidate status
|
|
68
|
+
* update and this merge land atomically (Policy B1, hard transaction).
|
|
69
|
+
*
|
|
70
|
+
* Validates: source != target, both exist, both active/unmerged, same kind,
|
|
71
|
+
* same scope. Throws `EntityMergeError` with a stable `code` on any violation.
|
|
72
|
+
*/
|
|
73
|
+
export declare function mergeEntityNodes(input: MergeEntityNodesInput): MergeEntityNodesResult;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=store.d.ts.map
|