mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 10:51:57 +01:00
- Convert biome-ignore to oxlint-disable-next-line across client app - Fix no-base-to-string with type narrowing instead of suppressions - Fix no-floating-promises with fireAndForget() in proxy app - Fix restrict-template-expressions with String() wrapping - Resolve leftover merge conflict markers in manager.rs - Remove duplicate cmd_plugin_init_errors from lib.rs - Add graphql as explicit dependency in yaak-client Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
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. */
|
|
// oxlint-disable-next-line no-redundant-type-constituents -- ActionMetadata resolves at runtime
|
|
export function useActionMetadata(action: ActionInvocation): ActionMetadata | null {
|
|
// oxlint-disable-next-line no-redundant-type-constituents -- ActionMetadata resolves at runtime
|
|
const [meta, setMeta] = useState<ActionMetadata | null>(null);
|
|
|
|
useEffect(() => {
|
|
void 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;
|
|
}
|