refactor(runtime): harden channel-registry cache invalidation and split outbound delivery flow

This commit is contained in:
Peter Steinberger
2026-03-03 00:05:12 +00:00
parent d6491d8d71
commit 1d0a4d1be2
4 changed files with 254 additions and 140 deletions

View File

@@ -79,6 +79,10 @@ function unwrapQuoted(value: string): string | undefined {
return trimmed.slice(1, -1).trim();
}
function mayContainFenceMarkers(input: string): boolean {
return input.includes("```") || input.includes("~~~");
}
// Check if a character offset is inside any fenced code block
function isInsideFence(fenceSpans: Array<{ start: number; end: number }>, offset: number): boolean {
return fenceSpans.some((span) => offset >= span.start && offset < span.end);
@@ -106,7 +110,8 @@ export function splitMediaFromOutput(raw: string): {
let foundMediaToken = false;
// Parse fenced code blocks to avoid extracting MEDIA tokens from inside them
const fenceSpans = parseFenceSpans(trimmedRaw);
const hasFenceMarkers = mayContainFenceMarkers(trimmedRaw);
const fenceSpans = hasFenceMarkers ? parseFenceSpans(trimmedRaw) : [];
// Collect tokens line by line so we can strip them cleanly.
const lines = trimmedRaw.split("\n");
@@ -115,7 +120,7 @@ export function splitMediaFromOutput(raw: string): {
let lineOffset = 0; // Track character offset for fence checking
for (const line of lines) {
// Skip MEDIA extraction if this line is inside a fenced code block
if (isInsideFence(fenceSpans, lineOffset)) {
if (hasFenceMarkers && isInsideFence(fenceSpans, lineOffset)) {
keptLines.push(line);
lineOffset += line.length + 1; // +1 for newline
continue;