@remnic/core 9.3.735 → 9.3.737
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/dist/access-boundary.d.ts +17 -6
- package/dist/access-cli.js +1 -1
- package/dist/access-http.d.ts +17 -6
- package/dist/access-mcp.d.ts +17 -6
- package/dist/access-operations.d.ts +17 -6
- package/dist/access-schema.d.ts +4 -4
- package/dist/{access-service-CVx7mmvK.d.ts → access-service-DwQ6BIQw.d.ts} +3 -3
- package/dist/access-service.d.ts +16 -5
- package/dist/access-surface-catalog.d.ts +17 -6
- package/dist/action-confidence.d.ts +1 -1
- package/dist/active-memory-bridge.d.ts +1 -1
- package/dist/active-recall.d.ts +1 -1
- package/dist/behavior-learner.d.ts +1 -1
- package/dist/behavior-signals.d.ts +1 -1
- package/dist/bootstrap.d.ts +16 -4
- package/dist/briefing.d.ts +1 -1
- package/dist/buffer-surprise-report.d.ts +1 -1
- package/dist/buffer.d.ts +1 -1
- package/dist/calibration.d.ts +1 -1
- package/dist/capabilities.d.ts +1 -1
- package/dist/{catalog-BVhDEUhT.d.ts → catalog-_Bap6vfD.d.ts} +1 -1
- package/dist/causal-behavior.d.ts +1 -1
- package/dist/causal-consolidation.d.ts +1 -1
- package/dist/causal-trajectory-graph.d.ts +1 -1
- package/dist/{chunk-FLCYY5JX.js → chunk-PB5YON2G.js} +559 -481
- package/dist/chunk-PB5YON2G.js.map +1 -0
- package/dist/{cli-Cx5Mxwk7.d.ts → cli-BlEIWDQw.d.ts} +3 -3
- package/dist/cli.d.ts +9 -7
- package/dist/compounding/engine.d.ts +1 -1
- package/dist/compounding/preference-consolidator.d.ts +1 -1
- package/dist/compression-optimizer.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/connectors/codex-materialize-runner.d.ts +1 -1
- package/dist/connectors/codex-materialize.d.ts +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/consolidation-provenance-check.d.ts +1 -1
- package/dist/consolidation-undo.d.ts +1 -1
- package/dist/contradiction/index.d.ts +1 -1
- package/dist/conversation-index/backend.d.ts +1 -1
- package/dist/conversation-index/chunker.d.ts +1 -1
- package/dist/conversation-index/faiss-adapter.d.ts +1 -1
- package/dist/conversation-index/indexer.d.ts +1 -1
- package/dist/conversation-index/search.d.ts +1 -1
- package/dist/day-summary.d.ts +1 -1
- package/dist/delinearize.d.ts +1 -1
- package/dist/direct-answer-wiring.d.ts +1 -1
- package/dist/direct-answer.d.ts +1 -1
- package/dist/embedding-fallback.d.ts +1 -1
- package/dist/enrichment/index.d.ts +1 -1
- package/dist/entity-retrieval.d.ts +1 -1
- package/dist/entity-schema.d.ts +1 -1
- package/dist/explicit-capture.d.ts +16 -4
- package/dist/extraction-faithfulness.d.ts +1 -1
- package/dist/extraction-judge-telemetry.d.ts +1 -1
- package/dist/extraction-judge-training.d.ts +1 -1
- package/dist/extraction-judge.d.ts +1 -1
- package/dist/extraction.d.ts +1 -1
- package/dist/fallback-llm.d.ts +1 -1
- package/dist/graph-dashboard-diff.d.ts +1 -1
- package/dist/graph-dashboard-key.d.ts +1 -1
- package/dist/graph-dashboard-parser.d.ts +1 -1
- package/dist/graph-edge-reinforcement.d.ts +1 -1
- package/dist/graph-snapshot.d.ts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/identity-continuity.d.ts +1 -1
- package/dist/importance.d.ts +1 -1
- package/dist/index.d.ts +20 -18
- package/dist/index.js +1 -1
- package/dist/intent.d.ts +1 -1
- package/dist/lcm/engine.d.ts +1 -1
- package/dist/lcm/index.d.ts +1 -1
- package/dist/lcm/tools.d.ts +1 -1
- package/dist/lifecycle.d.ts +1 -1
- package/dist/live-connectors-runner.d.ts +1 -1
- package/dist/local-llm.d.ts +1 -1
- package/dist/local-model-endpoint.d.ts +1 -1
- package/dist/maintenance/memory-governance.d.ts +1 -1
- package/dist/mcp-memory-inspector-app.d.ts +17 -6
- package/dist/memory-action-policy.d.ts +1 -1
- package/dist/memory-cache.d.ts +1 -1
- package/dist/memory-lifecycle-ledger-utils.d.ts +1 -1
- package/dist/memory-projection-store.d.ts +1 -1
- package/dist/memory-provenance.d.ts +1 -1
- package/dist/memory-worth-outcomes.d.ts +1 -1
- package/dist/models-json.d.ts +1 -1
- package/dist/namespaces/migrate.d.ts +2 -2
- package/dist/namespaces/principal.d.ts +1 -1
- package/dist/namespaces/search.d.ts +1 -1
- package/dist/namespaces/storage.d.ts +2 -2
- package/dist/native-knowledge.d.ts +1 -1
- package/dist/operator-toolkit.d.ts +1 -1
- package/dist/orchestration/compression-guideline-coordinator.d.ts +1 -1
- package/dist/orchestration/maintenance.d.ts +2 -2
- package/dist/{orchestrator-oF0cceBX.d.ts → orchestrator-CJZ21ZiB.d.ts} +139 -14
- package/dist/orchestrator.d.ts +16 -4
- package/dist/orchestrator.js +1 -3
- package/dist/patterns-cli.d.ts +1 -1
- package/dist/policy-runtime.d.ts +1 -1
- package/dist/provenance.d.ts +1 -1
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd.d.ts +1 -1
- package/dist/recall-disclosure-escalation.d.ts +1 -1
- package/dist/recall-explain-renderer.d.ts +1 -1
- package/dist/recall-planner-llm.d.ts +1 -1
- package/dist/recall-state.d.ts +1 -1
- package/dist/recall-tag-filter.d.ts +1 -1
- package/dist/recall-xray-cli.d.ts +1 -1
- package/dist/recall-xray-renderer.d.ts +1 -1
- package/dist/recall-xray.d.ts +1 -1
- package/dist/resolve-auth-token.d.ts +1 -1
- package/dist/retrieval-agents.d.ts +1 -1
- package/dist/retrieval-tiers.d.ts +1 -1
- package/dist/routing/engine.d.ts +1 -1
- package/dist/routing/store.d.ts +1 -1
- package/dist/schemas.d.ts +24 -24
- package/dist/search/embed-helper.d.ts +1 -1
- package/dist/search/factory.d.ts +1 -1
- package/dist/search/index.d.ts +1 -1
- package/dist/search/lancedb-backend.d.ts +1 -1
- package/dist/search/meilisearch-backend.d.ts +1 -1
- package/dist/search/noop-backend.d.ts +1 -1
- package/dist/search/orama-backend.d.ts +1 -1
- package/dist/search/port.d.ts +1 -1
- package/dist/search/remote-backend.d.ts +1 -1
- package/dist/{semantic-consolidation-DKGbufYO.d.ts → semantic-consolidation-DsIEiCka.d.ts} +1 -1
- package/dist/semantic-consolidation.d.ts +2 -2
- package/dist/semantic-rule-verifier.d.ts +1 -1
- package/dist/session-observer-bands.d.ts +1 -1
- package/dist/session-observer-state.d.ts +1 -1
- package/dist/shared-context/manager.d.ts +3 -3
- package/dist/signal.d.ts +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/summarizer.d.ts +1 -1
- package/dist/summary-snapshot.d.ts +1 -1
- package/dist/temporal-supersession.d.ts +1 -1
- package/dist/temporal-validity.d.ts +1 -1
- package/dist/threading.d.ts +1 -1
- package/dist/tier-migration.d.ts +1 -1
- package/dist/tier-routing.d.ts +1 -1
- package/dist/topics.d.ts +1 -1
- package/dist/transcript.d.ts +1 -1
- package/dist/transfer/types.d.ts +42 -42
- package/dist/trust-score-stage.d.ts +2 -2
- package/dist/trust-score.d.ts +1 -1
- package/dist/{types-C7UCxpuO.d.ts → types-CglNn2V-.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utility-runtime.d.ts +1 -1
- package/package.json +2 -2
- package/src/orchestration/entity-synthesis-coordinator.ts +319 -0
- package/src/orchestration/recall-result-formatter.ts +438 -0
- package/src/orchestrator.ts +34 -540
- package/dist/chunk-FLCYY5JX.js.map +0 -1
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity synthesis coordinator — extracted from the orchestrator (issue #1526).
|
|
3
|
+
*
|
|
4
|
+
* Owns the entity-synthesis lifecycle: processing the queued entities whose
|
|
5
|
+
* evidence has changed since their last synthesis, gathering timeline +
|
|
6
|
+
* structured-section evidence, deduplicating it, batch-feeding it through the
|
|
7
|
+
* fast-tier LLM to produce a compact "current truth" synthesis, and persisting
|
|
8
|
+
* the result with drift/bookkeeping metadata.
|
|
9
|
+
*
|
|
10
|
+
* Moved here (behavior-preserving):
|
|
11
|
+
* - module-level helpers `dedupeEntitySynthesisEvidenceEntries`,
|
|
12
|
+
* `flattenStructuredSectionEvidence`, `fingerprintEntitySynthesisEvidence`
|
|
13
|
+
* - the orchestrator method `processEntitySynthesisQueue`
|
|
14
|
+
*
|
|
15
|
+
* The orchestrator constructs one instance and delegates the public entrypoint
|
|
16
|
+
* to it. Storage is resolved per-call via the injected accessor so namespace-
|
|
17
|
+
* scoped and default-namespace calls share one coordinator.
|
|
18
|
+
*
|
|
19
|
+
* Behavior-preserving move from orchestrator.ts. No logic changes — the
|
|
20
|
+
* orchestrator keeps a thin delegating `processEntitySynthesisQueue` so
|
|
21
|
+
* existing call sites (consolidation pass, access-service) and tests that
|
|
22
|
+
* exercise the public API continue to work.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { createHash } from "node:crypto";
|
|
26
|
+
|
|
27
|
+
import type { StorageManager } from "../index.js";
|
|
28
|
+
import {
|
|
29
|
+
compareEntityTimestamps,
|
|
30
|
+
fingerprintEntityStructuredFacts,
|
|
31
|
+
parseEntityFile,
|
|
32
|
+
} from "../storage.js";
|
|
33
|
+
import type {
|
|
34
|
+
EntityStructuredSection,
|
|
35
|
+
EntityTimelineEntry,
|
|
36
|
+
PluginConfig,
|
|
37
|
+
} from "../types.js";
|
|
38
|
+
import { log } from "../logger.js";
|
|
39
|
+
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Evidence helpers (moved verbatim from orchestrator.ts module scope)
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Deduplicate synthesis-evidence entries by normalized text, keeping the
|
|
46
|
+
* newest and oldest timestamp per unique fact when they differ.
|
|
47
|
+
*/
|
|
48
|
+
export function dedupeEntitySynthesisEvidenceEntries(
|
|
49
|
+
entries: EntityTimelineEntry[],
|
|
50
|
+
): EntityTimelineEntry[] {
|
|
51
|
+
const dedupedEvidenceEntries: EntityTimelineEntry[] = [];
|
|
52
|
+
const evidenceByFact = new Map<string, {
|
|
53
|
+
newest: EntityTimelineEntry;
|
|
54
|
+
oldest: EntityTimelineEntry;
|
|
55
|
+
}>();
|
|
56
|
+
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
const normalizedFact = entry.text.trim();
|
|
59
|
+
if (!normalizedFact) continue;
|
|
60
|
+
const existing = evidenceByFact.get(normalizedFact);
|
|
61
|
+
if (!existing) {
|
|
62
|
+
evidenceByFact.set(normalizedFact, { newest: entry, oldest: entry });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (compareEntityTimestamps(entry.timestamp, existing.newest.timestamp) > 0) {
|
|
66
|
+
existing.newest = entry;
|
|
67
|
+
}
|
|
68
|
+
if (compareEntityTimestamps(entry.timestamp, existing.oldest.timestamp) < 0) {
|
|
69
|
+
existing.oldest = entry;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const { newest, oldest } of evidenceByFact.values()) {
|
|
74
|
+
dedupedEvidenceEntries.push(newest);
|
|
75
|
+
const newestKey = [
|
|
76
|
+
newest.timestamp,
|
|
77
|
+
newest.source ?? "",
|
|
78
|
+
newest.sessionKey ?? "",
|
|
79
|
+
newest.principal ?? "",
|
|
80
|
+
newest.text,
|
|
81
|
+
].join("\u0000");
|
|
82
|
+
const oldestKey = [
|
|
83
|
+
oldest.timestamp,
|
|
84
|
+
oldest.source ?? "",
|
|
85
|
+
oldest.sessionKey ?? "",
|
|
86
|
+
oldest.principal ?? "",
|
|
87
|
+
oldest.text,
|
|
88
|
+
].join("\u0000");
|
|
89
|
+
if (oldestKey !== newestKey) {
|
|
90
|
+
dedupedEvidenceEntries.push(oldest);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return dedupedEvidenceEntries;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function flattenStructuredSectionEvidence(
|
|
98
|
+
sections: EntityStructuredSection[] | undefined,
|
|
99
|
+
): EntityTimelineEntry[] {
|
|
100
|
+
return (sections ?? []).flatMap((section) =>
|
|
101
|
+
section.facts
|
|
102
|
+
.map((fact) => fact.trim())
|
|
103
|
+
.filter((fact) => fact.length > 0)
|
|
104
|
+
.map((fact) => ({
|
|
105
|
+
timestamp: "",
|
|
106
|
+
text: fact,
|
|
107
|
+
source: `section:${section.title}`,
|
|
108
|
+
})),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function fingerprintEntitySynthesisEvidence(entity: {
|
|
113
|
+
timeline: EntityTimelineEntry[];
|
|
114
|
+
structuredSections?: EntityStructuredSection[];
|
|
115
|
+
}): string {
|
|
116
|
+
const fingerprint = createHash("sha256");
|
|
117
|
+
const timelineEntries = entity.timeline
|
|
118
|
+
.map((entry) => [
|
|
119
|
+
entry.timestamp,
|
|
120
|
+
entry.source ?? "",
|
|
121
|
+
entry.sessionKey ?? "",
|
|
122
|
+
entry.principal ?? "",
|
|
123
|
+
entry.text,
|
|
124
|
+
].join("\u0000"))
|
|
125
|
+
.sort();
|
|
126
|
+
const timelineEntrySeparator = String.fromCharCode(1);
|
|
127
|
+
const structuredFactsSeparator = String.fromCharCode(2);
|
|
128
|
+
fingerprint.update(timelineEntries.join(timelineEntrySeparator));
|
|
129
|
+
fingerprint.update(structuredFactsSeparator);
|
|
130
|
+
fingerprint.update(fingerprintEntityStructuredFacts(entity) ?? "");
|
|
131
|
+
return fingerprint.digest("hex");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Coordinator
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
/** Dependencies injected by the orchestrator. */
|
|
139
|
+
export interface EntitySynthesisCoordinatorDeps {
|
|
140
|
+
config: PluginConfig;
|
|
141
|
+
/** Resolve the storage manager for a namespace (or the default). */
|
|
142
|
+
getStorage: (namespace?: string) => Promise<StorageManager>;
|
|
143
|
+
/** Fast-tier LLM completion (same signature as Orchestrator.fastChatCompletion). */
|
|
144
|
+
fastChatCompletion: (
|
|
145
|
+
messages: Array<{ role: string; content: string }>,
|
|
146
|
+
options: {
|
|
147
|
+
temperature?: number;
|
|
148
|
+
maxTokens?: number;
|
|
149
|
+
timeoutMs?: number;
|
|
150
|
+
operation?: string;
|
|
151
|
+
priority?: "background" | "recall-critical";
|
|
152
|
+
},
|
|
153
|
+
) => Promise<{ content: string } | null>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Coordinates entity synthesis refresh for queued entities. Owns the
|
|
158
|
+
* evidence-gathering, dedup, batched-LLM-synthesis, and persistence logic
|
|
159
|
+
* that previously lived inline in the orchestrator.
|
|
160
|
+
*/
|
|
161
|
+
export class EntitySynthesisCoordinator {
|
|
162
|
+
constructor(private readonly deps: EntitySynthesisCoordinatorDeps) {}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Process up to `maxEntities` entities from the synthesis queue for the
|
|
166
|
+
* given namespace. Returns the number of entities whose synthesis was
|
|
167
|
+
* successfully refreshed.
|
|
168
|
+
*/
|
|
169
|
+
async processQueue(
|
|
170
|
+
namespace?: string,
|
|
171
|
+
maxEntities: number = 5,
|
|
172
|
+
): Promise<number> {
|
|
173
|
+
const { config } = this.deps;
|
|
174
|
+
if (
|
|
175
|
+
!config.entitySummaryEnabled
|
|
176
|
+
|| maxEntities <= 0
|
|
177
|
+
|| config.entitySynthesisMaxTokens <= 0
|
|
178
|
+
) return 0;
|
|
179
|
+
const storage = await this.deps.getStorage(namespace);
|
|
180
|
+
const queued = await storage.refreshEntitySynthesisQueue();
|
|
181
|
+
let processed = 0;
|
|
182
|
+
let attempted = 0;
|
|
183
|
+
|
|
184
|
+
for (const entityName of queued) {
|
|
185
|
+
if (attempted >= maxEntities) break;
|
|
186
|
+
attempted += 1;
|
|
187
|
+
try {
|
|
188
|
+
const raw = await storage.readEntity(entityName);
|
|
189
|
+
if (!raw) continue;
|
|
190
|
+
const entity = parseEntityFile(raw, config.entitySchemas);
|
|
191
|
+
const previousSynthesis = entity.synthesis || entity.summary || "";
|
|
192
|
+
const sortedTimelineEntries = entity.timeline
|
|
193
|
+
.slice()
|
|
194
|
+
.sort((left, right) => compareEntityTimestamps(right.timestamp, left.timestamp));
|
|
195
|
+
const newerTimelineEntries = sortedTimelineEntries.filter(
|
|
196
|
+
(entry) =>
|
|
197
|
+
!entity.synthesisUpdatedAt
|
|
198
|
+
|| compareEntityTimestamps(entry.timestamp, entity.synthesisUpdatedAt) > 0,
|
|
199
|
+
);
|
|
200
|
+
const appendedTimelineEntries = entity.synthesisTimelineCount === undefined
|
|
201
|
+
? []
|
|
202
|
+
: entity.timeline.slice(Math.max(0, entity.synthesisTimelineCount));
|
|
203
|
+
const structuredEvidenceEntries = flattenStructuredSectionEvidence(entity.structuredSections);
|
|
204
|
+
const structuredEvidenceCount = structuredEvidenceEntries.length;
|
|
205
|
+
const structuredEvidenceDigest = fingerprintEntityStructuredFacts(entity);
|
|
206
|
+
const structuredEvidenceDrifted = structuredEvidenceDigest !== (entity.synthesisStructuredFactDigest?.trim() || undefined);
|
|
207
|
+
const appendedStructuredEvidenceEntries = entity.synthesisStructuredFactCount === undefined
|
|
208
|
+
|| structuredEvidenceDrifted
|
|
209
|
+
? structuredEvidenceEntries
|
|
210
|
+
: structuredEvidenceEntries.slice(Math.max(0, entity.synthesisStructuredFactCount));
|
|
211
|
+
const candidateEvidenceEntries = [
|
|
212
|
+
...newerTimelineEntries,
|
|
213
|
+
...appendedTimelineEntries,
|
|
214
|
+
...appendedStructuredEvidenceEntries,
|
|
215
|
+
]
|
|
216
|
+
.slice()
|
|
217
|
+
.sort((left, right) => compareEntityTimestamps(right.timestamp, left.timestamp));
|
|
218
|
+
const dedupedEvidenceEntries = dedupeEntitySynthesisEvidenceEntries(
|
|
219
|
+
candidateEvidenceEntries.length > 0
|
|
220
|
+
? candidateEvidenceEntries
|
|
221
|
+
: [...sortedTimelineEntries, ...structuredEvidenceEntries],
|
|
222
|
+
);
|
|
223
|
+
const chronologicalEvidenceEntries = dedupedEvidenceEntries
|
|
224
|
+
.slice()
|
|
225
|
+
.sort((left, right) => compareEntityTimestamps(left.timestamp, right.timestamp));
|
|
226
|
+
if (chronologicalEvidenceEntries.length === 0) continue;
|
|
227
|
+
const latestEvidenceTimestamp = chronologicalEvidenceEntries
|
|
228
|
+
.slice()
|
|
229
|
+
.reverse()
|
|
230
|
+
.map((entry) => entry.timestamp?.trim() || undefined)
|
|
231
|
+
.find((timestamp) => Boolean(timestamp));
|
|
232
|
+
const previousSynthesisUpdatedAt = entity.synthesisUpdatedAt?.trim() || undefined;
|
|
233
|
+
const nextSynthesisUpdatedAt = compareEntityTimestamps(
|
|
234
|
+
latestEvidenceTimestamp,
|
|
235
|
+
previousSynthesisUpdatedAt,
|
|
236
|
+
) >= 0
|
|
237
|
+
? latestEvidenceTimestamp
|
|
238
|
+
: previousSynthesisUpdatedAt;
|
|
239
|
+
const evidenceBatches: typeof chronologicalEvidenceEntries[] = [];
|
|
240
|
+
for (let index = 0; index < chronologicalEvidenceEntries.length; index += 8) {
|
|
241
|
+
evidenceBatches.push(chronologicalEvidenceEntries.slice(index, index + 8));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
let nextSynthesis = previousSynthesis;
|
|
245
|
+
let batchFailed = false;
|
|
246
|
+
for (const evidenceEntries of evidenceBatches) {
|
|
247
|
+
const evidenceText = evidenceEntries
|
|
248
|
+
.map((entry) => {
|
|
249
|
+
const sectionTitle = entry.source?.startsWith("section:")
|
|
250
|
+
? entry.source.slice("section:".length)
|
|
251
|
+
: "";
|
|
252
|
+
const metadata = [
|
|
253
|
+
`timestamp=${entry.timestamp}`,
|
|
254
|
+
sectionTitle ? `section=${sectionTitle}` : entry.source ? `source=${entry.source}` : "",
|
|
255
|
+
entry.sessionKey ? `session=${entry.sessionKey}` : "",
|
|
256
|
+
entry.principal ? `principal=${entry.principal}` : "",
|
|
257
|
+
]
|
|
258
|
+
.filter(Boolean)
|
|
259
|
+
.join(", ");
|
|
260
|
+
return `- ${metadata}: ${entry.text}`;
|
|
261
|
+
})
|
|
262
|
+
.join("\n");
|
|
263
|
+
const response = await this.deps.fastChatCompletion(
|
|
264
|
+
[
|
|
265
|
+
{
|
|
266
|
+
role: "system",
|
|
267
|
+
content:
|
|
268
|
+
"Rewrite the entity synthesis as compact current truth. Preserve uncertainty when evidence conflicts. Return plain text only.",
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
role: "user",
|
|
272
|
+
content: [
|
|
273
|
+
`Entity: ${entity.name} (${entity.type})`,
|
|
274
|
+
nextSynthesis ? `Previous synthesis:\n${nextSynthesis}` : "Previous synthesis: none",
|
|
275
|
+
`New evidence:\n${evidenceText}`,
|
|
276
|
+
].join("\n\n"),
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
{
|
|
280
|
+
temperature: 0.2,
|
|
281
|
+
maxTokens: config.entitySynthesisMaxTokens,
|
|
282
|
+
operation: "entity_summary",
|
|
283
|
+
priority: "background",
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
const synthesis = response?.content?.trim().replace(/^["']|["']$/g, "");
|
|
287
|
+
const maxSynthesisChars = Math.max(2_000, config.entitySynthesisMaxTokens * 8);
|
|
288
|
+
if (!synthesis || synthesis.length < 10 || synthesis.length > maxSynthesisChars) {
|
|
289
|
+
batchFailed = true;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
nextSynthesis = synthesis;
|
|
293
|
+
}
|
|
294
|
+
if (batchFailed || nextSynthesis.length === 0) continue;
|
|
295
|
+
const latestRaw = await storage.readEntity(entityName);
|
|
296
|
+
if (!latestRaw) continue;
|
|
297
|
+
const latestEntity = parseEntityFile(latestRaw, config.entitySchemas);
|
|
298
|
+
if (
|
|
299
|
+
fingerprintEntitySynthesisEvidence(latestEntity)
|
|
300
|
+
!== fingerprintEntitySynthesisEvidence(entity)
|
|
301
|
+
) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
await storage.updateEntitySynthesis(entityName, nextSynthesis, {
|
|
305
|
+
entityUpdatedAt: new Date().toISOString(),
|
|
306
|
+
synthesisStructuredFactDigest: structuredEvidenceDigest,
|
|
307
|
+
synthesisStructuredFactCount: structuredEvidenceCount,
|
|
308
|
+
synthesisTimelineCount: entity.timeline.length,
|
|
309
|
+
updatedAt: nextSynthesisUpdatedAt,
|
|
310
|
+
});
|
|
311
|
+
processed += 1;
|
|
312
|
+
} catch (err) {
|
|
313
|
+
log.debug(`entity synthesis refresh failed for ${entityName}: ${err}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return processed;
|
|
318
|
+
}
|
|
319
|
+
}
|