@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
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { DatabaseAdapter } from '../db-manager.js';
|
|
1
2
|
import type { MemoryEventRecord } from './types.js';
|
|
2
3
|
export declare function appendMemoryEvent(input: Omit<MemoryEventRecord, 'event_id'>): Promise<string>;
|
|
4
|
+
export declare function insertMemoryEventInTransaction(adapter: Pick<DatabaseAdapter, 'prepare'>, input: Omit<MemoryEventRecord, 'event_id'>): string;
|
|
3
5
|
export declare function listMemoryEventsForTopic(topic: string): Promise<MemoryEventRecord[]>;
|
|
6
|
+
export declare function listMemoryEventsForMemory(memoryId: string): Promise<MemoryEventRecord[]>;
|
|
4
7
|
export declare function listRecentMemoryEvents(limit?: number): Promise<MemoryEventRecord[]>;
|
|
5
8
|
//# sourceMappingURL=event-store.d.ts.map
|
|
@@ -4,7 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.appendMemoryEvent = appendMemoryEvent;
|
|
7
|
+
exports.insertMemoryEventInTransaction = insertMemoryEventInTransaction;
|
|
7
8
|
exports.listMemoryEventsForTopic = listMemoryEventsForTopic;
|
|
9
|
+
exports.listMemoryEventsForMemory = listMemoryEventsForMemory;
|
|
8
10
|
exports.listRecentMemoryEvents = listRecentMemoryEvents;
|
|
9
11
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
12
|
const db_manager_js_1 = require("../db-manager.js");
|
|
@@ -29,6 +31,9 @@ function deserializeEvent(row) {
|
|
|
29
31
|
async function appendMemoryEvent(input) {
|
|
30
32
|
await (0, db_manager_js_1.initDB)();
|
|
31
33
|
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
34
|
+
return insertMemoryEventInTransaction(adapter, input);
|
|
35
|
+
}
|
|
36
|
+
function insertMemoryEventInTransaction(adapter, input) {
|
|
32
37
|
const eventId = `evt_${node_crypto_1.default.randomUUID().replace(/-/g, '')}`;
|
|
33
38
|
adapter
|
|
34
39
|
.prepare(`
|
|
@@ -50,11 +55,25 @@ async function listMemoryEventsForTopic(topic) {
|
|
|
50
55
|
scope_refs, evidence_refs, reason, created_at
|
|
51
56
|
FROM memory_events
|
|
52
57
|
WHERE topic = ?
|
|
53
|
-
ORDER BY created_at DESC
|
|
58
|
+
ORDER BY created_at DESC, rowid DESC
|
|
54
59
|
`)
|
|
55
60
|
.all(topic);
|
|
56
61
|
return rows.map(deserializeEvent);
|
|
57
62
|
}
|
|
63
|
+
async function listMemoryEventsForMemory(memoryId) {
|
|
64
|
+
await (0, db_manager_js_1.initDB)();
|
|
65
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
66
|
+
const rows = adapter
|
|
67
|
+
.prepare(`
|
|
68
|
+
SELECT event_id, event_type, actor, source_turn_id, memory_id, topic,
|
|
69
|
+
scope_refs, evidence_refs, reason, created_at
|
|
70
|
+
FROM memory_events
|
|
71
|
+
WHERE memory_id = ?
|
|
72
|
+
ORDER BY created_at DESC, rowid DESC
|
|
73
|
+
`)
|
|
74
|
+
.all(memoryId);
|
|
75
|
+
return rows.map(deserializeEvent);
|
|
76
|
+
}
|
|
58
77
|
async function listRecentMemoryEvents(limit = 10) {
|
|
59
78
|
await (0, db_manager_js_1.initDB)();
|
|
60
79
|
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
@@ -63,7 +82,7 @@ async function listRecentMemoryEvents(limit = 10) {
|
|
|
63
82
|
SELECT event_id, event_type, actor, source_turn_id, memory_id, topic,
|
|
64
83
|
scope_refs, evidence_refs, reason, created_at
|
|
65
84
|
FROM memory_events
|
|
66
|
-
ORDER BY created_at DESC
|
|
85
|
+
ORDER BY created_at DESC, rowid DESC
|
|
67
86
|
LIMIT ?
|
|
68
87
|
`)
|
|
69
88
|
.all(limit);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MemoryEventRecord, MemoryScopeRef } from './types.js';
|
|
2
|
+
export interface MemoryProvenanceAuditRecord {
|
|
3
|
+
memory_id: string;
|
|
4
|
+
topic: string;
|
|
5
|
+
summary: string;
|
|
6
|
+
envelope_hash: string | null;
|
|
7
|
+
model_run_id: string | null;
|
|
8
|
+
gateway_call_id: string | null;
|
|
9
|
+
tool_name: string | null;
|
|
10
|
+
latest_event?: MemoryEventRecord;
|
|
11
|
+
scope_refs: MemoryScopeRef[];
|
|
12
|
+
legacy_caveats: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface MemoryProvenanceAuditListOptions {
|
|
15
|
+
envelope_hash?: string;
|
|
16
|
+
model_run_id?: string;
|
|
17
|
+
gateway_call_id?: string;
|
|
18
|
+
limit?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function getMemoryProvenanceAudit(memoryId: string): Promise<MemoryProvenanceAuditRecord | null>;
|
|
21
|
+
export declare function listMemoryProvenanceAudit(options: MemoryProvenanceAuditListOptions): Promise<MemoryProvenanceAuditRecord[]>;
|
|
22
|
+
//# sourceMappingURL=provenance-audit.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMemoryProvenanceAudit = getMemoryProvenanceAudit;
|
|
4
|
+
exports.listMemoryProvenanceAudit = listMemoryProvenanceAudit;
|
|
5
|
+
const db_manager_js_1 = require("../db-manager.js");
|
|
6
|
+
const event_store_js_1 = require("./event-store.js");
|
|
7
|
+
async function getMemoryProvenanceAudit(memoryId) {
|
|
8
|
+
await (0, db_manager_js_1.initDB)();
|
|
9
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
10
|
+
const row = adapter
|
|
11
|
+
.prepare(`
|
|
12
|
+
SELECT id, topic, decision, summary, envelope_hash, model_run_id, gateway_call_id,
|
|
13
|
+
provenance_json
|
|
14
|
+
FROM decisions
|
|
15
|
+
WHERE id = ?
|
|
16
|
+
`)
|
|
17
|
+
.get(memoryId);
|
|
18
|
+
return row ? toAuditRecord(row) : null;
|
|
19
|
+
}
|
|
20
|
+
async function listMemoryProvenanceAudit(options) {
|
|
21
|
+
await (0, db_manager_js_1.initDB)();
|
|
22
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
23
|
+
const filter = buildAuditFilter(options);
|
|
24
|
+
const rows = adapter
|
|
25
|
+
.prepare(`
|
|
26
|
+
SELECT id, topic, decision, summary, envelope_hash, model_run_id, gateway_call_id,
|
|
27
|
+
provenance_json
|
|
28
|
+
FROM decisions
|
|
29
|
+
WHERE ${filter.sql}
|
|
30
|
+
ORDER BY created_at DESC, id DESC
|
|
31
|
+
LIMIT ?
|
|
32
|
+
`)
|
|
33
|
+
.all(...filter.params, normalizeLimit(options.limit));
|
|
34
|
+
const records = [];
|
|
35
|
+
for (const row of rows) {
|
|
36
|
+
records.push(await toAuditRecord(row));
|
|
37
|
+
}
|
|
38
|
+
return records;
|
|
39
|
+
}
|
|
40
|
+
function buildAuditFilter(options) {
|
|
41
|
+
const filters = [];
|
|
42
|
+
const params = [];
|
|
43
|
+
for (const column of ['envelope_hash', 'model_run_id', 'gateway_call_id']) {
|
|
44
|
+
const value = options[column];
|
|
45
|
+
if (value !== undefined) {
|
|
46
|
+
filters.push(`${column} = ?`);
|
|
47
|
+
params.push(value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (filters.length !== 1) {
|
|
51
|
+
throw new Error('Exactly one provenance audit filter is required.');
|
|
52
|
+
}
|
|
53
|
+
return { sql: filters[0], params };
|
|
54
|
+
}
|
|
55
|
+
async function toAuditRecord(row) {
|
|
56
|
+
const events = await (0, event_store_js_1.listMemoryEventsForMemory)(row.id);
|
|
57
|
+
const scopeRefs = listScopeRefs(row.id);
|
|
58
|
+
const provenance = parseObject(row.provenance_json);
|
|
59
|
+
const legacyCaveats = [];
|
|
60
|
+
if (provenance.source_type === 'legacy') {
|
|
61
|
+
legacyCaveats.push('legacy_provenance_backfill');
|
|
62
|
+
}
|
|
63
|
+
if (scopeRefs.length === 0) {
|
|
64
|
+
legacyCaveats.push('unscoped_memory');
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
memory_id: row.id,
|
|
68
|
+
topic: row.topic,
|
|
69
|
+
summary: row.summary ?? row.decision ?? '',
|
|
70
|
+
envelope_hash: row.envelope_hash,
|
|
71
|
+
model_run_id: row.model_run_id,
|
|
72
|
+
gateway_call_id: row.gateway_call_id,
|
|
73
|
+
tool_name: typeof provenance.tool_name === 'string' ? provenance.tool_name : null,
|
|
74
|
+
latest_event: events[0],
|
|
75
|
+
scope_refs: scopeRefs,
|
|
76
|
+
legacy_caveats: legacyCaveats,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function listScopeRefs(memoryId) {
|
|
80
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
81
|
+
const rows = adapter
|
|
82
|
+
.prepare(`
|
|
83
|
+
SELECT ms.kind, ms.external_id
|
|
84
|
+
FROM memory_scope_bindings msb
|
|
85
|
+
JOIN memory_scopes ms ON ms.id = msb.scope_id
|
|
86
|
+
WHERE msb.memory_id = ?
|
|
87
|
+
ORDER BY msb.is_primary DESC, ms.kind ASC, ms.external_id ASC
|
|
88
|
+
`)
|
|
89
|
+
.all(memoryId);
|
|
90
|
+
return rows.map((row) => ({ kind: row.kind, id: row.external_id }));
|
|
91
|
+
}
|
|
92
|
+
function normalizeLimit(limit) {
|
|
93
|
+
if (!Number.isFinite(limit)) {
|
|
94
|
+
return 50;
|
|
95
|
+
}
|
|
96
|
+
return Math.max(1, Math.min(200, Math.floor(limit)));
|
|
97
|
+
}
|
|
98
|
+
function parseObject(value) {
|
|
99
|
+
if (!value) {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const parsed = JSON.parse(value);
|
|
104
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
105
|
+
? parsed
|
|
106
|
+
: {};
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return {};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=provenance-audit.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MemoryProvenanceRecord, MemoryScopeRef } from './types.js';
|
|
2
|
+
export interface MemoryProvenanceQueryOptions {
|
|
3
|
+
scopes?: MemoryScopeRef[];
|
|
4
|
+
includeLegacyUnscoped?: boolean;
|
|
5
|
+
limit?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function getMemoryProvenance(memoryId: string, options?: MemoryProvenanceQueryOptions): Promise<MemoryProvenanceRecord | null>;
|
|
8
|
+
export declare function listMemoriesByEnvelopeHash(envelopeHash: string, options?: MemoryProvenanceQueryOptions): Promise<MemoryProvenanceRecord[]>;
|
|
9
|
+
export declare function listMemoriesByGatewayCallId(gatewayCallId: string, options?: MemoryProvenanceQueryOptions): Promise<MemoryProvenanceRecord[]>;
|
|
10
|
+
export declare function listMemoriesByModelRunId(modelRunId: string, options?: MemoryProvenanceQueryOptions): Promise<MemoryProvenanceRecord[]>;
|
|
11
|
+
//# sourceMappingURL=provenance-query.d.ts.map
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMemoryProvenance = getMemoryProvenance;
|
|
4
|
+
exports.listMemoriesByEnvelopeHash = listMemoriesByEnvelopeHash;
|
|
5
|
+
exports.listMemoriesByGatewayCallId = listMemoriesByGatewayCallId;
|
|
6
|
+
exports.listMemoriesByModelRunId = listMemoriesByModelRunId;
|
|
7
|
+
const db_manager_js_1 = require("../db-manager.js");
|
|
8
|
+
const event_store_js_1 = require("./event-store.js");
|
|
9
|
+
async function getMemoryProvenance(memoryId, options = {}) {
|
|
10
|
+
await (0, db_manager_js_1.initDB)();
|
|
11
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
12
|
+
const row = adapter
|
|
13
|
+
.prepare(`
|
|
14
|
+
SELECT id, agent_id, model_run_id, envelope_hash, gateway_call_id,
|
|
15
|
+
source_refs_json, provenance_json, created_at
|
|
16
|
+
FROM decisions
|
|
17
|
+
WHERE id = ?
|
|
18
|
+
`)
|
|
19
|
+
.get(memoryId);
|
|
20
|
+
if (!row || !(await isVisibleMemory(row.id, options))) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return toProvenanceRecord(row);
|
|
24
|
+
}
|
|
25
|
+
async function listMemoriesByEnvelopeHash(envelopeHash, options = {}) {
|
|
26
|
+
return listMemoriesByColumn('envelope_hash', envelopeHash, options);
|
|
27
|
+
}
|
|
28
|
+
async function listMemoriesByGatewayCallId(gatewayCallId, options = {}) {
|
|
29
|
+
return listMemoriesByColumn('gateway_call_id', gatewayCallId, options);
|
|
30
|
+
}
|
|
31
|
+
async function listMemoriesByModelRunId(modelRunId, options = {}) {
|
|
32
|
+
return listMemoriesByColumn('model_run_id', modelRunId, options);
|
|
33
|
+
}
|
|
34
|
+
async function listMemoriesByColumn(column, value, options) {
|
|
35
|
+
await (0, db_manager_js_1.initDB)();
|
|
36
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
37
|
+
const limit = normalizeLimit(options.limit);
|
|
38
|
+
const visibility = buildVisibilityPredicate(options);
|
|
39
|
+
const rows = adapter
|
|
40
|
+
.prepare(`
|
|
41
|
+
SELECT d.id, d.agent_id, d.model_run_id, d.envelope_hash, d.gateway_call_id,
|
|
42
|
+
d.source_refs_json, d.provenance_json, d.created_at
|
|
43
|
+
FROM decisions d
|
|
44
|
+
WHERE d.${column} = ?${visibility.sql}
|
|
45
|
+
ORDER BY d.created_at DESC, d.id DESC
|
|
46
|
+
LIMIT ?
|
|
47
|
+
`)
|
|
48
|
+
.all(value, ...visibility.params, limit);
|
|
49
|
+
const records = [];
|
|
50
|
+
for (const row of rows) {
|
|
51
|
+
records.push(await toProvenanceRecord(row));
|
|
52
|
+
}
|
|
53
|
+
return records;
|
|
54
|
+
}
|
|
55
|
+
function buildVisibilityPredicate(options) {
|
|
56
|
+
if (!hasScopeFilter(options)) {
|
|
57
|
+
return { sql: '', params: [] };
|
|
58
|
+
}
|
|
59
|
+
const scopeIds = resolveMemoryScopeIds(options.scopes);
|
|
60
|
+
const legacyUnscopedPredicate = `
|
|
61
|
+
NOT EXISTS (
|
|
62
|
+
SELECT 1
|
|
63
|
+
FROM memory_scope_bindings msb_legacy
|
|
64
|
+
WHERE msb_legacy.memory_id = d.id
|
|
65
|
+
)
|
|
66
|
+
`;
|
|
67
|
+
if (scopeIds.length === 0) {
|
|
68
|
+
return options.includeLegacyUnscoped === true
|
|
69
|
+
? { sql: ` AND ${legacyUnscopedPredicate}`, params: [] }
|
|
70
|
+
: { sql: ' AND 0 = 1', params: [] };
|
|
71
|
+
}
|
|
72
|
+
const placeholders = scopeIds.map(() => '?').join(', ');
|
|
73
|
+
const scopedPredicate = `
|
|
74
|
+
EXISTS (
|
|
75
|
+
SELECT 1
|
|
76
|
+
FROM memory_scope_bindings msb_scope
|
|
77
|
+
WHERE msb_scope.memory_id = d.id
|
|
78
|
+
AND msb_scope.scope_id IN (${placeholders})
|
|
79
|
+
)
|
|
80
|
+
`;
|
|
81
|
+
if (options.includeLegacyUnscoped === true) {
|
|
82
|
+
return {
|
|
83
|
+
sql: ` AND (${scopedPredicate} OR ${legacyUnscopedPredicate})`,
|
|
84
|
+
params: scopeIds,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { sql: ` AND ${scopedPredicate}`, params: scopeIds };
|
|
88
|
+
}
|
|
89
|
+
function hasScopeFilter(options) {
|
|
90
|
+
return Array.isArray(options.scopes) && options.scopes.length > 0;
|
|
91
|
+
}
|
|
92
|
+
function resolveMemoryScopeIds(scopes) {
|
|
93
|
+
const scopeIds = [];
|
|
94
|
+
for (const scope of scopes) {
|
|
95
|
+
const scopeId = resolveMemoryScopeId(scope.kind, scope.id);
|
|
96
|
+
if (scopeId) {
|
|
97
|
+
scopeIds.push(scopeId);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return scopeIds;
|
|
101
|
+
}
|
|
102
|
+
async function toProvenanceRecord(row) {
|
|
103
|
+
const events = await (0, event_store_js_1.listMemoryEventsForMemory)(row.id);
|
|
104
|
+
return {
|
|
105
|
+
memory_id: row.id,
|
|
106
|
+
agent_id: row.agent_id,
|
|
107
|
+
model_run_id: row.model_run_id,
|
|
108
|
+
envelope_hash: row.envelope_hash,
|
|
109
|
+
gateway_call_id: row.gateway_call_id,
|
|
110
|
+
source_refs: parseStringArray(row.source_refs_json),
|
|
111
|
+
provenance: parseObject(row.provenance_json),
|
|
112
|
+
latest_event: events[0],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function isVisibleMemory(memoryId, options) {
|
|
116
|
+
if (!hasScopeFilter(options)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
await (0, db_manager_js_1.initDB)();
|
|
120
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
121
|
+
const scopeIds = resolveMemoryScopeIds(options.scopes);
|
|
122
|
+
const bindingCount = adapter
|
|
123
|
+
.prepare(`
|
|
124
|
+
SELECT COUNT(*) as count
|
|
125
|
+
FROM memory_scope_bindings
|
|
126
|
+
WHERE memory_id = ?
|
|
127
|
+
`)
|
|
128
|
+
.get(memoryId);
|
|
129
|
+
const count = bindingCount.count;
|
|
130
|
+
if (count === 0) {
|
|
131
|
+
return options.includeLegacyUnscoped === true;
|
|
132
|
+
}
|
|
133
|
+
if (scopeIds.length === 0) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
const placeholders = scopeIds.map(() => '?').join(', ');
|
|
137
|
+
const row = adapter
|
|
138
|
+
.prepare(`
|
|
139
|
+
SELECT 1 as visible
|
|
140
|
+
FROM memory_scope_bindings
|
|
141
|
+
WHERE memory_id = ? AND scope_id IN (${placeholders})
|
|
142
|
+
LIMIT 1
|
|
143
|
+
`)
|
|
144
|
+
.get(memoryId, ...scopeIds);
|
|
145
|
+
return row?.visible === 1;
|
|
146
|
+
}
|
|
147
|
+
function resolveMemoryScopeId(kind, externalId) {
|
|
148
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
149
|
+
const row = adapter
|
|
150
|
+
.prepare(`
|
|
151
|
+
SELECT id
|
|
152
|
+
FROM memory_scopes
|
|
153
|
+
WHERE kind = ? AND external_id = ?
|
|
154
|
+
LIMIT 1
|
|
155
|
+
`)
|
|
156
|
+
.get(kind, externalId);
|
|
157
|
+
return row?.id ?? null;
|
|
158
|
+
}
|
|
159
|
+
function normalizeLimit(limit) {
|
|
160
|
+
if (!Number.isFinite(limit)) {
|
|
161
|
+
return 50;
|
|
162
|
+
}
|
|
163
|
+
return Math.max(1, Math.min(200, Math.floor(limit)));
|
|
164
|
+
}
|
|
165
|
+
function parseStringArray(value) {
|
|
166
|
+
if (!value) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const parsed = JSON.parse(value);
|
|
171
|
+
return Array.isArray(parsed)
|
|
172
|
+
? parsed.filter((item) => typeof item === 'string')
|
|
173
|
+
: [];
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function parseObject(value) {
|
|
180
|
+
if (!value) {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const parsed = JSON.parse(value);
|
|
185
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
186
|
+
? parsed
|
|
187
|
+
: {};
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return {};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=provenance-query.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MemoryEventRecord, MemoryWriteProvenance, PublicIngestConversationInput, PublicIngestMemoryInput, PublicSaveMemoryInput } from './types.js';
|
|
2
|
+
export interface TrustedProvenanceCapability {
|
|
3
|
+
readonly __trustedProvenanceCapability: 'mama-core';
|
|
4
|
+
}
|
|
5
|
+
export interface TrustedMemoryWriteOptions {
|
|
6
|
+
provenance: MemoryWriteProvenance;
|
|
7
|
+
capability: TrustedProvenanceCapability;
|
|
8
|
+
}
|
|
9
|
+
export interface NormalizedMemoryProvenance {
|
|
10
|
+
actor: MemoryEventRecord['actor'];
|
|
11
|
+
agent_id: string | null;
|
|
12
|
+
model_run_id: string | null;
|
|
13
|
+
envelope_hash: string | null;
|
|
14
|
+
tool_name: string | null;
|
|
15
|
+
gateway_call_id: string | null;
|
|
16
|
+
source_turn_id: string | null;
|
|
17
|
+
source_message_ref: string | null;
|
|
18
|
+
source_refs: string[];
|
|
19
|
+
provenance: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export declare function createTrustedProvenanceCapability(): TrustedProvenanceCapability;
|
|
22
|
+
export declare function assertTrustedProvenanceCapability(capability: TrustedProvenanceCapability | undefined): asserts capability is TrustedProvenanceCapability;
|
|
23
|
+
export declare function stripCallerProvenance<T extends Record<string, unknown>>(input: T): T;
|
|
24
|
+
export declare function sanitizePublicSaveMemoryInput(input: PublicSaveMemoryInput): PublicSaveMemoryInput;
|
|
25
|
+
export declare function sanitizePublicIngestMemoryInput(input: PublicIngestMemoryInput): PublicIngestMemoryInput;
|
|
26
|
+
export declare function sanitizePublicIngestConversationInput(input: PublicIngestConversationInput): PublicIngestConversationInput;
|
|
27
|
+
export declare function normalizeMemoryWriteProvenance(options?: TrustedMemoryWriteOptions): NormalizedMemoryProvenance;
|
|
28
|
+
export declare function appendProvenanceSourceRefs(options: TrustedMemoryWriteOptions | undefined, refs: string[]): TrustedMemoryWriteOptions | undefined;
|
|
29
|
+
//# sourceMappingURL=provenance.d.ts.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTrustedProvenanceCapability = createTrustedProvenanceCapability;
|
|
4
|
+
exports.assertTrustedProvenanceCapability = assertTrustedProvenanceCapability;
|
|
5
|
+
exports.stripCallerProvenance = stripCallerProvenance;
|
|
6
|
+
exports.sanitizePublicSaveMemoryInput = sanitizePublicSaveMemoryInput;
|
|
7
|
+
exports.sanitizePublicIngestMemoryInput = sanitizePublicIngestMemoryInput;
|
|
8
|
+
exports.sanitizePublicIngestConversationInput = sanitizePublicIngestConversationInput;
|
|
9
|
+
exports.normalizeMemoryWriteProvenance = normalizeMemoryWriteProvenance;
|
|
10
|
+
exports.appendProvenanceSourceRefs = appendProvenanceSourceRefs;
|
|
11
|
+
const issuedCapabilities = new WeakSet();
|
|
12
|
+
const ALLOWED_PROVENANCE_FIELDS = new Set([
|
|
13
|
+
'actor',
|
|
14
|
+
'agent_id',
|
|
15
|
+
'model_run_id',
|
|
16
|
+
'envelope_hash',
|
|
17
|
+
'tool_name',
|
|
18
|
+
'gateway_call_id',
|
|
19
|
+
'source_turn_id',
|
|
20
|
+
'source_message_ref',
|
|
21
|
+
'source_refs',
|
|
22
|
+
]);
|
|
23
|
+
function createTrustedProvenanceCapability() {
|
|
24
|
+
const capability = Object.freeze({
|
|
25
|
+
__trustedProvenanceCapability: 'mama-core',
|
|
26
|
+
});
|
|
27
|
+
issuedCapabilities.add(capability);
|
|
28
|
+
return capability;
|
|
29
|
+
}
|
|
30
|
+
function assertTrustedProvenanceCapability(capability) {
|
|
31
|
+
if (!capability || typeof capability !== 'object' || !issuedCapabilities.has(capability)) {
|
|
32
|
+
throw new Error('Invalid trusted provenance capability');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function stripCallerProvenance(input) {
|
|
36
|
+
if (!Object.prototype.hasOwnProperty.call(input, 'provenance')) {
|
|
37
|
+
return input;
|
|
38
|
+
}
|
|
39
|
+
const { provenance: _provenance, ...rest } = input;
|
|
40
|
+
return rest;
|
|
41
|
+
}
|
|
42
|
+
function sanitizePublicSaveMemoryInput(input) {
|
|
43
|
+
return stripCallerProvenance(input);
|
|
44
|
+
}
|
|
45
|
+
function sanitizePublicIngestMemoryInput(input) {
|
|
46
|
+
return stripCallerProvenance(input);
|
|
47
|
+
}
|
|
48
|
+
function sanitizePublicIngestConversationInput(input) {
|
|
49
|
+
return stripCallerProvenance(input);
|
|
50
|
+
}
|
|
51
|
+
function normalizeMemoryWriteProvenance(options) {
|
|
52
|
+
if (!options) {
|
|
53
|
+
return buildFallbackProvenance();
|
|
54
|
+
}
|
|
55
|
+
assertTrustedProvenanceCapability(options.capability);
|
|
56
|
+
const provenance = options.provenance ?? {};
|
|
57
|
+
const actor = provenance.actor ?? 'main_agent';
|
|
58
|
+
const sourceRefs = normalizeStringArray(provenance.source_refs);
|
|
59
|
+
const compact = {
|
|
60
|
+
actor,
|
|
61
|
+
};
|
|
62
|
+
for (const [key, value] of Object.entries(provenance)) {
|
|
63
|
+
if (!ALLOWED_PROVENANCE_FIELDS.has(key)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (key === 'source_refs') {
|
|
67
|
+
compact.source_refs = sourceRefs;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (isCompactValue(value)) {
|
|
71
|
+
compact[key] = value;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
actor,
|
|
76
|
+
agent_id: normalizeNullableString(provenance.agent_id),
|
|
77
|
+
model_run_id: normalizeNullableString(provenance.model_run_id),
|
|
78
|
+
envelope_hash: normalizeNullableString(provenance.envelope_hash),
|
|
79
|
+
tool_name: normalizeNullableString(provenance.tool_name),
|
|
80
|
+
gateway_call_id: normalizeNullableString(provenance.gateway_call_id),
|
|
81
|
+
source_turn_id: normalizeNullableString(provenance.source_turn_id),
|
|
82
|
+
source_message_ref: normalizeNullableString(provenance.source_message_ref),
|
|
83
|
+
source_refs: sourceRefs,
|
|
84
|
+
provenance: compact,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function appendProvenanceSourceRefs(options, refs) {
|
|
88
|
+
if (!options) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
assertTrustedProvenanceCapability(options.capability);
|
|
92
|
+
return {
|
|
93
|
+
capability: options.capability,
|
|
94
|
+
provenance: {
|
|
95
|
+
...options.provenance,
|
|
96
|
+
source_refs: [...(options.provenance.source_refs ?? []), ...refs],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function buildFallbackProvenance() {
|
|
101
|
+
const actor = 'actor:direct_client';
|
|
102
|
+
return {
|
|
103
|
+
actor,
|
|
104
|
+
agent_id: null,
|
|
105
|
+
model_run_id: null,
|
|
106
|
+
envelope_hash: null,
|
|
107
|
+
tool_name: null,
|
|
108
|
+
gateway_call_id: null,
|
|
109
|
+
source_turn_id: null,
|
|
110
|
+
source_message_ref: null,
|
|
111
|
+
source_refs: [],
|
|
112
|
+
provenance: {
|
|
113
|
+
actor,
|
|
114
|
+
source_type: 'direct_client',
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function normalizeNullableString(value) {
|
|
119
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
120
|
+
}
|
|
121
|
+
function normalizeStringArray(value) {
|
|
122
|
+
if (!Array.isArray(value)) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
return value.filter((item) => typeof item === 'string' && item.length > 0);
|
|
126
|
+
}
|
|
127
|
+
function isCompactValue(value) {
|
|
128
|
+
if (value === null) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (['string', 'number', 'boolean'].includes(typeof value)) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=provenance.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DatabaseAdapter } from '../db-manager.js';
|
|
2
|
+
export interface BackfillResult {
|
|
3
|
+
scanned: number;
|
|
4
|
+
updated: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ConnectorEventScopeBackfillInput {
|
|
7
|
+
source_connector?: string;
|
|
8
|
+
source_id?: string;
|
|
9
|
+
source_cursor?: string;
|
|
10
|
+
tenant_id?: string;
|
|
11
|
+
project_id?: string;
|
|
12
|
+
memory_scope_kind?: string;
|
|
13
|
+
memory_scope_id?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function backfillLegacyMemoryProvenance(adapter?: DatabaseAdapter | null): Promise<BackfillResult>;
|
|
16
|
+
export declare function backfillConnectorEventScopeMetadata(input: ConnectorEventScopeBackfillInput, adapter?: DatabaseAdapter | null): Promise<BackfillResult>;
|
|
17
|
+
//# sourceMappingURL=scope-backfill.d.ts.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.backfillLegacyMemoryProvenance = backfillLegacyMemoryProvenance;
|
|
4
|
+
exports.backfillConnectorEventScopeMetadata = backfillConnectorEventScopeMetadata;
|
|
5
|
+
const db_manager_js_1 = require("../db-manager.js");
|
|
6
|
+
const LEGACY_PROVENANCE_JSON = JSON.stringify({
|
|
7
|
+
actor: 'actor:legacy',
|
|
8
|
+
source_type: 'legacy',
|
|
9
|
+
});
|
|
10
|
+
async function backfillLegacyMemoryProvenance(adapter = null) {
|
|
11
|
+
await (0, db_manager_js_1.initDB)();
|
|
12
|
+
const db = adapter ?? (0, db_manager_js_1.getAdapter)();
|
|
13
|
+
const row = db
|
|
14
|
+
.prepare(`
|
|
15
|
+
SELECT COUNT(*) AS count
|
|
16
|
+
FROM decisions
|
|
17
|
+
WHERE provenance_json IS NULL
|
|
18
|
+
`)
|
|
19
|
+
.get();
|
|
20
|
+
const result = db
|
|
21
|
+
.prepare(`
|
|
22
|
+
UPDATE decisions
|
|
23
|
+
SET
|
|
24
|
+
source_refs_json = COALESCE(source_refs_json, '[]'),
|
|
25
|
+
provenance_json = ?
|
|
26
|
+
WHERE provenance_json IS NULL
|
|
27
|
+
`)
|
|
28
|
+
.run(LEGACY_PROVENANCE_JSON);
|
|
29
|
+
return {
|
|
30
|
+
scanned: row.count,
|
|
31
|
+
updated: result.changes,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function backfillConnectorEventScopeMetadata(input, adapter = null) {
|
|
35
|
+
await (0, db_manager_js_1.initDB)();
|
|
36
|
+
const db = adapter ?? (0, db_manager_js_1.getAdapter)();
|
|
37
|
+
const assignments = [];
|
|
38
|
+
const assignmentParams = [];
|
|
39
|
+
for (const column of [
|
|
40
|
+
'source_cursor',
|
|
41
|
+
'tenant_id',
|
|
42
|
+
'project_id',
|
|
43
|
+
'memory_scope_kind',
|
|
44
|
+
'memory_scope_id',
|
|
45
|
+
]) {
|
|
46
|
+
const value = input[column];
|
|
47
|
+
if (value !== undefined) {
|
|
48
|
+
assignments.push(`${column} = COALESCE(${column}, ?)`);
|
|
49
|
+
assignmentParams.push(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (assignments.length === 0) {
|
|
53
|
+
return { scanned: 0, updated: 0 };
|
|
54
|
+
}
|
|
55
|
+
const where = [];
|
|
56
|
+
const whereParams = [];
|
|
57
|
+
if (input.source_connector !== undefined) {
|
|
58
|
+
where.push('source_connector = ?');
|
|
59
|
+
whereParams.push(input.source_connector);
|
|
60
|
+
}
|
|
61
|
+
if (input.source_id !== undefined) {
|
|
62
|
+
where.push('source_id = ?');
|
|
63
|
+
whereParams.push(input.source_id);
|
|
64
|
+
}
|
|
65
|
+
const whereSql = where.length > 0 ? ` WHERE ${where.join(' AND ')}` : '';
|
|
66
|
+
const scanned = db
|
|
67
|
+
.prepare(`SELECT COUNT(*) AS count FROM connector_event_index${whereSql}`)
|
|
68
|
+
.get(...whereParams);
|
|
69
|
+
const result = db
|
|
70
|
+
.prepare(`UPDATE connector_event_index SET ${assignments.join(', ')}${whereSql}`)
|
|
71
|
+
.run(...assignmentParams, ...whereParams);
|
|
72
|
+
return {
|
|
73
|
+
scanned: scanned.count,
|
|
74
|
+
updated: result.changes,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=scope-backfill.js.map
|