feat: add intercom extension API for typed subagent to root messaging#21
Open
avtc wants to merge 1 commit into
Open
feat: add intercom extension API for typed subagent to root messaging#21avtc wants to merge 1 commit into
avtc wants to merge 1 commit into
Conversation
Expose a public API (emitted via `intercom:ready` event) that allows
other extensions to communicate with the root session (hasUI=true)
through structured typed messages:
- `registerHandler(contentType, handler)` — extensions register handlers
for specific content types; pi-intercom auto-routes incoming messages
and sends replies back to the caller
- `sendAndWait({ contentType, payload, text, timeoutMs })` — queued,
serialized RPC-style call from subagent to root session with
configurable timeout
- `contentType` + `payload` fields on Message for structured routing
- `replyTimeoutMs` config option (default 10 min, supports Infinity)
- Reload-safe listener cleanup via globalThis-backed unsubscribe array
This decouples pi-intercom from specific extension integrations — any
extension can now interact with the user through the root session
without pi-intercom knowing about the use case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a public extension API to pi-intercom that allows other extensions running in headless subagent sessions to communicate with the root session (which has UI access) through structured, typed messages.
Why
Previously, pi-intercom had hardcoded handlers for specific message types (permission requests, interview requests). Every new extension that needed to interact with the user through the root session required modifying pi-intercom itself.
This PR replaces that coupling with a generic, extensible protocol. Any extension can now register a handler and send typed messages to the root session — pi-intercom handles routing, serialization, and reply delivery without knowing anything about the specific use case.
How
API surface
The API is emitted via an
intercom:readyevent onpi.events(fired duringsession_start, after all extensions have loaded — no load-order issues):Root session (hasUI=true) — register a handler:
Subagent session — send and wait for reply:
Key pieces
contentType+payloadfields onMessage; a registry (Map<string, Handler>) routes incoming messages to the correct handlersendAndWait()— queued, serialized RPC-style call from subagent to root session; concurrent calls chain sequentially so only one reply waiter is active at a timereplyTimeoutMsconfig option (default 10 min, supportsInfinity)globalThis-backed unsubscribe array prevents listener stacking on/reloadTested with
pi-askuserquestion — PR (ghoseb/pi-askuserquestion#1)