@aigne/doc-smith 0.9.8-alpha.3 → 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 (257) 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/completer.md +0 -54
  21. package/agentic-agents/common/planner.md +0 -168
  22. package/agentic-agents/common/worker.md +0 -93
  23. package/agentic-agents/create/index.yaml +0 -129
  24. package/agentic-agents/create/objective.md +0 -44
  25. package/agentic-agents/create/set-custom-prompt.mjs +0 -27
  26. package/agentic-agents/detail/index.yaml +0 -95
  27. package/agentic-agents/detail/objective.md +0 -9
  28. package/agentic-agents/detail/set-custom-prompt.mjs +0 -88
  29. package/agentic-agents/predict-resources/index.yaml +0 -44
  30. package/agentic-agents/predict-resources/instructions.md +0 -61
  31. package/agentic-agents/structure/design-rules.md +0 -39
  32. package/agentic-agents/structure/index.yaml +0 -86
  33. package/agentic-agents/structure/objective.md +0 -14
  34. package/agentic-agents/structure/review-criteria.md +0 -55
  35. package/agentic-agents/structure/set-custom-prompt.mjs +0 -78
  36. package/agentic-agents/utils/init-workspace-cache.mjs +0 -171
  37. package/agentic-agents/utils/load-base-sources.mjs +0 -20
  38. package/agentic-agents/workspace-cache-sharing-design.md +0 -671
  39. package/agents/chat/chat-system.md +0 -38
  40. package/agents/chat/index.mjs +0 -59
  41. package/agents/chat/skills/generate-document.yaml +0 -15
  42. package/agents/chat/skills/list-documents.mjs +0 -15
  43. package/agents/chat/skills/update-document.yaml +0 -24
  44. package/agents/clear/choose-contents.mjs +0 -192
  45. package/agents/clear/clear-auth-tokens.mjs +0 -88
  46. package/agents/clear/clear-deployment-config.mjs +0 -49
  47. package/agents/clear/clear-document-config.mjs +0 -36
  48. package/agents/clear/clear-document-structure.mjs +0 -102
  49. package/agents/clear/clear-generated-docs.mjs +0 -142
  50. package/agents/clear/clear-media-description.mjs +0 -129
  51. package/agents/clear/index.yaml +0 -26
  52. package/agents/create/analyze-diagram-type-llm.yaml +0 -160
  53. package/agents/create/analyze-diagram-type.mjs +0 -297
  54. package/agents/create/check-document-structure.yaml +0 -30
  55. package/agents/create/check-need-generate-structure.mjs +0 -105
  56. package/agents/create/document-structure-tools/add-document.mjs +0 -85
  57. package/agents/create/document-structure-tools/delete-document.mjs +0 -116
  58. package/agents/create/document-structure-tools/move-document.mjs +0 -109
  59. package/agents/create/document-structure-tools/update-document.mjs +0 -84
  60. package/agents/create/generate-diagram-image.yaml +0 -60
  61. package/agents/create/generate-structure.yaml +0 -117
  62. package/agents/create/index.yaml +0 -49
  63. package/agents/create/refine-document-structure.yaml +0 -12
  64. package/agents/create/replace-d2-with-image.mjs +0 -625
  65. package/agents/create/update-document-structure.yaml +0 -54
  66. package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
  67. package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
  68. package/agents/create/user-add-document/index.yaml +0 -46
  69. package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
  70. package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
  71. package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
  72. package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
  73. package/agents/create/user-remove-document/index.yaml +0 -40
  74. package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
  75. package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
  76. package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
  77. package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
  78. package/agents/create/user-review-document-structure.mjs +0 -140
  79. package/agents/create/utils/init-current-content.mjs +0 -34
  80. package/agents/create/utils/merge-document-structures.mjs +0 -30
  81. package/agents/evaluate/code-snippet.mjs +0 -97
  82. package/agents/evaluate/document-structure.yaml +0 -67
  83. package/agents/evaluate/document.yaml +0 -82
  84. package/agents/evaluate/generate-report.mjs +0 -85
  85. package/agents/evaluate/index.yaml +0 -46
  86. package/agents/history/index.yaml +0 -6
  87. package/agents/history/view.mjs +0 -78
  88. package/agents/init/check.mjs +0 -16
  89. package/agents/init/index.mjs +0 -275
  90. package/agents/init/validate.mjs +0 -16
  91. package/agents/localize/choose-language.mjs +0 -107
  92. package/agents/localize/index.yaml +0 -58
  93. package/agents/localize/record-translation-history.mjs +0 -23
  94. package/agents/localize/translate-document.yaml +0 -24
  95. package/agents/localize/translate-multilingual.yaml +0 -51
  96. package/agents/media/batch-generate-media-description.yaml +0 -46
  97. package/agents/media/generate-media-description.yaml +0 -50
  98. package/agents/media/load-media-description.mjs +0 -256
  99. package/agents/prefs/index.mjs +0 -203
  100. package/agents/publish/index.yaml +0 -26
  101. package/agents/publish/publish-docs.mjs +0 -356
  102. package/agents/publish/translate-meta.mjs +0 -103
  103. package/agents/schema/document-structure-item.yaml +0 -26
  104. package/agents/schema/document-structure-refine-item.yaml +0 -23
  105. package/agents/schema/document-structure.yaml +0 -29
  106. package/agents/update/batch-generate-document.yaml +0 -27
  107. package/agents/update/batch-update-document.yaml +0 -7
  108. package/agents/update/check-diagram-flag.mjs +0 -116
  109. package/agents/update/check-document.mjs +0 -162
  110. package/agents/update/check-generate-diagram.mjs +0 -106
  111. package/agents/update/check-sync-image-flag.mjs +0 -55
  112. package/agents/update/check-update-is-single.mjs +0 -53
  113. package/agents/update/document-tools/update-document-content.mjs +0 -303
  114. package/agents/update/generate-diagram.yaml +0 -63
  115. package/agents/update/generate-document.yaml +0 -70
  116. package/agents/update/handle-document-update.yaml +0 -103
  117. package/agents/update/index.yaml +0 -79
  118. package/agents/update/pre-check-generate-diagram.yaml +0 -44
  119. package/agents/update/save-and-translate-document.mjs +0 -76
  120. package/agents/update/sync-images-and-exit.mjs +0 -148
  121. package/agents/update/update-document-detail.yaml +0 -71
  122. package/agents/update/update-single/update-single-document-detail.mjs +0 -280
  123. package/agents/update/update-single-document.yaml +0 -7
  124. package/agents/update/user-review-document.mjs +0 -272
  125. package/agents/utils/action-success.mjs +0 -16
  126. package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
  127. package/agents/utils/analyze-feedback-intent.mjs +0 -136
  128. package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
  129. package/agents/utils/check-detail-result.mjs +0 -38
  130. package/agents/utils/check-feedback-refiner.mjs +0 -81
  131. package/agents/utils/choose-docs.mjs +0 -293
  132. package/agents/utils/document-icon-generate.yaml +0 -52
  133. package/agents/utils/document-title-streamline.yaml +0 -48
  134. package/agents/utils/ensure-document-icons.mjs +0 -129
  135. package/agents/utils/exit.mjs +0 -6
  136. package/agents/utils/feedback-refiner.yaml +0 -50
  137. package/agents/utils/find-item-by-path.mjs +0 -114
  138. package/agents/utils/find-user-preferences-by-path.mjs +0 -37
  139. package/agents/utils/format-document-structure.mjs +0 -35
  140. package/agents/utils/generate-document-or-skip.mjs +0 -41
  141. package/agents/utils/handle-diagram-operations.mjs +0 -263
  142. package/agents/utils/load-all-document-content.mjs +0 -30
  143. package/agents/utils/load-document-all-content.mjs +0 -84
  144. package/agents/utils/load-sources.mjs +0 -405
  145. package/agents/utils/map-reasoning-effort-level.mjs +0 -15
  146. package/agents/utils/post-generate.mjs +0 -144
  147. package/agents/utils/read-current-document-content.mjs +0 -46
  148. package/agents/utils/save-doc-translation.mjs +0 -61
  149. package/agents/utils/save-doc.mjs +0 -88
  150. package/agents/utils/save-output.mjs +0 -26
  151. package/agents/utils/save-sidebar.mjs +0 -51
  152. package/agents/utils/skip-if-content-exists.mjs +0 -27
  153. package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
  154. package/agents/utils/transform-detail-data-sources.mjs +0 -45
  155. package/agents/utils/update-branding.mjs +0 -84
  156. package/assets/report-template/report.html +0 -198
  157. package/docs-mcp/analyze-content-relevance.yaml +0 -50
  158. package/docs-mcp/analyze-docs-relevance.yaml +0 -59
  159. package/docs-mcp/docs-search.yaml +0 -42
  160. package/docs-mcp/get-docs-detail.mjs +0 -41
  161. package/docs-mcp/get-docs-structure.mjs +0 -16
  162. package/docs-mcp/read-doc-content.mjs +0 -119
  163. package/prompts/common/document/content-rules-core.md +0 -20
  164. package/prompts/common/document/markdown-syntax-rules.md +0 -65
  165. package/prompts/common/document/media-file-list-usage-rules.md +0 -18
  166. package/prompts/common/document/openapi-usage-rules.md +0 -189
  167. package/prompts/common/document/role-and-personality.md +0 -16
  168. package/prompts/common/document/user-preferences.md +0 -9
  169. package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
  170. package/prompts/common/document-structure/document-icon-generate.md +0 -116
  171. package/prompts/common/document-structure/document-structure-rules.md +0 -43
  172. package/prompts/common/document-structure/document-title-streamline.md +0 -86
  173. package/prompts/common/document-structure/glossary.md +0 -7
  174. package/prompts/common/document-structure/intj-traits.md +0 -5
  175. package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
  176. package/prompts/common/document-structure/output-constraints.md +0 -18
  177. package/prompts/common/document-structure/user-locale-rules.md +0 -10
  178. package/prompts/common/document-structure/user-preferences.md +0 -9
  179. package/prompts/detail/custom/admonition-usage-rules.md +0 -94
  180. package/prompts/detail/custom/code-block-usage-rules.md +0 -163
  181. package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
  182. package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
  183. package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
  184. package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
  185. package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
  186. package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
  187. package/prompts/detail/diagram/generate-image-system.md +0 -135
  188. package/prompts/detail/diagram/generate-image-user.md +0 -32
  189. package/prompts/detail/diagram/guide.md +0 -29
  190. package/prompts/detail/diagram/official-examples.md +0 -712
  191. package/prompts/detail/diagram/pre-check.md +0 -23
  192. package/prompts/detail/diagram/role-and-personality.md +0 -2
  193. package/prompts/detail/diagram/rules.md +0 -46
  194. package/prompts/detail/diagram/system-prompt.md +0 -1139
  195. package/prompts/detail/diagram/user-prompt.md +0 -43
  196. package/prompts/detail/generate/detail-example.md +0 -457
  197. package/prompts/detail/generate/document-rules.md +0 -45
  198. package/prompts/detail/generate/system-prompt.md +0 -61
  199. package/prompts/detail/generate/user-prompt.md +0 -99
  200. package/prompts/detail/jsx/rules.md +0 -6
  201. package/prompts/detail/update/system-prompt.md +0 -121
  202. package/prompts/detail/update/user-prompt.md +0 -41
  203. package/prompts/evaluate/document-structure.md +0 -93
  204. package/prompts/evaluate/document.md +0 -149
  205. package/prompts/media/media-description/system-prompt.md +0 -43
  206. package/prompts/media/media-description/user-prompt.md +0 -17
  207. package/prompts/structure/check-document-structure.md +0 -93
  208. package/prompts/structure/document-rules.md +0 -21
  209. package/prompts/structure/find-documents-to-add-links.md +0 -52
  210. package/prompts/structure/generate/system-prompt.md +0 -13
  211. package/prompts/structure/generate/user-prompt.md +0 -137
  212. package/prompts/structure/review/structure-review-system.md +0 -81
  213. package/prompts/structure/structure-example.md +0 -89
  214. package/prompts/structure/structure-getting-started.md +0 -10
  215. package/prompts/structure/update/system-prompt.md +0 -93
  216. package/prompts/structure/update/user-prompt.md +0 -43
  217. package/prompts/translate/admonition.md +0 -20
  218. package/prompts/translate/code-block.md +0 -33
  219. package/prompts/translate/glossary.md +0 -6
  220. package/prompts/translate/translate-document.md +0 -305
  221. package/prompts/utils/analyze-document-feedback-intent.md +0 -54
  222. package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
  223. package/prompts/utils/feedback-refiner.md +0 -105
  224. package/types/document-schema.mjs +0 -55
  225. package/types/document-structure-schema.mjs +0 -261
  226. package/utils/auth-utils.mjs +0 -275
  227. package/utils/blocklet.mjs +0 -104
  228. package/utils/check-document-has-diagram.mjs +0 -95
  229. package/utils/conflict-detector.mjs +0 -149
  230. package/utils/constants/index.mjs +0 -620
  231. package/utils/constants/linter.mjs +0 -102
  232. package/utils/d2-utils.mjs +0 -198
  233. package/utils/debug.mjs +0 -3
  234. package/utils/delete-diagram-images.mjs +0 -99
  235. package/utils/deploy.mjs +0 -86
  236. package/utils/docs-finder-utils.mjs +0 -623
  237. package/utils/evaluate/report-utils.mjs +0 -132
  238. package/utils/extract-api.mjs +0 -32
  239. package/utils/file-utils.mjs +0 -960
  240. package/utils/history-utils.mjs +0 -203
  241. package/utils/icon-map.mjs +0 -26
  242. package/utils/image-compress.mjs +0 -75
  243. package/utils/kroki-utils.mjs +0 -173
  244. package/utils/linter/index.mjs +0 -50
  245. package/utils/load-config.mjs +0 -107
  246. package/utils/markdown/index.mjs +0 -26
  247. package/utils/markdown-checker.mjs +0 -694
  248. package/utils/mermaid-validator.mjs +0 -140
  249. package/utils/mermaid-worker-pool.mjs +0 -250
  250. package/utils/mermaid-worker.mjs +0 -233
  251. package/utils/openapi/index.mjs +0 -28
  252. package/utils/preferences-utils.mjs +0 -175
  253. package/utils/request.mjs +0 -10
  254. package/utils/store/index.mjs +0 -45
  255. package/utils/sync-diagram-to-translations.mjs +0 -262
  256. package/utils/upload-files.mjs +0 -231
  257. package/utils/utils.mjs +0 -1354
@@ -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,275 +0,0 @@
1
- import { existsSync, mkdirSync } from "node:fs";
2
- import { homedir } from "node:os";
3
- import { join } from "node:path";
4
- import { createConnect } from "@aigne/cli/utils/aigne-hub/credential.js";
5
- import chalk from "chalk";
6
- import open from "open";
7
- import { joinURL, withQuery } from "ufo";
8
- import {
9
- ComponentNotFoundError,
10
- getComponentMountPoint,
11
- InvalidBlockletError,
12
- } from "./blocklet.mjs";
13
- import {
14
- BLOCKLET_ADD_COMPONENT_DOCS,
15
- CLOUD_SERVICE_URL_PROD,
16
- CLOUD_SERVICE_URL_STAGING,
17
- DISCUSS_KIT_DID,
18
- DISCUSS_KIT_STORE_URL,
19
- PAYMENT_KIT_DID,
20
- } from "./constants/index.mjs";
21
- import { createStore } from "./store/index.mjs";
22
-
23
- const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
24
-
25
- const TIMEOUT_MINUTES = 5; // Just wait 5 min
26
- const FETCH_INTERVAL = 3000; // 3 seconds
27
-
28
- const RETRY_COUNT = (TIMEOUT_MINUTES * 60 * 1000) / FETCH_INTERVAL;
29
-
30
- /**
31
- * Get access token from environment, config file, or prompt user for authorization
32
- * @param {string} baseUrl - The application URL
33
- * @returns {Promise<string>} - The access token
34
- */
35
- export async function getCachedAccessToken(baseUrl) {
36
- const { hostname: targetHostname } = new URL(baseUrl);
37
- const store = await createStore();
38
-
39
- let accessToken =
40
- process.env.DOC_SMITH_PUBLISH_ACCESS_TOKEN || process.env.DOC_DISCUSS_KIT_ACCESS_TOKEN;
41
-
42
- // Check if access token exists in environment or config file
43
- if (!accessToken) {
44
- try {
45
- const storeItem = await store.getItem(targetHostname);
46
- accessToken = storeItem?.DOC_DISCUSS_KIT_ACCESS_TOKEN;
47
- } catch (error) {
48
- console.warn("Could not read the configuration file:", error.message);
49
- }
50
- }
51
-
52
- return accessToken;
53
- }
54
-
55
- export const getDiscussKitMountPoint = async (origin) => {
56
- try {
57
- const mountPoint = await getComponentMountPoint(origin, DISCUSS_KIT_DID);
58
- return mountPoint;
59
- } catch (error) {
60
- const storeLink = chalk.cyan(DISCUSS_KIT_STORE_URL);
61
- if (error instanceof InvalidBlockletError) {
62
- throw new Error(
63
- `${chalk.yellow("⚠️ The provided URL is not a valid ArcBlock-powered website.")}\n\n` +
64
- `${chalk.bold("💡 Solution:")} To host your documentation, you can get a website from the ArcBlock store:\n${storeLink}\n\n`,
65
- );
66
- } else if (error instanceof ComponentNotFoundError) {
67
- const docsLink = chalk.cyan(BLOCKLET_ADD_COMPONENT_DOCS);
68
- throw new Error(
69
- `${chalk.yellow("⚠️ This website is missing the required components for publishing.")}\n\n` +
70
- `${chalk.bold(
71
- "💡 Solution:",
72
- )} Please refer to the documentation to add the Discuss Kit component:\n${docsLink}\n\n`,
73
- );
74
- } else {
75
- throw new Error(
76
- `❌ Could not connect to: ${chalk.cyan(origin)}\n\n` +
77
- `${chalk.bold("Possible causes:")}\n` +
78
- `• There may be a network issue.\n` +
79
- `• The server may be temporarily unavailable.\n` +
80
- `• The URL may be incorrect.\n\n` +
81
- `${chalk.green("Suggestion:")} Please check your network connection and the URL, then try again.`,
82
- );
83
- }
84
- }
85
- };
86
-
87
- /**
88
- * Get access token from environment, config file, or prompt user for authorization
89
- * @param {string} appUrl - The application URL
90
- * @returns {Promise<string>} - The access token
91
- */
92
- export async function getAccessToken(appUrl, ltToken = "", locale = "en") {
93
- const { hostname: targetHostname, origin: targetOrigin } = new URL(appUrl);
94
-
95
- let accessToken = await getCachedAccessToken(targetOrigin);
96
-
97
- // If still no access token, prompt user to authorize
98
- if (accessToken) {
99
- return accessToken;
100
- }
101
-
102
- const connectUrl = joinURL(targetOrigin, WELLKNOWN_SERVICE_PATH_PREFIX);
103
-
104
- try {
105
- const result = await createConnect({
106
- connectUrl: connectUrl,
107
- connectAction: "gen-simple-access-key",
108
- source: `AIGNE DocSmith connect to website`,
109
- closeOnSuccess: true,
110
- appName: "AIGNE DocSmith",
111
- appLogo: "https://docsmith.aigne.io/image-bin/uploads/9645caf64b4232699982c4d940b03b90.svg",
112
- retry: RETRY_COUNT,
113
- fetchInterval: FETCH_INTERVAL,
114
- openPage: async (pageUrl) => {
115
- const url = new URL(pageUrl);
116
- const isOfficial = [CLOUD_SERVICE_URL_PROD, CLOUD_SERVICE_URL_STAGING].includes(url.origin);
117
- if (!isOfficial) {
118
- url.searchParams.set("required_roles", "owner,admin");
119
- }
120
- if (ltToken) {
121
- url.searchParams.set("__lt", ltToken);
122
- }
123
- url.searchParams.set("locale", locale);
124
-
125
- let connectUrl = url.toString();
126
- open(connectUrl);
127
-
128
- try {
129
- const officialBaseUrl = process.env.DOC_SMITH_BASE_URL || CLOUD_SERVICE_URL_PROD;
130
- const mountPoint = await getComponentMountPoint(officialBaseUrl, PAYMENT_KIT_DID);
131
- const response = await fetch(
132
- withQuery(joinURL(officialBaseUrl, mountPoint, "/api/tool/short-connect-url"), {
133
- url: connectUrl,
134
- locale,
135
- }),
136
- );
137
- const data = await response.json();
138
- if (data.url) {
139
- connectUrl = data.url;
140
- }
141
- } catch {
142
- // Ignore error
143
- }
144
-
145
- console.log(
146
- "🔗 Please open the following URL in your browser to authorize access:",
147
- chalk.cyan(connectUrl),
148
- "\n",
149
- );
150
- },
151
- });
152
-
153
- accessToken = result.accessKeySecret;
154
- process.env.DOC_SMITH_PUBLISH_ACCESS_TOKEN = accessToken;
155
- process.env.DOC_DISCUSS_KIT_ACCESS_TOKEN = accessToken;
156
-
157
- // Save the access token to config file
158
- await saveTokenToConfigFile(targetHostname, { DOC_DISCUSS_KIT_ACCESS_TOKEN: accessToken });
159
- } catch {
160
- throw new Error(
161
- `${chalk.yellow("⚠️ Failed to obtain access token. This may be due to network issues or authorization timeout.")}\n\n` +
162
- `${chalk.bold("💡 Solution:")}\n` +
163
- ` • Step 1: Ensure your network can access the service URL: ${chalk.cyan(targetOrigin)}\n` +
164
- ` • Step 2: Run ${chalk.cyan("aigne doc publish")} again\n` +
165
- ` • Step 3: If prompted, select ${chalk.cyan("Resume previous website setup")} to continue from where you left off\n\n`,
166
- );
167
- }
168
-
169
- return accessToken;
170
- }
171
-
172
- /**
173
- * Gets the official access token from the environment, config file, or prompts the user to authorize.
174
- * @param {string} baseUrl - The official service URL.
175
- * @returns {Promise<string>} The access token.
176
- */
177
- export async function getOfficialAccessToken(baseUrl, openPage = true, locale = "en") {
178
- if (!baseUrl) {
179
- throw new Error("The baseUrl parameter is required for getOfficialAccessToken.");
180
- }
181
-
182
- // Parse URL once and reuse
183
- const { hostname: targetHostname, origin: targetOrigin } = new URL(baseUrl);
184
-
185
- // 1. Check environment variable
186
- let accessToken = await getCachedAccessToken(targetOrigin);
187
-
188
- // If token is found, return it
189
- if (accessToken || !openPage) {
190
- return accessToken;
191
- }
192
-
193
- // Generate new access token
194
- const connectUrl = joinURL(targetOrigin, WELLKNOWN_SERVICE_PATH_PREFIX);
195
-
196
- try {
197
- const result = await createConnect({
198
- connectUrl,
199
- connectAction: "gen-simple-access-key",
200
- source: "AIGNE DocSmith connect to official service",
201
- closeOnSuccess: true,
202
- retry: RETRY_COUNT,
203
- fetchInterval: FETCH_INTERVAL,
204
- appName: "AIGNE DocSmith",
205
- appLogo: "https://docsmith.aigne.io/image-bin/uploads/9645caf64b4232699982c4d940b03b90.svg",
206
- openPage: async (pageUrl) => {
207
- const url = new URL(pageUrl);
208
- if (locale) {
209
- url.searchParams.set("locale", locale);
210
- }
211
-
212
- let connectUrl = url.toString();
213
- open(connectUrl);
214
- try {
215
- const officialBaseUrl = process.env.DOC_SMITH_BASE_URL || CLOUD_SERVICE_URL_PROD;
216
- const mountPoint = await getComponentMountPoint(officialBaseUrl, PAYMENT_KIT_DID);
217
- const response = await fetch(
218
- withQuery(joinURL(officialBaseUrl, mountPoint, "/api/tool/short-connect-url"), {
219
- url: connectUrl,
220
- locale,
221
- }),
222
- );
223
- const data = await response.json();
224
- if (data.url) {
225
- connectUrl = data.url;
226
- }
227
- } catch {
228
- // Ignore error
229
- }
230
-
231
- console.log(
232
- "🔗 Please open the following URL in your browser to authorize access:",
233
- chalk.cyan(connectUrl),
234
- "\n",
235
- );
236
- },
237
- });
238
-
239
- accessToken = result.accessKeySecret;
240
-
241
- // Save the access token to config file
242
- await saveTokenToConfigFile(targetHostname, { DOC_DISCUSS_KIT_ACCESS_TOKEN: accessToken });
243
- } catch {
244
- throw new Error(
245
- `${chalk.yellow("⚠️ Failed to obtain official access token. This may be due to network issues or authorization timeout.")}\n\n` +
246
- `${chalk.bold("💡 Solution:")}\n` +
247
- ` • Step 1: Ensure your network can access the official service URL: ${chalk.cyan(targetOrigin)}\n` +
248
- ` • Step 2: Run ${chalk.cyan("aigne doc publish")} again\n\n`,
249
- );
250
- }
251
-
252
- return accessToken;
253
- }
254
-
255
- /**
256
- * Saves the access token and related fields to the configuration file.
257
- * @param {string} configFile - The path to the config file.
258
- * @param {string} hostname - The hostname key.
259
- * @param {Object} fields - Fields to save (e.g., { DOC_DISCUSS_KIT_ACCESS_TOKEN: "..." }).
260
- */
261
- async function saveTokenToConfigFile(hostname, fields) {
262
- try {
263
- const store = await createStore();
264
-
265
- const aigneDir = join(homedir(), ".aigne");
266
- if (!existsSync(aigneDir)) {
267
- mkdirSync(aigneDir, { recursive: true });
268
- }
269
-
270
- await store.setItem(hostname, fields);
271
- } catch (error) {
272
- console.warn(`Could not save the token to the configuration file: ${error.message}`, error);
273
- // The token is already in the environment, so we don't need to throw an error here.
274
- }
275
- }
@@ -1,104 +0,0 @@
1
- import { joinURL } from "ufo";
2
-
3
- /**
4
- * Custom error class for invalid blocklet application URLs.
5
- */
6
- export class InvalidBlockletError extends Error {
7
- constructor(url, status, statusText) {
8
- super(`The application URL "${url}" is invalid. I was unable to fetch the configuration.`);
9
- this.name = "InvalidBlockletError";
10
- this.url = url;
11
- this.status = status;
12
- this.statusText = statusText;
13
- }
14
- }
15
-
16
- /**
17
- * Custom error class for missing component mount points.
18
- */
19
- export class ComponentNotFoundError extends Error {
20
- constructor(did, appUrl) {
21
- super(`Your website "${appUrl}" is missing a required component to host your documentation.`);
22
- this.name = "ComponentNotFoundError";
23
- this.did = did;
24
- this.appUrl = appUrl;
25
- }
26
- }
27
-
28
- const BLOCKLET_INFO_CACHE = {};
29
-
30
- // Export for testing purposes
31
- export function clearBlockletCache() {
32
- Object.keys(BLOCKLET_INFO_CACHE).forEach((key) => {
33
- delete BLOCKLET_INFO_CACHE[key];
34
- });
35
- }
36
-
37
- export async function getComponentInfo(appUrl) {
38
- const blockletJsUrl = joinURL(appUrl, "__blocklet__.js?type=json");
39
-
40
- const cacheInfo = BLOCKLET_INFO_CACHE[appUrl];
41
-
42
- // Cache for 10 min
43
- if (cacheInfo) {
44
- if (Date.now() > cacheInfo.__blocklet_info_cache_timestamp + 1000 * 60 * 10) {
45
- delete BLOCKLET_INFO_CACHE[appUrl];
46
- } else {
47
- // Return a copy without the cache timestamp
48
- const { __blocklet_info_cache_timestamp, ...config } = cacheInfo;
49
- return config;
50
- }
51
- }
52
-
53
- let blockletJs;
54
- try {
55
- blockletJs = await fetch(blockletJsUrl, {
56
- method: "GET",
57
- headers: { Accept: "application/json" },
58
- });
59
- } catch (error) {
60
- throw new InvalidBlockletError(appUrl, null, error.message);
61
- }
62
-
63
- if (!blockletJs.ok) {
64
- throw new InvalidBlockletError(appUrl, blockletJs.status, blockletJs.statusText);
65
- }
66
-
67
- let config;
68
- try {
69
- config = await blockletJs.json();
70
- BLOCKLET_INFO_CACHE[appUrl] = {
71
- ...config,
72
- __blocklet_info_cache_timestamp: Date.now(),
73
- };
74
- } catch {
75
- throw new InvalidBlockletError(appUrl, null, "The server returned an invalid JSON response.");
76
- }
77
-
78
- return config;
79
- }
80
-
81
- export async function getComponentMountPoint(appUrl, did) {
82
- const config = await getComponentInfo(appUrl);
83
-
84
- const component = config.componentMountPoints?.find((component) => component.did === did);
85
- if (!component) {
86
- throw new ComponentNotFoundError(did, appUrl);
87
- }
88
-
89
- return component.mountPoint;
90
- }
91
-
92
- export async function getComponentInfoWithMountPoint(appUrl, did) {
93
- const config = await getComponentInfo(appUrl);
94
-
95
- const component = config.componentMountPoints?.find((component) => component.did === did);
96
- if (!component) {
97
- throw new ComponentNotFoundError(did, appUrl);
98
- }
99
-
100
- return {
101
- ...config,
102
- mountPoint: component.mountPoint,
103
- };
104
- }