@aigne/doc-smith 0.9.8-alpha.2 → 0.9.8-alpha.4

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.
Files changed (256) hide show
  1. package/CLAUDE.md +43 -0
  2. package/README.md +94 -250
  3. package/aigne.yaml +2 -149
  4. package/doc-smith/SKILL.md +117 -0
  5. package/doc-smith/references/changeset_schema.md +118 -0
  6. package/doc-smith/references/document_structure_schema.md +139 -0
  7. package/doc-smith/references/document_update_guide.md +193 -0
  8. package/doc-smith/references/structure_confirmation_guide.md +133 -0
  9. package/doc-smith/references/structure_planning_guide.md +146 -0
  10. package/doc-smith/references/user_intent_guide.md +172 -0
  11. package/doc-smith.yaml +114 -0
  12. package/main-system-prompt.md +56 -0
  13. package/package.json +3 -69
  14. package/scripts/README.md +90 -0
  15. package/scripts/install.sh +86 -0
  16. package/scripts/uninstall.sh +52 -0
  17. package/CHANGELOG.md +0 -994
  18. package/LICENSE +0 -93
  19. package/agentic-agents/common/base-info.md +0 -53
  20. package/agentic-agents/common/planner.md +0 -168
  21. package/agentic-agents/common/worker.md +0 -93
  22. package/agentic-agents/create/index.yaml +0 -118
  23. package/agentic-agents/create/objective.md +0 -44
  24. package/agentic-agents/create/set-custom-prompt.mjs +0 -27
  25. package/agentic-agents/detail/index.yaml +0 -95
  26. package/agentic-agents/detail/objective.md +0 -9
  27. package/agentic-agents/detail/set-custom-prompt.mjs +0 -88
  28. package/agentic-agents/predict-resources/index.yaml +0 -44
  29. package/agentic-agents/predict-resources/instructions.md +0 -61
  30. package/agentic-agents/structure/design-rules.md +0 -39
  31. package/agentic-agents/structure/index.yaml +0 -86
  32. package/agentic-agents/structure/objective.md +0 -14
  33. package/agentic-agents/structure/review-criteria.md +0 -55
  34. package/agentic-agents/structure/set-custom-prompt.mjs +0 -78
  35. package/agentic-agents/utils/init-workspace-cache.mjs +0 -171
  36. package/agentic-agents/utils/load-base-sources.mjs +0 -20
  37. package/agentic-agents/workspace-cache-sharing-design.md +0 -671
  38. package/agents/chat/chat-system.md +0 -38
  39. package/agents/chat/index.mjs +0 -59
  40. package/agents/chat/skills/generate-document.yaml +0 -15
  41. package/agents/chat/skills/list-documents.mjs +0 -15
  42. package/agents/chat/skills/update-document.yaml +0 -24
  43. package/agents/clear/choose-contents.mjs +0 -192
  44. package/agents/clear/clear-auth-tokens.mjs +0 -88
  45. package/agents/clear/clear-deployment-config.mjs +0 -49
  46. package/agents/clear/clear-document-config.mjs +0 -36
  47. package/agents/clear/clear-document-structure.mjs +0 -102
  48. package/agents/clear/clear-generated-docs.mjs +0 -142
  49. package/agents/clear/clear-media-description.mjs +0 -129
  50. package/agents/clear/index.yaml +0 -26
  51. package/agents/create/analyze-diagram-type-llm.yaml +0 -160
  52. package/agents/create/analyze-diagram-type.mjs +0 -297
  53. package/agents/create/check-document-structure.yaml +0 -30
  54. package/agents/create/check-need-generate-structure.mjs +0 -105
  55. package/agents/create/document-structure-tools/add-document.mjs +0 -85
  56. package/agents/create/document-structure-tools/delete-document.mjs +0 -116
  57. package/agents/create/document-structure-tools/move-document.mjs +0 -109
  58. package/agents/create/document-structure-tools/update-document.mjs +0 -84
  59. package/agents/create/generate-diagram-image.yaml +0 -60
  60. package/agents/create/generate-structure.yaml +0 -117
  61. package/agents/create/index.yaml +0 -49
  62. package/agents/create/refine-document-structure.yaml +0 -12
  63. package/agents/create/replace-d2-with-image.mjs +0 -625
  64. package/agents/create/update-document-structure.yaml +0 -54
  65. package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
  66. package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
  67. package/agents/create/user-add-document/index.yaml +0 -46
  68. package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
  69. package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
  70. package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
  71. package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
  72. package/agents/create/user-remove-document/index.yaml +0 -40
  73. package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
  74. package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
  75. package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
  76. package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
  77. package/agents/create/user-review-document-structure.mjs +0 -140
  78. package/agents/create/utils/init-current-content.mjs +0 -34
  79. package/agents/create/utils/merge-document-structures.mjs +0 -30
  80. package/agents/evaluate/code-snippet.mjs +0 -97
  81. package/agents/evaluate/document-structure.yaml +0 -67
  82. package/agents/evaluate/document.yaml +0 -82
  83. package/agents/evaluate/generate-report.mjs +0 -85
  84. package/agents/evaluate/index.yaml +0 -46
  85. package/agents/history/index.yaml +0 -6
  86. package/agents/history/view.mjs +0 -78
  87. package/agents/init/check.mjs +0 -16
  88. package/agents/init/index.mjs +0 -275
  89. package/agents/init/validate.mjs +0 -16
  90. package/agents/localize/choose-language.mjs +0 -107
  91. package/agents/localize/index.yaml +0 -58
  92. package/agents/localize/record-translation-history.mjs +0 -23
  93. package/agents/localize/translate-document.yaml +0 -24
  94. package/agents/localize/translate-multilingual.yaml +0 -51
  95. package/agents/media/batch-generate-media-description.yaml +0 -46
  96. package/agents/media/generate-media-description.yaml +0 -50
  97. package/agents/media/load-media-description.mjs +0 -256
  98. package/agents/prefs/index.mjs +0 -203
  99. package/agents/publish/index.yaml +0 -26
  100. package/agents/publish/publish-docs.mjs +0 -356
  101. package/agents/publish/translate-meta.mjs +0 -103
  102. package/agents/schema/document-structure-item.yaml +0 -26
  103. package/agents/schema/document-structure-refine-item.yaml +0 -23
  104. package/agents/schema/document-structure.yaml +0 -29
  105. package/agents/update/batch-generate-document.yaml +0 -27
  106. package/agents/update/batch-update-document.yaml +0 -7
  107. package/agents/update/check-diagram-flag.mjs +0 -116
  108. package/agents/update/check-document.mjs +0 -162
  109. package/agents/update/check-generate-diagram.mjs +0 -106
  110. package/agents/update/check-sync-image-flag.mjs +0 -55
  111. package/agents/update/check-update-is-single.mjs +0 -53
  112. package/agents/update/document-tools/update-document-content.mjs +0 -303
  113. package/agents/update/generate-diagram.yaml +0 -63
  114. package/agents/update/generate-document.yaml +0 -70
  115. package/agents/update/handle-document-update.yaml +0 -103
  116. package/agents/update/index.yaml +0 -79
  117. package/agents/update/pre-check-generate-diagram.yaml +0 -44
  118. package/agents/update/save-and-translate-document.mjs +0 -76
  119. package/agents/update/sync-images-and-exit.mjs +0 -148
  120. package/agents/update/update-document-detail.yaml +0 -71
  121. package/agents/update/update-single/update-single-document-detail.mjs +0 -280
  122. package/agents/update/update-single-document.yaml +0 -7
  123. package/agents/update/user-review-document.mjs +0 -272
  124. package/agents/utils/action-success.mjs +0 -16
  125. package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
  126. package/agents/utils/analyze-feedback-intent.mjs +0 -136
  127. package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
  128. package/agents/utils/check-detail-result.mjs +0 -38
  129. package/agents/utils/check-feedback-refiner.mjs +0 -81
  130. package/agents/utils/choose-docs.mjs +0 -293
  131. package/agents/utils/document-icon-generate.yaml +0 -52
  132. package/agents/utils/document-title-streamline.yaml +0 -48
  133. package/agents/utils/ensure-document-icons.mjs +0 -129
  134. package/agents/utils/exit.mjs +0 -6
  135. package/agents/utils/feedback-refiner.yaml +0 -50
  136. package/agents/utils/find-item-by-path.mjs +0 -114
  137. package/agents/utils/find-user-preferences-by-path.mjs +0 -37
  138. package/agents/utils/format-document-structure.mjs +0 -35
  139. package/agents/utils/generate-document-or-skip.mjs +0 -41
  140. package/agents/utils/handle-diagram-operations.mjs +0 -263
  141. package/agents/utils/load-all-document-content.mjs +0 -30
  142. package/agents/utils/load-document-all-content.mjs +0 -84
  143. package/agents/utils/load-sources.mjs +0 -405
  144. package/agents/utils/map-reasoning-effort-level.mjs +0 -15
  145. package/agents/utils/post-generate.mjs +0 -144
  146. package/agents/utils/read-current-document-content.mjs +0 -46
  147. package/agents/utils/save-doc-translation.mjs +0 -61
  148. package/agents/utils/save-doc.mjs +0 -88
  149. package/agents/utils/save-output.mjs +0 -26
  150. package/agents/utils/save-sidebar.mjs +0 -51
  151. package/agents/utils/skip-if-content-exists.mjs +0 -27
  152. package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
  153. package/agents/utils/transform-detail-data-sources.mjs +0 -45
  154. package/agents/utils/update-branding.mjs +0 -84
  155. package/assets/report-template/report.html +0 -198
  156. package/docs-mcp/analyze-content-relevance.yaml +0 -50
  157. package/docs-mcp/analyze-docs-relevance.yaml +0 -59
  158. package/docs-mcp/docs-search.yaml +0 -42
  159. package/docs-mcp/get-docs-detail.mjs +0 -41
  160. package/docs-mcp/get-docs-structure.mjs +0 -16
  161. package/docs-mcp/read-doc-content.mjs +0 -119
  162. package/prompts/common/document/content-rules-core.md +0 -20
  163. package/prompts/common/document/markdown-syntax-rules.md +0 -65
  164. package/prompts/common/document/media-file-list-usage-rules.md +0 -18
  165. package/prompts/common/document/openapi-usage-rules.md +0 -189
  166. package/prompts/common/document/role-and-personality.md +0 -16
  167. package/prompts/common/document/user-preferences.md +0 -9
  168. package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
  169. package/prompts/common/document-structure/document-icon-generate.md +0 -116
  170. package/prompts/common/document-structure/document-structure-rules.md +0 -43
  171. package/prompts/common/document-structure/document-title-streamline.md +0 -86
  172. package/prompts/common/document-structure/glossary.md +0 -7
  173. package/prompts/common/document-structure/intj-traits.md +0 -5
  174. package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
  175. package/prompts/common/document-structure/output-constraints.md +0 -18
  176. package/prompts/common/document-structure/user-locale-rules.md +0 -10
  177. package/prompts/common/document-structure/user-preferences.md +0 -9
  178. package/prompts/detail/custom/admonition-usage-rules.md +0 -94
  179. package/prompts/detail/custom/code-block-usage-rules.md +0 -163
  180. package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
  181. package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
  182. package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
  183. package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
  184. package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
  185. package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
  186. package/prompts/detail/diagram/generate-image-system.md +0 -135
  187. package/prompts/detail/diagram/generate-image-user.md +0 -32
  188. package/prompts/detail/diagram/guide.md +0 -29
  189. package/prompts/detail/diagram/official-examples.md +0 -712
  190. package/prompts/detail/diagram/pre-check.md +0 -23
  191. package/prompts/detail/diagram/role-and-personality.md +0 -2
  192. package/prompts/detail/diagram/rules.md +0 -46
  193. package/prompts/detail/diagram/system-prompt.md +0 -1139
  194. package/prompts/detail/diagram/user-prompt.md +0 -43
  195. package/prompts/detail/generate/detail-example.md +0 -457
  196. package/prompts/detail/generate/document-rules.md +0 -45
  197. package/prompts/detail/generate/system-prompt.md +0 -61
  198. package/prompts/detail/generate/user-prompt.md +0 -99
  199. package/prompts/detail/jsx/rules.md +0 -6
  200. package/prompts/detail/update/system-prompt.md +0 -121
  201. package/prompts/detail/update/user-prompt.md +0 -41
  202. package/prompts/evaluate/document-structure.md +0 -93
  203. package/prompts/evaluate/document.md +0 -149
  204. package/prompts/media/media-description/system-prompt.md +0 -43
  205. package/prompts/media/media-description/user-prompt.md +0 -17
  206. package/prompts/structure/check-document-structure.md +0 -93
  207. package/prompts/structure/document-rules.md +0 -21
  208. package/prompts/structure/find-documents-to-add-links.md +0 -52
  209. package/prompts/structure/generate/system-prompt.md +0 -13
  210. package/prompts/structure/generate/user-prompt.md +0 -137
  211. package/prompts/structure/review/structure-review-system.md +0 -81
  212. package/prompts/structure/structure-example.md +0 -89
  213. package/prompts/structure/structure-getting-started.md +0 -10
  214. package/prompts/structure/update/system-prompt.md +0 -93
  215. package/prompts/structure/update/user-prompt.md +0 -43
  216. package/prompts/translate/admonition.md +0 -20
  217. package/prompts/translate/code-block.md +0 -33
  218. package/prompts/translate/glossary.md +0 -6
  219. package/prompts/translate/translate-document.md +0 -305
  220. package/prompts/utils/analyze-document-feedback-intent.md +0 -54
  221. package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
  222. package/prompts/utils/feedback-refiner.md +0 -105
  223. package/types/document-schema.mjs +0 -55
  224. package/types/document-structure-schema.mjs +0 -261
  225. package/utils/auth-utils.mjs +0 -275
  226. package/utils/blocklet.mjs +0 -104
  227. package/utils/check-document-has-diagram.mjs +0 -95
  228. package/utils/conflict-detector.mjs +0 -149
  229. package/utils/constants/index.mjs +0 -620
  230. package/utils/constants/linter.mjs +0 -102
  231. package/utils/d2-utils.mjs +0 -198
  232. package/utils/debug.mjs +0 -3
  233. package/utils/delete-diagram-images.mjs +0 -99
  234. package/utils/deploy.mjs +0 -86
  235. package/utils/docs-finder-utils.mjs +0 -623
  236. package/utils/evaluate/report-utils.mjs +0 -132
  237. package/utils/extract-api.mjs +0 -32
  238. package/utils/file-utils.mjs +0 -960
  239. package/utils/history-utils.mjs +0 -203
  240. package/utils/icon-map.mjs +0 -26
  241. package/utils/image-compress.mjs +0 -75
  242. package/utils/kroki-utils.mjs +0 -173
  243. package/utils/linter/index.mjs +0 -50
  244. package/utils/load-config.mjs +0 -107
  245. package/utils/markdown/index.mjs +0 -26
  246. package/utils/markdown-checker.mjs +0 -694
  247. package/utils/mermaid-validator.mjs +0 -140
  248. package/utils/mermaid-worker-pool.mjs +0 -250
  249. package/utils/mermaid-worker.mjs +0 -233
  250. package/utils/openapi/index.mjs +0 -28
  251. package/utils/preferences-utils.mjs +0 -175
  252. package/utils/request.mjs +0 -10
  253. package/utils/store/index.mjs +0 -45
  254. package/utils/sync-diagram-to-translations.mjs +0 -262
  255. package/utils/upload-files.mjs +0 -231
  256. package/utils/utils.mjs +0 -1354
@@ -1,46 +0,0 @@
1
- import { readFileContent } from "../../utils/docs-finder-utils.mjs";
2
- import { getFileName } from "../../utils/utils.mjs";
3
-
4
- /**
5
- * Read current document content from file system
6
- * Used when skipping document generation (e.g., for diagram-only updates)
7
- * Only reads content if intentType is diagram-related, otherwise returns input unchanged
8
- */
9
- export default async function readCurrentDocumentContent(input) {
10
- const { path, docsDir, locale = "en", intentType } = input;
11
-
12
- // Only read content if intentType is diagram-related
13
- // Otherwise, return input unchanged to allow document generation to proceed
14
- if (!intentType || !["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType)) {
15
- return input;
16
- }
17
-
18
- if (!path || !docsDir) {
19
- return input;
20
- }
21
-
22
- try {
23
- // Read document content using the same utility as other parts of the system
24
- const fileName = getFileName(path, locale);
25
- const content = await readFileContent(docsDir, fileName);
26
-
27
- if (!content) {
28
- console.warn(`⚠️ Could not read content from ${fileName}`);
29
- return input;
30
- }
31
-
32
- // Return content as both content, documentContent, and originalContent
33
- // This matches the structure expected by downstream agents
34
- return {
35
- ...input,
36
- content,
37
- documentContent: content,
38
- originalContent: content,
39
- };
40
- } catch (error) {
41
- console.warn(`Failed to read current content for ${path}: ${error.message}`);
42
- return input;
43
- }
44
- }
45
-
46
- readCurrentDocumentContent.task_render_mode = "hide";
@@ -1,61 +0,0 @@
1
- import { saveDocTranslation as _saveDocTranslation } from "../../utils/utils.mjs";
2
- import { readFileContent } from "../../utils/docs-finder-utils.mjs";
3
- import { getFileName } from "../../utils/utils.mjs";
4
- import { debug } from "../../utils/debug.mjs";
5
- import { syncDiagramToTranslations } from "../../utils/sync-diagram-to-translations.mjs";
6
-
7
- export default async function saveDocTranslation({
8
- path,
9
- docsDir,
10
- translation,
11
- language,
12
- labels,
13
- isShowMessage = false,
14
- locale,
15
- }) {
16
- await _saveDocTranslation({
17
- path,
18
- docsDir,
19
- language,
20
- translation,
21
- labels,
22
- });
23
-
24
- // Sync diagram images from main document to translations
25
- // This ensures all images (including diagrams) in the main document are synced to translation files
26
- if (path && docsDir && locale) {
27
- try {
28
- // Read main document content (it should already be saved)
29
- const mainFileName = getFileName(path, locale);
30
- const mainContent = await readFileContent(docsDir, mainFileName);
31
-
32
- if (mainContent) {
33
- const syncResult = await syncDiagramToTranslations(
34
- mainContent,
35
- path,
36
- docsDir,
37
- locale,
38
- "sync",
39
- );
40
-
41
- if (syncResult.updated > 0) {
42
- debug(
43
- `✅ Synced diagram images to ${syncResult.updated} translation file(s) after translation`,
44
- );
45
- }
46
- }
47
- } catch (error) {
48
- // Don't fail the translation if sync fails
49
- debug(`⚠️ Failed to sync diagram images after translation: ${error.message}`);
50
- }
51
- }
52
-
53
- if (isShowMessage) {
54
- const message = `✅ Translation completed successfully.`;
55
- return { message };
56
- }
57
-
58
- return {};
59
- }
60
-
61
- saveDocTranslation.task_render_mode = "hide";
@@ -1,88 +0,0 @@
1
- import { shutdownMermaidWorkerPool } from "../../utils/mermaid-worker-pool.mjs";
2
- import { saveDoc as _saveDoc } from "../../utils/utils.mjs";
3
- import { debug } from "../../utils/debug.mjs";
4
-
5
- export default async function saveDoc({
6
- path,
7
- content,
8
- docsDir,
9
- labels,
10
- locale,
11
- feedback,
12
- isShowMessage = false,
13
- intentType,
14
- originalContent,
15
- ...rest
16
- }) {
17
- await _saveDoc({
18
- path,
19
- content,
20
- docsDir,
21
- labels,
22
- locale,
23
- });
24
-
25
- // Sync diagram changes to translation documents if needed
26
- // Only sync for diagram-related operations (addDiagram, updateDiagram, deleteDiagram)
27
- if (
28
- docsDir &&
29
- path &&
30
- intentType &&
31
- ["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType)
32
- ) {
33
- try {
34
- const { syncDiagramToTranslations } = await import(
35
- "../../utils/sync-diagram-to-translations.mjs"
36
- );
37
-
38
- // Determine operation type for sync
39
- // deleteDiagram -> "delete" (process even if 0 diagrams)
40
- // addDiagram/updateDiagram -> "update" (skip if 0 diagrams)
41
- const operationType = intentType === "deleteDiagram" ? "delete" : "update";
42
-
43
- const syncResult = await syncDiagramToTranslations(
44
- content,
45
- path,
46
- docsDir,
47
- locale || "en",
48
- operationType,
49
- );
50
-
51
- if (syncResult.updated > 0) {
52
- debug(
53
- `✅ Synced diagram changes to ${syncResult.updated} translation file(s) for ${intentType}`,
54
- );
55
- }
56
- } catch (error) {
57
- // Don't fail the operation if sync fails
58
- debug(`⚠️ Failed to sync diagram to translations: ${error.message}`);
59
- }
60
- }
61
-
62
- if (isShowMessage) {
63
- // Shutdown mermaid worker pool to ensure clean exit
64
- try {
65
- await shutdownMermaidWorkerPool();
66
- } catch (error) {
67
- console.warn("Failed to shutdown mermaid worker pool:", error.message);
68
- }
69
-
70
- const message = `✅ Document updated successfully.`;
71
- return { message };
72
- }
73
-
74
- return {
75
- path,
76
- content,
77
- docsDir,
78
- labels,
79
- locale,
80
- feedback,
81
- isShowMessage,
82
- intentType,
83
- originalContent,
84
- ...rest,
85
- };
86
- }
87
-
88
- saveDoc.task_render_mode = "hide";
@@ -1,26 +0,0 @@
1
- import { promises as fs } from "node:fs";
2
- import { join } from "node:path";
3
-
4
- export default async function saveOutput({ savePath, fileName, saveKey, ...rest }) {
5
- if (!(saveKey in rest)) {
6
- console.warn(`saveKey "${saveKey}" not found in input, skip saving.`);
7
- return {
8
- saveOutputStatus: false,
9
- saveOutputPath: null,
10
- };
11
- }
12
-
13
- const value = rest[saveKey];
14
- const content =
15
- typeof value === "object" && value !== null ? JSON.stringify(value, null, 2) : String(value);
16
- await fs.mkdir(savePath, { recursive: true });
17
- const filePath = join(savePath, fileName);
18
- await fs.writeFile(filePath, content, "utf8");
19
-
20
- return {
21
- saveOutputStatus: true,
22
- saveOutputPath: filePath,
23
- };
24
- }
25
-
26
- saveOutput.task_render_mode = "hide";
@@ -1,51 +0,0 @@
1
- import { join } from "node:path";
2
- import fs from "fs-extra";
3
- import { buildDocumentTree } from "../../utils/docs-finder-utils.mjs";
4
-
5
- export default async function saveSidebar({
6
- documentStructure,
7
- originalDocumentStructure,
8
- docsDir,
9
- }) {
10
- // Generate _sidebar.md
11
- try {
12
- const sidebar = generateSidebar(documentStructure || originalDocumentStructure);
13
- const sidebarPath = join(docsDir, "_sidebar.md");
14
-
15
- await fs.ensureDir(docsDir);
16
- await fs.writeFile(sidebarPath, sidebar, "utf8");
17
- } catch (err) {
18
- console.error("Failed to save _sidebar.md:", err.message);
19
- }
20
- return {};
21
- }
22
-
23
- // Recursively generate sidebar text
24
- function walk(nodes, indent = "") {
25
- let out = "";
26
- for (const node of nodes) {
27
- const realIndent = node.parentId === null ? "" : indent;
28
-
29
- // If path already ends with .md, use it directly
30
- let linkPath;
31
- if (node.path.endsWith(".md")) {
32
- linkPath = node.path.startsWith("/") ? node.path : `/${node.path}`;
33
- } else {
34
- // Otherwise, convert to flattened file name
35
- const relPath = node.path.replace(/^\//, "");
36
- linkPath = `/${relPath.split("/").join("-")}.md`;
37
- }
38
-
39
- out += `${realIndent}* [${node.title}](${linkPath})\n`;
40
-
41
- if (node.children && node.children.length > 0) {
42
- out += walk(node.children, `${indent} `);
43
- }
44
- }
45
- return out;
46
- }
47
-
48
- function generateSidebar(documentStructure) {
49
- const { rootNodes } = buildDocumentTree(documentStructure);
50
- return walk(rootNodes).replace(/\n+$/, "");
51
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Determine whether to skip document generation when the document already exists.
3
- * If intentType is diagram-related *and* content is already present, mark that
4
- * generation should be skipped so downstream agents can short-circuit.
5
- */
6
- export default async function skipIfContentExists(input) {
7
- const { intentType, content } = input;
8
-
9
- const isDiagramIntent =
10
- intentType && ["addDiagram", "updateDiagram", "deleteDiagram"].includes(intentType);
11
- const shouldSkipGeneration = Boolean(isDiagramIntent && content);
12
-
13
- return {
14
- ...input,
15
- skipGenerateDocument: shouldSkipGeneration,
16
- // Ensure downstream steps have content available when skipping
17
- ...(shouldSkipGeneration
18
- ? {
19
- content,
20
- documentContent: content,
21
- originalContent: content,
22
- }
23
- : {}),
24
- };
25
- }
26
-
27
- skipIfContentExists.task_render_mode = "hide";
@@ -1,88 +0,0 @@
1
- /**
2
- * Check if a string contains character-based language characters (Chinese, Japanese, Korean, etc.)
3
- * @param {string} str - String to check
4
- * @returns {boolean} - True if string contains character-based language characters
5
- */
6
- function isCharacterBasedLanguage(str) {
7
- if (!str) return false;
8
- // Check for Chinese, Japanese, Korean, and other character-based languages
9
- // Chinese: \u4e00-\u9fff (CJK Unified Ideographs)
10
- // Japanese: \u3040-\u309f (Hiragana), \u30a0-\u30ff (Katakana)
11
- // Korean: \uac00-\ud7a3 (Hangul Syllables)
12
- // Thai: \u0e00-\u0e7f
13
- // Arabic: \u0600-\u06ff
14
- const characterBasedPattern =
15
- /[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7a3\u0e00-\u0e7f\u0600-\u06ff]/;
16
- return characterBasedPattern.test(str);
17
- }
18
-
19
- /**
20
- * Get character limit based on language type
21
- * @param {string} title - Title to check
22
- * @returns {number} - Character limit (24 for English, 12 for character-based languages)
23
- */
24
- function getCharacterLimit(title) {
25
- return isCharacterBasedLanguage(title) ? 12 : 24;
26
- }
27
-
28
- /**
29
- * Streamline document titles if they exceed length limits
30
- * Reusable function for streamlining document titles in various contexts
31
- * @param {Object} params
32
- * @param {Array<{title: string, path: string}>} params.documentStructure - Document structure array
33
- * @param {Object} options - Agent options with context
34
- * @returns {Promise<void>} - Modifies documentStructure in place
35
- */
36
- export default async function streamlineDocumentTitlesIfNeeded({ documentStructure }, options) {
37
- if (!documentStructure || !Array.isArray(documentStructure)) {
38
- return;
39
- }
40
-
41
- // Filter items that need streamlining based on character count and language type
42
- // English: > 24 characters, Character-based languages (Chinese, Japanese, etc.): > 12 characters
43
- const itemsNeedingStreamline = documentStructure.filter((item) => {
44
- if (!item.title) return false;
45
- const limit = getCharacterLimit(item.title);
46
- return item.title.length > limit;
47
- });
48
-
49
- if (itemsNeedingStreamline.length === 0) {
50
- return;
51
- }
52
-
53
- const documentList = itemsNeedingStreamline.map((item) => ({
54
- path: item.path,
55
- title: item.title,
56
- }));
57
-
58
- const streamlineAgent = options?.context?.agents?.["documentTitleStreamline"];
59
- if (!streamlineAgent) {
60
- console.warn("⚠️ documentTitleStreamline agent not found. Skipping title streamlining.");
61
- return;
62
- }
63
-
64
- try {
65
- const streamlineResult = await options.context.invoke(streamlineAgent, {
66
- documentList,
67
- });
68
-
69
- // Update the document items with streamlined titles using path as the key
70
- if (streamlineResult.documentList && Array.isArray(streamlineResult.documentList)) {
71
- const streamlineMap = new Map(streamlineResult.documentList.map((item) => [item.path, item]));
72
-
73
- for (const item of documentStructure) {
74
- const streamlined = streamlineMap.get(item.path);
75
- if (streamlined) {
76
- item.title = streamlined.title;
77
- }
78
- }
79
- }
80
- } catch (error) {
81
- console.warn("⚠️ Failed to streamline document titles:", error.message);
82
- console.warn("Continuing with original titles.");
83
- }
84
- }
85
-
86
- streamlineDocumentTitlesIfNeeded.taskTitle = "Streamline document titles if needed";
87
- streamlineDocumentTitlesIfNeeded.description =
88
- "Shorten document titles that exceed length limits to make sidebar navigation less crowded";
@@ -1,45 +0,0 @@
1
- import fs from "node:fs";
2
- import { isRemoteFile } from "../../utils/file-utils.mjs";
3
- import { normalizePath, toRelativePath } from "../../utils/utils.mjs";
4
-
5
- export default function transformDetailDataSource({ sourceIds }, options = {}) {
6
- // Read file content for each sourceId, ignoring failures
7
- let openAPISpec;
8
- const remoteFileList = options?.context?.userContext?.remoteFileList || [];
9
- const contents = (sourceIds || [])
10
- .filter((id) => {
11
- const openApiSourceId = options?.context?.userContext?.openAPISpec?.sourceId;
12
- if (openApiSourceId !== undefined && openApiSourceId === id) {
13
- openAPISpec = options.context.userContext.openAPISpec;
14
- return false;
15
- }
16
- return true;
17
- })
18
- .map((id) => {
19
- try {
20
- if (isRemoteFile(id)) {
21
- const findFile = remoteFileList.find((f) => f.sourceId === id);
22
- if (findFile) {
23
- return `// sourceId: ${id}\n${findFile.content}\n`;
24
- }
25
- return null;
26
- }
27
-
28
- const normalizedId = normalizePath(id);
29
- const content = fs.readFileSync(normalizedId, "utf8");
30
- const relativeId = toRelativePath(id);
31
- return `// sourceId: ${relativeId}\n${content}\n`;
32
- } catch {
33
- // Ignore files that cannot be read
34
- return null;
35
- }
36
- })
37
- .filter(Boolean);
38
-
39
- return {
40
- detailDataSource: contents.join(""),
41
- openAPISpec,
42
- };
43
- }
44
-
45
- transformDetailDataSource.task_render_mode = "hide";
@@ -1,84 +0,0 @@
1
- import { stat } from "node:fs/promises";
2
- import chalk from "chalk";
3
- import { joinURL } from "ufo";
4
-
5
- import { getComponentInfoWithMountPoint } from "../../utils/blocklet.mjs";
6
- import {
7
- CLOUD_SERVICE_URL_PROD,
8
- CLOUD_SERVICE_URL_STAGING,
9
- DISCUSS_KIT_DID,
10
- } from "../../utils/constants/index.mjs";
11
- import { requestWithAuthToken } from "../../utils/request.mjs";
12
- import { uploadFiles } from "../../utils/upload-files.mjs";
13
-
14
- export default async function updateBranding({ appUrl, projectInfo, accessToken, finalPath }) {
15
- try {
16
- const origin = new URL(appUrl).origin;
17
- if ([CLOUD_SERVICE_URL_PROD, CLOUD_SERVICE_URL_STAGING].includes(origin)) {
18
- console.log("ℹ️ Skipped updating branding for official service\n");
19
- return;
20
- }
21
-
22
- console.log(`🔄 Updating branding for ${chalk.cyan(origin)}`);
23
-
24
- // Get component information and mount point
25
- const componentInfo = await getComponentInfoWithMountPoint(origin, DISCUSS_KIT_DID);
26
- const mountPoint = componentInfo.mountPoint || "/";
27
-
28
- if (projectInfo.name.length > 40) {
29
- console.warn(
30
- `⚠️ Name is too long, it should be less than 40 characters\nWill be truncated to 40 characters`,
31
- );
32
- }
33
-
34
- if (projectInfo.description.length > 160) {
35
- console.warn(
36
- `⚠️ Description is too long, it should be less than 160 characters\nWill be truncated to 160 characters`,
37
- );
38
- }
39
-
40
- const res = await requestWithAuthToken(
41
- joinURL(origin, mountPoint, "/api/branding"),
42
- {
43
- method: "PUT",
44
- headers: {
45
- "Content-Type": "application/json",
46
- },
47
- body: JSON.stringify({
48
- appName: projectInfo.name.slice(0, 40),
49
- appDescription: projectInfo.description.slice(0, 160),
50
- }),
51
- },
52
- accessToken,
53
- );
54
-
55
- if (res.success) {
56
- if (!finalPath) {
57
- console.warn("\n🔄 Skipped updating branding for missing logo file\n");
58
- return;
59
- }
60
-
61
- try {
62
- const projectLogoStat = await stat(finalPath);
63
-
64
- if (projectLogoStat.isFile()) {
65
- // Upload to blocklet logo endpoint
66
- await uploadFiles({
67
- appUrl: origin,
68
- filePaths: [finalPath],
69
- accessToken,
70
- concurrency: 1,
71
- endpoint: `${origin}/.well-known/service/blocklet/logo/upload/square/${componentInfo.did}`,
72
- });
73
- }
74
- console.log("✅ Branding has been successfully updated\n");
75
- } catch (error) {
76
- console.warn(`⚠️ Just failed to update logo: ${error.message}\n`);
77
- }
78
- } else {
79
- console.warn(`⚠️ Failed to update branding: ${res.error}\n`);
80
- }
81
- } catch (error) {
82
- console.warn(`⚠️ Failed to update branding: ${error.message}\n`);
83
- }
84
- }