9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
import {
|
|
YUANBAO_DOMAIN,
|
|
authRequired,
|
|
ensureYuanbaoPage,
|
|
hasLoginGate,
|
|
normalizeBooleanFlag,
|
|
sendYuanbaoMessage,
|
|
startNewYuanbaoChat,
|
|
} from './shared.js';
|
|
|
|
cli({
|
|
site: 'yuanbao',
|
|
name: 'send',
|
|
access: 'write',
|
|
description: 'Fire-and-forget: send a prompt to Yuanbao without waiting for the reply',
|
|
domain: YUANBAO_DOMAIN,
|
|
strategy: Strategy.COOKIE,
|
|
browser: true,
|
|
siteSession: 'persistent',
|
|
navigateBefore: false,
|
|
args: [
|
|
{ name: 'prompt', positional: true, required: true, help: 'Prompt to send to Yuanbao' },
|
|
{ name: 'new', type: 'boolean', default: false, help: 'Start a new chat before sending' },
|
|
],
|
|
columns: ['Status', 'Prompt'],
|
|
func: async (page, kwargs) => {
|
|
const prompt = String(kwargs.prompt || '').trim();
|
|
if (!prompt) throw new ArgumentError('prompt', 'is required');
|
|
const startFresh = normalizeBooleanFlag(kwargs.new, false);
|
|
|
|
await ensureYuanbaoPage(page);
|
|
if (await hasLoginGate(page)) {
|
|
throw authRequired('Yuanbao opened a login gate before sending the prompt.');
|
|
}
|
|
if (startFresh) {
|
|
const action = await startNewYuanbaoChat(page);
|
|
if (action === 'blocked') {
|
|
throw authRequired('Yuanbao opened a login gate while starting a new chat.');
|
|
}
|
|
}
|
|
const send = await sendYuanbaoMessage(page, prompt);
|
|
if (!send?.ok) {
|
|
if (await hasLoginGate(page)) {
|
|
throw authRequired('Yuanbao opened a login gate instead of accepting the prompt.');
|
|
}
|
|
throw new CommandExecutionError(
|
|
send?.reason || 'Failed to send Yuanbao prompt',
|
|
send?.detail
|
|
? `Detail: ${send.detail}`
|
|
: 'Make sure the Yuanbao chat composer is visible and not in a disabled state.',
|
|
);
|
|
}
|
|
return [{ Status: 'sent', Prompt: prompt }];
|
|
},
|
|
});
|