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
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
|
|
import {
|
|
GROK_DOMAIN,
|
|
authRequired,
|
|
ensureOnGrok,
|
|
getHistoryFromSidebar,
|
|
isLoggedIn,
|
|
} from './utils.js';
|
|
|
|
cli({
|
|
site: 'grok',
|
|
name: 'history',
|
|
access: 'read',
|
|
description: 'List recent Grok conversations from the sidebar (requires login)',
|
|
domain: GROK_DOMAIN,
|
|
strategy: Strategy.COOKIE,
|
|
browser: true,
|
|
siteSession: 'persistent',
|
|
navigateBefore: false,
|
|
args: [
|
|
{ name: 'limit', type: 'int', default: 20, help: 'Max conversations to show (default 20, max 100)' },
|
|
],
|
|
columns: ['Index', 'Title', 'Url'],
|
|
func: async (page, kwargs) => {
|
|
const limit = Number(kwargs.limit ?? 20);
|
|
if (!Number.isInteger(limit) || limit <= 0) {
|
|
throw new ArgumentError('limit', 'must be a positive integer');
|
|
}
|
|
if (limit > 100) {
|
|
throw new ArgumentError('limit', 'must be <= 100');
|
|
}
|
|
await ensureOnGrok(page);
|
|
await page.wait(2);
|
|
if (!(await isLoggedIn(page))) {
|
|
throw authRequired();
|
|
}
|
|
const sessions = await getHistoryFromSidebar(page, limit);
|
|
if (!sessions.length) {
|
|
throw new EmptyResultError('grok history', 'No Grok conversations found in the sidebar for the signed-in account.');
|
|
}
|
|
return sessions.slice(0, limit).map((s, i) => ({
|
|
Index: i + 1,
|
|
Title: s.title || '(untitled)',
|
|
Url: `https://grok.com/c/${s.id}`,
|
|
}));
|
|
},
|
|
});
|