markdown-ai-rewriter 0.2.0
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 +29 -0
- package/README.md +298 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +87 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/full-rewriter.d.ts +28 -0
- package/dist/core/full-rewriter.d.ts.map +1 -0
- package/dist/core/full-rewriter.js +195 -0
- package/dist/core/full-rewriter.js.map +1 -0
- package/dist/core/parser.d.ts +21 -0
- package/dist/core/parser.d.ts.map +1 -0
- package/dist/core/parser.js +239 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/providers/anthropic.d.ts +12 -0
- package/dist/core/providers/anthropic.d.ts.map +1 -0
- package/dist/core/providers/anthropic.js +77 -0
- package/dist/core/providers/anthropic.js.map +1 -0
- package/dist/core/providers/base.d.ts +8 -0
- package/dist/core/providers/base.d.ts.map +1 -0
- package/dist/core/providers/base.js +28 -0
- package/dist/core/providers/base.js.map +1 -0
- package/dist/core/providers/minimax.d.ts +20 -0
- package/dist/core/providers/minimax.d.ts.map +1 -0
- package/dist/core/providers/minimax.js +87 -0
- package/dist/core/providers/minimax.js.map +1 -0
- package/dist/core/providers/openai.d.ts +12 -0
- package/dist/core/providers/openai.d.ts.map +1 -0
- package/dist/core/providers/openai.js +76 -0
- package/dist/core/providers/openai.js.map +1 -0
- package/dist/core/quota-manager.d.ts +17 -0
- package/dist/core/quota-manager.d.ts.map +1 -0
- package/dist/core/quota-manager.js +60 -0
- package/dist/core/quota-manager.js.map +1 -0
- package/dist/core/rewriter.d.ts +13 -0
- package/dist/core/rewriter.d.ts.map +1 -0
- package/dist/core/rewriter.js +88 -0
- package/dist/core/rewriter.js.map +1 -0
- package/dist/core/section-parser.d.ts +20 -0
- package/dist/core/section-parser.d.ts.map +1 -0
- package/dist/core/section-parser.js +199 -0
- package/dist/core/section-parser.js.map +1 -0
- package/dist/core/section-rewriter.d.ts +25 -0
- package/dist/core/section-rewriter.d.ts.map +1 -0
- package/dist/core/section-rewriter.js +152 -0
- package/dist/core/section-rewriter.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +81 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class QuotaManager {
|
|
2
|
+
private quotaFile;
|
|
3
|
+
private dailyLimit;
|
|
4
|
+
constructor(dailyLimit?: number);
|
|
5
|
+
private getToday;
|
|
6
|
+
private loadQuota;
|
|
7
|
+
private saveQuota;
|
|
8
|
+
canUse(): boolean;
|
|
9
|
+
getRemainingQuota(): number;
|
|
10
|
+
incrementUsage(): void;
|
|
11
|
+
getUsageInfo(): {
|
|
12
|
+
used: number;
|
|
13
|
+
limit: number;
|
|
14
|
+
remaining: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=quota-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-manager.d.ts","sourceRoot":"","sources":["../../src/core/quota-manager.ts"],"names":[],"mappings":"AASA,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;gBAEf,UAAU,GAAE,MAAW;IASnC,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,SAAS;IAgBjB,OAAO,CAAC,SAAS;IAIjB,MAAM,IAAI,OAAO;IAKjB,iBAAiB,IAAI,MAAM;IAK3B,cAAc,IAAI,IAAI;IAMtB,YAAY,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;CAQnE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuotaManager = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
class QuotaManager {
|
|
8
|
+
constructor(dailyLimit = 10) {
|
|
9
|
+
const configDir = (0, path_1.join)((0, os_1.homedir)(), '.markdown-ai-rewriter');
|
|
10
|
+
if (!(0, fs_1.existsSync)(configDir)) {
|
|
11
|
+
(0, fs_1.mkdirSync)(configDir, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
this.quotaFile = (0, path_1.join)(configDir, 'quota.json');
|
|
14
|
+
this.dailyLimit = dailyLimit;
|
|
15
|
+
}
|
|
16
|
+
getToday() {
|
|
17
|
+
return new Date().toISOString().split('T')[0];
|
|
18
|
+
}
|
|
19
|
+
loadQuota() {
|
|
20
|
+
if (!(0, fs_1.existsSync)(this.quotaFile)) {
|
|
21
|
+
return { date: this.getToday(), count: 0 };
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const data = JSON.parse((0, fs_1.readFileSync)(this.quotaFile, 'utf-8'));
|
|
25
|
+
if (data.date !== this.getToday()) {
|
|
26
|
+
return { date: this.getToday(), count: 0 };
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return { date: this.getToday(), count: 0 };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
saveQuota(data) {
|
|
35
|
+
(0, fs_1.writeFileSync)(this.quotaFile, JSON.stringify(data, null, 2), 'utf-8');
|
|
36
|
+
}
|
|
37
|
+
canUse() {
|
|
38
|
+
const quota = this.loadQuota();
|
|
39
|
+
return quota.count < this.dailyLimit;
|
|
40
|
+
}
|
|
41
|
+
getRemainingQuota() {
|
|
42
|
+
const quota = this.loadQuota();
|
|
43
|
+
return Math.max(0, this.dailyLimit - quota.count);
|
|
44
|
+
}
|
|
45
|
+
incrementUsage() {
|
|
46
|
+
const quota = this.loadQuota();
|
|
47
|
+
quota.count += 1;
|
|
48
|
+
this.saveQuota(quota);
|
|
49
|
+
}
|
|
50
|
+
getUsageInfo() {
|
|
51
|
+
const quota = this.loadQuota();
|
|
52
|
+
return {
|
|
53
|
+
used: quota.count,
|
|
54
|
+
limit: this.dailyLimit,
|
|
55
|
+
remaining: this.getRemainingQuota(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.QuotaManager = QuotaManager;
|
|
60
|
+
//# sourceMappingURL=quota-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quota-manager.js","sourceRoot":"","sources":["../../src/core/quota-manager.ts"],"names":[],"mappings":";;;AAAA,2BAAwE;AACxE,+BAA4B;AAC5B,2BAA6B;AAO7B,MAAa,YAAY;IAIvB,YAAY,aAAqB,EAAE;QACjC,MAAM,SAAS,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,uBAAuB,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAA,eAAU,EAAC,SAAS,CAAC,EAAE,CAAC;YAC3B,IAAA,cAAS,EAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAEO,QAAQ;QACd,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,CAAC;IAEO,SAAS;QACf,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,Q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IAAI,CAAC,SAAS,EAAE,CAAC;QAC/B,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,UAAU;YACtB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE;SACpC,CAAC;IACJ,CAAC;CACF;AA7DD,oCA6DC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RewriterConfig, RewriteResult } from '../types';
|
|
2
|
+
export declare class MarkdownRewriter {
|
|
3
|
+
private sectionRewriter;
|
|
4
|
+
private fullRewriter;
|
|
5
|
+
private provider;
|
|
6
|
+
private config;
|
|
7
|
+
private quotaManager?;
|
|
8
|
+
private usingSharedKey;
|
|
9
|
+
constructor(config: RewriterConfig);
|
|
10
|
+
private resolveApiKey;
|
|
11
|
+
rewrite(markdown: string): Promise<RewriteResult>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=rewriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewriter.d.ts","sourceRoot":"","sources":["../../src/core/rewriter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAc,MAAM,UAAU,CAAC;AAIrE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,cAAc,CAAkB;gBAE5B,MAAM,EAAE,cAAc;IAsBlC,OAAO,CAAC,aAAa;IAkCf,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CA+BxD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MarkdownRewriter = void 0;
|
|
4
|
+
const openai_1 = require("./providers/openai");
|
|
5
|
+
const anthropic_1 = require("./providers/anthropic");
|
|
6
|
+
const minimax_1 = require("./providers/minimax");
|
|
7
|
+
const quota_manager_1 = require("./quota-manager");
|
|
8
|
+
const section_rewriter_1 = require("./section-rewriter");
|
|
9
|
+
const full_rewriter_1 = require("./full-rewriter");
|
|
10
|
+
const SHARED_OPENAI_KEY = process.env.SHARED_OPENAI_KEY || '';
|
|
11
|
+
class MarkdownRewriter {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.usingSharedKey = false;
|
|
14
|
+
this.config = config;
|
|
15
|
+
const apiKey = this.resolveApiKey(config);
|
|
16
|
+
if (config.customProvider) {
|
|
17
|
+
this.provider = config.customProvider;
|
|
18
|
+
}
|
|
19
|
+
else if (config.provider === 'openai') {
|
|
20
|
+
this.provider = new openai_1.OpenAIProvider(apiKey, config.model);
|
|
21
|
+
}
|
|
22
|
+
else if (config.provider === 'anthropic') {
|
|
23
|
+
this.provider = new anthropic_1.AnthropicProvider(apiKey, config.model);
|
|
24
|
+
}
|
|
25
|
+
else if (config.provider === 'minimax') {
|
|
26
|
+
this.provider = new minimax_1.MinimaxProvider(apiKey, config.model, config.minimaxBaseUrl);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new Error(`Unsupported provider: ${config.provider}`);
|
|
30
|
+
}
|
|
31
|
+
// 初始化新的重写器
|
|
32
|
+
this.sectionRewriter = new section_rewriter_1.SectionRewriter(this.provider, config.verbose);
|
|
33
|
+
this.fullRewriter = new full_rewriter_1.FullRewriter(this.provider, config.verbose);
|
|
34
|
+
}
|
|
35
|
+
resolveApiKey(config) {
|
|
36
|
+
if (config.apiKey) {
|
|
37
|
+
return config.apiKey;
|
|
38
|
+
}
|
|
39
|
+
if (config.useSharedKey !== false && SHARED_OPENAI_KEY) {
|
|
40
|
+
this.usingSharedKey = true;
|
|
41
|
+
this.quotaManager = new quota_manager_1.QuotaManager(config.dailyLimit || 10);
|
|
42
|
+
if (!this.quotaManager.canUse()) {
|
|
43
|
+
const info = this.quotaManager.getUsageInfo();
|
|
44
|
+
throw new Error(`Daily quota exceeded (${info.used}/${info.limit}). ` +
|
|
45
|
+
`Please configure your own API key:\n` +
|
|
46
|
+
`export OPENAI_API_KEY='sk-...' or export ANTHROPIC_API_KEY='sk-ant-...' or export MINIMAX_API_KEY='...'`);
|
|
47
|
+
}
|
|
48
|
+
if (config.verbose) {
|
|
49
|
+
const remaining = this.quotaManager.getRemainingQuota();
|
|
50
|
+
console.log(`ℹ️ Using shared API key (${remaining} uses remaining today)`);
|
|
51
|
+
}
|
|
52
|
+
return SHARED_OPENAI_KEY;
|
|
53
|
+
}
|
|
54
|
+
throw new Error('API key required. Please set:\n' +
|
|
55
|
+
' export OPENAI_API_KEY="sk-..." or\n' +
|
|
56
|
+
' export ANTHROPIC_API_KEY="sk-ant-..." or\n' +
|
|
57
|
+
' export MINIMAX_API_KEY="..."');
|
|
58
|
+
}
|
|
59
|
+
async rewrite(markdown) {
|
|
60
|
+
const mode = this.config.mode || 'section';
|
|
61
|
+
if (mode !== 'section' && mode !== 'full') {
|
|
62
|
+
throw new Error(`Unsupported mode: ${String(mode)}. Use 'section' or 'full'.`);
|
|
63
|
+
}
|
|
64
|
+
if (this.usingSharedKey && this.quotaManager) {
|
|
65
|
+
this.quotaManager.incrementUsage();
|
|
66
|
+
}
|
|
67
|
+
switch (mode) {
|
|
68
|
+
case 'full':
|
|
69
|
+
if (this.config.verbose) {
|
|
70
|
+
console.log('📝 使用全文改写模式(最连贯)');
|
|
71
|
+
}
|
|
72
|
+
return this.fullRewriter.rewrite(markdown, this.config.options || {});
|
|
73
|
+
case 'section':
|
|
74
|
+
if (this.config.verbose) {
|
|
75
|
+
console.log('📚 使用章节改写模式(推荐)');
|
|
76
|
+
}
|
|
77
|
+
return this.sectionRewriter.rewrite(markdown, {
|
|
78
|
+
...this.config.options,
|
|
79
|
+
sectionLevel: this.config.sectionLevel || 1,
|
|
80
|
+
maintainImageContext: true,
|
|
81
|
+
crossSectionContext: true,
|
|
82
|
+
concurrency: this.config.concurrency,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.MarkdownRewriter = MarkdownRewriter;
|
|
88
|
+
//# sourceMappingURL=rewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewriter.js","sourceRoot":"","sources":["../../src/core/rewriter.ts"],"names":[],"mappings":";;;AAAA,+CAAoD;AACpD,qDAA0D;AAC1D,iDAAsD;AACtD,mDAA+C;AAC/C,yDAAqD;AACrD,mDAA+C;AAG/C,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAC;AAE9D,MAAa,gBAAgB;IAQ3B,YAAY,MAAsB;QAF1B,mBAAc,GAAY,KAAK,CAAC;QAGtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAE1C,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC;QACxC,CAAC;aAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACxC,IAAI,CAAC,QAAQ,GAAG,IAAI,uBAAc,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC;aAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAC3C,IAAI,CAAC,QAAQ,GAAG,IAAI,6BAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9D,CAAC;aAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,yBAAe,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAA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@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Section } from '../types';
|
|
2
|
+
export declare class SectionParser {
|
|
3
|
+
/**
|
|
4
|
+
* 按指定级别的标题分割文档
|
|
5
|
+
*/
|
|
6
|
+
parseIntoSections(markdown: string, level?: number): Section[];
|
|
7
|
+
/**
|
|
8
|
+
* 将章节重组为 Markdown
|
|
9
|
+
*/
|
|
10
|
+
reconstructFromSections(sections: Section[]): string;
|
|
11
|
+
private isHeading;
|
|
12
|
+
private getHeadingLevel;
|
|
13
|
+
private isImage;
|
|
14
|
+
private isCodeBlockStart;
|
|
15
|
+
private isTableRow;
|
|
16
|
+
private isHorizontalRule;
|
|
17
|
+
private extractCodeBlock;
|
|
18
|
+
private extractTable;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=section-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"section-parser.d.ts","sourceRoot":"","sources":["../../src/core/section-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,UAAU,CAAC;AAEnD,qBAAa,aAAa;IACxB;;OAEG;IACH,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,OAAO,EAAE;IA8GjE;;OAEG;IACH,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM;IAyDpD,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,YAAY;CAcrB"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SectionParser = void 0;
|
|
4
|
+
class SectionParser {
|
|
5
|
+
/**
|
|
6
|
+
* 按指定级别的标题分割文档
|
|
7
|
+
*/
|
|
8
|
+
parseIntoSections(markdown, level = 1) {
|
|
9
|
+
const lines = markdown.split('\n');
|
|
10
|
+
const sections = [];
|
|
11
|
+
let currentSection = null;
|
|
12
|
+
let currentParagraphIndex = -1;
|
|
13
|
+
for (let i = 0; i < lines.length; i++) {
|
|
14
|
+
const line = lines[i];
|
|
15
|
+
// 检测是否是目标级别的标题
|
|
16
|
+
if (this.isHeading(line, level)) {
|
|
17
|
+
// 保存上一个章节
|
|
18
|
+
if (currentSection) {
|
|
19
|
+
sections.push(currentSection);
|
|
20
|
+
}
|
|
21
|
+
// 创建新章节
|
|
22
|
+
currentSection = {
|
|
23
|
+
id: `section-${sections.length}`,
|
|
24
|
+
title: line,
|
|
25
|
+
level: this.getHeadingLevel(line),
|
|
26
|
+
content: [],
|
|
27
|
+
images: [],
|
|
28
|
+
codeBlocks: [],
|
|
29
|
+
tables: [],
|
|
30
|
+
metadata: {
|
|
31
|
+
startLine: i,
|
|
32
|
+
endLine: i,
|
|
33
|
+
wordCount: 0,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
currentParagraphIndex = -1;
|
|
37
|
+
}
|
|
38
|
+
else if (currentSection) {
|
|
39
|
+
// 处理章节内容
|
|
40
|
+
if (this.isImage(line)) {
|
|
41
|
+
// 图片
|
|
42
|
+
currentSection.images.push({
|
|
43
|
+
syntax: line,
|
|
44
|
+
afterParagraph: currentParagraphIndex,
|
|
45
|
+
originalLine: i,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else if (this.isCodeBlockStart(line)) {
|
|
49
|
+
// 代码块
|
|
50
|
+
const { code, endIndex } = this.extractCodeBlock(lines, i);
|
|
51
|
+
currentSection.codeBlocks.push(code);
|
|
52
|
+
i = endIndex;
|
|
53
|
+
}
|
|
54
|
+
else if (this.isTableRow(line)) {
|
|
55
|
+
// 表格
|
|
56
|
+
const { table, endIndex } = this.extractTable(lines, i);
|
|
57
|
+
currentSection.tables.push(table);
|
|
58
|
+
i = endIndex;
|
|
59
|
+
}
|
|
60
|
+
else if (line.trim() && !this.isHorizontalRule(line)) {
|
|
61
|
+
// 普通段落
|
|
62
|
+
if (currentSection.content.length === 0 ||
|
|
63
|
+
lines[i - 1].trim() === '') {
|
|
64
|
+
// 新段落
|
|
65
|
+
currentParagraphIndex++;
|
|
66
|
+
}
|
|
67
|
+
if (!currentSection.content[currentParagraphIndex]) {
|
|
68
|
+
currentSection.content[currentParagraphIndex] = '';
|
|
69
|
+
}
|
|
70
|
+
currentSection.content[currentParagraphIndex] +=
|
|
71
|
+
(currentSection.content[currentParagraphIndex] ? '\n' : '') + line;
|
|
72
|
+
}
|
|
73
|
+
currentSection.metadata.endLine = i;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// 文档开头没有标题的内容,创建一个默认章节
|
|
77
|
+
if (!currentSection && line.trim()) {
|
|
78
|
+
currentSection = {
|
|
79
|
+
id: 'section-intro',
|
|
80
|
+
title: '',
|
|
81
|
+
level: 0,
|
|
82
|
+
content: [],
|
|
83
|
+
images: [],
|
|
84
|
+
codeBlocks: [],
|
|
85
|
+
tables: [],
|
|
86
|
+
metadata: {
|
|
87
|
+
startLine: 0,
|
|
88
|
+
endLine: 0,
|
|
89
|
+
wordCount: 0,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
currentParagraphIndex = -1;
|
|
93
|
+
i--; // 重新处理这一行
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// 保存最后一个章节
|
|
98
|
+
if (currentSection) {
|
|
99
|
+
sections.push(currentSection);
|
|
100
|
+
}
|
|
101
|
+
// 计算字数
|
|
102
|
+
sections.forEach(section => {
|
|
103
|
+
section.metadata.wordCount = section.content
|
|
104
|
+
.join('')
|
|
105
|
+
.replace(/\s/g, '')
|
|
106
|
+
.length;
|
|
107
|
+
});
|
|
108
|
+
return sections;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 将章节重组为 Markdown
|
|
112
|
+
*/
|
|
113
|
+
reconstructFromSections(sections) {
|
|
114
|
+
const result = [];
|
|
115
|
+
for (const section of sections) {
|
|
116
|
+
// 添加标题
|
|
117
|
+
if (section.title) {
|
|
118
|
+
result.push(section.title);
|
|
119
|
+
result.push('');
|
|
120
|
+
}
|
|
121
|
+
// 重建内容,插入图片到合适位置
|
|
122
|
+
const contentParts = [];
|
|
123
|
+
for (let i = 0; i < section.content.length; i++) {
|
|
124
|
+
// 添加段落
|
|
125
|
+
contentParts.push(section.content[i]);
|
|
126
|
+
// 查找这段之后的图片
|
|
127
|
+
const imagesAfter = section.images.filter(img => img.afterParagraph === i);
|
|
128
|
+
if (imagesAfter.length > 0) {
|
|
129
|
+
contentParts.push('');
|
|
130
|
+
imagesAfter.forEach(img => contentParts.push(img.syntax));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// 添加章节开头的图片
|
|
134
|
+
const imagesAtStart = section.images.filter(img => img.afterParagraph === -1);
|
|
135
|
+
if (imagesAtStart.length > 0) {
|
|
136
|
+
imagesAtStart.forEach(img => result.push(img.syntax));
|
|
137
|
+
result.push('');
|
|
138
|
+
}
|
|
139
|
+
result.push(...contentParts);
|
|
140
|
+
// 添加代码块
|
|
141
|
+
if (section.codeBlocks.length > 0) {
|
|
142
|
+
result.push('');
|
|
143
|
+
result.push(...section.codeBlocks);
|
|
144
|
+
}
|
|
145
|
+
// 添加表格
|
|
146
|
+
if (section.tables.length > 0) {
|
|
147
|
+
result.push('');
|
|
148
|
+
result.push(...section.tables);
|
|
149
|
+
}
|
|
150
|
+
result.push('');
|
|
151
|
+
}
|
|
152
|
+
return result.join('\n').trim();
|
|
153
|
+
}
|
|
154
|
+
isHeading(line, targetLevel) {
|
|
155
|
+
const match = line.match(/^(#{1,6})\s/);
|
|
156
|
+
if (!match)
|
|
157
|
+
return false;
|
|
158
|
+
return match[1].length === targetLevel;
|
|
159
|
+
}
|
|
160
|
+
getHeadingLevel(line) {
|
|
161
|
+
const match = line.match(/^(#{1,6})\s/);
|
|
162
|
+
return match ? match[1].length : 0;
|
|
163
|
+
}
|
|
164
|
+
isImage(line) {
|
|
165
|
+
return /^!\[([^\]]*)\]\(([^)]+)\)/.test(line.trim());
|
|
166
|
+
}
|
|
167
|
+
isCodeBlockStart(line) {
|
|
168
|
+
return line.trim().startsWith('```');
|
|
169
|
+
}
|
|
170
|
+
isTableRow(line) {
|
|
171
|
+
return line.trim().startsWith('|');
|
|
172
|
+
}
|
|
173
|
+
isHorizontalRule(line) {
|
|
174
|
+
return /^[\s]*[-*_]{3,}[\s]*$/.test(line);
|
|
175
|
+
}
|
|
176
|
+
extractCodeBlock(lines, start) {
|
|
177
|
+
const codeLines = [lines[start]];
|
|
178
|
+
let i = start + 1;
|
|
179
|
+
while (i < lines.length && !lines[i].trim().startsWith('```')) {
|
|
180
|
+
codeLines.push(lines[i]);
|
|
181
|
+
i++;
|
|
182
|
+
}
|
|
183
|
+
if (i < lines.length) {
|
|
184
|
+
codeLines.push(lines[i]);
|
|
185
|
+
}
|
|
186
|
+
return { code: codeLines.join('\n'), endIndex: i };
|
|
187
|
+
}
|
|
188
|
+
extractTable(lines, start) {
|
|
189
|
+
const tableLines = [lines[start]];
|
|
190
|
+
let i = start + 1;
|
|
191
|
+
while (i < lines.length && this.isTableRow(lines[i])) {
|
|
192
|
+
tableLines.push(lines[i]);
|
|
193
|
+
i++;
|
|
194
|
+
}
|
|
195
|
+
return { table: tableLines.join('\n'), endIndex: i - 1 };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.SectionParser = SectionParser;
|
|
199
|
+
//# sourceMappingURL=section-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"section-parser.js","sourceRoot":"","sources":["../../src/core/section-parser.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IACxB;;OAEG;IACH,iBAAiB,CAAC,QAAgB,EAAE,QAAgB,CAAC;QACnD,MAAM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Result, AIProvider } from '../types';
|
|
2
|
+
export declare class SectionRewriter {
|
|
3
|
+
private parser;
|
|
4
|
+
private provider;
|
|
5
|
+
private verbose;
|
|
6
|
+
constructor(provider: AIProvider, verbose?: boolean);
|
|
7
|
+
rewrite(markdown: string, options: SectionRewriteOptions): Promise<RewriteResult>;
|
|
8
|
+
/**
|
|
9
|
+
* 改写单个章节
|
|
10
|
+
*/
|
|
11
|
+
private rewriteSection;
|
|
12
|
+
/**
|
|
13
|
+
* 构建章节上下文
|
|
14
|
+
*/
|
|
15
|
+
private buildContext;
|
|
16
|
+
/**
|
|
17
|
+
* 构建改写提示
|
|
18
|
+
*/
|
|
19
|
+
private buildPrompt;
|
|
20
|
+
/**
|
|
21
|
+
* 重新分配图片位置
|
|
22
|
+
*/
|
|
23
|
+
private redistributeImages;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=section-rewriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"section-rewriter.d.ts","sourceRoot":"","sources":["../../src/core/section-rewriter.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,qBAAqB,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,UAAU,CAAC;AAErG,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,OAAO,CAAU;gBAEb,QAAQ,EAAE,UAAU,EAAE,OAAO,GAAE,OAAe;IAMpD,OAAO,CACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,aAAa,CAAC;IA2DzB;;OAEG;YACW,cAAc;IAyC5B;;OAEG;IACH,OAAO,CAAC,YAAY;IA8BpB;;OAEG;IACH,OAAO,CAAC,WAAW;IAmCnB;;OAEG;IACH,OAAO,CAAC,kBAAkB;CA4B3B"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SectionRewriter = void 0;
|
|
4
|
+
const section_parser_1 = require("./section-parser");
|
|
5
|
+
class SectionRewriter {
|
|
6
|
+
constructor(provider, verbose = false) {
|
|
7
|
+
this.parser = new section_parser_1.SectionParser();
|
|
8
|
+
this.provider = provider;
|
|
9
|
+
this.verbose = verbose;
|
|
10
|
+
}
|
|
11
|
+
async rewrite(markdown, options) {
|
|
12
|
+
const sectionLevel = options.sectionLevel || 1;
|
|
13
|
+
// 1. 解析章节
|
|
14
|
+
const sections = this.parser.parseIntoSections(markdown, sectionLevel);
|
|
15
|
+
if (this.verbose) {
|
|
16
|
+
console.log(`📚 发现 ${sections.length} 个章节`);
|
|
17
|
+
sections.forEach((s, i) => {
|
|
18
|
+
console.log(` ${i + 1}. ${s.title || '(无标题)'} - ${s.metadata.wordCount}字, ${s.images.length}张图片`);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// 2. 并发改写章节(与 CLI --concurrency 一致)
|
|
22
|
+
const concurrency = Math.max(1, options.concurrency ?? 3);
|
|
23
|
+
let processed = 0;
|
|
24
|
+
for (let i = 0; i < sections.length; i += concurrency) {
|
|
25
|
+
const batch = sections.slice(i, i + concurrency);
|
|
26
|
+
const promises = batch.map(async (section, batchIndex) => {
|
|
27
|
+
const actualIndex = i + batchIndex;
|
|
28
|
+
try {
|
|
29
|
+
// 提供上下文信息
|
|
30
|
+
const context = this.buildContext(sections, actualIndex, options);
|
|
31
|
+
const rewritten = await this.rewriteSection(section, context, options);
|
|
32
|
+
processed++;
|
|
33
|
+
if (this.verbose) {
|
|
34
|
+
console.log(`✅ [${processed}/${sections.length}] 已改写: ${section.title || '(无标题)'}`);
|
|
35
|
+
}
|
|
36
|
+
return rewritten;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (this.verbose) {
|
|
40
|
+
console.error(`❌ 改写失败: ${section.title}`, error.message);
|
|
41
|
+
}
|
|
42
|
+
return section; // 失败时返回原章节
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const results = await Promise.all(promises);
|
|
46
|
+
sections.splice(i, batch.length, ...results);
|
|
47
|
+
}
|
|
48
|
+
// 3. 重组文档
|
|
49
|
+
const rewritten = this.parser.reconstructFromSections(sections);
|
|
50
|
+
return {
|
|
51
|
+
original: markdown,
|
|
52
|
+
rewritten,
|
|
53
|
+
blocksProcessed: sections.length,
|
|
54
|
+
blocksRewritten: processed,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 改写单个章节
|
|
59
|
+
*/
|
|
60
|
+
async rewriteSection(section, context, options) {
|
|
61
|
+
// 只改写文本内容,保留图片、代码、表格
|
|
62
|
+
const contentText = section.content.join('\n\n');
|
|
63
|
+
if (!contentText.trim()) {
|
|
64
|
+
return section; // 空章节不改写
|
|
65
|
+
}
|
|
66
|
+
// 构建改写提示
|
|
67
|
+
const prompt = this.buildPrompt(section, context, options);
|
|
68
|
+
// 调用 AI 改写
|
|
69
|
+
const rewrittenText = await this.provider.rewrite(contentText, {
|
|
70
|
+
...options,
|
|
71
|
+
prompt,
|
|
72
|
+
});
|
|
73
|
+
// 将改写后的文本分段
|
|
74
|
+
const newParagraphs = rewrittenText
|
|
75
|
+
.split(/\n\n+/)
|
|
76
|
+
.filter(p => p.trim());
|
|
77
|
+
// 重新分配图片位置
|
|
78
|
+
const newImages = this.redistributeImages(section.images, section.content.length, newParagraphs.length, options.maintainImageContext);
|
|
79
|
+
return {
|
|
80
|
+
...section,
|
|
81
|
+
content: newParagraphs,
|
|
82
|
+
images: newImages,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 构建章节上下文
|
|
87
|
+
*/
|
|
88
|
+
buildContext(sections, currentIndex, options) {
|
|
89
|
+
if (!options.crossSectionContext) {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
const contextParts = [];
|
|
93
|
+
// 添加上一章节的标题和摘要
|
|
94
|
+
if (currentIndex > 0) {
|
|
95
|
+
const prevSection = sections[currentIndex - 1];
|
|
96
|
+
contextParts.push(`上一章节: ${prevSection.title}`);
|
|
97
|
+
if (prevSection.content.length > 0) {
|
|
98
|
+
const summary = prevSection.content[0].substring(0, 100);
|
|
99
|
+
contextParts.push(`概要: ${summary}...`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// 添加下一章节的标题
|
|
103
|
+
if (currentIndex < sections.length - 1) {
|
|
104
|
+
const nextSection = sections[currentIndex + 1];
|
|
105
|
+
contextParts.push(`下一章节: ${nextSection.title}`);
|
|
106
|
+
}
|
|
107
|
+
return contextParts.join('\n');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 构建改写提示
|
|
111
|
+
*/
|
|
112
|
+
buildPrompt(section, context, options) {
|
|
113
|
+
const parts = [];
|
|
114
|
+
parts.push(`你正在改写文档中的一个章节: ${section.title || '(引言部分)'}`);
|
|
115
|
+
if (context) {
|
|
116
|
+
parts.push(`\n上下文信息:\n${context}`);
|
|
117
|
+
}
|
|
118
|
+
if (section.images.length > 0) {
|
|
119
|
+
parts.push(`\n注意: 这个章节包含 ${section.images.length} 张图片,` +
|
|
120
|
+
`改写后段落数量应该相近,以便图片能合理分布。`);
|
|
121
|
+
}
|
|
122
|
+
parts.push(`\n改写要求:`, `1. 保持章节主题和核心信息`, `2. 段落之间要有自然的衔接和过渡`, `3. 使用统一的语言风格`, `4. 段落数量保持在 ${section.content.length - 1} 到 ${section.content.length + 1} 个之间`);
|
|
123
|
+
if (options.preserveLength) {
|
|
124
|
+
parts.push(`5. 保持与原文相近的长度 (~${section.metadata.wordCount}字)`);
|
|
125
|
+
}
|
|
126
|
+
return parts.join('\n');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 重新分配图片位置
|
|
130
|
+
*/
|
|
131
|
+
redistributeImages(originalImages, originalParagraphs, newParagraphs, maintainContext = true) {
|
|
132
|
+
if (!maintainContext || originalImages.length === 0) {
|
|
133
|
+
return originalImages;
|
|
134
|
+
}
|
|
135
|
+
// 按比例重新分配图片位置
|
|
136
|
+
return originalImages.map(img => {
|
|
137
|
+
const originalPosition = img.afterParagraph;
|
|
138
|
+
if (originalPosition === -1) {
|
|
139
|
+
return img; // 章节开头的图片保持不变
|
|
140
|
+
}
|
|
141
|
+
// 计算新位置(按比例)
|
|
142
|
+
const ratio = newParagraphs / originalParagraphs;
|
|
143
|
+
const newPosition = Math.round(originalPosition * ratio);
|
|
144
|
+
return {
|
|
145
|
+
...img,
|
|
146
|
+
afterParagraph: Math.min(newPosition, newParagraphs - 1),
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.SectionRewriter = SectionRewriter;
|
|
152
|
+
//# sourceMappingURL=section-rewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"section-rewriter.js","sourceRoot":"","sources":["../../src/core/section-rewriter.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,MAAa,eAAe;IAK1B,YAAY,QAAoB,EAAE,UAAmB,KAAK;QACxD,IAAI,CAAC,MAAM,GAAG,IAAI,8BAAa,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO,CACX,QAAgB,EAChB,OAA8B;QAE9B,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC;QAE/C,UAAU;QACV,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAEvE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,SAAS,QAAQ,CAAC,MAAM,MAAM,CAAC,CAAC;YAC5C,QAAQ,CAAC,OAAO,CAAC,CAAC,C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AC;YAE5C,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC5B,OAAO,GAAG,CAAC,CAAC,cAAc;YAC5B,CAAC;YAED,aAAa;YACb,MAAM,KAAK,GAAG,aAAa,GAAG,kBAAkB,CAAC;YACjD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;YAEzD,OAAO;gBACL,GAAG,GAAG;gBACN,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,aAAa,GAAG,CAAC,CAAC;aACzD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA3ND,0CA2NC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { MarkdownRewriter } from './core/rewriter';
|
|
2
|
+
export { MarkdownParser } from './core/parser';
|
|
3
|
+
export { QuotaManager } from './core/quota-manager';
|
|
4
|
+
export { SectionParser } from './core/section-parser';
|
|
5
|
+
export { SectionRewriter } from './core/section-rewriter';
|
|
6
|
+
export { FullRewriter } from './core/full-rewriter';
|
|
7
|
+
export { OpenAIProvider } from './core/providers/openai';
|
|
8
|
+
export { AnthropicProvider } from './core/providers/anthropic';
|
|
9
|
+
export { MinimaxProvider, DEFAULT_MINIMAX_BASE_URL } from './core/providers/minimax';
|
|
10
|
+
export { BaseProvider } from './core/providers/base';
|
|
11
|
+
export * from './types';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,cAAc,SAAS,CAAC"}
|