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
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.BaseProvider = exports.DEFAULT_MINIMAX_BASE_URL = exports.MinimaxProvider = exports.AnthropicProvider = exports.OpenAIProvider = exports.FullRewriter = exports.SectionRewriter = exports.SectionParser = exports.QuotaManager = exports.MarkdownParser = exports.MarkdownRewriter = void 0;
|
|
18
|
+
var rewriter_1 = require("./core/rewriter");
|
|
19
|
+
Object.defineProperty(exports, "MarkdownRewriter", { enumerable: true, get: function () { return rewriter_1.MarkdownRewriter; } });
|
|
20
|
+
var parser_1 = require("./core/parser");
|
|
21
|
+
Object.defineProperty(exports, "MarkdownParser", { enumerable: true, get: function () { return parser_1.MarkdownParser; } });
|
|
22
|
+
var quota_manager_1 = require("./core/quota-manager");
|
|
23
|
+
Object.defineProperty(exports, "QuotaManager", { enumerable: true, get: function () { return quota_manager_1.QuotaManager; } });
|
|
24
|
+
var section_parser_1 = require("./core/section-parser");
|
|
25
|
+
Object.defineProperty(exports, "SectionParser", { enumerable: true, get: function () { return section_parser_1.SectionParser; } });
|
|
26
|
+
var section_rewriter_1 = require("./core/section-rewriter");
|
|
27
|
+
Object.defineProperty(exports, "SectionRewriter", { enumerable: true, get: function () { return section_rewriter_1.SectionRewriter; } });
|
|
28
|
+
var full_rewriter_1 = require("./core/full-rewriter");
|
|
29
|
+
Object.defineProperty(exports, "FullRewriter", { enumerable: true, get: function () { return full_rewriter_1.FullRewriter; } });
|
|
30
|
+
var openai_1 = require("./core/providers/openai");
|
|
31
|
+
Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return openai_1.OpenAIProvider; } });
|
|
32
|
+
var anthropic_1 = require("./core/providers/anthropic");
|
|
33
|
+
Object.defineProperty(exports, "AnthropicProvider", { enumerable: true, get: function () { return anthropic_1.AnthropicProvider; } });
|
|
34
|
+
var minimax_1 = require("./core/providers/minimax");
|
|
35
|
+
Object.defineProperty(exports, "MinimaxProvider", { enumerable: true, get: function () { return minimax_1.MinimaxProvider; } });
|
|
36
|
+
Object.defineProperty(exports, "DEFAULT_MINIMAX_BASE_URL", { enumerable: true, get: function () { return minimax_1.DEFAULT_MINIMAX_BASE_URL; } });
|
|
37
|
+
var base_1 = require("./core/providers/base");
|
|
38
|
+
Object.defineProperty(exports, "BaseProvider", { enumerable: true, get: function () { return base_1.BaseProvider; } });
|
|
39
|
+
__exportStar(require("./types"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAmD;AAA1C,4GAAA,gBAAgB,OAAA;AACzB,wCAA+C;AAAtC,wGAAA,cAAc,OAAA;AACvB,sDAAoD;AAA3C,6GAAA,YAAY,OAAA;AACrB,wDAAsD;AAA7C,+GAAA,aAAa,OAAA;AACtB,4DAA0D;AAAjD,mHAAA,eAAe,OAAA;AACxB,sDAAoD;AAA3C,6GAAA,YAAY,OAAA;AACrB,kDAAyD;AAAhD,wGAAA,cAAc,OAAA;AACvB,wDAA+D;AAAtD,8GAAA,iBAAiB,OAAA;AAC1B,oDAAqF;AAA5E,0GAAA,eAAe,OAAA;AAAE,mHAAA,wBAAwB,OAAA;AAClD,8CAAqD;AAA5C,oGAAA,YAAY,OAAA;AACrB,0CAAwB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export interface MarkdownBlock {
|
|
2
|
+
type: 'heading' | 'paragraph' | 'list' | 'code' | 'blockquote' | 'image' | 'hr' | 'table' | 'html';
|
|
3
|
+
content: string;
|
|
4
|
+
level?: number;
|
|
5
|
+
rewritable: boolean;
|
|
6
|
+
metadata?: {
|
|
7
|
+
textContent?: string;
|
|
8
|
+
items?: string[];
|
|
9
|
+
isOrdered?: boolean;
|
|
10
|
+
language?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface AIProvider {
|
|
14
|
+
name: string;
|
|
15
|
+
rewrite(text: string, options: RewriteOptions): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface RewriteOptions {
|
|
18
|
+
prompt?: string;
|
|
19
|
+
temperature?: number;
|
|
20
|
+
maxTokens?: number;
|
|
21
|
+
style?: 'casual' | 'formal' | 'technical' | 'creative' | 'custom';
|
|
22
|
+
preserveLength?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface RewriterConfig {
|
|
25
|
+
provider: 'openai' | 'anthropic' | 'minimax' | 'custom';
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
model?: string;
|
|
28
|
+
/** MiniMax OpenAI-compatible API base URL(默认读 `MINIMAX_BASE_URL` 或国际区 `https://api.minimax.io/v1`) */
|
|
29
|
+
minimaxBaseUrl?: string;
|
|
30
|
+
options?: RewriteOptions;
|
|
31
|
+
customProvider?: AIProvider;
|
|
32
|
+
verbose?: boolean;
|
|
33
|
+
concurrency?: number;
|
|
34
|
+
useSharedKey?: boolean;
|
|
35
|
+
dailyLimit?: number;
|
|
36
|
+
/** 改写模式:`section`(按标题分章,默认)或 `full`(整篇一次) */
|
|
37
|
+
mode?: 'section' | 'full';
|
|
38
|
+
sectionLevel?: 1 | 2 | 3;
|
|
39
|
+
}
|
|
40
|
+
export interface RewriteResult {
|
|
41
|
+
original: string;
|
|
42
|
+
rewritten: string;
|
|
43
|
+
blocksProcessed: number;
|
|
44
|
+
blocksRewritten: number;
|
|
45
|
+
tokensUsed?: number;
|
|
46
|
+
cost?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface Section {
|
|
49
|
+
id: string;
|
|
50
|
+
title: string;
|
|
51
|
+
level: number;
|
|
52
|
+
content: string[];
|
|
53
|
+
images: ImagePlacement[];
|
|
54
|
+
codeBlocks: string[];
|
|
55
|
+
tables: string[];
|
|
56
|
+
metadata: {
|
|
57
|
+
startLine: number;
|
|
58
|
+
endLine: number;
|
|
59
|
+
wordCount: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface ImagePlacement {
|
|
63
|
+
syntax: string;
|
|
64
|
+
afterParagraph: number;
|
|
65
|
+
originalLine: number;
|
|
66
|
+
}
|
|
67
|
+
export interface SectionRewriteOptions extends RewriteOptions {
|
|
68
|
+
sectionLevel?: 1 | 2 | 3;
|
|
69
|
+
maintainImageContext?: boolean;
|
|
70
|
+
crossSectionContext?: boolean;
|
|
71
|
+
/** 并发改写章节数,默认 3 */
|
|
72
|
+
concurrency?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface ImageAnchor {
|
|
75
|
+
id: string;
|
|
76
|
+
syntax: string;
|
|
77
|
+
placeholder: string;
|
|
78
|
+
contextBefore: string;
|
|
79
|
+
contextAfter: string;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC;IACnG,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE;QACT,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC;IAClE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxD,MAAM,CAAC,EAAE,MAAM,C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GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAGD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-ai-rewriter",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "AI-powered Markdown content rewriter that preserves document structure",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"markdown-ai-rewrite": "./dist/cli.js",
|
|
9
|
+
"md-rewrite": "./dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"prepublishOnly": "npm run build",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"test": "jest --passWithNoTests",
|
|
21
|
+
"example": "ts-node examples/basic.ts"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"markdown",
|
|
25
|
+
"ai",
|
|
26
|
+
"rewriter",
|
|
27
|
+
"openai",
|
|
28
|
+
"anthropic",
|
|
29
|
+
"minimax",
|
|
30
|
+
"content",
|
|
31
|
+
"nlp"
|
|
32
|
+
],
|
|
33
|
+
"author": "Ping Si <sipingme@gmail.com>",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/sipingme/markdown-ai-rewriter.git"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/jest": "^29.5.0",
|
|
41
|
+
"@types/node": "^20.0.0",
|
|
42
|
+
"jest": "^29.5.0",
|
|
43
|
+
"ts-jest": "^29.1.0",
|
|
44
|
+
"ts-node": "^10.9.0",
|
|
45
|
+
"typescript": "^5.0.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"chalk": "^5.3.0",
|
|
49
|
+
"commander": "^12.0.0",
|
|
50
|
+
"ora": "^8.0.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@anthropic-ai/sdk": "^0.20.9",
|
|
54
|
+
"openai": "^4.104.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"openai": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"@anthropic-ai/sdk": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|