improve assistant question placement
This commit is contained in:
1 parent
454a35d1a9
commit
3d7c95ddcc
7 files changed
+300
-154
No files matched your search
@@ -145,7 +145,9 @@ floating assistant are visible.
|
|||||||
When the assistant genuinely needs missing information or a choice, it can pause with a structured
|
When the assistant genuinely needs missing information or a choice, it can pause with a structured
|
||||||
question. Each proposed answer is visibly categorized as **Confirm**, **Decline**, or **Option**, so the effect
|
question. Each proposed answer is visibly categorized as **Confirm**, **Decline**, or **Option**, so the effect
|
||||||
of automatic approval is unambiguous. Users can select one of the proposed answers or choose **Other** and
|
of automatic approval is unambiguous. Users can select one of the proposed answers or choose **Other** and
|
||||||
enter their own response.
|
enter their own response. While a question is unanswered, its controls stay in a dedicated area immediately
|
||||||
|
above the composer instead of requiring the user to find the tool call in the transcript. The answered choice
|
||||||
|
then remains in the conversation history.
|
||||||
Submitting the answer resumes the same agent run automatically. The minimized activity bar shows the
|
Submitting the answer resumes the same agent run automatically. The minimized activity bar shows the
|
||||||
question or approval that needs attention and opens directly back to the request. While an answer, app
|
question or approval that needs attention and opens directly back to the request. While an answer, app
|
||||||
form, or mutation approval is pending, the composer preserves its draft but does not replace the pending
|
form, or mutation approval is pending, the composer preserves its draft but does not replace the pending
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ active conversation silently: select **Open conversation** inside the widget bef
|
|||||||
- Mention permitted apps, integrations, boards, widgets, and tools with `@`.
|
- Mention permitted apps, integrations, boards, widgets, and tools with `@`.
|
||||||
- Use `/` shortcuts for common dashboard tasks.
|
- Use `/` shortcuts for common dashboard tasks.
|
||||||
- Review tool calls, approve mutations, and answer structured assistant questions inline.
|
- Review tool calls, approve mutations, and answer structured assistant questions inline.
|
||||||
|
- Answer pending structured questions from the dock above the composer without scrolling through the conversation.
|
||||||
- Enable conversation-scoped automatic approvals from the shield control to approve protected mutations, use presented form details, and choose answers categorized as affirmative without individual clicks.
|
- Enable conversation-scoped automatic approvals from the shield control to approve protected mutations, use presented form details, and choose answers categorized as affirmative without individual clicks.
|
||||||
- Edit user messages and copy, regenerate, branch, quote, export, or rate responses.
|
- Edit user messages and copy, regenerate, branch, quote, export, or rate responses.
|
||||||
- Inspect Markdown, sources, generated files, tool results, reasoning, token use, context-window use, timing,
|
- Inspect Markdown, sources, generated files, tool results, reasoning, token use, context-window use, timing,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { getAssistantAffirmativeResult, getAssistantAskUserOptionKind } from "./
|
|||||||
import { useAssistantAutomaticAction } from "./assistant-auto-approval";
|
import { useAssistantAutomaticAction } from "./assistant-auto-approval";
|
||||||
import { AssistantAutomaticActionProgress } from "./assistant-automatic-action-progress";
|
import { AssistantAutomaticActionProgress } from "./assistant-automatic-action-progress";
|
||||||
import classes from "./assistant-panel.module.css";
|
import classes from "./assistant-panel.module.css";
|
||||||
|
import { AssistantPendingQuestionPortal } from "./assistant-question-portal";
|
||||||
import { hasCompleteAssistantToolArguments, hasFailedAssistantToolArguments } from "./assistant-human-tool-status";
|
import { hasCompleteAssistantToolArguments, hasFailedAssistantToolArguments } from "./assistant-human-tool-status";
|
||||||
import { normalizeAssistantAppIconUrl } from "./assistant-tool-contracts";
|
import { normalizeAssistantAppIconUrl } from "./assistant-tool-contracts";
|
||||||
import type { AskUserArgs, AskUserResult, ConfigureAppArgs } from "./assistant-tool-contracts";
|
import type { AskUserArgs, AskUserResult, ConfigureAppArgs } from "./assistant-tool-contracts";
|
||||||
@@ -101,17 +102,25 @@ export const AssistantAskUserTool = ({
|
|||||||
|
|
||||||
if (!hasCompleteAssistantToolArguments(status)) {
|
if (!hasCompleteAssistantToolArguments(status)) {
|
||||||
return (
|
return (
|
||||||
<Box className={classes.humanTool} aria-label={t("preparing")}>
|
<AssistantPendingQuestionPortal>
|
||||||
<Stack gap="xs">
|
<Box className={classes.humanTool} aria-label={t("preparing")}>
|
||||||
<Skeleton height={18} width="62%" />
|
<Stack gap="xs">
|
||||||
<Skeleton height={52} />
|
<Skeleton height={18} width="62%" />
|
||||||
<Skeleton height={52} />
|
<Skeleton height={52} />
|
||||||
</Stack>
|
<Skeleton height={52} />
|
||||||
</Box>
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
</AssistantPendingQuestionPortal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args?.question || options.length < 2) return <AssistantHumanToolError />;
|
if (!args?.question || options.length < 2) {
|
||||||
|
return (
|
||||||
|
<AssistantPendingQuestionPortal>
|
||||||
|
<AssistantHumanToolError />
|
||||||
|
</AssistantPendingQuestionPortal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const submitResult = (answer: AskUserResult) => {
|
const submitResult = (answer: AskUserResult) => {
|
||||||
if (submitting) return;
|
if (submitting) return;
|
||||||
@@ -126,128 +135,130 @@ export const AssistantAskUserTool = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className={classes.humanTool}>
|
<AssistantPendingQuestionPortal>
|
||||||
<Group align="flex-start" wrap="nowrap" gap="sm">
|
<Box className={classes.humanTool}>
|
||||||
<ThemeIcon size="lg" radius="xl" variant="light" color="red">
|
<Group align="flex-start" wrap="nowrap" gap="sm">
|
||||||
<IconMessageQuestion size={18} />
|
<ThemeIcon size="lg" radius="xl" variant="light" color="red">
|
||||||
</ThemeIcon>
|
<IconMessageQuestion size={18} />
|
||||||
<Box flex={1} miw={0}>
|
</ThemeIcon>
|
||||||
<Text fw={700} className={classes.humanToolQuestion}>
|
<Box flex={1} miw={0}>
|
||||||
{args.question}
|
<Text fw={700} className={classes.humanToolQuestion}>
|
||||||
</Text>
|
{args.question}
|
||||||
{args.description && (
|
|
||||||
<Text size="sm" c="dimmed" mt={3}>
|
|
||||||
{args.description}
|
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
{args.description && (
|
||||||
</Box>
|
<Text size="sm" c="dimmed" mt={3}>
|
||||||
</Group>
|
{args.description}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Group>
|
||||||
|
|
||||||
<Stack gap="xs" mt="md">
|
<Stack gap="xs" mt="md">
|
||||||
{autoConfirming ? (
|
{autoConfirming ? (
|
||||||
<AssistantAutomaticActionProgress label={t("automaticAffirmative")} />
|
<AssistantAutomaticActionProgress label={t("automaticAffirmative")} />
|
||||||
) : (
|
) : (
|
||||||
options.map((option, index) => {
|
options.map((option, index) => {
|
||||||
const kind = getAssistantAskUserOptionKind(option);
|
const kind = getAssistantAskUserOptionKind(option);
|
||||||
const icon =
|
const icon =
|
||||||
kind === "affirmative" ? (
|
kind === "affirmative" ? (
|
||||||
<IconCheck size={17} />
|
<IconCheck size={17} />
|
||||||
) : kind === "negative" ? (
|
) : kind === "negative" ? (
|
||||||
<IconX size={17} />
|
<IconX size={17} />
|
||||||
) : (
|
) : (
|
||||||
<IconArrowRight size={17} />
|
<IconArrowRight size={17} />
|
||||||
|
);
|
||||||
|
const color = kind === "affirmative" ? "green" : kind === "negative" ? "red" : "gray";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
key={`${option.id}:${index}`}
|
||||||
|
className={classes.humanToolOption}
|
||||||
|
variant={kind === "alternative" ? "default" : "light"}
|
||||||
|
color={color}
|
||||||
|
size="md"
|
||||||
|
fullWidth
|
||||||
|
justify="space-between"
|
||||||
|
leftSection={icon}
|
||||||
|
rightSection={
|
||||||
|
<Badge variant="light" color={color} size="xs">
|
||||||
|
{t(`optionKind.${kind}`)}
|
||||||
|
</Badge>
|
||||||
|
}
|
||||||
|
disabled={submitting}
|
||||||
|
onClick={() =>
|
||||||
|
submitResult({ answer: option.label, optionId: option.id, optionKind: kind, source: "option" })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Box ta="start">
|
||||||
|
<Text component="span" size="sm" fw={650}>
|
||||||
|
{option.label}
|
||||||
|
</Text>
|
||||||
|
{option.description && (
|
||||||
|
<Text component="span" display="block" size="xs" c="dimmed" fw={400}>
|
||||||
|
{option.description}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</Button>
|
||||||
);
|
);
|
||||||
const color = kind === "affirmative" ? "green" : kind === "negative" ? "red" : "gray";
|
})
|
||||||
|
)}
|
||||||
|
|
||||||
return (
|
{!autoConfirming &&
|
||||||
|
args.allowOther !== false &&
|
||||||
|
(showOther ? (
|
||||||
|
<Group align="flex-end" gap="xs" wrap="nowrap">
|
||||||
|
<TextInput
|
||||||
|
ref={otherInputRef}
|
||||||
|
className={classes.humanToolOtherInput}
|
||||||
|
value={other}
|
||||||
|
onChange={(event) => setOther(event.currentTarget.value)}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === "Enter" && !event.nativeEvent.isComposing) {
|
||||||
|
event.preventDefault();
|
||||||
|
submitOther();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
label={t("otherLabel")}
|
||||||
|
placeholder={t("otherPlaceholder")}
|
||||||
|
/>
|
||||||
|
<Button size="md" onClick={submitOther} disabled={!other.trim() || submitting} loading={submitting}>
|
||||||
|
{t("submit")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="md"
|
||||||
|
variant="default"
|
||||||
|
px="sm"
|
||||||
|
aria-label={t("cancelOther")}
|
||||||
|
onClick={() => {
|
||||||
|
setShowOther(false);
|
||||||
|
setOther("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconX size={17} />
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
key={`${option.id}:${index}`}
|
|
||||||
className={classes.humanToolOption}
|
className={classes.humanToolOption}
|
||||||
variant={kind === "alternative" ? "default" : "light"}
|
variant="default"
|
||||||
color={color}
|
|
||||||
size="md"
|
size="md"
|
||||||
fullWidth
|
fullWidth
|
||||||
justify="space-between"
|
leftSection={<IconPencil size={17} />}
|
||||||
leftSection={icon}
|
|
||||||
rightSection={
|
rightSection={
|
||||||
<Badge variant="light" color={color} size="xs">
|
<Badge variant="light" color="gray" size="xs">
|
||||||
{t(`optionKind.${kind}`)}
|
{t("optionKind.custom")}
|
||||||
</Badge>
|
</Badge>
|
||||||
}
|
}
|
||||||
disabled={submitting}
|
justify="flex-start"
|
||||||
onClick={() =>
|
onClick={() => setShowOther(true)}
|
||||||
submitResult({ answer: option.label, optionId: option.id, optionKind: kind, source: "option" })
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Box ta="start">
|
{t("other")}
|
||||||
<Text component="span" size="sm" fw={650}>
|
|
||||||
{option.label}
|
|
||||||
</Text>
|
|
||||||
{option.description && (
|
|
||||||
<Text component="span" display="block" size="xs" c="dimmed" fw={400}>
|
|
||||||
{option.description}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
</Button>
|
</Button>
|
||||||
);
|
))}
|
||||||
})
|
</Stack>
|
||||||
)}
|
</Box>
|
||||||
|
</AssistantPendingQuestionPortal>
|
||||||
{!autoConfirming &&
|
|
||||||
args.allowOther !== false &&
|
|
||||||
(showOther ? (
|
|
||||||
<Group align="flex-end" gap="xs" wrap="nowrap">
|
|
||||||
<TextInput
|
|
||||||
ref={otherInputRef}
|
|
||||||
className={classes.humanToolOtherInput}
|
|
||||||
value={other}
|
|
||||||
onChange={(event) => setOther(event.currentTarget.value)}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
if (event.key === "Enter" && !event.nativeEvent.isComposing) {
|
|
||||||
event.preventDefault();
|
|
||||||
submitOther();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
label={t("otherLabel")}
|
|
||||||
placeholder={t("otherPlaceholder")}
|
|
||||||
/>
|
|
||||||
<Button size="md" onClick={submitOther} disabled={!other.trim() || submitting} loading={submitting}>
|
|
||||||
{t("submit")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="md"
|
|
||||||
variant="default"
|
|
||||||
px="sm"
|
|
||||||
aria-label={t("cancelOther")}
|
|
||||||
onClick={() => {
|
|
||||||
setShowOther(false);
|
|
||||||
setOther("");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IconX size={17} />
|
|
||||||
</Button>
|
|
||||||
</Group>
|
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
className={classes.humanToolOption}
|
|
||||||
variant="default"
|
|
||||||
size="md"
|
|
||||||
fullWidth
|
|
||||||
leftSection={<IconPencil size={17} />}
|
|
||||||
rightSection={
|
|
||||||
<Badge variant="light" color="gray" size="xs">
|
|
||||||
{t("optionKind.custom")}
|
|
||||||
</Badge>
|
|
||||||
}
|
|
||||||
justify="flex-start"
|
|
||||||
onClick={() => setShowOther(true)}
|
|
||||||
>
|
|
||||||
{t("other")}
|
|
||||||
</Button>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -572,6 +572,31 @@
|
|||||||
background: var(--mantine-color-yellow-light);
|
background: var(--mantine-color-yellow-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pendingQuestionDock {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
max-height: min(22rem, 50cqh);
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
padding: 0.65rem 0.75rem 0.35rem;
|
||||||
|
border-top: 1px solid var(--mantine-color-default-border);
|
||||||
|
background: var(--mantine-color-body);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pendingQuestionTarget {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 44rem;
|
||||||
|
margin-inline: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pendingQuestionTarget .humanTool {
|
||||||
|
margin-block: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pendingQuestionDock + .composerWrap {
|
||||||
|
padding-top: 0.35rem;
|
||||||
|
border-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.humanTool,
|
.humanTool,
|
||||||
.appTool {
|
.appTool {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ import { useAssistantAutoApproval, useAssistantAutomaticAction } from "./assista
|
|||||||
import { normalizeAssistantMarkdown } from "./assistant-markdown";
|
import { normalizeAssistantMarkdown } from "./assistant-markdown";
|
||||||
import { getAssistantTelemetry, getAssistantUsage } from "./assistant-message-metadata";
|
import { getAssistantTelemetry, getAssistantUsage } from "./assistant-message-metadata";
|
||||||
import type { AssistantPendingAction } from "./assistant-pending-action";
|
import type { AssistantPendingAction } from "./assistant-pending-action";
|
||||||
|
import { AssistantQuestionPortalProvider } from "./assistant-question-portal";
|
||||||
import type { AssistantReasoningMode, AssistantRuntimeModelOption } from "./assistant-preferences";
|
import type { AssistantReasoningMode, AssistantRuntimeModelOption } from "./assistant-preferences";
|
||||||
import { getNearestTriggerScrollTop } from "./assistant-trigger-scroll";
|
import { getNearestTriggerScrollTop } from "./assistant-trigger-scroll";
|
||||||
import { getToolResultPresentation } from "./assistant-tool-result";
|
import { getToolResultPresentation } from "./assistant-tool-result";
|
||||||
@@ -1851,7 +1852,7 @@ const usePendingActionCopy = (action: AssistantPendingAction | undefined) => {
|
|||||||
const PendingActionBanner = ({ pendingAction }: { pendingAction: AssistantPendingAction | undefined }) => {
|
const PendingActionBanner = ({ pendingAction }: { pendingAction: AssistantPendingAction | undefined }) => {
|
||||||
const t = useScopedI18n("common.assistant");
|
const t = useScopedI18n("common.assistant");
|
||||||
const copy = usePendingActionCopy(pendingAction);
|
const copy = usePendingActionCopy(pendingAction);
|
||||||
if (!copy) return null;
|
if (!copy || pendingAction?.kind === "question") return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box component="output" className={classes.pendingActionBanner}>
|
<Box component="output" className={classes.pendingActionBanner}>
|
||||||
@@ -1877,6 +1878,23 @@ const PendingActionBanner = ({ pendingAction }: { pendingAction: AssistantPendin
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PendingQuestionDock = ({
|
||||||
|
pendingAction,
|
||||||
|
setTarget,
|
||||||
|
}: {
|
||||||
|
pendingAction: AssistantPendingAction | undefined;
|
||||||
|
setTarget: (target: HTMLDivElement | null) => void;
|
||||||
|
}) => {
|
||||||
|
const t = useScopedI18n("common.assistant");
|
||||||
|
if (pendingAction?.kind !== "question") return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box component="section" className={classes.pendingQuestionDock} aria-label={t("pendingAction.answerTitle")}>
|
||||||
|
<div ref={setTarget} className={classes.pendingQuestionTarget} />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const AssistantActivityBar = ({
|
const AssistantActivityBar = ({
|
||||||
isRunning,
|
isRunning,
|
||||||
unreadCount,
|
unreadCount,
|
||||||
@@ -2003,6 +2021,7 @@ export const AssistantConversationSurface = ({
|
|||||||
onMinimize,
|
onMinimize,
|
||||||
}: AssistantConversationSurfaceProps) => {
|
}: AssistantConversationSurfaceProps) => {
|
||||||
const t = useScopedI18n("common.assistant");
|
const t = useScopedI18n("common.assistant");
|
||||||
|
const [questionPortalTarget, setQuestionPortalTarget] = useState<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -2063,41 +2082,44 @@ export const AssistantConversationSurface = ({
|
|||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
<ThreadPrimitive.Root className={classes.thread}>
|
<AssistantQuestionPortalProvider target={questionPortalTarget}>
|
||||||
<ThreadPrimitive.Viewport className={classes.viewport}>
|
<ThreadPrimitive.Root className={classes.thread}>
|
||||||
<Box className={classes.messages}>
|
<ThreadPrimitive.Viewport className={classes.viewport}>
|
||||||
<EmptyThread />
|
<Box className={classes.messages}>
|
||||||
<ThreadPrimitive.Messages components={{ UserMessage, AssistantMessage }} />
|
<EmptyThread />
|
||||||
</Box>
|
<ThreadPrimitive.Messages components={{ UserMessage, AssistantMessage }} />
|
||||||
<SelectionToolbarPrimitive.Root className={classes.selectionToolbar}>
|
</Box>
|
||||||
<SelectionToolbarPrimitive.Quote asChild>
|
<SelectionToolbarPrimitive.Root className={classes.selectionToolbar}>
|
||||||
<Button variant="filled" color="dark" size="compact-sm" leftSection={<IconQuote size={14} />}>
|
<SelectionToolbarPrimitive.Quote asChild>
|
||||||
{t("quoteSelection")}
|
<Button variant="filled" color="dark" size="compact-sm" leftSection={<IconQuote size={14} />}>
|
||||||
</Button>
|
{t("quoteSelection")}
|
||||||
</SelectionToolbarPrimitive.Quote>
|
</Button>
|
||||||
</SelectionToolbarPrimitive.Root>
|
</SelectionToolbarPrimitive.Quote>
|
||||||
<ThreadPrimitive.ScrollToBottom asChild>
|
</SelectionToolbarPrimitive.Root>
|
||||||
<ActionIcon
|
<ThreadPrimitive.ScrollToBottom asChild>
|
||||||
className={classes.scrollToBottom}
|
<ActionIcon
|
||||||
variant="default"
|
className={classes.scrollToBottom}
|
||||||
radius="xl"
|
variant="default"
|
||||||
aria-label={t("scrollToLatest")}
|
radius="xl"
|
||||||
>
|
aria-label={t("scrollToLatest")}
|
||||||
<IconArrowUp size={16} style={{ transform: "rotate(180deg)" }} />
|
>
|
||||||
</ActionIcon>
|
<IconArrowUp size={16} style={{ transform: "rotate(180deg)" }} />
|
||||||
</ThreadPrimitive.ScrollToBottom>
|
</ActionIcon>
|
||||||
</ThreadPrimitive.Viewport>
|
</ThreadPrimitive.ScrollToBottom>
|
||||||
<PendingActionBanner pendingAction={pendingAction} />
|
</ThreadPrimitive.Viewport>
|
||||||
<Composer
|
<PendingQuestionDock pendingAction={pendingAction} setTarget={setQuestionPortalTarget} />
|
||||||
modelId={modelId}
|
<PendingActionBanner pendingAction={pendingAction} />
|
||||||
models={models}
|
<Composer
|
||||||
modelOptionsLoading={modelOptionsLoading}
|
modelId={modelId}
|
||||||
reasoning={reasoning}
|
models={models}
|
||||||
onModelChange={onModelChange}
|
modelOptionsLoading={modelOptionsLoading}
|
||||||
onReasoningChange={onReasoningChange}
|
reasoning={reasoning}
|
||||||
pendingAction={pendingAction}
|
onModelChange={onModelChange}
|
||||||
/>
|
onReasoningChange={onReasoningChange}
|
||||||
</ThreadPrimitive.Root>
|
pendingAction={pendingAction}
|
||||||
|
/>
|
||||||
|
</ThreadPrimitive.Root>
|
||||||
|
</AssistantQuestionPortalProvider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
// @vitest-environment jsdom
|
||||||
|
|
||||||
|
import { act, createElement, useState } from "react";
|
||||||
|
import { createRoot } from "react-dom/client";
|
||||||
|
import { afterEach, describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import { AssistantPendingQuestionPortal, AssistantQuestionPortalProvider } from "./assistant-question-portal";
|
||||||
|
|
||||||
|
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||||
|
|
||||||
|
const containers: HTMLDivElement[] = [];
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const container of containers.splice(0)) container.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
const QuestionSurface = () => {
|
||||||
|
const [target, setTarget] = useState<HTMLDivElement | null>(null);
|
||||||
|
return createElement(
|
||||||
|
AssistantQuestionPortalProvider,
|
||||||
|
{ target },
|
||||||
|
createElement(
|
||||||
|
"div",
|
||||||
|
{ "data-testid": "transcript" },
|
||||||
|
createElement(AssistantPendingQuestionPortal, null, "Question"),
|
||||||
|
),
|
||||||
|
createElement("div", { "data-testid": "dock", ref: setTarget }),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("AssistantPendingQuestionPortal", () => {
|
||||||
|
test("keeps the question visible when a surface has no composer dock", async () => {
|
||||||
|
const container = document.createElement("div");
|
||||||
|
containers.push(container);
|
||||||
|
document.body.append(container);
|
||||||
|
const root = createRoot(container);
|
||||||
|
|
||||||
|
await act(async () =>
|
||||||
|
root.render(
|
||||||
|
createElement(
|
||||||
|
AssistantQuestionPortalProvider,
|
||||||
|
{ target: null },
|
||||||
|
createElement(AssistantPendingQuestionPortal, null, "Question"),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(container.textContent).toBe("Question");
|
||||||
|
|
||||||
|
await act(async () => root.unmount());
|
||||||
|
});
|
||||||
|
|
||||||
|
test("moves one pending question from the transcript into the composer dock", async () => {
|
||||||
|
const container = document.createElement("div");
|
||||||
|
containers.push(container);
|
||||||
|
document.body.append(container);
|
||||||
|
const root = createRoot(container);
|
||||||
|
|
||||||
|
await act(async () => root.render(createElement(QuestionSurface)));
|
||||||
|
|
||||||
|
expect(container.querySelector('[data-testid="transcript"]')?.textContent).toBe("");
|
||||||
|
expect(container.querySelector('[data-testid="dock"]')?.textContent).toBe("Question");
|
||||||
|
|
||||||
|
await act(async () => root.unmount());
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type { PropsWithChildren, ReactNode } from "react";
|
||||||
|
import { createContext, useContext } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
|
||||||
|
const AssistantQuestionPortalContext = createContext<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
export const AssistantQuestionPortalProvider = ({
|
||||||
|
children,
|
||||||
|
target,
|
||||||
|
}: PropsWithChildren<{ target: HTMLElement | null }>) => (
|
||||||
|
<AssistantQuestionPortalContext.Provider value={target}>{children}</AssistantQuestionPortalContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
export const AssistantPendingQuestionPortal = ({ children }: { children: ReactNode }) => {
|
||||||
|
const target = useContext(AssistantQuestionPortalContext);
|
||||||
|
return target ? createPortal(children, target) : children;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user