chatgpt-webui-mcp 0.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/.env.example +50 -0
- package/INSTALL.md +65 -0
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/deploy/systemd/chatgpt-webui-mcp-sse.sh +16 -0
- package/deploy/systemd/chatgpt-webui-mcp.env.example +28 -0
- package/deploy/systemd/chatgpt-webui-mcp.service +15 -0
- package/dist/chatgpt-webui-client.d.ts +43 -0
- package/dist/chatgpt-webui-client.js +1284 -0
- package/dist/chatgpt-webui-client.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +700 -0
- package/dist/index.js.map +1 -0
- package/dist/self-test.d.ts +1 -0
- package/dist/self-test.js +72 -0
- package/dist/self-test.js.map +1 -0
- package/package.json +50 -0
- package/src/chatgpt-webui-client.ts +1688 -0
- package/src/index.ts +858 -0
- package/src/self-test.ts +86 -0
- package/tsconfig.json +16 -0
package/src/self-test.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ChatgptWebuiClient } from "./chatgpt-webui-client.js";
|
|
2
|
+
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
function readFlagValue(flag: string): string | null {
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const direct = args.find((entry) => entry.startsWith(`${flag}=`));
|
|
8
|
+
if (direct) {
|
|
9
|
+
return direct.slice(flag.length + 1).trim() || null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const idx = args.indexOf(flag);
|
|
13
|
+
if (idx >= 0) {
|
|
14
|
+
const value = String(args[idx + 1] ?? "").trim();
|
|
15
|
+
return value || null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function resolveSessionToken(): Promise<string> {
|
|
22
|
+
const cliToken = readFlagValue("--token");
|
|
23
|
+
if (cliToken) {
|
|
24
|
+
return cliToken;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const envToken = String(process.env.CHATGPT_SESSION_TOKEN ?? "").trim();
|
|
28
|
+
if (envToken) {
|
|
29
|
+
return envToken;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const envTokenFile = String(process.env.CHATGPT_SESSION_TOKEN_FILE ?? "").trim();
|
|
33
|
+
const tokenFile = readFlagValue("--token-file") ?? (envTokenFile || null);
|
|
34
|
+
if (tokenFile) {
|
|
35
|
+
const raw = await readFile(tokenFile, "utf8");
|
|
36
|
+
const fileToken = raw.trim();
|
|
37
|
+
if (fileToken) {
|
|
38
|
+
return fileToken;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new Error(
|
|
43
|
+
"CHATGPT_SESSION_TOKEN is required (env CHATGPT_SESSION_TOKEN, --token, or CHATGPT_SESSION_TOKEN_FILE/--token-file)",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function main(): Promise<void> {
|
|
48
|
+
const token = await resolveSessionToken();
|
|
49
|
+
process.env.CHATGPT_SESSION_TOKEN = token;
|
|
50
|
+
console.log(`[info] token length: ${token.length}`);
|
|
51
|
+
|
|
52
|
+
const client = new ChatgptWebuiClient();
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
const session = await client.getSession();
|
|
56
|
+
const email = session.user?.email ?? "unknown";
|
|
57
|
+
console.log(`[ok] session: ${email}`);
|
|
58
|
+
|
|
59
|
+
const instant = await client.ask({
|
|
60
|
+
prompt: "Reply exactly with SELF_TEST_INSTANT_OK",
|
|
61
|
+
modelMode: "instant",
|
|
62
|
+
waitTimeoutMs: 300000,
|
|
63
|
+
});
|
|
64
|
+
if (!instant.text.includes("SELF_TEST_INSTANT_OK")) {
|
|
65
|
+
throw new Error(`instant_mismatch: ${instant.text.slice(0, 200)}`);
|
|
66
|
+
}
|
|
67
|
+
console.log("[ok] instant");
|
|
68
|
+
|
|
69
|
+
const pro = await client.ask({
|
|
70
|
+
prompt: "Reply exactly with SELF_TEST_PRO_OK",
|
|
71
|
+
modelMode: "pro",
|
|
72
|
+
waitTimeoutMs: 900000,
|
|
73
|
+
});
|
|
74
|
+
if (!pro.text.includes("SELF_TEST_PRO_OK")) {
|
|
75
|
+
throw new Error(`pro_mismatch: ${pro.text.slice(0, 200)}`);
|
|
76
|
+
}
|
|
77
|
+
console.log("[ok] pro");
|
|
78
|
+
} finally {
|
|
79
|
+
client.close();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main().catch((error) => {
|
|
84
|
+
console.error("self-test failed:", error);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"outDir": "dist",
|
|
13
|
+
"rootDir": "src"
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts"]
|
|
16
|
+
}
|