@sentientui/react 0.32.0 → 0.34.0
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/README.md +127 -46
- package/dist/devtools.js +1 -1
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.mjs +1 -1
- package/dist/devtools.mjs.map +1 -1
- package/dist/index.d.cts +76 -45
- package/dist/index.d.ts +76 -45
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/next/adaptive-root.d.ts +41 -5
- package/dist/next/adaptive-root.js +2 -2
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/server.d.cts +10 -2
- package/dist/server.d.ts +10 -2
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +1 -1
- package/dist/testing/msw.d.cts +1 -1
- package/dist/testing/msw.d.ts +1 -1
- package/dist/testing/msw.js.map +1 -1
- package/dist/testing/msw.mjs.map +1 -1
- package/dist/testing/node.d.cts +1 -1
- package/dist/testing/node.d.ts +1 -1
- package/dist/testing/node.js.map +1 -1
- package/dist/testing/node.mjs.map +1 -1
- package/dist/testing/react.d.cts +1 -1
- package/dist/testing/react.d.ts +1 -1
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/react.mjs +1 -1
- package/dist/testing/react.mjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs.map +1 -1
- package/llms.txt +5 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npx @sentientui/cli init
|
|
|
17
17
|
# then follow its printed instructions: wrap your app with <AdaptiveRoot> (or
|
|
18
18
|
# <AdaptiveProvider>) and mount the generated components/adaptive-example.tsx
|
|
19
19
|
npm run dev
|
|
20
|
-
# open http://localhost:3000?sentient_persona=
|
|
20
|
+
# open http://localhost:3000?sentient_persona=a, then ?sentient_persona=b — the example adapts
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
The CLI installs the package, writes `.env.local`, and generates an example component — it does
|
|
@@ -47,7 +47,6 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
47
47
|
<AdaptiveRoot
|
|
48
48
|
apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}
|
|
49
49
|
appOrigin={process.env.NEXT_PUBLIC_APP_URL!}
|
|
50
|
-
context="saas"
|
|
51
50
|
>
|
|
52
51
|
{children}
|
|
53
52
|
</AdaptiveRoot>
|
|
@@ -86,24 +85,21 @@ data-sentient-confidence = low | medium | high
|
|
|
86
85
|
```
|
|
87
86
|
|
|
88
87
|
The persona value is a key from the project's persona vocabulary (dashboard → Settings →
|
|
89
|
-
Personas) — declared by your app via the `persona` prop, or
|
|
90
|
-
|
|
88
|
+
Personas) — declared by your app via the `persona` prop, or discovered from behavior. The
|
|
89
|
+
vocabulary starts empty (every visitor is `unknown` until a persona exists). Renaming a persona in
|
|
91
90
|
the dashboard keeps the old key resolving as an alias, so existing CSS stays intact.
|
|
92
91
|
|
|
93
|
-
Write plain CSS against them (the canonical block —
|
|
92
|
+
Write plain CSS against them (the canonical block — swap in your own persona keys):
|
|
94
93
|
|
|
95
94
|
```css
|
|
96
95
|
/* Show each visitor type what it cares about. Confidence-gate bold treatments. */
|
|
97
|
-
html[data-sentient-persona='
|
|
98
|
-
html[data-sentient-persona='
|
|
99
|
-
html[data-sentient-
|
|
100
|
-
html[data-sentient-persona='browser'] .newsletter-nudge { display: block; }
|
|
101
|
-
html[data-sentient-confidence='low'] .discount-banner,
|
|
102
|
-
html[data-sentient-confidence='low'] .newsletter-nudge { display: none; }
|
|
96
|
+
html[data-sentient-persona='admin'] .admin-tools { display: block; }
|
|
97
|
+
html[data-sentient-persona='evaluator'] .spec-details { display: block; }
|
|
98
|
+
html[data-sentient-confidence='low'] .spec-details { display: none; }
|
|
103
99
|
```
|
|
104
100
|
|
|
105
101
|
In keyless local mode (development without a `pk_` key), force any persona with
|
|
106
|
-
`?sentient_persona=
|
|
102
|
+
`?sentient_persona=evaluator` (any key works locally). The override is not read in hosted (`pk_`) mode.
|
|
107
103
|
|
|
108
104
|
**1b. Adaptive tokens — learned.** Declare a bounded design space; the optimizer picks per
|
|
109
105
|
visitor type; values arrive as element-scoped `data-*` props (SSR-serialized — zero flicker):
|
|
@@ -137,6 +133,41 @@ Optional `{ goal: 'buy_click' }` third argument credits conversions to this elem
|
|
|
137
133
|
|
|
138
134
|
### Rung 2 — Swap (alternate content)
|
|
139
135
|
|
|
136
|
+
`<Adaptive>` fills a region one of two ways.
|
|
137
|
+
|
|
138
|
+
**Generated versions (start here).** Wrap what you show today — the children are the original:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { Adaptive } from '@sentientui/react';
|
|
142
|
+
|
|
143
|
+
<Adaptive id="hero-cta" goal="signup_click">
|
|
144
|
+
<a href="/signup">Start free trial</a>
|
|
145
|
+
</Adaptive>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Mounting it and deploying registers the region. SentientUI then writes versions per visitor type
|
|
149
|
+
in the dashboard ("Who sees what") — no redeploy. The children render for holdout/control
|
|
150
|
+
traffic, unknown visitor types, visitor types with no version yet, and every error path, so the
|
|
151
|
+
worst case is always "nothing changed". This works in any React app under `<AdaptiveRoot>` or
|
|
152
|
+
`<AdaptiveProvider>` as-is — no server preload: the regions mounted on a page are requested in
|
|
153
|
+
one batched call scoped to exactly those ids. A first visit shows the original briefly, then
|
|
154
|
+
swaps; return visits start from the last version served. Keyless local mode renders the
|
|
155
|
+
originals only. (Formerly `<AdaptiveSlot>`.)
|
|
156
|
+
|
|
157
|
+
**Code variants.** When you want to write the alternatives yourself, pass `variants` instead of
|
|
158
|
+
children:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
<Adaptive
|
|
162
|
+
id="buy-box"
|
|
163
|
+
goal="buy_click" // required
|
|
164
|
+
variants={{ control: <CalmBuyBox />, urgent: <UrgentBuyBox /> }} // first key = baseline
|
|
165
|
+
/>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Use one or the other on a given `<Adaptive>`, not both. `useAdaptive` is the hook form of code
|
|
169
|
+
variants:
|
|
170
|
+
|
|
140
171
|
```tsx
|
|
141
172
|
import { useAdaptive } from '@sentientui/react';
|
|
142
173
|
|
|
@@ -150,8 +181,8 @@ function BuyBox() {
|
|
|
150
181
|
```
|
|
151
182
|
|
|
152
183
|
`bind` (ref + data attributes) wires exposure tracking, goal listeners, and engagement signals —
|
|
153
|
-
attach it or the
|
|
154
|
-
|
|
184
|
+
attach it or the component cannot learn (dev mode warns loudly if you don't). `<AdaptiveText>`
|
|
185
|
+
swaps dashboard-managed text.
|
|
155
186
|
|
|
156
187
|
### Rung 3 — Reorder (structure)
|
|
157
188
|
|
|
@@ -187,22 +218,22 @@ Imported from `@sentientui/react/next`.
|
|
|
187
218
|
|
|
188
219
|
| Prop | Type | Description |
|
|
189
220
|
|------|------|-------------|
|
|
190
|
-
| `components` | `Array<{ id: string; variantIds: string[] }>` *(optional, default `[]`)* |
|
|
221
|
+
| `components` | `Array<{ id: string; variantIds: string[] }>` *(optional, default `[]`)* | Code-variant components to preload server-side. `id` must match `<Adaptive id="…" variants={…}>`; generated-version `<Adaptive>` regions need no entry. Omit when the tree uses only slots/sections or assigns client-side. |
|
|
191
222
|
| `sections` | `string[]` *(optional)* | Page section IDs in default order. When provided, a single `POST /v1/decide` returns both layout order and assignments; `useLayoutOrder()` becomes available. Give each section's element `data-sentient-id="<sectionId>"` — the only attribute a section needs — so the graph scanner can register it; without it the server types the section `generic` and every persona gets the same order. The provider warns about unresolvable ids in development. |
|
|
223
|
+
| `registrySlotIds` | `string[]` *(optional)* | The generated-mode `<Adaptive id>`s this page renders. Decides their published versions in the same SSR round trip and serializes the served content into the HTML, so first paint shows the version instead of the original children. Scoped to exactly these ids — an unscoped registry decide would record a trial for every published slot on every page. Omit and the regions decide client-side after mount. |
|
|
192
224
|
| `sectionTypes` | `Partial<Record<string, SemanticType>>` *(optional)* | What each section is, keyed by `data-sentient-id`: `{ about: 'trust', contact: 'cta' }`. Sections are classified from their content, so declare only the ones it gets wrong — a band with little signal-bearing copy (an "About us" block, a contact form) reads `generic` and is ordered the same for every persona. Any section with a `data-sentient-id` can appear, reorderable or not. Also accepted by `AdaptiveProvider`. |
|
|
193
225
|
| `apiKey` | `string` | `pk_…` key — used by both the browser SDK and server-side SSR requests. |
|
|
194
226
|
| `appOrigin` | `string` *(default `http://localhost:3001`)* | Your app origin (e.g. `https://yourapp.com`). Must be on the project's allowed-origins list. Always set in production. |
|
|
195
|
-
| `context` | `'landing' \| 'ecommerce' \| 'saas' \| 'marketplace'` |
|
|
227
|
+
| `context` | `'landing' \| 'ecommerce' \| 'saas' \| 'marketplace'` *(optional, deprecated)* | Unused — the project's type is set in the dashboard. Safe to omit. |
|
|
196
228
|
| `persona` | `string` *(optional)* | Declared persona — the role your app already knows for this visitor (e.g. from your auth context). Must be a key in the project's persona vocabulary (dashboard → Settings → Personas); unrecognized values are ignored server-side. Served at full confidence, overriding the inferred persona; forwarded through both SSR paths. Stable for the session — remount to apply a new value. Never a user id or email. |
|
|
197
229
|
| `consent` | `boolean` *(default `true`)* | Set `false` to skip SDK init (no cookies, no events). Flip to `true` after the visitor accepts. |
|
|
198
230
|
| `respectDoNotTrack` | `boolean` *(default `true`)* | Honor the browser's Do Not Track signal. When on and DNT is enabled, the SDK sets no cookies and sends no tracking data (overriding `consent: true`), and `grantConsent()` won't re-enable it. Set `false` to make your own consent gate authoritative. |
|
|
199
|
-
| `ssrFallback` | `'first' \| 'none'` *(default `'first'`)* | What to render in SSR HTML for components not in `components`. `'first'` is safe for SEO. |
|
|
200
231
|
| `timeoutMs` | `number` *(default `1000`)* | Server-side fetch timeout before falling back to the first variant. Typical decide is well under 150 ms; the full budget is only reached on a cold start or an API distant from your SSR host. |
|
|
201
232
|
| `debug` | `boolean` | Log assignment and event activity to the console. |
|
|
202
233
|
|
|
203
234
|
### `<AdaptiveProvider>` (any React app)
|
|
204
235
|
|
|
205
|
-
Accepts the same `apiKey`, `
|
|
236
|
+
Accepts the same `apiKey`, `persona`, `consent`, `debug` props as `<AdaptiveRoot>`, plus `onAssignment` (not available on `<AdaptiveRoot>` — function props can't cross the RSC boundary) and:
|
|
206
237
|
|
|
207
238
|
| Prop | Type | Description |
|
|
208
239
|
|------|------|-------------|
|
|
@@ -213,14 +244,32 @@ Accepts the same `apiKey`, `context`, `persona`, `consent`, `ssrFallback`, `debu
|
|
|
213
244
|
|
|
214
245
|
### `<Adaptive>`
|
|
215
246
|
|
|
247
|
+
One component, two modes — pass `children` (generated versions) or `variants` (code variants),
|
|
248
|
+
never both. `AdaptiveProps` is the union of the two exported prop types below.
|
|
249
|
+
|
|
250
|
+
**Generated versions** — `AdaptiveGeneratedProps`:
|
|
251
|
+
|
|
252
|
+
| Prop | Type | Description |
|
|
253
|
+
|------|------|-------------|
|
|
254
|
+
| `id` | `string` | Unique region identifier within your project. |
|
|
255
|
+
| `children` | `ReactNode` | The original. Renders for holdout/control traffic, unknown visitor types, visitor types with no version, and every error path. |
|
|
256
|
+
| `goal` | `string \| GoalConfig` *(optional)* | Conversion goal credited to this region. |
|
|
257
|
+
| `onFormSubmit` | `(values: Record<string, string>) => void` *(optional)* | Receives the values when a generated form version submits. Form versions are only offered when this is present; values never reach SentientUI. |
|
|
258
|
+
| `className` | `string` *(optional)* | Class for the wrapper `<div>`. |
|
|
259
|
+
| `reportBaselineText` | `boolean` *(default `true`)* | At first registration, send this region's rendered text (capped at 400 chars) so generated versions are grounded in what they replace. Set `false` for a region wrapping personalized or account content. |
|
|
260
|
+
|
|
261
|
+
**Code variants** — `AdaptiveVariantsProps`:
|
|
262
|
+
|
|
216
263
|
| Prop | Type | Description |
|
|
217
264
|
|------|------|-------------|
|
|
218
265
|
| `id` | `string` | Unique component identifier within your project. |
|
|
219
|
-
| `variants` | `Record<string, ReactNode>` | Map of variant ID → content. Any two or more keys; the bandit explores them all. |
|
|
220
|
-
| `goal` | `string \| GoalConfig` | Conversion goal. A string is a click-goal label; an object is an explicit `GoalConfig`. |
|
|
266
|
+
| `variants` | `Record<string, ReactNode>` | Map of variant ID → content. Any two or more keys; the first key is the control, and the bandit explores them all. |
|
|
267
|
+
| `goal` | `string \| GoalConfig` | Conversion goal (required). A string is a click-goal label; an object is an explicit `GoalConfig`. |
|
|
268
|
+
| `funnel` | `string` *(optional)* | Funnel this component serves — see [Funnels](#funnels--funnel-prop). |
|
|
269
|
+
| `microSignalGoals` | `MicroSignalGoals` *(optional)* | When a passive micro-signal fires on this component, also record a named goal: micro-signal type → goal name (or `{ name, weight?, stepIndex? }`), e.g. `{ rage_click: 'confused_by_hero' }`. |
|
|
221
270
|
| `agentDataByVariant` | `Record<string, unknown>` *(optional)* | Structured data keyed by variant ID that AI agents can consume via `GET /v1/agent/layout`. Only the assigned variant's entry is sent to the server. Preferred over `agentData`. |
|
|
222
271
|
| `agentData` | `unknown` *(optional, deprecated)* | Deprecated in favour of `agentDataByVariant`. Single value stored once regardless of which variant is shown; kept for backward compatibility. |
|
|
223
|
-
| `clientOnly` | `boolean` | Render nothing on the server; resolve on the client only. Use for cookie-dependent
|
|
272
|
+
| `clientOnly` | `boolean` | Render nothing on the server; resolve on the client only. Use for cookie-dependent components. Without it, a component with no preloaded assignment server-renders its first variant. (This replaces the deprecated provider-level `ssrFallback="none"`, which is still accepted.) |
|
|
224
273
|
|
|
225
274
|
#### Goal types
|
|
226
275
|
|
|
@@ -290,13 +339,13 @@ The funnel id is stable — a funnel created in the dashboard or chat is referen
|
|
|
290
339
|
|
|
291
340
|
### `<AdaptiveText>`
|
|
292
341
|
|
|
293
|
-
Lightweight text-only variant (renders an inline `<span>` wrapper by default — change it via the `component` prop
|
|
342
|
+
Lightweight text-only variant (renders an inline `<span>` wrapper by default — change it via the `component` prop). Useful when you publish text variants from the dashboard WYSIWYG. Pass `goal` (a name or a goal config, exactly like `<Adaptive>`) to score the copy — without it the wording is served and logged but never learns.
|
|
294
343
|
|
|
295
344
|
```tsx
|
|
296
345
|
import { AdaptiveText } from '@sentientui/react';
|
|
297
346
|
|
|
298
347
|
<h1>
|
|
299
|
-
<AdaptiveText id="hero_headline" default="Ship faster with SentientUI" />
|
|
348
|
+
<AdaptiveText id="hero_headline" default="Ship faster with SentientUI" goal="signup_click" />
|
|
300
349
|
</h1>
|
|
301
350
|
```
|
|
302
351
|
|
|
@@ -320,7 +369,12 @@ hydration mismatch. Renaming a value is a cold start for that value's learning.
|
|
|
320
369
|
```ts
|
|
321
370
|
function useAdaptive<T>(
|
|
322
371
|
id: string,
|
|
323
|
-
config: {
|
|
372
|
+
config: {
|
|
373
|
+
variants: Record<string, T>; // first key = baseline
|
|
374
|
+
goal: string | GoalConfig;
|
|
375
|
+
funnel?: string;
|
|
376
|
+
microSignalGoals?: MicroSignalGoals; // same mapping as <Adaptive microSignalGoals>
|
|
377
|
+
},
|
|
324
378
|
): {
|
|
325
379
|
variant: string;
|
|
326
380
|
value: T;
|
|
@@ -330,7 +384,9 @@ function useAdaptive<T>(
|
|
|
330
384
|
```
|
|
331
385
|
|
|
332
386
|
Headless Swap-rung hook. `goal` is required and `bind` must be attached to a rendered element —
|
|
333
|
-
learning needs both. Supersedes `useAssignment`.
|
|
387
|
+
learning needs both. Supersedes `useAssignment`. It runs the same exposure, goal, funnel and
|
|
388
|
+
micro-signal tracking as `<Adaptive variants>` (everything waits for the real assignment, not the
|
|
389
|
+
first-key placeholder), minus the wrapper `<div>` and the hover `cursor_signal`.
|
|
334
390
|
|
|
335
391
|
### `<AdaptiveGroup>`
|
|
336
392
|
|
|
@@ -412,8 +468,8 @@ Prefer this over a click goal on the link that led here. Arrival survives the na
|
|
|
412
468
|
|
|
413
469
|
Two failure modes it exists to prevent, both silent if you hand-roll this with `useAdaptiveGoal` in a `useEffect`:
|
|
414
470
|
|
|
415
|
-
- **Double counting.**
|
|
416
|
-
- **Losing the goal to a consent gate.** Behind a cookie banner the client doesn't exist when the page mounts, so firing on mount drops the arrival for every visitor who accepts a moment later. `usePageGoal` holds it until the SDK is running.
|
|
471
|
+
- **Double counting.** A hand-rolled effect re-runs — React's double-invoked effects in development, or the client arriving — and records the arrival again unless you pass `useAdaptiveGoal`'s `{ once: true }`. Both latches are per mounted component, so a genuine remount records again with either.
|
|
472
|
+
- **Losing the goal to a consent gate.** Behind a cookie banner the client doesn't exist when the page mounts, so firing on mount drops the arrival for every visitor who accepts a moment later (and `once` spends its latch on that dropped call). `usePageGoal` holds it until the SDK is running.
|
|
417
473
|
|
|
418
474
|
### `useLayoutOrder()`
|
|
419
475
|
|
|
@@ -458,7 +514,6 @@ Pass `assignments` as `initialAssignments` **and `sessionId` as `ssrSessionId`**
|
|
|
458
514
|
```tsx
|
|
459
515
|
<AdaptiveProvider
|
|
460
516
|
apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}
|
|
461
|
-
context="saas"
|
|
462
517
|
onAssignment={(componentId, variantId) => {
|
|
463
518
|
posthog.capture('$feature_flag_called', { $feature_flag: componentId, $feature_flag_response: variantId });
|
|
464
519
|
mixpanel.register({ [`variant_${componentId}`]: variantId });
|
|
@@ -496,7 +551,7 @@ Both modules are loaded on demand after init, so the base bundle stays lean, and
|
|
|
496
551
|
Opt out per feature:
|
|
497
552
|
|
|
498
553
|
```tsx
|
|
499
|
-
<AdaptiveProvider apiKey="pk_…"
|
|
554
|
+
<AdaptiveProvider apiKey="pk_…" enableGraph={false} engagement={false}>
|
|
500
555
|
<App />
|
|
501
556
|
</AdaptiveProvider>
|
|
502
557
|
```
|
|
@@ -510,7 +565,6 @@ By default the SDK initialises with `consent: true`, so tracking starts on first
|
|
|
510
565
|
```tsx
|
|
511
566
|
<AdaptiveProvider
|
|
512
567
|
apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}
|
|
513
|
-
context="saas"
|
|
514
568
|
consent={hasConsent}
|
|
515
569
|
preConsentBehavior="statistical_winner"
|
|
516
570
|
>
|
|
@@ -527,7 +581,6 @@ import { init, grantConsent } from '@sentientui/core';
|
|
|
527
581
|
|
|
528
582
|
const client = init({
|
|
529
583
|
apiKey: 'pk_...',
|
|
530
|
-
context: 'saas',
|
|
531
584
|
consent: false,
|
|
532
585
|
preConsentBehavior: 'statistical_winner',
|
|
533
586
|
});
|
|
@@ -536,27 +589,55 @@ const client = init({
|
|
|
536
589
|
grantConsent(); // upgrades client in place — no need to reassign
|
|
537
590
|
```
|
|
538
591
|
|
|
539
|
-
### OneTrust
|
|
592
|
+
### OneTrust and Cookiebot
|
|
540
593
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
594
|
+
In React, don't wire a CMP callback to `grantConsent()`: with `consent={false}` and no
|
|
595
|
+
`preConsentBehavior`, `<AdaptiveProvider>` never creates a client, so there is nothing to
|
|
596
|
+
upgrade — `grantConsent()` just warns "called before init()" and tracking never starts. Point
|
|
597
|
+
`consentFrom` at the CMP instead. The source is re-read every time the event fires, so a later
|
|
598
|
+
withdrawal gates the SDK again too:
|
|
599
|
+
|
|
600
|
+
```tsx
|
|
601
|
+
// OneTrust — C0002 = Analytics/Performance category
|
|
602
|
+
<AdaptiveProvider
|
|
603
|
+
apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}
|
|
604
|
+
consentFrom={{
|
|
605
|
+
check: () => window.OnetrustActiveGroups?.includes('C0002') === true,
|
|
606
|
+
event: 'OneTrustGroupsUpdated',
|
|
607
|
+
}}
|
|
608
|
+
>
|
|
609
|
+
{children}
|
|
610
|
+
</AdaptiveProvider>
|
|
611
|
+
|
|
612
|
+
// Cookiebot — re-read on accept AND decline, so withdrawal is honoured
|
|
613
|
+
<AdaptiveProvider
|
|
614
|
+
apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}
|
|
615
|
+
consentFrom={{
|
|
616
|
+
check: () => window.Cookiebot?.consent?.statistics === true,
|
|
617
|
+
event: 'CookiebotOnConsentReady',
|
|
618
|
+
}}
|
|
619
|
+
>
|
|
620
|
+
{children}
|
|
621
|
+
</AdaptiveProvider>
|
|
548
622
|
```
|
|
549
623
|
|
|
550
|
-
|
|
624
|
+
`<AdaptiveRoot>` is a Server Component and accepts only the cookie form — a `check` function
|
|
625
|
+
cannot cross the server→client boundary. Point it at a cookie your CMP (or a one-line listener)
|
|
626
|
+
writes, and it also resolves the cookie on the server for already-consented visitors:
|
|
551
627
|
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
628
|
+
```tsx
|
|
629
|
+
<AdaptiveRoot
|
|
630
|
+
apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}
|
|
631
|
+
consentFrom={{ cookie: 'analytics_consent', value: 'granted', event: 'consent-decided' }}
|
|
632
|
+
>
|
|
633
|
+
{children}
|
|
634
|
+
</AdaptiveRoot>
|
|
558
635
|
```
|
|
559
636
|
|
|
637
|
+
For a `check()` predicate in the App Router, render `<AdaptiveProvider>` from a client component
|
|
638
|
+
instead. `grantConsent()` remains correct for direct `@sentientui/core` users (above), whose
|
|
639
|
+
`init({ consent: false })` does create an upgradeable client.
|
|
640
|
+
|
|
560
641
|
When `consent: false` without `preConsentBehavior`, the SDK is a complete no-op — no API calls, no cookies, nothing. The `preConsentBehavior: 'statistical_winner'` mode calls only `GET /v1/winner`, a read-only endpoint that returns the best variant without storing any visitor data.
|
|
561
642
|
|
|
562
643
|
## Docs
|
package/dist/devtools.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";"use client";var Ce=Object.create;var k=Object.defineProperty,Ee=Object.defineProperties,Pe=Object.getOwnPropertyDescriptor,Ae=Object.getOwnPropertyDescriptors,De=Object.getOwnPropertyNames,q=Object.getOwnPropertySymbols,Le=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var Q=(e,t,o)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,l=(e,t)=>{for(var o in t||(t={}))Z.call(t,o)&&Q(e,o,t[o]);if(q)for(var o of q(t))Ve.call(t,o)&&Q(e,o,t[o]);return e},b=(e,t)=>Ee(e,Ae(t));var Ne=(e,t)=>{for(var o in t)k(e,o,{get:t[o],enumerable:!0})},ee=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of De(t))!Z.call(e,d)&&d!==o&&k(e,d,{get:()=>t[d],enumerable:!(r=Pe(t,d))||r.enumerable});return e};var We=(e,t,o)=>(o=e!=null?Ce(Le(e)):{},ee(t||!e||!e.__esModule?k(o,"default",{value:e,enumerable:!0}):o,e)),Me=e=>ee(k({},"__esModule",{value:!0}),e);var Xe={};Ne(Xe,{AdaptiveDevtools:()=>Je,LOCAL_MODE_DEVTOOLS_BANNER:()=>ce});module.exports=Me(Xe);var u=require("react"),x=require("@sentientui/policy"),O=require("@sentientui/core");var Be={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function C(){if(typeof window=="undefined")return Be;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function P(){return[...C().components.values()]}function T(){return[...C().slots.values()]}function A(){return[...C().sections]}function te(e){let t=C().listeners;return t.add(e),()=>{t.delete(e)}}function ne(){return C().version}function j(){let e=window;return e.__sentient_overrides||(e.__sentient_overrides={}),e.__sentient_overrides}function z(e,t){j()[e]=t}function F(e){delete j()[e]}function D(){return l({},j())}function U(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function G(e,t){U()[e]=t}function oe(e){delete U()[e]}function L(){return l({},U())}var Ie={on:!1,listeners:new Set};function ie(){if(typeof window=="undefined")return Ie;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function _(e){let t=ie();if(t.on!==e){t.on=e;for(let o of t.listeners)o()}}function re(){return ie().on}var Te="sentient:overrides-changed";function p(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(Te))}function $(){var e;return typeof window=="undefined"?null:(e=window.__sentient_devtools_config)!=null?e:null}var i=require("react/jsx-runtime"),le,se=typeof process!="undefined"&&((le=process.env)==null?void 0:le.NODE_ENV)==="production",de="https://api.sentient-ui.com/v1",ce="Local mode \u2014 decisions are simulated; add a key to learn from real traffic";function ue(){let e=window.__sentient_layout_override,t=A();return!e||e.length===0?t:[...e,...t.filter(o=>!e.includes(o))]}function je(e,t){let o=ue();if(e===t||e<0||t<0||e>=o.length||t>=o.length)return;let r=[...o],[d]=r.splice(e,1);r.splice(t,0,d),window.__sentient_layout_override=r,_(!0),p()}function ze(){delete window.__sentient_layout_override,p()}function pe(e){var o,r;for(let[d,c]of Object.entries((o=e.assignments)!=null?o:{}))z(d,c);let t=window;e.layoutOrder&&e.layoutOrder.length>0&&(t.__sentient_layout_override=e.layoutOrder),e.slots&&(t.__sentient_slot_overrides=l(l({},(r=t.__sentient_slot_overrides)!=null?r:{}),e.slots)),e.personaAttributes&&(document.documentElement.dataset.sentientPersona=e.personaAttributes.persona,document.documentElement.dataset.sentientConfidence=e.personaAttributes.confidence),_(!0),p()}function Fe(e){var o,r;let t=d=>{try{let c=document.cookie.match(new RegExp(`(?:^|; )${d}=([^;]*)`));return c?decodeURIComponent(c[1]):null}catch(c){return null}};return(r=(o=e?t((0,O.sessionCookieName)(e)):null)!=null?o:t(O.LEGACY_SESSION_COOKIE_NAME))!=null?r:"devtools-preview"}function ge(){return T().map(e=>l(l({id:e.id},e.arms?{arms:e.arms}:{}),e.dims?{dims:e.dims}:{}))}var ae=x.PERSONAS.map(e=>({key:e,displayName:x.PERSONA_DISPLAY[e]}));async function Ue(e,t){try{let o=await fetch(`${t}/personas`,{headers:{authorization:`Bearer ${e}`}});if(!o.ok)return null;let r=await o.json(),d=w=>Array.isArray(w)?w.filter(g=>g&&typeof g.key=="string"&&typeof g.displayName=="string"):[],c=d(r.personas);return c.length>0?{personas:c,discovered:d(r.discovered)}:null}catch(o){return null}}async function Ge(e,t,o){var c,w,g;let r=await fetch(`${t}/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({persona:o,sections:A().map(S=>({id:S})),components:P().map(S=>({id:S.id,variantIds:S.variantIds})),slots:ge()})});if(!r.ok)return null;let d=await r.json();return pe(b(l({},d),{personaAttributes:(c=d.personaAttributes)!=null?c:{persona:o,confidence:"high"}})),{recognized:d.recognized!==!1,resolvedDisplay:(g=(w=d.personaDisplay)!=null?w:d.persona)!=null?g:o}}async function $e(e,t){let o=await import("@sentientui/core/local");if(!o.LOCAL_ENGINE_AVAILABLE)return;let r=o.createLocalEngine({sessionId:Fe(t),forcedPersona:e}).decide({sections:A(),components:P().map(d=>({id:d.id,variantIds:d.variantIds})),slots:ge()});pe({assignments:r.assignments,layoutOrder:r.layoutOrder,slots:r.slots,personaAttributes:{persona:r.persona,confidence:(0,x.confidenceBand)(r.confidence)}})}function He(){for(let t of Object.keys(D()))F(t);let e=window;delete e.__sentient_layout_override,delete e.__sentient_slot_overrides,delete document.documentElement.dataset.sentientPersona,delete document.documentElement.dataset.sentientConfidence;try{let t=[];for(let o=0;o<localStorage.length;o++){let r=localStorage.key(o);r&&r.startsWith(O.SNAPSHOT_STORAGE_KEY_PREFIX)&&t.push(r)}for(let o of t)localStorage.removeItem(o)}catch(t){}_(!1),p();try{window.location.reload()}catch(t){}}var y=e=>({padding:"2px 8px",borderRadius:4,border:"1px solid #444",background:e?"#3b82f6":"#222",color:"#eee",cursor:"pointer"});function Ye({size:e=26}={}){return(0,i.jsxs)("svg",{width:e,height:e,viewBox:"0 0 32 32",fill:"none","aria-hidden":"true",children:[(0,i.jsx)("path",{d:"M21 9H14C11.2 9 9.8 10.8 9.8 13C9.8 15.4 11.6 16.6 14.5 16.6H18.5C20.5 16.6 20.7 18.2 20.4 19.6",stroke:"#fff",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,i.jsx)("path",{d:"M10 22H17",stroke:"#fff",strokeWidth:"2.2",strokeLinecap:"round"}),(0,i.jsx)("circle",{cx:"20.6",cy:"22",r:"2.1",fill:"#fff"})]})}function Je({apiKey:e}={}){var X;let[t,o]=(0,u.useState)(!1),[r,d]=(0,u.useState)(null),[c,w]=(0,u.useState)(null),[g,S]=(0,u.useState)([]),[H,Y]=(0,u.useState)(null),[R,V]=(0,u.useState)(null),[fe,ve]=(0,u.useState)(!1),[,f]=(0,u.useReducer)(n=>n+1,0);if((0,u.useSyncExternalStore)(te,ne,()=>0),(0,u.useEffect)(()=>ve(!0),[]),(0,u.useEffect)(()=>{var a;if(se)return;let n=(a=$())!=null?a:{apiKey:e!=null?e:"",apiBaseUrl:de,isLocal:!1};if(n.isLocal||!n.apiKey)return;let s=!1;return Ue(n.apiKey,n.apiBaseUrl).then(v=>{s||!v||(w(v.personas),S(v.discovered))}),()=>{s=!0}},[e]),se||!fe)return null;let h=(X=$())!=null?X:{apiKey:e!=null?e:"",apiBaseUrl:de,isLocal:!1},N=h.isLocal||!h.apiKey,E=P(),W=T(),M=D(),J=L(),B=ue(),ye=window.__sentient_layout_override!==void 0;function me(n,s){je(n,s),f()}function _e(){ze(),I(),f()}function I(){Object.keys(D()).length===0&&Object.keys(L()).length===0&&window.__sentient_layout_override===void 0&&_(!1)}function we(n,s){z(n,s),_(!0),p(),f()}function be(n){F(n),I(),p(),f()}function Se(n,s){G(n,s),_(!0),p(),f()}function he(n,s,a,v){let m=L()[n],K=m&&typeof m=="object"?l({},m):Object.fromEntries(Object.entries(v!=null?v:{}).map(([Re,ke])=>[Re,ke[0]]));K[s]=a,G(n,K),_(!0),p(),f()}function xe(n){oe(n),I(),p(),f()}function Oe(n){if(d(n.key),Y(null),N){$e(n.key,h.apiKey).then(f).catch(()=>{});return}Ge(h.apiKey,h.apiBaseUrl,n.key).then(s=>{s&&!s.recognized&&Y(`\u201C${n.displayName}\u201D isn\u2019t in this project\u2019s personas \u2014 the page is showing the default experience.`),f()}).catch(()=>{})}return(0,i.jsxs)("div",{style:{position:"fixed",bottom:16,right:16,zIndex:2147483647,fontFamily:"system-ui"},children:[(0,i.jsx)("div",{"aria-hidden":!t,style:{position:"absolute",bottom:52,right:0,transformOrigin:"bottom right",transition:"opacity .18s ease, transform .2s cubic-bezier(.16,1,.3,1)",opacity:t?1:0,transform:t?"translateY(0) scale(1)":"translateY(6px) scale(.96)",pointerEvents:t?"auto":"none"},children:(0,i.jsxs)("div",{style:{width:300,maxHeight:460,overflowY:"auto",background:"#111",color:"#eee",borderRadius:8,padding:12,boxShadow:"0 8px 30px rgba(0,0,0,.4)",fontSize:12},children:[h.isLocal&&(0,i.jsx)("div",{style:{background:"#1e293b",border:"1px solid #334155",borderRadius:4,padding:"6px 8px",marginBottom:8},children:ce}),(0,i.jsxs)("div",{style:{opacity:.7,marginBottom:8},children:[E.length," component",E.length===1?"":"s"," \xB7 ",re()?"preview \u2014 writing nothing":"live"]}),(0,i.jsxs)("div",{style:{borderBottom:"1px solid #333",paddingBottom:8,marginBottom:8},children:[(0,i.jsx)("div",{style:{opacity:.7,marginBottom:4},children:"Preview persona"}),(0,i.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[(N?ae:c!=null?c:ae).map(n=>(0,i.jsx)("button",{onClick:()=>Oe(n),style:y(r===n.key),children:n.displayName},n.key)),(r!==null||Object.keys(M).length>0||Object.keys(J).length>0)&&(0,i.jsx)("button",{onClick:He,style:b(l({},y(!1)),{color:"#aaa"}),children:"Reset"})]}),H&&(0,i.jsx)("div",{style:{marginTop:6,fontSize:11,color:"#fbbf24"},children:H}),!N&&g.length>0&&(0,i.jsxs)("div",{style:{marginTop:8},children:[(0,i.jsx)("div",{style:{opacity:.5,fontSize:11,marginBottom:4},children:"Discovered \u2014 not serving yet (promote from the dashboard)"}),(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:g.map(n=>(0,i.jsx)("span",{title:"Found by clustering your traffic; it starts serving only after promotion.",style:b(l({},y(!1)),{opacity:.45,cursor:"default",display:"inline-block"}),children:n.displayName},n.key))})]})]}),B.length>0&&(0,i.jsxs)("div",{style:{borderBottom:"1px solid #333",paddingBottom:8,marginBottom:8},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[(0,i.jsx)("span",{style:{opacity:.7},children:"Layout \u2014 drag to reorder"}),ye&&(0,i.jsx)("button",{"aria-label":"Reset section order",onClick:_e,style:b(l({},y(!1)),{color:"#aaa"}),children:"reset"})]}),(0,i.jsx)("ul",{"aria-label":"Section order",style:{listStyle:"none",margin:0,padding:0},children:B.map((n,s)=>(0,i.jsxs)("li",{draggable:!0,onDragStart:()=>V(s),onDragOver:a=>a.preventDefault(),onDrop:a=>{a.preventDefault(),R!==null&&me(R,s),V(null)},onDragEnd:()=>V(null),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 6px",marginBottom:2,borderRadius:4,border:"1px solid #262626",cursor:"grab",background:R===s?"#1e293b":"#181818",opacity:R!==null&&R!==s?.6:1},children:[(0,i.jsx)("span",{style:{opacity:.4,minWidth:10,fontVariantNumeric:"tabular-nums"},children:s+1}),(0,i.jsx)("span",{"aria-hidden":"true",style:{opacity:.35},children:"\u283F"}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n})]},n))})]}),E.length===0&&W.length===0&&B.length===0&&(0,i.jsx)("div",{style:{opacity:.6},children:"No components, sections or slots on this page yet."}),E.map(n=>(0,i.jsxs)("div",{style:{borderTop:"1px solid #333",padding:"8px 0"},children:[(0,i.jsxs)("div",{style:{fontWeight:600},children:[n.id,n.goal?` \xB7 goal: ${n.goal}`:""]}),(0,i.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:4},children:[n.variantIds.map(s=>(0,i.jsx)("button",{onClick:()=>we(n.id,s),style:y(M[n.id]===s),children:s},s)),M[n.id]&&(0,i.jsx)("button",{onClick:()=>be(n.id),style:b(l({},y(!1)),{color:"#aaa"}),children:"reset"})]})]},n.id)),W.length>0&&(0,i.jsxs)("div",{style:{borderTop:"1px solid #333",paddingTop:8,marginTop:4},children:[(0,i.jsx)("div",{style:{opacity:.7,marginBottom:4},children:"Slots"}),W.map(n=>{let s=J[n.id];return(0,i.jsxs)("div",{style:{padding:"6px 0"},children:[(0,i.jsx)("div",{style:{fontWeight:600},children:n.id}),n.arms&&(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:4},children:n.arms.map(a=>(0,i.jsx)("button",{onClick:()=>Se(n.id,a),style:y(s===a),children:a},a))}),n.dims&&Object.entries(n.dims).map(([a,v])=>(0,i.jsxs)("div",{style:{marginTop:4},children:[(0,i.jsx)("div",{style:{opacity:.6,fontSize:11},children:a}),(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:v.map(m=>(0,i.jsx)("button",{onClick:()=>he(n.id,a,m,n.dims),style:y(!!s&&typeof s=="object"&&s[a]===m),children:m},m))})]},a)),s!==void 0&&(0,i.jsx)("button",{onClick:()=>xe(n.id),style:b(l({},y(!1)),{color:"#aaa",marginTop:4}),children:"reset"})]},n.id)})]})]})}),(0,i.jsx)("button",{"aria-label":"Sentient DevTools","aria-expanded":t,onClick:()=>o(n=>!n),style:{width:44,height:44,borderRadius:12,border:"1px solid #2a2a2a",background:"#000",display:"flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",boxShadow:"0 6px 18px rgba(0,0,0,.4)"},children:(0,i.jsx)(Ye,{})})]})}0&&(module.exports={AdaptiveDevtools,LOCAL_MODE_DEVTOOLS_BANNER});
|
|
2
|
+
"use strict";"use client";var Ee=Object.create;var R=Object.defineProperty,Pe=Object.defineProperties,Ne=Object.getOwnPropertyDescriptor,De=Object.getOwnPropertyDescriptors,Ae=Object.getOwnPropertyNames,Z=Object.getOwnPropertySymbols,Le=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable;var ee=(e,t,o)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,l=(e,t)=>{for(var o in t||(t={}))te.call(t,o)&&ee(e,o,t[o]);if(Z)for(var o of Z(t))We.call(t,o)&&ee(e,o,t[o]);return e},S=(e,t)=>Pe(e,De(t));var Ve=(e,t)=>{for(var o in t)R(e,o,{get:t[o],enumerable:!0})},ne=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let d of Ae(t))!te.call(e,d)&&d!==o&&R(e,d,{get:()=>t[d],enumerable:!(s=Ne(t,d))||s.enumerable});return e};var Me=(e,t,o)=>(o=e!=null?Ee(Le(e)):{},ne(t||!e||!e.__esModule?R(o,"default",{value:e,enumerable:!0}):o,e)),Be=e=>ne(R({},"__esModule",{value:!0}),e);var qe={};Ve(qe,{AdaptiveDevtools:()=>Xe,LOCAL_MODE_DEVTOOLS_BANNER:()=>ue});module.exports=Be(qe);var c=require("react"),w=require("@sentientui/policy"),k=require("@sentientui/core");var Ie={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function C(){if(typeof window=="undefined")return Ie;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function P(){return[...C().components.values()]}function T(){return[...C().slots.values()]}function N(){return[...C().sections]}function oe(e){let t=C().listeners;return t.add(e),()=>{t.delete(e)}}function ie(){return C().version}function j(){let e=window;return e.__sentient_overrides||(e.__sentient_overrides={}),e.__sentient_overrides}function z(e,t){j()[e]=t}function U(e){delete j()[e]}function D(){return l({},j())}function F(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function G(e,t){F()[e]=t}function re(e){delete F()[e]}function A(){return l({},F())}var Te={on:!1,listeners:new Set};function se(){if(typeof window=="undefined")return Te;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function _(e){let t=se();if(t.on!==e){t.on=e;for(let o of t.listeners)o()}}function de(){return se().on}var je="sentient:overrides-changed";function p(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(je))}function $(){var e;return typeof window=="undefined"?null:(e=window.__sentient_devtools_config)!=null?e:null}var i=require("react/jsx-runtime"),ce,ae=typeof process!="undefined"&&((ce=process.env)==null?void 0:ce.NODE_ENV)==="production",le="https://api.sentient-ui.com/v1",ue="Local mode \u2014 decisions are simulated; add a key to learn from real traffic";function pe(){let e=window.__sentient_layout_override,t=N();return!e||e.length===0?t:[...e,...t.filter(o=>!e.includes(o))]}function ze(e,t){let o=pe();if(e===t||e<0||t<0||e>=o.length||t>=o.length)return;let s=[...o],[d]=s.splice(e,1);s.splice(t,0,d),window.__sentient_layout_override=s,_(!0),p()}function Ue(){delete window.__sentient_layout_override,p()}function ge(e){var o,s;for(let[d,u]of Object.entries((o=e.assignments)!=null?o:{}))z(d,u);let t=window;e.layoutOrder&&e.layoutOrder.length>0&&(t.__sentient_layout_override=e.layoutOrder),e.slots&&(t.__sentient_slot_overrides=l(l({},(s=t.__sentient_slot_overrides)!=null?s:{}),e.slots)),e.personaAttributes&&(document.documentElement.dataset.sentientPersona=e.personaAttributes.persona,document.documentElement.dataset.sentientConfidence=e.personaAttributes.confidence),_(!0),p()}function Fe(e){var o,s;let t=d=>{try{let u=document.cookie.match(new RegExp(`(?:^|; )${d}=([^;]*)`));return u?decodeURIComponent(u[1]):null}catch(u){return null}};return(s=(o=e?t((0,k.sessionCookieName)(e)):null)!=null?o:t(k.LEGACY_SESSION_COOKIE_NAME))!=null?s:"devtools-preview"}function fe(){return T().map(e=>l(l({id:e.id},e.arms?{arms:e.arms}:{}),e.dims?{dims:e.dims}:{}))}var Ge={key:w.UNKNOWN_PERSONA,displayName:w.UNKNOWN_PERSONA_DISPLAY};async function $e(e,t){try{let o=await fetch(`${t}/personas`,{headers:{authorization:`Bearer ${e}`}});if(!o.ok)return null;let s=await o.json(),d=b=>Array.isArray(b)?b.filter(f=>f&&typeof f.key=="string"&&typeof f.displayName=="string"):[],u=d(s.personas);return u.length>0?{personas:u,discovered:d(s.discovered)}:null}catch(o){return null}}async function He(e,t,o){var u,b,f;let s=await fetch(`${t}/explain`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e}`},body:JSON.stringify({persona:o,sections:N().map(h=>({id:h})),components:P().map(h=>({id:h.id,variantIds:h.variantIds})),slots:fe()})});if(!s.ok)return null;let d=await s.json();return ge(S(l({},d),{personaAttributes:(u=d.personaAttributes)!=null?u:{persona:o,confidence:"high"}})),{recognized:d.recognized!==!1,resolvedDisplay:(f=(b=d.personaDisplay)!=null?b:d.persona)!=null?f:o}}async function Ke(e,t){let o=await import("@sentientui/core/local");if(!o.LOCAL_ENGINE_AVAILABLE)return;let s=o.createLocalEngine({sessionId:Fe(t),forcedPersona:e}).decide({sections:N(),components:P().map(d=>({id:d.id,variantIds:d.variantIds})),slots:fe()});ge({assignments:s.assignments,layoutOrder:s.layoutOrder,slots:s.slots,personaAttributes:{persona:s.persona,confidence:(0,w.confidenceBand)(s.confidence)}})}function Ye(){for(let t of Object.keys(D()))U(t);let e=window;delete e.__sentient_layout_override,delete e.__sentient_slot_overrides,delete document.documentElement.dataset.sentientPersona,delete document.documentElement.dataset.sentientConfidence;try{let t=[];for(let o=0;o<localStorage.length;o++){let s=localStorage.key(o);s&&s.startsWith(k.SNAPSHOT_STORAGE_KEY_PREFIX)&&t.push(s)}for(let o of t)localStorage.removeItem(o)}catch(t){}_(!1),p();try{window.location.reload()}catch(t){}}var g=e=>({padding:"2px 8px",borderRadius:4,border:"1px solid #444",background:e?"#3b82f6":"#222",color:"#eee",cursor:"pointer"});function Je({size:e=26}={}){return(0,i.jsxs)("svg",{width:e,height:e,viewBox:"0 0 32 32",fill:"none","aria-hidden":"true",children:[(0,i.jsx)("path",{d:"M21 9H14C11.2 9 9.8 10.8 9.8 13C9.8 15.4 11.6 16.6 14.5 16.6H18.5C20.5 16.6 20.7 18.2 20.4 19.6",stroke:"#fff",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"}),(0,i.jsx)("path",{d:"M10 22H17",stroke:"#fff",strokeWidth:"2.2",strokeLinecap:"round"}),(0,i.jsx)("circle",{cx:"20.6",cy:"22",r:"2.1",fill:"#fff"})]})}function Xe({apiKey:e}={}){var q;let[t,o]=(0,c.useState)(!1),[s,d]=(0,c.useState)(null),[u,b]=(0,c.useState)(null),[f,h]=(0,c.useState)(""),[H,ve]=(0,c.useState)([]),[K,Y]=(0,c.useState)(null),[O,L]=(0,c.useState)(null),[ye,me]=(0,c.useState)(!1),[,v]=(0,c.useReducer)(n=>n+1,0);if((0,c.useSyncExternalStore)(oe,ie,()=>0),(0,c.useEffect)(()=>me(!0),[]),(0,c.useEffect)(()=>{var a;if(ae)return;let n=(a=$())!=null?a:{apiKey:e!=null?e:"",apiBaseUrl:le,isLocal:!1};if(n.isLocal||!n.apiKey)return;let r=!1;return $e(n.apiKey,n.apiBaseUrl).then(y=>{r||!y||(b(y.personas),ve(y.discovered))}),()=>{r=!0}},[e]),ae||!ye)return null;let x=(q=$())!=null?q:{apiKey:e!=null?e:"",apiBaseUrl:le,isLocal:!1},W=x.isLocal||!x.apiKey,E=P(),V=T(),M=D(),J=A(),B=pe(),_e=window.__sentient_layout_override!==void 0;function we(n,r){ze(n,r),v()}function be(){Ue(),I(),v()}function I(){Object.keys(D()).length===0&&Object.keys(A()).length===0&&window.__sentient_layout_override===void 0&&_(!1)}function Se(n,r){z(n,r),_(!0),p(),v()}function he(n){U(n),I(),p(),v()}function xe(n,r){G(n,r),_(!0),p(),v()}function ke(n,r,a,y){let m=A()[n],Q=m&&typeof m=="object"?l({},m):Object.fromEntries(Object.entries(y!=null?y:{}).map(([Re,Ce])=>[Re,Ce[0]]));Q[r]=a,G(n,Q),_(!0),p(),v()}function Oe(n){re(n),I(),p(),v()}function X(n){if(d(n.key),Y(null),W){Ke(n.key,x.apiKey).then(v).catch(()=>{});return}He(x.apiKey,x.apiBaseUrl,n.key).then(r=>{r&&!r.recognized&&Y(`\u201C${n.displayName}\u201D isn\u2019t in this project\u2019s personas \u2014 the page is showing the default experience.`),v()}).catch(()=>{})}return(0,i.jsxs)("div",{style:{position:"fixed",bottom:16,right:16,zIndex:2147483647,fontFamily:"system-ui"},children:[(0,i.jsx)("div",{"aria-hidden":!t,style:{position:"absolute",bottom:52,right:0,transformOrigin:"bottom right",transition:"opacity .18s ease, transform .2s cubic-bezier(.16,1,.3,1)",opacity:t?1:0,transform:t?"translateY(0) scale(1)":"translateY(6px) scale(.96)",pointerEvents:t?"auto":"none"},children:(0,i.jsxs)("div",{style:{width:300,maxHeight:460,overflowY:"auto",background:"#111",color:"#eee",borderRadius:8,padding:12,boxShadow:"0 8px 30px rgba(0,0,0,.4)",fontSize:12},children:[x.isLocal&&(0,i.jsx)("div",{style:{background:"#1e293b",border:"1px solid #334155",borderRadius:4,padding:"6px 8px",marginBottom:8},children:ue}),(0,i.jsxs)("div",{style:{opacity:.7,marginBottom:8},children:[E.length," component",E.length===1?"":"s"," \xB7 ",de()?"preview \u2014 writing nothing":"live"]}),(0,i.jsxs)("div",{style:{borderBottom:"1px solid #333",paddingBottom:8,marginBottom:8},children:[(0,i.jsx)("div",{style:{opacity:.7,marginBottom:4},children:"Preview persona"}),(0,i.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:[[...W?[]:u!=null?u:[],Ge].map(n=>(0,i.jsx)("button",{onClick:()=>X(n),style:g(s===n.key),children:n.displayName},n.key)),(s!==null||Object.keys(M).length>0||Object.keys(J).length>0)&&(0,i.jsx)("button",{onClick:Ye,style:S(l({},g(!1)),{color:"#aaa"}),children:"Reset"})]}),(0,i.jsxs)("form",{onSubmit:n=>{n.preventDefault();let r=(0,w.normalizeDeclaredPersona)(f);r&&X({key:r,displayName:r})},style:{display:"flex",gap:4,marginTop:6},children:[(0,i.jsx)("input",{"aria-label":"Persona key",placeholder:"any persona key, e.g. admin",value:f,onChange:n=>h(n.target.value),style:{flex:1,minWidth:0,background:"#111",color:"#fff",border:"1px solid #333",borderRadius:4,padding:"4px 6px",fontSize:12}}),(0,i.jsx)("button",{type:"submit",style:g(!1),children:"Preview"})]}),K&&(0,i.jsx)("div",{style:{marginTop:6,fontSize:11,color:"#fbbf24"},children:K}),!W&&H.length>0&&(0,i.jsxs)("div",{style:{marginTop:8},children:[(0,i.jsx)("div",{style:{opacity:.5,fontSize:11,marginBottom:4},children:"Discovered \u2014 not serving yet (promote from the dashboard)"}),(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:H.map(n=>(0,i.jsx)("span",{title:"Found by clustering your traffic; it starts serving only after promotion.",style:S(l({},g(!1)),{opacity:.45,cursor:"default",display:"inline-block"}),children:n.displayName},n.key))})]})]}),B.length>0&&(0,i.jsxs)("div",{style:{borderBottom:"1px solid #333",paddingBottom:8,marginBottom:8},children:[(0,i.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[(0,i.jsx)("span",{style:{opacity:.7},children:"Layout \u2014 drag to reorder"}),_e&&(0,i.jsx)("button",{"aria-label":"Reset section order",onClick:be,style:S(l({},g(!1)),{color:"#aaa"}),children:"reset"})]}),(0,i.jsx)("ul",{"aria-label":"Section order",style:{listStyle:"none",margin:0,padding:0},children:B.map((n,r)=>(0,i.jsxs)("li",{draggable:!0,onDragStart:()=>L(r),onDragOver:a=>a.preventDefault(),onDrop:a=>{a.preventDefault(),O!==null&&we(O,r),L(null)},onDragEnd:()=>L(null),style:{display:"flex",alignItems:"center",gap:6,padding:"4px 6px",marginBottom:2,borderRadius:4,border:"1px solid #262626",cursor:"grab",background:O===r?"#1e293b":"#181818",opacity:O!==null&&O!==r?.6:1},children:[(0,i.jsx)("span",{style:{opacity:.4,minWidth:10,fontVariantNumeric:"tabular-nums"},children:r+1}),(0,i.jsx)("span",{"aria-hidden":"true",style:{opacity:.35},children:"\u283F"}),(0,i.jsx)("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n})]},n))})]}),E.length===0&&V.length===0&&B.length===0&&(0,i.jsx)("div",{style:{opacity:.6},children:"No components, sections or slots on this page yet."}),E.map(n=>(0,i.jsxs)("div",{style:{borderTop:"1px solid #333",padding:"8px 0"},children:[(0,i.jsxs)("div",{style:{fontWeight:600},children:[n.id,n.goal?` \xB7 goal: ${n.goal}`:""]}),(0,i.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:4},children:[n.variantIds.map(r=>(0,i.jsx)("button",{onClick:()=>Se(n.id,r),style:g(M[n.id]===r),children:r},r)),M[n.id]&&(0,i.jsx)("button",{onClick:()=>he(n.id),style:S(l({},g(!1)),{color:"#aaa"}),children:"reset"})]})]},n.id)),V.length>0&&(0,i.jsxs)("div",{style:{borderTop:"1px solid #333",paddingTop:8,marginTop:4},children:[(0,i.jsx)("div",{style:{opacity:.7,marginBottom:4},children:"Slots"}),V.map(n=>{let r=J[n.id];return(0,i.jsxs)("div",{style:{padding:"6px 0"},children:[(0,i.jsx)("div",{style:{fontWeight:600},children:n.id}),n.arms&&(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginTop:4},children:n.arms.map(a=>(0,i.jsx)("button",{onClick:()=>xe(n.id,a),style:g(r===a),children:a},a))}),n.dims&&Object.entries(n.dims).map(([a,y])=>(0,i.jsxs)("div",{style:{marginTop:4},children:[(0,i.jsx)("div",{style:{opacity:.6,fontSize:11},children:a}),(0,i.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:y.map(m=>(0,i.jsx)("button",{onClick:()=>ke(n.id,a,m,n.dims),style:g(!!r&&typeof r=="object"&&r[a]===m),children:m},m))})]},a)),r!==void 0&&(0,i.jsx)("button",{onClick:()=>Oe(n.id),style:S(l({},g(!1)),{color:"#aaa",marginTop:4}),children:"reset"})]},n.id)})]})]})}),(0,i.jsx)("button",{"aria-label":"Sentient DevTools","aria-expanded":t,onClick:()=>o(n=>!n),style:{width:44,height:44,borderRadius:12,border:"1px solid #2a2a2a",background:"#000",display:"flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",boxShadow:"0 6px 18px rgba(0,0,0,.4)"},children:(0,i.jsx)(Je,{})})]})}0&&(module.exports={AdaptiveDevtools,LOCAL_MODE_DEVTOOLS_BANNER});
|
|
3
3
|
//# sourceMappingURL=devtools.js.map
|