@thanh01.pmt/research-kit 1.2.1 → 1.2.4

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.
Files changed (61) hide show
  1. package/dist/academic/index.cjs +11 -2
  2. package/dist/academic/index.cjs.map +1 -1
  3. package/dist/academic/index.d.cts +3 -3
  4. package/dist/academic/index.d.ts +3 -3
  5. package/dist/academic/index.js +1 -1
  6. package/dist/{catalogBuilder-DHV6y1gD.d.ts → catalogBuilder-B4eiLS_S.d.cts} +20 -6
  7. package/dist/{catalogBuilder-BaVRvg-9.d.cts → catalogBuilder-BNB_gaWP.d.ts} +20 -6
  8. package/dist/{chunk-RW7VS7NI.js → chunk-GK5KI5PB.js} +88 -22
  9. package/dist/chunk-GK5KI5PB.js.map +1 -0
  10. package/dist/{chunk-X3X26W2I.js → chunk-HESXWQEF.js} +12 -7
  11. package/dist/chunk-HESXWQEF.js.map +1 -0
  12. package/dist/{chunk-QFYM2NV4.js → chunk-KXJDQBSJ.js} +3 -3
  13. package/dist/{chunk-QFYM2NV4.js.map → chunk-KXJDQBSJ.js.map} +1 -1
  14. package/dist/{chunk-ON6VFCJO.js → chunk-QQZQNBJC.js} +51 -2
  15. package/dist/chunk-QQZQNBJC.js.map +1 -0
  16. package/dist/{chunk-HZNSZDSM.js → chunk-SAHBBO3U.js} +99 -11
  17. package/dist/chunk-SAHBBO3U.js.map +1 -0
  18. package/dist/{chunk-UKGR45VZ.js → chunk-SDDZFFL6.js} +13 -4
  19. package/dist/chunk-SDDZFFL6.js.map +1 -0
  20. package/dist/chunk-YICMTZS5.js +527 -0
  21. package/dist/chunk-YICMTZS5.js.map +1 -0
  22. package/dist/config/index.cjs +10 -5
  23. package/dist/config/index.cjs.map +1 -1
  24. package/dist/config/index.d.cts +1 -1
  25. package/dist/config/index.d.ts +1 -1
  26. package/dist/config/index.js +1 -1
  27. package/dist/evidence/index.cjs.map +1 -1
  28. package/dist/evidence/index.d.cts +2 -2
  29. package/dist/evidence/index.d.ts +2 -2
  30. package/dist/evidence/index.js +2 -2
  31. package/dist/harvester/index.cjs +674 -9
  32. package/dist/harvester/index.cjs.map +1 -1
  33. package/dist/harvester/index.d.cts +87 -5
  34. package/dist/harvester/index.d.ts +87 -5
  35. package/dist/harvester/index.js +3 -3
  36. package/dist/{index-DlngvZBr.d.cts → index-9rDiFuR4.d.cts} +43 -12
  37. package/dist/{index-DlngvZBr.d.ts → index-9rDiFuR4.d.ts} +43 -12
  38. package/dist/index.cjs +783 -32
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +13 -11
  41. package/dist/index.d.ts +13 -11
  42. package/dist/index.js +19 -12
  43. package/dist/index.js.map +1 -1
  44. package/dist/{literatureReview-C7hsjrn4.d.cts → literatureReview-BwidpYJo.d.cts} +2 -1
  45. package/dist/{literatureReview-DWl13r_3.d.ts → literatureReview-DOzgm9Q2.d.ts} +2 -1
  46. package/dist/pipeline/index.cjs +256 -29
  47. package/dist/pipeline/index.cjs.map +1 -1
  48. package/dist/pipeline/index.d.cts +10 -4
  49. package/dist/pipeline/index.d.ts +10 -4
  50. package/dist/pipeline/index.js +5 -5
  51. package/dist/{webScraper-yO9P-oLb.d.cts → webScraper-CAQjE46m.d.cts} +11 -2
  52. package/dist/{webScraper-DBFUIqoO.d.ts → webScraper-CXIpvyA6.d.ts} +11 -2
  53. package/package.json +9 -8
  54. package/LICENSE +0 -21
  55. package/dist/chunk-HZNSZDSM.js.map +0 -1
  56. package/dist/chunk-LSMSIPTZ.js +0 -3
  57. package/dist/chunk-LSMSIPTZ.js.map +0 -1
  58. package/dist/chunk-ON6VFCJO.js.map +0 -1
  59. package/dist/chunk-RW7VS7NI.js.map +0 -1
  60. package/dist/chunk-UKGR45VZ.js.map +0 -1
  61. package/dist/chunk-X3X26W2I.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
- return { area: CS2023_KNOWLEDGE_AREAS.SDF, k12Strand: CSTA_K12_STRANDS.AP, matchConfidence: 0.8 };
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,6 +714,8 @@ var MultiSourceSearchEngine = class {
700
714
  tavilyKey;
701
715
  exaKey;
702
716
  serperKey;
717
+ brightDataKey;
718
+ brightDataZone;
703
719
  searxngHost;
704
720
  searxngHeaders;
705
721
  allowEnvFallback;
@@ -710,6 +726,8 @@ var MultiSourceSearchEngine = class {
710
726
  this.tavilyKey = options.apiKeys?.tavily || options.tavilyKey || (this.allowEnvFallback ? process.env.TAVILY_API_KEY : void 0);
711
727
  this.exaKey = options.apiKeys?.exa || options.exaKey || (this.allowEnvFallback ? process.env.EXA_API_KEY : void 0);
712
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";
713
731
  this.searxngHost = options.searxngHost || (this.allowEnvFallback ? process.env.SEARXNG_URL || process.env.SEARXNG_HOST : void 0);
714
732
  const cfId = process.env.CF_ACCESS_CLIENT_ID;
715
733
  const cfSecret = process.env.CF_ACCESS_CLIENT_SECRET;
@@ -727,6 +745,12 @@ var MultiSourceSearchEngine = class {
727
745
  if (keys.tavily !== void 0) this.tavilyKey = keys.tavily;
728
746
  if (keys.exa !== void 0) this.exaKey = keys.exa;
729
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;
730
754
  }
731
755
  setSearxng(host, headers) {
732
756
  this.searxngHost = host;
@@ -773,11 +797,20 @@ var MultiSourceSearchEngine = class {
773
797
  const tavilyKey = options.apiKeys?.tavily || options.tavilyKey || this.tavilyKey;
774
798
  const exaKey = options.apiKeys?.exa || options.exaKey || this.exaKey;
775
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;
776
802
  const searxngHost = options.searxngHost || this.searxngHost;
777
803
  if (preferred === "searxng" && searxngHost) {
778
804
  const searxHits = await this.querySearxng(query, searxngHost, limit, options.searxngHeaders);
779
805
  if (searxHits.length > 0) return searxHits;
780
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
+ }
781
814
  if (preferred === "exa" && exaKey) {
782
815
  const exaHits = await this.queryExa(query, exaKey, limit, options.domainFilter);
783
816
  if (exaHits.length > 0) return exaHits;
@@ -799,6 +832,9 @@ var MultiSourceSearchEngine = class {
799
832
  include_answer: true,
800
833
  max_results: limit
801
834
  };
835
+ if (options.timeRange) {
836
+ body.time_range = options.timeRange;
837
+ }
802
838
  if (options.domainFilter && options.domainFilter.length > 0) {
803
839
  body.include_domains = options.domainFilter;
804
840
  }
@@ -825,25 +861,76 @@ var MultiSourceSearchEngine = class {
825
861
  }
826
862
  }
827
863
  if (exaKey) {
828
- const exaHits = await this.queryExa(query, exaKey, limit, options.domainFilter);
864
+ const exaHits = await this.queryExa(query, exaKey, limit, options.domainFilter, options.timeRange);
829
865
  if (exaHits.length > 0) return exaHits;
830
866
  }
831
867
  if (serperKey) {
832
- const serperHits = await this.querySerper(query, serperKey, limit);
868
+ const serperHits = await this.querySerper(query, serperKey, limit, options.timeRange);
833
869
  if (serperHits.length > 0) return serperHits;
834
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
+ }
835
878
  if (searxngHost) {
836
- const searxHits = await this.querySearxng(query, searxngHost, limit, options.searxngHeaders);
879
+ const searxHits = await this.querySearxng(query, searxngHost, limit, options.searxngHeaders, options.timeRange);
837
880
  if (searxHits.length > 0) return searxHits;
838
881
  }
839
882
  const ddgHits = await this.queryDuckDuckGo(query, limit);
840
883
  if (ddgHits.length > 0) return ddgHits;
841
884
  return [];
842
885
  }
843
- async querySearxng(query, searxngHost, limit, customHeaders) {
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) {
844
928
  try {
845
929
  const cleanHost = searxngHost.replace(/\/$/, "");
846
- const searchUrl = `${cleanHost}/search?q=${encodeURIComponent(query)}&format=json`;
930
+ let searchUrl = `${cleanHost}/search?q=${encodeURIComponent(query)}&format=json`;
931
+ if (timeRange) {
932
+ searchUrl += `&time_range=${encodeURIComponent(timeRange)}`;
933
+ }
847
934
  const headers = {
848
935
  "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
849
936
  ...this.searxngHeaders || {},
@@ -870,7 +957,7 @@ var MultiSourceSearchEngine = class {
870
957
  }
871
958
  return [];
872
959
  }
873
- async queryExa(query, exaKey, limit, domainFilter) {
960
+ async queryExa(query, exaKey, limit, domainFilter, timeRange) {
874
961
  try {
875
962
  const body = {
876
963
  query,
@@ -880,6 +967,14 @@ var MultiSourceSearchEngine = class {
880
967
  if (domainFilter && domainFilter.length > 0) {
881
968
  body.includeDomains = domainFilter;
882
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
+ }
883
978
  const res = await fetch("https://api.exa.ai/search", {
884
979
  method: "POST",
885
980
  headers: {
@@ -906,15 +1001,22 @@ var MultiSourceSearchEngine = class {
906
1001
  }
907
1002
  return [];
908
1003
  }
909
- async querySerper(query, serperKey, limit) {
1004
+ async querySerper(query, serperKey, limit, timeRange) {
910
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
+ }
911
1013
  const res = await fetch("https://google.serper.dev/search", {
912
1014
  method: "POST",
913
1015
  headers: {
914
1016
  "X-API-KEY": serperKey,
915
1017
  "Content-Type": "application/json"
916
1018
  },
917
- body: JSON.stringify({ q: query, num: limit }),
1019
+ body: JSON.stringify(body),
918
1020
  signal: AbortSignal.timeout(1e4)
919
1021
  });
920
1022
  if (res.ok) {
@@ -1163,6 +1265,8 @@ function extractSubstantiveExcerpts(markdown, maxExcerpts = 6) {
1163
1265
  var WebScraper = class {
1164
1266
  crawl4aiHost;
1165
1267
  jinaKey;
1268
+ brightDataKey;
1269
+ brightDataZone;
1166
1270
  allowEnvFallback;
1167
1271
  customAdapter;
1168
1272
  youtubeService;
@@ -1170,6 +1274,8 @@ var WebScraper = class {
1170
1274
  this.allowEnvFallback = options.allowEnvFallback ?? true;
1171
1275
  this.crawl4aiHost = options.crawl4aiHost || (this.allowEnvFallback ? process.env.CRAWL4AI_HOST : void 0) || "http://localhost:11235";
1172
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";
1173
1279
  this.customAdapter = options.customAdapter;
1174
1280
  this.youtubeService = new YouTubeIngestionService();
1175
1281
  }
@@ -1179,8 +1285,15 @@ var WebScraper = class {
1179
1285
  setJinaKey(key) {
1180
1286
  this.jinaKey = key;
1181
1287
  }
1288
+ setBrightData(key, zone) {
1289
+ if (key !== void 0) this.brightDataKey = key;
1290
+ if (zone !== void 0) this.brightDataZone = zone;
1291
+ }
1182
1292
  async scrapeUrl(targetUrl, options = {}) {
1183
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;
1184
1297
  if (adapter) {
1185
1298
  try {
1186
1299
  const result = await adapter.crawl(targetUrl);
@@ -1201,6 +1314,13 @@ var WebScraper = class {
1201
1314
  console.warn(`[WebScraper] YouTube transcript extraction failed for ${targetUrl}:`, e?.message || e);
1202
1315
  }
1203
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
+ }
1204
1324
  try {
1205
1325
  const jinaUrl = `https://r.jina.ai/${targetUrl}`;
1206
1326
  const jinaKey = options.jinaKey || this.jinaKey;
@@ -1245,6 +1365,13 @@ var WebScraper = class {
1245
1365
  } catch {
1246
1366
  }
1247
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
+ }
1248
1375
  try {
1249
1376
  const res = await fetch(targetUrl, {
1250
1377
  headers: { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" },
@@ -1269,6 +1396,30 @@ ${p.replace(/<[^>]+>/g, " ").trim()}
1269
1396
  }
1270
1397
  throw new Error(`Unable to fetch content from URL: ${targetUrl}`);
1271
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
+ }
1272
1423
  packageDocument(url, markdown, provider, explicitTitle) {
1273
1424
  const titleMatch = markdown.match(/^#\s+(.+)$/m) || markdown.match(/^Title:\s*(.+)$/im);
1274
1425
  const title = (explicitTitle || (titleMatch ? titleMatch[1].trim() : url.split("/").filter(Boolean).pop() || "Document")).slice(0, 180);
@@ -1823,7 +1974,7 @@ ${corpusPreview}`,
1823
1974
  `
1824
1975
  Return ONLY a valid JSON array of 6 to 12 atomic pedagogical concepts ordered from foundational to advanced.`,
1825
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.`,
1826
- `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"]}`
1827
1978
  ].filter(Boolean).join("\n");
1828
1979
  const rawResponse = await options.llm(prompt, {
1829
1980
  system: "You are a Principal Computer Science Curriculum Architect & Bilingual Terminology Specialist (Vietnamese-English). Output strictly valid JSON array without markdown commentary.",
@@ -2023,6 +2174,530 @@ var HealthAuditor = class {
2023
2174
  }
2024
2175
  };
2025
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 ? `![preview](${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
+
2026
2701
  // src/evidence/evidenceScorer.ts
2027
2702
  function tokenizeBilingualKeywords(text) {
2028
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));
@@ -2962,35 +3637,71 @@ var TechnicalGroundingEngine = class {
2962
3637
  try {
2963
3638
  const doc = await this.scraper.scrapeUrl(h.url);
2964
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);
2965
3641
  return {
2966
3642
  title: h.title,
2967
3643
  url: h.url,
2968
- excerpt: doc.markdownContent.slice(0, 1500)
3644
+ excerpt: substantiveExcerpt,
3645
+ codeBlocks: (doc.extractedCodeBlocks || []).slice(0, 2),
3646
+ tables: (doc.extractedTables || []).slice(0, 2),
3647
+ keyExcerpts: (doc.keyExcerpts || []).slice(0, 4)
2969
3648
  };
2970
3649
  }
2971
3650
  } catch {
2972
3651
  }
2973
- return { title: h.title, url: h.url, excerpt: h.content.slice(0, 500) };
3652
+ return {
3653
+ title: h.title,
3654
+ url: h.url,
3655
+ excerpt: h.content.slice(0, 500),
3656
+ codeBlocks: [],
3657
+ tables: [],
3658
+ keyExcerpts: []
3659
+ };
2974
3660
  })
2975
3661
  );
2976
3662
  const scrapedSnippets = scrapeResults.map(
2977
- (res, idx) => res.status === "fulfilled" ? res.value : { title: hitsToScrape[idx].title, url: hitsToScrape[idx].url, excerpt: hitsToScrape[idx].content.slice(0, 500) }
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
+ }
2978
3671
  );
2979
- const defaultBottlenecks = [
2980
- "Power supply insufficiency when driving motors or actuators simultaneously with microcontrollers.",
2981
- "Baud rate mismatch or driver incompatibility across host OS versions.",
2982
- "Syntax confusion between blocking loops (delay/sleep) and non-blocking event handling."
2983
- ];
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
+ }
2984
3686
  const defaultExemplars = [
2985
3687
  {
2986
- title: `${topic} Hands-on Foundation Project`,
2987
- description: `Verified core implementation integrating ${hardware || "hardware"} and ${software || "software logic"}.`,
3688
+ title: scrapedSnippets[0]?.title || `${topic} Hands-on Foundation Project`,
3689
+ description: scrapedSnippets[0]?.excerpt ? scrapedSnippets[0].excerpt.slice(0, 220) : `Verified practical implementation integrating ${hardware || "core principles"} and ${software || "standard development tools"}.`,
2988
3690
  targetAudience: `Students aged ${ageBand[0]}-${ageBand[1]}`,
2989
3691
  sourceUrl: scrapedSnippets[0]?.url,
2990
3692
  hardwareRequirements: hardware ? [hardware] : void 0,
2991
3693
  softwareRequirements: software ? [software] : void 0
2992
3694
  }
2993
3695
  ];
3696
+ const defaultBottlenecks = domain === "hardware" || Boolean(hardware) ? [
3697
+ "Power supply decoupling and current surge when powering sensors or actuators.",
3698
+ "Logic level shifting and hardware pin mapping conflicts."
3699
+ ] : domain === "academic" ? [
3700
+ "Cognitive load pacing and abstract concept grounding with physical analogies."
3701
+ ] : [
3702
+ "SDK/runtime version compatibility and local environment dependencies.",
3703
+ "Syntax confusion between asynchronous event handling and blocking calls."
3704
+ ];
2994
3705
  let factsheet = {
2995
3706
  topic,
2996
3707
  domain,
@@ -2998,18 +3709,21 @@ var TechnicalGroundingEngine = class {
2998
3709
  hardwarePlatform: hardware || void 0,
2999
3710
  softwareEnv: software || void 0,
3000
3711
  verifiedCompatible: true,
3001
- notes: [`Targeting ${hardware || "General Platform"} with ${software || "Standard SDK"}.`]
3712
+ notes: hardware || software ? [`Targeting ${hardware || "General Platform"} with ${software || "Standard SDK"}.`] : [`Baseline technical verification for ${topic}.`]
3002
3713
  },
3003
3714
  ageFeasibility: {
3004
3715
  recommendedMinAge: ageBand[0],
3005
3716
  recommendedMaxAge: ageBand[1],
3006
3717
  cognitiveReadinessVerdict: "feasible",
3007
- potentialBarriers: ["Understanding abstract signal flows and state-based logic."]
3718
+ potentialBarriers: []
3008
3719
  },
3009
3720
  exemplarProjects: defaultExemplars,
3010
3721
  technicalBottlenecks: defaultBottlenecks,
3011
3722
  groundingSources: scrapedSnippets.map((s) => ({ title: s.title, url: s.url })),
3012
- markdownReport: ""
3723
+ markdownReport: "",
3724
+ codeSnippets: preservedCodeSnippets.slice(0, 4),
3725
+ pinoutTables: preservedTables.slice(0, 4),
3726
+ keyExcerpts: preservedKeyExcerpts.slice(0, 6)
3013
3727
  };
3014
3728
  if (llm && scrapedSnippets.length > 0) {
3015
3729
  try {
@@ -3018,8 +3732,19 @@ var TechnicalGroundingEngine = class {
3018
3732
  `Hardware: ${hardware || "N/A"}, Software/Env: ${software || "N/A"}, Student Age Band: ${ageBand[0]}-${ageBand[1]} years old.`,
3019
3733
  `
3020
3734
  Harvested Sources:
3021
- ${scrapedSnippets.map((s, i) => `[Source ${i + 1}: ${s.title} (${s.url})]
3022
- ${s.excerpt}`).join("\n\n")}`,
3735
+ ${scrapedSnippets.map((s, i) => {
3736
+ const parts = [`[Source ${i + 1}: ${s.title} (${s.url})]
3737
+ ${s.excerpt}`];
3738
+ if (s.codeBlocks && s.codeBlocks.length > 0) {
3739
+ parts.push("Code Snippets:\n" + s.codeBlocks.map((c) => `\`\`\`${c.language || ""}
3740
+ ${c.code}
3741
+ \`\`\``).join("\n"));
3742
+ }
3743
+ if (s.tables && s.tables.length > 0) {
3744
+ parts.push("Tables/Pinouts:\n" + s.tables.join("\n\n"));
3745
+ }
3746
+ return parts.join("\n");
3747
+ }).join("\n\n")}`,
3023
3748
  `
3024
3749
  Synthesize a strictly valid JSON object with:`,
3025
3750
  `{`,
@@ -3058,7 +3783,7 @@ Synthesize a strictly valid JSON object with:`,
3058
3783
  if (Array.isArray(parsed.technicalBottlenecks)) factsheet.technicalBottlenecks = parsed.technicalBottlenecks.map(String);
3059
3784
  }
3060
3785
  } catch (err) {
3061
- console.warn("[TechnicalGroundingEngine] LLM synthesis fallback to baseline:", err?.message || err);
3786
+ console.warn("[TechnicalGroundingEngine] LLM synthesis error:", err?.message || err);
3062
3787
  }
3063
3788
  }
3064
3789
  factsheet.markdownReport = this.renderMarkdownReport(factsheet);
@@ -3090,6 +3815,22 @@ Synthesize a strictly valid JSON object with:`,
3090
3815
  ## 5. Grounding Citations`,
3091
3816
  ...fs.groundingSources.map((s, idx) => `${idx + 1}. [${s.title}](${s.url})`)
3092
3817
  ];
3818
+ if (fs.codeSnippets && fs.codeSnippets.length > 0) {
3819
+ lines.push(
3820
+ `
3821
+ ## 6. Verified Code Snippets & Syntax Reference`,
3822
+ ...fs.codeSnippets.map((c) => `\`\`\`${c.language || "text"}
3823
+ ${c.code}
3824
+ \`\`\``)
3825
+ );
3826
+ }
3827
+ if (fs.pinoutTables && fs.pinoutTables.length > 0) {
3828
+ lines.push(
3829
+ `
3830
+ ## 7. Pinout & Specification Tables`,
3831
+ ...fs.pinoutTables
3832
+ );
3833
+ }
3093
3834
  return lines.join("\n");
3094
3835
  }
3095
3836
  };
@@ -3106,14 +3847,17 @@ var KnowledgeDiscoveryService = class {
3106
3847
  this.webScraper = new WebScraper({
3107
3848
  crawl4aiHost: config.crawl4aiHost,
3108
3849
  jinaKey: config.apiKeys?.jina,
3850
+ brightDataKey: config.apiKeys?.brightdata || config.apiKeys?.brightData,
3109
3851
  allowEnvFallback: config.allowEnvFallback,
3110
3852
  customAdapter: config.customCrawlerAdapter
3111
3853
  });
3112
3854
  this.youtubeService = new YouTubeIngestionService();
3855
+ this.stemResearcher = new StemResourceResearcher();
3113
3856
  }
3114
3857
  searchEngine;
3115
3858
  webScraper;
3116
3859
  youtubeService;
3860
+ stemResearcher;
3117
3861
  async search(query, limit = 5) {
3118
3862
  return this.searchEngine.search(query, {
3119
3863
  limit,
@@ -3130,6 +3874,9 @@ var KnowledgeDiscoveryService = class {
3130
3874
  async ingestYouTube(urlOrVideoId, preferredLanguages = ["vi", "en"]) {
3131
3875
  return this.youtubeService.fetchTranscript(urlOrVideoId, preferredLanguages);
3132
3876
  }
3877
+ async findStemResources(query, options) {
3878
+ return this.stemResearcher.findResources(query, options);
3879
+ }
3133
3880
  };
3134
3881
  var TerminologyGraphService = class {
3135
3882
  constructor(config) {
@@ -3355,17 +4102,21 @@ exports.ECOMMERCE_AND_COMMERCIAL_PATTERNS = ECOMMERCE_AND_COMMERCIAL_PATTERNS;
3355
4102
  exports.ECOMMERCE_DOMAINS = ECOMMERCE_DOMAINS;
3356
4103
  exports.EvidenceScorer = EvidenceScorer;
3357
4104
  exports.EvidenceVerificationService = EvidenceVerificationService;
4105
+ exports.GitHubCurriculumClient = GitHubCurriculumClient;
3358
4106
  exports.HarvestPipeline = HarvestPipeline;
3359
4107
  exports.HealthAuditor = HealthAuditor;
3360
4108
  exports.KnowledgeDiscoveryService = KnowledgeDiscoveryService;
3361
4109
  exports.LiteratureReviewSynthesizer = LiteratureReviewSynthesizer;
3362
4110
  exports.MultiSourceSearchEngine = MultiSourceSearchEngine;
4111
+ exports.NasaMediaClient = NasaMediaClient;
4112
+ exports.OpenverseClient = OpenverseClient;
3363
4113
  exports.PedagogicalSynthesisService = PedagogicalSynthesisService;
3364
4114
  exports.PedagogicalTermExtractor = PedagogicalTermExtractor;
3365
4115
  exports.ProvenanceTracker = ProvenanceTracker;
3366
4116
  exports.ReferencePackBuilder = ReferencePackBuilder;
3367
4117
  exports.ResearchConfigSchema = ResearchConfigSchema;
3368
4118
  exports.ResearchKitClient = ResearchKitClient;
4119
+ exports.StemResourceResearcher = StemResourceResearcher;
3369
4120
  exports.TechnicalGroundingEngine = TechnicalGroundingEngine;
3370
4121
  exports.TechnicalGroundingService = TechnicalGroundingService;
3371
4122
  exports.TerminologyGraphService = TerminologyGraphService;