mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 18:01:22 +00:00
fix: RPC mode session management not saving sessions
Since version 0.9.0, RPC mode (--mode rpc) was not saving messages to session files. The agent.subscribe() call with session management logic was only present in the TUI renderer after it was refactored. RPC mode now properly saves sessions just like interactive mode. Added test for RPC mode session management to prevent regression. Fixes #83 Thanks @kiliman for reporting this issue!
This commit is contained in:
parent
5fa30b8add
commit
d2b60f11eb
14 changed files with 284 additions and 123 deletions
|
|
@ -806,10 +806,24 @@ async function runSingleShotMode(
|
|||
}
|
||||
}
|
||||
|
||||
async function runRpcMode(agent: Agent, _sessionManager: SessionManager): Promise<void> {
|
||||
// Subscribe to all events and output as JSON
|
||||
agent.subscribe((event) => {
|
||||
async function runRpcMode(agent: Agent, sessionManager: SessionManager): Promise<void> {
|
||||
// Subscribe to all events and output as JSON (same pattern as tui-renderer)
|
||||
agent.subscribe(async (event) => {
|
||||
console.log(JSON.stringify(event));
|
||||
|
||||
// Save messages to session
|
||||
if (event.type === "message_end") {
|
||||
sessionManager.saveMessage(event.message);
|
||||
|
||||
// Yield to microtask queue to allow agent state to update
|
||||
// (tui-renderer does this implicitly via await handleEvent)
|
||||
await Promise.resolve();
|
||||
|
||||
// Check if we should initialize session now (after first user+assistant exchange)
|
||||
if (sessionManager.shouldInitializeSession(agent.state.messages)) {
|
||||
sessionManager.startSession(agent.state);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for JSON input on stdin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue