Files
openclaw/src/shared/text/assistant-transcript-role-headers.ts
snowzlmbot e8ad0466ff fix: render assistant transcript headers safely (#99404)
* fix: render assistant transcript headers safely

Co-authored-by: snowzlmbot <293528334+snowzlmbot@users.noreply.github.com>

* fix(markdown): nest crossing annotation spans

* fix(markdown): protect final transport projections

* refactor(markdown): split transcript render ownership

* test(ui): cover assistant transcript render flag

* refactor(markdown): keep transcript helpers private

* docs(changelog): note assistant transcript headers

* chore(plugin-sdk): refresh transcript annotation baseline

* fix(markdown): harden final transcript projections

* docs(changelog): defer transcript note to release

* refactor(markdown): centralize HTML tokenization

* fix(markdown): satisfy lint gates

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: snowzlmbot <293528334+snowzlmbot@users.noreply.github.com>
2026-07-14 02:25:37 -07:00

23 lines
806 B
TypeScript

import { markdownToIR } from "../../../packages/markdown-core/src/ir.js";
type AssistantTranscriptRoleHeaderDetection = {
kind: "angle_role_header" | "role_timestamp_bracket" | "timestamp_role_colon";
role: "assistant" | "developer" | "system" | "user";
};
/** Detect transcript-role headers in assistant Markdown through the canonical parser. */
export function detectAssistantTranscriptRoleHeaderText(
text: string,
): AssistantTranscriptRoleHeaderDetection | null {
const annotation = markdownToIR(text, {
assistantTranscriptRoleHeaders: true,
enableSpoilers: true,
linkify: false,
tableMode: "off",
}).annotations?.[0];
if (!annotation || annotation.type !== "assistant_transcript_role") {
return null;
}
return { kind: annotation.kind, role: annotation.role };
}