diff --git a/src/App.css b/src/App.css index 80aca7d..4cf0e72 100644 --- a/src/App.css +++ b/src/App.css @@ -1745,6 +1745,42 @@ a:hover { gap: 6px; } +.book-travel-submit-cluster { + display: flex; + align-items: center; + gap: 8px; +} + +.book-travel-submit-button.ant-btn, +.book-travel-scene-change-button.ant-btn { + height: 32px; + padding: 0 12px; + border-radius: 8px; + font-size: 13px; +} + +.book-travel-submit-button.ant-btn { + background: #d97757; + border-color: #d97757; +} + +.book-travel-submit-button.ant-btn:not(:disabled):hover { + background: #c4664a; + border-color: #c4664a; +} + +.book-travel-scene-change-button.ant-btn { + color: #d97757; + border-color: #e7c3b6; + background: #fff; +} + +.book-travel-scene-change-button.ant-btn:not(:disabled):hover { + color: #c4664a; + border-color: #d97757; + background: #fff7f3; +} + .book-travel-composer-actions, .adventure-composer-actions { position: absolute; diff --git a/src/__tests__/story-book-travel-mode.test.tsx b/src/__tests__/story-book-travel-mode.test.tsx index fa21c15..707aa81 100644 --- a/src/__tests__/story-book-travel-mode.test.tsx +++ b/src/__tests__/story-book-travel-mode.test.tsx @@ -637,9 +637,7 @@ describe('Story book-travel mode', () => { }); it('shows a submitted book-travel action immediately and locks sending while it is processed', async () => { - const classification = createDeferred<{ classification: 'insert-beat' }>(); invokeMock.mockImplementation((command: string, args?: any) => { - if (command === 'classify_book_travel_input') return classification.promise; if (command === 'start_write_book_travel_insert_beat_stream') { return Promise.resolve({ runId: 'pending-insert-run' }); } @@ -651,18 +649,19 @@ describe('Story book-travel mode', () => { const inputBox = screen.getByPlaceholderText(/说些什么/); fireEvent.change(inputBox, { target: { value: '查看窗外动静' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; + const sendButton = screen.getByRole('button', { name: '提交行动' }); fireEvent.click(sendButton); expect(await screen.findByText(/查看窗外动静/)).toBeInTheDocument(); fireEvent.change(inputBox, { target: { value: '继续追问' } }); expect(sendButton).toBeDisabled(); + expect(screen.getByRole('button', { name: '换场提交' })).toBeDisabled(); - classification.resolve({ classification: 'insert-beat' }); await waitFor(() => { expect(invokeMock).toHaveBeenCalledWith('start_write_book_travel_insert_beat_stream', expect.anything()); }); + expect(invokeMock.mock.calls.filter(([command]) => command === 'classify_book_travel_input')).toHaveLength(0); fireEvent.change(inputBox, { target: { value: '继续追问' } }); expect(sendButton).toBeDisabled(); @@ -682,9 +681,7 @@ describe('Story book-travel mode', () => { }); it('recovers when the scene writer returns JSON with raw newlines inside a string value', async () => { - const classification = createDeferred<{ classification: 'insert-beat' }>(); invokeMock.mockImplementation((command: string, args?: any) => { - if (command === 'classify_book_travel_input') return classification.promise; if (command === 'start_write_book_travel_insert_beat_stream') { return Promise.resolve({ runId: 'raw-newline-insert-run' }); } @@ -696,11 +693,10 @@ describe('Story book-travel mode', () => { const inputBox = screen.getByPlaceholderText(/说些什么/); fireEvent.change(inputBox, { target: { value: '查看窗外动静' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; + const sendButton = screen.getByRole('button', { name: '提交行动' }); fireEvent.click(sendButton); expect(await screen.findByText(/查看窗外动静/)).toBeInTheDocument(); - classification.resolve({ classification: 'insert-beat' }); await waitFor(() => { expect(invokeMock).toHaveBeenCalledWith('start_write_book_travel_insert_beat_stream', expect.anything()); }); @@ -737,8 +733,8 @@ describe('Story book-travel mode', () => { const inputBox = screen.getByPlaceholderText(/说些什么/); fireEvent.change(inputBox, { target: { value: '去正厅见沈家人' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; - fireEvent.click(sendButton); + const sendButton = screen.getByRole('button', { name: '提交行动' }); + fireEvent.click(screen.getByRole('button', { name: '换场提交' })); expect(await screen.findByText(/去正厅见沈家人/)).toBeInTheDocument(); expect(screen.getByText('正在识别行动...')).toBeInTheDocument(); @@ -814,8 +810,8 @@ describe('Story book-travel mode', () => { renderWithRouter(); fireEvent.change(screen.getByPlaceholderText(/说些什么/), { target: { value: '转去偏院搜证' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; - fireEvent.click(sendButton); + const sendButton = screen.getByRole('button', { name: '提交行动' }); + fireEvent.click(screen.getByRole('button', { name: '换场提交' })); expect(await screen.findByText(/转去偏院搜证/)).toBeInTheDocument(); await waitFor(() => { @@ -1083,8 +1079,13 @@ describe('Story book-travel mode', () => { renderWithRouter(); fireEvent.change(screen.getByPlaceholderText(/说些什么/), { target: { value: '查看状态' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; - fireEvent.click(sendButton); + fireEvent.click(screen.getByRole('button', { name: '提交行动' })); + await waitFor(() => expect(invokeMock).toHaveBeenCalledWith('start_write_book_travel_insert_beat_stream', expect.anything())); + expect(invokeMock.mock.calls.filter(([command]) => command === 'classify_book_travel_input')).toHaveLength(0); + expect(await screen.findByText(/她回应了/)).toBeInTheDocument(); + + fireEvent.change(screen.getByPlaceholderText(/说些什么/), { target: { value: '离开喜房' } }); + fireEvent.click(screen.getByRole('button', { name: '换场提交' })); await waitFor(() => { expect(invokeMock).toHaveBeenCalledWith('classify_book_travel_input', expect.anything()); @@ -1107,13 +1108,12 @@ describe('Story book-travel mode', () => { renderWithRouter(); fireEvent.change(screen.getByPlaceholderText(/说些什么/), { target: { value: '查看状态' } }); - fireEvent.click(document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement); + fireEvent.click(screen.getByRole('button', { name: '提交行动' })); await waitFor(() => expect(invokeMock).toHaveBeenCalledWith('start_write_book_travel_insert_beat_stream', expect.anything())); const writerCall = invokeMock.mock.calls.find(([command]) => command === 'start_write_book_travel_insert_beat_stream'); - const classifierCall = invokeMock.mock.calls.find(([command]) => command === 'classify_book_travel_input'); + expect(invokeMock.mock.calls.filter(([command]) => command === 'classify_book_travel_input')).toHaveLength(0); expect(writerCall?.[1].request.systemPrompt).toMatch(/穿书预设正文[\s\S]*穿书场景写手/); - expect(classifierCall?.[1].request.systemPrompt).not.toContain('穿书预设正文'); }); it('passes the selected book-travel input mode prefix into the runtime calls and turn record', async () => { @@ -1123,23 +1123,17 @@ describe('Story book-travel mode', () => { fireEvent.click(screen.getByText('角色行为')); fireEvent.change(screen.getByPlaceholderText(/做点什么/), { target: { value: '抬手试探门锁' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; - fireEvent.click(sendButton); + fireEvent.click(screen.getByRole('button', { name: '提交行动' })); expect(await screen.findByText('【行为】抬手试探门锁')).toBeInTheDocument(); - await waitFor(() => { - expect(invokeMock).toHaveBeenCalledWith( - 'classify_book_travel_input', - expect.objectContaining({ userInput: '【行为】抬手试探门锁' }), - ); - }); await waitFor(() => { expect(invokeMock).toHaveBeenCalledWith( 'start_write_book_travel_insert_beat_stream', expect.objectContaining({ userInput: '【行为】抬手试探门锁' }), ); }); + expect(invokeMock.mock.calls.filter(([command]) => command === 'classify_book_travel_input')).toHaveLength(0); }); it('keeps scene-writer streaming visible after leaving and returning to the story page', async () => { @@ -1155,8 +1149,7 @@ describe('Story book-travel mode', () => { const firstRender = renderWithRouter(); fireEvent.change(screen.getByPlaceholderText(/说些什么/), { target: { value: '查看门外' } }); - const sendButton = document.querySelector('.de-ai-agent-run-button') as HTMLButtonElement; - fireEvent.click(sendButton); + fireEvent.click(screen.getByRole('button', { name: '提交行动' })); await waitFor(() => { expect(invokeMock).toHaveBeenCalledWith('start_write_book_travel_insert_beat_stream', expect.anything()); diff --git a/src/pages/Story.tsx b/src/pages/Story.tsx index 119dbd0..5902a4e 100644 --- a/src/pages/Story.tsx +++ b/src/pages/Story.tsx @@ -4,7 +4,6 @@ import { HistoryOutlined, ReloadOutlined, CompassOutlined, - StopOutlined, PlayCircleOutlined, DeleteOutlined, UserOutlined, @@ -1338,7 +1337,7 @@ const useStoryView = () => { } }; - const handleSend = async () => { + const handleSend = async (bookTravelMode: 'continue' | 'scene-check' = 'continue') => { const trimmed = input.trim(); if (!trimmed || isStreaming || isBookTravelBusy) return; @@ -1354,6 +1353,21 @@ const useStoryView = () => { message.error('素材缺失,请重新装配素材'); return; } + if (bookTravelMode === 'continue') { + useBookTravelStore.getState().appendTurn({ + id: pendingTurnId, + userInput: formattedBookTravelInput, + classification: 'insert-beat', + status: 'writing', + narrativeOutput: '', + stateSnapshot: useBookTravelStore.getState().currentState, + createdBeatIds: [], + }); + pendingTurnCreated = true; + scrollToBottomOnce(); + await handleInsertBeatStream(formattedBookTravelInput, pendingTurnId); + return; + } useBookTravelStore.getState().appendTurn({ id: pendingTurnId, userInput: formattedBookTravelInput, @@ -1407,7 +1421,7 @@ const useStoryView = () => { if (pendingTurnCreated) { useBookTravelStore.getState().updateTurn(pendingTurnId, { status: 'error', - failedStage: 'classifying', + failedStage: bookTravelMode === 'continue' ? 'writing' : 'classifying', narrativeOutput: `处理失败:${String(err)}`, }); } @@ -2155,7 +2169,7 @@ const useStoryView = () => { onKeyDown={(event) => { if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) { event.preventDefault(); - void handleSend(); + void handleSend('continue'); } }} placeholder={ @@ -2180,7 +2194,7 @@ const useStoryView = () => {
-
+
- - + ) : ( + <> + + + + + + + + + + + + )}