@flamingo-stack/openframe-frontend-core 0.0.210 → 0.0.212-snapshot.20260528112413
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/dist/{chunk-VBFOCTMD.cjs → chunk-35XIT2CF.cjs} +17 -17
- package/dist/{chunk-VBFOCTMD.cjs.map → chunk-35XIT2CF.cjs.map} +1 -1
- package/dist/{chunk-ATEUJQKU.js → chunk-3JWIJJ44.js} +2 -2
- package/dist/chunk-CZR7ARBA.js +698 -0
- package/dist/chunk-CZR7ARBA.js.map +1 -0
- package/dist/{chunk-UYQOPC57.js → chunk-HICZPTRR.js} +4 -351
- package/dist/chunk-HICZPTRR.js.map +1 -0
- package/dist/{chunk-WJBPLMBX.js → chunk-IK2X5YJU.js} +3 -3
- package/dist/{chunk-MDTIOPVS.cjs → chunk-OTKJASSX.cjs} +26 -26
- package/dist/{chunk-MDTIOPVS.cjs.map → chunk-OTKJASSX.cjs.map} +1 -1
- package/dist/chunk-OZ3GH6OQ.cjs +698 -0
- package/dist/chunk-OZ3GH6OQ.cjs.map +1 -0
- package/dist/{chunk-6RZYJICV.cjs → chunk-P5EE2VJX.cjs} +1 -1
- package/dist/chunk-P5EE2VJX.cjs.map +1 -0
- package/dist/{chunk-EH3RWVF3.cjs → chunk-WT5JV2GS.cjs} +8 -355
- package/dist/chunk-WT5JV2GS.cjs.map +1 -0
- package/dist/{chunk-TWKPYZNQ.cjs → chunk-ZDF6F7ED.cjs} +569 -694
- package/dist/chunk-ZDF6F7ED.cjs.map +1 -0
- package/dist/{chunk-7L4DWM7P.js → chunk-ZG2YY5E7.js} +1 -1
- package/dist/chunk-ZG2YY5E7.js.map +1 -0
- package/dist/{chunk-R5RNRH62.js → chunk-ZTJVRSN5.js} +422 -547
- package/dist/chunk-ZTJVRSN5.js.map +1 -0
- package/dist/components/chat/hooks/use-chat-identity.d.ts +3 -3
- package/dist/components/chat/hooks/use-chat-identity.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-nats-dialog-subscription.d.ts +0 -9
- package/dist/components/chat/hooks/use-nats-dialog-subscription.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +6 -5
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +5 -4
- package/dist/components/contact/index.cjs +7 -6
- package/dist/components/contact/index.cjs.map +1 -1
- package/dist/components/contact/index.js +6 -5
- package/dist/components/features/index.cjs +6 -5
- package/dist/components/features/index.cjs.map +1 -1
- package/dist/components/features/index.js +5 -4
- package/dist/components/features/notifications/index.d.ts +2 -2
- package/dist/components/features/notifications/index.d.ts.map +1 -1
- package/dist/components/features/notifications/notifications-context.d.ts +16 -1
- package/dist/components/features/notifications/notifications-context.d.ts.map +1 -1
- package/dist/components/features/notifications/types.d.ts +4 -0
- package/dist/components/features/notifications/types.d.ts.map +1 -1
- package/dist/components/footer-waitlist-button.d.ts +21 -2
- package/dist/components/footer-waitlist-button.d.ts.map +1 -1
- package/dist/components/index.cjs +93 -96
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +17 -20
- package/dist/components/index.js.map +1 -1
- package/dist/components/navigation/app-header.d.ts.map +1 -1
- package/dist/components/navigation/index.cjs +6 -5
- package/dist/components/navigation/index.cjs.map +1 -1
- package/dist/components/navigation/index.js +5 -4
- package/dist/components/navigation/sticky-section-nav.d.ts.map +1 -1
- package/dist/components/tickets/help-center-card.d.ts.map +1 -1
- package/dist/components/tickets/index.cjs +144 -102
- package/dist/components/tickets/index.cjs.map +1 -1
- package/dist/components/tickets/index.js +98 -56
- package/dist/components/tickets/index.js.map +1 -1
- package/dist/components/tickets/ticket-row.d.ts.map +1 -1
- package/dist/components/ui/index.cjs +6 -5
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +5 -4
- package/dist/contexts/chat-runtime-context.d.ts +6 -3
- package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
- package/dist/contexts/index.cjs +2 -2
- package/dist/contexts/index.js +1 -1
- package/dist/embed-shims/index.cjs +3 -3
- package/dist/embed-shims/index.cjs.map +1 -1
- package/dist/embed-shims/index.js +4 -4
- package/dist/hooks/index.cjs +3 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/index.cjs +8 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -4
- package/dist/nats/index.cjs +28 -346
- package/dist/nats/index.cjs.map +1 -1
- package/dist/nats/index.d.ts +3 -0
- package/dist/nats/index.d.ts.map +1 -1
- package/dist/nats/index.js +30 -346
- package/dist/nats/index.js.map +1 -1
- package/dist/nats/nats-provider.d.ts +28 -0
- package/dist/nats/nats-provider.d.ts.map +1 -0
- package/dist/nats/nats.d.ts +1 -0
- package/dist/nats/nats.d.ts.map +1 -1
- package/dist/nats/shared-connection.d.ts +73 -0
- package/dist/nats/shared-connection.d.ts.map +1 -0
- package/dist/nats/use-nats-subscription.d.ts +18 -0
- package/dist/nats/use-nats-subscription.d.ts.map +1 -0
- package/dist/utils/index.cjs +10 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +10 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/scroll-into-view.d.ts +63 -0
- package/dist/utils/scroll-into-view.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/chat/hooks/use-chat-identity.ts +8 -7
- package/src/components/chat/hooks/use-jetstream-dialog-subscription.ts +60 -207
- package/src/components/chat/hooks/use-nats-dialog-subscription.ts +71 -214
- package/src/components/features/notifications/index.ts +2 -1
- package/src/components/features/notifications/notifications-context.tsx +104 -6
- package/src/components/features/notifications/types.ts +5 -0
- package/src/components/footer-waitlist-button.tsx +33 -16
- package/src/components/navigation/app-header.tsx +7 -9
- package/src/components/navigation/sticky-section-nav.tsx +6 -4
- package/src/components/tickets/help-center-card.tsx +55 -1
- package/src/components/tickets/help-center-list.tsx +9 -1
- package/src/components/tickets/ticket-detail-drawer.tsx +19 -4
- package/src/components/tickets/ticket-row.tsx +30 -19
- package/src/contexts/chat-runtime-context.tsx +6 -3
- package/src/nats/index.ts +3 -0
- package/src/nats/nats-provider.tsx +146 -0
- package/src/nats/nats.ts +2 -0
- package/src/nats/shared-connection.ts +285 -0
- package/src/nats/use-nats-subscription.ts +99 -0
- package/src/stories/EmbeddableChat.stories.tsx +1 -1
- package/src/utils/index.ts +12 -0
- package/src/utils/scroll-into-view.ts +74 -0
- package/dist/chunk-6RZYJICV.cjs.map +0 -1
- package/dist/chunk-7L4DWM7P.js.map +0 -1
- package/dist/chunk-EH3RWVF3.cjs.map +0 -1
- package/dist/chunk-R5RNRH62.js.map +0 -1
- package/dist/chunk-TWKPYZNQ.cjs.map +0 -1
- package/dist/chunk-UYQOPC57.js.map +0 -1
- /package/dist/{chunk-ATEUJQKU.js.map → chunk-3JWIJJ44.js.map} +0 -0
- /package/dist/{chunk-WJBPLMBX.js.map → chunk-IK2X5YJU.js.map} +0 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { createNatsClient, type NatsClient, type NatsStatus, type NatsStatusEvent } from './nats'
|
|
2
|
+
|
|
3
|
+
export const NATS_DEFAULTS = {
|
|
4
|
+
SHARED_CLOSE_DELAY_MS: 3000,
|
|
5
|
+
CONNECT_TIMEOUT_MS: 10_000,
|
|
6
|
+
PING_INTERVAL_MS: 30_000,
|
|
7
|
+
MAX_PING_OUT: 3,
|
|
8
|
+
RETRY_INITIAL_DELAY_MS: 1000,
|
|
9
|
+
RETRY_MAX_DELAY_MS: 30_000,
|
|
10
|
+
RETRY_MULTIPLIER: 2,
|
|
11
|
+
} as const
|
|
12
|
+
|
|
13
|
+
export interface NatsReconnectionBackoff {
|
|
14
|
+
/** Number of fast retries before exponential phase kicks in. Default: 0. */
|
|
15
|
+
fastRetries?: number
|
|
16
|
+
/** Delay used during the fast-retry phase. Default: RETRY_INITIAL_DELAY_MS. */
|
|
17
|
+
fastRetryDelayMs?: number
|
|
18
|
+
/** Base delay for the exponential phase. Default: RETRY_INITIAL_DELAY_MS. */
|
|
19
|
+
initialDelayMs?: number
|
|
20
|
+
/** Upper cap on any single retry delay. Default: RETRY_MAX_DELAY_MS. */
|
|
21
|
+
maxDelayMs?: number
|
|
22
|
+
/** Per-attempt multiplier during exponential phase. Default: RETRY_MULTIPLIER. */
|
|
23
|
+
multiplier?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SharedConnection {
|
|
27
|
+
wsUrl: string
|
|
28
|
+
client: NatsClient
|
|
29
|
+
connectPromise: Promise<void> | null
|
|
30
|
+
refCount: number
|
|
31
|
+
closeTimer: ReturnType<typeof setTimeout> | null
|
|
32
|
+
retryTimer: ReturnType<typeof setTimeout> | null
|
|
33
|
+
/**
|
|
34
|
+
* Identity of the consumer driving reconnect. When set, other consumers
|
|
35
|
+
* should observe status only and skip their own scheduleRetry — otherwise
|
|
36
|
+
* each disconnect triggers multiple concurrent connect() calls racing over
|
|
37
|
+
* connectPromise.
|
|
38
|
+
*/
|
|
39
|
+
retryOwner: object | null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AcquireClientOptions {
|
|
43
|
+
name?: string
|
|
44
|
+
user?: string
|
|
45
|
+
pass?: string
|
|
46
|
+
connectTimeoutMs?: number
|
|
47
|
+
pingIntervalMs?: number
|
|
48
|
+
maxPingOut?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ReleaseClientOptions {
|
|
52
|
+
delayMs?: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let shared: SharedConnection | null = null
|
|
56
|
+
|
|
57
|
+
export function getSharedConnection(): SharedConnection | null {
|
|
58
|
+
return shared
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function acquireClient(url: string, opts?: AcquireClientOptions): SharedConnection {
|
|
62
|
+
if (shared?.wsUrl !== url) {
|
|
63
|
+
if (shared) {
|
|
64
|
+
if (shared.closeTimer) clearTimeout(shared.closeTimer)
|
|
65
|
+
const old = shared
|
|
66
|
+
shared = null
|
|
67
|
+
void old.client.close().catch(() => {})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
name = 'openframe-frontend',
|
|
72
|
+
user = 'machine',
|
|
73
|
+
pass = '',
|
|
74
|
+
connectTimeoutMs = NATS_DEFAULTS.CONNECT_TIMEOUT_MS,
|
|
75
|
+
pingIntervalMs = NATS_DEFAULTS.PING_INTERVAL_MS,
|
|
76
|
+
maxPingOut = NATS_DEFAULTS.MAX_PING_OUT,
|
|
77
|
+
} = opts ?? {}
|
|
78
|
+
|
|
79
|
+
const client = createNatsClient({
|
|
80
|
+
servers: url,
|
|
81
|
+
name,
|
|
82
|
+
user,
|
|
83
|
+
pass,
|
|
84
|
+
connectTimeoutMs,
|
|
85
|
+
reconnect: false,
|
|
86
|
+
pingIntervalMs,
|
|
87
|
+
maxPingOut,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
shared = {
|
|
91
|
+
wsUrl: url,
|
|
92
|
+
client,
|
|
93
|
+
connectPromise: null,
|
|
94
|
+
refCount: 0,
|
|
95
|
+
closeTimer: null,
|
|
96
|
+
retryTimer: null,
|
|
97
|
+
retryOwner: null,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
shared.refCount += 1
|
|
102
|
+
if (shared.closeTimer) {
|
|
103
|
+
clearTimeout(shared.closeTimer)
|
|
104
|
+
shared.closeTimer = null
|
|
105
|
+
}
|
|
106
|
+
return shared
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function releaseClient(url: string, opts?: ReleaseClientOptions): void {
|
|
110
|
+
if (!shared || shared.wsUrl !== url) return
|
|
111
|
+
|
|
112
|
+
shared.refCount = Math.max(0, shared.refCount - 1)
|
|
113
|
+
if (shared.refCount > 0) return
|
|
114
|
+
|
|
115
|
+
const delay = opts?.delayMs ?? NATS_DEFAULTS.SHARED_CLOSE_DELAY_MS
|
|
116
|
+
shared.closeTimer = setTimeout(() => {
|
|
117
|
+
const s = shared
|
|
118
|
+
shared = null
|
|
119
|
+
if (s) {
|
|
120
|
+
if (s.retryTimer) {
|
|
121
|
+
clearTimeout(s.retryTimer)
|
|
122
|
+
s.retryTimer = null
|
|
123
|
+
}
|
|
124
|
+
void s.client.close().catch(() => {})
|
|
125
|
+
}
|
|
126
|
+
}, delay)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function getSharedConnectionFor(url: string | null | undefined): SharedConnection | null {
|
|
130
|
+
if (!url) return null
|
|
131
|
+
return shared && shared.wsUrl === url ? shared : null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Connection lifecycle: retry + status loop, shared by NatsProvider and the
|
|
136
|
+
// chat hooks. Each consumer that wants to drive reconnect creates an
|
|
137
|
+
// ownerToken and calls startConnectionLifecycle(). The first caller to claim
|
|
138
|
+
// retryOwner runs the actual retry loop; subsequent claimants observe status
|
|
139
|
+
// only. When the owner unmounts and releases retryOwner, the next status
|
|
140
|
+
// event lets a surviving consumer pick up ownership opportunistically.
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
export interface ConnectionLifecycleOptions {
|
|
144
|
+
conn: SharedConnection
|
|
145
|
+
wsUrl: string
|
|
146
|
+
onBeforeReconnect?: () => Promise<void> | void
|
|
147
|
+
backoff?: NatsReconnectionBackoff
|
|
148
|
+
getFreshUrl: () => string | null
|
|
149
|
+
/** Called on every status change (after closed-guard). */
|
|
150
|
+
onStatusChange?: (status: NatsStatus, evt: NatsStatusEvent) => void
|
|
151
|
+
/**
|
|
152
|
+
* Decide which statuses should trigger a retry attempt. Defaults to closed +
|
|
153
|
+
* disconnected. Override to skip 'error' (JetStream protocol errors that
|
|
154
|
+
* don't close the WS) or include it.
|
|
155
|
+
*/
|
|
156
|
+
shouldRetryOn?: (status: NatsStatus) => boolean
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ConnectionLifecycleHandle {
|
|
160
|
+
/** Stop observing status, clear any pending retry, release ownership if held. */
|
|
161
|
+
stop(): void
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const defaultShouldRetryOn = (status: NatsStatus) => status === 'closed' || status === 'disconnected'
|
|
165
|
+
|
|
166
|
+
export function startConnectionLifecycle(options: ConnectionLifecycleOptions): ConnectionLifecycleHandle {
|
|
167
|
+
const { conn, wsUrl } = options
|
|
168
|
+
// Each lifecycle gets its own identity for retry ownership. The first lifecycle to claim
|
|
169
|
+
// an unowned connection drives reconnect; later attachers observe status only until the
|
|
170
|
+
// owner releases (see opportunistic claim in scheduleRetry).
|
|
171
|
+
const ownerToken = {}
|
|
172
|
+
if (!conn.retryOwner) conn.retryOwner = ownerToken
|
|
173
|
+
|
|
174
|
+
let closed = false
|
|
175
|
+
let retryAttempt = 0
|
|
176
|
+
|
|
177
|
+
function emitSynthetic(status: NatsStatus) {
|
|
178
|
+
if (closed) return
|
|
179
|
+
options.onStatusChange?.(status, { status })
|
|
180
|
+
if (status === 'connected') {
|
|
181
|
+
retryAttempt = 0
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function scheduleRetry() {
|
|
186
|
+
if (closed) return
|
|
187
|
+
if (getSharedConnectionFor(wsUrl) !== conn) return
|
|
188
|
+
if (!conn.retryOwner) conn.retryOwner = ownerToken
|
|
189
|
+
if (conn.retryOwner !== ownerToken) return
|
|
190
|
+
|
|
191
|
+
if (conn.retryTimer) {
|
|
192
|
+
clearTimeout(conn.retryTimer)
|
|
193
|
+
conn.retryTimer = null
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const cfg = options.backoff ?? {}
|
|
197
|
+
const fastRetries = cfg.fastRetries ?? 0
|
|
198
|
+
const fastDelay = cfg.fastRetryDelayMs ?? NATS_DEFAULTS.RETRY_INITIAL_DELAY_MS
|
|
199
|
+
const baseDelay = cfg.initialDelayMs ?? NATS_DEFAULTS.RETRY_INITIAL_DELAY_MS
|
|
200
|
+
const maxDelay = cfg.maxDelayMs ?? NATS_DEFAULTS.RETRY_MAX_DELAY_MS
|
|
201
|
+
const multiplier = cfg.multiplier ?? NATS_DEFAULTS.RETRY_MULTIPLIER
|
|
202
|
+
|
|
203
|
+
const delay =
|
|
204
|
+
retryAttempt < fastRetries
|
|
205
|
+
? fastDelay
|
|
206
|
+
: Math.min(baseDelay * multiplier ** (retryAttempt - fastRetries), maxDelay)
|
|
207
|
+
const jitteredDelay = delay * (0.5 + Math.random() * 0.5)
|
|
208
|
+
retryAttempt++
|
|
209
|
+
|
|
210
|
+
conn.retryTimer = setTimeout(async () => {
|
|
211
|
+
conn.retryTimer = null
|
|
212
|
+
if (closed) return
|
|
213
|
+
if (getSharedConnectionFor(wsUrl) !== conn) return
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
await options.onBeforeReconnect?.()
|
|
217
|
+
} catch {
|
|
218
|
+
// continue regardless of token-refresh outcome
|
|
219
|
+
}
|
|
220
|
+
if (closed) return
|
|
221
|
+
if (getSharedConnectionFor(wsUrl) !== conn) return
|
|
222
|
+
|
|
223
|
+
const freshUrl = options.getFreshUrl()
|
|
224
|
+
if (freshUrl !== wsUrl) return
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
conn.connectPromise = null
|
|
228
|
+
conn.connectPromise = conn.client.connect()
|
|
229
|
+
await conn.connectPromise
|
|
230
|
+
if (!closed && getSharedConnectionFor(wsUrl) === conn) {
|
|
231
|
+
retryAttempt = 0
|
|
232
|
+
}
|
|
233
|
+
} catch {
|
|
234
|
+
conn.connectPromise = null
|
|
235
|
+
if (!closed && getSharedConnectionFor(wsUrl) === conn) {
|
|
236
|
+
scheduleRetry()
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}, jitteredDelay)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const shouldRetryOn = options.shouldRetryOn ?? defaultShouldRetryOn
|
|
243
|
+
|
|
244
|
+
const unsubStatus = conn.client.onStatus((evt) => {
|
|
245
|
+
if (closed) return
|
|
246
|
+
options.onStatusChange?.(evt.status, evt)
|
|
247
|
+
if (evt.status === 'connected') {
|
|
248
|
+
retryAttempt = 0
|
|
249
|
+
}
|
|
250
|
+
if (shouldRetryOn(evt.status)) {
|
|
251
|
+
scheduleRetry()
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
if (conn.client.isConnected()) {
|
|
256
|
+
emitSynthetic('connected')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
void (async () => {
|
|
260
|
+
try {
|
|
261
|
+
conn.connectPromise ||= conn.client.connect()
|
|
262
|
+
await conn.connectPromise
|
|
263
|
+
} catch {
|
|
264
|
+
conn.connectPromise = null
|
|
265
|
+
if (closed) return
|
|
266
|
+
|
|
267
|
+
emitSynthetic('disconnected')
|
|
268
|
+
scheduleRetry()
|
|
269
|
+
}
|
|
270
|
+
})()
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
stop() {
|
|
274
|
+
closed = true
|
|
275
|
+
unsubStatus()
|
|
276
|
+
if (conn.retryTimer) {
|
|
277
|
+
clearTimeout(conn.retryTimer)
|
|
278
|
+
conn.retryTimer = null
|
|
279
|
+
}
|
|
280
|
+
if (conn.retryOwner === ownerToken) {
|
|
281
|
+
conn.retryOwner = null
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import type { JsMsg, Msg, NatsSubscribeOptions } from './nats'
|
|
5
|
+
import { useOptionalNats } from './nats-provider'
|
|
6
|
+
|
|
7
|
+
export interface UseNatsSubscriptionOptions extends NatsSubscribeOptions {
|
|
8
|
+
enabled?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface UseNatsSubscriptionReturn {
|
|
12
|
+
isSubscribed: boolean
|
|
13
|
+
isReady: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to a NATS subject using the shared connection from <NatsProvider>.
|
|
18
|
+
* Automatically (re)subscribes when the connection becomes ready, when the
|
|
19
|
+
* subject changes, and after reconnections.
|
|
20
|
+
*/
|
|
21
|
+
export function useNatsSubscription(
|
|
22
|
+
subject: string | null,
|
|
23
|
+
onMessage: (msg: Msg) => void | Promise<void>,
|
|
24
|
+
options?: UseNatsSubscriptionOptions,
|
|
25
|
+
): UseNatsSubscriptionReturn {
|
|
26
|
+
const nats = useOptionalNats()
|
|
27
|
+
const handlerRef = React.useRef(onMessage)
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
handlerRef.current = onMessage
|
|
30
|
+
}, [onMessage])
|
|
31
|
+
|
|
32
|
+
const [isSubscribed, setIsSubscribed] = React.useState(false)
|
|
33
|
+
|
|
34
|
+
const enabled = options?.enabled !== false
|
|
35
|
+
const queue = options?.queue
|
|
36
|
+
const max = options?.max
|
|
37
|
+
const reconnectionCount = nats?.reconnectionCount ?? 0
|
|
38
|
+
const isReady = !!nats?.isReady
|
|
39
|
+
const client = nats?.client ?? null
|
|
40
|
+
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (!client || !isReady || !subject || !enabled) {
|
|
43
|
+
setIsSubscribed(false)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const sub = client.subscribeBytes(
|
|
48
|
+
subject,
|
|
49
|
+
(msg) => handlerRef.current(msg),
|
|
50
|
+
{ queue, max },
|
|
51
|
+
)
|
|
52
|
+
setIsSubscribed(true)
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
setIsSubscribed(false)
|
|
56
|
+
try {
|
|
57
|
+
sub.unsubscribe()
|
|
58
|
+
} catch {
|
|
59
|
+
// ignore
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// reconnectionCount intentionally in deps: re-subscribe after reconnect
|
|
63
|
+
}, [client, isReady, subject, enabled, queue, max, reconnectionCount])
|
|
64
|
+
|
|
65
|
+
return { isSubscribed, isReady }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type UseNatsJsonSubscriptionOptions = UseNatsSubscriptionOptions
|
|
69
|
+
|
|
70
|
+
export function useNatsJsonSubscription<T = unknown>(
|
|
71
|
+
subject: string | null,
|
|
72
|
+
onPayload: (payload: T, msg: Msg) => void | Promise<void>,
|
|
73
|
+
options?: UseNatsJsonSubscriptionOptions,
|
|
74
|
+
): UseNatsSubscriptionReturn {
|
|
75
|
+
const handlerRef = React.useRef(onPayload)
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
handlerRef.current = onPayload
|
|
78
|
+
}, [onPayload])
|
|
79
|
+
|
|
80
|
+
const decoderRef = React.useRef<TextDecoder | null>(null)
|
|
81
|
+
if (!decoderRef.current && typeof TextDecoder !== 'undefined') {
|
|
82
|
+
decoderRef.current = new TextDecoder()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const wrapped = React.useCallback(async (msg: Msg) => {
|
|
86
|
+
const decoder = decoderRef.current
|
|
87
|
+
if (!decoder) return
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(decoder.decode(msg.data)) as T
|
|
90
|
+
await handlerRef.current(parsed, msg)
|
|
91
|
+
} catch {
|
|
92
|
+
// ignore malformed payloads
|
|
93
|
+
}
|
|
94
|
+
}, [])
|
|
95
|
+
|
|
96
|
+
return useNatsSubscription(subject, wrapped, options)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export type NatsJsMsg = JsMsg
|
|
@@ -35,7 +35,7 @@ function createMockRuntime(): ChatRuntime {
|
|
|
35
35
|
buildListUrl: () => null,
|
|
36
36
|
attachmentUploadUrl: '/__story__/upload',
|
|
37
37
|
attachmentViewUrlPrefix: '/__story__/view/',
|
|
38
|
-
|
|
38
|
+
identityUrl: '/__story__/identity',
|
|
39
39
|
},
|
|
40
40
|
navigation: {
|
|
41
41
|
mode: 'embed',
|
package/src/utils/index.ts
CHANGED
|
@@ -200,3 +200,15 @@ export { fetchPriorityProp, type FetchPriorityValue } from './fetch-priority'
|
|
|
200
200
|
// server-safe (no JSX, no contexts/* imports); imported by route-page
|
|
201
201
|
// `metadata` exports + the shared `<DevSectionView>` chrome.
|
|
202
202
|
export * from './dev-sections'
|
|
203
|
+
|
|
204
|
+
// Canonical "smooth scroll element into view with sticky-chrome
|
|
205
|
+
// offset" helper. Single source of truth across the lib + hub for
|
|
206
|
+
// pre-computed-target scrolling — see `scroll-into-view.ts` for the
|
|
207
|
+
// rationale (TL;DR: window.scrollTo({top, behavior:'smooth'}) with a
|
|
208
|
+
// pre-computed pixel value avoids the mid-animation jitter that
|
|
209
|
+
// `element.scrollIntoView()` produces when layout shifts during the
|
|
210
|
+
// scroll).
|
|
211
|
+
export {
|
|
212
|
+
type ScrollElementIntoViewOptions,
|
|
213
|
+
scrollElementIntoView,
|
|
214
|
+
} from './scroll-into-view'
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `scrollElementIntoView` — canonical "smooth scroll element to top
|
|
3
|
+
* of viewport, account for sticky chrome, optionally adjust for
|
|
4
|
+
* known layout shifts" helper.
|
|
5
|
+
*
|
|
6
|
+
* Before this util existed, ~3 different call sites in the lib + hub
|
|
7
|
+
* had the same 5-line snippet copy-pasted with subtle differences:
|
|
8
|
+
*
|
|
9
|
+
* - `useUnifiedNav` same-URL re-scroll branch (hub)
|
|
10
|
+
* - `<HelpCenterCard>` click-to-expand (lib, with cross-row
|
|
11
|
+
* layout-shift adjustment)
|
|
12
|
+
* - Future ticket-row / docs anchor scrolls
|
|
13
|
+
*
|
|
14
|
+
* The canonical pattern is `window.scrollTo({top, behavior:'smooth'})`
|
|
15
|
+
* with a pre-computed pixel target — NOT `element.scrollIntoView()`.
|
|
16
|
+
* Pre-computing the target lets the browser run a clean uninterrupted
|
|
17
|
+
* smooth animation to a fixed pixel value. `scrollIntoView` re-targets
|
|
18
|
+
* continuously as the page layout shifts during the animation, which
|
|
19
|
+
* causes visible jitter when content above the target is also moving
|
|
20
|
+
* (a sibling collapsing, an async image loading, …).
|
|
21
|
+
*
|
|
22
|
+
* The `adjustTargetY` callback is the escape hatch for cases where
|
|
23
|
+
* the consumer KNOWS about an upcoming layout shift and can compute
|
|
24
|
+
* the correct FINAL target before the animation starts. Example: in
|
|
25
|
+
* `HelpCenterCard`, clicking row B while row A above is currently
|
|
26
|
+
* expanded — A's drawer collapses simultaneously with B's expansion,
|
|
27
|
+
* shifting B's tile up by A's drawer height. The consumer passes
|
|
28
|
+
* `adjustTargetY: raw => raw - getAboveDrawerHeight()` and the
|
|
29
|
+
* browser smooth-scrolls to the post-collapse position directly.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export interface ScrollElementIntoViewOptions {
|
|
33
|
+
/** Pixels to subtract from the target element's `top` so it lands
|
|
34
|
+
* BELOW sticky chrome. Defaults to 0. Pass `96` (matches
|
|
35
|
+
* `scroll-mt-24`) for the standard hub header offset. */
|
|
36
|
+
headerOffset?: number
|
|
37
|
+
/** Scroll animation style. Defaults to `'smooth'`. Use `'instant'`
|
|
38
|
+
* for imperative jumps where animation would feel laggy (deep
|
|
39
|
+
* link land, programmatic focus moves). */
|
|
40
|
+
behavior?: ScrollBehavior
|
|
41
|
+
/** Optional adjustment applied to the computed pixel target. The
|
|
42
|
+
* callback receives the "raw" Y (`element.top + scrollY -
|
|
43
|
+
* headerOffset`) and returns the FINAL pixel target. Use this
|
|
44
|
+
* when the caller knows about a layout shift that will happen
|
|
45
|
+
* between the call and the animation completing — the browser's
|
|
46
|
+
* smooth-scroll commits to a single pixel value, so providing the
|
|
47
|
+
* post-shift target up front lands the element correctly even as
|
|
48
|
+
* content above it moves. */
|
|
49
|
+
adjustTargetY?: (rawTargetY: number) => number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Scroll the page so `target` lands at the top of the viewport,
|
|
54
|
+
* accounting for sticky chrome via `headerOffset`. Returns void; the
|
|
55
|
+
* scroll runs async via the browser's smooth-scroll engine.
|
|
56
|
+
*
|
|
57
|
+
* Accepts:
|
|
58
|
+
* - `HTMLElement` — direct reference (most common from `useRef`).
|
|
59
|
+
* - `null` / `undefined` — no-op so callers can pass refs without
|
|
60
|
+
* defensive branching.
|
|
61
|
+
*
|
|
62
|
+
* SSR-safe: short-circuits when `window` is undefined.
|
|
63
|
+
*/
|
|
64
|
+
export function scrollElementIntoView(
|
|
65
|
+
target: HTMLElement | null | undefined,
|
|
66
|
+
options: ScrollElementIntoViewOptions = {},
|
|
67
|
+
): void {
|
|
68
|
+
if (typeof window === 'undefined' || !target) return
|
|
69
|
+
const { headerOffset = 0, behavior = 'smooth', adjustTargetY } = options
|
|
70
|
+
const rawTargetY =
|
|
71
|
+
target.getBoundingClientRect().top + window.scrollY - headerOffset
|
|
72
|
+
const finalY = adjustTargetY ? adjustTargetY(rawTargetY) : rawTargetY
|
|
73
|
+
window.scrollTo({ top: Math.max(0, finalY), behavior })
|
|
74
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-6RZYJICV.cjs","../src/contexts/chat-runtime-context.tsx"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACA;ACiCA,8BAA0D;AA8FnD,IAAM,mBAAA,EAAqB,kCAAA,IAAsC,CAAA;AAQjE,SAAS,cAAA,CAAA,EAAqC;AACnD,EAAA,OAAO,+BAAA,kBAA6B,CAAA;AACtC;AAUO,SAAS,sBAAA,CAAA,EAAsC;AACpD,EAAA,MAAM,EAAA,EAAI,+BAAA,kBAA6B,CAAA;AACvC,EAAA,GAAA,CAAI,CAAC,CAAA,EAAG;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,IAMF,CAAA;AAAA,EACF;AACA,EAAA,OAAO,CAAA;AACT;ADjJA;AACA;AACE;AACA;AACA;AACF,kJAAC","file":"/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-6RZYJICV.cjs","sourcesContent":[null,"'use client'\n\n/**\n * Chat runtime context — single seam for embedding the chat panel in a\n * different host (e.g. user1.openframe.ai reverse-proxying API calls\n * under /api/mingo-guide/* to hub.openframe.ai/api/*).\n *\n * Three concerns, one context:\n * 1. API endpoints: chatStreamUrl / approvalToolUrl / commandsUrl /\n * buildListUrl + attachment endpoints + chat-identity. The chat\n * reads them from runtime; hub vs embedded app supply different\n * strings via different providers.\n * 2. Navigation mode + callbacks: 'host' or 'embed' mode. Host wires\n * its own router/docNav via the optional `navigate` callback\n * (plain function, NOT a hook); embed forces new-tab via\n * `defaultContentOrigin` + lib's `resolveExternalNavigation`.\n * 3. Identity context: only `source` (required for localStorage\n * namespacing). The display identity (greeting first-name etc.)\n * comes from the server via `useChatIdentity()` — never injected\n * client-side, so it always matches the server-resolved auth.\n *\n * Sibling of EndpointsRuntimeContext (announcement bar, contact form,\n * access codes). Each runtime stays an independent React context so\n * embedders can opt into either feature without forcing the other.\n *\n * IMPORTANT for embedders: memoize the value passed to\n * `<ChatRuntimeContext.Provider value={...}>` (e.g. via React.useMemo).\n * Every change to its reference identity invalidates downstream\n * `useMemo` consumers (the chat input's slash-commands binding,\n * useNavLink's embed-resolution memo, useDocChat's streamFn factory).\n * The hub's `<HubRuntimeProvider>` already memoizes correctly with\n * stable deps. Embedded apps that build the value inline on each render\n * will pay an avoidable re-render cost across the entire chat tree.\n */\n\nimport { createContext, useContext, type ReactNode } from 'react'\n\n/**\n * Runtime config consumed by the chat panel.\n */\nexport interface ChatRuntime {\n endpoints: {\n /** POST streaming chat. Hub: '/api/docs/chat'. */\n chatStreamUrl: string\n /** POST agent approve/reject. Hub: '/api/chat/agent/confirm-tool'. */\n approvalToolUrl: string\n /** GET slash-command catalog. Hub: '/api/docs/commands'. */\n commandsUrl: string\n /** Build entity-card list URL for a content type + ids. Hub delegates\n * to the rag-table-config registry; embedded app provides its own\n * per-type URL builder against the reverse proxy. Returns null when\n * the type has no list endpoint (caller skips rendering). */\n buildListUrl: (type: string, ids: string[]) => string | null\n /** Chat-attachment endpoints — added for the v2 attachment feature.\n *\n * Three concerns:\n * - `attachmentUploadUrl` — POSTed by the chat-attachment hook\n * to mint a Supabase signed-upload-URL + HMAC view token.\n * - `attachmentViewUrlPrefix` — embedded in markdown URLs the\n * chat hosts in user message bubbles (`![]()` / `[Attached]`).\n * Stored in chat history; chosen at SEND time. In host mode the\n * relative `/api/storage/view/chat-attachments/` is sufficient\n * (same-origin); embedders supply an absolute hub URL so the\n * browser can fetch cross-origin.\n * - `chatIdentityUrl` — GET endpoint the `useChatIdentity` hook\n * hits to learn the `{authTier, source, attachmentsEnabled}`\n * capability bag for the current session. */\n attachmentUploadUrl: string\n attachmentViewUrlPrefix: string\n chatIdentityUrl: string\n /** Optional URL prefix for the image proxy (`<prefix>?url=<external>`).\n * When unset, lib's `getProxiedImageUrl` returns the original URL\n * unchanged. Hub default: '/api/image-proxy'. Embedders that don't\n * host an image-proxy route leave this undefined → images load\n * directly cross-origin (CORS-permitting). */\n imageProxyUrlPrefix?: string\n /** Optional list of hostnames that should bypass the image proxy\n * (rendered direct). Hub uses ['openmsp.ai']; embedders typically\n * leave it unset. Matches the `skipDomains` parameter of\n * `getProxiedImageUrl`. */\n imageProxySkipDomains?: string[]\n }\n navigation: {\n /** ONE knob, two behaviors:\n * - 'host' = use the host page's existing click-routing untouched.\n * The chat panel calls `navigate?.()` for in-app routing.\n * - 'embed' = guest inside another app: short-circuit at the top\n * of click handlers to force new-tab + absolutize via\n * resolveExternalNavigation. */\n mode: 'host' | 'embed'\n /** Embed-only fallback origin for relative URLs whose target platform\n * can't be inferred. Used by resolveExternalNavigation when\n * `targetPlatform` is null — without this, a relative `/foo` href would\n * window.open against the embedder's origin, which is WRONG.\n * Set to your content host (e.g. 'https://hub.openframe.ai').\n * Required by the embedded app whenever mode='embed'. */\n defaultContentOrigin?: string\n /** Override for opening external URLs. MUST BE SYNCHRONOUS —\n * Safari/Firefox block popups opened outside a direct user gesture.\n * Default: window.open(href, '_blank', 'noopener,noreferrer'). */\n openExternal?: (href: string) => void\n /** Optional in-app navigation callback (host-mode only).\n * Returns `true` if the host handled the click in-app\n * (router.push + docNav.navigate); returns `false`, `undefined`,\n * or `void` → lib falls back to window.location.assign(href).\n * Hub wires this via HubRuntimeProvider's HubNavigationWiring;\n * embedders not in Next.js leave it undefined. */\n navigate?: (input: { href: string; path?: string | null; targetPlatform?: string | null }) => boolean | void\n /** Optional new-tab decision callback. Returns true → lib opens in\n * new tab; false → same tab via `navigate`. Hub wires the existing\n * `decideNewTab` logic from use-nav-link.tsx (re-imports the pure\n * helper from lib). Embedders may omit; lib defaults to:\n * same-origin/same-platform → same tab, else new tab. */\n decideNewTab?: (args: { href: string; targetPlatform?: string | null }) => boolean\n }\n /** Chat source identifier — REQUIRED. Used for localStorage\n * namespacing (`mingo-chat-<source>-v1`). Hub sets via\n * `currentPlatform()`; embedders set explicitly.\n * `useEmbeddedChat()` throws if source is empty/missing. */\n source: string\n // NOTE: No `user` field. The chat's display identity (greeting\n // first-name, etc.) comes from the SERVER-resolved auth via\n // `useChatIdentity()` — the same identity the server uses to\n // authorize requests. Letting embedders pass a client-side `user`\n // would let it desync from the actual auth tier, causing greetings\n // like \"Hey Bob\" while the server treats the session as\n // alice@example.com. Single source of truth: the server.\n}\n\nexport const ChatRuntimeContext = createContext<ChatRuntime | null>(null)\n\n/**\n * Returns the active runtime, or null when no provider is mounted.\n * NULL is a first-class value — it signals \"no chat runtime configured.\"\n * Optional consumers fall back to no-op behavior; strict consumers\n * use `useRequiredChatRuntime` (below).\n */\nexport function useChatRuntime(): ChatRuntime | null {\n return useContext(ChatRuntimeContext)\n}\n\n/**\n * Strict variant used INSIDE the chat panel. Throws if no provider.\n * The hub guarantees one exists by mounting `<HubRuntimeProvider>` at\n * root; the embedded app mounts its own `<ChatRuntimeContext.Provider>`\n * at the tree root. In Jest / Storybook tests that render chat\n * internals directly, wrap with `<HubRuntimeProvider>` (hub defaults)\n * or supply `<ChatRuntimeContext.Provider value={mockedRuntime}>`.\n */\nexport function useRequiredChatRuntime(): ChatRuntime {\n const v = useContext(ChatRuntimeContext)\n if (!v) {\n throw new Error(\n '[chat-runtime] hook called outside a <ChatRuntimeContext.Provider>. ' +\n 'The hub mounts <HubRuntimeProvider> at root — this only fires when ' +\n 'chat internals are rendered above the provider tree. ' +\n 'Fix: ensure the rendering subtree descends from the runtime provider. ' +\n 'In tests/Storybook: wrap with <HubRuntimeProvider> or supply ' +\n 'a <ChatRuntimeContext.Provider value={mockedRuntime}>.',\n )\n }\n return v\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contexts/chat-runtime-context.tsx"],"sourcesContent":["'use client'\n\n/**\n * Chat runtime context — single seam for embedding the chat panel in a\n * different host (e.g. user1.openframe.ai reverse-proxying API calls\n * under /api/mingo-guide/* to hub.openframe.ai/api/*).\n *\n * Three concerns, one context:\n * 1. API endpoints: chatStreamUrl / approvalToolUrl / commandsUrl /\n * buildListUrl + attachment endpoints + chat-identity. The chat\n * reads them from runtime; hub vs embedded app supply different\n * strings via different providers.\n * 2. Navigation mode + callbacks: 'host' or 'embed' mode. Host wires\n * its own router/docNav via the optional `navigate` callback\n * (plain function, NOT a hook); embed forces new-tab via\n * `defaultContentOrigin` + lib's `resolveExternalNavigation`.\n * 3. Identity context: only `source` (required for localStorage\n * namespacing). The display identity (greeting first-name etc.)\n * comes from the server via `useChatIdentity()` — never injected\n * client-side, so it always matches the server-resolved auth.\n *\n * Sibling of EndpointsRuntimeContext (announcement bar, contact form,\n * access codes). Each runtime stays an independent React context so\n * embedders can opt into either feature without forcing the other.\n *\n * IMPORTANT for embedders: memoize the value passed to\n * `<ChatRuntimeContext.Provider value={...}>` (e.g. via React.useMemo).\n * Every change to its reference identity invalidates downstream\n * `useMemo` consumers (the chat input's slash-commands binding,\n * useNavLink's embed-resolution memo, useDocChat's streamFn factory).\n * The hub's `<HubRuntimeProvider>` already memoizes correctly with\n * stable deps. Embedded apps that build the value inline on each render\n * will pay an avoidable re-render cost across the entire chat tree.\n */\n\nimport { createContext, useContext, type ReactNode } from 'react'\n\n/**\n * Runtime config consumed by the chat panel.\n */\nexport interface ChatRuntime {\n endpoints: {\n /** POST streaming chat. Hub: '/api/docs/chat'. */\n chatStreamUrl: string\n /** POST agent approve/reject. Hub: '/api/chat/agent/confirm-tool'. */\n approvalToolUrl: string\n /** GET slash-command catalog. Hub: '/api/docs/commands'. */\n commandsUrl: string\n /** Build entity-card list URL for a content type + ids. Hub delegates\n * to the rag-table-config registry; embedded app provides its own\n * per-type URL builder against the reverse proxy. Returns null when\n * the type has no list endpoint (caller skips rendering). */\n buildListUrl: (type: string, ids: string[]) => string | null\n /** Chat-attachment endpoints — added for the v2 attachment feature.\n *\n * Three concerns:\n * - `attachmentUploadUrl` — POSTed by the chat-attachment hook\n * to mint a Supabase signed-upload-URL + HMAC view token.\n * - `attachmentViewUrlPrefix` — embedded in markdown URLs the\n * chat hosts in user message bubbles (`![]()` / `[Attached]`).\n * Stored in chat history; chosen at SEND time. In host mode the\n * relative `/api/storage/view/chat-attachments/` is sufficient\n * (same-origin); embedders supply an absolute hub URL so the\n * browser can fetch cross-origin.\n * - `chatIdentityUrl` — GET endpoint the `useChatIdentity` hook\n * hits to learn the `{authTier, source, attachmentsEnabled}`\n * capability bag for the current session. */\n attachmentUploadUrl: string\n attachmentViewUrlPrefix: string\n chatIdentityUrl: string\n /** Optional URL prefix for the image proxy (`<prefix>?url=<external>`).\n * When unset, lib's `getProxiedImageUrl` returns the original URL\n * unchanged. Hub default: '/api/image-proxy'. Embedders that don't\n * host an image-proxy route leave this undefined → images load\n * directly cross-origin (CORS-permitting). */\n imageProxyUrlPrefix?: string\n /** Optional list of hostnames that should bypass the image proxy\n * (rendered direct). Hub uses ['openmsp.ai']; embedders typically\n * leave it unset. Matches the `skipDomains` parameter of\n * `getProxiedImageUrl`. */\n imageProxySkipDomains?: string[]\n }\n navigation: {\n /** ONE knob, two behaviors:\n * - 'host' = use the host page's existing click-routing untouched.\n * The chat panel calls `navigate?.()` for in-app routing.\n * - 'embed' = guest inside another app: short-circuit at the top\n * of click handlers to force new-tab + absolutize via\n * resolveExternalNavigation. */\n mode: 'host' | 'embed'\n /** Embed-only fallback origin for relative URLs whose target platform\n * can't be inferred. Used by resolveExternalNavigation when\n * `targetPlatform` is null — without this, a relative `/foo` href would\n * window.open against the embedder's origin, which is WRONG.\n * Set to your content host (e.g. 'https://hub.openframe.ai').\n * Required by the embedded app whenever mode='embed'. */\n defaultContentOrigin?: string\n /** Override for opening external URLs. MUST BE SYNCHRONOUS —\n * Safari/Firefox block popups opened outside a direct user gesture.\n * Default: window.open(href, '_blank', 'noopener,noreferrer'). */\n openExternal?: (href: string) => void\n /** Optional in-app navigation callback (host-mode only).\n * Returns `true` if the host handled the click in-app\n * (router.push + docNav.navigate); returns `false`, `undefined`,\n * or `void` → lib falls back to window.location.assign(href).\n * Hub wires this via HubRuntimeProvider's HubNavigationWiring;\n * embedders not in Next.js leave it undefined. */\n navigate?: (input: { href: string; path?: string | null; targetPlatform?: string | null }) => boolean | void\n /** Optional new-tab decision callback. Returns true → lib opens in\n * new tab; false → same tab via `navigate`. Hub wires the existing\n * `decideNewTab` logic from use-nav-link.tsx (re-imports the pure\n * helper from lib). Embedders may omit; lib defaults to:\n * same-origin/same-platform → same tab, else new tab. */\n decideNewTab?: (args: { href: string; targetPlatform?: string | null }) => boolean\n }\n /** Chat source identifier — REQUIRED. Used for localStorage\n * namespacing (`mingo-chat-<source>-v1`). Hub sets via\n * `currentPlatform()`; embedders set explicitly.\n * `useEmbeddedChat()` throws if source is empty/missing. */\n source: string\n // NOTE: No `user` field. The chat's display identity (greeting\n // first-name, etc.) comes from the SERVER-resolved auth via\n // `useChatIdentity()` — the same identity the server uses to\n // authorize requests. Letting embedders pass a client-side `user`\n // would let it desync from the actual auth tier, causing greetings\n // like \"Hey Bob\" while the server treats the session as\n // alice@example.com. Single source of truth: the server.\n}\n\nexport const ChatRuntimeContext = createContext<ChatRuntime | null>(null)\n\n/**\n * Returns the active runtime, or null when no provider is mounted.\n * NULL is a first-class value — it signals \"no chat runtime configured.\"\n * Optional consumers fall back to no-op behavior; strict consumers\n * use `useRequiredChatRuntime` (below).\n */\nexport function useChatRuntime(): ChatRuntime | null {\n return useContext(ChatRuntimeContext)\n}\n\n/**\n * Strict variant used INSIDE the chat panel. Throws if no provider.\n * The hub guarantees one exists by mounting `<HubRuntimeProvider>` at\n * root; the embedded app mounts its own `<ChatRuntimeContext.Provider>`\n * at the tree root. In Jest / Storybook tests that render chat\n * internals directly, wrap with `<HubRuntimeProvider>` (hub defaults)\n * or supply `<ChatRuntimeContext.Provider value={mockedRuntime}>`.\n */\nexport function useRequiredChatRuntime(): ChatRuntime {\n const v = useContext(ChatRuntimeContext)\n if (!v) {\n throw new Error(\n '[chat-runtime] hook called outside a <ChatRuntimeContext.Provider>. ' +\n 'The hub mounts <HubRuntimeProvider> at root — this only fires when ' +\n 'chat internals are rendered above the provider tree. ' +\n 'Fix: ensure the rendering subtree descends from the runtime provider. ' +\n 'In tests/Storybook: wrap with <HubRuntimeProvider> or supply ' +\n 'a <ChatRuntimeContext.Provider value={mockedRuntime}>.',\n )\n }\n return v\n}\n"],"mappings":";;;AAmCA,SAAS,eAAe,kBAAkC;AA8FnD,IAAM,qBAAqB,cAAkC,IAAI;AAQjE,SAAS,iBAAqC;AACnD,SAAO,WAAW,kBAAkB;AACtC;AAUO,SAAS,yBAAsC;AACpD,QAAM,IAAI,WAAW,kBAAkB;AACvC,MAAI,CAAC,GAAG;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IAMF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|