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
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) {