@li-canghai/dsh-paper 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -93
- package/THIRD_PARTY_NOTICES.md +69 -0
- package/lib/annotate-tool.js +58 -10
- package/lib/block-cache.js +45 -26
- package/lib/blocks-reconcile.js +56 -17
- package/lib/client-parts/01-pure-helpers.js +410 -7
- package/lib/client-parts/02-author-year.js +111 -24
- package/lib/client-parts/03-pdf-stack.js +97 -0
- package/lib/client.js +1022 -112
- package/lib/code-source.js +8 -8
- package/lib/discussion.js +2 -101
- package/lib/export.js +228 -14
- package/lib/file-lock.js +128 -16
- package/lib/gloss.js +1030 -12
- package/lib/index.js +193 -68
- package/lib/inline-html.js +1 -1
- package/lib/item-ops.js +14 -2
- package/lib/library-service.js +32 -8
- package/lib/library-tool.js +6 -0
- package/lib/metadata-enrichment.js +8 -1
- package/lib/pdf-analysis-tool.js +72 -0
- package/lib/pdf-page.js +609 -13
- package/lib/picker.js +19 -5
- package/lib/reader-store.js +14 -10
- package/lib/rename-document.js +25 -3
- package/lib/search-index.js +0 -9
- package/lib/selection-message.js +2 -3
- package/lib/storage.js +122 -10
- package/lib/store-paths.js +0 -13
- package/lib/table-gfm.js +42 -14
- package/lib/tex-fetch.js +0 -1
- package/lib/tex-merge.js +0 -1
- package/lib/tex-prepare.js +74 -13
- package/lib/text-similarity.js +0 -9
- package/lib/tool-host.js +4 -1
- package/lib/translate-prompts.js +11 -1
- package/lib/translate-queue.js +1 -34
- package/lib/translate-task.js +1 -1
- package/lib/translate.js +57 -26
- package/lib/update-contracts.js +5 -5
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +7 -2
|
@@ -100,6 +100,14 @@ function canTryAnotherSource(error) {
|
|
|
100
100
|
export function metadataIdentifier(value) {
|
|
101
101
|
let input = text(value)
|
|
102
102
|
if (!input || input.length > 2048) return null
|
|
103
|
+
// 🔴 前缀要在解析 URL **之前**剥掉。
|
|
104
|
+
//
|
|
105
|
+
// `doi:10.1234/x` 是个合法的 URI —— `new URL()` 会接受它并把 `protocol` 认成 `'doi:'`、
|
|
106
|
+
// `hostname` 认成空串。于是它既不是 doi.org、也不是 aclanthology、也不是 arxiv.org,
|
|
107
|
+
// 走进最后的 `else return null` —— 后面那句剥前缀的代码**永远执行不到**。
|
|
108
|
+
// 实测:模型按提示写 `doi:10.1234/test` 或 `arxiv:2101.00001` 一律 null,
|
|
109
|
+
// 而裸写同样的值能过,用户收到的却是一句「标识无效」。
|
|
110
|
+
input = input.replace(/^doi:\s*/i, '').replace(/^arxiv:\s*/i, '').trim()
|
|
103
111
|
try {
|
|
104
112
|
const url = new URL(input)
|
|
105
113
|
if (url.username || url.password || url.port) return null
|
|
@@ -112,7 +120,6 @@ export function metadataIdentifier(value) {
|
|
|
112
120
|
input = url.pathname.replace(/^\/(?:abs|pdf)\//, '').replace(/\.pdf$/, '')
|
|
113
121
|
} else return null
|
|
114
122
|
} catch { /* Bare identifiers have no URL scheme. */ }
|
|
115
|
-
input = input.replace(/^doi:\s*/i, '').replace(/^arxiv:\s*/i, '')
|
|
116
123
|
if (DOI.test(input) && !/[<>"\\]/.test(input)) return { type: 'doi', id: input.toLowerCase() }
|
|
117
124
|
if (ARXIV.test(input)) return { type: 'arxiv', id: input }
|
|
118
125
|
return null
|
package/lib/pdf-analysis-tool.js
CHANGED
|
@@ -180,6 +180,65 @@ export function createPdfAnalysisTool(deps) {
|
|
|
180
180
|
? deps.outlineBudgetBytes
|
|
181
181
|
: FALLBACK_OUTLINE_BUDGET_BYTES
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
* 查一个已登记的解析任务。
|
|
185
|
+
*
|
|
186
|
+
* 🔴 这里刻意**不碰** `deps.tasks.getTask` 之外的任何服务:任务清单是派生 UI 状态
|
|
187
|
+
* (tasks.js 的模块注释),查不到就是查不到,不该为了补一个进度去读整个 state。
|
|
188
|
+
* 进度由宿主侧 `summarizeTask(task, jobs)` 现算 —— 那份实现与 summarizeProgress 同口径。
|
|
189
|
+
*
|
|
190
|
+
* @param {string} taskId 回执里给出的持久任务编号
|
|
191
|
+
* @param {object} [exec] 宿主执行的上下文(当前没有用到的字段,保留是为了与其它分支同形)
|
|
192
|
+
* @returns {Promise<object>} 与 generate() 同形的回执
|
|
193
|
+
*/
|
|
194
|
+
async function describeTask(taskId, exec) {
|
|
195
|
+
const lookup = deps?.tasks?.getTask
|
|
196
|
+
if (typeof lookup !== 'function') {
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
mode: 'result',
|
|
200
|
+
notice: '这个宿主没有任务清单,无法按任务编号查询。',
|
|
201
|
+
papers: [],
|
|
202
|
+
failures: ['任务清单不可用'],
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let task
|
|
206
|
+
try {
|
|
207
|
+
task = await lookup.call(deps.tasks, taskId)
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return { ok: false, mode: 'result', notice: '查任务时出错:' + messageOf(error), papers: [], failures: [messageOf(error)] }
|
|
210
|
+
}
|
|
211
|
+
if (task === undefined || task === null) {
|
|
212
|
+
return {
|
|
213
|
+
ok: false,
|
|
214
|
+
mode: 'result',
|
|
215
|
+
notice: '没有任务 ' + taskId + ':它可能已被永久删除,或来自另一台机器。',
|
|
216
|
+
papers: [],
|
|
217
|
+
failures: ['任务不存在'],
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// summarizeTask 需要 jobs,而这一层拿不到宿主 state。工具的职责到「把登记项交回去」为止,
|
|
221
|
+
// 逐篇进度由调用方(或 /task 路由)补齐 —— 编一份假进度比不报更糟。
|
|
222
|
+
const items = Array.isArray(task.items) ? task.items : []
|
|
223
|
+
// OUTPUT_SCHEMA 的 papers 元素要求 pdfName / pdfPath / sourceType / status 四个字段
|
|
224
|
+
// 全在。任务登记项里没有 sourceType,这里按「已入库的解析任务」据实填 library ——
|
|
225
|
+
// 独立解析(library:false)不产生 documentId,也就不会进任务清单。
|
|
226
|
+
const papers = items.map(item => ({
|
|
227
|
+
pdfName: readText(item?.label),
|
|
228
|
+
pdfPath: readText(item?.pdfPath),
|
|
229
|
+
sourceType: 'library',
|
|
230
|
+
status: 'queued',
|
|
231
|
+
}))
|
|
232
|
+
const label = readText(task.label) === '' ? '(未命名)' : readText(task.label)
|
|
233
|
+
return {
|
|
234
|
+
ok: true,
|
|
235
|
+
mode: 'result',
|
|
236
|
+
notice: '任务 ' + taskId + '(' + label + ')登记了 ' + items.length + ' 篇。逐篇进度用宿主 GET /task?id=' + taskId + ' 查。',
|
|
237
|
+
taskId,
|
|
238
|
+
papers,
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
183
242
|
function warn(message) {
|
|
184
243
|
try {
|
|
185
244
|
deps?.logger?.warn?.(message)
|
|
@@ -553,6 +612,9 @@ export function createPdfAnalysisTool(deps) {
|
|
|
553
612
|
parameters: {
|
|
554
613
|
type: 'object',
|
|
555
614
|
properties: {
|
|
615
|
+
// required 仍是 ['source']:那个数组本身是被测试钉住的契约(见 pdf-analysis-tool.test.js)。
|
|
616
|
+
// 只查任务时传 taskId 即可、source 留空——execute 在读 source 之前就分叉,
|
|
617
|
+
// 而 JSON Schema 的 required 是给模型的提示,宿主不会因此拒绝缺字段的调用。
|
|
556
618
|
source: { type: 'string', description: SOURCE_DESCRIPTION },
|
|
557
619
|
library: {
|
|
558
620
|
type: 'boolean',
|
|
@@ -563,6 +625,10 @@ export function createPdfAnalysisTool(deps) {
|
|
|
563
625
|
description: '可选:最多等多久拿结果(毫秒,0–120000,默认 0 表示不等)。等到就返回可用结果,等不到返回 jobId。',
|
|
564
626
|
},
|
|
565
627
|
title: { type: 'string', description: '可选:给这批论文一个易读的名字。' },
|
|
628
|
+
taskId: {
|
|
629
|
+
type: 'string',
|
|
630
|
+
description: '可选:查一个已提交解析任务的进度。传它时不需要 source——回执里的任务编号是持久编号,宿主重启后仍可查;jobId 只活当前宿主周期。',
|
|
631
|
+
},
|
|
566
632
|
},
|
|
567
633
|
required: ['source'],
|
|
568
634
|
},
|
|
@@ -574,6 +640,12 @@ export function createPdfAnalysisTool(deps) {
|
|
|
574
640
|
timeoutMs: TOOL_TIMEOUT_MS,
|
|
575
641
|
|
|
576
642
|
async execute(args, exec) {
|
|
643
|
+
// 只传 taskId = 查一个已提交任务的进度。这条分支在读 source 之前就分叉:
|
|
644
|
+
// 回执里的编号是给「稍后再看」用的,调用方手里没有、也不需要来源。
|
|
645
|
+
const requestedTaskId = readText(args?.taskId).trim()
|
|
646
|
+
if (requestedTaskId !== '' && readText(args?.source).trim() === '') {
|
|
647
|
+
return await describeTask(requestedTaskId, exec)
|
|
648
|
+
}
|
|
577
649
|
const sessionId = exec?.agent?.session?.id
|
|
578
650
|
// 没有会话就没有 cwd。这里不退回 process.cwd():那是宿主的目录,不是用户的项目目录,
|
|
579
651
|
// 相对路径按它解析会得到一个看似合理却错的答案;交给来源解析器按自己的默认处理。
|