mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 10:00:39 +00:00
Add emitLastMessage flag to agent.continue()
When calling continue() with emitLastMessage=true, the agent loop emits message_start/message_end events for the last message in context. This allows messages added outside the loop (e.g., hook messages via sendHookMessage) to trigger proper TUI rendering. Changes across packages: - packages/ai: agentLoopContinue() accepts emitLastMessage parameter - packages/agent: Agent.continue(), transports updated to pass flag - packages/coding-agent: sendHookMessage passes true when triggerTurn
This commit is contained in:
parent
30cd723411
commit
357bd946c2
6 changed files with 34 additions and 12 deletions
|
|
@ -206,7 +206,12 @@ export class Agent {
|
|||
* Continue from the current context without adding a new user message.
|
||||
* Used for retry after overflow recovery when context already has user message or tool results.
|
||||
*/
|
||||
async continue() {
|
||||
/**
|
||||
* Continue from the current context without adding a new user message.
|
||||
* Used for retry after overflow recovery when context already has user message or tool results.
|
||||
* @param emitLastMessage If true, emit message_start/message_end for the last message
|
||||
*/
|
||||
async continue(emitLastMessage?: boolean) {
|
||||
const messages = this._state.messages;
|
||||
if (messages.length === 0) {
|
||||
throw new Error("No messages to continue from");
|
||||
|
|
@ -217,7 +222,7 @@ export class Agent {
|
|||
throw new Error(`Cannot continue from message role: ${lastMessage.role}`);
|
||||
}
|
||||
|
||||
await this._runAgentLoopContinue();
|
||||
await this._runAgentLoopContinue(emitLastMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -234,10 +239,10 @@ export class Agent {
|
|||
/**
|
||||
* Internal: Continue the agent loop from current context.
|
||||
*/
|
||||
private async _runAgentLoopContinue() {
|
||||
private async _runAgentLoopContinue(emitLastMessage?: boolean) {
|
||||
const { llmMessages, cfg } = await this._prepareRun();
|
||||
|
||||
const events = this.transport.continue(llmMessages, cfg, this.abortController!.signal);
|
||||
const events = this.transport.continue(llmMessages, cfg, this.abortController!.signal, emitLastMessage);
|
||||
|
||||
await this._processEvents(events);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue