UNPKG

aiwg

Version:

Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo

112 lines 3.49 kB
/** * CrossRef API client * * @module research/clients/crossref */ import { BaseClient } from './base.js'; /** * CrossRef API client */ export class CrossRefClient extends BaseClient { constructor(config) { super({ baseUrl: 'https://api.crossref.org', timeout: 30000, rateLimit: { maxTokens: 50, refillRate: 1, // 1 request per second (polite pool) currentTokens: 50, lastRefill: Date.now(), }, retry: { maxRetries: 3, initialDelay: 1000, maxDelay: 10000, backoffMultiplier: 2, }, ...config, }); } /** * Get paper by DOI */ async getPaperByDoi(doi) { const url = this.buildUrl(`/works/${encodeURIComponent(doi)}`, {}); const response = await this.request(url); return this.transformResponse(response.message); } /** * Search papers by query */ async search(query, options = {}) { const { limit = 10, offset = 0 } = options; const url = this.buildUrl('/works', { query, rows: limit, offset, }); const response = await this.request(url); return { total: response.message['total-results'], papers: response.message.items.map((paper) => this.transformResponse(paper)), offset, limit, hasMore: offset + response.message.items.length < response.message['total-results'], }; } /** * Transform CrossRef response to ResearchPaper */ transformResponse(response) { const authors = response.author?.map((author) => { const name = [author.given, author.family] .filter(Boolean) .join(' '); const affiliations = author.affiliation?.map((aff) => aff.name) || []; return { name, affiliations, }; }) || []; const year = response.published?.['date-parts']?.[0]?.[0] || 0; const title = Array.isArray(response.title) ? response.title[0] : response.title || ''; const venue = Array.isArray(response['container-title']) ? response['container-title'][0] : response['container-title'] || ''; return { id: response.DOI, title, authors, year, abstract: response.abstract, doi: response.DOI, venue, citationCount: response['is-referenced-by-count'], type: this.mapType(response.type), source: 'crossref', retrievedAt: new Date().toISOString(), }; } /** * Map CrossRef type to ResearchPaper type */ mapType(crossrefType) { if (!crossrefType) return 'other'; const type = crossrefType.toLowerCase(); if (type.includes('journal')) return 'journal'; if (type.includes('proceedings')) return 'conference'; if (type.includes('posted-content')) return 'preprint'; if (type.includes('book')) return 'book'; if (type.includes('dissertation') || type.includes('thesis')) return 'thesis'; return 'other'; } } //# sourceMappingURL=crossref.js.map