autodocsync 1.0.1 → 1.1.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/bin/index.js +8 -0
- package/package.json +1 -1
- package/src/llm.js +66 -16
package/bin/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
describeEndpointWithMistral,
|
|
14
14
|
summarizeProjectWithMistral,
|
|
15
|
+
generateREADMEWithMistral,
|
|
15
16
|
} from "../src/llm.js";
|
|
16
17
|
import { generateOpenAPI } from "../src/openapi-gen.js";
|
|
17
18
|
|
|
@@ -100,6 +101,13 @@ program
|
|
|
100
101
|
console.log(
|
|
101
102
|
`[docSync] SUCCESS: openapi.json generated at ${path.join(outDir, "openapi.json")}`,
|
|
102
103
|
);
|
|
104
|
+
|
|
105
|
+
console.log("[docSync] Projecting professional README.md with Mistral...");
|
|
106
|
+
const readmeContent = await generateREADMEWithMistral(openApiSpec);
|
|
107
|
+
fs.writeFileSync(path.join(outDir, "README.md"), readmeContent, "utf-8");
|
|
108
|
+
console.log(
|
|
109
|
+
`[docSync] SUCCESS: README.md generated at ${path.join(outDir, "README.md")}`,
|
|
110
|
+
);
|
|
103
111
|
} else {
|
|
104
112
|
console.log(
|
|
105
113
|
"[docSync] Generating openapi.json (without AI enhancement)...",
|
package/package.json
CHANGED
package/src/llm.js
CHANGED
|
@@ -3,19 +3,19 @@ import axios from "axios";
|
|
|
3
3
|
export async function describeEndpointWithMistral(endpoint) {
|
|
4
4
|
const method = endpoint.method.toUpperCase();
|
|
5
5
|
const url = endpoint.url;
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
// Extract the resource from the URL (e.g., /users, /posts, /comments)
|
|
8
8
|
const resourceMatch = url.match(/\/([a-zA-Z]+)(\?|$|\/{1})/);
|
|
9
|
-
const resource = resourceMatch ? resourceMatch[1] :
|
|
10
|
-
|
|
9
|
+
const resource = resourceMatch ? resourceMatch[1] : "resource";
|
|
10
|
+
|
|
11
11
|
try {
|
|
12
12
|
// Try to use Ollama HTTP API
|
|
13
13
|
const prompt = `As a Senior API Architect, generate a highly professional, detailed description for this API endpoint. Explain its purpose and its role in the system. Use industry-standard terminology.\n\nMethod: ${method}\nURL: ${url}\n\nReturn only the description text.`;
|
|
14
|
-
|
|
15
|
-
const response = await axios.post(
|
|
16
|
-
model:
|
|
14
|
+
|
|
15
|
+
const response = await axios.post("http://localhost:11434/api/generate", {
|
|
16
|
+
model: "mistral",
|
|
17
17
|
prompt: prompt,
|
|
18
|
-
stream: false
|
|
18
|
+
stream: false,
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
const data = response.data;
|
|
@@ -30,10 +30,10 @@ export async function describeEndpointWithMistral(endpoint) {
|
|
|
30
30
|
export async function summarizeProjectWithMistral(readme) {
|
|
31
31
|
try {
|
|
32
32
|
const prompt = `Based on this README, generate a brief (1-2 sentences), professional description of this project for API documentation:\n\n${readme.slice(0, 3000)}`;
|
|
33
|
-
const response = await axios.post(
|
|
34
|
-
model:
|
|
33
|
+
const response = await axios.post("http://localhost:11434/api/generate", {
|
|
34
|
+
model: "mistral",
|
|
35
35
|
prompt: prompt,
|
|
36
|
-
stream: false
|
|
36
|
+
stream: false,
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
const data = response.data;
|
|
@@ -44,13 +44,63 @@ export async function summarizeProjectWithMistral(readme) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export async function generateREADMEWithMistral(openApiSpec) {
|
|
48
|
+
try {
|
|
49
|
+
const prompt = `As a Visionary Technical Architect and documentation specialist, generate an "Ultra-Premium" (Vercel/Linear-tier) README.md file for the following API project.
|
|
50
|
+
|
|
51
|
+
Project Name: ${openApiSpec.info.title}
|
|
52
|
+
Project Goal: ${openApiSpec.info.description}
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🏗️ High-Level Structuring Instructions:
|
|
57
|
+
|
|
58
|
+
1. **Header**: Premium title with dynamic-looking badges (License, Node.js version, Tech used).
|
|
59
|
+
2. **The Vision**: A high-impact executive summary and a "The Problem vs. The Solution" section illustrating why this project matters.
|
|
60
|
+
3. **Real-Time Architecture**: Provide a high-quality Mermaid.js diagram illustrating the core logic and flow of the API.
|
|
61
|
+
4. **Premium Feature Grid**: Use a clear, sophisticated layout to list key features with professional, benefit-driven copy.
|
|
62
|
+
5. **Tech Stack**: List all core technologies (Node.js, Express, etc.).
|
|
63
|
+
6. **Interactive API Documentation**: Generate a clean, comprehensive "API Reference" table with Path, Method, and Description.
|
|
64
|
+
7. **The Golden Path (Quick Start)**: A copy-paste ready installation and usage section designed for zero friction.
|
|
65
|
+
8. **Development & Roadmap**: Sections for contributors, including a vision for future improvements.
|
|
66
|
+
9. **Premium Formatting**: Use GitHub-style "Alerts" (> [!TIP], > [!NOTE]) and professional hierarchy throughout.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Technical Context (OpenAPI 3.0):
|
|
71
|
+
${JSON.stringify(openApiSpec, null, 2).slice(0, 6000)}
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
**CRITICAL**: Return ONLY the Markdown content. Do not add conversational text or wrap in code blocks. Make it look better than any standard technical README. Focus on clarity, aesthetics, and developer experience.`;
|
|
76
|
+
|
|
77
|
+
const response = await axios.post("http://localhost:11434/api/generate", {
|
|
78
|
+
model: "mistral",
|
|
79
|
+
prompt: prompt,
|
|
80
|
+
stream: false,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const data = response.data;
|
|
84
|
+
return (
|
|
85
|
+
data.response?.trim() ||
|
|
86
|
+
"# " + openApiSpec.info.title + "\n\nGenerated API documentation."
|
|
87
|
+
);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error("[llm] Failed to generate README:", error.message);
|
|
90
|
+
return "# " + openApiSpec.info.title + "\n\nGenerated API documentation.";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
47
94
|
function generateDefaultDescription(method, resource, url) {
|
|
48
95
|
const descriptions = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
96
|
+
GET: `Retrieves ${resource} data from the server.`,
|
|
97
|
+
POST: `Creates a new ${resource.slice(0, -1) || "resource"} and returns the created object.`,
|
|
98
|
+
PUT: `Updates an existing ${resource.slice(0, -1) || "resource"} with the provided data.`,
|
|
99
|
+
DELETE: `Permanently deletes the specified ${resource.slice(0, -1) || "resource"} from the server.`,
|
|
100
|
+
PATCH: `Partially updates a ${resource.slice(0, -1) || "resource"} with the provided changes.`,
|
|
54
101
|
};
|
|
55
|
-
return
|
|
102
|
+
return (
|
|
103
|
+
descriptions[method] ||
|
|
104
|
+
`Performs a ${method} request to the ${resource} endpoint.`
|
|
105
|
+
);
|
|
56
106
|
}
|