@sentientui/react 0.6.0 → 0.7.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
CHANGED
|
@@ -26,7 +26,7 @@ SENTIENT_API_KEY=pk_your_key
|
|
|
26
26
|
NEXT_PUBLIC_SENTIENT_API_KEY=pk_your_key
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
The SDK points at `https://sentient-
|
|
29
|
+
The SDK points at `https://api.sentient-ui.com` (the hosted API) automatically — no ingest URL configuration required.
|
|
30
30
|
|
|
31
31
|
## Quick start — Next.js App Router (recommended)
|
|
32
32
|
|
|
@@ -235,7 +235,7 @@ export async function getServerSideProps({ req }) {
|
|
|
235
235
|
{
|
|
236
236
|
cookies: req.cookies,
|
|
237
237
|
apiKey: process.env.SENTIENT_API_KEY!,
|
|
238
|
-
baseUrl: 'https://sentient-
|
|
238
|
+
baseUrl: 'https://api.sentient-ui.com/v1',
|
|
239
239
|
origin: process.env.NEXT_PUBLIC_APP_URL,
|
|
240
240
|
},
|
|
241
241
|
);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var C=Object.defineProperty,M=Object.defineProperties;var w=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var P=(e,i,t)=>i in e?C(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,I=(e,i)=>{for(var t in i||(i={}))U.call(i,t)&&P(e,t,i[t]);if(g)for(var t of g(i))D.call(i,t)&&P(e,t,i[t]);return e},O=(e,i)=>M(e,w(i));var R=(e,i)=>{var t={};for(var r in e)U.call(e,r)&&i.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&g)for(var r of g(e))i.indexOf(r)<0&&D.call(e,r)&&(t[r]=e[r]);return t};import{deriveSessionSegment as N}from"@sentientui/core";import{cookies as $,headers as B}from"next/headers";import{preloadAssignments as E,readSessionCookie as _}from"@sentientui/core/server";import{preloadDecisions as z}from"@sentientui/core/server";function b(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`snt-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}async function h(e,i){var r,s,n;let t=(n=(s=_(i.cookies))!=null?s:(r=i.createSessionId)==null?void 0:r.call(i))!=null?n:b();return E(e,t,{apiKey:i.apiKey,baseUrl:i.baseUrl,origin:i.origin,userAgent:i.userAgent,referer:i.referer,timeoutMs:i.timeoutMs})}async function k(e){var s,n,o,a;let{preloadDecisions:i,readSessionCookie:t}=await import("@sentientui/core/server"),r=(o=(n=t(e.cookies))!=null?n:(s=e.createSessionId)==null?void 0:s.call(e))!=null?o:b();return i({sections:e.sections,components:(a=e.components)!=null?a:[]},r,{apiKey:e.apiKey,baseUrl:e.baseUrl,origin:e.origin,userAgent:e.userAgent,referer:e.referer,timeoutMs:e.timeoutMs})}import{AdaptiveRootClient as F}from"./adaptive-root-client.js";import{jsx as J}from"react/jsx-runtime";var x="https://sentient-
|
|
1
|
+
var C=Object.defineProperty,M=Object.defineProperties;var w=Object.getOwnPropertyDescriptors;var g=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var P=(e,i,t)=>i in e?C(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t,I=(e,i)=>{for(var t in i||(i={}))U.call(i,t)&&P(e,t,i[t]);if(g)for(var t of g(i))D.call(i,t)&&P(e,t,i[t]);return e},O=(e,i)=>M(e,w(i));var R=(e,i)=>{var t={};for(var r in e)U.call(e,r)&&i.indexOf(r)<0&&(t[r]=e[r]);if(e!=null&&g)for(var r of g(e))i.indexOf(r)<0&&D.call(e,r)&&(t[r]=e[r]);return t};import{deriveSessionSegment as N}from"@sentientui/core";import{cookies as $,headers as B}from"next/headers";import{preloadAssignments as E,readSessionCookie as _}from"@sentientui/core/server";import{preloadDecisions as z}from"@sentientui/core/server";function b(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`snt-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}async function h(e,i){var r,s,n;let t=(n=(s=_(i.cookies))!=null?s:(r=i.createSessionId)==null?void 0:r.call(i))!=null?n:b();return E(e,t,{apiKey:i.apiKey,baseUrl:i.baseUrl,origin:i.origin,userAgent:i.userAgent,referer:i.referer,timeoutMs:i.timeoutMs})}async function k(e){var s,n,o,a;let{preloadDecisions:i,readSessionCookie:t}=await import("@sentientui/core/server"),r=(o=(n=t(e.cookies))!=null?n:(s=e.createSessionId)==null?void 0:s.call(e))!=null?o:b();return i({sections:e.sections,components:(a=e.components)!=null?a:[]},r,{apiKey:e.apiKey,baseUrl:e.baseUrl,origin:e.origin,userAgent:e.userAgent,referer:e.referer,timeoutMs:e.timeoutMs})}import{AdaptiveRootClient as F}from"./adaptive-root-client.js";import{jsx as J}from"react/jsx-runtime";var x="https://api.sentient-ui.com/v1";async function W(e){var y,f;let v=e,{components:i,sections:t,serverApiKey:r,appOrigin:s,initialAssignments:n,timeoutMs:o,children:a}=v,K=R(v,["components","sections","serverApiKey","appOrigin","initialAssignments","timeoutMs","children"]),A=await B(),m=s!=null?s:"http://localhost:3001",p=(y=A.get("user-agent"))!=null?y:void 0,c=(f=A.get("referer"))!=null?f:void 0,L=N({userAgent:p,referer:c,appOrigin:m}),l=await $(),d,u=null;if(n)d=n;else if(t&&t.length>0){let S=await k({sections:t,components:i,cookies:l,apiKey:r,baseUrl:x,origin:m,userAgent:p,referer:c,timeoutMs:o});d=S.assignments,u=S.layoutOrder}else d=await h(i,{cookies:l,apiKey:r,baseUrl:x,origin:m,userAgent:p,referer:c,timeoutMs:o});return J(F,O(I({},K),{initialAssignments:d,initialLayoutOrder:u,sessionSegment:L,children:a}))}export{W as AdaptiveRoot};
|
|
2
2
|
//# sourceMappingURL=adaptive-root.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/adaptive-root.tsx","../../src/server.ts"],"sourcesContent":["import { deriveSessionSegment } from '@sentientui/core';\nimport { cookies, headers } from 'next/headers';\nimport type { ReactNode } from 'react';\nimport type { AdaptiveProviderProps } from '../provider.js';\nimport {\n loadAdaptiveAssignments,\n loadAdaptiveDecision,\n type ServerAssignments,\n} from '../server.js';\nimport { AdaptiveRootClient } from './adaptive-root-client.js';\n\nconst DEFAULT_API_BASE_URL = 'https://sentient-api.fly.dev/v1';\n\nexport type PreloadComponent = { id: string; variantIds: string[] };\n\nexport type AdaptiveRootProps = Omit<AdaptiveProviderProps, 'initialAssignments'> & {\n /** Components to assign server-side (SEO-safe). */\n components: PreloadComponent[];\n /**\n * Declare page section IDs in their default order. When provided,\n * AdaptiveRoot calls `/v1/decide` (single round trip) instead of\n * individual `/v1/assign` calls, and `useLayoutOrder()` returns the\n * persona-specific order on first render.\n *\n * @example sections={['hero', 'pricing', 'features', 'social_proof']}\n */\n sections?: string[];\n /** Server-only API key for `/v1/sessions`, `/v1/assign`, and `/v1/decide`. */\n serverApiKey: string;\n /** App origin — must be in the project's `allowed_origins`. */\n appOrigin?: string;\n /** Override: when set no network fetch is made. Useful for tests. */\n initialAssignments?: ServerAssignments;\n /**\n * Milliseconds to wait for the API before rendering default variants.\n * Defaults to 1500. Increase if you see unexpected fallbacks in production.\n */\n timeoutMs?: number;\n children: ReactNode;\n};\n\n/**\n * Next.js Server Component that resolves variant assignments (and optionally\n * section layout order) server-side for zero layout shift on first paint.\n *\n * When `sections` is provided, a single `POST /v1/decide` call returns both\n * the persona-specific section order and all component assignments.\n * Without `sections`, individual `/v1/assign` calls are made per component.\n *\n * @example\n * // app/page.tsx — with section layout\n * import { AdaptiveRoot } from '@sentientui/react/next';\n *\n * export default async function Page() {\n * return (\n * <AdaptiveRoot\n * apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}\n * serverApiKey={process.env.SENTIENT_SECRET_KEY!}\n * context={{ appId: 'my-app' }}\n * sections={['hero', 'pricing', 'features', 'social_proof']}\n * components={[\n * { id: 'hero_cta', variantIds: ['default', 'accent'] },\n * ]}\n * >\n * <HeroSection />\n * <PricingSection />\n * <FeaturesSection />\n * <SocialProofSection />\n * </AdaptiveRoot>\n * );\n * }\n */\nexport async function AdaptiveRoot(props: AdaptiveRootProps): Promise<JSX.Element> {\n const {\n components,\n sections,\n serverApiKey,\n appOrigin,\n initialAssignments: initialAssignmentsOverride,\n timeoutMs,\n children,\n ...providerProps\n } = props;\n\n const headerStore = await headers();\n const resolvedOrigin = appOrigin ?? 'http://localhost:3001';\n const userAgent = headerStore.get('user-agent') ?? undefined;\n const referer = headerStore.get('referer') ?? undefined;\n const sessionSegment = deriveSessionSegment({ userAgent, referer, appOrigin: resolvedOrigin });\n const cookieStore = await cookies();\n\n let initialAssignments: ServerAssignments;\n let initialLayoutOrder: string[] | null = null;\n\n if (initialAssignmentsOverride) {\n initialAssignments = initialAssignmentsOverride;\n } else if (sections && sections.length > 0) {\n const decision = await loadAdaptiveDecision({\n sections,\n components,\n cookies: cookieStore,\n apiKey: serverApiKey,\n baseUrl: DEFAULT_API_BASE_URL,\n origin: resolvedOrigin,\n userAgent,\n referer,\n timeoutMs,\n });\n initialAssignments = decision.assignments;\n initialLayoutOrder = decision.layoutOrder;\n } else {\n initialAssignments = await loadAdaptiveAssignments(components, {\n cookies: cookieStore,\n apiKey: serverApiKey,\n baseUrl: DEFAULT_API_BASE_URL,\n origin: resolvedOrigin,\n userAgent,\n referer,\n timeoutMs,\n });\n }\n\n return (\n <AdaptiveRootClient\n {...providerProps}\n initialAssignments={initialAssignments}\n initialLayoutOrder={initialLayoutOrder}\n sessionSegment={sessionSegment}\n >\n {children}\n </AdaptiveRootClient>\n );\n}\n","/**\n * Server-only helpers for Next.js / SSR. No React or DOM APIs.\n */\nimport {\n preloadAssignments,\n readSessionCookie,\n type ServerAssignConfig,\n type ServerAssignments,\n} from '@sentientui/core/server';\n\nexport { preloadAssignments, readSessionCookie };\nexport type { ServerAssignConfig, ServerAssignments };\n\nexport type LoadAdaptiveAssignmentsOptions = {\n /** Next.js `cookies()` return value, or any object with `get(name)`. */\n cookies: { get(name: string): { value: string } | undefined };\n apiKey: string;\n baseUrl: string;\n /** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */\n createSessionId?: () => string;\n /** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */\n origin?: string;\n /** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */\n userAgent?: string;\n /** From Next.js `headers().get('referer')`. */\n referer?: string;\n /** Milliseconds to wait for the API before returning default variants. Defaults to 1500. */\n timeoutMs?: number;\n};\n\nfunction defaultSessionId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * Fetches bandit assignments on the server for SEO-safe HTML.\n * Pass the result as `initialAssignments` on `<AdaptiveProvider>`.\n */\nexport async function loadAdaptiveAssignments(\n components: Array<{ id: string; variantIds: string[] }>,\n options: LoadAdaptiveAssignmentsOptions,\n): Promise<ServerAssignments> {\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadAssignments(components, sessionId, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n });\n}\n\nexport { preloadDecisions, type DecideResult } from '@sentientui/core/server';\n\nexport type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {\n /** Section IDs in default order. Passed to /v1/decide as the candidate layout. */\n sections: string[];\n /** Components to assign in the same decide call. */\n components?: Array<{ id: string; variantIds?: string[] }>;\n};\n\n/**\n * SSR helper for pages with a declared section layout. Calls `/v1/decide`\n * instead of multiple `/v1/assign` round trips.\n */\nexport async function loadAdaptiveDecision(\n options: LoadAdaptiveDecisionOptions,\n): Promise<import('@sentientui/core/server').DecideResult> {\n const { preloadDecisions, readSessionCookie } = await import('@sentientui/core/server');\n\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadDecisions(\n {\n sections: options.sections,\n components: options.components ?? [],\n },\n sessionId,\n {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n },\n );\n}\n"],"mappings":"+kBAAA,OAAS,wBAAAA,MAA4B,mBACrC,OAAS,WAAAC,EAAS,WAAAC,MAAe,eCEjC,OACE,sBAAAC,EACA,qBAAAC,MAGK,0BAoDP,OAAS,oBAAAC,MAA2C,0BA9BpD,SAASC,GAA2B,CAClC,OAAI,OAAO,QAAW,aAAe,OAAO,OAAO,YAAe,WACzD,OAAO,WAAW,EAEpB,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAG,EAAE,CAAC,EACrE,CAMA,eAAsBC,EACpBC,EACAC,EAC4B,CA5C9B,IAAAC,EAAAC,EAAAC,EA6CE,IAAMC,GACJD,GAAAD,EAAAG,EAAkBL,EAAQ,OAAO,IAAjC,KAAAE,GACAD,EAAAD,EAAQ,kBAAR,YAAAC,EAAA,KAAAD,KADA,KAAAG,EAEAN,EAAiB,EAEnB,OAAOS,EAAmBP,EAAYK,EAAW,CAC/C,OAAQJ,EAAQ,OAChB,QAASA,EAAQ,QACjB,OAAQA,EAAQ,OAChB,UAAWA,EAAQ,UACnB,QAASA,EAAQ,QACjB,UAAWA,EAAQ,SACrB,CAAC,CACH,CAeA,eAAsBO,EACpBP,EACyD,CA3E3D,IAAAC,EAAAC,EAAAC,EAAAK,EA4EE,GAAM,CAAE,iBAAAC,EAAkB,kBAAAJ,CAAkB,EAAI,KAAM,QAAO,yBAAyB,EAEhFD,GACJD,GAAAD,EAAAG,EAAkBL,EAAQ,OAAO,IAAjC,KAAAE,GACAD,EAAAD,EAAQ,kBAAR,YAA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AC7D,QAASgB,EACT,OAAQd,EACR,QAASR,EACT,OAAQiB,EACR,UAAAC,EACA,QAAAC,EACA,UAAAR,CACF,CAAC,EAGH,OACEZ,EAAC8B,EAAAC,EAAAC,EAAA,GACKlB,GADL,CAEC,mBAAoBW,EACpB,mBAAoBC,EACpB,eAAgBL,EAEf,SAAAR,GACH,CAEJ","names":["deriveSessionSegment","cookies","headers","preloadAssignments","readSessionCookie","preloadDecisions","defaultSessionId","loadAdaptiveAssignments","components","options","_a","_b","_c","sessionId","readSessionCookie","preloadAssignments","loadAdaptiveDecision","_d","preloadDecisions","AdaptiveRootClient","jsx","DEFAULT_API_BASE_URL","AdaptiveRoot","props","_b","_c","_a","components","sections","serverApiKey","appOrigin","initialAssignmentsOverride","timeoutMs","children","providerProps","__objRest","headerStore","headers","resolvedOrigin","userAgent","referer","sessionSegment","deriveSessionSegment","cookieStore","cookies","initialAssignments","initialLayoutOrder","decision","loadAdaptiveDecision","loadAdaptiveAssignments","AdaptiveRootClient","__spreadProps","__spreadValues"]}
|
|
1
|
+
{"version":3,"sources":["../../src/next/adaptive-root.tsx","../../src/server.ts"],"sourcesContent":["import { deriveSessionSegment } from '@sentientui/core';\nimport { cookies, headers } from 'next/headers';\nimport type { ReactNode } from 'react';\nimport type { AdaptiveProviderProps } from '../provider.js';\nimport {\n loadAdaptiveAssignments,\n loadAdaptiveDecision,\n type ServerAssignments,\n} from '../server.js';\nimport { AdaptiveRootClient } from './adaptive-root-client.js';\n\nconst DEFAULT_API_BASE_URL = 'https://api.sentient-ui.com/v1';\n\nexport type PreloadComponent = { id: string; variantIds: string[] };\n\nexport type AdaptiveRootProps = Omit<AdaptiveProviderProps, 'initialAssignments'> & {\n /** Components to assign server-side (SEO-safe). */\n components: PreloadComponent[];\n /**\n * Declare page section IDs in their default order. When provided,\n * AdaptiveRoot calls `/v1/decide` (single round trip) instead of\n * individual `/v1/assign` calls, and `useLayoutOrder()` returns the\n * persona-specific order on first render.\n *\n * @example sections={['hero', 'pricing', 'features', 'social_proof']}\n */\n sections?: string[];\n /** Server-only API key for `/v1/sessions`, `/v1/assign`, and `/v1/decide`. */\n serverApiKey: string;\n /** App origin — must be in the project's `allowed_origins`. */\n appOrigin?: string;\n /** Override: when set no network fetch is made. Useful for tests. */\n initialAssignments?: ServerAssignments;\n /**\n * Milliseconds to wait for the API before rendering default variants.\n * Defaults to 1500. Increase if you see unexpected fallbacks in production.\n */\n timeoutMs?: number;\n children: ReactNode;\n};\n\n/**\n * Next.js Server Component that resolves variant assignments (and optionally\n * section layout order) server-side for zero layout shift on first paint.\n *\n * When `sections` is provided, a single `POST /v1/decide` call returns both\n * the persona-specific section order and all component assignments.\n * Without `sections`, individual `/v1/assign` calls are made per component.\n *\n * @example\n * // app/page.tsx — with section layout\n * import { AdaptiveRoot } from '@sentientui/react/next';\n *\n * export default async function Page() {\n * return (\n * <AdaptiveRoot\n * apiKey={process.env.NEXT_PUBLIC_SENTIENT_API_KEY!}\n * serverApiKey={process.env.SENTIENT_SECRET_KEY!}\n * context={{ appId: 'my-app' }}\n * sections={['hero', 'pricing', 'features', 'social_proof']}\n * components={[\n * { id: 'hero_cta', variantIds: ['default', 'accent'] },\n * ]}\n * >\n * <HeroSection />\n * <PricingSection />\n * <FeaturesSection />\n * <SocialProofSection />\n * </AdaptiveRoot>\n * );\n * }\n */\nexport async function AdaptiveRoot(props: AdaptiveRootProps): Promise<JSX.Element> {\n const {\n components,\n sections,\n serverApiKey,\n appOrigin,\n initialAssignments: initialAssignmentsOverride,\n timeoutMs,\n children,\n ...providerProps\n } = props;\n\n const headerStore = await headers();\n const resolvedOrigin = appOrigin ?? 'http://localhost:3001';\n const userAgent = headerStore.get('user-agent') ?? undefined;\n const referer = headerStore.get('referer') ?? undefined;\n const sessionSegment = deriveSessionSegment({ userAgent, referer, appOrigin: resolvedOrigin });\n const cookieStore = await cookies();\n\n let initialAssignments: ServerAssignments;\n let initialLayoutOrder: string[] | null = null;\n\n if (initialAssignmentsOverride) {\n initialAssignments = initialAssignmentsOverride;\n } else if (sections && sections.length > 0) {\n const decision = await loadAdaptiveDecision({\n sections,\n components,\n cookies: cookieStore,\n apiKey: serverApiKey,\n baseUrl: DEFAULT_API_BASE_URL,\n origin: resolvedOrigin,\n userAgent,\n referer,\n timeoutMs,\n });\n initialAssignments = decision.assignments;\n initialLayoutOrder = decision.layoutOrder;\n } else {\n initialAssignments = await loadAdaptiveAssignments(components, {\n cookies: cookieStore,\n apiKey: serverApiKey,\n baseUrl: DEFAULT_API_BASE_URL,\n origin: resolvedOrigin,\n userAgent,\n referer,\n timeoutMs,\n });\n }\n\n return (\n <AdaptiveRootClient\n {...providerProps}\n initialAssignments={initialAssignments}\n initialLayoutOrder={initialLayoutOrder}\n sessionSegment={sessionSegment}\n >\n {children}\n </AdaptiveRootClient>\n );\n}\n","/**\n * Server-only helpers for Next.js / SSR. No React or DOM APIs.\n */\nimport {\n preloadAssignments,\n readSessionCookie,\n type ServerAssignConfig,\n type ServerAssignments,\n} from '@sentientui/core/server';\n\nexport { preloadAssignments, readSessionCookie };\nexport type { ServerAssignConfig, ServerAssignments };\n\nexport type LoadAdaptiveAssignmentsOptions = {\n /** Next.js `cookies()` return value, or any object with `get(name)`. */\n cookies: { get(name: string): { value: string } | undefined };\n apiKey: string;\n baseUrl: string;\n /** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */\n createSessionId?: () => string;\n /** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */\n origin?: string;\n /** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */\n userAgent?: string;\n /** From Next.js `headers().get('referer')`. */\n referer?: string;\n /** Milliseconds to wait for the API before returning default variants. Defaults to 1500. */\n timeoutMs?: number;\n};\n\nfunction defaultSessionId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * Fetches bandit assignments on the server for SEO-safe HTML.\n * Pass the result as `initialAssignments` on `<AdaptiveProvider>`.\n */\nexport async function loadAdaptiveAssignments(\n components: Array<{ id: string; variantIds: string[] }>,\n options: LoadAdaptiveAssignmentsOptions,\n): Promise<ServerAssignments> {\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadAssignments(components, sessionId, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n });\n}\n\nexport { preloadDecisions, type DecideResult } from '@sentientui/core/server';\n\nexport type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {\n /** Section IDs in default order. Passed to /v1/decide as the candidate layout. */\n sections: string[];\n /** Components to assign in the same decide call. */\n components?: Array<{ id: string; variantIds?: string[] }>;\n};\n\n/**\n * SSR helper for pages with a declared section layout. Calls `/v1/decide`\n * instead of multiple `/v1/assign` round trips.\n */\nexport async function loadAdaptiveDecision(\n options: LoadAdaptiveDecisionOptions,\n): Promise<import('@sentientui/core/server').DecideResult> {\n const { preloadDecisions, readSessionCookie } = await import('@sentientui/core/server');\n\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadDecisions(\n {\n sections: options.sections,\n components: options.components ?? [],\n },\n sessionId,\n {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n },\n );\n}\n"],"mappings":"+kBAAA,OAAS,wBAAAA,MAA4B,mBACrC,OAAS,WAAAC,EAAS,WAAAC,MAAe,eCEjC,OACE,sBAAAC,EACA,qBAAAC,MAGK,0BAoDP,OAAS,oBAAAC,MAA2C,0BA9BpD,SAASC,GAA2B,CAClC,OAAI,OAAO,QAAW,aAAe,OAAO,OAAO,YAAe,WACzD,OAAO,WAAW,EAEpB,OAAO,KAAK,IAAI,CAAC,IAAI,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EAkFMP,EADCQ,EAAAC,EACDT,EADC,CAPH,aACA,WACA,eACA,YACA,qBACA,YACA,aAIIU,EAAc,MAAMC,EAAQ,EAC5BC,EAAiBR,GAAA,KAAAA,EAAa,wBAC9BS,GAAYf,EAAAY,EAAY,IAAI,YAAY,IAA5B,KAAAZ,EAAiC,OAC7CgB,GAAUf,EAAAW,EAAY,IAAI,SAAS,IAAzB,KAAAX,EAA8B,OACxCgB,EAAiBC,EAAqB,CAAE,UAAAH,EAAW,QAAAC,EAAS,UAAWF,CAAe,CAAC,EACvFK,EAAc,MAAMC,EAAQ,EAE9BC,EACAC,EAAsC,KAE1C,GAAIf,EACFc,EAAqBd,UACZH,GAAYA,EAAS,OAAS,EAAG,CAC1C,IAAMmB,EAAW,MAAMC,EAAqB,CAC1C,SAAApB,EACA,WAAAD,EACA,QAASgB,EACT,OAAQd,EACR,QAASR,EACT,OAAQiB,EACR,UAAAC,EACA,QAAAC,EACA,UAAAR,CACF,CAAC,EACDa,EAAqBE,EAAS,YAC9BD,EAAqBC,EAAS,WAChC,MACEF,EAAqB,MAAMI,EAAwBtB,EAAY,CAC7D,QAASgB,EACT,OAAQd,EACR,QAASR,EACT,OAAQiB,EACR,UAAAC,EACA,QAAAC,EACA,UAAAR,CACF,CAAC,EAGH,OACEZ,EAAC8B,EAAAC,EAAAC,EAAA,GACKlB,GADL,CAEC,mBAAoBW,EACpB,mBAAoBC,EACpB,eAAgBL,EAEf,SAAAR,GACH,CAEJ","names":["deriveSessionSegment","cookies","headers","preloadAssignments","readSessionCookie","preloadDecisions","defaultSessionId","loadAdaptiveAssignments","components","options","_a","_b","_c","sessionId","readSessionCookie","preloadAssignments","loadAdaptiveDecision","_d","preloadDecisions","AdaptiveRootClient","jsx","DEFAULT_API_BASE_URL","AdaptiveRoot","props","_b","_c","_a","components","sections","serverApiKey","appOrigin","initialAssignmentsOverride","timeoutMs","children","providerProps","__objRest","headerStore","headers","resolvedOrigin","userAgent","referer","sessionSegment","deriveSessionSegment","cookieStore","cookies","initialAssignments","initialLayoutOrder","decision","loadAdaptiveDecision","loadAdaptiveAssignments","AdaptiveRootClient","__spreadProps","__spreadValues"]}
|