@aigne/doc-smith 0.9.7 → 0.9.8-beta.1
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 +20 -0
- package/agents/create/analyze-diagram-type-llm.yaml +160 -0
- package/agents/create/analyze-diagram-type.mjs +297 -0
- package/agents/create/generate-diagram-image.yaml +60 -0
- package/agents/create/replace-d2-with-image.mjs +625 -0
- package/agents/create/utils/init-current-content.mjs +5 -9
- package/agents/evaluate/document.yaml +6 -0
- package/agents/evaluate/index.yaml +1 -0
- package/agents/init/index.mjs +16 -0
- package/agents/media/batch-generate-media-description.yaml +2 -0
- package/agents/media/generate-media-description.yaml +3 -0
- package/agents/media/load-media-description.mjs +44 -15
- package/agents/publish/publish-docs.mjs +1 -4
- package/agents/update/check-diagram-flag.mjs +116 -0
- package/agents/update/check-document.mjs +0 -1
- package/agents/update/check-generate-diagram.mjs +48 -30
- package/agents/update/check-sync-image-flag.mjs +55 -0
- package/agents/update/check-update-is-single.mjs +11 -0
- package/agents/update/generate-diagram.yaml +43 -9
- package/agents/update/generate-document.yaml +9 -0
- package/agents/update/handle-document-update.yaml +10 -8
- package/agents/update/index.yaml +16 -1
- package/agents/update/sync-images-and-exit.mjs +148 -0
- package/agents/update/update-single/update-single-document-detail.mjs +131 -17
- package/agents/utils/analyze-feedback-intent.mjs +136 -0
- package/agents/utils/choose-docs.mjs +183 -40
- package/agents/utils/generate-document-or-skip.mjs +41 -0
- package/agents/utils/handle-diagram-operations.mjs +263 -0
- package/agents/utils/load-all-document-content.mjs +30 -0
- package/agents/utils/load-sources.mjs +2 -2
- package/agents/utils/read-current-document-content.mjs +46 -0
- package/agents/utils/save-doc-translation.mjs +34 -0
- package/agents/utils/save-doc.mjs +42 -0
- package/agents/utils/skip-if-content-exists.mjs +27 -0
- package/aigne.yaml +6 -1
- package/assets/report-template/report.html +17 -17
- package/docs-mcp/read-doc-content.mjs +30 -1
- package/package.json +4 -4
- package/prompts/detail/diagram/generate-image-system.md +135 -0
- package/prompts/detail/diagram/generate-image-user.md +32 -0
- package/prompts/detail/generate/user-prompt.md +27 -13
- package/prompts/evaluate/document.md +23 -10
- package/prompts/media/media-description/system-prompt.md +10 -2
- package/prompts/media/media-description/user-prompt.md +9 -0
- package/utils/check-document-has-diagram.mjs +95 -0
- package/utils/constants/index.mjs +46 -0
- package/utils/d2-utils.mjs +119 -178
- package/utils/delete-diagram-images.mjs +99 -0
- package/utils/docs-finder-utils.mjs +34 -1
- package/utils/image-compress.mjs +75 -0
- package/utils/kroki-utils.mjs +2 -3
- package/utils/sync-diagram-to-translations.mjs +262 -0
- package/utils/utils.mjs +24 -0
- package/agents/create/check-diagram.mjs +0 -40
- package/agents/create/draw-diagram.yaml +0 -27
- package/agents/create/merge-diagram.yaml +0 -39
- package/agents/create/wrap-diagram-code.mjs +0 -35
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { saveDocTranslation as _saveDocTranslation } from "../../utils/utils.mjs";
|
|
2
|
+
import { readFileContent } from "../../utils/docs-finder-utils.mjs";
|
|
3
|
+
import { getFileName } from "../../utils/utils.mjs";
|
|
4
|
+
import { debug } from "../../utils/debug.mjs";
|
|
5
|
+
import { syncDiagramToTranslations } from "../../utils/sync-diagram-to-translations.mjs";
|
|
2
6
|
|
|
3
7
|
export default async function saveDocTranslation({
|
|
4
8
|
path,
|
|
@@ -7,6 +11,7 @@ export default async function saveDocTranslation({
|
|
|
7
11
|
language,
|
|
8
12
|
labels,
|
|
9
13
|
isShowMessage = false,
|
|
14
|
+
locale,
|
|
10
15
|
}) {
|
|
11
16
|
await _saveDocTranslation({
|
|
12
17
|
path,
|
|
@@ -16,6 +21,35 @@ export default async function saveDocTranslation({
|
|
|
16
21
|
labels,
|
|
17
22
|
});
|
|
18
23
|
|
|
24
|
+
// Sync diagram images from main document to translations
|
|
25
|
+
// This ensures all images (including diagrams) in the main document are synced to translation files
|
|
26
|
+
if (path && docsDir && locale) {
|
|
27
|
+
try {
|
|
28
|
+
// Read main document content (it should already be saved)
|
|
29
|
+
const mainFileName = getFileName(path, locale);
|
|
30
|
+
const mainContent = await readFileContent(docsDir, mainFileName);
|
|
31
|
+
|
|
32
|
+
if (mainContent) {
|
|
33
|
+
const syncResult = await syncDiagramToTranslations(
|
|
34
|
+
mainContent,
|
|
35
|
+
path,
|
|
36
|
+
docsDir,
|
|
37
|
+
locale,
|
|
38
|
+
"sync",
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (syncResult.updated > 0) {
|
|
42
|
+
debug(
|
|
43
|
+
`✅ Synced diagram images to ${syncResult.updated} translation file(s) after translation`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
// Don't fail the translation if sync fails
|
|
49
|
+
debug(`⚠️ Failed to sync diagram images after translation: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
19
53
|
if (isShowMessage) {
|
|
20
54
|
const message = `✅ Translation completed successfully.`;
|
|
21
55
|
return { message };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { shutdownMermaidWorkerPool } from "../../utils/mermaid-worker-pool.mjs";
|
|
2
2
|
import { saveDoc as _saveDoc } from "../../utils/utils.mjs";
|
|
3
|
+
import { debug } from "../../utils/debug.mjs";
|
|
3
4
|
|
|
4
5
|
export default async function saveDoc({
|
|
5
6
|
path,
|
|
@@ -9,6 +10,8 @@ export default async function saveDoc({
|
|
|
9
10
|
locale,
|
|
10
11
|
feedback,
|
|
11
12
|
isShowMessage = false,
|
|
13
|
+
intentType,
|
|
14
|
+
originalContent,
|
|
12
15
|
...rest
|
|
13
16
|
}) {
|
|
14
17
|
await _saveDoc({
|
|
@@ -19,6 +22,43 @@ export default async function saveDoc({
|
|
|
19
22
|
locale,
|
|
20
23
|
});
|
|
21
24
|
|
|
25
|
+
// Sync diagram changes to translation documents if needed
|
|
26
|
+
// Only sync for diagram-related operations (addDiagram, updateDiagram, deleteDiagram)
|
|
27
|
+
if (
|
|
28
|
+
docsDir &&
|
|
29
|
+
path &&
|
|
30
|
+
intentType &&
|
|
31
|
+
["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType)
|
|
32
|
+
) {
|
|
33
|
+
try {
|
|
34
|
+
const { syncDiagramToTranslations } = await import(
|
|
35
|
+
"../../utils/sync-diagram-to-translations.mjs"
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// Determine operation type for sync
|
|
39
|
+
// deleteDiagram -> "delete" (process even if 0 diagrams)
|
|
40
|
+
// addDiagram/updateDiagram -> "update" (skip if 0 diagrams)
|
|
41
|
+
const operationType = intentType === "deleteDiagram" ? "delete" : "update";
|
|
42
|
+
|
|
43
|
+
const syncResult = await syncDiagramToTranslations(
|
|
44
|
+
content,
|
|
45
|
+
path,
|
|
46
|
+
docsDir,
|
|
47
|
+
locale || "en",
|
|
48
|
+
operationType,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if (syncResult.updated > 0) {
|
|
52
|
+
debug(
|
|
53
|
+
`✅ Synced diagram changes to ${syncResult.updated} translation file(s) for ${intentType}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
// Don't fail the operation if sync fails
|
|
58
|
+
debug(`⚠️ Failed to sync diagram to translations: ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
22
62
|
if (isShowMessage) {
|
|
23
63
|
// Shutdown mermaid worker pool to ensure clean exit
|
|
24
64
|
try {
|
|
@@ -39,6 +79,8 @@ export default async function saveDoc({
|
|
|
39
79
|
locale,
|
|
40
80
|
feedback,
|
|
41
81
|
isShowMessage,
|
|
82
|
+
intentType,
|
|
83
|
+
originalContent,
|
|
42
84
|
...rest,
|
|
43
85
|
};
|
|
44
86
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determine whether to skip document generation when the document already exists.
|
|
3
|
+
* If intentType is diagram-related *and* content is already present, mark that
|
|
4
|
+
* generation should be skipped so downstream agents can short-circuit.
|
|
5
|
+
*/
|
|
6
|
+
export default async function skipIfContentExists(input) {
|
|
7
|
+
const { intentType, content } = input;
|
|
8
|
+
|
|
9
|
+
const isDiagramIntent =
|
|
10
|
+
intentType && ["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType);
|
|
11
|
+
const shouldSkipGeneration = Boolean(isDiagramIntent && content);
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
...input,
|
|
15
|
+
skipGenerateDocument: shouldSkipGeneration,
|
|
16
|
+
// Ensure downstream steps have content available when skipping
|
|
17
|
+
...(shouldSkipGeneration
|
|
18
|
+
? {
|
|
19
|
+
content,
|
|
20
|
+
documentContent: content,
|
|
21
|
+
originalContent: content,
|
|
22
|
+
}
|
|
23
|
+
: {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
skipIfContentExists.task_render_mode = "hide";
|
package/aigne.yaml
CHANGED
|
@@ -105,10 +105,15 @@ agents:
|
|
|
105
105
|
- ./agents/evaluate/code-snippet.mjs
|
|
106
106
|
|
|
107
107
|
# Diagram
|
|
108
|
-
- ./agents/create/
|
|
108
|
+
- ./agents/create/analyze-diagram-type.mjs
|
|
109
|
+
- ./agents/create/analyze-diagram-type-llm.yaml
|
|
110
|
+
- ./agents/create/generate-diagram-image.yaml
|
|
111
|
+
- ./agents/create/replace-d2-with-image.mjs
|
|
109
112
|
- ./agents/update/generate-diagram.yaml
|
|
110
113
|
- ./agents/update/check-generate-diagram.mjs
|
|
111
114
|
- ./agents/update/pre-check-generate-diagram.yaml
|
|
115
|
+
- ./agents/update/check-sync-image-flag.mjs
|
|
116
|
+
- ./agents/update/sync-images-and-exit.mjs
|
|
112
117
|
cli:
|
|
113
118
|
chat: ./agents/chat/index.mjs
|
|
114
119
|
agents:
|