mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:47:26 +00:00
refactor(runtime): harden channel-registry cache invalidation and split outbound delivery flow
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user