@jungjaehoon/mama-core 1.6.0 → 1.7.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/db/migrations/037-create-context-packets.sql +32 -0
- package/dist/cases/wiki-page-index.js +6 -2
- package/dist/context-compile/boundary-defaults.d.ts +12 -0
- package/dist/context-compile/boundary-defaults.js +105 -0
- package/dist/context-compile/compiler-policy.d.ts +39 -0
- package/dist/context-compile/compiler-policy.js +147 -0
- package/dist/context-compile/compiler.d.ts +18 -0
- package/dist/context-compile/compiler.js +401 -0
- package/dist/context-compile/index.d.ts +9 -0
- package/dist/context-compile/index.js +25 -0
- package/dist/context-compile/packet-store.d.ts +9 -0
- package/dist/context-compile/packet-store.js +255 -0
- package/dist/context-compile/ref.d.ts +7 -0
- package/dist/context-compile/ref.js +102 -0
- package/dist/context-compile/source-readers.d.ts +69 -0
- package/dist/context-compile/source-readers.js +707 -0
- package/dist/context-compile/types.d.ts +138 -0
- package/dist/context-compile/types.js +11 -0
- package/dist/context-compile/visibility.d.ts +21 -0
- package/dist/context-compile/visibility.js +200 -0
- package/dist/db-adapter/node-sqlite-adapter.d.ts +3 -0
- package/dist/db-adapter/node-sqlite-adapter.js +76 -0
- package/dist/edges/ref-validation.js +55 -16
- package/dist/edges/types.d.ts +2 -0
- package/dist/embeddings.d.ts +3 -0
- package/dist/embeddings.js +37 -10
- package/dist/entities/store.d.ts +4 -1
- package/dist/entities/store.js +206 -78
- package/dist/entities/types.d.ts +5 -1
- package/dist/entities/types.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/memory/provenance.js +1 -0
- package/dist/memory/types.d.ts +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.insertContextPacket = insertContextPacket;
|
|
4
|
+
exports.getContextPacket = getContextPacket;
|
|
5
|
+
exports.listContextPacketsForModelRun = listContextPacketsForModelRun;
|
|
6
|
+
exports.getContextPacketForTrustedUse = getContextPacketForTrustedUse;
|
|
7
|
+
function parseJson(row, field) {
|
|
8
|
+
const value = row[field];
|
|
9
|
+
if (typeof value !== 'string') {
|
|
10
|
+
throw new Error(`Invalid context packet JSON field ${field}: expected string`);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(value);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
17
|
+
throw new Error(`Invalid context packet JSON field ${field}: ${message}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function stringField(row, field) {
|
|
21
|
+
const value = row[field];
|
|
22
|
+
if (typeof value !== 'string') {
|
|
23
|
+
throw new Error(`Invalid context packet field ${field}: expected string`);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function numberField(row, field) {
|
|
28
|
+
const value = row[field];
|
|
29
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
30
|
+
throw new Error(`Invalid context packet field ${field}: expected non-negative finite number`);
|
|
31
|
+
}
|
|
32
|
+
return Math.floor(value);
|
|
33
|
+
}
|
|
34
|
+
function mapPacketRow(row) {
|
|
35
|
+
return {
|
|
36
|
+
packet_id: stringField(row, 'packet_id'),
|
|
37
|
+
task: stringField(row, 'task'),
|
|
38
|
+
packet_json: stringField(row, 'packet_json'),
|
|
39
|
+
packet: parseJson(row, 'packet_json'),
|
|
40
|
+
scope_json: stringField(row, 'scope_json'),
|
|
41
|
+
scopes: parseJson(row, 'scope_json'),
|
|
42
|
+
scope_hash: stringField(row, 'scope_hash'),
|
|
43
|
+
envelope_hash: stringField(row, 'envelope_hash'),
|
|
44
|
+
model_run_id: stringField(row, 'model_run_id'),
|
|
45
|
+
agent_id: stringField(row, 'agent_id'),
|
|
46
|
+
input_snapshot_ref: stringField(row, 'input_snapshot_ref'),
|
|
47
|
+
source_refs_json: stringField(row, 'source_refs_json'),
|
|
48
|
+
source_refs: parseJson(row, 'source_refs_json'),
|
|
49
|
+
tenant_id: stringField(row, 'tenant_id'),
|
|
50
|
+
project_id: stringField(row, 'project_id'),
|
|
51
|
+
memory_scope_kind: stringField(row, 'memory_scope_kind'),
|
|
52
|
+
memory_scope_id: stringField(row, 'memory_scope_id'),
|
|
53
|
+
created_at: numberField(row, 'created_at'),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function normalizeJsonInput(value, field) {
|
|
57
|
+
try {
|
|
58
|
+
if (typeof value === 'string') {
|
|
59
|
+
return JSON.stringify(JSON.parse(value));
|
|
60
|
+
}
|
|
61
|
+
const serialized = JSON.stringify(value);
|
|
62
|
+
if (typeof serialized !== 'string') {
|
|
63
|
+
throw new Error('value is not JSON serializable');
|
|
64
|
+
}
|
|
65
|
+
return serialized;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
+
throw new Error(`Invalid context packet JSON field ${field}: ${message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function normalizePacketCreatedAt(value) {
|
|
73
|
+
let createdAt;
|
|
74
|
+
if (typeof value === 'number') {
|
|
75
|
+
createdAt = value;
|
|
76
|
+
}
|
|
77
|
+
else if (typeof value === 'string') {
|
|
78
|
+
const trimmed = value.trim();
|
|
79
|
+
if (trimmed.length === 0) {
|
|
80
|
+
throw new Error('Invalid context packet field created_at: expected valid timestamp');
|
|
81
|
+
}
|
|
82
|
+
const numeric = Number(trimmed);
|
|
83
|
+
createdAt = Number.isFinite(numeric) ? numeric : Date.parse(trimmed);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error('Invalid context packet field created_at: expected valid timestamp');
|
|
87
|
+
}
|
|
88
|
+
if (!Number.isFinite(createdAt) ||
|
|
89
|
+
createdAt < 0 ||
|
|
90
|
+
!Number.isFinite(new Date(createdAt).getTime())) {
|
|
91
|
+
throw new Error('Invalid context packet field created_at: expected valid timestamp');
|
|
92
|
+
}
|
|
93
|
+
return Math.floor(createdAt);
|
|
94
|
+
}
|
|
95
|
+
function modelRunsTableExists(adapter) {
|
|
96
|
+
const row = adapter
|
|
97
|
+
.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'model_runs'")
|
|
98
|
+
.get();
|
|
99
|
+
return row?.name === 'model_runs';
|
|
100
|
+
}
|
|
101
|
+
function modelRunStatus(adapter, modelRunId) {
|
|
102
|
+
if (!modelRunsTableExists(adapter)) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const row = adapter
|
|
106
|
+
.prepare('SELECT status FROM model_runs WHERE model_run_id = ?')
|
|
107
|
+
.get(modelRunId);
|
|
108
|
+
return typeof row?.status === 'string' ? row.status : null;
|
|
109
|
+
}
|
|
110
|
+
function modelRunLineageNode(adapter, modelRunId) {
|
|
111
|
+
if (!modelRunsTableExists(adapter)) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const row = adapter
|
|
115
|
+
.prepare(`
|
|
116
|
+
SELECT model_run_id, parent_model_run_id, envelope_hash
|
|
117
|
+
FROM model_runs
|
|
118
|
+
WHERE model_run_id = ?
|
|
119
|
+
`)
|
|
120
|
+
.get(modelRunId);
|
|
121
|
+
if (typeof row?.model_run_id !== 'string') {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
model_run_id: row.model_run_id,
|
|
126
|
+
parent_model_run_id: typeof row.parent_model_run_id === 'string' && row.parent_model_run_id.length > 0
|
|
127
|
+
? row.parent_model_run_id
|
|
128
|
+
: null,
|
|
129
|
+
envelope_hash: typeof row.envelope_hash === 'string' && row.envelope_hash.length > 0
|
|
130
|
+
? row.envelope_hash
|
|
131
|
+
: null,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function modelRunLineage(adapter, modelRunId) {
|
|
135
|
+
const lineage = [];
|
|
136
|
+
const seen = new Set();
|
|
137
|
+
let currentId = modelRunId;
|
|
138
|
+
while (currentId && !seen.has(currentId) && lineage.length < 1_000) {
|
|
139
|
+
seen.add(currentId);
|
|
140
|
+
const node = modelRunLineageNode(adapter, currentId);
|
|
141
|
+
if (!node) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
lineage.push(node);
|
|
145
|
+
currentId = node.parent_model_run_id;
|
|
146
|
+
}
|
|
147
|
+
return lineage;
|
|
148
|
+
}
|
|
149
|
+
function sharesTrustedModelRunLineage(adapter, packet, callerModelRunId) {
|
|
150
|
+
const packetLineage = modelRunLineage(adapter, packet.model_run_id);
|
|
151
|
+
const callerLineage = modelRunLineage(adapter, callerModelRunId);
|
|
152
|
+
if (packetLineage.length === 0 || callerLineage.length === 0) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (packetLineage.some((node) => node.envelope_hash !== packet.envelope_hash)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (callerLineage.some((node) => node.envelope_hash !== packet.envelope_hash)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
const callerAncestors = new Set(callerLineage.map((node) => node.model_run_id));
|
|
162
|
+
return packetLineage.some((node) => callerAncestors.has(node.model_run_id));
|
|
163
|
+
}
|
|
164
|
+
function assertTrustedModelRunStatus(adapter, packet, includeFailed) {
|
|
165
|
+
if (!modelRunsTableExists(adapter)) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const status = modelRunStatus(adapter, packet.model_run_id);
|
|
169
|
+
if (!status) {
|
|
170
|
+
throw new Error(`Context packet model run not found: ${packet.model_run_id}`);
|
|
171
|
+
}
|
|
172
|
+
if (status === 'committed') {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (includeFailed && status === 'failed') {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
throw new Error(`Context packet model run must be committed before trusted use: ${packet.model_run_id} (${status})`);
|
|
179
|
+
}
|
|
180
|
+
function assertTrustedModelRunLineage(adapter, packet, callerModelRunId) {
|
|
181
|
+
if (!callerModelRunId) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (packet.model_run_id === callerModelRunId) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!modelRunsTableExists(adapter)) {
|
|
188
|
+
throw new Error(`Context packet model run lineage cannot be verified: ${packet.model_run_id}`);
|
|
189
|
+
}
|
|
190
|
+
if (sharesTrustedModelRunLineage(adapter, packet, callerModelRunId)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
throw new Error(`Context packet model run lineage mismatch for ${packet.packet_id}: caller ${callerModelRunId}, packet ${packet.model_run_id}`);
|
|
194
|
+
}
|
|
195
|
+
function insertContextPacket(adapter, packet) {
|
|
196
|
+
const packetToInsert = {
|
|
197
|
+
...packet,
|
|
198
|
+
packet_json: normalizeJsonInput(packet.packet_json, 'packet_json'),
|
|
199
|
+
scope_json: normalizeJsonInput(packet.scope_json, 'scope_json'),
|
|
200
|
+
source_refs_json: normalizeJsonInput(packet.source_refs_json, 'source_refs_json'),
|
|
201
|
+
created_at: normalizePacketCreatedAt(packet.created_at),
|
|
202
|
+
};
|
|
203
|
+
adapter
|
|
204
|
+
.prepare(`
|
|
205
|
+
INSERT INTO context_packets (
|
|
206
|
+
packet_id, task, packet_json, scope_json, scope_hash, envelope_hash, model_run_id,
|
|
207
|
+
agent_id, input_snapshot_ref, source_refs_json, tenant_id, project_id,
|
|
208
|
+
memory_scope_kind, memory_scope_id, created_at
|
|
209
|
+
)
|
|
210
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
211
|
+
`)
|
|
212
|
+
.run(packetToInsert.packet_id, packetToInsert.task, packetToInsert.packet_json, packetToInsert.scope_json, packetToInsert.scope_hash, packetToInsert.envelope_hash, packetToInsert.model_run_id, packetToInsert.agent_id, packetToInsert.input_snapshot_ref, packetToInsert.source_refs_json, packetToInsert.tenant_id, packetToInsert.project_id, packetToInsert.memory_scope_kind, packetToInsert.memory_scope_id, packetToInsert.created_at);
|
|
213
|
+
const inserted = adapter
|
|
214
|
+
.prepare('SELECT * FROM context_packets WHERE packet_id = ?')
|
|
215
|
+
.get(packetToInsert.packet_id);
|
|
216
|
+
if (!inserted) {
|
|
217
|
+
throw new Error(`Context packet insert failed: ${packetToInsert.packet_id}`);
|
|
218
|
+
}
|
|
219
|
+
return mapPacketRow(inserted);
|
|
220
|
+
}
|
|
221
|
+
function getContextPacket(adapter, packetId) {
|
|
222
|
+
const row = adapter.prepare('SELECT * FROM context_packets WHERE packet_id = ?').get(packetId);
|
|
223
|
+
return row ? mapPacketRow(row) : null;
|
|
224
|
+
}
|
|
225
|
+
function listContextPacketsForModelRun(adapter, modelRunId, limit = 50) {
|
|
226
|
+
if (!Number.isFinite(limit) || limit <= 0) {
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
const rows = adapter
|
|
230
|
+
.prepare(`
|
|
231
|
+
SELECT *
|
|
232
|
+
FROM context_packets
|
|
233
|
+
WHERE model_run_id = ?
|
|
234
|
+
ORDER BY created_at DESC, packet_id DESC
|
|
235
|
+
LIMIT ?
|
|
236
|
+
`)
|
|
237
|
+
.all(modelRunId, Math.floor(limit));
|
|
238
|
+
return rows.map((row) => mapPacketRow(row));
|
|
239
|
+
}
|
|
240
|
+
function getContextPacketForTrustedUse(adapter, input) {
|
|
241
|
+
const packet = getContextPacket(adapter, input.packetId);
|
|
242
|
+
if (!packet) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
if (packet.envelope_hash !== input.envelopeHash) {
|
|
246
|
+
throw new Error(`Context packet envelope mismatch for ${input.packetId}: expected ${input.envelopeHash}, got ${packet.envelope_hash}`);
|
|
247
|
+
}
|
|
248
|
+
if (input.modelRunId && packet.model_run_id !== input.modelRunId) {
|
|
249
|
+
throw new Error(`Context packet model run mismatch for ${input.packetId}: expected ${input.modelRunId}, got ${packet.model_run_id}`);
|
|
250
|
+
}
|
|
251
|
+
assertTrustedModelRunLineage(adapter, packet, input.callerModelRunId);
|
|
252
|
+
assertTrustedModelRunStatus(adapter, packet, input.includeFailed === true);
|
|
253
|
+
return packet;
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=packet-store.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TwinRef } from '../edges/types.js';
|
|
2
|
+
import type { ContextRef } from './types.js';
|
|
3
|
+
export declare function normalizeContextRef(input: unknown): ContextRef;
|
|
4
|
+
export declare function normalizeContextRefs(refs: readonly unknown[] | undefined): ContextRef[];
|
|
5
|
+
export declare function serializeContextRefForProvenance(ref: ContextRef): string;
|
|
6
|
+
export declare function toTwinRef(ref: ContextRef): TwinRef;
|
|
7
|
+
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeContextRef = normalizeContextRef;
|
|
4
|
+
exports.normalizeContextRefs = normalizeContextRefs;
|
|
5
|
+
exports.serializeContextRefForProvenance = serializeContextRefForProvenance;
|
|
6
|
+
exports.toTwinRef = toTwinRef;
|
|
7
|
+
const SUPPORTED_KINDS = new Set(['memory', 'raw', 'entity', 'case']);
|
|
8
|
+
const UNSUPPORTED_KINDS = new Set(['decision', 'wiki_page', 'context_packet', 'report']);
|
|
9
|
+
function asRecord(value) {
|
|
10
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
11
|
+
throw new Error('Context ref must be an object with a kind field');
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function requiredString(value, field) {
|
|
16
|
+
if (typeof value !== 'string') {
|
|
17
|
+
throw new Error(`Context ref ${field} must be a string`);
|
|
18
|
+
}
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (trimmed.length === 0) {
|
|
21
|
+
throw new Error(`Context ref ${field} must not be empty`);
|
|
22
|
+
}
|
|
23
|
+
return trimmed;
|
|
24
|
+
}
|
|
25
|
+
function optionalString(value, field) {
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (typeof value !== 'string') {
|
|
30
|
+
throw new Error(`Context ref ${field} must be a string`);
|
|
31
|
+
}
|
|
32
|
+
const trimmed = value.trim();
|
|
33
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
34
|
+
}
|
|
35
|
+
function optionalNullableString(value, field) {
|
|
36
|
+
if (value === null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return optionalString(value, field);
|
|
40
|
+
}
|
|
41
|
+
function normalizeContextRef(input) {
|
|
42
|
+
const record = asRecord(input);
|
|
43
|
+
const kind = record.kind;
|
|
44
|
+
if (typeof kind !== 'string') {
|
|
45
|
+
throw new Error('Context ref kind must be a string');
|
|
46
|
+
}
|
|
47
|
+
if (UNSUPPORTED_KINDS.has(kind) || !SUPPORTED_KINDS.has(kind)) {
|
|
48
|
+
throw new Error(`Unsupported V0 context ref kind: ${kind}`);
|
|
49
|
+
}
|
|
50
|
+
switch (kind) {
|
|
51
|
+
case 'raw': {
|
|
52
|
+
const normalized = {
|
|
53
|
+
kind,
|
|
54
|
+
raw_id: requiredString(record.raw_id, 'raw_id'),
|
|
55
|
+
connector: requiredString(record.connector, 'connector'),
|
|
56
|
+
};
|
|
57
|
+
const sourceId = optionalString(record.source_id, 'source_id');
|
|
58
|
+
const channelId = optionalNullableString(record.channel_id, 'channel_id');
|
|
59
|
+
if (sourceId !== undefined) {
|
|
60
|
+
normalized.source_id = sourceId;
|
|
61
|
+
}
|
|
62
|
+
if (channelId !== undefined) {
|
|
63
|
+
normalized.channel_id = channelId;
|
|
64
|
+
}
|
|
65
|
+
return normalized;
|
|
66
|
+
}
|
|
67
|
+
case 'memory':
|
|
68
|
+
case 'entity':
|
|
69
|
+
case 'case':
|
|
70
|
+
return {
|
|
71
|
+
kind,
|
|
72
|
+
id: requiredString(record.id, 'id'),
|
|
73
|
+
};
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(`Unsupported V0 context ref kind: ${kind}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function normalizeContextRefs(refs) {
|
|
79
|
+
if (!Array.isArray(refs)) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
return refs.map((ref) => normalizeContextRef(ref));
|
|
83
|
+
}
|
|
84
|
+
function serializeContextRefForProvenance(ref) {
|
|
85
|
+
if (ref.kind === 'raw') {
|
|
86
|
+
return `raw:${ref.connector}:${ref.raw_id}`;
|
|
87
|
+
}
|
|
88
|
+
return `${ref.kind}:${ref.id}`;
|
|
89
|
+
}
|
|
90
|
+
function toTwinRef(ref) {
|
|
91
|
+
if (ref.kind === 'raw') {
|
|
92
|
+
return {
|
|
93
|
+
kind: 'raw',
|
|
94
|
+
id: ref.raw_id,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
kind: ref.kind,
|
|
99
|
+
id: ref.id,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=ref.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DatabaseAdapter } from '../db-manager.js';
|
|
2
|
+
import type { ListVisibleTwinEdgesOptions, TwinEdgeRecord, TwinRef } from '../edges/types.js';
|
|
3
|
+
import type { RecallBundle, RecallMemoryOptions } from '../memory/types.js';
|
|
4
|
+
import type { SearchHitDiagnostics, SearchStrictness } from '../search/search-quality.js';
|
|
5
|
+
import type { ContextBoundary, ContextProjectRef, ContextRange, ContextRef } from './types.js';
|
|
6
|
+
import type { MemoryScopeRef } from '../memory/types.js';
|
|
7
|
+
type ContextSourceAdapter = Pick<DatabaseAdapter, 'prepare'>;
|
|
8
|
+
export type ContextCandidateSource = 'memory' | 'raw' | 'graph';
|
|
9
|
+
export type ContextCandidateKind = ContextRef['kind'];
|
|
10
|
+
export interface ContextCandidateSupport {
|
|
11
|
+
retrieval_source?: string;
|
|
12
|
+
lexical_support?: boolean;
|
|
13
|
+
entity_support?: boolean;
|
|
14
|
+
scope_support?: boolean;
|
|
15
|
+
graph_source?: 'primary' | 'expanded' | null;
|
|
16
|
+
graph_expanded?: boolean;
|
|
17
|
+
is_vector_only?: boolean;
|
|
18
|
+
vector_similarity?: number | null;
|
|
19
|
+
confirmation_signals: string[];
|
|
20
|
+
metadata_signals: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface ContextCandidate {
|
|
23
|
+
ref: ContextRef;
|
|
24
|
+
title: string;
|
|
25
|
+
excerpt: string;
|
|
26
|
+
score: number;
|
|
27
|
+
timestamp_ms: number | null;
|
|
28
|
+
source: ContextCandidateSource;
|
|
29
|
+
visible: boolean;
|
|
30
|
+
hidden_reason?: string;
|
|
31
|
+
support: ContextCandidateSupport;
|
|
32
|
+
retrieval_diagnostics?: SearchHitDiagnostics;
|
|
33
|
+
edge_id?: string;
|
|
34
|
+
edge_type?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface HiddenCandidateAggregate {
|
|
37
|
+
total: number;
|
|
38
|
+
by_kind: Partial<Record<ContextCandidateKind, number>>;
|
|
39
|
+
by_reason: Record<string, number>;
|
|
40
|
+
}
|
|
41
|
+
export interface ContextSourceReadResult {
|
|
42
|
+
candidates: ContextCandidate[];
|
|
43
|
+
hidden: HiddenCandidateAggregate;
|
|
44
|
+
source_refs: ContextRef[];
|
|
45
|
+
}
|
|
46
|
+
export interface ContextSourceReadInput {
|
|
47
|
+
task: string;
|
|
48
|
+
scopes?: MemoryScopeRef[];
|
|
49
|
+
connectors?: string[];
|
|
50
|
+
project_refs?: ContextProjectRef[];
|
|
51
|
+
tenant_id?: string | null;
|
|
52
|
+
boundary?: ContextBoundary;
|
|
53
|
+
range?: ContextRange;
|
|
54
|
+
as_of?: string | number | null;
|
|
55
|
+
limit?: number;
|
|
56
|
+
threshold?: number;
|
|
57
|
+
strictness?: SearchStrictness;
|
|
58
|
+
}
|
|
59
|
+
export interface ContextSourceReaderDeps {
|
|
60
|
+
adapter?: ContextSourceAdapter;
|
|
61
|
+
recallMemory?: (query: string, options?: RecallMemoryOptions) => Promise<RecallBundle>;
|
|
62
|
+
listVisibleTwinEdgesForRefs?: (adapter: ContextSourceAdapter, refs: readonly TwinRef[], options?: ListVisibleTwinEdgesOptions) => TwinEdgeRecord[];
|
|
63
|
+
}
|
|
64
|
+
export declare function sourceRefsFromCandidates(candidates: readonly ContextCandidate[]): ContextRef[];
|
|
65
|
+
export declare function readMemoryCandidates(input: ContextSourceReadInput, deps?: ContextSourceReaderDeps): Promise<ContextSourceReadResult>;
|
|
66
|
+
export declare function readRawCandidates(adapter: ContextSourceAdapter, input: ContextSourceReadInput): ContextSourceReadResult;
|
|
67
|
+
export declare function readGraphCandidates(adapter: ContextSourceAdapter, input: ContextSourceReadInput, visibleRefs: readonly ContextRef[], deps?: ContextSourceReaderDeps): ContextSourceReadResult;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=source-readers.d.ts.map
|