@aigne/doc-smith 0.8.15-beta.8 → 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.
- package/CHANGELOG.md +73 -0
- 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/generate-structure.yaml +25 -71
- package/agents/generate/index.yaml +1 -2
- package/agents/generate/{merge-d2-diagram.yaml → merge-diagram.yaml} +7 -6
- package/agents/generate/update-document-structure.yaml +51 -45
- package/agents/generate/user-review-document-structure.mjs +3 -26
- package/agents/generate/utils/merge-document-structures.mjs +8 -32
- package/agents/init/check.mjs +1 -1
- package/agents/init/index.mjs +52 -2
- package/agents/init/validate.mjs +16 -0
- package/agents/publish/publish-docs.mjs +16 -10
- package/agents/schema/document-execution-structure.yaml +1 -1
- package/agents/schema/document-structure-item.yaml +1 -1
- package/agents/schema/document-structure-refine-item.yaml +20 -0
- package/agents/schema/document-structure.yaml +4 -2
- package/agents/update/batch-generate-document.yaml +1 -1
- package/agents/update/check-generate-diagram.mjs +84 -0
- package/agents/update/generate-diagram.yaml +0 -1
- package/agents/update/generate-document.yaml +4 -4
- package/agents/update/handle-document-update.yaml +9 -1
- package/agents/update/pre-check-generate-diagram.yaml +44 -0
- package/agents/update/update-document-detail.yaml +64 -58
- package/agents/update/update-single-document.yaml +1 -2
- package/agents/update/user-review-document.mjs +8 -6
- package/agents/utils/analyze-feedback-intent.yaml +29 -0
- package/agents/utils/choose-docs.mjs +16 -6
- package/agents/utils/find-item-by-path.mjs +4 -2
- package/agents/utils/load-sources.mjs +6 -6
- package/agents/utils/map-reasoning-effort-level.mjs +15 -0
- package/agents/utils/save-sidebar.mjs +12 -33
- package/agents/utils/{transform-detail-datasources.mjs → transform-detail-data-sources.mjs} +3 -3
- package/aigne.yaml +14 -3
- package/package.json +10 -9
- package/prompts/common/document/content-rules-core.md +6 -6
- 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-code-block.md +36 -1
- package/prompts/detail/custom/{custom-components.md → custom-components-usage-rules.md} +29 -7
- package/prompts/detail/d2-diagram/pre-check.md +23 -0
- package/prompts/detail/d2-diagram/rules.md +44 -29
- package/prompts/detail/d2-diagram/system-prompt.md +0 -14
- package/prompts/detail/d2-diagram/user-prompt.md +10 -1
- package/prompts/detail/generate/document-rules.md +3 -3
- package/prompts/detail/generate/system-prompt.md +2 -8
- package/prompts/detail/generate/user-prompt.md +13 -60
- package/prompts/detail/update/system-prompt.md +3 -8
- package/prompts/detail/update/user-prompt.md +9 -5
- package/prompts/evaluate/document.md +0 -4
- package/prompts/structure/check-document-structure.md +4 -4
- package/prompts/structure/generate/system-prompt.md +0 -1
- package/prompts/structure/generate/user-prompt.md +21 -18
- package/prompts/structure/review/structure-review-system.md +24 -16
- package/prompts/structure/update/system-prompt.md +0 -13
- package/prompts/structure/update/user-prompt.md +6 -5
- package/prompts/translate/translate-document.md +3 -3
- package/prompts/utils/analyze-feedback-intent.md +55 -0
- package/utils/constants/index.mjs +38 -0
- package/utils/deploy.mjs +3 -1
- package/utils/docs-finder-utils.mjs +37 -3
- package/utils/file-utils.mjs +97 -0
- package/utils/load-config.mjs +19 -0
|
@@ -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 {
|
|
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
|
-
|
|
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
|
-
|
|
268
|
-
|
|
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
|
|
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
|
|
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:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type: object
|
|
2
|
+
description: Document structure item representing a node in the document hierarchy
|
|
3
|
+
properties:
|
|
4
|
+
id:
|
|
5
|
+
type: string
|
|
6
|
+
description: Unique identifier for the document structure item
|
|
7
|
+
title:
|
|
8
|
+
type: string
|
|
9
|
+
description:
|
|
10
|
+
type: string
|
|
11
|
+
path:
|
|
12
|
+
type: string
|
|
13
|
+
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
|
|
14
|
+
parentPath:
|
|
15
|
+
type: string
|
|
16
|
+
description: Parent node path, if null indicates it is a top-level node
|
|
17
|
+
required:
|
|
18
|
+
- title
|
|
19
|
+
- description
|
|
20
|
+
- path
|
|
@@ -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:
|
|
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
|
|
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:
|
|
@@ -6,7 +6,7 @@ skills:
|
|
|
6
6
|
input_schema:
|
|
7
7
|
type: object
|
|
8
8
|
properties:
|
|
9
|
-
|
|
9
|
+
detailDataSource:
|
|
10
10
|
type: string
|
|
11
11
|
description: Context for documentation structure generation, used to assist generate documentation structure
|
|
12
12
|
documentExecutionStructure: ../schema/document-execution-structure.yaml
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const PLACEHOLDER = "DIAGRAM_PLACEHOLDER";
|
|
2
|
+
const DEFAULT_DIAGRAMMING_EFFORT = 5;
|
|
3
|
+
const MIN_DIAGRAMMING_EFFORT = 0;
|
|
4
|
+
const MAX_DIAGRAMMING_EFFORT = 10;
|
|
5
|
+
|
|
6
|
+
export default async function checkGenerateDiagram(
|
|
7
|
+
{
|
|
8
|
+
documentContent,
|
|
9
|
+
locale,
|
|
10
|
+
feedback,
|
|
11
|
+
detailFeedback,
|
|
12
|
+
originalContent,
|
|
13
|
+
path: docPath,
|
|
14
|
+
diagramming,
|
|
15
|
+
},
|
|
16
|
+
options,
|
|
17
|
+
) {
|
|
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;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let diagrammingEffort = diagramming?.effort
|
|
37
|
+
? Number(diagramming?.effort)
|
|
38
|
+
: DEFAULT_DIAGRAMMING_EFFORT;
|
|
39
|
+
|
|
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
|
+
);
|
|
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
|
+
|
|
83
|
+
return { content };
|
|
84
|
+
}
|
|
@@ -16,7 +16,7 @@ input_schema:
|
|
|
16
16
|
locale:
|
|
17
17
|
type: string
|
|
18
18
|
description: User language, such as zh, en
|
|
19
|
-
|
|
19
|
+
detailDataSource:
|
|
20
20
|
type: string
|
|
21
21
|
description: Source data and context for document content generation
|
|
22
22
|
targetAudience:
|
|
@@ -44,7 +44,7 @@ input_schema:
|
|
|
44
44
|
description: Additional supplementary information
|
|
45
45
|
required:
|
|
46
46
|
- rules
|
|
47
|
-
-
|
|
47
|
+
- detailDataSource
|
|
48
48
|
- originalDocumentStructure
|
|
49
49
|
output_key: content
|
|
50
50
|
afs:
|
|
@@ -57,5 +57,5 @@ afs:
|
|
|
57
57
|
Codebase of the project to be documented used as context for document generation,
|
|
58
58
|
should search and read as needed while generating document content
|
|
59
59
|
keep_text_in_tool_uses: false
|
|
60
|
-
skills:
|
|
61
|
-
|
|
60
|
+
# skills:
|
|
61
|
+
# - ./generate-diagram.yaml
|
|
@@ -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-
|
|
5
|
+
- ../utils/transform-detail-data-sources.mjs
|
|
6
6
|
- type: team
|
|
7
7
|
task_render_mode: collapse
|
|
8
8
|
name: generateDocumentContent
|
|
@@ -23,6 +23,14 @@ skills:
|
|
|
23
23
|
max_iterations: 5
|
|
24
24
|
return_last_on_max_iterations: true
|
|
25
25
|
task_title: Generate document for '{{ title }}'
|
|
26
|
+
- type: transform
|
|
27
|
+
jsonata: |
|
|
28
|
+
$merge([
|
|
29
|
+
$,
|
|
30
|
+
{ "documentContent": content }
|
|
31
|
+
])
|
|
32
|
+
- ./check-generate-diagram.mjs
|
|
33
|
+
# - ../generate/merge-diagram.yaml
|
|
26
34
|
- ../utils/save-doc.mjs
|
|
27
35
|
input_schema:
|
|
28
36
|
type: object
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: preCheckGenerateDiagram
|
|
2
|
+
description: Pre-check for generating diagram
|
|
3
|
+
model:
|
|
4
|
+
reasoning_effort: 1
|
|
5
|
+
instructions:
|
|
6
|
+
url: ../../prompts/detail/d2-diagram/pre-check.md
|
|
7
|
+
input_schema:
|
|
8
|
+
type: object
|
|
9
|
+
properties:
|
|
10
|
+
documentContent:
|
|
11
|
+
type: string
|
|
12
|
+
description: Source content of the document
|
|
13
|
+
feedback:
|
|
14
|
+
type: string
|
|
15
|
+
description: User generation feedback
|
|
16
|
+
detailFeedback:
|
|
17
|
+
type: string
|
|
18
|
+
description: Current document detail feedback
|
|
19
|
+
previousGenerationContent:
|
|
20
|
+
type: string
|
|
21
|
+
description: Previous document content
|
|
22
|
+
required:
|
|
23
|
+
- documentContent
|
|
24
|
+
output_schema:
|
|
25
|
+
type: object
|
|
26
|
+
properties:
|
|
27
|
+
content:
|
|
28
|
+
type: string
|
|
29
|
+
description: Document content
|
|
30
|
+
details:
|
|
31
|
+
type: array
|
|
32
|
+
description: Detailed needDiagram score
|
|
33
|
+
items:
|
|
34
|
+
type: object
|
|
35
|
+
properties:
|
|
36
|
+
type:
|
|
37
|
+
type: string
|
|
38
|
+
score:
|
|
39
|
+
type: number
|
|
40
|
+
reason:
|
|
41
|
+
type: string
|
|
42
|
+
required:
|
|
43
|
+
- content
|
|
44
|
+
|
|
@@ -1,61 +1,67 @@
|
|
|
1
|
-
type:
|
|
1
|
+
type: team
|
|
2
2
|
name: updateDocumentDetail
|
|
3
3
|
description: Update and optimize document content based on user feedback using diff patches
|
|
4
|
-
instructions:
|
|
5
|
-
- role: system
|
|
6
|
-
url: ../../prompts/detail/update/system-prompt.md
|
|
7
|
-
- role: user
|
|
8
|
-
url: ../../prompts/detail/update/user-prompt.md
|
|
9
|
-
auto_reorder_system_messages: true
|
|
10
|
-
auto_merge_system_messages: true
|
|
11
|
-
input_schema:
|
|
12
|
-
type: object
|
|
13
|
-
properties:
|
|
14
|
-
originalContent:
|
|
15
|
-
type: string
|
|
16
|
-
description: Original markdown content to be updated
|
|
17
|
-
feedback:
|
|
18
|
-
type: string
|
|
19
|
-
description: User feedback for content improvements
|
|
20
|
-
rules:
|
|
21
|
-
type: string
|
|
22
|
-
description: User configuration rules
|
|
23
|
-
locale:
|
|
24
|
-
type: string
|
|
25
|
-
description: User language, e.g. zh, en
|
|
26
|
-
datasources:
|
|
27
|
-
type: string
|
|
28
|
-
description: Context for document content
|
|
29
|
-
glossary:
|
|
30
|
-
type: string
|
|
31
|
-
description: Glossary of terms
|
|
32
|
-
userPreferences:
|
|
33
|
-
type: string
|
|
34
|
-
description: User's saved preferences for content and documentation style
|
|
35
|
-
targetAudience:
|
|
36
|
-
type: string
|
|
37
|
-
description: Target audience for the documentation
|
|
38
|
-
title:
|
|
39
|
-
type: string
|
|
40
|
-
description: Document title
|
|
41
|
-
description:
|
|
42
|
-
type: string
|
|
43
|
-
description: Document description
|
|
44
|
-
required:
|
|
45
|
-
- originalContent
|
|
46
|
-
- feedback
|
|
47
|
-
output_key: message
|
|
48
|
-
afs:
|
|
49
|
-
modules:
|
|
50
|
-
- module: system-fs
|
|
51
|
-
options:
|
|
52
|
-
mount: /sources
|
|
53
|
-
path: .
|
|
54
|
-
description: |
|
|
55
|
-
Codebase of the project to be documented used as context for document generation,
|
|
56
|
-
should search and read as needed while generating document content
|
|
57
|
-
keep_text_in_tool_uses: false
|
|
58
|
-
skills:
|
|
59
|
-
- ./document-tools/update-document-content.mjs
|
|
60
|
-
- ./generate-diagram.yaml
|
|
61
4
|
task_render_mode: collapse
|
|
5
|
+
skills:
|
|
6
|
+
- url: ../utils/analyze-feedback-intent.yaml
|
|
7
|
+
- type: ai
|
|
8
|
+
instructions:
|
|
9
|
+
- role: system
|
|
10
|
+
url: ../../prompts/detail/update/system-prompt.md
|
|
11
|
+
- role: user
|
|
12
|
+
url: ../../prompts/detail/update/user-prompt.md
|
|
13
|
+
auto_reorder_system_messages: true
|
|
14
|
+
auto_merge_system_messages: true
|
|
15
|
+
input_schema:
|
|
16
|
+
type: object
|
|
17
|
+
properties:
|
|
18
|
+
originalContent:
|
|
19
|
+
type: string
|
|
20
|
+
description: Original markdown content to be updated
|
|
21
|
+
feedback:
|
|
22
|
+
type: string
|
|
23
|
+
description: User feedback for content improvements
|
|
24
|
+
rules:
|
|
25
|
+
type: string
|
|
26
|
+
description: User configuration rules
|
|
27
|
+
locale:
|
|
28
|
+
type: string
|
|
29
|
+
description: User language, e.g. zh, en
|
|
30
|
+
detailDataSource:
|
|
31
|
+
type: string
|
|
32
|
+
description: Context for document content
|
|
33
|
+
glossary:
|
|
34
|
+
type: string
|
|
35
|
+
description: Glossary of terms
|
|
36
|
+
userPreferences:
|
|
37
|
+
type: string
|
|
38
|
+
description: User's saved preferences for content and documentation style
|
|
39
|
+
targetAudience:
|
|
40
|
+
type: string
|
|
41
|
+
description: Target audience for the documentation
|
|
42
|
+
title:
|
|
43
|
+
type: string
|
|
44
|
+
description: Document title
|
|
45
|
+
description:
|
|
46
|
+
type: string
|
|
47
|
+
description: Document description
|
|
48
|
+
needDataSources:
|
|
49
|
+
type: boolean
|
|
50
|
+
description: Whether data sources are needed for content modifications
|
|
51
|
+
required:
|
|
52
|
+
- originalContent
|
|
53
|
+
- feedback
|
|
54
|
+
output_key: message
|
|
55
|
+
afs:
|
|
56
|
+
modules:
|
|
57
|
+
- module: system-fs
|
|
58
|
+
options:
|
|
59
|
+
mount: /sources
|
|
60
|
+
path: .
|
|
61
|
+
description: |
|
|
62
|
+
Codebase of the project to be documented used as context for document generation,
|
|
63
|
+
should search and read as needed while generating document content
|
|
64
|
+
keep_text_in_tool_uses: false
|
|
65
|
+
skills:
|
|
66
|
+
- ./document-tools/update-document-content.mjs
|
|
67
|
+
# - ./generate-diagram.yaml
|
|
@@ -105,6 +105,7 @@ async function showDocumentDetail(content, title) {
|
|
|
105
105
|
renderer: new markedTerminal(),
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
+
// FIXME: @zhanghan fix error "Could not find the language 'd2', did you forget to load/include a language module?"
|
|
108
109
|
const renderedMarkdown = marked(content);
|
|
109
110
|
|
|
110
111
|
// Restore original console.error
|
|
@@ -121,16 +122,15 @@ async function showDocumentDetail(content, title) {
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
export default async function userReviewDocument(
|
|
125
|
-
{ content, title, description, ...rest },
|
|
126
|
-
options,
|
|
127
|
-
) {
|
|
125
|
+
export default async function userReviewDocument({ content, description, ...rest }, options) {
|
|
128
126
|
// Check if document content exists
|
|
129
127
|
if (!content || typeof content !== "string" || content.trim().length === 0) {
|
|
130
128
|
console.log("Please provide document content to review.");
|
|
131
129
|
return { content };
|
|
132
130
|
}
|
|
133
131
|
|
|
132
|
+
const title = rest.documentStructure?.find((x) => x.path === rest.path)?.title;
|
|
133
|
+
|
|
134
134
|
// Print current document headings structure
|
|
135
135
|
printDocumentHeadings(content, title || "Untitled Document");
|
|
136
136
|
|
|
@@ -190,7 +190,7 @@ export default async function userReviewDocument(
|
|
|
190
190
|
feedbacks.push(feedback.trim());
|
|
191
191
|
|
|
192
192
|
// Get the updateDocument agent
|
|
193
|
-
const updateAgent = options.context.agents["
|
|
193
|
+
const updateAgent = options.context.agents["handleDocumentUpdate"];
|
|
194
194
|
if (!updateAgent) {
|
|
195
195
|
console.log(
|
|
196
196
|
"We can't process your feedback right now. The document update feature is temporarily unavailable.",
|
|
@@ -208,12 +208,14 @@ export default async function userReviewDocument(
|
|
|
208
208
|
|
|
209
209
|
try {
|
|
210
210
|
// Call updateDocument agent with feedback
|
|
211
|
-
await options.context.invoke(updateAgent, {
|
|
211
|
+
const result = await options.context.invoke(updateAgent, {
|
|
212
212
|
...rest,
|
|
213
213
|
originalContent: options.context.userContext.currentContent,
|
|
214
214
|
feedback: feedback.trim(),
|
|
215
215
|
userPreferences,
|
|
216
|
+
title,
|
|
216
217
|
});
|
|
218
|
+
options.context.userContext.currentContent = result.content;
|
|
217
219
|
|
|
218
220
|
// Check if feedback should be saved as user preference
|
|
219
221
|
const feedbackRefinerAgent = options.context.agents["checkFeedbackRefiner"];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: analyzeFeedbackIntent
|
|
2
|
+
description: Analyze user feedback to determine if data sources are needed for content modifications
|
|
3
|
+
task_render_mode: hide
|
|
4
|
+
instructions:
|
|
5
|
+
url: ../../prompts/utils/analyze-feedback-intent.md
|
|
6
|
+
input_schema:
|
|
7
|
+
type: object
|
|
8
|
+
properties:
|
|
9
|
+
feedback:
|
|
10
|
+
type: string
|
|
11
|
+
description: User feedback for content modifications
|
|
12
|
+
required:
|
|
13
|
+
- feedback
|
|
14
|
+
output_schema:
|
|
15
|
+
type: object
|
|
16
|
+
properties:
|
|
17
|
+
needDataSources:
|
|
18
|
+
type: boolean
|
|
19
|
+
description: Whether data sources are needed - true for add/edit operations that need context, false for delete/move/reorder operations
|
|
20
|
+
intentType:
|
|
21
|
+
type: string
|
|
22
|
+
description: The primary type of user intention
|
|
23
|
+
reason:
|
|
24
|
+
type: string
|
|
25
|
+
description: Explanation of why data sources are or aren't needed
|
|
26
|
+
required:
|
|
27
|
+
- needDataSources
|
|
28
|
+
- intentType
|
|
29
|
+
- reason
|
|
@@ -6,6 +6,14 @@ import {
|
|
|
6
6
|
getMainLanguageFiles,
|
|
7
7
|
processSelectedFiles,
|
|
8
8
|
} from "../../utils/docs-finder-utils.mjs";
|
|
9
|
+
import { DOC_ACTION } from "../../utils/constants/index.mjs";
|
|
10
|
+
|
|
11
|
+
function getFeedbackMessage(action) {
|
|
12
|
+
if (action === DOC_ACTION.translate) {
|
|
13
|
+
return "Any specific translation preferences or instructions? (Press Enter to skip):";
|
|
14
|
+
}
|
|
15
|
+
return "How would you like to improve this document? (Press Enter to skip)";
|
|
16
|
+
}
|
|
9
17
|
|
|
10
18
|
export default async function chooseDocs(
|
|
11
19
|
{
|
|
@@ -18,12 +26,13 @@ export default async function chooseDocs(
|
|
|
18
26
|
locale,
|
|
19
27
|
reset = false,
|
|
20
28
|
requiredFeedback = true,
|
|
21
|
-
|
|
29
|
+
action,
|
|
22
30
|
},
|
|
23
31
|
options,
|
|
24
32
|
) {
|
|
25
33
|
let foundItems = [];
|
|
26
34
|
let selectedFiles = [];
|
|
35
|
+
const docAction = action || (isTranslate ? DOC_ACTION.translate : DOC_ACTION.update);
|
|
27
36
|
|
|
28
37
|
// If docs is empty or not provided, let user select multiple documents
|
|
29
38
|
if (!docs || docs.length === 0) {
|
|
@@ -37,7 +46,9 @@ export default async function chooseDocs(
|
|
|
37
46
|
|
|
38
47
|
if (mainLanguageFiles.length === 0) {
|
|
39
48
|
throw new Error(
|
|
40
|
-
`No documents found in the docs directory.
|
|
49
|
+
`No documents found in the docs directory. You can generate them with ${chalk.yellow(
|
|
50
|
+
"`aigne doc generate`",
|
|
51
|
+
)}`,
|
|
41
52
|
);
|
|
42
53
|
}
|
|
43
54
|
|
|
@@ -66,7 +77,7 @@ export default async function chooseDocs(
|
|
|
66
77
|
|
|
67
78
|
// Let user select multiple files
|
|
68
79
|
selectedFiles = await options.prompts.checkbox({
|
|
69
|
-
message:
|
|
80
|
+
message: getActionText("Select documents to {action}:", docAction),
|
|
70
81
|
source: (term) => {
|
|
71
82
|
if (!term) return choices;
|
|
72
83
|
|
|
@@ -88,7 +99,7 @@ export default async function chooseDocs(
|
|
|
88
99
|
foundItems = await processSelectedFiles(selectedFiles, documentExecutionStructure, docsDir);
|
|
89
100
|
} catch (error) {
|
|
90
101
|
console.log(
|
|
91
|
-
getActionText(
|
|
102
|
+
getActionText(`\nFailed to select documents to {action}: ${error.message}`, docAction),
|
|
92
103
|
);
|
|
93
104
|
process.exit(0);
|
|
94
105
|
}
|
|
@@ -123,8 +134,7 @@ export default async function chooseDocs(
|
|
|
123
134
|
// Prompt for feedback if not provided
|
|
124
135
|
let userFeedback = feedback;
|
|
125
136
|
if (!userFeedback && (requiredFeedback || foundItems?.length > 1)) {
|
|
126
|
-
const feedbackMessage =
|
|
127
|
-
"How should we improve this document? (Enter to skip, will auto-update from content sources):";
|
|
137
|
+
const feedbackMessage = getFeedbackMessage(docAction);
|
|
128
138
|
|
|
129
139
|
userFeedback = await options.prompts.input({
|
|
130
140
|
message: feedbackMessage,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DOC_ACTION } from "../../utils/constants/index.mjs";
|
|
1
2
|
import {
|
|
2
3
|
fileNameToFlatPath,
|
|
3
4
|
findItemByFlatName,
|
|
@@ -14,6 +15,7 @@ export default async function findItemByPath(
|
|
|
14
15
|
let foundItem = null;
|
|
15
16
|
let selectedFileContent = null;
|
|
16
17
|
let docPath = doc;
|
|
18
|
+
const docAction = isTranslate ? DOC_ACTION.translate : DOC_ACTION.update;
|
|
17
19
|
|
|
18
20
|
// If docPath is empty, let user select from available documents
|
|
19
21
|
if (!docPath) {
|
|
@@ -31,7 +33,7 @@ export default async function findItemByPath(
|
|
|
31
33
|
|
|
32
34
|
// Let user select a file
|
|
33
35
|
const selectedFile = await options.prompts.search({
|
|
34
|
-
message: getActionText(
|
|
36
|
+
message: getActionText("Select a document to {action}:", docAction),
|
|
35
37
|
source: async (input) => {
|
|
36
38
|
if (!input || input.trim() === "") {
|
|
37
39
|
return mainLanguageFiles.map((file) => ({
|
|
@@ -74,8 +76,8 @@ export default async function findItemByPath(
|
|
|
74
76
|
console.debug(error?.message);
|
|
75
77
|
throw new Error(
|
|
76
78
|
getActionText(
|
|
77
|
-
isTranslate,
|
|
78
79
|
"Please run 'aigne doc generate' first to generate documents, then select which document to {action}",
|
|
80
|
+
docAction,
|
|
79
81
|
),
|
|
80
82
|
);
|
|
81
83
|
}
|
|
@@ -171,7 +171,7 @@ export default async function loadSources(
|
|
|
171
171
|
if (dimensions.width < minImageWidth) {
|
|
172
172
|
filteredImageCount++;
|
|
173
173
|
console.log(
|
|
174
|
-
`
|
|
174
|
+
`Ignored image: ${fileName} (${dimensions.width}x${dimensions.height}px < ${minImageWidth}px minimum)`,
|
|
175
175
|
);
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
@@ -218,8 +218,8 @@ export default async function loadSources(
|
|
|
218
218
|
0,
|
|
219
219
|
);
|
|
220
220
|
|
|
221
|
-
const
|
|
222
|
-
(i) => ({
|
|
221
|
+
const dataSources = splitSourcesToChunks(sourceFiles, INTELLIGENT_SUGGESTION_TOKEN_THRESHOLD).map(
|
|
222
|
+
(i) => ({ dataSourceChunk: buildSourcesContent(i) }),
|
|
223
223
|
);
|
|
224
224
|
|
|
225
225
|
const remoteFileList = [];
|
|
@@ -290,7 +290,7 @@ export default async function loadSources(
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
return {
|
|
293
|
-
|
|
293
|
+
dataSources,
|
|
294
294
|
content,
|
|
295
295
|
originalDocumentStructure,
|
|
296
296
|
files,
|
|
@@ -345,12 +345,12 @@ loadSources.input_schema = {
|
|
|
345
345
|
loadSources.output_schema = {
|
|
346
346
|
type: "object",
|
|
347
347
|
properties: {
|
|
348
|
-
|
|
348
|
+
dataSources: {
|
|
349
349
|
type: "array",
|
|
350
350
|
items: {
|
|
351
351
|
type: "object",
|
|
352
352
|
properties: {
|
|
353
|
-
|
|
353
|
+
dataSourceChunk: { type: "string" },
|
|
354
354
|
},
|
|
355
355
|
},
|
|
356
356
|
},
|