bloby-bot 0.49.0 → 0.49.2

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.
@@ -2,7 +2,7 @@ import { useState } from 'react';
2
2
  import { Streamdown } from 'streamdown';
3
3
  import { code } from '@streamdown/code';
4
4
  import 'streamdown/styles.css';
5
- import { Paperclip, Copy, Check, ExternalLink, Mic, Play, Pause } from 'lucide-react';
5
+ import { Paperclip, Copy, Check, ExternalLink, Mic, Play, Pause, Laptop, Smartphone, Monitor, Globe, Volume2 } from 'lucide-react';
6
6
  import AudioBubble from './AudioBubble';
7
7
  import EnvForm, { type EnvGroupData, type EnvField } from './EnvForm';
8
8
  import BlobyImageCard from './BlobyImageCard';
@@ -29,6 +29,24 @@ function formatTime(iso: string): string {
29
29
  }
30
30
  }
31
31
 
32
+ /** Parse the leading channel tag from content, e.g. "[Mac]\n..." → { tag: "Mac", body: "..." } */
33
+ function parseChannelTag(text: string): { tag: string | null; body: string } {
34
+ const m = text.match(/^\[([^\]]+)\]\n([\s\S]*)$/);
35
+ if (!m) return { tag: null, body: text };
36
+ return { tag: m[1].split('|')[0].trim(), body: m[2] };
37
+ }
38
+
39
+ function ChannelIcon({ tag }: { tag: string | null }) {
40
+ const cls = 'h-3 w-3 opacity-60';
41
+ if (!tag) return null;
42
+ if (tag === 'Mac') return <Laptop className={cls} />;
43
+ if (tag === 'WhatsApp') return <Smartphone className={cls} />;
44
+ if (tag === 'workspace') return <Monitor className={cls} />;
45
+ if (tag === 'PWA') return <Globe className={cls} />;
46
+ if (tag === 'Alexa') return <Volume2 className={cls} />;
47
+ return null;
48
+ }
49
+
32
50
  /** Convert channel-pair URLs (any format) into markdown links so the buttons render */
33
51
  function preprocessContent(text: string): string {
34
52
  let out = text;
@@ -172,6 +190,9 @@ export default function MessageBubble({ role, content, timestamp, hasAttachments
172
190
  const isUser = role === 'user';
173
191
  const time = timestamp ? formatTime(timestamp) : '';
174
192
 
193
+ // Strip channel tag from user messages for clean display
194
+ const { tag: channelTag, body: displayContent } = isUser ? parseChannelTag(content) : { tag: null, body: content };
195
+
175
196
  // Separate image and document attachments
176
197
  const imageAtts = attachments?.filter((a) => a.mediaType?.startsWith('image/')) || [];
177
198
  const docAtts = attachments?.filter((a) => !a.mediaType?.startsWith('image/')) || [];
@@ -187,7 +208,7 @@ export default function MessageBubble({ role, content, timestamp, hasAttachments
187
208
  return (
188
209
  <div className="flex flex-col items-end gap-0.5">
189
210
  <div className="group relative max-w-[85%]">
190
- <CopyButton text={content} />
211
+ <CopyButton text={displayContent} />
191
212
  <div className="rounded-2xl px-4 py-2.5 text-sm leading-relaxed whitespace-pre-wrap bg-primary text-primary-foreground break-words">
192
213
  {/* Image thumbnails */}
193
214
  {imageUrls.length > 0 && (
@@ -224,7 +245,7 @@ export default function MessageBubble({ role, content, timestamp, hasAttachments
224
245
  </div>
225
246
  )}
226
247
  {/* Text content */}
227
- {content}
248
+ {displayContent}
228
249
  {/* Inline audio bar */}
229
250
  {audioData && (
230
251
  <div className="mt-2 pt-2 border-t border-white/10">
@@ -233,7 +254,16 @@ export default function MessageBubble({ role, content, timestamp, hasAttachments
233
254
  )}
234
255
  </div>
235
256
  </div>
236
- {time && <span className="text-[10px] text-muted-foreground/50 px-1 self-end">{time}</span>}
257
+ {/* Timestamp + channel icon */}
258
+ <div className="flex items-center gap-1 px-1 self-end">
259
+ {channelTag && (
260
+ <span className="flex items-center gap-0.5 text-[10px] text-muted-foreground/40">
261
+ <ChannelIcon tag={channelTag} />
262
+ {channelTag}
263
+ </span>
264
+ )}
265
+ {time && <span className="text-[10px] text-muted-foreground/50">{time}</span>}
266
+ </div>
237
267
  </div>
238
268
  );
239
269
  }
@@ -197,6 +197,7 @@ export function useBlobyChat(ws: WsClient | null, triggerReload?: number, enable
197
197
  });
198
198
  }),
199
199
  ws.on('bot:response', (data: { conversationId: string; messageId?: string; content: string }) => {
200
+ if (conversationIdRef.current && data.conversationId !== conversationIdRef.current) return;
200
201
  setConversationId(data.conversationId);
201
202
 
202
203
  // Strip text that was already committed as a partial message
@@ -269,7 +270,7 @@ export function useBlobyChat(ws: WsClient | null, triggerReload?: number, enable
269
270
  ]);
270
271
  }),
271
272
  // Cross-device sync: append message from another client
272
- ws.on('chat:sync', (data: { conversationId: string; message: { role: string; content: string; timestamp: string } }) => {
273
+ ws.on('chat:sync', (data: { conversationId: string; message: { role: string; content: string; timestamp: string; attachments?: StoredAttachment[] } }) => {
273
274
  if (conversationIdRef.current && data.conversationId !== conversationIdRef.current) return;
274
275
  setMessages((msgs) => [
275
276
  ...msgs,
@@ -278,6 +279,8 @@ export function useBlobyChat(ws: WsClient | null, triggerReload?: number, enable
278
279
  role: data.message.role as 'user' | 'assistant',
279
280
  content: data.message.content,
280
281
  timestamp: data.message.timestamp,
282
+ hasAttachments: !!(data.message.attachments?.length),
283
+ attachments: data.message.attachments,
281
284
  },
282
285
  ]);
283
286
  }),
@@ -33,7 +33,7 @@ export function saveAttachment(att: { type: 'image' | 'file'; name: string; medi
33
33
  const ext = extFromName || extFromMime[att.mediaType] || 'bin';
34
34
 
35
35
  const filename = `${stamp}_${rand}.${ext}`;
36
- const relPath = `files/${category}/${filename}`;
36
+ const relPath = `${category}/${filename}`;
37
37
 
38
38
  const dir = category === 'images' ? paths.filesImages : paths.filesDocuments;
39
39
  const absPath = `${dir}/${filename}`;
@@ -1451,10 +1451,13 @@ mint();
1451
1451
  const ownPhone = waStatus?.connected ? (waStatus.info?.phoneNumber as string | undefined) : undefined;
1452
1452
  const waMirrorTo = ownPhone ? `${ownPhone}@s.whatsapp.net` : undefined;
1453
1453
 
1454
+ // Channel tag so the agent knows the message came from the dashboard workspace
1455
+ // (parallel to [WhatsApp ...] and [Alexa ...] tags). DB + chat:sync use the raw
1456
+ // content so user-facing UIs show what was typed.
1454
1457
  channelManager.pushWithRouting(
1455
1458
  convId,
1456
1459
  { surface: 'workspace', waSendTo: waMirrorTo, isSelfChat: true },
1457
- content,
1460
+ `[workspace]\n${content}`,
1458
1461
  agentAttachments,
1459
1462
  savedFiles,
1460
1463
  );
@@ -1832,6 +1835,8 @@ mint();
1832
1835
  *
1833
1836
  * Factored so adding a new surface (here: workspace) cannot drift from the chat WS
1834
1837
  * behaviour — same buffer, same persistence, same restart timing. */
1838
+ const CHAT_TURN_EVENTS = new Set(['bot:token', 'bot:response', 'bot:tool', 'bot:task-created', 'bot:task-progress', 'bot:task-done']);
1839
+
1835
1840
  function createSharedChatOnMessage(
1836
1841
  convId: string,
1837
1842
  model: string,
@@ -1839,12 +1844,17 @@ mint();
1839
1844
  waState: ReturnType<typeof channelManager.createWaStreamState>,
1840
1845
  ) {
1841
1846
  return async (type: string, eventData: any) => {
1847
+ // Capture surface BEFORE routeWaStreamEvent consumes the routing target on bot:response.
1848
+ // Used below to suppress chat-bubble broadcasts for non-dashboard turns.
1849
+ const triggerSurface = channelManager.peekCurrentSurface(convId);
1850
+ const isDashboardTurn = !triggerSurface || triggerSurface === 'workspace' || triggerSurface === 'chat';
1851
+
1842
1852
  if (type === 'bot:typing') {
1843
1853
  currentStreamConvId = convId;
1844
1854
  currentStreamBuffer = '';
1845
1855
  agentQueryActive = true;
1846
1856
  }
1847
- if (type === 'bot:token' && eventData.token) {
1857
+ if (type === 'bot:token' && eventData.token && isDashboardTurn) {
1848
1858
  currentStreamBuffer += eventData.token;
1849
1859
  }
1850
1860
 
@@ -1895,6 +1905,11 @@ mint();
1895
1905
  }
1896
1906
  }
1897
1907
 
1908
+ // Suppress agent-turn events from non-dashboard surfaces. WhatsApp/Alexa replies
1909
+ // are already delivered via the routing FIFO; broadcasting them would bleed
1910
+ // content into chat-bubble clients that weren't part of that conversation.
1911
+ if (CHAT_TURN_EVENTS.has(type) && !isDashboardTurn) return;
1912
+
1898
1913
  broadcastBloby(type, eventData);
1899
1914
  };
1900
1915
  }
@@ -2172,10 +2187,17 @@ mint();
2172
2187
  role: 'user', content, meta,
2173
2188
  });
2174
2189
 
2175
- // Broadcast user message to other clients
2190
+ // Broadcast user message to other clients (include saved attachment metadata)
2176
2191
  broadcastBlobyExcept(ws, 'chat:sync', {
2177
2192
  conversationId: convId,
2178
- message: { role: 'user', content, timestamp: new Date().toISOString() },
2193
+ message: {
2194
+ role: 'user',
2195
+ content,
2196
+ timestamp: new Date().toISOString(),
2197
+ attachments: savedFiles.length
2198
+ ? savedFiles.map((f) => ({ type: f.type, name: f.name, mediaType: f.mediaType, filePath: f.relPath }))
2199
+ : undefined,
2200
+ },
2179
2201
  });
2180
2202
  } catch (err: any) {
2181
2203
  log.warn(`[bloby] DB persist error: ${err.message}`);
@@ -2238,10 +2260,12 @@ mint();
2238
2260
  const ownPhone = waStatus?.connected ? (waStatus.info?.phoneNumber as string | undefined) : undefined;
2239
2261
  const waMirrorTo = ownPhone ? `${ownPhone}@s.whatsapp.net` : undefined;
2240
2262
  log.info(`[orchestrator] Pushing message into live conversation (waMirror=${waMirrorTo || 'none'})`);
2263
+ // Don't prepend [PWA] if content already carries its own channel tag (e.g. [Mac] from Morphy)
2264
+ const alreadyTagged = /^\[[^\]]+\]\n/.test(content);
2241
2265
  channelManager.pushWithRouting(
2242
2266
  convId,
2243
2267
  { surface: 'chat', waSendTo: waMirrorTo, isSelfChat: true },
2244
- content,
2268
+ alreadyTagged ? content : `[PWA]\n${content}`,
2245
2269
  data.attachments,
2246
2270
  savedFiles,
2247
2271
  );
@@ -274,11 +274,17 @@ If your human asks you to update a skill's behavior, edit the files INSIDE `skil
274
274
  - Correct: `skills/my-skill/SCRIPT.md`
275
275
  - Wrong: `SCRIPT.md` (this writes to workspace root!)
276
276
 
277
- ## Channels (WhatsApp, Telegram, Discord, etc.)
277
+ ## Channels (chat, workspace, WhatsApp, Telegram, Discord, etc.)
278
278
 
279
- You can communicate through messaging channels beyond the chat bubble. Channel support is provided by **skills** — if your human wants to use WhatsApp, Telegram, Discord, or any other channel, check the Bloby Marketplace for the corresponding skill. They install it, the skill teaches you everything you need to know about that channel.
279
+ You can communicate through several surfaces at once. The two built-in ones are:
280
280
 
281
- **Channel discipline.** Every incoming message is tagged with a surface (e.g. `[WhatsApp | ... | role | name]`)that tag is the truth about who you're talking to and where your reply will go. The supervisor pins each turn's reply to the surface that triggered it; concurrent inbounds from another channel cannot redirect this turn. **Don't infer the channel from prior messages, conversation drift, or what feels right** read the tag on the current turn and respond accordingly. Chat-bubble content does not belong in a WhatsApp reply, and WhatsApp-specific context (group dynamics, customer back-and-forth, etc.) does not belong in a chat-bubble reply. If a tag isn't present, you're on the chat bubble. If you ever feel the urge to mention a different channel's content in your reply, stop and re-check the tag.
281
+ - **`[PWA]`** — the chat bubble in the dashboard (web app / PWA). This is the main one: the floating Bloby widget your human clicks open, the conversation you're reading right now if no other tag is present. Treat it as your home base.
282
+ - **`[Mac]`** — the Morphy native Mac app living in the MacBook notch. Your human held a hotkey, spoke, and Morphy sent the transcript here. Screenshots of their screen may be attached. Keep replies concise — they'll be spoken aloud via TTS. No markdown, no bullet lists — plain spoken sentences only.
283
+ - **`[workspace]`** — a chat-shaped widget your human placed somewhere inside their dashboard *workspace*. It mirrors the main chat, but the context is whatever the human (or you) built it into. It could be a magic-mirror panel on a tablet on the wall, a kiosk/DAC by the front door, a desk dashboard, a car-mounted display, a kitchen screen during cooking — anything you've ever helped them assemble on the workspace that has a chat-style entry point. **Check `MEMORY.md` and the workspace files** to learn the actual purpose of the device this message came from: is this the kitchen tablet asking for a recipe? The hallway mirror asking what's on today's schedule? The garage panel asking about the car? Tailor tone, brevity, and content to that role. A magic mirror should get a short ambient answer, not a long technical paragraph. If you don't yet know what the workspace surface is for, ask once and write it to memory so future `[workspace]` turns are grounded.
284
+
285
+ Beyond those, your human can install additional channels (WhatsApp, Telegram, Discord, Alexa…) as **skills** from the Bloby Marketplace. Each channel skill teaches you the conventions for that surface.
286
+
287
+ **Channel discipline.** Every incoming message is tagged with a surface (e.g. `[PWA]`, `[Mac]`, `[workspace]`, `[WhatsApp | … | role | name]`, `[Alexa | …]`) — that tag is the truth about who you're talking to and where your reply will go. The supervisor pins each turn's reply to the surface that triggered it; concurrent inbounds from another channel cannot redirect this turn. **Don't infer the channel from prior messages, conversation drift, or what feels right** — read the tag on the current turn and respond accordingly. If a tag isn't present, you're on the PWA chat bubble. If you ever feel the urge to mention a different channel's content in your reply, stop and re-check the tag.
282
288
 
283
289
  ## Marketplace — Getting New Skills
284
290
 
@@ -1 +0,0 @@
1
- import{i as e}from"./bloby-DU3UB3X1.js";export{e as Mermaid};