natureco-cli 2.23.29 → 2.23.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.
Files changed (111) hide show
  1. package/README.md +94 -11
  2. package/bin/natureco.js +495 -94
  3. package/package.json +1 -1
  4. package/src/commands/acp.js +39 -0
  5. package/src/commands/admin-rpc.js +302 -0
  6. package/src/commands/agent.js +280 -0
  7. package/src/commands/agents.js +114 -30
  8. package/src/commands/approvals.js +214 -0
  9. package/src/commands/backup.js +124 -0
  10. package/src/commands/bonjour.js +167 -0
  11. package/src/commands/browser.js +815 -0
  12. package/src/commands/capability.js +237 -0
  13. package/src/commands/channels.js +422 -267
  14. package/src/commands/chat.js +5 -8
  15. package/src/commands/clawbot.js +19 -0
  16. package/src/commands/clickclack.js +130 -0
  17. package/src/commands/code.js +3 -2
  18. package/src/commands/commitments.js +148 -0
  19. package/src/commands/completion.js +84 -0
  20. package/src/commands/config.js +219 -30
  21. package/src/commands/configure.js +110 -0
  22. package/src/commands/crestodian.js +92 -0
  23. package/src/commands/cron.js +239 -19
  24. package/src/commands/daemon.js +90 -0
  25. package/src/commands/dashboard.js +47 -374
  26. package/src/commands/device-pair.js +248 -0
  27. package/src/commands/devices.js +137 -0
  28. package/src/commands/directory.js +179 -0
  29. package/src/commands/dns.js +196 -0
  30. package/src/commands/docs.js +136 -0
  31. package/src/commands/doctor.js +143 -492
  32. package/src/commands/exec-policy.js +80 -0
  33. package/src/commands/gateway-server.js +1155 -24
  34. package/src/commands/gateway.js +492 -249
  35. package/src/commands/health.js +148 -0
  36. package/src/commands/help.js +24 -25
  37. package/src/commands/hooks.js +141 -87
  38. package/src/commands/imessage.js +128 -14
  39. package/src/commands/infer.js +1474 -0
  40. package/src/commands/irc.js +64 -15
  41. package/src/commands/logs.js +122 -99
  42. package/src/commands/mattermost.js +114 -12
  43. package/src/commands/mcp.js +121 -309
  44. package/src/commands/memory-cmd.js +134 -1
  45. package/src/commands/memory.js +128 -0
  46. package/src/commands/message.js +720 -134
  47. package/src/commands/migrate.js +213 -2
  48. package/src/commands/models.js +39 -1
  49. package/src/commands/node.js +98 -0
  50. package/src/commands/nodes.js +362 -0
  51. package/src/commands/oc-path.js +200 -0
  52. package/src/commands/onboard.js +129 -0
  53. package/src/commands/open-prose.js +67 -0
  54. package/src/commands/pairing.js +108 -107
  55. package/src/commands/path.js +206 -0
  56. package/src/commands/plugins.js +35 -1
  57. package/src/commands/policy.js +176 -0
  58. package/src/commands/proxy.js +306 -0
  59. package/src/commands/qr.js +70 -0
  60. package/src/commands/reset.js +101 -94
  61. package/src/commands/sandbox.js +125 -0
  62. package/src/commands/secrets.js +201 -0
  63. package/src/commands/sessions.js +110 -51
  64. package/src/commands/setup.js +102 -543
  65. package/src/commands/signal.js +447 -18
  66. package/src/commands/skills.js +67 -1
  67. package/src/commands/sms.js +123 -19
  68. package/src/commands/status.js +101 -127
  69. package/src/commands/system.js +53 -0
  70. package/src/commands/tasks.js +208 -100
  71. package/src/commands/terminal.js +139 -0
  72. package/src/commands/thread-ownership.js +157 -0
  73. package/src/commands/transcripts.js +95 -0
  74. package/src/commands/tui.js +41 -0
  75. package/src/commands/uninstall.js +73 -92
  76. package/src/commands/update.js +146 -91
  77. package/src/commands/voice.js +82 -0
  78. package/src/commands/vydra.js +98 -0
  79. package/src/commands/webhooks.js +58 -66
  80. package/src/commands/wiki.js +783 -0
  81. package/src/commands/workboard.js +207 -0
  82. package/src/tools/audio_understanding.js +154 -0
  83. package/src/tools/browser.js +112 -0
  84. package/src/tools/canvas.js +104 -0
  85. package/src/tools/document_extract.js +84 -0
  86. package/src/tools/duckduckgo.js +54 -0
  87. package/src/tools/exa_search.js +66 -0
  88. package/src/tools/firecrawl.js +104 -0
  89. package/src/tools/image_generation.js +99 -0
  90. package/src/tools/llm_task.js +118 -0
  91. package/src/tools/media_understanding.js +128 -0
  92. package/src/tools/music_generation.js +113 -0
  93. package/src/tools/parallel_search.js +77 -0
  94. package/src/tools/phone_control.js +80 -0
  95. package/src/tools/phone_control_enhanced.js +184 -0
  96. package/src/tools/searxng.js +61 -0
  97. package/src/tools/speech_to_text.js +135 -0
  98. package/src/tools/text_to_speech.js +105 -0
  99. package/src/tools/thread_ownership.js +88 -0
  100. package/src/tools/video_generation.js +72 -0
  101. package/src/tools/web_readability.js +104 -0
  102. package/src/utils/agents-md.js +85 -0
  103. package/src/utils/api.js +39 -40
  104. package/src/utils/format.js +144 -0
  105. package/src/utils/headless.js +2 -1
  106. package/src/utils/memory.js +200 -0
  107. package/src/utils/parallel-tools.js +106 -0
  108. package/src/utils/sub-agent.js +148 -0
  109. package/src/utils/token-budget.js +304 -0
  110. package/src/utils/tool-runner.js +7 -5
  111. package/src/utils/web-fetch.js +107 -0
@@ -1,91 +1,146 @@
1
- const chalk = require('chalk');
2
- const { execSync } = require('child_process');
3
- const semver = require('semver');
4
- const inquirer = require('../utils/inquirer-wrapper');
5
- const packageJson = require('../../package.json');
6
-
7
- async function update() {
8
- const currentVersion = packageJson.version;
9
-
10
- console.log(chalk.yellow('\n⏳ Güncelleme kontrol ediliyor...\n'));
11
-
12
- try {
13
- // npm registry'den en son versiyonu al
14
- const response = await fetch('https://registry.npmjs.org/natureco-cli/latest');
15
- const data = await response.json();
16
- const latestVersion = data.version;
17
-
18
- console.log(chalk.cyan('Mevcut versiyon:'), chalk.white(`v${currentVersion}`));
19
- console.log(chalk.cyan('En son versiyon:'), chalk.white(`v${latestVersion}`));
20
- console.log('');
21
-
22
- if (currentVersion === latestVersion) {
23
- console.log(chalk.green(`✅ Zaten güncel: v${currentVersion}\n`));
24
- return;
25
- }
26
-
27
- // Versiyon karşılaştırması
28
- const isNewer = semver.gt(latestVersion, currentVersion);
29
-
30
- if (isNewer) {
31
- console.log(chalk.green(`✅ Yeni versiyon mevcut: v${currentVersion} → v${latestVersion}\n`));
32
- console.log(chalk.gray('Güncellemek için:\n'));
33
- console.log(chalk.cyan(' npm install -g natureco-cli@latest --force\n'));
34
-
35
- // İsteğe bağlı otomatik güncelleme
36
- const { shouldUpdate } = await inquirer.prompt([
37
- {
38
- type: 'confirm',
39
- name: 'shouldUpdate',
40
- message: 'Şimdi güncellensin mi?',
41
- default: true,
42
- },
43
- ]);
44
-
45
- if (shouldUpdate) {
46
- console.log(chalk.yellow('\n⏳ Güncelleme yapılıyor...\n'));
47
-
48
- try {
49
- execSync('npm install -g natureco-cli@latest --force', {
50
- stdio: 'inherit',
51
- });
52
-
53
- console.log(chalk.green(`\n✅ Güncelleme tamamlandı! v${latestVersion}\n`));
54
- } catch (err) {
55
- console.log(chalk.red('\n Güncelleme başarısız oldu.\n'));
56
- console.log(chalk.gray('Manuel olarak güncellemek için:\n'));
57
- console.log(chalk.cyan(' npm install -g natureco-cli@latest --force\n'));
58
- }
59
- } else {
60
- console.log(chalk.gray('\nGüncelleme iptal edildi.\n'));
61
- }
62
- } else {
63
- console.log(chalk.green(`✅ Zaten güncel: v${currentVersion}\n`));
64
- }
65
- } catch (err) {
66
- // Fetch başarısız olursa fallback olarak npm view kullan
67
- try {
68
- const latestVersion = execSync('npm view natureco-cli version', {
69
- encoding: 'utf8',
70
- stdio: ['pipe', 'pipe', 'ignore'],
71
- }).trim();
72
-
73
- console.log(chalk.cyan('Mevcut versiyon:'), chalk.white(`v${currentVersion}`));
74
- console.log(chalk.cyan('En son versiyon:'), chalk.white(`v${latestVersion}`));
75
- console.log('');
76
-
77
- if (currentVersion === latestVersion) {
78
- console.log(chalk.green(`✅ Zaten güncel: v${currentVersion}\n`));
79
- } else {
80
- console.log(chalk.green(`✅ Yeni versiyon mevcut: v${currentVersion} → v${latestVersion}\n`));
81
- console.log(chalk.gray('Güncellemek için:\n'));
82
- console.log(chalk.cyan(' npm install -g natureco-cli@latest --force\n'));
83
- }
84
- } catch (fallbackErr) {
85
- console.log(chalk.gray('Güncelleme kontrolü yapılamadı.\n'));
86
- console.log(chalk.gray('İnternet bağlantınızı kontrol edin.\n'));
87
- }
88
- }
89
- }
90
-
91
- module.exports = update;
1
+ const chalk = require('chalk');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const os = require('os');
5
+ const { execSync } = require('child_process');
6
+ const readline = require('readline');
7
+
8
+ const VERSION_FILE = path.join(os.homedir(), '.natureco', 'version.json');
9
+
10
+ function rlQuestion(query) {
11
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
12
+ return new Promise(resolve => {
13
+ rl.question(query, answer => { rl.close(); resolve(answer.trim().toLowerCase()); });
14
+ });
15
+ }
16
+
17
+ function loadVersion() {
18
+ if (!fs.existsSync(VERSION_FILE)) return { installed: null, checked: null };
19
+ try { return JSON.parse(fs.readFileSync(VERSION_FILE, 'utf8')); }
20
+ catch { return { installed: null, checked: null }; }
21
+ }
22
+
23
+ function saveVersion(data) {
24
+ const dir = path.dirname(VERSION_FILE);
25
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
26
+ fs.writeFileSync(VERSION_FILE, JSON.stringify(data, null, 2), 'utf8');
27
+ }
28
+
29
+ function getCurrentVersion() {
30
+ try {
31
+ const pkg = require('../../package.json');
32
+ return pkg.version;
33
+ } catch {
34
+ return '0.0.0';
35
+ }
36
+ }
37
+
38
+ function getLatestVersion() {
39
+ try {
40
+ const result = execSync('npm view natureco-cli version', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] });
41
+ return result.trim();
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ async function update(params) {
48
+ try {
49
+ const [action] = params || [];
50
+
51
+ if (!action || action === 'status') return cmdStatus();
52
+ if (action === 'run') return await cmdRun();
53
+ if (action === 'wizard') return await cmdWizard();
54
+
55
+ console.log(chalk.red(`\n Unknown update action: ${action}\n`));
56
+ console.log(chalk.gray(' Usage: natureco update [run|status|wizard]\n'));
57
+ } catch (err) {
58
+ console.log(chalk.red(`\n Update error: ${err.message}\n`));
59
+ }
60
+ }
61
+
62
+ function cmdStatus() {
63
+ const current = getCurrentVersion();
64
+ const latest = getLatestVersion();
65
+ const ver = loadVersion();
66
+
67
+ console.log(chalk.cyan('\n Update Status\n'));
68
+ console.log(chalk.white(' Installed: ') + chalk.cyan('v' + current));
69
+
70
+ if (latest) {
71
+ console.log(chalk.white(' Latest: ') + chalk.cyan('v' + latest));
72
+ if (current === latest) {
73
+ console.log(chalk.green(' You are up to date.\n'));
74
+ } else {
75
+ console.log(chalk.yellow(' Update available: v' + current + ' → v' + latest + '\n'));
76
+ }
77
+ } else {
78
+ console.log(chalk.gray(' Could not check latest version.\n'));
79
+ }
80
+
81
+ saveVersion({ installed: current, checked: new Date().toISOString(), latest: latest || ver.latest });
82
+ }
83
+
84
+ async function cmdRun() {
85
+ const current = getCurrentVersion();
86
+ const latest = getLatestVersion();
87
+
88
+ if (!latest) {
89
+ console.log(chalk.yellow('\n Could not fetch latest version. Check your internet connection.\n'));
90
+ return;
91
+ }
92
+
93
+ if (current === latest) {
94
+ console.log(chalk.green('\n Already up to date (v' + current + ').\n'));
95
+ return;
96
+ }
97
+
98
+ console.log(chalk.cyan('\n Updating: v' + current + ' → v' + latest + '\n'));
99
+
100
+ try {
101
+ execSync('npm update -g natureco-cli', { stdio: 'inherit' });
102
+ saveVersion({ installed: latest, updated: new Date().toISOString(), latest });
103
+ console.log(chalk.green('\n ✓ Updated to v' + latest + '\n'));
104
+ } catch (e) {
105
+ console.log(chalk.red('\n Update failed: ' + e.message + '\n'));
106
+ console.log(chalk.gray(' Try: npm install -g natureco-cli@latest\n'));
107
+ }
108
+ }
109
+
110
+ async function cmdWizard() {
111
+ const current = getCurrentVersion();
112
+ const latest = getLatestVersion();
113
+
114
+ console.log(chalk.cyan('\n Update Wizard\n'));
115
+
116
+ if (!latest) {
117
+ console.log(chalk.yellow(' Could not check for updates.\n'));
118
+ return;
119
+ }
120
+
121
+ console.log(chalk.white(' Current: v' + current));
122
+ console.log(chalk.white(' Latest: v' + latest));
123
+
124
+ if (current === latest) {
125
+ console.log(chalk.green('\n You are up to date!\n'));
126
+ return;
127
+ }
128
+
129
+ const answer = await rlQuestion(chalk.yellow(' Update to v' + latest + '? [Y/n]: '));
130
+ if (answer === 'n' || answer === 'no') {
131
+ console.log(chalk.gray('\n Skipped.\n'));
132
+ return;
133
+ }
134
+
135
+ console.log(chalk.gray('\n Installing...\n'));
136
+
137
+ try {
138
+ execSync('npm install -g natureco-cli@latest', { stdio: 'inherit' });
139
+ saveVersion({ installed: latest, updated: new Date().toISOString(), latest });
140
+ console.log(chalk.green('\n ✓ Updated to v' + latest + '\n'));
141
+ } catch (e) {
142
+ console.log(chalk.red('\n Update failed: ' + e.message + '\n'));
143
+ }
144
+ }
145
+
146
+ module.exports = update;
@@ -0,0 +1,82 @@
1
+ const chalk = require('chalk');
2
+ const { getConfig, saveConfig } = require('../utils/config');
3
+
4
+ const PROVIDER_LABELS = {
5
+ openai: 'OpenAI',
6
+ elevenlabs: 'ElevenLabs',
7
+ microsoft: 'Microsoft (Azure)',
8
+ deepgram: 'Deepgram',
9
+ google: 'Google Cloud'
10
+ };
11
+
12
+ function mask(str, keep = 6) {
13
+ if (!str) return '(unset)';
14
+ return str.length <= keep ? '***' : `${str.slice(0, keep)}…`;
15
+ }
16
+
17
+ async function voice(args) {
18
+ const [action, ...params] = args || [];
19
+
20
+ if (!action || action === 'status') return statusVoice();
21
+ if (action === 'providers') return listProviders();
22
+ if (action === 'set') return setVoiceProvider(params);
23
+
24
+ console.log(chalk.red(`\n ❌ Unknown command: ${action}\n`));
25
+ console.log(chalk.gray(' Usage: natureco voice [status|providers|set]\n'));
26
+ process.exit(1);
27
+ }
28
+
29
+ function statusVoice() {
30
+ const config = getConfig();
31
+ const ttsConfig = config.tts || {};
32
+ const provider = ttsConfig.provider || 'openai';
33
+ const voiceId = ttsConfig.voiceId;
34
+ const apiKey = ttsConfig.apiKey || config[`${provider}ApiKey`] || process.env[`${provider.toUpperCase()}_API_KEY`];
35
+
36
+ console.log(chalk.cyan('\n 🎤 Voice Status\n'));
37
+ console.log(chalk.gray(' ' + '─'.repeat(48)));
38
+ console.log(` ${chalk.white('Provider:')} ${chalk.cyan(provider)}`);
39
+ console.log(` ${chalk.white('Voice ID:')} ${chalk.cyan(voiceId || '(default)')}`);
40
+ console.log(` ${chalk.white('API Key:')} ${chalk.gray(mask(apiKey))}`);
41
+ console.log(chalk.gray('\n Commands:'));
42
+ console.log(chalk.cyan(' natureco voice providers') + chalk.gray(' List available providers'));
43
+ console.log(chalk.cyan(' natureco voice set <provider> [voiceId]') + chalk.gray(' Set voice provider'));
44
+ console.log();
45
+ }
46
+
47
+ function listProviders() {
48
+ console.log(chalk.cyan('\n 🎤 Voice Providers\n'));
49
+ console.log(chalk.gray(' ' + '─'.repeat(48)));
50
+
51
+ for (const [id, label] of Object.entries(PROVIDER_LABELS)) {
52
+ console.log(` ${chalk.white(label)} ${chalk.gray(`(${id})`)}`);
53
+ }
54
+
55
+ console.log(chalk.gray('\n Set provider:'));
56
+ console.log(chalk.cyan(' natureco voice set openai'));
57
+ console.log(chalk.cyan(' natureco voice set elevenlabs [voiceId]'));
58
+ console.log();
59
+ }
60
+
61
+ function setVoiceProvider(args) {
62
+ const provider = args[0];
63
+ const voiceId = args.slice(1).join(' ') || '';
64
+
65
+ if (!provider || !PROVIDER_LABELS[provider]) {
66
+ console.log(chalk.red(`\n ❌ Unknown provider: ${provider}\n`));
67
+ console.log(chalk.gray(' Available: ' + Object.keys(PROVIDER_LABELS).join(', ')));
68
+ console.log();
69
+ process.exit(1);
70
+ }
71
+
72
+ const config = getConfig();
73
+ if (!config.tts) config.tts = {};
74
+ config.tts.provider = provider;
75
+ if (voiceId) config.tts.voiceId = voiceId;
76
+ else delete config.tts.voiceId;
77
+ saveConfig(config);
78
+
79
+ console.log(chalk.green(`\n ✅ Voice provider set to ${PROVIDER_LABELS[provider]}${voiceId ? ` (voice: ${voiceId})` : ''}\n`));
80
+ }
81
+
82
+ module.exports = voice;
@@ -0,0 +1,98 @@
1
+ const chalk = require('chalk');
2
+ const { getConfig, saveConfig } = require('../utils/config');
3
+
4
+ const VYDRA_ENDPOINTS = {
5
+ 'vydra-image': {
6
+ name: 'Vydra Image Generation',
7
+ endpoint: 'https://api.vydra.ai/v1/images/generations',
8
+ docs: 'https://docs.vydra.ai/image-generation'
9
+ },
10
+ 'vydra-video': {
11
+ name: 'Vydra Video Generation',
12
+ endpoint: 'https://api.vydra.ai/v1/video/generations',
13
+ docs: 'https://docs.vydra.ai/video-generation'
14
+ },
15
+ 'vydra-music': {
16
+ name: 'Vydra Music Generation',
17
+ endpoint: 'https://api.vydra.ai/v1/music/generations',
18
+ docs: 'https://docs.vydra.ai/music-generation'
19
+ }
20
+ };
21
+
22
+ function vydra(args) {
23
+ const [action, ...params] = args || [];
24
+
25
+ if (!action || action === 'status') return statusVydra();
26
+ if (action === 'configure') return configureVydra(params[0], params[1]);
27
+ if (action === 'test') return testVydra();
28
+
29
+ console.log(chalk.red(`\n ❌ Bilinmeyen komut: ${action}\n`));
30
+ console.log(chalk.gray(' Kullanım: natureco vydra [status|configure|test]\n'));
31
+ process.exit(1);
32
+ }
33
+
34
+ function statusVydra() {
35
+ const config = getConfig();
36
+ const apiKey = config.vydraApiKey || process.env.VYDRA_API_KEY;
37
+
38
+ console.log(chalk.cyan('\n 🎬 Vydra Media Provider\n'));
39
+ console.log(chalk.gray(' ' + '─'.repeat(48)));
40
+ console.log(` ${chalk.white('API Key:')} ${apiKey ? chalk.green('Configured') : chalk.red('Not set')}`);
41
+ console.log(chalk.gray('\n Available endpoints:\n'));
42
+
43
+ for (const [id, ep] of Object.entries(VYDRA_ENDPOINTS)) {
44
+ const configured = apiKey ? chalk.green('✅') : chalk.gray('⏸️');
45
+ console.log(` ${configured} ${chalk.white(ep.name)}`);
46
+ console.log(` ${chalk.gray(ep.endpoint)}`);
47
+ }
48
+
49
+ console.log(chalk.gray('\n Commands:'));
50
+ console.log(chalk.cyan(' configure <key>') + chalk.gray(' Set Vydra API key'));
51
+ console.log(chalk.cyan(' test') + chalk.gray(' Test API connection'));
52
+ console.log();
53
+ }
54
+
55
+ function configureVydra(key) {
56
+ if (!key) {
57
+ console.log(chalk.red('\n ❌ API key gerekli\n'));
58
+ process.exit(1);
59
+ }
60
+
61
+ const config = getConfig();
62
+ config.vydraApiKey = key;
63
+ saveConfig(config);
64
+ console.log(chalk.green('\n ✅ Vydra API key saved\n'));
65
+ }
66
+
67
+ async function testVydra() {
68
+ const config = getConfig();
69
+ const apiKey = config.vydraApiKey || process.env.VYDRA_API_KEY;
70
+
71
+ if (!apiKey) {
72
+ console.log(chalk.red('\n ❌ Vydra API key gerekli\n'));
73
+ console.log(chalk.cyan(' natureco vydra configure <your-api-key>\n'));
74
+ process.exit(1);
75
+ }
76
+
77
+ console.log(chalk.cyan('\n Testing Vydra API connection...\n'));
78
+
79
+ for (const [id, ep] of Object.entries(VYDRA_ENDPOINTS)) {
80
+ try {
81
+ const response = await fetch(ep.endpoint, {
82
+ method: 'HEAD',
83
+ headers: { 'Authorization': `Bearer ${apiKey}` }
84
+ });
85
+ console.log(` ${response.ok ? chalk.green('✅') : chalk.red('❌')} ${chalk.white(ep.name)} ${chalk.gray(`(${response.status})`)}`);
86
+ } catch (err) {
87
+ console.log(` ${chalk.red('❌')} ${chalk.white(ep.name)} ${chalk.gray(`(${err.message})`)}`);
88
+ }
89
+ }
90
+
91
+ console.log(chalk.gray('\n Vydra API endpoints are available as providers for:'));
92
+ console.log(chalk.cyan(' image_generation') + chalk.gray(' tool (provider: vydra)'));
93
+ console.log(chalk.cyan(' video_generation') + chalk.gray(' tool (provider: vydra)'));
94
+ console.log(chalk.cyan(' music_generation') + chalk.gray(' tool (provider: vydra)'));
95
+ console.log();
96
+ }
97
+
98
+ module.exports = vydra;
@@ -1,79 +1,71 @@
1
1
  const chalk = require('chalk');
2
- const inquirer = require('../utils/inquirer-wrapper');
3
- const { getConfig, saveConfig } = require('../utils/config');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const os = require('os');
4
5
 
5
- async function webhooks(action) {
6
- if (!action || action === 'connect') return connectWebhook();
7
- if (action === 'disconnect') return disconnectWebhook();
8
- if (action === 'status') return statusWebhooks();
9
- if (action === 'list') return listWebhooks();
10
- console.log(chalk.red('\n❌ Unknown action\n'));
11
- console.log(chalk.gray('Available actions: connect, disconnect, status, list\n'));
12
- process.exit(1);
6
+ const WEBHOOKS_FILE = path.join(os.homedir(), '.natureco', 'webhooks.json');
7
+
8
+ function loadWebhooks() {
9
+ if (!fs.existsSync(WEBHOOKS_FILE)) return [];
10
+ try { return JSON.parse(fs.readFileSync(WEBHOOKS_FILE, 'utf8')); }
11
+ catch { return []; }
13
12
  }
14
13
 
15
- async function connectWebhook() {
16
- const config = getConfig();
17
- if (!config.providerUrl) { console.log(chalk.red('\n❌ Setup yapılmamış. Önce "natureco setup" çalıştırın.\n')); process.exit(1); }
18
- console.log(chalk.yellow('\n⏳ Webhook bağlantısı hazırlanıyor...\n'));
19
- console.log(chalk.gray('Gelen webhook\'lar NatureCo\'nun gateway\'ine yönlendirilir.\n'));
20
- const answers = await inquirer.prompt([
21
- { type: 'input', name: 'name', message: 'Webhook adı:', validate: v => v.trim() ? true : 'Gerekli' },
22
- { type: 'input', name: 'path', message: 'Webhook yolu (örn: /my-webhook):', validate: v => v.startsWith('/') ? true : 'Yol / ile başlamalı' },
23
- { type: 'input', name: 'secret', message: 'Webhook secret (opsiyonel):' },
24
- ]);
25
- const webhooks = config.webhooks || [];
26
- const entry = {
27
- id: `webhook_${Date.now()}`,
28
- name: answers.name.trim(),
29
- path: answers.path.trim(),
30
- secret: answers.secret.trim() || '',
31
- createdAt: new Date().toISOString(),
32
- };
33
- webhooks.push(entry);
34
- config.webhooks = webhooks;
35
- config.webhookEnabled = true;
36
- saveConfig(config);
37
- console.log(chalk.green('\n✅ Webhook eklendi!\n'));
38
- console.log(chalk.cyan('ID:'), chalk.white(entry.id));
39
- console.log(chalk.cyan('İsim:'), chalk.white(entry.name));
40
- console.log(chalk.cyan('Yol:'), chalk.white(entry.path));
41
- console.log(chalk.gray('\nGateway ile başlatmak için: natureco gateway start\n'));
14
+ function saveWebhooks(webhooks) {
15
+ const dir = path.dirname(WEBHOOKS_FILE);
16
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
17
+ fs.writeFileSync(WEBHOOKS_FILE, JSON.stringify(webhooks, null, 2), 'utf8');
18
+ }
19
+
20
+ function webhooks(args) {
21
+ const [action, subAction, ...params] = args || [];
22
+
23
+ if (!action || action === 'list') return cmdList();
24
+ if (action === 'gmail' && subAction === 'setup') return cmdGmailSetup();
25
+ if (action === 'gmail' && subAction === 'run') return cmdGmailRun();
26
+
27
+ console.log(chalk.red(`\n Unknown webhooks action: ${action} ${subAction || ''}\n`));
28
+ console.log(chalk.gray(' Usage: natureco webhooks <action> [params]'));
29
+ console.log(chalk.gray(' Actions: list, gmail setup, gmail run\n'));
30
+ process.exit(1);
42
31
  }
43
32
 
44
- async function disconnectWebhook() {
45
- const config = getConfig();
46
- const webhooks = config.webhooks || [];
47
- if (webhooks.length === 0) { console.log(chalk.gray('\n⚠️ No webhooks configured\n')); return; }
48
- const { confirm } = await inquirer.prompt([{ type: 'confirm', name: 'confirm', message: 'Tüm webhook\'ları kaldırmak istediğinize emin misiniz?', default: false }]);
49
- if (!confirm) { console.log(chalk.gray('\nCancelled\n')); return; }
50
- delete config.webhooks;
51
- delete config.webhookEnabled;
52
- saveConfig(config);
53
- console.log(chalk.green('\n✅ All webhooks removed\n'));
33
+ function cmdList() {
34
+ const webhooks = loadWebhooks();
35
+
36
+ console.log(chalk.cyan(`\n Webhooks (${webhooks.length})\n`));
37
+ console.log(chalk.gray(' ' + ''.repeat(48)));
38
+
39
+ if (webhooks.length === 0) {
40
+ console.log(chalk.gray(' No webhooks configured.\n'));
41
+ return;
42
+ }
43
+
44
+ for (const w of webhooks) {
45
+ console.log(` ${chalk.white(w.name || w.id || 'unnamed')}`);
46
+ if (w.url) console.log(chalk.gray(` URL: ${w.url}`));
47
+ if (w.path) console.log(chalk.gray(` Path: ${w.path}`));
48
+ if (w.type) console.log(chalk.gray(` Type: ${w.type}`));
49
+ }
50
+ console.log('');
54
51
  }
55
52
 
56
- function listWebhooks() {
57
- const config = getConfig();
58
- const webhooks = config.webhooks || [];
59
- if (webhooks.length === 0) { console.log(chalk.gray('\n⚠️ No webhooks configured\n')); return; }
60
- console.log(chalk.green(`\n✅ ${webhooks.length} webhook(s) configured\n`));
61
- webhooks.forEach(w => {
62
- console.log(chalk.cyan(' ID:'), chalk.white(w.id));
63
- console.log(chalk.cyan(' İsim:'), chalk.white(w.name));
64
- console.log(chalk.cyan(' Yol:'), chalk.white(w.path));
65
- if (w.secret) console.log(chalk.cyan(' Secret:'), chalk.gray('✓ ayarlı'));
66
- console.log('');
67
- });
53
+ function cmdGmailSetup() {
54
+ console.log(chalk.cyan('\n Gmail Pub/Sub Webhook Setup\n'));
55
+ console.log(chalk.gray(' ' + '─'.repeat(48)));
56
+ console.log(` ${chalk.white('Status:')} ${chalk.yellow('Not configured')}`);
57
+ console.log('');
58
+ console.log(chalk.gray(' To set up Gmail webhooks:'));
59
+ console.log(chalk.gray(' 1. Enable Gmail API in Google Cloud Console'));
60
+ console.log(chalk.gray(' 2. Create a Pub/Sub topic'));
61
+ console.log(chalk.gray(' 3. Configure the push endpoint'));
62
+ console.log(chalk.gray(' 4. Run: natureco webhooks gmail run'));
63
+ console.log('');
68
64
  }
69
65
 
70
- function statusWebhooks() {
71
- const config = getConfig();
72
- const webhooks = config.webhooks || [];
73
- if (webhooks.length === 0) { console.log(chalk.gray('\n⚠️ No webhooks configured\n')); console.log(chalk.gray('Add with: natureco webhooks connect\n')); return; }
74
- console.log(chalk.green(`\n✅ Webhooks active (${webhooks.length} route(s))\n`));
75
- webhooks.forEach(w => console.log(chalk.white(` ${w.path} → ${w.name}`)));
76
- console.log(chalk.gray('\nDisconnect with: natureco webhooks disconnect\n'));
66
+ function cmdGmailRun() {
67
+ console.log(chalk.cyan('\n Triggering Gmail Webhook\n'));
68
+ console.log(chalk.gray(' (Stub Gmail webhook execution not implemented)\n'));
77
69
  }
78
70
 
79
71
  module.exports = webhooks;