@aigne/doc-smith 0.8.12-beta.3 → 0.8.12-beta.5
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/.aigne/doc-smith/config.yaml +9 -6
- package/.aigne/doc-smith/output/structure-plan.json +123 -109
- package/.aigne/doc-smith/upload-cache.yaml +48 -0
- package/.github/workflows/publish-docs.yml +4 -7
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +20 -0
- package/agents/clear/choose-contents.mjs +22 -5
- package/agents/clear/clear-auth-tokens.mjs +2 -4
- package/agents/clear/clear-deployment-config.mjs +49 -0
- package/agents/clear/clear-document-config.mjs +2 -5
- package/agents/clear/clear-document-structure.mjs +2 -6
- package/agents/clear/clear-generated-docs.mjs +0 -1
- package/agents/generate/check-need-generate-structure.mjs +15 -60
- package/agents/generate/document-structure-tools/generate-sub-structure.mjs +131 -0
- package/agents/generate/generate-structure-without-tools.yaml +65 -0
- package/agents/generate/generate-structure.yaml +7 -1
- package/agents/generate/index.yaml +0 -3
- package/agents/generate/update-document-structure.yaml +3 -0
- package/agents/generate/user-review-document-structure.mjs +7 -5
- package/agents/init/index.mjs +15 -15
- package/agents/publish/publish-docs.mjs +130 -111
- package/agents/translate/index.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 +4 -19
- package/agents/update/user-review-document.mjs +4 -3
- package/agents/utils/load-sources.mjs +54 -151
- package/agents/utils/transform-detail-datasources.mjs +14 -18
- package/aigne.yaml +2 -0
- package/biome.json +1 -1
- package/docs/_sidebar.md +13 -15
- package/docs/configuration-initial-setup.ja.md +179 -0
- package/docs/configuration-initial-setup.md +179 -0
- package/docs/configuration-initial-setup.zh-TW.md +179 -0
- package/docs/configuration-initial-setup.zh.md +179 -0
- package/docs/configuration-managing-preferences.ja.md +100 -0
- package/docs/configuration-managing-preferences.md +100 -0
- package/docs/configuration-managing-preferences.zh-TW.md +100 -0
- package/docs/configuration-managing-preferences.zh.md +100 -0
- package/docs/configuration.ja.md +68 -184
- package/docs/configuration.md +62 -178
- package/docs/configuration.zh-TW.md +70 -186
- package/docs/configuration.zh.md +67 -183
- package/docs/getting-started.ja.md +46 -78
- package/docs/getting-started.md +46 -78
- package/docs/getting-started.zh-TW.md +47 -79
- package/docs/getting-started.zh.md +47 -79
- package/docs/guides-cleaning-up.ja.md +50 -0
- package/docs/guides-cleaning-up.md +50 -0
- package/docs/guides-cleaning-up.zh-TW.md +50 -0
- package/docs/guides-cleaning-up.zh.md +50 -0
- package/docs/guides-evaluating-documents.ja.md +66 -0
- package/docs/guides-evaluating-documents.md +66 -0
- package/docs/guides-evaluating-documents.zh-TW.md +66 -0
- package/docs/guides-evaluating-documents.zh.md +66 -0
- package/docs/guides-generating-documentation.ja.md +149 -0
- package/docs/guides-generating-documentation.md +149 -0
- package/docs/guides-generating-documentation.zh-TW.md +149 -0
- package/docs/guides-generating-documentation.zh.md +149 -0
- package/docs/guides-interactive-chat.ja.md +85 -0
- package/docs/guides-interactive-chat.md +85 -0
- package/docs/guides-interactive-chat.zh-TW.md +85 -0
- package/docs/guides-interactive-chat.zh.md +85 -0
- package/docs/guides-managing-history.ja.md +51 -0
- package/docs/guides-managing-history.md +51 -0
- package/docs/guides-managing-history.zh-TW.md +51 -0
- package/docs/guides-managing-history.zh.md +51 -0
- package/docs/guides-publishing-your-docs.ja.md +78 -0
- package/docs/guides-publishing-your-docs.md +78 -0
- package/docs/guides-publishing-your-docs.zh-TW.md +78 -0
- package/docs/guides-publishing-your-docs.zh.md +78 -0
- package/docs/guides-translating-documentation.ja.md +95 -0
- package/docs/guides-translating-documentation.md +95 -0
- package/docs/guides-translating-documentation.zh-TW.md +95 -0
- package/docs/guides-translating-documentation.zh.md +95 -0
- package/docs/guides-updating-documentation.ja.md +77 -0
- package/docs/guides-updating-documentation.md +77 -0
- package/docs/guides-updating-documentation.zh-TW.md +77 -0
- package/docs/guides-updating-documentation.zh.md +77 -0
- package/docs/guides.ja.md +32 -0
- package/docs/guides.md +32 -0
- package/docs/guides.zh-TW.md +32 -0
- package/docs/guides.zh.md +32 -0
- package/docs/overview.ja.md +39 -60
- package/docs/overview.md +39 -60
- package/docs/overview.zh-TW.md +39 -60
- package/docs/overview.zh.md +39 -60
- package/docs/release-notes.ja.md +255 -0
- package/docs/release-notes.md +255 -0
- package/docs/release-notes.zh-TW.md +255 -0
- package/docs/release-notes.zh.md +255 -0
- package/package.json +4 -2
- package/prompts/common/document/content-rules-core.md +1 -0
- package/prompts/common/document-structure/document-structure-rules.md +8 -9
- package/prompts/common/document-structure/output-constraints.md +1 -1
- package/prompts/structure/document-rules.md +8 -2
- package/prompts/structure/generate/system-prompt.md +27 -2
- package/prompts/structure/generate/user-prompt.md +18 -0
- package/prompts/structure/update/system-prompt.md +12 -0
- package/prompts/structure/update/user-prompt.md +3 -0
- package/tests/agents/clear/choose-contents.test.mjs +8 -4
- package/tests/agents/generate/check-need-generate-structure.test.mjs +53 -63
- package/tests/agents/generate/document-structure-tools/generate-sub-structure.test.mjs +277 -0
- package/tests/agents/init/init.test.mjs +18 -18
- package/tests/agents/publish/publish-docs.test.mjs +79 -0
- package/tests/agents/update/check-document.test.mjs +7 -67
- package/tests/agents/utils/load-sources.test.mjs +90 -90
- package/tests/agents/utils/transform-detail-datasources.test.mjs +153 -196
- package/tests/utils/file-utils.test.mjs +309 -1
- package/utils/auth-utils.mjs +9 -3
- package/utils/constants/index.mjs +3 -1
- package/utils/file-utils.mjs +315 -0
- package/utils/utils.mjs +89 -50
- package/docs/advanced-how-it-works.ja.md +0 -101
- package/docs/advanced-how-it-works.md +0 -101
- package/docs/advanced-how-it-works.zh-TW.md +0 -101
- package/docs/advanced-how-it-works.zh.md +0 -101
- package/docs/advanced-quality-assurance.ja.md +0 -92
- package/docs/advanced-quality-assurance.md +0 -92
- package/docs/advanced-quality-assurance.zh-TW.md +0 -92
- package/docs/advanced-quality-assurance.zh.md +0 -92
- package/docs/advanced.ja.md +0 -20
- package/docs/advanced.md +0 -20
- package/docs/advanced.zh-TW.md +0 -20
- package/docs/advanced.zh.md +0 -20
- package/docs/changelog.ja.md +0 -486
- package/docs/changelog.md +0 -486
- package/docs/changelog.zh-TW.md +0 -486
- package/docs/changelog.zh.md +0 -486
- package/docs/cli-reference.ja.md +0 -311
- package/docs/cli-reference.md +0 -311
- package/docs/cli-reference.zh-TW.md +0 -311
- package/docs/cli-reference.zh.md +0 -311
- package/docs/configuration-interactive-setup.ja.md +0 -138
- package/docs/configuration-interactive-setup.md +0 -138
- package/docs/configuration-interactive-setup.zh-TW.md +0 -138
- package/docs/configuration-interactive-setup.zh.md +0 -138
- package/docs/configuration-language-support.ja.md +0 -64
- package/docs/configuration-language-support.md +0 -64
- package/docs/configuration-language-support.zh-TW.md +0 -64
- package/docs/configuration-language-support.zh.md +0 -64
- package/docs/configuration-llm-setup.ja.md +0 -56
- package/docs/configuration-llm-setup.md +0 -56
- package/docs/configuration-llm-setup.zh-TW.md +0 -56
- package/docs/configuration-llm-setup.zh.md +0 -56
- package/docs/configuration-preferences.ja.md +0 -144
- package/docs/configuration-preferences.md +0 -144
- package/docs/configuration-preferences.zh-TW.md +0 -144
- package/docs/configuration-preferences.zh.md +0 -144
- package/docs/features-generate-documentation.ja.md +0 -95
- package/docs/features-generate-documentation.md +0 -95
- package/docs/features-generate-documentation.zh-TW.md +0 -95
- package/docs/features-generate-documentation.zh.md +0 -95
- package/docs/features-publish-your-docs.ja.md +0 -130
- package/docs/features-publish-your-docs.md +0 -130
- package/docs/features-publish-your-docs.zh-TW.md +0 -130
- package/docs/features-publish-your-docs.zh.md +0 -130
- package/docs/features-translate-documentation.ja.md +0 -90
- package/docs/features-translate-documentation.md +0 -90
- package/docs/features-translate-documentation.zh-TW.md +0 -90
- package/docs/features-translate-documentation.zh.md +0 -90
- package/docs/features-update-and-refine.ja.md +0 -142
- package/docs/features-update-and-refine.md +0 -142
- package/docs/features-update-and-refine.zh-TW.md +0 -143
- package/docs/features-update-and-refine.zh.md +0 -142
- package/docs/features.ja.md +0 -62
- package/docs/features.md +0 -62
- package/docs/features.zh-TW.md +0 -62
- package/docs/features.zh.md +0 -62
|
@@ -2,7 +2,17 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
|
2
2
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
buildSourcesContent,
|
|
7
|
+
calculateFileStats,
|
|
8
|
+
getFilesWithGlob,
|
|
9
|
+
loadFilesFromPaths,
|
|
10
|
+
loadGitignore,
|
|
11
|
+
pathExists,
|
|
12
|
+
readFileContents,
|
|
13
|
+
resolveToAbsolute,
|
|
14
|
+
toDisplayPath,
|
|
15
|
+
} from "../../utils/file-utils.mjs";
|
|
6
16
|
|
|
7
17
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
18
|
|
|
@@ -210,4 +220,302 @@ temp*
|
|
|
210
220
|
expect(files.length).toBe(0);
|
|
211
221
|
});
|
|
212
222
|
});
|
|
223
|
+
|
|
224
|
+
describe("pathExists", () => {
|
|
225
|
+
test("should return true for existing file", async () => {
|
|
226
|
+
const testFile = join(testDir, "exists.txt");
|
|
227
|
+
await writeFile(testFile, "test");
|
|
228
|
+
|
|
229
|
+
const exists = await pathExists(testFile);
|
|
230
|
+
expect(exists).toBe(true);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("should return true for existing directory", async () => {
|
|
234
|
+
const exists = await pathExists(testDir);
|
|
235
|
+
expect(exists).toBe(true);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("should return false for non-existent path", async () => {
|
|
239
|
+
const nonExistent = join(testDir, "does-not-exist.txt");
|
|
240
|
+
const exists = await pathExists(nonExistent);
|
|
241
|
+
expect(exists).toBe(false);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("toDisplayPath", () => {
|
|
246
|
+
test("should return relative path for paths inside cwd", () => {
|
|
247
|
+
const testPath = join(process.cwd(), "test", "file.txt");
|
|
248
|
+
const display = toDisplayPath(testPath);
|
|
249
|
+
expect(display.startsWith("..")).toBe(false);
|
|
250
|
+
expect(display).toContain("test");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test("should return absolute path for paths outside cwd", () => {
|
|
254
|
+
const testPath = "/some/other/path/file.txt";
|
|
255
|
+
const display = toDisplayPath(testPath);
|
|
256
|
+
expect(display.startsWith("/") || display.startsWith("..")).toBe(true);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("should return . for current directory", () => {
|
|
260
|
+
const display = toDisplayPath(process.cwd());
|
|
261
|
+
expect(display).toBe(".");
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("resolveToAbsolute", () => {
|
|
266
|
+
test("should return absolute path as-is", () => {
|
|
267
|
+
const absolutePath = "/absolute/path/file.txt";
|
|
268
|
+
const resolved = resolveToAbsolute(absolutePath);
|
|
269
|
+
expect(resolved).toBe(absolutePath);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("should resolve relative path to absolute", () => {
|
|
273
|
+
const relativePath = "relative/file.txt";
|
|
274
|
+
const resolved = resolveToAbsolute(relativePath);
|
|
275
|
+
expect(resolved).toBeDefined();
|
|
276
|
+
expect(resolved?.startsWith("/")).toBe(true);
|
|
277
|
+
expect(resolved).toContain("relative");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("should return undefined for empty value", () => {
|
|
281
|
+
expect(resolveToAbsolute("")).toBeUndefined();
|
|
282
|
+
expect(resolveToAbsolute(null)).toBeUndefined();
|
|
283
|
+
expect(resolveToAbsolute(undefined)).toBeUndefined();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe("loadFilesFromPaths", () => {
|
|
288
|
+
beforeEach(async () => {
|
|
289
|
+
await mkdir(join(testDir, "src"), { recursive: true });
|
|
290
|
+
await mkdir(join(testDir, "docs"), { recursive: true });
|
|
291
|
+
await writeFile(join(testDir, "src", "index.js"), "// index");
|
|
292
|
+
await writeFile(join(testDir, "src", "utils.ts"), "// utils");
|
|
293
|
+
await writeFile(join(testDir, "docs", "readme.md"), "# readme");
|
|
294
|
+
await writeFile(join(testDir, "config.json"), "{}");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("should load single file path", async () => {
|
|
298
|
+
const filePath = join(testDir, "config.json");
|
|
299
|
+
const files = await loadFilesFromPaths(filePath);
|
|
300
|
+
|
|
301
|
+
expect(files).toBeDefined();
|
|
302
|
+
expect(files.length).toBe(1);
|
|
303
|
+
expect(files[0]).toBe(filePath);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("should load multiple file paths", async () => {
|
|
307
|
+
const file1 = join(testDir, "config.json");
|
|
308
|
+
const file2 = join(testDir, "docs", "readme.md");
|
|
309
|
+
const files = await loadFilesFromPaths([file1, file2]);
|
|
310
|
+
|
|
311
|
+
expect(files.length).toBe(2);
|
|
312
|
+
expect(files).toContain(file1);
|
|
313
|
+
expect(files).toContain(file2);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("should load files from directory with default patterns", async () => {
|
|
317
|
+
const files = await loadFilesFromPaths(testDir, {
|
|
318
|
+
useDefaultPatterns: true,
|
|
319
|
+
defaultIncludePatterns: ["**/*.js", "**/*.ts"],
|
|
320
|
+
defaultExcludePatterns: [],
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
expect(files.length).toBeGreaterThan(0);
|
|
324
|
+
expect(files.some((f) => f.includes("index.js"))).toBe(true);
|
|
325
|
+
expect(files.some((f) => f.includes("utils.ts"))).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("should handle glob patterns", async () => {
|
|
329
|
+
const files = await loadFilesFromPaths(join(testDir, "**/*.js"));
|
|
330
|
+
|
|
331
|
+
expect(files).toBeDefined();
|
|
332
|
+
expect(files.some((f) => f.includes("index.js"))).toBe(true);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test("should handle invalid paths gracefully", async () => {
|
|
336
|
+
const files = await loadFilesFromPaths([123, null, "valid-but-not-exist"], {
|
|
337
|
+
useDefaultPatterns: false,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
expect(Array.isArray(files)).toBe(true);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("should apply include and exclude patterns", async () => {
|
|
344
|
+
const files = await loadFilesFromPaths(testDir, {
|
|
345
|
+
includePatterns: ["**/*.js", "**/*.ts"],
|
|
346
|
+
excludePatterns: ["**/*.ts"],
|
|
347
|
+
useDefaultPatterns: false,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
expect(files.some((f) => f.includes("index.js"))).toBe(true);
|
|
351
|
+
expect(files.some((f) => f.includes("utils.ts"))).toBe(false);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("should handle string patterns as array", async () => {
|
|
355
|
+
const files = await loadFilesFromPaths(testDir, {
|
|
356
|
+
includePatterns: "**/*.js",
|
|
357
|
+
excludePatterns: "**/*.ts",
|
|
358
|
+
useDefaultPatterns: false,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
expect(Array.isArray(files)).toBe(true);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe("readFileContents", () => {
|
|
366
|
+
beforeEach(async () => {
|
|
367
|
+
await mkdir(join(testDir, "src"), { recursive: true });
|
|
368
|
+
await writeFile(join(testDir, "src", "file1.js"), "const x = 1;");
|
|
369
|
+
await writeFile(join(testDir, "src", "file2.js"), "const y = 2;");
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("should read multiple files with content", async () => {
|
|
373
|
+
const files = [join(testDir, "src", "file1.js"), join(testDir, "src", "file2.js")];
|
|
374
|
+
const contents = await readFileContents(files, testDir);
|
|
375
|
+
|
|
376
|
+
expect(contents.length).toBe(2);
|
|
377
|
+
expect(contents[0].sourceId).toContain("file1.js");
|
|
378
|
+
expect(contents[0].content).toContain("const x = 1");
|
|
379
|
+
expect(contents[1].sourceId).toContain("file2.js");
|
|
380
|
+
expect(contents[1].content).toContain("const y = 2");
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test("should use custom baseDir for relative paths", async () => {
|
|
384
|
+
const files = [join(testDir, "src", "file1.js")];
|
|
385
|
+
const contents = await readFileContents(files, testDir);
|
|
386
|
+
|
|
387
|
+
expect(contents[0].sourceId).not.toContain(testDir);
|
|
388
|
+
expect(contents[0].sourceId).toContain("src");
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("should skip binary files by default", async () => {
|
|
392
|
+
const binaryFile = join(testDir, "binary.bin");
|
|
393
|
+
await writeFile(binaryFile, Buffer.from([0xff, 0xfe, 0xfd, 0xfc]));
|
|
394
|
+
const textFile = join(testDir, "text.txt");
|
|
395
|
+
await writeFile(textFile, "text content");
|
|
396
|
+
|
|
397
|
+
const contents = await readFileContents([binaryFile, textFile], testDir);
|
|
398
|
+
|
|
399
|
+
expect(contents.length).toBeGreaterThanOrEqual(1);
|
|
400
|
+
expect(contents.some((c) => c.sourceId.includes("text.txt"))).toBe(true);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test("should include binary files when skipBinaryFiles is false", async () => {
|
|
404
|
+
const binaryFile = join(testDir, "binary.bin");
|
|
405
|
+
await writeFile(binaryFile, Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f]));
|
|
406
|
+
|
|
407
|
+
const contents = await readFileContents([binaryFile], testDir, {
|
|
408
|
+
skipBinaryFiles: false,
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
expect(contents.length).toBeGreaterThanOrEqual(0);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("should handle empty file array", async () => {
|
|
415
|
+
const contents = await readFileContents([], testDir);
|
|
416
|
+
expect(contents.length).toBe(0);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
describe("calculateFileStats", () => {
|
|
421
|
+
test("should calculate tokens and lines correctly", () => {
|
|
422
|
+
const sourceFiles = [
|
|
423
|
+
{ content: "const x = 1;\nconst y = 2;" },
|
|
424
|
+
{ content: "function test() {\n return true;\n}" },
|
|
425
|
+
];
|
|
426
|
+
|
|
427
|
+
const stats = calculateFileStats(sourceFiles);
|
|
428
|
+
|
|
429
|
+
expect(stats.totalTokens).toBeGreaterThan(0);
|
|
430
|
+
expect(stats.totalLines).toBeGreaterThan(0);
|
|
431
|
+
expect(stats.totalLines).toBeGreaterThan(3);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("should handle empty content", () => {
|
|
435
|
+
const sourceFiles = [{ content: "" }, { content: "" }];
|
|
436
|
+
const stats = calculateFileStats(sourceFiles);
|
|
437
|
+
|
|
438
|
+
expect(stats.totalTokens).toBe(0);
|
|
439
|
+
expect(stats.totalLines).toBe(0);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
test("should exclude empty lines from line count", () => {
|
|
443
|
+
const sourceFiles = [{ content: "line1\n\nline2\n\n\nline3" }];
|
|
444
|
+
const stats = calculateFileStats(sourceFiles);
|
|
445
|
+
|
|
446
|
+
expect(stats.totalLines).toBe(3);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test("should handle files without content property", () => {
|
|
450
|
+
const sourceFiles = [{ noContent: true }, { content: "test" }];
|
|
451
|
+
const stats = calculateFileStats(sourceFiles);
|
|
452
|
+
|
|
453
|
+
expect(stats.totalTokens).toBeGreaterThan(0);
|
|
454
|
+
expect(stats.totalLines).toBe(1);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
describe("buildSourcesContent", () => {
|
|
459
|
+
test("should build sources for normal context", () => {
|
|
460
|
+
const sourceFiles = [
|
|
461
|
+
{ sourceId: "file1.js", content: "const x = 1;" },
|
|
462
|
+
{ sourceId: "file2.js", content: "const y = 2;" },
|
|
463
|
+
];
|
|
464
|
+
|
|
465
|
+
const sources = buildSourcesContent(sourceFiles, false);
|
|
466
|
+
|
|
467
|
+
expect(sources).toContain("// sourceId: file1.js");
|
|
468
|
+
expect(sources).toContain("const x = 1;");
|
|
469
|
+
expect(sources).toContain("// sourceId: file2.js");
|
|
470
|
+
expect(sources).toContain("const y = 2;");
|
|
471
|
+
expect(sources).not.toContain("Note: Context is large");
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test("should filter core files for large context", () => {
|
|
475
|
+
const sourceFiles = [
|
|
476
|
+
{ sourceId: "package.json", content: '{"name": "test"}' },
|
|
477
|
+
{ sourceId: "README.md", content: "# Test" },
|
|
478
|
+
{ sourceId: "random.js", content: "const x = 1;" },
|
|
479
|
+
];
|
|
480
|
+
|
|
481
|
+
const sources = buildSourcesContent(sourceFiles, true);
|
|
482
|
+
|
|
483
|
+
expect(sources).toContain("Note: Context is large");
|
|
484
|
+
expect(sources).toContain("package.json");
|
|
485
|
+
expect(sources).toContain("README.md");
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
test("should include core files matching patterns", () => {
|
|
489
|
+
const sourceFiles = [
|
|
490
|
+
{ sourceId: "index.js", content: "// entry" },
|
|
491
|
+
{ sourceId: "main.ts", content: "// main" },
|
|
492
|
+
{ sourceId: "types.d.ts", content: "// types" },
|
|
493
|
+
{ sourceId: "api/routes.js", content: "// routes" },
|
|
494
|
+
];
|
|
495
|
+
|
|
496
|
+
const sources = buildSourcesContent(sourceFiles, true);
|
|
497
|
+
|
|
498
|
+
expect(sources).toContain("index.js");
|
|
499
|
+
expect(sources).toContain("main.ts");
|
|
500
|
+
expect(sources).toContain("types.d.ts");
|
|
501
|
+
expect(sources).toContain("routes.js");
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test("should handle empty sourceFiles array", () => {
|
|
505
|
+
const sources = buildSourcesContent([], false);
|
|
506
|
+
expect(sources).toBe("");
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
test("should use all files as fallback when no core files in large context", () => {
|
|
510
|
+
const sourceFiles = [
|
|
511
|
+
{ sourceId: "random1.xyz", content: "test1" },
|
|
512
|
+
{ sourceId: "random2.xyz", content: "test2" },
|
|
513
|
+
];
|
|
514
|
+
|
|
515
|
+
const sources = buildSourcesContent(sourceFiles, true);
|
|
516
|
+
|
|
517
|
+
expect(sources).toContain("Note: Context is large");
|
|
518
|
+
expect(sources).toContain("showing a sample of files");
|
|
519
|
+
});
|
|
520
|
+
});
|
|
213
521
|
});
|
package/utils/auth-utils.mjs
CHANGED
|
@@ -24,14 +24,18 @@ import {
|
|
|
24
24
|
|
|
25
25
|
const WELLKNOWN_SERVICE_PATH_PREFIX = "/.well-known/service";
|
|
26
26
|
|
|
27
|
+
export function getDocSmithEnvFilePath() {
|
|
28
|
+
return join(homedir(), ".aigne", "doc-smith-connected.yaml");
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
/**
|
|
28
32
|
* Get access token from environment, config file, or prompt user for authorization
|
|
29
33
|
* @param {string} appUrl - The application URL
|
|
30
34
|
* @returns {Promise<string>} - The access token
|
|
31
35
|
*/
|
|
32
36
|
export async function getAccessToken(appUrl, ltToken = "") {
|
|
33
|
-
const DOC_SMITH_ENV_FILE = join(homedir(), ".aigne", "doc-smith-connected.yaml");
|
|
34
37
|
const { hostname } = new URL(appUrl);
|
|
38
|
+
const DOC_SMITH_ENV_FILE = getDocSmithEnvFilePath();
|
|
35
39
|
|
|
36
40
|
let accessToken = process.env.DOC_DISCUSS_KIT_ACCESS_TOKEN;
|
|
37
41
|
|
|
@@ -72,7 +76,9 @@ export async function getAccessToken(appUrl, ltToken = "") {
|
|
|
72
76
|
const docsLink = chalk.cyan(BLOCKLET_ADD_COMPONENT_DOCS);
|
|
73
77
|
throw new Error(
|
|
74
78
|
`${chalk.yellow("⚠️ This website does not have required components for publishing")}\n\n` +
|
|
75
|
-
`${chalk.bold(
|
|
79
|
+
`${chalk.bold(
|
|
80
|
+
"💡 Solution:",
|
|
81
|
+
)} Please refer to the documentation to add Discuss Kit component:\n${docsLink}\n\n`,
|
|
76
82
|
);
|
|
77
83
|
} else {
|
|
78
84
|
throw new Error(
|
|
@@ -160,7 +166,7 @@ export async function getOfficialAccessToken(baseUrl) {
|
|
|
160
166
|
// Parse URL once and reuse
|
|
161
167
|
const urlObj = new URL(baseUrl);
|
|
162
168
|
const { hostname, origin } = urlObj;
|
|
163
|
-
const DOC_SMITH_ENV_FILE =
|
|
169
|
+
const DOC_SMITH_ENV_FILE = getDocSmithEnvFilePath();
|
|
164
170
|
|
|
165
171
|
// 1. Check environment variable
|
|
166
172
|
let accessToken = process.env[DOC_OFFICIAL_ACCESS_TOKEN];
|
|
@@ -347,6 +347,9 @@ export const BLOCKLET_ADD_COMPONENT_DOCS =
|
|
|
347
347
|
// Supported file extensions for content reading
|
|
348
348
|
export const SUPPORTED_FILE_EXTENSIONS = [".txt", ".md", ".json", ".yaml", ".yml"];
|
|
349
349
|
|
|
350
|
+
// Token count threshold for intelligent source path suggestion
|
|
351
|
+
export const INTELLIGENT_SUGGESTION_TOKEN_THRESHOLD = 600000;
|
|
352
|
+
|
|
350
353
|
// Conflict rules configuration for documentation generation
|
|
351
354
|
export const CONFLICT_RULES = {
|
|
352
355
|
// Internal conflicts within the same question (multi-select conflicts)
|
|
@@ -544,7 +547,6 @@ export const FILE_CONCURRENCY = 3;
|
|
|
544
547
|
export const DOC_SMITH_DIR = ".aigne/doc-smith";
|
|
545
548
|
export const TMP_DIR = ".tmp";
|
|
546
549
|
export const TMP_DOCS_DIR = "docs";
|
|
547
|
-
|
|
548
550
|
export const TMP_ASSETS_DIR = "assets";
|
|
549
551
|
|
|
550
552
|
// Default evaluation scoring weights
|