feat(companion): add known event name typing and listing
This commit is contained in:
@@ -14,6 +14,7 @@ export type {
|
||||
CompanionRuntimeClientOptions,
|
||||
CompanionEventHandler,
|
||||
CompanionTypedEventHandler,
|
||||
CompanionEventName,
|
||||
CompanionEventPredicate,
|
||||
CompanionEventEnvelope,
|
||||
RegisterNodeInput,
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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