@sentientui/react 0.2.1 → 0.3.1

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/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { SentientConfig, SentientClient } from '@sentientui/core';
4
4
  export { deriveSessionSegment as detectSegment } from '@sentientui/core';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
 
6
7
  /** How to render adaptive slots during SSR when assignments are not preloaded. */
7
8
  type SsrFallback = 'first' | 'none';
@@ -39,6 +40,12 @@ type AdaptiveProviderProps = {
39
40
  * (Mixpanel, PostHog, Segment, etc.) without having to wrap `useAssignment`.
40
41
  */
41
42
  onAssignment?: (componentId: string, variantId: string) => void;
43
+ /**
44
+ * SSR-preloaded section order from `loadAdaptiveDecision()`.
45
+ * Pass the `layoutOrder` field from `DecideResult`. When set,
46
+ * `useLayoutOrder()` returns this on first render so there is no layout shift.
47
+ */
48
+ initialLayoutOrder?: string[] | null;
42
49
  children: ReactNode;
43
50
  };
44
51
  /**
@@ -53,6 +60,11 @@ declare function AdaptiveProvider(props: AdaptiveProviderProps): JSX.Element;
53
60
  declare function useSentient(): SentientClient | null;
54
61
  /** Internal: SSR-preloaded assignments for hydration-safe first render. */
55
62
  declare function useInitialAssignments(): Record<string, string>;
63
+ /**
64
+ * Returns the persona-specific section order from SSR, or null when no
65
+ * sections were declared on AdaptiveRoot or reliability is below threshold.
66
+ */
67
+ declare function useLayoutOrder(): string[] | null;
56
68
 
57
69
  type ScrollDepthGoal = {
58
70
  type: 'scroll_depth';
@@ -85,6 +97,14 @@ declare function AdaptiveImpl(props: AdaptiveProps): JSX.Element | null;
85
97
  /** Re-renders only when the chosen variant changes. */
86
98
  declare const Adaptive: react.MemoExoticComponent<typeof AdaptiveImpl>;
87
99
 
100
+ type AdaptiveTextProps = {
101
+ id: string;
102
+ default: string;
103
+ component?: keyof JSX.IntrinsicElements;
104
+ className?: string;
105
+ };
106
+ declare function AdaptiveText({ id, default: defaultText, component: Tag, className, }: AdaptiveTextProps): react_jsx_runtime.JSX.Element;
107
+
88
108
  declare global {
89
109
  interface Window {
90
110
  __sentient_overrides?: Record<string, string>;
@@ -92,6 +112,8 @@ declare global {
92
112
  }
93
113
  type AssignmentState = {
94
114
  variantId: string | null;
115
+ /** Populated when the assigned variant is a dashboard-managed text variant. */
116
+ content: string | null;
95
117
  isLoading: boolean;
96
118
  };
97
119
  /**
@@ -99,7 +121,7 @@ type AssignmentState = {
99
121
  *
100
122
  * First render reads the local SDK cache; if empty, falls back to a
101
123
  * deterministic default and asynchronously calls `/v1/assign`. The server
102
- * picks the actual variant via ε-greedy and the result replaces the fallback
124
+ * picks the actual variant via Thompson Sampling and the result replaces the fallback
103
125
  * on the next render. Subsequent paints read synchronously from cache —
104
126
  * no flicker, no loading state after first paint.
105
127
  */
@@ -132,4 +154,4 @@ declare function update(componentId: string, weights: ComponentWeights): void;
132
154
  */
133
155
  declare function getWeights(componentId: string): ComponentWeights | null;
134
156
 
135
- export { Adaptive, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FormSubmitGoal, type GoalConfig, type ScrollDepthGoal, type SsrFallback, type VariantWeight, getWeights, subscribe as subscribeWeights, update as updateWeights, useAssignment, useInitialAssignments, useSentient };
157
+ export { Adaptive, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, AdaptiveText, type AdaptiveTextProps, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FormSubmitGoal, type GoalConfig, type ScrollDepthGoal, type SsrFallback, type VariantWeight, getWeights, subscribe as subscribeWeights, update as updateWeights, useAssignment, useInitialAssignments, useLayoutOrder, useSentient };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { SentientConfig, SentientClient } from '@sentientui/core';
4
4
  export { deriveSessionSegment as detectSegment } from '@sentientui/core';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
6
 
6
7
  /** How to render adaptive slots during SSR when assignments are not preloaded. */
7
8
  type SsrFallback = 'first' | 'none';
@@ -39,6 +40,12 @@ type AdaptiveProviderProps = {
39
40
  * (Mixpanel, PostHog, Segment, etc.) without having to wrap `useAssignment`.
40
41
  */
41
42
  onAssignment?: (componentId: string, variantId: string) => void;
43
+ /**
44
+ * SSR-preloaded section order from `loadAdaptiveDecision()`.
45
+ * Pass the `layoutOrder` field from `DecideResult`. When set,
46
+ * `useLayoutOrder()` returns this on first render so there is no layout shift.
47
+ */
48
+ initialLayoutOrder?: string[] | null;
42
49
  children: ReactNode;
43
50
  };
44
51
  /**
@@ -53,6 +60,11 @@ declare function AdaptiveProvider(props: AdaptiveProviderProps): JSX.Element;
53
60
  declare function useSentient(): SentientClient | null;
54
61
  /** Internal: SSR-preloaded assignments for hydration-safe first render. */
55
62
  declare function useInitialAssignments(): Record<string, string>;
63
+ /**
64
+ * Returns the persona-specific section order from SSR, or null when no
65
+ * sections were declared on AdaptiveRoot or reliability is below threshold.
66
+ */
67
+ declare function useLayoutOrder(): string[] | null;
56
68
 
57
69
  type ScrollDepthGoal = {
58
70
  type: 'scroll_depth';
@@ -85,6 +97,14 @@ declare function AdaptiveImpl(props: AdaptiveProps): JSX.Element | null;
85
97
  /** Re-renders only when the chosen variant changes. */
86
98
  declare const Adaptive: react.MemoExoticComponent<typeof AdaptiveImpl>;
87
99
 
100
+ type AdaptiveTextProps = {
101
+ id: string;
102
+ default: string;
103
+ component?: keyof JSX.IntrinsicElements;
104
+ className?: string;
105
+ };
106
+ declare function AdaptiveText({ id, default: defaultText, component: Tag, className, }: AdaptiveTextProps): react_jsx_runtime.JSX.Element;
107
+
88
108
  declare global {
89
109
  interface Window {
90
110
  __sentient_overrides?: Record<string, string>;
@@ -92,6 +112,8 @@ declare global {
92
112
  }
93
113
  type AssignmentState = {
94
114
  variantId: string | null;
115
+ /** Populated when the assigned variant is a dashboard-managed text variant. */
116
+ content: string | null;
95
117
  isLoading: boolean;
96
118
  };
97
119
  /**
@@ -99,7 +121,7 @@ type AssignmentState = {
99
121
  *
100
122
  * First render reads the local SDK cache; if empty, falls back to a
101
123
  * deterministic default and asynchronously calls `/v1/assign`. The server
102
- * picks the actual variant via ε-greedy and the result replaces the fallback
124
+ * picks the actual variant via Thompson Sampling and the result replaces the fallback
103
125
  * on the next render. Subsequent paints read synchronously from cache —
104
126
  * no flicker, no loading state after first paint.
105
127
  */
@@ -132,4 +154,4 @@ declare function update(componentId: string, weights: ComponentWeights): void;
132
154
  */
133
155
  declare function getWeights(componentId: string): ComponentWeights | null;
134
156
 
135
- export { Adaptive, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FormSubmitGoal, type GoalConfig, type ScrollDepthGoal, type SsrFallback, type VariantWeight, getWeights, subscribe as subscribeWeights, update as updateWeights, useAssignment, useInitialAssignments, useSentient };
157
+ export { Adaptive, type AdaptiveProps, AdaptiveProvider, type AdaptiveProviderProps, AdaptiveText, type AdaptiveTextProps, type AssignmentState, type ClickGoal, type ComponentWeights, type CompositeGoal, type FormSubmitGoal, type GoalConfig, type ScrollDepthGoal, type SsrFallback, type VariantWeight, getWeights, subscribe as subscribeWeights, update as updateWeights, useAssignment, useInitialAssignments, useLayoutOrder, useSentient };
package/dist/index.js CHANGED
@@ -23,12 +23,14 @@ var src_exports = {};
23
23
  __export(src_exports, {
24
24
  Adaptive: () => Adaptive,
25
25
  AdaptiveProvider: () => AdaptiveProvider,
26
+ AdaptiveText: () => AdaptiveText,
26
27
  detectSegment: () => import_core2.deriveSessionSegment,
27
28
  getWeights: () => getWeights,
28
29
  subscribeWeights: () => subscribe,
29
30
  updateWeights: () => update,
30
31
  useAssignment: () => useAssignment,
31
32
  useInitialAssignments: () => useInitialAssignments,
33
+ useLayoutOrder: () => useLayoutOrder,
32
34
  useSentient: () => useSentient
33
35
  });
34
36
  module.exports = __toCommonJS(src_exports);
@@ -39,14 +41,15 @@ var import_core = require("@sentientui/core");
39
41
  var import_jsx_runtime = require("react/jsx-runtime");
40
42
  var AdaptiveContext = (0, import_react.createContext)({
41
43
  client: null,
42
- projectId: "",
44
+ apiKey: "",
43
45
  initialAssignments: {},
44
46
  sessionSegment: "desktop:direct",
45
47
  ssrFallback: "first",
46
- onAssignment: void 0
48
+ onAssignment: void 0,
49
+ initialLayoutOrder: null
47
50
  });
48
51
  function AdaptiveProvider(props) {
49
- var _a, _b, _c;
52
+ var _a, _b, _c, _d;
50
53
  const [client, setClient] = (0, import_react.useState)(null);
51
54
  (0, import_react.useEffect)(() => {
52
55
  if (props.consent === false) {
@@ -75,11 +78,12 @@ function AdaptiveProvider(props) {
75
78
  {
76
79
  value: {
77
80
  client,
78
- projectId: props.apiKey,
81
+ apiKey: props.apiKey,
79
82
  initialAssignments: (_b = props.initialAssignments) != null ? _b : {},
80
83
  sessionSegment: (_c = props.sessionSegment) != null ? _c : "desktop:direct",
81
84
  ssrFallback,
82
- onAssignment: props.onAssignment
85
+ onAssignment: props.onAssignment,
86
+ initialLayoutOrder: (_d = props.initialLayoutOrder) != null ? _d : null
83
87
  },
84
88
  children: props.children
85
89
  }
@@ -88,8 +92,8 @@ function AdaptiveProvider(props) {
88
92
  function useSentient() {
89
93
  return (0, import_react.useContext)(AdaptiveContext).client;
90
94
  }
91
- function useAdaptiveProjectId() {
92
- return (0, import_react.useContext)(AdaptiveContext).projectId;
95
+ function useAdaptiveApiKey() {
96
+ return (0, import_react.useContext)(AdaptiveContext).apiKey;
93
97
  }
94
98
  function useInitialAssignments() {
95
99
  return (0, import_react.useContext)(AdaptiveContext).initialAssignments;
@@ -103,6 +107,9 @@ function useSsrFallback() {
103
107
  function useOnAssignment() {
104
108
  return (0, import_react.useContext)(AdaptiveContext).onAssignment;
105
109
  }
110
+ function useLayoutOrder() {
111
+ return (0, import_react.useContext)(AdaptiveContext).initialLayoutOrder;
112
+ }
106
113
 
107
114
  // src/adaptive.tsx
108
115
  var import_react3 = require("react");
@@ -182,30 +189,30 @@ function useAssignment(componentId, variantIds) {
182
189
  console.info(`[sentient] override active: ${componentId} -> ${overrideVariant}`);
183
190
  }
184
191
  const initial = (() => {
185
- var _a;
192
+ var _a, _b;
186
193
  if (overrideVariant) {
187
- return { variantId: overrideVariant, isLoading: false };
194
+ return { variantId: overrideVariant, content: null, isLoading: false };
188
195
  }
189
196
  if (!client) {
190
197
  const preloaded = initialAssignments[componentId];
191
198
  if (preloaded && variantIds.includes(preloaded)) {
192
- return { variantId: preloaded, isLoading: false };
199
+ return { variantId: preloaded, content: null, isLoading: false };
193
200
  }
194
201
  if (ssrFallback === "first" && variantIds.length > 0) {
195
- return { variantId: variantIds[0], isLoading: false };
202
+ return { variantId: variantIds[0], content: null, isLoading: false };
196
203
  }
197
- return { variantId: null, isLoading: true };
204
+ return { variantId: null, content: null, isLoading: true };
198
205
  }
199
206
  const cached = client.getAssignment(componentId, segment);
200
- if (cached && variantIds.includes(cached.variantId)) {
201
- return { variantId: cached.variantId, isLoading: false };
207
+ if (cached && (variantIds.includes(cached.variantId) || cached.content)) {
208
+ return { variantId: cached.variantId, content: (_a = cached.content) != null ? _a : null, isLoading: false };
202
209
  }
203
210
  const weights = getWeights(componentId);
204
211
  if (weights) {
205
212
  const chosen = pickFromWeights(weights, variantIds);
206
- if (chosen) return { variantId: chosen, isLoading: false };
213
+ if (chosen) return { variantId: chosen, content: null, isLoading: false };
207
214
  }
208
- return { variantId: (_a = variantIds[0]) != null ? _a : null, isLoading: false };
215
+ return { variantId: (_b = variantIds[0]) != null ? _b : null, content: null, isLoading: false };
209
216
  })();
210
217
  const [state, setState] = (0, import_react2.useState)(initial);
211
218
  const reportAssignment = (variantId) => {
@@ -215,17 +222,18 @@ function useAssignment(componentId, variantIds) {
215
222
  onAssignment(componentId, variantId);
216
223
  };
217
224
  (0, import_react2.useEffect)(() => {
225
+ var _a;
218
226
  if (overrideVariant) return;
219
227
  if (!client) return;
220
228
  const cached = client.getAssignment(componentId, segment);
221
- if (cached && variantIds.includes(cached.variantId)) {
222
- setState({ variantId: cached.variantId, isLoading: false });
229
+ if (cached && (variantIds.includes(cached.variantId) || cached.content)) {
230
+ setState({ variantId: cached.variantId, content: (_a = cached.content) != null ? _a : null, isLoading: false });
223
231
  reportAssignment(cached.variantId);
224
232
  return;
225
233
  }
226
234
  setState((prev) => {
227
- var _a;
228
- return prev.variantId ? prev : { variantId: (_a = variantIds[0]) != null ? _a : null, isLoading: false };
235
+ var _a2;
236
+ return prev.variantId ? prev : { variantId: (_a2 = variantIds[0]) != null ? _a2 : null, content: null, isLoading: false };
229
237
  });
230
238
  }, [overrideVariant, client, componentId, segment]);
231
239
  (0, import_react2.useEffect)(() => {
@@ -235,9 +243,11 @@ function useAssignment(componentId, variantIds) {
235
243
  if (cached && variantIds.includes(cached.variantId)) return;
236
244
  let cancelled = false;
237
245
  void client.assign(componentId, variantIds).then((result) => {
246
+ var _a;
238
247
  if (cancelled) return;
239
- if (!result || !variantIds.includes(result.variantId)) return;
240
- setState({ variantId: result.variantId, isLoading: false });
248
+ if (!result) return;
249
+ if (!variantIds.includes(result.variantId) && !result.content) return;
250
+ setState({ variantId: result.variantId, content: (_a = result.content) != null ? _a : null, isLoading: false });
241
251
  reportAssignment(result.variantId);
242
252
  });
243
253
  return () => {
@@ -248,17 +258,18 @@ function useAssignment(componentId, variantIds) {
248
258
  if (overrideVariant) return;
249
259
  if (!client) return;
250
260
  return subscribe(componentId, (weights) => {
261
+ var _a;
251
262
  const cached = client.getAssignment(componentId, segment);
252
- if (cached && variantIds.includes(cached.variantId)) {
253
- setState({ variantId: cached.variantId, isLoading: false });
263
+ if (cached && (variantIds.includes(cached.variantId) || cached.content)) {
264
+ setState({ variantId: cached.variantId, content: (_a = cached.content) != null ? _a : null, isLoading: false });
254
265
  return;
255
266
  }
256
267
  const chosen = pickFromWeights(weights, variantIds);
257
- if (chosen) setState({ variantId: chosen, isLoading: false });
268
+ if (chosen) setState({ variantId: chosen, content: null, isLoading: false });
258
269
  });
259
270
  }, [overrideVariant, client, componentId, segment]);
260
271
  if (overrideVariant) {
261
- return { variantId: overrideVariant, isLoading: false };
272
+ return { variantId: overrideVariant, content: null, isLoading: false };
262
273
  }
263
274
  return state;
264
275
  }
@@ -285,11 +296,11 @@ function findClickable(start, container) {
285
296
  return false;
286
297
  }
287
298
  function AdaptiveImpl(props) {
288
- var _a;
299
+ var _a, _b;
289
300
  const client = useSentient();
290
- const projectId = useAdaptiveProjectId();
301
+ const apiKey = useAdaptiveApiKey();
291
302
  const variantIds = (0, import_react3.useMemo)(() => Object.keys(props.variants), [props.variants]);
292
- const { variantId } = useAssignment(props.id, variantIds);
303
+ const { variantId, content } = useAssignment(props.id, variantIds);
293
304
  const containerRef = (0, import_react3.useRef)(null);
294
305
  const [mounted, setMounted] = (0, import_react3.useState)(false);
295
306
  (0, import_react3.useEffect)(() => {
@@ -300,20 +311,20 @@ function AdaptiveImpl(props) {
300
311
  const goal = (0, import_react3.useMemo)(() => normalize(props.goal), [props.goal]);
301
312
  const goalLabel = typeof props.goal === "string" ? props.goal : goal.type;
302
313
  (0, import_react3.useEffect)(() => {
303
- var _a2, _b;
304
- if (!client || !variantId || !projectId) return;
314
+ var _a2, _b2;
315
+ if (!client || !variantId || !apiKey) return;
305
316
  if (assignTrackedRef.current === variantId) return;
306
- const rawHtml = (_b = (_a2 = containerRef.current) == null ? void 0 : _a2.innerHTML) != null ? _b : "";
317
+ const rawHtml = (_b2 = (_a2 = containerRef.current) == null ? void 0 : _a2.innerHTML) != null ? _b2 : "";
307
318
  if (!rawHtml && !mounted) return;
308
319
  assignTrackedRef.current = variantId;
309
320
  client.track({
310
- projectId,
321
+ projectId: apiKey,
311
322
  componentId: props.id,
312
323
  variantId,
313
324
  eventType: "variant_assigned",
314
325
  payload: rawHtml ? { previewHtml: rawHtml.slice(0, 3e4) } : {}
315
326
  });
316
- }, [client, variantId, projectId, props.id, mounted]);
327
+ }, [client, variantId, apiKey, props.id, mounted]);
317
328
  (0, import_react3.useEffect)(() => {
318
329
  goalFiredRef.current = false;
319
330
  }, [variantId]);
@@ -327,7 +338,7 @@ function AdaptiveImpl(props) {
327
338
  hoverStart = Date.now();
328
339
  timerId = setTimeout(() => {
329
340
  client.track({
330
- projectId,
341
+ projectId: apiKey,
331
342
  componentId: props.id,
332
343
  variantId,
333
344
  eventType: "cursor_signal",
@@ -349,7 +360,7 @@ function AdaptiveImpl(props) {
349
360
  node.removeEventListener("mouseleave", onLeave);
350
361
  if (timerId !== null) clearTimeout(timerId);
351
362
  };
352
- }, [client, variantId, projectId, props.id]);
363
+ }, [client, variantId, apiKey, props.id]);
353
364
  (0, import_react3.useEffect)(() => {
354
365
  if (!client || !variantId) return;
355
366
  const node = containerRef.current;
@@ -358,7 +369,7 @@ function AdaptiveImpl(props) {
358
369
  if (goalFiredRef.current) return;
359
370
  goalFiredRef.current = true;
360
371
  client.track({
361
- projectId,
372
+ projectId: apiKey,
362
373
  componentId: props.id,
363
374
  variantId,
364
375
  eventType: "goal_achieved",
@@ -420,11 +431,17 @@ function AdaptiveImpl(props) {
420
431
  return () => {
421
432
  for (const c of cleanups) c();
422
433
  };
423
- }, [client, variantId, projectId, props.id, goal, goalLabel]);
434
+ }, [client, variantId, apiKey, props.id, goal, goalLabel]);
424
435
  if (props.clientOnly && (!mounted || !client)) return null;
425
436
  if (!variantId) return null;
426
- const content = (_a = props.variants[variantId]) != null ? _a : null;
427
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: containerRef, "data-sentient-id": props.id, "data-sentient-variant": variantId, children: content });
437
+ const jsxContent = (_a = props.variants[variantId]) != null ? _a : null;
438
+ const managedContent = jsxContent === null ? content : null;
439
+ if (((_b = process == null ? void 0 : process.env) == null ? void 0 : _b.NODE_ENV) !== "production" && jsxContent === null && managedContent === null) {
440
+ console.warn(
441
+ `[sentient] <Adaptive id="${props.id}"> was assigned variant "${variantId}" but no matching key exists in props.variants. If this is a dashboard-managed text variant, use <AdaptiveText id="${props.id}"> instead.`
442
+ );
443
+ }
444
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: containerRef, "data-sentient-id": props.id, "data-sentient-variant": variantId, children: jsxContent != null ? jsxContent : managedContent });
428
445
  }
429
446
  var Adaptive = (0, import_react3.memo)(AdaptiveImpl, (prev, next) => {
430
447
  if (prev.id !== next.id) return false;
@@ -436,18 +453,63 @@ var Adaptive = (0, import_react3.memo)(AdaptiveImpl, (prev, next) => {
436
453
  return prevKeys.every((k) => k in next.variants);
437
454
  });
438
455
 
456
+ // src/adaptive-text.tsx
457
+ var import_react4 = require("react");
458
+ var import_jsx_runtime3 = require("react/jsx-runtime");
459
+ function AdaptiveText({
460
+ id,
461
+ default: defaultText,
462
+ component: Tag = "span",
463
+ className
464
+ }) {
465
+ const client = useSentient();
466
+ const apiKey = useAdaptiveApiKey();
467
+ const onAssignment = useOnAssignment();
468
+ const [text, setText] = (0, import_react4.useState)(null);
469
+ const [variantId, setVariantId] = (0, import_react4.useState)(null);
470
+ const trackedRef = (0, import_react4.useRef)(null);
471
+ (0, import_react4.useEffect)(() => {
472
+ if (!client) return;
473
+ let cancelled = false;
474
+ void client.assign(id).then((result) => {
475
+ if (cancelled || !result) return;
476
+ setVariantId(result.variantId);
477
+ if (result.content) setText(result.content);
478
+ });
479
+ return () => {
480
+ cancelled = true;
481
+ };
482
+ }, [client, id]);
483
+ (0, import_react4.useEffect)(() => {
484
+ if (!client || !variantId || !apiKey) return;
485
+ if (trackedRef.current === variantId) return;
486
+ trackedRef.current = variantId;
487
+ client.track({
488
+ projectId: apiKey,
489
+ componentId: id,
490
+ variantId,
491
+ eventType: "variant_assigned",
492
+ payload: {}
493
+ });
494
+ onAssignment == null ? void 0 : onAssignment(id, variantId);
495
+ }, [client, variantId, apiKey, id, onAssignment]);
496
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Tag, { className, children: text != null ? text : defaultText });
497
+ }
498
+
439
499
  // src/segment.ts
440
500
  var import_core2 = require("@sentientui/core");
441
501
  // Annotate the CommonJS export names for ESM import in node:
442
502
  0 && (module.exports = {
443
503
  Adaptive,
444
504
  AdaptiveProvider,
505
+ AdaptiveText,
445
506
  detectSegment,
446
507
  getWeights,
447
508
  subscribeWeights,
448
509
  updateWeights,
449
510
  useAssignment,
450
511
  useInitialAssignments,
512
+ useLayoutOrder,
451
513
  useSentient
452
514
  });
453
515
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/adaptive.tsx","../src/use-assignment.ts","../src/weights-store.ts","../src/segment.ts"],"sourcesContent":["export { AdaptiveProvider, useSentient, useInitialAssignments } from './provider.js';\nexport type { AdaptiveProviderProps, SsrFallback } from './provider.js';\n\nexport { Adaptive } from './adaptive.js';\nexport type {\n AdaptiveProps,\n GoalConfig,\n ClickGoal,\n ScrollDepthGoal,\n FormSubmitGoal,\n CompositeGoal,\n} from './adaptive.js';\n\nexport { useAssignment } from './use-assignment.js';\nexport type { AssignmentState } from './use-assignment.js';\n\nexport {\n subscribe as subscribeWeights,\n update as updateWeights,\n getWeights,\n} from './weights-store.js';\nexport type { ComponentWeights, VariantWeight } from './weights-store.js';\n\nexport { detectSegment } from './segment.js';\n","'use client';\n\nimport { createContext, useContext, useEffect, useState, type ReactNode } from 'react';\nimport { init, type SentientClient, type SentientConfig } from '@sentientui/core';\n\n/** How to render adaptive slots during SSR when assignments are not preloaded. */\nexport type SsrFallback = 'first' | 'none';\n\ntype AdaptiveContextValue = {\n client: SentientClient | null;\n projectId: string;\n initialAssignments: Record<string, string>;\n sessionSegment: string;\n ssrFallback: SsrFallback;\n onAssignment: ((componentId: string, variantId: string) => void) | undefined;\n};\n\nconst AdaptiveContext = createContext<AdaptiveContextValue>({\n client: null,\n projectId: '',\n initialAssignments: {},\n sessionSegment: 'desktop:direct',\n ssrFallback: 'first',\n onAssignment: undefined,\n});\n\nexport type AdaptiveProviderProps = {\n apiKey: string;\n context: SentientConfig['context'];\n debug?: boolean;\n /**\n * SSR-preloaded assignments from `preloadAssignments()` / `loadAdaptiveAssignments()`.\n * Passed through to `useAssignment` as synchronous initial state so crawlers and\n * the first paint see real content (recommended for SEO).\n */\n initialAssignments?: Record<string, string>;\n /**\n * Bandit segment from SSR (`device:source`). Keeps cache, assign, and worker\n * weights on one row — must match `loadAdaptiveAssignments` / session upsert.\n */\n sessionSegment?: string;\n /**\n * When no `initialAssignments` exist for a component, `'first'` renders\n * `variantIds[0]` in server HTML (safe default for SEO). Use `'none'` only for\n * decorative slots marked `clientOnly`.\n * @default 'first'\n */\n ssrFallback?: SsrFallback;\n /**\n * Consent gate. When `false` the SDK is not initialised and no events are\n * sent. Flip to `true` (e.g. after the user accepts the cookie banner) to\n * initialise and begin tracking.\n */\n consent?: boolean;\n /**\n * Called once per component the first time a variant is resolved for that\n * component in this session. Use to forward assignments to your own analytics\n * (Mixpanel, PostHog, Segment, etc.) without having to wrap `useAssignment`.\n */\n onAssignment?: (componentId: string, variantId: string) => void;\n children: ReactNode;\n};\n\n/**\n * Initialises the Sentient core SDK in a useEffect (SSR-safe) and exposes the\n * client via React context. Re-initialises when `consent` changes.\n */\nexport function AdaptiveProvider(props: AdaptiveProviderProps): JSX.Element {\n const [client, setClient] = useState<SentientClient | null>(null);\n\n useEffect(() => {\n // When consent is explicitly false, tear down any existing client.\n if (props.consent === false) {\n setClient((prev: SentientClient | null) => {\n prev?.destroy();\n return null;\n });\n return;\n }\n\n const c = init({\n apiKey: props.apiKey,\n context: props.context,\n debug: props.debug,\n initialAssignments: props.initialAssignments,\n sessionSegment: props.sessionSegment,\n consent: props.consent,\n });\n setClient(c);\n return () => {\n c.destroy();\n };\n // Re-init when consent changes. Other props are intentionally stable.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.consent]);\n\n const ssrFallback = props.ssrFallback ?? 'first';\n\n return (\n <AdaptiveContext.Provider\n value={{\n client,\n projectId: props.apiKey,\n initialAssignments: props.initialAssignments ?? {},\n sessionSegment: props.sessionSegment ?? 'desktop:direct',\n ssrFallback,\n onAssignment: props.onAssignment,\n }}\n >\n {props.children}\n </AdaptiveContext.Provider>\n );\n}\n\n/**\n * Returns the SentientClient, or null until the provider has finished\n * initialising on the client.\n */\nexport function useSentient(): SentientClient | null {\n return useContext(AdaptiveContext).client;\n}\n\n/** Internal: project identifier carried alongside the client. */\nexport function useAdaptiveProjectId(): string {\n return useContext(AdaptiveContext).projectId;\n}\n\n/** Internal: SSR-preloaded assignments for hydration-safe first render. */\nexport function useInitialAssignments(): Record<string, string> {\n return useContext(AdaptiveContext).initialAssignments;\n}\n\n/** Internal: bandit segment aligned with SSR session upsert. */\nexport function useSessionSegment(): string {\n return useContext(AdaptiveContext).sessionSegment;\n}\n\n/** Internal: SSR fallback strategy when a slot has no preloaded assignment. */\nexport function useSsrFallback(): SsrFallback {\n return useContext(AdaptiveContext).ssrFallback;\n}\n\n/** Internal: forwarding hook for consumer analytics integration. */\nexport function useOnAssignment(): ((componentId: string, variantId: string) => void) | undefined {\n return useContext(AdaptiveContext).onAssignment;\n}\n","'use client';\n\nimport { memo, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';\nimport { useAdaptiveProjectId, useSentient } from './provider.js';\nimport { useAssignment } from './use-assignment.js';\n\nexport type ScrollDepthGoal = { type: 'scroll_depth'; threshold: number };\nexport type ClickGoal = { type: 'click'; selector?: string };\nexport type FormSubmitGoal = { type: 'form_submit' };\nexport type CompositeGoal = { type: 'composite'; all: GoalConfig[] };\nexport type GoalConfig = ScrollDepthGoal | ClickGoal | FormSubmitGoal | CompositeGoal;\n\nexport type AdaptiveProps = {\n id: string;\n variants: Record<string, ReactNode>;\n goal: string | GoalConfig;\n /**\n * When true, renders nothing during SSR and before client hydration.\n * Use when you cannot pass `initialAssignments` and prefer a blank slot over\n * a hydration mismatch. Tradeoff: minor CLS on first paint.\n */\n clientOnly?: boolean;\n};\n\nfunction normalize(goal: string | GoalConfig): GoalConfig {\n if (typeof goal === 'string') return { type: 'click' };\n return goal;\n}\n\nfunction isClickableTarget(el: EventTarget | null): boolean {\n if (!(el instanceof Element)) return false;\n const tag = el.tagName.toLowerCase();\n if (tag === 'a' || tag === 'button') return true;\n const role = el.getAttribute('role');\n return role === 'button';\n}\n\nfunction findClickable(start: Element, container: Element): boolean {\n let cursor: Element | null = start;\n while (cursor && cursor !== container) {\n if (isClickableTarget(cursor)) return true;\n cursor = cursor.parentElement;\n }\n return false;\n}\n\nfunction AdaptiveImpl(props: AdaptiveProps): JSX.Element | null {\n const client = useSentient();\n const projectId = useAdaptiveProjectId();\n const variantIds = useMemo(() => Object.keys(props.variants), [props.variants]);\n const { variantId } = useAssignment(props.id, variantIds);\n const containerRef = useRef<HTMLDivElement>(null);\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => { setMounted(true); }, []);\n const goalFiredRef = useRef(false);\n const assignTrackedRef = useRef<string | null>(null);\n const goal = useMemo(() => normalize(props.goal), [props.goal]);\n const goalLabel = typeof props.goal === 'string' ? props.goal : goal.type;\n\n // Track variant_assigned exactly once per (component, variant) mount.\n // Captures innerHTML as previewHtml so the dashboard can render a live preview\n // without requiring manual registry calls. First-seen wins on the server.\n // `mounted` is in deps so the effect re-runs after clientOnly components hydrate\n // and their container div is actually in the DOM.\n useEffect(() => {\n if (!client || !variantId || !projectId) return;\n if (assignTrackedRef.current === variantId) return;\n const rawHtml = containerRef.current?.innerHTML ?? '';\n // For clientOnly, the container is null until mounted — defer until it exists.\n if (!rawHtml && !mounted) return;\n assignTrackedRef.current = variantId;\n client.track({\n projectId,\n componentId: props.id,\n variantId,\n eventType: 'variant_assigned',\n payload: rawHtml ? { previewHtml: rawHtml.slice(0, 30_000) } : {},\n });\n }, [client, variantId, projectId, props.id, mounted]);\n\n // Reset goal latch when variant changes.\n useEffect(() => {\n goalFiredRef.current = false;\n }, [variantId]);\n\n // Emit cursor_signal after 800 ms of continuous hover.\n useEffect(() => {\n if (!client || !variantId) return;\n const node = containerRef.current;\n if (!node) return;\n\n let timerId: ReturnType<typeof setTimeout> | null = null;\n let hoverStart = 0;\n\n const onEnter = (): void => {\n hoverStart = Date.now();\n timerId = setTimeout(() => {\n client.track({\n projectId,\n componentId: props.id,\n variantId: variantId!,\n eventType: 'cursor_signal',\n payload: { hoverDuration: Date.now() - hoverStart },\n });\n timerId = null;\n }, 800);\n };\n\n const onLeave = (): void => {\n if (timerId !== null) {\n clearTimeout(timerId);\n timerId = null;\n }\n };\n\n node.addEventListener('mouseenter', onEnter);\n node.addEventListener('mouseleave', onLeave);\n return () => {\n node.removeEventListener('mouseenter', onEnter);\n node.removeEventListener('mouseleave', onLeave);\n if (timerId !== null) clearTimeout(timerId);\n };\n }, [client, variantId, projectId, props.id]);\n\n // Attach goal tracking.\n useEffect(() => {\n if (!client || !variantId) return;\n const node = containerRef.current;\n if (!node) return;\n\n const fireGoal = (): void => {\n if (goalFiredRef.current) return;\n goalFiredRef.current = true;\n client.track({\n projectId,\n componentId: props.id,\n variantId,\n eventType: 'goal_achieved',\n goalType: goalLabel,\n payload: { reward: 1.0 },\n });\n };\n\n const subgoals: GoalConfig[] = goal.type === 'composite' ? goal.all : [goal];\n const remaining = new Set<number>(subgoals.map((_, i) => i));\n const checkComposite = (idx: number): void => {\n remaining.delete(idx);\n if (remaining.size === 0) fireGoal();\n };\n\n const cleanups: Array<() => void> = [];\n\n subgoals.forEach((sub, idx) => {\n if (sub.type === 'click') {\n const onClick = (e: MouseEvent): void => {\n const target = e.target;\n if (!(target instanceof Element)) return;\n if (!findClickable(target, node)) return;\n if (goal.type === 'composite') checkComposite(idx);\n else fireGoal();\n };\n node.addEventListener('click', onClick);\n cleanups.push(() => node.removeEventListener('click', onClick));\n return;\n }\n\n if (sub.type === 'form_submit') {\n const onSubmit = (e: Event): void => {\n if (!(e.target instanceof HTMLFormElement)) return;\n if (!node.contains(e.target)) return;\n if (goal.type === 'composite') checkComposite(idx);\n else fireGoal();\n };\n node.addEventListener('submit', onSubmit);\n cleanups.push(() => node.removeEventListener('submit', onSubmit));\n return;\n }\n\n if (sub.type === 'scroll_depth') {\n const threshold = Math.max(0, Math.min(1, sub.threshold));\n const io = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n if (entry.intersectionRatio >= threshold) {\n if (goal.type === 'composite') checkComposite(idx);\n else fireGoal();\n io.disconnect();\n break;\n }\n }\n },\n { threshold: [threshold] },\n );\n io.observe(node);\n cleanups.push(() => io.disconnect());\n return;\n }\n });\n\n return () => {\n for (const c of cleanups) c();\n };\n }, [client, variantId, projectId, props.id, goal, goalLabel]);\n\n // Decorative slots: empty in SSR HTML and until the client has mounted.\n if (props.clientOnly && (!mounted || !client)) return null;\n if (!variantId) return null;\n const content = props.variants[variantId] ?? null;\n\n return (\n <div ref={containerRef} data-sentient-id={props.id} data-sentient-variant={variantId}>\n {content}\n </div>\n );\n}\n\n/** Re-renders only when the chosen variant changes. */\nexport const Adaptive = memo(AdaptiveImpl, (prev, next) => {\n if (prev.id !== next.id) return false;\n if (prev.goal !== next.goal) return false;\n if (prev.variants === next.variants) return true;\n const prevKeys = Object.keys(prev.variants);\n const nextKeys = Object.keys(next.variants);\n if (prevKeys.length !== nextKeys.length) return false;\n return prevKeys.every((k) => k in next.variants);\n});\n","import { useEffect, useRef, useState } from 'react';\nimport { type AssignResult } from '@sentientui/core';\nimport { useSentient, useInitialAssignments, useSessionSegment, useSsrFallback, useOnAssignment } from './provider.js';\nimport { subscribe, getWeights, type ComponentWeights } from './weights-store.js';\n\ndeclare global {\n interface Window { __sentient_overrides?: Record<string, string>; }\n}\n\nfunction getDevOverride(componentId: string): string | null {\n if (typeof window === 'undefined') return null;\n const global = window.__sentient_overrides?.[componentId];\n if (global) return global;\n try {\n const params = new URLSearchParams(window.location.search);\n for (const raw of params.getAll('sentient_variant')) {\n // sentient_variant=componentId:variantId (repeatable for multiple components)\n const sep = raw.indexOf(':');\n if (sep === -1) continue;\n if (raw.slice(0, sep) === componentId) return raw.slice(sep + 1);\n }\n } catch { /* non-browser env */ }\n return null;\n}\n\nexport type AssignmentState = {\n variantId: string | null;\n isLoading: boolean;\n};\n\nfunction pickFromWeights(weights: ComponentWeights, variantIds: string[]): string | null {\n let best: { variantId: string; avgReward: number } | null = null;\n for (const v of weights.variants) {\n if (!variantIds.includes(v.variantId)) continue;\n if (!best || v.avgReward > best.avgReward) {\n best = { variantId: v.variantId, avgReward: v.avgReward };\n }\n }\n return best?.variantId ?? null;\n}\n\n/**\n * Returns a sticky variant assignment for a component.\n *\n * First render reads the local SDK cache; if empty, falls back to a\n * deterministic default and asynchronously calls `/v1/assign`. The server\n * picks the actual variant via ε-greedy and the result replaces the fallback\n * on the next render. Subsequent paints read synchronously from cache —\n * no flicker, no loading state after first paint.\n */\nexport function useAssignment(componentId: string, variantIds: string[]): AssignmentState {\n const initialAssignments = useInitialAssignments();\n const ssrFallback = useSsrFallback();\n const client = useSentient();\n const segment = useSessionSegment();\n const onAssignment = useOnAssignment();\n const assignmentReportedRef = useRef<string | null>(null);\n\n // Dev override: URL param ?sentient_variant=componentId:variantId\n // or window.__sentient_overrides[componentId]. Short-circuits the bandit entirely.\n const devOverride = getDevOverride(componentId);\n const overrideVariant = devOverride && variantIds.includes(devOverride) ? devOverride : null;\n if (overrideVariant) {\n console.info(`[sentient] override active: ${componentId} -> ${overrideVariant}`);\n }\n\n const initial = (() => {\n if (overrideVariant) {\n return { variantId: overrideVariant, isLoading: false };\n }\n // SSR / pre-hydration: no client yet. Use initialAssignments if provided so\n // the server and client first render agree on the same variant (no mismatch).\n if (!client) {\n const preloaded = initialAssignments[componentId];\n if (preloaded && variantIds.includes(preloaded)) {\n return { variantId: preloaded, isLoading: false };\n }\n if (ssrFallback === 'first' && variantIds.length > 0) {\n return { variantId: variantIds[0], isLoading: false };\n }\n return { variantId: null, isLoading: true };\n }\n const cached = client.getAssignment(componentId, segment);\n if (cached && variantIds.includes(cached.variantId)) {\n return { variantId: cached.variantId, isLoading: false };\n }\n const weights = getWeights(componentId);\n if (weights) {\n const chosen = pickFromWeights(weights, variantIds);\n if (chosen) return { variantId: chosen, isLoading: false };\n }\n return { variantId: variantIds[0] ?? null, isLoading: false };\n })();\n\n const [state, setState] = useState<AssignmentState>(initial);\n\n // Helper: call onAssignment at most once per resolved variant.\n const reportAssignment = (variantId: string): void => {\n if (!onAssignment) return;\n if (assignmentReportedRef.current === variantId) return;\n assignmentReportedRef.current = variantId;\n onAssignment(componentId, variantId);\n };\n\n // As soon as the client is ready, unblock the UI immediately with variantIds[0]\n // (or a cached value) so the component never stays invisible while assign is\n // in-flight. The async assign call below then swaps to the bandit-chosen variant.\n useEffect(() => {\n if (overrideVariant) return;\n if (!client) return;\n const cached = client.getAssignment(componentId, segment);\n if (cached && variantIds.includes(cached.variantId)) {\n setState({ variantId: cached.variantId, isLoading: false });\n reportAssignment(cached.variantId);\n return;\n }\n setState((prev) => prev.variantId ? prev : { variantId: variantIds[0] ?? null, isLoading: false });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [overrideVariant, client, componentId, segment]);\n\n // Ask the server for a real assignment when we have a client but no cached one.\n useEffect(() => {\n if (overrideVariant) return;\n if (!client) return;\n const cached = client.getAssignment(componentId, segment);\n if (cached && variantIds.includes(cached.variantId)) return;\n\n let cancelled = false;\n void client.assign(componentId, variantIds).then((result: AssignResult | null) => {\n if (cancelled) return;\n // If the API is unreachable or returns null, the fallback set above stays.\n if (!result || !variantIds.includes(result.variantId)) return;\n setState({ variantId: result.variantId, isLoading: false });\n reportAssignment(result.variantId);\n });\n return () => { cancelled = true; };\n // variantIds intentionally excluded — changing variants mid-mount is unsupported\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [overrideVariant, client, componentId, segment]);\n\n // Live weight updates from the dashboard SSE stream (when wired).\n useEffect(() => {\n if (overrideVariant) return;\n if (!client) return;\n return subscribe(componentId, (weights) => {\n const cached = client.getAssignment(componentId, segment);\n if (cached && variantIds.includes(cached.variantId)) {\n setState({ variantId: cached.variantId, isLoading: false });\n return;\n }\n const chosen = pickFromWeights(weights, variantIds);\n if (chosen) setState({ variantId: chosen, isLoading: false });\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [overrideVariant, client, componentId, segment]);\n\n if (overrideVariant) {\n return { variantId: overrideVariant, isLoading: false };\n }\n\n return state;\n}\n","/** Per-component weights store with isolated subscriptions. */\n\nexport type VariantWeight = {\n variantId: string;\n pulls: number;\n avgReward: number;\n};\n\nexport type ComponentWeights = {\n componentId: string;\n variants: VariantWeight[];\n updatedAt: number;\n};\n\ntype Listener = (weights: ComponentWeights) => void;\n\nconst store = new Map<string, ComponentWeights>();\nconst listeners = new Map<string, Set<Listener>>();\n\n/**\n * Subscribes a listener to a single component. Returns an unsubscribe function.\n * Updates to other components never trigger this listener.\n */\nexport function subscribe(componentId: string, cb: Listener): () => void {\n let set = listeners.get(componentId);\n if (!set) {\n set = new Set();\n listeners.set(componentId, set);\n }\n set.add(cb);\n return () => {\n set!.delete(cb);\n if (set!.size === 0) listeners.delete(componentId);\n };\n}\n\n/**\n * Replaces the weights for a component and notifies only that component's\n * subscribers.\n */\nexport function update(componentId: string, weights: ComponentWeights): void {\n store.set(componentId, weights);\n const set = listeners.get(componentId);\n if (!set) return;\n for (const cb of set) {\n try {\n cb(weights);\n } catch {\n /* never throw to other listeners */\n }\n }\n}\n\n/**\n * Returns the latest known weights for a component, or null if none seen.\n */\nexport function getWeights(componentId: string): ComponentWeights | null {\n return store.get(componentId) ?? null;\n}\n\n/** Test-only: wipe the entire store. */\nexport function _resetWeightsStore(): void {\n store.clear();\n listeners.clear();\n}\n","/** @deprecated Use `useSessionSegment()` from the provider, or `deriveSessionSegment` from `@sentientui/core`. */\nexport { deriveSessionSegment as detectSegment } from '@sentientui/core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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ACF;AAAA,UACF;AAAA,UACA,EAAE,WAAW,CAAC,SAAS,EAAE;AAAA,QAC3B;AACA,WAAG,QAAQ,IAAI;AACf,iBAAS,KAAK,MAAM,GAAG,WAAW,CAAC;AACnC;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,iBAAW,KAAK,SAAU,GAAE;AAAA,IAC9B;AAAA,EACF,GAAG,CAAC,QAAQ,WAAW,WAAW,MAAM,IAAI,MAAM,SAAS,CAAC;AAG5D,MAAI,MAAM,eAAe,CAAC,WAAW,CAAC,QAAS,QAAO;AACtD,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,WAAU,WAAM,SAAS,SAAS,MAAxB,YAA6B;AAE7C,SACE,6CAAC,SAAI,KAAK,cAAc,oBAAkB,MAAM,IAAI,yBAAuB,WACxE,mBACH;AAEJ;AAGO,IAAM,eAAW,oBAAK,cAAc,CAAC,MAAM,SAAS;AACzD,MAAI,KAAK,OAAO,KAAK,GAAI,QAAO;AAChC,MAAI,KAAK,SAAS,KAAK,KAAM,QAAO;AACpC,MAAI,KAAK,aAAa,KAAK,SAAU,QAAO;AAC5C,QAAM,WAAW,OAAO,KAAK,KAAK,QAAQ;AAC1C,QAAM,WAAW,OAAO,KAAK,KAAK,QAAQ;AAC1C,MAAI,SAAS,WAAW,SAAS,OAAQ,QAAO;AAChD,SAAO,SAAS,MAAM,CAAC,MAAM,KAAK,KAAK,QAAQ;AACjD,CAAC;;;AGjOD,IAAAC,eAAsD;","names":["import_react","import_react","import_jsx_runtime","_a","import_core"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/adaptive.tsx","../src/use-assignment.ts","../src/weights-store.ts","../src/adaptive-text.tsx","../src/segment.ts"],"sourcesContent":["export { AdaptiveProvider, useSentient, useInitialAssignments, useLayoutOrder } from './provider.js';\nexport type { AdaptiveProviderProps, SsrFallback } from './provider.js';\n\nexport { Adaptive } from './adaptive.js';\nexport type {\n AdaptiveProps,\n GoalConfig,\n ClickGoal,\n ScrollDepthGoal,\n FormSubmitGoal,\n CompositeGoal,\n} from './adaptive.js';\n\nexport { AdaptiveText } from './adaptive-text.js';\nexport type { AdaptiveTextProps } from './adaptive-text.js';\n\nexport { useAssignment } from './use-assignment.js';\nexport type { AssignmentState } from './use-assignment.js';\n\nexport {\n subscribe as subscribeWeights,\n update as updateWeights,\n getWeights,\n} from './weights-store.js';\nexport type { ComponentWeights, VariantWeight } from './weights-store.js';\n\nexport { detectSegment } from './segment.js';\n","'use client';\n\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\nimport { createContext, useContext, useEffect, useState, type ReactNode } from 'react';\nimport { init, type SentientClient, type SentientConfig } from '@sentientui/core';\n\n/** How to render adaptive slots during SSR when assignments are not preloaded. */\nexport type SsrFallback = 'first' | 'none';\n\ntype AdaptiveContextValue = {\n client: SentientClient | null;\n // The publishable API key (pk_…). Historically named `projectId` because the\n // API uses it as the project identifier on the wire, but it is the API key,\n // not the project UUID. Field renamed for clarity.\n apiKey: string;\n initialAssignments: Record<string, string>;\n sessionSegment: string;\n ssrFallback: SsrFallback;\n onAssignment: ((componentId: string, variantId: string) => void) | undefined;\n initialLayoutOrder: string[] | null;\n};\n\nconst AdaptiveContext = createContext<AdaptiveContextValue>({\n client: null,\n apiKey: '',\n initialAssignments: {},\n sessionSegment: 'desktop:direct',\n ssrFallback: 'first',\n onAssignment: undefined,\n initialLayoutOrder: null,\n});\n\nexport type AdaptiveProviderProps = {\n apiKey: string;\n context: SentientConfig['context'];\n debug?: boolean;\n /**\n * SSR-preloaded assignments from `preloadAssignments()` / `loadAdaptiveAssignments()`.\n * Passed through to `useAssignment` as synchronous initial state so crawlers and\n * the first paint see real content (recommended for SEO).\n */\n initialAssignments?: Record<string, string>;\n /**\n * Bandit segment from SSR (`device:source`). Keeps cache, assign, and worker\n * weights on one row — must match `loadAdaptiveAssignments` / session upsert.\n */\n sessionSegment?: string;\n /**\n * When no `initialAssignments` exist for a component, `'first'` renders\n * `variantIds[0]` in server HTML (safe default for SEO). Use `'none'` only for\n * decorative slots marked `clientOnly`.\n * @default 'first'\n */\n ssrFallback?: SsrFallback;\n /**\n * Consent gate. When `false` the SDK is not initialised and no events are\n * sent. Flip to `true` (e.g. after the user accepts the cookie banner) to\n * initialise and begin tracking.\n */\n consent?: boolean;\n /**\n * Called once per component the first time a variant is resolved for that\n * component in this session. Use to forward assignments to your own analytics\n * (Mixpanel, PostHog, Segment, etc.) without having to wrap `useAssignment`.\n */\n onAssignment?: (componentId: string, variantId: string) => void;\n /**\n * SSR-preloaded section order from `loadAdaptiveDecision()`.\n * Pass the `layoutOrder` field from `DecideResult`. When set,\n * `useLayoutOrder()` returns this on first render so there is no layout shift.\n */\n initialLayoutOrder?: string[] | null;\n children: ReactNode;\n};\n\n/**\n * Initialises the Sentient core SDK in a useEffect (SSR-safe) and exposes the\n * client via React context. Re-initialises when `consent` changes.\n */\nexport function AdaptiveProvider(props: AdaptiveProviderProps): JSX.Element {\n const [client, setClient] = useState<SentientClient | null>(null);\n\n useEffect(() => {\n // When consent is explicitly false, tear down any existing client.\n if (props.consent === false) {\n setClient((prev: SentientClient | null) => {\n prev?.destroy();\n return null;\n });\n return;\n }\n\n const c = init({\n apiKey: props.apiKey,\n context: props.context,\n debug: props.debug,\n initialAssignments: props.initialAssignments,\n sessionSegment: props.sessionSegment,\n consent: props.consent,\n });\n setClient(c);\n return () => {\n c.destroy();\n };\n // Re-init when consent changes. Other props are intentionally stable.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.consent]);\n\n const ssrFallback = props.ssrFallback ?? 'first';\n\n return (\n <AdaptiveContext.Provider\n value={{\n client,\n apiKey: props.apiKey,\n initialAssignments: props.initialAssignments ?? {},\n sessionSegment: props.sessionSegment ?? 'desktop:direct',\n ssrFallback,\n onAssignment: props.onAssignment,\n initialLayoutOrder: props.initialLayoutOrder ?? null,\n }}\n >\n {props.children}\n </AdaptiveContext.Provider>\n );\n}\n\n/**\n * Returns the SentientClient, or null until the provider has finished\n * initialising on the client.\n */\nexport function useSentient(): SentientClient | null {\n return useContext(AdaptiveContext).client;\n}\n\n/** Internal: publishable API key carried alongside the client. */\nexport function useAdaptiveApiKey(): string {\n return useContext(AdaptiveContext).apiKey;\n}\n\n/**\n * @deprecated Renamed to `useAdaptiveApiKey`. Kept as an alias so external\n * imports from earlier versions of this package keep working. Will be removed\n * in 0.4.0.\n */\nlet warnedProjectIdAlias = false;\nexport function useAdaptiveProjectId(): string {\n if (\n !warnedProjectIdAlias &&\n typeof process !== 'undefined' &&\n process.env?.NODE_ENV !== 'production'\n ) {\n warnedProjectIdAlias = true;\n // eslint-disable-next-line no-console\n console.warn(\n '[@sentientui/react] useAdaptiveProjectId is deprecated; use useAdaptiveApiKey. Will be removed in 0.4.0.',\n );\n }\n return useAdaptiveApiKey();\n}\n\n/** Internal: SSR-preloaded assignments for hydration-safe first render. */\nexport function useInitialAssignments(): Record<string, string> {\n return useContext(AdaptiveContext).initialAssignments;\n}\n\n/** Internal: bandit segment aligned with SSR session upsert. */\nexport function useSessionSegment(): string {\n return useContext(AdaptiveContext).sessionSegment;\n}\n\n/** Internal: SSR fallback strategy when a slot has no preloaded assignment. */\nexport function useSsrFallback(): SsrFallback {\n return useContext(AdaptiveContext).ssrFallback;\n}\n\n/** Internal: forwarding hook for consumer analytics integration. */\nexport function useOnAssignment(): ((componentId: string, variantId: string) => void) | undefined {\n return useContext(AdaptiveContext).onAssignment;\n}\n\n/**\n * Returns the persona-specific section order from SSR, or null when no\n * sections were declared on AdaptiveRoot or reliability is below threshold.\n */\nexport function useLayoutOrder(): string[] | null {\n return useContext(AdaptiveContext).initialLayoutOrder;\n}\n","'use client';\n\ndeclare const process: { env?: { NODE_ENV?: string } } | undefined;\n\nimport { memo, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';\nimport { useAdaptiveApiKey, useSentient } from './provider.js';\nimport { useAssignment } from './use-assignment.js';\n\nexport type ScrollDepthGoal = { type: 'scroll_depth'; threshold: number };\nexport type ClickGoal = { type: 'click'; selector?: string };\nexport type FormSubmitGoal = { type: 'form_submit' };\nexport type CompositeGoal = { type: 'composite'; all: GoalConfig[] };\nexport type GoalConfig = ScrollDepthGoal | ClickGoal | FormSubmitGoal | CompositeGoal;\n\nexport type AdaptiveProps = {\n id: string;\n variants: Record<string, ReactNode>;\n goal: string | GoalConfig;\n /**\n * When true, renders nothing during SSR and before client hydration.\n * Use when you cannot pass `initialAssignments` and prefer a blank slot over\n * a hydration mismatch. Tradeoff: minor CLS on first paint.\n */\n clientOnly?: boolean;\n};\n\nfunction normalize(goal: string | GoalConfig): GoalConfig {\n if (typeof goal === 'string') return { type: 'click' };\n return goal;\n}\n\nfunction isClickableTarget(el: EventTarget | null): boolean {\n if (!(el instanceof Element)) return false;\n const tag = el.tagName.toLowerCase();\n if (tag === 'a' || tag === 'button') return true;\n const role = el.getAttribute('role');\n return role === 'button';\n}\n\nfunction findClickable(start: Element, container: Element): boolean {\n let cursor: Element | null = start;\n while (cursor && cursor !== container) {\n if (isClickableTarget(cursor)) return true;\n cursor = cursor.parentElement;\n }\n return false;\n}\n\nfunction AdaptiveImpl(props: AdaptiveProps): JSX.Element | null {\n const client = useSentient();\n const apiKey = useAdaptiveApiKey();\n const variantIds = useMemo(() => Object.keys(props.variants), [props.variants]);\n const { variantId, content } = useAssignment(props.id, variantIds);\n const containerRef = useRef<HTMLDivElement>(null);\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => { setMounted(true); }, []);\n const goalFiredRef = useRef(false);\n const assignTrackedRef = useRef<string | null>(null);\n const goal = useMemo(() => normalize(props.goal), [props.goal]);\n const goalLabel = typeof props.goal === 'string' ? props.goal : goal.type;\n\n // Track variant_assigned exactly once per (component, variant) mount.\n // Captures innerHTML as previewHtml so the dashboard can render a live preview\n // without requiring manual registry calls. First-seen wins on the server.\n // `mounted` is in deps so the effect re-runs after clientOnly components hydrate\n // and their container div is actually in the DOM.\n useEffect(() => {\n if (!client || !variantId || !apiKey) return;\n if (assignTrackedRef.current === variantId) return;\n const rawHtml = containerRef.current?.innerHTML ?? '';\n // For clientOnly, the container is null until mounted — defer until it exists.\n if (!rawHtml && !mounted) return;\n assignTrackedRef.current = variantId;\n client.track({\n projectId: apiKey,\n componentId: props.id,\n variantId,\n eventType: 'variant_assigned',\n payload: rawHtml ? { previewHtml: rawHtml.slice(0, 30_000) } : {},\n });\n }, [client, variantId, apiKey, props.id, mounted]);\n\n // Reset goal latch when variant changes.\n useEffect(() => {\n goalFiredRef.current = false;\n }, [variantId]);\n\n // Emit cursor_signal after 800 ms of continuous hover.\n useEffect(() => {\n if (!client || !variantId) return;\n const node = containerRef.current;\n if (!node) return;\n\n let timerId: ReturnType<typeof setTimeout> | null = null;\n let hoverStart = 0;\n\n const onEnter = (): void => {\n hoverStart = Date.now();\n timerId = setTimeout(() => {\n client.track({\n projectId: apiKey,\n componentId: props.id,\n variantId: variantId!,\n eventType: 'cursor_signal',\n payload: { hoverDuration: Date.now() - hoverStart },\n });\n timerId = null;\n }, 800);\n };\n\n const onLeave = (): void => {\n if (timerId !== null) {\n clearTimeout(timerId);\n timerId = null;\n }\n };\n\n node.addEventListener('mouseenter', onEnter);\n node.addEventListener('mouseleave', onLeave);\n return () => {\n node.removeEventListener('mouseenter', onEnter);\n node.removeEventListener('mouseleave', onLeave);\n if (timerId !== null) clearTimeout(timerId);\n };\n }, [client, variantId, apiKey, props.id]);\n\n // Attach goal tracking.\n useEffect(() => {\n if (!client || !variantId) return;\n const node = containerRef.current;\n if (!node) return;\n\n const fireGoal = (): void => {\n if (goalFiredRef.current) return;\n goalFiredRef.current = true;\n client.track({\n projectId: apiKey,\n componentId: props.id,\n variantId,\n eventType: 'goal_achieved',\n goalType: goalLabel,\n payload: { reward: 1.0 },\n });\n };\n\n const subgoals: GoalConfig[] = goal.type === 'composite' ? goal.all : [goal];\n const remaining = new Set<number>(subgoals.map((_, i) => i));\n const checkComposite = (idx: number): void => {\n remaining.delete(idx);\n if (remaining.size === 0) fireGoal();\n };\n\n const cleanups: Array<() => void> = [];\n\n subgoals.forEach((sub, idx) => {\n if (sub.type === 'click') {\n const onClick = (e: MouseEvent): void => {\n const target = e.target;\n if (!(target instanceof Element)) return;\n if (!findClickable(target, node)) return;\n if (goal.type === 'composite') checkComposite(idx);\n else fireGoal();\n };\n node.addEventListener('click', onClick);\n cleanups.push(() => node.removeEventListener('click', onClick));\n return;\n }\n\n if (sub.type === 'form_submit') {\n const onSubmit = (e: Event): void => {\n if (!(e.target instanceof HTMLFormElement)) return;\n if (!node.contains(e.target)) return;\n if (goal.type === 'composite') checkComposite(idx);\n else fireGoal();\n };\n node.addEventListener('submit', onSubmit);\n cleanups.push(() => node.removeEventListener('submit', onSubmit));\n return;\n }\n\n if (sub.type === 'scroll_depth') {\n const threshold = Math.max(0, Math.min(1, sub.threshold));\n const io = new IntersectionObserver(\n (entries) => {\n for (const entry of entries) {\n if (entry.intersectionRatio >= threshold) {\n if (goal.type === 'composite') checkComposite(idx);\n else fireGoal();\n io.disconnect();\n break;\n }\n }\n },\n { threshold: [threshold] },\n );\n io.observe(node);\n cleanups.push(() => io.disconnect());\n return;\n }\n });\n\n return () => {\n for (const c of cleanups) c();\n };\n }, [client, variantId, apiKey, props.id, goal, goalLabel]);\n\n // Decorative slots: empty in SSR HTML and until the client has mounted.\n if (props.clientOnly && (!mounted || !client)) return null;\n if (!variantId) return null;\n\n const jsxContent = props.variants[variantId] ?? null;\n const managedContent = jsxContent === null ? content : null;\n\n if (process?.env?.NODE_ENV !== 'production' && jsxContent === null && managedContent === null) {\n console.warn(\n `[sentient] <Adaptive id=\"${props.id}\"> was assigned variant \"${variantId}\" but no matching key exists in props.variants.` +\n ` If this is a dashboard-managed text variant, use <AdaptiveText id=\"${props.id}\"> instead.`,\n );\n }\n\n return (\n <div ref={containerRef} data-sentient-id={props.id} data-sentient-variant={variantId}>\n {jsxContent ?? managedContent}\n </div>\n );\n}\n\n/** Re-renders only when the chosen variant changes. */\nexport const Adaptive = memo(AdaptiveImpl, (prev, next) => {\n if (prev.id !== next.id) return false;\n if (prev.goal !== next.goal) return false;\n if (prev.variants === next.variants) return true;\n const prevKeys = Object.keys(prev.variants);\n const nextKeys = Object.keys(next.variants);\n if (prevKeys.length !== nextKeys.length) return false;\n return prevKeys.every((k) => k in next.variants);\n});\n","import { useEffect, useRef, useState } from 'react';\nimport { type AssignResult } from '@sentientui/core';\nimport { useSentient, useInitialAssignments, useSessionSegment, useSsrFallback, useOnAssignment } from './provider.js';\nimport { subscribe, getWeights, type ComponentWeights } from './weights-store.js';\n\ndeclare global {\n interface Window { __sentient_overrides?: Record<string, string>; }\n}\n\nfunction getDevOverride(componentId: string): string | null {\n if (typeof window === 'undefined') return null;\n const global = window.__sentient_overrides?.[componentId];\n if (global) return global;\n try {\n const params = new URLSearchParams(window.location.search);\n for (const raw of params.getAll('sentient_variant')) {\n // sentient_variant=componentId:variantId (repeatable for multiple components)\n const sep = raw.indexOf(':');\n if (sep === -1) continue;\n if (raw.slice(0, sep) === componentId) return raw.slice(sep + 1);\n }\n } catch { /* non-browser env */ }\n return null;\n}\n\nexport type AssignmentState = {\n variantId: string | null;\n /** Populated when the assigned variant is a dashboard-managed text variant. */\n content: string | null;\n isLoading: boolean;\n};\n\nfunction pickFromWeights(weights: ComponentWeights, variantIds: string[]): string | null {\n let best: { variantId: string; avgReward: number } | null = null;\n for (const v of weights.variants) {\n if (!variantIds.includes(v.variantId)) continue;\n if (!best || v.avgReward > best.avgReward) {\n best = { variantId: v.variantId, avgReward: v.avgReward };\n }\n }\n return best?.variantId ?? null;\n}\n\n/**\n * Returns a sticky variant assignment for a component.\n *\n * First render reads the local SDK cache; if empty, falls back to a\n * deterministic default and asynchronously calls `/v1/assign`. The server\n * picks the actual variant via Thompson Sampling and the result replaces the fallback\n * on the next render. Subsequent paints read synchronously from cache —\n * no flicker, no loading state after first paint.\n */\nexport function useAssignment(componentId: string, variantIds: string[]): AssignmentState {\n const initialAssignments = useInitialAssignments();\n const ssrFallback = useSsrFallback();\n const client = useSentient();\n const segment = useSessionSegment();\n const onAssignment = useOnAssignment();\n const assignmentReportedRef = useRef<string | null>(null);\n\n // Dev override: URL param ?sentient_variant=componentId:variantId\n // or window.__sentient_overrides[componentId]. Short-circuits the bandit entirely.\n const devOverride = getDevOverride(componentId);\n const overrideVariant = devOverride && variantIds.includes(devOverride) ? devOverride : null;\n if (overrideVariant) {\n console.info(`[sentient] override active: ${componentId} -> ${overrideVariant}`);\n }\n\n const initial = (() => {\n if (overrideVariant) {\n return { variantId: overrideVariant, content: null, isLoading: false };\n }\n // SSR / pre-hydration: no client yet. Use initialAssignments if provided so\n // the server and client first render agree on the same variant (no mismatch).\n if (!client) {\n const preloaded = initialAssignments[componentId];\n if (preloaded && variantIds.includes(preloaded)) {\n return { variantId: preloaded, content: null, isLoading: false };\n }\n if (ssrFallback === 'first' && variantIds.length > 0) {\n return { variantId: variantIds[0], content: null, isLoading: false };\n }\n return { variantId: null, content: null, isLoading: true };\n }\n const cached = client.getAssignment(componentId, segment);\n // Allow cached managed variants (content present) even if not in variantIds.\n if (cached && (variantIds.includes(cached.variantId) || cached.content)) {\n return { variantId: cached.variantId, content: cached.content ?? null, isLoading: false };\n }\n const weights = getWeights(componentId);\n if (weights) {\n const chosen = pickFromWeights(weights, variantIds);\n if (chosen) return { variantId: chosen, content: null, isLoading: false };\n }\n return { variantId: variantIds[0] ?? null, content: null, isLoading: false };\n })();\n\n const [state, setState] = useState<AssignmentState>(initial);\n\n // Helper: call onAssignment at most once per resolved variant.\n const reportAssignment = (variantId: string): void => {\n if (!onAssignment) return;\n if (assignmentReportedRef.current === variantId) return;\n assignmentReportedRef.current = variantId;\n onAssignment(componentId, variantId);\n };\n\n // As soon as the client is ready, unblock the UI immediately with variantIds[0]\n // (or a cached value) so the component never stays invisible while assign is\n // in-flight. The async assign call below then swaps to the bandit-chosen variant.\n useEffect(() => {\n if (overrideVariant) return;\n if (!client) return;\n const cached = client.getAssignment(componentId, segment);\n if (cached && (variantIds.includes(cached.variantId) || cached.content)) {\n setState({ variantId: cached.variantId, content: cached.content ?? null, isLoading: false });\n reportAssignment(cached.variantId);\n return;\n }\n setState((prev) => prev.variantId ? prev : { variantId: variantIds[0] ?? null, content: null, isLoading: false });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [overrideVariant, client, componentId, segment]);\n\n // Ask the server for a real assignment when we have a client but no cached one.\n useEffect(() => {\n if (overrideVariant) return;\n if (!client) return;\n const cached = client.getAssignment(componentId, segment);\n if (cached && variantIds.includes(cached.variantId)) return;\n\n let cancelled = false;\n void client.assign(componentId, variantIds).then((result: AssignResult | null) => {\n if (cancelled) return;\n if (!result) return;\n // Allow the result if it's a known code variant OR a managed text variant (has content).\n if (!variantIds.includes(result.variantId) && !result.content) return;\n setState({ variantId: result.variantId, content: result.content ?? null, isLoading: false });\n reportAssignment(result.variantId);\n });\n return () => { cancelled = true; };\n // variantIds intentionally excluded — changing variants mid-mount is unsupported\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [overrideVariant, client, componentId, segment]);\n\n // Live weight updates from the dashboard SSE stream (when wired).\n useEffect(() => {\n if (overrideVariant) return;\n if (!client) return;\n return subscribe(componentId, (weights) => {\n const cached = client.getAssignment(componentId, segment);\n if (cached && (variantIds.includes(cached.variantId) || cached.content)) {\n setState({ variantId: cached.variantId, content: cached.content ?? null, isLoading: false });\n return;\n }\n const chosen = pickFromWeights(weights, variantIds);\n if (chosen) setState({ variantId: chosen, content: null, isLoading: false });\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [overrideVariant, client, componentId, segment]);\n\n if (overrideVariant) {\n return { variantId: overrideVariant, content: null, isLoading: false };\n }\n\n return state;\n}\n","/** Per-component weights store with isolated subscriptions. */\n\nexport type VariantWeight = {\n variantId: string;\n pulls: number;\n avgReward: number;\n};\n\nexport type ComponentWeights = {\n componentId: string;\n variants: VariantWeight[];\n updatedAt: number;\n};\n\ntype Listener = (weights: ComponentWeights) => void;\n\nconst store = new Map<string, ComponentWeights>();\nconst listeners = new Map<string, Set<Listener>>();\n\n/**\n * Subscribes a listener to a single component. Returns an unsubscribe function.\n * Updates to other components never trigger this listener.\n */\nexport function subscribe(componentId: string, cb: Listener): () => void {\n let set = listeners.get(componentId);\n if (!set) {\n set = new Set();\n listeners.set(componentId, set);\n }\n set.add(cb);\n return () => {\n set!.delete(cb);\n if (set!.size === 0) listeners.delete(componentId);\n };\n}\n\n/**\n * Replaces the weights for a component and notifies only that component's\n * subscribers.\n */\nexport function update(componentId: string, weights: ComponentWeights): void {\n store.set(componentId, weights);\n const set = listeners.get(componentId);\n if (!set) return;\n for (const cb of set) {\n try {\n cb(weights);\n } catch {\n /* never throw to other listeners */\n }\n }\n}\n\n/**\n * Returns the latest known weights for a component, or null if none seen.\n */\nexport function getWeights(componentId: string): ComponentWeights | null {\n return store.get(componentId) ?? null;\n}\n\n/** Test-only: wipe the entire store. */\nexport function _resetWeightsStore(): void {\n store.clear();\n listeners.clear();\n}\n","'use client';\n\nimport { useEffect, useRef, useState } from 'react';\nimport type { AssignResult } from '@sentientui/core';\nimport { useSentient, useAdaptiveApiKey, useOnAssignment } from './provider.js';\n\nexport type AdaptiveTextProps = {\n id: string;\n default: string;\n component?: keyof JSX.IntrinsicElements;\n className?: string;\n};\n\nexport function AdaptiveText({\n id,\n default: defaultText,\n component: Tag = 'span',\n className,\n}: AdaptiveTextProps) {\n const client = useSentient();\n const apiKey = useAdaptiveApiKey();\n const onAssignment = useOnAssignment();\n const [text, setText] = useState<string | null>(null);\n const [variantId, setVariantId] = useState<string | null>(null);\n const trackedRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!client) return;\n let cancelled = false;\n void client.assign(id).then((result: AssignResult | null) => {\n if (cancelled || !result) return;\n setVariantId(result.variantId);\n if (result.content) setText(result.content);\n });\n return () => {\n cancelled = true;\n };\n }, [client, id]);\n\n useEffect(() => {\n if (!client || !variantId || !apiKey) return;\n if (trackedRef.current === variantId) return;\n trackedRef.current = variantId;\n client.track({\n projectId: apiKey,\n componentId: id,\n variantId,\n eventType: 'variant_assigned',\n payload: {},\n });\n onAssignment?.(id, variantId);\n }, [client, variantId, apiKey, id, onAssignment]);\n\n return <Tag className={className}>{text ?? defaultText}</Tag>;\n}\n","/** @deprecated Use `useSessionSegment()` from the provider, or `deriveSessionSegment` from `@sentientui/core`. */\nexport { deriveSessionSegment as detectSegment } from '@sentientui/core';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,mBAA+E;AAC/E,kBAA+D;AA2G3D;AAzFJ,IAAM,sBAAkB,4BAAoC;AAAA,EAC1D,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,oBAAoB,CAAC;AAAA,EACrB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,oBAAoB;AACtB,CAAC;AAiDM,SAAS,iBAAiB,OAA2C;AAhF5E;AAiFE,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAgC,IAAI;AAEhE,8BAAU,MAAM;AAEd,QAAI,MAAM,YAAY,OAAO;AAC3B,gBAAU,CAAC,SAAgC;AACzC,qCAAM;AACN,eAAO;AAAA,MACT,CAAC;AACD;AAAA,IACF;AAEA,UAAM,QAAI,kBAAK;AAAA,MACb,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,OAAO,MAAM;AAAA,MACb,oBAAoB,MAAM;AAAA,MAC1B,gBAAgB,MAAM;AAAA,MACtB,SAAS,MAAM;AAAA,IACjB,CAAC;AACD,cAAU,CAAC;AACX,WAAO,MAAM;AACX,QAAE,QAAQ;AAAA,IACZ;AAAA,EAGF,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,QAAM,eAAc,WAAM,gBAAN,YAAqB;AAEzC,SACE;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC,OAAO;AAAA,QACL;AAAA,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