@aigne/doc-smith 0.9.10 → 0.9.11-beta
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/CHANGELOG.md +12 -0
- package/README.md +189 -219
- package/README.zh.md +270 -0
- package/agents/bash-executor/index.mjs +347 -0
- package/agents/clear/ai/intent.md +142 -0
- package/agents/clear/choose-contents.mjs +13 -65
- package/agents/clear/clear-auth-tokens.mjs +17 -21
- package/agents/clear/clear-deployment-config.mjs +33 -24
- package/agents/clear/index.yaml +1 -9
- package/agents/content-checker/ai/intent.md +209 -0
- package/agents/content-checker/clean-invalid-docs.mjs +254 -0
- package/agents/content-checker/index.mjs +191 -0
- package/agents/content-checker/validate-content.mjs +983 -0
- package/agents/generate-images/generate-image.yaml +75 -0
- package/agents/generate-images/generate-summary.mjs +213 -0
- package/agents/generate-images/index.yaml +39 -0
- package/agents/generate-images/prepare-generation.mjs +286 -0
- package/agents/generate-images/prepare-image-generation.mjs +130 -0
- package/{prompts/detail/diagram/generate-image-system.md → agents/generate-images/prompts/system.md} +22 -56
- package/agents/generate-images/prompts/user.md +85 -0
- package/agents/generate-images/save-image-result.mjs +247 -0
- package/agents/generate-images/scan-image-slots.mjs +247 -0
- package/agents/localize/index.yaml +19 -42
- package/{prompts/translate → agents/localize/prompts}/translate-document.md +0 -139
- package/agents/localize/translate-documents/generate-summary.mjs +163 -0
- package/agents/localize/translate-documents/load-glossary.mjs +52 -0
- package/agents/localize/translate-documents/prepare-translation.mjs +249 -0
- package/agents/localize/translate-documents/save-translation.mjs +171 -0
- package/agents/localize/translate-documents/translate-document-to-language.mjs +209 -0
- package/agents/localize/translate-documents/translate-document.yaml +23 -0
- package/agents/localize/translate-documents/translate-to-languages.yaml +10 -0
- package/agents/localize/translate-images/check-image-translation.mjs +225 -0
- package/agents/localize/translate-images/detect-text/detect-and-update-shared.mjs +148 -0
- package/agents/localize/translate-images/detect-text/detect-image-text.yaml +44 -0
- package/agents/localize/translate-images/detect-text/detect-images-text.yaml +21 -0
- package/agents/localize/translate-images/detect-text/prompts/detect-image-text-system.md +43 -0
- package/agents/localize/translate-images/detect-text/prompts/detect-image-text-user.md +14 -0
- package/agents/localize/translate-images/detect-text/save-text-detection.mjs +105 -0
- package/agents/localize/translate-images/prepare-image-input.mjs +124 -0
- package/agents/localize/translate-images/save-image-translation.mjs +172 -0
- package/agents/localize/translate-images/scan-doc-images.mjs +165 -0
- package/agents/localize/translate-images/translate-doc-images.yaml +24 -0
- package/agents/localize/{translate-diagram.yaml → translate-images/translate-image.yaml} +25 -14
- package/agents/publish/ai/intent.md +182 -0
- package/agents/publish/check.mjs +107 -0
- package/agents/publish/index.yaml +9 -14
- package/agents/publish/publish-docs.mjs +81 -61
- package/agents/publish/translate-meta.mjs +79 -58
- package/agents/save-document/index.mjs +260 -0
- package/agents/structure-checker/index.mjs +307 -0
- package/agents/structure-checker/validate-structure.mjs +477 -0
- package/agents/update-image/analyze-feedback.yaml +37 -0
- package/agents/update-image/index.yaml +78 -0
- package/agents/update-image/load-existing-image.mjs +211 -0
- package/agents/update-image/prompts/analyze-feedback-system.md +43 -0
- package/agents/update-image/prompts/analyze-feedback-user.md +15 -0
- package/aigne.yaml +26 -139
- package/package.json +16 -48
- package/scripts/README.md +90 -0
- package/scripts/install.sh +86 -0
- package/scripts/uninstall.sh +52 -0
- package/skills/doc-smith/SKILL.md +285 -0
- package/skills/doc-smith/ai/intent/sources-improve.md +290 -0
- package/skills/doc-smith/references/changeset-guide.md +171 -0
- package/skills/doc-smith/references/document-content-guide.md +214 -0
- package/skills/doc-smith/references/document-structure-schema.md +138 -0
- package/skills/doc-smith/references/patch-guide.md +96 -0
- package/skills/doc-smith/references/structure-confirmation-guide.md +133 -0
- package/skills/doc-smith/references/structure-planning-guide.md +149 -0
- package/skills/doc-smith/references/update-workflow.md +108 -0
- package/skills/doc-smith/references/user-intent-guide.md +175 -0
- package/skills/doc-smith/references/workspace-initialization.md +376 -0
- package/skills/doc-smith-docs-detail/SKILL.md +356 -0
- package/skills/doc-smith-docs-detail/ai/intent.md +271 -0
- package/skills-entry/doc-smith/ai/intent.md +260 -0
- package/skills-entry/doc-smith/index.mjs +66 -0
- package/skills-entry/doc-smith/prompt.md +57 -0
- package/skills-entry/doc-smith/utils.mjs +27 -0
- package/skills-entry/doc-smith-docs-detail/batch.yaml +56 -0
- package/skills-entry/doc-smith-docs-detail/index.mjs +95 -0
- package/skills-entry/doc-smith-docs-detail/prompt.md +64 -0
- package/utils/afs-factory.mjs +183 -0
- package/utils/agent-constants.mjs +97 -0
- package/utils/{auth-utils.mjs → auth.mjs} +6 -9
- package/{agents/utils/update-branding.mjs → utils/branding.mjs} +3 -4
- package/utils/config.mjs +261 -0
- package/utils/constants.mjs +32 -0
- package/utils/deploy.mjs +3 -3
- package/utils/docs-converter.mjs +454 -0
- package/utils/docs.mjs +212 -0
- package/utils/document-paths.mjs +172 -0
- package/utils/files.mjs +74 -0
- package/utils/git.mjs +65 -0
- package/utils/{blocklet.mjs → http.mjs} +18 -0
- package/utils/image-slots.mjs +57 -0
- package/utils/image-utils.mjs +114 -0
- package/utils/project.mjs +95 -0
- package/utils/sources-path-resolver.mjs +76 -0
- package/utils/{upload-files.mjs → upload.mjs} +3 -3
- package/utils/workspace.mjs +371 -0
- package/agents/chat/chat-system.md +0 -38
- package/agents/chat/index.mjs +0 -59
- package/agents/chat/skills/generate-document.yaml +0 -15
- package/agents/chat/skills/list-documents.mjs +0 -15
- package/agents/chat/skills/update-document.yaml +0 -24
- package/agents/clear/clear-document-config.mjs +0 -36
- package/agents/clear/clear-document-structure.mjs +0 -102
- package/agents/clear/clear-generated-docs.mjs +0 -142
- package/agents/clear/clear-media-description.mjs +0 -129
- package/agents/create/aggregate-document-structure.mjs +0 -21
- package/agents/create/analyze-diagram-type-llm.yaml +0 -159
- package/agents/create/analyze-diagram-type.mjs +0 -455
- package/agents/create/check-document-structure.yaml +0 -30
- package/agents/create/check-need-generate-structure.mjs +0 -138
- package/agents/create/document-structure-tools/add-document.mjs +0 -85
- package/agents/create/document-structure-tools/delete-document.mjs +0 -116
- package/agents/create/document-structure-tools/move-document.mjs +0 -109
- package/agents/create/document-structure-tools/update-document.mjs +0 -84
- package/agents/create/generate-diagram-image.yaml +0 -91
- package/agents/create/generate-structure.yaml +0 -106
- package/agents/create/index.yaml +0 -45
- package/agents/create/refine-document-structure.yaml +0 -12
- package/agents/create/replace-d2-with-image.mjs +0 -610
- package/agents/create/update-document-structure.yaml +0 -54
- package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
- package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
- package/agents/create/user-add-document/index.yaml +0 -46
- package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
- package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
- package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
- package/agents/create/user-remove-document/index.yaml +0 -40
- package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
- package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
- package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
- package/agents/create/user-review-document-structure.mjs +0 -139
- package/agents/create/utils/init-current-content.mjs +0 -34
- package/agents/create/utils/merge-document-structures.mjs +0 -36
- package/agents/evaluate/code-snippet.mjs +0 -97
- package/agents/evaluate/document-structure.yaml +0 -67
- package/agents/evaluate/document.yaml +0 -82
- package/agents/evaluate/generate-report.mjs +0 -85
- package/agents/evaluate/index.yaml +0 -46
- package/agents/history/index.yaml +0 -6
- package/agents/history/view.mjs +0 -78
- package/agents/init/check.mjs +0 -16
- package/agents/init/index.mjs +0 -643
- package/agents/init/validate.mjs +0 -16
- package/agents/localize/choose-language.mjs +0 -107
- package/agents/localize/record-translation-history.mjs +0 -23
- package/agents/localize/save-doc-translation-or-skip.mjs +0 -18
- package/agents/localize/set-review-content.mjs +0 -58
- package/agents/localize/translate-document-wrapper.mjs +0 -34
- package/agents/localize/translate-document.yaml +0 -24
- package/agents/localize/translate-multilingual.yaml +0 -57
- package/agents/localize/translate-or-skip-diagram.mjs +0 -52
- package/agents/media/batch-generate-media-description.yaml +0 -46
- package/agents/media/generate-media-description.yaml +0 -50
- package/agents/media/load-media-description.mjs +0 -454
- package/agents/prefs/index.mjs +0 -203
- package/agents/schema/document-structure-item.yaml +0 -26
- package/agents/schema/document-structure-refine-item.yaml +0 -23
- package/agents/schema/document-structure.yaml +0 -29
- package/agents/update/batch-generate-document.yaml +0 -27
- package/agents/update/batch-update-document.yaml +0 -7
- package/agents/update/check-diagram-flag.mjs +0 -116
- package/agents/update/check-document.mjs +0 -162
- package/agents/update/check-generate-diagram.mjs +0 -106
- package/agents/update/check-update-is-single.mjs +0 -53
- package/agents/update/document-tools/update-document-content.mjs +0 -303
- package/agents/update/generate-diagram.yaml +0 -80
- package/agents/update/generate-document.yaml +0 -70
- package/agents/update/handle-document-update.yaml +0 -103
- package/agents/update/index.yaml +0 -69
- package/agents/update/pre-check-generate-diagram.yaml +0 -44
- package/agents/update/save-and-translate-document.mjs +0 -80
- package/agents/update/update-document-detail.yaml +0 -71
- package/agents/update/update-single/update-single-document-detail.mjs +0 -322
- package/agents/update/update-single-document.yaml +0 -7
- package/agents/update/user-review-document.mjs +0 -272
- package/agents/utils/action-success.mjs +0 -16
- package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
- package/agents/utils/analyze-feedback-intent.mjs +0 -253
- package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
- package/agents/utils/check-detail-result.mjs +0 -51
- package/agents/utils/check-feedback-refiner.mjs +0 -81
- package/agents/utils/choose-docs.mjs +0 -251
- package/agents/utils/document-icon-generate.yaml +0 -52
- package/agents/utils/document-title-streamline.yaml +0 -48
- package/agents/utils/ensure-document-icons.mjs +0 -129
- package/agents/utils/exit.mjs +0 -6
- package/agents/utils/feedback-refiner.yaml +0 -50
- package/agents/utils/find-item-by-path.mjs +0 -114
- package/agents/utils/find-user-preferences-by-path.mjs +0 -37
- package/agents/utils/format-document-structure.mjs +0 -35
- package/agents/utils/generate-document-or-skip.mjs +0 -41
- package/agents/utils/handle-diagram-operations.mjs +0 -263
- package/agents/utils/load-all-document-content.mjs +0 -30
- package/agents/utils/load-document-all-content.mjs +0 -96
- package/agents/utils/load-sources.mjs +0 -405
- package/agents/utils/map-reasoning-effort-level.mjs +0 -15
- package/agents/utils/post-generate.mjs +0 -133
- package/agents/utils/read-current-document-content.mjs +0 -46
- package/agents/utils/save-doc-translation.mjs +0 -30
- package/agents/utils/save-doc.mjs +0 -54
- package/agents/utils/save-output.mjs +0 -26
- package/agents/utils/save-sidebar.mjs +0 -38
- package/agents/utils/skip-if-content-exists.mjs +0 -27
- package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
- package/agents/utils/transform-detail-data-sources.mjs +0 -45
- package/assets/report-template/report.html +0 -198
- package/docs-mcp/analyze-content-relevance.yaml +0 -50
- package/docs-mcp/analyze-docs-relevance.yaml +0 -59
- package/docs-mcp/docs-search.yaml +0 -42
- package/docs-mcp/get-docs-detail.mjs +0 -41
- package/docs-mcp/get-docs-structure.mjs +0 -16
- package/docs-mcp/read-doc-content.mjs +0 -119
- package/prompts/common/document/content-rules-core.md +0 -20
- package/prompts/common/document/markdown-syntax-rules.md +0 -65
- package/prompts/common/document/media-file-list-usage-rules.md +0 -18
- package/prompts/common/document/openapi-usage-rules.md +0 -189
- package/prompts/common/document/role-and-personality.md +0 -16
- package/prompts/common/document/user-preferences.md +0 -9
- package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
- package/prompts/common/document-structure/document-icon-generate.md +0 -116
- package/prompts/common/document-structure/document-structure-rules.md +0 -43
- package/prompts/common/document-structure/document-title-streamline.md +0 -86
- package/prompts/common/document-structure/glossary.md +0 -7
- package/prompts/common/document-structure/intj-traits.md +0 -5
- package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
- package/prompts/common/document-structure/output-constraints.md +0 -18
- package/prompts/common/document-structure/user-locale-rules.md +0 -10
- package/prompts/common/document-structure/user-preferences.md +0 -9
- package/prompts/detail/custom/admonition-usage-rules.md +0 -94
- package/prompts/detail/custom/code-block-usage-rules.md +0 -163
- package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
- package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
- package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
- package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
- package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
- package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
- package/prompts/detail/diagram/generate-image-user.md +0 -81
- package/prompts/detail/diagram/guide.md +0 -29
- package/prompts/detail/diagram/official-examples.md +0 -712
- package/prompts/detail/diagram/pre-check.md +0 -23
- package/prompts/detail/diagram/role-and-personality.md +0 -2
- package/prompts/detail/diagram/rules.md +0 -46
- package/prompts/detail/diagram/system-prompt.md +0 -1139
- package/prompts/detail/diagram/user-prompt.md +0 -43
- package/prompts/detail/generate/detail-example.md +0 -457
- package/prompts/detail/generate/document-rules.md +0 -45
- package/prompts/detail/generate/system-prompt.md +0 -61
- package/prompts/detail/generate/user-prompt.md +0 -99
- package/prompts/detail/jsx/rules.md +0 -6
- package/prompts/detail/update/system-prompt.md +0 -121
- package/prompts/detail/update/user-prompt.md +0 -41
- package/prompts/evaluate/document-structure.md +0 -93
- package/prompts/evaluate/document.md +0 -149
- package/prompts/media/media-description/system-prompt.md +0 -43
- package/prompts/media/media-description/user-prompt.md +0 -17
- package/prompts/structure/check-document-structure.md +0 -93
- package/prompts/structure/document-rules.md +0 -21
- package/prompts/structure/find-documents-to-add-links.md +0 -52
- package/prompts/structure/generate/system-prompt.md +0 -13
- package/prompts/structure/generate/user-prompt.md +0 -137
- package/prompts/structure/review/structure-review-system.md +0 -81
- package/prompts/structure/structure-example.md +0 -89
- package/prompts/structure/structure-getting-started.md +0 -10
- package/prompts/structure/update/system-prompt.md +0 -93
- package/prompts/structure/update/user-prompt.md +0 -43
- package/prompts/translate/admonition.md +0 -20
- package/prompts/translate/code-block.md +0 -33
- package/prompts/utils/analyze-document-feedback-intent.md +0 -54
- package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
- package/prompts/utils/feedback-refiner.md +0 -105
- package/types/document-schema.mjs +0 -55
- package/types/document-structure-schema.mjs +0 -261
- package/utils/check-document-has-diagram.mjs +0 -95
- package/utils/conflict-detector.mjs +0 -149
- package/utils/constants/index.mjs +0 -620
- package/utils/constants/linter.mjs +0 -102
- package/utils/d2-utils.mjs +0 -205
- package/utils/debug.mjs +0 -3
- package/utils/delete-diagram-images.mjs +0 -99
- package/utils/diagram-version-utils.mjs +0 -14
- package/utils/docs-finder-utils.mjs +0 -548
- package/utils/evaluate/report-utils.mjs +0 -132
- package/utils/extract-api.mjs +0 -32
- package/utils/file-utils.mjs +0 -960
- package/utils/history-utils.mjs +0 -203
- package/utils/icon-map.mjs +0 -26
- package/utils/image-compress.mjs +0 -154
- package/utils/kroki-utils.mjs +0 -173
- package/utils/linter/index.mjs +0 -50
- package/utils/load-config.mjs +0 -78
- package/utils/markdown/index.mjs +0 -26
- package/utils/markdown-checker.mjs +0 -694
- package/utils/mermaid-validator.mjs +0 -140
- package/utils/mermaid-worker-pool.mjs +0 -250
- package/utils/mermaid-worker.mjs +0 -233
- package/utils/openapi/index.mjs +0 -28
- package/utils/preferences-utils.mjs +0 -175
- package/utils/request.mjs +0 -10
- package/utils/sync-diagram-to-translations.mjs +0 -272
- package/utils/translate-diagram-images.mjs +0 -807
- package/utils/utils.mjs +0 -1354
- /package/{prompts/translate → agents/localize/prompts}/glossary.md +0 -0
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { DOC_ACTION } from "../../utils/constants/index.mjs";
|
|
2
|
-
import {
|
|
3
|
-
fileNameToFlatPath,
|
|
4
|
-
findItemByFlatName,
|
|
5
|
-
findItemByPath as findItemByPathUtil,
|
|
6
|
-
getActionText,
|
|
7
|
-
getMainLanguageFiles,
|
|
8
|
-
readFileContent,
|
|
9
|
-
} from "../../utils/docs-finder-utils.mjs";
|
|
10
|
-
|
|
11
|
-
export default async function findItemByPath(
|
|
12
|
-
{ doc, documentStructure, boardId, docsDir, isTranslate, feedback, locale },
|
|
13
|
-
options,
|
|
14
|
-
) {
|
|
15
|
-
let foundItem = null;
|
|
16
|
-
let selectedFileContent = null;
|
|
17
|
-
let docPath = doc;
|
|
18
|
-
const docAction = isTranslate ? DOC_ACTION.translate : DOC_ACTION.update;
|
|
19
|
-
|
|
20
|
-
// If docPath is empty, let user select from available documents
|
|
21
|
-
if (!docPath) {
|
|
22
|
-
try {
|
|
23
|
-
// Get all main language .md files in docsDir
|
|
24
|
-
const mainLanguageFiles = await getMainLanguageFiles(docsDir, locale, documentStructure);
|
|
25
|
-
|
|
26
|
-
if (mainLanguageFiles.length === 0) {
|
|
27
|
-
throw new Error("No documents found in the docs directory");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Let user select a file
|
|
31
|
-
const selectedFile = await options.prompts.search({
|
|
32
|
-
message: getActionText("Select a document to {action}:", docAction),
|
|
33
|
-
source: async (input) => {
|
|
34
|
-
if (!input || input.trim() === "") {
|
|
35
|
-
return mainLanguageFiles.map((file) => ({
|
|
36
|
-
name: file,
|
|
37
|
-
value: file,
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const searchTerm = input.trim().toLowerCase();
|
|
42
|
-
const filteredFiles = mainLanguageFiles.filter((file) =>
|
|
43
|
-
file.toLowerCase().includes(searchTerm),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return filteredFiles.map((file) => ({
|
|
47
|
-
name: file,
|
|
48
|
-
value: file,
|
|
49
|
-
}));
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (!selectedFile) {
|
|
54
|
-
throw new Error("No document selected");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Read the selected .md file content
|
|
58
|
-
selectedFileContent = await readFileContent(docsDir, selectedFile);
|
|
59
|
-
|
|
60
|
-
// Convert filename back to path
|
|
61
|
-
const flatName = fileNameToFlatPath(selectedFile);
|
|
62
|
-
|
|
63
|
-
// Try to find matching item by comparing flattened paths
|
|
64
|
-
const foundItemByFile = findItemByFlatName(documentStructure, flatName);
|
|
65
|
-
|
|
66
|
-
if (!foundItemByFile) {
|
|
67
|
-
throw new Error("No document found");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
docPath = foundItemByFile.path;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.debug(error?.message);
|
|
73
|
-
throw new Error(
|
|
74
|
-
getActionText(
|
|
75
|
-
"Please run 'aigne doc create' first to create documents, then select which document to {action}",
|
|
76
|
-
docAction,
|
|
77
|
-
),
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Use the utility function to find item and read content
|
|
83
|
-
foundItem = await findItemByPathUtil(documentStructure, docPath, boardId, docsDir, locale);
|
|
84
|
-
|
|
85
|
-
if (!foundItem) {
|
|
86
|
-
throw new Error(`Item with path "${docPath}" not found in documentStructure`);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Prompt for feedback if not provided
|
|
90
|
-
let userFeedback = feedback;
|
|
91
|
-
if (!userFeedback) {
|
|
92
|
-
const feedbackMessage = "How should we improve this document? (press Enter to skip):";
|
|
93
|
-
userFeedback = await options.prompts.input({
|
|
94
|
-
message: feedbackMessage,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Merge the found item and ensure content is available
|
|
99
|
-
const result = {
|
|
100
|
-
...foundItem,
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Add content if we read it from user selection (takes precedence over utility method content)
|
|
104
|
-
if (selectedFileContent !== null) {
|
|
105
|
-
result.content = selectedFileContent;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Add feedback to result if provided
|
|
109
|
-
if (userFeedback?.trim()) {
|
|
110
|
-
result.feedback = userFeedback.trim();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { getActiveRulesForScope } from "../../utils/preferences-utils.mjs";
|
|
2
|
-
|
|
3
|
-
export default async function findUserPreferencesByPath({ path, scope }) {
|
|
4
|
-
// Get global rules (always applicable)
|
|
5
|
-
const globalRules = getActiveRulesForScope("global", []);
|
|
6
|
-
|
|
7
|
-
// Get scope-specific rules (document/translation based on scope parameter)
|
|
8
|
-
const scopeRules = getActiveRulesForScope(scope, path ? [path] : []);
|
|
9
|
-
|
|
10
|
-
// Combine all applicable rules
|
|
11
|
-
const allApplicableRules = [...globalRules, ...scopeRules];
|
|
12
|
-
|
|
13
|
-
// Extract only rule text and join with double newlines
|
|
14
|
-
const ruleTexts = allApplicableRules.map((rule) => rule.rule);
|
|
15
|
-
const userPreferences = ruleTexts.length > 0 ? ruleTexts.join("\n\n") : "";
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
userPreferences,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
findUserPreferencesByPath.input_schema = {
|
|
23
|
-
type: "object",
|
|
24
|
-
properties: {
|
|
25
|
-
path: {
|
|
26
|
-
type: "string",
|
|
27
|
-
description: "Document path to find preferences for",
|
|
28
|
-
},
|
|
29
|
-
scope: {
|
|
30
|
-
type: "string",
|
|
31
|
-
description:
|
|
32
|
-
"Preference scope: 'document' for update operations, 'translation' for translate operations",
|
|
33
|
-
enum: ["document", "translation"],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
required: ["scope"],
|
|
37
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { stringify } from "yaml";
|
|
2
|
-
|
|
3
|
-
export default async function formatDocumentStructure({
|
|
4
|
-
documentStructure,
|
|
5
|
-
originalDocumentStructure,
|
|
6
|
-
}) {
|
|
7
|
-
if (!documentStructure && !originalDocumentStructure) {
|
|
8
|
-
return {
|
|
9
|
-
documentStructureYaml: "",
|
|
10
|
-
documentStructure: [],
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Extract required fields from each item in documentStructure
|
|
15
|
-
const formattedData = (documentStructure || originalDocumentStructure)?.map((item) => ({
|
|
16
|
-
title: item.title,
|
|
17
|
-
path: item.path,
|
|
18
|
-
parentId: item.parentId,
|
|
19
|
-
description: item.description,
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
// Convert to YAML string
|
|
23
|
-
const yamlString = stringify(formattedData, {
|
|
24
|
-
indent: 2,
|
|
25
|
-
lineWidth: 120,
|
|
26
|
-
minContentWidth: 20,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
documentStructureYaml: yamlString,
|
|
31
|
-
documentStructure,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
formatDocumentStructure.task_render_mode = "hide";
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conditionally call generateDocument. If we already have content for diagram-only intents,
|
|
3
|
-
* skip LLM generation and pass through the existing content.
|
|
4
|
-
*/
|
|
5
|
-
export default async function generateDocumentOrSkip(input, options) {
|
|
6
|
-
const { intentType, content, skipGenerateDocument } = input;
|
|
7
|
-
|
|
8
|
-
const isDiagramIntent =
|
|
9
|
-
intentType && ["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType);
|
|
10
|
-
const shouldSkip = Boolean(skipGenerateDocument || (isDiagramIntent && content));
|
|
11
|
-
|
|
12
|
-
if (shouldSkip) {
|
|
13
|
-
// Return the existing content and mark the generation as skipped
|
|
14
|
-
return {
|
|
15
|
-
...input,
|
|
16
|
-
content,
|
|
17
|
-
documentContent: content,
|
|
18
|
-
originalContent: content,
|
|
19
|
-
reviewContent: content,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const generateAgent = options.context?.agents?.["generateDocument"];
|
|
24
|
-
if (!generateAgent) {
|
|
25
|
-
throw new Error("generateDocument agent not found");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const result = await options.context.invoke(generateAgent, input);
|
|
29
|
-
const generatedContent = result?.content ?? result;
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
...input,
|
|
33
|
-
...result,
|
|
34
|
-
content: generatedContent,
|
|
35
|
-
documentContent: generatedContent,
|
|
36
|
-
originalContent: generatedContent,
|
|
37
|
-
reviewContent: generatedContent,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
generateDocumentOrSkip.task_render_mode = "hide";
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { AIAgent } from "@aigne/core";
|
|
2
|
-
import { pick } from "@aigne/core/utils/type-utils.js";
|
|
3
|
-
import z from "zod";
|
|
4
|
-
import {
|
|
5
|
-
DIAGRAM_PLACEHOLDER,
|
|
6
|
-
replaceD2WithPlaceholder,
|
|
7
|
-
replaceDiagramsWithPlaceholder,
|
|
8
|
-
} from "../../utils/d2-utils.mjs";
|
|
9
|
-
import { readFileContent } from "../../utils/docs-finder-utils.mjs";
|
|
10
|
-
import { getFileName, userContextAt } from "../../utils/utils.mjs";
|
|
11
|
-
import { debug } from "../../utils/debug.mjs";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Read current document content from file system
|
|
15
|
-
* Reuses the same logic as initCurrentContent but returns the content
|
|
16
|
-
* First checks userContext, then reads from file if not in context
|
|
17
|
-
*/
|
|
18
|
-
async function readCurrentContent(input, options) {
|
|
19
|
-
const { path, docsDir, locale = "en" } = input;
|
|
20
|
-
|
|
21
|
-
if (!path || !docsDir) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// First check if content is already in userContext
|
|
26
|
-
const contentContext = userContextAt(options, `currentContents.${path}`);
|
|
27
|
-
const existingContent = contentContext.get();
|
|
28
|
-
if (existingContent) {
|
|
29
|
-
return existingContent;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// If not in context, read from file (same logic as initCurrentContent)
|
|
33
|
-
try {
|
|
34
|
-
const fileName = getFileName(path, locale);
|
|
35
|
-
const content = await readFileContent(docsDir, fileName);
|
|
36
|
-
|
|
37
|
-
if (!content) {
|
|
38
|
-
console.warn(`⚠️ Could not read content from ${fileName}`);
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Set in userContext for future use
|
|
43
|
-
contentContext.set(content);
|
|
44
|
-
|
|
45
|
-
return content;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.warn(`Failed to read current content for ${path}: ${error.message}`);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Save document content
|
|
54
|
-
*/
|
|
55
|
-
async function saveDoc(input, options, { content, intentType }) {
|
|
56
|
-
const saveAgent = options.context?.agents?.["saveDoc"];
|
|
57
|
-
if (!saveAgent) {
|
|
58
|
-
console.warn("saveDoc agent not found");
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
await options.context.invoke(saveAgent, {
|
|
62
|
-
...pick(input, ["path", "docsDir", "labels", "locale"]),
|
|
63
|
-
content,
|
|
64
|
-
intentType, // Pass intentType so saveDoc can handle translation sync
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Handle addDiagram intent
|
|
70
|
-
*/
|
|
71
|
-
async function addDiagram(input, options) {
|
|
72
|
-
// readCurrentContent will check userContext first, then read from file if needed
|
|
73
|
-
const currentContent = await readCurrentContent(input, options);
|
|
74
|
-
if (!currentContent) {
|
|
75
|
-
throw new Error(`Could not read current content for ${input.path}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
79
|
-
|
|
80
|
-
const generateDiagramAgent = options.context.agents["checkGenerateDiagram"];
|
|
81
|
-
if (!generateDiagramAgent) {
|
|
82
|
-
throw new Error("checkGenerateDiagram agent not found");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const generateDiagramResult = await options.context.invoke(generateDiagramAgent, {
|
|
86
|
-
...pick(input, ["locale", "diagramming", "feedback", "path", "docsDir"]),
|
|
87
|
-
documentContent: currentContent,
|
|
88
|
-
originalContent: currentContent,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const content = generateDiagramResult.content;
|
|
92
|
-
contentContext.set(content);
|
|
93
|
-
// Pass intentType to saveDoc so it can handle translation sync automatically
|
|
94
|
-
await saveDoc(input, options, { content, intentType: "addDiagram" });
|
|
95
|
-
return { content };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Handle updateDiagram intent
|
|
100
|
-
*/
|
|
101
|
-
async function updateDiagram(input, options) {
|
|
102
|
-
// readCurrentContent will check userContext first, then read from file if needed
|
|
103
|
-
const currentContent = await readCurrentContent(input, options);
|
|
104
|
-
if (!currentContent) {
|
|
105
|
-
throw new Error(`Could not read current content for ${input.path}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
109
|
-
|
|
110
|
-
let [content] = replaceD2WithPlaceholder({
|
|
111
|
-
content: currentContent,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const generateAgent = options.context?.agents?.["generateDiagram"];
|
|
115
|
-
if (!generateAgent) {
|
|
116
|
-
throw new Error("generateDiagram agent not found");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const result = await options.context.invoke(generateAgent, {
|
|
120
|
-
documentContent: content,
|
|
121
|
-
locale: input.locale,
|
|
122
|
-
diagramming: input.diagramming || {},
|
|
123
|
-
feedback: input.feedback,
|
|
124
|
-
originalContent: currentContent, // Pass original content to find existing diagrams
|
|
125
|
-
path: input.path,
|
|
126
|
-
docsDir: input.docsDir,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// generateDiagram now returns { content } with image already inserted
|
|
130
|
-
// The image replaces DIAGRAM_PLACEHOLDER or D2 code blocks
|
|
131
|
-
if (result?.content) {
|
|
132
|
-
content = result.content;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
contentContext.set(content);
|
|
136
|
-
// Pass intentType to saveDoc so it can handle translation sync automatically
|
|
137
|
-
await saveDoc(input, options, { content, intentType: "updateDiagram" });
|
|
138
|
-
return { content };
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Handle deleteDiagram intent
|
|
143
|
-
*/
|
|
144
|
-
async function deleteDiagram(input, options) {
|
|
145
|
-
// readCurrentContent will check userContext first, then read from file if needed
|
|
146
|
-
const currentContent = await readCurrentContent(input, options);
|
|
147
|
-
if (!currentContent) {
|
|
148
|
-
throw new Error(`Could not read current content for ${input.path}`);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const contentContext = userContextAt(options, `currentContents.${input.path}`);
|
|
152
|
-
|
|
153
|
-
// Extract diagram index from feedback if provided
|
|
154
|
-
// This allows deleting a specific diagram when multiple diagrams exist
|
|
155
|
-
let diagramIndex = input.diagramIndex;
|
|
156
|
-
if (diagramIndex === undefined && input.feedback) {
|
|
157
|
-
// Import extractDiagramIndexFromFeedback from replace-d2-with-image.mjs
|
|
158
|
-
const { extractDiagramIndexFromFeedback } = await import("../create/replace-d2-with-image.mjs");
|
|
159
|
-
const extractedIndex = extractDiagramIndexFromFeedback(input.feedback);
|
|
160
|
-
if (extractedIndex !== null) {
|
|
161
|
-
diagramIndex = extractedIndex;
|
|
162
|
-
debug(`Extracted diagram index ${diagramIndex} from feedback: "${input.feedback}"`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Replace all diagrams (D2 code blocks, generated images, Mermaid) with placeholder
|
|
167
|
-
// If diagramIndex is provided, only replace that specific diagram
|
|
168
|
-
// This ensures LLM can identify and remove the diagram regardless of its type
|
|
169
|
-
const documentContent = replaceDiagramsWithPlaceholder({
|
|
170
|
-
content: currentContent,
|
|
171
|
-
diagramIndex,
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const instructions = `<role>
|
|
175
|
-
Your task is to remove ${DIAGRAM_PLACEHOLDER} and adjust the document context (based on the user's feedback) to make it easier to understand.
|
|
176
|
-
</role>
|
|
177
|
-
|
|
178
|
-
<document_content>
|
|
179
|
-
{{documentContent}}
|
|
180
|
-
</document_content>
|
|
181
|
-
|
|
182
|
-
<user_feedback>
|
|
183
|
-
{{feedback}}
|
|
184
|
-
</user_feedback>
|
|
185
|
-
|
|
186
|
-
<output_constraints>
|
|
187
|
-
- Do not provide any explanations; include only the document content itself
|
|
188
|
-
</output_constraints>`;
|
|
189
|
-
|
|
190
|
-
const deleteAgent = AIAgent.from({
|
|
191
|
-
name: "deleteDiagram",
|
|
192
|
-
description: "Remove a diagram from the document content",
|
|
193
|
-
task_render_mode: "hide",
|
|
194
|
-
instructions,
|
|
195
|
-
inputSchema: z.object({
|
|
196
|
-
documentContent: z.string().describe("Source content of the document"),
|
|
197
|
-
feedback: z.string().describe("User feedback for content modifications"),
|
|
198
|
-
}),
|
|
199
|
-
outputKey: "message",
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
const { message: content } = await options.context.invoke(deleteAgent, {
|
|
203
|
-
documentContent,
|
|
204
|
-
feedback: input.feedback,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// Delete associated diagram image files
|
|
208
|
-
if (input.docsDir) {
|
|
209
|
-
try {
|
|
210
|
-
const { deleteDiagramImages } = await import("../../utils/delete-diagram-images.mjs");
|
|
211
|
-
const { deleted } = await deleteDiagramImages(currentContent, input.path, input.docsDir);
|
|
212
|
-
if (deleted > 0) {
|
|
213
|
-
debug(`Deleted ${deleted} diagram image file(s) for ${input.path}`);
|
|
214
|
-
}
|
|
215
|
-
} catch (error) {
|
|
216
|
-
// Don't fail the operation if image deletion fails
|
|
217
|
-
console.warn(`Failed to delete diagram images: ${error.message}`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
contentContext.set(content);
|
|
222
|
-
// Pass intentType to saveDoc so it can handle translation sync automatically
|
|
223
|
-
await saveDoc(input, options, { content, intentType: "deleteDiagram" });
|
|
224
|
-
|
|
225
|
-
return { content };
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Handle diagram operations based on intent type
|
|
230
|
-
* Supports: addDiagram, updateDiagram, deleteDiagram
|
|
231
|
-
*/
|
|
232
|
-
export default async function handleDiagramOperations(
|
|
233
|
-
{ intentType, path, docsDir, locale, feedback, diagramming, labels },
|
|
234
|
-
options,
|
|
235
|
-
) {
|
|
236
|
-
if (!intentType || !["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType)) {
|
|
237
|
-
throw new Error(`Invalid intent type for diagram operations: ${intentType}`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const input = {
|
|
241
|
-
path,
|
|
242
|
-
docsDir,
|
|
243
|
-
locale,
|
|
244
|
-
feedback,
|
|
245
|
-
diagramming,
|
|
246
|
-
labels,
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const fnMap = {
|
|
250
|
-
addDiagram,
|
|
251
|
-
updateDiagram,
|
|
252
|
-
deleteDiagram,
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
if (fnMap[intentType]) {
|
|
256
|
-
const result = await fnMap[intentType](input, options);
|
|
257
|
-
return result;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
throw new Error(`Unsupported intent type: ${intentType}`);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
handleDiagramOperations.task_render_mode = "hide";
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import pMap from "p-map";
|
|
2
|
-
import { findItemByPath } from "../../utils/docs-finder-utils.mjs";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Loads all document content from the file system based on the provided document structure.
|
|
6
|
-
*
|
|
7
|
-
* @async
|
|
8
|
-
* @function loadAllDocumentContent
|
|
9
|
-
* @param {Object} params - The parameters object
|
|
10
|
-
* @param {string} params.docsDir - The root directory path where documents are located
|
|
11
|
-
* @param {Array<Object>} params.documentStructure - The document structure array containing items with path information
|
|
12
|
-
* @param {string} params.documentStructure[].path - The file path of each document item
|
|
13
|
-
* @returns {Promise<Array>} returns.allDocumentContentList - An array of document content items loaded from the file system
|
|
14
|
-
* @example
|
|
15
|
-
* const result = await loadAllDocumentContent({
|
|
16
|
-
* docsDir: './docs',
|
|
17
|
-
* documentStructure: [{ path: 'readme.md' }, { path: 'guide.md' }]
|
|
18
|
-
* });
|
|
19
|
-
*/
|
|
20
|
-
export default async function loadAllDocumentContent({ docsDir, documentStructure = [] }) {
|
|
21
|
-
const allDocumentContentList = await pMap(documentStructure, async (item) => {
|
|
22
|
-
const itemResult = await findItemByPath(documentStructure, item.path, null, docsDir);
|
|
23
|
-
return itemResult;
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
allDocumentContentList,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
loadAllDocumentContent.taskRenderMode = "hide";
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { readdirSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { findItemByPath, readFileContent } from "../../utils/docs-finder-utils.mjs";
|
|
4
|
-
import { pathExists } from "../../utils/file-utils.mjs";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Loads a document's content along with all its translations from the docs directory.
|
|
8
|
-
*
|
|
9
|
-
* This function finds a document by its path in the documentation structure, then searches
|
|
10
|
-
* for all translation files in the docs directory that match the document's naming pattern.
|
|
11
|
-
* Translation files are identified by the pattern: {flatName}.{language-code}.md
|
|
12
|
-
*
|
|
13
|
-
* @param {Object} params - The parameters object
|
|
14
|
-
* @param {string} params.path - The document path to find in the structure
|
|
15
|
-
* @param {string} params.docsDir - The directory containing document files and translations
|
|
16
|
-
* @param {Object} params.documentStructure - The documentation structure object to search in
|
|
17
|
-
* @returns {Promise<Object>} An object containing the document data with translations
|
|
18
|
-
* @throws {Error} Throws an error if the document path is not found in the structure
|
|
19
|
-
*/
|
|
20
|
-
export default async function loadDocumentAllContent({ path, docsDir, documentStructure }) {
|
|
21
|
-
// Find the document item by path in the documentation structure
|
|
22
|
-
const result = await findItemByPath(documentStructure, path, null, docsDir);
|
|
23
|
-
|
|
24
|
-
if (!result) {
|
|
25
|
-
throw new Error(`Document with path "${path}" not found in documentStructure`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Convert path to flat filename format (remove leading slash, replace slashes with dashes)
|
|
29
|
-
// e.g., "/api/users" becomes "api-users"
|
|
30
|
-
const flatName = result.path.replace(/^\//, "").replace(/\//g, "-");
|
|
31
|
-
|
|
32
|
-
// Arrays to store translation data in different formats
|
|
33
|
-
const translations = [];
|
|
34
|
-
const translationsString = [];
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
// Read all files in the docs directory
|
|
38
|
-
const files = readdirSync(docsDir);
|
|
39
|
-
|
|
40
|
-
// Filter files to find translation files matching the pattern:
|
|
41
|
-
// - Starts with the flat name
|
|
42
|
-
// - Ends with .md
|
|
43
|
-
// - Is not the main document file (flatName.md)
|
|
44
|
-
// - Matches language pattern: .{language-code}.md (e.g., .en.md, .zh-CN.md)
|
|
45
|
-
const translationFiles = files.filter(
|
|
46
|
-
(file) =>
|
|
47
|
-
file.startsWith(`${flatName}.`) &&
|
|
48
|
-
file.endsWith(".md") &&
|
|
49
|
-
file !== `${flatName}.md` &&
|
|
50
|
-
file.match(/\.\w+(-\w+)?\.md$/),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// Process each translation file
|
|
54
|
-
// Note: translationFiles are already filtered by readdirSync, but we check existence again for safety
|
|
55
|
-
for (const file of translationFiles) {
|
|
56
|
-
const filePath = join(docsDir, file);
|
|
57
|
-
|
|
58
|
-
// Check if file exists before reading to avoid unnecessary warnings
|
|
59
|
-
// (though readdirSync should already filter existing files)
|
|
60
|
-
const fileExists = await pathExists(filePath);
|
|
61
|
-
if (!fileExists) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const content = await readFileContent(docsDir, file);
|
|
66
|
-
if (content) {
|
|
67
|
-
// Extract language code from filename (e.g., "en" from "doc.en.md" or "zh-CN" from "doc.zh-CN.md")
|
|
68
|
-
const langMatch = file.match(/\.(\w+(-\w+)?)\.md$/);
|
|
69
|
-
if (langMatch) {
|
|
70
|
-
const language = langMatch[1];
|
|
71
|
-
// Store translation in structured format
|
|
72
|
-
translations.push({
|
|
73
|
-
language,
|
|
74
|
-
translation: content,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Store translation in XML-like string format for prompt templates
|
|
78
|
-
translationsString.push(`<${language}>\n${content}\n</${language}>`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.warn(`⚠️ Could not read translation files from ${docsDir}:`, error.message);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Return the original document result enhanced with translation data
|
|
87
|
-
return {
|
|
88
|
-
...result,
|
|
89
|
-
// FIXME: @zhanghan use anthoer way to evaluate translationQuality
|
|
90
|
-
// translates: translations, // Array of translation objects with language and content
|
|
91
|
-
translationsString: translationsString.join("\n\n"), // Combined translations as formatted string
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Hide this function from task rendering in the UI
|
|
96
|
-
loadDocumentAllContent.taskRenderMode = "hide";
|