MCPcopy Index your code
hub / github.com/inkeep/open-knowledge / runObserverASyncImpl

Function runObserverASyncImpl

packages/server/src/server-observers.ts:302–456  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

300 }
301
302 const runObserverASyncImpl = (): void => {
303 try {
304 const json = yXmlFragmentToProseMirrorRootNode(xmlFragment, schema).toJSON();
305 const body = mdManager.serialize(json);
306 const frontmatter = readCurrentFm();
307 const md = prependFrontmatter(frontmatter, body);
308
309 if (canonicalWitnessCoherent && lastSyncedCanonicalMd === md) {
310 if (settlesSplitBrain(ytext.toString(), md)) {
311 recordDivergedAttachBaselines(md);
312 textDirty = true;
313 recordSplitBrainRederive('identity-gate');
314 setActiveSpanAttributes({ 'observer.a.path': 'gated-fragment-unchanged-rederive' });
315 } else {
316 setActiveSpanAttributes({ 'observer.a.path': 'gated-fragment-unchanged' });
317 }
318 return;
319 }
320
321 const currentText = ytext.toString();
322
323 const normCurrent = normalizeBridge(currentText);
324 const normMd = normalizeBridge(md);
325 if (normCurrent === normMd) {
326 setActiveSpanAttributes({ 'observer.a.path': 'gated-in-sync' });
327 recordSettledBaselines(md);
328 return;
329 }
330
331 const preMergeBaseline = lastSyncedYTextBytes;
332 const ytextInSync = currentText === lastSyncedYTextBytes;
333 const residualMergeEligible =
334 ytextInSync &&
335 canonicalWitnessCoherent &&
336 lastSyncedYTextBytes !== lastSyncedCanonicalMd &&
337 normCurrent !== normalizeBridge(lastSyncedCanonicalMd);
338 setActiveSpanAttributes({
339 'observer.a.path': ytextInSync
340 ? residualMergeEligible
341 ? 'residual-merge'
342 : 'path-a'
343 : 'path-b',
344 });
345 const pathBState: { mergedText: string | null } = { mergedText: null };
346
347 const spliceComputeStart = performance.now();
348 const mapDrivenSplice =
349 ytextInSync && residualMergeEligible
350 ? null
351 : tryComputeMapDrivenSplice({
352 currentText,
353 lastSyncedXmlMd: lastSyncedYTextBytes,
354 json,
355 mdManager,
356 docName: opts.docName,
357 });
358 if (mapDrivenSplice) {
359 setActiveSpanAttributes({

Callers

nothing calls this directly

Calls 15

setActiveSpanAttributesFunction · 0.90
emitObserverAPathBFiredFunction · 0.90
readCurrentFmFunction · 0.85
prependFrontmatterFunction · 0.85
settlesSplitBrainFunction · 0.85
recordSplitBrainRederiveFunction · 0.85

Tested by

no test coverage detected