@avemeva/agent-telegram 0.1.3

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,82 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const os = require('node:os');
6
+
7
+ function run(target) {
8
+ const result = require('node:child_process').spawnSync(target, process.argv.slice(2), {
9
+ stdio: 'inherit',
10
+ });
11
+ if (result.error) {
12
+ console.error(result.error.message);
13
+ process.exit(1);
14
+ }
15
+ process.exit(typeof result.status === 'number' ? result.status : 0);
16
+ }
17
+
18
+ // Allow override via environment variable
19
+ const envPath = process.env.TG_BIN_PATH;
20
+ if (envPath) {
21
+ run(envPath);
22
+ }
23
+
24
+ const scriptDir = path.dirname(fs.realpathSync(__filename));
25
+
26
+ // Check for cached hardlink from postinstall
27
+ const cached = path.join(scriptDir, '.tg');
28
+ if (fs.existsSync(cached)) {
29
+ run(cached);
30
+ }
31
+
32
+ // Platform/arch detection
33
+ const platformMap = {
34
+ darwin: 'darwin',
35
+ linux: 'linux',
36
+ win32: 'win32',
37
+ };
38
+ const archMap = {
39
+ x64: 'x64',
40
+ arm64: 'arm64',
41
+ };
42
+
43
+ const platform = platformMap[os.platform()];
44
+ const arch = archMap[os.arch()];
45
+
46
+ if (!platform || !arch) {
47
+ console.error(
48
+ `Unsupported platform: ${os.platform()}-${os.arch()}\n` +
49
+ 'agent-telegram supports: darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-x64',
50
+ );
51
+ process.exit(1);
52
+ }
53
+
54
+ const packageName = `@avemeva/agent-telegram-${platform}-${arch}`;
55
+ const binary = platform === 'win32' ? 'agent-telegram.exe' : 'agent-telegram';
56
+
57
+ // Walk up from script directory to find node_modules
58
+ function findBinary(startDir) {
59
+ let current = startDir;
60
+ for (;;) {
61
+ const candidate = path.join(current, 'node_modules', packageName, 'bin', binary);
62
+ if (fs.existsSync(candidate)) return candidate;
63
+
64
+ const parent = path.dirname(current);
65
+ if (parent === current) return null;
66
+ current = parent;
67
+ }
68
+ }
69
+
70
+ const resolved = findBinary(scriptDir);
71
+ if (!resolved) {
72
+ console.error(
73
+ `Could not find the "${packageName}" package.\n\n` +
74
+ 'Your package manager may have failed to install the platform-specific binary.\n' +
75
+ 'Try reinstalling: npm i -g @avemeva/agent-telegram\n\n' +
76
+ `If your platform (${os.platform()}-${os.arch()}) is not supported, ` +
77
+ 'see https://github.com/avemeva/kurier for alternatives.',
78
+ );
79
+ process.exit(1);
80
+ }
81
+
82
+ run(resolved);
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@avemeva/agent-telegram",
3
+ "version": "0.1.3",
4
+ "description": "AI-powered Telegram CLI",
5
+ "bin": {
6
+ "agent-telegram": "./bin/agent-telegram.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node ./postinstall.mjs"
10
+ },
11
+ "optionalDependencies": {
12
+ "@avemeva/agent-telegram-win32-x64": "0.1.3",
13
+ "@avemeva/agent-telegram-darwin-arm64": "0.1.3",
14
+ "@avemeva/agent-telegram-linux-x64": "0.1.3"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/avemeva/kurier"
20
+ }
21
+ }
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const require = createRequire(import.meta.url);
11
+
12
+ try {
13
+ const platformMap = { darwin: 'darwin', linux: 'linux', win32: 'win32' };
14
+ const archMap = { x64: 'x64', arm64: 'arm64' };
15
+
16
+ const platform = platformMap[os.platform()];
17
+ const arch = archMap[os.arch()];
18
+
19
+ if (!platform || !arch) {
20
+ console.log(`tg: no prebuilt binary for ${os.platform()}-${os.arch()}`);
21
+ process.exit(0);
22
+ }
23
+
24
+ const packageName = `@avemeva/agent-telegram-${platform}-${arch}`;
25
+ const binaryName = platform === 'win32' ? 'agent-telegram.exe' : 'agent-telegram';
26
+
27
+ // Find the platform package binary via require.resolve
28
+ let binaryPath;
29
+ try {
30
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
31
+ binaryPath = path.join(path.dirname(packageJsonPath), 'bin', binaryName);
32
+ } catch {
33
+ console.log(`tg: platform package "${packageName}" not installed, skipping`);
34
+ process.exit(0);
35
+ }
36
+
37
+ if (!fs.existsSync(binaryPath)) {
38
+ console.log(`tg: binary not found at ${binaryPath}, skipping`);
39
+ process.exit(0);
40
+ }
41
+
42
+ // Create hardlink at bin/.tg so the wrapper can exec it directly
43
+ // In the published agent-telegram package, postinstall.mjs and bin/ are siblings at root
44
+ const binDir = path.join(__dirname, 'bin');
45
+ const target = path.join(binDir, '.tg');
46
+
47
+ if (!fs.existsSync(binDir)) {
48
+ fs.mkdirSync(binDir, { recursive: true });
49
+ }
50
+
51
+ if (fs.existsSync(target)) {
52
+ fs.unlinkSync(target);
53
+ }
54
+
55
+ try {
56
+ fs.linkSync(binaryPath, target);
57
+ } catch {
58
+ // Hardlink failed (cross-device), fall back to copy
59
+ fs.copyFileSync(binaryPath, target);
60
+ }
61
+
62
+ if (platform !== 'win32') {
63
+ fs.chmodSync(target, 0o755);
64
+ }
65
+
66
+ console.log(`tg: binary linked for ${platform}-${arch}`);
67
+
68
+ // Copy libtdjson to ~/.local/lib/agent-telegram/ so the daemon can find it
69
+ const libSrcDir = path.join(path.dirname(binaryPath), '..', 'lib');
70
+ const tdjsonNames = { darwin: 'libtdjson.dylib', linux: 'libtdjson.so', win32: 'tdjson.dll' };
71
+ const tdjsonName = tdjsonNames[platform];
72
+
73
+ if (tdjsonName) {
74
+ const tdjsonSrc = path.join(libSrcDir, tdjsonName);
75
+ if (fs.existsSync(tdjsonSrc)) {
76
+ const libDestDir =
77
+ platform === 'win32'
78
+ ? path.join(
79
+ process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local'),
80
+ 'agent-telegram',
81
+ 'lib',
82
+ )
83
+ : path.join(os.homedir(), '.local', 'lib', 'agent-telegram');
84
+ fs.mkdirSync(libDestDir, { recursive: true });
85
+ const tdjsonDest = path.join(libDestDir, tdjsonName);
86
+ try {
87
+ fs.copyFileSync(tdjsonSrc, tdjsonDest);
88
+ console.log(`tg: tdjson installed to ${libDestDir}`);
89
+ } catch (e) {
90
+ console.log(`tg: could not copy tdjson (${e.message})`);
91
+ }
92
+ }
93
+ }
94
+ } catch (error) {
95
+ // Postinstall must never fail the install
96
+ console.log(`tg: postinstall skipped (${error.message})`);
97
+ process.exit(0);
98
+ }