slashvibe-mcp 0.3.20 → 0.3.21

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 (167) hide show
  1. package/README.md +47 -252
  2. package/analytics.js +107 -0
  3. package/auth-store.js +148 -0
  4. package/auto-update.js +130 -0
  5. package/bridges/bridge-monitor.js +388 -0
  6. package/bridges/discord-bot.js +431 -0
  7. package/bridges/farcaster.js +299 -0
  8. package/bridges/telegram.js +261 -0
  9. package/bridges/webhook-health.js +420 -0
  10. package/bridges/webhook-server.js +437 -0
  11. package/bridges/whatsapp.js +441 -0
  12. package/bridges/x-webhook.js +423 -0
  13. package/config.js +27 -15
  14. package/games/arcade.js +406 -0
  15. package/games/chess.js +451 -0
  16. package/games/colorguess.js +343 -0
  17. package/games/crossword-words.js +171 -0
  18. package/games/crossword.js +461 -0
  19. package/games/drawing.js +347 -0
  20. package/games/gameroulette.js +300 -0
  21. package/games/gamerouter.js +336 -0
  22. package/games/gamestatus.js +337 -0
  23. package/games/guessnumber.js +209 -0
  24. package/games/hangman.js +279 -0
  25. package/games/memory.js +338 -0
  26. package/games/multiplayer-tictactoe.js +389 -0
  27. package/games/pixelart.js +399 -0
  28. package/games/quickduel.js +354 -0
  29. package/games/riddle.js +371 -0
  30. package/games/rockpaperscissors.js +291 -0
  31. package/games/snake.js +406 -0
  32. package/games/storybuilder.js +343 -0
  33. package/games/tictactoe.js +345 -0
  34. package/games/twentyquestions.js +286 -0
  35. package/games/twotruths.js +207 -0
  36. package/games/werewolf.js +508 -0
  37. package/games/wordassociation.js +247 -0
  38. package/games/wordchain.js +135 -0
  39. package/index.js +116 -159
  40. package/intelligence/index.js +9 -2
  41. package/intelligence/interests.js +369 -0
  42. package/notification-emitter.js +77 -0
  43. package/notify.js +5 -1
  44. package/package.json +21 -16
  45. package/prompts.js +1 -1
  46. package/protocol/index.js +73 -0
  47. package/setup.js +480 -0
  48. package/smart-inbox.js +276 -0
  49. package/store/api.js +536 -215
  50. package/store/profiles.js +160 -12
  51. package/tools/_actions.js +362 -21
  52. package/tools/_discovery.js +119 -26
  53. package/tools/_shared/index.js +64 -0
  54. package/tools/_shared.js +234 -0
  55. package/tools/_work-context.js +338 -0
  56. package/tools/_work-context.manual-test.js +199 -0
  57. package/tools/_work-context.test.js +260 -0
  58. package/tools/activity.js +220 -0
  59. package/tools/analytics.js +191 -0
  60. package/tools/approve.js +197 -0
  61. package/tools/artifact-create.js +14 -3
  62. package/tools/artifacts-price.js +107 -0
  63. package/tools/available.js +120 -0
  64. package/tools/broadcast.js +325 -0
  65. package/tools/chat.js +202 -0
  66. package/tools/collaborative-drawing.js +1 -1
  67. package/tools/connection-status.js +178 -0
  68. package/tools/discover.js +350 -34
  69. package/tools/dm.js +80 -8
  70. package/tools/earnings.js +126 -0
  71. package/tools/feed.js +35 -4
  72. package/tools/follow.js +224 -0
  73. package/tools/friends.js +207 -0
  74. package/tools/gig-browse.js +206 -0
  75. package/tools/gig-complete.js +144 -0
  76. package/tools/health.js +87 -0
  77. package/tools/help.js +3 -3
  78. package/tools/idea.js +9 -2
  79. package/tools/inbox.js +289 -105
  80. package/tools/init.js +131 -34
  81. package/tools/invite.js +15 -4
  82. package/tools/leaderboard.js +117 -0
  83. package/tools/lib/git-apply.js +206 -0
  84. package/tools/lib/git-bundle.js +407 -0
  85. package/tools/migrate.js +3 -3
  86. package/tools/multiplayer-game.js +1 -1
  87. package/tools/onboarding.js +7 -7
  88. package/tools/open.js +143 -12
  89. package/tools/party-game.js +1 -1
  90. package/tools/plan.js +225 -0
  91. package/tools/proof-of-work.js +144 -0
  92. package/tools/reply.js +166 -0
  93. package/tools/report.js +1 -1
  94. package/tools/request.js +17 -3
  95. package/tools/schedule.js +367 -0
  96. package/tools/search-messages.js +123 -0
  97. package/tools/session.js +467 -0
  98. package/tools/session_price.js +128 -0
  99. package/tools/settings.js +90 -2
  100. package/tools/ship.js +30 -7
  101. package/tools/smart-check.js +201 -0
  102. package/tools/start.js +147 -12
  103. package/tools/status.js +53 -6
  104. package/tools/streak.js +147 -0
  105. package/tools/stuck.js +297 -0
  106. package/tools/subscribe.js +148 -0
  107. package/tools/subscriptions.js +134 -0
  108. package/tools/suggest-tags.js +6 -8
  109. package/tools/tag-suggestions.js +1 -1
  110. package/tools/tip.js +150 -77
  111. package/tools/token.js +4 -4
  112. package/tools/update.js +1 -1
  113. package/tools/wallet.js +221 -79
  114. package/tools/watch.js +157 -0
  115. package/tools/who.js +30 -1
  116. package/tools/withdraw.js +145 -0
  117. package/tools/work-summary.js +96 -0
  118. package/version.json +10 -8
  119. package/LICENSE +0 -21
  120. package/store/sqlite.js +0 -347
  121. /package/tools/{auto-suggest-connections.js → _deprecated/auto-suggest-connections.js} +0 -0
  122. /package/tools/{away.js → _deprecated/away.js} +0 -0
  123. /package/tools/{back.js → _deprecated/back.js} +0 -0
  124. /package/tools/{bootstrap-skills.js → _deprecated/bootstrap-skills.js} +0 -0
  125. /package/tools/{bridge-dashboard.js → _deprecated/bridge-dashboard.js} +0 -0
  126. /package/tools/{bridge-health.js → _deprecated/bridge-health.js} +0 -0
  127. /package/tools/{bridge-live.js → _deprecated/bridge-live.js} +0 -0
  128. /package/tools/{bridges.js → _deprecated/bridges.js} +0 -0
  129. /package/tools/{colorguess.js → _deprecated/colorguess.js} +0 -0
  130. /package/tools/{discover-insights.js → _deprecated/discover-insights.js} +0 -0
  131. /package/tools/{discover-momentum.js → _deprecated/discover-momentum.js} +0 -0
  132. /package/tools/{discovery-analytics.js → _deprecated/discovery-analytics.js} +0 -0
  133. /package/tools/{discovery-auto-suggest.js → _deprecated/discovery-auto-suggest.js} +0 -0
  134. /package/tools/{discovery-bootstrap.js → _deprecated/discovery-bootstrap.js} +0 -0
  135. /package/tools/{discovery-daily.js → _deprecated/discovery-daily.js} +0 -0
  136. /package/tools/{discovery-dashboard.js → _deprecated/discovery-dashboard.js} +0 -0
  137. /package/tools/{discovery-digest.js → _deprecated/discovery-digest.js} +0 -0
  138. /package/tools/{discovery-hub.js → _deprecated/discovery-hub.js} +0 -0
  139. /package/tools/{discovery-insights.js → _deprecated/discovery-insights.js} +0 -0
  140. /package/tools/{discovery-momentum.js → _deprecated/discovery-momentum.js} +0 -0
  141. /package/tools/{discovery-monitor.js → _deprecated/discovery-monitor.js} +0 -0
  142. /package/tools/{discovery-proactive.js → _deprecated/discovery-proactive.js} +0 -0
  143. /package/tools/{draw.js → _deprecated/draw.js} +0 -0
  144. /package/tools/{farcaster.js → _deprecated/farcaster.js} +0 -0
  145. /package/tools/{forget.js → _deprecated/forget.js} +0 -0
  146. /package/tools/{games-catalog.js → _deprecated/games-catalog.js} +0 -0
  147. /package/tools/{games.js → _deprecated/games.js} +0 -0
  148. /package/tools/{guessnumber.js → _deprecated/guessnumber.js} +0 -0
  149. /package/tools/{hangman.js → _deprecated/hangman.js} +0 -0
  150. /package/tools/{multiplayer-tictactoe.js → _deprecated/multiplayer-tictactoe.js} +0 -0
  151. /package/tools/{mute.js → _deprecated/mute.js} +0 -0
  152. /package/tools/{recall.js → _deprecated/recall.js} +0 -0
  153. /package/tools/{remember.js → _deprecated/remember.js} +0 -0
  154. /package/tools/{riddle.js → _deprecated/riddle.js} +0 -0
  155. /package/tools/{run-bootstrap.js → _deprecated/run-bootstrap.js} +0 -0
  156. /package/tools/{skills-analytics.js → _deprecated/skills-analytics.js} +0 -0
  157. /package/tools/{skills-bootstrap.js → _deprecated/skills-bootstrap.js} +0 -0
  158. /package/tools/{skills-dashboard.js → _deprecated/skills-dashboard.js} +0 -0
  159. /package/tools/{skills-exchange.js → _deprecated/skills-exchange.js} +0 -0
  160. /package/tools/{skills.js → _deprecated/skills.js} +0 -0
  161. /package/tools/{smart-intro.js → _deprecated/smart-intro.js} +0 -0
  162. /package/tools/{storybuilder.js → _deprecated/storybuilder.js} +0 -0
  163. /package/tools/{telegram-bot.js → _deprecated/telegram-bot.js} +0 -0
  164. /package/tools/{telegram-setup.js → _deprecated/telegram-setup.js} +0 -0
  165. /package/tools/{tictactoe.js → _deprecated/tictactoe.js} +0 -0
  166. /package/tools/{twentyquestions.js → _deprecated/twentyquestions.js} +0 -0
  167. /package/tools/{wordassociation.js → _deprecated/wordassociation.js} +0 -0
@@ -0,0 +1,431 @@
1
+ /**
2
+ * /vibe Discord Bot Bridge
3
+ *
4
+ * Two-way Discord integration using Discord.js bot API.
5
+ * Complements discord.js webhook functionality with full bot features.
6
+ */
7
+
8
+ const config = require('../config');
9
+
10
+ /**
11
+ * Get Discord bot credentials from config
12
+ */
13
+ function getBotToken() {
14
+ const cfg = config.load();
15
+ return cfg.discord_bot_token || process.env.DISCORD_BOT_TOKEN || null;
16
+ }
17
+
18
+ /**
19
+ * Get guild ID from config (optional - bot can work in any server)
20
+ */
21
+ function getGuildId() {
22
+ const cfg = config.load();
23
+ return cfg.discord_guild_id || process.env.DISCORD_GUILD_ID || null;
24
+ }
25
+
26
+ /**
27
+ * Check if Discord bot is configured
28
+ */
29
+ function isConfigured() {
30
+ return !!getBotToken();
31
+ }
32
+
33
+ /**
34
+ * Make authenticated request to Discord API
35
+ */
36
+ async function discordRequest(method, endpoint, body = null) {
37
+ const token = getBotToken();
38
+ if (!token) throw new Error('Discord bot token not configured');
39
+
40
+ const url = `https://discord.com/api/v10${endpoint}`;
41
+
42
+ const headers = {
43
+ 'Authorization': `Bot ${token}`,
44
+ 'Content-Type': 'application/json'
45
+ };
46
+
47
+ const response = await fetch(url, {
48
+ method,
49
+ headers,
50
+ body: body ? JSON.stringify(body) : undefined
51
+ });
52
+
53
+ if (!response.ok) {
54
+ const error = await response.text();
55
+ throw new Error(`Discord API error ${response.status}: ${error}`);
56
+ }
57
+
58
+ // Some endpoints return 204 No Content
59
+ if (response.status === 204) {
60
+ return null;
61
+ }
62
+
63
+ return response.json();
64
+ }
65
+
66
+ /**
67
+ * Get bot user info
68
+ */
69
+ async function getBotInfo() {
70
+ return discordRequest('GET', '/users/@me');
71
+ }
72
+
73
+ /**
74
+ * Get guilds (servers) the bot is in
75
+ */
76
+ async function getGuilds() {
77
+ return discordRequest('GET', '/users/@me/guilds');
78
+ }
79
+
80
+ /**
81
+ * Get channels in a guild
82
+ */
83
+ async function getChannels(guildId) {
84
+ return discordRequest('GET', `/guilds/${guildId}/channels`);
85
+ }
86
+
87
+ /**
88
+ * Send message to a channel
89
+ */
90
+ async function sendMessage(channelId, content, options = {}) {
91
+ const body = {
92
+ content,
93
+ embeds: options.embeds || undefined,
94
+ reply: options.replyTo ? { message_id: options.replyTo } : undefined,
95
+ flags: options.silent ? 4096 : undefined // SUPPRESS_NOTIFICATIONS
96
+ };
97
+
98
+ return discordRequest('POST', `/channels/${channelId}/messages`, body);
99
+ }
100
+
101
+ /**
102
+ * Get recent messages from a channel
103
+ */
104
+ async function getMessages(channelId, limit = 50, before = null) {
105
+ let endpoint = `/channels/${channelId}/messages?limit=${limit}`;
106
+ if (before) endpoint += `&before=${before}`;
107
+
108
+ return discordRequest('GET', endpoint);
109
+ }
110
+
111
+ /**
112
+ * Create a DM channel with a user
113
+ */
114
+ async function createDM(userId) {
115
+ return discordRequest('POST', '/users/@me/channels', {
116
+ recipient_id: userId
117
+ });
118
+ }
119
+
120
+ /**
121
+ * Send DM to user
122
+ */
123
+ async function sendDM(userId, content, options = {}) {
124
+ // Create DM channel first
125
+ const dmChannel = await createDM(userId);
126
+ return sendMessage(dmChannel.id, content, options);
127
+ }
128
+
129
+ /**
130
+ * Process Discord message into standardized format
131
+ */
132
+ function processMessage(message) {
133
+ const author = message.author;
134
+ const channel = message.channel_id;
135
+
136
+ // Skip bot messages
137
+ if (author.bot) return null;
138
+
139
+ return {
140
+ id: `discord:${message.id}`,
141
+ channel: 'discord',
142
+ type: message.guild_id ? 'channel' : 'dm',
143
+ from: {
144
+ id: author.id,
145
+ handle: author.username,
146
+ name: author.global_name || author.username,
147
+ discriminator: author.discriminator
148
+ },
149
+ content: message.content || '[embed/media]',
150
+ timestamp: message.timestamp,
151
+ channelId: channel,
152
+ guildId: message.guild_id || null,
153
+ mentions: message.mentions || [],
154
+ embeds: message.embeds || [],
155
+ attachments: message.attachments || [],
156
+ raw: message
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Parse /vibe commands from Discord messages
162
+ */
163
+ function parseVibeCommand(content) {
164
+ const trimmed = content.trim();
165
+
166
+ // !status mood [note]
167
+ const statusMatch = trimmed.match(/^!status\s+(\w+)(?:\s+(.+))?$/);
168
+ if (statusMatch) {
169
+ return {
170
+ command: 'status',
171
+ params: {
172
+ mood: statusMatch[1],
173
+ note: statusMatch[2] || null
174
+ }
175
+ };
176
+ }
177
+
178
+ // !who
179
+ if (trimmed === '!who') {
180
+ return { command: 'who' };
181
+ }
182
+
183
+ // !ship [message]
184
+ const shipMatch = trimmed.match(/^!ship(?:\s+(.+))?$/);
185
+ if (shipMatch) {
186
+ return {
187
+ command: 'ship',
188
+ params: {
189
+ message: shipMatch[1] || null
190
+ }
191
+ };
192
+ }
193
+
194
+ // !dm @user message
195
+ const dmMatch = trimmed.match(/^!dm\s+<@!?(\d+)>\s+(.+)$/);
196
+ if (dmMatch) {
197
+ return {
198
+ command: 'dm',
199
+ params: {
200
+ userId: dmMatch[1],
201
+ message: dmMatch[2]
202
+ }
203
+ };
204
+ }
205
+
206
+ // !vibe message (forward to /vibe)
207
+ const vibeMatch = trimmed.match(/^!vibe\s+(.+)$/);
208
+ if (vibeMatch) {
209
+ return {
210
+ command: 'vibe',
211
+ params: {
212
+ message: vibeMatch[1]
213
+ }
214
+ };
215
+ }
216
+
217
+ return null;
218
+ }
219
+
220
+ /**
221
+ * Send /vibe activity notification to Discord
222
+ */
223
+ async function notifyActivity(channelId, activity) {
224
+ const { handle, action, context } = activity;
225
+
226
+ const embed = {
227
+ color: 0x6B8FFF, // /vibe blue
228
+ description: `🔔 **@${handle}** ${action}`,
229
+ footer: { text: context || 'slashvibe.dev' },
230
+ timestamp: new Date().toISOString()
231
+ };
232
+
233
+ return sendMessage(channelId, '', { embeds: [embed] });
234
+ }
235
+
236
+ /**
237
+ * Send /vibe status update to Discord
238
+ */
239
+ async function notifyStatus(channelId, handle, mood, note) {
240
+ const moodEmoji = {
241
+ 'shipping': '🔥',
242
+ 'debugging': '🐛',
243
+ 'deep': '🧠',
244
+ 'afk': '☕',
245
+ 'celebrating': '🎉',
246
+ 'pairing': '👯'
247
+ };
248
+
249
+ const emoji = moodEmoji[mood] || '●';
250
+ let description = `${emoji} **@${handle}** is ${mood}`;
251
+
252
+ if (note) {
253
+ description += `\n_"${note}"_`;
254
+ }
255
+
256
+ const embed = {
257
+ color: 0x9B59B6, // Purple for status
258
+ description,
259
+ timestamp: new Date().toISOString()
260
+ };
261
+
262
+ return sendMessage(channelId, '', { embeds: [embed] });
263
+ }
264
+
265
+ /**
266
+ * Forward message from /vibe to Discord
267
+ */
268
+ async function forwardFromVibe(channelId, handle, message, context = null) {
269
+ const embed = {
270
+ color: 0x2ECC71, // Green for /vibe messages
271
+ author: {
272
+ name: `@${handle}`,
273
+ icon_url: 'https://slashvibe.dev/vibe-icon.png'
274
+ },
275
+ description: message,
276
+ footer: { text: context || '/vibe' },
277
+ timestamp: new Date().toISOString()
278
+ };
279
+
280
+ return sendMessage(channelId, '', { embeds: [embed] });
281
+ }
282
+
283
+ /**
284
+ * Create embed for /vibe announcements
285
+ */
286
+ function createVibeEmbed(title, description, color = 0x6B8FFF, fields = []) {
287
+ return {
288
+ color,
289
+ title,
290
+ description,
291
+ fields,
292
+ footer: {
293
+ text: 'slashvibe.dev',
294
+ icon_url: 'https://slashvibe.dev/vibe-icon.png'
295
+ },
296
+ timestamp: new Date().toISOString()
297
+ };
298
+ }
299
+
300
+ /**
301
+ * Send who's online list to Discord
302
+ */
303
+ async function sendOnlineList(channelId, users) {
304
+ if (users.length === 0) {
305
+ const embed = createVibeEmbed(
306
+ '🤫 Room is quiet...',
307
+ 'No one is currently active in /vibe.'
308
+ );
309
+ return sendMessage(channelId, '', { embeds: [embed] });
310
+ }
311
+
312
+ const fields = users.map(u => {
313
+ const mood = u.mood ? ` (${u.mood})` : '';
314
+ return {
315
+ name: `@${u.handle}${mood}`,
316
+ value: u.one_liner || 'building',
317
+ inline: true
318
+ };
319
+ });
320
+
321
+ const embed = createVibeEmbed(
322
+ `👥 ${users.length} online in /vibe`,
323
+ 'Current activity:',
324
+ 0x2ECC71,
325
+ fields
326
+ );
327
+
328
+ return sendMessage(channelId, '', { embeds: [embed] });
329
+ }
330
+
331
+ /**
332
+ * Handle Discord slash commands
333
+ */
334
+ async function registerSlashCommands(guildId = null) {
335
+ const commands = [
336
+ {
337
+ name: 'vibe',
338
+ description: 'Send message to /vibe',
339
+ options: [
340
+ {
341
+ name: 'message',
342
+ description: 'Message to send',
343
+ type: 3, // STRING
344
+ required: true
345
+ }
346
+ ]
347
+ },
348
+ {
349
+ name: 'status',
350
+ description: 'Update your /vibe status',
351
+ options: [
352
+ {
353
+ name: 'mood',
354
+ description: 'Your current mood/activity',
355
+ type: 3, // STRING
356
+ required: true,
357
+ choices: [
358
+ { name: '🔥 shipping', value: 'shipping' },
359
+ { name: '🐛 debugging', value: 'debugging' },
360
+ { name: '🧠 deep work', value: 'deep' },
361
+ { name: '☕ away', value: 'afk' },
362
+ { name: '🎉 celebrating', value: 'celebrating' },
363
+ { name: '👯 pairing', value: 'pairing' }
364
+ ]
365
+ },
366
+ {
367
+ name: 'note',
368
+ description: 'Optional note about what you\'re working on',
369
+ type: 3, // STRING
370
+ required: false
371
+ }
372
+ ]
373
+ },
374
+ {
375
+ name: 'who',
376
+ description: 'See who\'s online in /vibe'
377
+ }
378
+ ];
379
+
380
+ const endpoint = guildId
381
+ ? `/applications/@me/guilds/${guildId}/commands`
382
+ : '/applications/@me/commands';
383
+
384
+ // Register each command
385
+ for (const command of commands) {
386
+ await discordRequest('POST', endpoint, command);
387
+ }
388
+
389
+ return commands.length;
390
+ }
391
+
392
+ /**
393
+ * Set up Discord bot webhook for receiving interactions
394
+ */
395
+ async function setupInteractionEndpoint(publicKey, endpointUrl) {
396
+ // This would typically be done in Discord Developer Portal
397
+ // But we can validate the setup here
398
+
399
+ if (!publicKey || !endpointUrl) {
400
+ throw new Error('Need both public key and endpoint URL for interactions');
401
+ }
402
+
403
+ // The actual webhook setup happens in Discord Developer Portal
404
+ return {
405
+ message: 'Interaction endpoint configured. Set this URL in Discord Developer Portal:',
406
+ url: endpointUrl,
407
+ publicKey: publicKey
408
+ };
409
+ }
410
+
411
+ module.exports = {
412
+ isConfigured,
413
+ getBotToken,
414
+ getGuildId,
415
+ getBotInfo,
416
+ getGuilds,
417
+ getChannels,
418
+ getMessages,
419
+ sendMessage,
420
+ sendDM,
421
+ createDM,
422
+ processMessage,
423
+ parseVibeCommand,
424
+ notifyActivity,
425
+ notifyStatus,
426
+ forwardFromVibe,
427
+ sendOnlineList,
428
+ createVibeEmbed,
429
+ registerSlashCommands,
430
+ setupInteractionEndpoint
431
+ };
@@ -0,0 +1,299 @@
1
+ /**
2
+ * /vibe Farcaster Bridge
3
+ *
4
+ * Connects /vibe to Farcaster via Neynar API for web3 social integration.
5
+ * - Read: Casts, mentions, replies
6
+ * - Write: Casts, replies
7
+ * - Channel integration: Post to specific channels
8
+ */
9
+
10
+ const config = require('../config');
11
+
12
+ /**
13
+ * Get Farcaster credentials from config
14
+ */
15
+ function getCredentials() {
16
+ const cfg = config.load();
17
+ return {
18
+ apiKey: cfg.neynar_api_key || process.env.NEYNAR_API_KEY || null,
19
+ signerUuid: cfg.farcaster_signer_uuid || process.env.FARCASTER_SIGNER_UUID || null,
20
+ fid: cfg.farcaster_fid || process.env.FARCASTER_FID || null
21
+ };
22
+ }
23
+
24
+ /**
25
+ * Check if Farcaster bridge is configured
26
+ */
27
+ function isConfigured() {
28
+ const creds = getCredentials();
29
+ return !!(creds.apiKey && creds.signerUuid && creds.fid);
30
+ }
31
+
32
+ /**
33
+ * Make authenticated request to Neynar API
34
+ */
35
+ async function neynarRequest(method, endpoint, params = {}, body = null) {
36
+ const { apiKey } = getCredentials();
37
+ if (!apiKey) throw new Error('Neynar API key not configured');
38
+
39
+ const baseUrl = 'https://api.neynar.com/v2';
40
+ let url = `${baseUrl}${endpoint}`;
41
+
42
+ const headers = {
43
+ 'accept': 'application/json',
44
+ 'api_key': apiKey
45
+ };
46
+
47
+ // GET requests: params in URL
48
+ if (method === 'GET' && Object.keys(params).length > 0) {
49
+ url += '?' + new URLSearchParams(params);
50
+ }
51
+
52
+ // POST/PUT requests: body as JSON
53
+ if (body && (method === 'POST' || method === 'PUT')) {
54
+ headers['content-type'] = 'application/json';
55
+ }
56
+
57
+ const response = await fetch(url, {
58
+ method,
59
+ headers,
60
+ body: body ? JSON.stringify(body) : undefined
61
+ });
62
+
63
+ if (!response.ok) {
64
+ const error = await response.text();
65
+ throw new Error(`Neynar API error ${response.status}: ${error}`);
66
+ }
67
+
68
+ return response.json();
69
+ }
70
+
71
+ /**
72
+ * Get user info by FID
73
+ */
74
+ async function getUser(fid = null) {
75
+ const { fid: defaultFid } = getCredentials();
76
+ const targetFid = fid || defaultFid;
77
+
78
+ if (!targetFid) throw new Error('No FID specified');
79
+
80
+ return neynarRequest('GET', '/farcaster/user/bulk', {
81
+ fids: targetFid.toString()
82
+ });
83
+ }
84
+
85
+ /**
86
+ * Get casts from user's feed
87
+ */
88
+ async function getFeed(fid = null, limit = 25) {
89
+ const { fid: defaultFid } = getCredentials();
90
+ const targetFid = fid || defaultFid;
91
+
92
+ if (!targetFid) throw new Error('No FID specified');
93
+
94
+ return neynarRequest('GET', '/farcaster/feed/user', {
95
+ fid: targetFid.toString(),
96
+ limit: limit.toString()
97
+ });
98
+ }
99
+
100
+ /**
101
+ * Get mentions for user
102
+ */
103
+ async function getMentions(fid = null, limit = 25) {
104
+ const { fid: defaultFid } = getCredentials();
105
+ const targetFid = fid || defaultFid;
106
+
107
+ if (!targetFid) throw new Error('No FID specified');
108
+
109
+ return neynarRequest('GET', '/farcaster/notifications', {
110
+ fid: targetFid.toString(),
111
+ type: 'mentions',
112
+ limit: limit.toString()
113
+ });
114
+ }
115
+
116
+ /**
117
+ * Get cast by hash
118
+ */
119
+ async function getCast(castHash) {
120
+ return neynarRequest('GET', '/farcaster/cast', {
121
+ identifier: castHash,
122
+ type: 'hash'
123
+ });
124
+ }
125
+
126
+ /**
127
+ * Publish a cast
128
+ */
129
+ async function publishCast(text, options = {}) {
130
+ const { signerUuid } = getCredentials();
131
+ if (!signerUuid) throw new Error('Signer UUID not configured');
132
+
133
+ const body = {
134
+ signer_uuid: signerUuid,
135
+ text
136
+ };
137
+
138
+ // Reply to another cast
139
+ if (options.replyTo) {
140
+ body.parent = options.replyTo;
141
+ }
142
+
143
+ // Post to specific channel
144
+ if (options.channel) {
145
+ body.channel_id = options.channel;
146
+ }
147
+
148
+ // Add embeds (links, images)
149
+ if (options.embeds && options.embeds.length > 0) {
150
+ body.embeds = options.embeds;
151
+ }
152
+
153
+ return neynarRequest('POST', '/farcaster/cast', {}, body);
154
+ }
155
+
156
+ /**
157
+ * React to a cast (like/recast)
158
+ */
159
+ async function reactToCast(castHash, reaction = 'like') {
160
+ const { signerUuid } = getCredentials();
161
+ if (!signerUuid) throw new Error('Signer UUID not configured');
162
+
163
+ const body = {
164
+ signer_uuid: signerUuid,
165
+ target: castHash,
166
+ reaction_type: reaction // 'like' or 'recast'
167
+ };
168
+
169
+ return neynarRequest('POST', '/farcaster/reaction', {}, body);
170
+ }
171
+
172
+ /**
173
+ * Follow a user
174
+ */
175
+ async function followUser(targetFid) {
176
+ const { signerUuid } = getCredentials();
177
+ if (!signerUuid) throw new Error('Signer UUID not configured');
178
+
179
+ const body = {
180
+ signer_uuid: signerUuid,
181
+ target_fids: [parseInt(targetFid)]
182
+ };
183
+
184
+ return neynarRequest('POST', '/farcaster/follows', {}, body);
185
+ }
186
+
187
+ /**
188
+ * Get trending casts in a channel
189
+ */
190
+ async function getChannelFeed(channelId, limit = 25) {
191
+ return neynarRequest('GET', '/farcaster/feed/channels', {
192
+ channel_ids: channelId,
193
+ limit: limit.toString()
194
+ });
195
+ }
196
+
197
+ /**
198
+ * Search for casts
199
+ */
200
+ async function searchCasts(query, limit = 25) {
201
+ return neynarRequest('GET', '/farcaster/cast/search', {
202
+ q: query,
203
+ limit: limit.toString()
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Get user's followers
209
+ */
210
+ async function getFollowers(fid = null, limit = 100) {
211
+ const { fid: defaultFid } = getCredentials();
212
+ const targetFid = fid || defaultFid;
213
+
214
+ if (!targetFid) throw new Error('No FID specified');
215
+
216
+ return neynarRequest('GET', '/farcaster/followers', {
217
+ fid: targetFid.toString(),
218
+ limit: limit.toString()
219
+ });
220
+ }
221
+
222
+ /**
223
+ * Get user's following
224
+ */
225
+ async function getFollowing(fid = null, limit = 100) {
226
+ const { fid: defaultFid } = getCredentials();
227
+ const targetFid = fid || defaultFid;
228
+
229
+ if (!targetFid) throw new Error('No FID specified');
230
+
231
+ return neynarRequest('GET', '/farcaster/following', {
232
+ fid: targetFid.toString(),
233
+ limit: limit.toString()
234
+ });
235
+ }
236
+
237
+ /**
238
+ * Process cast data into standardized format for /vibe
239
+ */
240
+ function processCast(cast) {
241
+ const author = cast.author;
242
+
243
+ return {
244
+ id: `farcaster:${cast.hash}`,
245
+ channel: 'farcaster',
246
+ type: 'cast',
247
+ from: {
248
+ id: author.fid.toString(),
249
+ handle: author.username,
250
+ name: author.display_name || author.username
251
+ },
252
+ content: cast.text || '[media]',
253
+ timestamp: cast.timestamp,
254
+ hash: cast.hash,
255
+ replies: cast.replies?.count || 0,
256
+ reactions: cast.reactions?.likes_count || 0,
257
+ recasts: cast.reactions?.recasts_count || 0,
258
+ channel_id: cast.channel?.id || null,
259
+ parent_hash: cast.parent_hash || null,
260
+ embeds: cast.embeds || [],
261
+ raw: cast
262
+ };
263
+ }
264
+
265
+ /**
266
+ * Get relevant channels for /vibe users
267
+ */
268
+ function getRecommendedChannels() {
269
+ return [
270
+ { id: 'dev', name: 'Development' },
271
+ { id: 'builders', name: 'Builders' },
272
+ { id: 'startups', name: 'Startups' },
273
+ { id: 'crypto-dev', name: 'Crypto Development' },
274
+ { id: 'base', name: 'Base' },
275
+ { id: 'ethereum', name: 'Ethereum' },
276
+ { id: 'farcaster', name: 'Farcaster' },
277
+ { id: 'design', name: 'Design' },
278
+ { id: 'product', name: 'Product' },
279
+ { id: 'ai', name: 'AI' }
280
+ ];
281
+ }
282
+
283
+ module.exports = {
284
+ isConfigured,
285
+ getCredentials,
286
+ getUser,
287
+ getFeed,
288
+ getMentions,
289
+ getCast,
290
+ publishCast,
291
+ reactToCast,
292
+ followUser,
293
+ getChannelFeed,
294
+ searchCasts,
295
+ getFollowers,
296
+ getFollowing,
297
+ processCast,
298
+ getRecommendedChannels
299
+ };