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:
Mario Zechner 2025-12-27 01:31:31 +01:00
parent 30cd723411
commit 357bd946c2
6 changed files with 34 additions and 12 deletions

View file

@ -73,12 +73,12 @@ export class ProviderTransport implements AgentTransport {
}
}
async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {
async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal, emitLastMessage?: boolean) {
const model = this.getModel(cfg);
const context = this.buildContext(messages, cfg);
const pc = this.buildLoopConfig(model, cfg);
for await (const ev of agentLoopContinue(context, pc, signal)) {
for await (const ev of agentLoopContinue(context, pc, signal, undefined, emitLastMessage)) {
yield ev;
}
}