@keychat-io/keychat-openclaw 0.1.8

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.
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * postinstall — download pre-compiled keychat-openclaw binary.
4
+ * Runs automatically after `npm install` / `openclaw plugins install`.
5
+ * Uses native fetch/https — no child_process dependency.
6
+ */
7
+ import { existsSync, mkdirSync, chmodSync, writeFileSync } from "node:fs";
8
+ import { join, dirname } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import https from "node:https";
11
+
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
13
+ const REPO = "keychat-io/keychat-openclaw";
14
+ const BINARY_DIR = join(__dirname, "..", "bridge", "target", "release");
15
+ const BINARY_PATH = join(BINARY_DIR, "keychat-openclaw");
16
+
17
+ if (existsSync(BINARY_PATH)) {
18
+ console.log("[keychat] Binary already exists, skipping download");
19
+ process.exit(0);
20
+ }
21
+
22
+ const platform = process.platform; // darwin, linux
23
+ const arch = process.arch; // arm64, x64
24
+
25
+ const ARTIFACTS = {
26
+ "darwin-arm64": "keychat-openclaw-darwin-arm64",
27
+ "darwin-x64": "keychat-openclaw-darwin-x64",
28
+ "linux-x64": "keychat-openclaw-linux-x64",
29
+ "linux-arm64": "keychat-openclaw-linux-arm64",
30
+ };
31
+
32
+ const artifact = ARTIFACTS[`${platform}-${arch}`];
33
+ if (!artifact) {
34
+ console.warn(`[keychat] No pre-compiled binary for ${platform}-${arch}`);
35
+ console.warn("[keychat] Build from source: cd bridge && cargo build --release");
36
+ process.exit(0); // Don't fail install
37
+ }
38
+
39
+ const url = `https://github.com/${REPO}/releases/latest/download/${artifact}`;
40
+ console.log(`[keychat] Downloading ${artifact}...`);
41
+
42
+ /**
43
+ * Download a URL following redirects, return a Buffer.
44
+ */
45
+ function download(downloadUrl) {
46
+ return new Promise((resolve, reject) => {
47
+ https.get(downloadUrl, (res) => {
48
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
49
+ return download(res.headers.location).then(resolve, reject);
50
+ }
51
+ if (res.statusCode !== 200) {
52
+ return reject(new Error(`HTTP ${res.statusCode}`));
53
+ }
54
+ const chunks = [];
55
+ res.on("data", (chunk) => chunks.push(chunk));
56
+ res.on("end", () => resolve(Buffer.concat(chunks)));
57
+ res.on("error", reject);
58
+ }).on("error", reject);
59
+ });
60
+ }
61
+
62
+ try {
63
+ mkdirSync(BINARY_DIR, { recursive: true });
64
+ const buffer = await download(url);
65
+ writeFileSync(BINARY_PATH, buffer);
66
+ chmodSync(BINARY_PATH, 0o755);
67
+ console.log("[keychat] ✅ Binary installed");
68
+ } catch (err) {
69
+ console.warn(`[keychat] Download failed: ${err.message}`);
70
+ console.warn("[keychat] Build from source: cd bridge && cargo build --release");
71
+ // Don't fail install — user can build manually
72
+ }
73
+
74
+ // Auto-initialize config if channels.keychat not set
75
+ import { readFileSync } from "node:fs";
76
+ import { homedir } from "node:os";
77
+
78
+ const configPath = join(homedir(), ".openclaw", "openclaw.json");
79
+ try {
80
+ let config = {};
81
+ if (existsSync(configPath)) {
82
+ config = JSON.parse(readFileSync(configPath, "utf-8"));
83
+ }
84
+
85
+ if (config.channels?.keychat) {
86
+ console.log("[keychat] Config already contains keychat settings, skipping init");
87
+ } else {
88
+ if (!config.channels) config.channels = {};
89
+ config.channels.keychat = { enabled: true, dmPolicy: "open" };
90
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
91
+ console.log("[keychat] ✅ Config initialized (channels.keychat.enabled = true)");
92
+ console.log("[keychat] Restart gateway to activate: openclaw gateway restart");
93
+ }
94
+ } catch (err) {
95
+ console.warn(`[keychat] Could not auto-configure: ${err.message}`);
96
+ console.warn("[keychat] Run manually: openclaw config set channels.keychat.enabled true");
97
+ }
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+ # Publish @keychat-io/keychat to npm
3
+ # Usage: ./scripts/publish.sh [--dry-run]
4
+
5
+ set -e
6
+ cd "$(dirname "$0")/.."
7
+
8
+ # Load .env
9
+ if [ -f .env ]; then
10
+ export $(grep -v '^#' .env | xargs)
11
+ fi
12
+
13
+ if [ -z "$NPM_TOKEN" ]; then
14
+ echo "❌ NPM_TOKEN not set. Create .env with: NPM_TOKEN=npm_xxxxx"
15
+ exit 1
16
+ fi
17
+
18
+ # Set token for this publish
19
+ echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc.tmp
20
+
21
+ echo "📦 Publishing @keychat-io/keychat v$(node -p "require('./package.json').version")..."
22
+ npm publish --access public --tag latest --userconfig .npmrc.tmp "$@"
23
+
24
+ rm -f .npmrc.tmp
25
+ echo "✅ Published!"