@thanh01.pmt/research-kit 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -14
- package/dist/academic/index.d.cts +3 -3
- package/dist/academic/index.d.ts +3 -3
- package/dist/academic/index.js +2 -1
- package/dist/catalogBuilder-BaVRvg-9.d.cts +90 -0
- package/dist/catalogBuilder-DHV6y1gD.d.ts +90 -0
- package/dist/chunk-AKEI7H2C.js +223 -0
- package/dist/chunk-AKEI7H2C.js.map +1 -0
- package/dist/{chunk-XIF5YNI7.js → chunk-HZNSZDSM.js} +318 -8
- package/dist/chunk-HZNSZDSM.js.map +1 -0
- package/dist/chunk-LSMSIPTZ.js +3 -0
- package/dist/{chunk-2JEVBCIF.js.map → chunk-LSMSIPTZ.js.map} +1 -1
- package/dist/{chunk-KAFQVI2R.js → chunk-ON6VFCJO.js} +3 -3
- package/dist/{chunk-KAFQVI2R.js.map → chunk-ON6VFCJO.js.map} +1 -1
- package/dist/{chunk-GKF3NDEX.js → chunk-QFYM2NV4.js} +3 -3
- package/dist/{chunk-GKF3NDEX.js.map → chunk-QFYM2NV4.js.map} +1 -1
- package/dist/{chunk-AUGVVZTL.js → chunk-RW7VS7NI.js} +175 -7
- package/dist/chunk-RW7VS7NI.js.map +1 -0
- package/dist/{chunk-DOXSPRSP.js → chunk-UKGR45VZ.js} +3 -223
- package/dist/chunk-UKGR45VZ.js.map +1 -0
- package/dist/{chunk-J7XKDMGL.js → chunk-X3X26W2I.js} +2 -2
- package/dist/{chunk-J7XKDMGL.js.map → chunk-X3X26W2I.js.map} +1 -1
- package/dist/config/index.cjs.map +1 -1
- package/dist/config/index.d.cts +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/evidence/index.cjs.map +1 -1
- package/dist/evidence/index.d.cts +2 -2
- package/dist/evidence/index.d.ts +2 -2
- package/dist/evidence/index.js +2 -2
- package/dist/harvester/index.cjs +542 -6
- package/dist/harvester/index.cjs.map +1 -1
- package/dist/harvester/index.d.cts +63 -49
- package/dist/harvester/index.d.ts +63 -49
- package/dist/harvester/index.js +4 -3
- package/dist/{index-t8pahlJ4.d.ts → index-DlngvZBr.d.cts} +15 -1
- package/dist/{index-t8pahlJ4.d.cts → index-DlngvZBr.d.ts} +15 -1
- package/dist/index.cjs +515 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -13
- package/dist/index.d.ts +28 -13
- package/dist/index.js +41 -13
- package/dist/index.js.map +1 -1
- package/dist/{literatureReview-BTPFe7eb.d.cts → literatureReview-C7hsjrn4.d.cts} +1 -1
- package/dist/{literatureReview-hGbfrBmw.d.ts → literatureReview-DWl13r_3.d.ts} +1 -1
- package/dist/pipeline/index.cjs +658 -231
- package/dist/pipeline/index.cjs.map +1 -1
- package/dist/pipeline/index.d.cts +49 -5
- package/dist/pipeline/index.d.ts +49 -5
- package/dist/pipeline/index.js +6 -5
- package/dist/{webScraper-BhiQ8s9x.d.ts → webScraper-DBFUIqoO.d.ts} +1 -1
- package/dist/{webScraper-D9Ldus9p.d.cts → webScraper-yO9P-oLb.d.cts} +1 -1
- package/package.json +1 -1
- package/dist/catalogBuilder-CmmQzUnf.d.ts +0 -38
- package/dist/catalogBuilder-DgXYxL2F.d.cts +0 -38
- package/dist/chunk-2JEVBCIF.js +0 -3
- package/dist/chunk-AUGVVZTL.js.map +0 -1
- package/dist/chunk-DOXSPRSP.js.map +0 -1
- package/dist/chunk-XIF5YNI7.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,31 +24,39 @@ It solves the fundamental problems of hallucinations, obsolete technical syntax,
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
## 📦 The
|
|
27
|
+
## 📦 The 6 Core Services
|
|
28
28
|
|
|
29
29
|
`@thanh01.pmt/research-kit` exposes a unified facade (`ResearchKitClient`) or standalone service classes:
|
|
30
30
|
|
|
31
31
|
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
▼
|
|
38
|
-
|
|
39
|
-
│
|
|
40
|
-
│
|
|
41
|
-
│
|
|
42
|
-
│
|
|
43
|
-
|
|
32
|
+
┌───────────────────────────┐
|
|
33
|
+
│ ResearchKitClient │
|
|
34
|
+
└─────────────┬─────────────┘
|
|
35
|
+
│
|
|
36
|
+
┌───────────────┬───────────────┬───────────┼───────────┬───────────────┬───────────────┐
|
|
37
|
+
▼ ▼ ▼ ▼ ▼ ▼ ▼
|
|
38
|
+
┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────────┐ ┌───────────────┐
|
|
39
|
+
│ Service 1 │ │ Service 2 │ │ Service 3 │ │ Service 4 │ │ Service 5 │ │ Service 6 │
|
|
40
|
+
│ Discovery │ │ Term & │ │ Academic │ │ Evidence │ │ Pedagogical │ │ Technical │
|
|
41
|
+
│ & Scrape │ │ Clean DAG │ │ Standards │ │ & NLI │ │ Synthesis │ │ Grounding │
|
|
42
|
+
│ Ingestion │ │ Extraction│ │ Alignment │ │ Auditor │ │ Orchestrator │ │ Factsheet │
|
|
43
|
+
└───────────┘ └───────────┘ └───────────┘ └───────────┘ └───────────────┘ └───────────────┘
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
### 1. `KnowledgeDiscoveryService` (Discovery & Multimodal Ingestion)
|
|
47
47
|
* **Multi-Engine Search**: Auto-routes queries across Tavily, Exa, Serper, SearXNG, DuckDuckGo, and custom adapters.
|
|
48
|
+
* **Commercial Noise Filter & Quality Auditor**: Automatically identifies and rejects e-commerce clutter (Shopee, Lazada, Tiki, AliExpress, eBay, Amazon product listings) and calculates substantive technical density (code blocks, technical headings, tables).
|
|
48
49
|
* **High-Fidelity Scraper**: Jina Reader API / Crawl4AI / Direct Fetch extracting clean Markdown, formatted code snippets with correct language tags (`lua`, `cpp`, `python`, `swift`), and tabular structures.
|
|
49
50
|
* **YouTube Transcript Ingestion**: Parses video transcripts, stitches caption fragments into timestamped paragraphs (every ~30–45s), and filters out sponsor segments and subscribe filler noise.
|
|
50
51
|
|
|
51
|
-
### 2. `TerminologyGraphService` (
|
|
52
|
+
### 2. `TerminologyGraphService` (Clean Prerequisite DAG & Concept Facets)
|
|
53
|
+
* **Deterministic DAG & Prerequisite Engine**: Applies transitive reduction to strip redundant shortcut edges ($A \to B \to C \implies$ remove $A \to C$) and runs Kahn's topological sort with cycle detection to guarantee clean, acyclic dependency graphs.
|
|
54
|
+
* **Multi-dimensional Concept Facets**: Concept extraction captures cognitive facets across Marr's tripartite layers:
|
|
55
|
+
* `facets.ulo`: Conceptual purpose, real-world rationale & scientific nature.
|
|
56
|
+
* `facets.cio`: Algorithmic mental model, data flow & internal mechanics.
|
|
57
|
+
* `facets.sio`: Syntactic implementation, pinout connections & code drill.
|
|
58
|
+
* `commonMisconceptions`: Empirical student pitfalls and misconceptions.
|
|
59
|
+
* `troubleshootingHints`: Practical debugging and setup fixes.
|
|
52
60
|
* **Tier 1 (Deterministic Candidate Harvester)**: Rapidly mines candidate terms from markdown headings, inline code blocks, bold markers, bilingual parenthetical pairs `Thuật ngữ (English)`, and Vietnamese technical head nouns.
|
|
53
61
|
* **Tier 2 (LLM Semantic Curator & Ontologist)**: Deduplicates synonyms (e.g., subsumes *LDR*, *Quang trở*, *Cảm biến ánh sáng* into `C_PHOTORESISTOR`), assigns Marr cognitive layers (`ULO`/`CIO`/`SIO`) and Bloom taxonomy levels, and constructs genuine pedagogical prerequisite DAG edges (`CONCEPT_DAG.tsv`).
|
|
54
62
|
|
|
@@ -68,6 +76,11 @@ It solves the fundamental problems of hallucinations, obsolete technical syntax,
|
|
|
68
76
|
* **URL Normalization & Deduplication**: Strips tracking parameters (`utm_*`, `fbclid`, `gclid`, `#hash`) to eliminate redundant crawling.
|
|
69
77
|
* **Canonical Reference Pack**: Bundles all verified evidence into `REFERENCE_PACK.md`, `RESOURCE_CATALOG.md`, `KNOWLEDGE_GRAPH.md`, and `RESOURCE_INDEX.json`.
|
|
70
78
|
|
|
79
|
+
### 6. `TechnicalGroundingService` (Hardware/Software Compatibility & Empirical Exemplars)
|
|
80
|
+
* **Compatibility Matrix**: Validates firmware, OS versions, libraries, and pinout requirements.
|
|
81
|
+
* **Age Feasibility Constraints**: Verifies if cognitive and motor skills match target age groups (e.g., fine soldering vs. breadboard dupont wires).
|
|
82
|
+
* **Empirical Exemplar Projects**: Extracts verified hands-on student projects with concrete hardware lists, target outcomes, and troubleshooting gotchas into `TECHNICAL_FACTSHEET.md`.
|
|
83
|
+
|
|
71
84
|
---
|
|
72
85
|
|
|
73
86
|
## 🚀 Quick Start
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as AcademicPaper } from '../index-
|
|
2
|
-
export {
|
|
3
|
-
export { C as CS2023KnowledgeArea, c as CS2023_KNOWLEDGE_AREAS, a as CSTAK12Strand, b as CSTA_K12_STRANDS, L as LiteratureReviewReport, d as LiteratureReviewSynthesizer, S as SotaComparisonRow, T as TaxonomyMappingResult, m as mapTopicToCS2023 } from '../literatureReview-
|
|
1
|
+
import { A as AcademicPaper } from '../index-DlngvZBr.cjs';
|
|
2
|
+
export { j as AcademicPaperSchema, l as AcademicSearchEngine, k as AcademicSearchOptions, r as reconstructOpenAlexAbstract } from '../index-DlngvZBr.cjs';
|
|
3
|
+
export { C as CS2023KnowledgeArea, c as CS2023_KNOWLEDGE_AREAS, a as CSTAK12Strand, b as CSTA_K12_STRANDS, L as LiteratureReviewReport, d as LiteratureReviewSynthesizer, S as SotaComparisonRow, T as TaxonomyMappingResult, m as mapTopicToCS2023 } from '../literatureReview-C7hsjrn4.cjs';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/academic/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as AcademicPaper } from '../index-
|
|
2
|
-
export {
|
|
3
|
-
export { C as CS2023KnowledgeArea, c as CS2023_KNOWLEDGE_AREAS, a as CSTAK12Strand, b as CSTA_K12_STRANDS, L as LiteratureReviewReport, d as LiteratureReviewSynthesizer, S as SotaComparisonRow, T as TaxonomyMappingResult, m as mapTopicToCS2023 } from '../literatureReview-
|
|
1
|
+
import { A as AcademicPaper } from '../index-DlngvZBr.js';
|
|
2
|
+
export { j as AcademicPaperSchema, l as AcademicSearchEngine, k as AcademicSearchOptions, r as reconstructOpenAlexAbstract } from '../index-DlngvZBr.js';
|
|
3
|
+
export { C as CS2023KnowledgeArea, c as CS2023_KNOWLEDGE_AREAS, a as CSTAK12Strand, b as CSTA_K12_STRANDS, L as LiteratureReviewReport, d as LiteratureReviewSynthesizer, S as SotaComparisonRow, T as TaxonomyMappingResult, m as mapTopicToCS2023 } from '../literatureReview-DWl13r_3.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/academic/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import '../chunk-J3VCGH7Z.js';
|
|
2
|
-
export {
|
|
2
|
+
export { CS2023_KNOWLEDGE_AREAS, CSTA_K12_STRANDS, CitationManager, LiteratureReviewSynthesizer, mapTopicToCS2023 } from '../chunk-UKGR45VZ.js';
|
|
3
|
+
export { AcademicPaperSchema, AcademicSearchEngine, ArXivSearchEngine, reconstructOpenAlexAbstract } from '../chunk-AKEI7H2C.js';
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { R as ResearchApiKeys, a as CustomSearchAdapter, C as CourseResearchContext, E as ExtractedConceptNode } from './index-DlngvZBr.cjs';
|
|
2
|
+
import { T as TechnicalDomain, S as ScrapedDocument } from './webScraper-yO9P-oLb.cjs';
|
|
3
|
+
|
|
4
|
+
interface SearchHit {
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
content: string;
|
|
8
|
+
score?: number;
|
|
9
|
+
engine: 'tavily' | 'exa' | 'serper' | 'duckduckgo' | 'searxng' | 'academic' | 'custom';
|
|
10
|
+
}
|
|
11
|
+
interface MultiSearchOptions {
|
|
12
|
+
limit?: number;
|
|
13
|
+
tavilyKey?: string;
|
|
14
|
+
exaKey?: string;
|
|
15
|
+
serperKey?: string;
|
|
16
|
+
apiKeys?: ResearchApiKeys;
|
|
17
|
+
allowEnvFallback?: boolean;
|
|
18
|
+
searxngHost?: string;
|
|
19
|
+
searxngHeaders?: Record<string, string>;
|
|
20
|
+
domainFilter?: string[];
|
|
21
|
+
preferredEngine?: 'tavily' | 'exa' | 'serper' | 'duckduckgo' | 'searxng' | 'academic' | 'custom';
|
|
22
|
+
customAdapter?: CustomSearchAdapter;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unified multi-engine search engine with host-injected API keys, automatic provider failover, and custom adapter support
|
|
26
|
+
*/
|
|
27
|
+
declare class MultiSourceSearchEngine {
|
|
28
|
+
private tavilyKey?;
|
|
29
|
+
private exaKey?;
|
|
30
|
+
private serperKey?;
|
|
31
|
+
private searxngHost?;
|
|
32
|
+
private searxngHeaders?;
|
|
33
|
+
private allowEnvFallback;
|
|
34
|
+
private customAdapter?;
|
|
35
|
+
private academicEngine;
|
|
36
|
+
constructor(options?: {
|
|
37
|
+
tavilyKey?: string;
|
|
38
|
+
exaKey?: string;
|
|
39
|
+
serperKey?: string;
|
|
40
|
+
searxngHost?: string;
|
|
41
|
+
searxngHeaders?: Record<string, string>;
|
|
42
|
+
apiKeys?: ResearchApiKeys;
|
|
43
|
+
allowEnvFallback?: boolean;
|
|
44
|
+
customAdapter?: CustomSearchAdapter;
|
|
45
|
+
});
|
|
46
|
+
setCustomAdapter(adapter: CustomSearchAdapter): void;
|
|
47
|
+
setApiKeys(keys: ResearchApiKeys): void;
|
|
48
|
+
setSearxng(host: string, headers?: Record<string, string>): void;
|
|
49
|
+
search(query: string, options?: MultiSearchOptions): Promise<SearchHit[]>;
|
|
50
|
+
querySearxng(query: string, searxngHost: string, limit: number, customHeaders?: Record<string, string>): Promise<SearchHit[]>;
|
|
51
|
+
private queryExa;
|
|
52
|
+
private querySerper;
|
|
53
|
+
private queryDuckDuckGo;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface HarvestedResourceItem {
|
|
57
|
+
id: string;
|
|
58
|
+
title: string;
|
|
59
|
+
url: string;
|
|
60
|
+
domain: TechnicalDomain;
|
|
61
|
+
relevanceScore: number;
|
|
62
|
+
byteSize: number;
|
|
63
|
+
tablesCount: number;
|
|
64
|
+
codeSnippetsCount: number;
|
|
65
|
+
summary: string;
|
|
66
|
+
keyTakeaways?: string[];
|
|
67
|
+
}
|
|
68
|
+
interface ResourceCatalogBundle {
|
|
69
|
+
resourceIndexJson: string;
|
|
70
|
+
resourceCatalogMd: string;
|
|
71
|
+
knowledgeGraphMd: string;
|
|
72
|
+
conceptDagTsv?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds the 3-Layer Catalog & Distilled Knowledge Graph from real harvested content and extracted concepts
|
|
76
|
+
*/
|
|
77
|
+
declare class CatalogBuilder {
|
|
78
|
+
buildBundle(topic: string, domain: TechnicalDomain, items: {
|
|
79
|
+
doc: ScrapedDocument;
|
|
80
|
+
score: number;
|
|
81
|
+
summary: string;
|
|
82
|
+
keyTakeaways?: string[];
|
|
83
|
+
}[], options?: {
|
|
84
|
+
context?: CourseResearchContext;
|
|
85
|
+
concepts?: ExtractedConceptNode[];
|
|
86
|
+
conceptDagTsv?: string;
|
|
87
|
+
}): ResourceCatalogBundle;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { CatalogBuilder as C, type HarvestedResourceItem as H, type MultiSearchOptions as M, type ResourceCatalogBundle as R, type SearchHit as S, MultiSourceSearchEngine as a };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { R as ResearchApiKeys, a as CustomSearchAdapter, C as CourseResearchContext, E as ExtractedConceptNode } from './index-DlngvZBr.js';
|
|
2
|
+
import { T as TechnicalDomain, S as ScrapedDocument } from './webScraper-DBFUIqoO.js';
|
|
3
|
+
|
|
4
|
+
interface SearchHit {
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
content: string;
|
|
8
|
+
score?: number;
|
|
9
|
+
engine: 'tavily' | 'exa' | 'serper' | 'duckduckgo' | 'searxng' | 'academic' | 'custom';
|
|
10
|
+
}
|
|
11
|
+
interface MultiSearchOptions {
|
|
12
|
+
limit?: number;
|
|
13
|
+
tavilyKey?: string;
|
|
14
|
+
exaKey?: string;
|
|
15
|
+
serperKey?: string;
|
|
16
|
+
apiKeys?: ResearchApiKeys;
|
|
17
|
+
allowEnvFallback?: boolean;
|
|
18
|
+
searxngHost?: string;
|
|
19
|
+
searxngHeaders?: Record<string, string>;
|
|
20
|
+
domainFilter?: string[];
|
|
21
|
+
preferredEngine?: 'tavily' | 'exa' | 'serper' | 'duckduckgo' | 'searxng' | 'academic' | 'custom';
|
|
22
|
+
customAdapter?: CustomSearchAdapter;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Unified multi-engine search engine with host-injected API keys, automatic provider failover, and custom adapter support
|
|
26
|
+
*/
|
|
27
|
+
declare class MultiSourceSearchEngine {
|
|
28
|
+
private tavilyKey?;
|
|
29
|
+
private exaKey?;
|
|
30
|
+
private serperKey?;
|
|
31
|
+
private searxngHost?;
|
|
32
|
+
private searxngHeaders?;
|
|
33
|
+
private allowEnvFallback;
|
|
34
|
+
private customAdapter?;
|
|
35
|
+
private academicEngine;
|
|
36
|
+
constructor(options?: {
|
|
37
|
+
tavilyKey?: string;
|
|
38
|
+
exaKey?: string;
|
|
39
|
+
serperKey?: string;
|
|
40
|
+
searxngHost?: string;
|
|
41
|
+
searxngHeaders?: Record<string, string>;
|
|
42
|
+
apiKeys?: ResearchApiKeys;
|
|
43
|
+
allowEnvFallback?: boolean;
|
|
44
|
+
customAdapter?: CustomSearchAdapter;
|
|
45
|
+
});
|
|
46
|
+
setCustomAdapter(adapter: CustomSearchAdapter): void;
|
|
47
|
+
setApiKeys(keys: ResearchApiKeys): void;
|
|
48
|
+
setSearxng(host: string, headers?: Record<string, string>): void;
|
|
49
|
+
search(query: string, options?: MultiSearchOptions): Promise<SearchHit[]>;
|
|
50
|
+
querySearxng(query: string, searxngHost: string, limit: number, customHeaders?: Record<string, string>): Promise<SearchHit[]>;
|
|
51
|
+
private queryExa;
|
|
52
|
+
private querySerper;
|
|
53
|
+
private queryDuckDuckGo;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface HarvestedResourceItem {
|
|
57
|
+
id: string;
|
|
58
|
+
title: string;
|
|
59
|
+
url: string;
|
|
60
|
+
domain: TechnicalDomain;
|
|
61
|
+
relevanceScore: number;
|
|
62
|
+
byteSize: number;
|
|
63
|
+
tablesCount: number;
|
|
64
|
+
codeSnippetsCount: number;
|
|
65
|
+
summary: string;
|
|
66
|
+
keyTakeaways?: string[];
|
|
67
|
+
}
|
|
68
|
+
interface ResourceCatalogBundle {
|
|
69
|
+
resourceIndexJson: string;
|
|
70
|
+
resourceCatalogMd: string;
|
|
71
|
+
knowledgeGraphMd: string;
|
|
72
|
+
conceptDagTsv?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds the 3-Layer Catalog & Distilled Knowledge Graph from real harvested content and extracted concepts
|
|
76
|
+
*/
|
|
77
|
+
declare class CatalogBuilder {
|
|
78
|
+
buildBundle(topic: string, domain: TechnicalDomain, items: {
|
|
79
|
+
doc: ScrapedDocument;
|
|
80
|
+
score: number;
|
|
81
|
+
summary: string;
|
|
82
|
+
keyTakeaways?: string[];
|
|
83
|
+
}[], options?: {
|
|
84
|
+
context?: CourseResearchContext;
|
|
85
|
+
concepts?: ExtractedConceptNode[];
|
|
86
|
+
conceptDagTsv?: string;
|
|
87
|
+
}): ResourceCatalogBundle;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { CatalogBuilder as C, type HarvestedResourceItem as H, type MultiSearchOptions as M, type ResourceCatalogBundle as R, type SearchHit as S, MultiSourceSearchEngine as a };
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/academic/arxivClient.ts
|
|
4
|
+
var ArXivSearchEngine = class {
|
|
5
|
+
/**
|
|
6
|
+
* Search ArXiv repository using the public atom XML API
|
|
7
|
+
*/
|
|
8
|
+
async search(query, maxResults = 5) {
|
|
9
|
+
const papers = [];
|
|
10
|
+
try {
|
|
11
|
+
const url = `https://export.arxiv.org/api/query?search_query=all:${encodeURIComponent(query)}&start=0&max_results=${maxResults}&sortBy=relevance&sortOrder=descending`;
|
|
12
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(1e4) });
|
|
13
|
+
if (res.ok) {
|
|
14
|
+
const xmlText = await res.text();
|
|
15
|
+
const entryMatches = xmlText.match(/<entry>[\s\S]*?<\/entry>/g) || [];
|
|
16
|
+
for (const entry of entryMatches) {
|
|
17
|
+
const idMatch = entry.match(/<id>([\s\S]*?)<\/id>/);
|
|
18
|
+
const titleMatch = entry.match(/<title>([\s\S]*?)<\/title>/);
|
|
19
|
+
const summaryMatch = entry.match(/<summary>([\s\S]*?)<\/summary>/);
|
|
20
|
+
const publishedMatch = entry.match(/<published>(\d{4})/);
|
|
21
|
+
const authorMatches = [...entry.matchAll(/<author>\s*<name>([\s\S]*?)<\/name>/g)].map((m) => m[1]?.trim()).filter(Boolean);
|
|
22
|
+
const arxivUrl = idMatch ? idMatch[1]?.trim() : "";
|
|
23
|
+
const pdfUrl = arxivUrl ? arxivUrl.replace("/abs/", "/pdf/") + ".pdf" : void 0;
|
|
24
|
+
if (titleMatch) {
|
|
25
|
+
papers.push({
|
|
26
|
+
id: arxivUrl || `arxiv-${Math.random().toString(36).substring(7)}`,
|
|
27
|
+
title: titleMatch[1]?.trim().replace(/\s+/g, " ") || "Untitled ArXiv Paper",
|
|
28
|
+
abstract: summaryMatch ? summaryMatch[1]?.trim().replace(/\s+/g, " ") : "",
|
|
29
|
+
authors: authorMatches,
|
|
30
|
+
year: publishedMatch ? parseInt(publishedMatch[1], 10) : (/* @__PURE__ */ new Date()).getFullYear(),
|
|
31
|
+
citationCount: 0,
|
|
32
|
+
venue: "arXiv preprint",
|
|
33
|
+
url: arxivUrl,
|
|
34
|
+
pdfUrl,
|
|
35
|
+
fieldsOfStudy: ["Computer Science", "AI & Machine Learning"]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.warn("[ArXivSearchEngine] ArXiv search failed:", e?.message || e);
|
|
42
|
+
}
|
|
43
|
+
return papers;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var AcademicPaperSchema = z.object({
|
|
47
|
+
id: z.string(),
|
|
48
|
+
title: z.string(),
|
|
49
|
+
abstract: z.string().optional(),
|
|
50
|
+
authors: z.array(z.string()).default([]),
|
|
51
|
+
year: z.number().optional(),
|
|
52
|
+
citationCount: z.number().default(0),
|
|
53
|
+
venue: z.string().optional(),
|
|
54
|
+
doi: z.string().optional(),
|
|
55
|
+
url: z.string().optional(),
|
|
56
|
+
pdfUrl: z.string().optional(),
|
|
57
|
+
tldr: z.string().optional(),
|
|
58
|
+
fieldsOfStudy: z.array(z.string()).default([])
|
|
59
|
+
});
|
|
60
|
+
function reconstructOpenAlexAbstract(invertedIndex) {
|
|
61
|
+
if (!invertedIndex || typeof invertedIndex !== "object") return void 0;
|
|
62
|
+
const entries = Object.entries(invertedIndex);
|
|
63
|
+
if (entries.length === 0) return void 0;
|
|
64
|
+
let maxIndex = 0;
|
|
65
|
+
for (const [, positions] of entries) {
|
|
66
|
+
if (Array.isArray(positions)) {
|
|
67
|
+
for (const p of positions) {
|
|
68
|
+
if (typeof p === "number" && p > maxIndex) maxIndex = p;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (maxIndex > 5e3) maxIndex = 5e3;
|
|
73
|
+
const words = new Array(maxIndex + 1);
|
|
74
|
+
for (const [word, positions] of entries) {
|
|
75
|
+
if (Array.isArray(positions)) {
|
|
76
|
+
for (const p of positions) {
|
|
77
|
+
if (typeof p === "number" && p >= 0 && p <= maxIndex) {
|
|
78
|
+
words[p] = word;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const reconstructed = words.filter(Boolean).join(" ").trim();
|
|
84
|
+
return reconstructed.length > 0 ? reconstructed : void 0;
|
|
85
|
+
}
|
|
86
|
+
var AcademicSearchEngine = class {
|
|
87
|
+
apiKey;
|
|
88
|
+
allowEnvFallback;
|
|
89
|
+
customAdapter;
|
|
90
|
+
arxivEngine;
|
|
91
|
+
constructor(options = {}) {
|
|
92
|
+
this.arxivEngine = new ArXivSearchEngine();
|
|
93
|
+
if (typeof options === "string") {
|
|
94
|
+
this.apiKey = options;
|
|
95
|
+
this.allowEnvFallback = true;
|
|
96
|
+
} else {
|
|
97
|
+
this.allowEnvFallback = options.allowEnvFallback ?? true;
|
|
98
|
+
this.apiKey = options.apiKey || (this.allowEnvFallback ? process.env.SEMANTIC_SCHOLAR_API_KEY : void 0);
|
|
99
|
+
this.customAdapter = options.customAdapter;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
setCustomAdapter(adapter) {
|
|
103
|
+
this.customAdapter = adapter;
|
|
104
|
+
}
|
|
105
|
+
setApiKey(apiKey) {
|
|
106
|
+
this.apiKey = apiKey;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Search academic papers across Semantic Scholar with OpenAlex and ArXiv fallback or Custom Adapter
|
|
110
|
+
*/
|
|
111
|
+
async searchPapers(query, options = {}) {
|
|
112
|
+
const adapter = options.customAdapter || this.customAdapter;
|
|
113
|
+
if (adapter) {
|
|
114
|
+
try {
|
|
115
|
+
const customPapers = await adapter.searchPapers(query, { limit: options.limit, yearRange: options.yearRange });
|
|
116
|
+
if (Array.isArray(customPapers) && customPapers.length > 0) {
|
|
117
|
+
return customPapers;
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.warn("[AcademicSearchEngine] Custom academic adapter failed:", e?.message || e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const limit = options.limit ?? 5;
|
|
124
|
+
const papers = [];
|
|
125
|
+
const seenTitles = /* @__PURE__ */ new Set();
|
|
126
|
+
const pushUnique = (p) => {
|
|
127
|
+
const normTitle = p.title.toLowerCase().replace(/[^a-z0-9\u00C0-\u1EF9]+/g, "");
|
|
128
|
+
if (!normTitle || seenTitles.has(normTitle)) return;
|
|
129
|
+
seenTitles.add(normTitle);
|
|
130
|
+
papers.push(p);
|
|
131
|
+
};
|
|
132
|
+
try {
|
|
133
|
+
const apiKey = options.apiKey || this.apiKey;
|
|
134
|
+
const headers = { "Content-Type": "application/json" };
|
|
135
|
+
if (apiKey) {
|
|
136
|
+
headers["x-api-key"] = apiKey;
|
|
137
|
+
}
|
|
138
|
+
const params = new URLSearchParams({
|
|
139
|
+
query,
|
|
140
|
+
limit: limit.toString(),
|
|
141
|
+
fields: "paperId,title,abstract,authors,year,citationCount,venue,externalIds,url,openAccessPdf,tldr,fieldsOfStudy"
|
|
142
|
+
});
|
|
143
|
+
if (options.yearRange) {
|
|
144
|
+
params.append("year", options.yearRange);
|
|
145
|
+
}
|
|
146
|
+
const res = await fetch(`https://api.semanticscholar.org/graph/v1/paper/search?${params.toString()}`, {
|
|
147
|
+
headers,
|
|
148
|
+
signal: AbortSignal.timeout(6e3)
|
|
149
|
+
});
|
|
150
|
+
if (res.ok) {
|
|
151
|
+
const data = await res.json();
|
|
152
|
+
if (Array.isArray(data?.data)) {
|
|
153
|
+
for (const item of data.data) {
|
|
154
|
+
pushUnique({
|
|
155
|
+
id: item.paperId || `s2-${Math.random().toString(36).slice(2, 8)}`,
|
|
156
|
+
title: item.title || "Untitled",
|
|
157
|
+
abstract: item.abstract || void 0,
|
|
158
|
+
authors: Array.isArray(item.authors) ? item.authors.map((a) => a.name).filter(Boolean) : [],
|
|
159
|
+
year: item.year,
|
|
160
|
+
citationCount: item.citationCount || 0,
|
|
161
|
+
venue: item.venue || void 0,
|
|
162
|
+
doi: item.externalIds?.DOI,
|
|
163
|
+
url: item.url || (item.externalIds?.DOI ? `https://doi.org/${item.externalIds.DOI}` : void 0),
|
|
164
|
+
pdfUrl: item.openAccessPdf?.url,
|
|
165
|
+
tldr: item.tldr?.text,
|
|
166
|
+
fieldsOfStudy: Array.isArray(item.fieldsOfStudy) && item.fieldsOfStudy.length > 0 ? item.fieldsOfStudy : ["Computer Science"]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (papers.length >= limit) return papers.slice(0, limit);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (e) {
|
|
173
|
+
console.warn("[AcademicSearchEngine] Semantic Scholar failed:", e?.message || e);
|
|
174
|
+
}
|
|
175
|
+
if (papers.length < limit) {
|
|
176
|
+
try {
|
|
177
|
+
const res = await fetch(`https://api.openalex.org/works?search=${encodeURIComponent(query)}&per-page=${limit}`, {
|
|
178
|
+
headers: { "User-Agent": "OrchableComposer/1.0 (mailto:team@orchable.app)" },
|
|
179
|
+
signal: AbortSignal.timeout(6e3)
|
|
180
|
+
});
|
|
181
|
+
if (res.ok) {
|
|
182
|
+
const data = await res.json();
|
|
183
|
+
if (Array.isArray(data?.results)) {
|
|
184
|
+
for (const item of data.results) {
|
|
185
|
+
const abstractText = reconstructOpenAlexAbstract(item.abstract_inverted_index);
|
|
186
|
+
const concepts = Array.isArray(item.concepts) ? item.concepts.slice(0, 3).map((c) => c.display_name).filter(Boolean) : ["Computer Science"];
|
|
187
|
+
pushUnique({
|
|
188
|
+
id: item.id || `oa-${Math.random().toString(36).slice(2, 8)}`,
|
|
189
|
+
title: item.title || "Untitled",
|
|
190
|
+
abstract: abstractText,
|
|
191
|
+
authors: Array.isArray(item.authorships) ? item.authorships.map((a) => a.author?.display_name).filter(Boolean) : [],
|
|
192
|
+
year: item.publication_year,
|
|
193
|
+
citationCount: item.cited_by_count || 0,
|
|
194
|
+
venue: item.primary_location?.source?.display_name,
|
|
195
|
+
doi: item.doi ? String(item.doi).replace(/^https?:\/\/doi\.org\//i, "") : void 0,
|
|
196
|
+
url: item.doi || item.id,
|
|
197
|
+
pdfUrl: item.open_access?.oa_url,
|
|
198
|
+
fieldsOfStudy: concepts.length > 0 ? concepts : ["Computer Science"]
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
} catch (e) {
|
|
204
|
+
console.warn("[AcademicSearchEngine] OpenAlex failed:", e?.message || e);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (papers.length < limit && options.includeArxivFallback !== false) {
|
|
208
|
+
try {
|
|
209
|
+
const arxivPapers = await this.arxivEngine.search(query, limit - papers.length);
|
|
210
|
+
for (const p of arxivPapers) {
|
|
211
|
+
pushUnique(p);
|
|
212
|
+
}
|
|
213
|
+
} catch (e) {
|
|
214
|
+
console.warn("[AcademicSearchEngine] ArXiv fallback failed:", e?.message || e);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return papers.slice(0, limit);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export { AcademicPaperSchema, AcademicSearchEngine, ArXivSearchEngine, reconstructOpenAlexAbstract };
|
|
222
|
+
//# sourceMappingURL=chunk-AKEI7H2C.js.map
|
|
223
|
+
//# sourceMappingURL=chunk-AKEI7H2C.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/academic/arxivClient.ts","../src/academic/semanticScholar.ts"],"names":[],"mappings":";;;AAKO,IAAM,oBAAN,MAAwB;AAAA;AAAA;AAAA;AAAA,EAI7B,MAAM,MAAA,CAAO,KAAA,EAAe,UAAA,GAAa,CAAA,EAA6B;AACpE,IAAA,MAAM,SAA0B,EAAC;AAEjC,IAAA,IAAI;AACF,MAAA,MA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,GAAA,EAAK,IAAA,CAAK,GAAA,GAAM,MAAA,CAAO,IAAA,CAAK,GAAG,CAAA,CAAE,OAAA,CAAQ,yBAAA,EAA2B,EAAE,CAAA,GAAI,KAAA,CAAA;AAAA,gBAC1E,GAAA,EAAK,IAAA,CAAK,GAAA,IAAO,IAAA,CAAK,EAAA;AAAA,gBACtB,MAAA,EAAQ,KAAK,WAAA,EAAa,MAAA;AAAA,gBAC1B,eAAe,QAAA,CAAS,MAAA,GAAS,CAAA,GAAI,QAAA,GAAW,CAAC,kBAAkB;AAAA,eACpE,CAAA;AAAA,YACH;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,CAAA,EAAQ;AACf,QAAA,OAAA,CAAQ,IAAA,CAAK,yCAAA,EAA2C,CAAA,EAAG,OAAA,IAAW,CAAC,CAAA;AAAA,MACzE;AAAA,IACF;AAGA,IAAA,IAAI,MAAA,CAAO,MAAA,GAAS,KAAA,IAAS,OAAA,CAAQ,yBAAyB,KAAA,EAAO;AACnE,MAAA,IAAI;AACF,QAAA,MAAM,WAAA,GAAc,MAAM,IAAA,CAAK,WAAA,CAAY,OAAO,KAAA,EAAO,KAAA,GAAQ,OAAO,MAAM,CAAA;AAC9E,QAAA,KAAA,MAAW,KAAK,WAAA,EAAa;AAC3B,UAAA,UAAA,CAAW,CAAC,CAAA;AAAA,QACd;AAAA,MACF,SAAS,CAAA,EAAQ;AACf,QAAA,OAAA,CAAQ,IAAA,CAAK,+CAAA,EAAiD,CAAA,EAAG,OAAA,IAAW,CAAC,CAAA;AAAA,MAC/E;AAAA,IACF;AAEA,IAAA,OAAO,MAAA,CAAO,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA;AAAA,EAC9B;AACF","file":"chunk-AKEI7H2C.js","sourcesContent":["import { AcademicPaper } from './semanticScholar';\n\n/**\n * ArXiv API Client for Deep AI & Computer Science Paper Discovery\n */\nexport class ArXivSearchEngine {\n /**\n * Search ArXiv repository using the public atom XML API\n */\n async search(query: string, maxResults = 5): Promise<AcademicPaper[]> {\n const papers: AcademicPaper[] = [];\n\n try {\n const url = `https://export.arxiv.org/api/query?search_query=all:${encodeURIComponent(query)}&start=0&max_results=${maxResults}&sortBy=relevance&sortOrder=descending`;\n const res = await fetch(url, { signal: AbortSignal.timeout(10000) });\n\n if (res.ok) {\n const xmlText = await res.text();\n const entryMatches = xmlText.match(/<entry>[\\s\\S]*?<\\/entry>/g) || [];\n\n for (const entry of entryMatches) {\n const idMatch = entry.match(/<id>([\\s\\S]*?)<\\/id>/);\n const titleMatch = entry.match(/<title>([\\s\\S]*?)<\\/title>/);\n const summaryMatch = entry.match(/<summary>([\\s\\S]*?)<\\/summary>/);\n const publishedMatch = entry.match(/<published>(\\d{4})/);\n const authorMatches = [...entry.matchAll(/<author>\\s*<name>([\\s\\S]*?)<\\/name>/g)].map(m => m[1]?.trim()).filter(Boolean);\n\n const arxivUrl = idMatch ? idMatch[1]?.trim() : '';\n const pdfUrl = arxivUrl ? arxivUrl.replace('/abs/', '/pdf/') + '.pdf' : undefined;\n\n if (titleMatch) {\n papers.push({\n id: arxivUrl || `arxiv-${Math.random().toString(36).substring(7)}`,\n title: titleMatch[1]?.trim().replace(/\\s+/g, ' ') || 'Untitled ArXiv Paper',\n abstract: summaryMatch ? summaryMatch[1]?.trim().replace(/\\s+/g, ' ') : '',\n authors: authorMatches,\n year: publishedMatch ? parseInt(publishedMatch[1]!, 10) : new Date().getFullYear(),\n citationCount: 0,\n venue: 'arXiv preprint',\n url: arxivUrl,\n pdfUrl,\n fieldsOfStudy: ['Computer Science', 'AI & Machine Learning']\n });\n }\n }\n }\n } catch (e: any) {\n console.warn('[ArXivSearchEngine] ArXiv search failed:', e?.message || e);\n }\n\n return papers;\n }\n}\n","import { z } from 'zod';\nimport { CustomAcademicSearchAdapter } from '../config/researchConfig';\nimport { ArXivSearchEngine } from './arxivClient';\n\nexport const AcademicPaperSchema = z.object({\n id: z.string(),\n title: z.string(),\n abstract: z.string().optional(),\n authors: z.array(z.string()).default([]),\n year: z.number().optional(),\n citationCount: z.number().default(0),\n venue: z.string().optional(),\n doi: z.string().optional(),\n url: z.string().optional(),\n pdfUrl: z.string().optional(),\n tldr: z.string().optional(),\n fieldsOfStudy: z.array(z.string()).default([]),\n});\n\nexport type AcademicPaper = z.infer<typeof AcademicPaperSchema>;\n\nexport interface AcademicSearchOptions {\n limit?: number;\n yearRange?: string; // e.g. \"2020-2026\"\n fieldsOfStudy?: string[];\n apiKey?: string;\n allowEnvFallback?: boolean;\n includeArxivFallback?: boolean;\n customAdapter?: CustomAcademicSearchAdapter;\n}\n\n/**\n * Reconstructs plain-text abstract from OpenAlex's `abstract_inverted_index` object (`{ word: [pos1, pos2] }`).\n */\nexport function reconstructOpenAlexAbstract(invertedIndex: Record<string, number[]> | undefined | null): string | undefined {\n if (!invertedIndex || typeof invertedIndex !== 'object') return undefined;\n const entries = Object.entries(invertedIndex);\n if (entries.length === 0) return undefined;\n\n let maxIndex = 0;\n for (const [, positions] of entries) {\n if (Array.isArray(positions)) {\n for (const p of positions) {\n if (typeof p === 'number' && p > maxIndex) maxIndex = p;\n }\n }\n }\n if (maxIndex > 5000) maxIndex = 5000;\n\n const words = new Array<string>(maxIndex + 1);\n for (const [word, positions] of entries) {\n if (Array.isArray(positions)) {\n for (const p of positions) {\n if (typeof p === 'number' && p >= 0 && p <= maxIndex) {\n words[p] = word;\n }\n }\n }\n }\n\n const reconstructed = words.filter(Boolean).join(' ').trim();\n return reconstructed.length > 0 ? reconstructed : undefined;\n}\n\n/**\n * Semantic Scholar, OpenAlex & ArXiv Academic Search Engine with Custom Adapter Support\n */\nexport class AcademicSearchEngine {\n private apiKey?: string;\n private allowEnvFallback: boolean;\n private customAdapter?: CustomAcademicSearchAdapter;\n private arxivEngine: ArXivSearchEngine;\n\n constructor(\n options: { apiKey?: string; allowEnvFallback?: boolean; customAdapter?: CustomAcademicSearchAdapter } | string = {}\n ) {\n this.arxivEngine = new ArXivSearchEngine();\n if (typeof options === 'string') {\n this.apiKey = options;\n this.allowEnvFallback = true;\n } else {\n this.allowEnvFallback = options.allowEnvFallback ?? true;\n this.apiKey = options.apiKey || (this.allowEnvFallback ? process.env.SEMANTIC_SCHOLAR_API_KEY : undefined);\n this.customAdapter = options.customAdapter;\n }\n }\n\n setCustomAdapter(adapter: CustomAcademicSearchAdapter) {\n this.customAdapter = adapter;\n }\n\n setApiKey(apiKey?: string) {\n this.apiKey = apiKey;\n }\n\n /**\n * Search academic papers across Semantic Scholar with OpenAlex and ArXiv fallback or Custom Adapter\n */\n async searchPapers(query: string, options: AcademicSearchOptions = {}): Promise<AcademicPaper[]> {\n const adapter = options.customAdapter || this.customAdapter;\n\n // 0. Custom Academic Adapter\n if (adapter) {\n try {\n const customPapers = await adapter.searchPapers(query, { limit: options.limit, yearRange: options.yearRange });\n if (Array.isArray(customPapers) && customPapers.length > 0) {\n return customPapers;\n }\n } catch (e: any) {\n console.warn('[AcademicSearchEngine] Custom academic adapter failed:', e?.message || e);\n }\n }\n\n const limit = options.limit ?? 5;\n const papers: AcademicPaper[] = [];\n const seenTitles = new Set<string>();\n\n const pushUnique = (p: AcademicPaper) => {\n const normTitle = p.title.toLowerCase().replace(/[^a-z0-9\\u00C0-\\u1EF9]+/g, '');\n if (!normTitle || seenTitles.has(normTitle)) return;\n seenTitles.add(normTitle);\n papers.push(p);\n };\n\n // 1. Try Semantic Scholar API\n try {\n const apiKey = options.apiKey || this.apiKey;\n const headers: Record<string, string> = { 'Content-Type': 'application/json' };\n if (apiKey) {\n headers['x-api-key'] = apiKey;\n }\n\n const params = new URLSearchParams({\n query,\n limit: limit.toString(),\n fields: 'paperId,title,abstract,authors,year,citationCount,venue,externalIds,url,openAccessPdf,tldr,fieldsOfStudy',\n });\n\n if (options.yearRange) {\n params.append('year', options.yearRange);\n }\n\n const res = await fetch(`https://api.semanticscholar.org/graph/v1/paper/search?${params.toString()}`, {\n headers,\n signal: AbortSignal.timeout(6000),\n });\n\n if (res.ok) {\n const data = await res.json();\n if (Array.isArray(data?.data)) {\n for (const item of data.data) {\n pushUnique({\n id: item.paperId || `s2-${Math.random().toString(36).slice(2, 8)}`,\n title: item.title || 'Untitled',\n abstract: item.abstract || undefined,\n authors: Array.isArray(item.authors) ? item.authors.map((a: any) => a.name).filter(Boolean) : [],\n year: item.year,\n citationCount: item.citationCount || 0,\n venue: item.venue || undefined,\n doi: item.externalIds?.DOI,\n url: item.url || (item.externalIds?.DOI ? `https://doi.org/${item.externalIds.DOI}` : undefined),\n pdfUrl: item.openAccessPdf?.url,\n tldr: item.tldr?.text,\n fieldsOfStudy: Array.isArray(item.fieldsOfStudy) && item.fieldsOfStudy.length > 0 ? item.fieldsOfStudy : ['Computer Science'],\n });\n }\n if (papers.length >= limit) return papers.slice(0, limit);\n }\n }\n } catch (e: any) {\n console.warn('[AcademicSearchEngine] Semantic Scholar failed:', e?.message || e);\n }\n\n // 2. OpenAlex Fallback API (Zero-Key Open Academic Database with real abstract reconstruction)\n if (papers.length < limit) {\n try {\n const res = await fetch(`https://api.openalex.org/works?search=${encodeURIComponent(query)}&per-page=${limit}`, {\n headers: { 'User-Agent': 'OrchableComposer/1.0 (mailto:team@orchable.app)' },\n signal: AbortSignal.timeout(6000),\n });\n\n if (res.ok) {\n const data = await res.json();\n if (Array.isArray(data?.results)) {\n for (const item of data.results) {\n const abstractText = reconstructOpenAlexAbstract(item.abstract_inverted_index);\n const concepts = Array.isArray(item.concepts)\n ? item.concepts.slice(0, 3).map((c: any) => c.display_name).filter(Boolean)\n : ['Computer Science'];\n pushUnique({\n id: item.id || `oa-${Math.random().toString(36).slice(2, 8)}`,\n title: item.title || 'Untitled',\n abstract: abstractText,\n authors: Array.isArray(item.authorships)\n ? item.authorships.map((a: any) => a.author?.display_name).filter(Boolean)\n : [],\n year: item.publication_year,\n citationCount: item.cited_by_count || 0,\n venue: item.primary_location?.source?.display_name,\n doi: item.doi ? String(item.doi).replace(/^https?:\\/\\/doi\\.org\\//i, '') : undefined,\n url: item.doi || item.id,\n pdfUrl: item.open_access?.oa_url,\n fieldsOfStudy: concepts.length > 0 ? concepts : ['Computer Science'],\n });\n }\n }\n }\n } catch (e: any) {\n console.warn('[AcademicSearchEngine] OpenAlex failed:', e?.message || e);\n }\n }\n\n // 3. ArXiv Fallback API (if still below limit and not disabled)\n if (papers.length < limit && options.includeArxivFallback !== false) {\n try {\n const arxivPapers = await this.arxivEngine.search(query, limit - papers.length);\n for (const p of arxivPapers) {\n pushUnique(p);\n }\n } catch (e: any) {\n console.warn('[AcademicSearchEngine] ArXiv fallback failed:', e?.message || e);\n }\n }\n\n return papers.slice(0, limit);\n }\n}\n"]}
|