@li-canghai/dsh-paper 0.8.2 → 0.8.6

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.
@@ -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
  // 相对路径按它解析会得到一个看似合理却错的答案;交给来源解析器按自己的默认处理。