@aigne/doc-smith 0.9.10 → 0.9.11-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +189 -219
- package/README.zh.md +270 -0
- package/agents/bash-executor/index.mjs +347 -0
- package/agents/clear/ai/intent.md +142 -0
- package/agents/clear/choose-contents.mjs +13 -65
- package/agents/clear/clear-auth-tokens.mjs +17 -21
- package/agents/clear/clear-deployment-config.mjs +33 -24
- package/agents/clear/index.yaml +1 -9
- package/agents/content-checker/ai/intent.md +209 -0
- package/agents/content-checker/clean-invalid-docs.mjs +254 -0
- package/agents/content-checker/index.mjs +191 -0
- package/agents/content-checker/validate-content.mjs +983 -0
- package/agents/generate-images/generate-image.yaml +75 -0
- package/agents/generate-images/generate-summary.mjs +213 -0
- package/agents/generate-images/index.yaml +39 -0
- package/agents/generate-images/prepare-generation.mjs +286 -0
- package/agents/generate-images/prepare-image-generation.mjs +130 -0
- package/{prompts/detail/diagram/generate-image-system.md → agents/generate-images/prompts/system.md} +22 -56
- package/agents/generate-images/prompts/user.md +85 -0
- package/agents/generate-images/save-image-result.mjs +247 -0
- package/agents/generate-images/scan-image-slots.mjs +247 -0
- package/agents/localize/index.yaml +19 -42
- package/{prompts/translate → agents/localize/prompts}/translate-document.md +0 -139
- package/agents/localize/translate-documents/generate-summary.mjs +163 -0
- package/agents/localize/translate-documents/load-glossary.mjs +52 -0
- package/agents/localize/translate-documents/prepare-translation.mjs +249 -0
- package/agents/localize/translate-documents/save-translation.mjs +171 -0
- package/agents/localize/translate-documents/translate-document-to-language.mjs +209 -0
- package/agents/localize/translate-documents/translate-document.yaml +23 -0
- package/agents/localize/translate-documents/translate-to-languages.yaml +10 -0
- package/agents/localize/translate-images/check-image-translation.mjs +225 -0
- package/agents/localize/translate-images/detect-text/detect-and-update-shared.mjs +148 -0
- package/agents/localize/translate-images/detect-text/detect-image-text.yaml +44 -0
- package/agents/localize/translate-images/detect-text/detect-images-text.yaml +21 -0
- package/agents/localize/translate-images/detect-text/prompts/detect-image-text-system.md +43 -0
- package/agents/localize/translate-images/detect-text/prompts/detect-image-text-user.md +14 -0
- package/agents/localize/translate-images/detect-text/save-text-detection.mjs +105 -0
- package/agents/localize/translate-images/prepare-image-input.mjs +124 -0
- package/agents/localize/translate-images/save-image-translation.mjs +172 -0
- package/agents/localize/translate-images/scan-doc-images.mjs +165 -0
- package/agents/localize/translate-images/translate-doc-images.yaml +24 -0
- package/agents/localize/{translate-diagram.yaml → translate-images/translate-image.yaml} +25 -14
- package/agents/publish/ai/intent.md +182 -0
- package/agents/publish/check.mjs +107 -0
- package/agents/publish/index.yaml +9 -14
- package/agents/publish/publish-docs.mjs +81 -61
- package/agents/publish/translate-meta.mjs +79 -58
- package/agents/save-document/index.mjs +260 -0
- package/agents/structure-checker/index.mjs +307 -0
- package/agents/structure-checker/validate-structure.mjs +477 -0
- package/agents/update-image/analyze-feedback.yaml +37 -0
- package/agents/update-image/index.yaml +78 -0
- package/agents/update-image/load-existing-image.mjs +211 -0
- package/agents/update-image/prompts/analyze-feedback-system.md +43 -0
- package/agents/update-image/prompts/analyze-feedback-user.md +15 -0
- package/aigne.yaml +26 -139
- package/package.json +16 -48
- package/scripts/README.md +90 -0
- package/scripts/install.sh +86 -0
- package/scripts/uninstall.sh +52 -0
- package/skills/doc-smith/SKILL.md +285 -0
- package/skills/doc-smith/ai/intent/sources-improve.md +290 -0
- package/skills/doc-smith/references/changeset-guide.md +171 -0
- package/skills/doc-smith/references/document-content-guide.md +214 -0
- package/skills/doc-smith/references/document-structure-schema.md +138 -0
- package/skills/doc-smith/references/patch-guide.md +96 -0
- package/skills/doc-smith/references/structure-confirmation-guide.md +133 -0
- package/skills/doc-smith/references/structure-planning-guide.md +149 -0
- package/skills/doc-smith/references/update-workflow.md +108 -0
- package/skills/doc-smith/references/user-intent-guide.md +175 -0
- package/skills/doc-smith/references/workspace-initialization.md +376 -0
- package/skills/doc-smith-docs-detail/SKILL.md +356 -0
- package/skills/doc-smith-docs-detail/ai/intent.md +271 -0
- package/skills-entry/doc-smith/ai/intent.md +260 -0
- package/skills-entry/doc-smith/index.mjs +66 -0
- package/skills-entry/doc-smith/prompt.md +57 -0
- package/skills-entry/doc-smith/utils.mjs +27 -0
- package/skills-entry/doc-smith-docs-detail/batch.yaml +56 -0
- package/skills-entry/doc-smith-docs-detail/index.mjs +95 -0
- package/skills-entry/doc-smith-docs-detail/prompt.md +64 -0
- package/utils/afs-factory.mjs +183 -0
- package/utils/agent-constants.mjs +97 -0
- package/utils/{auth-utils.mjs → auth.mjs} +6 -9
- package/{agents/utils/update-branding.mjs → utils/branding.mjs} +3 -4
- package/utils/config.mjs +261 -0
- package/utils/constants.mjs +32 -0
- package/utils/deploy.mjs +3 -3
- package/utils/docs-converter.mjs +454 -0
- package/utils/docs.mjs +212 -0
- package/utils/document-paths.mjs +172 -0
- package/utils/files.mjs +74 -0
- package/utils/git.mjs +65 -0
- package/utils/{blocklet.mjs → http.mjs} +18 -0
- package/utils/image-slots.mjs +57 -0
- package/utils/image-utils.mjs +114 -0
- package/utils/project.mjs +95 -0
- package/utils/sources-path-resolver.mjs +76 -0
- package/utils/{upload-files.mjs → upload.mjs} +3 -3
- package/utils/workspace.mjs +371 -0
- package/agents/chat/chat-system.md +0 -38
- package/agents/chat/index.mjs +0 -59
- package/agents/chat/skills/generate-document.yaml +0 -15
- package/agents/chat/skills/list-documents.mjs +0 -15
- package/agents/chat/skills/update-document.yaml +0 -24
- package/agents/clear/clear-document-config.mjs +0 -36
- package/agents/clear/clear-document-structure.mjs +0 -102
- package/agents/clear/clear-generated-docs.mjs +0 -142
- package/agents/clear/clear-media-description.mjs +0 -129
- package/agents/create/aggregate-document-structure.mjs +0 -21
- package/agents/create/analyze-diagram-type-llm.yaml +0 -159
- package/agents/create/analyze-diagram-type.mjs +0 -455
- package/agents/create/check-document-structure.yaml +0 -30
- package/agents/create/check-need-generate-structure.mjs +0 -138
- package/agents/create/document-structure-tools/add-document.mjs +0 -85
- package/agents/create/document-structure-tools/delete-document.mjs +0 -116
- package/agents/create/document-structure-tools/move-document.mjs +0 -109
- package/agents/create/document-structure-tools/update-document.mjs +0 -84
- package/agents/create/generate-diagram-image.yaml +0 -91
- package/agents/create/generate-structure.yaml +0 -106
- package/agents/create/index.yaml +0 -45
- package/agents/create/refine-document-structure.yaml +0 -12
- package/agents/create/replace-d2-with-image.mjs +0 -610
- package/agents/create/update-document-structure.yaml +0 -54
- package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
- package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
- package/agents/create/user-add-document/index.yaml +0 -46
- package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
- package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
- package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
- package/agents/create/user-remove-document/index.yaml +0 -40
- package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
- package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
- package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
- package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
- package/agents/create/user-review-document-structure.mjs +0 -139
- package/agents/create/utils/init-current-content.mjs +0 -34
- package/agents/create/utils/merge-document-structures.mjs +0 -36
- package/agents/evaluate/code-snippet.mjs +0 -97
- package/agents/evaluate/document-structure.yaml +0 -67
- package/agents/evaluate/document.yaml +0 -82
- package/agents/evaluate/generate-report.mjs +0 -85
- package/agents/evaluate/index.yaml +0 -46
- package/agents/history/index.yaml +0 -6
- package/agents/history/view.mjs +0 -78
- package/agents/init/check.mjs +0 -16
- package/agents/init/index.mjs +0 -643
- package/agents/init/validate.mjs +0 -16
- package/agents/localize/choose-language.mjs +0 -107
- package/agents/localize/record-translation-history.mjs +0 -23
- package/agents/localize/save-doc-translation-or-skip.mjs +0 -18
- package/agents/localize/set-review-content.mjs +0 -58
- package/agents/localize/translate-document-wrapper.mjs +0 -34
- package/agents/localize/translate-document.yaml +0 -24
- package/agents/localize/translate-multilingual.yaml +0 -57
- package/agents/localize/translate-or-skip-diagram.mjs +0 -52
- package/agents/media/batch-generate-media-description.yaml +0 -46
- package/agents/media/generate-media-description.yaml +0 -50
- package/agents/media/load-media-description.mjs +0 -454
- package/agents/prefs/index.mjs +0 -203
- package/agents/schema/document-structure-item.yaml +0 -26
- package/agents/schema/document-structure-refine-item.yaml +0 -23
- package/agents/schema/document-structure.yaml +0 -29
- package/agents/update/batch-generate-document.yaml +0 -27
- package/agents/update/batch-update-document.yaml +0 -7
- package/agents/update/check-diagram-flag.mjs +0 -116
- package/agents/update/check-document.mjs +0 -162
- package/agents/update/check-generate-diagram.mjs +0 -106
- package/agents/update/check-update-is-single.mjs +0 -53
- package/agents/update/document-tools/update-document-content.mjs +0 -303
- package/agents/update/generate-diagram.yaml +0 -80
- package/agents/update/generate-document.yaml +0 -70
- package/agents/update/handle-document-update.yaml +0 -103
- package/agents/update/index.yaml +0 -69
- package/agents/update/pre-check-generate-diagram.yaml +0 -44
- package/agents/update/save-and-translate-document.mjs +0 -80
- package/agents/update/update-document-detail.yaml +0 -71
- package/agents/update/update-single/update-single-document-detail.mjs +0 -322
- package/agents/update/update-single-document.yaml +0 -7
- package/agents/update/user-review-document.mjs +0 -272
- package/agents/utils/action-success.mjs +0 -16
- package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
- package/agents/utils/analyze-feedback-intent.mjs +0 -253
- package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
- package/agents/utils/check-detail-result.mjs +0 -51
- package/agents/utils/check-feedback-refiner.mjs +0 -81
- package/agents/utils/choose-docs.mjs +0 -251
- package/agents/utils/document-icon-generate.yaml +0 -52
- package/agents/utils/document-title-streamline.yaml +0 -48
- package/agents/utils/ensure-document-icons.mjs +0 -129
- package/agents/utils/exit.mjs +0 -6
- package/agents/utils/feedback-refiner.yaml +0 -50
- package/agents/utils/find-item-by-path.mjs +0 -114
- package/agents/utils/find-user-preferences-by-path.mjs +0 -37
- package/agents/utils/format-document-structure.mjs +0 -35
- package/agents/utils/generate-document-or-skip.mjs +0 -41
- package/agents/utils/handle-diagram-operations.mjs +0 -263
- package/agents/utils/load-all-document-content.mjs +0 -30
- package/agents/utils/load-document-all-content.mjs +0 -96
- package/agents/utils/load-sources.mjs +0 -405
- package/agents/utils/map-reasoning-effort-level.mjs +0 -15
- package/agents/utils/post-generate.mjs +0 -133
- package/agents/utils/read-current-document-content.mjs +0 -46
- package/agents/utils/save-doc-translation.mjs +0 -30
- package/agents/utils/save-doc.mjs +0 -54
- package/agents/utils/save-output.mjs +0 -26
- package/agents/utils/save-sidebar.mjs +0 -38
- package/agents/utils/skip-if-content-exists.mjs +0 -27
- package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
- package/agents/utils/transform-detail-data-sources.mjs +0 -45
- package/assets/report-template/report.html +0 -198
- package/docs-mcp/analyze-content-relevance.yaml +0 -50
- package/docs-mcp/analyze-docs-relevance.yaml +0 -59
- package/docs-mcp/docs-search.yaml +0 -42
- package/docs-mcp/get-docs-detail.mjs +0 -41
- package/docs-mcp/get-docs-structure.mjs +0 -16
- package/docs-mcp/read-doc-content.mjs +0 -119
- package/prompts/common/document/content-rules-core.md +0 -20
- package/prompts/common/document/markdown-syntax-rules.md +0 -65
- package/prompts/common/document/media-file-list-usage-rules.md +0 -18
- package/prompts/common/document/openapi-usage-rules.md +0 -189
- package/prompts/common/document/role-and-personality.md +0 -16
- package/prompts/common/document/user-preferences.md +0 -9
- package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
- package/prompts/common/document-structure/document-icon-generate.md +0 -116
- package/prompts/common/document-structure/document-structure-rules.md +0 -43
- package/prompts/common/document-structure/document-title-streamline.md +0 -86
- package/prompts/common/document-structure/glossary.md +0 -7
- package/prompts/common/document-structure/intj-traits.md +0 -5
- package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
- package/prompts/common/document-structure/output-constraints.md +0 -18
- package/prompts/common/document-structure/user-locale-rules.md +0 -10
- package/prompts/common/document-structure/user-preferences.md +0 -9
- package/prompts/detail/custom/admonition-usage-rules.md +0 -94
- package/prompts/detail/custom/code-block-usage-rules.md +0 -163
- package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
- package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
- package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
- package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
- package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
- package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
- package/prompts/detail/diagram/generate-image-user.md +0 -81
- package/prompts/detail/diagram/guide.md +0 -29
- package/prompts/detail/diagram/official-examples.md +0 -712
- package/prompts/detail/diagram/pre-check.md +0 -23
- package/prompts/detail/diagram/role-and-personality.md +0 -2
- package/prompts/detail/diagram/rules.md +0 -46
- package/prompts/detail/diagram/system-prompt.md +0 -1139
- package/prompts/detail/diagram/user-prompt.md +0 -43
- package/prompts/detail/generate/detail-example.md +0 -457
- package/prompts/detail/generate/document-rules.md +0 -45
- package/prompts/detail/generate/system-prompt.md +0 -61
- package/prompts/detail/generate/user-prompt.md +0 -99
- package/prompts/detail/jsx/rules.md +0 -6
- package/prompts/detail/update/system-prompt.md +0 -121
- package/prompts/detail/update/user-prompt.md +0 -41
- package/prompts/evaluate/document-structure.md +0 -93
- package/prompts/evaluate/document.md +0 -149
- package/prompts/media/media-description/system-prompt.md +0 -43
- package/prompts/media/media-description/user-prompt.md +0 -17
- package/prompts/structure/check-document-structure.md +0 -93
- package/prompts/structure/document-rules.md +0 -21
- package/prompts/structure/find-documents-to-add-links.md +0 -52
- package/prompts/structure/generate/system-prompt.md +0 -13
- package/prompts/structure/generate/user-prompt.md +0 -137
- package/prompts/structure/review/structure-review-system.md +0 -81
- package/prompts/structure/structure-example.md +0 -89
- package/prompts/structure/structure-getting-started.md +0 -10
- package/prompts/structure/update/system-prompt.md +0 -93
- package/prompts/structure/update/user-prompt.md +0 -43
- package/prompts/translate/admonition.md +0 -20
- package/prompts/translate/code-block.md +0 -33
- package/prompts/utils/analyze-document-feedback-intent.md +0 -54
- package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
- package/prompts/utils/feedback-refiner.md +0 -105
- package/types/document-schema.mjs +0 -55
- package/types/document-structure-schema.mjs +0 -261
- package/utils/check-document-has-diagram.mjs +0 -95
- package/utils/conflict-detector.mjs +0 -149
- package/utils/constants/index.mjs +0 -620
- package/utils/constants/linter.mjs +0 -102
- package/utils/d2-utils.mjs +0 -205
- package/utils/debug.mjs +0 -3
- package/utils/delete-diagram-images.mjs +0 -99
- package/utils/diagram-version-utils.mjs +0 -14
- package/utils/docs-finder-utils.mjs +0 -548
- package/utils/evaluate/report-utils.mjs +0 -132
- package/utils/extract-api.mjs +0 -32
- package/utils/file-utils.mjs +0 -960
- package/utils/history-utils.mjs +0 -203
- package/utils/icon-map.mjs +0 -26
- package/utils/image-compress.mjs +0 -154
- package/utils/kroki-utils.mjs +0 -173
- package/utils/linter/index.mjs +0 -50
- package/utils/load-config.mjs +0 -78
- package/utils/markdown/index.mjs +0 -26
- package/utils/markdown-checker.mjs +0 -694
- package/utils/mermaid-validator.mjs +0 -140
- package/utils/mermaid-worker-pool.mjs +0 -250
- package/utils/mermaid-worker.mjs +0 -233
- package/utils/openapi/index.mjs +0 -28
- package/utils/preferences-utils.mjs +0 -175
- package/utils/request.mjs +0 -10
- package/utils/sync-diagram-to-translations.mjs +0 -272
- package/utils/translate-diagram-images.mjs +0 -807
- package/utils/utils.mjs +0 -1354
- /package/{prompts/translate → agents/localize/prompts}/glossary.md +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<role>
|
|
2
|
-
You are a feedback intent analyzer for **document structure modifications**. Your task is to determine the intent type of user feedback regarding document-level operations and whether external data sources are needed.
|
|
3
|
-
</role>
|
|
4
|
-
|
|
5
|
-
<input>
|
|
6
|
-
feedback: {{feedback}}
|
|
7
|
-
</input>
|
|
8
|
-
|
|
9
|
-
<analysis_rules>
|
|
10
|
-
Scope: Only analyze feedback related to document structure. Ignore any content-level operations inside document (e.g. sections, text, images).
|
|
11
|
-
|
|
12
|
-
**intent types:**
|
|
13
|
-
|
|
14
|
-
1. add - Adding new documents
|
|
15
|
-
2. edit - Modifying document-level properties (e.g., path, parentId, title of the document itself)
|
|
16
|
-
3. delete - Removing documents
|
|
17
|
-
4. move - Moving documents to different positions or parent sections
|
|
18
|
-
5. reorder - Changing the order of documents
|
|
19
|
-
6. mixed - Combination of multiple intent types
|
|
20
|
-
|
|
21
|
-
**Data source rules:**
|
|
22
|
-
|
|
23
|
-
- add/edit -> needDataSources = true
|
|
24
|
-
- delete/move/reorder -> needDataSources = false
|
|
25
|
-
- mixed -> needDataSources = true if any add/edit is included
|
|
26
|
-
|
|
27
|
-
**Decision logic:**
|
|
28
|
-
|
|
29
|
-
- Only consider document-level operations in the feedback.
|
|
30
|
-
- If any add or edit operation exists -> needDataSources = true
|
|
31
|
-
- If only delete, move, or reorder operations exist -> needDataSources = false
|
|
32
|
-
- When uncertain, default to needDataSources = true
|
|
33
|
-
</analysis_rules>
|
|
34
|
-
|
|
35
|
-
<output_rules>
|
|
36
|
-
Return a JSON object:
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
"needDataSources": boolean,
|
|
40
|
-
"intentType": "add" | "edit" | "delete" | "move" | "reorder" | "mixed",
|
|
41
|
-
"reason": "Explanation of why data sources are or aren't needed based on document-level operations."
|
|
42
|
-
}
|
|
43
|
-
</output_rules>
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
<role>
|
|
2
|
-
You are a "Feedback→Rule" converter. Transform one-time natural language feedback into a **single sentence**, **executable**, **reusable** instruction, and determine whether it needs **persistent saving**, along with its scope (global/structure/document/translation) and whether it should be limited to "input paths range".
|
|
3
|
-
</role>
|
|
4
|
-
|
|
5
|
-
<input>
|
|
6
|
-
- feedback: {{feedback}}
|
|
7
|
-
- stage: {{stage}} # Possible values: document_structure | document_refine | translation_refine
|
|
8
|
-
- paths: {{paths}} # Array of paths input in current command (can be empty). Used only to determine whether to "limit to these paths". Do not include them in output.
|
|
9
|
-
- existingPreferences: {{existingPreferences}} # Currently saved user preference rules
|
|
10
|
-
</input>
|
|
11
|
-
|
|
12
|
-
<scope_rules>
|
|
13
|
-
Scope determination heuristic rules:
|
|
14
|
-
|
|
15
|
-
**Classification by stage**:
|
|
16
|
-
- If stage=document_structure: Default `scope="structure"`, unless feedback is clearly global writing/tone/exclusion policy (then use `global`).
|
|
17
|
-
- If stage=document_refine: Default `scope="document"`; if feedback is general writing policy or exclusion strategy that doesn't depend on specific pages, can be elevated to `global`.
|
|
18
|
-
- If stage=translation_refine: Default `scope="translation"`; if feedback is general translation policy, maintain this scope.
|
|
19
|
-
|
|
20
|
-
**Path Limitation (`limitToInputPaths`) Determination**:
|
|
21
|
-
- **Set to `true` IF** the feedback explicitly names a specific document, path, or section (e.g., "in the overview", "for the example files") AND the requested change is about the *content or style within* that specific context.
|
|
22
|
-
- **Set to `false` IF** the feedback describes a general policy (e.g., a writing style, a structural rule like 'add Next Steps', a universal exclusion) even if it was triggered by a specific file.
|
|
23
|
-
- **Tie-breaker**: When in doubt, default to `false` to create a more broadly applicable rule.
|
|
24
|
-
|
|
25
|
-
- **Never** return specific paths lists in output.
|
|
26
|
-
</scope_rules>
|
|
27
|
-
|
|
28
|
-
<save_rules>
|
|
29
|
-
Save determination rules:
|
|
30
|
-
|
|
31
|
-
**Primary Goal: Your most critical task is to distinguish between a reusable policy and a one-time fix. Be conservative: when in doubt, default to `save=false`.**
|
|
32
|
-
|
|
33
|
-
**One-time operations (do not save)**:
|
|
34
|
-
- Only corrects current version/typos/individual phrasing/local factual errors with no stable reusable value → `save=false`
|
|
35
|
-
- Fixes that are highly specific to a single line or data point and unlikely to recur (e.g., "change the year from 2020 to 2021") → `save=false`
|
|
36
|
-
- Documentation Structure adjustments, adding new documents, update document, delete document, and moving document positions are always one-time operations → `save=false`
|
|
37
|
-
|
|
38
|
-
**Reusable policies (save)**:
|
|
39
|
-
- Writing styles, structural conventions, translation conventions that are broadly applicable and should be consistently executed in the future → `save=true`
|
|
40
|
-
|
|
41
|
-
**Duplication check (do not save)**:
|
|
42
|
-
- If `existingPreferences` already contains **similar or covering** rules for current feedback intent, then `save=false`
|
|
43
|
-
- Check logic: Compare feedback intent, rule meaning, and applicable scope. If new feedback is already sufficiently covered by existing rules, no need to save duplicates
|
|
44
|
-
- If new feedback is **refinement, supplement, or conflicting correction** to existing rules, it can still be `save=true`
|
|
45
|
-
|
|
46
|
-
**Determination principle**:
|
|
47
|
-
- Prioritize avoiding duplicate saves; if difficult to determine whether duplicate, prioritize `save=false` to avoid rule redundancy
|
|
48
|
-
</save_rules>
|
|
49
|
-
|
|
50
|
-
<rule_format>
|
|
51
|
-
Rule writing requirements:
|
|
52
|
-
|
|
53
|
-
- Model-oriented **single sentence** instruction; allow using clear wording like "must/must not/always".
|
|
54
|
-
- Do not introduce specific paths or bind to specific file names.
|
|
55
|
-
- **Crucially, preserve specific, domain-related keywords** (e.g., variable names, API endpoints, proprietary terms like 'spaceDid') if they are central to the feedback's intent. Generalize the *action*, not the *subject*.
|
|
56
|
-
- **If the feedback is about deleting or removing content, the resulting rule must be a preventative, forward-looking instruction.** Rephrase it as "Do not generate..." or "Avoid including content about...".
|
|
57
|
-
- Example: "Write for beginners; terms must be given clear explanations on first appearance."
|
|
58
|
-
</rule_format>
|
|
59
|
-
|
|
60
|
-
<output_rules>
|
|
61
|
-
Return a complete JSON object with a `reason` field explaining *why* you are setting `save` to true or false, and how you derived the rule and scope.
|
|
62
|
-
Return the summarized rule in the same language as the feedback in user input.
|
|
63
|
-
</output_rules>
|
|
64
|
-
|
|
65
|
-
<feedback_processing_examples>
|
|
66
|
-
Example 1 (Keyword Preservation):
|
|
67
|
-
- Input: stage=document_refine, paths=["examples/demo.md"], feedback="Do not use ellipsis in the spaceDid part of endpoint strings used in demo"
|
|
68
|
-
- Output:
|
|
69
|
-
{"rule":"Endpoint strings with 'spaceDid' in code examples should not use ellipsis for abbreviation.","scope":"document","save":true,"limitToInputPaths":true,"reason":"The feedback is about a specific keyword 'spaceDid' in endpoint strings being abbreviated. This is a recurring style issue that should be a policy. It's a reusable rule, so `save` is `true`. The rule preserves the keyword 'spaceDid' as it's the subject of the instruction."}
|
|
70
|
-
|
|
71
|
-
Example 2:
|
|
72
|
-
- Input: stage=document_structure, paths=[], feedback="Add 'Next Steps' at the end of overview and tutorials with 2-3 links."
|
|
73
|
-
- Output:
|
|
74
|
-
{"rule":"Add 'Next Steps' section at the end of overview and tutorial documents with 2-3 links within the repository.","scope":"structure","save":false,"limitToInputPaths":false,"reason":"This feedback is about adjusting document structure by adding a new section. According to save rules, documentation structure adjustments are always one-time operations, so `save` should be `false`. The scope remains `structure` as it affects document organization."}
|
|
75
|
-
|
|
76
|
-
Example 3:
|
|
77
|
-
- Input: stage=translation_refine, paths=[], feedback="Don't translate variable names and code."
|
|
78
|
-
- Output:
|
|
79
|
-
{"rule":"Keep code and identifiers unchanged during translation, must not translate them.","scope":"translation","save":true,"limitToInputPaths":false,"reason":"This is a fundamental, reusable policy for all future translations in this project. It's not a one-time fix. So, `save` is `true` and the scope is correctly `translation`."}
|
|
80
|
-
|
|
81
|
-
Example 4 (One-time Fix):
|
|
82
|
-
- Input: stage=document_refine, paths=["overview.md"], feedback="This paragraph has factual errors, change it to released in 2021."
|
|
83
|
-
- Output:
|
|
84
|
-
{"rule":"Correct facts to the accurate year.","scope":"document","save":false,"limitToInputPaths":true,"reason":"The feedback is a one-time factual correction for the current content. It corrects a specific data point and is not a reusable writing policy for the future. Therefore, `save` should be `false`."}
|
|
85
|
-
|
|
86
|
-
Example 5 (Deduplication):
|
|
87
|
-
- Input: stage=document_refine, paths=[], feedback="Code examples are too complex, simplify them.", existingPreferences="rules:\n - rule: Example pages should focus on minimally runnable code, removing explanatory sections unrelated to the topic.\n scope: document\n active: true"
|
|
88
|
-
- Output:
|
|
89
|
-
{"rule":"Simplify the complexity of code examples.","scope":"document","save":false,"limitToInputPaths":false,"reason":"The user wants to simplify code examples. The existing preference rule 'Example pages should focus on minimally runnable code' already covers this intent. Saving a new, similar rule would be redundant. Therefore, `save` should be `false`."}
|
|
90
|
-
|
|
91
|
-
Example 6 (Non-duplication):
|
|
92
|
-
- Input: stage=document_refine, paths=[], feedback="Code comments should be written in English.", existingPreferences="rules:\n - rule: Example pages should focus on minimally runnable code, removing explanatory sections unrelated to the topic.\n scope: document\n active: true"
|
|
93
|
-
- Output:
|
|
94
|
-
{"rule":"Code comments must be written in English.","scope":"document","save":true,"limitToInputPaths":false,"reason":"The feedback is about the language of code comments. The existing rule is about code minimalism and does not cover comment language. This is a new, non-overlapping rule. Thus, it should be saved. `save` is `true`."}
|
|
95
|
-
|
|
96
|
-
Example 7 (Deletion Handling):
|
|
97
|
-
- Input: stage=document_structure, paths=[], feedback="The 'Legacy API Reference' document is outdated and should be removed."
|
|
98
|
-
- Output:
|
|
99
|
-
{"rule":"Do not generate documents or sections for outdated 'Legacy API Reference'.","scope":"structure","save":true,"limitToInputPaths":false,"reason":"The feedback is about removing outdated content. Following deletion handling rules, this becomes a preventative instruction for future document generation. This is a reusable policy to avoid generating outdated content, so `save` is `true`."}
|
|
100
|
-
|
|
101
|
-
Example 8 (Path-limited Deletion Rule):
|
|
102
|
-
- Input: stage=document_refine, paths=["overview.md"], feedback="Remove contribution-related content from overview"
|
|
103
|
-
- Output:
|
|
104
|
-
{"rule":"Do not include contribution-related content in 'overview' document.","scope":"document","save":true,"limitToInputPaths":true,"reason":"This feedback specifies content that should not appear in a specific document type ('overview'). While it's about removing content, we convert it to a preventative rule. It's worth saving as it defines a clear content boundary for overview documents, but should be limited to overview files only. Therefore `save` is `true` with `limitToInputPaths` also `true`."}
|
|
105
|
-
</feedback_processing_examples>
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
-
|
|
4
|
-
// Update document content schemas
|
|
5
|
-
export const updateDocumentContentInputSchema = z.object({
|
|
6
|
-
diffPatch: z.string().min(1, "Diff patch is required"),
|
|
7
|
-
path: z.string().min(1, "Path is required for concurrent document updates"),
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export const updateDocumentContentOutputSchema = z.object({
|
|
11
|
-
success: z.boolean(),
|
|
12
|
-
updatedContent: z.string().optional(),
|
|
13
|
-
error: z.object({ message: z.string() }).optional(),
|
|
14
|
-
message: z.string().optional(),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// JSON Schema conversions for update document content
|
|
18
|
-
export const getUpdateDocumentContentInputJsonSchema = () => {
|
|
19
|
-
const schema = zodToJsonSchema(updateDocumentContentInputSchema);
|
|
20
|
-
if (schema.properties) {
|
|
21
|
-
schema.properties.diffPatch.description = "Diff patch string to apply to the original content";
|
|
22
|
-
schema.properties.path.description = "Document path";
|
|
23
|
-
}
|
|
24
|
-
return schema;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const getUpdateDocumentContentOutputJsonSchema = () => {
|
|
28
|
-
const schema = zodToJsonSchema(updateDocumentContentOutputSchema);
|
|
29
|
-
if (schema.properties) {
|
|
30
|
-
schema.properties.success.description = "Whether the update was successful";
|
|
31
|
-
schema.properties.updatedContent.description =
|
|
32
|
-
"Updated markdown content (only present if success is true)";
|
|
33
|
-
schema.properties.error.description =
|
|
34
|
-
"Error object containing error message (only present if success is false)";
|
|
35
|
-
schema.properties.message.description = "Success message (only present if success is true)";
|
|
36
|
-
}
|
|
37
|
-
return schema;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// Validation helper for update document content
|
|
41
|
-
export const validateUpdateDocumentContentInput = (input) => {
|
|
42
|
-
try {
|
|
43
|
-
return {
|
|
44
|
-
success: true,
|
|
45
|
-
data: updateDocumentContentInputSchema.parse(input),
|
|
46
|
-
};
|
|
47
|
-
} catch (error) {
|
|
48
|
-
return {
|
|
49
|
-
success: false,
|
|
50
|
-
error:
|
|
51
|
-
error.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join(", ") ||
|
|
52
|
-
error.message,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
};
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
-
|
|
4
|
-
// Document item schema - represents a single document in the structure
|
|
5
|
-
export const documentItemSchema = z.object({
|
|
6
|
-
title: z.string().min(1, "Title is required"),
|
|
7
|
-
description: z.string().min(1, "Description is required"),
|
|
8
|
-
path: z.string().startsWith("/", 'Path must start with "/"'),
|
|
9
|
-
parentId: z.string().nullish(),
|
|
10
|
-
sourceIds: z.array(z.string()).min(1, "At least one source ID is required"),
|
|
11
|
-
icon: z.string().optional(), // Lucide icon name (e.g., lucide:book) for root-level documents
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Documentation structure schema - represents the entire documentation structure array
|
|
15
|
-
export const documentStructureSchema = z.array(documentItemSchema);
|
|
16
|
-
|
|
17
|
-
// Add document schemas
|
|
18
|
-
export const addDocumentInputSchema = z.object({
|
|
19
|
-
title: z.string().min(1, "Title is required"),
|
|
20
|
-
description: z.string().min(1, "Description is required"),
|
|
21
|
-
path: z.string().startsWith("/", 'Path must start with "/"'),
|
|
22
|
-
parentId: z.string().nullish(),
|
|
23
|
-
sourceIds: z.array(z.string()).min(1, "At least one source ID is required"),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const addDocumentOutputSchema = z.object({
|
|
27
|
-
documentStructure: documentStructureSchema,
|
|
28
|
-
message: z.string().optional(),
|
|
29
|
-
addedDocument: documentItemSchema.optional(),
|
|
30
|
-
error: z.object({ message: z.string() }).optional(),
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Delete document schemas
|
|
34
|
-
export const deleteDocumentInputSchema = z.object({
|
|
35
|
-
path: z.string().min(1, "Path is required"),
|
|
36
|
-
recursive: z.boolean().optional(),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export const deleteDocumentOutputSchema = z.object({
|
|
40
|
-
documentStructure: documentStructureSchema,
|
|
41
|
-
message: z.string().optional(),
|
|
42
|
-
deletedDocuments: z.array(documentItemSchema).optional(),
|
|
43
|
-
error: z.object({ message: z.string() }).optional(),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Move document schemas
|
|
47
|
-
export const moveDocumentInputSchema = z.object({
|
|
48
|
-
path: z.string().min(1, "Path is required"),
|
|
49
|
-
newParentId: z.string().nullish(),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export const moveDocumentOutputSchema = z.object({
|
|
53
|
-
documentStructure: documentStructureSchema,
|
|
54
|
-
message: z.string().optional(),
|
|
55
|
-
originalDocument: documentItemSchema.optional(),
|
|
56
|
-
updatedDocument: documentItemSchema.optional(),
|
|
57
|
-
error: z.object({ message: z.string() }).optional(),
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Update document schemas
|
|
61
|
-
export const updateDocumentInputSchema = z
|
|
62
|
-
.object({
|
|
63
|
-
path: z.string().min(1, "Path is required"),
|
|
64
|
-
title: z.string().min(1).optional(),
|
|
65
|
-
description: z.string().min(1).optional(),
|
|
66
|
-
sourceIds: z.array(z.string()).min(1).optional(),
|
|
67
|
-
})
|
|
68
|
-
.refine(
|
|
69
|
-
(data) =>
|
|
70
|
-
data.title !== undefined || data.description !== undefined || data.sourceIds !== undefined,
|
|
71
|
-
{
|
|
72
|
-
message: "At least one field (title, description, or sourceIds) must be provided for update",
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
export const updateDocumentOutputSchema = z.object({
|
|
77
|
-
documentStructure: documentStructureSchema,
|
|
78
|
-
message: z.string().optional(),
|
|
79
|
-
originalDocument: documentItemSchema.optional(),
|
|
80
|
-
updatedDocument: documentItemSchema.optional(),
|
|
81
|
-
error: z.object({ message: z.string() }).optional(),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// JSON Schema conversion functions using zodToJsonSchema
|
|
85
|
-
export const getAddDocumentInputJsonSchema = () => {
|
|
86
|
-
const schema = zodToJsonSchema(addDocumentInputSchema);
|
|
87
|
-
// Add custom descriptions
|
|
88
|
-
if (schema.properties) {
|
|
89
|
-
schema.properties.title.description = "Title of the new document";
|
|
90
|
-
schema.properties.description.description = "Description of the new document";
|
|
91
|
-
schema.properties.path.description = "URL path for the new document (must start with '/')";
|
|
92
|
-
schema.properties.parentId.description =
|
|
93
|
-
"Parent document path (leave empty for top-level documents)";
|
|
94
|
-
schema.properties.sourceIds.description =
|
|
95
|
-
"Source references from associated data sources (required)";
|
|
96
|
-
}
|
|
97
|
-
return schema;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const getAddDocumentOutputJsonSchema = () => {
|
|
101
|
-
const schema = zodToJsonSchema(addDocumentOutputSchema);
|
|
102
|
-
if (schema.properties) {
|
|
103
|
-
schema.properties.documentStructure.description =
|
|
104
|
-
"Updated documentation structure array with the new document added";
|
|
105
|
-
schema.properties.message.description = "Success message describing the operation result";
|
|
106
|
-
schema.properties.addedDocument.description = "The newly added document object";
|
|
107
|
-
schema.properties.error.description =
|
|
108
|
-
"Error object containing error message if operation failed";
|
|
109
|
-
}
|
|
110
|
-
return schema;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export const getDeleteDocumentInputJsonSchema = () => {
|
|
114
|
-
const schema = zodToJsonSchema(deleteDocumentInputSchema);
|
|
115
|
-
if (schema.properties) {
|
|
116
|
-
schema.properties.path.description = "URL path of the document to delete";
|
|
117
|
-
schema.properties.recursive.description =
|
|
118
|
-
"If true, recursively delete all child documents. If false or not provided, deletion will fail if child documents exist.";
|
|
119
|
-
}
|
|
120
|
-
return schema;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export const getDeleteDocumentOutputJsonSchema = () => {
|
|
124
|
-
const schema = zodToJsonSchema(deleteDocumentOutputSchema);
|
|
125
|
-
if (schema.properties) {
|
|
126
|
-
schema.properties.documentStructure.description =
|
|
127
|
-
"Updated documentation structure array with the document removed";
|
|
128
|
-
schema.properties.message.description = "Success message describing the operation result";
|
|
129
|
-
schema.properties.deletedDocuments.description =
|
|
130
|
-
"Array of deleted document objects (includes all recursively deleted child documents if recursive=true)";
|
|
131
|
-
schema.properties.error.description =
|
|
132
|
-
"Error object containing error message if operation failed";
|
|
133
|
-
}
|
|
134
|
-
return schema;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const getMoveDocumentInputJsonSchema = () => {
|
|
138
|
-
const schema = zodToJsonSchema(moveDocumentInputSchema);
|
|
139
|
-
if (schema.properties) {
|
|
140
|
-
schema.properties.path.description = "URL path of the document to move";
|
|
141
|
-
schema.properties.newParentId.description =
|
|
142
|
-
"Path of the new parent document (leave empty for top-level)";
|
|
143
|
-
}
|
|
144
|
-
return schema;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const getMoveDocumentOutputJsonSchema = () => {
|
|
148
|
-
const schema = zodToJsonSchema(moveDocumentOutputSchema);
|
|
149
|
-
if (schema.properties) {
|
|
150
|
-
schema.properties.documentStructure.description =
|
|
151
|
-
"Updated documentation structure array with the document moved";
|
|
152
|
-
schema.properties.message.description = "Success message describing the operation result";
|
|
153
|
-
schema.properties.originalDocument.description = "The original document object before moving";
|
|
154
|
-
schema.properties.updatedDocument.description = "The updated document object after moving";
|
|
155
|
-
schema.properties.error.description =
|
|
156
|
-
"Error object containing error message if operation failed";
|
|
157
|
-
}
|
|
158
|
-
return schema;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export const getUpdateDocumentInputJsonSchema = () => {
|
|
162
|
-
const schema = zodToJsonSchema(updateDocumentInputSchema);
|
|
163
|
-
if (schema.properties) {
|
|
164
|
-
schema.properties.path.description = "URL path of the document to update";
|
|
165
|
-
schema.properties.title.description = "New title for the document (optional)";
|
|
166
|
-
schema.properties.description.description = "New description for the document (optional)";
|
|
167
|
-
schema.properties.sourceIds.description =
|
|
168
|
-
"New source references for the document (optional, cannot be empty if provided)";
|
|
169
|
-
}
|
|
170
|
-
// Add anyOf constraint for at least one update field
|
|
171
|
-
schema.anyOf = [
|
|
172
|
-
{ required: ["title"] },
|
|
173
|
-
{ required: ["description"] },
|
|
174
|
-
{ required: ["sourceIds"] },
|
|
175
|
-
];
|
|
176
|
-
return schema;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export const getUpdateDocumentOutputJsonSchema = () => {
|
|
180
|
-
const schema = zodToJsonSchema(updateDocumentOutputSchema);
|
|
181
|
-
if (schema.properties) {
|
|
182
|
-
schema.properties.documentStructure.description =
|
|
183
|
-
"Updated documentation structure array with the document modified";
|
|
184
|
-
schema.properties.message.description = "Success message describing the operation result";
|
|
185
|
-
schema.properties.originalDocument.description = "The original document object before update";
|
|
186
|
-
schema.properties.updatedDocument.description =
|
|
187
|
-
"The updated document object after modification";
|
|
188
|
-
schema.properties.error.description =
|
|
189
|
-
"Error object containing error message if operation failed";
|
|
190
|
-
}
|
|
191
|
-
return schema;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
// Validation helper functions
|
|
195
|
-
export const validateAddDocumentInput = (input) => {
|
|
196
|
-
try {
|
|
197
|
-
return {
|
|
198
|
-
success: true,
|
|
199
|
-
data: addDocumentInputSchema.parse(input),
|
|
200
|
-
};
|
|
201
|
-
} catch (error) {
|
|
202
|
-
return {
|
|
203
|
-
success: false,
|
|
204
|
-
error:
|
|
205
|
-
error.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join(", ") ||
|
|
206
|
-
error.message,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
export const validateDeleteDocumentInput = (input) => {
|
|
212
|
-
try {
|
|
213
|
-
return {
|
|
214
|
-
success: true,
|
|
215
|
-
data: deleteDocumentInputSchema.parse(input),
|
|
216
|
-
};
|
|
217
|
-
} catch (error) {
|
|
218
|
-
return {
|
|
219
|
-
success: false,
|
|
220
|
-
error:
|
|
221
|
-
error.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join(", ") ||
|
|
222
|
-
error.message,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export const validateMoveDocumentInput = (input) => {
|
|
228
|
-
try {
|
|
229
|
-
return {
|
|
230
|
-
success: true,
|
|
231
|
-
data: moveDocumentInputSchema.parse(input),
|
|
232
|
-
};
|
|
233
|
-
} catch (error) {
|
|
234
|
-
return {
|
|
235
|
-
success: false,
|
|
236
|
-
error:
|
|
237
|
-
error.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join(", ") ||
|
|
238
|
-
error.message,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export const validateUpdateDocumentInput = (input) => {
|
|
244
|
-
try {
|
|
245
|
-
return {
|
|
246
|
-
success: true,
|
|
247
|
-
data: updateDocumentInputSchema.parse(input),
|
|
248
|
-
};
|
|
249
|
-
} catch (error) {
|
|
250
|
-
return {
|
|
251
|
-
success: false,
|
|
252
|
-
error:
|
|
253
|
-
error.errors?.map((err) => `${err.path.join(".")}: ${err.message}`).join(", ") ||
|
|
254
|
-
error.message,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
// Type inference helpers for better IDE support
|
|
260
|
-
export const createDocumentItem = (data) => documentItemSchema.parse(data);
|
|
261
|
-
export const createDocumentStructure = (data) => documentStructureSchema.parse(data);
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { DIAGRAM_PLACEHOLDER, d2CodeBlockRegex, diagramImageStartRegex } from "./d2-utils.mjs";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Check if document content contains diagram-related content
|
|
5
|
-
* @param {string} content - Document content to check
|
|
6
|
-
* @returns {boolean} - True if document contains d2 code blocks, DIAGRAM_PLACEHOLDER, or diagram images
|
|
7
|
-
*/
|
|
8
|
-
export function hasDiagramContent(content) {
|
|
9
|
-
if (!content || typeof content !== "string") {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Check for DIAGRAM_PLACEHOLDER
|
|
14
|
-
if (content.includes(DIAGRAM_PLACEHOLDER)) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Check for D2 code blocks
|
|
19
|
-
const d2Matches = Array.from(content.matchAll(d2CodeBlockRegex));
|
|
20
|
-
if (d2Matches.length > 0) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Check for existing diagram images (DIAGRAM_IMAGE_START markers)
|
|
25
|
-
const imageMatches = Array.from(content.matchAll(diagramImageStartRegex));
|
|
26
|
-
if (imageMatches.length > 0) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get diagram type labels for a document
|
|
35
|
-
* @param {string} content - Document content to analyze
|
|
36
|
-
* @returns {string[]} - Array of diagram type labels (e.g., ["D2", "AI Image", "Placeholder"])
|
|
37
|
-
*/
|
|
38
|
-
export function getDiagramTypeLabels(content) {
|
|
39
|
-
if (!content || typeof content !== "string") {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const labels = [];
|
|
44
|
-
|
|
45
|
-
// Check for D2 code blocks
|
|
46
|
-
const d2Matches = Array.from(content.matchAll(d2CodeBlockRegex));
|
|
47
|
-
if (d2Matches.length > 0) {
|
|
48
|
-
labels.push("⛔️ D2");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Check for existing diagram images (AI-generated images)
|
|
52
|
-
const imageMatches = Array.from(content.matchAll(diagramImageStartRegex));
|
|
53
|
-
if (imageMatches.length > 0) {
|
|
54
|
-
labels.push("🍌 Image");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Check for DIAGRAM_PLACEHOLDER
|
|
58
|
-
if (content.includes(DIAGRAM_PLACEHOLDER)) {
|
|
59
|
-
labels.push("Placeholder");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return labels;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Format diagram type labels as a suffix string
|
|
67
|
-
* @param {string[]} labels - Array of diagram type labels
|
|
68
|
-
* @returns {string} - Formatted suffix string (e.g., " [D2, AI Image]")
|
|
69
|
-
*/
|
|
70
|
-
export function formatDiagramTypeSuffix(labels) {
|
|
71
|
-
if (!labels || labels.length === 0) {
|
|
72
|
-
return "";
|
|
73
|
-
}
|
|
74
|
-
return ` [${labels.join(", ")}]`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Check if document content contains banana images (AI-generated images)
|
|
79
|
-
* Only checks for DIAGRAM_IMAGE_START markers, excludes D2 code blocks and placeholders
|
|
80
|
-
* @param {string} content - Document content to check
|
|
81
|
-
* @returns {boolean} - True if document contains banana images
|
|
82
|
-
*/
|
|
83
|
-
export function hasBananaImages(content) {
|
|
84
|
-
if (!content || typeof content !== "string") {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Check for existing diagram images (DIAGRAM_IMAGE_START markers)
|
|
89
|
-
const imageMatches = Array.from(content.matchAll(diagramImageStartRegex));
|
|
90
|
-
if (imageMatches.length > 0) {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return false;
|
|
95
|
-
}
|