"use client"; import { useEffect, useRef, useState } from "react"; import type { ToolCallMessagePartProps } from "@assistant-ui/react"; import { Box, Button, Group, Skeleton, Stack, Text, TextInput, ThemeIcon } from "@mantine/core"; import { IconCheck, IconMessageQuestion, IconPencil, IconX } from "@tabler/icons-react"; import type { z } from "zod/v4"; import { AppForm } from "@homarr/forms-collection"; import { useScopedI18n } from "@homarr/translation/client"; import type { appManageSchema } from "@homarr/validation/app"; import classes from "./assistant-panel.module.css"; import { normalizeAssistantAppIconUrl } from "./assistant-tool-contracts"; import type { AskUserArgs, AskUserResult, ConfigureAppArgs } from "./assistant-tool-contracts"; type AppValues = z.infer; const toAppValues = (args: ConfigureAppArgs | undefined): AppValues => ({ name: args?.name ?? "", description: args?.description ?? "", iconUrl: normalizeAssistantAppIconUrl(args?.iconUrl), href: args?.href ?? "", pingUrl: args?.pingUrl ?? "", }); export const AssistantAskUserTool = ({ args, result, addResult, }: ToolCallMessagePartProps) => { const t = useScopedI18n("common.assistant.askUser"); const [showOther, setShowOther] = useState(false); const [other, setOther] = useState(""); const otherInputRef = useRef(null); const options = Array.isArray(args?.options) ? args.options : []; useEffect(() => { if (showOther) otherInputRef.current?.focus(); }, [showOther]); if (result) { return ( {t("answered")} {result.answer} ); } if (!args?.question || options.length < 2) { return ( ); } const submitOther = () => { const answer = other.trim(); if (!answer) return; addResult({ answer, source: "other" }); }; return ( {args.question} {args.description && ( {args.description} )} {options.map((option, index) => ( ))} {args.allowOther !== false && (showOther ? ( setOther(event.currentTarget.value)} onKeyDown={(event) => { if (event.key === "Enter" && !event.nativeEvent.isComposing) { event.preventDefault(); submitOther(); } }} label={t("otherLabel")} placeholder={t("otherPlaceholder")} /> ) : ( ))} ); }; export const AssistantConfigureAppTool = ({ args, result, addResult, }: ToolCallMessagePartProps) => { const t = useScopedI18n("common.assistant.configureApp"); if (result) { return ( {t("ready")} {result.name} ); } return ( {t("title")} {t("description")} addResult(values)} isPending={false} /> ); };