@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,130 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prepare image generation parameters
|
|
5
|
+
* @param {Object} input - Input parameters
|
|
6
|
+
* @param {string} input.key - Image key
|
|
7
|
+
* @param {string} input.id - Slot id
|
|
8
|
+
* @param {string} input.desc - Slot description
|
|
9
|
+
* @param {Array} input.documents - Associated document list
|
|
10
|
+
* @param {string} input.locale - Main language
|
|
11
|
+
* @param {boolean} input.isUpdate - Whether in update mode
|
|
12
|
+
* @param {string|null} input.existingImagePath - Existing image path
|
|
13
|
+
* @returns {Object} - Object containing original input and image generation parameters
|
|
14
|
+
*/
|
|
15
|
+
export default function prepareImageGeneration(input) {
|
|
16
|
+
const { desc, documents, locale, isUpdate, existingImagePath } = input;
|
|
17
|
+
|
|
18
|
+
// Use content from the first document
|
|
19
|
+
const firstDoc = documents[0];
|
|
20
|
+
const documentContent = firstDoc.content;
|
|
21
|
+
|
|
22
|
+
// Prepare image generation parameters
|
|
23
|
+
const imageGenParams = {
|
|
24
|
+
documentContent,
|
|
25
|
+
desc,
|
|
26
|
+
locale,
|
|
27
|
+
size: "2K",
|
|
28
|
+
aspectRatio: "4:3",
|
|
29
|
+
useImageToImage: isUpdate || false,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// If in update mode and existing image exists, add existingImage parameter
|
|
33
|
+
if (isUpdate && existingImagePath) {
|
|
34
|
+
imageGenParams.existingImage = [
|
|
35
|
+
{
|
|
36
|
+
type: "local",
|
|
37
|
+
path: existingImagePath,
|
|
38
|
+
filename: basename(existingImagePath),
|
|
39
|
+
mimeType: "image/png",
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
...input, // Keep all original inputs
|
|
46
|
+
...imageGenParams, // Add image generation parameters
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Add description
|
|
51
|
+
prepareImageGeneration.description =
|
|
52
|
+
"Prepare image generation parameters, extract content from the first associated document, " +
|
|
53
|
+
"configure image generation parameters (desc, locale, size, aspectRatio), " +
|
|
54
|
+
"if in update mode, add existing image path for image-to-image generation.";
|
|
55
|
+
|
|
56
|
+
// Define input schema
|
|
57
|
+
prepareImageGeneration.input_schema = {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
key: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "Image key (directory name)",
|
|
63
|
+
},
|
|
64
|
+
id: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "Slot id",
|
|
67
|
+
},
|
|
68
|
+
desc: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "Slot description",
|
|
71
|
+
},
|
|
72
|
+
documents: {
|
|
73
|
+
type: "array",
|
|
74
|
+
description: "Associated document list",
|
|
75
|
+
items: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
path: { type: "string" },
|
|
79
|
+
hash: { type: "string" },
|
|
80
|
+
content: { type: "string" },
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
locale: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "Main language code",
|
|
87
|
+
},
|
|
88
|
+
isUpdate: {
|
|
89
|
+
type: "boolean",
|
|
90
|
+
description: "Whether in update mode",
|
|
91
|
+
},
|
|
92
|
+
existingImagePath: {
|
|
93
|
+
type: "string",
|
|
94
|
+
nullable: true,
|
|
95
|
+
description: "Existing image path (used in update mode)",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
required: ["key", "id", "desc", "documents", "locale"],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Define output schema
|
|
102
|
+
prepareImageGeneration.output_schema = {
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: {
|
|
105
|
+
key: { type: "string" },
|
|
106
|
+
id: { type: "string" },
|
|
107
|
+
desc: { type: "string" },
|
|
108
|
+
documents: { type: "array" },
|
|
109
|
+
locale: { type: "string" },
|
|
110
|
+
isUpdate: { type: "boolean" },
|
|
111
|
+
existingImagePath: { type: "string", nullable: true },
|
|
112
|
+
imageGenParams: {
|
|
113
|
+
type: "object",
|
|
114
|
+
description: "Parameters passed to image generation agent",
|
|
115
|
+
properties: {
|
|
116
|
+
documentContent: { type: "string" },
|
|
117
|
+
desc: { type: "string" },
|
|
118
|
+
locale: { type: "string" },
|
|
119
|
+
size: { type: "string" },
|
|
120
|
+
aspectRatio: { type: "string" },
|
|
121
|
+
useImageToImage: { type: "boolean" },
|
|
122
|
+
existingImage: {
|
|
123
|
+
type: "array",
|
|
124
|
+
nullable: true,
|
|
125
|
+
items: { type: "object" },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
};
|
package/{prompts/detail/diagram/generate-image-system.md → agents/generate-images/prompts/system.md}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
You are an AI assistant specialized in generating clean, modern, professional diagram images.
|
|
1
|
+
You are an AI assistant specialized in generating clean, modern, professional diagram images for technical documentation.
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# GLOBAL RULES — APPLY TO ALL DIAGRAMS
|
|
4
4
|
|
|
5
|
-
## VISUAL STYLE
|
|
5
|
+
## VISUAL STYLE
|
|
6
6
|
- Modern SaaS product aesthetic
|
|
7
7
|
- Flat vector style, light soft depth (Material Design 2.0 / 3.0)
|
|
8
8
|
- White or light-grey background
|
|
@@ -21,7 +21,7 @@ You are an AI assistant specialized in generating clean, modern, professional di
|
|
|
21
21
|
- Connectors: blue (#2196F3 or #1976D2), straight or orthogonal
|
|
22
22
|
|
|
23
23
|
## TYPOGRAPHY & TEXT RULES
|
|
24
|
-
-
|
|
24
|
+
- Use the language specified by {{ locale }}
|
|
25
25
|
- Short labels: 2–5 words, action-oriented
|
|
26
26
|
- No long sentences
|
|
27
27
|
- No text outside nodes
|
|
@@ -34,8 +34,7 @@ You are an AI assistant specialized in generating clean, modern, professional di
|
|
|
34
34
|
- Icons optional (thin-line, ≤20% node area)
|
|
35
35
|
- Architecture diagrams may use larger icons (30–50%)
|
|
36
36
|
|
|
37
|
-
## FLOW RULES
|
|
38
|
-
- ONE start → sequential flow → ONE end
|
|
37
|
+
## FLOW RULES
|
|
39
38
|
- Clear, unobstructed main flow
|
|
40
39
|
- Minimal branching
|
|
41
40
|
- Avoid crossings; use orthogonal routing
|
|
@@ -47,7 +46,7 @@ You are an AI assistant specialized in generating clean, modern, professional di
|
|
|
47
46
|
- If >10: merge related steps, use grouping containers
|
|
48
47
|
- Must preserve complete logical flow
|
|
49
48
|
|
|
50
|
-
#
|
|
49
|
+
# ASPECT RATIO RULES
|
|
51
50
|
|
|
52
51
|
{% if aspectRatio == "1:1" %}
|
|
53
52
|
## SQUARE (1:1)
|
|
@@ -57,9 +56,9 @@ You are an AI assistant specialized in generating clean, modern, professional di
|
|
|
57
56
|
- Use the full square; avoid tiny central clusters
|
|
58
57
|
|
|
59
58
|
{% elif aspectRatio == "4:3" or aspectRatio == "5:4" %}
|
|
60
|
-
## PORTRAIT (4:3 or 5:4)
|
|
59
|
+
## PORTRAIT/STANDARD (4:3 or 5:4)
|
|
61
60
|
- Canvas: ~1280×1024 or ~1365×1024
|
|
62
|
-
- Primary layout: vertical (top→bottom)
|
|
61
|
+
- Primary layout: vertical (top→bottom) or balanced grid
|
|
63
62
|
- Use height generously; avoid large top/bottom gaps
|
|
64
63
|
- 4:3 supports longer text wrapping
|
|
65
64
|
|
|
@@ -83,53 +82,20 @@ You are an AI assistant specialized in generating clean, modern, professional di
|
|
|
83
82
|
|
|
84
83
|
{% endif %}
|
|
85
84
|
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
{% if diagramType == "flowchart" %}
|
|
89
|
-
## FLOWCHART
|
|
90
|
-
- ONE start → ONE end
|
|
91
|
-
- Dominant main flow, minimal branches
|
|
92
|
-
- Logical grouping recommended:
|
|
93
|
-
- Initialization
|
|
94
|
-
- Processing
|
|
95
|
-
- Validation
|
|
96
|
-
- Output
|
|
97
|
-
- Optional group containers
|
|
98
|
-
|
|
99
|
-
{% elif diagramType == "architecture" %}
|
|
100
|
-
## ARCHITECTURE DIAGRAM
|
|
101
|
-
- Layout flexible: horizontal, vertical layers, or radial
|
|
102
|
-
- Use containers or zones for modules/services
|
|
103
|
-
- Icons may be larger and more expressive
|
|
104
|
-
- Emphasize structure and relationships
|
|
105
|
-
|
|
106
|
-
{% elif diagramType == "intro" %}
|
|
107
|
-
## INTRO / CONCEPT OVERVIEW
|
|
108
|
-
- Radial or hierarchical layout
|
|
109
|
-
- One central idea + surrounding concepts
|
|
110
|
-
- Few connectors required
|
|
111
|
-
|
|
112
|
-
{% elif diagramType == "guide" %}
|
|
113
|
-
## GUIDE DIAGRAM
|
|
114
|
-
- Simple linear progression
|
|
115
|
-
- Horizontal or vertical based on aspectRatio
|
|
116
|
-
|
|
117
|
-
{% elif diagramType == "sequence" %}
|
|
118
|
-
## SEQUENCE DIAGRAM
|
|
119
|
-
- Horizontal timeline
|
|
120
|
-
- Vertical lifelines for actors
|
|
121
|
-
- Horizontal message arrows
|
|
122
|
-
|
|
123
|
-
{% elif diagramType == "network" %}
|
|
124
|
-
## NETWORK DIAGRAM
|
|
125
|
-
- Node-based topology
|
|
126
|
-
- Minimize crossing connections
|
|
127
|
-
- Use relative spatial placement to show relationships
|
|
85
|
+
# DIAGRAM TYPE GUIDELINES
|
|
128
86
|
|
|
129
|
-
|
|
87
|
+
## Common Diagram Types:
|
|
88
|
+
- **Architecture**: System components, modules, layers, relationships
|
|
89
|
+
- **Flowchart**: Process flow, decision points, sequential steps
|
|
90
|
+
- **Sequence**: Time-based interactions, message flow between actors
|
|
91
|
+
- **Concept/Overview**: Central idea with surrounding concepts
|
|
92
|
+
- **Guide**: Simple linear progression
|
|
93
|
+
- **Network**: Node-based topology, connections
|
|
94
|
+
|
|
95
|
+
**Note:** Based on the description provided, automatically determine the most appropriate diagram type and layout.
|
|
130
96
|
|
|
131
|
-
#
|
|
132
|
-
(no dark background), (no neon colors), (no clutter),
|
|
133
|
-
(no overcrowding), (no messy lines), (no spaghetti diagram),
|
|
134
|
-
(no confusing flow), (no diagram title), (no captions),
|
|
97
|
+
# NEGATIVE PROMPT
|
|
98
|
+
(no dark background), (no neon colors), (no clutter),
|
|
99
|
+
(no overcrowding), (no messy lines), (no spaghetti diagram),
|
|
100
|
+
(no confusing flow), (no diagram title), (no captions),
|
|
135
101
|
(no long sentences), (no step numbers)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{% if useImageToImage and existingImage %}
|
|
2
|
+
# Image-to-Image Generation Mode
|
|
3
|
+
|
|
4
|
+
Your task is to **update an existing diagram** based on the current document content{% if feedback %} and user feedback{% endif %}.
|
|
5
|
+
|
|
6
|
+
**CRITICAL INSTRUCTIONS:**
|
|
7
|
+
1. **Use the existing image as the primary reference** - maintain its overall structure, layout, and visual style
|
|
8
|
+
2. **Analyze the document content** to understand what changes are needed
|
|
9
|
+
{% if feedback %}3. **Apply user feedback** - follow the user's specific modification requests while maintaining visual consistency
|
|
10
|
+
4. **Maintain visual consistency** - keep the same style, color scheme, and general layout (unless feedback requests otherwise)
|
|
11
|
+
5. **Make necessary updates** - update content, add/remove elements, adjust relationships based on the document and feedback
|
|
12
|
+
6. **Preserve what works** - keep elements that are still accurate and relevant
|
|
13
|
+
{% else %}3. **Maintain visual consistency** - keep the same style, color scheme, and general layout
|
|
14
|
+
4. **Make necessary updates** - update content, add/remove elements, adjust relationships based on the document
|
|
15
|
+
5. **Preserve what works** - keep elements that are still accurate and relevant
|
|
16
|
+
{% endif %}
|
|
17
|
+
|
|
18
|
+
**Task Parameters:**
|
|
19
|
+
- **Description:** {{ desc }}
|
|
20
|
+
- **Visual Style:** modern (maintain consistency with existing image)
|
|
21
|
+
- **Aspect Ratio:** {{ aspectRatio }}
|
|
22
|
+
- **Language:** {{ locale }}
|
|
23
|
+
|
|
24
|
+
**Existing Diagram:**
|
|
25
|
+
[The existing diagram image is provided as input to the model]
|
|
26
|
+
|
|
27
|
+
{% if feedback %}
|
|
28
|
+
**User Feedback:**
|
|
29
|
+
```
|
|
30
|
+
{{ feedback }}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Important:** The user feedback above contains specific modification requests. Please carefully apply these changes to the diagram while maintaining visual consistency with the existing image.
|
|
34
|
+
{% endif %}
|
|
35
|
+
|
|
36
|
+
**Document Content:**
|
|
37
|
+
{{ documentContent }}
|
|
38
|
+
|
|
39
|
+
**Your responsibilities:**
|
|
40
|
+
1. Analyze the existing diagram structure, style, and layout
|
|
41
|
+
2. Review the document content to identify what needs to be updated
|
|
42
|
+
{% if feedback %}3. Carefully apply the user feedback to make the requested modifications
|
|
43
|
+
4. Maintain visual consistency with the original design (unless feedback requests style changes)
|
|
44
|
+
5. Update the diagram to accurately reflect the current document content and user feedback
|
|
45
|
+
6. Make necessary changes while preserving the overall visual style and structure
|
|
46
|
+
{% else %}3. Maintain visual consistency with the original design
|
|
47
|
+
4. Update the diagram to accurately reflect the current document content
|
|
48
|
+
5. Make necessary changes while preserving the overall visual style and structure
|
|
49
|
+
{% endif %}
|
|
50
|
+
|
|
51
|
+
{% else %}
|
|
52
|
+
# Standard Text-to-Image Generation Mode
|
|
53
|
+
|
|
54
|
+
Your task is to create a professional diagram image based on the document content and description below.
|
|
55
|
+
|
|
56
|
+
Please follow **all global rules, styles, aspect ratio logic, and diagram-type guidelines** defined in the system prompt.
|
|
57
|
+
|
|
58
|
+
# Task Parameters:
|
|
59
|
+
- **Description:** {{ desc }}
|
|
60
|
+
- **Visual Style:** modern
|
|
61
|
+
- **Aspect Ratio:** {{ aspectRatio }}
|
|
62
|
+
- **Language:** {{ locale }}
|
|
63
|
+
|
|
64
|
+
# Your responsibilities:
|
|
65
|
+
1. Read and analyze the description and document content
|
|
66
|
+
2. Automatically determine the most appropriate diagram type (architecture, flowchart, sequence, concept, etc.)
|
|
67
|
+
3. Extract key concepts, steps, relationships, or flow sequences
|
|
68
|
+
4. Generate a diagram that accurately represents these elements
|
|
69
|
+
5. Apply all rules from the system prompt
|
|
70
|
+
6. Labels must be concise (2–5 words) in {{ locale }}
|
|
71
|
+
7. No titles or explanations outside nodes
|
|
72
|
+
8. Maintain clarity, structure, and proper layout based on the aspect ratio
|
|
73
|
+
|
|
74
|
+
# Description:
|
|
75
|
+
{{ desc }}
|
|
76
|
+
|
|
77
|
+
# Document Content:
|
|
78
|
+
|
|
79
|
+
Now analyze the following document content to understand the context and details:
|
|
80
|
+
|
|
81
|
+
{{ documentContent }}
|
|
82
|
+
|
|
83
|
+
**Task:** Based on the description "{{ desc }}" and the document content above, determine the appropriate diagram type and create a professional diagram that clearly illustrates the concepts, flow, or architecture described.
|
|
84
|
+
|
|
85
|
+
{% endif %}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { writeFile, mkdir, copyFile } from "node:fs/promises";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { stringify as yamlStringify } from "yaml";
|
|
4
|
+
import { PATHS, ERROR_CODES } from "../../utils/agent-constants.mjs";
|
|
5
|
+
import { getExtensionFromMimeType } from "../../utils/image-utils.mjs";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Save image file
|
|
9
|
+
* @param {string} key - Image key
|
|
10
|
+
* @param {string} locale - Language code
|
|
11
|
+
* @param {Object} imageInfo - Image information { path, mimeType, ... }
|
|
12
|
+
* @returns {Promise<string>} - Saved image path
|
|
13
|
+
*/
|
|
14
|
+
async function saveImage(key, locale, imageInfo) {
|
|
15
|
+
const ext = getExtensionFromMimeType(imageInfo.mimeType);
|
|
16
|
+
const imagePath = join(PATHS.ASSETS_DIR, key, "images", `${locale}.${ext}`);
|
|
17
|
+
|
|
18
|
+
// Ensure directory exists
|
|
19
|
+
await mkdir(dirname(imagePath), { recursive: true });
|
|
20
|
+
|
|
21
|
+
// Copy from temporary file to target location
|
|
22
|
+
await copyFile(imageInfo.path, imagePath);
|
|
23
|
+
|
|
24
|
+
return imagePath;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generate or update .meta.yaml
|
|
29
|
+
* @param {string} key - Image key
|
|
30
|
+
* @param {string} id - Slot id
|
|
31
|
+
* @param {string} desc - Slot description
|
|
32
|
+
* @param {Array} documents - Associated document list
|
|
33
|
+
* @param {string} locale - Main language
|
|
34
|
+
* @param {string} model - Model used
|
|
35
|
+
* @returns {Promise<void>}
|
|
36
|
+
*/
|
|
37
|
+
async function saveMeta(key, id, desc, documents, locale, model) {
|
|
38
|
+
const metaPath = join(PATHS.ASSETS_DIR, key, ".meta.yaml");
|
|
39
|
+
|
|
40
|
+
const meta = {
|
|
41
|
+
kind: "image",
|
|
42
|
+
slot: {
|
|
43
|
+
id,
|
|
44
|
+
key,
|
|
45
|
+
desc,
|
|
46
|
+
},
|
|
47
|
+
generation: {
|
|
48
|
+
model,
|
|
49
|
+
createdAt: new Date().toISOString(),
|
|
50
|
+
shared: false, // Default false, determined by LLM during translation
|
|
51
|
+
},
|
|
52
|
+
documents: documents.map((doc) => ({
|
|
53
|
+
path: doc.path,
|
|
54
|
+
hash: doc.hash,
|
|
55
|
+
})),
|
|
56
|
+
languages: [locale],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Ensure directory exists
|
|
60
|
+
await mkdir(dirname(metaPath), { recursive: true });
|
|
61
|
+
|
|
62
|
+
// Save meta
|
|
63
|
+
await writeFile(metaPath, yamlStringify(meta), "utf8");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Save image generation result
|
|
68
|
+
* @param {Object} input - Input parameters (containing generation result)
|
|
69
|
+
* @returns {Promise<Object>} - Save result
|
|
70
|
+
*/
|
|
71
|
+
export default async function saveImageResult(input) {
|
|
72
|
+
try {
|
|
73
|
+
const { key, id, desc, documents, locale, isUpdate, imageGenParams } = input;
|
|
74
|
+
|
|
75
|
+
// Validate parameters
|
|
76
|
+
if (!key || !id || !desc || !documents || !locale) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
key,
|
|
80
|
+
error: "MISSING_PARAMETERS",
|
|
81
|
+
message: "Missing required parameters",
|
|
82
|
+
suggestion: "Please ensure key, id, desc, documents, locale are provided",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!Array.isArray(documents) || documents.length === 0) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
key,
|
|
90
|
+
error: "INVALID_DOCUMENTS",
|
|
91
|
+
message: "documents parameter is invalid or empty",
|
|
92
|
+
suggestion: "Please ensure at least one associated document exists",
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Get generation result from input.images
|
|
97
|
+
// Format: [{ filename, mimeType, type, path }, ...]
|
|
98
|
+
const images = input.images;
|
|
99
|
+
|
|
100
|
+
if (!images || !Array.isArray(images) || images.length === 0) {
|
|
101
|
+
return {
|
|
102
|
+
success: false,
|
|
103
|
+
key,
|
|
104
|
+
error: "GENERATION_FAILED",
|
|
105
|
+
message: "Generated image data not found",
|
|
106
|
+
suggestion: "Please check the image generation agent output format, expecting images array",
|
|
107
|
+
availableKeys: Object.keys(input),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Use the first image
|
|
112
|
+
const imageInfo = images[0];
|
|
113
|
+
if (!imageInfo.path) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
key,
|
|
117
|
+
error: "INVALID_IMAGE_DATA",
|
|
118
|
+
message: "Image data missing path field",
|
|
119
|
+
suggestion: "Please check the images format returned by the image generation agent",
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const model = imageGenParams?.model;
|
|
124
|
+
|
|
125
|
+
// Save image (copy from temporary path to assets directory)
|
|
126
|
+
const imagePath = await saveImage(key, locale, imageInfo);
|
|
127
|
+
|
|
128
|
+
// Save or update meta
|
|
129
|
+
await saveMeta(key, id, desc, documents, locale, model);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
key,
|
|
134
|
+
imagePath,
|
|
135
|
+
isUpdate,
|
|
136
|
+
message: `Successfully ${isUpdate ? "updated" : "generated"} image: ${imagePath}`,
|
|
137
|
+
};
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
key: input.key,
|
|
142
|
+
error: ERROR_CODES.UNEXPECTED_ERROR,
|
|
143
|
+
message: `Error saving image: ${error.message}`,
|
|
144
|
+
suggestion: "Please check file system permissions and image generation agent configuration",
|
|
145
|
+
stack: error.stack,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Add description
|
|
151
|
+
saveImageResult.description =
|
|
152
|
+
"Save image generation agent results to assets directory, " +
|
|
153
|
+
"including image file and .meta.yaml metadata file.";
|
|
154
|
+
|
|
155
|
+
// Define input schema
|
|
156
|
+
saveImageResult.input_schema = {
|
|
157
|
+
type: "object",
|
|
158
|
+
properties: {
|
|
159
|
+
key: {
|
|
160
|
+
type: "string",
|
|
161
|
+
description: "Image key (directory name)",
|
|
162
|
+
},
|
|
163
|
+
id: {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: "Slot id",
|
|
166
|
+
},
|
|
167
|
+
desc: {
|
|
168
|
+
type: "string",
|
|
169
|
+
description: "Slot description",
|
|
170
|
+
},
|
|
171
|
+
documents: {
|
|
172
|
+
type: "array",
|
|
173
|
+
description: "Associated document list",
|
|
174
|
+
items: {
|
|
175
|
+
type: "object",
|
|
176
|
+
properties: {
|
|
177
|
+
path: { type: "string" },
|
|
178
|
+
hash: { type: "string" },
|
|
179
|
+
content: { type: "string" },
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
locale: {
|
|
184
|
+
type: "string",
|
|
185
|
+
description: "Main language code",
|
|
186
|
+
},
|
|
187
|
+
isUpdate: {
|
|
188
|
+
type: "boolean",
|
|
189
|
+
description: "Whether in update mode",
|
|
190
|
+
},
|
|
191
|
+
imageGenParams: {
|
|
192
|
+
type: "object",
|
|
193
|
+
description: "Parameters passed to image generation agent",
|
|
194
|
+
},
|
|
195
|
+
// Following fields are returned by image generation agent
|
|
196
|
+
images: {
|
|
197
|
+
type: "array",
|
|
198
|
+
description: "Image list returned by image generation agent",
|
|
199
|
+
items: {
|
|
200
|
+
type: "object",
|
|
201
|
+
properties: {
|
|
202
|
+
filename: { type: "string", description: "Filename" },
|
|
203
|
+
mimeType: { type: "string", description: "MIME type" },
|
|
204
|
+
type: { type: "string", description: "Type (local)" },
|
|
205
|
+
path: { type: "string", description: "Temporary file path" },
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
required: ["key", "id", "desc", "documents", "locale"],
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// Define output schema
|
|
214
|
+
saveImageResult.output_schema = {
|
|
215
|
+
type: "object",
|
|
216
|
+
required: ["success", "key"],
|
|
217
|
+
properties: {
|
|
218
|
+
success: {
|
|
219
|
+
type: "boolean",
|
|
220
|
+
description: "Whether operation succeeded",
|
|
221
|
+
},
|
|
222
|
+
key: {
|
|
223
|
+
type: "string",
|
|
224
|
+
description: "Image key",
|
|
225
|
+
},
|
|
226
|
+
imagePath: {
|
|
227
|
+
type: "string",
|
|
228
|
+
description: "Generated image path",
|
|
229
|
+
},
|
|
230
|
+
isUpdate: {
|
|
231
|
+
type: "boolean",
|
|
232
|
+
description: "Whether this is an update operation",
|
|
233
|
+
},
|
|
234
|
+
message: {
|
|
235
|
+
type: "string",
|
|
236
|
+
description: "Operation result description",
|
|
237
|
+
},
|
|
238
|
+
error: {
|
|
239
|
+
type: "string",
|
|
240
|
+
description: "Error code (present on failure)",
|
|
241
|
+
},
|
|
242
|
+
suggestion: {
|
|
243
|
+
type: "string",
|
|
244
|
+
description: "Suggested action (present on failure)",
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
};
|