mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-18 15:03:03 +00:00
feat: persist chat threads and recover gateway sessions
Add a Convex-backed durable chat layer for companion threads, recover gateway sessions from persisted Pi session files after eviction, and start splitting gateway runtime internals into focused modules. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
parent
8ecd55a522
commit
753cb935f1
5 changed files with 265 additions and 212 deletions
29
packages/coding-agent/src/core/gateway-runtime-helpers.ts
Normal file
29
packages/coding-agent/src/core/gateway-runtime-helpers.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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 "";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue