httpcat-cli 0.0.16 → 0.0.17

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,118 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Monitor FRIDA chat for mentions of "foobar"
5
+ *
6
+ * Usage:
7
+ * node monitor-foobar.js
8
+ */
9
+
10
+ import { spawn } from 'child_process';
11
+ import { fileURLToPath } from 'url';
12
+ import { dirname } from 'path';
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = dirname(__filename);
16
+
17
+ const TOKEN = 'FRIDA';
18
+ const SEARCH_TERM = 'foobar';
19
+
20
+ console.error(`šŸ” Monitoring FRIDA chat for mentions of "${SEARCH_TERM}"...`);
21
+ console.error(`Press Ctrl+C to stop monitoring\n`);
22
+
23
+ // Spawn httpcat chat process
24
+ const chatProcess = spawn('httpcat', ['chat', '--json', TOKEN], {
25
+ stdio: ['pipe', 'pipe', 'inherit'],
26
+ shell: true,
27
+ });
28
+
29
+ let outputBuffer = '';
30
+ let seenMessageIds = new Set();
31
+
32
+ chatProcess.stdout.on('data', (data) => {
33
+ outputBuffer += data.toString();
34
+ const lines = outputBuffer.split('\n');
35
+ outputBuffer = lines.pop() || '';
36
+
37
+ for (const line of lines) {
38
+ if (!line.trim()) continue;
39
+
40
+ try {
41
+ const event = JSON.parse(line);
42
+
43
+ switch (event.type) {
44
+ case 'joined':
45
+ console.error(`āœ… Joined FRIDA chat. Lease ID: ${event.leaseId}`);
46
+ console.error(`šŸ“” Monitoring for "${SEARCH_TERM}" mentions...\n`);
47
+ break;
48
+
49
+ case 'message':
50
+ const msg = event.data;
51
+
52
+ // Skip if we've already seen this message
53
+ if (seenMessageIds.has(msg.messageId)) {
54
+ break;
55
+ }
56
+ seenMessageIds.add(msg.messageId);
57
+
58
+ // Check if message contains search term (case-insensitive)
59
+ if (msg.message.toLowerCase().includes(SEARCH_TERM.toLowerCase())) {
60
+ const author = msg.authorShort || msg.author?.slice(0, 10);
61
+ const time = new Date(msg.timestamp).toLocaleString();
62
+
63
+ console.error('\n' + '='.repeat(60));
64
+ console.error(`šŸŽÆ FOUND "${SEARCH_TERM}" MENTION!`);
65
+ console.error('='.repeat(60));
66
+ console.error(`Time: ${time}`);
67
+ console.error(`Author: ${author}`);
68
+ console.error(`Message: ${msg.message}`);
69
+ console.error('='.repeat(60) + '\n');
70
+ }
71
+ break;
72
+
73
+ case 'lease_expired':
74
+ console.error('ā±ļø Lease expired. Sending /renew...');
75
+ if (chatProcess.stdin && !chatProcess.stdin.destroyed) {
76
+ chatProcess.stdin.write('/renew\n');
77
+ }
78
+ break;
79
+
80
+ case 'error':
81
+ console.error(`āŒ Error: ${event.error}`);
82
+ break;
83
+
84
+ case 'exiting':
85
+ console.error('šŸ‘‹ Chat session ended');
86
+ process.exit(0);
87
+ break;
88
+ }
89
+ } catch (error) {
90
+ // Not JSON, ignore
91
+ }
92
+ }
93
+ });
94
+
95
+ chatProcess.on('error', (error) => {
96
+ console.error(`āŒ Failed to start chat process: ${error.message}`);
97
+ process.exit(1);
98
+ });
99
+
100
+ chatProcess.on('exit', (code) => {
101
+ if (code !== 0 && code !== null) {
102
+ console.error(`Chat process exited with code ${code}`);
103
+ }
104
+ process.exit(code || 0);
105
+ });
106
+
107
+ // Handle Ctrl+C
108
+ process.on('SIGINT', () => {
109
+ console.error('\nšŸ‘‹ Stopping monitor...');
110
+ if (chatProcess.stdin && !chatProcess.stdin.destroyed) {
111
+ chatProcess.stdin.write('/exit\n');
112
+ }
113
+ setTimeout(() => {
114
+ chatProcess.kill();
115
+ process.exit(0);
116
+ }, 1000);
117
+ });
118
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "httpcat-cli",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "CLI tool for interacting with httpcat agent - create, buy, and sell tokens with x402 payments",
5
5
  "main": "dist/index.js",
6
6
  "bin": {