feat(companion): add known event name typing and listing
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user