20 lines
944 B
TypeScript
20 lines
944 B
TypeScript
export type ThinkingMode = "show" | "hide"
|
|
|
|
const MODES: readonly ThinkingMode[] = ["show", "hide"] as const
|
|
|
|
// OpenAI's Responses API surfaces reasoning summaries that start with a bolded
|
|
// title block: "**Inspecting PR workflow**\n\n<body>". Treat that first block,
|
|
// or a complete title still awaiting its body while streaming, as disclosure
|
|
// metadata so the TUI can style its header independently from the markdown body.
|
|
export function reasoningSummary(text: string) {
|
|
const content = text.trim()
|
|
const match = content.match(/^\*\*([^*\n]+)\*\*(?:\r?\n\r?\n|$)/)
|
|
if (!match) return { title: null, body: content }
|
|
return { title: match[1].trim(), body: content.slice(match[0].length).trimEnd() }
|
|
}
|
|
|
|
// Cycle order matches the slash command: show → hide → show.
|
|
export function nextThinkingMode(current: ThinkingMode): ThinkingMode {
|
|
const idx = MODES.indexOf(current)
|
|
return MODES[(idx + 1) % MODES.length] ?? "show"
|
|
}
|