mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
Add get_messages RPC command
This commit is contained in:
parent
2b0aa5ed8e
commit
3c8ab0280e
3 changed files with 25 additions and 3 deletions
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import { type ChildProcess, spawn } from "node:child_process";
|
||||
import * as readline from "node:readline";
|
||||
import type { AgentEvent, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core";
|
||||
import type { AgentEvent, AppMessage, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core";
|
||||
import type { CompactionResult, SessionStats } from "../../core/agent-session.js";
|
||||
import type { BashResult } from "../../core/bash-executor.js";
|
||||
import type { RpcCommand, RpcResponse, RpcSessionState } from "./rpc-types.js";
|
||||
|
|
@ -326,6 +326,14 @@ export class RpcClient {
|
|||
return this.getData<{ text: string | null }>(response).text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all messages in the session.
|
||||
*/
|
||||
async getMessages(): Promise<AppMessage[]> {
|
||||
const response = await this.send({ type: "get_messages" });
|
||||
return this.getData<{ messages: AppMessage[] }>(response).messages;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Helpers
|
||||
// =========================================================================
|
||||
|
|
|
|||
|
|
@ -227,6 +227,14 @@ export async function runRpcMode(session: AgentSession): Promise<never> {
|
|||
return success(id, "get_last_assistant_text", { text });
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
// Messages
|
||||
// =================================================================
|
||||
|
||||
case "get_messages": {
|
||||
return success(id, "get_messages", { messages: session.messages });
|
||||
}
|
||||
|
||||
default: {
|
||||
const unknownCommand = command as { type: string };
|
||||
return error(undefined, unknownCommand.type, `Unknown command: ${unknownCommand.type}`);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* Responses and events are emitted as JSON lines on stdout.
|
||||
*/
|
||||
|
||||
import type { Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core";
|
||||
import type { AppMessage, Attachment, ThinkingLevel } from "@mariozechner/pi-agent-core";
|
||||
import type { CompactionResult, SessionStats } from "../../core/agent-session.js";
|
||||
import type { BashResult } from "../../core/bash-executor.js";
|
||||
|
||||
|
|
@ -49,7 +49,10 @@ export type RpcCommand =
|
|||
| { id?: string; type: "switch_session"; sessionPath: string }
|
||||
| { id?: string; type: "branch"; entryIndex: number }
|
||||
| { id?: string; type: "get_branch_messages" }
|
||||
| { id?: string; type: "get_last_assistant_text" };
|
||||
| { id?: string; type: "get_last_assistant_text" }
|
||||
|
||||
// Messages
|
||||
| { id?: string; type: "get_messages" };
|
||||
|
||||
// ============================================================================
|
||||
// RPC State
|
||||
|
|
@ -146,6 +149,9 @@ export type RpcResponse =
|
|||
data: { text: string | null };
|
||||
}
|
||||
|
||||
// Messages
|
||||
| { id?: string; type: "response"; command: "get_messages"; success: true; data: { messages: AppMessage[] } }
|
||||
|
||||
// Error response (any command can fail)
|
||||
| { id?: string; type: "response"; command: string; success: false; error: string };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue