23 lines
714 B
TypeScript
23 lines
714 B
TypeScript
import type { UIMessage } from "@/lib/types";
|
|||
|
|
|
||
|
|
/**
|
||
|
|
* Older WebUI disk snapshots and historical sessions may still contain
|
||
|
|
* ``kind: "long_task"`` rows from the retired orchestrator UI. Map them to
|
||
|
|
* ordinary trace rows so the thread stays readable without bespoke cards.
|
||
|
|
*/
|
||
|
|
export function normalizeLegacyLongTaskMessages(messages: UIMessage[]): UIMessage[] {
|
||
|
|
return messages.map((m) => {
|
||
|
|
const kind = (m as { kind?: string }).kind;
|
||
|
|
if (kind !== "long_task") return m;
|
||
|
|
const text = (m.content ?? "").trim() || "(legacy thread activity)";
|
||
|
|
return {
|
||
|
|
id: m.id,
|
||
|
|
role: "tool",
|
||
|
|
kind: "trace",
|
||
|
|
content: text,
|
||
|
|
traces: [text],
|
||
|
|
createdAt: m.createdAt,
|
||
|
|
};
|
||
|
|
});
|
||
|
|
}
|