项目文件夹

文件
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

62 行
2.2 KiB
JavaScript

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import {
QIANWEN_DOMAIN,
authRequired,
dismissLoginModal,
ensureOnQianwen,
getSessionListFromApi,
} from './utils.js';
function formatDate(ms) {
if (!ms) return '';
const d = new Date(ms);
if (Number.isNaN(d.getTime())) return '';
const pad = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
}
cli({
site: 'qwen',
name: 'history',
access: 'read',
description: 'List recent Qianwen conversations (requires login)',
domain: QIANWEN_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', 'Updated', '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 ensureOnQianwen(page);
await dismissLoginModal(page);
await page.wait(1);
const result = await getSessionListFromApi(page, limit);
if (!result.ok) {
if (result.status === 401 || result.status === 403) throw authRequired();
if (!result.sessions.length) {
throw new CommandExecutionError(`Qianwen history API failed (status=${result.status}) ${result.error || ''}`.trim());
}
}
if (!result.sessions.length) {
throw new EmptyResultError('qwen history', 'No Qianwen conversations found.');
}
return result.sessions.slice(0, limit).map((s, i) => ({
Index: i + 1,
Title: s.title || '(untitled)',
Updated: formatDate(s.updated_at),
Url: `https://www.qianwen.com/chat/${s.id}`,
}));
},
});