apteva 0.4.30 → 0.4.31

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/bin/apteva.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { spawn } from "child_process";
3
+ import { spawn, execFileSync } from "child_process";
4
+ import { createRequire } from "module";
4
5
  import { fileURLToPath } from "url";
5
6
  import { dirname, join } from "path";
6
- import { existsSync } from "fs";
7
+ import { existsSync, readFileSync } from "fs";
7
8
 
8
9
  const __filename = fileURLToPath(import.meta.url);
9
10
  const __dirname = dirname(__filename);
11
+ const require = createRequire(import.meta.url);
10
12
 
11
13
  // Parse command line arguments
12
14
  const args = process.argv.slice(2);
@@ -32,8 +34,9 @@ for (let i = 0; i < args.length; i++) {
32
34
  }
33
35
 
34
36
  if (showVersion) {
35
- const pkg = await import("../package.json", { assert: { type: "json" } });
36
- console.log(`apteva v${pkg.default.version}`);
37
+ const pkgPath = join(__dirname, "..", "package.json");
38
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
39
+ console.log(`apteva v${pkg.version}`);
37
40
  process.exit(0);
38
41
  }
39
42
 
@@ -82,19 +85,7 @@ DOCUMENTATION:
82
85
  process.exit(0);
83
86
  }
84
87
 
85
- // Find the server entry point
86
- const serverPath = join(__dirname, "..", "src", "server.ts");
87
- const distServerPath = join(__dirname, "..", "dist", "server.js");
88
-
89
- let entryPoint;
90
- if (existsSync(serverPath)) {
91
- entryPoint = serverPath;
92
- } else if (existsSync(distServerPath)) {
93
- entryPoint = distServerPath;
94
- } else {
95
- console.error("Error: Could not find server entry point");
96
- process.exit(1);
97
- }
88
+ // ============ Find the server executable ============
98
89
 
99
90
  // Build environment
100
91
  const env = { ...process.env };
@@ -102,46 +93,104 @@ env.PORT = String(port);
102
93
  if (dataDir) env.DATA_DIR = dataDir;
103
94
  if (configFile) env.CONFIG_FILE = configFile;
104
95
 
105
- // Check if bun is available
106
- const runtime = process.env.BUN_INSTALL ? "bun" : "node";
96
+ // Strategy 1: Compiled platform binary (works without Bun)
97
+ function findCompiledBinary() {
98
+ const platform = { darwin: "darwin", linux: "linux", win32: "win32" }[process.platform];
99
+ const arch = { x64: "x64", arm64: "arm64" }[process.arch];
100
+ if (!platform || !arch) return null;
101
+
102
+ const packageName = `@apteva/apteva-${platform}-${arch}`;
103
+
104
+ // Try require.resolve() first (most reliable for npm-installed packages)
105
+ try {
106
+ const binaryPath = require(packageName);
107
+ if (existsSync(binaryPath)) return binaryPath;
108
+ } catch {
109
+ // Package not installed
110
+ }
111
+
112
+ // Try direct paths in node_modules
113
+ const binaryName = process.platform === "win32" ? "apteva.exe" : "apteva";
114
+ const directPaths = [
115
+ join(__dirname, "..", "node_modules", packageName, binaryName),
116
+ join(__dirname, "..", "..", packageName, binaryName),
117
+ ];
118
+ for (const p of directPaths) {
119
+ if (existsSync(p)) return p;
120
+ }
121
+
122
+ // Try postinstall symlink
123
+ const symlinkPath = join(__dirname, process.platform === "win32" ? "apteva-server.exe" : "apteva-server");
124
+ if (existsSync(symlinkPath)) return symlinkPath;
125
+
126
+ return null;
127
+ }
128
+
129
+ // Strategy 2: Source mode with Bun
130
+ function findSourceEntry() {
131
+ const serverPath = join(__dirname, "..", "src", "server.ts");
132
+ if (existsSync(serverPath)) return serverPath;
133
+ return null;
134
+ }
135
+
136
+ function hasBun() {
137
+ try {
138
+ execFileSync("bun", ["--version"], { stdio: "ignore" });
139
+ return true;
140
+ } catch {
141
+ return false;
142
+ }
143
+ }
107
144
 
108
- // Build args - use --silent for bun to suppress "Started development server" message
109
- const runtimeArgs = runtime === "bun" ? ["--silent", entryPoint] : [entryPoint];
145
+ // Try compiled binary first
146
+ const compiledBinary = findCompiledBinary();
147
+ if (compiledBinary) {
148
+ // Run the compiled binary directly — no Bun needed
149
+ const child = spawn(compiledBinary, [], {
150
+ env,
151
+ stdio: "inherit",
152
+ shell: false,
153
+ });
154
+
155
+ child.on("error", (err) => {
156
+ console.error("Error starting apteva:", err.message);
157
+ process.exit(1);
158
+ });
110
159
 
111
- // Spawn the server
112
- const child = spawn(runtime, runtimeArgs, {
113
- env,
114
- stdio: "inherit",
115
- shell: false,
116
- });
160
+ child.on("exit", (code) => process.exit(code || 0));
161
+ process.on("SIGINT", () => child.kill("SIGINT"));
162
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
163
+ } else {
164
+ // Fall back to source mode
165
+ const sourceEntry = findSourceEntry();
117
166
 
118
- child.on("error", (err) => {
119
- if (err.code === "ENOENT" && runtime === "bun") {
120
- // Fallback to node if bun not found
121
- const nodeChild = spawn("node", [entryPoint], {
167
+ if (sourceEntry && hasBun()) {
168
+ // Run with Bun (development mode)
169
+ const child = spawn("bun", ["--silent", sourceEntry], {
122
170
  env,
123
171
  stdio: "inherit",
124
172
  shell: false,
125
173
  });
126
- nodeChild.on("error", (nodeErr) => {
127
- console.error("Error starting server:", nodeErr.message);
174
+
175
+ child.on("error", (err) => {
176
+ console.error("Error starting apteva:", err.message);
128
177
  process.exit(1);
129
178
  });
179
+
180
+ child.on("exit", (code) => process.exit(code || 0));
181
+ process.on("SIGINT", () => child.kill("SIGINT"));
182
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
130
183
  } else {
131
- console.error("Error starting server:", err.message);
184
+ // No binary, no Bun — show helpful error
185
+ console.error("Error: Could not find apteva binary for your platform.");
186
+ console.error("");
187
+ console.error("Options:");
188
+ console.error(" 1. Install Bun (recommended for development):");
189
+ console.error(" curl -fsSL https://bun.sh/install | bash # macOS/Linux");
190
+ console.error(" powershell -c \"irm bun.sh/install.ps1 | iex\" # Windows");
191
+ console.error("");
192
+ console.error(" 2. Reinstall apteva (to get the platform binary):");
193
+ console.error(" npm install -g apteva");
132
194
  process.exit(1);
133
195
  }
134
- });
135
-
136
- child.on("exit", (code) => {
137
- process.exit(code || 0);
138
- });
139
-
140
- // Handle termination
141
- process.on("SIGINT", () => {
142
- child.kill("SIGINT");
143
- });
144
-
145
- process.on("SIGTERM", () => {
146
- child.kill("SIGTERM");
147
- });
196
+ }
package/dist/icon.png ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apteva",
3
- "version": "0.4.30",
3
+ "version": "0.4.31",
4
4
  "description": "Run AI agents locally. Multi-provider support for Claude, GPT, Gemini, Llama, and more.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,15 +12,20 @@
12
12
  "dev": "bun run --watch src/server.ts",
13
13
  "build": "bun run build.ts",
14
14
  "build:cli": "bun build ./src/cli.ts --outdir ./dist --target node",
15
+ "compile": "bun run build && bun run scripts/compile.ts",
16
+ "compile:single": "bun run build && bun run scripts/compile.ts --single",
15
17
  "start": "bun run src/server.ts",
16
18
  "tui": "bun run src/tui/index.tsx",
19
+ "postinstall": "node scripts/postinstall.mjs",
17
20
  "prepublishOnly": "bun run build"
18
21
  },
19
22
  "files": [
20
23
  "bin/apteva.js",
24
+ "scripts/postinstall.mjs",
21
25
  "dist/*.js",
22
26
  "dist/*.css",
23
27
  "dist/*.html",
28
+ "dist/*.png",
24
29
  "src",
25
30
  "LICENSE",
26
31
  "README.md"
@@ -70,6 +75,11 @@
70
75
  "react-dom": "19"
71
76
  },
72
77
  "optionalDependencies": {
78
+ "@apteva/apteva-darwin-arm64": "0.4.31",
79
+ "@apteva/apteva-darwin-x64": "0.4.31",
80
+ "@apteva/apteva-linux-arm64": "0.4.31",
81
+ "@apteva/apteva-linux-x64": "0.4.31",
82
+ "@apteva/apteva-win32-x64": "0.4.31",
73
83
  "@apteva/agent-darwin-arm64": "^1.33.73",
74
84
  "@apteva/agent-darwin-x64": "^1.33.73",
75
85
  "@apteva/agent-linux-arm64": "^1.33.73",
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Postinstall script for apteva npm package.
4
+ * Detects platform and creates a symlink to the compiled binary
5
+ * from the matching @apteva/apteva-{platform}-{arch} package.
6
+ *
7
+ * This runs with plain Node.js — no Bun required.
8
+ */
9
+
10
+ import { existsSync, symlinkSync, unlinkSync, mkdirSync, copyFileSync, chmodSync } from "fs";
11
+ import { join, dirname } from "path";
12
+ import { fileURLToPath } from "url";
13
+ import { createRequire } from "module";
14
+
15
+ const __dirname = dirname(fileURLToPath(import.meta.url));
16
+ const ROOT = join(__dirname, "..");
17
+ const BIN_DIR = join(ROOT, "bin");
18
+ const require = createRequire(import.meta.url);
19
+
20
+ // Map Node.js platform/arch to our package naming
21
+ const PLATFORM_MAP = {
22
+ darwin: "darwin",
23
+ linux: "linux",
24
+ win32: "win32",
25
+ };
26
+
27
+ const ARCH_MAP = {
28
+ x64: "x64",
29
+ arm64: "arm64",
30
+ };
31
+
32
+ function main() {
33
+ const platform = PLATFORM_MAP[process.platform];
34
+ const arch = ARCH_MAP[process.arch];
35
+
36
+ if (!platform || !arch) {
37
+ console.log(`apteva: No binary available for ${process.platform}-${process.arch}`);
38
+ console.log("apteva: You can still run with Bun: bun apteva");
39
+ process.exit(0);
40
+ }
41
+
42
+ const packageName = `@apteva/apteva-${platform}-${arch}`;
43
+
44
+ // Try to find the platform binary package
45
+ let binaryPath;
46
+ try {
47
+ binaryPath = require(packageName);
48
+ } catch {
49
+ // Package not installed (npm skips optionalDeps that don't match platform)
50
+ // Also try direct path resolution
51
+ const directPaths = [
52
+ join(ROOT, "node_modules", packageName, platform === "win32" ? "apteva.exe" : "apteva"),
53
+ join(ROOT, "..", packageName, platform === "win32" ? "apteva.exe" : "apteva"),
54
+ ];
55
+
56
+ for (const p of directPaths) {
57
+ if (existsSync(p)) {
58
+ binaryPath = p;
59
+ break;
60
+ }
61
+ }
62
+ }
63
+
64
+ if (!binaryPath || !existsSync(binaryPath)) {
65
+ // No compiled binary — that's OK, user can run with Bun
66
+ process.exit(0);
67
+ }
68
+
69
+ // Ensure bin directory exists
70
+ mkdirSync(BIN_DIR, { recursive: true });
71
+
72
+ const targetName = process.platform === "win32" ? "apteva-server.exe" : "apteva-server";
73
+ const targetPath = join(BIN_DIR, targetName);
74
+
75
+ // Remove existing link/file
76
+ try {
77
+ unlinkSync(targetPath);
78
+ } catch {
79
+ // Doesn't exist, that's fine
80
+ }
81
+
82
+ // Create symlink (or copy on Windows)
83
+ try {
84
+ if (process.platform === "win32") {
85
+ copyFileSync(binaryPath, targetPath);
86
+ } else {
87
+ symlinkSync(binaryPath, targetPath);
88
+ chmodSync(binaryPath, 0o755);
89
+ }
90
+ } catch (err) {
91
+ // Symlink may fail on some systems — try copy as fallback
92
+ try {
93
+ copyFileSync(binaryPath, targetPath);
94
+ chmodSync(targetPath, 0o755);
95
+ } catch {
96
+ // Silent fail — bin/apteva.js will find the binary via require() at runtime
97
+ process.exit(0);
98
+ }
99
+ }
100
+ }
101
+
102
+ main();
@@ -1,11 +1,12 @@
1
1
  import { join } from "path";
2
2
  import { existsSync, statSync } from "fs";
3
3
 
4
- // Find dist directory - handle both development and npx contexts
4
+ // Find dist directory - handle development, npx, and compiled binary contexts
5
5
  function findDistDir(): string {
6
6
  const candidates = [
7
7
  join(import.meta.dir, "../../dist"),
8
8
  join(import.meta.dir, "../dist"),
9
+ join(import.meta.dir, "dist"), // compiled binary: dist/ alongside the executable
9
10
  join(process.cwd(), "dist"),
10
11
  ];
11
12