-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(doubao): add --thread support for ask/send/read #828
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
hanxuanliang
wants to merge
1
commit into
jackwener:main
from
hanxuanliang:feat/doubao-thread-targeting
Closed
Changes from all commits
Commits
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
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,53 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { IPage } from '@jackwener/opencli/types'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| getDoubaoVisibleTurns: vi.fn(), | ||
| getDoubaoTranscriptLines: vi.fn(), | ||
| navigateToConversation: vi.fn(), | ||
| sendDoubaoMessage: vi.fn(), | ||
| waitForDoubaoResponse: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('./utils.js', async () => { | ||
| const actual = await vi.importActual<typeof import('./utils.js')>('./utils.js'); | ||
| return { | ||
| ...actual, | ||
| getDoubaoVisibleTurns: mocks.getDoubaoVisibleTurns, | ||
| getDoubaoTranscriptLines: mocks.getDoubaoTranscriptLines, | ||
| navigateToConversation: mocks.navigateToConversation, | ||
| sendDoubaoMessage: mocks.sendDoubaoMessage, | ||
| waitForDoubaoResponse: mocks.waitForDoubaoResponse, | ||
| }; | ||
| }); | ||
|
|
||
| import { askCommand } from './ask.js'; | ||
|
|
||
| function createPageMock(): IPage { | ||
| return { | ||
| wait: vi.fn().mockResolvedValue(undefined), | ||
| } as unknown as IPage; | ||
| } | ||
|
|
||
| describe('doubao ask --thread', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.getDoubaoVisibleTurns.mockResolvedValue([]); | ||
| mocks.getDoubaoTranscriptLines.mockResolvedValue([]); | ||
| mocks.sendDoubaoMessage.mockResolvedValue('button'); | ||
| mocks.waitForDoubaoResponse.mockResolvedValue('继续'); | ||
| }); | ||
|
|
||
| it('navigates to the requested conversation id before sending', async () => { | ||
| const page = createPageMock(); | ||
|
|
||
| await askCommand.func!(page, { | ||
| text: '继续', | ||
| thread: 'https://www.doubao.com/chat/1234567890123', | ||
| timeout: '60', | ||
| }); | ||
|
|
||
| expect(mocks.navigateToConversation).toHaveBeenCalledWith(page, '1234567890123'); | ||
| expect(mocks.sendDoubaoMessage).toHaveBeenCalledWith(page, '继续'); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { IPage } from '@jackwener/opencli/types'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| getDoubaoVisibleTurns: vi.fn(), | ||
| navigateToConversation: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('./utils.js', async () => { | ||
| const actual = await vi.importActual<typeof import('./utils.js')>('./utils.js'); | ||
| return { | ||
| ...actual, | ||
| getDoubaoVisibleTurns: mocks.getDoubaoVisibleTurns, | ||
| navigateToConversation: mocks.navigateToConversation, | ||
| }; | ||
| }); | ||
|
|
||
| import { readCommand } from './read.js'; | ||
|
|
||
| describe('doubao read --thread', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.getDoubaoVisibleTurns.mockResolvedValue([ | ||
| { Role: 'Assistant', Text: '这是指定会话' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('navigates to the requested conversation id before reading', async () => { | ||
| const page = {} as IPage; | ||
|
|
||
| const result = await readCommand.func!(page, { | ||
| thread: 'https://www.doubao.com/chat/1234567890123', | ||
| }); | ||
|
|
||
| expect(mocks.navigateToConversation).toHaveBeenCalledWith(page, '1234567890123'); | ||
| expect(result).toEqual([ | ||
| { Role: 'Assistant', Text: '这是指定会话' }, | ||
| ]); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { IPage } from '@jackwener/opencli/types'; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| navigateToConversation: vi.fn(), | ||
| sendDoubaoMessage: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('./utils.js', async () => { | ||
| const actual = await vi.importActual<typeof import('./utils.js')>('./utils.js'); | ||
| return { | ||
| ...actual, | ||
| navigateToConversation: mocks.navigateToConversation, | ||
| sendDoubaoMessage: mocks.sendDoubaoMessage, | ||
| }; | ||
| }); | ||
|
|
||
| import { sendCommand } from './send.js'; | ||
|
|
||
| describe('doubao send --thread', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.sendDoubaoMessage.mockResolvedValue('button'); | ||
| }); | ||
|
|
||
| it('navigates to the requested conversation id before sending', async () => { | ||
| const page = {} as IPage; | ||
|
|
||
| await sendCommand.func!(page, { | ||
| text: '补充一句', | ||
| thread: '1234567890123', | ||
| }); | ||
|
|
||
| expect(mocks.navigateToConversation).toHaveBeenCalledWith(page, '1234567890123'); | ||
| expect(mocks.sendDoubaoMessage).toHaveBeenCalledWith(page, '补充一句'); | ||
| }); | ||
| }); |
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
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.
If
--threadis malformed or only a partial id,parseDoubaoConversationId()falls back to the raw input. That becomes risky here becausenavigateToConversation()treatscurrentUrl.includes(/chat/${conversationId})as an exact match, so a value like123will match an existing/chat/1234567890123URL and skip navigation. In that caseaskcan post into the wrong conversation instead of failing fast. I think this should validate the parsed id before navigation, or tighten the current URL check to compare the full path segment.