@aigne/doc-smith 0.8.15-beta.9 → 0.8.15

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 (59) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/agents/evaluate/document-structure.yaml +3 -1
  3. package/agents/evaluate/document.yaml +3 -1
  4. package/agents/generate/generate-structure.yaml +1 -5
  5. package/agents/generate/merge-diagram.yaml +4 -4
  6. package/agents/generate/update-document-structure.yaml +51 -45
  7. package/agents/generate/user-review-document-structure.mjs +3 -26
  8. package/agents/generate/utils/merge-document-structures.mjs +4 -4
  9. package/agents/init/check.mjs +1 -1
  10. package/agents/init/index.mjs +52 -2
  11. package/agents/init/validate.mjs +16 -0
  12. package/agents/publish/publish-docs.mjs +16 -10
  13. package/agents/schema/document-execution-structure.yaml +1 -1
  14. package/agents/schema/document-structure-item.yaml +1 -1
  15. package/agents/schema/document-structure.yaml +4 -2
  16. package/agents/update/check-generate-diagram.mjs +74 -16
  17. package/agents/update/generate-document.yaml +1 -13
  18. package/agents/update/handle-document-update.yaml +1 -1
  19. package/agents/update/pre-check-generate-diagram.yaml +44 -0
  20. package/agents/update/update-document-detail.yaml +64 -58
  21. package/agents/update/update-single-document.yaml +1 -1
  22. package/agents/update/user-review-document.mjs +2 -1
  23. package/agents/utils/analyze-feedback-intent.yaml +29 -0
  24. package/agents/utils/choose-docs.mjs +16 -6
  25. package/agents/utils/find-item-by-path.mjs +4 -2
  26. package/agents/utils/load-sources.mjs +4 -4
  27. package/agents/utils/map-reasoning-effort-level.mjs +15 -0
  28. package/agents/utils/save-sidebar.mjs +12 -33
  29. package/agents/utils/{transform-detail-datasources.mjs → transform-detail-data-sources.mjs} +2 -2
  30. package/aigne.yaml +7 -3
  31. package/package.json +10 -9
  32. package/prompts/common/document/content-rules-core.md +5 -5
  33. package/prompts/common/document-structure/conflict-resolution-guidance.md +2 -2
  34. package/prompts/common/document-structure/document-structure-rules.md +8 -8
  35. package/prompts/common/document-structure/output-constraints.md +3 -3
  36. package/prompts/detail/custom/custom-code-block.md +36 -1
  37. package/prompts/detail/custom/{custom-components.md → custom-components-usage-rules.md} +29 -7
  38. package/prompts/detail/d2-diagram/pre-check.md +23 -0
  39. package/prompts/detail/d2-diagram/rules.md +42 -24
  40. package/prompts/detail/d2-diagram/user-prompt.md +0 -20
  41. package/prompts/detail/generate/document-rules.md +2 -2
  42. package/prompts/detail/generate/system-prompt.md +3 -3
  43. package/prompts/detail/generate/user-prompt.md +5 -5
  44. package/prompts/detail/update/system-prompt.md +4 -3
  45. package/prompts/detail/update/user-prompt.md +8 -4
  46. package/prompts/evaluate/document.md +0 -4
  47. package/prompts/structure/check-document-structure.md +4 -4
  48. package/prompts/structure/generate/system-prompt.md +0 -1
  49. package/prompts/structure/generate/user-prompt.md +14 -9
  50. package/prompts/structure/review/structure-review-system.md +5 -2
  51. package/prompts/structure/update/system-prompt.md +0 -13
  52. package/prompts/structure/update/user-prompt.md +6 -5
  53. package/prompts/translate/translate-document.md +3 -3
  54. package/prompts/utils/analyze-feedback-intent.md +55 -0
  55. package/utils/constants/index.mjs +38 -0
  56. package/utils/deploy.mjs +3 -1
  57. package/utils/docs-finder-utils.mjs +37 -3
  58. package/utils/file-utils.mjs +97 -0
  59. package/utils/load-config.mjs +19 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.15](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.16...v0.8.15) (2025-11-07)
4
+
5
+ ## [0.8.15-beta.16](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.15...v0.8.15-beta.16) (2025-11-07)
6
+
7
+
8
+ ### Features
9
+
10
+ * support customize diagramming quantity ([#277](https://github.com/AIGNE-io/aigne-doc-smith/issues/277)) ([9d9fa6a](https://github.com/AIGNE-io/aigne-doc-smith/commit/9d9fa6a1f344c93df187f2dc502c5479e304e0f4))
11
+
12
+ ## [0.8.15-beta.15](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.14...v0.8.15-beta.15) (2025-11-07)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * add two-tier thinking effort configuration system ([#273](https://github.com/AIGNE-io/aigne-doc-smith/issues/273)) ([b72d066](https://github.com/AIGNE-io/aigne-doc-smith/commit/b72d066698bae253a9ee2dfa231bf73cd59d7529))
18
+
19
+ ## [0.8.15-beta.14](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.13...v0.8.15-beta.14) (2025-11-06)
20
+
21
+
22
+ ### Features
23
+
24
+ * add reasoning effort configuration for customizable AI model settings ([#270](https://github.com/AIGNE-io/aigne-doc-smith/issues/270)) ([9f15638](https://github.com/AIGNE-io/aigne-doc-smith/commit/9f156387120e8705bf16cf611d7f8f39995c36b3))
25
+ * **cli:** enhance auth with short link responses and detailed error reporting for publishing ([#269](https://github.com/AIGNE-io/aigne-doc-smith/issues/269)) ([31cc252](https://github.com/AIGNE-io/aigne-doc-smith/commit/31cc25236667236dfe91543acdd7e8cccff659c5))
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * use default reasoning effort for existing config ([#272](https://github.com/AIGNE-io/aigne-doc-smith/issues/272)) ([2fc9c89](https://github.com/AIGNE-io/aigne-doc-smith/commit/2fc9c89e383c1c5446f2109a2846e831d1e1e871))
31
+
32
+ ## [0.8.15-beta.13](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.12...v0.8.15-beta.13) (2025-11-05)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * make paid deployment more smooth stable ([#266](https://github.com/AIGNE-io/aigne-doc-smith/issues/266)) ([ce8c00a](https://github.com/AIGNE-io/aigne-doc-smith/commit/ce8c00ab3eb045c482e07dc3c4e3bd149e754a06))
38
+ * validate docsDir on init and ensure latest doc on view after publish ([#267](https://github.com/AIGNE-io/aigne-doc-smith/issues/267)) ([e45864d](https://github.com/AIGNE-io/aigne-doc-smith/commit/e45864da4a7fb5b09af2bbffdb7ca93abd74397c))
39
+
40
+ ## [0.8.15-beta.12](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.11...v0.8.15-beta.12) (2025-11-05)
41
+
42
+
43
+ ### Features
44
+
45
+ * tune token consumption for update ops with intent analysis ([#264](https://github.com/AIGNE-io/aigne-doc-smith/issues/264)) ([8c53d28](https://github.com/AIGNE-io/aigne-doc-smith/commit/8c53d288346ae622e8841866db1b6fbed9d5023d))
46
+
47
+ ## [0.8.15-beta.11](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.10...v0.8.15-beta.11) (2025-11-04)
48
+
49
+
50
+ ### Features
51
+
52
+ * warn on invalid sources and tuning translate messages ([#241](https://github.com/AIGNE-io/aigne-doc-smith/issues/241)) ([bd786ca](https://github.com/AIGNE-io/aigne-doc-smith/commit/bd786cad8b0c6fa837511fdc2982c83b7f0095dd))
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * avoid useless diagram generate ([#245](https://github.com/AIGNE-io/aigne-doc-smith/issues/245)) ([de7600f](https://github.com/AIGNE-io/aigne-doc-smith/commit/de7600fb5839be9d1f0743adc34fd08c4c11729d))
58
+ * iterate on chunk of datasource to generate structure ([#242](https://github.com/AIGNE-io/aigne-doc-smith/issues/242)) ([0b4db2a](https://github.com/AIGNE-io/aigne-doc-smith/commit/0b4db2a8cac77d6f4a1c197374b9dadbe078346b))
59
+
60
+ ## [0.8.15-beta.10](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.9...v0.8.15-beta.10) (2025-11-03)
61
+
62
+
63
+ ### Bug Fixes
64
+
65
+ * remove empty xml tag in prompt ([#239](https://github.com/AIGNE-io/aigne-doc-smith/issues/239)) ([1ec771e](https://github.com/AIGNE-io/aigne-doc-smith/commit/1ec771eb8855bca3730f732a1b68404275633787))
66
+ * standardized variable names and xml tag usage ([#237](https://github.com/AIGNE-io/aigne-doc-smith/pull/237))([00f18b9](https://github.com/AIGNE-io/aigne-doc-smith/commit/00f18b95ba21cd376e369eefb102d2d258e95529))
67
+
3
68
  ## [0.8.15-beta.9](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.15-beta.8...v0.8.15-beta.9) (2025-11-03)
4
69
 
5
70
 
@@ -2,7 +2,9 @@ name: evaluateDocumentStructure
2
2
  description: Evaluates the results generated by the document-structure agent to ensure they meet expectations, especially in scenarios with previous generation results and user feedback.
3
3
  instructions:
4
4
  url: ../../prompts/evaluate/document-structure.md
5
- model: openai/gpt-5
5
+ model:
6
+ model: openai/gpt-5
7
+ temperature: 1
6
8
  # model: anthropic/claude-opus-4-0
7
9
  task_render_mode: collapse
8
10
  task_title: Evaluate the structure of the documentation
@@ -2,7 +2,9 @@ name: evaluateDocument
2
2
  description: Evaluates the quality of generated document content, ensuring compliance with user-configured goals, audiences, and knowledge level requirements.
3
3
  instructions:
4
4
  url: ../../prompts/evaluate/document.md
5
- model: openai/gpt-5
5
+ model:
6
+ model: openai/gpt-5
7
+ temperature: 1
6
8
  # model: anthropic/claude-opus-4-0
7
9
  task_render_mode: collapse
8
10
  task_title: Evaluate document for '{{ title }}'
@@ -4,11 +4,9 @@ description: Generate the structure and organization of your documentation
4
4
  skills:
5
5
  - type: team
6
6
  name: generateStructureWorker
7
- iterate_on: datasources
7
+ iterate_on: dataSources
8
8
  skills:
9
9
  - type: ai
10
- model:
11
- reasoning_effort: 500
12
10
  instructions:
13
11
  - role: system
14
12
  url: ../../prompts/structure/generate/system-prompt.md
@@ -82,8 +80,6 @@ skills:
82
80
 
83
81
  - type: ai
84
82
  name: refineStructure
85
- model:
86
- reasoning_effort: 500
87
83
  instructions:
88
84
  - role: system
89
85
  url: ../../prompts/structure/review/structure-review-system.md
@@ -3,13 +3,13 @@ description: Merge Diagram source code into document
3
3
  instructions: |
4
4
  You are an AI assistant that helps to merge d2 diagram into document.
5
5
 
6
- <detail_dataSource>
6
+ <detail_data_source>
7
7
  {{ content }}
8
- </detail_dataSource>
8
+ </detail_data_source>
9
9
 
10
- <diagramSourceCode>
10
+ <diagram_source_code>
11
11
  {{ diagramSourceCode }}
12
- </diagramSourceCode>
12
+ </diagram_source_code>
13
13
 
14
14
  Given the source content of a document and the D2 diagram source code, your task is to:
15
15
  - **Keep the original content as soon as possible.**
@@ -1,48 +1,54 @@
1
- type: ai
1
+ type: team
2
2
  name: updateDocumentStructure
3
3
  description: Update documentation structure based on user feedback and intentions using structure modification tools
4
- instructions:
5
- - role: system
6
- url: ../../prompts/structure/update/system-prompt.md
7
- - role: user
8
- url: ../../prompts/structure/update/user-prompt.md
9
- input_schema:
10
- type: object
11
- properties:
12
- documentStructure: ../schema/document-structure.yaml
13
- rules:
14
- type: string
15
- description: User configuration rules
16
- locale:
17
- type: string
18
- description: User language, e.g. zh, en
19
- dataSourceChunk:
20
- type: string
21
- description: Context for documentation structure
22
- glossary:
23
- type: string
24
- description: Glossary of terms
25
- feedback:
26
- type: string
27
- description: User feedback for structure modifications
28
- userPreferences:
29
- type: string
30
- description: Your saved preferences for structure and documentation style
31
- required:
32
- - documentStructure
33
- - feedback
34
- output_key: message
35
- afs:
36
- modules:
37
- - module: system-fs
38
- options:
39
- mount: /sources
40
- path: .
41
- description: |
42
- Codebase of the project to be documented used as context for document generation,
43
- should search and read as needed while generating document content
44
4
  skills:
45
- - ./document-structure-tools/add-document.mjs
46
- - ./document-structure-tools/delete-document.mjs
47
- - ./document-structure-tools/update-document.mjs
48
- - ./document-structure-tools/move-document.mjs
5
+ - url: ../utils/analyze-feedback-intent.yaml
6
+ - type: ai
7
+ instructions:
8
+ - role: system
9
+ url: ../../prompts/structure/update/system-prompt.md
10
+ - role: user
11
+ url: ../../prompts/structure/update/user-prompt.md
12
+ input_schema:
13
+ type: object
14
+ properties:
15
+ documentStructure: ../schema/document-structure.yaml
16
+ rules:
17
+ type: string
18
+ description: User configuration rules
19
+ locale:
20
+ type: string
21
+ description: User language, e.g. zh, en
22
+ dataSourceChunk:
23
+ type: string
24
+ description: Context for documentation structure
25
+ glossary:
26
+ type: string
27
+ description: Glossary of terms
28
+ feedback:
29
+ type: string
30
+ description: User feedback for structure modifications
31
+ userPreferences:
32
+ type: string
33
+ description: Your saved preferences for structure and documentation style
34
+ needDataSources:
35
+ type: boolean
36
+ description: Whether data sources are needed for content modifications
37
+ required:
38
+ - documentStructure
39
+ - feedback
40
+ output_key: message
41
+ afs:
42
+ modules:
43
+ - module: system-fs
44
+ options:
45
+ mount: /sources
46
+ path: .
47
+ description: |
48
+ Codebase of the project to be documented used as context for document generation,
49
+ should search and read as needed while generating document content
50
+ skills:
51
+ - ./document-structure-tools/add-document.mjs
52
+ - ./document-structure-tools/delete-document.mjs
53
+ - ./document-structure-tools/update-document.mjs
54
+ - ./document-structure-tools/move-document.mjs
@@ -1,32 +1,9 @@
1
1
  import { getActiveRulesForScope } from "../../utils/preferences-utils.mjs";
2
2
  import { recordUpdate } from "../../utils/history-utils.mjs";
3
+ import { buildDocumentTree } from "../../utils/docs-finder-utils.mjs";
3
4
 
4
5
  function formatDocumentStructure(structure) {
5
- // Create a map of nodes for easy lookup
6
- const nodeMap = new Map();
7
- const rootNodes = [];
8
-
9
- // First pass: create node map
10
- structure.forEach((node) => {
11
- nodeMap.set(node.path, {
12
- ...node,
13
- children: [],
14
- });
15
- });
16
-
17
- // Build the tree structure
18
- structure.forEach((node) => {
19
- if (node.parentId) {
20
- const parent = nodeMap.get(node.parentId);
21
- if (parent) {
22
- parent.children.push(nodeMap.get(node.path));
23
- } else {
24
- rootNodes.push(nodeMap.get(node.path));
25
- }
26
- } else {
27
- rootNodes.push(nodeMap.get(node.path));
28
- }
29
- });
6
+ const { rootNodes } = buildDocumentTree(structure);
30
7
 
31
8
  function printNode(node, depth = 0) {
32
9
  const INDENT_SPACES = " ";
@@ -140,7 +117,7 @@ export default async function userReviewDocumentStructure({ documentStructure, .
140
117
  // Call refineDocumentStructure agent with feedback
141
118
  await options.context.invoke(refineAgent, {
142
119
  ...rest,
143
- dataSourceChunk: rest.datasources[0].dataSourceChunk,
120
+ dataSourceChunk: rest.dataSources[0].dataSourceChunk,
144
121
  feedback: feedback.trim(),
145
122
  documentStructure: currentStructure,
146
123
  userPreferences,
@@ -11,13 +11,13 @@ export default async function mergeDocumentStructures(input, options) {
11
11
 
12
12
  options.context.userContext.originalDocumentStructure ??= [];
13
13
 
14
- const originalStructures = options.context.userContext.originalDocumentStructure;
14
+ const originalStructures = [...options.context.userContext.originalDocumentStructure];
15
15
 
16
16
  if (input.structures) {
17
17
  for (const item of input.structures) {
18
- const old = originalStructures.find((s) => s.path === item.path);
19
- if (old) {
20
- Object.assign(old, item);
18
+ const index = originalStructures.findIndex((s) => s.path === item.path);
19
+ if (index !== -1) {
20
+ originalStructures[index] = item;
21
21
  } else {
22
22
  originalStructures.push(item);
23
23
  }
@@ -6,7 +6,7 @@ export default async function checkNeedGenerate({ docsDir, locale, documentExecu
6
6
 
7
7
  if (mainLanguageFiles.length === 0) {
8
8
  console.log(
9
- `No documents found in the docs directory. Please run ${chalk.yellow("`aigne doc generate`")} to generate the documents`,
9
+ `No documents found in the docs directory. You can generate them with ${chalk.yellow("`aigne doc generate`")}`,
10
10
  );
11
11
  process.exit(0);
12
12
  }
@@ -4,6 +4,8 @@ import chalk from "chalk";
4
4
  import { stringify as yamlStringify } from "yaml";
5
5
  import { getFilteredOptions } from "../../utils/conflict-detector.mjs";
6
6
  import {
7
+ DEFAULT_REASONING_EFFORT_LEVEL,
8
+ DEFAULT_THINKING_EFFORT_LEVEL,
7
9
  DEPTH_RECOMMENDATION_LOGIC,
8
10
  DOCUMENT_STYLES,
9
11
  DOCUMENTATION_DEPTH,
@@ -21,6 +23,8 @@ import {
21
23
  validatePath,
22
24
  } from "../../utils/utils.mjs";
23
25
  import { isRemoteFile } from "../../utils/file-utils.mjs";
26
+ import { validateDocDir } from "./validate.mjs";
27
+ import mapReasoningEffortLevel from "../utils/map-reasoning-effort-level.mjs";
24
28
 
25
29
  const _PRESS_ENTER_TO_FINISH = "Press Enter to finish";
26
30
 
@@ -31,7 +35,23 @@ const _PRESS_ENTER_TO_FINISH = "Press Enter to finish";
31
35
  * @param {string} params.fileName - The name of the file.
32
36
  * @returns {Promise<Object>}
33
37
  */
34
- export default async function init(
38
+ export default async function init(input, options) {
39
+ const config = await _init(input, options);
40
+
41
+ // Set thinking effort (lite/standard/pro) and map to reasoningEffort
42
+ options.context.userContext.thinkingEffort =
43
+ config.thinking?.effort || DEFAULT_THINKING_EFFORT_LEVEL;
44
+
45
+ // Set global reasoningEffort based on thinkingEffort
46
+ options.context.userContext.reasoningEffort = mapReasoningEffortLevel(
47
+ { level: DEFAULT_REASONING_EFFORT_LEVEL },
48
+ options,
49
+ )?.reasoningEffort;
50
+
51
+ return config;
52
+ }
53
+
54
+ async function _init(
35
55
  {
36
56
  outputPath = ".aigne/doc-smith",
37
57
  fileName = "config.yaml",
@@ -64,7 +84,19 @@ export default async function init(
64
84
  // Only skip if file exists AND has non-empty content
65
85
  if (configContent && configContent.trim() !== "") {
66
86
  // load config from file
67
- return loadConfig({ config: filePath, appUrl });
87
+ const config = await loadConfig({ config: filePath, appUrl });
88
+ const isValid = validateDocDir(config.docsDir);
89
+ if (typeof isValid === "string") {
90
+ console.log(
91
+ `${chalk.red("Invalid docsDir")}: ${isValid}\nPlease check your configuration.`,
92
+ );
93
+ process.exit(1);
94
+ }
95
+ if (!isValid) {
96
+ console.log(`${chalk.red("Invalid docsDir")}, please check your configuration.`);
97
+ process.exit(1);
98
+ }
99
+ return config;
68
100
  }
69
101
  }
70
102
 
@@ -241,6 +273,7 @@ export default async function init(
241
273
  const docsDirInput = await options.prompts.input({
242
274
  message: `📁 [7/9]: Where should we save your documentation?`,
243
275
  default: `${outputPath}/docs`,
276
+ validate: validateDocDir,
244
277
  });
245
278
  input.docsDir = docsDirInput.trim() || `${outputPath}/docs`;
246
279
 
@@ -424,6 +457,10 @@ export function generateYAML(input) {
424
457
  projectDesc: input.projectDesc || "",
425
458
  projectLogo: input.projectLogo || "",
426
459
 
460
+ thinking: {
461
+ effort: input.thinking?.effort || DEFAULT_THINKING_EFFORT_LEVEL,
462
+ },
463
+
427
464
  // Documentation configuration
428
465
  documentPurpose: input.documentPurpose || [],
429
466
  targetAudienceTypes: input.targetAudienceTypes || [],
@@ -459,6 +496,19 @@ export function generateYAML(input) {
459
496
 
460
497
  yaml += `${projectSection}\n\n`;
461
498
 
499
+ const modelSection = yamlStringify({
500
+ thinking: config.thinking,
501
+ }).trim();
502
+
503
+ yaml += `\
504
+ # AI Thinking Configuration
505
+ # thinking.effort: Determines the depth of reasoning and cognitive effort the AI uses when responding, available options:
506
+ # - lite: Fast responses with basic reasoning
507
+ # - standard: Balanced speed and reasoning capability
508
+ # - pro: In-depth reasoning with longer response times
509
+ ${modelSection}
510
+ \n`;
511
+
462
512
  // Add documentation configuration with comments
463
513
  yaml += "# =============================================================================\n";
464
514
  yaml += "# Documentation Configuration\n";
@@ -0,0 +1,16 @@
1
+ import path from "node:path";
2
+ export function validateDocDir(input) {
3
+ const currentDir = process.cwd();
4
+ const targetDir = path.resolve(input);
5
+ const relativePath = path.relative(currentDir, targetDir);
6
+ if (relativePath.length === 0) {
7
+ return `Can't use current directory: ${targetDir}`;
8
+ }
9
+ if (relativePath.startsWith("..")) {
10
+ return `Can't use directory outside current directory: ${targetDir}`;
11
+ }
12
+ if (path.isAbsolute(relativePath)) {
13
+ return `Can't use absolute path: ${targetDir}`;
14
+ }
15
+ return true;
16
+ }
@@ -163,8 +163,13 @@ export default async function publishDocs(
163
163
  } else {
164
164
  console.log(`\nCreating a new website for your documentation...`);
165
165
  }
166
- const { appUrl: homeUrl, token: ltToken } = (await deploy(id, paymentLink)) || {};
166
+ const {
167
+ appUrl: homeUrl,
168
+ token: ltToken,
169
+ sessionId: newSessionId,
170
+ } = (await deploy(id, paymentLink)) || {};
167
171
 
172
+ sessionId = newSessionId;
168
173
  appUrl = homeUrl;
169
174
  token = ltToken;
170
175
  } catch (error) {
@@ -174,13 +179,7 @@ export default async function publishDocs(
174
179
  }
175
180
  }
176
181
 
177
- if (sessionId) {
178
- authToken = await getOfficialAccessToken(BASE_URL, false);
179
- client = client || new BrokerClient({ baseUrl: BASE_URL, authToken });
180
-
181
- const { vendors } = await client.getSessionDetail(sessionId, false);
182
- token = vendors?.find((vendor) => vendor.vendorType === "launcher" && vendor.token)?.token;
183
- }
182
+ appUrl = appUrl ?? CLOUD_SERVICE_URL_PROD;
184
183
 
185
184
  console.log(`\nPublishing your documentation to ${chalk.cyan(appUrl)}\n`);
186
185
 
@@ -264,8 +263,15 @@ export default async function publishDocs(
264
263
  await saveValueToConfig("shouldSyncBranding", "", "Should sync branding for documentation");
265
264
  } else {
266
265
  // If the error is 401 or 403, it means the access token is invalid
267
- if (error?.includes("401") || error?.includes("403")) {
268
- message = `❌ Publishing failed due to an authorization error. Please run ${chalk.cyan("aigne doc clear")} to reset your credentials and try again.`;
266
+ try {
267
+ const obj = JSON.parse(error);
268
+ message = `❌ Publishing failed with error: \n💡 ${obj.message || error}`;
269
+ } catch {
270
+ if (error?.includes("401")) {
271
+ message = `❌ Publishing failed due to an authorization error: \n💡 Please run ${chalk.cyan("aigne doc clear")} to reset your credentials and try again.`;
272
+ } else if (error?.includes("403")) {
273
+ message = `❌ Publishing failed due to an authorization error: \n💡 You’re not the creator of this document (Board ID: ${boardId}). You can change the board ID and try again. \n💡 Or run ${chalk.cyan("aigne doc clear")} to reset your credentials and try again.`;
274
+ }
269
275
  }
270
276
  }
271
277
 
@@ -25,7 +25,7 @@ items:
25
25
  type: array
26
26
  items:
27
27
  type: string
28
- description: Associated sourceId from dataSources for subsequent translation and content generation, must come from sourceId in datasources, cannot have fake ids, cannot be empty
28
+ description: Associated sourceId from `<data_sources>` for subsequent translation and content generation, must come from sourceId in `<data_sources>`, cannot have fake ids, cannot be empty
29
29
  required:
30
30
  - title
31
31
  - description
@@ -13,7 +13,7 @@ properties:
13
13
  description: Parent node path, if null indicates it is a top-level node
14
14
  sourceIds:
15
15
  type: array
16
- description: Associated sourceId from dataSources for subsequent translation and content generation, must come from sourceId in datasources, cannot have fake ids, **cannot be empty**
16
+ description: Associated sourceId from `<data_sources>` for subsequent translation and content generation, must come from sourceId in `<data_sources>`, cannot have fake ids, **cannot be empty**
17
17
  items:
18
18
  type: string
19
19
  required:
@@ -10,11 +10,13 @@ items:
10
10
  type: string
11
11
  description: Path in URL format, cannot be empty, cannot contain spaces or special characters, must start with /, no need to include language level, e.g., /zh/about should return /about
12
12
  parentId:
13
- type: string
13
+ type:
14
+ - string
15
+ - "null"
14
16
  description: Parent node path, if null indicates it is a top-level node
15
17
  sourceIds:
16
18
  type: array
17
- description: Associated sourceId from dataSources for subsequent translation and content generation, must come from sourceId in datasources, cannot have fake ids, **cannot be empty**
19
+ description: Associated sourceId from `<data_sources>` for subsequent translation and content generation, must come from sourceId in `<data_sources>`, cannot have fake ids, **cannot be empty**
18
20
  items:
19
21
  type: string
20
22
  required:
@@ -1,26 +1,84 @@
1
- const placeholder = "DIAGRAM_PLACEHOLDER";
1
+ const PLACEHOLDER = "DIAGRAM_PLACEHOLDER";
2
+ const DEFAULT_DIAGRAMMING_EFFORT = 5;
3
+ const MIN_DIAGRAMMING_EFFORT = 0;
4
+ const MAX_DIAGRAMMING_EFFORT = 10;
2
5
 
3
6
  export default async function checkGenerateDiagram(
4
- { needDiagram, documentContent, locale },
7
+ {
8
+ documentContent,
9
+ locale,
10
+ feedback,
11
+ detailFeedback,
12
+ originalContent,
13
+ path: docPath,
14
+ diagramming,
15
+ },
5
16
  options,
6
17
  ) {
7
- if (!needDiagram) {
8
- return {};
18
+ let content = documentContent;
19
+ let diagramSourceCode;
20
+ let skipGenerateDiagram = false;
21
+
22
+ const preCheckAgent = options.context?.agents?.["preCheckGenerateDiagram"];
23
+
24
+ const preCheckResult = await options.context.invoke(preCheckAgent, {
25
+ documentContent,
26
+ feedback,
27
+ detailFeedback,
28
+ previousGenerationContent: originalContent,
29
+ });
30
+
31
+ const totalScore = (preCheckResult.details || []).reduce((acc, curr) => acc + curr.score, 0);
32
+ if (![false, "false", "", undefined, null].includes(preCheckResult.content)) {
33
+ content = preCheckResult.content;
9
34
  }
10
35
 
11
- const generateAgent = options.context?.agents?.["generateDiagram"];
12
- let content = documentContent;
36
+ let diagrammingEffort = diagramming?.effort
37
+ ? Number(diagramming?.effort)
38
+ : DEFAULT_DIAGRAMMING_EFFORT;
13
39
 
14
- try {
15
- const { diagramSourceCode } = await options.context.invoke(generateAgent, {
16
- documentContent,
17
- locale,
18
- });
19
- content = content.replace(placeholder, diagramSourceCode);
20
- } catch (error) {
21
- // FIXME: @zhanghan should regenerate document without diagram
22
- content = content.replace(placeholder, "");
23
- console.log(`⚠️ Skip generate any diagram: ${error.message}`);
40
+ if (Number.isNaN(diagrammingEffort)) {
41
+ diagrammingEffort = DEFAULT_DIAGRAMMING_EFFORT;
42
+ } else {
43
+ diagrammingEffort = Math.min(
44
+ Math.max(MIN_DIAGRAMMING_EFFORT, diagrammingEffort),
45
+ MAX_DIAGRAMMING_EFFORT,
46
+ );
24
47
  }
48
+
49
+ if (totalScore <= diagrammingEffort) {
50
+ skipGenerateDiagram = true;
51
+ }
52
+
53
+ if (skipGenerateDiagram) {
54
+ content = documentContent;
55
+ } else {
56
+ try {
57
+ const generateAgent = options.context?.agents?.["generateDiagram"];
58
+ ({ diagramSourceCode } = await options.context.invoke(generateAgent, {
59
+ documentContent: content,
60
+ locale,
61
+ }));
62
+ } catch (error) {
63
+ diagramSourceCode = "";
64
+ skipGenerateDiagram = true;
65
+ console.log(`⚠️ Skip generate any diagram for ${docPath}: ${error.message}`);
66
+ }
67
+
68
+ if (diagramSourceCode && !skipGenerateDiagram) {
69
+ if (content.includes(PLACEHOLDER)) {
70
+ content = content.replace(PLACEHOLDER, diagramSourceCode);
71
+ } else {
72
+ const mergeAgent = options.context?.agents?.["mergeDiagramToDocument"];
73
+ ({ content } = await options.context.invoke(mergeAgent, {
74
+ diagramSourceCode,
75
+ content,
76
+ }));
77
+ }
78
+ } else {
79
+ content = documentContent;
80
+ }
81
+ }
82
+
25
83
  return { content };
26
84
  }
@@ -46,19 +46,7 @@ input_schema:
46
46
  - rules
47
47
  - detailDataSource
48
48
  - originalDocumentStructure
49
- # output_key: content
50
- output_schema:
51
- type: object
52
- properties:
53
- content:
54
- type: string
55
- description: Document content
56
- needDiagram:
57
- type: boolean
58
- description: Does this document need to generate diagram?
59
- required:
60
- - content
61
- - detailDataSource
49
+ output_key: content
62
50
  afs:
63
51
  modules:
64
52
  - module: system-fs
@@ -2,7 +2,7 @@ type: team
2
2
  name: handleDocumentUpdate
3
3
  description: Update a document in a batch
4
4
  skills:
5
- - ../utils/transform-detail-datasources.mjs
5
+ - ../utils/transform-detail-data-sources.mjs
6
6
  - type: team
7
7
  task_render_mode: collapse
8
8
  name: generateDocumentContent