fix: harden assistant interactive tools
This commit is contained in:
1 parent
38440a2e57
commit
3faac7a96d
9 files changed
+134
-17
No files matched your search
@@ -2,8 +2,8 @@
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { ToolCallMessagePartProps, ToolCallMessagePartStatus } 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 { Alert, Box, Button, Group, Skeleton, Stack, Text, TextInput, ThemeIcon } from "@mantine/core";
|
||||
import { IconAlertTriangle, IconCheck, IconMessageQuestion, IconPencil, IconX } from "@tabler/icons-react";
|
||||
import type { z } from "zod/v4";
|
||||
|
||||
import { AppForm } from "@homarr/forms-collection";
|
||||
@@ -11,7 +11,7 @@ import { useScopedI18n } from "@homarr/translation/client";
|
||||
import type { appManageSchema } from "@homarr/validation/app";
|
||||
|
||||
import classes from "./assistant-panel.module.css";
|
||||
import { hasCompleteAssistantToolArguments } from "./assistant-human-tool-status";
|
||||
import { hasCompleteAssistantToolArguments, hasFailedAssistantToolArguments } from "./assistant-human-tool-status";
|
||||
import { normalizeAssistantAppIconUrl } from "./assistant-tool-contracts";
|
||||
import type { AskUserArgs, AskUserResult, ConfigureAppArgs } from "./assistant-tool-contracts";
|
||||
|
||||
@@ -30,6 +30,15 @@ export const getAssistantAppFormValues = (
|
||||
status: ToolCallMessagePartStatus | undefined,
|
||||
) => (hasCompleteAssistantToolArguments(status) ? toAssistantAppValues(args) : null);
|
||||
|
||||
export const AssistantHumanToolError = () => {
|
||||
const t = useScopedI18n("common.assistant.toolPreparationError");
|
||||
return (
|
||||
<Alert color="red" variant="light" title={t("title")} icon={<IconAlertTriangle size={18} />}>
|
||||
{t("description")}
|
||||
</Alert>
|
||||
);
|
||||
};
|
||||
|
||||
export const AssistantAskUserTool = ({
|
||||
args,
|
||||
result,
|
||||
@@ -65,7 +74,9 @@ export const AssistantAskUserTool = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasCompleteAssistantToolArguments(status) || !args?.question || options.length < 2) {
|
||||
if (hasFailedAssistantToolArguments(status)) return <AssistantHumanToolError />;
|
||||
|
||||
if (!hasCompleteAssistantToolArguments(status)) {
|
||||
return (
|
||||
<Box className={classes.humanTool} aria-label={t("preparing")}>
|
||||
<Stack gap="xs">
|
||||
@@ -77,6 +88,8 @@ export const AssistantAskUserTool = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (!args?.question || options.length < 2) return <AssistantHumanToolError />;
|
||||
|
||||
const submitResult = (answer: AskUserResult) => {
|
||||
if (submitting) return;
|
||||
setSubmitting(true);
|
||||
@@ -212,6 +225,8 @@ export const AssistantConfigureAppTool = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (hasFailedAssistantToolArguments(status)) return <AssistantHumanToolError />;
|
||||
|
||||
if (initialValues === null) {
|
||||
return (
|
||||
<Box className={classes.appTool} aria-label={t("preparing")}>
|
||||
|
||||
Reference in new issue
Block a user