refactor: standardize pending permission keying and user message hydration

This commit is contained in:
Mohamed Boudra
2025-11-15 17:36:15 +01:00
parent e26219c967
commit b45583a2b2
11 changed files with 678 additions and 311 deletions
@@ -1118,29 +1118,33 @@ export function convertClaudeHistoryEntry(
const content = message.content as string | ClaudeContentChunk[];
const normalizedBlocks = normalizeHistoryBlocks(content);
const hasToolBlock = normalizedBlocks?.some((block) => hasToolLikeBlock(block)) ?? false;
const timeline: AgentTimelineItem[] = [];
if (entry.type === "user") {
const text = extractUserMessageText(content);
if (text) {
timeline.push({
type: "user_message",
text,
raw: message,
});
}
}
if (hasToolBlock && normalizedBlocks) {
return mapBlocks(Array.isArray(content) ? content : normalizedBlocks);
const mapped = mapBlocks(Array.isArray(content) ? content : normalizedBlocks);
if (entry.type === "user") {
const toolItems = mapped.filter((item) => item.type === "tool_call");
return timeline.length ? [...timeline, ...toolItems] : toolItems;
}
return mapped;
}
if (entry.type === "assistant" && content) {
return mapBlocks(content);
}
if (entry.type === "user") {
const text = extractUserMessageText(content);
if (text) {
return [
{
type: "user_message",
text,
raw: message,
},
];
}
}
return [];
return timeline;
}
class Pushable<T> implements AsyncIterable<T> {