@heripo/research-radar 6.1.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -7
- package/dist/index.d.ts +130 -4
- package/dist/index.js +677 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -200,7 +200,7 @@ function identityOf(candidate) {
|
|
|
200
200
|
candidate.classification?.trim() ?? '',
|
|
201
201
|
];
|
|
202
202
|
}
|
|
203
|
-
function buildUserPrompt$
|
|
203
|
+
function buildUserPrompt$2(candidates) {
|
|
204
204
|
const lines = candidates.map((candidate, index) => {
|
|
205
205
|
const [institution, title, classification] = identityOf(candidate);
|
|
206
206
|
return (`${index}. [${institution}] ${title}` +
|
|
@@ -218,7 +218,7 @@ async function triageBatch(candidates, { model, onFallback }, signal) {
|
|
|
218
218
|
model,
|
|
219
219
|
output: Output.object({ schema: KEEP_SCHEMA }),
|
|
220
220
|
system: SYSTEM_PROMPT,
|
|
221
|
-
prompt: buildUserPrompt$
|
|
221
|
+
prompt: buildUserPrompt$2(candidates),
|
|
222
222
|
abortSignal: signal,
|
|
223
223
|
});
|
|
224
224
|
const verdicts = new Array(candidates.length).fill(false);
|
|
@@ -551,7 +551,7 @@ function renderVerifiedDeadlineReminders(reminders, publicationDate, now = new D
|
|
|
551
551
|
* are discarded rather than trusted. Duplicates are named separately so a short
|
|
552
552
|
* selection can be filled without restoring an event the model merged.
|
|
553
553
|
*/
|
|
554
|
-
const SELECT_SCHEMA = jsonSchema({
|
|
554
|
+
const SELECT_SCHEMA$1 = jsonSchema({
|
|
555
555
|
type: 'object',
|
|
556
556
|
properties: {
|
|
557
557
|
select: {
|
|
@@ -568,7 +568,7 @@ const SELECT_SCHEMA = jsonSchema({
|
|
|
568
568
|
required: ['select', 'duplicates'],
|
|
569
569
|
additionalProperties: false,
|
|
570
570
|
});
|
|
571
|
-
const systemPrompt = (limit) => `너는 한국 고고학·문화유산 뉴스레터의 "다가오는 일정·마감" 안내를 고른다.
|
|
571
|
+
const systemPrompt$1 = (limit) => `너는 한국 고고학·문화유산 뉴스레터의 "다가오는 일정·마감" 안내를 고른다.
|
|
572
572
|
|
|
573
573
|
독자는 고고학·문화유산 연구자, 발굴·조사기관 종사자, 학예 인력, 관련 전공 학생이다.
|
|
574
574
|
후보는 모두 원문에서 다시 확인한 일정이다. 날짜·제목은 바꿀 수 없고, 너는 번호만 고른다.
|
|
@@ -593,7 +593,7 @@ function timingOf({ days, reminder }) {
|
|
|
593
593
|
function clockOf(date, time) {
|
|
594
594
|
return time ? `${date} ${time}` : date;
|
|
595
595
|
}
|
|
596
|
-
function buildUserPrompt(rows, publicationDate, limit) {
|
|
596
|
+
function buildUserPrompt$1(rows, publicationDate, limit) {
|
|
597
597
|
const lines = rows.map((row, index) => {
|
|
598
598
|
const { deadline, recentReminderCount } = row.reminder;
|
|
599
599
|
const start = clockOf(deadline.date, deadline.time);
|
|
@@ -644,9 +644,9 @@ const createDeadlineReminderSelector = (options) => {
|
|
|
644
644
|
const { output, usage } = await Promise.race([
|
|
645
645
|
generateText({
|
|
646
646
|
model: options.model,
|
|
647
|
-
output: Output.object({ schema: SELECT_SCHEMA }),
|
|
648
|
-
system: systemPrompt(limit),
|
|
649
|
-
prompt: buildUserPrompt(rows, publicationDate, limit),
|
|
647
|
+
output: Output.object({ schema: SELECT_SCHEMA$1 }),
|
|
648
|
+
system: systemPrompt$1(limit),
|
|
649
|
+
prompt: buildUserPrompt$1(rows, publicationDate, limit),
|
|
650
650
|
abortSignal: controller.signal,
|
|
651
651
|
}),
|
|
652
652
|
new Promise((_, reject) => {
|
|
@@ -697,6 +697,184 @@ const createDeadlineReminderSelector = (options) => {
|
|
|
697
697
|
};
|
|
698
698
|
};
|
|
699
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Shares one call of the application's source between the crawl, which turns
|
|
702
|
+
* issues into articles, and generation, which renders them as tables.
|
|
703
|
+
*
|
|
704
|
+
* A rejected call is forgotten, so a failure while crawling does not decide
|
|
705
|
+
* what generation sees: the next caller asks the source again. A call that
|
|
706
|
+
* does not settle within `timeoutMs` is rejected and forgotten the same way,
|
|
707
|
+
* so a stalled source cannot hold generation, which has no request timeout of
|
|
708
|
+
* its own.
|
|
709
|
+
*
|
|
710
|
+
* @param timeoutMs - Milliseconds before a source call is given up
|
|
711
|
+
*/
|
|
712
|
+
function createJournalIssueLoader(source, timeoutMs = 60_000) {
|
|
713
|
+
let pending = null;
|
|
714
|
+
return () => {
|
|
715
|
+
if (pending)
|
|
716
|
+
return pending;
|
|
717
|
+
let timer;
|
|
718
|
+
const call = Promise.race([
|
|
719
|
+
source(),
|
|
720
|
+
new Promise((_, reject) => {
|
|
721
|
+
timer = setTimeout(() => reject(new Error(`journal issue source timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
722
|
+
}),
|
|
723
|
+
])
|
|
724
|
+
.catch((error) => {
|
|
725
|
+
if (pending === call)
|
|
726
|
+
pending = null;
|
|
727
|
+
throw error;
|
|
728
|
+
})
|
|
729
|
+
.finally(() => clearTimeout(timer));
|
|
730
|
+
pending = call;
|
|
731
|
+
return call;
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Asks for paper indices, never for titles or authors.
|
|
737
|
+
*
|
|
738
|
+
* Rendering stays on the injected papers, so the model can only choose and
|
|
739
|
+
* order them; it cannot rename one or alter its authors. The only text it
|
|
740
|
+
* supplies is the short topic label of a paper it left out of the table.
|
|
741
|
+
*/
|
|
742
|
+
const SELECT_SCHEMA = jsonSchema({
|
|
743
|
+
type: 'object',
|
|
744
|
+
properties: {
|
|
745
|
+
featured: {
|
|
746
|
+
type: 'array',
|
|
747
|
+
items: { type: 'integer' },
|
|
748
|
+
description: '독자가 관심 가질 논문 번호. 관심이 클 것부터',
|
|
749
|
+
},
|
|
750
|
+
others: {
|
|
751
|
+
type: 'array',
|
|
752
|
+
items: {
|
|
753
|
+
type: 'object',
|
|
754
|
+
properties: {
|
|
755
|
+
index: { type: 'integer' },
|
|
756
|
+
topic: {
|
|
757
|
+
type: 'string',
|
|
758
|
+
description: '논문 주제를 2-12자로 요약한 명사구',
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
required: ['index', 'topic'],
|
|
762
|
+
additionalProperties: false,
|
|
763
|
+
},
|
|
764
|
+
description: '독자의 관심사에서 멀어 요약만 할 논문',
|
|
765
|
+
},
|
|
766
|
+
},
|
|
767
|
+
required: ['featured', 'others'],
|
|
768
|
+
additionalProperties: false,
|
|
769
|
+
});
|
|
770
|
+
const systemPrompt = (audience) => `너는 ${audience}에게 보내는 뉴스레터에서 학술지 신간 논문 중 무엇을 표로 소개할지 고른다.
|
|
771
|
+
|
|
772
|
+
기준은 학문 분야가 아니라 **${audience}이(가) 이 논문을 찾아 읽어볼 만큼 관심을 가질까**다.
|
|
773
|
+
제목·저자는 바꿀 수 없고, 너는 번호만 고른다. 모든 논문을 featured나 others 중 정확히 한 곳에 넣는다.
|
|
774
|
+
|
|
775
|
+
- featured: 독자가 관심을 가질 논문. 관심이 클 것부터 순서대로 넣는다.
|
|
776
|
+
- 고고학이 아니어도 독자의 연구·실무에 닿으면 넣는다. 예: 고대 환경·기후 복원, 연대측정·성분분석 같은 분석 기법,
|
|
777
|
+
인골·동물 유존체, 고지도·지명 연구, 전통 건축·토목 기술, 유적·유물을 다루는 문헌사·미술사, 매장유산 제도·정책,
|
|
778
|
+
문화유산 보존처리, 디지털 기록·GIS·AI의 유산 적용
|
|
779
|
+
- 다루는 대상이 독자의 관심 시대·지역·자료와 직접 맞닿는지 본다.
|
|
780
|
+
- others: 독자의 관심사에서 멀어 제목을 나열할 필요가 없는 논문. topic에 주제를 2-12자 명사구로 쓴다.
|
|
781
|
+
- 역사학·인문학이라도 독자와 거리가 멀면 여기에 넣는다. 예: 근현대 외교·정치사, 사상사·철학, 현대 문학 비평,
|
|
782
|
+
현대 사회·경제·교육·관광 정책, 유산과 무관한 언어학
|
|
783
|
+
- 애매하면 featured에 넣는다. others는 독자가 거의 찾아보지 않을 논문만이다.`;
|
|
784
|
+
function buildUserPrompt(issue) {
|
|
785
|
+
const lines = issue.papers.map((paper, index) => {
|
|
786
|
+
const keywords = [
|
|
787
|
+
...new Set(paper.keywords.map((k) => k.trim()).filter(Boolean)),
|
|
788
|
+
].join(', ');
|
|
789
|
+
const abstract = [...(paper.abstract ?? '').replace(/\s+/g, ' ').trim()]
|
|
790
|
+
.slice(0, 200)
|
|
791
|
+
.join('');
|
|
792
|
+
return `${index}. ${paper.title.replace(/\s+/g, ' ').trim()}${keywords ? ` · 키워드: ${keywords}` : ''}${abstract ? ` · 초록: ${abstract}` : ''}`;
|
|
793
|
+
});
|
|
794
|
+
return `학술지 「${issue.journalName.trim()}」 ${issue.publishedYear}년 ${issue.publishedMonth}월 호의 논문 ${issue.papers.length}편을 나눠라.\n\n${lines.join('\n')}`;
|
|
795
|
+
}
|
|
796
|
+
function normalizeTopic(topic) {
|
|
797
|
+
const normalized = topic.replace(/\s+/g, ' ').trim();
|
|
798
|
+
return normalized && [...normalized].length <= 30 ? normalized : null;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Builds the selector that shows an issue's papers its readers would care
|
|
802
|
+
* about as a table, most interesting first, and collapses the rest into a
|
|
803
|
+
* topic summary.
|
|
804
|
+
*
|
|
805
|
+
* It never fails the newsletter: an error, a timeout or an answer with no
|
|
806
|
+
* usable index falls back to null, and the section lists every paper. A paper
|
|
807
|
+
* the model left out, named in both lists or summarized twice is shown in the
|
|
808
|
+
* table after the chosen ones rather than collapsed, so a malformed answer can
|
|
809
|
+
* only show more, never hide a paper.
|
|
810
|
+
*/
|
|
811
|
+
const createJournalPaperSelector = (options) => {
|
|
812
|
+
const fallback = (issue, reason) => {
|
|
813
|
+
options.onFallback?.(reason, issue);
|
|
814
|
+
return null;
|
|
815
|
+
};
|
|
816
|
+
return async (issue) => {
|
|
817
|
+
if (issue.papers.length === 0)
|
|
818
|
+
return { featured: [], others: [] };
|
|
819
|
+
const timeoutMs = options.timeoutMs ?? 60_000;
|
|
820
|
+
const controller = new AbortController();
|
|
821
|
+
let timer;
|
|
822
|
+
try {
|
|
823
|
+
const { output } = await Promise.race([
|
|
824
|
+
generateText({
|
|
825
|
+
model: options.model,
|
|
826
|
+
output: Output.object({ schema: SELECT_SCHEMA }),
|
|
827
|
+
system: systemPrompt(options.audience),
|
|
828
|
+
prompt: buildUserPrompt(issue),
|
|
829
|
+
abortSignal: controller.signal,
|
|
830
|
+
}),
|
|
831
|
+
new Promise((_, reject) => {
|
|
832
|
+
timer = setTimeout(() => {
|
|
833
|
+
controller.abort();
|
|
834
|
+
reject(new Error(`selection timed out after ${timeoutMs}ms`));
|
|
835
|
+
}, timeoutMs);
|
|
836
|
+
}),
|
|
837
|
+
]);
|
|
838
|
+
const count = issue.papers.length;
|
|
839
|
+
const usable = (index) => Number.isInteger(index) && index >= 0 && index < count;
|
|
840
|
+
const featured = [];
|
|
841
|
+
for (const index of output.featured ?? [])
|
|
842
|
+
if (usable(index) && !featured.includes(index))
|
|
843
|
+
featured.push(index);
|
|
844
|
+
const topics = new Map();
|
|
845
|
+
const repeated = new Set();
|
|
846
|
+
for (const { index, topic } of output.others ?? []) {
|
|
847
|
+
if (!usable(index) || featured.includes(index))
|
|
848
|
+
continue;
|
|
849
|
+
if (topics.has(index))
|
|
850
|
+
repeated.add(index);
|
|
851
|
+
else
|
|
852
|
+
topics.set(index, normalizeTopic(topic));
|
|
853
|
+
}
|
|
854
|
+
// A paper summarized twice is ambiguous, so it is shown rather than hidden.
|
|
855
|
+
for (const index of repeated)
|
|
856
|
+
topics.delete(index);
|
|
857
|
+
if (featured.length === 0 && topics.size === 0)
|
|
858
|
+
return fallback(issue, 'no usable index in the selection');
|
|
859
|
+
for (let index = 0; index < count; index++)
|
|
860
|
+
if (!featured.includes(index) && !topics.has(index))
|
|
861
|
+
featured.push(index);
|
|
862
|
+
return {
|
|
863
|
+
featured,
|
|
864
|
+
others: [...topics]
|
|
865
|
+
.map(([index, topic]) => ({ index, topic }))
|
|
866
|
+
.sort((a, b) => a.index - b.index),
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
catch (error) {
|
|
870
|
+
return fallback(issue, error instanceof Error ? error.message : String(error));
|
|
871
|
+
}
|
|
872
|
+
finally {
|
|
873
|
+
clearTimeout(timer);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
};
|
|
877
|
+
|
|
700
878
|
/**
|
|
701
879
|
* Reads what data.go.kr said when it refused a request.
|
|
702
880
|
*
|
|
@@ -1061,20 +1239,20 @@ const buildExcavationReportDetailUrl = (externalId) => `${EXCAVATION_BASE_URL}/g
|
|
|
1061
1239
|
* Marks a response body as injected report data rather than scraped HTML, so
|
|
1062
1240
|
* the parsers below can tell the two apart without guessing.
|
|
1063
1241
|
*/
|
|
1064
|
-
const INJECTED_MARKER = '@heripo/research-radar:excavation-reports';
|
|
1065
|
-
function parseInjectedPayload(body) {
|
|
1066
|
-
if (!body.includes(INJECTED_MARKER)) {
|
|
1242
|
+
const INJECTED_MARKER$1 = '@heripo/research-radar:excavation-reports';
|
|
1243
|
+
function parseInjectedPayload$1(body) {
|
|
1244
|
+
if (!body.includes(INJECTED_MARKER$1)) {
|
|
1067
1245
|
return null;
|
|
1068
1246
|
}
|
|
1069
1247
|
try {
|
|
1070
1248
|
const parsed = JSON.parse(body);
|
|
1071
|
-
return parsed.marker === INJECTED_MARKER ? parsed : null;
|
|
1249
|
+
return parsed.marker === INJECTED_MARKER$1 ? parsed : null;
|
|
1072
1250
|
}
|
|
1073
1251
|
catch {
|
|
1074
1252
|
return null;
|
|
1075
1253
|
}
|
|
1076
1254
|
}
|
|
1077
|
-
function jsonResponse$
|
|
1255
|
+
function jsonResponse$2(payload) {
|
|
1078
1256
|
return new Response(JSON.stringify(payload), {
|
|
1079
1257
|
status: 200,
|
|
1080
1258
|
headers: { 'content-type': 'application/json' },
|
|
@@ -1107,8 +1285,8 @@ const createExcavationReportFetch = (baseFetch = fetch, source) => {
|
|
|
1107
1285
|
}
|
|
1108
1286
|
if (url.pathname === new URL(EXCAVATION_REPORT_LIST_URL).pathname) {
|
|
1109
1287
|
const reports = await loadReports();
|
|
1110
|
-
return jsonResponse$
|
|
1111
|
-
marker: INJECTED_MARKER,
|
|
1288
|
+
return jsonResponse$2({
|
|
1289
|
+
marker: INJECTED_MARKER$1,
|
|
1112
1290
|
reports,
|
|
1113
1291
|
});
|
|
1114
1292
|
}
|
|
@@ -1116,8 +1294,8 @@ const createExcavationReportFetch = (baseFetch = fetch, source) => {
|
|
|
1116
1294
|
const externalId = url.searchParams.get('ecexmRcno');
|
|
1117
1295
|
const report = (await loadReports()).find((candidate) => candidate.externalId === externalId);
|
|
1118
1296
|
if (report) {
|
|
1119
|
-
return jsonResponse$
|
|
1120
|
-
marker: INJECTED_MARKER,
|
|
1297
|
+
return jsonResponse$2({
|
|
1298
|
+
marker: INJECTED_MARKER$1,
|
|
1121
1299
|
report,
|
|
1122
1300
|
});
|
|
1123
1301
|
}
|
|
@@ -1133,7 +1311,7 @@ function renderExcavationReportContent(report) {
|
|
|
1133
1311
|
return ['## 발굴조사 보고서 정보', '', ...lines].join('\n');
|
|
1134
1312
|
}
|
|
1135
1313
|
const parseExcavationReportList = (html) => {
|
|
1136
|
-
const injected = parseInjectedPayload(html);
|
|
1314
|
+
const injected = parseInjectedPayload$1(html);
|
|
1137
1315
|
if (injected) {
|
|
1138
1316
|
return injected.reports.map((report) => ({
|
|
1139
1317
|
uniqId: report.externalId,
|
|
@@ -1199,7 +1377,7 @@ const parseExcavationSiteList = (html) => {
|
|
|
1199
1377
|
return posts;
|
|
1200
1378
|
};
|
|
1201
1379
|
const parseExcavationReportDetail = (html) => {
|
|
1202
|
-
const injected = parseInjectedPayload(html);
|
|
1380
|
+
const injected = parseInjectedPayload$1(html);
|
|
1203
1381
|
if (injected) {
|
|
1204
1382
|
return {
|
|
1205
1383
|
detailContent: renderExcavationReportContent(injected.report),
|
|
@@ -1283,7 +1461,7 @@ function toIsoDate$1(value) {
|
|
|
1283
1461
|
const match = /^(\d{4})-(\d{2})-(\d{2})/.exec(value ?? '');
|
|
1284
1462
|
return match ? `${match[1]}-${match[2]}-${match[3]}` : '';
|
|
1285
1463
|
}
|
|
1286
|
-
function jsonResponse(payload) {
|
|
1464
|
+
function jsonResponse$1(payload) {
|
|
1287
1465
|
return new Response(JSON.stringify(payload), {
|
|
1288
1466
|
status: 200,
|
|
1289
1467
|
headers: { 'content-type': 'application/json' },
|
|
@@ -1325,7 +1503,7 @@ const createG2bFetch = (baseFetch = fetch, options) => {
|
|
|
1325
1503
|
if (!apiKey) {
|
|
1326
1504
|
// Without a key the board is simply not collected: answer with an empty
|
|
1327
1505
|
// payload so the parsers yield nothing and no request is made.
|
|
1328
|
-
return jsonResponse({ items: [] });
|
|
1506
|
+
return jsonResponse$1({ items: [] });
|
|
1329
1507
|
}
|
|
1330
1508
|
const end = new Date();
|
|
1331
1509
|
const begin = new Date(end.getTime() - windowHours * 60 * 60 * 1000);
|
|
@@ -1419,7 +1597,7 @@ const createG2bFetch = (baseFetch = fetch, options) => {
|
|
|
1419
1597
|
for (const notice of heritage) {
|
|
1420
1598
|
noticeCache.set(`${notice.bidNtceNo}:${notice.bidNtceOrd}`, notice);
|
|
1421
1599
|
}
|
|
1422
|
-
return jsonResponse({ items: heritage });
|
|
1600
|
+
return jsonResponse$1({ items: heritage });
|
|
1423
1601
|
}
|
|
1424
1602
|
if (url.pathname === '/link/PNPE027_01/single/') {
|
|
1425
1603
|
if (refreshDetails) {
|
|
@@ -1456,13 +1634,13 @@ const createG2bFetch = (baseFetch = fetch, options) => {
|
|
|
1456
1634
|
}
|
|
1457
1635
|
const latest = revisions.sort((a, b) => Number(b.bidNtceOrd) - Number(a.bidNtceOrd))[0];
|
|
1458
1636
|
return latest
|
|
1459
|
-
? jsonResponse({ item: latest })
|
|
1637
|
+
? jsonResponse$1({ item: latest })
|
|
1460
1638
|
: fail('나라장터 notice not found');
|
|
1461
1639
|
}
|
|
1462
1640
|
const key = `${url.searchParams.get('bidPbancNo')}:${url.searchParams.get('bidPbancOrd')}`;
|
|
1463
1641
|
const notice = noticeCache.get(key);
|
|
1464
1642
|
if (notice) {
|
|
1465
|
-
return jsonResponse({ item: notice });
|
|
1643
|
+
return jsonResponse$1({ item: notice });
|
|
1466
1644
|
}
|
|
1467
1645
|
}
|
|
1468
1646
|
return baseFetch(input, init);
|
|
@@ -2170,6 +2348,226 @@ const parseJinjuMuseumDetail = (html) => {
|
|
|
2170
2348
|
};
|
|
2171
2349
|
};
|
|
2172
2350
|
|
|
2351
|
+
/**
|
|
2352
|
+
* Board URL of the journal issue target.
|
|
2353
|
+
*
|
|
2354
|
+
* There is no list page behind it: the adapter below answers it from the
|
|
2355
|
+
* application's injected issues and never sends it. It points at KCI because
|
|
2356
|
+
* that is where the issues come from, and it is what the source list shows.
|
|
2357
|
+
*/
|
|
2358
|
+
const JOURNAL_ISSUE_LIST_URL = 'https://www.kci.go.kr/kciportal/main.kci';
|
|
2359
|
+
/** Abstract length kept per paper, so a large issue stays a bounded input. */
|
|
2360
|
+
const ABSTRACT_MAX_LENGTH = 300;
|
|
2361
|
+
/** Keywords listed in the issue summary. */
|
|
2362
|
+
const KEYWORD_SUMMARY_LIMIT = 15;
|
|
2363
|
+
/**
|
|
2364
|
+
* Marks a response body as injected issue data rather than scraped HTML, so
|
|
2365
|
+
* the parsers below can tell the two apart without guessing.
|
|
2366
|
+
*/
|
|
2367
|
+
const INJECTED_MARKER = '@heripo/research-radar:journal-issues';
|
|
2368
|
+
function parseInjectedPayload(body) {
|
|
2369
|
+
if (!body.includes(INJECTED_MARKER)) {
|
|
2370
|
+
return null;
|
|
2371
|
+
}
|
|
2372
|
+
try {
|
|
2373
|
+
const parsed = JSON.parse(body);
|
|
2374
|
+
return parsed.marker === INJECTED_MARKER ? parsed : null;
|
|
2375
|
+
}
|
|
2376
|
+
catch {
|
|
2377
|
+
return null;
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
function jsonResponse(payload) {
|
|
2381
|
+
return new Response(JSON.stringify(payload), {
|
|
2382
|
+
status: 200,
|
|
2383
|
+
headers: { 'content-type': 'application/json' },
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
function requestHref(input) {
|
|
2387
|
+
return typeof input === 'string'
|
|
2388
|
+
? input
|
|
2389
|
+
: input instanceof URL
|
|
2390
|
+
? input.href
|
|
2391
|
+
: input.url;
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Settles with `promise`, or rejects once `signal` aborts. The promise keeps
|
|
2395
|
+
* running; only this request stops waiting for it, as a network fetch would.
|
|
2396
|
+
*/
|
|
2397
|
+
function untilAborted(promise, signal) {
|
|
2398
|
+
if (!signal)
|
|
2399
|
+
return promise;
|
|
2400
|
+
if (signal.aborted)
|
|
2401
|
+
return Promise.reject(signal.reason);
|
|
2402
|
+
return new Promise((resolve, reject) => {
|
|
2403
|
+
const onAbort = () => reject(signal.reason);
|
|
2404
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
2405
|
+
promise.then(resolve, reject).finally(() => {
|
|
2406
|
+
signal.removeEventListener('abort', onAbort);
|
|
2407
|
+
});
|
|
2408
|
+
});
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Serves the journal issue target from an injected source.
|
|
2412
|
+
*
|
|
2413
|
+
* Core's crawling chain always fetches a target's list URL and then each detail
|
|
2414
|
+
* URL, so the substitution happens at the fetch layer — the same seam
|
|
2415
|
+
* `createExcavationReportFetch` uses. Unlike that board there is nothing to
|
|
2416
|
+
* crawl instead, so the list URL is always answered here: with no source it is
|
|
2417
|
+
* an empty list and no request is made. Detail requests are matched against
|
|
2418
|
+
* the URLs of the issues already served; anything else is delegated.
|
|
2419
|
+
*
|
|
2420
|
+
* `source` is called once and its result reused for the detail requests that
|
|
2421
|
+
* follow. The adapter sits outermost on the fetch every target shares, so only
|
|
2422
|
+
* the list request ever waits on the source: other requests are matched
|
|
2423
|
+
* against issues already served, without awaiting, so a slow or failing source
|
|
2424
|
+
* cannot stall or break the rest of the crawl. Core requests this target's
|
|
2425
|
+
* details only after its list has parsed. A failed source is retried on the
|
|
2426
|
+
* next list request. The list request honors its abort signal, so core's
|
|
2427
|
+
* request timeout ends this target even when the source never settles.
|
|
2428
|
+
*
|
|
2429
|
+
* @param baseFetch - Fetch to delegate every other request to
|
|
2430
|
+
* @param source - Supplies the issues for this run
|
|
2431
|
+
*/
|
|
2432
|
+
const createJournalIssueFetch = (baseFetch = fetch, source) => {
|
|
2433
|
+
let pending = null;
|
|
2434
|
+
const issuesByUrl = new Map();
|
|
2435
|
+
const loadIssues = () => (pending ??= (source ? source() : Promise.resolve([])).then((issues) => {
|
|
2436
|
+
for (const issue of issues)
|
|
2437
|
+
issuesByUrl.set(issue.url, issue);
|
|
2438
|
+
return issues;
|
|
2439
|
+
}, (error) => {
|
|
2440
|
+
pending = null;
|
|
2441
|
+
throw error;
|
|
2442
|
+
}));
|
|
2443
|
+
return async (input, init) => {
|
|
2444
|
+
const href = requestHref(input);
|
|
2445
|
+
if (href === JOURNAL_ISSUE_LIST_URL) {
|
|
2446
|
+
return jsonResponse({
|
|
2447
|
+
marker: INJECTED_MARKER,
|
|
2448
|
+
issues: await untilAborted(loadIssues(), init?.signal),
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
const issue = issuesByUrl.get(href);
|
|
2452
|
+
if (issue) {
|
|
2453
|
+
return jsonResponse({
|
|
2454
|
+
marker: INJECTED_MARKER,
|
|
2455
|
+
issue,
|
|
2456
|
+
});
|
|
2457
|
+
}
|
|
2458
|
+
return baseFetch(input, init);
|
|
2459
|
+
};
|
|
2460
|
+
};
|
|
2461
|
+
/** "제59권 제3호", or whichever part the journal numbers. */
|
|
2462
|
+
function formatVolumeIssue(issue) {
|
|
2463
|
+
const label = (value, unit) => {
|
|
2464
|
+
const trimmed = value.trim();
|
|
2465
|
+
if (!trimmed)
|
|
2466
|
+
return '';
|
|
2467
|
+
return /^\d+$/.test(trimmed) ? `제${trimmed}${unit}` : trimmed;
|
|
2468
|
+
};
|
|
2469
|
+
// Some journals register the publication year as the volume on KCI
|
|
2470
|
+
// (한국고고학보 2026-3), which would read as "제2026권".
|
|
2471
|
+
const volume = issue.volume.trim() === String(issue.publishedYear) ? '' : issue.volume;
|
|
2472
|
+
return [label(volume, '권'), label(issue.issue, '호')]
|
|
2473
|
+
.filter(Boolean)
|
|
2474
|
+
.join(' ');
|
|
2475
|
+
}
|
|
2476
|
+
function formatJournalIssueTitle(issue) {
|
|
2477
|
+
const volumeIssue = formatVolumeIssue(issue);
|
|
2478
|
+
return [
|
|
2479
|
+
issue.journalName.trim(),
|
|
2480
|
+
volumeIssue,
|
|
2481
|
+
`발간 (${issue.publishedYear}년 ${issue.publishedMonth}월)`,
|
|
2482
|
+
]
|
|
2483
|
+
.filter(Boolean)
|
|
2484
|
+
.join(' ');
|
|
2485
|
+
}
|
|
2486
|
+
/** Keyword counts by paper. A keyword repeated within one paper counts once. */
|
|
2487
|
+
function countKeywords(papers) {
|
|
2488
|
+
const counts = new Map();
|
|
2489
|
+
for (const paper of papers) {
|
|
2490
|
+
const keywords = new Set(paper.keywords.map((keyword) => keyword.trim()).filter(Boolean));
|
|
2491
|
+
for (const keyword of keywords) {
|
|
2492
|
+
counts.set(keyword, (counts.get(keyword) ?? 0) + 1);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
return [...counts]
|
|
2496
|
+
.map(([keyword, paperCount]) => ({ keyword, paperCount }))
|
|
2497
|
+
.sort((a, b) => b.paperCount - a.paperCount || a.keyword.localeCompare(b.keyword, 'ko'));
|
|
2498
|
+
}
|
|
2499
|
+
function truncate(text, maxLength) {
|
|
2500
|
+
const normalized = text.replace(/\s+/g, ' ').trim();
|
|
2501
|
+
const characters = [...normalized];
|
|
2502
|
+
return characters.length > maxLength
|
|
2503
|
+
? `${characters.slice(0, maxLength).join('')}…`
|
|
2504
|
+
: normalized;
|
|
2505
|
+
}
|
|
2506
|
+
/** Renders an issue as the article body: summary, keywords, then every paper. */
|
|
2507
|
+
function renderJournalIssueContent(issue) {
|
|
2508
|
+
const volumeIssue = formatVolumeIssue(issue);
|
|
2509
|
+
const lines = [
|
|
2510
|
+
'## 학술지 권호 정보',
|
|
2511
|
+
'',
|
|
2512
|
+
`- **학술지**: ${issue.journalName.trim()}`,
|
|
2513
|
+
`- **발행**: ${issue.publishedYear}년 ${issue.publishedMonth}월`,
|
|
2514
|
+
...(volumeIssue ? [`- **권호**: ${volumeIssue}`] : []),
|
|
2515
|
+
`- **수록 논문**: ${issue.papers.length}편`,
|
|
2516
|
+
];
|
|
2517
|
+
// Counts are per paper and overlap, so they are not summed into a total.
|
|
2518
|
+
// Only keywords shared by several papers say anything about the issue; when
|
|
2519
|
+
// every keyword is unique the summary would just be the alphabetical head of
|
|
2520
|
+
// the list, so it is left out.
|
|
2521
|
+
const keywords = countKeywords(issue.papers)
|
|
2522
|
+
.filter(({ paperCount }) => paperCount > 1)
|
|
2523
|
+
.slice(0, KEYWORD_SUMMARY_LIMIT);
|
|
2524
|
+
if (keywords.length > 0) {
|
|
2525
|
+
lines.push('', '## 여러 논문이 다룬 키워드', '', keywords
|
|
2526
|
+
.map(({ keyword, paperCount }) => `${keyword}(${paperCount}편)`)
|
|
2527
|
+
.join(', '));
|
|
2528
|
+
}
|
|
2529
|
+
lines.push('', '## 수록 논문', '');
|
|
2530
|
+
issue.papers.forEach((paper, index) => {
|
|
2531
|
+
lines.push(`${index + 1}. **[${paper.title.trim()}](${paper.url})**`);
|
|
2532
|
+
const authors = paper.authors.map((name) => name.trim()).filter(Boolean);
|
|
2533
|
+
if (authors.length > 0) {
|
|
2534
|
+
lines.push(` - 저자: ${authors.join(', ')}`);
|
|
2535
|
+
}
|
|
2536
|
+
const keywords = [
|
|
2537
|
+
...new Set(paper.keywords.map((k) => k.trim()).filter(Boolean)),
|
|
2538
|
+
];
|
|
2539
|
+
if (keywords.length > 0) {
|
|
2540
|
+
lines.push(` - 키워드: ${keywords.join(', ')}`);
|
|
2541
|
+
}
|
|
2542
|
+
const abstract = paper.abstract?.trim();
|
|
2543
|
+
if (abstract) {
|
|
2544
|
+
lines.push(` - 초록: ${truncate(abstract, ABSTRACT_MAX_LENGTH)}`);
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
return lines.join('\n');
|
|
2548
|
+
}
|
|
2549
|
+
const parseJournalIssueList = (html) => {
|
|
2550
|
+
const injected = parseInjectedPayload(html);
|
|
2551
|
+
if (!injected) {
|
|
2552
|
+
return [];
|
|
2553
|
+
}
|
|
2554
|
+
return injected.issues.map((issue) => ({
|
|
2555
|
+
uniqId: issue.externalId,
|
|
2556
|
+
title: formatJournalIssueTitle(issue),
|
|
2557
|
+
date: issue.registeredDate,
|
|
2558
|
+
detailUrl: issue.url,
|
|
2559
|
+
dateType: DateType.REGISTERED,
|
|
2560
|
+
}));
|
|
2561
|
+
};
|
|
2562
|
+
const parseJournalIssueDetail = (html) => {
|
|
2563
|
+
const injected = parseInjectedPayload(html);
|
|
2564
|
+
return {
|
|
2565
|
+
detailContent: injected ? renderJournalIssueContent(injected.issue) : '',
|
|
2566
|
+
hasAttachedFile: false,
|
|
2567
|
+
hasAttachedImage: false,
|
|
2568
|
+
};
|
|
2569
|
+
};
|
|
2570
|
+
|
|
2173
2571
|
const parseKaahList = (html) => {
|
|
2174
2572
|
const $ = cheerio.load(html);
|
|
2175
2573
|
const posts = [];
|
|
@@ -2661,31 +3059,6 @@ const parseNrichMajorEventList = (html) => {
|
|
|
2661
3059
|
});
|
|
2662
3060
|
return posts;
|
|
2663
3061
|
};
|
|
2664
|
-
const parseNrichJournalList = (html) => {
|
|
2665
|
-
const $ = cheerio.load(html);
|
|
2666
|
-
const posts = [];
|
|
2667
|
-
const baseUrl = 'https://www.nrich.go.kr';
|
|
2668
|
-
$('ul.list-body li').each((index, element) => {
|
|
2669
|
-
const titleElement = $(element).find('.col2 a.cont-link');
|
|
2670
|
-
const relativeHref = titleElement.attr('href');
|
|
2671
|
-
if (!relativeHref) {
|
|
2672
|
-
return;
|
|
2673
|
-
}
|
|
2674
|
-
const fullUrl = new URL(`${relativeHref}`, baseUrl);
|
|
2675
|
-
const detailUrl = fullUrl.href;
|
|
2676
|
-
const uniqId = fullUrl.searchParams.get('idx') ?? undefined;
|
|
2677
|
-
const title = titleElement.text()?.trim() ?? '';
|
|
2678
|
-
const date = getDate($(element).find('.col3 .cont-txt').text().trim());
|
|
2679
|
-
posts.push({
|
|
2680
|
-
uniqId,
|
|
2681
|
-
title,
|
|
2682
|
-
date,
|
|
2683
|
-
detailUrl: cleanUrl(detailUrl),
|
|
2684
|
-
dateType: DateType.REGISTERED,
|
|
2685
|
-
});
|
|
2686
|
-
});
|
|
2687
|
-
return posts;
|
|
2688
|
-
};
|
|
2689
3062
|
const parseNrichPortalList = (html) => {
|
|
2690
3063
|
const $ = cheerio.load(html);
|
|
2691
3064
|
const posts = [];
|
|
@@ -2733,27 +3106,6 @@ const parseNrichMajorEventDetail = (html) => {
|
|
|
2733
3106
|
hasAttachedImage: content.find('img').length > 0,
|
|
2734
3107
|
};
|
|
2735
3108
|
};
|
|
2736
|
-
const parseNrichJournalDetail = (html) => {
|
|
2737
|
-
const $ = cheerio.load(html);
|
|
2738
|
-
$('script, style').remove();
|
|
2739
|
-
const articles = [];
|
|
2740
|
-
// 리스트의 각 항목을 순회하면서 논문 정보 추출
|
|
2741
|
-
$('ul.list-body li').each((index, element) => {
|
|
2742
|
-
const number = $(element).find('.col1 .cont-txt').text().trim();
|
|
2743
|
-
const titleElement = $(element).find('.col2 a.cont-link');
|
|
2744
|
-
const title = titleElement.text().trim();
|
|
2745
|
-
const author = $(element).find('.col3 .cont-txt').text().trim();
|
|
2746
|
-
if (title && author) {
|
|
2747
|
-
articles.push(`${number}. **${title}**\n 저자: ${author}`);
|
|
2748
|
-
}
|
|
2749
|
-
});
|
|
2750
|
-
const content = articles.length > 0 ? `## 논문 목록\n\n${articles.join('\n\n')}` : '';
|
|
2751
|
-
return {
|
|
2752
|
-
detailContent: content,
|
|
2753
|
-
hasAttachedFile: true,
|
|
2754
|
-
hasAttachedImage: false,
|
|
2755
|
-
};
|
|
2756
|
-
};
|
|
2757
3109
|
const parseNrichPortalDetail = (html) => {
|
|
2758
3110
|
const $ = cheerio.load(html);
|
|
2759
3111
|
const content = $('div.detail_Area2');
|
|
@@ -3064,18 +3416,12 @@ function createCrawlingTargetGroups(customFetch) {
|
|
|
3064
3416
|
parseDetail: parseNrichMajorEventDetail,
|
|
3065
3417
|
},
|
|
3066
3418
|
{
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
{
|
|
3074
|
-
id: '국립문화유산연구원_학술지_보존과학연구',
|
|
3075
|
-
name: '국립문화유산연구원 보존과학연구 학술지',
|
|
3076
|
-
url: 'https://www.nrich.go.kr/kor/subscriptionDataUsrList.do?menuIdx=2065&gubun=K',
|
|
3077
|
-
parseList: parseNrichJournalList,
|
|
3078
|
-
parseDetail: parseNrichJournalDetail,
|
|
3419
|
+
// Served from the application's injected KCI issues, never crawled.
|
|
3420
|
+
id: 'KCI_학술지_신간',
|
|
3421
|
+
name: 'KCI 학술지 신간 권호',
|
|
3422
|
+
url: JOURNAL_ISSUE_LIST_URL,
|
|
3423
|
+
parseList: parseJournalIssueList,
|
|
3424
|
+
parseDetail: parseJournalIssueDetail,
|
|
3079
3425
|
},
|
|
3080
3426
|
{
|
|
3081
3427
|
id: '국가유산지식이음_공지사항',
|
|
@@ -4402,6 +4748,13 @@ class AnalysisProvider {
|
|
|
4402
4748
|
targetUrl: 'https://www.seamuse.go.kr/resources/academicreport/list/1#tab4',
|
|
4403
4749
|
minScore: 6,
|
|
4404
4750
|
},
|
|
4751
|
+
// Injected journal issues: the prompt asks for the same floor that
|
|
4752
|
+
// `update()` enforces, so the model is not asked for scores it cannot
|
|
4753
|
+
// keep.
|
|
4754
|
+
{
|
|
4755
|
+
targetUrl: JOURNAL_ISSUE_LIST_URL,
|
|
4756
|
+
minScore: JOURNAL_ISSUE_MINIMUM_SCORE,
|
|
4757
|
+
},
|
|
4405
4758
|
// Excavation report news: minimum score 2
|
|
4406
4759
|
{
|
|
4407
4760
|
targetUrl: 'https://www.e-minwon.go.kr/ge/ee/getListEcexmPrmsnAply.do',
|
|
@@ -4439,10 +4792,35 @@ class AnalysisProvider {
|
|
|
4439
4792
|
async update(article) {
|
|
4440
4793
|
await this.articleRepository.updateAnalysis({
|
|
4441
4794
|
...article,
|
|
4442
|
-
importanceScore: capScoreByHeritageDomain(
|
|
4795
|
+
importanceScore: capScoreByHeritageDomain({
|
|
4796
|
+
...article,
|
|
4797
|
+
importanceScore: raiseJournalIssueScore(article),
|
|
4798
|
+
}),
|
|
4443
4799
|
});
|
|
4444
4800
|
}
|
|
4445
4801
|
}
|
|
4802
|
+
/**
|
|
4803
|
+
* Lowest score an injected journal issue article is saved with.
|
|
4804
|
+
*
|
|
4805
|
+
* The application only injects issues of journals it chose for the
|
|
4806
|
+
* newsletter, and their papers are filtered for the readers when rendered, so
|
|
4807
|
+
* a low score must not drop a whole issue before then: the application leaves
|
|
4808
|
+
* articles scored 1 out of the candidates.
|
|
4809
|
+
*/
|
|
4810
|
+
const JOURNAL_ISSUE_MINIMUM_SCORE = 6;
|
|
4811
|
+
/**
|
|
4812
|
+
* Enforces the journal issue floor on the saved score.
|
|
4813
|
+
*
|
|
4814
|
+
* Core only states `minimumImportanceScoreRules` in the prompt; it keeps the
|
|
4815
|
+
* model's score as returned and falls back to 1 when scoring fails. The floor
|
|
4816
|
+
* is applied here so neither can drop an issue. The per-domain ceiling still
|
|
4817
|
+
* applies afterwards.
|
|
4818
|
+
*/
|
|
4819
|
+
function raiseJournalIssueScore(article) {
|
|
4820
|
+
return article.targetUrl === JOURNAL_ISSUE_LIST_URL
|
|
4821
|
+
? Math.max(article.importanceScore, JOURNAL_ISSUE_MINIMUM_SCORE)
|
|
4822
|
+
: article.importanceScore;
|
|
4823
|
+
}
|
|
4446
4824
|
/**
|
|
4447
4825
|
* Applies the per-domain score ceiling from `maximumImportanceScoreByDomain`.
|
|
4448
4826
|
*
|
|
@@ -4995,6 +5373,16 @@ ${options.heripolabNewsMarkdown}
|
|
|
4995
5373
|
|
|
4996
5374
|
{{NEWSLETTER_CONTENT}}
|
|
4997
5375
|
|
|
5376
|
+
${options?.journalIssuesMarkdown
|
|
5377
|
+
? `<div data-research-radar-journal-issues="">${safeMarkdown2Html(options.journalIssuesMarkdown, {
|
|
5378
|
+
window: new JSDOM('').window,
|
|
5379
|
+
linkTargetBlank: true,
|
|
5380
|
+
fixMalformedUrls: true,
|
|
5381
|
+
fixBoldSyntax: true,
|
|
5382
|
+
convertStrikethrough: true,
|
|
5383
|
+
})}</div>`
|
|
5384
|
+
: ''}
|
|
5385
|
+
|
|
4998
5386
|
<div data-research-radar-closing="">
|
|
4999
5387
|
|
|
5000
5388
|
${options?.deadlineRemindersMarkdown
|
|
@@ -5175,6 +5563,122 @@ function collectNewsletterDeadlines(content, articles, verified) {
|
|
|
5175
5563
|
return result;
|
|
5176
5564
|
}
|
|
5177
5565
|
|
|
5566
|
+
/** Heading of the journal issue section. Distinct from any 학술지 heading the model writes. */
|
|
5567
|
+
const JOURNAL_ISSUE_SECTION_HEADING = '📖 새로 나온 학술지';
|
|
5568
|
+
/** Authors listed per paper before the rest are counted. */
|
|
5569
|
+
const AUTHOR_LIMIT = 3;
|
|
5570
|
+
/** Topic labels named in the summary of papers left out of the table. */
|
|
5571
|
+
const TOPIC_LIMIT = 5;
|
|
5572
|
+
/**
|
|
5573
|
+
* Escapes a plain table cell: a `|` would end the cell, a newline the row.
|
|
5574
|
+
* Link labels go through `escapeLabel`, which already covers both.
|
|
5575
|
+
*/
|
|
5576
|
+
function cell(value) {
|
|
5577
|
+
return value.replace(/\s+/g, ' ').trim().replace(/\|/g, '\\|');
|
|
5578
|
+
}
|
|
5579
|
+
function formatAuthors(authors) {
|
|
5580
|
+
const names = authors.map((name) => name.trim()).filter(Boolean);
|
|
5581
|
+
if (names.length === 0)
|
|
5582
|
+
return '—';
|
|
5583
|
+
return names.length > AUTHOR_LIMIT
|
|
5584
|
+
? `${names.slice(0, AUTHOR_LIMIT).join(', ')} 외 ${names.length - AUTHOR_LIMIT}명`
|
|
5585
|
+
: names.join(', ');
|
|
5586
|
+
}
|
|
5587
|
+
function paperLink(paper) {
|
|
5588
|
+
return `[${escapeLabel(paper.title.trim())}](${paper.url})`;
|
|
5589
|
+
}
|
|
5590
|
+
function issueHeading(issue) {
|
|
5591
|
+
const label = [issue.journalName.trim(), formatVolumeIssue(issue)]
|
|
5592
|
+
.filter(Boolean)
|
|
5593
|
+
.join(' ');
|
|
5594
|
+
return `**[${escapeLabel(label)}](${issue.url})** · ${issue.publishedYear}년 ${issue.publishedMonth}월 · 논문 ${issue.papers.length}편`;
|
|
5595
|
+
}
|
|
5596
|
+
function topicSummary(topics) {
|
|
5597
|
+
const named = [
|
|
5598
|
+
...new Set(topics.filter((topic) => Boolean(topic))),
|
|
5599
|
+
];
|
|
5600
|
+
if (named.length === 0)
|
|
5601
|
+
return '';
|
|
5602
|
+
return named.slice(0, TOPIC_LIMIT).map(escapeLabel).join(', ');
|
|
5603
|
+
}
|
|
5604
|
+
/**
|
|
5605
|
+
* Renders one issue: the papers its readers would care about as a table, most
|
|
5606
|
+
* interesting first, and the rest as a count with their topics. Table rows plus
|
|
5607
|
+
* that count always equal the paper count.
|
|
5608
|
+
*/
|
|
5609
|
+
function renderIssue({ issue, selection }) {
|
|
5610
|
+
const lines = [issueHeading(issue), ''];
|
|
5611
|
+
const featured = selection
|
|
5612
|
+
? selection.featured
|
|
5613
|
+
: issue.papers.map((_, index) => index);
|
|
5614
|
+
const others = selection?.others ?? [];
|
|
5615
|
+
const topics = topicSummary(others.map(({ topic }) => topic));
|
|
5616
|
+
if (featured.length > 0) {
|
|
5617
|
+
lines.push('| 논문 | 저자 |', '| --- | --- |');
|
|
5618
|
+
for (const index of featured) {
|
|
5619
|
+
const paper = issue.papers[index];
|
|
5620
|
+
lines.push(`| ${paperLink(paper)} | ${cell(formatAuthors(paper.authors))} |`);
|
|
5621
|
+
}
|
|
5622
|
+
if (others.length > 0)
|
|
5623
|
+
lines.push('', topics
|
|
5624
|
+
? `그 밖에 ${topics} 등을 다룬 논문 ${others.length}편이 함께 실렸습니다.`
|
|
5625
|
+
: `그 밖에 논문 ${others.length}편이 함께 실렸습니다.`);
|
|
5626
|
+
}
|
|
5627
|
+
else {
|
|
5628
|
+
lines.push(topics
|
|
5629
|
+
? `${topics} 등을 다룬 논문이 실렸습니다.`
|
|
5630
|
+
: '이번 호에는 소개할 만한 논문이 없었습니다.');
|
|
5631
|
+
}
|
|
5632
|
+
return lines.join('\n');
|
|
5633
|
+
}
|
|
5634
|
+
/** Renders the whole section, or '' when there is no issue to show. */
|
|
5635
|
+
function renderJournalIssueSection(entries) {
|
|
5636
|
+
if (entries.length === 0)
|
|
5637
|
+
return '';
|
|
5638
|
+
return [
|
|
5639
|
+
`## ${JOURNAL_ISSUE_SECTION_HEADING}`,
|
|
5640
|
+
'',
|
|
5641
|
+
...entries.flatMap((entry, index) => index === 0 ? [renderIssue(entry)] : ['', renderIssue(entry)]),
|
|
5642
|
+
].join('\n');
|
|
5643
|
+
}
|
|
5644
|
+
/**
|
|
5645
|
+
* Headings the section is placed before, in order of preference.
|
|
5646
|
+
*
|
|
5647
|
+
* 사업·입찰 runs last so it does not bury academic news; placing journals after
|
|
5648
|
+
* it would bury them in turn. Without that section the journals go before
|
|
5649
|
+
* 마무리, and without either at the end of the body.
|
|
5650
|
+
*/
|
|
5651
|
+
const JOURNAL_ISSUE_SECTION_ANCHORS = [
|
|
5652
|
+
'📑 사업·입찰 공고',
|
|
5653
|
+
'📌 마무리',
|
|
5654
|
+
];
|
|
5655
|
+
/** Inserts the section Markdown before the first anchor heading found. */
|
|
5656
|
+
function insertJournalIssueMarkdown(content, section) {
|
|
5657
|
+
if (!section)
|
|
5658
|
+
return content;
|
|
5659
|
+
for (const anchor of JOURNAL_ISSUE_SECTION_ANCHORS) {
|
|
5660
|
+
const match = new RegExp(`^##\\s+${anchor.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*$`, 'm').exec(content);
|
|
5661
|
+
if (match)
|
|
5662
|
+
return `${content.slice(0, match.index)}${section}\n\n${content.slice(match.index)}`;
|
|
5663
|
+
}
|
|
5664
|
+
return `${content.trimEnd()}\n\n${section}`;
|
|
5665
|
+
}
|
|
5666
|
+
/**
|
|
5667
|
+
* Inserts the rendered section before the first anchor `<h2>` found, or before
|
|
5668
|
+
* `fallback` (the closing block) when neither heading is present.
|
|
5669
|
+
*/
|
|
5670
|
+
function insertJournalIssueHtml(document, section, fallback) {
|
|
5671
|
+
const headings = [...document.querySelectorAll('h2')];
|
|
5672
|
+
for (const anchor of JOURNAL_ISSUE_SECTION_ANCHORS) {
|
|
5673
|
+
const heading = headings.find((element) => element.textContent?.replace(/\s+/g, ' ').trim() === anchor);
|
|
5674
|
+
if (heading) {
|
|
5675
|
+
heading.before(section);
|
|
5676
|
+
return;
|
|
5677
|
+
}
|
|
5678
|
+
}
|
|
5679
|
+
fallback.before(section);
|
|
5680
|
+
}
|
|
5681
|
+
|
|
5178
5682
|
/**
|
|
5179
5683
|
* Content generation provider implementation
|
|
5180
5684
|
* - LLM-based newsletter content generation
|
|
@@ -5186,8 +5690,10 @@ class ContentGenerateProvider {
|
|
|
5186
5690
|
newsletterRepository;
|
|
5187
5691
|
templateOptions;
|
|
5188
5692
|
selectDeadlineReminders;
|
|
5693
|
+
journalIssues;
|
|
5189
5694
|
_issueOrder = null;
|
|
5190
5695
|
deadlineRemindersMarkdown;
|
|
5696
|
+
heldJournalIssues = [];
|
|
5191
5697
|
model;
|
|
5192
5698
|
fetchRecentTitles;
|
|
5193
5699
|
/** HTML template with markers for title and content injection */
|
|
@@ -5196,11 +5702,12 @@ class ContentGenerateProvider {
|
|
|
5196
5702
|
newsletterBrandName;
|
|
5197
5703
|
constructor(model, articleRepository, newsletterRepository, templateOptions, brandName,
|
|
5198
5704
|
/** Chooses displayed reminders; omitted, the first rows by date display. */
|
|
5199
|
-
selectDeadlineReminders) {
|
|
5705
|
+
selectDeadlineReminders, journalIssues) {
|
|
5200
5706
|
this.articleRepository = articleRepository;
|
|
5201
5707
|
this.newsletterRepository = newsletterRepository;
|
|
5202
5708
|
this.templateOptions = templateOptions;
|
|
5203
5709
|
this.selectDeadlineReminders = selectDeadlineReminders;
|
|
5710
|
+
this.journalIssues = journalIssues;
|
|
5204
5711
|
this.model = model;
|
|
5205
5712
|
this.deadlineRemindersMarkdown =
|
|
5206
5713
|
templateOptions?.deadlineRemindersMarkdown?.trim() ?? '';
|
|
@@ -5251,7 +5758,29 @@ class ContentGenerateProvider {
|
|
|
5251
5758
|
* @returns Articles eligible for inclusion in the newsletter
|
|
5252
5759
|
*/
|
|
5253
5760
|
async fetchArticleCandidates() {
|
|
5254
|
-
|
|
5761
|
+
const candidates = await this.articleRepository.findCandidatesForNewsletter();
|
|
5762
|
+
this.heldJournalIssues = [];
|
|
5763
|
+
const journalCandidates = candidates.filter((article) => article.targetUrl === JOURNAL_ISSUE_LIST_URL);
|
|
5764
|
+
if (!this.journalIssues || journalCandidates.length === 0) {
|
|
5765
|
+
return candidates;
|
|
5766
|
+
}
|
|
5767
|
+
// An issue this run cannot load is left to the model, as before; it is
|
|
5768
|
+
// never dropped.
|
|
5769
|
+
let issues;
|
|
5770
|
+
try {
|
|
5771
|
+
issues = await this.journalIssues.load();
|
|
5772
|
+
}
|
|
5773
|
+
catch (error) {
|
|
5774
|
+
this.journalIssues.onUnavailable?.(error instanceof Error ? error.message : String(error));
|
|
5775
|
+
return candidates;
|
|
5776
|
+
}
|
|
5777
|
+
const issuesByUrl = new Map(issues.map((issue) => [issue.url, issue]));
|
|
5778
|
+
this.heldJournalIssues = journalCandidates.flatMap((article) => {
|
|
5779
|
+
const issue = issuesByUrl.get(article.url);
|
|
5780
|
+
return issue ? [{ article, issue }] : [];
|
|
5781
|
+
});
|
|
5782
|
+
const held = new Set(this.heldJournalIssues.map(({ article }) => article));
|
|
5783
|
+
return candidates.filter((article) => !held.has(article));
|
|
5255
5784
|
}
|
|
5256
5785
|
/**
|
|
5257
5786
|
* Save generated newsletter to the repository
|
|
@@ -5271,6 +5800,7 @@ class ContentGenerateProvider {
|
|
|
5271
5800
|
? await this.renderDeadlineReminders(reminders, newsletter.date)
|
|
5272
5801
|
: this.deadlineRemindersMarkdown ||
|
|
5273
5802
|
(await this.renderDeadlineReminders(reminders, newsletter.date));
|
|
5803
|
+
const journalMarkdown = await this.renderJournalIssues();
|
|
5274
5804
|
const share = this.templateOptions?.shareNoticeMarkdown ??
|
|
5275
5805
|
`이 소식이 도움이 되셨다면 동료 연구자에게도 소개해주시면 좋겠습니다. [${escapeLabel(this.newsletterBrandName)} 구독하기](${this.subscribePageUrl})`;
|
|
5276
5806
|
// Render only the closing block with the original stylesheet. Keep core's
|
|
@@ -5279,22 +5809,46 @@ class ContentGenerateProvider {
|
|
|
5279
5809
|
...this.templateOptions,
|
|
5280
5810
|
deadlineRemindersMarkdown: markdown,
|
|
5281
5811
|
shareNoticeMarkdown: share,
|
|
5812
|
+
journalIssuesMarkdown: journalMarkdown,
|
|
5282
5813
|
}))).window.document;
|
|
5283
5814
|
const dom = new JSDOM(newsletter.htmlBody);
|
|
5284
5815
|
const document = dom.window.document;
|
|
5285
5816
|
const closing = document.querySelector('[data-research-radar-closing]');
|
|
5286
5817
|
if (!closing)
|
|
5287
5818
|
throw new Error('Newsletter closing block not found');
|
|
5819
|
+
const journalSection = closingDocument.querySelector('[data-research-radar-journal-issues]');
|
|
5820
|
+
if (journalSection) {
|
|
5821
|
+
insertJournalIssueHtml(document, document.importNode(journalSection, true), closing);
|
|
5822
|
+
}
|
|
5288
5823
|
closing.outerHTML = closingDocument.querySelector('[data-research-radar-closing]').outerHTML;
|
|
5824
|
+
// Core hands back only the candidates the model saw; the held-aside
|
|
5825
|
+
// journal articles are part of this issue too.
|
|
5826
|
+
const usedIds = new Set(usedArticles.map((article) => article.id));
|
|
5289
5827
|
return this.newsletterRepository.saveNewsletter({
|
|
5290
5828
|
...input,
|
|
5829
|
+
usedArticles: [
|
|
5830
|
+
...usedArticles,
|
|
5831
|
+
...this.heldJournalIssues
|
|
5832
|
+
.map(({ article }) => article)
|
|
5833
|
+
.filter((article) => !usedIds.has(article.id)),
|
|
5834
|
+
],
|
|
5291
5835
|
newsletter: {
|
|
5292
5836
|
...newsletter,
|
|
5293
|
-
content: `${newsletter.content}${markdown ? `\n\n<!-- research-radar-deadline-reminders -->\n${markdown}` : ''}${share ? `\n\n<!-- research-radar-share-notice -->\n${share}` : ''}`,
|
|
5837
|
+
content: `${insertJournalIssueMarkdown(newsletter.content, journalMarkdown)}${markdown ? `\n\n<!-- research-radar-deadline-reminders -->\n${markdown}` : ''}${share ? `\n\n<!-- research-radar-share-notice -->\n${share}` : ''}`,
|
|
5294
5838
|
htmlBody: dom.serialize(),
|
|
5295
5839
|
},
|
|
5296
5840
|
});
|
|
5297
5841
|
}
|
|
5842
|
+
async renderJournalIssues() {
|
|
5843
|
+
if (this.heldJournalIssues.length === 0)
|
|
5844
|
+
return '';
|
|
5845
|
+
const select = this.journalIssues?.select;
|
|
5846
|
+
const entries = await Promise.all(this.heldJournalIssues.map(async ({ issue }) => ({
|
|
5847
|
+
issue,
|
|
5848
|
+
selection: select ? await select(issue) : null,
|
|
5849
|
+
})));
|
|
5850
|
+
return renderJournalIssueSection(entries);
|
|
5851
|
+
}
|
|
5298
5852
|
async renderDeadlineReminders(reminders, publicationDate) {
|
|
5299
5853
|
if (!this.selectDeadlineReminders)
|
|
5300
5854
|
return renderVerifiedDeadlineReminders(reminders, publicationDate);
|
|
@@ -5548,7 +6102,7 @@ function createRobotsAwareFetch(baseFetch = fetch, options = {}) {
|
|
|
5548
6102
|
}
|
|
5549
6103
|
|
|
5550
6104
|
/** Shared network/adapters path for daily crawling and single-source refresh. */
|
|
5551
|
-
function createResearchRadarFetch({ customFetch, excavationReportSource, logger, publicDataApiKey, bidTriage, refreshG2bDetails, } = {}) {
|
|
6105
|
+
function createResearchRadarFetch({ customFetch, excavationReportSource, journalIssueSource, logger, publicDataApiKey, bidTriage, refreshG2bDetails, } = {}) {
|
|
5552
6106
|
// robots.txt is checked first, so a disallowed request is never sent — not
|
|
5553
6107
|
// even through a proxy. The injected and KRAS adapters sit inside it: their
|
|
5554
6108
|
// requests either bypass the network entirely or are rewritten to a URL
|
|
@@ -5596,9 +6150,13 @@ function createResearchRadarFetch({ customFetch, excavationReportSource, logger,
|
|
|
5596
6150
|
// When the application supplies excavation reports, that board is served
|
|
5597
6151
|
// from the injected source and never requested over the network. Every
|
|
5598
6152
|
// other target keeps going through the same fetch as before.
|
|
5599
|
-
|
|
6153
|
+
const withExcavationReports = excavationReportSource
|
|
5600
6154
|
? createExcavationReportFetch(withPublicJobs, excavationReportSource)
|
|
5601
6155
|
: withPublicJobs;
|
|
6156
|
+
// Journal issues have no live board to fall back to, so this adapter is
|
|
6157
|
+
// always installed: without a source the target is an empty list and its
|
|
6158
|
+
// URL is never requested.
|
|
6159
|
+
return createJournalIssueFetch(withExcavationReports, journalIssueSource);
|
|
5602
6160
|
}
|
|
5603
6161
|
|
|
5604
6162
|
/**
|
|
@@ -5615,11 +6173,12 @@ class CrawlingProvider {
|
|
|
5615
6173
|
customFetch;
|
|
5616
6174
|
/** Crawling target groups configuration */
|
|
5617
6175
|
crawlingTargetGroups;
|
|
5618
|
-
constructor(articleRepository, customFetch, excavationReportSource, logger, publicDataApiKey, bidTriage) {
|
|
6176
|
+
constructor(articleRepository, customFetch, excavationReportSource, logger, publicDataApiKey, bidTriage, journalIssueSource) {
|
|
5619
6177
|
this.articleRepository = articleRepository;
|
|
5620
6178
|
this.customFetch = createResearchRadarFetch({
|
|
5621
6179
|
customFetch,
|
|
5622
6180
|
excavationReportSource,
|
|
6181
|
+
journalIssueSource,
|
|
5623
6182
|
logger,
|
|
5624
6183
|
publicDataApiKey,
|
|
5625
6184
|
bidTriage,
|
|
@@ -5738,6 +6297,10 @@ function createNewsletterGenerator(dependencies) {
|
|
|
5738
6297
|
};
|
|
5739
6298
|
const dateService = new DateService(dependencies.publishDate);
|
|
5740
6299
|
const taskService = new TaskService(dependencies.taskRepository);
|
|
6300
|
+
// One source call serves both the crawl and the journal tables at save time.
|
|
6301
|
+
const loadJournalIssues = dependencies.journalIssueSource
|
|
6302
|
+
? createJournalIssueLoader(dependencies.journalIssueSource)
|
|
6303
|
+
: undefined;
|
|
5741
6304
|
const crawlingProvider = new CrawlingProvider(dependencies.articleRepository, dependencies.customFetch, dependencies.excavationReportSource, dependencies.logger, dependencies.publicDataApiKey,
|
|
5742
6305
|
// 나라장터 publishes about 1,500 notices per 48-hour window, so which ones
|
|
5743
6306
|
// reach per-article scoring is decided here, 100 titles per request. The
|
|
@@ -5750,7 +6313,7 @@ function createNewsletterGenerator(dependencies) {
|
|
|
5750
6313
|
data: { reason, batchSize },
|
|
5751
6314
|
});
|
|
5752
6315
|
},
|
|
5753
|
-
}));
|
|
6316
|
+
}), loadJournalIssues);
|
|
5754
6317
|
const analysisProvider = new AnalysisProvider({
|
|
5755
6318
|
classifyTags: resolveModel('classifyTags'),
|
|
5756
6319
|
analyzeImages: resolveModel('analyzeImages'),
|
|
@@ -5804,7 +6367,29 @@ function createNewsletterGenerator(dependencies) {
|
|
|
5804
6367
|
data,
|
|
5805
6368
|
});
|
|
5806
6369
|
},
|
|
5807
|
-
})
|
|
6370
|
+
}), loadJournalIssues && {
|
|
6371
|
+
load: loadJournalIssues,
|
|
6372
|
+
// Choosing papers is a relevance judgement for the readers, like
|
|
6373
|
+
// importance, so it reuses that model.
|
|
6374
|
+
select: createJournalPaperSelector({
|
|
6375
|
+
model: resolveModel('determineImportance'),
|
|
6376
|
+
audience: templateOptions?.isKrasNewsletter
|
|
6377
|
+
? '한국고고학회 회원(고고학 연구자, 발굴·조사기관 종사자, 관련 전공 학생)'
|
|
6378
|
+
: '문화유산 연구자와 실무자(고고학, 보존과학, 학예, 문화유산 행정)',
|
|
6379
|
+
onFallback: (reason, issue) => {
|
|
6380
|
+
dependencies.logger?.info({
|
|
6381
|
+
event: 'newsletter.journals.selection.fallback',
|
|
6382
|
+
data: { reason, issueUrl: issue.url },
|
|
6383
|
+
});
|
|
6384
|
+
},
|
|
6385
|
+
}),
|
|
6386
|
+
onUnavailable: (reason) => {
|
|
6387
|
+
dependencies.logger?.error({
|
|
6388
|
+
event: 'newsletter.journals.load.failed',
|
|
6389
|
+
data: { reason },
|
|
6390
|
+
});
|
|
6391
|
+
},
|
|
6392
|
+
});
|
|
5808
6393
|
return new GenerateNewsletter({
|
|
5809
6394
|
contentOptions: resolvedContentOptions,
|
|
5810
6395
|
promptProvider: dependencies.promptProvider ?? researchRadarPromptProvider,
|
|
@@ -6329,5 +6914,5 @@ async function refreshResearchRadarDeadlines(config) {
|
|
|
6329
6914
|
}
|
|
6330
6915
|
}
|
|
6331
6916
|
|
|
6332
|
-
export { AnalysisProvider, ContentGenerateProvider, CrawlingProvider, DEADLINE_REMINDER_LEAD_DAYS, DEADLINE_REMINDER_LIMIT, DateService, TaskService, contentOptions, createCrawlingTargetGroups, createDeadlineReminderSelector, extractResearchRadarDeadlines, fetchResearchRadarDeadlineSource, generateNewsletter, generateWelcomeHTML, getSourceList, llmConfig, maximumImportanceScoreByDomain, newsletterConfig, refreshResearchRadarDeadlines, renderVerifiedDeadlineReminders, researchRadarPromptProvider, robotsExemptOrigins };
|
|
6917
|
+
export { AnalysisProvider, ContentGenerateProvider, CrawlingProvider, DEADLINE_REMINDER_LEAD_DAYS, DEADLINE_REMINDER_LIMIT, DateService, JOURNAL_ISSUE_LIST_URL, TaskService, contentOptions, createCrawlingTargetGroups, createDeadlineReminderSelector, extractResearchRadarDeadlines, fetchResearchRadarDeadlineSource, generateNewsletter, generateWelcomeHTML, getSourceList, llmConfig, maximumImportanceScoreByDomain, newsletterConfig, refreshResearchRadarDeadlines, renderVerifiedDeadlineReminders, researchRadarPromptProvider, robotsExemptOrigins };
|
|
6333
6918
|
//# sourceMappingURL=index.js.map
|