bloby-bot 0.49.0 → 0.49.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bloby-bot",
3
- "version": "0.49.0",
3
+ "version": "0.49.1",
4
4
  "releaseNotes": [
5
5
  "1. Something great..",
6
6
  "2. ",
@@ -85,6 +85,15 @@ export interface WaStreamState {
85
85
  chunkBuf: string;
86
86
  }
87
87
 
88
+ /** Agent-turn events that carry per-turn content. Broadcast only for dashboard surfaces
89
+ * ('workspace' / 'chat'); suppressed for WhatsApp/Alexa turns so their replies don't
90
+ * bleed into the chat-bubble UI. Non-turn events (bot:idle, bot:error, channel:*) are
91
+ * always broadcast. */
92
+ const CHAT_TURN_EVENTS = new Set([
93
+ 'bot:token', 'bot:response', 'bot:tool',
94
+ 'bot:task-created', 'bot:task-progress', 'bot:task-done',
95
+ ]);
96
+
88
97
  export class ChannelManager {
89
98
  private providers = new Map<ChannelType, ChannelProvider>();
90
99
  private opts: ChannelManagerOpts;
@@ -377,7 +386,7 @@ export class ChannelManager {
377
386
  q = [];
378
387
  this.routingQueues.set(convId, q);
379
388
  }
380
- q.push(target);
389
+ q.push({ ...target, pushedAt: Date.now() });
381
390
  pushMessage(convId, content, attachments, savedFiles);
382
391
  }
383
392
 
@@ -395,9 +404,18 @@ export class ChannelManager {
395
404
  if (!q || q.length === 0) return undefined;
396
405
  const target = q.shift();
397
406
  if (q.length === 0) this.routingQueues.delete(convId);
407
+ if (target?.pushedAt && Date.now() - target.pushedAt > 30_000) {
408
+ log.warn(`[channels] Stale route popped: surface=${target.surface}, age=${Math.round((Date.now() - target.pushedAt) / 1000)}s, to=${target.waSendTo || 'none'}, queueDepth=${q?.length ?? 0}`);
409
+ }
398
410
  return target;
399
411
  }
400
412
 
413
+ /** Return the surface of the current turn's routing target without consuming it.
414
+ * Used by broadcast guards to suppress chat-bubble events for non-dashboard turns. */
415
+ peekCurrentSurface(convId: string): RoutingTarget['surface'] | undefined {
416
+ return this.routingQueues.get(convId)?.[0]?.surface;
417
+ }
418
+
401
419
  /** Drop all pending routes for a conversation — used when the live conversation ends.
402
420
  * Accepts undefined for ergonomics in callers that hold a possibly-undefined convId. */
403
421
  clearRoutes(convId: string | undefined): void {
@@ -883,8 +901,9 @@ export class ChannelManager {
883
901
  return;
884
902
  }
885
903
 
886
- // Mirror streaming + task events to chat clients
887
- broadcastBloby(type, eventData);
904
+ // Mirror non-turn events (bot:idle, bot:error, channel:*) to chat clients.
905
+ // Turn events (tokens, response, tools) go to WhatsApp only via the routing FIFO.
906
+ if (!CHAT_TURN_EVENTS.has(type)) broadcastBloby(type, eventData);
888
907
  }, { botName, humanName }, recentMessages);
889
908
  }
890
909
 
@@ -1006,7 +1025,8 @@ export class ChannelManager {
1006
1025
  return;
1007
1026
  }
1008
1027
 
1009
- broadcastBloby(type, eventData);
1028
+ // Turn events go to Alexa only via the routing FIFO; suppress from chat-bubble.
1029
+ if (!CHAT_TURN_EVENTS.has(type)) broadcastBloby(type, eventData);
1010
1030
  }, { botName, humanName }, recentMessages);
1011
1031
  }
1012
1032
 
@@ -86,6 +86,8 @@ export interface RoutingTarget {
86
86
  assistantBufferKey?: string;
87
87
  /** Original inbound WA message key — kept opaque here, used by the channel to react/quote. */
88
88
  inboundKey?: unknown;
89
+ /** Unix ms when this target was pushed — used to detect stale queue entries. */
90
+ pushedAt?: number;
89
91
  }
90
92
 
91
93
  export interface ChannelProvider {
@@ -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
@@ -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
  }
@@ -2241,7 +2256,7 @@ mint();
2241
2256
  channelManager.pushWithRouting(
2242
2257
  convId,
2243
2258
  { surface: 'chat', waSendTo: waMirrorTo, isSelfChat: true },
2244
- content,
2259
+ `[chat]\n${content}`,
2245
2260
  data.attachments,
2246
2261
  savedFiles,
2247
2262
  );
@@ -274,11 +274,16 @@ 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
+ - **`[chat]`** — the chat bubble in the dashboard. 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
+ - **`[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.
283
+
284
+ 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.
285
+
286
+ **Channel discipline.** Every incoming message is tagged with a surface (e.g. `[chat]`, `[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. Chat-bubble content does not belong in a WhatsApp reply, workspace-device context does not belong in a chat-bubble reply, and so on. 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.
282
287
 
283
288
  ## Marketplace — Getting New Skills
284
289