Files
outline/app/hooks/useCommandBarActions.ts
T
Tom Moor a531c2b02e feat: WebMCP support (#13576)
* feat: WebMCP support — expose command bar actions as browser model context tools

* fix: Handle async rejection from WebMCP registerTool

* Surface errors

* Suppress action factories in webMCP
2026-09-03 01:36:05 -04:00

37 lines
1.0 KiB
TypeScript

import { useRegisterActions } from "kbar";
import { flattenDeep } from "es-toolkit/compat";
import { useLocation } from "react-router-dom";
import { actionToKBar } from "~/actions";
import type { ActionVariant } from "~/types";
import useActionContext from "./useActionContext";
import useWebMCPActions from "./useWebMCPActions";
/**
* Hook to add actions to the command bar while the hook is inside a mounted
* component. The same actions are also exposed as WebMCP tools in supported
* browsers.
*
* @param actions actions to make available
*/
export default function useCommandBarActions(
actions: ActionVariant[],
additionalDeps: React.DependencyList = []
) {
const location = useLocation();
const context = useActionContext({
isCommandBar: true,
});
useWebMCPActions(actions, additionalDeps);
const registerable = flattenDeep(
actions.map((action) => actionToKBar(action, context))
);
useRegisterActions(registerable, [
registerable.map((r) => r.id).join(""),
location.pathname,
...additionalDeps,
]);
}