@aigne/doc-smith 0.8.15-beta.1 → 0.8.15-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -0
- package/agents/clear/choose-contents.mjs +4 -4
- package/agents/clear/clear-auth-tokens.mjs +8 -8
- package/agents/clear/clear-deployment-config.mjs +2 -2
- package/agents/clear/clear-document-config.mjs +3 -3
- package/agents/clear/clear-document-structure.mjs +10 -10
- package/agents/clear/clear-generated-docs.mjs +103 -14
- package/agents/clear/clear-media-description.mjs +7 -7
- package/agents/evaluate/document-structure.yaml +3 -1
- package/agents/evaluate/document.yaml +3 -1
- package/agents/evaluate/index.yaml +1 -3
- package/agents/generate/check-diagram.mjs +1 -1
- package/agents/generate/check-need-generate-structure.mjs +2 -7
- package/agents/generate/draw-diagram.yaml +4 -0
- package/agents/generate/generate-structure.yaml +117 -65
- package/agents/generate/index.yaml +3 -3
- package/agents/generate/{merge-d2-diagram.yaml → merge-diagram.yaml} +7 -6
- package/agents/generate/update-document-structure.yaml +1 -1
- package/agents/generate/user-review-document-structure.mjs +3 -25
- package/agents/generate/utils/merge-document-structures.mjs +30 -0
- package/agents/init/check.mjs +4 -2
- package/agents/init/index.mjs +37 -7
- package/agents/media/load-media-description.mjs +12 -24
- package/agents/publish/publish-docs.mjs +3 -8
- package/agents/schema/document-execution-structure.yaml +1 -1
- package/agents/schema/document-structure-item.yaml +23 -0
- package/agents/schema/document-structure-refine-item.yaml +20 -0
- package/agents/schema/document-structure.yaml +1 -1
- package/agents/translate/index.yaml +1 -4
- package/agents/translate/record-translation-history.mjs +6 -2
- package/agents/translate/translate-multilingual.yaml +1 -1
- package/agents/update/batch-generate-document.yaml +1 -1
- package/agents/update/batch-update-document.yaml +1 -1
- package/agents/update/check-document.mjs +35 -13
- package/agents/update/check-generate-diagram.mjs +29 -0
- package/agents/update/generate-diagram.yaml +29 -0
- package/agents/update/generate-document.yaml +17 -30
- package/agents/update/handle-document-update.yaml +10 -1
- package/agents/update/save-and-translate-document.mjs +18 -47
- package/agents/update/update-document-detail.yaml +2 -1
- package/agents/update/update-single-document.yaml +1 -1
- package/agents/update/user-review-document.mjs +6 -5
- package/agents/utils/choose-docs.mjs +16 -5
- package/agents/utils/find-item-by-path.mjs +4 -2
- package/agents/utils/load-sources.mjs +63 -46
- package/agents/utils/{save-docs.mjs → post-generate.mjs} +2 -51
- package/agents/utils/save-doc-translation.mjs +27 -0
- package/agents/utils/{save-single-doc.mjs → save-doc.mjs} +17 -12
- package/agents/utils/save-sidebar.mjs +38 -0
- package/agents/utils/{transform-detail-datasources.mjs → transform-detail-data-sources.mjs} +7 -7
- package/aigne.yaml +16 -8
- package/package.json +3 -1
- package/prompts/common/document/content-rules-core.md +6 -6
- package/prompts/common/document/media-file-list-usage-rules.md +12 -0
- package/prompts/common/document/openapi-usage-rules.md +36 -0
- package/prompts/common/document/role-and-personality.md +1 -2
- package/prompts/common/document-structure/conflict-resolution-guidance.md +2 -2
- package/prompts/common/document-structure/document-structure-rules.md +8 -8
- package/prompts/common/document-structure/output-constraints.md +3 -3
- package/prompts/detail/custom/custom-components.md +38 -3
- package/prompts/detail/d2-diagram/rules.md +11 -14
- package/prompts/detail/d2-diagram/system-prompt.md +0 -14
- package/prompts/detail/d2-diagram/user-prompt.md +39 -0
- package/prompts/detail/generate/document-rules.md +3 -3
- package/prompts/detail/generate/system-prompt.md +2 -6
- package/prompts/detail/generate/user-prompt.md +20 -61
- package/prompts/detail/update/system-prompt.md +2 -6
- package/prompts/detail/update/user-prompt.md +7 -6
- package/prompts/evaluate/document.md +0 -4
- package/prompts/structure/check-document-structure.md +4 -4
- package/prompts/structure/generate/system-prompt.md +0 -31
- package/prompts/structure/generate/user-prompt.md +73 -29
- package/prompts/structure/review/structure-review-system.md +81 -0
- package/prompts/structure/update/system-prompt.md +1 -1
- package/prompts/structure/update/user-prompt.md +4 -4
- package/prompts/translate/code-block.md +13 -3
- package/prompts/translate/translate-document.md +3 -3
- package/types/document-structure-schema.mjs +3 -3
- package/utils/constants/index.mjs +6 -0
- package/utils/docs-finder-utils.mjs +85 -3
- package/utils/extract-api.mjs +32 -0
- package/utils/file-utils.mjs +153 -101
- package/utils/history-utils.mjs +20 -8
- package/utils/load-config.mjs +20 -1
- package/utils/markdown-checker.mjs +35 -1
- package/utils/utils.mjs +67 -65
- package/agents/generate/document-structure-tools/generate-sub-structure.mjs +0 -131
- package/agents/generate/generate-structure-without-tools.yaml +0 -65
- package/prompts/common/document/media-handling-rules.md +0 -9
package/utils/history-utils.mjs
CHANGED
|
@@ -99,7 +99,7 @@ function recordUpdateGit({ feedback }) {
|
|
|
99
99
|
/**
|
|
100
100
|
* Records an update in the YAML file.
|
|
101
101
|
*/
|
|
102
|
-
function recordUpdateYaml({ operation, feedback,
|
|
102
|
+
function recordUpdateYaml({ operation, feedback, docPaths = null }) {
|
|
103
103
|
try {
|
|
104
104
|
const docSmithDir = join(process.cwd(), DOC_SMITH_DIR);
|
|
105
105
|
if (!existsSync(docSmithDir)) {
|
|
@@ -125,9 +125,9 @@ function recordUpdateYaml({ operation, feedback, documentPath = null }) {
|
|
|
125
125
|
feedback,
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
// Add document
|
|
129
|
-
if (
|
|
130
|
-
entry.
|
|
128
|
+
// Add document paths if provided
|
|
129
|
+
if (Array.isArray(docPaths) && docPaths.length > 0) {
|
|
130
|
+
entry.docPaths = docPaths;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// Add to beginning (newest first)
|
|
@@ -153,14 +153,14 @@ function recordUpdateYaml({ operation, feedback, documentPath = null }) {
|
|
|
153
153
|
* @param {Object} params
|
|
154
154
|
* @param {string} params.operation - The type of operation (e.g., 'document_update', 'structure_update', 'translation_update').
|
|
155
155
|
* @param {string} params.feedback - The user's feedback text.
|
|
156
|
-
* @param {string} params.
|
|
156
|
+
* @param {string[]} [params.docPaths] - Document path list for updates.
|
|
157
157
|
*/
|
|
158
|
-
export function recordUpdate({ operation, feedback,
|
|
158
|
+
export function recordUpdate({ operation, feedback, docPaths = null }) {
|
|
159
159
|
// Skip if no feedback
|
|
160
160
|
if (!feedback?.trim()) return;
|
|
161
161
|
|
|
162
162
|
// Always record in YAML
|
|
163
|
-
recordUpdateYaml({ operation, feedback,
|
|
163
|
+
recordUpdateYaml({ operation, feedback, docPaths });
|
|
164
164
|
|
|
165
165
|
// Also record in git if git is available and not in a git repository
|
|
166
166
|
if (isGitAvailable() && !isInGitRepository(process.cwd())) {
|
|
@@ -183,7 +183,19 @@ export function getHistory() {
|
|
|
183
183
|
|
|
184
184
|
try {
|
|
185
185
|
const content = readFileSync(historyPath, "utf8");
|
|
186
|
-
|
|
186
|
+
const parsed = parse(content) || { entries: [] };
|
|
187
|
+
const entries = Array.isArray(parsed.entries) ? parsed.entries : [];
|
|
188
|
+
|
|
189
|
+
const normalized = entries.map((entry) => {
|
|
190
|
+
if (!entry) return entry;
|
|
191
|
+
// Normalize legacy entries: documentPath -> docPaths: [documentPath]
|
|
192
|
+
if (!entry.docPaths && entry.documentPath) {
|
|
193
|
+
return { ...entry, docPaths: [entry.documentPath] };
|
|
194
|
+
}
|
|
195
|
+
return entry;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return { ...parsed, entries: normalized };
|
|
187
199
|
} catch (error) {
|
|
188
200
|
console.warn("Could not read the history:", error.message);
|
|
189
201
|
return { entries: [] };
|
package/utils/load-config.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
+
import chalk from "chalk";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { parse } from "yaml";
|
|
4
5
|
import { processConfigFields, resolveFileReferences } from "./utils.mjs";
|
|
6
|
+
import { DEFAULT_EXCLUDE_PATTERNS } from "./constants/index.mjs";
|
|
7
|
+
import { findInvalidSourcePaths, toDisplayPath } from "./file-utils.mjs";
|
|
5
8
|
|
|
6
9
|
export default async function loadConfig({ config, appUrl }) {
|
|
7
10
|
const configPath = path.isAbsolute(config) ? config : path.join(process.cwd(), config);
|
|
@@ -28,7 +31,23 @@ export default async function loadConfig({ config, appUrl }) {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
// Parse new configuration fields and convert keys to actual content
|
|
31
|
-
const processedConfig = processConfigFields(parsedConfig);
|
|
34
|
+
const processedConfig = await processConfigFields(parsedConfig);
|
|
35
|
+
|
|
36
|
+
// Validate sourcePaths against exclude patterns
|
|
37
|
+
const sourcesPath = processedConfig.sourcesPath || parsedConfig.sourcesPath;
|
|
38
|
+
if (sourcesPath) {
|
|
39
|
+
const excludePatterns = [
|
|
40
|
+
...DEFAULT_EXCLUDE_PATTERNS,
|
|
41
|
+
...(processedConfig.excludePatterns || parsedConfig.excludePatterns || []),
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const invalidPaths = await findInvalidSourcePaths(sourcesPath, excludePatterns);
|
|
45
|
+
if (invalidPaths.length > 0) {
|
|
46
|
+
console.warn(
|
|
47
|
+
`⚠️ Some source paths have been excluded and will not be processed:\n${invalidPaths.map((p) => ` - ${chalk.yellow(p)}`).join("\n")}\n💡 Tip: You can remove these paths in ${toDisplayPath(configPath)}\n`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
32
51
|
|
|
33
52
|
return {
|
|
34
53
|
lastGitHead: parsedConfig.lastGitHead || "",
|
|
@@ -3,9 +3,12 @@ import path from "node:path";
|
|
|
3
3
|
import remarkGfm from "remark-gfm";
|
|
4
4
|
import remarkLint from "remark-lint";
|
|
5
5
|
import remarkParse from "remark-parse";
|
|
6
|
+
import { isRelative } from "ufo";
|
|
6
7
|
import { unified } from "unified";
|
|
7
8
|
import { visit } from "unist-util-visit";
|
|
8
9
|
import { VFile } from "vfile";
|
|
10
|
+
|
|
11
|
+
import { isRemoteFile, isRemoteFileAvailable } from "./file-utils.mjs";
|
|
9
12
|
import { validateMermaidSyntax } from "./mermaid-validator.mjs";
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -232,6 +235,34 @@ function checkLocalImages(markdown, source, errorMessages, markdownFilePath, bas
|
|
|
232
235
|
}
|
|
233
236
|
}
|
|
234
237
|
|
|
238
|
+
async function checkRemoteImages(markdown, source, errorMessages) {
|
|
239
|
+
const imageRegex = /!\[([^\]]*)\]\(([^)]+)\)/g;
|
|
240
|
+
let match;
|
|
241
|
+
|
|
242
|
+
while (true) {
|
|
243
|
+
match = imageRegex.exec(markdown);
|
|
244
|
+
if (match === null) break;
|
|
245
|
+
const imagePath = match[2].trim();
|
|
246
|
+
const altText = match[1];
|
|
247
|
+
|
|
248
|
+
if (isRelative(imagePath)) continue;
|
|
249
|
+
if (imagePath.startsWith("/")) continue;
|
|
250
|
+
|
|
251
|
+
// Skip data URLs
|
|
252
|
+
if (/^data:/.test(imagePath)) continue;
|
|
253
|
+
|
|
254
|
+
if (isRemoteFile(imagePath)) {
|
|
255
|
+
const isAvailable = await isRemoteFileAvailable(imagePath);
|
|
256
|
+
if (isAvailable) continue;
|
|
257
|
+
else {
|
|
258
|
+
errorMessages.push(
|
|
259
|
+
`Found invalid remote image in ${source}:  - only valid media resources can be used`,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
235
266
|
/**
|
|
236
267
|
* Check content structure and formatting issues
|
|
237
268
|
* @param {string} markdown - The markdown content
|
|
@@ -370,7 +401,10 @@ export async function checkMarkdown(markdown, source = "content", options = {})
|
|
|
370
401
|
// 2. Check local images existence
|
|
371
402
|
checkLocalImages(markdown, source, errorMessages, filePath, baseDir);
|
|
372
403
|
|
|
373
|
-
// 3. Check
|
|
404
|
+
// 3. Check remote images existence
|
|
405
|
+
await checkRemoteImages(markdown, source, errorMessages);
|
|
406
|
+
|
|
407
|
+
// 4. Check content structure and formatting issues
|
|
374
408
|
checkContentStructure(markdown, source, errorMessages);
|
|
375
409
|
|
|
376
410
|
// Check mermaid code blocks and other custom validations
|
package/utils/utils.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
SUPPORTED_LANGUAGES,
|
|
19
19
|
TARGET_AUDIENCES,
|
|
20
20
|
} from "./constants/index.mjs";
|
|
21
|
+
import { isRemoteFile, getRemoteFileContent } from "./file-utils.mjs";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Normalize path to absolute path for consistent comparison
|
|
@@ -47,16 +48,6 @@ export function isGlobPattern(pattern) {
|
|
|
47
48
|
return /[*?[\]]|(\*\*)/.test(pattern);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
/**
|
|
51
|
-
* Check if a string is an HTTP/HTTPS URL
|
|
52
|
-
* @param {string} url - The string to check
|
|
53
|
-
* @returns {boolean} - True if the string starts with http:// or https://
|
|
54
|
-
*/
|
|
55
|
-
export function isHttp(url) {
|
|
56
|
-
if (typeof url !== "string") return false;
|
|
57
|
-
return url.startsWith("http://") || url.startsWith("https://");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
51
|
export function processContent({ content }) {
|
|
61
52
|
// Match markdown regular links [text](link), exclude images 
|
|
62
53
|
return content.replace(/(?<!!)\[([^\]]+)\]\(([^)]+)\)/g, (match, text, link) => {
|
|
@@ -81,77 +72,72 @@ export function processContent({ content }) {
|
|
|
81
72
|
});
|
|
82
73
|
}
|
|
83
74
|
|
|
75
|
+
// Helper function to generate filename based on language
|
|
76
|
+
export function getFileName(docPath, language) {
|
|
77
|
+
// Flatten path: remove leading /, replace all / with -
|
|
78
|
+
const flatName = docPath.replace(/^\//, "").replace(/\//g, "-");
|
|
79
|
+
const isEnglish = language === "en";
|
|
80
|
+
return isEnglish ? `${flatName}.md` : `${flatName}.${language}.md`;
|
|
81
|
+
}
|
|
82
|
+
|
|
84
83
|
/**
|
|
85
|
-
* Save a single document
|
|
84
|
+
* Save a single document to files
|
|
86
85
|
* @param {Object} params
|
|
87
86
|
* @param {string} params.path - Relative path (without extension)
|
|
88
87
|
* @param {string} params.content - Main document content
|
|
89
88
|
* @param {string} params.docsDir - Root directory
|
|
90
89
|
* @param {string} params.locale - Main content language (e.g., 'en', 'zh', 'fr')
|
|
91
|
-
* @param {Array<{language: string, translation: string}>} [params.translates] - Translation content
|
|
92
90
|
* @param {Array<string>} [params.labels] - Document labels for front matter
|
|
93
|
-
* @returns {Promise<
|
|
91
|
+
* @returns {Promise<{ path: string, success: boolean, error?: string }>}
|
|
94
92
|
*/
|
|
95
|
-
export async function
|
|
96
|
-
path: docPath,
|
|
97
|
-
content,
|
|
98
|
-
docsDir,
|
|
99
|
-
locale,
|
|
100
|
-
translates = [],
|
|
101
|
-
labels,
|
|
102
|
-
isTranslate = false,
|
|
103
|
-
}) {
|
|
104
|
-
const results = [];
|
|
93
|
+
export async function saveDoc({ path: docPath, content, docsDir, locale, labels }) {
|
|
105
94
|
try {
|
|
106
|
-
// Flatten path: remove leading /, replace all / with -
|
|
107
|
-
const flatName = docPath.replace(/^\//, "").replace(/\//g, "-");
|
|
108
95
|
await fs.mkdir(docsDir, { recursive: true });
|
|
96
|
+
const mainFileName = getFileName(docPath, locale);
|
|
97
|
+
const mainFilePath = path.join(docsDir, mainFileName);
|
|
109
98
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
const isEnglish = language === "en";
|
|
113
|
-
return isEnglish ? `${flatName}.md` : `${flatName}.${language}.md`;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Save main content with appropriate filename based on locale (skip if isTranslate is true)
|
|
117
|
-
if (!isTranslate) {
|
|
118
|
-
const mainFileName = getFileName(locale);
|
|
119
|
-
const mainFilePath = path.join(docsDir, mainFileName);
|
|
120
|
-
|
|
121
|
-
// Add labels front matter if labels are provided
|
|
122
|
-
let finalContent = processContent({ content });
|
|
99
|
+
// Add labels front matter if labels are provided
|
|
100
|
+
let finalContent = processContent({ content });
|
|
123
101
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await fs.writeFile(mainFilePath, finalContent, "utf8");
|
|
130
|
-
results.push({ path: mainFilePath, success: true });
|
|
102
|
+
if (labels && labels.length > 0) {
|
|
103
|
+
const frontMatter = `---\nlabels: ${JSON.stringify(labels)}\n---\n\n`;
|
|
104
|
+
finalContent = frontMatter + finalContent;
|
|
131
105
|
}
|
|
132
106
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
107
|
+
await fs.writeFile(mainFilePath, finalContent, "utf8");
|
|
108
|
+
return { path: mainFilePath, success: true };
|
|
109
|
+
} catch (err) {
|
|
110
|
+
return { path: docPath, success: false, error: err.message };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
137
113
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
114
|
+
export async function saveDocTranslation({
|
|
115
|
+
path: docPath,
|
|
116
|
+
docsDir,
|
|
117
|
+
translation,
|
|
118
|
+
language,
|
|
119
|
+
labels,
|
|
120
|
+
}) {
|
|
121
|
+
try {
|
|
122
|
+
await fs.mkdir(docsDir, { recursive: true });
|
|
123
|
+
const translateFileName = getFileName(docPath, language);
|
|
124
|
+
const translatePath = path.join(docsDir, translateFileName);
|
|
142
125
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
126
|
+
// Add labels front matter to translation content if labels are provided
|
|
127
|
+
let finalTranslationContent = processContent({
|
|
128
|
+
content: translation,
|
|
129
|
+
});
|
|
147
130
|
|
|
148
|
-
|
|
149
|
-
|
|
131
|
+
if (labels && labels.length > 0) {
|
|
132
|
+
const frontMatter = `---\nlabels: ${JSON.stringify(labels)}\n---\n\n`;
|
|
133
|
+
finalTranslationContent = frontMatter + finalTranslationContent;
|
|
150
134
|
}
|
|
135
|
+
|
|
136
|
+
await fs.writeFile(translatePath, finalTranslationContent, "utf8");
|
|
137
|
+
return { path: translatePath, success: true };
|
|
151
138
|
} catch (err) {
|
|
152
|
-
|
|
139
|
+
return { path: docPath, success: false, error: err.message };
|
|
153
140
|
}
|
|
154
|
-
return results;
|
|
155
141
|
}
|
|
156
142
|
|
|
157
143
|
/**
|
|
@@ -963,7 +949,7 @@ export function processTargetAudience(targetAudienceTypes, existingTargetAudienc
|
|
|
963
949
|
* @param {Object} config - Parsed configuration
|
|
964
950
|
* @returns {Object} Processed configuration with content fields
|
|
965
951
|
*/
|
|
966
|
-
export function processConfigFields(config) {
|
|
952
|
+
export async function processConfigFields(config) {
|
|
967
953
|
const processed = {};
|
|
968
954
|
const allRulesContent = [];
|
|
969
955
|
|
|
@@ -995,7 +981,15 @@ export function processConfigFields(config) {
|
|
|
995
981
|
if (typeof config.rules === "string") {
|
|
996
982
|
const existingRules = config.rules.trim();
|
|
997
983
|
if (existingRules) {
|
|
998
|
-
|
|
984
|
+
// load rules from remote url
|
|
985
|
+
if (isRemoteFile(existingRules)) {
|
|
986
|
+
const remoteFileContent = await getRemoteFileContent(existingRules);
|
|
987
|
+
if (remoteFileContent) {
|
|
988
|
+
allRulesContent.push(remoteFileContent);
|
|
989
|
+
}
|
|
990
|
+
} else {
|
|
991
|
+
allRulesContent.push(existingRules);
|
|
992
|
+
}
|
|
999
993
|
}
|
|
1000
994
|
} else if (Array.isArray(config.rules)) {
|
|
1001
995
|
// Handle array of rules - join them with newlines
|
|
@@ -1054,6 +1048,12 @@ export function processConfigFields(config) {
|
|
|
1054
1048
|
}
|
|
1055
1049
|
}
|
|
1056
1050
|
|
|
1051
|
+
if (config.glossary) {
|
|
1052
|
+
if (isRemoteFile(config.glossary)) {
|
|
1053
|
+
processed.glossary = await getRemoteFileContent(config.glossary);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
1057
|
// Detect and handle conflicts in user selections
|
|
1058
1058
|
const conflicts = detectResolvableConflicts(config);
|
|
1059
1059
|
if (conflicts.length > 0) {
|
|
@@ -1097,8 +1097,10 @@ export function processConfigFields(config) {
|
|
|
1097
1097
|
* @returns {Promise<any>} - The processed configuration with file content loaded in place of references.
|
|
1098
1098
|
*/
|
|
1099
1099
|
export async function resolveFileReferences(obj, basePath = process.cwd()) {
|
|
1100
|
-
if (typeof obj === "string"
|
|
1101
|
-
|
|
1100
|
+
if (typeof obj === "string") {
|
|
1101
|
+
if (obj.startsWith("@")) {
|
|
1102
|
+
return await loadFileContent(obj.slice(1), basePath);
|
|
1103
|
+
}
|
|
1102
1104
|
}
|
|
1103
1105
|
|
|
1104
1106
|
if (Array.isArray(obj)) {
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildSourcesContent,
|
|
3
|
-
calculateFileStats,
|
|
4
|
-
loadFilesFromPaths,
|
|
5
|
-
readFileContents,
|
|
6
|
-
} from "../../../utils/file-utils.mjs";
|
|
7
|
-
import {
|
|
8
|
-
INTELLIGENT_SUGGESTION_TOKEN_THRESHOLD,
|
|
9
|
-
DEFAULT_EXCLUDE_PATTERNS,
|
|
10
|
-
DEFAULT_INCLUDE_PATTERNS,
|
|
11
|
-
} from "../../../utils/constants/index.mjs";
|
|
12
|
-
import { toRelativePath } from "../../../utils/utils.mjs";
|
|
13
|
-
|
|
14
|
-
export default async function generateSubStructure(
|
|
15
|
-
{
|
|
16
|
-
parentDocument,
|
|
17
|
-
subSourcePaths,
|
|
18
|
-
includePatterns,
|
|
19
|
-
excludePatterns,
|
|
20
|
-
useDefaultPatterns = true,
|
|
21
|
-
...rest
|
|
22
|
-
},
|
|
23
|
-
options,
|
|
24
|
-
) {
|
|
25
|
-
const sourcePaths = subSourcePaths?.map((item) => item.path);
|
|
26
|
-
if (!sourcePaths || sourcePaths.length === 0) {
|
|
27
|
-
return {
|
|
28
|
-
subStructure: [],
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let files = await loadFilesFromPaths(sourcePaths, {
|
|
33
|
-
includePatterns,
|
|
34
|
-
excludePatterns,
|
|
35
|
-
useDefaultPatterns,
|
|
36
|
-
defaultIncludePatterns: DEFAULT_INCLUDE_PATTERNS,
|
|
37
|
-
defaultExcludePatterns: DEFAULT_EXCLUDE_PATTERNS,
|
|
38
|
-
});
|
|
39
|
-
files = [...new Set(files)];
|
|
40
|
-
|
|
41
|
-
// all files path
|
|
42
|
-
const allFilesPaths = files.map((file) => `- ${toRelativePath(file)}`).join("\n");
|
|
43
|
-
|
|
44
|
-
// Read all source files using the utility function
|
|
45
|
-
const sourceFiles = await readFileContents(files, process.cwd());
|
|
46
|
-
|
|
47
|
-
// Count tokens and lines using utility function
|
|
48
|
-
const { totalTokens } = calculateFileStats(sourceFiles);
|
|
49
|
-
|
|
50
|
-
// check if totalTokens is too large
|
|
51
|
-
let isLargeContext = false;
|
|
52
|
-
if (totalTokens > INTELLIGENT_SUGGESTION_TOKEN_THRESHOLD) {
|
|
53
|
-
isLargeContext = true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Build allSources string using utility function
|
|
57
|
-
const allSources = buildSourcesContent(sourceFiles, isLargeContext);
|
|
58
|
-
|
|
59
|
-
// Performance optimization:
|
|
60
|
-
// Using both structured output and Tool with Gemini model causes redundant calls
|
|
61
|
-
// Only use Tool when context is very large
|
|
62
|
-
const generateStructureAgent = isLargeContext
|
|
63
|
-
? options.context.agents["generateStructure"]
|
|
64
|
-
: options.context.agents["generateStructureWithoutTools"];
|
|
65
|
-
const result = await options.context.invoke(generateStructureAgent, {
|
|
66
|
-
...rest,
|
|
67
|
-
isSubStructure: true,
|
|
68
|
-
parentDocument,
|
|
69
|
-
datasources: allSources,
|
|
70
|
-
allFilesPaths,
|
|
71
|
-
isLargeContext,
|
|
72
|
-
files,
|
|
73
|
-
totalTokens,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
subStructure: result.documentStructure || [],
|
|
78
|
-
message: `Generated a sub structure for '${parentDocument.path}' successfully. Please merge all sub-structures to output the complete document structure.`,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
generateSubStructure.description = `
|
|
83
|
-
Generates a sub-structure.
|
|
84
|
-
Handles large file sets by splitting them into smaller sub-document structures when the context size exceeds limits. This approach ensures more focused and complete documentation generation.
|
|
85
|
-
`;
|
|
86
|
-
|
|
87
|
-
generateSubStructure.inputSchema = {
|
|
88
|
-
type: "object",
|
|
89
|
-
properties: {
|
|
90
|
-
parentDocument: {
|
|
91
|
-
type: "object",
|
|
92
|
-
description: "The parent node to generate a sub structure for",
|
|
93
|
-
properties: {
|
|
94
|
-
title: { type: "string", description: "The title of the parent node" },
|
|
95
|
-
description: { type: "string", description: "The description of the parent node" },
|
|
96
|
-
path: {
|
|
97
|
-
type: "string",
|
|
98
|
-
description:
|
|
99
|
-
"The path of the parent node, 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 ",
|
|
100
|
-
},
|
|
101
|
-
parentId: { type: "string", description: "The parent ID of the parent node" },
|
|
102
|
-
sourceIds: { type: "array", description: "The source IDs of the parent node" },
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
subSourcePaths: {
|
|
106
|
-
type: "array",
|
|
107
|
-
description: "The source paths of the sub structure",
|
|
108
|
-
items: {
|
|
109
|
-
type: "object",
|
|
110
|
-
properties: {
|
|
111
|
-
path: { type: "string", description: "The source path of the sub structure" },
|
|
112
|
-
reason: { type: "string", description: "The reason for selecting the source path" },
|
|
113
|
-
},
|
|
114
|
-
required: ["path", "reason"],
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
generateSubStructure.outputSchema = {
|
|
121
|
-
type: "object",
|
|
122
|
-
properties: {
|
|
123
|
-
subStructure: {
|
|
124
|
-
type: "array",
|
|
125
|
-
description:
|
|
126
|
-
"The sub structure of the parent node, need merge all sub-structures and output the complete document structure.",
|
|
127
|
-
},
|
|
128
|
-
message: { type: "string", description: "The message of the sub structure" },
|
|
129
|
-
},
|
|
130
|
-
required: ["subStructure"],
|
|
131
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
name: generateStructureWithoutTools
|
|
2
|
-
description: Generate the structure and organization of your documentation
|
|
3
|
-
instructions:
|
|
4
|
-
- role: system
|
|
5
|
-
url: ../../prompts/structure/generate/system-prompt.md
|
|
6
|
-
- role: user
|
|
7
|
-
url: ../../prompts/structure/generate/user-prompt.md
|
|
8
|
-
task_render_mode: collapse
|
|
9
|
-
task_title: Generate the structure of the documentation
|
|
10
|
-
input_schema:
|
|
11
|
-
type: object
|
|
12
|
-
properties:
|
|
13
|
-
rules:
|
|
14
|
-
type: string
|
|
15
|
-
description: Your specific requirements for documentation structure
|
|
16
|
-
locale:
|
|
17
|
-
type: string
|
|
18
|
-
description: Primary language for documentation (e.g., zh, en, ja)
|
|
19
|
-
datasources:
|
|
20
|
-
type: string
|
|
21
|
-
description: Project content and context to help generate documentation structure
|
|
22
|
-
targetAudience:
|
|
23
|
-
type: string
|
|
24
|
-
description: Target audience for the documentation
|
|
25
|
-
nodeName:
|
|
26
|
-
type: string
|
|
27
|
-
description: Specific section or page name to focus on
|
|
28
|
-
glossary:
|
|
29
|
-
type: string
|
|
30
|
-
description: Glossary for consistent terminology
|
|
31
|
-
feedback:
|
|
32
|
-
type: string
|
|
33
|
-
description: Tell us how to improve the documentation structure
|
|
34
|
-
userPreferences:
|
|
35
|
-
type: string
|
|
36
|
-
description: Your saved preferences for structure and documentation style
|
|
37
|
-
docsType:
|
|
38
|
-
type: string
|
|
39
|
-
description: "Documentation type (options: general, getting-started, reference, faq)"
|
|
40
|
-
default: general
|
|
41
|
-
required:
|
|
42
|
-
- rules
|
|
43
|
-
- datasources
|
|
44
|
-
output_schema:
|
|
45
|
-
type: object
|
|
46
|
-
properties:
|
|
47
|
-
projectName:
|
|
48
|
-
type: string
|
|
49
|
-
description: Project name identified from your content sources
|
|
50
|
-
projectDesc:
|
|
51
|
-
type: string
|
|
52
|
-
description: Brief project description generated from content analysis (under 50 words)
|
|
53
|
-
documentStructure: ../schema/document-structure.yaml
|
|
54
|
-
documentStructureTree:
|
|
55
|
-
type: string
|
|
56
|
-
description: |
|
|
57
|
-
Visual tree structure showing documentation hierarchy with indented levels for easy review:
|
|
58
|
-
```
|
|
59
|
-
- Home
|
|
60
|
-
- Getting Started
|
|
61
|
-
- Installation
|
|
62
|
-
- Requirements
|
|
63
|
-
```
|
|
64
|
-
required:
|
|
65
|
-
- documentStructure
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<media_handling_rules>
|
|
2
|
-
Media resource usage rules:
|
|
3
|
-
|
|
4
|
-
- When DataSources contain media resource files, incorporate them appropriately in the generated content
|
|
5
|
-
- Media resources are provided in markdown format, example: 
|
|
6
|
-
- Display images in markdown format within generated results
|
|
7
|
-
- Based on resource descriptions, place images strategically in contextually relevant positions to enhance the presentation
|
|
8
|
-
- To ensure correct media resource paths, **only use media resources provided in media_list or remote URL media resources**
|
|
9
|
-
</media_handling_rules>
|