@khiem_enhance/ai-doc-agent 0.1.7 → 0.1.11
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/dist/cli.js +40 -0
- package/dist/commands/doctor.js +48 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
require("dotenv/config");
|
|
5
38
|
const commander_1 = require("commander");
|
|
6
39
|
const generate_1 = require("./commands/generate");
|
|
7
40
|
const program = new commander_1.Command();
|
|
41
|
+
program
|
|
42
|
+
.command("doctor")
|
|
43
|
+
.description("Check environment, OpenAI API key, and rate limits")
|
|
44
|
+
.action(async () => {
|
|
45
|
+
const { runDoctor } = await Promise.resolve().then(() => __importStar(require("./commands/doctor")));
|
|
46
|
+
await runDoctor();
|
|
47
|
+
});
|
|
8
48
|
program
|
|
9
49
|
.name("ai-doc-agent")
|
|
10
50
|
.description("AI-powered documentation generator")
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runDoctor = runDoctor;
|
|
7
|
+
const openai_1 = __importDefault(require("openai"));
|
|
8
|
+
async function runDoctor() {
|
|
9
|
+
console.log("🩺 AI Doc Agent — Doctor\n");
|
|
10
|
+
// ---------- Node & Platform ----------
|
|
11
|
+
console.log(`✔ Node.js version: ${process.version}`);
|
|
12
|
+
console.log(`✔ Platform: ${process.platform} (${process.arch})`);
|
|
13
|
+
// ---------- API Key ----------
|
|
14
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
console.error("\n❌ OPENAI_API_KEY not found");
|
|
17
|
+
console.error("👉 export OPENAI_API_KEY=sk-xxxx\n");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
console.log("✔ OPENAI_API_KEY: detected");
|
|
21
|
+
// ---------- Model ----------
|
|
22
|
+
const model = process.env.MODEL || "gpt-4.1-mini";
|
|
23
|
+
console.log(`✔ Model: ${model}`);
|
|
24
|
+
// ---------- OpenAI connectivity ----------
|
|
25
|
+
console.log("\n🔎 OpenAI connectivity check...");
|
|
26
|
+
try {
|
|
27
|
+
const client = new openai_1.default({ apiKey });
|
|
28
|
+
// cực nhẹ: không sinh token đáng kể
|
|
29
|
+
await client.models.retrieve(model);
|
|
30
|
+
console.log("✔ OpenAI API reachable");
|
|
31
|
+
console.log("✔ Rate limit OK (basic check)");
|
|
32
|
+
console.log("\n✅ Doctor check passed\n");
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
console.error("\n❌ OpenAI API check failed");
|
|
36
|
+
if (err?.status === 401) {
|
|
37
|
+
console.error("👉 Invalid API key");
|
|
38
|
+
}
|
|
39
|
+
else if (err?.status === 429) {
|
|
40
|
+
console.error("👉 Rate limited / quota exceeded");
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error(err?.message || err);
|
|
44
|
+
}
|
|
45
|
+
console.error("\n❌ Doctor check failed\n");
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|