@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
package/utils/image-compress.mjs
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import sharp from "sharp";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { stat } from "node:fs/promises";
|
|
4
|
-
import { debug } from "./debug.mjs";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Compress an image using sharp
|
|
8
|
-
* Supports JPEG, PNG, and WebP formats
|
|
9
|
-
* @param {string} inputPath - Path to the input image file
|
|
10
|
-
* @param {object} options - Compression options
|
|
11
|
-
* @param {number} options.quality - Compression quality (0-100, default: 80)
|
|
12
|
-
* @param {string} options.outputFormat - Output format: 'jpeg', 'png', 'webp' (default: auto-detect from input)
|
|
13
|
-
* @param {string} options.outputPath - Output path for compressed image (if not provided, creates temp file)
|
|
14
|
-
* @param {number} options.maxWidth - Maximum width in pixels (default: undefined, no limit)
|
|
15
|
-
* @param {number} options.maxHeight - Maximum height in pixels (default: undefined, no limit)
|
|
16
|
-
* @param {number} options.maxSizeBytes - Maximum file size in bytes (default: undefined, no limit)
|
|
17
|
-
* @returns {Promise<string>} - Path to the compressed image (outputPath if provided, or temp path, or inputPath if compression fails)
|
|
18
|
-
*/
|
|
19
|
-
export async function compressImage(inputPath, options = {}) {
|
|
20
|
-
const { quality = 80, outputFormat, outputPath, maxWidth, maxHeight, maxSizeBytes } = options;
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const inputExt = path.extname(inputPath).toLowerCase();
|
|
24
|
-
|
|
25
|
-
// Determine output format
|
|
26
|
-
let format = outputFormat;
|
|
27
|
-
if (!format) {
|
|
28
|
-
// Auto-detect from input extension
|
|
29
|
-
if (inputExt === ".jpg" || inputExt === ".jpeg") {
|
|
30
|
-
format = "jpeg";
|
|
31
|
-
} else if (inputExt === ".png") {
|
|
32
|
-
format = "png";
|
|
33
|
-
} else if (inputExt === ".webp") {
|
|
34
|
-
format = "webp";
|
|
35
|
-
} else {
|
|
36
|
-
// Default to JPEG for unknown formats
|
|
37
|
-
format = "jpeg";
|
|
38
|
-
debug(`Unknown image format ${inputExt}, defaulting to JPEG`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Determine output path
|
|
43
|
-
let finalOutputPath = outputPath;
|
|
44
|
-
if (!finalOutputPath) {
|
|
45
|
-
// If no output path provided, create temp file in same directory as input
|
|
46
|
-
const outputExt = format === "jpeg" ? ".jpg" : format === "png" ? ".png" : ".webp";
|
|
47
|
-
const inputDir = path.dirname(inputPath);
|
|
48
|
-
const inputBase = path.basename(inputPath, path.extname(inputPath));
|
|
49
|
-
finalOutputPath = path.join(inputDir, `${inputBase}.compressed${outputExt}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Get image metadata
|
|
53
|
-
const metadata = await sharp(inputPath).metadata();
|
|
54
|
-
const { width, height } = metadata;
|
|
55
|
-
|
|
56
|
-
// Calculate target dimensions if maxWidth or maxHeight is specified
|
|
57
|
-
let targetWidth = width;
|
|
58
|
-
let targetHeight = height;
|
|
59
|
-
if (maxWidth || maxHeight) {
|
|
60
|
-
const aspectRatio = width / height;
|
|
61
|
-
if (maxWidth && width > maxWidth) {
|
|
62
|
-
targetWidth = maxWidth;
|
|
63
|
-
targetHeight = Math.round(maxWidth / aspectRatio);
|
|
64
|
-
}
|
|
65
|
-
if (maxHeight && targetHeight > maxHeight) {
|
|
66
|
-
targetHeight = maxHeight;
|
|
67
|
-
targetWidth = Math.round(maxHeight * aspectRatio);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Create sharp instance
|
|
72
|
-
let sharpInstance = sharp(inputPath);
|
|
73
|
-
|
|
74
|
-
// Resize if needed
|
|
75
|
-
if (targetWidth !== width || targetHeight !== height) {
|
|
76
|
-
sharpInstance = sharpInstance.resize(targetWidth, targetHeight, {
|
|
77
|
-
fit: "inside",
|
|
78
|
-
withoutEnlargement: true,
|
|
79
|
-
});
|
|
80
|
-
debug(`Resizing image from ${width}x${height} to ${targetWidth}x${targetHeight}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Apply format-specific compression options
|
|
84
|
-
if (format === "jpeg") {
|
|
85
|
-
// mozjpeg is a valid sharp option for better JPEG compression
|
|
86
|
-
const jpegOptions = { quality, mozjpeg: true };
|
|
87
|
-
sharpInstance = sharpInstance.jpeg(jpegOptions);
|
|
88
|
-
} else if (format === "png") {
|
|
89
|
-
sharpInstance = sharpInstance.png({ quality, compressionLevel: 9 });
|
|
90
|
-
} else if (format === "webp") {
|
|
91
|
-
sharpInstance = sharpInstance.webp({ quality });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If maxSizeBytes is specified, try to compress to target size
|
|
95
|
-
if (maxSizeBytes) {
|
|
96
|
-
let currentQuality = quality;
|
|
97
|
-
const compressedPath = finalOutputPath;
|
|
98
|
-
let attempts = 0;
|
|
99
|
-
const maxAttempts = 10;
|
|
100
|
-
const qualityStep = 5;
|
|
101
|
-
|
|
102
|
-
while (attempts < maxAttempts) {
|
|
103
|
-
// Create a new sharp instance for each attempt
|
|
104
|
-
let attemptInstance = sharp(inputPath);
|
|
105
|
-
if (targetWidth !== width || targetHeight !== height) {
|
|
106
|
-
attemptInstance = attemptInstance.resize(targetWidth, targetHeight, {
|
|
107
|
-
fit: "inside",
|
|
108
|
-
withoutEnlargement: true,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Apply format with current quality
|
|
113
|
-
if (format === "jpeg") {
|
|
114
|
-
attemptInstance = attemptInstance.jpeg({ quality: currentQuality, mozjpeg: true });
|
|
115
|
-
} else if (format === "png") {
|
|
116
|
-
attemptInstance = attemptInstance.png({ quality: currentQuality, compressionLevel: 9 });
|
|
117
|
-
} else if (format === "webp") {
|
|
118
|
-
attemptInstance = attemptInstance.webp({ quality: currentQuality });
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
await attemptInstance.toFile(compressedPath);
|
|
122
|
-
|
|
123
|
-
const stats = await stat(compressedPath);
|
|
124
|
-
if (stats.size <= maxSizeBytes || currentQuality <= 20) {
|
|
125
|
-
// Target size achieved or quality too low, stop
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Reduce quality and try again
|
|
130
|
-
currentQuality = Math.max(20, currentQuality - qualityStep);
|
|
131
|
-
attempts++;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
debug(
|
|
135
|
-
`✅ Image compressed: ${inputPath} -> ${compressedPath} (format: ${format}, quality: ${currentQuality}, size: ${(await stat(compressedPath)).size} bytes)`,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
return compressedPath;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Write compressed image directly to output path
|
|
142
|
-
await sharpInstance.toFile(finalOutputPath);
|
|
143
|
-
|
|
144
|
-
debug(
|
|
145
|
-
`✅ Image compressed: ${inputPath} -> ${finalOutputPath} (format: ${format}, quality: ${quality}, dimensions: ${targetWidth}x${targetHeight})`,
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
return finalOutputPath;
|
|
149
|
-
} catch (error) {
|
|
150
|
-
debug(`❌ Failed to compress image ${inputPath}`, error);
|
|
151
|
-
// Return original path if compression fails
|
|
152
|
-
return inputPath;
|
|
153
|
-
}
|
|
154
|
-
}
|
package/utils/kroki-utils.mjs
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
import Debug from "debug";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
|
-
import { glob } from "glob";
|
|
6
|
-
import pMap from "p-map";
|
|
7
|
-
import { joinURL } from "ufo";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
D2_CONFIG,
|
|
11
|
-
DOC_SMITH_DIR,
|
|
12
|
-
FILE_CONCURRENCY,
|
|
13
|
-
KROKI_CONCURRENCY,
|
|
14
|
-
TMP_ASSETS_DIR,
|
|
15
|
-
TMP_DIR,
|
|
16
|
-
} from "./constants/index.mjs";
|
|
17
|
-
import { getContentHash } from "./utils.mjs";
|
|
18
|
-
import { d2CodeBlockRegex } from "./d2-utils.mjs";
|
|
19
|
-
|
|
20
|
-
const debug = Debug("doc-smith");
|
|
21
|
-
|
|
22
|
-
export async function getChart({ chart = "d2", format = "svg", content, strict }) {
|
|
23
|
-
const baseUrl = "https://chart.abtnet.io";
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const res = await fetch(joinURL(baseUrl, chart, format), {
|
|
27
|
-
method: "POST",
|
|
28
|
-
body: content,
|
|
29
|
-
headers: {
|
|
30
|
-
Accept: "image/svg+xml",
|
|
31
|
-
"Content-Type": "text/plain",
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
if (strict && !res.ok) {
|
|
35
|
-
throw new Error(`Could not fetch the chart: ${res.status} ${res.statusText}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const data = await res.text();
|
|
39
|
-
return data;
|
|
40
|
-
} catch (err) {
|
|
41
|
-
if (strict) throw err;
|
|
42
|
-
|
|
43
|
-
console.error(`Could not generate the chart from: ${baseUrl}`, err);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function getD2Svg({ content, strict = false }) {
|
|
49
|
-
const svgContent = await getChart({
|
|
50
|
-
chart: "d2",
|
|
51
|
-
format: "svg",
|
|
52
|
-
content,
|
|
53
|
-
strict,
|
|
54
|
-
});
|
|
55
|
-
return svgContent;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function saveD2Assets({ markdown, docsDir }) {
|
|
59
|
-
if (!markdown) {
|
|
60
|
-
return markdown;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const { replaced } = await runIterator({
|
|
64
|
-
input: markdown,
|
|
65
|
-
regexp: d2CodeBlockRegex,
|
|
66
|
-
replace: true,
|
|
67
|
-
fn: async ([_match, _code]) => {
|
|
68
|
-
const assetDir = path.join(docsDir, "../", TMP_ASSETS_DIR, "d2");
|
|
69
|
-
await fs.ensureDir(assetDir);
|
|
70
|
-
const d2Content = [D2_CONFIG, _code].join("\n");
|
|
71
|
-
const fileName = `${getContentHash(d2Content)}.svg`;
|
|
72
|
-
const svgPath = path.join(assetDir, fileName);
|
|
73
|
-
|
|
74
|
-
if (await fs.pathExists(svgPath)) {
|
|
75
|
-
debug("Asset cache found, skipping generation", svgPath);
|
|
76
|
-
} else {
|
|
77
|
-
try {
|
|
78
|
-
debug("Generating d2 diagram", svgPath);
|
|
79
|
-
if (debug.enabled) {
|
|
80
|
-
const d2FileName = `${getContentHash(d2Content)}.d2`;
|
|
81
|
-
const d2Path = path.join(assetDir, d2FileName);
|
|
82
|
-
await fs.writeFile(d2Path, d2Content, { encoding: "utf8" });
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const svg = await getD2Svg({ content: d2Content });
|
|
86
|
-
if (svg) {
|
|
87
|
-
await fs.writeFile(svgPath, svg, { encoding: "utf8" });
|
|
88
|
-
}
|
|
89
|
-
} catch (error) {
|
|
90
|
-
debug("Could not generate the D2 diagram:", error);
|
|
91
|
-
return _code;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return `})`;
|
|
95
|
-
},
|
|
96
|
-
options: { concurrency: KROKI_CONCURRENCY },
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return replaced;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export async function beforePublishHook({ docsDir }) {
|
|
103
|
-
// Process each markdown file to save the d2 svg assets.
|
|
104
|
-
const mdFilePaths = await glob("**/*.md", { cwd: docsDir });
|
|
105
|
-
await pMap(
|
|
106
|
-
mdFilePaths,
|
|
107
|
-
async (filePath) => {
|
|
108
|
-
let finalContent = await fs.readFile(path.join(docsDir, filePath), { encoding: "utf8" });
|
|
109
|
-
finalContent = await saveD2Assets({ markdown: finalContent, docsDir });
|
|
110
|
-
|
|
111
|
-
await fs.writeFile(path.join(docsDir, filePath), finalContent, { encoding: "utf8" });
|
|
112
|
-
},
|
|
113
|
-
{ concurrency: FILE_CONCURRENCY },
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function runIterator({ input, regexp, fn = () => {}, options, replace = false }) {
|
|
118
|
-
if (!input) return input;
|
|
119
|
-
const matches = [...input.matchAll(regexp)];
|
|
120
|
-
const results = [];
|
|
121
|
-
await pMap(
|
|
122
|
-
matches,
|
|
123
|
-
async (...args) => {
|
|
124
|
-
const resultItem = await fn(...args);
|
|
125
|
-
results.push(resultItem);
|
|
126
|
-
},
|
|
127
|
-
options,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
let replaced = input;
|
|
131
|
-
if (replace) {
|
|
132
|
-
let index = 0;
|
|
133
|
-
replaced = replaced.replace(regexp, () => {
|
|
134
|
-
return results[index++];
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
results,
|
|
140
|
-
replaced,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export async function checkD2Content({ content }) {
|
|
145
|
-
await ensureTmpDir();
|
|
146
|
-
const assetDir = path.join(DOC_SMITH_DIR, TMP_DIR, TMP_ASSETS_DIR, "d2");
|
|
147
|
-
await fs.ensureDir(assetDir);
|
|
148
|
-
const d2Content = [D2_CONFIG, content].join("\n");
|
|
149
|
-
const fileName = `${getContentHash(d2Content)}.svg`;
|
|
150
|
-
const svgPath = path.join(assetDir, fileName);
|
|
151
|
-
|
|
152
|
-
if (debug.enabled) {
|
|
153
|
-
const d2FileName = `${getContentHash(d2Content)}.d2`;
|
|
154
|
-
const d2Path = path.join(assetDir, d2FileName);
|
|
155
|
-
await fs.writeFile(d2Path, d2Content, { encoding: "utf8" });
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (await fs.pathExists(svgPath)) {
|
|
159
|
-
debug("Asset cache found, skipping generation", svgPath);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const svg = await getD2Svg({ content: d2Content, strict: true });
|
|
164
|
-
await fs.writeFile(svgPath, svg, { encoding: "utf8" });
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export async function ensureTmpDir() {
|
|
168
|
-
const tmpDir = path.join(DOC_SMITH_DIR, TMP_DIR);
|
|
169
|
-
if (!(await fs.pathExists(path.join(tmpDir, ".gitignore")))) {
|
|
170
|
-
await fs.ensureDir(tmpDir);
|
|
171
|
-
await fs.writeFile(path.join(tmpDir, ".gitignore"), "**/*", { encoding: "utf8" });
|
|
172
|
-
}
|
|
173
|
-
}
|
package/utils/linter/index.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { LINTER_API_URL } from "../constants/linter.mjs";
|
|
2
|
-
|
|
3
|
-
export async function lintCode({ code, linter = "biome-lint", suffix = ".js" }) {
|
|
4
|
-
if (!code) {
|
|
5
|
-
throw new Error("Code parameter is required");
|
|
6
|
-
}
|
|
7
|
-
const timeout = 30 * 1000;
|
|
8
|
-
let filename = `code${suffix}`;
|
|
9
|
-
if (suffix === ".dockerfile") {
|
|
10
|
-
filename = "Dockerfile";
|
|
11
|
-
}
|
|
12
|
-
const testData = {
|
|
13
|
-
filename,
|
|
14
|
-
content: code,
|
|
15
|
-
options: {
|
|
16
|
-
validate_all: true,
|
|
17
|
-
fix: false,
|
|
18
|
-
log_level: "INFO",
|
|
19
|
-
timeout,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
try {
|
|
23
|
-
const controller = new AbortController();
|
|
24
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
25
|
-
|
|
26
|
-
const response = await fetch(`${LINTER_API_URL}/${linter}/json`, {
|
|
27
|
-
method: "POST",
|
|
28
|
-
headers: {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
},
|
|
31
|
-
body: JSON.stringify(testData),
|
|
32
|
-
signal: controller.signal,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
clearTimeout(timeoutId);
|
|
36
|
-
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const data = await response.json();
|
|
42
|
-
if (!data) {
|
|
43
|
-
throw new Error("Invalid response data");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return data;
|
|
47
|
-
} catch (error) {
|
|
48
|
-
throw new Error(`Linting failed: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
package/utils/load-config.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { parse } from "yaml";
|
|
5
|
-
import { processConfigFields, resolveFileReferences } from "./utils.mjs";
|
|
6
|
-
import { DEFAULT_EXCLUDE_PATTERNS } from "./constants/index.mjs";
|
|
7
|
-
import { findInvalidSourcePaths, toDisplayPath } from "./file-utils.mjs";
|
|
8
|
-
|
|
9
|
-
export default async function loadConfig({ config, appUrl }) {
|
|
10
|
-
const configPath = path.isAbsolute(config) ? config : path.join(process.cwd(), config);
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
// Check if config file exists
|
|
14
|
-
await fs.access(configPath);
|
|
15
|
-
} catch (_error) {
|
|
16
|
-
console.log(`The config file was not found at: ${configPath}`);
|
|
17
|
-
console.log("You can run 'aigne doc init' to create a new config file.");
|
|
18
|
-
throw new Error(`The config file was not found at: ${configPath}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// Read and parse YAML file
|
|
23
|
-
const configContent = await fs.readFile(configPath, "utf-8");
|
|
24
|
-
let parsedConfig = parse(configContent);
|
|
25
|
-
|
|
26
|
-
// Resolve file references (@ prefixed values)
|
|
27
|
-
parsedConfig = await resolveFileReferences(parsedConfig);
|
|
28
|
-
|
|
29
|
-
if (appUrl) {
|
|
30
|
-
parsedConfig.appUrl = appUrl.includes("://") ? appUrl : `https://${appUrl}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Parse new configuration fields and convert keys to actual content
|
|
34
|
-
const processedConfig = await processConfigFields(parsedConfig);
|
|
35
|
-
|
|
36
|
-
// Validate sourcePaths against exclude patterns
|
|
37
|
-
const sourcesPath = processedConfig.sourcesPath || parsedConfig.sourcesPath;
|
|
38
|
-
if (sourcesPath) {
|
|
39
|
-
const excludePatterns = [
|
|
40
|
-
...DEFAULT_EXCLUDE_PATTERNS,
|
|
41
|
-
...(processedConfig.excludePatterns || parsedConfig.excludePatterns || []),
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
const { excluded, notFound } = await findInvalidSourcePaths(sourcesPath, excludePatterns);
|
|
45
|
-
|
|
46
|
-
if (excluded.length > 0 || notFound.length > 0) {
|
|
47
|
-
const warnings = [];
|
|
48
|
-
|
|
49
|
-
if (excluded.length > 0) {
|
|
50
|
-
warnings.push(
|
|
51
|
-
`⚠️ These paths were excluded (ignored by config):\n${excluded.map((p) => ` - ${chalk.yellow(p)}`).join("\n")}`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (notFound.length > 0) {
|
|
56
|
-
warnings.push(
|
|
57
|
-
`🚫 These paths were skipped because they do not exist:\n${notFound.map((p) => ` - ${chalk.red(p)}`).join("\n")}`,
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
warnings.push(
|
|
62
|
-
`💡 Tip: You can remove these paths in ${chalk.cyan(toDisplayPath(configPath))}`,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
console.warn(`${warnings.join("\n\n")}\n`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
lastGitHead: parsedConfig.lastGitHead || "",
|
|
71
|
-
...parsedConfig,
|
|
72
|
-
...processedConfig,
|
|
73
|
-
};
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error(`I encountered an error while parsing the config file: ${error.message}`);
|
|
76
|
-
throw new Error(`I could not parse the config file: ${error.message}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
package/utils/markdown/index.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import remarkGfm from "remark-gfm";
|
|
2
|
-
import remarkParse from "remark-parse";
|
|
3
|
-
import { unified } from "unified";
|
|
4
|
-
import { visit } from "unist-util-visit";
|
|
5
|
-
import { VFile } from "vfile";
|
|
6
|
-
|
|
7
|
-
export function traverseMarkdownAst({ ast, test, visitor }) {
|
|
8
|
-
if (!ast || !test || !visitor) {
|
|
9
|
-
throw new Error("Required parameters missing: ast, test, and visitor must be provided");
|
|
10
|
-
}
|
|
11
|
-
visit(ast, test, visitor);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getMarkdownAst({ markdown }) {
|
|
15
|
-
if (!markdown || typeof markdown !== "string") {
|
|
16
|
-
throw new Error("Invalid markdown input: must be a non-empty string");
|
|
17
|
-
}
|
|
18
|
-
const file = new VFile({ value: markdown });
|
|
19
|
-
const processor = unified().use(remarkParse).use(remarkGfm);
|
|
20
|
-
try {
|
|
21
|
-
const ast = processor.parse(file);
|
|
22
|
-
return ast;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw new Error(`Failed to parse markdown: ${error.message}`);
|
|
25
|
-
}
|
|
26
|
-
}
|