diff --git a/pkgs/clan-cli/clan_cli/api/modules.py b/pkgs/clan-cli/clan_cli/api/modules.py index d09da67c5..88048bc66 100644 --- a/pkgs/clan-cli/clan_cli/api/modules.py +++ b/pkgs/clan-cli/clan_cli/api/modules.py @@ -163,6 +163,28 @@ def get_modules(base_path: str) -> dict[str, str]: return modules +@API.register +def get_module_interface(base_path: str, module_name: str) -> dict[str, Any]: + """ + Check if a module exists and returns the interface schema + Returns an error if the module does not exist or has an incorrect interface + """ + cmd = nix_eval([f"{base_path}#clanInternals.moduleSchemas.{module_name}", "--json"]) + try: + proc = run_no_stdout(cmd) + res = proc.stdout.strip() + except ClanCmdError as e: + msg = "clanInternals might not have moduleSchemas attributes" + raise ClanError( + msg, + location=f"list_modules {base_path}", + description="Evaluation failed on clanInternals.moduleSchemas attribute", + ) from e + modules_schema: dict[str, Any] = json.loads(res) + + return modules_schema + + @API.register def list_modules(base_path: str) -> dict[str, ModuleInfo]: """ diff --git a/pkgs/webview-ui/app/src/api_test.tsx b/pkgs/webview-ui/app/src/api_test.tsx new file mode 100644 index 000000000..0fc9a6648 --- /dev/null +++ b/pkgs/webview-ui/app/src/api_test.tsx @@ -0,0 +1,107 @@ +import { + createForm, + FieldValues, + getValues, + SubmitHandler, +} from "@modular-forms/solid"; +import { TextInput } from "./components/TextInput"; +import { Button } from "./components/button"; +import { callApi } from "./api"; +import { API } from "@/api/API"; +import { createSignal, Match, Switch } from "solid-js"; +import { Typography } from "./components/Typography"; +import { createQuery } from "@tanstack/solid-query"; +import { makePersisted } from "@solid-primitives/storage"; + +interface APITesterForm extends FieldValues { + endpoint: string; + payload: string; +} + +export const ApiTester = () => { + const [persistedTestData, setPersistedTestData] = makePersisted( + createSignal(), + { + name: "_test_data", + storage: localStorage, + }, + ); + + const [formStore, { Form, Field }] = createForm({ + initialValues: persistedTestData(), + }); + + const query = createQuery(() => ({ + // eslint-disable-next-line @tanstack/query/exhaustive-deps + queryKey: [], + queryFn: async () => { + const values = getValues(formStore); + return await callApi( + values.endpoint as keyof API, + JSON.parse(values.payload || ""), + ); + }, + staleTime: Infinity, + })); + + const handleSubmit: SubmitHandler = (values) => { + console.log(values); + setPersistedTestData(values); + query.refetch(); + + const v = getValues(formStore); + console.log(v); + // const result = callApi( + // values.endpoint as keyof API, + // JSON.parse(values.payload) + // ); + // setResult(result); + }; + return ( +
+

API Tester

+
+
+ + {(field, fieldProps) => ( + + )} + + + {(field, fieldProps) => ( + + )} + + +
+
+
+ + Result + + + + loading ... + + +
+              {JSON.stringify(query.data, null, 2)}
+            
+
+
+
+
+ ); +}; diff --git a/pkgs/webview-ui/app/src/components/Sidebar/index.tsx b/pkgs/webview-ui/app/src/components/Sidebar/index.tsx index 8ba262499..896f2de55 100644 --- a/pkgs/webview-ui/app/src/components/Sidebar/index.tsx +++ b/pkgs/webview-ui/app/src/components/Sidebar/index.tsx @@ -69,7 +69,12 @@ export const Sidebar = (props: RouteSectionProps) => {