@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
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { ERROR_CODES } from "../../../utils/agent-constants.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prepare input parameters for image translation
|
|
6
|
+
* @param {Object} input - Input parameters (single task from translationTasks)
|
|
7
|
+
* @param {string} input.key - Image key
|
|
8
|
+
* @param {string} input.desc - Image description
|
|
9
|
+
* @param {string} input.assetDir - Image asset directory
|
|
10
|
+
* @param {string} input.sourceImagePath - Source image path
|
|
11
|
+
* @param {string} input.sourceHash - Source image hash
|
|
12
|
+
* @param {string} input.aspectRatio - Aspect ratio
|
|
13
|
+
* @param {string} input.size - Image size
|
|
14
|
+
* @param {string} input.sourceLanguage - Source language (from parent)
|
|
15
|
+
* @param {string} input.targetLanguage - Target language (from parent)
|
|
16
|
+
* @returns {Promise<Object>} - Prepared input parameters
|
|
17
|
+
*/
|
|
18
|
+
export default async function prepareImageInput(input) {
|
|
19
|
+
const {
|
|
20
|
+
key,
|
|
21
|
+
desc,
|
|
22
|
+
assetDir,
|
|
23
|
+
sourceImagePath,
|
|
24
|
+
sourceHash,
|
|
25
|
+
aspectRatio,
|
|
26
|
+
size,
|
|
27
|
+
sourceLanguage,
|
|
28
|
+
targetLanguage,
|
|
29
|
+
} = input;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Prepare existingImage parameter (mediaFile format)
|
|
33
|
+
const existingImage = [
|
|
34
|
+
{
|
|
35
|
+
type: "local",
|
|
36
|
+
path: sourceImagePath,
|
|
37
|
+
filename: basename(sourceImagePath),
|
|
38
|
+
mimeType: sourceImagePath.endsWith(".png") ? "image/png" : "image/jpeg",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
// Parameters for translate-image.yaml
|
|
45
|
+
existingImage,
|
|
46
|
+
desc,
|
|
47
|
+
sourceLanguage,
|
|
48
|
+
targetLocale: targetLanguage,
|
|
49
|
+
ratio: aspectRatio,
|
|
50
|
+
size,
|
|
51
|
+
// Parameters for save-image-translation.mjs
|
|
52
|
+
key,
|
|
53
|
+
assetDir,
|
|
54
|
+
targetLanguage,
|
|
55
|
+
sourceHash,
|
|
56
|
+
message: `Preparing image translation: ${key} (${sourceLanguage} → ${targetLanguage})`,
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
error: ERROR_CODES.UNEXPECTED_ERROR,
|
|
62
|
+
message: `Error preparing image translation input: ${error.message}`,
|
|
63
|
+
key,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Add description
|
|
69
|
+
prepareImageInput.description =
|
|
70
|
+
"Prepare input parameters for image translation, converting translation tasks to the format required by translate-image.yaml. " +
|
|
71
|
+
"Build sourceImage mediaFile object array and pass necessary parameters.";
|
|
72
|
+
|
|
73
|
+
// Define input schema
|
|
74
|
+
prepareImageInput.input_schema = {
|
|
75
|
+
type: "object",
|
|
76
|
+
required: [
|
|
77
|
+
"key",
|
|
78
|
+
"desc",
|
|
79
|
+
"assetDir",
|
|
80
|
+
"sourceImagePath",
|
|
81
|
+
"sourceHash",
|
|
82
|
+
"aspectRatio",
|
|
83
|
+
"size",
|
|
84
|
+
"sourceLanguage",
|
|
85
|
+
"targetLanguage",
|
|
86
|
+
],
|
|
87
|
+
properties: {
|
|
88
|
+
key: { type: "string", description: "Image key" },
|
|
89
|
+
desc: { type: "string", description: "Image description" },
|
|
90
|
+
assetDir: { type: "string", description: "Image asset directory" },
|
|
91
|
+
sourceImagePath: { type: "string", description: "Source image path" },
|
|
92
|
+
sourceHash: { type: "string", description: "Source image hash" },
|
|
93
|
+
aspectRatio: { type: "string", description: "Aspect ratio" },
|
|
94
|
+
size: { type: "string", description: "Image size" },
|
|
95
|
+
sourceLanguage: { type: "string", description: "Source language code" },
|
|
96
|
+
targetLanguage: { type: "string", description: "Target language code" },
|
|
97
|
+
reason: { type: "string", description: "Translation reason" },
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Define output schema
|
|
102
|
+
prepareImageInput.output_schema = {
|
|
103
|
+
type: "object",
|
|
104
|
+
required: ["success"],
|
|
105
|
+
properties: {
|
|
106
|
+
success: { type: "boolean", description: "Whether operation succeeded" },
|
|
107
|
+
existingImage: {
|
|
108
|
+
type: "array",
|
|
109
|
+
description: "Source image mediaFile object array",
|
|
110
|
+
items: { type: "object" },
|
|
111
|
+
},
|
|
112
|
+
desc: { type: "string", description: "Image description" },
|
|
113
|
+
sourceLanguage: { type: "string", description: "Source language code" },
|
|
114
|
+
targetLocale: { type: "string", description: "Target language code" },
|
|
115
|
+
ratio: { type: "string", description: "Aspect ratio" },
|
|
116
|
+
size: { type: "string", description: "Image size" },
|
|
117
|
+
key: { type: "string", description: "Image key" },
|
|
118
|
+
assetDir: { type: "string", description: "Image asset directory" },
|
|
119
|
+
targetLanguage: { type: "string", description: "Target language code" },
|
|
120
|
+
sourceHash: { type: "string", description: "Source image hash" },
|
|
121
|
+
message: { type: "string", description: "Operation result description" },
|
|
122
|
+
error: { type: "string", description: "Error code (present on failure)" },
|
|
123
|
+
},
|
|
124
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { readFile, writeFile, copyFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { parse as yamlParse, stringify as yamlStringify } from "yaml";
|
|
4
|
+
import { ERROR_CODES } from "../../../utils/agent-constants.mjs";
|
|
5
|
+
import { getExtensionFromMimeType } from "../../../utils/image-utils.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Save translated image and update .meta.yaml
|
|
9
|
+
* @param {Object} input - Input parameters
|
|
10
|
+
* @param {string} input.key - Image key
|
|
11
|
+
* @param {string} input.assetDir - Image asset directory
|
|
12
|
+
* @param {string} input.targetLanguage - Target language
|
|
13
|
+
* @param {string} input.sourceHash - Source image hash
|
|
14
|
+
* @param {Array} input.images - Image translation result (from translate-image.yaml)
|
|
15
|
+
* @returns {Promise<Object>} - Operation result
|
|
16
|
+
*/
|
|
17
|
+
export default async function saveImageTranslation(input) {
|
|
18
|
+
const { key, assetDir, targetLanguage, sourceHash, images } = input;
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
// 1. Validate image data
|
|
22
|
+
// Format: [{ filename, mimeType, type, path }, ...]
|
|
23
|
+
if (!images || !Array.isArray(images) || images.length === 0) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
key,
|
|
27
|
+
error: "GENERATION_FAILED",
|
|
28
|
+
message: "Translated image data not found",
|
|
29
|
+
suggestion:
|
|
30
|
+
"Check the output format of the image translation agent, expecting images array",
|
|
31
|
+
availableKeys: Object.keys(input),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Use the first image
|
|
36
|
+
const imageInfo = images[0];
|
|
37
|
+
if (!imageInfo.path) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
key,
|
|
41
|
+
error: "INVALID_IMAGE_DATA",
|
|
42
|
+
message: "Image data missing path field",
|
|
43
|
+
suggestion: "Check the images format returned by the image translation agent",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 2. Determine target file path
|
|
48
|
+
const ext = getExtensionFromMimeType(imageInfo.mimeType);
|
|
49
|
+
const targetImagePath = join(assetDir, "images", `${targetLanguage}.${ext}`);
|
|
50
|
+
|
|
51
|
+
// Ensure directory exists
|
|
52
|
+
await mkdir(dirname(targetImagePath), { recursive: true });
|
|
53
|
+
|
|
54
|
+
// 3. Copy from temporary file to target location
|
|
55
|
+
await copyFile(imageInfo.path, targetImagePath);
|
|
56
|
+
|
|
57
|
+
// 4. Update .meta.yaml
|
|
58
|
+
const metaPath = join(assetDir, ".meta.yaml");
|
|
59
|
+
const metaContent = await readFile(metaPath, "utf8");
|
|
60
|
+
const meta = yamlParse(metaContent);
|
|
61
|
+
|
|
62
|
+
// 4.1 Add target language to languages array
|
|
63
|
+
if (!meta.languages || !Array.isArray(meta.languages)) {
|
|
64
|
+
meta.languages = [];
|
|
65
|
+
}
|
|
66
|
+
if (!meta.languages.includes(targetLanguage)) {
|
|
67
|
+
meta.languages.push(targetLanguage);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 4.2 Update translations info
|
|
71
|
+
if (!meta.translations) {
|
|
72
|
+
meta.translations = {};
|
|
73
|
+
}
|
|
74
|
+
meta.translations[targetLanguage] = {
|
|
75
|
+
sourceHash,
|
|
76
|
+
translatedAt: new Date().toISOString(),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// 5. Save updated .meta.yaml
|
|
80
|
+
const updatedMetaContent = yamlStringify(meta);
|
|
81
|
+
await writeFile(metaPath, updatedMetaContent, "utf8");
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
success: true,
|
|
85
|
+
key,
|
|
86
|
+
targetLanguage,
|
|
87
|
+
targetImagePath,
|
|
88
|
+
message: `Image translation saved: ${targetImagePath}`,
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: ERROR_CODES.SAVE_ERROR,
|
|
94
|
+
message: `Error saving image translation: ${error.message}`,
|
|
95
|
+
key,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Add description
|
|
101
|
+
saveImageTranslation.description =
|
|
102
|
+
"Save translated image to target path and update .meta.yaml file. " +
|
|
103
|
+
"Record source image hash and translation time for determining if re-translation is needed later.";
|
|
104
|
+
|
|
105
|
+
// Define input schema
|
|
106
|
+
saveImageTranslation.input_schema = {
|
|
107
|
+
type: "object",
|
|
108
|
+
required: ["key", "assetDir", "targetLanguage", "sourceHash", "images"],
|
|
109
|
+
properties: {
|
|
110
|
+
key: {
|
|
111
|
+
type: "string",
|
|
112
|
+
description: "Image key",
|
|
113
|
+
},
|
|
114
|
+
assetDir: {
|
|
115
|
+
type: "string",
|
|
116
|
+
description: "Image asset directory path",
|
|
117
|
+
},
|
|
118
|
+
targetLanguage: {
|
|
119
|
+
type: "string",
|
|
120
|
+
description: "Target language code",
|
|
121
|
+
},
|
|
122
|
+
sourceHash: {
|
|
123
|
+
type: "string",
|
|
124
|
+
description: "Source image hash",
|
|
125
|
+
},
|
|
126
|
+
images: {
|
|
127
|
+
type: "array",
|
|
128
|
+
description: "Image list returned by image translation agent",
|
|
129
|
+
items: {
|
|
130
|
+
type: "object",
|
|
131
|
+
properties: {
|
|
132
|
+
filename: { type: "string", description: "Filename" },
|
|
133
|
+
mimeType: { type: "string", description: "MIME type" },
|
|
134
|
+
type: { type: "string", description: "Type (local)" },
|
|
135
|
+
path: { type: "string", description: "Temporary file path" },
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Define output schema
|
|
143
|
+
saveImageTranslation.output_schema = {
|
|
144
|
+
type: "object",
|
|
145
|
+
required: ["success"],
|
|
146
|
+
properties: {
|
|
147
|
+
success: {
|
|
148
|
+
type: "boolean",
|
|
149
|
+
description: "Whether operation succeeded",
|
|
150
|
+
},
|
|
151
|
+
key: {
|
|
152
|
+
type: "string",
|
|
153
|
+
description: "Image key",
|
|
154
|
+
},
|
|
155
|
+
targetLanguage: {
|
|
156
|
+
type: "string",
|
|
157
|
+
description: "Target language code (present on success)",
|
|
158
|
+
},
|
|
159
|
+
targetImagePath: {
|
|
160
|
+
type: "string",
|
|
161
|
+
description: "Saved image path (present on success)",
|
|
162
|
+
},
|
|
163
|
+
message: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: "Operation result description",
|
|
166
|
+
},
|
|
167
|
+
error: {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "Error code (present on failure)",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parseSlots } from "../../../utils/image-slots.mjs";
|
|
5
|
+
import { PATHS, ERROR_CODES } from "../../../utils/agent-constants.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Scan image slots in document
|
|
9
|
+
* @param {Object} input - Input parameters
|
|
10
|
+
* @param {string} input.path - Document path
|
|
11
|
+
* @param {string} input.sourceLanguage - Source language code
|
|
12
|
+
* @param {string} input.language - Target language
|
|
13
|
+
* @returns {Promise<Object>} - Scan result
|
|
14
|
+
*/
|
|
15
|
+
export default async function scanDocImages(input) {
|
|
16
|
+
const { path: docPath, sourceLanguage, language } = input;
|
|
17
|
+
const targetLanguage = language;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
// 1. Build source document file path
|
|
21
|
+
const docFolder = path.join(PATHS.DOCS_DIR, docPath);
|
|
22
|
+
const sourceFile = path.join(docFolder, `${sourceLanguage}.md`);
|
|
23
|
+
|
|
24
|
+
// 2. Read source document content
|
|
25
|
+
let content;
|
|
26
|
+
try {
|
|
27
|
+
await access(sourceFile, constants.F_OK | constants.R_OK);
|
|
28
|
+
content = await readFile(sourceFile, "utf-8");
|
|
29
|
+
} catch (_error) {
|
|
30
|
+
throw new Error(`Source document does not exist: ${sourceFile}, document path: ${docPath}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 3. Parse slots in document
|
|
34
|
+
const slots = parseSlots(content, docPath);
|
|
35
|
+
|
|
36
|
+
if (slots.length === 0) {
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
hasSlots: false,
|
|
40
|
+
slots: [],
|
|
41
|
+
targetLanguage,
|
|
42
|
+
path: docPath,
|
|
43
|
+
message: `No image slots in document`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 4. Check source image info for each slot
|
|
48
|
+
const slotsWithInfo = [];
|
|
49
|
+
for (const slot of slots) {
|
|
50
|
+
const { key, desc } = slot;
|
|
51
|
+
|
|
52
|
+
// Check if image directory exists
|
|
53
|
+
const assetDir = path.join(PATHS.ASSETS_DIR, key);
|
|
54
|
+
const metaPath = path.join(assetDir, ".meta.yaml");
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
await access(metaPath, constants.F_OK | constants.R_OK);
|
|
58
|
+
|
|
59
|
+
slotsWithInfo.push({
|
|
60
|
+
key,
|
|
61
|
+
desc,
|
|
62
|
+
assetDir,
|
|
63
|
+
metaPath,
|
|
64
|
+
exists: true,
|
|
65
|
+
});
|
|
66
|
+
} catch (_error) {
|
|
67
|
+
// Image asset does not exist, skip
|
|
68
|
+
slotsWithInfo.push({
|
|
69
|
+
key,
|
|
70
|
+
desc,
|
|
71
|
+
assetDir: null,
|
|
72
|
+
metaPath: null,
|
|
73
|
+
exists: false,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
hasSlots: true,
|
|
81
|
+
slots: slotsWithInfo,
|
|
82
|
+
targetLanguage,
|
|
83
|
+
path: docPath,
|
|
84
|
+
message: `Found ${slots.length} image slots in document, ${slotsWithInfo.filter((s) => s.exists).length} have source images`,
|
|
85
|
+
};
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: ERROR_CODES.UNEXPECTED_ERROR,
|
|
90
|
+
message: `Error scanning document images: ${error.message}`,
|
|
91
|
+
path: docPath,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Add description
|
|
97
|
+
scanDocImages.description =
|
|
98
|
+
"Scan main language document content, extract AFS image slots, and check if corresponding image assets exist. " +
|
|
99
|
+
"Return list of images that need translation status check.";
|
|
100
|
+
|
|
101
|
+
// Define input schema
|
|
102
|
+
scanDocImages.input_schema = {
|
|
103
|
+
type: "object",
|
|
104
|
+
required: ["path", "sourceLanguage", "language"],
|
|
105
|
+
properties: {
|
|
106
|
+
path: {
|
|
107
|
+
type: "string",
|
|
108
|
+
description: "Document path",
|
|
109
|
+
},
|
|
110
|
+
sourceLanguage: {
|
|
111
|
+
type: "string",
|
|
112
|
+
description: "Source language code",
|
|
113
|
+
},
|
|
114
|
+
language: {
|
|
115
|
+
type: "string",
|
|
116
|
+
description: "Target language code",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// Define output schema
|
|
122
|
+
scanDocImages.output_schema = {
|
|
123
|
+
type: "object",
|
|
124
|
+
required: ["success"],
|
|
125
|
+
properties: {
|
|
126
|
+
success: {
|
|
127
|
+
type: "boolean",
|
|
128
|
+
description: "Whether operation succeeded",
|
|
129
|
+
},
|
|
130
|
+
hasSlots: {
|
|
131
|
+
type: "boolean",
|
|
132
|
+
description: "Whether document contains image slots",
|
|
133
|
+
},
|
|
134
|
+
slots: {
|
|
135
|
+
type: "array",
|
|
136
|
+
description: "Image slot list",
|
|
137
|
+
items: {
|
|
138
|
+
type: "object",
|
|
139
|
+
properties: {
|
|
140
|
+
key: { type: "string", description: "Image key" },
|
|
141
|
+
desc: { type: "string", description: "Image description" },
|
|
142
|
+
assetDir: { type: "string", description: "Image asset directory path", nullable: true },
|
|
143
|
+
metaPath: { type: "string", description: ".meta.yaml file path", nullable: true },
|
|
144
|
+
exists: { type: "boolean", description: "Whether image asset exists" },
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
targetLanguage: {
|
|
149
|
+
type: "string",
|
|
150
|
+
description: "Target language code",
|
|
151
|
+
},
|
|
152
|
+
path: {
|
|
153
|
+
type: "string",
|
|
154
|
+
description: "Document path",
|
|
155
|
+
},
|
|
156
|
+
message: {
|
|
157
|
+
type: "string",
|
|
158
|
+
description: "Operation result description",
|
|
159
|
+
},
|
|
160
|
+
error: {
|
|
161
|
+
type: "string",
|
|
162
|
+
description: "Error code (present on failure)",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type: team
|
|
2
|
+
name: translateDocImages
|
|
3
|
+
description: Detect images in document and translate to target language
|
|
4
|
+
skills:
|
|
5
|
+
- url: ./scan-doc-images.mjs # Scan image slots in document
|
|
6
|
+
- url: ./detect-text/detect-images-text.yaml # Detect if images contain text and update shared field
|
|
7
|
+
- url: ./check-image-translation.mjs # Check which images need translation
|
|
8
|
+
- type: team
|
|
9
|
+
name: processImageTranslations # Process all image translation tasks
|
|
10
|
+
skills:
|
|
11
|
+
- type: team
|
|
12
|
+
name: translateSingleImage
|
|
13
|
+
description: Translate a single image (from source language to target language)
|
|
14
|
+
skills:
|
|
15
|
+
- url: ./prepare-image-input.mjs # Prepare input parameters for image translation
|
|
16
|
+
- url: ./translate-image.yaml # Execute image translation
|
|
17
|
+
- url: ./save-image-translation.mjs # Save translation result
|
|
18
|
+
mode: sequential
|
|
19
|
+
include_input_in_output: true
|
|
20
|
+
|
|
21
|
+
iterate_on: translationTasks
|
|
22
|
+
concurrency: 1
|
|
23
|
+
mode: sequential
|
|
24
|
+
include_input_in_output: true
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
type: image
|
|
2
|
-
name:
|
|
2
|
+
name: translateSlotImage
|
|
3
|
+
description: Translate image to target language using image-to-image mode
|
|
3
4
|
image_model:
|
|
4
5
|
model: google/gemini-3-pro-image-preview
|
|
5
6
|
imageConfig:
|
|
@@ -11,16 +12,16 @@ image_model:
|
|
|
11
12
|
instructions: |
|
|
12
13
|
You are a multilingual diagram translator specializing in technical diagrams such as flowcharts, architecture diagrams, network topologies, and mind maps.
|
|
13
14
|
|
|
14
|
-
Your task is to regenerate the provided image by translating all label-style text into {{
|
|
15
|
+
Your task is to regenerate the provided image by translating all label-style text from {{sourceLanguage}} into {{targetLocale}}.
|
|
15
16
|
|
|
16
17
|
Requirements:
|
|
17
18
|
- Retain all command-style, technical, or protocol-specific terms (e.g., "API", "TCP/IP", "POST") in English;
|
|
18
|
-
- Maintain the original diagram
|
|
19
|
+
- Maintain the original diagram's structure, layout, visual style, and spatial relationships between elements;
|
|
19
20
|
- Only translate label or annotation text — all graphical elements should remain unchanged;
|
|
20
|
-
- **If {{
|
|
21
|
+
- **If {{targetLocale}} is Simplified Chinese, Traditional Chinese, Japanese, or Korean, use the font "Microsoft YaHei" (微软雅黑)** to ensure optimal readability, proper character rendering, and consistent typographic style across Latin and CJK scripts;
|
|
21
22
|
- For other languages, use a clean sans-serif font that best fits the visual style of the original image;
|
|
22
23
|
|
|
23
|
-
Your final output should be a regenerated image identical in design but localized in text according to {{
|
|
24
|
+
Your final output should be a regenerated image identical in design but localized in text according to {{targetLocale}}.
|
|
24
25
|
|
|
25
26
|
input_file_key: existingImage
|
|
26
27
|
|
|
@@ -29,7 +30,7 @@ input_schema:
|
|
|
29
30
|
properties:
|
|
30
31
|
existingImage:
|
|
31
32
|
type: array
|
|
32
|
-
description: Array of mediaFile objects for
|
|
33
|
+
description: Array of mediaFile objects for source language image (main language)
|
|
33
34
|
items:
|
|
34
35
|
type: object
|
|
35
36
|
properties:
|
|
@@ -44,19 +45,29 @@ input_schema:
|
|
|
44
45
|
description: Image filename
|
|
45
46
|
mimeType:
|
|
46
47
|
type: string
|
|
47
|
-
description: MIME type
|
|
48
|
+
description: MIME type (e.g., "image/png", "image/jpeg")
|
|
49
|
+
desc:
|
|
50
|
+
type: string
|
|
51
|
+
description: AFS slot description, explaining the image content
|
|
52
|
+
sourceLanguage:
|
|
53
|
+
type: string
|
|
54
|
+
description: Source language code (e.g., "zh", "en")
|
|
55
|
+
targetLocale:
|
|
56
|
+
type: string
|
|
57
|
+
description: Target language code
|
|
48
58
|
ratio:
|
|
49
59
|
type: string
|
|
50
|
-
description:
|
|
60
|
+
description: Image aspect ratio
|
|
61
|
+
enum: ["1:1", "5:4", "4:3", "3:2", "16:9", "21:9"]
|
|
62
|
+
default: "4:3"
|
|
51
63
|
size:
|
|
52
64
|
type: string
|
|
53
|
-
description:
|
|
54
|
-
default: "
|
|
55
|
-
locale:
|
|
56
|
-
type: string
|
|
57
|
-
description: Target language code for translation
|
|
65
|
+
description: Generated image size
|
|
66
|
+
default: "2K"
|
|
58
67
|
required:
|
|
59
68
|
- existingImage
|
|
69
|
+
- sourceLanguage
|
|
70
|
+
- targetLocale
|
|
60
71
|
- ratio
|
|
61
|
-
|
|
72
|
+
|
|
62
73
|
include_input_in_output: true
|