@@ -68,17 +68,48 @@ export const POSTHOG_NOTIFICATIONS = {
6868 PERMISSION_RESPONSE : "_posthog/permission_response" ,
6969} as const ;
7070
71- type NotificationMethod =
71+ /**
72+ * Custom request methods for PostHog-specific operations that need a response
73+ * (request/response, not fire-and-forget). Used with
74+ * ClientSideConnection.extMethod() on the sender and Agent.extMethod() on the
75+ * receiver.
76+ */
77+ export const POSTHOG_METHODS = {
78+ /**
79+ * Client requests a session refresh between turns. Payload may include
80+ * `mcpServers` to trigger a resume-with-new-options reinit; future fields
81+ * can extend this without adding new methods. Returns once the refresh has
82+ * completed so the caller can safely send the next prompt.
83+ */
84+ REFRESH_SESSION : "_posthog/refresh_session" ,
85+ } as const ;
86+
87+ type PosthogNotification =
7288 ( typeof POSTHOG_NOTIFICATIONS ) [ keyof typeof POSTHOG_NOTIFICATIONS ] ;
7389
90+ type PosthogMethod = ( typeof POSTHOG_METHODS ) [ keyof typeof POSTHOG_METHODS ] ;
91+
7492/**
75- * Check if an ACP method matches a PostHog notification, handling the
76- * possible `__posthog/` double-prefix from extNotification().
93+ * Does ` method` match `expected`? Shared by notification and method matchers.
94+ * Handles the `__posthog/` double-prefix that extNotification() can produce .
7795 */
96+ function matchesExt ( method : string | undefined , expected : string ) : boolean {
97+ if ( ! method ) return false ;
98+ return method === expected || method === `_${ expected } ` ;
99+ }
100+
101+ /** Dispatcher check for incoming `extNotification` calls on the agent side. */
78102export function isNotification (
79103 method : string | undefined ,
80- notification : NotificationMethod ,
104+ expected : PosthogNotification ,
81105) : boolean {
82- if ( ! method ) return false ;
83- return method === notification || method === `_${ notification } ` ;
106+ return matchesExt ( method , expected ) ;
107+ }
108+
109+ /** Dispatcher check for incoming `extMethod` calls on the agent side. */
110+ export function isMethod (
111+ method : string | undefined ,
112+ expected : PosthogMethod ,
113+ ) : boolean {
114+ return matchesExt ( method , expected ) ;
84115}
0 commit comments