@burdenoff/fe-libs 2026.1114.7 → 2026.1114.9

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.
@@ -132,6 +132,7 @@ export * from './ui/AssistantAvatar';
132
132
  export * from './ui/AssistantToolActivity';
133
133
  export * from './ui/AssistantSpeechProvider';
134
134
  export * from './ui/useVoiceSession';
135
+ export * from './ui/transcriptAutoOpenSlot';
135
136
  export * from './clipboard';
136
137
  export * from './context';
137
138
  export * from './attachmentSources';
@@ -224,6 +225,7 @@ export * from './history/historyErrors';
224
225
  export * from './history/historyControls';
225
226
  export * from './history/historyMapping';
226
227
  export * from './history/profileBoundStorage';
228
+ export * from './profileFollowingStorage';
227
229
  export * from './history/historyStore';
228
230
  export * from './history/historyStatus';
229
231
  export * from './history/stampRegistry';
@@ -0,0 +1,28 @@
1
+ import { StateStorage } from 'zustand/middleware';
2
+ export interface ProfileFollowingStorage extends StateStorage {
3
+ getItem(name: string): string | null;
4
+ setItem(name: string, value: string): void;
5
+ removeItem(name: string): void;
6
+ /** The key the state was last read from, or null before the first read. */
7
+ boundKey(): string | null;
8
+ /** True when `name` still resolves to the key the state was read from. */
9
+ isCurrent(name: string): boolean;
10
+ /**
11
+ * True once after a read moved the binding to a different key (another
12
+ * profile), then false until the next such move. Reading it clears it.
13
+ */
14
+ takeProfileChange(): boolean;
15
+ }
16
+ export interface ProfileFollowingStorageOptions {
17
+ /** The storage that actually reads and writes, resolving the key itself. */
18
+ inner: StateStorage;
19
+ /**
20
+ * The key `inner` will use for `name` right now: the profile-scoped key, or
21
+ * `name` itself when no profile is active. Must agree with `inner`.
22
+ */
23
+ resolveKey: (name: string) => string;
24
+ /** Told about each write dropped because the profile changed under it. */
25
+ onDropped?: (name: string) => void;
26
+ }
27
+ /** See the module docblock. */
28
+ export declare function createProfileFollowingStorage(options: ProfileFollowingStorageOptions): ProfileFollowingStorage;
@@ -0,0 +1,44 @@
1
+ // src/shared/assistant/profileFollowingStorage.ts
2
+ function e(e) {
3
+ let { inner: t, resolveKey: n, onDropped: r } = e, i = null, a = !1, o = (e) => {
4
+ try {
5
+ return n(e);
6
+ } catch {
7
+ return null;
8
+ }
9
+ }, s = (e) => {
10
+ let t = o(e);
11
+ return i !== null && t === i || (r?.(e), !1);
12
+ };
13
+ return {
14
+ getItem(e) {
15
+ let n = o(e);
16
+ if (n === null) return null;
17
+ i !== null && n !== i && (a = !0), i = n;
18
+ let r;
19
+ try {
20
+ r = t.getItem(e);
21
+ } catch {
22
+ return null;
23
+ }
24
+ return typeof r == "string" ? r : null;
25
+ },
26
+ setItem(e, n) {
27
+ s(e) && t.setItem(e, n);
28
+ },
29
+ removeItem(e) {
30
+ s(e) && t.removeItem(e);
31
+ },
32
+ boundKey() {
33
+ return i;
34
+ },
35
+ isCurrent(e) {
36
+ return i !== null && o(e) === i;
37
+ },
38
+ takeProfileChange() {
39
+ let e = a;
40
+ return a = !1, e;
41
+ }
42
+ };
43
+ }
44
+ export { e as createProfileFollowingStorage };
@@ -257,6 +257,28 @@ export declare function resolveActiveModeSandbox(state: {
257
257
  * by mistake as a second source of truth.
258
258
  */
259
259
  export declare function mergePersistedAssistantState<S extends object>(persisted: unknown, current: S): S;
260
+ /**
261
+ * ★★ HISTORICAL — and it must stay exactly this (decision D12).
262
+ *
263
+ * The `hb-` is from HealthyBowl, where this store was born; EVERY product
264
+ * that mounts the shared assistant persists under this name. It cannot
265
+ * collide between products: localStorage is per ORIGIN and each product
266
+ * app is its own origin, and within one the key is profile-scoped
267
+ * (`bf-p-<profileId>-hb-ai-assistant`, `createProfileScopedStorage`).
268
+ *
269
+ * ★★ Renaming it ORPHANS every user's saved conversations, voice and
270
+ * language preferences and write-mode consent in every product: the new
271
+ * name starts empty, and nothing reads the old one again. A rename needs
272
+ * a migration that copies the old key first — not a find-and-replace.
273
+ */
274
+ export declare const ASSISTANT_STORE_NAME = "hb-ai-assistant";
275
+ /**
276
+ * Re-read the store when the tab's active profile is no longer the one it was
277
+ * read for (BOFF-8009). Resolves true when it moved to another profile, false
278
+ * when there was nothing to do. Called on every profile-storage change; most of
279
+ * those (a token refresh, a workspace switch) keep the same profile.
280
+ */
281
+ export declare function followActiveProfile(): Promise<boolean>;
260
282
  export declare const useAssistantStore: import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<AssistantState>, "setState" | "persist"> & {
261
283
  setState(partial: AssistantState | Partial<AssistantState> | ((state: AssistantState) => AssistantState | Partial<AssistantState>), replace?: false | undefined): unknown;
262
284
  setState(state: AssistantState | ((state: AssistantState) => AssistantState), replace: true): unknown;
@@ -270,4 +292,11 @@ export declare const useAssistantStore: import('zustand').UseBoundStore<Omit<imp
270
292
  getOptions: () => Partial<import('zustand/middleware').PersistOptions<AssistantState, unknown, unknown>>;
271
293
  };
272
294
  }>;
295
+ /**
296
+ * Keep the store on the tab's active profile (BOFF-8009): an account switch,
297
+ * sign-in or sign-out in THIS tab changes the profile without a reload and
298
+ * announces it with `PROFILE_STORAGE_CHANGE_EVENT`; the store then re-reads for
299
+ * the new profile. Until it has, its writes are dropped. Returns the unsubscribe.
300
+ */
301
+ export declare function followProfileChanges(target: Pick<Window, 'addEventListener' | 'removeEventListener'>): () => void;
273
302
  export {};
@@ -1,55 +1,56 @@
1
- import { createProfileScopedStorage as e } from "../utils/profileScopedStorage.js";
2
- import "../../shared-utils.js";
3
- import { restoreAutoRouting as t } from "./autoRouting.js";
4
- import { createGuardedAssistantStorage as n } from "./guardedStorage.js";
5
- import { DEFAULT_VOICE_GRACE_MS as r, resolveVoiceGraceMs as i } from "./voice/handsFree.js";
6
- import { resolveStoredHandsFree as a } from "./voice/handsfree/handsFreeSetting.js";
7
- import { normaliseHistoryTitle as o } from "./history/historyControls.js";
8
- import { getHistoryStamp as s, historyOpenFilter as c, notifyAssistantStorageFull as l, offerHistoryRename as u } from "./history/stampRegistry.js";
9
- import { forgetLiveTurns as d } from "./liveTurns.js";
10
- import { LEGACY_WRITE_CONSENT_KEY as f, restoreAcknowledgedWriteModes as p, withWriteModeAcknowledged as m } from "./writeModeConsent.js";
11
- import { create as h } from "zustand";
12
- import { persist as g } from "zustand/middleware";
1
+ import { PROFILE_STORAGE_CHANGE_EVENT as e } from "../providers/shell/ProfileStorageManager.js";
2
+ import { getProfileScopedKey as t, profileScopedStateStorage as n } from "../utils/profileScopedStorage.js";
3
+ import { restoreAutoRouting as r } from "./autoRouting.js";
4
+ import { createGuardedAssistantStorage as i } from "./guardedStorage.js";
5
+ import { DEFAULT_VOICE_GRACE_MS as a, resolveVoiceGraceMs as o } from "./voice/handsFree.js";
6
+ import { resolveStoredHandsFree as s } from "./voice/handsfree/handsFreeSetting.js";
7
+ import { normaliseHistoryTitle as c } from "./history/historyControls.js";
8
+ import { getHistoryStamp as l, historyOpenFilter as u, notifyAssistantStorageFull as d, offerHistoryRename as f } from "./history/stampRegistry.js";
9
+ import { forgetLiveTurns as p } from "./liveTurns.js";
10
+ import { createProfileFollowingStorage as m } from "./profileFollowingStorage.js";
11
+ import { LEGACY_WRITE_CONSENT_KEY as h, restoreAcknowledgedWriteModes as g, withWriteModeAcknowledged as _ } from "./writeModeConsent.js";
12
+ import { create as v } from "zustand";
13
+ import { createJSONStorage as y, persist as b } from "zustand/middleware";
13
14
  // src/shared/assistant/store.ts
14
- function _() {
15
+ function x() {
15
16
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
16
17
  }
17
- function v(e) {
18
+ function S(e) {
18
19
  let t = e.sandboxesByMode[e.mode]?.sandboxId;
19
20
  return t ? {
20
21
  sandboxId: t,
21
22
  mode: e.mode
22
23
  } : null;
23
24
  }
24
- var y = /* @__PURE__ */ new Set([f, "sandboxWriteCapabilities"]);
25
- function b(e, n) {
26
- let r = typeof e == "object" && e ? Object.fromEntries(Object.entries(e).filter(([e]) => !y.has(e))) : {};
25
+ var C = /* @__PURE__ */ new Set([h, "sandboxWriteCapabilities"]);
26
+ function w(e, t) {
27
+ let n = typeof e == "object" && e ? Object.fromEntries(Object.entries(e).filter(([e]) => !C.has(e))) : {};
27
28
  return {
29
+ ...t,
28
30
  ...n,
29
- ...r,
30
- acknowledgedWriteModes: p(e),
31
- autoRouting: t(e),
32
- voiceGraceMs: i(r.voiceGraceMs),
33
- handsFreeInterrupt: a(r.handsFreeInterrupt),
34
- handsFreeStreamNoticeAccepted: x(r.handsFreeStreamNoticeAccepted)
31
+ acknowledgedWriteModes: g(e),
32
+ autoRouting: r(e),
33
+ voiceGraceMs: o(n.voiceGraceMs),
34
+ handsFreeInterrupt: s(n.handsFreeInterrupt),
35
+ handsFreeStreamNoticeAccepted: T(n.handsFreeStreamNoticeAccepted)
35
36
  };
36
37
  }
37
- function x(e) {
38
+ function T(e) {
38
39
  return typeof e == "string" && e !== "" && e.length <= 64 ? e : null;
39
40
  }
40
- function S(e, t, n) {
41
+ function E(e, t, n) {
41
42
  let r = new Set(t);
42
43
  n && e.activeConversationId !== null && r.delete(e.activeConversationId);
43
44
  let i = e.conversations.filter((e) => r.has(e.id));
44
45
  if (i.length === 0) return {};
45
- d(i.flatMap((e) => e.messages.map((e) => e.id)));
46
+ p(i.flatMap((e) => e.messages.map((e) => e.id)));
46
47
  let a = e.conversations.filter((e) => !r.has(e.id)), o = { ...e.processingByConversationId };
47
48
  for (let e of r) delete o[e];
48
49
  if (e.activeConversationId === null || !r.has(e.activeConversationId)) return {
49
50
  conversations: a,
50
51
  processingByConversationId: o
51
52
  };
52
- let s = a.find(c());
53
+ let s = a.find(u());
53
54
  return {
54
55
  conversations: a,
55
56
  processingByConversationId: o,
@@ -60,26 +61,47 @@ function S(e, t, n) {
60
61
  } : {}
61
62
  };
62
63
  }
63
- var C = h()(g((e, t) => ({
64
- conversations: [],
65
- activeConversationId: null,
66
- mode: "assistant",
67
- autoRouting: !0,
68
- processingByConversationId: {},
69
- conversationListOpen: !1,
70
- sandboxesByMode: {},
71
- sandboxWriteCapabilities: {},
72
- pendingPrompt: null,
73
- acknowledgedWriteModes: [],
74
- autoSpeakEnabled: !1,
75
- assistantLanguage: null,
76
- replyLanguage: null,
77
- preferredVoices: {},
78
- voiceGraceMs: r,
79
- handsFreeInterrupt: !1,
80
- handsFreeStreamNoticeAccepted: null,
64
+ function D() {
65
+ return {
66
+ conversations: [],
67
+ activeConversationId: null,
68
+ mode: "assistant",
69
+ autoRouting: !0,
70
+ processingByConversationId: {},
71
+ conversationListOpen: !1,
72
+ sandboxesByMode: {},
73
+ sandboxWriteCapabilities: {},
74
+ pendingPrompt: null,
75
+ acknowledgedWriteModes: [],
76
+ autoSpeakEnabled: !1,
77
+ assistantLanguage: null,
78
+ replyLanguage: null,
79
+ preferredVoices: {},
80
+ voiceGraceMs: a,
81
+ handsFreeInterrupt: !1,
82
+ handsFreeStreamNoticeAccepted: null
83
+ };
84
+ }
85
+ var O = "hb-ai-assistant", k = m({
86
+ inner: n,
87
+ resolveKey: t
88
+ });
89
+ function A(e, t) {
90
+ return k.takeProfileChange() ? (p(t.conversations.flatMap((e) => e.messages.map((e) => e.id))), w(e, {
91
+ ...t,
92
+ ...D()
93
+ })) : w(e, t);
94
+ }
95
+ async function j() {
96
+ return !k.isCurrent("hb-ai-assistant") && (await N.persist.rehydrate(), !0);
97
+ }
98
+ function M(e) {
99
+ return typeof window < "u" && typeof window.addEventListener == "function" && P(window), e;
100
+ }
101
+ var N = M(v()(b((e, t) => ({
102
+ ...D(),
81
103
  createConversation: (n, r, i) => {
82
- let a = _(), o = (/* @__PURE__ */ new Date()).toISOString(), c = r === void 0 && t().autoRouting, l = i?.routedBy ?? (c ? "auto" : void 0), u = r ?? (c ? "assistant" : t().mode), d = s(), f = {
104
+ let a = x(), o = (/* @__PURE__ */ new Date()).toISOString(), s = r === void 0 && t().autoRouting, c = i?.routedBy ?? (s ? "auto" : void 0), u = r ?? (s ? "assistant" : t().mode), d = l(), f = {
83
105
  id: a,
84
106
  title: n || "New conversation",
85
107
  mode: u,
@@ -87,7 +109,7 @@ var C = h()(g((e, t) => ({
87
109
  backendSessionId: null,
88
110
  createdAt: o,
89
111
  updatedAt: o,
90
- ...l ? { routedBy: l } : {},
112
+ ...c ? { routedBy: c } : {},
91
113
  ...d ? { sync: {
92
114
  v: 1,
93
115
  ...d,
@@ -99,7 +121,7 @@ var C = h()(g((e, t) => ({
99
121
  activeConversationId: a,
100
122
  conversationListOpen: !1,
101
123
  mode: u,
102
- autoRouting: l === "auto"
124
+ autoRouting: c === "auto"
103
125
  })), a;
104
126
  },
105
127
  deleteConversation: (t) => e((e) => {
@@ -108,7 +130,7 @@ var C = h()(g((e, t) => ({
108
130
  conversations: n,
109
131
  processingByConversationId: r
110
132
  };
111
- let i = n.find(c());
133
+ let i = n.find(u());
112
134
  return {
113
135
  conversations: n,
114
136
  processingByConversationId: r,
@@ -120,8 +142,8 @@ var C = h()(g((e, t) => ({
120
142
  };
121
143
  }),
122
144
  renameConversation: (t, n) => {
123
- let r = o(n);
124
- r && (u(t, r) || e((e) => ({ conversations: e.conversations.map((e) => e.id === t ? {
145
+ let r = c(n);
146
+ r && (f(t, r) || e((e) => ({ conversations: e.conversations.map((e) => e.id === t ? {
125
147
  ...e,
126
148
  title: r,
127
149
  updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -269,42 +291,24 @@ var C = h()(g((e, t) => ({
269
291
  let r = { ...e.sandboxWriteCapabilities };
270
292
  return n === null ? delete r[t] : r[t] = { ...n }, { sandboxWriteCapabilities: r };
271
293
  }),
272
- resetStore: () => e({
273
- conversations: [],
274
- activeConversationId: null,
275
- mode: "assistant",
276
- autoRouting: !0,
277
- processingByConversationId: {},
278
- conversationListOpen: !1,
279
- sandboxesByMode: {},
280
- sandboxWriteCapabilities: {},
281
- pendingPrompt: null,
282
- acknowledgedWriteModes: [],
283
- autoSpeakEnabled: !1,
284
- assistantLanguage: null,
285
- replyLanguage: null,
286
- preferredVoices: {},
287
- voiceGraceMs: r,
288
- handsFreeInterrupt: !1,
289
- handsFreeStreamNoticeAccepted: null
290
- }),
294
+ resetStore: () => e(D()),
291
295
  submitPrompt: (t) => e({ pendingPrompt: t }),
292
296
  consumePendingPrompt: () => {
293
297
  let n = t().pendingPrompt;
294
298
  return n !== null && e({ pendingPrompt: null }), n;
295
299
  },
296
- acknowledgeWriteMode: (t) => e((e) => ({ acknowledgedWriteModes: m(e.acknowledgedWriteModes, t) })),
300
+ acknowledgeWriteMode: (t) => e((e) => ({ acknowledgedWriteModes: _(e.acknowledgedWriteModes, t) })),
297
301
  setAutoSpeak: (t) => e({ autoSpeakEnabled: t }),
298
302
  setAssistantLanguage: (t) => e({ assistantLanguage: t }),
299
303
  setReplyLanguage: (t) => e({ replyLanguage: t }),
300
304
  setVoiceGraceMs: (t) => {
301
- i(t) === t && e({ voiceGraceMs: i(t) });
305
+ o(t) === t && e({ voiceGraceMs: o(t) });
302
306
  },
303
307
  setHandsFreeInterrupt: (t) => {
304
- e({ handsFreeInterrupt: a(t) });
308
+ e({ handsFreeInterrupt: s(t) });
305
309
  },
306
310
  acceptHandsFreeStreamNotice: (t) => {
307
- let n = x(t);
311
+ let n = T(t);
308
312
  n !== null && e({ handsFreeStreamNoticeAccepted: n });
309
313
  },
310
314
  setPreferredVoice: (t, n) => e((e) => {
@@ -344,11 +348,11 @@ var C = h()(g((e, t) => ({
344
348
  ...a && !i.titleLocked ? { title: a } : {}
345
349
  };
346
350
  }) })),
347
- removeConversationsSilently: (t) => e((e) => S(e, t, !1)),
348
- evictConversations: (t) => e((e) => S(e, t, !0))
351
+ removeConversationsSilently: (t) => e((e) => E(e, t, !1)),
352
+ evictConversations: (t) => e((e) => E(e, t, !0))
349
353
  }), {
350
- name: "hb-ai-assistant",
351
- storage: n(e(), (e, t, n) => l(n)),
354
+ name: O,
355
+ storage: i(y(() => k), (e, t, n) => d(n)),
352
356
  partialize: (e) => ({
353
357
  conversations: e.conversations.map(({ ...e }) => e),
354
358
  activeConversationId: e.activeConversationId,
@@ -364,6 +368,12 @@ var C = h()(g((e, t) => ({
364
368
  handsFreeInterrupt: e.handsFreeInterrupt,
365
369
  handsFreeStreamNoticeAccepted: e.handsFreeStreamNoticeAccepted
366
370
  }),
367
- merge: b
368
- }));
369
- export { b as mergePersistedAssistantState, v as resolveActiveModeSandbox, C as useAssistantStore };
371
+ merge: A
372
+ })));
373
+ function P(t) {
374
+ let n = () => {
375
+ j();
376
+ };
377
+ return t.addEventListener(e, n), () => t.removeEventListener(e, n);
378
+ }
379
+ export { O as ASSISTANT_STORE_NAME, j as followActiveProfile, P as followProfileChanges, w as mergePersistedAssistantState, S as resolveActiveModeSandbox, N as useAssistantStore };