feat(companion): add known event name typing and listing

This commit is contained in:
William Valentin
2026-02-16 19:30:39 -08:00
parent 4d6bed72d8
commit 4f25994876
5 changed files with 37 additions and 4 deletions
+1 -1
View File
@@ -1190,7 +1190,7 @@ Methods:
- `system.capabilities` returns gateway protocol and node policy snapshot.
Companion runtime helper:
- `src/companion/runtimeClient.ts` provides a typed Node/WebSocket client for companion runtimes (macOS/iOS/Android workers) with wrappers for `node.register`, `node.capabilities.get`, `node.location.set/get`, `node.status.set`, `node.push_token.set`, `system.capabilities`, `system.nodes`, and canvas artifact RPCs (`canvas.put/get/list/delete/clear`), plus convenience helpers (`bootstrapNode`, optional `autoConnect`, `dispose()`) and event helpers (`subscribeEvents()`, `subscribeEvent()`, `subscribeAgentStream()`, `subscribeAgentTyping()`, `subscribeContextWarning()`, `waitForEvent()` with timeout/predicate/abort support and deterministic teardown cancellation, `waitForAnyEvent()`, `waitForAgentStream()`, `waitForAgentTyping()`, `waitForContextWarning()`, `clearEventSubscriptions()`).
- `src/companion/runtimeClient.ts` provides a typed Node/WebSocket client for companion runtimes (macOS/iOS/Android workers) with wrappers for `node.register`, `node.capabilities.get`, `node.location.set/get`, `node.status.set`, `node.push_token.set`, `system.capabilities`, `system.nodes`, and canvas artifact RPCs (`canvas.put/get/list/delete/clear`), plus convenience helpers (`bootstrapNode`, optional `autoConnect`, `dispose()`) and event helpers (`subscribeEvents()`, `subscribeEvent()`, `subscribeAgentStream()`, `subscribeAgentTyping()`, `subscribeContextWarning()`, `waitForEvent()` with timeout/predicate/abort support and deterministic teardown cancellation, `waitForAnyEvent()`, `waitForAgentStream()`, `waitForAgentTyping()`, `waitForContextWarning()`, `clearEventSubscriptions()`, `listKnownEventNames()`).
- `src/companion/platformClients.ts` provides platform-focused wrappers:
- `MacOSCompanionClient` (`platform: "macos"`, APNs push registration)
- `IOSCompanionClient` (`platform: "ios"`, APNs push registration)
+14
View File
@@ -633,6 +633,20 @@
],
"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"
},
"companion-runtime-known-event-names": {
"status": "completed",
"date": "2026-02-17",
"updated": "2026-02-17",
"summary": "Added typed companion event-name contract (`CompanionEventName`) and `listKnownEventNames()` helper for discoverable event surfaces in companion clients.",
"files_modified": [
"src/companion/runtimeClient.ts",
"src/companion/runtimeClient.test.ts",
"src/companion/index.ts",
"README.md",
"docs/plans/state.json"
],
"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"
},
"browser-tools-activation-clarity": {
"status": "completed",
"date": "2026-02-17",
+1
View File
@@ -14,6 +14,7 @@ export type {
CompanionRuntimeClientOptions,
CompanionEventHandler,
CompanionTypedEventHandler,
CompanionEventName,
CompanionEventPredicate,
CompanionEventEnvelope,
RegisterNodeInput,
+12
View File
@@ -224,6 +224,18 @@ describe('CompanionRuntimeClient', () => {
expect(typingHandler).toHaveBeenCalledWith({ active: true });
});
it('lists known companion event names', () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
expect(client.listKnownEventNames()).toEqual([
'agent.stream',
'agent.typing',
'context_warning',
]);
});
it('supports subscribeContextWarning helper', () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
+9 -3
View File
@@ -54,6 +54,8 @@ export const COMPANION_EVENT_NAMES = {
agentTyping: 'agent.typing',
contextWarning: 'context_warning',
} as const;
export type CompanionEventName =
(typeof COMPANION_EVENT_NAMES)[keyof typeof COMPANION_EVENT_NAMES];
export interface RegisterNodeInput {
nodeId: string;
@@ -388,7 +390,7 @@ export class CompanionRuntimeClient {
}
subscribeEvent<TData = unknown>(
eventName: string,
eventName: CompanionEventName | string,
handler: CompanionTypedEventHandler<TData>,
): () => void {
return this.subscribeEvents((event, data) => {
@@ -418,7 +420,7 @@ export class CompanionRuntimeClient {
}
waitForEvent<TData = unknown>(
eventName: string,
eventName: CompanionEventName | string,
options?: {
timeoutMs?: number;
predicate?: CompanionEventPredicate<TData>;
@@ -480,7 +482,7 @@ export class CompanionRuntimeClient {
}
waitForAnyEvent<TData = unknown>(
eventNames: readonly string[],
eventNames: readonly (CompanionEventName | string)[],
options?: {
timeoutMs?: number;
predicate?: (event: string, data: TData) => boolean;
@@ -573,6 +575,10 @@ export class CompanionRuntimeClient {
return this.waitForEvent<TData>(COMPANION_EVENT_NAMES.contextWarning, options);
}
listKnownEventNames(): CompanionEventName[] {
return Object.values(COMPANION_EVENT_NAMES);
}
async call<T>(method: string, params?: Record<string, unknown>): Promise<T> {
if (!this.connected) {
if (!this.autoConnect) {