@kortix/ui 0.14.16 → 0.14.19

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 (130) hide show
  1. package/README.md +2 -2
  2. package/dist/_vendor/kortix-shared.js +38 -2
  3. package/dist/_vendor/shared/artifact-annotations.d.ts +126 -1
  4. package/dist/_vendor/shared/artifact-comments.d.ts +30 -1
  5. package/dist/_vendor/shared/channel-descriptors.d.ts +20 -1
  6. package/dist/_vendor/shared/channel-message.d.ts +1 -1
  7. package/dist/_vendor/shared/my-kortix-agent.d.ts +1 -1
  8. package/dist/_vendor/shared/space-slug.d.ts +3 -4
  9. package/dist/_vendor/shared/utils/ambiguous-write.d.ts +3 -3
  10. package/dist/customize/agents/agent-instructions.d.ts +8 -0
  11. package/dist/customize/agents/agent-instructions.js +38 -12
  12. package/dist/customize/agents/agent-overview.d.ts +6 -3
  13. package/dist/customize/agents/agent-overview.js +8 -2
  14. package/dist/customize/agents/agent-page-chrome.d.ts +45 -27
  15. package/dist/customize/agents/agent-page-chrome.js +60 -37
  16. package/dist/customize/agents/agent-page.js +88 -99
  17. package/dist/customize/agents/agent-tabs.d.ts +15 -14
  18. package/dist/customize/agents/agent-tabs.js +19 -16
  19. package/dist/customize/agents/agents-page.js +8 -6
  20. package/dist/customize/connectors/detail/account-info.js +1 -1
  21. package/dist/customize/project-settings/project-admin-sections.d.ts +6 -2
  22. package/dist/customize/project-settings/project-admin-sections.js +5 -3
  23. package/dist/customize/project-settings/project-settings-sections.js +1 -1
  24. package/dist/customize/sections/component/channel-access-panel.js +16 -0
  25. package/dist/customize/sections/component/channel-mocks.d.ts +5 -0
  26. package/dist/customize/sections/component/channel-mocks.js +14 -2
  27. package/dist/customize/sections/component/discord-channel-row.d.ts +6 -0
  28. package/dist/customize/sections/component/discord-channel-row.js +48 -0
  29. package/dist/customize/sections/gateway-access-tab.js +1 -1
  30. package/dist/customize/sections/view/channels-view.js +18 -1
  31. package/dist/customize/sections/view/git-view.js +2 -2
  32. package/dist/customize/sections/view/secret-delivery.js +1 -1
  33. package/dist/customize/sections/view/secrets-view.js +1 -1
  34. package/dist/customize/settings/rail.js +2 -2
  35. package/dist/customize/settings/tabs/experimental-tab.d.ts +2 -2
  36. package/dist/customize/settings/tabs/experimental-tab.js +3 -6
  37. package/dist/customize/settings/tabs/general-tab.js +5 -4
  38. package/dist/customize/shared/capability-library.js +19 -22
  39. package/dist/customize/shared/channels-switch-dialog.d.ts +4 -8
  40. package/dist/customize/shared/channels-switch-dialog.js +5 -16
  41. package/dist/customize/shared/customize-tab-bar.d.ts +1 -2
  42. package/dist/customize/shared/customize-tab-bar.js +10 -11
  43. package/dist/customize/shared/feature-gate-screen.js +5 -7
  44. package/dist/files/drives/drive-path-param.d.ts +4 -0
  45. package/dist/files/drives/drive-path-param.js +50 -0
  46. package/dist/files/index.d.ts +1 -0
  47. package/dist/files/index.js +1 -0
  48. package/dist/files/project/components/drive-create-dialog.js +3 -3
  49. package/dist/i18n/en.d.ts +99 -18
  50. package/dist/i18n/en.js +125 -44
  51. package/dist/i18n/ui-catalog/remaining-ui-translation-keys.generated.js +1 -1
  52. package/dist/internal/branding/branding-provider.d.ts +15 -4
  53. package/dist/internal/branding/branding-provider.js +12 -7
  54. package/dist/internal/connector-logo/connector-logo.js +2 -0
  55. package/dist/internal/connector-logo/connector-mark-files.js +1 -0
  56. package/dist/internal/hooks/channels/use-channels-installations.d.ts +7 -2
  57. package/dist/internal/hooks/channels/use-channels-installations.js +31 -1
  58. package/dist/internal/hooks/projects/use-new-project-session.d.ts +6 -14
  59. package/dist/internal/hooks/projects/use-new-project-session.js +12 -97
  60. package/dist/internal/hooks/use-notification-center.d.ts +11 -8
  61. package/dist/internal/hooks/use-notification-center.js +22 -10
  62. package/dist/internal/icons/discord.d.ts +9 -0
  63. package/dist/internal/icons/discord.js +9 -0
  64. package/dist/internal/layout/connect-mcp-modal.js +1 -1
  65. package/dist/internal/lib/browser-noise/rules/expected-states.js +1 -1
  66. package/dist/internal/lib/error-handler.js +1 -1
  67. package/dist/internal/lib/use-project-feature-flags.js +5 -3
  68. package/dist/markdown/doc-editor/doc-menus.d.ts +6 -0
  69. package/dist/markdown/doc-editor/doc-menus.js +74 -9
  70. package/dist/markdown/markdown-frontmatter.d.ts +0 -3
  71. package/dist/markdown/markdown-frontmatter.js +45 -5
  72. package/dist/session/actions/project-session-list-helpers.d.ts +4 -14
  73. package/dist/session/actions/project-session-list-helpers.js +5 -16
  74. package/dist/session/actions/session-label.d.ts +5 -9
  75. package/dist/session/actions/session-label.js +6 -10
  76. package/dist/session/participants/session-participants.d.ts +7 -5
  77. package/dist/session/participants/session-participants.js +11 -7
  78. package/dist/session/status/provisioning-failure.d.ts +26 -6
  79. package/dist/session/status/provisioning-failure.js +39 -12
  80. package/dist/session/thread/optimistic-turn.js +11 -2
  81. package/dist/session/thread/session-chat.js +73 -25
  82. package/dist/session/thread/transcript.d.ts +9 -0
  83. package/dist/session/thread/transcript.js +44 -5
  84. package/dist/session/tool/tools/channel-send-card.js +1 -0
  85. package/dist/session/turn/channel-brand.js +4 -0
  86. package/dist/session/turn/message-author.d.ts +13 -8
  87. package/dist/session/turn/message-author.js +34 -16
  88. package/dist/session/turn/peer-message-row.js +24 -6
  89. package/dist/session/turn/user-message.js +1 -1
  90. package/dist/session/voice/call-audio.d.ts +32 -0
  91. package/dist/session/voice/call-audio.js +146 -0
  92. package/dist/session/voice/screen-share.d.ts +24 -0
  93. package/dist/session/voice/screen-share.js +75 -0
  94. package/dist/session/voice/use-voice-call.d.ts +15 -0
  95. package/dist/session/voice/use-voice-call.js +220 -0
  96. package/dist/session/voice/voice-call-bar.d.ts +4 -0
  97. package/dist/session/voice/voice-call-bar.js +39 -0
  98. package/dist/session/voice/voice-call-state.d.ts +96 -0
  99. package/dist/session/voice/voice-call-state.js +103 -0
  100. package/dist/session/voice/voice-call-store.d.ts +12 -0
  101. package/dist/session/voice/voice-call-store.js +10 -0
  102. package/dist/session/voice/voice-call-url.d.ts +24 -0
  103. package/dist/session/voice/voice-call-url.js +33 -0
  104. package/dist/session/voice/voice-call.d.ts +15 -0
  105. package/dist/session/voice/voice-call.js +54 -0
  106. package/dist/styles.css +1 -1
  107. package/dist/workspace/admin/project-admin-dashboard.js +9 -4
  108. package/dist/workspace/layout/project-home.js +13 -14
  109. package/dist/workspace/sidebar/footer/project-manifest-issues-alert.d.ts +1 -1
  110. package/dist/workspace/sidebar/footer/project-manifest-issues-alert.js +4 -3
  111. package/dist/workspace/sidebar/project-session-list.js +14 -26
  112. package/dist/workspace/sidebar/session-brief-hover-card.d.ts +0 -3
  113. package/dist/workspace/sidebar/session-brief-hover-card.js +0 -3
  114. package/dist/workspace/sidebar/session-filter-menu.js +1 -0
  115. package/dist/workspace/sidebar/session-grouping.d.ts +4 -0
  116. package/dist/workspace/sidebar/session-grouping.js +2 -0
  117. package/dist/workspace/sidebar/session-source-icons.js +2 -0
  118. package/dist/workspace/space/space-page.js +2 -2
  119. package/package.json +9 -9
  120. package/skills/kortix-ui/SKILL.md +2 -2
  121. package/skills/kortix-ui/references/custom-dashboard.md +1 -1
  122. package/skills/kortix-ui/references/modules.md +1 -1
  123. package/dist/customize/agents/agent-section-rail.d.ts +0 -21
  124. package/dist/customize/agents/agent-section-rail.js +0 -23
  125. package/dist/internal/hooks/projects/use-warm-project-session.d.ts +0 -270
  126. package/dist/internal/hooks/projects/use-warm-project-session.js +0 -362
  127. package/dist/internal/hooks/projects/warm-session-seed.d.ts +0 -66
  128. package/dist/internal/hooks/projects/warm-session-seed.js +0 -80
  129. package/dist/internal/hooks/projects/warm-session-taken-registry.d.ts +0 -61
  130. package/dist/internal/hooks/projects/warm-session-taken-registry.js +0 -141
@@ -1,66 +0,0 @@
1
- /** @internal Kortix apps only. No semver: it may change in any release. */
2
- import type { ProjectSession } from '@kortix/sdk';
3
- /**
4
- * JAY-599 / T21 — an adopted warm session must appear in the session list
5
- * immediately, not seconds later when the sandbox wakes.
6
- *
7
- * Root cause: a warm session is hidden from the `visible` list scope by
8
- * `metadata.warm` (`apps/api/src/projects/lib/session-inventory.ts`) until the
9
- * marker drops. The
10
- * server drops that marker at adoption time — the first `POST .../start`
11
- * call, `apps/api/src/projects/routes/session-runtime.ts` — instead of waiting for the
12
- * first accepted TURN, seconds later, behind the whole sandbox boot window.
13
- * That closes the gap for everyone ELSE reading the list, but the adopting
14
- * tab itself still has to wait for its own `invalidateQueries` refetch to
15
- * round-trip. This function is the zero-latency half: insert the row the
16
- * warm ensure already returned (`WarmSession.session`,
17
- * `use-warm-project-session.ts`) directly into the cache the instant the send
18
- * happens, so THIS tab never waits on the network at all.
19
- *
20
- * Idempotent and order-preserving: a session id already in the list is
21
- * replaced in place (never duplicated), so a retried seed for the same id
22
- * cannot create two rows. `undefined` (nothing cached yet) becomes a fresh
23
- * one-row list rather than a throw — `use-new-project-session.ts` calls this
24
- * from a project the sidebar may not have fetched yet (e.g. a background tab).
25
- *
26
- * Placed FIRST when new: a just-adopted session is the most recently active
27
- * one, which is where every other creation path (the ordinary create POST)
28
- * already expects to see it once the list refetches.
29
- *
30
- * The seeded copy is the row AS THE SERVER WILL REPORT IT once adoption
31
- * lands: `metadata.warm` removed and `last_activity_at` stamped — the same
32
- * two writes `/start`'s `dropWarmSessionMarkerOnAdopt` makes in one statement
33
- * (`apps/api/src/projects/routes/warm-sessions.ts`). Seeding the raw
34
- * create-time row instead carried `warm: true` and no activity stamp, so the
35
- * sidebar's activity sort (`project-session-list-helpers.ts`) placed the
36
- * just-started session at its CREATE time — the start of the user's dwell on
37
- * the project home — burying it below sessions that were active more
38
- * recently. `adoptedAtIso` is injected (never read from a clock here) so the
39
- * transform stays pure and the caller's timestamp is the single truth.
40
- *
41
- * The reconcile that follows this seed no longer races the marker-drop:
42
- * `use-new-project-session.ts` defers its sessions invalidate until the
43
- * `/start` prefetch settles, by which point the drop is durable server-side.
44
- */
45
- /**
46
- * When to reconcile the sessions-list cache with the server after a create.
47
- *
48
- * Ordinary create: the row is visible server-side the moment the POST returns,
49
- * so invalidate immediately.
50
- *
51
- * Warm adoption: the row only becomes visible when `/start` drops
52
- * `metadata.warm`. An invalidate issued alongside the `/start` prefetch races
53
- * it — when the list GET wins, the server response (row still hidden)
54
- * overwrites the optimistic seed above and, with `refetchOnWindowFocus`
55
- * disabled, the just-started session stays missing from the sidebar for up to
56
- * the 60s open-session poll. Deferring the invalidate until the prefetch
57
- * settles makes the refetch observe the drop. `started` is
58
- * `prefetchSessionStart`'s return, which never rejects; the rejection arm is
59
- * belt-and-braces so a future caller cannot wedge the reconcile.
60
- */
61
- export declare function reconcileSessionsAfterCreate(input: {
62
- adoptedWarm: boolean;
63
- started: Promise<unknown>;
64
- invalidate: () => void;
65
- }): void;
66
- export declare function seedAdoptedWarmSession(sessions: ProjectSession[] | undefined, session: ProjectSession, adoptedAtIso: string): ProjectSession[];
@@ -1,80 +0,0 @@
1
- /**
2
- * JAY-599 / T21 — an adopted warm session must appear in the session list
3
- * immediately, not seconds later when the sandbox wakes.
4
- *
5
- * Root cause: a warm session is hidden from the `visible` list scope by
6
- * `metadata.warm` (`apps/api/src/projects/lib/session-inventory.ts`) until the
7
- * marker drops. The
8
- * server drops that marker at adoption time — the first `POST .../start`
9
- * call, `apps/api/src/projects/routes/session-runtime.ts` — instead of waiting for the
10
- * first accepted TURN, seconds later, behind the whole sandbox boot window.
11
- * That closes the gap for everyone ELSE reading the list, but the adopting
12
- * tab itself still has to wait for its own `invalidateQueries` refetch to
13
- * round-trip. This function is the zero-latency half: insert the row the
14
- * warm ensure already returned (`WarmSession.session`,
15
- * `use-warm-project-session.ts`) directly into the cache the instant the send
16
- * happens, so THIS tab never waits on the network at all.
17
- *
18
- * Idempotent and order-preserving: a session id already in the list is
19
- * replaced in place (never duplicated), so a retried seed for the same id
20
- * cannot create two rows. `undefined` (nothing cached yet) becomes a fresh
21
- * one-row list rather than a throw — `use-new-project-session.ts` calls this
22
- * from a project the sidebar may not have fetched yet (e.g. a background tab).
23
- *
24
- * Placed FIRST when new: a just-adopted session is the most recently active
25
- * one, which is where every other creation path (the ordinary create POST)
26
- * already expects to see it once the list refetches.
27
- *
28
- * The seeded copy is the row AS THE SERVER WILL REPORT IT once adoption
29
- * lands: `metadata.warm` removed and `last_activity_at` stamped — the same
30
- * two writes `/start`'s `dropWarmSessionMarkerOnAdopt` makes in one statement
31
- * (`apps/api/src/projects/routes/warm-sessions.ts`). Seeding the raw
32
- * create-time row instead carried `warm: true` and no activity stamp, so the
33
- * sidebar's activity sort (`project-session-list-helpers.ts`) placed the
34
- * just-started session at its CREATE time — the start of the user's dwell on
35
- * the project home — burying it below sessions that were active more
36
- * recently. `adoptedAtIso` is injected (never read from a clock here) so the
37
- * transform stays pure and the caller's timestamp is the single truth.
38
- *
39
- * The reconcile that follows this seed no longer races the marker-drop:
40
- * `use-new-project-session.ts` defers its sessions invalidate until the
41
- * `/start` prefetch settles, by which point the drop is durable server-side.
42
- */
43
- /**
44
- * When to reconcile the sessions-list cache with the server after a create.
45
- *
46
- * Ordinary create: the row is visible server-side the moment the POST returns,
47
- * so invalidate immediately.
48
- *
49
- * Warm adoption: the row only becomes visible when `/start` drops
50
- * `metadata.warm`. An invalidate issued alongside the `/start` prefetch races
51
- * it — when the list GET wins, the server response (row still hidden)
52
- * overwrites the optimistic seed above and, with `refetchOnWindowFocus`
53
- * disabled, the just-started session stays missing from the sidebar for up to
54
- * the 60s open-session poll. Deferring the invalidate until the prefetch
55
- * settles makes the refetch observe the drop. `started` is
56
- * `prefetchSessionStart`'s return, which never rejects; the rejection arm is
57
- * belt-and-braces so a future caller cannot wedge the reconcile.
58
- */
59
- export function reconcileSessionsAfterCreate(input) {
60
- if (!input.adoptedWarm) {
61
- input.invalidate();
62
- return;
63
- }
64
- void input.started.then(input.invalidate, input.invalidate);
65
- }
66
- export function seedAdoptedWarmSession(sessions, session, adoptedAtIso) {
67
- const { warm: _warm, ...metadata } = (session.metadata ?? {});
68
- const adopted = {
69
- ...session,
70
- metadata: { ...metadata, last_activity_at: adoptedAtIso },
71
- };
72
- if (!sessions)
73
- return [adopted];
74
- const index = sessions.findIndex((existing) => existing.session_id === adopted.session_id);
75
- if (index === -1)
76
- return [adopted, ...sessions];
77
- const next = sessions.slice();
78
- next[index] = adopted;
79
- return next;
80
- }
@@ -1,61 +0,0 @@
1
- /** @internal Kortix apps only. No semver: it may change in any release. */
2
- /**
3
- * Cross-tab registry of warm-session ids this BROWSER has already taken.
4
- *
5
- * Why it exists: the server deliberately reuses one warm session per user per
6
- * project (`apps/api/src/projects/routes/warm-sessions.ts`), so every tab the
7
- * user has open on a project holds the SAME session id in its in-memory ready
8
- * store (`use-warm-project-session.ts`). The moment one tab takes it for a
9
- * send, every other tab's held copy silently points at a session that now has
10
- * a conversation in it — and a later send from one of those tabs would land a
11
- * new prompt inside that old conversation. The in-memory `takenSessionIds`
12
- * defense (JAY-596/T20) cannot see across tabs; this registry is the shared
13
- * half of it.
14
- *
15
- * localStorage is the medium because it is the only synchronous cross-tab
16
- * channel: `takeWarmSessionEntry` must stay network-free and synchronous, so
17
- * the staleness check has to be a sync read. The `storage` event doubles as
18
- * the push channel — it fires in every OTHER tab on write, letting them drop
19
- * a now-stale ready entry and replenish while the user is still present.
20
- *
21
- * Scope and limits: per-browser only. Two different browsers/devices of the
22
- * same user can still race a take; that window is the seconds between one
23
- * device's take and the server's own marker drop at `/start`, versus the
24
- * minutes-to-hours a stale tab used to hold. Entries are pruned by age and
25
- * count because the server never re-offers a session once its warm marker
26
- * drops (~1s after a take), so old entries protect nothing.
27
- */
28
- export interface WarmTakenStorage {
29
- getItem(key: string): string | null;
30
- setItem(key: string, value: string): void;
31
- }
32
- export interface WarmTakenRegistry {
33
- has(sessionId: string): boolean;
34
- record(sessionId: string): void;
35
- }
36
- export declare const WARM_TAKEN_STORAGE_KEY = "kortix:warm-session-taken:v1";
37
- export declare function createWarmTakenRegistry(storage: WarmTakenStorage | null, now?: () => number): WarmTakenRegistry;
38
- /**
39
- * The ids a `storage` event ADDED to the registry — i.e. the takes some OTHER
40
- * tab just made. Pure so the event wiring stays a one-liner and this logic is
41
- * testable without a window.
42
- */
43
- export declare function takenIdsAddedByStorageEvent(event: {
44
- key: string | null;
45
- oldValue: string | null;
46
- newValue: string | null;
47
- }): string[];
48
- /** The app-wide registry every real caller shares. */
49
- export declare const warmTakenRegistry: WarmTakenRegistry;
50
- /**
51
- * Test hook: drop the app-wide registry's in-memory mirror. bun runs every
52
- * suite in one process, so without this a take recorded by one test leaks
53
- * into the next — the same reason the warm-session store is reset in
54
- * `beforeEach`. Production code never calls it.
55
- */
56
- export declare function resetWarmTakenRegistry(): void;
57
- /**
58
- * Notify `listener` of every warm-session take made by ANOTHER tab. Returns an
59
- * unsubscribe. A no-op outside a browser (SSR, tests).
60
- */
61
- export declare function subscribeToExternalWarmTakes(listener: (sessionId: string) => void): () => void;
@@ -1,141 +0,0 @@
1
- /**
2
- * Cross-tab registry of warm-session ids this BROWSER has already taken.
3
- *
4
- * Why it exists: the server deliberately reuses one warm session per user per
5
- * project (`apps/api/src/projects/routes/warm-sessions.ts`), so every tab the
6
- * user has open on a project holds the SAME session id in its in-memory ready
7
- * store (`use-warm-project-session.ts`). The moment one tab takes it for a
8
- * send, every other tab's held copy silently points at a session that now has
9
- * a conversation in it — and a later send from one of those tabs would land a
10
- * new prompt inside that old conversation. The in-memory `takenSessionIds`
11
- * defense (JAY-596/T20) cannot see across tabs; this registry is the shared
12
- * half of it.
13
- *
14
- * localStorage is the medium because it is the only synchronous cross-tab
15
- * channel: `takeWarmSessionEntry` must stay network-free and synchronous, so
16
- * the staleness check has to be a sync read. The `storage` event doubles as
17
- * the push channel — it fires in every OTHER tab on write, letting them drop
18
- * a now-stale ready entry and replenish while the user is still present.
19
- *
20
- * Scope and limits: per-browser only. Two different browsers/devices of the
21
- * same user can still race a take; that window is the seconds between one
22
- * device's take and the server's own marker drop at `/start`, versus the
23
- * minutes-to-hours a stale tab used to hold. Entries are pruned by age and
24
- * count because the server never re-offers a session once its warm marker
25
- * drops (~1s after a take), so old entries protect nothing.
26
- */
27
- export const WARM_TAKEN_STORAGE_KEY = 'kortix:warm-session-taken:v1';
28
- /** Drop entries older than this — the server-side marker drop makes a taken id
29
- * unofferable within seconds, so a day is generous. */
30
- const ENTRY_TTL_MS = 24 * 60 * 60 * 1000;
31
- /** Hard cap so a pathological loop can never bloat the payload. */
32
- const MAX_ENTRIES = 64;
33
- function parseEntries(raw) {
34
- if (!raw)
35
- return [];
36
- try {
37
- const parsed = JSON.parse(raw);
38
- if (!Array.isArray(parsed))
39
- return [];
40
- return parsed.filter((entry) => Array.isArray(entry) && typeof entry[0] === 'string' && typeof entry[1] === 'number');
41
- }
42
- catch {
43
- return [];
44
- }
45
- }
46
- function pruneEntries(entries, nowMs) {
47
- const fresh = entries.filter(([, at]) => nowMs - at < ENTRY_TTL_MS);
48
- fresh.sort((a, b) => a[1] - b[1]);
49
- return fresh.slice(-MAX_ENTRIES);
50
- }
51
- export function createWarmTakenRegistry(storage, now = Date.now) {
52
- // Mirror of everything THIS registry recorded, so a missing or throwing
53
- // storage degrades to exactly the old per-tab behavior instead of breaking.
54
- const memory = new Set();
55
- const read = () => {
56
- if (!storage)
57
- return [];
58
- try {
59
- return parseEntries(storage.getItem(WARM_TAKEN_STORAGE_KEY));
60
- }
61
- catch {
62
- return [];
63
- }
64
- };
65
- return {
66
- has(sessionId) {
67
- if (memory.has(sessionId))
68
- return true;
69
- return read().some(([id]) => id === sessionId);
70
- },
71
- record(sessionId) {
72
- memory.add(sessionId);
73
- if (!storage)
74
- return;
75
- try {
76
- const entries = read().filter(([id]) => id !== sessionId);
77
- entries.push([sessionId, now()]);
78
- storage.setItem(WARM_TAKEN_STORAGE_KEY, JSON.stringify(pruneEntries(entries, now())));
79
- }
80
- catch {
81
- // Quota/privacy-mode failures leave the in-memory mirror as the
82
- // defense — same coverage the app had before this registry existed.
83
- }
84
- },
85
- };
86
- }
87
- /**
88
- * The ids a `storage` event ADDED to the registry — i.e. the takes some OTHER
89
- * tab just made. Pure so the event wiring stays a one-liner and this logic is
90
- * testable without a window.
91
- */
92
- export function takenIdsAddedByStorageEvent(event) {
93
- if (event.key !== WARM_TAKEN_STORAGE_KEY)
94
- return [];
95
- const before = new Set(parseEntries(event.oldValue).map(([id]) => id));
96
- const added = [];
97
- for (const [id] of parseEntries(event.newValue)) {
98
- if (!before.has(id))
99
- added.push(id);
100
- }
101
- return added;
102
- }
103
- function safeLocalStorage() {
104
- if (typeof window === 'undefined')
105
- return null;
106
- try {
107
- return window.localStorage;
108
- }
109
- catch {
110
- return null;
111
- }
112
- }
113
- let appRegistry = createWarmTakenRegistry(safeLocalStorage());
114
- /** The app-wide registry every real caller shares. */
115
- export const warmTakenRegistry = {
116
- has: (sessionId) => appRegistry.has(sessionId),
117
- record: (sessionId) => appRegistry.record(sessionId),
118
- };
119
- /**
120
- * Test hook: drop the app-wide registry's in-memory mirror. bun runs every
121
- * suite in one process, so without this a take recorded by one test leaks
122
- * into the next — the same reason the warm-session store is reset in
123
- * `beforeEach`. Production code never calls it.
124
- */
125
- export function resetWarmTakenRegistry() {
126
- appRegistry = createWarmTakenRegistry(safeLocalStorage());
127
- }
128
- /**
129
- * Notify `listener` of every warm-session take made by ANOTHER tab. Returns an
130
- * unsubscribe. A no-op outside a browser (SSR, tests).
131
- */
132
- export function subscribeToExternalWarmTakes(listener) {
133
- if (typeof window === 'undefined')
134
- return () => { };
135
- const onStorage = (event) => {
136
- for (const id of takenIdsAddedByStorageEvent(event))
137
- listener(id);
138
- };
139
- window.addEventListener('storage', onStorage);
140
- return () => window.removeEventListener('storage', onStorage);
141
- }