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
37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
|
|
import { arxivFetch, normalizeArxivLimit, parseEntries } from './utils.js';
|
|
cli({
|
|
site: 'arxiv',
|
|
name: 'search',
|
|
access: 'read',
|
|
description: 'Search arXiv papers',
|
|
strategy: Strategy.PUBLIC,
|
|
browser: false,
|
|
args: [
|
|
{ name: 'query', positional: true, required: true, help: 'Search keyword (e.g. "attention is all you need")' },
|
|
{ name: 'limit', type: 'int', default: 10, help: 'Max results (max 25)' },
|
|
],
|
|
columns: ['id', 'title', 'authors', 'published', 'primary_category', 'url'],
|
|
func: async (args) => {
|
|
const queryText = String(args.query || '').trim();
|
|
if (!queryText) {
|
|
throw new ArgumentError('arxiv search query cannot be empty');
|
|
}
|
|
const limit = normalizeArxivLimit(args.limit, 10, 25);
|
|
const query = encodeURIComponent(`all:${queryText}`);
|
|
const xml = await arxivFetch(`search_query=${query}&max_results=${limit}&sortBy=relevance`);
|
|
const entries = parseEntries(xml);
|
|
if (!entries.length)
|
|
throw new EmptyResultError('arxiv', 'No papers found. Try a different keyword.');
|
|
return entries.map(e => ({
|
|
id: e.id,
|
|
title: e.title,
|
|
authors: e.authors,
|
|
published: e.published,
|
|
primary_category: e.primary_category,
|
|
url: e.url,
|
|
}));
|
|
},
|
|
});
|