-
Notifications
You must be signed in to change notification settings - Fork 36
Feat/ask user with form #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c1dafd0
docs: add ask_user form-in-chat design spec
DivXPro 2b4a46a
worker: add ask_user display mode
DivXPro 2d0f9ab
feat: persist and render ask_user form messages in chat history
DivXPro daac5ba
fix: render ask_user form cards in chat stream and fix display_mode p…
DivXPro aea0674
fix: relocate form-mode ask_user to input area and fix dropdown clipping
DivXPro ab76a8b
feat: replace BooleanField checkbox with PillToggle switch component
DivXPro 6aa6d8c
fix(web): ask_user form reopens on thread switch due to overly strict…
DivXPro 67acc53
i18n(web): add translations for ask-user form buttons and labels
DivXPro 16ef1ba
ui(web): move submitted form labels outside value boxes
DivXPro f3b310c
fix(web): prevent duplicate ask_user form display in message list
DivXPro c614d4d
fix(MessageList): 修复活跃用户问询表单重复显示的问题
DivXPro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,061 changes: 1,061 additions & 0 deletions
1,061
docs/superpowers/plans/2026-05-25-ask-user-form-chat.md
Large diffs are not rendered by default.
Oops, something went wrong.
495 changes: 495 additions & 0 deletions
495
docs/superpowers/specs/2026-05-25-ask-user-form-chat-design.md
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此文件不应提交 |
Large diffs are not rendered by default.
Oops, something went wrong.
231 changes: 231 additions & 0 deletions
231
src/apps/web/src/__tests__/messageList.askUserForm.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| import { createRef, type ReactNode } from 'react' | ||
| import { act } from 'react' | ||
| import { createRoot } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { MessageList } from '../components/MessageList' | ||
| import type { AgentMessage } from '../agent-ui' | ||
|
|
||
| vi.mock('../components/MessageBubble', () => ({ | ||
| MessageBubble: ({ message, contentOverride }: { message: { content: string }; contentOverride?: string }) => ( | ||
| <div data-testid="message-bubble">{contentOverride ?? message.content}</div> | ||
| ), | ||
| })) | ||
|
|
||
| vi.mock('../components/AskUserFormMessageCard', () => ({ | ||
| default: ({ content }: { content: { message: string } }) => ( | ||
| <div data-testid="ask-user-form-card">{content.message}</div> | ||
| ), | ||
| })) | ||
|
|
||
| vi.mock('../components/WidgetBlock', () => ({ | ||
| WidgetBlock: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../components/CopSegmentBlocks', () => ({ | ||
| CopSegmentBlocks: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../components/TopLevelCopToolBlock', () => ({ | ||
| TopLevelCopToolBlock: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../components/IncognitoDivider', () => ({ | ||
| IncognitoDivider: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../components/MarkdownRenderer', () => ({ | ||
| MarkdownRenderer: ({ content }: { content: string }) => <div>{content}</div>, | ||
| })) | ||
|
|
||
| vi.mock('../components/WorkGroup', () => ({ | ||
| WorkGroup: ({ children }: { children: ReactNode }) => <div>{children}</div>, | ||
| })) | ||
|
|
||
| vi.mock('../components/cop-timeline/CopTimeline', () => ({ | ||
| CopTimeline: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../components/messagebubble/AssistantMessage', () => ({ | ||
| AssistantActionBar: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../contexts/chat-session', () => ({ | ||
| useChatSession: () => ({ threadId: 'thread-1', isSearchThread: false }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/run-lifecycle', () => ({ | ||
| useRunLifecycle: () => ({ | ||
| isStreaming: false, | ||
| sending: false, | ||
| terminalRunDisplayId: null, | ||
| terminalRunHandoffStatus: null, | ||
| terminalRunCoveredRunIds: [], | ||
| activeRunId: 'run-form', | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/message-store', () => ({ | ||
| isLocalTerminalMessage: () => false, | ||
| useMessageStore: () => ({ | ||
| messages: [], | ||
| userEnterMessageId: null, | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/message-meta', () => ({ | ||
| useMessageMeta: () => ({ | ||
| getMeta: () => undefined, | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/stream', () => ({ | ||
| useStream: () => ({ | ||
| preserveLiveRunUi: false, | ||
| liveAssistantTurn: null, | ||
| topLevelCodeExecutions: [], | ||
| topLevelSubAgents: [], | ||
| topLevelFileOps: [], | ||
| topLevelWebFetches: [], | ||
| streamingArtifacts: [], | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/panels', () => ({ | ||
| useActiveCodeExecutionId: () => null, | ||
| usePanelActions: () => ({ | ||
| closePanel: vi.fn(), | ||
| openSourcePanel: vi.fn(), | ||
| setShareState: vi.fn(), | ||
| }), | ||
| useShareModalState: () => ({ | ||
| sharingMessageId: null, | ||
| sharedMessageId: null, | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/auth', () => ({ | ||
| useAuth: () => ({ accessToken: 'token' }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/thread-list', () => ({ | ||
| useThreadList: () => ({ privateThreadIds: new Set<string>() }), | ||
| })) | ||
|
|
||
| vi.mock('../contexts/LocaleContext', () => ({ | ||
| useLocale: () => ({ | ||
| t: { | ||
| incognitoForkDivider: 'fork', | ||
| }, | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('../lib/chat-helpers', () => ({ | ||
| turnHasCopThinkingItems: () => false, | ||
| widgetToolCallIdsPlacedInTurn: () => new Set<string>(), | ||
| historicWidgetsForCop: () => [], | ||
| })) | ||
|
|
||
| vi.mock('../components/chatSourceResolver', () => ({ | ||
| resolveMessageSourcesForRender: () => new Map(), | ||
| })) | ||
|
|
||
| vi.mock('../storage', () => ({ | ||
| readMessageTerminalStatus: () => null, | ||
| readMessageWidgets: () => null, | ||
| })) | ||
|
|
||
| vi.mock('../api', () => ({ | ||
| createThreadShare: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@arkloop/shared/api', () => ({ | ||
| apiBaseUrl: () => '', | ||
| })) | ||
|
|
||
| vi.mock('react-router-dom', async () => { | ||
| const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom') | ||
| return { | ||
| ...actual, | ||
| useLocation: () => ({ state: null }), | ||
| } | ||
| }) | ||
|
|
||
| describe('MessageList ask_user_form', () => { | ||
| let container: HTMLDivElement | ||
| let root: ReturnType<typeof createRoot> | ||
|
|
||
| beforeEach(() => { | ||
| container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| root = createRoot(container) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => { | ||
| root.unmount() | ||
| }) | ||
| container.remove() | ||
| }) | ||
|
|
||
| it('隐藏当前活跃 pending form 的历史消息行,避免 prompt 重复显示', async () => { | ||
| const messages: AgentMessage[] = [ | ||
| { | ||
| id: 'msg-form', | ||
| role: 'assistant', | ||
| content: '请补充项目地址', | ||
| contentJson: { | ||
| kind: 'ask_user_form', | ||
| displayMode: 'form', | ||
| requestId: 'req-1', | ||
| runId: 'run-form', | ||
| message: '请补充项目地址', | ||
| schema: { | ||
| properties: { | ||
| project_url: { type: 'string', title: '项目地址' }, | ||
| }, | ||
| required: ['project_url'], | ||
| _fieldOrder: ['project_url'], | ||
| }, | ||
| status: 'pending', | ||
| answers: null, | ||
| submittedAt: null, | ||
| }, | ||
| createdAt: '2026-03-10T00:00:01Z', | ||
| parts: [], | ||
| streamId: 'run-form', | ||
| }, | ||
| ] | ||
|
|
||
| await act(async () => { | ||
| root.render( | ||
| <MessageList | ||
| ref={null} | ||
| lastTurnRef={createRef<HTMLDivElement>()} | ||
| lastUserPromptRef={createRef<HTMLDivElement>()} | ||
| lastTurnStartIdx={0} | ||
| handleRetryUserMessage={() => {}} | ||
| handleEditMessage={() => {}} | ||
| handleFork={async () => {}} | ||
| handleArtifactAction={() => {}} | ||
| handleAskUserFormSubmit={async () => {}} | ||
| handleAskUserFormDismiss={async () => {}} | ||
| openDocumentPanel={() => {}} | ||
| openResourcePanel={() => {}} | ||
| openCodePanel={() => {}} | ||
| openAgentPanel={() => {}} | ||
| showRunDetailButton={false} | ||
| sourcePanelMessageId={null} | ||
| setRunDetailPanelRunId={() => {}} | ||
| currentRunCopHeaderOverride={() => undefined} | ||
| clearUserEnterAnimation={() => {}} | ||
| messagesOverride={messages} | ||
| />, | ||
| ) | ||
| }) | ||
|
|
||
| expect(container.querySelector('[data-testid="message-bubble"]')).toBeNull() | ||
| expect(container.querySelector('[data-testid="ask-user-form-card"]')).toBeNull() | ||
| expect(container.textContent).not.toContain('请补充项目地址') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export type { | ||
| AgentAskUserFormContent, | ||
| AgentBackendAdapter, | ||
| AgentChatRequestOptions, | ||
| AgentClient, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此文件不应提交