@paytaca/opencode-plugin 0.1.4 → 0.1.5

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/dist/proxy.js CHANGED
@@ -48,10 +48,55 @@ const proxy_1 = require("./bundled/proxy");
48
48
  const wrapper_1 = require("./bundled/wrapper");
49
49
  // Store heartbeat interval reference
50
50
  let heartbeatInterval = null;
51
- // Get path to local paytaca binary
51
+ // Get path to paytaca binary (multi-strategy resolution)
52
52
  function getPaytacaCommand() {
53
+ // Priority 1: Local node_modules (via require.resolve)
54
+ try {
55
+ const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
56
+ return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
57
+ }
58
+ catch { }
59
+ // Priority 2: Local .bin symlink
53
60
  const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
54
- return fs.existsSync(localPaytaca) ? localPaytaca : 'paytaca';
61
+ if (fs.existsSync(localPaytaca)) {
62
+ return localPaytaca;
63
+ }
64
+ // Priority 3: Global npm root
65
+ try {
66
+ const globalRoot = (0, child_process_1.execSync)('npm root -g', { encoding: 'utf8' }).trim();
67
+ const pathsToCheck = [
68
+ path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js'),
69
+ path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js'),
70
+ ];
71
+ for (const p of pathsToCheck) {
72
+ if (fs.existsSync(p)) {
73
+ return p;
74
+ }
75
+ }
76
+ }
77
+ catch { }
78
+ // Priority 4: Common global installation paths
79
+ const commonPaths = [
80
+ '/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
81
+ '/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
82
+ '/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
83
+ ];
84
+ for (const p of commonPaths) {
85
+ if (fs.existsSync(p)) {
86
+ return p;
87
+ }
88
+ }
89
+ // Priority 5: which/where on PATH
90
+ try {
91
+ const which = process.platform === 'win32' ? 'where' : 'which';
92
+ const result = (0, child_process_1.execSync)(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
93
+ if (result) {
94
+ return result;
95
+ }
96
+ }
97
+ catch { }
98
+ // Priority 6: Bare command (rely on PATH at runtime)
99
+ return 'paytaca';
55
100
  }
56
101
  async function isPortAvailable(port) {
57
102
  return new Promise((resolve) => {
package/dist/wallet.js CHANGED
@@ -42,20 +42,65 @@ exports.importWallet = importWallet;
42
42
  exports.extractWalletHash = extractWalletHash;
43
43
  exports.getReceivingAddress = getReceivingAddress;
44
44
  exports.getWalletBalance = getWalletBalance;
45
+ const child_process_1 = require("child_process");
45
46
  const fs = __importStar(require("fs"));
47
+ const os = __importStar(require("os"));
46
48
  const util_1 = require("util");
47
49
  const path = __importStar(require("path"));
48
50
  const execAsync = (0, util_1.promisify)(require('child_process').exec);
51
+ function getGlobalNpmRoot() {
52
+ try {
53
+ return (0, child_process_1.execSync)('npm root -g', { encoding: 'utf8' }).trim();
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
49
59
  function getPaytacaCommand() {
60
+ // Priority 1: Local node_modules (via require.resolve)
50
61
  try {
51
62
  const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
52
63
  return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
53
64
  }
54
65
  catch { }
66
+ // Priority 2: Local .bin symlink
55
67
  const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
56
68
  if (fs.existsSync(localPaytaca)) {
57
69
  return localPaytaca;
58
70
  }
71
+ // Priority 3: Global npm root
72
+ const globalRoot = getGlobalNpmRoot();
73
+ if (globalRoot) {
74
+ const globalPaytaca = path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js');
75
+ if (fs.existsSync(globalPaytaca)) {
76
+ return globalPaytaca;
77
+ }
78
+ const scopedPaytaca = path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js');
79
+ if (fs.existsSync(scopedPaytaca)) {
80
+ return scopedPaytaca;
81
+ }
82
+ }
83
+ // Priority 4: Common global installation paths
84
+ const commonPaths = [
85
+ '/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
86
+ '/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
87
+ '/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
88
+ ];
89
+ for (const p of commonPaths) {
90
+ if (fs.existsSync(p)) {
91
+ return p;
92
+ }
93
+ }
94
+ // Priority 5: which/where on PATH
95
+ try {
96
+ const which = process.platform === 'win32' ? 'where' : 'which';
97
+ const result = (0, child_process_1.execSync)(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
98
+ if (result) {
99
+ return result;
100
+ }
101
+ }
102
+ catch { }
103
+ // Priority 6: Bare command (rely on PATH at runtime)
59
104
  return 'paytaca';
60
105
  }
61
106
  const PAYTACA_CMD = getPaytacaCommand();
@@ -88,19 +133,47 @@ async function checkWallet() {
88
133
  };
89
134
  }
90
135
  }
136
+ function addToPath(dir) {
137
+ if (dir && fs.existsSync(dir) && !process.env.PATH?.includes(dir)) {
138
+ process.env.PATH = `${dir}${path.delimiter}${process.env.PATH}`;
139
+ }
140
+ }
91
141
  function ensurePaytacaOnPath() {
142
+ // Priority 1: Local node_modules .bin dir
92
143
  try {
93
144
  const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
94
145
  const binDir = path.resolve(path.dirname(paytacaCliPkg), '..', '.bin');
95
146
  const paytacaBin = path.join(binDir, 'paytaca');
96
147
  if (fs.existsSync(paytacaBin)) {
97
- if (!process.env.PATH?.includes(binDir)) {
98
- process.env.PATH = `${binDir}${path.delimiter}${process.env.PATH}`;
99
- }
148
+ addToPath(binDir);
100
149
  return binDir;
101
150
  }
102
151
  }
103
152
  catch { }
153
+ // Priority 2: Global npm root .bin dir
154
+ const globalRoot = getGlobalNpmRoot();
155
+ if (globalRoot) {
156
+ const globalBinDir = path.resolve(globalRoot, '..', '.bin');
157
+ const globalPaytaca = path.join(globalBinDir, 'paytaca');
158
+ if (fs.existsSync(globalPaytaca)) {
159
+ addToPath(globalBinDir);
160
+ return globalBinDir;
161
+ }
162
+ }
163
+ // Priority 3: Common global bin directories
164
+ const commonBinDirs = [
165
+ '/usr/local/bin',
166
+ '/usr/bin',
167
+ path.join(os.homedir(), '.npm-global', 'bin'),
168
+ process.env.NVM_BIN,
169
+ ].filter((p) => !!p);
170
+ for (const binDir of commonBinDirs) {
171
+ const paytacaBin = path.join(binDir, 'paytaca');
172
+ if (fs.existsSync(paytacaBin)) {
173
+ addToPath(binDir);
174
+ return binDir;
175
+ }
176
+ }
104
177
  return null;
105
178
  }
106
179
  async function checkPaytacaCli() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paytaca/opencode-plugin",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "OpenCode plugin for Paytaca AI - AI inference provider powered by Bitcoin Cash micropayments",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/proxy.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import { spawn } from 'child_process';
3
+ import { spawn, execSync } from 'child_process';
4
4
  import { Config, ProxyInfo } from './types';
5
5
  import {
6
6
  getConfigDir,
@@ -19,10 +19,57 @@ import { WRAPPER_SCRIPT_CONTENT } from './bundled/wrapper';
19
19
  // Store heartbeat interval reference
20
20
  let heartbeatInterval: NodeJS.Timeout | null = null;
21
21
 
22
- // Get path to local paytaca binary
22
+ // Get path to paytaca binary (multi-strategy resolution)
23
23
  function getPaytacaCommand(): string {
24
+ // Priority 1: Local node_modules (via require.resolve)
25
+ try {
26
+ const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
27
+ return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
28
+ } catch {}
29
+
30
+ // Priority 2: Local .bin symlink
24
31
  const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
25
- return fs.existsSync(localPaytaca) ? localPaytaca : 'paytaca';
32
+ if (fs.existsSync(localPaytaca)) {
33
+ return localPaytaca;
34
+ }
35
+
36
+ // Priority 3: Global npm root
37
+ try {
38
+ const globalRoot = execSync('npm root -g', { encoding: 'utf8' }).trim();
39
+ const pathsToCheck = [
40
+ path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js'),
41
+ path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js'),
42
+ ];
43
+ for (const p of pathsToCheck) {
44
+ if (fs.existsSync(p)) {
45
+ return p;
46
+ }
47
+ }
48
+ } catch {}
49
+
50
+ // Priority 4: Common global installation paths
51
+ const commonPaths = [
52
+ '/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
53
+ '/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
54
+ '/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
55
+ ];
56
+ for (const p of commonPaths) {
57
+ if (fs.existsSync(p)) {
58
+ return p;
59
+ }
60
+ }
61
+
62
+ // Priority 5: which/where on PATH
63
+ try {
64
+ const which = process.platform === 'win32' ? 'where' : 'which';
65
+ const result = execSync(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
66
+ if (result) {
67
+ return result;
68
+ }
69
+ } catch {}
70
+
71
+ // Priority 6: Bare command (rely on PATH at runtime)
72
+ return 'paytaca';
26
73
  }
27
74
 
28
75
  export async function isPortAvailable(port: number): Promise<boolean> {
package/src/wallet.ts CHANGED
@@ -1,22 +1,68 @@
1
- import { spawn } from 'child_process';
1
+ import { spawn, execSync } from 'child_process';
2
2
  import * as fs from 'fs';
3
+ import * as os from 'os';
3
4
  import { promisify } from 'util';
4
5
  import * as path from 'path';
5
6
  import { WalletInfo } from './types';
6
7
 
7
8
  const execAsync = promisify(require('child_process').exec);
8
9
 
10
+ function getGlobalNpmRoot(): string | null {
11
+ try {
12
+ return execSync('npm root -g', { encoding: 'utf8' }).trim();
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+
9
18
  function getPaytacaCommand(): string {
19
+ // Priority 1: Local node_modules (via require.resolve)
10
20
  try {
11
21
  const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
12
22
  return path.resolve(path.dirname(paytacaCliPkg), 'bin', 'paytaca.js');
13
23
  } catch {}
14
24
 
25
+ // Priority 2: Local .bin symlink
15
26
  const localPaytaca = path.join(__dirname, '..', 'node_modules', '.bin', 'paytaca');
16
27
  if (fs.existsSync(localPaytaca)) {
17
28
  return localPaytaca;
18
29
  }
19
30
 
31
+ // Priority 3: Global npm root
32
+ const globalRoot = getGlobalNpmRoot();
33
+ if (globalRoot) {
34
+ const globalPaytaca = path.join(globalRoot, 'paytaca-cli', 'bin', 'paytaca.js');
35
+ if (fs.existsSync(globalPaytaca)) {
36
+ return globalPaytaca;
37
+ }
38
+ const scopedPaytaca = path.join(globalRoot, '@paytaca', 'opencode-plugin', 'node_modules', 'paytaca-cli', 'bin', 'paytaca.js');
39
+ if (fs.existsSync(scopedPaytaca)) {
40
+ return scopedPaytaca;
41
+ }
42
+ }
43
+
44
+ // Priority 4: Common global installation paths
45
+ const commonPaths = [
46
+ '/usr/lib/node_modules/paytaca-cli/bin/paytaca.js',
47
+ '/usr/local/lib/node_modules/paytaca-cli/bin/paytaca.js',
48
+ '/opt/homebrew/lib/node_modules/paytaca-cli/bin/paytaca.js',
49
+ ];
50
+ for (const p of commonPaths) {
51
+ if (fs.existsSync(p)) {
52
+ return p;
53
+ }
54
+ }
55
+
56
+ // Priority 5: which/where on PATH
57
+ try {
58
+ const which = process.platform === 'win32' ? 'where' : 'which';
59
+ const result = execSync(`${which} paytaca`, { encoding: 'utf8' }).trim().split('\n')[0];
60
+ if (result) {
61
+ return result;
62
+ }
63
+ } catch {}
64
+
65
+ // Priority 6: Bare command (rely on PATH at runtime)
20
66
  return 'paytaca';
21
67
  }
22
68
 
@@ -56,18 +102,51 @@ export async function checkWallet(): Promise<WalletInfo> {
56
102
  }
57
103
  }
58
104
 
105
+ function addToPath(dir: string): void {
106
+ if (dir && fs.existsSync(dir) && !process.env.PATH?.includes(dir)) {
107
+ process.env.PATH = `${dir}${path.delimiter}${process.env.PATH}`;
108
+ }
109
+ }
110
+
59
111
  export function ensurePaytacaOnPath(): string | null {
112
+ // Priority 1: Local node_modules .bin dir
60
113
  try {
61
114
  const paytacaCliPkg = require.resolve('paytaca-cli/package.json');
62
115
  const binDir = path.resolve(path.dirname(paytacaCliPkg), '..', '.bin');
63
116
  const paytacaBin = path.join(binDir, 'paytaca');
64
117
  if (fs.existsSync(paytacaBin)) {
65
- if (!process.env.PATH?.includes(binDir)) {
66
- process.env.PATH = `${binDir}${path.delimiter}${process.env.PATH}`;
67
- }
118
+ addToPath(binDir);
68
119
  return binDir;
69
120
  }
70
121
  } catch {}
122
+
123
+ // Priority 2: Global npm root .bin dir
124
+ const globalRoot = getGlobalNpmRoot();
125
+ if (globalRoot) {
126
+ const globalBinDir = path.resolve(globalRoot, '..', '.bin');
127
+ const globalPaytaca = path.join(globalBinDir, 'paytaca');
128
+ if (fs.existsSync(globalPaytaca)) {
129
+ addToPath(globalBinDir);
130
+ return globalBinDir;
131
+ }
132
+ }
133
+
134
+ // Priority 3: Common global bin directories
135
+ const commonBinDirs = [
136
+ '/usr/local/bin',
137
+ '/usr/bin',
138
+ path.join(os.homedir(), '.npm-global', 'bin'),
139
+ process.env.NVM_BIN,
140
+ ].filter((p): p is string => !!p);
141
+
142
+ for (const binDir of commonBinDirs) {
143
+ const paytacaBin = path.join(binDir, 'paytaca');
144
+ if (fs.existsSync(paytacaBin)) {
145
+ addToPath(binDir);
146
+ return binDir;
147
+ }
148
+ }
149
+
71
150
  return null;
72
151
  }
73
152
 
package/dist/package.json DELETED
@@ -1,43 +0,0 @@
1
- {
2
- "name": "@paytaca/opencode-plugin",
3
- "version": "0.1.0",
4
- "description": "OpenCode plugin for Paytaca AI - BCH micropayment provider for DeepSeek V4 Flash",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "engines": {
8
- "node": ">=20.0.0"
9
- },
10
- "scripts": {
11
- "build": "tsc",
12
- "prepare": "npm run build"
13
- },
14
- "keywords": [
15
- "opencode",
16
- "plugin",
17
- "paytaca",
18
- "bch",
19
- "ai",
20
- "provider"
21
- ],
22
- "author": "Paytaca",
23
- "license": "MIT",
24
- "dependencies": {
25
- "@opencode-ai/plugin": "^1.16.0",
26
- "paytaca-cli": "^0.3.2"
27
- },
28
- "devDependencies": {
29
- "@types/node": "^20.0.0",
30
- "typescript": "^5.0.0"
31
- },
32
- "peerDependencies": {
33
- "opencode": ">=1.0.0"
34
- },
35
- "peerDependenciesMeta": {
36
- "opencode": {
37
- "optional": true
38
- }
39
- },
40
- "publishConfig": {
41
- "access": "public"
42
- }
43
- }