@thanh01.pmt/research-kit 1.2.0 → 1.2.3
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/dist/academic/index.cjs +11 -2
- package/dist/academic/index.cjs.map +1 -1
- 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-nrGYEY4b.d.cts → catalogBuilder-B4eiLS_S.d.cts} +27 -5
- package/dist/{catalogBuilder-2i5KASUF.d.ts → catalogBuilder-BNB_gaWP.d.ts} +27 -5
- package/dist/chunk-AKEI7H2C.js +223 -0
- package/dist/chunk-AKEI7H2C.js.map +1 -0
- package/dist/{chunk-X3X26W2I.js → chunk-HESXWQEF.js} +12 -7
- package/dist/chunk-HESXWQEF.js.map +1 -0
- package/dist/{chunk-QFYM2NV4.js → chunk-KXJDQBSJ.js} +3 -3
- package/dist/{chunk-QFYM2NV4.js.map → chunk-KXJDQBSJ.js.map} +1 -1
- package/dist/{chunk-XDDTHWJW.js → chunk-P6RHBJY2.js} +89 -25
- package/dist/chunk-P6RHBJY2.js.map +1 -0
- package/dist/{chunk-ON6VFCJO.js → chunk-QQZQNBJC.js} +51 -2
- package/dist/chunk-QQZQNBJC.js.map +1 -0
- package/dist/{chunk-QK3LVGI7.js → chunk-SAHBBO3U.js} +170 -8
- package/dist/chunk-SAHBBO3U.js.map +1 -0
- package/dist/{chunk-DOXSPRSP.js → chunk-SDDZFFL6.js} +14 -225
- package/dist/chunk-SDDZFFL6.js.map +1 -0
- package/dist/chunk-YICMTZS5.js +527 -0
- package/dist/chunk-YICMTZS5.js.map +1 -0
- package/dist/config/index.cjs +10 -5
- 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 +965 -6
- package/dist/harvester/index.cjs.map +1 -1
- package/dist/harvester/index.d.cts +87 -5
- package/dist/harvester/index.d.ts +87 -5
- package/dist/harvester/index.js +4 -3
- package/dist/{index-DlngvZBr.d.ts → index-9rDiFuR4.d.cts} +43 -12
- package/dist/{index-DlngvZBr.d.cts → index-9rDiFuR4.d.ts} +43 -12
- package/dist/index.cjs +852 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/dist/{literatureReview-C7hsjrn4.d.cts → literatureReview-BwidpYJo.d.cts} +2 -1
- package/dist/{literatureReview-DWl13r_3.d.ts → literatureReview-DOzgm9Q2.d.ts} +2 -1
- package/dist/pipeline/index.cjs +545 -249
- package/dist/pipeline/index.cjs.map +1 -1
- package/dist/pipeline/index.d.cts +10 -4
- package/dist/pipeline/index.d.ts +10 -4
- package/dist/pipeline/index.js +6 -5
- package/dist/{webScraper-yO9P-oLb.d.cts → webScraper-CAQjE46m.d.cts} +11 -2
- package/dist/{webScraper-DBFUIqoO.d.ts → webScraper-CXIpvyA6.d.ts} +11 -2
- package/package.json +1 -1
- package/dist/chunk-DOXSPRSP.js.map +0 -1
- package/dist/chunk-LSMSIPTZ.js +0 -3
- package/dist/chunk-LSMSIPTZ.js.map +0 -1
- package/dist/chunk-ON6VFCJO.js.map +0 -1
- package/dist/chunk-QK3LVGI7.js.map +0 -1
- package/dist/chunk-X3X26W2I.js.map +0 -1
- package/dist/chunk-XDDTHWJW.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -5,23 +5,28 @@ var zod = require('zod');
|
|
|
5
5
|
// src/config/researchConfig.ts
|
|
6
6
|
var ResearchConfigSchema = zod.z.object({
|
|
7
7
|
search: zod.z.object({
|
|
8
|
-
preferredProvider: zod.z.enum(["tavily", "exa", "serper", "searxng", "duckduckgo", "semantic_scholar", "openalex", "arxiv", "custom"]).default("tavily"),
|
|
9
|
-
fallbackChain: zod.z.array(zod.z.string()).default(["tavily", "exa", "serper", "duckduckgo"]),
|
|
8
|
+
preferredProvider: zod.z.enum(["tavily", "exa", "serper", "searxng", "brightdata", "duckduckgo", "semantic_scholar", "openalex", "arxiv", "custom"]).default("tavily"),
|
|
9
|
+
fallbackChain: zod.z.array(zod.z.string()).default(["tavily", "exa", "brightdata", "serper", "duckduckgo"]),
|
|
10
10
|
apiKeys: zod.z.object({
|
|
11
11
|
tavily: zod.z.string().optional(),
|
|
12
12
|
exa: zod.z.string().optional(),
|
|
13
13
|
jina: zod.z.string().optional(),
|
|
14
14
|
serper: zod.z.string().optional(),
|
|
15
|
-
semanticScholar: zod.z.string().optional()
|
|
15
|
+
semanticScholar: zod.z.string().optional(),
|
|
16
|
+
brightdata: zod.z.string().optional(),
|
|
17
|
+
brightData: zod.z.string().optional()
|
|
16
18
|
}).default({}),
|
|
17
19
|
searxngHost: zod.z.string().optional(),
|
|
20
|
+
brightDataZone: zod.z.string().optional(),
|
|
21
|
+
brightDataEngine: zod.z.enum(["google", "bing", "yandex"]).default("bing"),
|
|
18
22
|
timeoutMs: zod.z.number().default(12e3),
|
|
19
23
|
maxResultsPerQuery: zod.z.number().default(5)
|
|
20
24
|
}).default({}),
|
|
21
25
|
crawler: zod.z.object({
|
|
22
|
-
preferredProvider: zod.z.enum(["jina", "crawl4ai", "youtube", "defuddle", "direct", "custom"]).default("jina"),
|
|
23
|
-
fallbackChain: zod.z.array(zod.z.string()).default(["jina", "crawl4ai", "direct"]),
|
|
26
|
+
preferredProvider: zod.z.enum(["jina", "crawl4ai", "brightdata", "youtube", "defuddle", "direct", "custom"]).default("jina"),
|
|
27
|
+
fallbackChain: zod.z.array(zod.z.string()).default(["jina", "crawl4ai", "brightdata", "direct"]),
|
|
24
28
|
crawl4aiHost: zod.z.string().default("http://localhost:11235"),
|
|
29
|
+
brightDataZone: zod.z.string().optional(),
|
|
25
30
|
timeoutMs: zod.z.number().default(15e3),
|
|
26
31
|
maxContentLength: zod.z.number().default(1e5)
|
|
27
32
|
}).default({}),
|
|
@@ -414,9 +419,18 @@ function mapTopicToCS2023(topic, context) {
|
|
|
414
419
|
return { area: CS2023_KNOWLEDGE_AREAS.SE, k12Strand: CSTA_K12_STRANDS.AP, matchConfidence: 0.88 };
|
|
415
420
|
}
|
|
416
421
|
if (/\b(algorithm|data structure|tree|graph|dynamic programming|sorting|thuật toán|cấu trúc dữ liệu|đồ thị|quy hoạch động)\b/.test(combined)) {
|
|
417
|
-
return { area: CS2023_KNOWLEDGE_AREAS.AL, k12Strand: CSTA_K12_STRANDS.AP, matchConfidence: 0.9 };
|
|
422
|
+
return { area: CS2023_KNOWLEDGE_AREAS.AL, k12Strand: CSTA_K12_STRANDS.AP, matchConfidence: 0.9, isCsApplicable: true };
|
|
418
423
|
}
|
|
419
|
-
|
|
424
|
+
const isExplicitNonCoding = /\b(noncoding|non-coding|phi lập trình|không lập trình|applied science|khoa học ứng dụng|general science|khoa học tự nhiên|applied-noncoding)\b/i.test(combined);
|
|
425
|
+
if (isExplicitNonCoding) {
|
|
426
|
+
return {
|
|
427
|
+
area: CS2023_KNOWLEDGE_AREAS.SPD,
|
|
428
|
+
k12Strand: CSTA_K12_STRANDS.IC,
|
|
429
|
+
matchConfidence: 0.25,
|
|
430
|
+
isCsApplicable: false
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
return { area: CS2023_KNOWLEDGE_AREAS.SDF, k12Strand: CSTA_K12_STRANDS.AP, matchConfidence: 0.45, isCsApplicable: true };
|
|
420
434
|
}
|
|
421
435
|
|
|
422
436
|
// src/academic/citationManager.ts
|
|
@@ -700,14 +714,29 @@ var MultiSourceSearchEngine = class {
|
|
|
700
714
|
tavilyKey;
|
|
701
715
|
exaKey;
|
|
702
716
|
serperKey;
|
|
717
|
+
brightDataKey;
|
|
718
|
+
brightDataZone;
|
|
719
|
+
searxngHost;
|
|
720
|
+
searxngHeaders;
|
|
703
721
|
allowEnvFallback;
|
|
704
722
|
customAdapter;
|
|
723
|
+
academicEngine;
|
|
705
724
|
constructor(options = {}) {
|
|
706
725
|
this.allowEnvFallback = options.allowEnvFallback ?? true;
|
|
707
726
|
this.tavilyKey = options.apiKeys?.tavily || options.tavilyKey || (this.allowEnvFallback ? process.env.TAVILY_API_KEY : void 0);
|
|
708
727
|
this.exaKey = options.apiKeys?.exa || options.exaKey || (this.allowEnvFallback ? process.env.EXA_API_KEY : void 0);
|
|
709
728
|
this.serperKey = options.apiKeys?.serper || options.serperKey || (this.allowEnvFallback ? process.env.SERPER_API_KEY : void 0);
|
|
729
|
+
this.brightDataKey = options.apiKeys?.brightdata || options.apiKeys?.brightData || options.brightDataKey || (this.allowEnvFallback ? process.env.BRIGHTDATA_API_KEY || process.env.BRIGHT_DATA_KEY : void 0);
|
|
730
|
+
this.brightDataZone = options.brightDataZone || (this.allowEnvFallback ? process.env.BRIGHTDATA_SERP_ZONE || process.env.BRIGHTDATA_UNLOCKER_ZONE : void 0) || "cli_unlocker";
|
|
731
|
+
this.searxngHost = options.searxngHost || (this.allowEnvFallback ? process.env.SEARXNG_URL || process.env.SEARXNG_HOST : void 0);
|
|
732
|
+
const cfId = process.env.CF_ACCESS_CLIENT_ID;
|
|
733
|
+
const cfSecret = process.env.CF_ACCESS_CLIENT_SECRET;
|
|
734
|
+
this.searxngHeaders = {
|
|
735
|
+
...options.searxngHeaders || {},
|
|
736
|
+
...cfId && cfSecret ? { "CF-Access-Client-Id": cfId, "CF-Access-Client-Secret": cfSecret } : {}
|
|
737
|
+
};
|
|
710
738
|
this.customAdapter = options.customAdapter;
|
|
739
|
+
this.academicEngine = new AcademicSearchEngine({ allowEnvFallback: this.allowEnvFallback });
|
|
711
740
|
}
|
|
712
741
|
setCustomAdapter(adapter) {
|
|
713
742
|
this.customAdapter = adapter;
|
|
@@ -716,6 +745,18 @@ var MultiSourceSearchEngine = class {
|
|
|
716
745
|
if (keys.tavily !== void 0) this.tavilyKey = keys.tavily;
|
|
717
746
|
if (keys.exa !== void 0) this.exaKey = keys.exa;
|
|
718
747
|
if (keys.serper !== void 0) this.serperKey = keys.serper;
|
|
748
|
+
if (keys.brightdata !== void 0) this.brightDataKey = keys.brightdata;
|
|
749
|
+
if (keys.brightData !== void 0) this.brightDataKey = keys.brightData;
|
|
750
|
+
}
|
|
751
|
+
setBrightData(key, zone) {
|
|
752
|
+
if (key !== void 0) this.brightDataKey = key;
|
|
753
|
+
if (zone !== void 0) this.brightDataZone = zone;
|
|
754
|
+
}
|
|
755
|
+
setSearxng(host, headers) {
|
|
756
|
+
this.searxngHost = host;
|
|
757
|
+
if (headers) {
|
|
758
|
+
this.searxngHeaders = { ...this.searxngHeaders, ...headers };
|
|
759
|
+
}
|
|
719
760
|
}
|
|
720
761
|
async search(query, options = {}) {
|
|
721
762
|
const limit = options.limit ?? 5;
|
|
@@ -737,9 +778,39 @@ var MultiSourceSearchEngine = class {
|
|
|
737
778
|
console.warn("[MultiSourceSearchEngine] Custom search adapter failed:", e?.message || e);
|
|
738
779
|
}
|
|
739
780
|
}
|
|
781
|
+
if (preferred === "academic") {
|
|
782
|
+
try {
|
|
783
|
+
const papers = await this.academicEngine.searchPapers(query, { limit });
|
|
784
|
+
if (papers.length > 0) {
|
|
785
|
+
return papers.map((p) => ({
|
|
786
|
+
title: p.title,
|
|
787
|
+
url: p.url || p.pdfUrl || (p.doi ? `https://doi.org/${p.doi}` : `https://openalex.org/${p.id}`),
|
|
788
|
+
content: p.tldr || p.abstract || "",
|
|
789
|
+
score: p.citationCount,
|
|
790
|
+
engine: "academic"
|
|
791
|
+
}));
|
|
792
|
+
}
|
|
793
|
+
} catch (e) {
|
|
794
|
+
console.warn("[MultiSourceSearchEngine] Academic search failed:", e?.message || e);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
740
797
|
const tavilyKey = options.apiKeys?.tavily || options.tavilyKey || this.tavilyKey;
|
|
741
798
|
const exaKey = options.apiKeys?.exa || options.exaKey || this.exaKey;
|
|
742
799
|
const serperKey = options.apiKeys?.serper || options.serperKey || this.serperKey;
|
|
800
|
+
const brightDataKey = options.apiKeys?.brightdata || options.apiKeys?.brightData || options.brightDataKey || this.brightDataKey;
|
|
801
|
+
const brightDataZone = options.brightDataZone || this.brightDataZone;
|
|
802
|
+
const searxngHost = options.searxngHost || this.searxngHost;
|
|
803
|
+
if (preferred === "searxng" && searxngHost) {
|
|
804
|
+
const searxHits = await this.querySearxng(query, searxngHost, limit, options.searxngHeaders);
|
|
805
|
+
if (searxHits.length > 0) return searxHits;
|
|
806
|
+
}
|
|
807
|
+
if (preferred === "brightdata" && brightDataKey) {
|
|
808
|
+
const bdHits = await this.queryBrightData(query, brightDataKey, limit, {
|
|
809
|
+
zone: brightDataZone,
|
|
810
|
+
engine: options.brightDataEngine
|
|
811
|
+
});
|
|
812
|
+
if (bdHits.length > 0) return bdHits;
|
|
813
|
+
}
|
|
743
814
|
if (preferred === "exa" && exaKey) {
|
|
744
815
|
const exaHits = await this.queryExa(query, exaKey, limit, options.domainFilter);
|
|
745
816
|
if (exaHits.length > 0) return exaHits;
|
|
@@ -761,6 +832,9 @@ var MultiSourceSearchEngine = class {
|
|
|
761
832
|
include_answer: true,
|
|
762
833
|
max_results: limit
|
|
763
834
|
};
|
|
835
|
+
if (options.timeRange) {
|
|
836
|
+
body.time_range = options.timeRange;
|
|
837
|
+
}
|
|
764
838
|
if (options.domainFilter && options.domainFilter.length > 0) {
|
|
765
839
|
body.include_domains = options.domainFilter;
|
|
766
840
|
}
|
|
@@ -787,18 +861,103 @@ var MultiSourceSearchEngine = class {
|
|
|
787
861
|
}
|
|
788
862
|
}
|
|
789
863
|
if (exaKey) {
|
|
790
|
-
const exaHits = await this.queryExa(query, exaKey, limit, options.domainFilter);
|
|
864
|
+
const exaHits = await this.queryExa(query, exaKey, limit, options.domainFilter, options.timeRange);
|
|
791
865
|
if (exaHits.length > 0) return exaHits;
|
|
792
866
|
}
|
|
793
867
|
if (serperKey) {
|
|
794
|
-
const serperHits = await this.querySerper(query, serperKey, limit);
|
|
868
|
+
const serperHits = await this.querySerper(query, serperKey, limit, options.timeRange);
|
|
795
869
|
if (serperHits.length > 0) return serperHits;
|
|
796
870
|
}
|
|
871
|
+
if (brightDataKey) {
|
|
872
|
+
const bdHits = await this.queryBrightData(query, brightDataKey, limit, {
|
|
873
|
+
zone: brightDataZone,
|
|
874
|
+
engine: options.brightDataEngine
|
|
875
|
+
});
|
|
876
|
+
if (bdHits.length > 0) return bdHits;
|
|
877
|
+
}
|
|
878
|
+
if (searxngHost) {
|
|
879
|
+
const searxHits = await this.querySearxng(query, searxngHost, limit, options.searxngHeaders, options.timeRange);
|
|
880
|
+
if (searxHits.length > 0) return searxHits;
|
|
881
|
+
}
|
|
797
882
|
const ddgHits = await this.queryDuckDuckGo(query, limit);
|
|
798
883
|
if (ddgHits.length > 0) return ddgHits;
|
|
799
884
|
return [];
|
|
800
885
|
}
|
|
801
|
-
async
|
|
886
|
+
async queryBrightData(query, key, limit = 5, options = {}) {
|
|
887
|
+
try {
|
|
888
|
+
const zone = options.zone || this.brightDataZone || "cli_unlocker";
|
|
889
|
+
const engine = options.engine || "bing";
|
|
890
|
+
let searchUrl = `https://www.bing.com/search?q=${encodeURIComponent(query)}&brd_json=1`;
|
|
891
|
+
if (engine === "google") {
|
|
892
|
+
searchUrl = `https://www.google.com/search?q=${encodeURIComponent(query)}&brd_json=1&hl=en&gl=us`;
|
|
893
|
+
} else if (engine === "yandex") {
|
|
894
|
+
searchUrl = `https://www.yandex.com/search?q=${encodeURIComponent(query)}&brd_json=1`;
|
|
895
|
+
}
|
|
896
|
+
const res = await fetch("https://api.brightdata.com/request", {
|
|
897
|
+
method: "POST",
|
|
898
|
+
headers: {
|
|
899
|
+
Authorization: `Bearer ${key}`,
|
|
900
|
+
"Content-Type": "application/json"
|
|
901
|
+
},
|
|
902
|
+
body: JSON.stringify({
|
|
903
|
+
zone,
|
|
904
|
+
url: searchUrl,
|
|
905
|
+
format: "raw"
|
|
906
|
+
}),
|
|
907
|
+
signal: AbortSignal.timeout(15e3)
|
|
908
|
+
});
|
|
909
|
+
if (res.ok) {
|
|
910
|
+
const data = await res.json();
|
|
911
|
+
const organic = Array.isArray(data?.organic) ? data.organic : [];
|
|
912
|
+
if (organic.length > 0) {
|
|
913
|
+
return organic.slice(0, limit).map((r, idx) => ({
|
|
914
|
+
title: r.title || "Untitled",
|
|
915
|
+
url: r.link,
|
|
916
|
+
content: r.description || r.snippet || "",
|
|
917
|
+
score: r.rank ? 1 / r.rank : 1 / (idx + 1),
|
|
918
|
+
engine: "brightdata"
|
|
919
|
+
}));
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
} catch (e) {
|
|
923
|
+
console.warn("[MultiSourceSearchEngine] Bright Data attempt failed:", e?.message || e);
|
|
924
|
+
}
|
|
925
|
+
return [];
|
|
926
|
+
}
|
|
927
|
+
async querySearxng(query, searxngHost, limit, customHeaders, timeRange) {
|
|
928
|
+
try {
|
|
929
|
+
const cleanHost = searxngHost.replace(/\/$/, "");
|
|
930
|
+
let searchUrl = `${cleanHost}/search?q=${encodeURIComponent(query)}&format=json`;
|
|
931
|
+
if (timeRange) {
|
|
932
|
+
searchUrl += `&time_range=${encodeURIComponent(timeRange)}`;
|
|
933
|
+
}
|
|
934
|
+
const headers = {
|
|
935
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
|
|
936
|
+
...this.searxngHeaders || {},
|
|
937
|
+
...customHeaders || {}
|
|
938
|
+
};
|
|
939
|
+
const res = await fetch(searchUrl, {
|
|
940
|
+
headers,
|
|
941
|
+
signal: AbortSignal.timeout(1e4)
|
|
942
|
+
});
|
|
943
|
+
if (res.ok) {
|
|
944
|
+
const data = await res.json();
|
|
945
|
+
if (Array.isArray(data?.results) && data.results.length > 0) {
|
|
946
|
+
return data.results.slice(0, limit).map((r) => ({
|
|
947
|
+
title: r.title || "Untitled",
|
|
948
|
+
url: r.url,
|
|
949
|
+
content: r.content || r.snippet || "",
|
|
950
|
+
score: r.score,
|
|
951
|
+
engine: "searxng"
|
|
952
|
+
}));
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
} catch (e) {
|
|
956
|
+
console.warn("[MultiSourceSearchEngine] SearXNG attempt failed:", e?.message || e);
|
|
957
|
+
}
|
|
958
|
+
return [];
|
|
959
|
+
}
|
|
960
|
+
async queryExa(query, exaKey, limit, domainFilter, timeRange) {
|
|
802
961
|
try {
|
|
803
962
|
const body = {
|
|
804
963
|
query,
|
|
@@ -808,6 +967,14 @@ var MultiSourceSearchEngine = class {
|
|
|
808
967
|
if (domainFilter && domainFilter.length > 0) {
|
|
809
968
|
body.includeDomains = domainFilter;
|
|
810
969
|
}
|
|
970
|
+
if (timeRange) {
|
|
971
|
+
const now = /* @__PURE__ */ new Date();
|
|
972
|
+
if (timeRange === "day") now.setDate(now.getDate() - 1);
|
|
973
|
+
else if (timeRange === "week") now.setDate(now.getDate() - 7);
|
|
974
|
+
else if (timeRange === "month") now.setMonth(now.getMonth() - 1);
|
|
975
|
+
else if (timeRange === "year") now.setFullYear(now.getFullYear() - 1);
|
|
976
|
+
body.startPublishedDate = now.toISOString();
|
|
977
|
+
}
|
|
811
978
|
const res = await fetch("https://api.exa.ai/search", {
|
|
812
979
|
method: "POST",
|
|
813
980
|
headers: {
|
|
@@ -834,15 +1001,22 @@ var MultiSourceSearchEngine = class {
|
|
|
834
1001
|
}
|
|
835
1002
|
return [];
|
|
836
1003
|
}
|
|
837
|
-
async querySerper(query, serperKey, limit) {
|
|
1004
|
+
async querySerper(query, serperKey, limit, timeRange) {
|
|
838
1005
|
try {
|
|
1006
|
+
const body = { q: query, num: limit };
|
|
1007
|
+
if (timeRange) {
|
|
1008
|
+
const tbsMap = { day: "qdr:d", week: "qdr:w", month: "qdr:m", year: "qdr:y" };
|
|
1009
|
+
if (tbsMap[timeRange]) {
|
|
1010
|
+
body.tbs = tbsMap[timeRange];
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
839
1013
|
const res = await fetch("https://google.serper.dev/search", {
|
|
840
1014
|
method: "POST",
|
|
841
1015
|
headers: {
|
|
842
1016
|
"X-API-KEY": serperKey,
|
|
843
1017
|
"Content-Type": "application/json"
|
|
844
1018
|
},
|
|
845
|
-
body: JSON.stringify(
|
|
1019
|
+
body: JSON.stringify(body),
|
|
846
1020
|
signal: AbortSignal.timeout(1e4)
|
|
847
1021
|
});
|
|
848
1022
|
if (res.ok) {
|
|
@@ -1091,6 +1265,8 @@ function extractSubstantiveExcerpts(markdown, maxExcerpts = 6) {
|
|
|
1091
1265
|
var WebScraper = class {
|
|
1092
1266
|
crawl4aiHost;
|
|
1093
1267
|
jinaKey;
|
|
1268
|
+
brightDataKey;
|
|
1269
|
+
brightDataZone;
|
|
1094
1270
|
allowEnvFallback;
|
|
1095
1271
|
customAdapter;
|
|
1096
1272
|
youtubeService;
|
|
@@ -1098,6 +1274,8 @@ var WebScraper = class {
|
|
|
1098
1274
|
this.allowEnvFallback = options.allowEnvFallback ?? true;
|
|
1099
1275
|
this.crawl4aiHost = options.crawl4aiHost || (this.allowEnvFallback ? process.env.CRAWL4AI_HOST : void 0) || "http://localhost:11235";
|
|
1100
1276
|
this.jinaKey = options.jinaKey || (this.allowEnvFallback ? process.env.JINA_API_KEY : void 0);
|
|
1277
|
+
this.brightDataKey = options.brightDataKey || (this.allowEnvFallback ? process.env.BRIGHTDATA_API_KEY || process.env.BRIGHT_DATA_KEY : void 0);
|
|
1278
|
+
this.brightDataZone = options.brightDataZone || (this.allowEnvFallback ? process.env.BRIGHTDATA_UNLOCKER_ZONE : void 0) || "cli_unlocker";
|
|
1101
1279
|
this.customAdapter = options.customAdapter;
|
|
1102
1280
|
this.youtubeService = new YouTubeIngestionService();
|
|
1103
1281
|
}
|
|
@@ -1107,8 +1285,15 @@ var WebScraper = class {
|
|
|
1107
1285
|
setJinaKey(key) {
|
|
1108
1286
|
this.jinaKey = key;
|
|
1109
1287
|
}
|
|
1288
|
+
setBrightData(key, zone) {
|
|
1289
|
+
if (key !== void 0) this.brightDataKey = key;
|
|
1290
|
+
if (zone !== void 0) this.brightDataZone = zone;
|
|
1291
|
+
}
|
|
1110
1292
|
async scrapeUrl(targetUrl, options = {}) {
|
|
1111
1293
|
const adapter = options.customAdapter || this.customAdapter;
|
|
1294
|
+
const bdKey = options.brightDataKey || this.brightDataKey;
|
|
1295
|
+
const bdZone = options.brightDataZone || this.brightDataZone;
|
|
1296
|
+
const preferred = options.preferredProvider;
|
|
1112
1297
|
if (adapter) {
|
|
1113
1298
|
try {
|
|
1114
1299
|
const result = await adapter.crawl(targetUrl);
|
|
@@ -1129,6 +1314,13 @@ var WebScraper = class {
|
|
|
1129
1314
|
console.warn(`[WebScraper] YouTube transcript extraction failed for ${targetUrl}:`, e?.message || e);
|
|
1130
1315
|
}
|
|
1131
1316
|
}
|
|
1317
|
+
if (preferred === "brightdata" && bdKey) {
|
|
1318
|
+
try {
|
|
1319
|
+
return await this.scrapeWithBrightData(targetUrl, bdKey, bdZone);
|
|
1320
|
+
} catch (e) {
|
|
1321
|
+
console.warn(`[WebScraper] Preferred Bright Data failed for ${targetUrl}:`, e?.message || e);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1132
1324
|
try {
|
|
1133
1325
|
const jinaUrl = `https://r.jina.ai/${targetUrl}`;
|
|
1134
1326
|
const jinaKey = options.jinaKey || this.jinaKey;
|
|
@@ -1173,6 +1365,13 @@ var WebScraper = class {
|
|
|
1173
1365
|
} catch {
|
|
1174
1366
|
}
|
|
1175
1367
|
}
|
|
1368
|
+
if (bdKey) {
|
|
1369
|
+
try {
|
|
1370
|
+
return await this.scrapeWithBrightData(targetUrl, bdKey, bdZone);
|
|
1371
|
+
} catch (e) {
|
|
1372
|
+
console.warn(`[WebScraper] Bright Data fallback failed for ${targetUrl}:`, e?.message || e);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1176
1375
|
try {
|
|
1177
1376
|
const res = await fetch(targetUrl, {
|
|
1178
1377
|
headers: { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" },
|
|
@@ -1197,6 +1396,30 @@ ${p.replace(/<[^>]+>/g, " ").trim()}
|
|
|
1197
1396
|
}
|
|
1198
1397
|
throw new Error(`Unable to fetch content from URL: ${targetUrl}`);
|
|
1199
1398
|
}
|
|
1399
|
+
async scrapeWithBrightData(targetUrl, key, zone) {
|
|
1400
|
+
const reqZone = zone || this.brightDataZone || "cli_unlocker";
|
|
1401
|
+
const res = await fetch("https://api.brightdata.com/request", {
|
|
1402
|
+
method: "POST",
|
|
1403
|
+
headers: {
|
|
1404
|
+
Authorization: `Bearer ${key}`,
|
|
1405
|
+
"Content-Type": "application/json"
|
|
1406
|
+
},
|
|
1407
|
+
body: JSON.stringify({
|
|
1408
|
+
zone: reqZone,
|
|
1409
|
+
url: targetUrl,
|
|
1410
|
+
format: "raw",
|
|
1411
|
+
data_format: "markdown"
|
|
1412
|
+
}),
|
|
1413
|
+
signal: AbortSignal.timeout(2e4)
|
|
1414
|
+
});
|
|
1415
|
+
if (res.ok) {
|
|
1416
|
+
const markdown = await res.text();
|
|
1417
|
+
if (markdown && markdown.length > 30) {
|
|
1418
|
+
return this.packageDocument(targetUrl, markdown, "brightdata");
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
throw new Error(`Bright Data Web Unlocker failed with HTTP ${res.status}`);
|
|
1422
|
+
}
|
|
1200
1423
|
packageDocument(url, markdown, provider, explicitTitle) {
|
|
1201
1424
|
const titleMatch = markdown.match(/^#\s+(.+)$/m) || markdown.match(/^Title:\s*(.+)$/im);
|
|
1202
1425
|
const title = (explicitTitle || (titleMatch ? titleMatch[1].trim() : url.split("/").filter(Boolean).pop() || "Document")).slice(0, 180);
|
|
@@ -1751,7 +1974,7 @@ ${corpusPreview}`,
|
|
|
1751
1974
|
`
|
|
1752
1975
|
Return ONLY a valid JSON array of 6 to 12 atomic pedagogical concepts ordered from foundational to advanced.`,
|
|
1753
1976
|
`IMPORTANT FOR VIETNAMESE TERMS: Keep multi-syllable Vietnamese compound terms intact (e.g. "Bi\u1EBFn tr\u1EA1ng th\xE1i", "C\u1EA3m bi\u1EBFn \xE1nh s\xE1ng", "V\xF2ng l\u1EB7p s\u1EF1 ki\u1EC7n") and pair them with accurate English canonical terms.`,
|
|
1754
|
-
`Each item in the JSON array must have: {"id": "C_01", "term": "Display Name", "termVi": "Thu\u1EADt ng\u1EEF Ti\u1EBFng Vi\u1EC7t chu\u1EA9n", "termEn": "Canonical English Term", "category": "core_concept"|"api_syntax"|"hardware_component"|"pedagogical_pattern", "marrLayer": "ULO"|"CIO"|"SIO", "bloomLevel": "understand"|"apply"|"analyze", "salienceScore": 9.0, "definition": "1-sentence clear definition grounded in sources", "prerequisites": ["C_01"], "sourceIds": ["RES-01"], "facets": {"computationalPrinciple": "...", "mentalModel": "...", "syntaxAndTools": ["..."]}, "commonMisconceptions": ["..."]}`
|
|
1977
|
+
`Each item in the JSON array must have: {"id": "C_01", "term": "Display Name", "termVi": "Thu\u1EADt ng\u1EEF Ti\u1EBFng Vi\u1EC7t chu\u1EA9n", "termEn": "Canonical English Term", "category": "core_concept"|"api_syntax"|"hardware_component"|"pedagogical_pattern", "marrLayer": "ULO"|"CIO"|"SIO", "bloomLevel": "understand"|"apply"|"analyze", "salienceScore": 9.0, "definition": "1-sentence clear definition grounded in sources", "prerequisites": ["C_01"], "sourceIds": ["RES-01"], "facets": {"computationalPrinciple": "...", "mentalModel": "...", "syntaxAndTools": ["..."]}, "commonMisconceptions": ["..."], "troubleshootingHints": ["2-minute quick fix for common student pitfall"]}`
|
|
1755
1978
|
].filter(Boolean).join("\n");
|
|
1756
1979
|
const rawResponse = await options.llm(prompt, {
|
|
1757
1980
|
system: "You are a Principal Computer Science Curriculum Architect & Bilingual Terminology Specialist (Vietnamese-English). Output strictly valid JSON array without markdown commentary.",
|
|
@@ -1951,6 +2174,530 @@ var HealthAuditor = class {
|
|
|
1951
2174
|
}
|
|
1952
2175
|
};
|
|
1953
2176
|
|
|
2177
|
+
// src/harvester/stemResources.ts
|
|
2178
|
+
var PHET_SIMULATIONS = [
|
|
2179
|
+
{
|
|
2180
|
+
id: "phet-circuit-construction-kit-dc",
|
|
2181
|
+
titleEn: "Circuit Construction Kit: DC",
|
|
2182
|
+
titleVi: "B\u1ED9 L\u1EAFp R\xE1p M\u1EA1ch \u0110i\u1EC7n M\u1ED9t Chi\u1EC1u (DC)",
|
|
2183
|
+
descriptionEn: "Build circuits with batteries, light bulbs, resistors, switches, and conductors. Measure voltage and current with voltmeter and ammeter.",
|
|
2184
|
+
descriptionVi: "X\xE2y d\u1EF1ng m\u1EA1ch \u0111i\u1EC7n m\u1ED9t chi\u1EC1u v\u1EDBi pin, b\xF3ng \u0111\xE8n, \u0111i\u1EC7n tr\u1EDF, c\xF4ng t\u1EAFc. \u0110o \u0111i\u1EC7n \xE1p v\xE0 d\xF2ng \u0111i\u1EC7n b\u1EB1ng v\xF4n k\u1EBF v\xE0 ampe k\u1EBF.",
|
|
2185
|
+
simUrl: "https://phet.colorado.edu/sims/html/circuit-construction-kit-dc/latest/circuit-construction-kit-dc_all.html",
|
|
2186
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/circuit-construction-kit-dc/latest/circuit-construction-kit-dc-600.png",
|
|
2187
|
+
subject: "electronics",
|
|
2188
|
+
targetLevel: "all",
|
|
2189
|
+
keywords: ["circuit", "m\u1EA1ch \u0111i\u1EC7n", "\u0111i\u1EC7n tr\u1EDF", "resistor", "pin", "battery", "led", "voltage", "current", "d\xF2ng \u0111i\u1EC7n", "hi\u1EC7u \u0111i\u1EC7n th\u1EBF", "ohm", "\u0111o \u0111i\u1EC7n"]
|
|
2190
|
+
},
|
|
2191
|
+
{
|
|
2192
|
+
id: "phet-wave-on-a-string",
|
|
2193
|
+
titleEn: "Wave on a String",
|
|
2194
|
+
titleVi: "S\xF3ng Tr\xEAn D\xE2y",
|
|
2195
|
+
descriptionEn: "Simulate mechanical wave pulse and periodic oscillations. Adjust frequency, amplitude, tension, and damping.",
|
|
2196
|
+
descriptionVi: "M\xF4 ph\u1ECFng s\xF3ng c\u01A1 h\u1ECDc tr\xEAn d\xE2y. \u0110i\u1EC1u ch\u1EC9nh t\u1EA7n s\u1ED1, bi\xEAn \u0111\u1ED9, l\u1EF1c c\u0103ng v\xE0 \u0111\u1ED9 suy gi\u1EA3m.",
|
|
2197
|
+
simUrl: "https://phet.colorado.edu/sims/html/wave-on-a-string/latest/wave-on-a-string_all.html",
|
|
2198
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/wave-on-a-string/latest/wave-on-a-string-600.png",
|
|
2199
|
+
subject: "physics",
|
|
2200
|
+
targetLevel: "lower_secondary",
|
|
2201
|
+
keywords: ["wave", "s\xF3ng", "t\u1EA7n s\u1ED1", "frequency", "bi\xEAn \u0111\u1ED9", "amplitude", "sound", "\xE2m thanh", "si\xEAu \xE2m", "ultrasonic"]
|
|
2202
|
+
},
|
|
2203
|
+
{
|
|
2204
|
+
id: "phet-balloons-and-static-electricity",
|
|
2205
|
+
titleEn: "Balloons and Static Electricity",
|
|
2206
|
+
titleVi: "B\xF3ng Bay v\xE0 T\u0129nh \u0110i\u1EC7n",
|
|
2207
|
+
descriptionEn: "Explore electrical charges, attraction, repulsion, and static electricity by rubbing a balloon on a sweater.",
|
|
2208
|
+
descriptionVi: "Kh\xE1m ph\xE1 \u0111i\u1EC7n t\xEDch, l\u1EF1c h\xFAt, l\u1EF1c \u0111\u1EA9y v\xE0 hi\u1EC7n t\u01B0\u1EE3ng t\u0129nh \u0111i\u1EC7n qua qu\u1EA3 b\xF3ng bay v\xE0 \xE1o len.",
|
|
2209
|
+
simUrl: "https://phet.colorado.edu/sims/html/balloons-and-static-electricity/latest/balloons-and-static-electricity_all.html",
|
|
2210
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/balloons-and-static-electricity/latest/balloons-and-static-electricity-600.png",
|
|
2211
|
+
subject: "physics",
|
|
2212
|
+
targetLevel: "primary",
|
|
2213
|
+
keywords: ["static electricity", "t\u0129nh \u0111i\u1EC7n", "\u0111i\u1EC7n t\xEDch", "electron", "charge", "l\u1EF1c \u0111i\u1EC7n", "h\xFAt \u0111\u1EA9y"]
|
|
2214
|
+
},
|
|
2215
|
+
{
|
|
2216
|
+
id: "phet-faradays-law",
|
|
2217
|
+
titleEn: "Faraday's Law & Electromagnetic Induction",
|
|
2218
|
+
titleVi: "\u0110\u1ECBnh Lu\u1EADt Faraday & C\u1EA3m \u1EE8ng \u0110i\u1EC7n T\u1EEB",
|
|
2219
|
+
descriptionEn: "Move a bar magnet through a coil of wire to generate an electric current and illuminate a bulb. Observe magnet direction and voltage.",
|
|
2220
|
+
descriptionVi: "Di chuy\u1EC3n nam ch\xE2m qua cu\u1ED9n d\xE2y \u0111\u1EC3 t\u1EA1o ra d\xF2ng \u0111i\u1EC7n c\u1EA3m \u1EE9ng l\xE0m s\xE1ng b\xF3ng \u0111\xE8n. Quan s\xE1t chi\u1EC1u d\xF2ng \u0111i\u1EC7n v\xE0 c\u1EF1c t\u1EEB.",
|
|
2221
|
+
simUrl: "https://phet.colorado.edu/sims/html/faradays-law/latest/faradays-law_all.html",
|
|
2222
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/faradays-law/latest/faradays-law-600.png",
|
|
2223
|
+
subject: "electronics",
|
|
2224
|
+
targetLevel: "upper_secondary",
|
|
2225
|
+
keywords: ["faraday", "c\u1EA3m \u1EE9ng \u0111i\u1EC7n t\u1EEB", "nam ch\xE2m", "magnet", "cu\u1ED9n d\xE2y", "coil", "\u0111\u1ED9ng c\u01A1", "motor", "m\xE1y ph\xE1t \u0111i\u1EC7n", "generator"]
|
|
2226
|
+
},
|
|
2227
|
+
{
|
|
2228
|
+
id: "phet-color-vision",
|
|
2229
|
+
titleEn: "Color Vision (RGB & Light Filters)",
|
|
2230
|
+
titleVi: "Th\u1ECB Gi\xE1c M\xE0u (Ph\u1ED1i M\xE0u RGB & B\u1ED9 L\u1ECDc \xC1nh S\xE1ng)",
|
|
2231
|
+
descriptionEn: "Combine red, green, and blue light sources to create full spectrum colors. Ideal for teaching RGB LEDs, sensors, and display screens.",
|
|
2232
|
+
descriptionVi: "K\u1EBFt h\u1EE3p c\xE1c ngu\u1ED3n s\xE1ng \u0110\u1ECF (Red), Xanh l\u1EE5c (Green), Xanh lam (Blue) \u0111\u1EC3 t\u1EA1o ra c\xE1c d\u1EA3i m\xE0u. R\u1EA5t ph\xF9 h\u1EE3p khi d\u1EA1y LED RGB v\xE0 c\u1EA3m bi\u1EBFn m\xE0u.",
|
|
2233
|
+
simUrl: "https://phet.colorado.edu/sims/html/color-vision/latest/color-vision_all.html",
|
|
2234
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/color-vision/latest/color-vision-600.png",
|
|
2235
|
+
subject: "physics",
|
|
2236
|
+
targetLevel: "all",
|
|
2237
|
+
keywords: ["color", "m\xE0u s\u1EAFc", "rgb", "led rgb", "\xE1nh s\xE1ng", "light", "c\u1EA3m bi\u1EBFn \xE1nh s\xE1ng", "ldr", "quang h\u1ECDc", "optics"]
|
|
2238
|
+
},
|
|
2239
|
+
{
|
|
2240
|
+
id: "phet-forces-and-motion-basics",
|
|
2241
|
+
titleEn: "Forces and Motion: Basics",
|
|
2242
|
+
titleVi: "L\u1EF1c v\xE0 Chuy\u1EC3n \u0110\u1ED9ng C\u01A1 B\u1EA3n",
|
|
2243
|
+
descriptionEn: "Explore the forces at work when tugging a crate, sliding on ice, or pushing objects. Observe friction, acceleration, and Newton laws.",
|
|
2244
|
+
descriptionVi: "Kh\xE1m ph\xE1 c\xE1c l\u1EF1c t\xE1c d\u1EE5ng khi k\xE9o th\xF9ng h\xE0ng, ma s\xE1t, gia t\u1ED1c v\xE0 \u0111\u1ECBnh lu\u1EADt Newton. C\u1ED1t l\xF5i cho robot di \u0111\u1ED9ng v\xE0 xe t\u1EF1 h\xE0nh.",
|
|
2245
|
+
simUrl: "https://phet.colorado.edu/sims/html/forces-and-motion-basics/latest/forces-and-motion-basics_all.html",
|
|
2246
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/forces-and-motion-basics/latest/forces-and-motion-basics-600.png",
|
|
2247
|
+
subject: "physics",
|
|
2248
|
+
targetLevel: "all",
|
|
2249
|
+
keywords: ["force", "l\u1EF1c", "motion", "chuy\u1EC3n \u0111\u1ED9ng", "friction", "ma s\xE1t", "robotics", "xe t\u1EF1 h\xE0nh", "newton", "v\u1EADn t\u1ED1c", "gia t\u1ED1c"]
|
|
2250
|
+
},
|
|
2251
|
+
{
|
|
2252
|
+
id: "phet-gravity-and-orbits",
|
|
2253
|
+
titleEn: "Gravity and Orbits",
|
|
2254
|
+
titleVi: "L\u1EF1c H\u1EA5p D\u1EABn v\xE0 Qu\u1EF9 \u0110\u1EA1o V\u1EC7 Tinh",
|
|
2255
|
+
descriptionEn: "Move the sun, earth, moon and space station to see how gravity controls orbital velocity and gravitational pull.",
|
|
2256
|
+
descriptionVi: "Di chuy\u1EC3n M\u1EB7t Tr\u1EDDi, Tr\xE1i \u0110\u1EA5t, M\u1EB7t Tr\u0103ng v\xE0 tr\u1EA1m kh\xF4ng gian \u0111\u1EC3 xem l\u1EF1c h\u1EA5p d\u1EABn \u0111i\u1EC1u khi\u1EC3n qu\u1EF9 \u0111\u1EA1o v\xE0 v\u1EADn t\u1ED1c.",
|
|
2257
|
+
simUrl: "https://phet.colorado.edu/sims/html/gravity-and-orbits/latest/gravity-and-orbits_all.html",
|
|
2258
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/gravity-and-orbits/latest/gravity-and-orbits-600.png",
|
|
2259
|
+
subject: "physics",
|
|
2260
|
+
targetLevel: "lower_secondary",
|
|
2261
|
+
keywords: ["gravity", "tr\u1ECDng l\u1EF1c", "l\u1EF1c h\u1EA5p d\u1EABn", "qu\u1EF9 \u0111\u1EA1o", "orbit", "nasa", "kh\xF4ng gian", "space", "v\u1EC7 tinh", "satellite", "earth", "moon"]
|
|
2262
|
+
},
|
|
2263
|
+
{
|
|
2264
|
+
id: "phet-projectile-motion",
|
|
2265
|
+
titleEn: "Projectile Motion",
|
|
2266
|
+
titleVi: "Chuy\u1EC3n \u0110\u1ED9ng N\xE9m Ngang & N\xE9m Xi\xEAn",
|
|
2267
|
+
descriptionEn: "Blast cannonballs, baseballs, or pianos. Adjust launch angle, initial speed, mass, and air resistance to hit targets.",
|
|
2268
|
+
descriptionVi: "B\u1EAFn \u0111\u1EA1i b\xE1c, b\xF3ng ch\xE0y ho\u1EB7c \u0111\xE0n piano. \u0110i\u1EC1u ch\u1EC9nh g\xF3c b\u1EAFn, v\u1EADn t\u1ED1c \u0111\u1EA7u v\xE0 l\u1EF1c c\u1EA3n kh\xF4ng kh\xED. C\u1EF1c k\u1EF3 h\u1EEFu \xEDch cho l\u1EADp tr\xECnh game v\u1EADt l\xFD.",
|
|
2269
|
+
simUrl: "https://phet.colorado.edu/sims/html/projectile-motion/latest/projectile-motion_all.html",
|
|
2270
|
+
thumbnailUrl: "https://phet.colorado.edu/sims/html/projectile-motion/latest/projectile-motion-600.png",
|
|
2271
|
+
subject: "physics",
|
|
2272
|
+
targetLevel: "upper_secondary",
|
|
2273
|
+
keywords: ["projectile", "n\xE9m xi\xEAn", "qu\u1EF9 \u0111\u1EA1o", "trajectory", "game physics", "v\u1EADt l\xFD tr\xF2 ch\u01A1i", "v\u1EADn t\u1ED1c", "g\xF3c b\u1EAFn"]
|
|
2274
|
+
}
|
|
2275
|
+
];
|
|
2276
|
+
var OpenverseClient = class {
|
|
2277
|
+
baseUrl = "https://api.openverse.org/v1";
|
|
2278
|
+
async searchImages(query, options = {}) {
|
|
2279
|
+
try {
|
|
2280
|
+
const limit = Math.min(options.limit ?? 5, 20);
|
|
2281
|
+
const params = new URLSearchParams({
|
|
2282
|
+
q: query,
|
|
2283
|
+
page_size: String(limit)
|
|
2284
|
+
});
|
|
2285
|
+
if (options.license) {
|
|
2286
|
+
params.set("license", options.license);
|
|
2287
|
+
}
|
|
2288
|
+
const res = await fetch(`${this.baseUrl}/images/?${params.toString()}`, {
|
|
2289
|
+
headers: {
|
|
2290
|
+
"User-Agent": "CurriculumStudio-ResearchKit/1.2.2",
|
|
2291
|
+
Accept: "application/json"
|
|
2292
|
+
},
|
|
2293
|
+
signal: AbortSignal.timeout(8e3)
|
|
2294
|
+
});
|
|
2295
|
+
if (!res.ok) return [];
|
|
2296
|
+
const data = await res.json();
|
|
2297
|
+
const results = Array.isArray(data?.results) ? data.results : [];
|
|
2298
|
+
return results.map((item) => {
|
|
2299
|
+
const licenseType = (item.license || "CC").toUpperCase();
|
|
2300
|
+
const licenseVer = item.license_version ? ` ${item.license_version}` : "";
|
|
2301
|
+
const creator = item.creator ? ` b\u1EDFi ${item.creator}` : "";
|
|
2302
|
+
return {
|
|
2303
|
+
id: `openverse-${item.id}`,
|
|
2304
|
+
title: item.title || `H\xECnh \u1EA3nh minh h\u1ECDa: ${query}`,
|
|
2305
|
+
url: item.foreign_landing_url || item.url,
|
|
2306
|
+
description: `H\xECnh \u1EA3nh gi\u1EA5y ph\xE9p m\u1EDF (${licenseType}${licenseVer})${creator} t\u1EEB ngu\u1ED3n ${item.source || item.provider || "Openverse"}.`,
|
|
2307
|
+
type: "media_image",
|
|
2308
|
+
provider: "openverse",
|
|
2309
|
+
thumbnailUrl: item.thumbnail || item.url,
|
|
2310
|
+
mediaType: "image",
|
|
2311
|
+
license: {
|
|
2312
|
+
type: `${licenseType}${licenseVer}`,
|
|
2313
|
+
attributionText: `\u1EA2nh: "${item.title || query}"${creator} (${licenseType}${licenseVer}) via Openverse.`,
|
|
2314
|
+
url: item.license_url,
|
|
2315
|
+
commercialUseAllowed: !licenseType.includes("NC")
|
|
2316
|
+
},
|
|
2317
|
+
subject: "general_stem",
|
|
2318
|
+
targetLevel: "all",
|
|
2319
|
+
tags: Array.isArray(item.tags) ? item.tags.slice(0, 5).map((t) => t.name || String(t)) : [query],
|
|
2320
|
+
relevanceScore: 8.5
|
|
2321
|
+
};
|
|
2322
|
+
});
|
|
2323
|
+
} catch (e) {
|
|
2324
|
+
console.warn("[OpenverseClient] Kh\xF4ng th\u1EC3 t\xECm ki\u1EBFm media Openverse:", e?.message || e);
|
|
2325
|
+
return [];
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
};
|
|
2329
|
+
var NasaMediaClient = class {
|
|
2330
|
+
baseUrl = "https://images-api.nasa.gov";
|
|
2331
|
+
async search(query, options = {}) {
|
|
2332
|
+
try {
|
|
2333
|
+
const limit = Math.min(options.limit ?? 5, 20);
|
|
2334
|
+
const mediaType = options.mediaType || "image";
|
|
2335
|
+
const params = new URLSearchParams({
|
|
2336
|
+
q: query,
|
|
2337
|
+
media_type: mediaType,
|
|
2338
|
+
page_size: String(limit)
|
|
2339
|
+
});
|
|
2340
|
+
const res = await fetch(`${this.baseUrl}/search?${params.toString()}`, {
|
|
2341
|
+
headers: {
|
|
2342
|
+
"User-Agent": "CurriculumStudio-ResearchKit/1.2.2",
|
|
2343
|
+
Accept: "application/json"
|
|
2344
|
+
},
|
|
2345
|
+
signal: AbortSignal.timeout(8e3)
|
|
2346
|
+
});
|
|
2347
|
+
if (!res.ok) return [];
|
|
2348
|
+
const data = await res.json();
|
|
2349
|
+
const items = Array.isArray(data?.collection?.items) ? data.collection.items : [];
|
|
2350
|
+
return items.slice(0, limit).map((item) => {
|
|
2351
|
+
const meta = Array.isArray(item.data) && item.data[0] ? item.data[0] : {};
|
|
2352
|
+
const link = Array.isArray(item.links) && item.links[0] ? item.links[0] : {};
|
|
2353
|
+
const title = meta.title || `NASA Media: ${query}`;
|
|
2354
|
+
const desc = (meta.description || meta.caption || "").slice(0, 220);
|
|
2355
|
+
const nasaId = meta.nasa_id || item.href;
|
|
2356
|
+
const actualMediaType = meta.media_type === "video" ? "video" : "image";
|
|
2357
|
+
return {
|
|
2358
|
+
id: `nasa-${nasaId}`,
|
|
2359
|
+
title,
|
|
2360
|
+
url: `https://images.nasa.gov/details/${encodeURIComponent(nasaId)}`,
|
|
2361
|
+
description: desc || `T\u01B0 li\u1EC7u khoa h\u1ECDc v\u0169 tr\u1EE5, v\u1EC7 tinh v\xE0 k\u1EF9 thu\u1EADt kh\xF4ng gian t\u1EEB NASA.`,
|
|
2362
|
+
type: actualMediaType === "video" ? "media_video" : "media_image",
|
|
2363
|
+
provider: "nasa",
|
|
2364
|
+
thumbnailUrl: link.href,
|
|
2365
|
+
mediaType: actualMediaType,
|
|
2366
|
+
license: {
|
|
2367
|
+
type: "Public Domain (NASA Media Guidelines)",
|
|
2368
|
+
attributionText: `T\u01B0 li\u1EC7u khoa h\u1ECDc t\u1EEB NASA (ID: ${nasaId}). S\u1EED d\u1EE5ng t\u1EF1 do cho m\u1EE5c \u0111\xEDch gi\xE1o d\u1EE5c.`,
|
|
2369
|
+
url: "https://www.nasa.gov/multimedia/guidelines/index.html",
|
|
2370
|
+
commercialUseAllowed: true
|
|
2371
|
+
},
|
|
2372
|
+
subject: "physics",
|
|
2373
|
+
targetLevel: "all",
|
|
2374
|
+
tags: Array.isArray(meta.keywords) ? meta.keywords.slice(0, 5) : ["nasa", "space", "stem"],
|
|
2375
|
+
relevanceScore: 9
|
|
2376
|
+
};
|
|
2377
|
+
});
|
|
2378
|
+
} catch (e) {
|
|
2379
|
+
console.warn("[NasaMediaClient] L\u1ED7i t\xECm ki\u1EBFm NASA media:", e?.message || e);
|
|
2380
|
+
return [];
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
var GitHubCurriculumClient = class {
|
|
2385
|
+
baseUrl = "https://api.github.com";
|
|
2386
|
+
async searchCurricula(query, options = {}) {
|
|
2387
|
+
try {
|
|
2388
|
+
const limit = Math.min(options.limit ?? 5, 10);
|
|
2389
|
+
const q = `${query} curriculum in:name,description,topics`;
|
|
2390
|
+
const params = new URLSearchParams({
|
|
2391
|
+
q,
|
|
2392
|
+
sort: "stars",
|
|
2393
|
+
order: "desc",
|
|
2394
|
+
per_page: String(limit)
|
|
2395
|
+
});
|
|
2396
|
+
const headers = {
|
|
2397
|
+
"User-Agent": "CurriculumStudio-ResearchKit/1.2.2",
|
|
2398
|
+
Accept: "application/vnd.github.v3+json"
|
|
2399
|
+
};
|
|
2400
|
+
if (options.token || process.env.GITHUB_TOKEN) {
|
|
2401
|
+
headers["Authorization"] = `token ${options.token || process.env.GITHUB_TOKEN}`;
|
|
2402
|
+
}
|
|
2403
|
+
const res = await fetch(`${this.baseUrl}/search/repositories?${params.toString()}`, {
|
|
2404
|
+
headers,
|
|
2405
|
+
signal: AbortSignal.timeout(8e3)
|
|
2406
|
+
});
|
|
2407
|
+
if (!res.ok) return [];
|
|
2408
|
+
const data = await res.json();
|
|
2409
|
+
const items = Array.isArray(data?.items) ? data.items : [];
|
|
2410
|
+
return items.map((repo) => {
|
|
2411
|
+
const licenseName = repo.license?.name || repo.license?.spdx_id || "Open Source";
|
|
2412
|
+
return {
|
|
2413
|
+
id: `github-${repo.id}`,
|
|
2414
|
+
title: `${repo.name} (${repo.stargazers_count.toLocaleString()} \u2B50)`,
|
|
2415
|
+
url: repo.html_url,
|
|
2416
|
+
description: repo.description || `Gi\xE1o tr\xECnh v\xE0 m\xE3 ngu\u1ED3n m\u1EDF tr\xEAn GitHub b\u1EDFi ${repo.owner?.login}.`,
|
|
2417
|
+
type: "curriculum",
|
|
2418
|
+
provider: "github",
|
|
2419
|
+
mediaType: "code",
|
|
2420
|
+
license: {
|
|
2421
|
+
type: licenseName,
|
|
2422
|
+
attributionText: `Gi\xE1o tr\xECnh m\u1EDF t\u1EEB repo "${repo.full_name}" tr\xEAn GitHub (${licenseName}).`,
|
|
2423
|
+
url: repo.license?.url || repo.html_url,
|
|
2424
|
+
commercialUseAllowed: !licenseName.toLowerCase().includes("non-commercial")
|
|
2425
|
+
},
|
|
2426
|
+
subject: "computer_science",
|
|
2427
|
+
targetLevel: "upper_secondary",
|
|
2428
|
+
tags: Array.isArray(repo.topics) ? repo.topics.slice(0, 5) : ["curriculum", "education", "programming"],
|
|
2429
|
+
relevanceScore: Math.min(10, 7 + Math.log10(Math.max(1, repo.stargazers_count)) * 0.7)
|
|
2430
|
+
};
|
|
2431
|
+
});
|
|
2432
|
+
} catch (e) {
|
|
2433
|
+
console.warn("[GitHubCurriculumClient] L\u1ED7i t\xECm ki\u1EBFm GitHub curriculum:", e?.message || e);
|
|
2434
|
+
return [];
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
};
|
|
2438
|
+
var CURATED_OER_PROGRAMS = [
|
|
2439
|
+
{
|
|
2440
|
+
id: "cs-unplugged-algorithms",
|
|
2441
|
+
title: "CS Unplugged: H\u1ECDc Khoa H\u1ECDc M\xE1y T\xEDnh Kh\xF4ng C\u1EA7n M\xE1y T\xEDnh",
|
|
2442
|
+
url: "https://www.csunplugged.org/en/",
|
|
2443
|
+
description: "B\u1ED9 ho\u1EA1t \u0111\u1ED9ng offline gi\u1EA3ng d\u1EA1y thu\u1EADt to\xE1n, h\u1EC7 nh\u1ECB ph\xE2n, c\u1EA5u tr\xFAc d\u1EEF li\u1EC7u qua tr\xF2 ch\u01A1i \u0111\xF3ng vai, x\u1EBFp h\xECnh v\xE0 b\xE0i t\u1EADp nh\xF3m.",
|
|
2444
|
+
type: "hands_on_lab",
|
|
2445
|
+
provider: "cs_unplugged",
|
|
2446
|
+
subject: "computer_science",
|
|
2447
|
+
targetLevel: "primary",
|
|
2448
|
+
keywords: ["unplugged", "kh\xF4ng d\xF9ng m\xE1y", "thu\u1EADt to\xE1n", "nh\u1ECB ph\xE2n", "binary", "sorting", "s\u1EAFp x\u1EBFp", "tr\u1EBB em", "kids", "logic"],
|
|
2449
|
+
licenseType: "Creative Commons CC BY-NC-SA 4.0"
|
|
2450
|
+
},
|
|
2451
|
+
{
|
|
2452
|
+
id: "scratch-mit-studio",
|
|
2453
|
+
title: "Scratch MIT: M\xF4i Tr\u01B0\u1EDDng L\u1EADp Tr\xECnh Kh\u1ED1i & S\xE1ng T\u1EA1o Tr\u1EF1c Quan",
|
|
2454
|
+
url: "https://scratch.mit.edu/",
|
|
2455
|
+
description: "N\u1EC1n t\u1EA3ng l\u1EADp tr\xECnh kh\u1ED1i do MIT Media Lab ph\xE1t tri\u1EC3n, th\xEDch h\u1EE3p l\xE0m quen v\u1EDBi t\u01B0 duy bi\u1EBFn s\u1ED1, r\u1EBD nh\xE1nh, v\xF2ng l\u1EB7p v\xE0 s\u1EF1 ki\u1EC7n \xE2m thanh/h\xECnh \u1EA3nh.",
|
|
2456
|
+
type: "curriculum",
|
|
2457
|
+
provider: "scratch",
|
|
2458
|
+
subject: "computer_science",
|
|
2459
|
+
targetLevel: "primary",
|
|
2460
|
+
keywords: ["scratch", "blockly", "l\u1EADp tr\xECnh kh\u1ED1i", "k\xE9o th\u1EA3", "game 2d", "ho\u1EA1t h\xECnh", "tr\u1EBB em", "mit scratch"],
|
|
2461
|
+
licenseType: "Free & Open Educational Platform"
|
|
2462
|
+
},
|
|
2463
|
+
{
|
|
2464
|
+
id: "freecodecamp-responsive-web",
|
|
2465
|
+
title: "freeCodeCamp: L\u1ED9 Tr\xECnh L\u1EADp Tr\xECnh D\u1EF1 \xC1n Th\u1EF1c Chi\u1EBFn Mi\u1EC5n Ph\xED",
|
|
2466
|
+
url: "https://www.freecodecamp.org/learn",
|
|
2467
|
+
description: "H\xE0ng ng\xE0n gi\u1EDD b\xE0i h\u1ECDc t\u01B0\u01A1ng t\xE1c t\u1EEB c\u01A1 b\u1EA3n \u0111\u1EBFn n\xE2ng cao: HTML/CSS, JavaScript, Python, C\u1EA5u tr\xFAc d\u1EEF li\u1EC7u v\xE0 AI.",
|
|
2468
|
+
type: "curriculum",
|
|
2469
|
+
provider: "web",
|
|
2470
|
+
subject: "computer_science",
|
|
2471
|
+
targetLevel: "upper_secondary",
|
|
2472
|
+
keywords: ["freecodecamp", "web", "javascript", "python", "html", "css", "l\u1EADp tr\xECnh web", "ch\u1EE9ng ch\u1EC9 mi\u1EC5n ph\xED"],
|
|
2473
|
+
licenseType: "Creative Commons CC BY-SA 4.0 / Open Source"
|
|
2474
|
+
},
|
|
2475
|
+
{
|
|
2476
|
+
id: "the-odin-project-fullstack",
|
|
2477
|
+
title: "The Odin Project: L\u1ED9 Tr\xECnh Full-Stack Web Open Source",
|
|
2478
|
+
url: "https://www.theodinproject.com/",
|
|
2479
|
+
description: "Curriculum h\u1ECDc ph\xE1t tri\u1EC3n web b\xE0i b\u1EA3n theo chu\u1EA9n c\xF4ng nghi\u1EC7p: Git, CLI, HTML/CSS, JavaScript hi\u1EC7n \u0111\u1EA1i, Node.js v\xE0 React.",
|
|
2480
|
+
type: "curriculum",
|
|
2481
|
+
provider: "web",
|
|
2482
|
+
subject: "computer_science",
|
|
2483
|
+
targetLevel: "developer",
|
|
2484
|
+
keywords: ["odin project", "fullstack", "git", "github", "frontend", "backend", "react", "web developer"],
|
|
2485
|
+
licenseType: "Open Source Curriculum"
|
|
2486
|
+
},
|
|
2487
|
+
{
|
|
2488
|
+
id: "openstax-physics-volume-1",
|
|
2489
|
+
title: "OpenStax: S\xE1ch Gi\xE1o Tr\xECnh V\u1EADt L\xFD \u0110\u1EA1i H\u1ECDc & Ph\u1ED5 Th\xF4ng M\u1EDF",
|
|
2490
|
+
url: "https://openstax.org/subjects/science",
|
|
2491
|
+
description: "S\xE1ch gi\xE1o khoa s\u1ED1 chu\u1EA9n h\u1ECDc thu\u1EADt \u0111\u01B0\u1EE3c b\xECnh duy\u1EC7t \u0111\u1ED9c l\u1EADp, bao g\u1ED3m C\u01A1 h\u1ECDc, S\xF3ng, \u0110i\u1EC7n t\u1EEB h\u1ECDc v\xE0 Quang h\u1ECDc.",
|
|
2492
|
+
type: "textbook",
|
|
2493
|
+
provider: "openstax",
|
|
2494
|
+
subject: "physics",
|
|
2495
|
+
targetLevel: "upper_secondary",
|
|
2496
|
+
keywords: ["openstax", "gi\xE1o tr\xECnh", "s\xE1ch gi\xE1o khoa", "v\u1EADt l\xFD", "physics", "c\u01A1 h\u1ECDc", "\u0111i\u1EC7n t\u1EEB", "s\xE1ch m\u1EDF"],
|
|
2497
|
+
licenseType: "Creative Commons CC BY 4.0"
|
|
2498
|
+
},
|
|
2499
|
+
{
|
|
2500
|
+
id: "exercism-coding-practice",
|
|
2501
|
+
title: "Exercism: Luy\u1EC7n T\u1EADp T\u01B0 Duy Thu\u1EADt To\xE1n & Code Review \u0110a Ng\xF4n Ng\u1EEF",
|
|
2502
|
+
url: "https://exercism.org/",
|
|
2503
|
+
description: "H\u01A1n 70 ng\xF4n ng\u1EEF l\u1EADp tr\xECnh (Python, C++, Rust, Swift, JavaScript) v\u1EDBi l\u1ED9 tr\xECnh b\xE0i t\u1EADp r\xE8n luy\u1EC7n c\xFA ph\xE1p v\xE0 phong c\xE1ch m\xE3 ngu\u1ED3n chu\u1EA9n.",
|
|
2504
|
+
type: "problem_set",
|
|
2505
|
+
provider: "exercism",
|
|
2506
|
+
subject: "computer_science",
|
|
2507
|
+
targetLevel: "developer",
|
|
2508
|
+
keywords: ["exercism", "thu\u1EADt to\xE1n", "luy\u1EC7n code", "b\xE0i t\u1EADp l\u1EADp tr\xECnh", "c++", "python", "swift", "clean code"],
|
|
2509
|
+
licenseType: "Open Source & Free Non-profit Education"
|
|
2510
|
+
}
|
|
2511
|
+
];
|
|
2512
|
+
var StemResourceResearcher = class {
|
|
2513
|
+
openverse = new OpenverseClient();
|
|
2514
|
+
nasa = new NasaMediaClient();
|
|
2515
|
+
github = new GitHubCurriculumClient();
|
|
2516
|
+
async findResources(query, options = {}) {
|
|
2517
|
+
const limit = options.limit ?? 10;
|
|
2518
|
+
const rawTypes = options.types && options.types.length > 0 ? options.types : ["simulation", "curriculum", "media_image", "media_video", "hands_on_lab", "textbook", "problem_set"];
|
|
2519
|
+
const requestedTypes = /* @__PURE__ */ new Set();
|
|
2520
|
+
for (const t of rawTypes) {
|
|
2521
|
+
if (t === "interactive") {
|
|
2522
|
+
requestedTypes.add("simulation");
|
|
2523
|
+
requestedTypes.add("hands_on_lab");
|
|
2524
|
+
} else if (t === "open_media") {
|
|
2525
|
+
requestedTypes.add("media_image");
|
|
2526
|
+
requestedTypes.add("media_video");
|
|
2527
|
+
} else {
|
|
2528
|
+
requestedTypes.add(t);
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
const lowerQuery = query.toLowerCase();
|
|
2532
|
+
const queryTokens = lowerQuery.split(/\s+/).filter((t) => t.length > 1);
|
|
2533
|
+
const matches = [];
|
|
2534
|
+
if (requestedTypes.has("simulation")) {
|
|
2535
|
+
for (const sim of PHET_SIMULATIONS) {
|
|
2536
|
+
let score = 0;
|
|
2537
|
+
for (const token of queryTokens) {
|
|
2538
|
+
if (sim.keywords.some((k) => k.toLowerCase().includes(token))) score += 2;
|
|
2539
|
+
if (sim.titleEn.toLowerCase().includes(token) || sim.titleVi.toLowerCase().includes(token)) score += 3;
|
|
2540
|
+
if (sim.descriptionEn.toLowerCase().includes(token) || sim.descriptionVi.toLowerCase().includes(token)) score += 1;
|
|
2541
|
+
}
|
|
2542
|
+
if (score > 0) {
|
|
2543
|
+
matches.push({
|
|
2544
|
+
id: sim.id,
|
|
2545
|
+
title: `${sim.titleVi} (${sim.titleEn})`,
|
|
2546
|
+
url: sim.simUrl,
|
|
2547
|
+
description: sim.descriptionVi,
|
|
2548
|
+
type: "simulation",
|
|
2549
|
+
provider: "phet",
|
|
2550
|
+
thumbnailUrl: sim.thumbnailUrl,
|
|
2551
|
+
embedUrl: sim.simUrl,
|
|
2552
|
+
mediaType: "interactive",
|
|
2553
|
+
license: {
|
|
2554
|
+
type: "Creative Commons CC BY 4.0",
|
|
2555
|
+
attributionText: `M\xF4 ph\u1ECFng PhET Interactive Simulations, University of Colorado Boulder (https://phet.colorado.edu). CC BY 4.0.`,
|
|
2556
|
+
url: "https://phet.colorado.edu/en/licensing",
|
|
2557
|
+
commercialUseAllowed: true
|
|
2558
|
+
},
|
|
2559
|
+
subject: sim.subject,
|
|
2560
|
+
targetLevel: sim.targetLevel,
|
|
2561
|
+
tags: ["phet", "simulation", sim.subject, ...sim.keywords.slice(0, 3)],
|
|
2562
|
+
relevanceScore: Math.min(10, 7.5 + score * 0.4)
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
for (const prog of CURATED_OER_PROGRAMS) {
|
|
2568
|
+
if (!requestedTypes.has(prog.type)) continue;
|
|
2569
|
+
let score = 0;
|
|
2570
|
+
for (const token of queryTokens) {
|
|
2571
|
+
if (prog.keywords.some((k) => k.toLowerCase().includes(token))) score += 2;
|
|
2572
|
+
if (prog.title.toLowerCase().includes(token)) score += 3;
|
|
2573
|
+
if (prog.description.toLowerCase().includes(token)) score += 1;
|
|
2574
|
+
}
|
|
2575
|
+
if (score > 0) {
|
|
2576
|
+
matches.push({
|
|
2577
|
+
id: prog.id,
|
|
2578
|
+
title: prog.title,
|
|
2579
|
+
url: prog.url,
|
|
2580
|
+
description: prog.description,
|
|
2581
|
+
type: prog.type,
|
|
2582
|
+
provider: prog.provider,
|
|
2583
|
+
mediaType: prog.type === "hands_on_lab" || prog.type === "curriculum" ? "text" : "code",
|
|
2584
|
+
license: {
|
|
2585
|
+
type: prog.licenseType,
|
|
2586
|
+
attributionText: `T\xE0i nguy\xEAn gi\xE1o d\u1EE5c m\u1EDF t\u1EEB ${prog.provider.toUpperCase()} (${prog.licenseType}).`,
|
|
2587
|
+
commercialUseAllowed: !prog.licenseType.includes("NC")
|
|
2588
|
+
},
|
|
2589
|
+
subject: prog.subject,
|
|
2590
|
+
targetLevel: prog.targetLevel,
|
|
2591
|
+
tags: [prog.provider, prog.type, ...prog.keywords.slice(0, 3)],
|
|
2592
|
+
relevanceScore: Math.min(10, 7 + score * 0.4)
|
|
2593
|
+
});
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
const asyncTasks = [];
|
|
2597
|
+
if (requestedTypes.has("media_image")) {
|
|
2598
|
+
asyncTasks.push(this.openverse.searchImages(query, { limit: 4 }));
|
|
2599
|
+
}
|
|
2600
|
+
if (requestedTypes.has("media_image") || requestedTypes.has("media_video")) {
|
|
2601
|
+
const isSpaceOrPhysics = /(vũ trụ|space|physics|vật lý|quỹ đạo|orbit|sensor|cảm biến|robot|nasa|trọng lực|gravity|earth|solar)/i.test(query);
|
|
2602
|
+
if (isSpaceOrPhysics) {
|
|
2603
|
+
asyncTasks.push(this.nasa.search(query, { limit: 3 }));
|
|
2604
|
+
}
|
|
2605
|
+
}
|
|
2606
|
+
if (requestedTypes.has("curriculum")) {
|
|
2607
|
+
asyncTasks.push(this.github.searchCurricula(query, { limit: 3, token: options.githubToken }));
|
|
2608
|
+
}
|
|
2609
|
+
const asyncResults = await Promise.allSettled(asyncTasks);
|
|
2610
|
+
for (const r of asyncResults) {
|
|
2611
|
+
if (r.status === "fulfilled" && Array.isArray(r.value)) {
|
|
2612
|
+
matches.push(...r.value);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
let filtered = matches;
|
|
2616
|
+
if (options.licenseFilter === "creative_commons") {
|
|
2617
|
+
filtered = filtered.filter((item) => /cc\s*by|creative\s*commons|cc0/i.test(item.license.type));
|
|
2618
|
+
} else if (options.licenseFilter === "public_domain") {
|
|
2619
|
+
filtered = filtered.filter((item) => /public\s*domain|cc0/i.test(item.license.type));
|
|
2620
|
+
}
|
|
2621
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2622
|
+
const deduped = [];
|
|
2623
|
+
for (const item of filtered) {
|
|
2624
|
+
const key = item.url || item.id;
|
|
2625
|
+
if (seen.has(key)) continue;
|
|
2626
|
+
seen.add(key);
|
|
2627
|
+
deduped.push(item);
|
|
2628
|
+
}
|
|
2629
|
+
deduped.sort((a, b) => b.relevanceScore - a.relevanceScore);
|
|
2630
|
+
const topResults = deduped.slice(0, limit);
|
|
2631
|
+
const categoryCounts = {
|
|
2632
|
+
simulation: 0,
|
|
2633
|
+
curriculum: 0,
|
|
2634
|
+
media_image: 0,
|
|
2635
|
+
media_video: 0,
|
|
2636
|
+
hands_on_lab: 0,
|
|
2637
|
+
textbook: 0,
|
|
2638
|
+
problem_set: 0
|
|
2639
|
+
};
|
|
2640
|
+
for (const item of topResults) {
|
|
2641
|
+
if (categoryCounts[item.type] !== void 0) {
|
|
2642
|
+
categoryCounts[item.type]++;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
const markdownSummary = this.generateMarkdownSummary(query, topResults);
|
|
2646
|
+
return {
|
|
2647
|
+
query,
|
|
2648
|
+
totalFound: topResults.length,
|
|
2649
|
+
categoryCounts,
|
|
2650
|
+
resources: topResults,
|
|
2651
|
+
items: topResults,
|
|
2652
|
+
markdownSummary,
|
|
2653
|
+
markdownReport: markdownSummary
|
|
2654
|
+
};
|
|
2655
|
+
}
|
|
2656
|
+
async searchAndCatalog(query, options = {}) {
|
|
2657
|
+
return this.findResources(query, options);
|
|
2658
|
+
}
|
|
2659
|
+
generateMarkdown(catalog) {
|
|
2660
|
+
return catalog.markdownSummary;
|
|
2661
|
+
}
|
|
2662
|
+
generateMarkdownSummary(query, items) {
|
|
2663
|
+
if (items.length === 0) {
|
|
2664
|
+
return `Kh\xF4ng t\xECm th\u1EA5y t\xE0i nguy\xEAn gi\xE1o d\u1EE5c m\u1EDF ph\xF9 h\u1EE3p cho ch\u1EE7 \u0111\u1EC1: "${query}".`;
|
|
2665
|
+
}
|
|
2666
|
+
const sections = [`### \u{1F52C} Danh m\u1EE5c T\xE0i nguy\xEAn STEM & L\u1EADp tr\xECnh cho "${query}"
|
|
2667
|
+
`];
|
|
2668
|
+
const typeLabels = {
|
|
2669
|
+
simulation: "\u{1F3AE} M\xF4 ph\u1ECFng T\u01B0\u01A1ng t\xE1c (PhET / Labs)",
|
|
2670
|
+
curriculum: "\u{1F4DA} Gi\xE1o tr\xECnh & L\u1ED9 tr\xECnh M\u1EDF",
|
|
2671
|
+
media_image: "\u{1F5BC}\uFE0F H\xECnh \u1EA3nh & S\u01A1 \u0111\u1ED3 Gi\u1EA5y ph\xE9p M\u1EDF (CC / Public Domain)",
|
|
2672
|
+
media_video: "\u{1F3AC} Video & T\u01B0 li\u1EC7u Khoa h\u1ECDc",
|
|
2673
|
+
hands_on_lab: "\u{1F9EA} Ho\u1EA1t \u0111\u1ED9ng Th\u1EF1c h\xE0nh & Kh\xE1m ph\xE1 (Hands-on)",
|
|
2674
|
+
textbook: "\u{1F4D6} S\xE1ch Gi\xE1o tr\xECnh M\u1EDF (OpenStax / OER)",
|
|
2675
|
+
problem_set: "\u{1F4A1} B\xE0i t\u1EADp & Th\u1EED th\xE1ch L\u1EADp tr\xECnh"
|
|
2676
|
+
};
|
|
2677
|
+
const grouped = {};
|
|
2678
|
+
for (const it of items) {
|
|
2679
|
+
if (!grouped[it.type]) grouped[it.type] = [];
|
|
2680
|
+
grouped[it.type].push(it);
|
|
2681
|
+
}
|
|
2682
|
+
for (const [type, groupItems] of Object.entries(grouped)) {
|
|
2683
|
+
sections.push(`#### ${typeLabels[type] || type}`);
|
|
2684
|
+
for (const it of groupItems) {
|
|
2685
|
+
it.thumbnailUrl ? `
|
|
2686
|
+
` : "";
|
|
2687
|
+
const embed = it.embedUrl ? `> \u{1F517} **T\u01B0\u01A1ng t\xE1c tr\u1EF1c ti\u1EBFp**: [M\u1EDF Simulation To\xE0n m\xE0n h\xECnh](${it.embedUrl})
|
|
2688
|
+
` : "";
|
|
2689
|
+
sections.push(
|
|
2690
|
+
`- **[${it.title}](${it.url})** \u2014 *${it.provider.toUpperCase()}* (${it.license.type})
|
|
2691
|
+
${it.description}
|
|
2692
|
+
${embed} *Tr\xEDch d\u1EABn b\u1EA3n quy\u1EC1n*: \`${it.license.attributionText}\``
|
|
2693
|
+
);
|
|
2694
|
+
}
|
|
2695
|
+
sections.push("");
|
|
2696
|
+
}
|
|
2697
|
+
return sections.join("\n");
|
|
2698
|
+
}
|
|
2699
|
+
};
|
|
2700
|
+
|
|
1954
2701
|
// src/evidence/evidenceScorer.ts
|
|
1955
2702
|
function tokenizeBilingualKeywords(text) {
|
|
1956
2703
|
return text.normalize("NFC").toLowerCase().replace(/[.,;:!?()[\]{}"“”‘’/\\|`*_~#-]+/g, " ").split(/\s+/).filter((w) => w.length >= 2 && !/^(and|the|for|with|from|into|của|trong|được|những|các|cho|với|khi|và|hoặc|để|từ|đến|về)$/.test(w));
|
|
@@ -2890,35 +3637,68 @@ var TechnicalGroundingEngine = class {
|
|
|
2890
3637
|
try {
|
|
2891
3638
|
const doc = await this.scraper.scrapeUrl(h.url);
|
|
2892
3639
|
if (doc && doc.markdownContent) {
|
|
3640
|
+
const substantiveExcerpt = doc.keyExcerpts && doc.keyExcerpts.length > 0 ? doc.keyExcerpts.slice(0, 3).join("\n\n") : doc.markdownContent.slice(0, 1500);
|
|
2893
3641
|
return {
|
|
2894
3642
|
title: h.title,
|
|
2895
3643
|
url: h.url,
|
|
2896
|
-
excerpt:
|
|
3644
|
+
excerpt: substantiveExcerpt,
|
|
3645
|
+
codeBlocks: (doc.extractedCodeBlocks || []).slice(0, 2),
|
|
3646
|
+
tables: (doc.extractedTables || []).slice(0, 2),
|
|
3647
|
+
keyExcerpts: (doc.keyExcerpts || []).slice(0, 4)
|
|
2897
3648
|
};
|
|
2898
3649
|
}
|
|
2899
3650
|
} catch {
|
|
2900
3651
|
}
|
|
2901
|
-
return {
|
|
3652
|
+
return {
|
|
3653
|
+
title: h.title,
|
|
3654
|
+
url: h.url,
|
|
3655
|
+
excerpt: h.content.slice(0, 500),
|
|
3656
|
+
codeBlocks: [],
|
|
3657
|
+
tables: [],
|
|
3658
|
+
keyExcerpts: []
|
|
3659
|
+
};
|
|
2902
3660
|
})
|
|
2903
3661
|
);
|
|
2904
3662
|
const scrapedSnippets = scrapeResults.map(
|
|
2905
|
-
(res, idx) => res.status === "fulfilled" ? res.value : {
|
|
3663
|
+
(res, idx) => res.status === "fulfilled" ? res.value : {
|
|
3664
|
+
title: hitsToScrape[idx].title,
|
|
3665
|
+
url: hitsToScrape[idx].url,
|
|
3666
|
+
excerpt: hitsToScrape[idx].content.slice(0, 500),
|
|
3667
|
+
codeBlocks: [],
|
|
3668
|
+
tables: [],
|
|
3669
|
+
keyExcerpts: []
|
|
3670
|
+
}
|
|
2906
3671
|
);
|
|
2907
|
-
const
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
3672
|
+
const preservedCodeSnippets = [];
|
|
3673
|
+
const preservedTables = [];
|
|
3674
|
+
const preservedKeyExcerpts = [];
|
|
3675
|
+
for (const s of scrapedSnippets) {
|
|
3676
|
+
if (s.codeBlocks && s.codeBlocks.length > 0) {
|
|
3677
|
+
preservedCodeSnippets.push(...s.codeBlocks);
|
|
3678
|
+
}
|
|
3679
|
+
if (s.tables && s.tables.length > 0) {
|
|
3680
|
+
preservedTables.push(...s.tables);
|
|
3681
|
+
}
|
|
3682
|
+
if (s.keyExcerpts && s.keyExcerpts.length > 0) {
|
|
3683
|
+
preservedKeyExcerpts.push(...s.keyExcerpts);
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
const defaultExemplars = scrapedSnippets.length > 0 ? [
|
|
2913
3687
|
{
|
|
2914
|
-
title: `${topic}
|
|
2915
|
-
description:
|
|
3688
|
+
title: scrapedSnippets[0].title || `${topic} Practical Foundation`,
|
|
3689
|
+
description: scrapedSnippets[0].excerpt ? scrapedSnippets[0].excerpt.slice(0, 220) : `Hands-on implementation project for ${topic}.`,
|
|
2916
3690
|
targetAudience: `Students aged ${ageBand[0]}-${ageBand[1]}`,
|
|
2917
|
-
sourceUrl: scrapedSnippets[0]
|
|
3691
|
+
sourceUrl: scrapedSnippets[0].url,
|
|
2918
3692
|
hardwareRequirements: hardware ? [hardware] : void 0,
|
|
2919
3693
|
softwareRequirements: software ? [software] : void 0
|
|
2920
3694
|
}
|
|
2921
|
-
];
|
|
3695
|
+
] : [];
|
|
3696
|
+
const defaultBottlenecks = scrapedSnippets.length > 0 ? domain === "hardware" || Boolean(hardware) ? [
|
|
3697
|
+
"Power supply decoupling and current sufficiency when powering sensors or actuators.",
|
|
3698
|
+
"Logic level shifting and hardware pin mapping conflicts."
|
|
3699
|
+
] : [
|
|
3700
|
+
"SDK/runtime version compatibility and local environment dependencies."
|
|
3701
|
+
] : [];
|
|
2922
3702
|
let factsheet = {
|
|
2923
3703
|
topic,
|
|
2924
3704
|
domain,
|
|
@@ -2926,18 +3706,21 @@ var TechnicalGroundingEngine = class {
|
|
|
2926
3706
|
hardwarePlatform: hardware || void 0,
|
|
2927
3707
|
softwareEnv: software || void 0,
|
|
2928
3708
|
verifiedCompatible: true,
|
|
2929
|
-
notes: [`Targeting ${hardware || "General Platform"} with ${software || "Standard SDK"}.`]
|
|
3709
|
+
notes: hardware || software ? [`Targeting ${hardware || "General Platform"} with ${software || "Standard SDK"}.`] : [`Baseline technical verification for ${topic}.`]
|
|
2930
3710
|
},
|
|
2931
3711
|
ageFeasibility: {
|
|
2932
3712
|
recommendedMinAge: ageBand[0],
|
|
2933
3713
|
recommendedMaxAge: ageBand[1],
|
|
2934
3714
|
cognitiveReadinessVerdict: "feasible",
|
|
2935
|
-
potentialBarriers: [
|
|
3715
|
+
potentialBarriers: []
|
|
2936
3716
|
},
|
|
2937
3717
|
exemplarProjects: defaultExemplars,
|
|
2938
3718
|
technicalBottlenecks: defaultBottlenecks,
|
|
2939
3719
|
groundingSources: scrapedSnippets.map((s) => ({ title: s.title, url: s.url })),
|
|
2940
|
-
markdownReport: ""
|
|
3720
|
+
markdownReport: "",
|
|
3721
|
+
codeSnippets: preservedCodeSnippets.slice(0, 4),
|
|
3722
|
+
pinoutTables: preservedTables.slice(0, 4),
|
|
3723
|
+
keyExcerpts: preservedKeyExcerpts.slice(0, 6)
|
|
2941
3724
|
};
|
|
2942
3725
|
if (llm && scrapedSnippets.length > 0) {
|
|
2943
3726
|
try {
|
|
@@ -2946,8 +3729,19 @@ var TechnicalGroundingEngine = class {
|
|
|
2946
3729
|
`Hardware: ${hardware || "N/A"}, Software/Env: ${software || "N/A"}, Student Age Band: ${ageBand[0]}-${ageBand[1]} years old.`,
|
|
2947
3730
|
`
|
|
2948
3731
|
Harvested Sources:
|
|
2949
|
-
${scrapedSnippets.map((s, i) =>
|
|
2950
|
-
${s.
|
|
3732
|
+
${scrapedSnippets.map((s, i) => {
|
|
3733
|
+
const parts = [`[Source ${i + 1}: ${s.title} (${s.url})]
|
|
3734
|
+
${s.excerpt}`];
|
|
3735
|
+
if (s.codeBlocks && s.codeBlocks.length > 0) {
|
|
3736
|
+
parts.push("Code Snippets:\n" + s.codeBlocks.map((c) => `\`\`\`${c.language || ""}
|
|
3737
|
+
${c.code}
|
|
3738
|
+
\`\`\``).join("\n"));
|
|
3739
|
+
}
|
|
3740
|
+
if (s.tables && s.tables.length > 0) {
|
|
3741
|
+
parts.push("Tables/Pinouts:\n" + s.tables.join("\n\n"));
|
|
3742
|
+
}
|
|
3743
|
+
return parts.join("\n");
|
|
3744
|
+
}).join("\n\n")}`,
|
|
2951
3745
|
`
|
|
2952
3746
|
Synthesize a strictly valid JSON object with:`,
|
|
2953
3747
|
`{`,
|
|
@@ -2986,7 +3780,7 @@ Synthesize a strictly valid JSON object with:`,
|
|
|
2986
3780
|
if (Array.isArray(parsed.technicalBottlenecks)) factsheet.technicalBottlenecks = parsed.technicalBottlenecks.map(String);
|
|
2987
3781
|
}
|
|
2988
3782
|
} catch (err) {
|
|
2989
|
-
console.warn("[TechnicalGroundingEngine] LLM synthesis
|
|
3783
|
+
console.warn("[TechnicalGroundingEngine] LLM synthesis error:", err?.message || err);
|
|
2990
3784
|
}
|
|
2991
3785
|
}
|
|
2992
3786
|
factsheet.markdownReport = this.renderMarkdownReport(factsheet);
|
|
@@ -3018,6 +3812,22 @@ Synthesize a strictly valid JSON object with:`,
|
|
|
3018
3812
|
## 5. Grounding Citations`,
|
|
3019
3813
|
...fs.groundingSources.map((s, idx) => `${idx + 1}. [${s.title}](${s.url})`)
|
|
3020
3814
|
];
|
|
3815
|
+
if (fs.codeSnippets && fs.codeSnippets.length > 0) {
|
|
3816
|
+
lines.push(
|
|
3817
|
+
`
|
|
3818
|
+
## 6. Verified Code Snippets & Syntax Reference`,
|
|
3819
|
+
...fs.codeSnippets.map((c) => `\`\`\`${c.language || "text"}
|
|
3820
|
+
${c.code}
|
|
3821
|
+
\`\`\``)
|
|
3822
|
+
);
|
|
3823
|
+
}
|
|
3824
|
+
if (fs.pinoutTables && fs.pinoutTables.length > 0) {
|
|
3825
|
+
lines.push(
|
|
3826
|
+
`
|
|
3827
|
+
## 7. Pinout & Specification Tables`,
|
|
3828
|
+
...fs.pinoutTables
|
|
3829
|
+
);
|
|
3830
|
+
}
|
|
3021
3831
|
return lines.join("\n");
|
|
3022
3832
|
}
|
|
3023
3833
|
};
|
|
@@ -3034,14 +3844,17 @@ var KnowledgeDiscoveryService = class {
|
|
|
3034
3844
|
this.webScraper = new WebScraper({
|
|
3035
3845
|
crawl4aiHost: config.crawl4aiHost,
|
|
3036
3846
|
jinaKey: config.apiKeys?.jina,
|
|
3847
|
+
brightDataKey: config.apiKeys?.brightdata || config.apiKeys?.brightData,
|
|
3037
3848
|
allowEnvFallback: config.allowEnvFallback,
|
|
3038
3849
|
customAdapter: config.customCrawlerAdapter
|
|
3039
3850
|
});
|
|
3040
3851
|
this.youtubeService = new YouTubeIngestionService();
|
|
3852
|
+
this.stemResearcher = new StemResourceResearcher();
|
|
3041
3853
|
}
|
|
3042
3854
|
searchEngine;
|
|
3043
3855
|
webScraper;
|
|
3044
3856
|
youtubeService;
|
|
3857
|
+
stemResearcher;
|
|
3045
3858
|
async search(query, limit = 5) {
|
|
3046
3859
|
return this.searchEngine.search(query, {
|
|
3047
3860
|
limit,
|
|
@@ -3058,6 +3871,9 @@ var KnowledgeDiscoveryService = class {
|
|
|
3058
3871
|
async ingestYouTube(urlOrVideoId, preferredLanguages = ["vi", "en"]) {
|
|
3059
3872
|
return this.youtubeService.fetchTranscript(urlOrVideoId, preferredLanguages);
|
|
3060
3873
|
}
|
|
3874
|
+
async findStemResources(query, options) {
|
|
3875
|
+
return this.stemResearcher.findResources(query, options);
|
|
3876
|
+
}
|
|
3061
3877
|
};
|
|
3062
3878
|
var TerminologyGraphService = class {
|
|
3063
3879
|
constructor(config) {
|
|
@@ -3283,17 +4099,21 @@ exports.ECOMMERCE_AND_COMMERCIAL_PATTERNS = ECOMMERCE_AND_COMMERCIAL_PATTERNS;
|
|
|
3283
4099
|
exports.ECOMMERCE_DOMAINS = ECOMMERCE_DOMAINS;
|
|
3284
4100
|
exports.EvidenceScorer = EvidenceScorer;
|
|
3285
4101
|
exports.EvidenceVerificationService = EvidenceVerificationService;
|
|
4102
|
+
exports.GitHubCurriculumClient = GitHubCurriculumClient;
|
|
3286
4103
|
exports.HarvestPipeline = HarvestPipeline;
|
|
3287
4104
|
exports.HealthAuditor = HealthAuditor;
|
|
3288
4105
|
exports.KnowledgeDiscoveryService = KnowledgeDiscoveryService;
|
|
3289
4106
|
exports.LiteratureReviewSynthesizer = LiteratureReviewSynthesizer;
|
|
3290
4107
|
exports.MultiSourceSearchEngine = MultiSourceSearchEngine;
|
|
4108
|
+
exports.NasaMediaClient = NasaMediaClient;
|
|
4109
|
+
exports.OpenverseClient = OpenverseClient;
|
|
3291
4110
|
exports.PedagogicalSynthesisService = PedagogicalSynthesisService;
|
|
3292
4111
|
exports.PedagogicalTermExtractor = PedagogicalTermExtractor;
|
|
3293
4112
|
exports.ProvenanceTracker = ProvenanceTracker;
|
|
3294
4113
|
exports.ReferencePackBuilder = ReferencePackBuilder;
|
|
3295
4114
|
exports.ResearchConfigSchema = ResearchConfigSchema;
|
|
3296
4115
|
exports.ResearchKitClient = ResearchKitClient;
|
|
4116
|
+
exports.StemResourceResearcher = StemResourceResearcher;
|
|
3297
4117
|
exports.TechnicalGroundingEngine = TechnicalGroundingEngine;
|
|
3298
4118
|
exports.TechnicalGroundingService = TechnicalGroundingService;
|
|
3299
4119
|
exports.TerminologyGraphService = TerminologyGraphService;
|