@flamingo-stack/openframe-frontend-core 0.0.487 → 0.0.488-snapshot.20260728130942

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 (124) hide show
  1. package/dist/{chunk-4TFUB2CR.cjs → chunk-2IHN7NNB.cjs} +29 -29
  2. package/dist/{chunk-4TFUB2CR.cjs.map → chunk-2IHN7NNB.cjs.map} +1 -1
  3. package/dist/{chunk-UU4DW7JX.cjs → chunk-2RNJYJWO.cjs} +42 -42
  4. package/dist/{chunk-UU4DW7JX.cjs.map → chunk-2RNJYJWO.cjs.map} +1 -1
  5. package/dist/{chunk-W6GDTB4R.cjs → chunk-3OIB763B.cjs} +15 -15
  6. package/dist/{chunk-W6GDTB4R.cjs.map → chunk-3OIB763B.cjs.map} +1 -1
  7. package/dist/{chunk-NETEA5E4.js → chunk-5VSEMWWE.js} +6 -6
  8. package/dist/{chunk-K6MITU6M.cjs → chunk-5YMY4BAW.cjs} +77 -77
  9. package/dist/{chunk-K6MITU6M.cjs.map → chunk-5YMY4BAW.cjs.map} +1 -1
  10. package/dist/{chunk-KFQXO7QB.js → chunk-6GT557KN.js} +1 -1
  11. package/dist/chunk-6GT557KN.js.map +1 -0
  12. package/dist/{chunk-QBDHNUQX.js → chunk-B4YR342L.js} +6 -6
  13. package/dist/{chunk-SMD67GJP.js → chunk-BGWDDB7Y.js} +4 -4
  14. package/dist/{chunk-A7IPON2V.cjs → chunk-BIKOJ4FH.cjs} +5 -5
  15. package/dist/{chunk-A7IPON2V.cjs.map → chunk-BIKOJ4FH.cjs.map} +1 -1
  16. package/dist/{chunk-G4XU7BYU.js → chunk-EU6QNO4S.js} +2 -2
  17. package/dist/{chunk-ITEPRN6L.js → chunk-FKPXFTZT.js} +3 -3
  18. package/dist/{chunk-EO7MUGY4.cjs → chunk-H3YRJ3LZ.cjs} +14 -14
  19. package/dist/{chunk-EO7MUGY4.cjs.map → chunk-H3YRJ3LZ.cjs.map} +1 -1
  20. package/dist/{chunk-TJSJPOPL.cjs → chunk-IN4IO7BL.cjs} +395 -337
  21. package/dist/chunk-IN4IO7BL.cjs.map +1 -0
  22. package/dist/{chunk-HWK5CH5N.cjs → chunk-J7H32E3R.cjs} +18 -18
  23. package/dist/{chunk-HWK5CH5N.cjs.map → chunk-J7H32E3R.cjs.map} +1 -1
  24. package/dist/{chunk-BTMYUK4P.js → chunk-K7MNWYYI.js} +3 -3
  25. package/dist/{chunk-PECGZWQR.cjs → chunk-KP5KRRD6.cjs} +3 -3
  26. package/dist/{chunk-PECGZWQR.cjs.map → chunk-KP5KRRD6.cjs.map} +1 -1
  27. package/dist/{chunk-2B6773QM.cjs → chunk-LILQJ3UZ.cjs} +1 -1
  28. package/dist/chunk-LILQJ3UZ.cjs.map +1 -0
  29. package/dist/{chunk-RAYDQGJV.cjs → chunk-LLEDO4P7.cjs} +75 -75
  30. package/dist/{chunk-RAYDQGJV.cjs.map → chunk-LLEDO4P7.cjs.map} +1 -1
  31. package/dist/{chunk-AUGM74CO.js → chunk-N4MTNTSX.js} +7 -7
  32. package/dist/{chunk-KLYHZRAD.js → chunk-PB3BTZDU.js} +2 -2
  33. package/dist/{chunk-QW6SPNPT.cjs → chunk-RO7Q56ZK.cjs} +40 -40
  34. package/dist/{chunk-QW6SPNPT.cjs.map → chunk-RO7Q56ZK.cjs.map} +1 -1
  35. package/dist/{chunk-CWQACI4Z.js → chunk-RW2LPL72.js} +2 -2
  36. package/dist/{chunk-SDNMOAT4.js → chunk-TWGYBXYV.js} +4 -4
  37. package/dist/{chunk-WLRBZXFB.js → chunk-VL4LUO32.js} +3 -3
  38. package/dist/{chunk-QL7S3CH4.cjs → chunk-VLOE7MI2.cjs} +35 -35
  39. package/dist/{chunk-QL7S3CH4.cjs.map → chunk-VLOE7MI2.cjs.map} +1 -1
  40. package/dist/{chunk-UBK5HIMH.js → chunk-W6ZUOWSB.js} +7 -7
  41. package/dist/{chunk-GXOUXAXU.js → chunk-X2YF5TJS.js} +2 -2
  42. package/dist/{chunk-BC74IKAX.js → chunk-YMJZOANX.js} +277 -219
  43. package/dist/chunk-YMJZOANX.js.map +1 -0
  44. package/dist/{chunk-6SBAF5VG.cjs → chunk-Z7Y63IFU.cjs} +7 -7
  45. package/dist/{chunk-6SBAF5VG.cjs.map → chunk-Z7Y63IFU.cjs.map} +1 -1
  46. package/dist/{chunk-KTD2MGYF.cjs → chunk-ZIAS5NNL.cjs} +7 -7
  47. package/dist/{chunk-KTD2MGYF.cjs.map → chunk-ZIAS5NNL.cjs.map} +1 -1
  48. package/dist/components/case-studies/index.cjs +10 -10
  49. package/dist/components/case-studies/index.js +4 -4
  50. package/dist/components/chat/hooks/use-chat-history-hydration.d.ts +47 -0
  51. package/dist/components/chat/hooks/use-chat-history-hydration.d.ts.map +1 -0
  52. package/dist/components/chat/hooks/use-chat.d.ts +1 -0
  53. package/dist/components/chat/hooks/use-chat.d.ts.map +1 -1
  54. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts +4 -0
  55. package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
  56. package/dist/components/chat/index.cjs +4 -4
  57. package/dist/components/chat/index.js +3 -3
  58. package/dist/components/chat/types/unified-chat-state.types.d.ts +5 -0
  59. package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
  60. package/dist/components/chat/utils/chat-conversation-storage.d.ts +34 -0
  61. package/dist/components/chat/utils/chat-conversation-storage.d.ts.map +1 -0
  62. package/dist/components/contact/index.cjs +5 -5
  63. package/dist/components/contact/index.js +4 -4
  64. package/dist/components/docs/index.cjs +7 -7
  65. package/dist/components/docs/index.js +6 -6
  66. package/dist/components/embeds/index.cjs +5 -5
  67. package/dist/components/embeds/index.js +4 -4
  68. package/dist/components/faq/index.cjs +6 -6
  69. package/dist/components/faq/index.js +5 -5
  70. package/dist/components/features/index.cjs +4 -4
  71. package/dist/components/features/index.js +3 -3
  72. package/dist/components/help-center-pages/index.cjs +23 -23
  73. package/dist/components/help-center-pages/index.js +14 -14
  74. package/dist/components/index.cjs +140 -140
  75. package/dist/components/index.js +12 -12
  76. package/dist/components/navigation/index.cjs +4 -4
  77. package/dist/components/navigation/index.js +3 -3
  78. package/dist/components/onboarding-guides/index.cjs +8 -8
  79. package/dist/components/onboarding-guides/index.js +7 -7
  80. package/dist/components/related-content/index.cjs +6 -6
  81. package/dist/components/related-content/index.js +5 -5
  82. package/dist/components/tickets/index.cjs +7 -7
  83. package/dist/components/tickets/index.js +6 -6
  84. package/dist/components/ui/index.cjs +4 -4
  85. package/dist/components/ui/index.js +3 -3
  86. package/dist/components/ui/query-report-table/query-report-table.d.ts.map +1 -1
  87. package/dist/components/ui/query-report-table/types.d.ts +2 -2
  88. package/dist/components/ui/query-report-table/types.d.ts.map +1 -1
  89. package/dist/contexts/chat-runtime-context.d.ts +8 -0
  90. package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
  91. package/dist/contexts/index.cjs +2 -2
  92. package/dist/contexts/index.js +1 -1
  93. package/dist/hooks/index.cjs +3 -3
  94. package/dist/hooks/index.js +2 -2
  95. package/dist/index.cjs +4 -4
  96. package/dist/index.js +3 -3
  97. package/package.json +1 -1
  98. package/src/components/chat/hooks/use-chat-history-hydration.ts +142 -0
  99. package/src/components/chat/hooks/use-chat.ts +12 -0
  100. package/src/components/chat/hooks/use-sse-chat-adapter.ts +109 -162
  101. package/src/components/chat/types/unified-chat-state.types.ts +6 -0
  102. package/src/components/chat/utils/chat-conversation-storage.ts +83 -0
  103. package/src/components/features/notifications/notification-drawer.tsx +1 -1
  104. package/src/components/ui/query-report-table/query-report-table-skeleton.tsx +1 -1
  105. package/src/components/ui/query-report-table/query-report-table.tsx +7 -8
  106. package/src/components/ui/query-report-table/types.ts +2 -2
  107. package/src/contexts/chat-runtime-context.tsx +8 -0
  108. package/dist/chunk-2B6773QM.cjs.map +0 -1
  109. package/dist/chunk-BC74IKAX.js.map +0 -1
  110. package/dist/chunk-KFQXO7QB.js.map +0 -1
  111. package/dist/chunk-TJSJPOPL.cjs.map +0 -1
  112. /package/dist/{chunk-NETEA5E4.js.map → chunk-5VSEMWWE.js.map} +0 -0
  113. /package/dist/{chunk-QBDHNUQX.js.map → chunk-B4YR342L.js.map} +0 -0
  114. /package/dist/{chunk-SMD67GJP.js.map → chunk-BGWDDB7Y.js.map} +0 -0
  115. /package/dist/{chunk-G4XU7BYU.js.map → chunk-EU6QNO4S.js.map} +0 -0
  116. /package/dist/{chunk-ITEPRN6L.js.map → chunk-FKPXFTZT.js.map} +0 -0
  117. /package/dist/{chunk-BTMYUK4P.js.map → chunk-K7MNWYYI.js.map} +0 -0
  118. /package/dist/{chunk-AUGM74CO.js.map → chunk-N4MTNTSX.js.map} +0 -0
  119. /package/dist/{chunk-KLYHZRAD.js.map → chunk-PB3BTZDU.js.map} +0 -0
  120. /package/dist/{chunk-CWQACI4Z.js.map → chunk-RW2LPL72.js.map} +0 -0
  121. /package/dist/{chunk-SDNMOAT4.js.map → chunk-TWGYBXYV.js.map} +0 -0
  122. /package/dist/{chunk-WLRBZXFB.js.map → chunk-VL4LUO32.js.map} +0 -0
  123. /package/dist/{chunk-UBK5HIMH.js.map → chunk-W6ZUOWSB.js.map} +0 -0
  124. /package/dist/{chunk-GXOUXAXU.js.map → chunk-X2YF5TJS.js.map} +0 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Chat conversation-id persistence — the SSE/Guide chat's ONLY local state.
3
+ *
4
+ * The stored value is the SERVER-minted conversation id echoed in the chat
5
+ * stream's leading metadata frame; the client never generates ids. Message
6
+ * history itself lives server-side (`chat_conversations` / `chat_messages`)
7
+ * and is rehydrated via the history endpoint — see
8
+ * `use-chat-history-hydration.ts`.
9
+ *
10
+ * Built on the lib-standard `createLocalStorageAdapter` (SSR guard,
11
+ * try/catch, quota-failure logging, dynamic namespacing) instead of raw
12
+ * `window.localStorage`. The namespace resolver runs on EVERY read/write, so
13
+ * a proxy-auth identity switch mid-page automatically re-partitions the key.
14
+ *
15
+ * Key shape: `mingo-chat-<source>[-u-<email>].conversation`
16
+ */
17
+
18
+ import {
19
+ createLocalStorageAdapter,
20
+ type LocalStorageAdapter,
21
+ } from '../../../utils/local-storage-adapter'
22
+ import { getChatProxyAuth } from './chat-proxy-auth-storage'
23
+
24
+ export interface PersistedChatConversation {
25
+ conversationId: string
26
+ }
27
+
28
+ const STORAGE_KEY = 'conversation'
29
+
30
+ const namespaceFor = (source: string): string => {
31
+ const base = `mingo-chat-${source}`
32
+ const auth = getChatProxyAuth()
33
+ return auth?.email ? `${base}-u-${encodeURIComponent(auth.email.toLowerCase())}` : base
34
+ }
35
+
36
+ /** One adapter per chat `source` (= platform). Memoize per mount. */
37
+ export function createChatConversationStorage(
38
+ source: string,
39
+ ): LocalStorageAdapter<PersistedChatConversation> {
40
+ return createLocalStorageAdapter<PersistedChatConversation>({
41
+ key: STORAGE_KEY,
42
+ namespace: () => namespaceFor(source),
43
+ validate: (parsed): parsed is PersistedChatConversation =>
44
+ !!parsed &&
45
+ typeof (parsed as PersistedChatConversation).conversationId === 'string' &&
46
+ (parsed as PersistedChatConversation).conversationId.length > 0,
47
+ logTag: '[chat-conversation-storage]',
48
+ })
49
+ }
50
+
51
+ /**
52
+ * Sweep THIS source's stale keys: the other-identity variants (base vs
53
+ * impersonation), and retired key shapes from before the server-minted-id
54
+ * design (raw `mingo-chat-<source>` and versioned `-v1`/`-v2` full-history
55
+ * stores). Boundary-aware: a hyphen-extended sibling source (`flamingo` vs
56
+ * `flamingo-teaser`) is NOT this source's namespace and must never be swept.
57
+ *
58
+ * Raw storage enumeration is unavoidable here — the adapter abstraction is
59
+ * per-key and Web Storage only exposes iteration on the raw object.
60
+ */
61
+ export function pruneStaleChatConversationStorage(source: string): void {
62
+ if (typeof window === 'undefined') return
63
+ try {
64
+ const base = `mingo-chat-${source}`
65
+ const currentKey = `${namespaceFor(source)}.${STORAGE_KEY}`
66
+ const ownedKey = (k: string) =>
67
+ k === base || // retired raw key (pre-adapter shape)
68
+ k === `${base}.${STORAGE_KEY}` || // current no-identity shape
69
+ k.startsWith(`${base}-u-`) || // per-identity shapes (current + retired)
70
+ k.startsWith(`${base}-v`) // retired versioned full-history shapes
71
+ const toRemove: string[] = []
72
+ for (let i = 0; i < window.localStorage.length; i++) {
73
+ const k = window.localStorage.key(i)
74
+ if (!k) continue
75
+ if (ownedKey(k) && k !== currentKey) toRemove.push(k)
76
+ }
77
+ for (const k of toRemove) {
78
+ window.localStorage.removeItem(k)
79
+ }
80
+ } catch {
81
+ // localStorage access blocked (Safari private mode etc.) — non-fatal.
82
+ }
83
+ }
@@ -73,7 +73,7 @@ export function NotificationDrawer({
73
73
  type="button"
74
74
  disabled={unreadCount === 0}
75
75
  onClick={markAllRead}
76
- className="self-center text-h6 text-ods-text-secondary underline transition-colors hover:text-ods-text-primary disabled:opacity-40"
76
+ className="self-center text-h6 text-ods-text-secondary underline transition-colors hover:text-ods-text-primary disabled:opacity-40 max-md:focus:outline-none max-md:focus-visible:outline-none"
77
77
  >
78
78
  Mark All Complete
79
79
  </button>
@@ -13,7 +13,7 @@ export function QueryReportTableSkeleton({
13
13
  const isCompact = variant === 'compact'
14
14
 
15
15
  return (
16
- <div className={cn('flex flex-col', isCompact ? 'gap-0' : 'gap-2', className)}>
16
+ <div className={cn('flex flex-col', isCompact ? 'gap-0' : 'gap-[var(--spacing-system-xs)]', className)}>
17
17
  {/* Skeleton header */}
18
18
  <div className={cn(
19
19
  'flex items-center gap-4 px-4',
@@ -58,21 +58,20 @@ export function QueryReportTable({
58
58
  } = useHorizontalScrollbar()
59
59
 
60
60
  return (
61
- <div className={cn('flex flex-col w-full', isCompact ? 'gap-0' : 'gap-6', className)}>
61
+ <div className={cn('flex flex-col w-full', isCompact ? 'gap-0' : 'gap-[var(--spacing-system-l)]', className)}>
62
62
  {/* Title bar — hidden in compact mode and when empty */}
63
63
  {!isCompact && (title || headerActions || (showExport && data.length > 0)) && (
64
- <div className="flex items-end justify-between pt-6">
64
+ <div className="flex items-end justify-between pt-[var(--spacing-system-l)]">
65
65
  <h2 className="text-h2 text-ods-text-primary">
66
66
  {title}
67
67
  </h2>
68
- <div className="flex items-center gap-3">
68
+ <div className="flex items-center gap-[var(--spacing-system-s)]">
69
69
  {headerActions}
70
70
  {showExport && data.length > 0 && (
71
71
  <Button
72
- className='bg-ods-card'
72
+ className='bg-ods-card max-md:hidden'
73
73
  variant="outline"
74
- size="small-legacy"
75
- leftIcon={<Download02Icon size={18} />}
74
+ leftIcon={<Download02Icon size={18} className="text-ods-text-secondary" />}
76
75
  onClick={handleExport}
77
76
  >
78
77
  Export CSV
@@ -99,7 +98,7 @@ export function QueryReportTable({
99
98
 
100
99
  {/* Table content */}
101
100
  {!loading && data.length > 0 && (
102
- <div className="flex flex-col gap-1">
101
+ <div className="flex flex-col">
103
102
  {/* Custom scrollbar track — hidden in compact mode */}
104
103
  {!isCompact && thumbRatio > 0 && (
105
104
  <div
@@ -136,7 +135,7 @@ export function QueryReportTable({
136
135
  columnWidth={columnWidth}
137
136
  variant={variant}
138
137
  />
139
- <div className={cn('flex flex-col', isCompact ? 'gap-0' : 'gap-2 p-4')}>
138
+ <div className={cn('flex flex-col', isCompact ? 'gap-0' : 'gap-[var(--spacing-system-xs)]')}>
140
139
  {data.map((row, index) => (
141
140
  <QueryReportTableRow
142
141
  key={index}
@@ -5,8 +5,8 @@ export type QueryResultRow = Record<string, string | number | null>
5
5
  export type QueryReportTableVariant = 'default' | 'compact'
6
6
 
7
7
  export interface QueryReportTableProps {
8
- /** Dynamic title displayed above the table (e.g., query name) */
9
- title: string
8
+ /** Dynamic title displayed above the table (e.g., query name); omit to render the table without a title bar */
9
+ title?: string
10
10
  /** Array of result rows — columns are derived from object keys */
11
11
  data: QueryResultRow[]
12
12
  /** Show skeleton loading state */
@@ -57,6 +57,14 @@ export interface ChatRuntime {
57
57
  listEngagementsUrl?: string
58
58
  /** GET slash-command catalog. Hub: '/api/docs/commands'. */
59
59
  commandsUrl: string
60
+ /** GET server-side conversation history (`?conversationId=<id>`) — the
61
+ * chat panel's mount-time hydration read against the server transcript
62
+ * store (localStorage keeps only the server-issued conversation id).
63
+ * OPTIONAL — defaults to `<chatStreamUrl>/history`, which is correct for
64
+ * same-origin hosts AND for reverse-proxy embedders (the proxied chat
65
+ * prefix covers it). Set explicitly only when the history route lives
66
+ * elsewhere. */
67
+ chatHistoryUrl?: string
60
68
  /** GET RAG-search endpoint behind `<DocSearchBar>` (the in-source search
61
69
  * bar mounted by `<DocViewer>` / `<DocsHubPage>` when `showAIChat` is on).
62
70
  * Hub: '/api/docs/search'. OPTIONAL — falls back to the hub path so
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-2B6773QM.cjs","../src/contexts/endpoints-runtime-context.tsx","../src/contexts/chat-runtime-context.tsx"],"names":["createContext","useContext"],"mappings":"AAAA,qFAAY;AACZ;AACA;ACqBA,8BAA0C;AAenC,IAAM,wBAAA,EAA0B,kCAAA,IAA2C,CAAA;AAO3E,SAAS,mBAAA,CAAA,EAA+C;AAC7D,EAAA,OAAO,+BAAA,uBAAkC,CAAA;AAC3C;AASO,SAAS,2BAAA,CAAA,EAAgD;AAC9D,EAAA,MAAM,EAAA,EAAI,+BAAA,uBAAkC,CAAA;AAC5C,EAAA,GAAA,CAAI,CAAC,CAAA,EAAG;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,IAIF,CAAA;AAAA,EACF;AACA,EAAA,OAAO,CAAA;AACT;ADlDA;AACA;AEiBA;AA0MO,IAAM,mBAAA,EAAqBA,kCAAAA,IAAsC,CAAA;AAQjE,SAAS,cAAA,CAAA,EAAqC;AACnD,EAAA,OAAOC,+BAAAA,kBAA6B,CAAA;AACtC;AAUO,SAAS,sBAAA,CAAA,EAAsC;AACpD,EAAA,MAAM,EAAA,EAAIA,+BAAAA,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;AF7OA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,mUAAC","file":"/home/runner/work/openframe-oss-lib/openframe-oss-lib/openframe-frontend-core/dist/chunk-2B6773QM.cjs","sourcesContent":[null,"'use client'\n\n/**\n * Endpoints runtime — sibling of ChatRuntime. Carries the API path\n * literals consumed by oss-lib components/hooks/utils so a host\n * application can override them (e.g. when running behind a reverse\n * proxy as `user1.openframe.ai` → `/api/mingo-guide/*`).\n *\n * The hub mounts `<HubRuntimeProvider>` at root with the\n * canonical hub paths; an embedded app mounts its own provider with\n * remapped paths. The pattern mirrors ChatRuntimeContext exactly:\n *\n * - `useEndpointsRuntime()` returns null when no provider is mounted.\n * For optional consumers that should gracefully no-op without one.\n * - `useRequiredEndpointsRuntime()` throws on missing provider — for\n * hooks/components that cannot function without endpoints.\n *\n * IMPORTANT for embedders: memoize the value passed to\n * `<EndpointsRuntimeContext.Provider value={...}>` (e.g. React.useMemo).\n * Reference changes invalidate downstream effect dependency arrays and\n * trigger unnecessary re-fetches.\n */\n\nimport { createContext, useContext } from 'react'\n\nexport interface EndpointsRuntime {\n /** GET active announcement (used by `<AnnouncementBar>` mount fetch + refocus revalidation). */\n announcementsUrl: string\n accessCode: {\n /** POST validate access code. */\n validateUrl: string\n /** POST consume / redeem access code after registration. */\n consumeUrl: string\n }\n /** POST contact-form submission. */\n contactUrl: string\n}\n\nexport const EndpointsRuntimeContext = createContext<EndpointsRuntime | null>(null)\n\n/**\n * Optional read — returns null when no provider is mounted. Use for\n * surfaces that should silently skip the fetch (e.g. announcement\n * polling on a page rendered outside the provider tree).\n */\nexport function useEndpointsRuntime(): EndpointsRuntime | null {\n return useContext(EndpointsRuntimeContext)\n}\n\n/**\n * Strict variant — throws on missing provider. Use for consumers that\n * cannot function without an endpoint (form submission, code\n * validation). In tests/Storybook, wrap with the hub's\n * `<HubRuntimeProvider>` or a stub\n * `<EndpointsRuntimeContext.Provider value={mockedEndpoints}>`.\n */\nexport function useRequiredEndpointsRuntime(): EndpointsRuntime {\n const v = useContext(EndpointsRuntimeContext)\n if (!v) {\n throw new Error(\n '[endpoints-runtime] hook called outside an <EndpointsRuntimeContext.Provider>. ' +\n 'Hub: mount <HubRuntimeProvider> in your providers tree. ' +\n 'Embedded app: mount your own provider with proxied URLs at the tree root. ' +\n 'Tests/Storybook: wrap render() in <EndpointsRuntimeContext.Provider value={mocked}>.',\n )\n }\n return v\n}\n","'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\nimport type { ComposeContentUrl } from '../utils/content-href'\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 /** Customer-ticket agent endpoints (Help Center). OPTIONAL — when unset,\n * the ticket hooks fall back to the bare hub paths\n * (`/api/chat/agent/{find-ticket,ticket-action,list-engagements}`).\n * Embedders behind a reverse proxy set these to their proxied paths\n * (e.g. `/content/api/chat/agent/...`) so tickets route through the SAME\n * endpoint config + proxy as every other endpoint. */\n findTicketUrl?: string\n ticketActionUrl?: string\n listEngagementsUrl?: string\n /** GET slash-command catalog. Hub: '/api/docs/commands'. */\n commandsUrl: string\n /** GET RAG-search endpoint behind `<DocSearchBar>` (the in-source search\n * bar mounted by `<DocViewer>` / `<DocsHubPage>` when `showAIChat` is on).\n * Hub: '/api/docs/search'. OPTIONAL — falls back to the hub path so\n * same-origin Next.js hosts don't need to set it. Cross-origin embedders\n * set their proxied path so the search bar routes through the same\n * reverse proxy as everything else. Same pattern as `findTicketUrl`. */\n docsSearchUrl?: string\n /** POST internal-link resolver. The in-source markdown renderer (lib or\n * custom) calls `<DocViewer>`'s `handlers.onResolveLink(href, currentPath)`\n * for relative hrefs like `./getting-started/intro.md` — that callback\n * posts to this URL with `{ link, currentPath, source }` and expects a\n * `ResolveLinkResult` back. Hub: '/api/docs/resolve-link'. OPTIONAL — same\n * fall-back chain as `docsSearchUrl`: prop override → runtime → default. */\n docsResolveLinkUrl?: string\n /** GET per-platform empty-state config (admin-edited in\n * `/admin/chat-config`): `{ greeting, enabledRagTableIds, suggestedQueries }`.\n * Hub: '/api/docs/empty-state'. OPTIONAL — the in-app (host-mode) chat\n * injects these values as SSR props instead, so it leaves this unset.\n * Cross-origin EMBEDDERS (no server hop) set it to their proxied path\n * (e.g. '/content/api/docs/empty-state') so `<EmbeddableChat>` can fetch\n * the greeting / quick-action chips / RAG-source filter at runtime. When\n * unset, the chat falls back to the explicit `emptyStateGreeting` /\n * `suggestedQueries` / `enabledRagTableIds` props (or in-code defaults). */\n emptyStateUrl?: string\n /** Build the per-agent display-config URL for an OpenFrame AI agent\n * (Fae/Mingo). OPTIONAL. The returned endpoint MUST be byte-compatible\n * with the empty-state wire shape ({ greeting, suggestedQueries,\n * enabledRagTableIds }). When set AND `EmbeddableChat` receives an\n * `activeAgentSlug` in embed mode, the chat fetches THIS url instead of\n * `emptyStateUrl` to render the selected agent's greeting + suggested\n * prompts (the \"agent mode\" URL override). Hub: `(slug) =>\n * '/api/ai-agents/' + encodeURIComponent(slug)`. */\n aiAgentConfigUrl?: (slug: string) => 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 * - `identityUrl` — GET endpoint the `useChatIdentity` hook\n * hits to learn the `{authTier, source, attachmentsEnabled}`\n * capability bag for the current session. Used beyond chat\n * (tickets / contact form / any embedded surface that needs\n * to identify the proxied customer), so the name has no\n * \"chat\" prefix even though the consuming hook still does. */\n attachmentUploadUrl: string\n attachmentViewUrlPrefix: string\n identityUrl: 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 /** Optional base URL for the branded og-placeholder image route — the\n * DEFAULT cover-image fallback for entity cards with no image. The lib\n * appends `?title=…` (+ `w`/`h` for square slots) itself, so this is\n * the base, NOT a full URL: relative (`/api/og-placeholder`) for same-\n * origin hosts, or the proxied path (`/content/api/og-placeholder`) for\n * cross-origin embedders. May carry baked-in query params (preserved when\n * the lib layers `title`/dimensions on top) — but per-platform brand\n * colors are NO LONGER baked here; the `/api/og-placeholder` route\n * resolves them server-side from the platform. Most hosts leave this unset\n * and let the lib derive the base from `imageProxyUrlPrefix`.\n *\n * OPTIONAL — when unset the lib derives the base from the sibling\n * `imageProxyUrlPrefix` (same API base, route name swapped), then falls\n * back to the relative `/api/og-placeholder`. So an embedder that already\n * proxies images needs NO og-placeholder wiring. See\n * `resolveOgPlaceholderBase` / `buildOgPlaceholderUrl` in `../utils`. */\n ogPlaceholderUrl?: string\n /** Supabase storage origin (e.g. `https://xyz.supabase.co`) — used\n * by `useVideoWarmup` to scope the `<link rel=\"preload\" as=\"video\">`\n * hint to MP4s the deployment actually hosts. Hub wires it via\n * `getSupabaseStorageOrigin()`; embedders without a Supabase\n * storage origin leave it unset (preload is then skipped; Mux/\n * YouTube preconnect still fires). */\n supabaseStorageOrigin?: 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 /** Optional content-URL composer. Returns the platform-aware href +\n * target-platform tuple for a content entity. Hub wires this to its\n * `buildContentURL(type, slug, extractPrimaryPlatform(platforms))`\n * pipeline so the lib catalog/detail views can derive cross-\n * platform hrefs without knowing the hub's platform topology\n * (openmsp.ai / openframe.app / flamingo.run / tmcg).\n *\n * THE single content-href authority for every embeddable surface — page\n * views (onboarding catalog/detail, releases) AND chat cards / chips /\n * search results all resolve content links through this one seam, so a\n * given type lands in the SAME place regardless of where it's rendered.\n * Embedders wire `makeComposeContentUrl({ hostedTypes, contentOrigin })`;\n * omit it and lib views fall back to a same-origin relative path\n * (`buildDefaultHref`).\n *\n * Takes a single `ComposeContentUrlInput`: `type` + `identifier` (page\n * views pass the slug; chat rows pass the id + `externalUrl`, whose path\n * yields the slug for in-app routing) + optional `platforms` /\n * `externalUrl` / `targetPlatform`. */\n composeContentUrl?: ComposeContentUrl\n /** Per-`documentType` doc-viewer targets — the UNIFIED, DYNAMIC replacement for\n * the single `chipBasePlatform` prop. Maps a doc-table documentType\n * (`'markdown'`, `'data_room_doc'`, …) → `{ platform, basePath }` for the PUBLIC\n * doc viewer that hosts it. Doc chips with no `externalUrl` resolve PER ROW to\n * `getBaseUrl(platform)/<basePath>/<path>`, so a chat mixing several doc sources\n * sends EACH to its own home (markdown→flamingo/knowledge-base,\n * data_room_doc→company-hub/data-room) instead of one static fallback. The hub\n * may keep using `chipBasePlatform` (one doc source per platform); embedders that\n * surface multiple doc sources wire this. Threaded into `resolveSourceRowCTA`. */\n docPlatformTargets?: Record<string, { platform: string; basePath: string }>\n /** Chat source / platform identifier — OPTIONAL. The hub sets it from\n * `currentPlatform()`; EMBEDDERS leave it unset and stay platform-agnostic.\n *\n * It is NOT required for chat to work. The wire resolves source server-side\n * (`/docs/chat|search|commands` reject any client `source`); the\n * same-tab-vs-new-tab link decision falls back to an origin comparison when\n * it's absent (`decideNewTab` → `isCrossOriginUrl`); and the localStorage\n * history namespace falls back to a stable constant. Set it only where the\n * client legitimately needs to know its platform a priori — i.e. the hub,\n * where several platforms share related origins so \"same platform\" can't be\n * inferred from a URL alone. */\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"]}