Files
yaak/apps/yaak-proxy/hooks/useActionMetadata.ts
Gregory Schier 7314aedc71 Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 12:09:59 -07:00

31 lines
962 B
TypeScript

import type { ActionInvocation, ActionMetadata } from "@yaakapp-internal/proxy-lib";
import { useEffect, useState } from "react";
import { rpc } from "../lib/rpc";
/** Look up metadata for a specific action invocation. */
export function useActionMetadata(action: ActionInvocation): ActionMetadata | null {
const [meta, setMeta] = useState<ActionMetadata | null>(null);
useEffect(() => {
getActions().then((actions) => {
const match = actions.find(
([inv]) => inv.scope === action.scope && inv.action === action.action,
);
setMeta(match?.[1] ?? null);
});
}, [action]);
return meta;
}
let cachedActions: [ActionInvocation, ActionMetadata][] | null = null;
/** Fetch and cache all action metadata. */
async function getActions(): Promise<[ActionInvocation, ActionMetadata][]> {
if (!cachedActions) {
const { actions } = await rpc("list_actions", {});
cachedActions = actions;
}
return cachedActions;
}