mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-15 09:01:13 +00:00
Move the gateway runtime files into a dedicated core/gateway module and fix follow-up issues in session deletion, history import batching, message IDs, and legacy thread parsing. Fixes #253 Co-authored-by: Codex <noreply@openai.com>
29 lines
797 B
TypeScript
29 lines
797 B
TypeScript
import type { AgentSession } from "../agent-session.js";
|
|
|
|
export function extractMessageText(message: { content: unknown }): string {
|
|
if (!Array.isArray(message.content)) {
|
|
return "";
|
|
}
|
|
return message.content
|
|
.filter((part): part is { type: "text"; text: string } => {
|
|
return (
|
|
typeof part === "object" &&
|
|
part !== null &&
|
|
"type" in part &&
|
|
"text" in part &&
|
|
part.type === "text"
|
|
);
|
|
})
|
|
.map((part) => part.text)
|
|
.join("");
|
|
}
|
|
|
|
export function getLastAssistantText(session: AgentSession): string {
|
|
for (let index = session.messages.length - 1; index >= 0; index--) {
|
|
const message = session.messages[index];
|
|
if (message.role === "assistant") {
|
|
return extractMessageText(message);
|
|
}
|
|
}
|
|
return "";
|
|
}
|