|
| 1 | +import { cli, Strategy } from '../../registry.js'; |
| 2 | +import type { IPage } from '../../types.js'; |
| 3 | +import { DOUBAO_DOMAIN, getDoubaoTranscriptLines, getDoubaoVisibleTurns, sendDoubaoMessage, waitForDoubaoResponse } from './common.js'; |
| 4 | + |
| 5 | +export const askCommand = cli({ |
| 6 | + site: 'doubao', |
| 7 | + name: 'ask', |
| 8 | + description: 'Send a prompt and wait for the Doubao response', |
| 9 | + domain: DOUBAO_DOMAIN, |
| 10 | + strategy: Strategy.COOKIE, |
| 11 | + browser: true, |
| 12 | + navigateBefore: false, |
| 13 | + timeoutSeconds: 180, |
| 14 | + args: [ |
| 15 | + { name: 'text', required: true, positional: true, help: 'Prompt to send' }, |
| 16 | + { name: 'timeout', required: false, help: 'Max seconds to wait (default: 60)', default: '60' }, |
| 17 | + ], |
| 18 | + columns: ['Role', 'Text'], |
| 19 | + func: async (page: IPage, kwargs: any) => { |
| 20 | + const text = kwargs.text as string; |
| 21 | + const timeout = parseInt(kwargs.timeout as string, 10) || 60; |
| 22 | + const beforeTurns = await getDoubaoVisibleTurns(page); |
| 23 | + const beforeLines = await getDoubaoTranscriptLines(page); |
| 24 | + |
| 25 | + await sendDoubaoMessage(page, text); |
| 26 | + const response = await waitForDoubaoResponse(page, beforeLines, beforeTurns, text, timeout); |
| 27 | + |
| 28 | + if (!response) { |
| 29 | + return [ |
| 30 | + { Role: 'User', Text: text }, |
| 31 | + { Role: 'System', Text: `No response within ${timeout}s. Doubao may still be generating.` }, |
| 32 | + ]; |
| 33 | + } |
| 34 | + |
| 35 | + return [ |
| 36 | + { Role: 'User', Text: text }, |
| 37 | + { Role: 'Assistant', Text: response }, |
| 38 | + ]; |
| 39 | + }, |
| 40 | +}); |
0 commit comments