@chathost/mcp-uat 1.0.7 → 1.0.9

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.
Files changed (3) hide show
  1. package/env.json +4 -0
  2. package/package.json +9 -6
  3. package/postinstall.js +109 -0
package/env.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "apiUrl": "https://api-uat.chathost.io",
3
+ "websiteUrl": "https://uat.chathost.io"
4
+ }
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@chathost/mcp-uat",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "chathost.io MCP server - deploy websites from your AI agent",
5
5
  "bin": { "chathost-mcp": "index.js" },
6
+ "scripts": {
7
+ "postinstall": "node postinstall.js"
8
+ },
6
9
  "optionalDependencies": {
7
- "@chathost/mcp-uat-linux-x64": "1.0.7",
8
- "@chathost/mcp-uat-darwin-arm64": "1.0.7",
9
- "@chathost/mcp-uat-darwin-x64": "1.0.7",
10
- "@chathost/mcp-uat-win-x64": "1.0.7"
10
+ "@chathost/mcp-uat-linux-x64": "1.0.9",
11
+ "@chathost/mcp-uat-darwin-arm64": "1.0.9",
12
+ "@chathost/mcp-uat-darwin-x64": "1.0.9",
13
+ "@chathost/mcp-uat-win-x64": "1.0.9"
11
14
  },
12
- "files": ["index.js", "README.md", "server.json"],
15
+ "files": ["index.js", "postinstall.js", "env.json", "README.md", "server.json"],
13
16
  "license": "MIT",
14
17
  "repository": { "type": "git", "url": "https://github.com/chathost/mcp" }
15
18
  }
package/postinstall.js ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /**
5
+ * postinstall script for @chathost/mcp[-dev|-uat]
6
+ *
7
+ * When a user runs `npm i @chathost/mcp-dev` (or mcp / mcp-uat), this script:
8
+ *
9
+ * 1. Creates the ~/.chathost directory tree (bin, cache, logs, img-state)
10
+ * 2. Copies the platform binary to ~/.chathost/bin/chathost
11
+ * 3. Writes ~/.chathost/env (API + website URLs for the environment)
12
+ */
13
+
14
+ const fs = require("fs");
15
+ const path = require("path");
16
+ const os = require("os");
17
+
18
+ // --- Skip in CI environments (no need for local setup) ---
19
+ if (process.env.CI === "true" || process.env.CI === "1") {
20
+ process.exit(0);
21
+ }
22
+
23
+ // --- Load own package info ---
24
+ const ownPkg = require("./package.json");
25
+ const pkgName = ownPkg.name;
26
+
27
+ // --- Platform detection ---
28
+ const PLATFORMS = {
29
+ "linux-x64": { suffix: "linux-x64", bin: "chathost" },
30
+ "darwin-arm64": { suffix: "darwin-arm64", bin: "chathost" },
31
+ "darwin-x64": { suffix: "darwin-x64", bin: "chathost" },
32
+ "win32-x64": { suffix: "win-x64", bin: "chathost.exe" },
33
+ };
34
+
35
+ const platformKey = `${process.platform}-${process.arch}`;
36
+ const platform = PLATFORMS[platformKey];
37
+ if (!platform) {
38
+ console.log(`chathost: unsupported platform ${platformKey}, skipping setup`);
39
+ process.exit(0);
40
+ }
41
+
42
+ const platformPkg = `${pkgName}-${platform.suffix}`;
43
+
44
+ // --- Locate the native binary inside the platform package ---
45
+ let srcBinary;
46
+ try {
47
+ const pkgJsonPath = require.resolve(`${platformPkg}/package.json`);
48
+ srcBinary = path.join(path.dirname(pkgJsonPath), "bin", platform.bin);
49
+ if (!fs.existsSync(srcBinary)) {
50
+ throw new Error("binary not found");
51
+ }
52
+ } catch {
53
+ console.log(`chathost: platform package ${platformPkg} not available, skipping setup`);
54
+ process.exit(0);
55
+ }
56
+
57
+ // --- Paths ---
58
+ const home = os.homedir();
59
+ const chathostDir = path.join(home, ".chathost");
60
+ const binDir = path.join(chathostDir, "bin");
61
+ const destBinary = path.join(binDir, platform.bin === "chathost.exe" ? "chathost.exe" : "chathost");
62
+
63
+ // ──────────────────────────────────────────────
64
+ // 1. Create ~/.chathost directory structure
65
+ // ──────────────────────────────────────────────
66
+ for (const dir of [
67
+ binDir,
68
+ path.join(chathostDir, "cache", "img"),
69
+ path.join(chathostDir, "logs"),
70
+ path.join(chathostDir, "img-state"),
71
+ ]) {
72
+ fs.mkdirSync(dir, { recursive: true });
73
+ }
74
+
75
+ // ──────────────────────────────────────────────
76
+ // 2. Copy platform binary to ~/.chathost/bin
77
+ // ──────────────────────────────────────────────
78
+ fs.copyFileSync(srcBinary, destBinary);
79
+ if (process.platform !== "win32") {
80
+ fs.chmodSync(destBinary, 0o755);
81
+ }
82
+ console.log(`chathost: binary installed to ${destBinary}`);
83
+
84
+ // ──────────────────────────────────────────────
85
+ // 3. Environment config (~/.chathost/env)
86
+ // env.json is populated by the CI pipeline with
87
+ // the correct API/website URLs for the environment.
88
+ // ──────────────────────────────────────────────
89
+ const envJsonPath = path.join(__dirname, "env.json");
90
+ if (fs.existsSync(envJsonPath)) {
91
+ try {
92
+ const envConfig = JSON.parse(fs.readFileSync(envJsonPath, "utf-8"));
93
+ if (
94
+ envConfig.apiUrl && !envConfig.apiUrl.includes("__") &&
95
+ envConfig.websiteUrl && !envConfig.websiteUrl.includes("__")
96
+ ) {
97
+ const envFile = path.join(chathostDir, "env");
98
+ fs.writeFileSync(envFile, [
99
+ "# chathost.io environment config (auto-generated by npm postinstall)",
100
+ `CHATHOST_API_URL=${envConfig.apiUrl}`,
101
+ `CHATHOST_WEBSITE_URL=${envConfig.websiteUrl}`,
102
+ "",
103
+ ].join("\n"));
104
+ }
105
+ } catch { /* skip on parse error */ }
106
+ }
107
+
108
+ // --- Done ---
109
+ console.log("chathost: setup complete!");