botschat 0.1.15 → 0.1.16

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 (30) hide show
  1. package/package.json +1 -1
  2. package/packages/api/src/do/connection-do.ts +106 -18
  3. package/packages/api/src/index.ts +49 -1
  4. package/packages/plugin/dist/src/channel.d.ts.map +1 -1
  5. package/packages/plugin/dist/src/channel.js +75 -6
  6. package/packages/plugin/dist/src/channel.js.map +1 -1
  7. package/packages/plugin/dist/src/types.d.ts +1 -0
  8. package/packages/plugin/dist/src/types.d.ts.map +1 -1
  9. package/packages/plugin/package.json +1 -1
  10. package/packages/web/dist/assets/{index-DsWBWQD6.js → index--A7c71kf.js} +1 -1
  11. package/packages/web/dist/assets/{index-CvbTpaza.js → index-CEStVU9o.js} +135 -135
  12. package/packages/web/dist/assets/{index-cm_3YFsA.css → index-CLKSdbmx.css} +1 -1
  13. package/packages/web/dist/assets/{index-dMn_npR3.js → index-Cd5GHqU6.js} +1 -1
  14. package/packages/web/dist/assets/index-D3Vfl8Ll.js +2 -0
  15. package/packages/web/dist/assets/index-DUpmW4Ay.js +2 -0
  16. package/packages/web/dist/assets/index-DfBArjKG.js +1 -0
  17. package/packages/web/dist/assets/{index.esm-DdTIpXjl.js → index.esm-Dc_1yrX1.js} +1 -1
  18. package/packages/web/dist/assets/{web-Dft_LGIH.js → web-CDcVasbM.js} +1 -1
  19. package/packages/web/dist/assets/{web-DIeOUVhn.js → web-D_QoLpUi.js} +1 -1
  20. package/packages/web/dist/index.html +2 -2
  21. package/packages/web/src/App.tsx +24 -4
  22. package/packages/web/src/api.ts +2 -1
  23. package/packages/web/src/components/ChatWindow.tsx +134 -73
  24. package/packages/web/src/components/ScheduleEditor.tsx +120 -47
  25. package/packages/web/src/components/ThreadPanel.tsx +21 -2
  26. package/packages/web/src/foreground.ts +40 -10
  27. package/packages/web/src/store.ts +4 -0
  28. package/packages/web/dist/assets/index-CbCpFrA9.js +0 -2
  29. package/packages/web/dist/assets/index-Ct0m11C8.js +0 -2
  30. package/packages/web/dist/assets/index-GwprVhDP.js +0 -1
@@ -1,18 +1,43 @@
1
1
  /**
2
- * Foreground/background detection notifies the ConnectionDO via WebSocket
3
- * so it knows whether to send push notifications.
2
+ * Foreground/background detection & channel-level focus tracking.
3
+ *
4
+ * Notifies the ConnectionDO via WebSocket so it knows whether to send push
5
+ * notifications and which session the user is currently viewing.
4
6
  */
5
7
 
6
8
  import { Capacitor } from "@capacitor/core";
7
9
  import type { BotsChatWSClient } from "./ws";
8
10
  import { dlog } from "./debug-log";
9
11
 
10
- export function setupForegroundDetection(
12
+ export interface ForegroundOptions {
13
+ wsClient: BotsChatWSClient;
14
+ getActiveSessionKey: () => string | null;
15
+ onResume?: () => void;
16
+ }
17
+
18
+ export interface ForegroundHandle {
19
+ cleanup: () => void;
20
+ /** Re-send the current foreground/background state. Call after WS auth succeeds. */
21
+ resend: () => void;
22
+ }
23
+
24
+ /**
25
+ * Send a focus.update message when the user switches channels/sessions
26
+ * while already in the foreground.
27
+ */
28
+ export function sendFocusUpdate(
11
29
  wsClient: BotsChatWSClient,
12
- onResume?: () => void,
13
- ): () => void {
30
+ sessionKey: string | null,
31
+ ): void {
32
+ wsClient.send({ type: "focus.update", sessionKey });
33
+ dlog.info("Foreground", `Focus updated: ${sessionKey ?? "(none)"}`);
34
+ }
35
+
36
+ export function setupForegroundDetection(opts: ForegroundOptions): ForegroundHandle {
37
+ const { wsClient, getActiveSessionKey, onResume } = opts;
38
+
14
39
  const notifyForeground = () => {
15
- wsClient.send({ type: "foreground.enter" });
40
+ wsClient.send({ type: "foreground.enter", sessionKey: getActiveSessionKey() });
16
41
  onResume?.();
17
42
  dlog.info("Foreground", "Entered foreground");
18
43
  };
@@ -24,19 +49,23 @@ export function setupForegroundDetection(
24
49
 
25
50
  if (Capacitor.isNativePlatform()) {
26
51
  let cleanup: (() => void) | null = null;
52
+ let nativeIsActive = true;
27
53
 
28
54
  import("@capacitor/app").then(({ App }) => {
29
55
  const handle = App.addListener("appStateChange", ({ isActive }) => {
56
+ nativeIsActive = isActive;
30
57
  if (isActive) notifyForeground();
31
58
  else notifyBackground();
32
59
  });
33
60
  cleanup = () => handle.then((h) => h.remove());
34
61
  });
35
62
 
36
- // Report initial foreground state once WS is connected
37
63
  notifyForeground();
38
64
 
39
- return () => cleanup?.();
65
+ return {
66
+ cleanup: () => cleanup?.(),
67
+ resend: () => { if (nativeIsActive) notifyForeground(); else notifyBackground(); },
68
+ };
40
69
  }
41
70
 
42
71
  // Web: Use Page Visibility API
@@ -49,7 +78,8 @@ export function setupForegroundDetection(
49
78
 
50
79
  if (!document.hidden) notifyForeground();
51
80
 
52
- return () => {
53
- document.removeEventListener("visibilitychange", handleVisibilityChange);
81
+ return {
82
+ cleanup: () => document.removeEventListener("visibilitychange", handleVisibilityChange),
83
+ resend: () => { if (!document.hidden) notifyForeground(); else notifyBackground(); },
54
84
  };
55
85
  }
@@ -15,6 +15,10 @@ export type ChatMessage = {
15
15
  /** Tracks which action blocks have been resolved, keyed by prompt hash */
16
16
  resolvedActions?: Record<string, { value: string; label: string }>;
17
17
  isEncryptedLocked?: boolean;
18
+ /** Whether the message text was E2E encrypted (bitmask from API: bit0=text, bit1=media) */
19
+ encrypted?: boolean | number;
20
+ /** Whether the media binary was E2E encrypted (derived from sender + encrypted flag) */
21
+ mediaEncrypted?: boolean;
18
22
  };
19
23
 
20
24
  export type ActiveView = "messages" | "automations";
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-DIeOUVhn.js","assets/index-CvbTpaza.js","assets/index-cm_3YFsA.css"])))=>i.map(i=>d[i]);
2
- import{r as o,f as t}from"./index-CvbTpaza.js";const n=o("SocialLogin",{web:()=>t(()=>import("./web-DIeOUVhn.js"),__vite__mapDeps([0,1,2])).then(e=>new e.SocialLoginWeb)});export{n as SocialLogin};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-Dft_LGIH.js","assets/index-CvbTpaza.js","assets/index-cm_3YFsA.css"])))=>i.map(i=>d[i]);
2
- import{r as p,f as r}from"./index-CvbTpaza.js";const o=p("App",{web:()=>r(()=>import("./web-Dft_LGIH.js"),__vite__mapDeps([0,1,2])).then(e=>new e.AppWeb)});export{o as App};
@@ -1 +0,0 @@
1
- import{r as i}from"./index-CvbTpaza.js";const t=i("PushNotifications",{});export{t as PushNotifications};