@aigne/doc-smith 0.8.12-beta.9 → 0.8.13-beta
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 +11 -0
- package/README.md +73 -74
- package/agents/clear/choose-contents.mjs +21 -28
- package/agents/evaluate/index.yaml +1 -0
- package/agents/generate/check-need-generate-structure.mjs +10 -18
- package/agents/generate/user-review-document-structure.mjs +4 -4
- package/agents/init/check.mjs +14 -0
- package/agents/init/index.mjs +40 -46
- package/agents/publish/index.yaml +1 -0
- package/agents/publish/publish-docs.mjs +43 -30
- package/agents/translate/choose-language.mjs +13 -13
- package/agents/translate/index.yaml +1 -0
- package/agents/update/check-update-is-single.mjs +7 -4
- package/agents/update/index.yaml +1 -0
- package/agents/utils/choose-docs.mjs +4 -2
- package/agents/utils/update-branding.mjs +3 -2
- package/package.json +1 -1
- package/utils/auth-utils.mjs +25 -26
- package/utils/blocklet.mjs +31 -5
- package/utils/conflict-detector.mjs +6 -4
- package/utils/constants/index.mjs +1 -0
- package/utils/d2-utils.mjs +7 -8
- package/utils/deploy.mjs +9 -10
- package/utils/history-utils.mjs +21 -21
- package/utils/kroki-utils.mjs +7 -8
- package/utils/load-config.mjs +5 -5
- package/utils/upload-files.mjs +2 -2
package/utils/auth-utils.mjs
CHANGED
|
@@ -53,7 +53,7 @@ export async function getAccessToken(appUrl, ltToken = "") {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
} catch (error) {
|
|
56
|
-
console.warn("
|
|
56
|
+
console.warn("Could not read the configuration file:", error.message);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -69,25 +69,25 @@ export async function getAccessToken(appUrl, ltToken = "") {
|
|
|
69
69
|
const storeLink = chalk.cyan(DISCUSS_KIT_STORE_URL);
|
|
70
70
|
if (error instanceof InvalidBlockletError) {
|
|
71
71
|
throw new Error(
|
|
72
|
-
`${chalk.yellow("⚠️ The provided URL is not a valid
|
|
73
|
-
`${chalk.bold("💡 Solution:")}
|
|
72
|
+
`${chalk.yellow("⚠️ The provided URL is not a valid ArcBlock-powered website.")}\n\n` +
|
|
73
|
+
`${chalk.bold("💡 Solution:")} To host your documentation, you can get a website from the ArcBlock store:\n${storeLink}\n\n`,
|
|
74
74
|
);
|
|
75
75
|
} else if (error instanceof ComponentNotFoundError) {
|
|
76
76
|
const docsLink = chalk.cyan(BLOCKLET_ADD_COMPONENT_DOCS);
|
|
77
77
|
throw new Error(
|
|
78
|
-
`${chalk.yellow("⚠️
|
|
78
|
+
`${chalk.yellow("⚠️ This website is missing the required components for publishing.")}\n\n` +
|
|
79
79
|
`${chalk.bold(
|
|
80
80
|
"💡 Solution:",
|
|
81
|
-
)} Please refer to the documentation to add Discuss Kit component:\n${docsLink}\n\n`,
|
|
81
|
+
)} Please refer to the documentation to add the Discuss Kit component:\n${docsLink}\n\n`,
|
|
82
82
|
);
|
|
83
83
|
} else {
|
|
84
84
|
throw new Error(
|
|
85
|
-
`❌
|
|
85
|
+
`❌ Could not connect to: ${chalk.cyan(appUrl)}\n\n` +
|
|
86
86
|
`${chalk.bold("Possible causes:")}\n` +
|
|
87
|
-
`•
|
|
88
|
-
`•
|
|
89
|
-
`•
|
|
90
|
-
`${chalk.green("Suggestion:")} Please check your network connection and URL, then try again
|
|
87
|
+
`• There may be a network issue.\n` +
|
|
88
|
+
`• The server may be temporarily unavailable.\n` +
|
|
89
|
+
`• The URL may be incorrect.\n\n` +
|
|
90
|
+
`${chalk.green("Suggestion:")} Please check your network connection and the URL, then try again.`,
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -145,7 +145,7 @@ export async function getAccessToken(appUrl, ltToken = "") {
|
|
|
145
145
|
} catch (error) {
|
|
146
146
|
console.debug(error);
|
|
147
147
|
throw new Error(
|
|
148
|
-
"
|
|
148
|
+
"Could not get an access token. Please check your network connection and try again.",
|
|
149
149
|
);
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -153,14 +153,13 @@ export async function getAccessToken(appUrl, ltToken = "") {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @param {string} baseUrl - The official service URL
|
|
158
|
-
* @returns {Promise<string>}
|
|
156
|
+
* Gets the official access token from the environment, config file, or prompts the user to authorize.
|
|
157
|
+
* @param {string} baseUrl - The official service URL.
|
|
158
|
+
* @returns {Promise<string>} The access token.
|
|
159
159
|
*/
|
|
160
160
|
export async function getOfficialAccessToken(baseUrl, openPage = true) {
|
|
161
|
-
// Early parameter validation
|
|
162
161
|
if (!baseUrl) {
|
|
163
|
-
throw new Error("baseUrl parameter is required for getOfficialAccessToken.");
|
|
162
|
+
throw new Error("The baseUrl parameter is required for getOfficialAccessToken.");
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
// Parse URL once and reuse
|
|
@@ -183,7 +182,7 @@ export async function getOfficialAccessToken(baseUrl, openPage = true) {
|
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
} catch (_error) {
|
|
186
|
-
//
|
|
185
|
+
// Ignore errors
|
|
187
186
|
}
|
|
188
187
|
}
|
|
189
188
|
|
|
@@ -205,7 +204,7 @@ export async function getOfficialAccessToken(baseUrl, openPage = true) {
|
|
|
205
204
|
appLogo: "https://docsmith.aigne.io/image-bin/uploads/9645caf64b4232699982c4d940b03b90.svg",
|
|
206
205
|
openPage: (pageUrl) => {
|
|
207
206
|
console.log(
|
|
208
|
-
"🔗 Please open
|
|
207
|
+
"🔗 Please open the following URL in your browser to authorize access: ",
|
|
209
208
|
chalk.cyan(pageUrl),
|
|
210
209
|
"\n",
|
|
211
210
|
);
|
|
@@ -226,7 +225,7 @@ export async function getOfficialAccessToken(baseUrl, openPage = true) {
|
|
|
226
225
|
} catch (error) {
|
|
227
226
|
console.debug(error);
|
|
228
227
|
throw new Error(
|
|
229
|
-
"
|
|
228
|
+
"Could not get an official access token. Please check your network connection and try again.",
|
|
230
229
|
);
|
|
231
230
|
}
|
|
232
231
|
|
|
@@ -234,11 +233,11 @@ export async function getOfficialAccessToken(baseUrl, openPage = true) {
|
|
|
234
233
|
}
|
|
235
234
|
|
|
236
235
|
/**
|
|
237
|
-
*
|
|
238
|
-
* @param {string} configFile -
|
|
239
|
-
* @param {string} hostname -
|
|
240
|
-
* @param {string} tokenKey -
|
|
241
|
-
* @param {string} tokenValue -
|
|
236
|
+
* Saves the access token to the configuration file.
|
|
237
|
+
* @param {string} configFile - The path to the config file.
|
|
238
|
+
* @param {string} hostname - The hostname key.
|
|
239
|
+
* @param {string} tokenKey - The token key name.
|
|
240
|
+
* @param {string} tokenValue - The token value.
|
|
242
241
|
*/
|
|
243
242
|
async function saveTokenToConfigFile(configFile, hostname, tokenKey, tokenValue) {
|
|
244
243
|
try {
|
|
@@ -266,7 +265,7 @@ async function saveTokenToConfigFile(configFile, hostname, tokenKey, tokenValue)
|
|
|
266
265
|
}),
|
|
267
266
|
);
|
|
268
267
|
} catch (error) {
|
|
269
|
-
console.warn(`
|
|
270
|
-
//
|
|
268
|
+
console.warn(`Could not save the token to the configuration file: ${error.message}`, error);
|
|
269
|
+
// The token is already in the environment, so we don't need to throw an error here.
|
|
271
270
|
}
|
|
272
271
|
}
|
package/utils/blocklet.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { joinURL } from "ufo";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Custom error class for invalid blocklet application URLs
|
|
4
|
+
* Custom error class for invalid blocklet application URLs.
|
|
5
5
|
*/
|
|
6
6
|
export class InvalidBlockletError extends Error {
|
|
7
7
|
constructor(url, status, statusText) {
|
|
8
|
-
super(`
|
|
8
|
+
super(`The application URL "${url}" is invalid. I was unable to fetch the configuration.`);
|
|
9
9
|
this.name = "InvalidBlockletError";
|
|
10
10
|
this.url = url;
|
|
11
11
|
this.status = status;
|
|
@@ -14,20 +14,42 @@ export class InvalidBlockletError extends Error {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Custom error class for missing component mount points
|
|
17
|
+
* Custom error class for missing component mount points.
|
|
18
18
|
*/
|
|
19
19
|
export class ComponentNotFoundError extends Error {
|
|
20
20
|
constructor(did, appUrl) {
|
|
21
|
-
super(`Your website "${appUrl}" missing required component to host your
|
|
21
|
+
super(`Your website "${appUrl}" is missing a required component to host your documentation.`);
|
|
22
22
|
this.name = "ComponentNotFoundError";
|
|
23
23
|
this.did = did;
|
|
24
24
|
this.appUrl = appUrl;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
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
|
+
|
|
28
37
|
export async function getComponentInfo(appUrl) {
|
|
29
38
|
const blockletJsUrl = joinURL(appUrl, "__blocklet__.js?type=json");
|
|
30
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
|
+
|
|
31
53
|
let blockletJs;
|
|
32
54
|
try {
|
|
33
55
|
blockletJs = await fetch(blockletJsUrl, {
|
|
@@ -45,8 +67,12 @@ export async function getComponentInfo(appUrl) {
|
|
|
45
67
|
let config;
|
|
46
68
|
try {
|
|
47
69
|
config = await blockletJs.json();
|
|
70
|
+
BLOCKLET_INFO_CACHE[appUrl] = {
|
|
71
|
+
...config,
|
|
72
|
+
__blocklet_info_cache_timestamp: Date.now(),
|
|
73
|
+
};
|
|
48
74
|
} catch {
|
|
49
|
-
throw new InvalidBlockletError(appUrl, null, "
|
|
75
|
+
throw new InvalidBlockletError(appUrl, null, "The server returned an invalid JSON response.");
|
|
50
76
|
}
|
|
51
77
|
|
|
52
78
|
return config;
|
|
@@ -135,13 +135,15 @@ export function generateConflictResolutionRules(conflicts) {
|
|
|
135
135
|
rules.push("");
|
|
136
136
|
rules.push("Conflict Resolution Principles:");
|
|
137
137
|
rules.push(
|
|
138
|
-
"1. Meet diverse needs through intelligent structural design, not
|
|
138
|
+
"1. Meet diverse needs through intelligent structural design, not by simply concatenating information.",
|
|
139
139
|
);
|
|
140
|
-
rules.push("2. Create clear navigation paths for different purposes and audiences");
|
|
140
|
+
rules.push("2. Create clear navigation paths for different purposes and audiences.");
|
|
141
141
|
rules.push(
|
|
142
|
-
"3. Ensure content hierarchy
|
|
142
|
+
"3. Ensure a reasonable content hierarchy that avoids information duplication and contradiction.",
|
|
143
|
+
);
|
|
144
|
+
rules.push(
|
|
145
|
+
"4. Prioritize the user experience by enabling users to quickly find the information they need.",
|
|
143
146
|
);
|
|
144
|
-
rules.push("4. Prioritize user experience, enable users to quickly find needed information");
|
|
145
147
|
|
|
146
148
|
return rules.join("\n");
|
|
147
149
|
}
|
|
@@ -329,6 +329,7 @@ export const DEPTH_RECOMMENDATION_LOGIC = {
|
|
|
329
329
|
|
|
330
330
|
// Component mount point ID for Discuss Kit
|
|
331
331
|
export const DISCUSS_KIT_DID = "z8ia1WEiBZ7hxURf6LwH21Wpg99vophFwSJdu";
|
|
332
|
+
export const MEDIA_KIT_DID = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
|
|
332
333
|
|
|
333
334
|
export const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
|
|
334
335
|
|
package/utils/d2-utils.mjs
CHANGED
|
@@ -32,12 +32,12 @@ export async function getChart({ content, strict }) {
|
|
|
32
32
|
try {
|
|
33
33
|
const { diagram, renderOptions, graph } = await d2.compile(contentWithBase64Img);
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// Do not apply a stroke-dash to sequence diagrams.
|
|
36
36
|
if (
|
|
37
37
|
graph?.root?.attributes?.shape &&
|
|
38
38
|
graph.root.attributes.shape.value !== "sequence_diagram"
|
|
39
39
|
) {
|
|
40
|
-
// Save first
|
|
40
|
+
// Save the first-level container.
|
|
41
41
|
const firstLevelContainer = new Set();
|
|
42
42
|
diagram.shapes.forEach((x) => {
|
|
43
43
|
const idList = x.id.split(".");
|
|
@@ -50,7 +50,7 @@ export async function getChart({ content, strict }) {
|
|
|
50
50
|
});
|
|
51
51
|
firstLevelContainer.forEach((shape) => {
|
|
52
52
|
if (!shape.strokeDash) {
|
|
53
|
-
//
|
|
53
|
+
// Note: The data structure here is different from the d2 source code.
|
|
54
54
|
shape.strokeDash = 3;
|
|
55
55
|
}
|
|
56
56
|
});
|
|
@@ -69,7 +69,6 @@ export async function getChart({ content, strict }) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
// Helper: save d2 svg assets alongside document
|
|
73
72
|
export async function saveAssets({ markdown, docsDir }) {
|
|
74
73
|
if (!markdown) {
|
|
75
74
|
return markdown;
|
|
@@ -87,10 +86,10 @@ export async function saveAssets({ markdown, docsDir }) {
|
|
|
87
86
|
const svgPath = path.join(assetDir, fileName);
|
|
88
87
|
|
|
89
88
|
if (await fs.pathExists(svgPath)) {
|
|
90
|
-
debug("
|
|
89
|
+
debug("Asset cache found, skipping generation", svgPath);
|
|
91
90
|
} else {
|
|
92
91
|
try {
|
|
93
|
-
debug("
|
|
92
|
+
debug("Generating d2 diagram", svgPath);
|
|
94
93
|
if (debug.enabled) {
|
|
95
94
|
const d2FileName = `${getContentHash(d2Content)}.d2`;
|
|
96
95
|
const d2Path = path.join(assetDir, d2FileName);
|
|
@@ -115,7 +114,7 @@ export async function saveAssets({ markdown, docsDir }) {
|
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
export async function beforePublishHook({ docsDir }) {
|
|
118
|
-
//
|
|
117
|
+
// Process each markdown file to save d2 svg assets.
|
|
119
118
|
const mdFilePaths = await glob("**/*.md", { cwd: docsDir });
|
|
120
119
|
await pMap(
|
|
121
120
|
mdFilePaths,
|
|
@@ -176,7 +175,7 @@ export async function checkContent({ content: _content }) {
|
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
if (await fs.pathExists(svgPath)) {
|
|
179
|
-
debug("
|
|
178
|
+
debug("Asset cache found, skipping generation", svgPath);
|
|
180
179
|
return;
|
|
181
180
|
}
|
|
182
181
|
|
package/utils/deploy.mjs
CHANGED
|
@@ -5,24 +5,23 @@ import { getOfficialAccessToken } from "./auth-utils.mjs";
|
|
|
5
5
|
import { CLOUD_SERVICE_URL_PROD } from "./constants/index.mjs";
|
|
6
6
|
import { saveValueToConfig } from "./utils.mjs";
|
|
7
7
|
|
|
8
|
-
// ==================== Configuration ====================
|
|
9
8
|
const BASE_URL = process.env.DOC_SMITH_BASE_URL || CLOUD_SERVICE_URL_PROD;
|
|
10
9
|
const SUCCESS_MESSAGE = {
|
|
11
|
-
en: "Congratulations! Your website has been successfully installed. You can return to the command-line tool to continue
|
|
10
|
+
en: "Congratulations! Your website has been successfully installed. You can now return to the command-line tool to continue.",
|
|
12
11
|
zh: "恭喜您,你的网站已安装成功!可以返回命令行工具继续后续操作!",
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {string} id -
|
|
18
|
-
* @param {string} cachedUrl -
|
|
19
|
-
* @returns {Promise<Object>}
|
|
15
|
+
* Deploys a new Discuss Kit Website and returns the installation URL.
|
|
16
|
+
* @param {string} id - The cached checkout ID (optional).
|
|
17
|
+
* @param {string} cachedUrl - The cached payment URL (optional).
|
|
18
|
+
* @returns {Promise<Object>} The deployment result with URLs.
|
|
20
19
|
*/
|
|
21
20
|
export async function deploy(id, cachedUrl) {
|
|
22
21
|
const authToken = await getOfficialAccessToken(BASE_URL);
|
|
23
22
|
|
|
24
23
|
if (!authToken) {
|
|
25
|
-
throw new Error("
|
|
24
|
+
throw new Error("Could not get an official access token.");
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
const client = new BrokerClient({ baseUrl: BASE_URL, authToken });
|
|
@@ -55,15 +54,15 @@ export async function deploy(id, cachedUrl) {
|
|
|
55
54
|
},
|
|
56
55
|
|
|
57
56
|
[STEPS.INSTALLATION_STARTING]: () => {
|
|
58
|
-
console.log(`📦 Step 2/4: Installing
|
|
57
|
+
console.log(`📦 Step 2/4: Installing the website...`);
|
|
59
58
|
},
|
|
60
59
|
|
|
61
60
|
[STEPS.SERVICE_STARTING]: () => {
|
|
62
|
-
console.log(`🚀 Step 3/4: Starting
|
|
61
|
+
console.log(`🚀 Step 3/4: Starting the website...`);
|
|
63
62
|
},
|
|
64
63
|
|
|
65
64
|
[STEPS.ACCESS_PREPARING]: () => {
|
|
66
|
-
console.log(`🌐 Step 4/4: Getting
|
|
65
|
+
console.log(`🌐 Step 4/4: Getting the website URL...`);
|
|
67
66
|
},
|
|
68
67
|
|
|
69
68
|
[STEPS.ACCESS_READY]: async ({ appUrl, homeUrl, subscriptionUrl }) => {
|
package/utils/history-utils.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { isInGitRepository } from "./file-utils.mjs";
|
|
|
8
8
|
const HISTORY_FILE = "history.yaml";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Checks if Git is available in the system.
|
|
12
12
|
*/
|
|
13
13
|
export function isGitAvailable() {
|
|
14
14
|
try {
|
|
@@ -20,7 +20,7 @@ export function isGitAvailable() {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Initializes a Git repository in the DOC_SMITH_DIR if it doesn't already exist.
|
|
24
24
|
*/
|
|
25
25
|
export function ensureGitRepo() {
|
|
26
26
|
if (!isGitAvailable()) return false;
|
|
@@ -43,10 +43,10 @@ export function ensureGitRepo() {
|
|
|
43
43
|
stdio: "ignore",
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
console.log("✔ Git history tracking initialized");
|
|
46
|
+
console.log("✔ Git history tracking has been initialized.");
|
|
47
47
|
return true;
|
|
48
48
|
} catch (error) {
|
|
49
|
-
console.warn("
|
|
49
|
+
console.warn("Could not initialize the Git history:", error.message);
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -76,10 +76,10 @@ function recordUpdateGit({ feedback }) {
|
|
|
76
76
|
// Check if there are changes to commit
|
|
77
77
|
try {
|
|
78
78
|
execSync("git diff --cached --quiet", { cwd, stdio: "ignore" });
|
|
79
|
-
console.log("✔ No update history changes to commit");
|
|
80
|
-
return;
|
|
79
|
+
console.log("✔ No update history changes to commit.");
|
|
80
|
+
return;
|
|
81
81
|
} catch {
|
|
82
|
-
//
|
|
82
|
+
// There are changes, so we'll continue.
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// Build commit message (only user feedback)
|
|
@@ -90,14 +90,14 @@ function recordUpdateGit({ feedback }) {
|
|
|
90
90
|
cwd,
|
|
91
91
|
stdio: "ignore",
|
|
92
92
|
});
|
|
93
|
-
console.log("✔
|
|
93
|
+
console.log("✔ The update history has been committed successfully.");
|
|
94
94
|
} catch (error) {
|
|
95
|
-
console.warn("
|
|
95
|
+
console.warn("The update history commit failed:", error.message);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
*
|
|
100
|
+
* Records an update in the YAML file.
|
|
101
101
|
*/
|
|
102
102
|
function recordUpdateYaml({ operation, feedback, documentPath = null }) {
|
|
103
103
|
try {
|
|
@@ -114,7 +114,7 @@ function recordUpdateYaml({ operation, feedback, documentPath = null }) {
|
|
|
114
114
|
const content = readFileSync(historyPath, "utf8");
|
|
115
115
|
history = parse(content) || { entries: [] };
|
|
116
116
|
} catch (error) {
|
|
117
|
-
console.warn("
|
|
117
|
+
console.warn("Could not read the history file:", error.message);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -142,18 +142,18 @@ function recordUpdateYaml({ operation, feedback, documentPath = null }) {
|
|
|
142
142
|
|
|
143
143
|
writeFileSync(historyPath, yamlContent, "utf8");
|
|
144
144
|
} catch (error) {
|
|
145
|
-
console.warn("YAML history tracking failed:", error.message);
|
|
145
|
+
console.warn("The YAML history tracking failed:", error.message);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
151
|
-
* - Always writes to YAML
|
|
152
|
-
* - Also commits to
|
|
150
|
+
* Records an update after user feedback.
|
|
151
|
+
* - Always writes to YAML.
|
|
152
|
+
* - Also commits to Git if available.
|
|
153
153
|
* @param {Object} params
|
|
154
|
-
* @param {string} params.operation -
|
|
155
|
-
* @param {string} params.feedback -
|
|
156
|
-
* @param {string} params.documentPath -
|
|
154
|
+
* @param {string} params.operation - The type of operation (e.g., 'document_update', 'structure_update', 'translation_update').
|
|
155
|
+
* @param {string} params.feedback - The user's feedback text.
|
|
156
|
+
* @param {string} params.documentPath - The document path.
|
|
157
157
|
*/
|
|
158
158
|
export function recordUpdate({ operation, feedback, documentPath = null }) {
|
|
159
159
|
// Skip if no feedback
|
|
@@ -167,12 +167,12 @@ export function recordUpdate({ operation, feedback, documentPath = null }) {
|
|
|
167
167
|
ensureGitRepo();
|
|
168
168
|
recordUpdateGit({ feedback });
|
|
169
169
|
} else {
|
|
170
|
-
console.warn("Git is not available, skipping
|
|
170
|
+
console.warn("Git is not available, so I am skipping the Git-based update history.");
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
175
|
+
* Gets the history entries from YAML.
|
|
176
176
|
*/
|
|
177
177
|
export function getHistory() {
|
|
178
178
|
const historyPath = join(process.cwd(), DOC_SMITH_DIR, HISTORY_FILE);
|
|
@@ -185,7 +185,7 @@ export function getHistory() {
|
|
|
185
185
|
const content = readFileSync(historyPath, "utf8");
|
|
186
186
|
return parse(content) || { entries: [] };
|
|
187
187
|
} catch (error) {
|
|
188
|
-
console.warn("
|
|
188
|
+
console.warn("Could not read the history:", error.message);
|
|
189
189
|
return { entries: [] };
|
|
190
190
|
}
|
|
191
191
|
}
|
package/utils/kroki-utils.mjs
CHANGED
|
@@ -31,7 +31,7 @@ export async function getChart({ chart = "d2", format = "svg", content, strict }
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
if (strict && !res.ok) {
|
|
34
|
-
throw new Error(`
|
|
34
|
+
throw new Error(`Could not fetch the chart: ${res.status} ${res.statusText}`);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const data = await res.text();
|
|
@@ -39,7 +39,7 @@ export async function getChart({ chart = "d2", format = "svg", content, strict }
|
|
|
39
39
|
} catch (err) {
|
|
40
40
|
if (strict) throw err;
|
|
41
41
|
|
|
42
|
-
console.error(
|
|
42
|
+
console.error(`Could not generate the chart from: ${baseUrl}`, err);
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -54,7 +54,6 @@ export async function getD2Svg({ content, strict = false }) {
|
|
|
54
54
|
return svgContent;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
// Helper: save d2 svg assets alongside document
|
|
58
57
|
export async function saveD2Assets({ markdown, docsDir }) {
|
|
59
58
|
if (!markdown) {
|
|
60
59
|
return markdown;
|
|
@@ -74,10 +73,10 @@ export async function saveD2Assets({ markdown, docsDir }) {
|
|
|
74
73
|
const svgPath = path.join(assetDir, fileName);
|
|
75
74
|
|
|
76
75
|
if (await fs.pathExists(svgPath)) {
|
|
77
|
-
debug("
|
|
76
|
+
debug("Asset cache found, skipping generation", svgPath);
|
|
78
77
|
} else {
|
|
79
78
|
try {
|
|
80
|
-
debug("
|
|
79
|
+
debug("Generating d2 diagram", svgPath);
|
|
81
80
|
if (debug.enabled) {
|
|
82
81
|
const d2FileName = `${getContentHash(d2Content)}.d2`;
|
|
83
82
|
const d2Path = path.join(assetDir, d2FileName);
|
|
@@ -89,7 +88,7 @@ export async function saveD2Assets({ markdown, docsDir }) {
|
|
|
89
88
|
await fs.writeFile(svgPath, svg, { encoding: "utf8" });
|
|
90
89
|
}
|
|
91
90
|
} catch (error) {
|
|
92
|
-
debug("
|
|
91
|
+
debug("Could not generate the D2 diagram:", error);
|
|
93
92
|
return _code;
|
|
94
93
|
}
|
|
95
94
|
}
|
|
@@ -102,7 +101,7 @@ export async function saveD2Assets({ markdown, docsDir }) {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
export async function beforePublishHook({ docsDir }) {
|
|
105
|
-
//
|
|
104
|
+
// Process each markdown file to save the d2 svg assets.
|
|
106
105
|
const mdFilePaths = await glob("**/*.md", { cwd: docsDir });
|
|
107
106
|
await pMap(
|
|
108
107
|
mdFilePaths,
|
|
@@ -158,7 +157,7 @@ export async function checkD2Content({ content }) {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
if (await fs.pathExists(svgPath)) {
|
|
161
|
-
debug("
|
|
160
|
+
debug("Asset cache found, skipping generation", svgPath);
|
|
162
161
|
return;
|
|
163
162
|
}
|
|
164
163
|
|
package/utils/load-config.mjs
CHANGED
|
@@ -10,9 +10,9 @@ export default async function loadConfig({ config, appUrl }) {
|
|
|
10
10
|
// Check if config file exists
|
|
11
11
|
await fs.access(configPath);
|
|
12
12
|
} catch (_error) {
|
|
13
|
-
console.log(`
|
|
14
|
-
console.log("
|
|
15
|
-
throw new Error(`
|
|
13
|
+
console.log(`The config file was not found at: ${configPath}`);
|
|
14
|
+
console.log("You can run 'aigne doc init' to create a new config file.");
|
|
15
|
+
throw new Error(`The config file was not found at: ${configPath}`);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
try {
|
|
@@ -36,7 +36,7 @@ export default async function loadConfig({ config, appUrl }) {
|
|
|
36
36
|
...processedConfig,
|
|
37
37
|
};
|
|
38
38
|
} catch (error) {
|
|
39
|
-
console.error(`
|
|
40
|
-
throw new Error(`
|
|
39
|
+
console.error(`I encountered an error while parsing the config file: ${error.message}`);
|
|
40
|
+
throw new Error(`I could not parse the config file: ${error.message}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
package/utils/upload-files.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import pLimit from "p-limit";
|
|
|
6
6
|
import pRetry from "p-retry";
|
|
7
7
|
|
|
8
8
|
import { getComponentMountPoint } from "./blocklet.mjs";
|
|
9
|
-
import { DISCUSS_KIT_DID } from "./constants/index.mjs";
|
|
9
|
+
import { DISCUSS_KIT_DID, MEDIA_KIT_DID } from "./constants/index.mjs";
|
|
10
10
|
import { getMimeType } from "./file-utils.mjs";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -143,7 +143,7 @@ export async function uploadFiles(options) {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
const url = new URL(appUrl);
|
|
146
|
-
const mountPoint = await getComponentMountPoint(appUrl,
|
|
146
|
+
const mountPoint = await getComponentMountPoint(appUrl, MEDIA_KIT_DID);
|
|
147
147
|
|
|
148
148
|
// Use custom endpoint or default to discuss kit media endpoint
|
|
149
149
|
const uploadEndpoint = endpoint || `${url.origin}${mountPoint}/api/uploads`;
|