feat(companion): add platform event subscription count passthrough

This commit is contained in:
William Valentin
2026-02-16 19:33:55 -08:00
parent d3e571b728
commit 6a9796066b
4 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -1200,7 +1200,7 @@ Companion runtime helper:
- `createHeartbeatLoop()` convenience helper that returns a bound `CompanionHeartbeatLoop`
- optional `defaultSessionId` for canvas helper calls so `sessionId` can be omitted per call
- `dispose()` lifecycle helper for unified runtime teardown
- stream passthrough helpers (`subscribeEvents`, `clearEventSubscriptions`, `listKnownEventNames`, `subscribeAgentStream/Typing/ContextWarning`, `waitForAnyEvent`, `waitForAgentStream/Typing/ContextWarning`)
- stream passthrough helpers (`subscribeEvents`, `clearEventSubscriptions`, `listKnownEventNames`, `eventSubscriptionCount`, `subscribeAgentStream/Typing/ContextWarning`, `waitForAnyEvent`, `waitForAgentStream/Typing/ContextWarning`)
- `src/companion/heartbeatLoop.ts` provides `CompanionHeartbeatLoop` for periodic heartbeat scheduling (`publishHeartbeat`) with start/stop safety, optional interval jitter (`jitterRatio`) to spread load, `tickNow()` for manual sends, success/error hooks, failure observability (`failureCount`, `lastFailure`, `getState()`), and optional auto-stop after repeated failures.
## Canvas / A2UI Foundation
+13
View File
@@ -673,6 +673,19 @@
],
"test_status": "pnpm test:run src/companion/runtimeClient.test.ts src/companion/platformClients.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
},
"companion-platform-event-subscription-count-passthrough": {
"status": "completed",
"date": "2026-02-17",
"updated": "2026-02-17",
"summary": "Added `eventSubscriptionCount` passthrough on platform companion clients so wrappers expose active runtime event-listener cardinality for observability and debugging.",
"files_modified": [
"src/companion/platformClients.ts",
"src/companion/platformClients.test.ts",
"README.md",
"docs/plans/state.json"
],
"test_status": "pnpm test:run src/companion/platformClients.test.ts src/companion/runtimeClient.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
},
"browser-tools-activation-clarity": {
"status": "completed",
"date": "2026-02-17",
+13
View File
@@ -35,6 +35,7 @@ function createRuntimeMock(): {
waitForAgentTyping: ReturnType<typeof vi.fn>;
waitForContextWarning: ReturnType<typeof vi.fn>;
waitForAnyEvent: ReturnType<typeof vi.fn>;
eventSubscriptionCount: number;
} {
const connect = vi.fn(async () => undefined);
const disconnect = vi.fn(() => undefined);
@@ -70,6 +71,7 @@ function createRuntimeMock(): {
const waitForAgentTyping = vi.fn(async () => ({ active: true }));
const waitForContextWarning = vi.fn(async () => ({ thresholdPct: 75, estimatedPct: 90 }));
const waitForAnyEvent = vi.fn(async () => ({ event: 'agent.stream', data: { token: 'any' } }));
const eventSubscriptionCount = 3;
const runtime = {
connect,
@@ -99,6 +101,9 @@ function createRuntimeMock(): {
waitForAgentTyping,
waitForContextWarning,
waitForAnyEvent,
get eventSubscriptionCount() {
return eventSubscriptionCount;
},
} as unknown as CompanionRuntimeClient;
return {
@@ -130,6 +135,7 @@ function createRuntimeMock(): {
waitForAgentTyping,
waitForContextWarning,
waitForAnyEvent,
eventSubscriptionCount,
};
}
@@ -244,6 +250,13 @@ describe('platform companion clients', () => {
expect(events).toEqual(['agent.stream', 'agent.typing', 'context_warning']);
});
it('platform eventSubscriptionCount forwards runtime getter value', async () => {
const mock = createRuntimeMock();
const client = new IOSCompanionClient({ runtime: mock.runtime, nodeId: 'ios-node' });
expect(client.eventSubscriptionCount).toBe(mock.eventSubscriptionCount);
});
it('macOS client forwards canvas methods to runtime client', async () => {
const mock = createRuntimeMock();
const client = new MacOSCompanionClient({ runtime: mock.runtime, nodeId: 'mac-node' });
+12
View File
@@ -260,6 +260,10 @@ export class MacOSCompanionClient {
return this.runtime.listKnownEventNames();
}
get eventSubscriptionCount(): number {
return this.runtime.eventSubscriptionCount;
}
waitForAnyEvent<TData = unknown>(
eventNames: readonly string[],
options?: {
@@ -476,6 +480,10 @@ export class IOSCompanionClient {
return this.runtime.listKnownEventNames();
}
get eventSubscriptionCount(): number {
return this.runtime.eventSubscriptionCount;
}
waitForAnyEvent<TData = unknown>(
eventNames: readonly string[],
options?: {
@@ -690,6 +698,10 @@ export class AndroidCompanionClient {
return this.runtime.listKnownEventNames();
}
get eventSubscriptionCount(): number {
return this.runtime.eventSubscriptionCount;
}
waitForAnyEvent<TData = unknown>(
eventNames: readonly string[],
options?: {