helixlife-expert-cli 0.1.0
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 +159 -0
- package/cli/bin/helixlife-expert.js +3 -0
- package/cli/dist/core/api/client.d.ts +31 -0
- package/cli/dist/core/api/client.d.ts.map +1 -0
- package/cli/dist/core/api/client.js +183 -0
- package/cli/dist/core/api/client.js.map +1 -0
- package/cli/dist/core/api/http.d.ts +3 -0
- package/cli/dist/core/api/http.d.ts.map +1 -0
- package/cli/dist/core/api/http.js +22 -0
- package/cli/dist/core/api/http.js.map +1 -0
- package/cli/dist/core/api/response.d.ts +48 -0
- package/cli/dist/core/api/response.d.ts.map +1 -0
- package/cli/dist/core/api/response.js +84 -0
- package/cli/dist/core/api/response.js.map +1 -0
- package/cli/dist/core/api/sse.d.ts +6 -0
- package/cli/dist/core/api/sse.d.ts.map +1 -0
- package/cli/dist/core/api/sse.js +60 -0
- package/cli/dist/core/api/sse.js.map +1 -0
- package/cli/dist/core/auth/index.d.ts +35 -0
- package/cli/dist/core/auth/index.d.ts.map +1 -0
- package/cli/dist/core/auth/index.js +150 -0
- package/cli/dist/core/auth/index.js.map +1 -0
- package/cli/dist/core/env-config.d.ts +16 -0
- package/cli/dist/core/env-config.d.ts.map +1 -0
- package/cli/dist/core/env-config.js +80 -0
- package/cli/dist/core/env-config.js.map +1 -0
- package/cli/dist/core/errors.d.ts +20 -0
- package/cli/dist/core/errors.d.ts.map +1 -0
- package/cli/dist/core/errors.js +28 -0
- package/cli/dist/core/errors.js.map +1 -0
- package/cli/dist/core/index.d.ts +16 -0
- package/cli/dist/core/index.d.ts.map +1 -0
- package/cli/dist/core/index.js +16 -0
- package/cli/dist/core/index.js.map +1 -0
- package/cli/dist/core/interactive.d.ts +18 -0
- package/cli/dist/core/interactive.d.ts.map +1 -0
- package/cli/dist/core/interactive.js +74 -0
- package/cli/dist/core/interactive.js.map +1 -0
- package/cli/dist/core/output/index.d.ts +29 -0
- package/cli/dist/core/output/index.d.ts.map +1 -0
- package/cli/dist/core/output/index.js +153 -0
- package/cli/dist/core/output/index.js.map +1 -0
- package/cli/dist/core/parse.d.ts +9 -0
- package/cli/dist/core/parse.d.ts.map +1 -0
- package/cli/dist/core/parse.js +31 -0
- package/cli/dist/core/parse.js.map +1 -0
- package/cli/dist/core/paths.d.ts +21 -0
- package/cli/dist/core/paths.d.ts.map +1 -0
- package/cli/dist/core/paths.js +65 -0
- package/cli/dist/core/paths.js.map +1 -0
- package/cli/dist/core/sse-utils.d.ts +49 -0
- package/cli/dist/core/sse-utils.d.ts.map +1 -0
- package/cli/dist/core/sse-utils.js +181 -0
- package/cli/dist/core/sse-utils.js.map +1 -0
- package/cli/dist/core/terminal.d.ts +2 -0
- package/cli/dist/core/terminal.d.ts.map +1 -0
- package/cli/dist/core/terminal.js +6 -0
- package/cli/dist/core/terminal.js.map +1 -0
- package/cli/dist/core/token/index.d.ts +5 -0
- package/cli/dist/core/token/index.d.ts.map +1 -0
- package/cli/dist/core/token/index.js +26 -0
- package/cli/dist/core/token/index.js.map +1 -0
- package/cli/dist/core/types/config.d.ts +8 -0
- package/cli/dist/core/types/config.d.ts.map +1 -0
- package/cli/dist/core/types/config.js +30 -0
- package/cli/dist/core/types/config.js.map +1 -0
- package/cli/dist/core/version.d.ts +2 -0
- package/cli/dist/core/version.d.ts.map +1 -0
- package/cli/dist/core/version.js +10 -0
- package/cli/dist/core/version.js.map +1 -0
- package/cli/dist/index.d.ts +2 -0
- package/cli/dist/index.d.ts.map +1 -0
- package/cli/dist/index.js +23 -0
- package/cli/dist/index.js.map +1 -0
- package/cli/dist/modules/analysis/constants.d.ts +3 -0
- package/cli/dist/modules/analysis/constants.d.ts.map +1 -0
- package/cli/dist/modules/analysis/constants.js +3 -0
- package/cli/dist/modules/analysis/constants.js.map +1 -0
- package/cli/dist/modules/analysis/index.d.ts +3 -0
- package/cli/dist/modules/analysis/index.d.ts.map +1 -0
- package/cli/dist/modules/analysis/index.js +23 -0
- package/cli/dist/modules/analysis/index.js.map +1 -0
- package/cli/dist/modules/auth/index.d.ts +3 -0
- package/cli/dist/modules/auth/index.d.ts.map +1 -0
- package/cli/dist/modules/auth/index.js +76 -0
- package/cli/dist/modules/auth/index.js.map +1 -0
- package/cli/dist/modules/expert-scaffold.d.ts +27 -0
- package/cli/dist/modules/expert-scaffold.d.ts.map +1 -0
- package/cli/dist/modules/expert-scaffold.js +25 -0
- package/cli/dist/modules/expert-scaffold.js.map +1 -0
- package/cli/dist/modules/fund/clinical/apps.d.ts +19 -0
- package/cli/dist/modules/fund/clinical/apps.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/apps.js +14 -0
- package/cli/dist/modules/fund/clinical/apps.js.map +1 -0
- package/cli/dist/modules/fund/clinical/command-utils.d.ts +4 -0
- package/cli/dist/modules/fund/clinical/command-utils.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/command-utils.js +40 -0
- package/cli/dist/modules/fund/clinical/command-utils.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/article-create.d.ts +9 -0
- package/cli/dist/modules/fund/clinical/commands/article-create.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/article-create.js +99 -0
- package/cli/dist/modules/fund/clinical/commands/article-create.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/article-download.d.ts +30 -0
- package/cli/dist/modules/fund/clinical/commands/article-download.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/article-download.js +153 -0
- package/cli/dist/modules/fund/clinical/commands/article-download.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-create.d.ts +7 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-create.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-create.js +81 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-create.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-precheck.d.ts +7 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-precheck.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-precheck.js +76 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-precheck.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-update.d.ts +16 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-update.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-update.js +108 -0
- package/cli/dist/modules/fund/clinical/commands/four-elements-update.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/sample-size.d.ts +14 -0
- package/cli/dist/modules/fund/clinical/commands/sample-size.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/sample-size.js +164 -0
- package/cli/dist/modules/fund/clinical/commands/sample-size.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-create.d.ts +25 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-create.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-create.js +228 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-create.js.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-parameters.d.ts +45 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-parameters.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-parameters.js +211 -0
- package/cli/dist/modules/fund/clinical/commands/topic-evaluation-parameters.js.map +1 -0
- package/cli/dist/modules/fund/clinical/constants.d.ts +85 -0
- package/cli/dist/modules/fund/clinical/constants.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/constants.js +161 -0
- package/cli/dist/modules/fund/clinical/constants.js.map +1 -0
- package/cli/dist/modules/fund/clinical/form-rules.d.ts +56 -0
- package/cli/dist/modules/fund/clinical/form-rules.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/form-rules.js +542 -0
- package/cli/dist/modules/fund/clinical/form-rules.js.map +1 -0
- package/cli/dist/modules/fund/clinical/four-elements.d.ts +46 -0
- package/cli/dist/modules/fund/clinical/four-elements.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/four-elements.js +190 -0
- package/cli/dist/modules/fund/clinical/four-elements.js.map +1 -0
- package/cli/dist/modules/fund/clinical/index.d.ts +3 -0
- package/cli/dist/modules/fund/clinical/index.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/index.js +176 -0
- package/cli/dist/modules/fund/clinical/index.js.map +1 -0
- package/cli/dist/modules/fund/clinical/parameters.d.ts +51 -0
- package/cli/dist/modules/fund/clinical/parameters.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/parameters.js +145 -0
- package/cli/dist/modules/fund/clinical/parameters.js.map +1 -0
- package/cli/dist/modules/fund/clinical/sample-size.d.ts +130 -0
- package/cli/dist/modules/fund/clinical/sample-size.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/sample-size.js +356 -0
- package/cli/dist/modules/fund/clinical/sample-size.js.map +1 -0
- package/cli/dist/modules/fund/clinical/session-cache.d.ts +25 -0
- package/cli/dist/modules/fund/clinical/session-cache.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/session-cache.js +100 -0
- package/cli/dist/modules/fund/clinical/session-cache.js.map +1 -0
- package/cli/dist/modules/fund/clinical/sse-utils.d.ts +22 -0
- package/cli/dist/modules/fund/clinical/sse-utils.d.ts.map +1 -0
- package/cli/dist/modules/fund/clinical/sse-utils.js +80 -0
- package/cli/dist/modules/fund/clinical/sse-utils.js.map +1 -0
- package/cli/dist/modules/fund/constants.d.ts +3 -0
- package/cli/dist/modules/fund/constants.d.ts.map +1 -0
- package/cli/dist/modules/fund/constants.js +3 -0
- package/cli/dist/modules/fund/constants.js.map +1 -0
- package/cli/dist/modules/fund/index.d.ts +3 -0
- package/cli/dist/modules/fund/index.d.ts.map +1 -0
- package/cli/dist/modules/fund/index.js +28 -0
- package/cli/dist/modules/fund/index.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/apps.d.ts +54 -0
- package/cli/dist/modules/fund/nsfc/apps.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/apps.js +76 -0
- package/cli/dist/modules/fund/nsfc/apps.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/article-cache.d.ts +14 -0
- package/cli/dist/modules/fund/nsfc/article-cache.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/article-cache.js +79 -0
- package/cli/dist/modules/fund/nsfc/article-cache.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/article-create.d.ts +8 -0
- package/cli/dist/modules/fund/nsfc/commands/article-create.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/article-create.js +108 -0
- package/cli/dist/modules/fund/nsfc/commands/article-create.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/article-download.d.ts +42 -0
- package/cli/dist/modules/fund/nsfc/commands/article-download.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/article-download.js +189 -0
- package/cli/dist/modules/fund/nsfc/commands/article-download.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/format-convert.d.ts +9 -0
- package/cli/dist/modules/fund/nsfc/commands/format-convert.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/format-convert.js +98 -0
- package/cli/dist/modules/fund/nsfc/commands/format-convert.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-analyze.d.ts +12 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-analyze.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-analyze.js +351 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-analyze.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-create.d.ts +21 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-create.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-create.js +197 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-create.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-figure.d.ts +9 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-figure.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-figure.js +120 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-figure.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-genes-select.d.ts +11 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-genes-select.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-genes-select.js +125 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-genes-select.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-pick.d.ts +11 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-pick.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-pick.js +109 -0
- package/cli/dist/modules/fund/nsfc/commands/hypothesis-pick.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-confirm.d.ts +9 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-confirm.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-confirm.js +64 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-confirm.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-create.d.ts +8 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-create.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-create.js +103 -0
- package/cli/dist/modules/fund/nsfc/commands/outline-create.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/research-path-confirm.d.ts +9 -0
- package/cli/dist/modules/fund/nsfc/commands/research-path-confirm.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/research-path-confirm.js +176 -0
- package/cli/dist/modules/fund/nsfc/commands/research-path-confirm.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/tech-roadmap.d.ts +9 -0
- package/cli/dist/modules/fund/nsfc/commands/tech-roadmap.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/commands/tech-roadmap.js +190 -0
- package/cli/dist/modules/fund/nsfc/commands/tech-roadmap.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/constants.d.ts +96 -0
- package/cli/dist/modules/fund/nsfc/constants.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/constants.js +156 -0
- package/cli/dist/modules/fund/nsfc/constants.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/graph-render.d.ts +25 -0
- package/cli/dist/modules/fund/nsfc/graph-render.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/graph-render.js +212 -0
- package/cli/dist/modules/fund/nsfc/graph-render.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/index.d.ts +4 -0
- package/cli/dist/modules/fund/nsfc/index.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/index.js +238 -0
- package/cli/dist/modules/fund/nsfc/index.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/mermaid-render.d.ts +18 -0
- package/cli/dist/modules/fund/nsfc/mermaid-render.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/mermaid-render.js +47 -0
- package/cli/dist/modules/fund/nsfc/mermaid-render.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/parse-hypothesis.d.ts +76 -0
- package/cli/dist/modules/fund/nsfc/parse-hypothesis.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/parse-hypothesis.js +278 -0
- package/cli/dist/modules/fund/nsfc/parse-hypothesis.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/parse-outline.d.ts +23 -0
- package/cli/dist/modules/fund/nsfc/parse-outline.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/parse-outline.js +91 -0
- package/cli/dist/modules/fund/nsfc/parse-outline.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/png-watermark.d.ts +24 -0
- package/cli/dist/modules/fund/nsfc/png-watermark.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/png-watermark.js +78 -0
- package/cli/dist/modules/fund/nsfc/png-watermark.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/prompt-hypothesis.d.ts +20 -0
- package/cli/dist/modules/fund/nsfc/prompt-hypothesis.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/prompt-hypothesis.js +107 -0
- package/cli/dist/modules/fund/nsfc/prompt-hypothesis.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/prompt-step2.d.ts +18 -0
- package/cli/dist/modules/fund/nsfc/prompt-step2.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/prompt-step2.js +107 -0
- package/cli/dist/modules/fund/nsfc/prompt-step2.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/request-body.d.ts +47 -0
- package/cli/dist/modules/fund/nsfc/request-body.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/request-body.js +38 -0
- package/cli/dist/modules/fund/nsfc/request-body.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/session-cache.d.ts +48 -0
- package/cli/dist/modules/fund/nsfc/session-cache.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/session-cache.js +90 -0
- package/cli/dist/modules/fund/nsfc/session-cache.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/sse-utils.d.ts +22 -0
- package/cli/dist/modules/fund/nsfc/sse-utils.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/sse-utils.js +81 -0
- package/cli/dist/modules/fund/nsfc/sse-utils.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/upload.d.ts +3 -0
- package/cli/dist/modules/fund/nsfc/upload.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/upload.js +59 -0
- package/cli/dist/modules/fund/nsfc/upload.js.map +1 -0
- package/cli/dist/modules/fund/nsfc/validate.d.ts +30 -0
- package/cli/dist/modules/fund/nsfc/validate.d.ts.map +1 -0
- package/cli/dist/modules/fund/nsfc/validate.js +91 -0
- package/cli/dist/modules/fund/nsfc/validate.js.map +1 -0
- package/cli/dist/modules/literature/commands/workflow-list.d.ts +5 -0
- package/cli/dist/modules/literature/commands/workflow-list.d.ts.map +1 -0
- package/cli/dist/modules/literature/commands/workflow-list.js +9 -0
- package/cli/dist/modules/literature/commands/workflow-list.js.map +1 -0
- package/cli/dist/modules/literature/commands/workflow-params.d.ts +6 -0
- package/cli/dist/modules/literature/commands/workflow-params.d.ts.map +1 -0
- package/cli/dist/modules/literature/commands/workflow-params.js +9 -0
- package/cli/dist/modules/literature/commands/workflow-params.js.map +1 -0
- package/cli/dist/modules/literature/commands/workflow-run.d.ts +7 -0
- package/cli/dist/modules/literature/commands/workflow-run.d.ts.map +1 -0
- package/cli/dist/modules/literature/commands/workflow-run.js +10 -0
- package/cli/dist/modules/literature/commands/workflow-run.js.map +1 -0
- package/cli/dist/modules/literature/constants.d.ts +20 -0
- package/cli/dist/modules/literature/constants.d.ts.map +1 -0
- package/cli/dist/modules/literature/constants.js +56 -0
- package/cli/dist/modules/literature/constants.js.map +1 -0
- package/cli/dist/modules/literature/index.d.ts +3 -0
- package/cli/dist/modules/literature/index.d.ts.map +1 -0
- package/cli/dist/modules/literature/index.js +63 -0
- package/cli/dist/modules/literature/index.js.map +1 -0
- package/cli/dist/modules/meta/analysis.d.ts +127 -0
- package/cli/dist/modules/meta/analysis.d.ts.map +1 -0
- package/cli/dist/modules/meta/analysis.js +1165 -0
- package/cli/dist/modules/meta/analysis.js.map +1 -0
- package/cli/dist/modules/meta/api.d.ts +11 -0
- package/cli/dist/modules/meta/api.d.ts.map +1 -0
- package/cli/dist/modules/meta/api.js +40 -0
- package/cli/dist/modules/meta/api.js.map +1 -0
- package/cli/dist/modules/meta/commands.d.ts +3 -0
- package/cli/dist/modules/meta/commands.d.ts.map +1 -0
- package/cli/dist/modules/meta/commands.js +1185 -0
- package/cli/dist/modules/meta/commands.js.map +1 -0
- package/cli/dist/modules/meta/constants.d.ts +8 -0
- package/cli/dist/modules/meta/constants.d.ts.map +1 -0
- package/cli/dist/modules/meta/constants.js +9 -0
- package/cli/dist/modules/meta/constants.js.map +1 -0
- package/cli/dist/modules/meta/extraction.d.ts +206 -0
- package/cli/dist/modules/meta/extraction.d.ts.map +1 -0
- package/cli/dist/modules/meta/extraction.js +1248 -0
- package/cli/dist/modules/meta/extraction.js.map +1 -0
- package/cli/dist/modules/meta/index.d.ts +3 -0
- package/cli/dist/modules/meta/index.d.ts.map +1 -0
- package/cli/dist/modules/meta/index.js +19 -0
- package/cli/dist/modules/meta/index.js.map +1 -0
- package/cli/dist/modules/meta/node.d.ts +70 -0
- package/cli/dist/modules/meta/node.d.ts.map +1 -0
- package/cli/dist/modules/meta/node.js +167 -0
- package/cli/dist/modules/meta/node.js.map +1 -0
- package/cli/dist/modules/meta/plot-params.d.ts +82 -0
- package/cli/dist/modules/meta/plot-params.d.ts.map +1 -0
- package/cli/dist/modules/meta/plot-params.js +1179 -0
- package/cli/dist/modules/meta/plot-params.js.map +1 -0
- package/cli/dist/modules/meta/prisma-flow-docx.d.ts +23 -0
- package/cli/dist/modules/meta/prisma-flow-docx.d.ts.map +1 -0
- package/cli/dist/modules/meta/prisma-flow-docx.js +302 -0
- package/cli/dist/modules/meta/prisma-flow-docx.js.map +1 -0
- package/cli/dist/modules/meta/retrieve.d.ts +113 -0
- package/cli/dist/modules/meta/retrieve.d.ts.map +1 -0
- package/cli/dist/modules/meta/retrieve.js +913 -0
- package/cli/dist/modules/meta/retrieve.js.map +1 -0
- package/cli/dist/modules/meta/screening.d.ts +179 -0
- package/cli/dist/modules/meta/screening.d.ts.map +1 -0
- package/cli/dist/modules/meta/screening.js +1255 -0
- package/cli/dist/modules/meta/screening.js.map +1 -0
- package/cli/dist/modules/meta/topic.d.ts +110 -0
- package/cli/dist/modules/meta/topic.d.ts.map +1 -0
- package/cli/dist/modules/meta/topic.js +865 -0
- package/cli/dist/modules/meta/topic.js.map +1 -0
- package/cli/dist/modules/meta/types.d.ts +49 -0
- package/cli/dist/modules/meta/types.d.ts.map +1 -0
- package/cli/dist/modules/meta/types.js +2 -0
- package/cli/dist/modules/meta/types.js.map +1 -0
- package/cli/dist/modules/meta/workflow.d.ts +154 -0
- package/cli/dist/modules/meta/workflow.d.ts.map +1 -0
- package/cli/dist/modules/meta/workflow.js +956 -0
- package/cli/dist/modules/meta/workflow.js.map +1 -0
- package/cli/dist/modules/meta/writing.d.ts +83 -0
- package/cli/dist/modules/meta/writing.d.ts.map +1 -0
- package/cli/dist/modules/meta/writing.js +1077 -0
- package/cli/dist/modules/meta/writing.js.map +1 -0
- package/cli/dist/modules/proposal/artifacts.d.ts +18 -0
- package/cli/dist/modules/proposal/artifacts.d.ts.map +1 -0
- package/cli/dist/modules/proposal/artifacts.js +43 -0
- package/cli/dist/modules/proposal/artifacts.js.map +1 -0
- package/cli/dist/modules/proposal/commands/basic-create.d.ts +22 -0
- package/cli/dist/modules/proposal/commands/basic-create.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/basic-create.js +81 -0
- package/cli/dist/modules/proposal/commands/basic-create.js.map +1 -0
- package/cli/dist/modules/proposal/commands/basic-result.d.ts +24 -0
- package/cli/dist/modules/proposal/commands/basic-result.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/basic-result.js +96 -0
- package/cli/dist/modules/proposal/commands/basic-result.js.map +1 -0
- package/cli/dist/modules/proposal/commands/bioinfo-params.d.ts +5 -0
- package/cli/dist/modules/proposal/commands/bioinfo-params.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/bioinfo-params.js +9 -0
- package/cli/dist/modules/proposal/commands/bioinfo-params.js.map +1 -0
- package/cli/dist/modules/proposal/commands/bioinfo-run.d.ts +6 -0
- package/cli/dist/modules/proposal/commands/bioinfo-run.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/bioinfo-run.js +10 -0
- package/cli/dist/modules/proposal/commands/bioinfo-run.js.map +1 -0
- package/cli/dist/modules/proposal/commands/clinical-list.d.ts +5 -0
- package/cli/dist/modules/proposal/commands/clinical-list.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/clinical-list.js +9 -0
- package/cli/dist/modules/proposal/commands/clinical-list.js.map +1 -0
- package/cli/dist/modules/proposal/commands/clinical-params.d.ts +6 -0
- package/cli/dist/modules/proposal/commands/clinical-params.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/clinical-params.js +9 -0
- package/cli/dist/modules/proposal/commands/clinical-params.js.map +1 -0
- package/cli/dist/modules/proposal/commands/clinical-run.d.ts +7 -0
- package/cli/dist/modules/proposal/commands/clinical-run.d.ts.map +1 -0
- package/cli/dist/modules/proposal/commands/clinical-run.js +10 -0
- package/cli/dist/modules/proposal/commands/clinical-run.js.map +1 -0
- package/cli/dist/modules/proposal/constants.d.ts +34 -0
- package/cli/dist/modules/proposal/constants.d.ts.map +1 -0
- package/cli/dist/modules/proposal/constants.js +75 -0
- package/cli/dist/modules/proposal/constants.js.map +1 -0
- package/cli/dist/modules/proposal/index.d.ts +3 -0
- package/cli/dist/modules/proposal/index.d.ts.map +1 -0
- package/cli/dist/modules/proposal/index.js +95 -0
- package/cli/dist/modules/proposal/index.js.map +1 -0
- package/cli/dist/modules/proposal/newidea-env.d.ts +28 -0
- package/cli/dist/modules/proposal/newidea-env.d.ts.map +1 -0
- package/cli/dist/modules/proposal/newidea-env.js +69 -0
- package/cli/dist/modules/proposal/newidea-env.js.map +1 -0
- package/cli/dist/modules/proposal/newidea-runner.d.ts +25 -0
- package/cli/dist/modules/proposal/newidea-runner.d.ts.map +1 -0
- package/cli/dist/modules/proposal/newidea-runner.js +158 -0
- package/cli/dist/modules/proposal/newidea-runner.js.map +1 -0
- package/cli/dist/modules/proposal/parse.d.ts +25 -0
- package/cli/dist/modules/proposal/parse.d.ts.map +1 -0
- package/cli/dist/modules/proposal/parse.js +173 -0
- package/cli/dist/modules/proposal/parse.js.map +1 -0
- package/cli/dist/modules/sci/apps.d.ts +48 -0
- package/cli/dist/modules/sci/apps.d.ts.map +1 -0
- package/cli/dist/modules/sci/apps.js +43 -0
- package/cli/dist/modules/sci/apps.js.map +1 -0
- package/cli/dist/modules/sci/article-cache.d.ts +32 -0
- package/cli/dist/modules/sci/article-cache.d.ts.map +1 -0
- package/cli/dist/modules/sci/article-cache.js +163 -0
- package/cli/dist/modules/sci/article-cache.js.map +1 -0
- package/cli/dist/modules/sci/article-validate.d.ts +11 -0
- package/cli/dist/modules/sci/article-validate.d.ts.map +1 -0
- package/cli/dist/modules/sci/article-validate.js +43 -0
- package/cli/dist/modules/sci/article-validate.js.map +1 -0
- package/cli/dist/modules/sci/commands/article-create.d.ts +46 -0
- package/cli/dist/modules/sci/commands/article-create.d.ts.map +1 -0
- package/cli/dist/modules/sci/commands/article-create.js +315 -0
- package/cli/dist/modules/sci/commands/article-create.js.map +1 -0
- package/cli/dist/modules/sci/commands/article-download.d.ts +50 -0
- package/cli/dist/modules/sci/commands/article-download.d.ts.map +1 -0
- package/cli/dist/modules/sci/commands/article-download.js +281 -0
- package/cli/dist/modules/sci/commands/article-download.js.map +1 -0
- package/cli/dist/modules/sci/commands/outline.d.ts +36 -0
- package/cli/dist/modules/sci/commands/outline.d.ts.map +1 -0
- package/cli/dist/modules/sci/commands/outline.js +491 -0
- package/cli/dist/modules/sci/commands/outline.js.map +1 -0
- package/cli/dist/modules/sci/commands/template.d.ts +9 -0
- package/cli/dist/modules/sci/commands/template.d.ts.map +1 -0
- package/cli/dist/modules/sci/commands/template.js +12 -0
- package/cli/dist/modules/sci/commands/template.js.map +1 -0
- package/cli/dist/modules/sci/commands.d.ts +3 -0
- package/cli/dist/modules/sci/commands.d.ts.map +1 -0
- package/cli/dist/modules/sci/commands.js +108 -0
- package/cli/dist/modules/sci/commands.js.map +1 -0
- package/cli/dist/modules/sci/constants.d.ts +117 -0
- package/cli/dist/modules/sci/constants.d.ts.map +1 -0
- package/cli/dist/modules/sci/constants.js +152 -0
- package/cli/dist/modules/sci/constants.js.map +1 -0
- package/cli/dist/modules/sci/content-source.d.ts +18 -0
- package/cli/dist/modules/sci/content-source.d.ts.map +1 -0
- package/cli/dist/modules/sci/content-source.js +54 -0
- package/cli/dist/modules/sci/content-source.js.map +1 -0
- package/cli/dist/modules/sci/index.d.ts +3 -0
- package/cli/dist/modules/sci/index.d.ts.map +1 -0
- package/cli/dist/modules/sci/index.js +19 -0
- package/cli/dist/modules/sci/index.js.map +1 -0
- package/cli/dist/modules/sci/outline-transform.d.ts +16 -0
- package/cli/dist/modules/sci/outline-transform.d.ts.map +1 -0
- package/cli/dist/modules/sci/outline-transform.js +67 -0
- package/cli/dist/modules/sci/outline-transform.js.map +1 -0
- package/cli/dist/modules/sci/precheck-cache.d.ts +23 -0
- package/cli/dist/modules/sci/precheck-cache.d.ts.map +1 -0
- package/cli/dist/modules/sci/precheck-cache.js +141 -0
- package/cli/dist/modules/sci/precheck-cache.js.map +1 -0
- package/cli/dist/modules/sci/prompt-article.d.ts +12 -0
- package/cli/dist/modules/sci/prompt-article.d.ts.map +1 -0
- package/cli/dist/modules/sci/prompt-article.js +37 -0
- package/cli/dist/modules/sci/prompt-article.js.map +1 -0
- package/cli/dist/modules/sci/prompt-precheck.d.ts +16 -0
- package/cli/dist/modules/sci/prompt-precheck.d.ts.map +1 -0
- package/cli/dist/modules/sci/prompt-precheck.js +61 -0
- package/cli/dist/modules/sci/prompt-precheck.js.map +1 -0
- package/cli/dist/modules/sci/sse-utils.d.ts +50 -0
- package/cli/dist/modules/sci/sse-utils.d.ts.map +1 -0
- package/cli/dist/modules/sci/sse-utils.js +207 -0
- package/cli/dist/modules/sci/sse-utils.js.map +1 -0
- package/cli/dist/modules/shared/result-wrapper.d.ts +71 -0
- package/cli/dist/modules/shared/result-wrapper.d.ts.map +1 -0
- package/cli/dist/modules/shared/result-wrapper.js +95 -0
- package/cli/dist/modules/shared/result-wrapper.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/api.d.ts +6 -0
- package/cli/dist/modules/shared/workflow-app/api.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/api.js +31 -0
- package/cli/dist/modules/shared/workflow-app/api.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/command.d.ts +30 -0
- package/cli/dist/modules/shared/workflow-app/command.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/command.js +183 -0
- package/cli/dist/modules/shared/workflow-app/command.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/constants.d.ts +12 -0
- package/cli/dist/modules/shared/workflow-app/constants.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/constants.js +21 -0
- package/cli/dist/modules/shared/workflow-app/constants.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/form.d.ts +21 -0
- package/cli/dist/modules/shared/workflow-app/form.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/form.js +123 -0
- package/cli/dist/modules/shared/workflow-app/form.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/index.d.ts +8 -0
- package/cli/dist/modules/shared/workflow-app/index.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/index.js +7 -0
- package/cli/dist/modules/shared/workflow-app/index.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/run.d.ts +15 -0
- package/cli/dist/modules/shared/workflow-app/run.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/run.js +71 -0
- package/cli/dist/modules/shared/workflow-app/run.js.map +1 -0
- package/cli/dist/modules/shared/workflow-app/types.d.ts +74 -0
- package/cli/dist/modules/shared/workflow-app/types.d.ts.map +1 -0
- package/cli/dist/modules/shared/workflow-app/types.js +3 -0
- package/cli/dist/modules/shared/workflow-app/types.js.map +1 -0
- package/cli/dist/modules/site-configs.d.ts +4 -0
- package/cli/dist/modules/site-configs.d.ts.map +1 -0
- package/cli/dist/modules/site-configs.js +21 -0
- package/cli/dist/modules/site-configs.js.map +1 -0
- package/cli/dist/modules/upgrade/index.d.ts +6 -0
- package/cli/dist/modules/upgrade/index.d.ts.map +1 -0
- package/cli/dist/modules/upgrade/index.js +105 -0
- package/cli/dist/modules/upgrade/index.js.map +1 -0
- package/cli/dist/program.d.ts +3 -0
- package/cli/dist/program.d.ts.map +1 -0
- package/cli/dist/program.js +69 -0
- package/cli/dist/program.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { helixlifeError, helixlifeErrorCode, isInteractiveTerminal, printOutput, createFormatLogger, ApiClient, extractSseText, assertWorkflowSucceeded, } from "../../../core/index.js";
|
|
2
|
+
import { resolveMarkdownContent, resolveTextOrFile, } from "../content-source.js";
|
|
3
|
+
import { getSciArticleAppIds, getSciTemplateLabel, parseSciTemplateType, SCI_ARTICLE_WAIT_HINT, SCI_EXECUTE_API_PATH, } from "../constants.js";
|
|
4
|
+
import { resolveSciArticleSelection, } from "../prompt-article.js";
|
|
5
|
+
import { extractReferences, formatElapsedHint, pickWebsiteWorkflowOutputText, } from "../sse-utils.js";
|
|
6
|
+
import { buildSciExecuteBody } from "../apps.js";
|
|
7
|
+
import { clearSciArticleCache, saveSciArticleCache, } from "../article-cache.js";
|
|
8
|
+
import { assertSciArticleComplete, isCompleteSciArticleMarkdown, } from "../article-validate.js";
|
|
9
|
+
import { wrapWorkbenchResult } from "../../shared/result-wrapper.js";
|
|
10
|
+
import { appendFileSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
/**
|
|
14
|
+
* 诊断用:设置 HELIX_SCI_DEBUG=1 时把全文 SSE 的事件类型计数与
|
|
15
|
+
* workflow_finished 全量 payload 落盘,用于定位偶发空正文真因。
|
|
16
|
+
* 行为中性:未设置环境变量时完全无副作用。
|
|
17
|
+
*/
|
|
18
|
+
const SCI_DEBUG_ENABLED = Boolean(process.env.HELIX_SCI_DEBUG);
|
|
19
|
+
const SCI_DEBUG_FILE = process.env.HELIX_SCI_DEBUG_FILE ||
|
|
20
|
+
join(tmpdir(), "helixlife-sci-debug.log");
|
|
21
|
+
function sciDebugLog(entry) {
|
|
22
|
+
if (!SCI_DEBUG_ENABLED) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
appendFileSync(SCI_DEBUG_FILE, `${JSON.stringify({ ts: new Date().toISOString(), ...entry })}\n`, "utf8");
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* 诊断失败不影响主流程 */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// ============================================================
|
|
33
|
+
// 工具函数(导出供单测)
|
|
34
|
+
// ============================================================
|
|
35
|
+
/** 检查是否为有效 Markdown(提纲格式:至少含 # 标题) */
|
|
36
|
+
export function isValidOutlineMarkdown(text) {
|
|
37
|
+
const trimmed = text.trim();
|
|
38
|
+
return trimmed.length > 0 && /^#{1,6}\s+\S/.test(trimmed);
|
|
39
|
+
}
|
|
40
|
+
/** 从提纲 Markdown 提取首个标题文本(对齐官网 outline_title) */
|
|
41
|
+
export function extractOutlineTitle(outline) {
|
|
42
|
+
const match = outline.trim().match(/^#{1,6}\s+(.+)$/m);
|
|
43
|
+
return match?.[1]?.trim() ?? "";
|
|
44
|
+
}
|
|
45
|
+
/** 解析模板类型 */
|
|
46
|
+
function resolveTemplate(template) {
|
|
47
|
+
return parseSciTemplateType(template ?? "basic");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 组装全文 execute inputs(对齐官网 Writing.getParams SCI existing)
|
|
51
|
+
* keywords ≈ outlineParams.query(existing 常为空,不用 results 冒充)
|
|
52
|
+
*/
|
|
53
|
+
export function buildSciArticleInputs(options) {
|
|
54
|
+
return {
|
|
55
|
+
outline: options.outline,
|
|
56
|
+
language: options.language,
|
|
57
|
+
methods: options.methods,
|
|
58
|
+
results: options.results,
|
|
59
|
+
keywords: "",
|
|
60
|
+
_bibliography: 0,
|
|
61
|
+
MethodAndResult: options.methodAndResult ?? "",
|
|
62
|
+
outline_title: extractOutlineTitle(options.outline),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 标题段规范化:官网 title 工作流前强制写入 "# "
|
|
67
|
+
*/
|
|
68
|
+
export function normalizeSciTitleSection(text) {
|
|
69
|
+
const trimmed = text.trim();
|
|
70
|
+
if (!trimmed) {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
if (/^#\s/.test(trimmed)) {
|
|
74
|
+
return trimmed;
|
|
75
|
+
}
|
|
76
|
+
return `# ${trimmed}`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 合并 title + body 各段(官网 list.join("\\n"))
|
|
80
|
+
*/
|
|
81
|
+
export function assembleSciArticleMarkdown(sections) {
|
|
82
|
+
return sections
|
|
83
|
+
.map((section) => section.trim())
|
|
84
|
+
.filter(Boolean)
|
|
85
|
+
.join("\n");
|
|
86
|
+
}
|
|
87
|
+
/** 解析 Step1 方法/结果:内联或 *-file,非空才通过 */
|
|
88
|
+
async function resolveMethodsAndResults(options) {
|
|
89
|
+
const methods = await resolveTextOrFile({
|
|
90
|
+
text: options.methods,
|
|
91
|
+
file: options.methodsFile,
|
|
92
|
+
label: "methods",
|
|
93
|
+
});
|
|
94
|
+
const results = await resolveTextOrFile({
|
|
95
|
+
text: options.results,
|
|
96
|
+
file: options.resultsFile,
|
|
97
|
+
label: "results",
|
|
98
|
+
});
|
|
99
|
+
if (!methods || !results) {
|
|
100
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, "缺少 methods/results:请传 --methods/--results 或 --methods-file/--results-file(取步骤①返回值)");
|
|
101
|
+
}
|
|
102
|
+
return { methods, results };
|
|
103
|
+
}
|
|
104
|
+
// 批量调用 SSE 流式生成 SCI 全文(与官网 batchFetchWorkflows + Writing.onMessage 对齐)
|
|
105
|
+
async function batchStreamSciArticle(appIds, orderId, parentOrderId, outline, language, methods, results, methodAndResult, format) {
|
|
106
|
+
const client = new ApiClient();
|
|
107
|
+
const streamToStdout = format !== "json";
|
|
108
|
+
const sectionTexts = [];
|
|
109
|
+
const allOutputs = [];
|
|
110
|
+
let lastWorkflowRunId;
|
|
111
|
+
let lastElapsedTime;
|
|
112
|
+
let totalElapsedTime = 0;
|
|
113
|
+
// 全文生成耗时长:一次性提示,不做百分比假进度(避免 Agent 订阅/轮询冲突)
|
|
114
|
+
process.stderr.write(`${SCI_ARTICLE_WAIT_HINT}\n`);
|
|
115
|
+
const inputs = buildSciArticleInputs({
|
|
116
|
+
outline,
|
|
117
|
+
language,
|
|
118
|
+
methods,
|
|
119
|
+
results,
|
|
120
|
+
methodAndResult,
|
|
121
|
+
});
|
|
122
|
+
for (let i = 0; i < appIds.length; i++) {
|
|
123
|
+
const appId = appIds[i];
|
|
124
|
+
const isTitleApp = i === 0;
|
|
125
|
+
if (streamToStdout) {
|
|
126
|
+
process.stderr.write(`\n[${i + 1}/${appIds.length}] 正在生成${isTitleApp ? "标题" : "正文"}...\n`);
|
|
127
|
+
}
|
|
128
|
+
const executeBody = buildSciExecuteBody({
|
|
129
|
+
// 官网 existing:query 多为 outlineParams.query(常空),results 在 inputs
|
|
130
|
+
query: "",
|
|
131
|
+
inputs,
|
|
132
|
+
appId,
|
|
133
|
+
appName: "全文",
|
|
134
|
+
appType: 1,
|
|
135
|
+
index: 1,
|
|
136
|
+
orderId,
|
|
137
|
+
// 官网 Writing extraParams.end=true 同时传给所有 app
|
|
138
|
+
end: true,
|
|
139
|
+
count: appIds.length,
|
|
140
|
+
parentOrderId,
|
|
141
|
+
});
|
|
142
|
+
const chunks = [];
|
|
143
|
+
let overrideText;
|
|
144
|
+
let elapsedTime;
|
|
145
|
+
const eventCounts = {};
|
|
146
|
+
let sawWorkflowFinished = false;
|
|
147
|
+
await new Promise((resolve, reject) => {
|
|
148
|
+
client
|
|
149
|
+
.requestSse(SCI_EXECUTE_API_PATH, { method: "POST", body: executeBody }, (payload) => {
|
|
150
|
+
const evt = typeof payload.event === "string" ? payload.event : "unknown";
|
|
151
|
+
eventCounts[evt] = (eventCounts[evt] ?? 0) + 1;
|
|
152
|
+
assertWorkflowSucceeded(payload, "全文生成失败,请稍后重试", [
|
|
153
|
+
"workflow_finished",
|
|
154
|
+
]);
|
|
155
|
+
const chunk = extractSseText(payload, { nested: true });
|
|
156
|
+
if (chunk) {
|
|
157
|
+
chunks.push(chunk);
|
|
158
|
+
if (streamToStdout) {
|
|
159
|
+
process.stdout.write(chunk);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (payload.event === "workflow_finished") {
|
|
163
|
+
sawWorkflowFinished = true;
|
|
164
|
+
const data = payload.data;
|
|
165
|
+
if (typeof data === "object" && data !== null) {
|
|
166
|
+
const record = data;
|
|
167
|
+
if (typeof record.elapsed_time === "number") {
|
|
168
|
+
elapsedTime = record.elapsed_time;
|
|
169
|
+
lastElapsedTime = elapsedTime;
|
|
170
|
+
totalElapsedTime += elapsedTime;
|
|
171
|
+
}
|
|
172
|
+
if (typeof record.outputs === "object" && record.outputs) {
|
|
173
|
+
const outputs = record.outputs;
|
|
174
|
+
allOutputs.push(outputs);
|
|
175
|
+
// 对齐官网 Object.values(outputs)[0]
|
|
176
|
+
const finishedText = pickWebsiteWorkflowOutputText(outputs);
|
|
177
|
+
if (finishedText) {
|
|
178
|
+
overrideText = finishedText;
|
|
179
|
+
if (streamToStdout && chunks.length === 0) {
|
|
180
|
+
process.stdout.write(finishedText);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
sciDebugLog({
|
|
185
|
+
phase: "workflow_finished",
|
|
186
|
+
appIndex: i,
|
|
187
|
+
isTitleApp,
|
|
188
|
+
appId,
|
|
189
|
+
status: record.status,
|
|
190
|
+
elapsedTime: record.elapsed_time,
|
|
191
|
+
outputsKeys: typeof record.outputs === "object" && record.outputs
|
|
192
|
+
? Object.keys(record.outputs)
|
|
193
|
+
: null,
|
|
194
|
+
data: record,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (typeof payload.workflow_run_id === "string") {
|
|
198
|
+
lastWorkflowRunId = payload.workflow_run_id;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
.then(resolve)
|
|
203
|
+
.catch((err) => {
|
|
204
|
+
sciDebugLog({
|
|
205
|
+
phase: "sse_error",
|
|
206
|
+
appIndex: i,
|
|
207
|
+
isTitleApp,
|
|
208
|
+
appId,
|
|
209
|
+
eventCounts,
|
|
210
|
+
sawWorkflowFinished,
|
|
211
|
+
error: err instanceof Error ? err.message : String(err),
|
|
212
|
+
});
|
|
213
|
+
reject(err);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
const streamed = chunks.join("").trim();
|
|
217
|
+
const finished = (overrideText ?? "").trim();
|
|
218
|
+
let sectionText = finished || streamed;
|
|
219
|
+
// 避免短 result 覆盖长流式正文
|
|
220
|
+
if (finished &&
|
|
221
|
+
streamed &&
|
|
222
|
+
streamed.length > finished.length * 2 &&
|
|
223
|
+
streamed.length - finished.length > 500) {
|
|
224
|
+
sectionText = streamed;
|
|
225
|
+
}
|
|
226
|
+
if (isTitleApp) {
|
|
227
|
+
sectionText = normalizeSciTitleSection(sectionText);
|
|
228
|
+
}
|
|
229
|
+
sciDebugLog({
|
|
230
|
+
phase: "section_done",
|
|
231
|
+
appIndex: i,
|
|
232
|
+
isTitleApp,
|
|
233
|
+
appId,
|
|
234
|
+
eventCounts,
|
|
235
|
+
sawWorkflowFinished,
|
|
236
|
+
streamedLen: streamed.length,
|
|
237
|
+
finishedLen: finished.length,
|
|
238
|
+
sectionTextLen: sectionText.length,
|
|
239
|
+
sectionHead: sectionText.slice(0, 120),
|
|
240
|
+
});
|
|
241
|
+
sectionTexts.push(sectionText);
|
|
242
|
+
}
|
|
243
|
+
assertSciArticleComplete(sectionTexts);
|
|
244
|
+
const article = assembleSciArticleMarkdown(sectionTexts);
|
|
245
|
+
const allReferences = [];
|
|
246
|
+
for (const outputs of allOutputs) {
|
|
247
|
+
const refs = extractReferences(outputs);
|
|
248
|
+
allReferences.push(...refs);
|
|
249
|
+
}
|
|
250
|
+
if (!isCompleteSciArticleMarkdown(article)) {
|
|
251
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_RESPONSE, "全文生成不完整:正文为空或过短(仅有标题不能视为成功),请重试 outline confirm create");
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
article,
|
|
255
|
+
references: allReferences,
|
|
256
|
+
workflowRunId: lastWorkflowRunId,
|
|
257
|
+
elapsedTime: lastElapsedTime ?? totalElapsedTime,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
// ============================================================
|
|
261
|
+
// 主入口:确认提纲并生成全文(Step2)
|
|
262
|
+
// ============================================================
|
|
263
|
+
export async function runCreateSciArticle(options = {}) {
|
|
264
|
+
const format = options.format ?? "markdown";
|
|
265
|
+
const interactive = isInteractiveTerminal() && !options.yes && options.format !== "json";
|
|
266
|
+
const log = createFormatLogger(format);
|
|
267
|
+
const template = resolveTemplate(options.template);
|
|
268
|
+
const outline = await resolveMarkdownContent(options, "请通过 --content、--file 或 --stdin 提供提纲 Markdown 内容");
|
|
269
|
+
if (!isValidOutlineMarkdown(outline)) {
|
|
270
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, "提纲内容格式无效,应为 Markdown 格式(以 # 标题开头)");
|
|
271
|
+
}
|
|
272
|
+
if (!options.orderId?.trim()) {
|
|
273
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, "缺少 orderId,请先执行 outline create 获取订单 ID");
|
|
274
|
+
}
|
|
275
|
+
// 直接复用步骤① 提纲订单(对齐官网首次生成 needRefreshOrder=false 路径);
|
|
276
|
+
// 不新建订单、不切换订单号(全文接口仅在结束时返回内容,切单只会丢弃进行中的生成)
|
|
277
|
+
const orderId = options.orderId.trim();
|
|
278
|
+
const { methods, results } = await resolveMethodsAndResults(options);
|
|
279
|
+
const methodAndResult = options.methodAndResult?.trim() ?? "";
|
|
280
|
+
const selection = await resolveSciArticleSelection({ language: options.language }, interactive);
|
|
281
|
+
const { language } = selection;
|
|
282
|
+
const appIds = getSciArticleAppIds(template);
|
|
283
|
+
// 生成前清理该订单可能残留的脏缓存(历史仅标题假成功)
|
|
284
|
+
await clearSciArticleCache(orderId);
|
|
285
|
+
const stream = await batchStreamSciArticle(appIds, orderId, null, outline, language, methods, results, methodAndResult, format);
|
|
286
|
+
const result = {
|
|
287
|
+
orderId,
|
|
288
|
+
template,
|
|
289
|
+
language,
|
|
290
|
+
article: stream.article,
|
|
291
|
+
references: stream.references,
|
|
292
|
+
workflowRunId: stream.workflowRunId,
|
|
293
|
+
elapsedTime: stream.elapsedTime,
|
|
294
|
+
};
|
|
295
|
+
const cacheReady = await saveSciArticleCache({
|
|
296
|
+
orderId,
|
|
297
|
+
template,
|
|
298
|
+
language,
|
|
299
|
+
article: stream.article,
|
|
300
|
+
references: stream.references,
|
|
301
|
+
workflowRunId: stream.workflowRunId,
|
|
302
|
+
});
|
|
303
|
+
if (format === "json") {
|
|
304
|
+
printOutput(wrapWorkbenchResult(result, { step: "article", subType: "sci" }, {
|
|
305
|
+
orderId,
|
|
306
|
+
workflowRunId: stream.workflowRunId,
|
|
307
|
+
cacheReady,
|
|
308
|
+
}), "json");
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const elapsedHint = formatElapsedHint(stream.elapsedTime);
|
|
312
|
+
log(`\n---\n模板:${getSciTemplateLabel(template)} | 语言:${language} | 参考文献 ${stream.references.length} 条${elapsedHint}`);
|
|
313
|
+
log("\n✅ 确认提纲并生成全文(Step2)完成。\n");
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=article-create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"article-create.js","sourceRoot":"","sources":["../../../../src/modules/sci/commands/article-create.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,uBAAuB,GAExB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GA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ACD,MAAM,CACP,CAAC;QACF,OAAO;IACT,CAAC;IAED,MAAM,WAAW,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC1D,GAAG,CACD,aAAa,mBAAmB,CAAC,QAAQ,CAAC,SAAS,QAAQ,WAAW,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,WAAW,EAAE,CACjH,CAAC;IACF,GAAG,CAAC,2BAA2B,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type OutputFormat } from "../../../core/index.js";
|
|
2
|
+
import { type SciArticleDownloadResult, type SciLanguage } from "../constants.js";
|
|
3
|
+
export type { SciArticleDownloadResult } from "../constants.js";
|
|
4
|
+
export interface DownloadSciArticleOptions {
|
|
5
|
+
orderId?: string;
|
|
6
|
+
file?: string;
|
|
7
|
+
references?: string[];
|
|
8
|
+
referencesFile?: string;
|
|
9
|
+
language?: string;
|
|
10
|
+
output?: string;
|
|
11
|
+
produceId?: string;
|
|
12
|
+
format?: OutputFormat;
|
|
13
|
+
emitOutput?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 将标题候选收成安全导出 basename(不含扩展名)。
|
|
17
|
+
* 对齐官网:整题作文件名、不截断;CLI 仅替换 Windows 非法字符以便 writeFile。
|
|
18
|
+
*/
|
|
19
|
+
export declare function toSciExportBasename(titleCandidate: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 从全文 Markdown 提取论文标题(对齐官网 getTitleFromArticle)
|
|
22
|
+
* 优先首个 H1(恰好一个 `#`);兼容「标题:」前缀;否则取首个非 ATX 标题段落;空则「未命名」
|
|
23
|
+
*/
|
|
24
|
+
export declare function extractSciArticleTitle(markdown: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* 专供导出文件名:只信任严格 H1;无 H1 或正文泄漏 →「未命名」
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractSciExportTitle(markdown: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* 若 Markdown 开头缺少 H1 标题,则注入 `# ${title}`(防御旧缓存 / 残缺正文)
|
|
31
|
+
* 注入标题经 toSciExportBasename,避免整篇正文写进 H1。
|
|
32
|
+
*/
|
|
33
|
+
export declare function ensureSciArticleTitleHeading(markdown: string, title?: string): {
|
|
34
|
+
markdown: string;
|
|
35
|
+
title: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function resolveSciArticleDownloadLanguage(explicitLanguage: string | undefined, cachedLanguage?: string): SciLanguage;
|
|
38
|
+
export declare function appendReferencesToMarkdown(article: string, references: string[], language?: string): string;
|
|
39
|
+
export declare function downloadSciArticleDocx(markdown: string, options?: Pick<DownloadSciArticleOptions, "produceId">): Promise<{
|
|
40
|
+
buffer: Buffer;
|
|
41
|
+
contentType: string | null;
|
|
42
|
+
filename?: string;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* 确定全文 docx 输出路径:默认 / -o 目录时用论文标题命名(对齐官网 saveAs)
|
|
46
|
+
* 文件名只吃 toSciExportBasename,禁止正文泄漏进路径。
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveArticleDownloadPath(outputOption: string | undefined, articleTitle: string): string;
|
|
49
|
+
export declare function runDownloadSciArticle(options?: DownloadSciArticleOptions): Promise<SciArticleDownloadResult>;
|
|
50
|
+
//# sourceMappingURL=article-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"article-download.d.ts","sourceRoot":"","sources":["../../../../src/modules/sci/commands/article-download.ts"],"names":[],"mappings":"AAGA,OAAO,EASL,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGhE,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAA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AE,MAAM,GAAG,SAAS,EAChC,YAAY,EAAE,MAAM,GACnB,MAAM,CAWR;AAYD,wBAAsB,qBAAqB,CACzC,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,wBAAwB,CAAC,CAsGnC"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// SCI 全文导出(Step3):命中步骤② 系统临时目录缓存 → 追加参考文献 → 输出 MD + Word
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { extname, join } from "node:path";
|
|
4
|
+
import { ApiClient, getDefaultNewideaBaseUrl, helixlifeError, helixlifeErrorCode, getUserDownloadsDir, printOutput, resolveUserPath, sanitizeFilename, } from "../../../core/index.js";
|
|
5
|
+
import { SCI_ARTICLE_CONTENT_PRODUCER, SCI_DOCX_CONVERT_API_PATH, } from "../constants.js";
|
|
6
|
+
import { loadSciArticleCache, popSciArticleCache } from "../article-cache.js";
|
|
7
|
+
const DEFAULT_SCI_ARTICLE_TITLE = "未命名";
|
|
8
|
+
/** 检测行首「标题:」/「Title:」类前缀(对齐官网语义,避免正文中含「标题」误伤) */
|
|
9
|
+
function checkIsTitleLabel(text) {
|
|
10
|
+
return /^(?:项目名称|标题|Title)\s*[::]?/.test(text);
|
|
11
|
+
}
|
|
12
|
+
/** 从「标题: xxx」提取标题正文(对齐官网 extractTitle) */
|
|
13
|
+
function extractLabeledTitle(text) {
|
|
14
|
+
const match = text.match(/^(?:项目名称|标题|Title)\s*[::]?\s*\*{0,2}([^*]+)\*{0,2}/);
|
|
15
|
+
return match?.[1]?.trim() || "";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 候选是否像正文(禁止当文件名)。
|
|
19
|
+
* 对齐官网:不因长度否决;仅空串 / 换行 / `##` 等多段泄漏(MD 特有防护)。
|
|
20
|
+
*/
|
|
21
|
+
function looksLikeArticleBody(text) {
|
|
22
|
+
if (!text.trim()) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (/[\r\n]/.test(text)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (text.includes("##") || /\n#{1,6}/.test(text)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 将标题候选收成安全导出 basename(不含扩展名)。
|
|
35
|
+
* 对齐官网:整题作文件名、不截断;CLI 仅替换 Windows 非法字符以便 writeFile。
|
|
36
|
+
*/
|
|
37
|
+
export function toSciExportBasename(titleCandidate) {
|
|
38
|
+
const raw = titleCandidate.trim();
|
|
39
|
+
if (!raw || looksLikeArticleBody(raw)) {
|
|
40
|
+
return DEFAULT_SCI_ARTICLE_TITLE;
|
|
41
|
+
}
|
|
42
|
+
const sanitized = sanitizeFilename(raw, { maxLength: null });
|
|
43
|
+
// sanitizeFilename 可能带扩展名;导出 basename 只要 stem
|
|
44
|
+
return (sanitized.replace(/\.[A-Za-z0-9]{1,8}$/, "") || DEFAULT_SCI_ARTICLE_TITLE);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 从全文 Markdown 提取论文标题(对齐官网 getTitleFromArticle)
|
|
48
|
+
* 优先首个 H1(恰好一个 `#`);兼容「标题:」前缀;否则取首个非 ATX 标题段落;空则「未命名」
|
|
49
|
+
*/
|
|
50
|
+
export function extractSciArticleTitle(markdown) {
|
|
51
|
+
const lines = markdown.split(/\r?\n/);
|
|
52
|
+
for (const raw of lines) {
|
|
53
|
+
const line = raw.trim();
|
|
54
|
+
if (!line) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// 恰好 H1:`# title`,排除 `##` / `###`
|
|
58
|
+
const h1Match = line.match(/^#(?!#)\s+(.+)$/);
|
|
59
|
+
if (h1Match) {
|
|
60
|
+
const heading = h1Match[1].trim();
|
|
61
|
+
if (checkIsTitleLabel(heading)) {
|
|
62
|
+
return (extractLabeledTitle(heading) || heading || DEFAULT_SCI_ARTICLE_TITLE);
|
|
63
|
+
}
|
|
64
|
+
return heading || DEFAULT_SCI_ARTICLE_TITLE;
|
|
65
|
+
}
|
|
66
|
+
// 跳过二级及以下标题,避免把「## 摘要」当成文件名
|
|
67
|
+
if (/^#{2,6}\s+/.test(line)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (checkIsTitleLabel(line)) {
|
|
71
|
+
const labeled = extractLabeledTitle(line);
|
|
72
|
+
if (labeled) {
|
|
73
|
+
return labeled;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// 非 ATX 标题的首个非空行(官网 else if nodeText)
|
|
77
|
+
return line;
|
|
78
|
+
}
|
|
79
|
+
return DEFAULT_SCI_ARTICLE_TITLE;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 专供导出文件名:只信任严格 H1;无 H1 或正文泄漏 →「未命名」
|
|
83
|
+
*/
|
|
84
|
+
export function extractSciExportTitle(markdown) {
|
|
85
|
+
const lines = markdown.split(/\r?\n/);
|
|
86
|
+
for (const raw of lines) {
|
|
87
|
+
const line = raw.trim();
|
|
88
|
+
if (!line) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const h1Match = line.match(/^#(?!#)\s+(.+)$/);
|
|
92
|
+
if (h1Match) {
|
|
93
|
+
let heading = h1Match[1].trim();
|
|
94
|
+
if (checkIsTitleLabel(heading)) {
|
|
95
|
+
heading = extractLabeledTitle(heading) || heading;
|
|
96
|
+
}
|
|
97
|
+
return toSciExportBasename(heading);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return DEFAULT_SCI_ARTICLE_TITLE;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 若 Markdown 开头缺少 H1 标题,则注入 `# ${title}`(防御旧缓存 / 残缺正文)
|
|
104
|
+
* 注入标题经 toSciExportBasename,避免整篇正文写进 H1。
|
|
105
|
+
*/
|
|
106
|
+
export function ensureSciArticleTitleHeading(markdown, title) {
|
|
107
|
+
const rawTitle = (title?.trim() || extractSciArticleTitle(markdown)).trim() ||
|
|
108
|
+
DEFAULT_SCI_ARTICLE_TITLE;
|
|
109
|
+
// 正文 H1 保留完整题目;文件名截断由 toSciExportBasename / extractSciExportTitle 负责
|
|
110
|
+
const resolvedTitle = looksLikeArticleBody(rawTitle)
|
|
111
|
+
? DEFAULT_SCI_ARTICLE_TITLE
|
|
112
|
+
: rawTitle;
|
|
113
|
+
const trimmed = markdown.trimStart();
|
|
114
|
+
if (/^#(?!#)\s+\S/.test(trimmed)) {
|
|
115
|
+
return {
|
|
116
|
+
markdown,
|
|
117
|
+
title: extractSciExportTitle(markdown) || toSciExportBasename(resolvedTitle),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
markdown: `# ${resolvedTitle}\n\n${markdown.trimStart()}`,
|
|
122
|
+
title: toSciExportBasename(resolvedTitle),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// 解析参考文献列表:CLI 参数或 JSON 文件
|
|
126
|
+
async function resolveReferences(options) {
|
|
127
|
+
if (options.references?.length) {
|
|
128
|
+
return options.references;
|
|
129
|
+
}
|
|
130
|
+
if (options.referencesFile) {
|
|
131
|
+
try {
|
|
132
|
+
const raw = await readFile(resolveUserPath(options.referencesFile), "utf8");
|
|
133
|
+
const parsed = JSON.parse(raw);
|
|
134
|
+
if (Array.isArray(parsed)) {
|
|
135
|
+
return parsed.filter((item) => typeof item === "string");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, `无法读取参考文献文件: ${options.referencesFile}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
// 解析步骤③ 参考文献标题语言:显式 --language 优先,否则缓存,否则中文
|
|
145
|
+
export function resolveSciArticleDownloadLanguage(explicitLanguage, cachedLanguage) {
|
|
146
|
+
return (explicitLanguage?.trim() ||
|
|
147
|
+
cachedLanguage?.trim() ||
|
|
148
|
+
"中文");
|
|
149
|
+
}
|
|
150
|
+
// 将参考文献追加到正文 Markdown(原始引文格式,全量保留)
|
|
151
|
+
export function appendReferencesToMarkdown(article, references, language) {
|
|
152
|
+
if (!references.length) {
|
|
153
|
+
return `${article.trim()}\n`;
|
|
154
|
+
}
|
|
155
|
+
const heading = language === "英文" ? "## References" : "## 参考文献";
|
|
156
|
+
const body = references
|
|
157
|
+
.map((line) => line.trim())
|
|
158
|
+
.filter(Boolean)
|
|
159
|
+
.join("\n");
|
|
160
|
+
return `${article.trim()}\n\n${heading}\n\n${body}\n`;
|
|
161
|
+
}
|
|
162
|
+
// 组装全文 markdown 转 docx 的 multipart 表单(原始引文格式,csl_key 留空)
|
|
163
|
+
function buildArticleDownloadFormData(markdown, produceId) {
|
|
164
|
+
const form = new FormData();
|
|
165
|
+
const blob = new Blob([markdown], { type: "text/plain" });
|
|
166
|
+
form.append("data", blob, "blob");
|
|
167
|
+
form.append("is_aigc", "true");
|
|
168
|
+
form.append("content_producer", SCI_ARTICLE_CONTENT_PRODUCER);
|
|
169
|
+
form.append("produce_id", produceId || "");
|
|
170
|
+
form.append("csl_key", "");
|
|
171
|
+
return form;
|
|
172
|
+
}
|
|
173
|
+
// 调用 PaaS 接口将全文 Markdown 转为 docx
|
|
174
|
+
export async function downloadSciArticleDocx(markdown, options = {}) {
|
|
175
|
+
const client = new ApiClient();
|
|
176
|
+
const form = buildArticleDownloadFormData(markdown, options.produceId ?? "");
|
|
177
|
+
return client.requestBinary(SCI_DOCX_CONVERT_API_PATH, {
|
|
178
|
+
method: "POST",
|
|
179
|
+
baseUrl: getDefaultNewideaBaseUrl(),
|
|
180
|
+
body: form,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 确定全文 docx 输出路径:默认 / -o 目录时用论文标题命名(对齐官网 saveAs)
|
|
185
|
+
* 文件名只吃 toSciExportBasename,禁止正文泄漏进路径。
|
|
186
|
+
*/
|
|
187
|
+
export function resolveArticleDownloadPath(outputOption, articleTitle) {
|
|
188
|
+
const safeName = `${toSciExportBasename(articleTitle)}.docx`;
|
|
189
|
+
if (outputOption) {
|
|
190
|
+
const resolved = resolveUserPath(outputOption);
|
|
191
|
+
if (extname(resolved)) {
|
|
192
|
+
return resolved;
|
|
193
|
+
}
|
|
194
|
+
return join(resolved, safeName);
|
|
195
|
+
}
|
|
196
|
+
return join(getUserDownloadsDir(), safeName);
|
|
197
|
+
}
|
|
198
|
+
// 由 docx 路径推导配套 MD 路径(同目录同名,扩展名替换为 .md)
|
|
199
|
+
function resolveArticleMarkdownPath(docxPath) {
|
|
200
|
+
const ext = extname(docxPath);
|
|
201
|
+
if (ext) {
|
|
202
|
+
return docxPath.slice(0, docxPath.length - ext.length) + ".md";
|
|
203
|
+
}
|
|
204
|
+
return `${docxPath}.md`;
|
|
205
|
+
}
|
|
206
|
+
// 执行全文下载:读取 Markdown → 追加参考文献 → 同时输出 MD 与 docx
|
|
207
|
+
export async function runDownloadSciArticle(options = {}) {
|
|
208
|
+
const explicitProvided = Boolean(options.file);
|
|
209
|
+
if (options.orderId && explicitProvided) {
|
|
210
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, "--order-id 与 --file 互斥,请二选一");
|
|
211
|
+
}
|
|
212
|
+
let article;
|
|
213
|
+
let references;
|
|
214
|
+
let produceId = options.produceId ?? "";
|
|
215
|
+
let language = "中文";
|
|
216
|
+
if (options.orderId) {
|
|
217
|
+
const cached = await loadSciArticleCache(options.orderId);
|
|
218
|
+
if (!cached) {
|
|
219
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, `订单 ${options.orderId} 的全文缓存缺失或已清理,请重新执行步骤② 或通过 --file <path> 显式提供全文 Markdown`);
|
|
220
|
+
}
|
|
221
|
+
article = cached.article;
|
|
222
|
+
references = cached.references;
|
|
223
|
+
if (!options.produceId && cached.workflowRunId) {
|
|
224
|
+
produceId = cached.workflowRunId;
|
|
225
|
+
}
|
|
226
|
+
language = resolveSciArticleDownloadLanguage(options.language, cached.language);
|
|
227
|
+
}
|
|
228
|
+
else if (options.file) {
|
|
229
|
+
try {
|
|
230
|
+
article = await readFile(resolveUserPath(options.file), "utf8");
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, `无法读取全文文件: ${options.file}`);
|
|
234
|
+
}
|
|
235
|
+
references = await resolveReferences(options);
|
|
236
|
+
language = resolveSciArticleDownloadLanguage(options.language);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
throw new helixlifeError(helixlifeErrorCode.INVALID_ARGUMENT, "请通过 --order-id 命中步骤② 缓存,或通过 --file <path> 显式提供全文 Markdown");
|
|
240
|
+
}
|
|
241
|
+
const withTitle = ensureSciArticleTitleHeading(article);
|
|
242
|
+
const markdown = appendReferencesToMarkdown(withTitle.markdown, references, language);
|
|
243
|
+
const articleTitle = extractSciExportTitle(markdown);
|
|
244
|
+
const { buffer, contentType } = await downloadSciArticleDocx(markdown, {
|
|
245
|
+
produceId,
|
|
246
|
+
});
|
|
247
|
+
const docxPath = resolveArticleDownloadPath(options.output, articleTitle);
|
|
248
|
+
await writeFile(docxPath, buffer);
|
|
249
|
+
const mdPath = resolveArticleMarkdownPath(docxPath);
|
|
250
|
+
const mdBuffer = Buffer.from(markdown, "utf8");
|
|
251
|
+
await writeFile(mdPath, mdBuffer);
|
|
252
|
+
if (options.orderId) {
|
|
253
|
+
try {
|
|
254
|
+
await popSciArticleCache(options.orderId);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
console.warn(`[sci-cache] 清理失败 orderId=${options.orderId}: ${error.message}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const filename = `${toSciExportBasename(articleTitle)}.docx`;
|
|
261
|
+
const result = {
|
|
262
|
+
mdPath,
|
|
263
|
+
mdSize: mdBuffer.byteLength,
|
|
264
|
+
docxPath,
|
|
265
|
+
docxSize: buffer.byteLength,
|
|
266
|
+
contentType,
|
|
267
|
+
filename,
|
|
268
|
+
};
|
|
269
|
+
const emitOutput = options.emitOutput !== false;
|
|
270
|
+
if (!emitOutput) {
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
if (options.format === "json") {
|
|
274
|
+
printOutput(result, "json");
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
console.log(`全文 Markdown 已保存: ${mdPath} (${result.mdSize} 字节)`);
|
|
278
|
+
console.log(`全文 Word 已保存: ${docxPath} (${result.docxSize} 字节)`);
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=article-download.js.map
|