11import { isNotification , POSTHOG_NOTIFICATIONS } from "./acpNotifications" ;
22import type {
3- PortableSessionEvent ,
43 PortableSessionNotification ,
54 PortableSessionToolCallStatus ,
5+ PortableSessionUpdateEvent ,
66} from "./portableSessionEvents" ;
77
88export type SessionActivityPhase = "idle" | "connecting" | "working" ;
99
10+ export type SessionActivityEvent =
11+ | PortableSessionUpdateEvent
12+ | {
13+ type : "acp_message" ;
14+ ts : number ;
15+ message : unknown ;
16+ } ;
17+
1018export interface SessionActivityState {
1119 isPromptPending ?: boolean ;
1220 awaitingAgentOutput ?: boolean ;
1321 terminalStatus ?: "failed" | "completed" ;
14- events ?: readonly PortableSessionEvent [ ] ;
22+ events ?: readonly SessionActivityEvent [ ] ;
1523}
1624
1725function isQuestionNotification (
@@ -44,7 +52,7 @@ function isPendingQuestionStatus(
4452}
4553
4654export function isSessionAwaitingUserInput (
47- events : readonly PortableSessionEvent [ ] = [ ] ,
55+ events : readonly SessionActivityEvent [ ] = [ ] ,
4856) : boolean {
4957 let awaitingUserInput = false ;
5058 const questionStatuses = new Map <
@@ -87,7 +95,13 @@ export function isSessionAwaitingUserInput(
8795 continue ;
8896 }
8997
90- const method = "method" in event . message ? event . message . method : undefined ;
98+ const method =
99+ typeof event . message === "object" &&
100+ event . message !== null &&
101+ "method" in event . message &&
102+ typeof event . message . method === "string"
103+ ? event . message . method
104+ : undefined ;
91105 if ( method === "_posthog/awaiting_user_input" ) {
92106 awaitingUserInput = true ;
93107 continue ;
@@ -107,7 +121,7 @@ export function isSessionAwaitingUserInput(
107121}
108122
109123export function countUserMessages (
110- events : readonly PortableSessionEvent [ ] = [ ] ,
124+ events : readonly SessionActivityEvent [ ] = [ ] ,
111125) : number {
112126 return events . filter (
113127 ( event ) =>
0 commit comments