Add session management and agent state methods to hooks API

HookAPI additions:
- pi.newSession(options?) - create new session with optional setup callback
- pi.branch(entryId) - branch from a specific entry
- pi.navigateTree(targetId, options?) - navigate the session tree

HookContext additions:
- ctx.isIdle() - check if agent is streaming
- ctx.waitForIdle() - wait for agent to finish
- ctx.abort() - abort current operation
- ctx.hasQueuedMessages() - check for queued user messages

These enable hooks to programmatically manage sessions (handoff, templates)
and check agent state before showing interactive UI.

Fixes #388
This commit is contained in:
Mario Zechner 2026-01-01 23:56:24 +01:00
parent 484d7e06bb
commit ccdd7bd283
9 changed files with 355 additions and 14 deletions

View file

@ -558,6 +558,10 @@ export class AgentSession {
sessionManager: this.sessionManager,
modelRegistry: this._modelRegistry,
model: this.model,
isIdle: () => !this.isStreaming,
waitForIdle: () => this.agent.waitForIdle(),
abort: () => this.abort(),
hasQueuedMessages: () => this.queuedMessageCount > 0,
};
try {