diff --git a/packages/hub/src/types/messages.ts b/packages/hub/src/types/messages.ts index d5e63b71..d64c3dcb 100644 --- a/packages/hub/src/types/messages.ts +++ b/packages/hub/src/types/messages.ts @@ -40,7 +40,23 @@ export interface DevframeMessageActivateAction { activate: { dockId: string, params?: Record } } -export type DevframeMessageAction = DevframeMessageActivateAction +/** + * `'command'` invokes a command from the hub's command registry (the same + * registry backing the command palette) by `command.id`, spreading + * `command.params` as its positional arguments, via the hub's + * `hub:commands:execute` RPC. + */ +export interface DevframeMessageCommandAction { + /** Stable id for the action within its entry. */ + id: string + /** Button label shown in the messages panel. */ + label: string + kind: 'command' + /** The command to invoke, plus an optional list of positional arguments. */ + command: { id: string, params?: unknown[] } +} + +export type DevframeMessageAction = DevframeMessageActivateAction | DevframeMessageCommandAction export interface DevframeMessageEntry { /** diff --git a/plugins/messages/src/client/App.vue b/plugins/messages/src/client/App.vue index 0fcd664a..955ba2ab 100644 --- a/plugins/messages/src/client/App.vue +++ b/plugins/messages/src/client/App.vue @@ -69,12 +69,13 @@ onMounted(() => { }) async function onActivate(action: DevframeMessageAction): Promise { - if (action.kind !== 'activate') + const callOptional = props.rpc.callOptional as (name: string, ...args: unknown[]) => Promise + if (action.kind === 'activate') { + await callOptional('hub:docks:activate', action.activate) return - await (props.rpc.callOptional as (name: string, ...args: unknown[]) => Promise)( - 'hub:docks:activate', - action.activate, - ) + } + if (action.kind === 'command') + await callOptional('hub:commands:execute', action.command.id, ...(action.command.params ?? [])) } async function onDismiss(id: string): Promise { diff --git a/tests/__snapshots__/tsnapi/@devframes/hub/index.snapshot.d.ts b/tests/__snapshots__/tsnapi/@devframes/hub/index.snapshot.d.ts index 9d94c09b..6bb10216 100644 --- a/tests/__snapshots__/tsnapi/@devframes/hub/index.snapshot.d.ts +++ b/tests/__snapshots__/tsnapi/@devframes/hub/index.snapshot.d.ts @@ -141,6 +141,15 @@ export interface DevframeMessageActivateAction { params?: Record; }; } +export interface DevframeMessageCommandAction { + id: string; + label: string; + kind: 'command'; + command: { + id: string; + params?: unknown[]; + }; +} export interface DevframeMessageElementPosition { selector?: string; boundingBox?: { @@ -337,7 +346,7 @@ export type DevframeDockEntryIcon = string | { dark: string; }; export type DevframeDockUserEntry = DevframeDockEntryRegistry[keyof DevframeDockEntryRegistry]; -export type DevframeMessageAction = DevframeMessageActivateAction; +export type DevframeMessageAction = DevframeMessageActivateAction | DevframeMessageCommandAction; export type DevframeMessageEntryFrom = 'server' | 'browser'; export type DevframeMessageEntryInput = Omit & { id?: string; diff --git a/tests/__snapshots__/tsnapi/@devframes/hub/types.snapshot.d.ts b/tests/__snapshots__/tsnapi/@devframes/hub/types.snapshot.d.ts index e22809a7..fae942b8 100644 --- a/tests/__snapshots__/tsnapi/@devframes/hub/types.snapshot.d.ts +++ b/tests/__snapshots__/tsnapi/@devframes/hub/types.snapshot.d.ts @@ -37,6 +37,7 @@ export { DevframeHost } export { DevframeHubContext } export { DevframeMessageAction } export { DevframeMessageActivateAction } +export { DevframeMessageCommandAction } export { DevframeMessageElementPosition } export { DevframeMessageEntry } export { DevframeMessageEntryFrom }