feat(companion): add known event name typing and listing
This commit is contained in:
@@ -1190,7 +1190,7 @@ Methods:
|
|||||||
- `system.capabilities` returns gateway protocol and node policy snapshot.
|
- `system.capabilities` returns gateway protocol and node policy snapshot.
|
||||||
|
|
||||||
Companion runtime helper:
|
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:
|
- `src/companion/platformClients.ts` provides platform-focused wrappers:
|
||||||
- `MacOSCompanionClient` (`platform: "macos"`, APNs push registration)
|
- `MacOSCompanionClient` (`platform: "macos"`, APNs push registration)
|
||||||
- `IOSCompanionClient` (`platform: "ios"`, APNs push registration)
|
- `IOSCompanionClient` (`platform: "ios"`, APNs push registration)
|
||||||
|
|||||||
@@ -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"
|
"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": {
|
"browser-tools-activation-clarity": {
|
||||||
"status": "completed",
|
"status": "completed",
|
||||||
"date": "2026-02-17",
|
"date": "2026-02-17",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export type {
|
|||||||
CompanionRuntimeClientOptions,
|
CompanionRuntimeClientOptions,
|
||||||
CompanionEventHandler,
|
CompanionEventHandler,
|
||||||
CompanionTypedEventHandler,
|
CompanionTypedEventHandler,
|
||||||
|
CompanionEventName,
|
||||||
CompanionEventPredicate,
|
CompanionEventPredicate,
|
||||||
CompanionEventEnvelope,
|
CompanionEventEnvelope,
|
||||||
RegisterNodeInput,
|
RegisterNodeInput,
|
||||||
|
|||||||
@@ -224,6 +224,18 @@ describe('CompanionRuntimeClient', () => {
|
|||||||
expect(typingHandler).toHaveBeenCalledWith({ active: true });
|
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', () => {
|
it('supports subscribeContextWarning helper', () => {
|
||||||
const client = new CompanionRuntimeClient({
|
const client = new CompanionRuntimeClient({
|
||||||
url: 'ws://127.0.0.1:1',
|
url: 'ws://127.0.0.1:1',
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ export const COMPANION_EVENT_NAMES = {
|
|||||||
agentTyping: 'agent.typing',
|
agentTyping: 'agent.typing',
|
||||||
contextWarning: 'context_warning',
|
contextWarning: 'context_warning',
|
||||||
} as const;
|
} as const;
|
||||||
|
export type CompanionEventName =
|
||||||
|
(typeof COMPANION_EVENT_NAMES)[keyof typeof COMPANION_EVENT_NAMES];
|
||||||
|
|
||||||
export interface RegisterNodeInput {
|
export interface RegisterNodeInput {
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
@@ -388,7 +390,7 @@ export class CompanionRuntimeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscribeEvent<TData = unknown>(
|
subscribeEvent<TData = unknown>(
|
||||||
eventName: string,
|
eventName: CompanionEventName | string,
|
||||||
handler: CompanionTypedEventHandler<TData>,
|
handler: CompanionTypedEventHandler<TData>,
|
||||||
): () => void {
|
): () => void {
|
||||||
return this.subscribeEvents((event, data) => {
|
return this.subscribeEvents((event, data) => {
|
||||||
@@ -418,7 +420,7 @@ export class CompanionRuntimeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
waitForEvent<TData = unknown>(
|
waitForEvent<TData = unknown>(
|
||||||
eventName: string,
|
eventName: CompanionEventName | string,
|
||||||
options?: {
|
options?: {
|
||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
predicate?: CompanionEventPredicate<TData>;
|
predicate?: CompanionEventPredicate<TData>;
|
||||||
@@ -480,7 +482,7 @@ export class CompanionRuntimeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
waitForAnyEvent<TData = unknown>(
|
waitForAnyEvent<TData = unknown>(
|
||||||
eventNames: readonly string[],
|
eventNames: readonly (CompanionEventName | string)[],
|
||||||
options?: {
|
options?: {
|
||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
predicate?: (event: string, data: TData) => boolean;
|
predicate?: (event: string, data: TData) => boolean;
|
||||||
@@ -573,6 +575,10 @@ export class CompanionRuntimeClient {
|
|||||||
return this.waitForEvent<TData>(COMPANION_EVENT_NAMES.contextWarning, options);
|
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> {
|
async call<T>(method: string, params?: Record<string, unknown>): Promise<T> {
|
||||||
if (!this.connected) {
|
if (!this.connected) {
|
||||||
if (!this.autoConnect) {
|
if (!this.autoConnect) {
|
||||||
|
|||||||
Reference in New Issue
Block a user