π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π style: polish ask user question results (#17539)
YuTengjing90065efe2399
diff --git a/packages/builtin-tool-claude-code/src/client/Render/AskUserQuestion/index.tsx b/packages/builtin-tool-claude-code/src/client/Render/AskUserQuestion/index.tsxindex 540c1da7d7c..f9d5cdc6284 100644--- a/packages/builtin-tool-claude-code/src/client/Render/AskUserQuestion/index.tsx+++ b/packages/builtin-tool-claude-code/src/client/Render/AskUserQuestion/index.tsx@@ -1,243 +1,39 @@'use client';-import { normalizeAskUserQuestions } from '@lobechat/shared-tool-ui/ask-user';+import {+ AskUserQuestionResult,+ type AskUserQuestionResultState,+ normalizeAskUserQuestions,+ resolveAskUserAnswers,+} from '@lobechat/shared-tool-ui/ask-user';import type { BuiltinRenderProps } from '@lobechat/types';-import { Flexbox, Icon, Text } from '@lobehub/ui';-import { createStaticStyles } from 'antd-style';-import { Check, PenLine } from 'lucide-react';import { memo } from 'react';import { useTranslation } from 'react-i18next';-import type { AskUserQuestionArgs, AskUserQuestionItem } from '../../../types';--/** Persisted draft + answer shape stored on `pluginState`. */-interface AskUserQuestionState {- askUserAnswers?: Record<string, string | string[]>;- askUserDraft?: Record<string, string | string[]>;-}--const styles = createStaticStyles(({ css, cssVar }) => ({- answer: css`- font-size: 14px;- line-height: 1.5;- color: ${cssVar.colorText};- `,- check: css`- flex-shrink: 0;- margin-block-start: 4px;- color: ${cssVar.colorPrimary};- `,- container: css`- padding-block: 4px;- `,- description: css`- font-size: 13px;- line-height: 1.5;- color: ${cssVar.colorTextTertiary};- `,- divider: css`- align-self: stretch;- height: 1px;- margin-block: 4px;- background: ${cssVar.colorFillSecondary};- `,- /** The question's own short `header`, riding along the title line β costs no row. */- header: css`- flex-shrink: 0;-- padding-block: 1px;- padding-inline: 6px;- border-radius: 4px;-- font-size: 11px;- font-weight: 400;- color: ${cssVar.colorTextTertiary};- white-space: nowrap;-- background: ${cssVar.colorFillQuaternary};- `,- /** Ordinal rail. Its presence is what groups the blocks β hence no hairline. */- ordinal: css`- flex-shrink: 0;-- width: 22px;- padding-block-start: 2px;-- font-family: ${cssVar.fontFamilyCode};- font-size: 11px;- font-variant-numeric: tabular-nums;- line-height: 1.5;- color: ${cssVar.colorTextQuaternary};- `,- question: css`- font-size: 14px;- font-weight: 500;- line-height: 1.5;- color: ${cssVar.colorText};- `,- titleRow: css`- display: flex;- flex-wrap: wrap;- gap: 6px;- align-items: baseline;- `,- unanswered: css`- padding-inline-start: 22px;- font-size: 14px;- line-height: 1.5;- color: ${cssVar.colorTextQuaternary};- `,-}));--interface AnswerLineProps {- description?: string;- icon: typeof Check;- text: string;-}--const AnswerLine = memo<AnswerLineProps>(({ icon, text, description }) => (- <Flexbox horizontal align="flex-start" gap={8}>- <Icon className={styles.check} icon={icon} size={14} />- <Flexbox gap={1}>- <span className={styles.answer}>{text}</span>- {description && <span className={styles.description}>{description}</span>}- </Flexbox>- </Flexbox>-));--AnswerLine.displayName = 'CCAskUserAnswerLine';--interface QABlockProps {- answer?: string | string[];- /** 1-based ordinal, only passed when the form carries more than one question. */- index?: number;- question: AskUserQuestionItem;-}+import type { AskUserQuestionArgs } from '../../../types';/**- * One question/answer pair, laid out flat (no nested cards, no field labels): the- * question line, then the pick(s) beneath it as check-prefixed rows with their- * description underneath. Multi-select fans out into several rows.- *- * With more than one question, `index` turns on an ordinal rail (`Q1`, `Q2`) and- * the question's own `header` rides along the title line as a trailing chip. The- * rail is what separates the blocks β it doubles as the grouping signal, so no- * hairline is drawn between them. A lone question gets neither: `Q1` would imply a- * `Q2` that doesn't exist, and the Inspector already names it.+ * Claude Code host for the shared completed AskUserQuestion result.*- * When `answer` is absent β older messages persisted before structured storage β- * we show a muted placeholder so the row still reads as an answer slot.- */-const QABlock = memo<QABlockProps>(({ question, answer, index }) => {- const { t } = useTranslation('plugin');- const labels: string[] = Array.isArray(answer) ? answer : answer ? [answer] : [];- const optionByLabel = new Map(question.options.map((o) => [o.label, o]));-- return (- <Flexbox align="flex-start" horizontal={!!index}>- {!!index && <span className={styles.ordinal}>{`Q${index}`}</span>}- <Flexbox gap={6}>- <div className={index ? styles.titleRow : undefined}>- <span className={styles.question}>{question.question}</span>- {!!index && question.header && <span className={styles.header}>{question.header}</span>}- </div>- {labels.length > 0 ? (- <Flexbox gap={6}>- {labels.map((label) => {- const opt = optionByLabel.get(label);- return (- <AnswerLine- icon={Check}- key={label}- text={label}- description={- opt?.description && opt.description !== label ? opt.description : undefined- }- />- );- })}- </Flexbox>- ) : (- <span className={styles.unanswered}>- {t('builtins.lobe-claude-code.askUserQuestion.notAnswered')}- </span>- )}- </Flexbox>- </Flexbox>- );-});--QABlock.displayName = 'CCAskUserQuestionQABlock';--/**- * CC `askUserQuestion` Render β answered / aborted state only.- *- * The pending form lives on the canonical Intervention surface- * (`BuiltinToolInterventions['claude-code']['askUserQuestion']`) β the- * framework hides this Render while `pluginIntervention.status === 'pending'`,- * then yields to it once the user submits / skips and a `tool_result` arrives.- *- * Structured rendering reads `pluginState.askUserAnswers`, written by- * `setInterventionAnswers` in `conversationControl` at submit time. If the- * key is missing (older messages, or skipped/cancelled flows where there's- * nothing to show), we fall back to the question list with a status hint.- *- * Single-layer surface: the framework's tool card already provides the- * containing card, so this Render stays flat (no own background) to avoid the- * card-in-card look.+ * The interactive form remains an Intervention. Once resolved, every producer+ * (Claude Code, lobe-agent, and user-interaction) now uses the same read-only+ * question/answer hierarchy instead of diverging into bespoke or raw JSON UI.*/const AskUserQuestion = memo<- BuiltinRenderProps<AskUserQuestionArgs, AskUserQuestionState, unknown>->(({ args, pluginError, pluginState }) => {+ BuiltinRenderProps<AskUserQuestionArgs, AskUserQuestionResultState, string>+>(({ args, content, pluginError, pluginState }) => {const { t } = useTranslation('plugin');- const questions = normalizeAskUserQuestions(args);- const answers = pluginState?.askUserAnswers;- const freeform = answers?.['__freeform__'];- const freeformText = typeof freeform === 'string' ? freeform.trim() : '';- const isError = !!pluginError;- const multiple = questions.length > 1;-- // Escape-mode reply: the user opted out of the multi-choice form and- // wrote freeform text instead. The form picks are intentionally absent,- // so render the questions for context plus the typed reply as its own line β- // Q&A pairs would render as empty rows.- if (freeformText) {- return (- <Flexbox className={styles.container} gap={12}>- {questions.map((q, idx) => (- <Flexbox align="flex-start" horizontal={multiple} key={`${q.question}-${idx}`}>- {multiple && <span className={styles.ordinal}>{`Q${idx + 1}`}</span>}- <div className={multiple ? styles.titleRow : undefined}>- <span className={styles.question}>{q.question}</span>- {multiple && q.header && <span className={styles.header}>{q.header}</span>}- </div>- </Flexbox>- ))}- {/* The reply answers the whole form, not the last question β with several- questions on screen that scope needs a rule to be legible. */}- {multiple && <div className={styles.divider} />}- <AnswerLine icon={PenLine} text={freeformText} />- {isError && (- <Text type="warning">{t('builtins.lobe-claude-code.askUserQuestion.noAnswer')}</Text>- )}- </Flexbox>- );- }return (- <Flexbox className={styles.container} gap={12}>- {questions.map((q, idx) => (- <QABlock- answer={answers?.[q.question]}- index={multiple ? idx + 1 : undefined}- key={`${q.question}-${idx}`}- question={q}- />- ))}- {isError && (- <Text type="warning">{t('builtins.lobe-claude-code.askUserQuestion.noAnswer')}</Text>- )}- </Flexbox>+ <AskUserQuestionResult+ answers={resolveAskUserAnswers(pluginState, content)}+ isError={!!pluginError}+ questions={normalizeAskUserQuestions(args)}+ labels={{+ noAnswer: t('builtins.lobe-claude-code.askUserQuestion.noAnswer'),+ notAnswered: t('builtins.lobe-claude-code.askUserQuestion.notAnswered'),+ }}+ />);});diff --git a/packages/builtin-tool-lobe-agent/src/client/Inspector/index.ts b/packages/builtin-tool-lobe-agent/src/client/Inspector/index.tsindex 12cd62e7b60..40df9b95e14 100644--- a/packages/builtin-tool-lobe-agent/src/client/Inspector/index.ts+++ b/packages/builtin-tool-lobe-agent/src/client/Inspector/index.ts@@ -1,3 +1,4 @@+import { AskUserQuestionInspector } from '@lobechat/builtin-tool-user-interaction/client';import type { BuiltinInspector } from '@lobechat/types';import { LobeAgentApiName } from '../../types';@@ -17,6 +18,7 @@ import { UpdateTodosInspector } from './UpdateTodos';*/export const LobeAgentInspectors: Record<string, BuiltinInspector> = {[LobeAgentApiName.analyzeVisualMedia]: AnalyzeVisualMediaInspector as BuiltinInspector,+ [LobeAgentApiName.askUserQuestion]: AskUserQuestionInspector as BuiltinInspector,[LobeAgentApiName.callSubAgent]: CallSubAgentInspector as BuiltinInspector,[LobeAgentApiName.clearTodos]: ClearTodosInspector as BuiltinInspector,[LobeAgentApiName.createPlan]: CreatePlanInspector as BuiltinInspector,diff --git a/packages/builtin-tool-lobe-agent/src/client/Render/index.ts b/packages/builtin-tool-lobe-agent/src/client/Render/index.tsindex f1bf50b7db9..824406765c5 100644--- a/packages/builtin-tool-lobe-agent/src/client/Render/index.ts+++ b/packages/builtin-tool-lobe-agent/src/client/Render/index.ts@@ -1,3 +1,5 @@+import { AskUserQuestionRender } from '@lobechat/builtin-tool-user-interaction/client';+import { LobeAgentApiName } from '../../types';import CallSubAgentRender from './CallSubAgent';import CreatePlan from './CreatePlan';@@ -11,6 +13,7 @@ import TodoListRender from './TodoList';* share a single TodoList render.*/export const LobeAgentRenders = {+ [LobeAgentApiName.askUserQuestion]: AskUserQuestionRender,[LobeAgentApiName.callSubAgent]: CallSubAgentRender,// Plan operations render the PlanCard UIdiff --git a/packages/builtin-tool-user-interaction/src/client/Render/AskUserQuestion/index.tsx b/packages/builtin-tool-user-interaction/src/client/Render/AskUserQuestion/index.tsxnew file mode 100644index 00000000000..09444e47dea--- /dev/null+++ b/packages/builtin-tool-user-interaction/src/client/Render/AskUserQuestion/index.tsx@@ -0,0 +1,35 @@+'use client';++import {+ AskUserQuestionResult,+ type AskUserQuestionResultState,+ normalizeAskUserQuestions,+ resolveAskUserAnswers,+} from '@lobechat/shared-tool-ui/ask-user';+import type { BuiltinRenderProps } from '@lobechat/types';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++import type { AskUserQuestionArgs } from '../../../types';++export const AskUserQuestionRender = memo<+ BuiltinRenderProps<AskUserQuestionArgs, AskUserQuestionResultState, string>+>(({ args, content, pluginError, pluginState }) => {+ const { t } = useTranslation('plugin');++ return (+ <AskUserQuestionResult+ answers={resolveAskUserAnswers(pluginState, content)}+ isError={!!pluginError}+ questions={normalizeAskUserQuestions(args)}+ labels={{+ noAnswer: t('builtins.lobe-claude-code.askUserQuestion.noAnswer'),+ notAnswered: t('builtins.lobe-claude-code.askUserQuestion.notAnswered'),+ }}+ />+ );+});++AskUserQuestionRender.displayName = 'AskUserQuestionRender';++export default AskUserQuestionRender;diff --git a/packages/builtin-tool-user-interaction/src/client/Render/index.ts b/packages/builtin-tool-user-interaction/src/client/Render/index.tsnew file mode 100644index 00000000000..8cf91b948b8--- /dev/null+++ b/packages/builtin-tool-user-interaction/src/client/Render/index.ts@@ -0,0 +1,10 @@+import type { BuiltinRender } from '@lobechat/types';++import { UserInteractionApiName } from '../../types';+import AskUserQuestionRender from './AskUserQuestion';++export const UserInteractionRenders: Record<string, BuiltinRender> = {+ [UserInteractionApiName.askUserQuestion]: AskUserQuestionRender as BuiltinRender,+};++export { default as AskUserQuestionRender } from './AskUserQuestion';diff --git a/packages/builtin-tool-user-interaction/src/client/index.ts b/packages/builtin-tool-user-interaction/src/client/index.tsindex 0a0c6b5a5cd..b3bf833154d 100644--- a/packages/builtin-tool-user-interaction/src/client/index.ts+++ b/packages/builtin-tool-user-interaction/src/client/index.ts@@ -4,3 +4,4 @@ export { UserInteractionInspectors } from './Inspector';export { default as AskUserQuestionInspector } from './Inspector/AskUserQuestion';export { UserInteractionInterventions } from './Intervention';export { default as AskUserQuestionIntervention } from './Intervention/AskUserQuestion';+export { AskUserQuestionRender, UserInteractionRenders } from './Render';diff --git a/packages/builtin-tools/src/register.ts b/packages/builtin-tools/src/register.tsindex 595956966f4..52a86d9ba81 100644--- a/packages/builtin-tools/src/register.ts+++ b/packages/builtin-tools/src/register.ts@@ -130,6 +130,7 @@ import {UserInteractionIdentifier,UserInteractionInspectors,UserInteractionInterventions,+ UserInteractionRenders,} from '@lobechat/builtin-tool-user-interaction/client';import {WebBrowsingInspectors,@@ -201,6 +202,7 @@ export const registerBuiltinToolSurfaces = (): void => {[SkillStoreManifest.identifier]: SkillStoreRenders as Record<string, BuiltinRender>,[SkillsManifest.identifier]: SkillsRenders as Record<string, BuiltinRender>,[TaskManifest.identifier]: TaskRenders as Record<string, BuiltinRender>,+ [UserInteractionIdentifier]: UserInteractionRenders as Record<string, BuiltinRender>,[LobeActivatorManifest.identifier]: LobeActivatorRenders as Record<string, BuiltinRender>,[WebBrowsingManifest.identifier]: WebBrowsingRenders as Record<string, BuiltinRender>,[WebOnboardingManifest.identifier]: WebOnboardingRenders as Record<string, BuiltinRender>,diff --git a/packages/shared-tool-ui/src/AskUserQuestion/AskUserQuestionResult.tsx b/packages/shared-tool-ui/src/AskUserQuestion/AskUserQuestionResult.tsxnew file mode 100644index 00000000000..fd418be3c5b--- /dev/null+++ b/packages/shared-tool-ui/src/AskUserQuestion/AskUserQuestionResult.tsx@@ -0,0 +1,258 @@+'use client';++import { Flexbox, Icon, Text } from '@lobehub/ui';+import { createStaticStyles, cx } from 'antd-style';+import { Check, PenLine } from 'lucide-react';+import { memo } from 'react';++import type { AskUserQuestionItem } from './types';++const styles = createStaticStyles(({ css, cssVar }) => ({+ answer: css`+ font-size: 14px;+ font-weight: 500;+ line-height: 1.5;+ color: ${cssVar.colorText};+ overflow-wrap: anywhere;+ `,+ answerContent: css`+ min-width: 0;+ `,+ answerIcon: css`+ flex-shrink: 0;+ margin-block-start: 3px;+ color: ${cssVar.colorTextSecondary};+ `,+ answerIconSelected: css`+ color: ${cssVar.colorSuccess};+ `,+ answerRow: css`+ box-sizing: border-box;+ width: fit-content;+ max-width: 100%;+ padding-block: 8px;+ padding-inline: 12px;+ border-radius: 8px;++ background: ${cssVar.colorFillTertiary};+ `,+ container: css`+ padding-block: 8px 4px;+ `,+ description: css`+ font-size: 12px;+ line-height: 1.5;+ color: ${cssVar.colorTextTertiary};+ overflow-wrap: anywhere;+ `,+ divider: css`+ align-self: stretch;+ height: 1px;+ margin-block: 4px;+ background: ${cssVar.colorFillSecondary};+ `,+ header: css`+ flex-shrink: 0;++ padding-inline: 8px;+ border-radius: 4px;++ font-size: 12px;+ font-weight: 400;+ line-height: 20px;+ color: ${cssVar.colorTextTertiary};+ white-space: nowrap;++ background: ${cssVar.colorFillQuaternary};+ `,+ ordinal: css`+ flex-shrink: 0;++ box-sizing: border-box;+ width: 28px;+ height: 20px;+ border-radius: 4px;++ font-family: ${cssVar.fontFamilyCode};+ font-size: 12px;+ font-variant-numeric: tabular-nums;+ line-height: 20px;+ color: ${cssVar.colorTextTertiary};+ text-align: center;++ background: ${cssVar.colorFillQuaternary};+ `,+ question: css`+ font-size: 14px;+ font-weight: 400;+ line-height: 1.5;+ color: ${cssVar.colorTextSecondary};+ overflow-wrap: anywhere;+ `,+ questionContent: css`+ min-width: 0;+ `,+ titleRow: css`+ display: flex;+ flex-wrap: wrap;+ gap: 8px;+ align-items: baseline;+ `,+ unanswered: css`+ width: fit-content;+ max-width: 100%;+ padding-block: 8px;+ padding-inline: 12px;+ border: 1px dashed ${cssVar.colorBorderSecondary};+ border-radius: 8px;++ font-size: 12px;+ line-height: 1.5;+ color: ${cssVar.colorTextQuaternary};+ `,+}));++export interface AskUserQuestionResultLabels {+ noAnswer: string;+ notAnswered: string;+}++interface AnswerLineProps {+ description?: string;+ icon: typeof Check;+ selected?: boolean;+ text: string;+}++const AnswerLine = memo<AnswerLineProps>(({ icon, text, description, selected }) => (+ <Flexbox horizontal align="flex-start" className={styles.answerRow} gap={12}>+ <Icon+ className={cx(styles.answerIcon, selected && styles.answerIconSelected)}+ icon={icon}+ size={14}+ />+ <Flexbox className={styles.answerContent} flex={1} gap={4}>+ <span className={styles.answer}>{text}</span>+ {description && <span className={styles.description}>{description}</span>}+ </Flexbox>+ </Flexbox>+));++AnswerLine.displayName = 'AskUserQuestionResultAnswerLine';++interface QuestionAnswerProps {+ answer?: string | string[];+ index?: number;+ notAnswered: string;+ question: AskUserQuestionItem;+}++const QuestionAnswer = memo<QuestionAnswerProps>(({ question, answer, index, notAnswered }) => {+ const labels: string[] = Array.isArray(answer) ? answer : answer ? [answer] : [];+ const optionByLabel = new Map(question.options.map((option) => [option.label, option]));++ return (+ <Flexbox align="flex-start" gap={8} horizontal={!!index}>+ {!!index && <span className={styles.ordinal}>{`Q${index}`}</span>}+ <Flexbox className={styles.questionContent} flex={1} gap={8}>+ <div className={index ? styles.titleRow : undefined}>+ <span className={styles.question}>{question.question}</span>+ {!!index && question.header && <span className={styles.header}>{question.header}</span>}+ </div>+ {labels.length > 0 ? (+ <Flexbox gap={8}>+ {labels.map((label) => {+ const option = optionByLabel.get(label);++ return (+ <AnswerLine+ selected+ icon={Check}+ key={label}+ text={label}+ description={+ option?.description && option.description !== label+ ? option.description+ : undefined+ }+ />+ );+ })}+ </Flexbox>+ ) : (+ <span className={styles.unanswered}>{notAnswered}</span>+ )}+ </Flexbox>+ </Flexbox>+ );+});++QuestionAnswer.displayName = 'AskUserQuestionResultQuestionAnswer';++export interface AskUserQuestionResultProps {+ answers?: Record<string, string | string[]>;+ isError?: boolean;+ labels: AskUserQuestionResultLabels;+ questions: AskUserQuestionItem[];+}++/**+ * Read-only result for a completed AskUserQuestion call.+ *+ * The enclosing tool already supplies the card chrome, so this view stays flat+ * and uses question/answer typography instead of nesting another panel.+ */+export const AskUserQuestionResult = memo<AskUserQuestionResultProps>(+ ({ answers, isError, labels, questions }) => {+ const freeform = answers?.__freeform__;+ const freeformText = typeof freeform === 'string' ? freeform.trim() : '';+ const multiple = questions.length > 1;++ if (freeformText) {+ return (+ <Flexbox className={styles.container} gap={16}>+ {questions.map((question, index) => (+ <Flexbox+ align="flex-start"+ gap={8}+ horizontal={multiple}+ key={`${question.question}-${index}`}+ >+ {multiple && <span className={styles.ordinal}>{`Q${index + 1}`}</span>}+ <div+ className={`${styles.questionContent} ${multiple ? styles.titleRow : ''}`.trim()}+ >+ <span className={styles.question}>{question.question}</span>+ {multiple && question.header && (+ <span className={styles.header}>{question.header}</span>+ )}+ </div>+ </Flexbox>+ ))}+ {multiple && <div className={styles.divider} />}+ <AnswerLine icon={PenLine} text={freeformText} />+ {isError && <Text type="warning">{labels.noAnswer}</Text>}+ </Flexbox>+ );+ }++ return (+ <Flexbox className={styles.container} gap={16}>+ {questions.map((question, index) => (+ <QuestionAnswer+ answer={answers?.[question.question]}+ index={multiple ? index + 1 : undefined}+ key={`${question.question}-${index}`}+ notAnswered={labels.notAnswered}+ question={question}+ />+ ))}+ {isError && <Text type="warning">{labels.noAnswer}</Text>}+ </Flexbox>+ );+ },+);++AskUserQuestionResult.displayName = 'AskUserQuestionResult';++export default AskUserQuestionResult;diff --git a/packages/shared-tool-ui/src/AskUserQuestion/index.ts b/packages/shared-tool-ui/src/AskUserQuestion/index.tsindex 345b8e5e508..661417c35e9 100644--- a/packages/shared-tool-ui/src/AskUserQuestion/index.ts+++ b/packages/shared-tool-ui/src/AskUserQuestion/index.ts@@ -1,3 +1,8 @@+export {+ AskUserQuestionResult,+ type AskUserQuestionResultLabels,+ type AskUserQuestionResultProps,+} from './AskUserQuestionResult';export {type AskUserQuestionLabels,AskUserQuestionView,@@ -14,6 +19,7 @@ export {} from './draft';export { normalizeAskUserQuestions } from './normalize';export { default as QuestionPanel } from './QuestionPanel';+export { type AskUserQuestionResultState, resolveAskUserAnswers } from './result';export type {AskUserDraft,AskUserQuestionArgs,diff --git a/packages/shared-tool-ui/src/AskUserQuestion/result.test.ts b/packages/shared-tool-ui/src/AskUserQuestion/result.test.tsnew file mode 100644index 00000000000..6d808a590a3--- /dev/null+++ b/packages/shared-tool-ui/src/AskUserQuestion/result.test.ts@@ -0,0 +1,32 @@+import { describe, expect, it } from 'vitest';++import { resolveAskUserAnswers } from './result';++describe('resolveAskUserAnswers', () => {+ it('prefers the structured answers persisted in plugin state', () => {+ expect(+ resolveAskUserAnswers(+ { askUserAnswers: { Scope: ['Chat', 'Settings'] } },+ 'User submitted: {"Scope":"Legacy"}',+ ),+ ).toEqual({ Scope: ['Chat', 'Settings'] });+ });++ it('recovers answers from legacy builtin tool result content', () => {+ expect(+ resolveAskUserAnswers(+ undefined,+ 'User submitted: {"Which direction?":"Visual polish","Surfaces":["Chat","Settings"]}',+ ),+ ).toEqual({+ 'Which direction?': 'Visual polish',+ 'Surfaces': ['Chat', 'Settings'],+ });+ });++ it('ignores malformed or unsupported answer payloads', () => {+ expect(resolveAskUserAnswers(undefined, 'User submitted: not-json')).toBeUndefined();+ expect(resolveAskUserAnswers(undefined, 'Question(s) presented to the user.')).toBeUndefined();+ expect(resolveAskUserAnswers({ askUserAnswers: { Scope: 42 } as any }, '')).toBeUndefined();+ });+});diff --git a/packages/shared-tool-ui/src/AskUserQuestion/result.ts b/packages/shared-tool-ui/src/AskUserQuestion/result.tsnew file mode 100644index 00000000000..0ec1c66da4b--- /dev/null+++ b/packages/shared-tool-ui/src/AskUserQuestion/result.ts@@ -0,0 +1,43 @@+export interface AskUserQuestionResultState {+ askUserAnswers?: Record<string, string | string[]>;+}++const USER_SUBMITTED_PREFIX = 'User submitted:';++const normalizeAnswers = (value: unknown): Record<string, string | string[]> | undefined => {+ if (!value || typeof value !== 'object' || Array.isArray(value)) return;++ const entries = Object.entries(value).filter(+ (entry): entry is [string, string | string[]] =>+ typeof entry[1] === 'string' ||+ (Array.isArray(entry[1]) && entry[1].every((item) => typeof item === 'string')),+ );++ return entries.length > 0 ? Object.fromEntries(entries) : undefined;+};++/**+ * Resolve the structured answers for a completed AskUserQuestion call.+ *+ * New messages persist `pluginState.askUserAnswers`. Older builtin calls only+ * stored `User submitted: {...}` in the tool result, so keep that lightweight+ * compatibility path instead of exposing the generic JSON result renderer.+ */+export const resolveAskUserAnswers = (+ pluginState: AskUserQuestionResultState | undefined,+ content: unknown,+): Record<string, string | string[]> | undefined => {+ const persisted = normalizeAnswers(pluginState?.askUserAnswers);+ if (persisted) return persisted;++ if (typeof content !== 'string') return;++ const prefixIndex = content.indexOf(USER_SUBMITTED_PREFIX);+ if (prefixIndex < 0) return;++ try {+ return normalizeAnswers(JSON.parse(content.slice(prefixIndex + USER_SUBMITTED_PREFIX.length)));+ } catch {+ return;+ }+};diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.test.ts b/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.test.tsindex f1dfe79d14e..deedcd3f12d 100644--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.test.ts+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.test.ts@@ -1,3 +1,8 @@+import { LobeAgentApiName, LobeAgentIdentifier } from '@lobechat/builtin-tool-lobe-agent';+import {+ UserInteractionApiName,+ UserInteractionIdentifier,+} from '@lobechat/builtin-tool-user-interaction';import {WebOnboardingApiName,WebOnboardingIdentifier,@@ -78,6 +83,23 @@ describe('customInteractionHandlers', () => {expect(result.options?.createUserMessage).toBe(false);});+ it.each([+ [LobeAgentIdentifier, LobeAgentApiName.askUserQuestion],+ [UserInteractionIdentifier, UserInteractionApiName.askUserQuestion],+ ])('persists structured ask-user answers for %s', async (identifier, apiName) => {+ const payload = {+ 'How broad should this pass be?': 'Focused',+ 'Which surfaces?': ['Chat', 'Settings'],+ };++ const result = await prepareCustomInteractionSubmit(identifier, payload, { apiName });++ expect(result).toEqual({+ options: { pluginState: { askUserAnswers: payload } },+ payload,+ });+ });+it('persists skipped marketplace picks from the original tool arguments', async () => {await recordCustomInteractionResolution(WebOnboardingIdentifier,diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.ts b/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.tsindex 6d9fb9ecfdb..10440ac4238 100644--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.ts+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Detail/Intervention/customInteractionHandlers.ts@@ -1,6 +1,9 @@import { ClaudeCodeIdentifier } from '@lobechat/builtin-tool-claude-code';import { LobeAgentApiName, LobeAgentIdentifier } from '@lobechat/builtin-tool-lobe-agent';-import { UserInteractionIdentifier } from '@lobechat/builtin-tool-user-interaction';+import {+ UserInteractionApiName,+ UserInteractionIdentifier,+} from '@lobechat/builtin-tool-user-interaction';import {WebOnboardingApiName,WebOnboardingIdentifier,@@ -38,6 +41,14 @@ type CustomInteractionSubmitHandler = (const isAgentMarketplaceCall = (identifier: string, apiName?: string) =>identifier === WebOnboardingIdentifier && apiName === WebOnboardingApiName.showAgentMarketplace;+const isLobeAgentAskUserQuestion = (identifier: string, apiName?: string) =>+ identifier === LobeAgentIdentifier && apiName === LobeAgentApiName.askUserQuestion;++const isAskUserQuestionCall = (identifier: string, apiName?: string) =>+ (identifier === UserInteractionIdentifier &&+ apiName === UserInteractionApiName.askUserQuestion) ||+ isLobeAgentAskUserQuestion(identifier, apiName);+const isStringArray = (value: unknown): value is string[] =>Array.isArray(value) && value.every((item) => typeof item === 'string');@@ -122,6 +133,13 @@ const customInteractionSubmitHandlers: Array<{handler: CustomInteractionSubmitHandler;match: (identifier: string, apiName?: string) => boolean;}> = [+ {+ handler: async (payload) => ({+ options: { pluginState: { askUserAnswers: payload } },+ payload,+ }),+ match: isAskUserQuestionCall,+ },{handler: handleAgentMarketplaceSubmit,match: isAgentMarketplaceCall,@@ -149,9 +167,6 @@ export const isHeteroInteractionIdentifier = (identifier: string) =>* has other APIs (createPlan / clearTodos β¦) that must keep the default* approve/reject UI β so only its `askUserQuestion` API is a custom interaction.*/-const isLobeAgentAskUserQuestion = (identifier: string, apiName?: string) =>- identifier === LobeAgentIdentifier && apiName === LobeAgentApiName.askUserQuestion;-export const isCustomInteractionIdentifier = (identifier: string, apiName?: string) =>identifier === UserInteractionIdentifier ||isLobeAgentAskUserQuestion(identifier, apiName) ||diff --git a/src/features/DevPanel/RenderGallery/fixtures/lobe-agent.ts b/src/features/DevPanel/RenderGallery/fixtures/lobe-agent.tsindex 55b48c5dc1f..88961b33790 100644--- a/src/features/DevPanel/RenderGallery/fixtures/lobe-agent.ts+++ b/src/features/DevPanel/RenderGallery/fixtures/lobe-agent.ts@@ -23,6 +23,41 @@ export default defineFixtures({provider: 'openai',},}),+ askUserQuestion: single({+ args: {+ questions: [+ {+ header: 'Audit level',+ options: [+ {+ description: 'Read the code and inspect the rendered surface.',+ label: 'Code + visual',+ },+ {+ description: 'Limit this pass to implementation details.',+ label: 'Code only',+ },+ ],+ question: 'How deep should this audit go?',+ },+ {+ header: 'Scope',+ multiSelect: true,+ options: [+ { description: 'Conversation messages and tool cards.', label: 'Chat' },+ { description: 'Agent configuration and settings.', label: 'Settings' },+ ],+ question: 'Which surfaces should it cover?',+ },+ ],+ },+ pluginState: {+ askUserAnswers: {+ 'How deep should this audit go?': 'Code + visual',+ 'Which surfaces should it cover?': ['Chat', 'Settings'],+ },+ },+ }),callSubAgent: single({pluginState: {task: {diff --git a/src/features/DevPanel/RenderGallery/fixtures/lobe-user-interaction.ts b/src/features/DevPanel/RenderGallery/fixtures/lobe-user-interaction.tsindex 211f118edf7..9953e9f57fc 100644--- a/src/features/DevPanel/RenderGallery/fixtures/lobe-user-interaction.ts+++ b/src/features/DevPanel/RenderGallery/fixtures/lobe-user-interaction.ts@@ -31,6 +31,11 @@ export default defineFixtures({],},label: 'Single question',+ pluginState: {+ askUserAnswers: {+ 'Which area should we explore first?': ['Evidence pages', 'Visual direction'],+ },+ },},{args: {@@ -48,6 +53,12 @@ export default defineFixtures({],},label: 'Multiple questions',+ pluginState: {+ askUserAnswers: {+ 'How broad should this pass be?': 'Focused',+ 'Which visual tone should we use?': 'Neutral',+ },+ },},]),},diff --git a/src/store/tool/builtinToolRegistry.test.ts b/src/store/tool/builtinToolRegistry.test.tsindex 74ef9833951..0c689f73297 100644--- a/src/store/tool/builtinToolRegistry.test.ts+++ b/src/store/tool/builtinToolRegistry.test.ts@@ -5,6 +5,7 @@ import {GroupAgentBuilderIdentifier,} from '@lobechat/builtin-tool-group-agent-builder';import { GroupAgentBuilderInspectors } from '@lobechat/builtin-tool-group-agent-builder/client';+import { LobeAgentApiName, LobeAgentIdentifier } from '@lobechat/builtin-tool-lobe-agent';import { RemoteDeviceApiName, RemoteDeviceIdentifier } from '@lobechat/builtin-tool-remote-device';import { SkillStoreApiName, SkillStoreIdentifier } from '@lobechat/builtin-tool-skill-store';import { SkillStoreInspectors, SkillStoreRenders } from '@lobechat/builtin-tool-skill-store/client';@@ -79,10 +80,20 @@ describe('builtin tool registry', () => {expect(runtime.agencyConfig?.executionTarget).toBe('none');});- it('registers the ask user question inspector', () => {+ it('registers the ask user question surfaces across builtin producers', () => {expect(getBuiltinInspector(UserInteractionIdentifier, UserInteractionApiName.askUserQuestion),).toBeDefined();+ expect(+ getBuiltinRender(UserInteractionIdentifier, UserInteractionApiName.askUserQuestion),+ ).toBeDefined();+ expect(+ getBuiltinInspector(LobeAgentIdentifier, LobeAgentApiName.askUserQuestion),+ ).toBeDefined();+ expect(getBuiltinRender(LobeAgentIdentifier, LobeAgentApiName.askUserQuestion)).toBeDefined();+ expect(+ getBuiltinRender(ClaudeCodeToolIdentifier, UserInteractionApiName.askUserQuestion),+ ).toBeDefined();});it('exposes the marketplace APIs under the web onboarding manifest', () => {