fix: repair typing for thinking promotion

This commit is contained in:
Peter Steinberger
2026-01-09 08:37:38 +00:00
parent 17ccf53eb1
commit 3db52c972d

View File

@@ -179,28 +179,22 @@ function splitThinkingTaggedText(text: string): ThinkTaggedSplitBlock[] | null {
function promoteThinkingTagsToBlocks(message: AssistantMessage): void { function promoteThinkingTagsToBlocks(message: AssistantMessage): void {
if (!Array.isArray(message.content)) return; if (!Array.isArray(message.content)) return;
const hasThinkingBlock = message.content.some((block) => { const hasThinkingBlock = message.content.some(
if (!block || typeof block !== "object") return false; (block) => block.type === "thinking",
return (block as Record<string, unknown>).type === "thinking"; );
});
if (hasThinkingBlock) return; if (hasThinkingBlock) return;
const next: Array<Record<string, unknown>> = []; const next: AssistantMessage["content"] = [];
let changed = false; let changed = false;
for (const block of message.content) { for (const block of message.content) {
if (!block || typeof block !== "object") { if (block.type !== "text") {
next.push(block as Record<string, unknown>); next.push(block);
continue; continue;
} }
const record = block as Record<string, unknown>; const split = splitThinkingTaggedText(block.text);
if (record.type !== "text" || typeof record.text !== "string") {
next.push(record);
continue;
}
const split = splitThinkingTaggedText(record.text);
if (!split) { if (!split) {
next.push(record); next.push(block);
continue; continue;
} }
changed = true; changed = true;
@@ -215,7 +209,7 @@ function promoteThinkingTagsToBlocks(message: AssistantMessage): void {
} }
if (!changed) return; if (!changed) return;
(message as unknown as { content: unknown }).content = next; message.content = next;
} }
function normalizeSlackTarget(raw: string): string | undefined { function normalizeSlackTarget(raw: string): string | undefined {