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
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import {
|
|
GROK_DOMAIN,
|
|
bubbleHtmlToMarkdown,
|
|
ensureOnGrok,
|
|
getMessageBubbles,
|
|
normalizeBooleanFlag,
|
|
} from './utils.js';
|
|
|
|
cli({
|
|
site: 'grok',
|
|
name: 'read',
|
|
access: 'read',
|
|
description: 'Read messages in the current Grok conversation',
|
|
domain: GROK_DOMAIN,
|
|
strategy: Strategy.COOKIE,
|
|
browser: true,
|
|
siteSession: 'persistent',
|
|
navigateBefore: false,
|
|
args: [
|
|
{ name: 'markdown', type: 'boolean', default: false, help: 'Emit assistant replies as markdown' },
|
|
],
|
|
columns: ['Role', 'Text'],
|
|
func: async (page, kwargs) => {
|
|
const wantMarkdown = normalizeBooleanFlag(kwargs.markdown, false);
|
|
await ensureOnGrok(page);
|
|
await page.wait(2);
|
|
const bubbles = await getMessageBubbles(page);
|
|
if (!bubbles.length) {
|
|
return [{ Role: 'system', Text: 'No visible messages in the current conversation.' }];
|
|
}
|
|
return bubbles.map((b) => ({
|
|
Role: b.role,
|
|
Text: wantMarkdown && b.role === 'Assistant' && b.html
|
|
? (bubbleHtmlToMarkdown(b.html) || b.text)
|
|
: b.text,
|
|
}));
|
|
},
|
|
});
|