@cuadra-ai/uikit 0.1.7 → 0.1.8

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
@@ -236,7 +236,6 @@ For detailed widget API documentation, see the [full documentation](https://docs
236
236
  | `baseUrl` | `string` | Yes* | - | Cuadra API base URL (e.g., `'https://api.cuadra.ai'`) |
237
237
  | `proxyUrl` | `string` | Yes* | - | Proxy URL for backend-handled auth (e.g., `'/api/chat'`) |
238
238
  | `sessionToken` | `string \| null` | No | `null` | Bearer token for authentication |
239
- | `tenantId` | `string` | No | - | Tenant ID for multi-tenant support |
240
239
  | `mode` | `'singleChat' \| 'multiChat'` | No | `'multiChat'` | Chat mode |
241
240
  | `modelMode` | `'fixed' \| 'selector'` | No | `'fixed'` | Model selection mode |
242
241
  | `modelId` | `string` | Yes** | - | Model ID from [dashboard.cuadra.ai](https://dashboard.cuadra.ai) (required if `modelMode='fixed'`) |
@@ -1 +1 @@
1
- {"version":3,"file":"CuadraChat.d.ts","sourceRoot":"","sources":["../../src/components/CuadraChat.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAG1E,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,0BAA0B,EAAE,UAAU,GAAG,aAAa,CAAC;IACnG,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kDAAkD;IAClD,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IACpC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,6BAA6B;QAC7B,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CA2BhD"}
1
+ {"version":3,"file":"CuadraChat.d.ts","sourceRoot":"","sources":["../../src/components/CuadraChat.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAG1E,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,0BAA0B,EAAE,UAAU,GAAG,aAAa,CAAC;IACnG,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kDAAkD;IAClD,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IACpC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,6BAA6B;QAC7B,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CA0BhD"}
@@ -4,7 +4,6 @@ export interface CuadraRuntimeProviderProps {
4
4
  baseUrl: string;
5
5
  sessionToken?: string | null;
6
6
  isProxyMode?: boolean;
7
- tenantId?: string;
8
7
  mode?: 'singleChat' | 'multiChat';
9
8
  modelMode?: 'selector' | 'fixed';
10
9
  modelId?: string;
@@ -21,5 +20,5 @@ export interface CuadraRuntimeProviderProps {
21
20
  * Main provider component that sets up assistant-ui runtime with Cuadra API
22
21
  * Supports single/multi chat modes, fixed/selector model modes, and ephemeral chats
23
22
  */
24
- export declare function CuadraRuntimeProvider({ children, baseUrl, sessionToken, isProxyMode, tenantId, mode, modelId, onModelChange: _onModelChange, ephemeral, systemPrompt, initialThreadId, onError, onChatCreated, onThreadIdUpdate, onChatsLoaded, }: CuadraRuntimeProviderProps): import("react/jsx-runtime").JSX.Element;
23
+ export declare function CuadraRuntimeProvider({ children, baseUrl, sessionToken, isProxyMode, mode, modelId, onModelChange: _onModelChange, ephemeral, systemPrompt, initialThreadId, onError, onChatCreated, onThreadIdUpdate, onChatsLoaded, }: CuadraRuntimeProviderProps): import("react/jsx-runtime").JSX.Element;
25
24
  //# sourceMappingURL=CuadraRuntimeProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CuadraRuntimeProvider.d.ts","sourceRoot":"","sources":["../../src/components/CuadraRuntimeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAUzE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAGlC,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAG1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,gBAAgB,CAAC,EAAE,CACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,KAChB,IAAI,CAAC;IACV,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,WAAmB,EACnB,QAAQ,EACR,IAAkB,EAClB,OAAO,EACP,aAAa,EAAE,cAAc,EAC7B,SAAiB,EACjB,YAAY,EACZ,eAAe,EACf,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,aAAa,GACd,EAAE,0BAA0B,2CAiE5B"}
1
+ {"version":3,"file":"CuadraRuntimeProvider.d.ts","sourceRoot":"","sources":["../../src/components/CuadraRuntimeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAUzE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IAGtB,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAGlC,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAG1C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,gBAAgB,CAAC,EAAE,CACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,KAChB,IAAI,CAAC;IACV,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,WAAmB,EACnB,IAAkB,EAClB,OAAO,EACP,aAAa,EAAE,cAAc,EAC7B,SAAiB,EACjB,YAAY,EACZ,eAAe,EACf,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,aAAa,GACd,EAAE,0BAA0B,2CAiE5B"}
@@ -6,8 +6,6 @@ export interface CuadraUIKitConfig {
6
6
  proxyUrl?: string;
7
7
  /** Bearer token for authentication (optional if backend handles auth) */
8
8
  sessionToken?: string | null;
9
- /** Tenant ID for multi-tenant support */
10
- tenantId?: string;
11
9
  /** Chat mode: single thread or multi-thread */
12
10
  mode?: 'singleChat' | 'multiChat';
13
11
  /** Model selection mode */
@@ -1 +1 @@
1
- {"version":3,"file":"WidgetContent.d.ts","sourceRoot":"","sources":["../../src/components/WidgetContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAcjF,MAAM,WAAW,iBAAiB;IAEhC,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAClC,2BAA2B;IAC3B,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IACjC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sCAAsC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,4CAA4C;IAC5C,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,6BAA6B;QAC7B,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IAGH,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kDAAkD;IAClD,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAGpC,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,kCAAkC;IAClC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3D;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,CAkVjE,CAAC"}
1
+ {"version":3,"file":"WidgetContent.d.ts","sourceRoot":"","sources":["../../src/components/WidgetContent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAcjF,MAAM,WAAW,iBAAiB;IAEhC,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAG7B,+CAA+C;IAC/C,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAClC,2BAA2B;IAC3B,SAAS,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IACjC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,8CAA8C;IAC9C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sCAAsC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,4CAA4C;IAC5C,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,6BAA6B;QAC7B,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IAGH,+BAA+B;IAC/B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,kDAAkD;IAClD,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAGpC,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,kCAAkC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,kCAAkC;IAClC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3D;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,CAiVjE,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,23 +1,23 @@
1
- "use strict";var jt=Object.defineProperty;var Tt=(e,r,t)=>r in e?jt(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var J=(e,r,t)=>Tt(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),w=require("react"),Ne=require("react-dom"),I=require("@assistant-ui/react"),be=require("@assistant-ui/react-markdown");var de=typeof document<"u"?document.currentScript:null;const It=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),At=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,t,n)=>n?n.toUpperCase():t.toLowerCase()),Le=e=>{const r=At(e);return r.charAt(0).toUpperCase()+r.slice(1)},qe=(...e)=>e.filter((r,t,n)=>!!r&&r.trim()!==""&&n.indexOf(r)===t).join(" ").trim(),St=e=>{for(const r in e)if(r.startsWith("aria-")||r==="role"||r==="title")return!0};var Nt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const Lt=w.forwardRef(({color:e="currentColor",size:r=24,strokeWidth:t=2,absoluteStrokeWidth:n,className:i="",children:o,iconNode:a,...l},s)=>w.createElement("svg",{ref:s,...Nt,width:r,height:r,stroke:e,strokeWidth:n?Number(t)*24/Number(r):t,className:qe("lucide",i),...!o&&!St(l)&&{"aria-hidden":"true"},...l},[...a.map(([c,h])=>w.createElement(c,h)),...Array.isArray(o)?o:[o]]));const _=(e,r)=>{const t=w.forwardRef(({className:n,...i},o)=>w.createElement(Lt,{ref:o,iconNode:r,className:qe(`lucide-${It(Le(e))}`,`lucide-${e}`,n),...i}));return t.displayName=Le(e),t};const Mt=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Pt=_("arrow-up",Mt);const Dt=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Et=_("check",Dt);const Rt=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],_t=_("chevron-down",Rt);const Ft=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 18a6 6 0 0 0 0-12v12z",key:"j4l70d"}]],zt=_("contrast",Ft);const $t=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Ot=_("copy",$t);const Ut=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Bt=_("ellipsis-vertical",Ut);const Wt=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ke=_("loader-circle",Wt);const Ht=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],qt=_("menu",Ht);const Kt=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Vt=_("plus",Kt);class Ve{constructor(r,t,n=!1,i){J(this,"baseUrl");J(this,"sessionToken",null);J(this,"isProxyMode",!1);J(this,"tenantId",null);this.baseUrl=r.replace(/\/$/,""),this.isProxyMode=n,t&&(this.sessionToken=t),i&&(this.tenantId=i)}setSessionToken(r){this.sessionToken=r}setTenantId(r){this.tenantId=r}getUrl(r){if(this.isProxyMode){const t=`${this.baseUrl}${r.replace("/v1","")}`;return t.startsWith("/")||t.startsWith("./"),t}return`${this.baseUrl}${r}`}async createOrContinueChat(r,t){const n=this.getUrl("/v1/chats"),o={"Content-Type":"application/json","Idempotency-Key":this.generateIdempotencyKey()};this.sessionToken&&(o.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(o["X-Tenant-Id"]=this.tenantId);const a={...r,stream:!0},l=await fetch(n,{method:"POST",headers:o,body:JSON.stringify(a),signal:t});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.detail||s.message||`API error: ${l.status} ${l.statusText}`)}if(!l.body)throw new Error("Response body is null");return l.body}async getChat(r){const t=this.getUrl(`/v1/chats/${r}`),n={"Content-Type":"application/json"};this.sessionToken&&(n.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(n["X-Tenant-Id"]=this.tenantId);const i=await fetch(t,{method:"GET",headers:n});if(!i.ok){const o=await i.json().catch(()=>({}));throw new Error(o.detail||o.message||`API error: ${i.status} ${i.statusText}`)}return i.json()}async listChats(r){const t=this.getUrl("/v1/chats"),n=t.startsWith("/")||t.startsWith("./")?new URL(t,window.location.origin):new URL(t);r?.limit&&n.searchParams.set("limit",r.limit.toString()),r?.cursor&&n.searchParams.set("cursor",r.cursor),r?.["expand[]"]&&r["expand[]"].forEach(a=>{n.searchParams.append("expand[]",a)});const i={"Content-Type":"application/json"};this.sessionToken&&(i.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(i["X-Tenant-Id"]=this.tenantId);const o=await fetch(n.toString(),{method:"GET",headers:i});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.detail||a.message||`API error: ${o.status} ${o.statusText}`)}return o.json()}generateIdempotencyKey(){try{if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID()}catch{}const r=n=>Array.from({length:n},()=>Math.floor(Math.random()*16).toString(16)).join(""),t=()=>{const n=["8","9","a","b"];return n[Math.floor(Math.random()*n.length)]};return`${r(8)}-${r(4)}-4${r(3)}-${t()}${r(3)}-${r(12)}`}async updateChat(r,t){const n=`/v1/chats/${r}`,i=this.getUrl(n),o=i.startsWith("/")||i.startsWith("./")?new URL(i,window.location.origin):new URL(i),l={"Content-Type":"application/json","Idempotency-Key":this.generateIdempotencyKey()};this.sessionToken&&(l.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(l["X-Tenant-Id"]=this.tenantId);const s=await fetch(o.toString(),{method:"PATCH",headers:l,body:JSON.stringify(t)});if(!s.ok){const h=await s.text();let u={};try{u=JSON.parse(h)}catch{u={detail:h}}throw new Error(u.detail||u.message||`API error: ${s.status} ${s.statusText}`)}if(s.status===204)return{};const c=await s.text();if(!c)return{};try{return JSON.parse(c)}catch{return{}}}async deleteChat(r){const t=`/v1/chats/${r}`,n=this.getUrl(t),i=n.startsWith("/")||n.startsWith("./")?new URL(n,window.location.origin):new URL(n),a={"Content-Type":"application/json","Idempotency-Key":this.generateIdempotencyKey()};this.sessionToken&&(a.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(a["X-Tenant-Id"]=this.tenantId);const l=await fetch(i.toString(),{method:"DELETE",headers:a});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.detail||s.message||`API error: ${l.status} ${l.statusText}`)}}async listModels(r){const t=this.getUrl("/v1/models"),n=t.startsWith("/")||t.startsWith("./")?new URL(t,window.location.origin):new URL(t);r?.limit&&n.searchParams.set("limit",r.limit.toString()),r?.cursor&&n.searchParams.set("cursor",r.cursor),r?.["expand[]"]&&r["expand[]"].forEach(a=>{n.searchParams.append("expand[]",a)});const i={"Content-Type":"application/json"};this.sessionToken&&(i.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(i["X-Tenant-Id"]=this.tenantId);const o=await fetch(n.toString(),{method:"GET",headers:i});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.detail||a.message||`API error: ${o.status} ${o.statusText}`)}return o.json()}async getModel(r){const t=this.getUrl(`/v1/models/${r}`),n={"Content-Type":"application/json"};this.sessionToken&&(n.Authorization=`Bearer ${this.sessionToken}`),this.tenantId&&(n["X-Tenant-Id"]=this.tenantId);const i=await fetch(t,{method:"GET",headers:n});if(!i.ok){const o=await i.json().catch(()=>({}));throw new Error(o.detail||o.message||`API error: ${i.status} ${i.statusText}`)}return i.json()}}async function*Xt(e,r){const t=e.getReader(),n=new TextDecoder;let i="";try{for(;;){if(r?.aborted){t.cancel();break}const{done:o,value:a}=await t.read();if(o)break;i+=n.decode(a,{stream:!0});const l=i.split(`
1
+ "use strict";var jt=Object.defineProperty;var Tt=(e,r,t)=>r in e?jt(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var te=(e,r,t)=>Tt(e,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),w=require("react"),Ne=require("react-dom"),T=require("@assistant-ui/react"),be=require("@assistant-ui/react-markdown");var de=typeof document<"u"?document.currentScript:null;const At=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),St=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(r,t,n)=>n?n.toUpperCase():t.toLowerCase()),Le=e=>{const r=St(e);return r.charAt(0).toUpperCase()+r.slice(1)},qe=(...e)=>e.filter((r,t,n)=>!!r&&r.trim()!==""&&n.indexOf(r)===t).join(" ").trim(),It=e=>{for(const r in e)if(r.startsWith("aria-")||r==="role"||r==="title")return!0};var Nt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const Lt=w.forwardRef(({color:e="currentColor",size:r=24,strokeWidth:t=2,absoluteStrokeWidth:n,className:i="",children:o,iconNode:a,...l},s)=>w.createElement("svg",{ref:s,...Nt,width:r,height:r,stroke:e,strokeWidth:n?Number(t)*24/Number(r):t,className:qe("lucide",i),...!o&&!It(l)&&{"aria-hidden":"true"},...l},[...a.map(([c,h])=>w.createElement(c,h)),...Array.isArray(o)?o:[o]]));const _=(e,r)=>{const t=w.forwardRef(({className:n,...i},o)=>w.createElement(Lt,{ref:o,iconNode:r,className:qe(`lucide-${At(Le(e))}`,`lucide-${e}`,n),...i}));return t.displayName=Le(e),t};const Mt=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Pt=_("arrow-up",Mt);const Dt=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Et=_("check",Dt);const Rt=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],_t=_("chevron-down",Rt);const Ft=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 18a6 6 0 0 0 0-12v12z",key:"j4l70d"}]],zt=_("contrast",Ft);const $t=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Ot=_("copy",$t);const Ut=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],Bt=_("ellipsis-vertical",Ut);const Wt=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ke=_("loader-circle",Wt);const Ht=[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]],qt=_("menu",Ht);const Kt=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],Vt=_("plus",Kt);class Ve{constructor(r,t,n=!1){te(this,"baseUrl");te(this,"sessionToken",null);te(this,"isProxyMode",!1);this.baseUrl=r.replace(/\/$/,""),this.isProxyMode=n,t&&(this.sessionToken=t)}setSessionToken(r){this.sessionToken=r}getUrl(r){if(this.isProxyMode){const t=`${this.baseUrl}${r.replace("/v1","")}`;return t.startsWith("/")||t.startsWith("./"),t}return`${this.baseUrl}${r}`}async createOrContinueChat(r,t){const n=this.getUrl("/v1/chats"),o={"Content-Type":"application/json","Idempotency-Key":this.generateIdempotencyKey()};this.sessionToken&&(o.Authorization=`Bearer ${this.sessionToken}`);const a={...r,stream:!0},l=await fetch(n,{method:"POST",headers:o,body:JSON.stringify(a),signal:t});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.detail||s.message||`API error: ${l.status} ${l.statusText}`)}if(!l.body)throw new Error("Response body is null");return l.body}async getChat(r){const t=this.getUrl(`/v1/chats/${r}`),n={"Content-Type":"application/json"};this.sessionToken&&(n.Authorization=`Bearer ${this.sessionToken}`);const i=await fetch(t,{method:"GET",headers:n});if(!i.ok){const o=await i.json().catch(()=>({}));throw new Error(o.detail||o.message||`API error: ${i.status} ${i.statusText}`)}return i.json()}async listChats(r){const t=this.getUrl("/v1/chats"),n=t.startsWith("/")||t.startsWith("./")?new URL(t,window.location.origin):new URL(t);r?.limit&&n.searchParams.set("limit",r.limit.toString()),r?.cursor&&n.searchParams.set("cursor",r.cursor),r?.["expand[]"]&&r["expand[]"].forEach(a=>{n.searchParams.append("expand[]",a)});const i={"Content-Type":"application/json"};this.sessionToken&&(i.Authorization=`Bearer ${this.sessionToken}`);const o=await fetch(n.toString(),{method:"GET",headers:i});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.detail||a.message||`API error: ${o.status} ${o.statusText}`)}return o.json()}generateIdempotencyKey(){try{if(typeof crypto<"u"&&crypto.randomUUID)return crypto.randomUUID()}catch{}const r=n=>Array.from({length:n},()=>Math.floor(Math.random()*16).toString(16)).join(""),t=()=>{const n=["8","9","a","b"];return n[Math.floor(Math.random()*n.length)]};return`${r(8)}-${r(4)}-4${r(3)}-${t()}${r(3)}-${r(12)}`}async updateChat(r,t){const n=`/v1/chats/${r}`,i=this.getUrl(n),o=i.startsWith("/")||i.startsWith("./")?new URL(i,window.location.origin):new URL(i),l={"Content-Type":"application/json","Idempotency-Key":this.generateIdempotencyKey()};this.sessionToken&&(l.Authorization=`Bearer ${this.sessionToken}`);const s=await fetch(o.toString(),{method:"PATCH",headers:l,body:JSON.stringify(t)});if(!s.ok){const h=await s.text();let u={};try{u=JSON.parse(h)}catch{u={detail:h}}throw new Error(u.detail||u.message||`API error: ${s.status} ${s.statusText}`)}if(s.status===204)return{};const c=await s.text();if(!c)return{};try{return JSON.parse(c)}catch{return{}}}async deleteChat(r){const t=`/v1/chats/${r}`,n=this.getUrl(t),i=n.startsWith("/")||n.startsWith("./")?new URL(n,window.location.origin):new URL(n),a={"Content-Type":"application/json","Idempotency-Key":this.generateIdempotencyKey()};this.sessionToken&&(a.Authorization=`Bearer ${this.sessionToken}`);const l=await fetch(i.toString(),{method:"DELETE",headers:a});if(!l.ok){const s=await l.json().catch(()=>({}));throw new Error(s.detail||s.message||`API error: ${l.status} ${l.statusText}`)}}async listModels(r){const t=this.getUrl("/v1/models"),n=t.startsWith("/")||t.startsWith("./")?new URL(t,window.location.origin):new URL(t);r?.limit&&n.searchParams.set("limit",r.limit.toString()),r?.cursor&&n.searchParams.set("cursor",r.cursor),r?.["expand[]"]&&r["expand[]"].forEach(a=>{n.searchParams.append("expand[]",a)});const i={"Content-Type":"application/json"};this.sessionToken&&(i.Authorization=`Bearer ${this.sessionToken}`);const o=await fetch(n.toString(),{method:"GET",headers:i});if(!o.ok){const a=await o.json().catch(()=>({}));throw new Error(a.detail||a.message||`API error: ${o.status} ${o.statusText}`)}return o.json()}async getModel(r){const t=this.getUrl(`/v1/models/${r}`),n={"Content-Type":"application/json"};this.sessionToken&&(n.Authorization=`Bearer ${this.sessionToken}`);const i=await fetch(t,{method:"GET",headers:n});if(!i.ok){const o=await i.json().catch(()=>({}));throw new Error(o.detail||o.message||`API error: ${i.status} ${i.statusText}`)}return i.json()}}async function*Gt(e,r){const t=e.getReader(),n=new TextDecoder;let i="";try{for(;;){if(r?.aborted){t.cancel();break}const{done:o,value:a}=await t.read();if(o)break;i+=n.decode(a,{stream:!0});const l=i.split(`
2
2
 
3
- `);i=l.pop()||"";for(const s of l)if(s.startsWith("data: ")){const c=s.slice(6);if(c.trim()==="[DONE]"){yield{done:!0};continue}try{yield JSON.parse(c)}catch{}}}}finally{t.releaseLock()}}function Gt(e){return e.map(r=>{let t="";if(typeof r.content=="string")t=r.content;else if(Array.isArray(r.content)){const n=r.content.find(i=>i.type==="text");n&&typeof n=="object"&&"text"in n&&(t=n.text)}return{role:r.role,content:t}})}function Zt(e,r){const{modelId:t,systemPrompt:n,ephemeral:i,onChatCreated:o}=r;return{async*run(a){const{messages:l,abortSignal:s}=a,h={messages:Gt(l),chatId:null,systemPrompt:n,ephemeral:i,stream:!0};t&&t.trim()!==""&&(h.modelId=t);const u=await e.createOrContinueChat(h,s);let p="",g;for await(const f of Xt(u,s)){if(s?.aborted)throw new Error("Request aborted");const b=f.id;b&&!g&&(g=b,o?.(b));const x=f.delta;if(x!=null&&(p+=x),f.type==="message"||f.content){const y=f.content||"";p+=y}if(f.message&&(p+=f.message.content||""),f.tool_calls,f.finished){p&&(yield{content:[{type:"text",text:p}]});break}p&&(yield{content:[{type:"text",text:p}]})}p&&(yield{content:[{type:"text",text:p}]})}}}const Me=new Map;function Jt(e,r){return{async list(){const t=[];let i,o=0;do{const l=await e.listChats({limit:50,cursor:i}),s=l.items||[];Array.isArray(s)&&s.length>0&&t.push(...s),i=l.nextCursor||void 0,o++}while(i&&o<50);return{threads:t.map(l=>{const s=l.id;return!s||l.deletedAt?null:{status:"regular",remoteId:s,title:l.title||"New Chat",createdAt:l.createdAt?new Date(l.createdAt):new Date,updatedAt:l.updatedAt?new Date(l.updatedAt):new Date}}).filter(l=>l!==null)}},async initialize(t){return{remoteId:Me.get(t)||t,externalId:void 0}},async rename(t,n){await e.updateChat(t,{title:n})},async archive(t){},async unarchive(t){},async delete(t){await e.deleteChat(t)},async generateTitle(t,n){return new ReadableStream},async fetch(t){try{const n=await e.getChat(t);return{status:"regular",remoteId:n.id||t,title:n.title||"Chat",createdAt:n.createdAt?new Date(n.createdAt):new Date,updatedAt:n.updatedAt?new Date(n.updatedAt):new Date}}catch{return{status:"regular",remoteId:t,createdAt:new Date,updatedAt:new Date}}},updateRemoteId(t,n){Me.set(t,n),r?.(t,n)}}}function Qt({children:e,baseUrl:r,sessionToken:t,isProxyMode:n=!1,tenantId:i,mode:o="multiChat",modelId:a,onModelChange:l,ephemeral:s=!1,systemPrompt:c,initialThreadId:h,onError:u,onChatCreated:p,onThreadIdUpdate:g,onChatsLoaded:f}){const b=w.useMemo(()=>new Ve(r,t||void 0,n,i),[r,t,n,i]),[x,k]=w.useState(a||null);w.useEffect(()=>{a&&k(a)},[a]);const y=w.useCallback(T=>{p?.(T)},[p]),C=w.useCallback((T,L)=>{g?.(T,L)},[g]),j=w.useMemo(()=>Zt(b,{modelId:x||void 0,systemPrompt:c,ephemeral:s,onChatCreated:y}),[b,x,c,s,y]),v=I.useLocalRuntime(j);return o==="singleChat"?d.jsx(I.AssistantRuntimeProvider,{runtime:v,children:e}):d.jsx(Yt,{client:b,modelAdapter:j,initialThreadId:h,onChatsLoaded:f,onThreadIdUpdate:C,onError:u,children:e})}function Yt({client:e,modelAdapter:r,initialThreadId:t,onChatsLoaded:n,onThreadIdUpdate:i,onError:o,children:a}){const l=w.useMemo(()=>Jt(e,(u,p)=>{i?.(u,p)}),[e,i]),s=w.useMemo(()=>({...l,async list(){const u=await l.list();return n?.(),u}}),[l,n]);w.useEffect(()=>{window.__cuadraThreadListAdapter=s,window.__cuadraThreadListRuntime=null},[s]);const c=w.useCallback(()=>I.useLocalRuntime(r),[r]),h=I.unstable_useRemoteThreadListRuntime({adapter:s,runtimeHook:c});return w.useEffect(()=>{window.__cuadraThreadListRuntime=h},[h]),d.jsx(I.AssistantRuntimeProvider,{runtime:h,children:a})}function Pe(e,r){const t=String(e);if(typeof r!="string")throw new TypeError("Expected character");let n=0,i=t.indexOf(r);for(;i!==-1;)n++,i=t.indexOf(r,i+r.length);return n}const Q=se(/[A-Za-z]/),ye=se(/[\dA-Za-z]/);function er(e){return e!==null&&(e<32||e===127)}function K(e){return e!==null&&e<-2}function N(e){return e!==null&&(e<0||e===32)}function E(e){return e===-2||e===-1||e===32}const oe=se(/\p{P}|\p{S}/u),B=se(/\s/);function se(e){return r;function r(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function tr(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}const le=(function(e){if(e==null)return ir;if(typeof e=="function")return ue(e);if(typeof e=="object")return Array.isArray(e)?rr(e):nr(e);if(typeof e=="string")return ar(e);throw new Error("Expected function, string, or object as test")});function rr(e){const r=[];let t=-1;for(;++t<e.length;)r[t]=le(e[t]);return ue(n);function n(...i){let o=-1;for(;++o<r.length;)if(r[o].apply(this,i))return!0;return!1}}function nr(e){const r=e;return ue(t);function t(n){const i=n;let o;for(o in e)if(i[o]!==r[o])return!1;return!0}}function ar(e){return ue(r);function r(t){return t&&t.type===e}}function ue(e){return r;function r(t,n,i){return!!(or(t)&&e.call(this,t,typeof n=="number"?n:void 0,i||void 0))}}function ir(){return!0}function or(e){return e!==null&&typeof e=="object"&&"type"in e}const Xe=[],sr=!0,ke=!1,lr="skip";function Ge(e,r,t,n){let i;typeof r=="function"&&typeof t!="function"?(n=t,t=r):i=r;const o=le(i),a=n?-1:1;l(e,void 0,[])();function l(s,c,h){const u=s&&typeof s=="object"?s:{};if(typeof u.type=="string"){const g=typeof u.tagName=="string"?u.tagName:typeof u.name=="string"?u.name:void 0;Object.defineProperty(p,"name",{value:"node ("+(s.type+(g?"<"+g+">":""))+")"})}return p;function p(){let g=Xe,f,b,x;if((!r||o(s,c,h[h.length-1]||void 0))&&(g=ur(t(s,h)),g[0]===ke))return g;if("children"in s&&s.children){const k=s;if(k.children&&g[0]!==lr)for(b=(n?k.children.length:-1)+a,x=h.concat(k);b>-1&&b<k.children.length;){const y=k.children[b];if(f=l(y,b,x)(),f[0]===ke)return f;b=typeof f[1]=="number"?f[1]:b+a}}return g}}}function ur(e){return Array.isArray(e)?e:typeof e=="number"?[sr,e]:e==null?Xe:[e]}function cr(e,r,t){const i=le((t||{}).ignore||[]),o=dr(r);let a=-1;for(;++a<o.length;)Ge(e,"text",l);function l(c,h){let u=-1,p;for(;++u<h.length;){const g=h[u],f=p?p.children:void 0;if(i(g,f?f.indexOf(g):void 0,p))return;p=g}if(p)return s(c,h)}function s(c,h){const u=h[h.length-1],p=o[a][0],g=o[a][1];let f=0;const x=u.children.indexOf(c);let k=!1,y=[];p.lastIndex=0;let C=p.exec(c.value);for(;C;){const j=C.index,v={index:C.index,input:C.input,stack:[...h,c]};let T=g(...C,v);if(typeof T=="string"&&(T=T.length>0?{type:"text",value:T}:void 0),T===!1?p.lastIndex=j+1:(f!==j&&y.push({type:"text",value:c.value.slice(f,j)}),Array.isArray(T)?y.push(...T):T&&y.push(T),f=j+C[0].length,k=!0),!p.global)break;C=p.exec(c.value)}return k?(f<c.value.length&&y.push({type:"text",value:c.value.slice(f)}),u.children.splice(x,1,...y)):y=[c],x+y.length}}function dr(e){const r=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const t=!e[0]||Array.isArray(e[0])?e:[e];let n=-1;for(;++n<t.length;){const i=t[n];r.push([fr(i[0]),hr(i[1])])}return r}function fr(e){return typeof e=="string"?new RegExp(tr(e),"g"):e}function hr(e){return typeof e=="function"?e:function(){return e}}const fe="phrasing",he=["autolink","link","image","label"];function mr(){return{transforms:[yr],enter:{literalAutolink:gr,literalAutolinkEmail:me,literalAutolinkHttp:me,literalAutolinkWww:me},exit:{literalAutolink:wr,literalAutolinkEmail:kr,literalAutolinkHttp:xr,literalAutolinkWww:br}}}function pr(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:fe,notInConstruct:he},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:fe,notInConstruct:he},{character:":",before:"[ps]",after:"\\/",inConstruct:fe,notInConstruct:he}]}}function gr(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function me(e){this.config.enter.autolinkProtocol.call(this,e)}function xr(e){this.config.exit.autolinkProtocol.call(this,e)}function br(e){this.config.exit.data.call(this,e);const r=this.stack[this.stack.length-1];r.type,r.url="http://"+this.sliceSerialize(e)}function kr(e){this.config.exit.autolinkEmail.call(this,e)}function wr(e){this.exit(e)}function yr(e){cr(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Cr],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,vr]],{ignore:["link","linkReference"]})}function Cr(e,r,t,n,i){let o="";if(!Ze(i)||(/^w/i.test(r)&&(t=r+t,r="",o="http://"),!jr(t)))return!1;const a=Tr(t+n);if(!a[0])return!1;const l={type:"link",title:null,url:o+r+a[0],children:[{type:"text",value:r+a[0]}]};return a[1]?[l,{type:"text",value:a[1]}]:l}function vr(e,r,t,n){return!Ze(n,!0)||/[-\d_]$/.test(t)?!1:{type:"link",title:null,url:"mailto:"+r+"@"+t,children:[{type:"text",value:r+"@"+t}]}}function jr(e){const r=e.split(".");return!(r.length<2||r[r.length-1]&&(/_/.test(r[r.length-1])||!/[a-zA-Z\d]/.test(r[r.length-1]))||r[r.length-2]&&(/_/.test(r[r.length-2])||!/[a-zA-Z\d]/.test(r[r.length-2])))}function Tr(e){const r=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!r)return[e,void 0];e=e.slice(0,r.index);let t=r[0],n=t.indexOf(")");const i=Pe(e,"(");let o=Pe(e,")");for(;n!==-1&&i>o;)e+=t.slice(0,n+1),t=t.slice(n+1),n=t.indexOf(")"),o++;return[e,t]}function Ze(e,r){const t=e.input.charCodeAt(e.index-1);return(e.index===0||B(t)||oe(t))&&(!r||t!==47)}function ee(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}Je.peek=Er;function Ir(){this.buffer()}function Ar(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function Sr(){this.buffer()}function Nr(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function Lr(e){const r=this.resume(),t=this.stack[this.stack.length-1];t.type,t.identifier=ee(this.sliceSerialize(e)).toLowerCase(),t.label=r}function Mr(e){this.exit(e)}function Pr(e){const r=this.resume(),t=this.stack[this.stack.length-1];t.type,t.identifier=ee(this.sliceSerialize(e)).toLowerCase(),t.label=r}function Dr(e){this.exit(e)}function Er(){return"["}function Je(e,r,t,n){const i=t.createTracker(n);let o=i.move("[^");const a=t.enter("footnoteReference"),l=t.enter("reference");return o+=i.move(t.safe(t.associationId(e),{after:"]",before:o})),l(),a(),o+=i.move("]"),o}function Rr(){return{enter:{gfmFootnoteCallString:Ir,gfmFootnoteCall:Ar,gfmFootnoteDefinitionLabelString:Sr,gfmFootnoteDefinition:Nr},exit:{gfmFootnoteCallString:Lr,gfmFootnoteCall:Mr,gfmFootnoteDefinitionLabelString:Pr,gfmFootnoteDefinition:Dr}}}function _r(e){let r=!1;return e&&e.firstLineBlank&&(r=!0),{handlers:{footnoteDefinition:t,footnoteReference:Je},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function t(n,i,o,a){const l=o.createTracker(a);let s=l.move("[^");const c=o.enter("footnoteDefinition"),h=o.enter("label");return s+=l.move(o.safe(o.associationId(n),{before:s,after:"]"})),h(),s+=l.move("]:"),n.children&&n.children.length>0&&(l.shift(4),s+=l.move((r?`
4
- `:" ")+o.indentLines(o.containerFlow(n,l.current()),r?Qe:Fr))),c(),s}}function Fr(e,r,t){return r===0?e:Qe(e,r,t)}function Qe(e,r,t){return(t?"":" ")+e}const zr=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Ye.peek=Wr;function $r(){return{canContainEols:["delete"],enter:{strikethrough:Ur},exit:{strikethrough:Br}}}function Or(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:zr}],handlers:{delete:Ye}}}function Ur(e){this.enter({type:"delete",children:[]},e)}function Br(e){this.exit(e)}function Ye(e,r,t,n){const i=t.createTracker(n),o=t.enter("strikethrough");let a=i.move("~~");return a+=t.containerPhrasing(e,{...i.current(),before:a,after:"~"}),a+=i.move("~~"),o(),a}function Wr(){return"~"}function Hr(e){return e.length}function qr(e,r){const t=r||{},n=(t.align||[]).concat(),i=t.stringLength||Hr,o=[],a=[],l=[],s=[];let c=0,h=-1;for(;++h<e.length;){const b=[],x=[];let k=-1;for(e[h].length>c&&(c=e[h].length);++k<e[h].length;){const y=Kr(e[h][k]);if(t.alignDelimiters!==!1){const C=i(y);x[k]=C,(s[k]===void 0||C>s[k])&&(s[k]=C)}b.push(y)}a[h]=b,l[h]=x}let u=-1;if(typeof n=="object"&&"length"in n)for(;++u<c;)o[u]=De(n[u]);else{const b=De(n);for(;++u<c;)o[u]=b}u=-1;const p=[],g=[];for(;++u<c;){const b=o[u];let x="",k="";b===99?(x=":",k=":"):b===108?x=":":b===114&&(k=":");let y=t.alignDelimiters===!1?1:Math.max(1,s[u]-x.length-k.length);const C=x+"-".repeat(y)+k;t.alignDelimiters!==!1&&(y=x.length+y+k.length,y>s[u]&&(s[u]=y),g[u]=y),p[u]=C}a.splice(1,0,p),l.splice(1,0,g),h=-1;const f=[];for(;++h<a.length;){const b=a[h],x=l[h];u=-1;const k=[];for(;++u<c;){const y=b[u]||"";let C="",j="";if(t.alignDelimiters!==!1){const v=s[u]-(x[u]||0),T=o[u];T===114?C=" ".repeat(v):T===99?v%2?(C=" ".repeat(v/2+.5),j=" ".repeat(v/2-.5)):(C=" ".repeat(v/2),j=C):j=" ".repeat(v)}t.delimiterStart!==!1&&!u&&k.push("|"),t.padding!==!1&&!(t.alignDelimiters===!1&&y==="")&&(t.delimiterStart!==!1||u)&&k.push(" "),t.alignDelimiters!==!1&&k.push(C),k.push(y),t.alignDelimiters!==!1&&k.push(j),t.padding!==!1&&k.push(" "),(t.delimiterEnd!==!1||u!==c-1)&&k.push("|")}f.push(t.delimiterEnd===!1?k.join("").replace(/ +$/,""):k.join(""))}return f.join(`
5
- `)}function Kr(e){return e==null?"":String(e)}function De(e){const r=typeof e=="string"?e.codePointAt(0):0;return r===67||r===99?99:r===76||r===108?108:r===82||r===114?114:0}function Vr(e,r,t,n){const i=t.enter("blockquote"),o=t.createTracker(n);o.move("> "),o.shift(2);const a=t.indentLines(t.containerFlow(e,o.current()),Xr);return i(),a}function Xr(e,r,t){return">"+(t?"":" ")+e}function Gr(e,r){return Ee(e,r.inConstruct,!0)&&!Ee(e,r.notInConstruct,!1)}function Ee(e,r,t){if(typeof r=="string"&&(r=[r]),!r||r.length===0)return t;let n=-1;for(;++n<r.length;)if(e.includes(r[n]))return!0;return!1}function Re(e,r,t,n){let i=-1;for(;++i<t.unsafe.length;)if(t.unsafe[i].character===`
6
- `&&Gr(t.stack,t.unsafe[i]))return/[ \t]/.test(n.before)?"":" ";return`\\
7
- `}function Zr(e,r){const t=String(e);let n=t.indexOf(r),i=n,o=0,a=0;if(typeof r!="string")throw new TypeError("Expected substring");for(;n!==-1;)n===i?++o>a&&(a=o):o=1,i=n+r.length,n=t.indexOf(r,i);return a}function Jr(e,r){return!!(r.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function Qr(e){const r=e.options.fence||"`";if(r!=="`"&&r!=="~")throw new Error("Cannot serialize code with `"+r+"` for `options.fence`, expected `` ` `` or `~`");return r}function Yr(e,r,t,n){const i=Qr(t),o=e.value||"",a=i==="`"?"GraveAccent":"Tilde";if(Jr(e,t)){const u=t.enter("codeIndented"),p=t.indentLines(o,en);return u(),p}const l=t.createTracker(n),s=i.repeat(Math.max(Zr(o,i)+1,3)),c=t.enter("codeFenced");let h=l.move(s);if(e.lang){const u=t.enter(`codeFencedLang${a}`);h+=l.move(t.safe(e.lang,{before:h,after:" ",encode:["`"],...l.current()})),u()}if(e.lang&&e.meta){const u=t.enter(`codeFencedMeta${a}`);h+=l.move(" "),h+=l.move(t.safe(e.meta,{before:h,after:`
3
+ `);i=l.pop()||"";for(const s of l)if(s.startsWith("data: ")){const c=s.slice(6);if(c.trim()==="[DONE]"){yield{done:!0};continue}try{yield JSON.parse(c)}catch{}}}}finally{t.releaseLock()}}function Zt(e){return e.map(r=>{let t="";if(typeof r.content=="string")t=r.content;else if(Array.isArray(r.content)){const n=r.content.find(i=>i.type==="text");n&&typeof n=="object"&&"text"in n&&(t=n.text)}return{role:r.role,content:t}})}function Jt(e,r){const{modelId:t,systemPrompt:n,ephemeral:i,onChatCreated:o}=r;return{async*run(a){const{messages:l,abortSignal:s}=a,h={messages:Zt(l),chatId:null,systemPrompt:n,ephemeral:i,stream:!0};t&&t.trim()!==""&&(h.modelId=t);const u=await e.createOrContinueChat(h,s);let p="",g;for await(const f of Gt(u,s)){if(s?.aborted)throw new Error("Request aborted");const b=f.id;b&&!g&&(g=b,o?.(b));const x=f.delta;if(x!=null&&(p+=x),f.type==="message"||f.content){const y=f.content||"";p+=y}if(f.message&&(p+=f.message.content||""),f.tool_calls,f.finished){p&&(yield{content:[{type:"text",text:p}]});break}p&&(yield{content:[{type:"text",text:p}]})}p&&(yield{content:[{type:"text",text:p}]})}}}const Me=new Map;function Qt(e,r){return{async list(){const t=[];let i,o=0;do{const l=await e.listChats({limit:50,cursor:i}),s=l.items||[];Array.isArray(s)&&s.length>0&&t.push(...s),i=l.nextCursor||void 0,o++}while(i&&o<50);return{threads:t.map(l=>{const s=l.id;return!s||l.deletedAt?null:{status:"regular",remoteId:s,title:l.title||"New Chat",createdAt:l.createdAt?new Date(l.createdAt):new Date,updatedAt:l.updatedAt?new Date(l.updatedAt):new Date}}).filter(l=>l!==null)}},async initialize(t){return{remoteId:Me.get(t)||t,externalId:void 0}},async rename(t,n){await e.updateChat(t,{title:n})},async archive(t){},async unarchive(t){},async delete(t){await e.deleteChat(t)},async generateTitle(t,n){return new ReadableStream},async fetch(t){try{const n=await e.getChat(t);return{status:"regular",remoteId:n.id||t,title:n.title||"Chat",createdAt:n.createdAt?new Date(n.createdAt):new Date,updatedAt:n.updatedAt?new Date(n.updatedAt):new Date}}catch{return{status:"regular",remoteId:t,createdAt:new Date,updatedAt:new Date}}},updateRemoteId(t,n){Me.set(t,n),r?.(t,n)}}}function Xt({children:e,baseUrl:r,sessionToken:t,isProxyMode:n=!1,mode:i="multiChat",modelId:o,onModelChange:a,ephemeral:l=!1,systemPrompt:s,initialThreadId:c,onError:h,onChatCreated:u,onThreadIdUpdate:p,onChatsLoaded:g}){const f=w.useMemo(()=>new Ve(r,t||void 0,n),[r,t,n]),[b,x]=w.useState(o||null);w.useEffect(()=>{o&&x(o)},[o]);const k=w.useCallback(v=>{u?.(v)},[u]),y=w.useCallback((v,A)=>{p?.(v,A)},[p]),C=w.useMemo(()=>Jt(f,{modelId:b||void 0,systemPrompt:s,ephemeral:l,onChatCreated:k}),[f,b,s,l,k]),j=T.useLocalRuntime(C);return i==="singleChat"?d.jsx(T.AssistantRuntimeProvider,{runtime:j,children:e}):d.jsx(Yt,{client:f,modelAdapter:C,initialThreadId:c,onChatsLoaded:g,onThreadIdUpdate:y,onError:h,children:e})}function Yt({client:e,modelAdapter:r,initialThreadId:t,onChatsLoaded:n,onThreadIdUpdate:i,onError:o,children:a}){const l=w.useMemo(()=>Qt(e,(u,p)=>{i?.(u,p)}),[e,i]),s=w.useMemo(()=>({...l,async list(){const u=await l.list();return n?.(),u}}),[l,n]);w.useEffect(()=>{window.__cuadraThreadListAdapter=s,window.__cuadraThreadListRuntime=null},[s]);const c=w.useCallback(()=>T.useLocalRuntime(r),[r]),h=T.unstable_useRemoteThreadListRuntime({adapter:s,runtimeHook:c});return w.useEffect(()=>{window.__cuadraThreadListRuntime=h},[h]),d.jsx(T.AssistantRuntimeProvider,{runtime:h,children:a})}function Pe(e,r){const t=String(e);if(typeof r!="string")throw new TypeError("Expected character");let n=0,i=t.indexOf(r);for(;i!==-1;)n++,i=t.indexOf(r,i+r.length);return n}const Q=se(/[A-Za-z]/),ye=se(/[\dA-Za-z]/);function er(e){return e!==null&&(e<32||e===127)}function K(e){return e!==null&&e<-2}function N(e){return e!==null&&(e<0||e===32)}function E(e){return e===-2||e===-1||e===32}const oe=se(/\p{P}|\p{S}/u),B=se(/\s/);function se(e){return r;function r(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function tr(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}const le=(function(e){if(e==null)return ir;if(typeof e=="function")return ue(e);if(typeof e=="object")return Array.isArray(e)?rr(e):nr(e);if(typeof e=="string")return ar(e);throw new Error("Expected function, string, or object as test")});function rr(e){const r=[];let t=-1;for(;++t<e.length;)r[t]=le(e[t]);return ue(n);function n(...i){let o=-1;for(;++o<r.length;)if(r[o].apply(this,i))return!0;return!1}}function nr(e){const r=e;return ue(t);function t(n){const i=n;let o;for(o in e)if(i[o]!==r[o])return!1;return!0}}function ar(e){return ue(r);function r(t){return t&&t.type===e}}function ue(e){return r;function r(t,n,i){return!!(or(t)&&e.call(this,t,typeof n=="number"?n:void 0,i||void 0))}}function ir(){return!0}function or(e){return e!==null&&typeof e=="object"&&"type"in e}const Ge=[],sr=!0,ke=!1,lr="skip";function Ze(e,r,t,n){let i;typeof r=="function"&&typeof t!="function"?(n=t,t=r):i=r;const o=le(i),a=n?-1:1;l(e,void 0,[])();function l(s,c,h){const u=s&&typeof s=="object"?s:{};if(typeof u.type=="string"){const g=typeof u.tagName=="string"?u.tagName:typeof u.name=="string"?u.name:void 0;Object.defineProperty(p,"name",{value:"node ("+(s.type+(g?"<"+g+">":""))+")"})}return p;function p(){let g=Ge,f,b,x;if((!r||o(s,c,h[h.length-1]||void 0))&&(g=ur(t(s,h)),g[0]===ke))return g;if("children"in s&&s.children){const k=s;if(k.children&&g[0]!==lr)for(b=(n?k.children.length:-1)+a,x=h.concat(k);b>-1&&b<k.children.length;){const y=k.children[b];if(f=l(y,b,x)(),f[0]===ke)return f;b=typeof f[1]=="number"?f[1]:b+a}}return g}}}function ur(e){return Array.isArray(e)?e:typeof e=="number"?[sr,e]:e==null?Ge:[e]}function cr(e,r,t){const i=le((t||{}).ignore||[]),o=dr(r);let a=-1;for(;++a<o.length;)Ze(e,"text",l);function l(c,h){let u=-1,p;for(;++u<h.length;){const g=h[u],f=p?p.children:void 0;if(i(g,f?f.indexOf(g):void 0,p))return;p=g}if(p)return s(c,h)}function s(c,h){const u=h[h.length-1],p=o[a][0],g=o[a][1];let f=0;const x=u.children.indexOf(c);let k=!1,y=[];p.lastIndex=0;let C=p.exec(c.value);for(;C;){const j=C.index,v={index:C.index,input:C.input,stack:[...h,c]};let A=g(...C,v);if(typeof A=="string"&&(A=A.length>0?{type:"text",value:A}:void 0),A===!1?p.lastIndex=j+1:(f!==j&&y.push({type:"text",value:c.value.slice(f,j)}),Array.isArray(A)?y.push(...A):A&&y.push(A),f=j+C[0].length,k=!0),!p.global)break;C=p.exec(c.value)}return k?(f<c.value.length&&y.push({type:"text",value:c.value.slice(f)}),u.children.splice(x,1,...y)):y=[c],x+y.length}}function dr(e){const r=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const t=!e[0]||Array.isArray(e[0])?e:[e];let n=-1;for(;++n<t.length;){const i=t[n];r.push([fr(i[0]),hr(i[1])])}return r}function fr(e){return typeof e=="string"?new RegExp(tr(e),"g"):e}function hr(e){return typeof e=="function"?e:function(){return e}}const fe="phrasing",he=["autolink","link","image","label"];function mr(){return{transforms:[yr],enter:{literalAutolink:gr,literalAutolinkEmail:me,literalAutolinkHttp:me,literalAutolinkWww:me},exit:{literalAutolink:wr,literalAutolinkEmail:kr,literalAutolinkHttp:xr,literalAutolinkWww:br}}}function pr(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:fe,notInConstruct:he},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:fe,notInConstruct:he},{character:":",before:"[ps]",after:"\\/",inConstruct:fe,notInConstruct:he}]}}function gr(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function me(e){this.config.enter.autolinkProtocol.call(this,e)}function xr(e){this.config.exit.autolinkProtocol.call(this,e)}function br(e){this.config.exit.data.call(this,e);const r=this.stack[this.stack.length-1];r.type,r.url="http://"+this.sliceSerialize(e)}function kr(e){this.config.exit.autolinkEmail.call(this,e)}function wr(e){this.exit(e)}function yr(e){cr(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,Cr],[/(?<=^|\s|\p{P}|\p{S})([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/gu,vr]],{ignore:["link","linkReference"]})}function Cr(e,r,t,n,i){let o="";if(!Je(i)||(/^w/i.test(r)&&(t=r+t,r="",o="http://"),!jr(t)))return!1;const a=Tr(t+n);if(!a[0])return!1;const l={type:"link",title:null,url:o+r+a[0],children:[{type:"text",value:r+a[0]}]};return a[1]?[l,{type:"text",value:a[1]}]:l}function vr(e,r,t,n){return!Je(n,!0)||/[-\d_]$/.test(t)?!1:{type:"link",title:null,url:"mailto:"+r+"@"+t,children:[{type:"text",value:r+"@"+t}]}}function jr(e){const r=e.split(".");return!(r.length<2||r[r.length-1]&&(/_/.test(r[r.length-1])||!/[a-zA-Z\d]/.test(r[r.length-1]))||r[r.length-2]&&(/_/.test(r[r.length-2])||!/[a-zA-Z\d]/.test(r[r.length-2])))}function Tr(e){const r=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!r)return[e,void 0];e=e.slice(0,r.index);let t=r[0],n=t.indexOf(")");const i=Pe(e,"(");let o=Pe(e,")");for(;n!==-1&&i>o;)e+=t.slice(0,n+1),t=t.slice(n+1),n=t.indexOf(")"),o++;return[e,t]}function Je(e,r){const t=e.input.charCodeAt(e.index-1);return(e.index===0||B(t)||oe(t))&&(!r||t!==47)}function Y(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}Qe.peek=Er;function Ar(){this.buffer()}function Sr(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function Ir(){this.buffer()}function Nr(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function Lr(e){const r=this.resume(),t=this.stack[this.stack.length-1];t.type,t.identifier=Y(this.sliceSerialize(e)).toLowerCase(),t.label=r}function Mr(e){this.exit(e)}function Pr(e){const r=this.resume(),t=this.stack[this.stack.length-1];t.type,t.identifier=Y(this.sliceSerialize(e)).toLowerCase(),t.label=r}function Dr(e){this.exit(e)}function Er(){return"["}function Qe(e,r,t,n){const i=t.createTracker(n);let o=i.move("[^");const a=t.enter("footnoteReference"),l=t.enter("reference");return o+=i.move(t.safe(t.associationId(e),{after:"]",before:o})),l(),a(),o+=i.move("]"),o}function Rr(){return{enter:{gfmFootnoteCallString:Ar,gfmFootnoteCall:Sr,gfmFootnoteDefinitionLabelString:Ir,gfmFootnoteDefinition:Nr},exit:{gfmFootnoteCallString:Lr,gfmFootnoteCall:Mr,gfmFootnoteDefinitionLabelString:Pr,gfmFootnoteDefinition:Dr}}}function _r(e){let r=!1;return e&&e.firstLineBlank&&(r=!0),{handlers:{footnoteDefinition:t,footnoteReference:Qe},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function t(n,i,o,a){const l=o.createTracker(a);let s=l.move("[^");const c=o.enter("footnoteDefinition"),h=o.enter("label");return s+=l.move(o.safe(o.associationId(n),{before:s,after:"]"})),h(),s+=l.move("]:"),n.children&&n.children.length>0&&(l.shift(4),s+=l.move((r?`
4
+ `:" ")+o.indentLines(o.containerFlow(n,l.current()),r?Xe:Fr))),c(),s}}function Fr(e,r,t){return r===0?e:Xe(e,r,t)}function Xe(e,r,t){return(t?"":" ")+e}const zr=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];Ye.peek=Wr;function $r(){return{canContainEols:["delete"],enter:{strikethrough:Ur},exit:{strikethrough:Br}}}function Or(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:zr}],handlers:{delete:Ye}}}function Ur(e){this.enter({type:"delete",children:[]},e)}function Br(e){this.exit(e)}function Ye(e,r,t,n){const i=t.createTracker(n),o=t.enter("strikethrough");let a=i.move("~~");return a+=t.containerPhrasing(e,{...i.current(),before:a,after:"~"}),a+=i.move("~~"),o(),a}function Wr(){return"~"}function Hr(e){return e.length}function qr(e,r){const t=r||{},n=(t.align||[]).concat(),i=t.stringLength||Hr,o=[],a=[],l=[],s=[];let c=0,h=-1;for(;++h<e.length;){const b=[],x=[];let k=-1;for(e[h].length>c&&(c=e[h].length);++k<e[h].length;){const y=Kr(e[h][k]);if(t.alignDelimiters!==!1){const C=i(y);x[k]=C,(s[k]===void 0||C>s[k])&&(s[k]=C)}b.push(y)}a[h]=b,l[h]=x}let u=-1;if(typeof n=="object"&&"length"in n)for(;++u<c;)o[u]=De(n[u]);else{const b=De(n);for(;++u<c;)o[u]=b}u=-1;const p=[],g=[];for(;++u<c;){const b=o[u];let x="",k="";b===99?(x=":",k=":"):b===108?x=":":b===114&&(k=":");let y=t.alignDelimiters===!1?1:Math.max(1,s[u]-x.length-k.length);const C=x+"-".repeat(y)+k;t.alignDelimiters!==!1&&(y=x.length+y+k.length,y>s[u]&&(s[u]=y),g[u]=y),p[u]=C}a.splice(1,0,p),l.splice(1,0,g),h=-1;const f=[];for(;++h<a.length;){const b=a[h],x=l[h];u=-1;const k=[];for(;++u<c;){const y=b[u]||"";let C="",j="";if(t.alignDelimiters!==!1){const v=s[u]-(x[u]||0),A=o[u];A===114?C=" ".repeat(v):A===99?v%2?(C=" ".repeat(v/2+.5),j=" ".repeat(v/2-.5)):(C=" ".repeat(v/2),j=C):j=" ".repeat(v)}t.delimiterStart!==!1&&!u&&k.push("|"),t.padding!==!1&&!(t.alignDelimiters===!1&&y==="")&&(t.delimiterStart!==!1||u)&&k.push(" "),t.alignDelimiters!==!1&&k.push(C),k.push(y),t.alignDelimiters!==!1&&k.push(j),t.padding!==!1&&k.push(" "),(t.delimiterEnd!==!1||u!==c-1)&&k.push("|")}f.push(t.delimiterEnd===!1?k.join("").replace(/ +$/,""):k.join(""))}return f.join(`
5
+ `)}function Kr(e){return e==null?"":String(e)}function De(e){const r=typeof e=="string"?e.codePointAt(0):0;return r===67||r===99?99:r===76||r===108?108:r===82||r===114?114:0}function Vr(e,r,t,n){const i=t.enter("blockquote"),o=t.createTracker(n);o.move("> "),o.shift(2);const a=t.indentLines(t.containerFlow(e,o.current()),Gr);return i(),a}function Gr(e,r,t){return">"+(t?"":" ")+e}function Zr(e,r){return Ee(e,r.inConstruct,!0)&&!Ee(e,r.notInConstruct,!1)}function Ee(e,r,t){if(typeof r=="string"&&(r=[r]),!r||r.length===0)return t;let n=-1;for(;++n<r.length;)if(e.includes(r[n]))return!0;return!1}function Re(e,r,t,n){let i=-1;for(;++i<t.unsafe.length;)if(t.unsafe[i].character===`
6
+ `&&Zr(t.stack,t.unsafe[i]))return/[ \t]/.test(n.before)?"":" ";return`\\
7
+ `}function Jr(e,r){const t=String(e);let n=t.indexOf(r),i=n,o=0,a=0;if(typeof r!="string")throw new TypeError("Expected substring");for(;n!==-1;)n===i?++o>a&&(a=o):o=1,i=n+r.length,n=t.indexOf(r,i);return a}function Qr(e,r){return!!(r.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function Xr(e){const r=e.options.fence||"`";if(r!=="`"&&r!=="~")throw new Error("Cannot serialize code with `"+r+"` for `options.fence`, expected `` ` `` or `~`");return r}function Yr(e,r,t,n){const i=Xr(t),o=e.value||"",a=i==="`"?"GraveAccent":"Tilde";if(Qr(e,t)){const u=t.enter("codeIndented"),p=t.indentLines(o,en);return u(),p}const l=t.createTracker(n),s=i.repeat(Math.max(Jr(o,i)+1,3)),c=t.enter("codeFenced");let h=l.move(s);if(e.lang){const u=t.enter(`codeFencedLang${a}`);h+=l.move(t.safe(e.lang,{before:h,after:" ",encode:["`"],...l.current()})),u()}if(e.lang&&e.meta){const u=t.enter(`codeFencedMeta${a}`);h+=l.move(" "),h+=l.move(t.safe(e.meta,{before:h,after:`
8
8
  `,encode:["`"],...l.current()})),u()}return h+=l.move(`
9
9
  `),o&&(h+=l.move(o+`
10
10
  `)),h+=l.move(s),c(),h}function en(e,r,t){return(t?"":" ")+e}function Ce(e){const r=e.options.quote||'"';if(r!=='"'&&r!=="'")throw new Error("Cannot serialize title with `"+r+"` for `options.quote`, expected `\"`, or `'`");return r}function tn(e,r,t,n){const i=Ce(t),o=i==='"'?"Quote":"Apostrophe",a=t.enter("definition");let l=t.enter("label");const s=t.createTracker(n);let c=s.move("[");return c+=s.move(t.safe(t.associationId(e),{before:c,after:"]",...s.current()})),c+=s.move("]: "),l(),!e.url||/[\0- \u007F]/.test(e.url)?(l=t.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(t.safe(e.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=t.enter("destinationRaw"),c+=s.move(t.safe(e.url,{before:c,after:e.title?" ":`
11
- `,...s.current()}))),l(),e.title&&(l=t.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(t.safe(e.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),a(),c}function rn(e){const r=e.options.emphasis||"*";if(r!=="*"&&r!=="_")throw new Error("Cannot serialize emphasis with `"+r+"` for `options.emphasis`, expected `*`, or `_`");return r}function Y(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ae(e){if(e===null||N(e)||B(e))return 1;if(oe(e))return 2}function ie(e,r,t){const n=ae(e),i=ae(r);return n===void 0?i===void 0?t==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:n===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}et.peek=nn;function et(e,r,t,n){const i=rn(t),o=t.enter("emphasis"),a=t.createTracker(n),l=a.move(i);let s=a.move(t.containerPhrasing(e,{after:i,before:l,...a.current()}));const c=s.charCodeAt(0),h=ie(n.before.charCodeAt(n.before.length-1),c,i);h.inside&&(s=Y(c)+s.slice(1));const u=s.charCodeAt(s.length-1),p=ie(n.after.charCodeAt(0),u,i);p.inside&&(s=s.slice(0,-1)+Y(u));const g=a.move(i);return o(),t.attentionEncodeSurroundingInfo={after:p.outside,before:h.outside},l+s+g}function nn(e,r,t){return t.options.emphasis||"*"}function an(e,r,t,n){let i,o,a;typeof r=="function"&&typeof t!="function"?(o=void 0,a=r,i=t):(o=r,a=t,i=n),Ge(e,o,l,i);function l(s,c){const h=c[c.length-1],u=h?h.children.indexOf(s):void 0;return a(s,u,h)}}const on={};function tt(e,r){const t=on,n=typeof t.includeImageAlt=="boolean"?t.includeImageAlt:!0,i=typeof t.includeHtml=="boolean"?t.includeHtml:!0;return rt(e,n,i)}function rt(e,r,t){if(sn(e)){if("value"in e)return e.type==="html"&&!t?"":e.value;if(r&&"alt"in e&&e.alt)return e.alt;if("children"in e)return _e(e.children,r,t)}return Array.isArray(e)?_e(e,r,t):""}function _e(e,r,t){const n=[];let i=-1;for(;++i<e.length;)n[i]=rt(e[i],r,t);return n.join("")}function sn(e){return!!(e&&typeof e=="object")}function ln(e,r){let t=!1;return an(e,function(n){if("value"in n&&/\r?\n|\r/.test(n.value)||n.type==="break")return t=!0,ke}),!!((!e.depth||e.depth<3)&&tt(e)&&(r.options.setext||t))}function un(e,r,t,n){const i=Math.max(Math.min(6,e.depth||1),1),o=t.createTracker(n);if(ln(e,t)){const h=t.enter("headingSetext"),u=t.enter("phrasing"),p=t.containerPhrasing(e,{...o.current(),before:`
11
+ `,...s.current()}))),l(),e.title&&(l=t.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(t.safe(e.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),a(),c}function rn(e){const r=e.options.emphasis||"*";if(r!=="*"&&r!=="_")throw new Error("Cannot serialize emphasis with `"+r+"` for `options.emphasis`, expected `*`, or `_`");return r}function X(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ae(e){if(e===null||N(e)||B(e))return 1;if(oe(e))return 2}function ie(e,r,t){const n=ae(e),i=ae(r);return n===void 0?i===void 0?t==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:n===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}et.peek=nn;function et(e,r,t,n){const i=rn(t),o=t.enter("emphasis"),a=t.createTracker(n),l=a.move(i);let s=a.move(t.containerPhrasing(e,{after:i,before:l,...a.current()}));const c=s.charCodeAt(0),h=ie(n.before.charCodeAt(n.before.length-1),c,i);h.inside&&(s=X(c)+s.slice(1));const u=s.charCodeAt(s.length-1),p=ie(n.after.charCodeAt(0),u,i);p.inside&&(s=s.slice(0,-1)+X(u));const g=a.move(i);return o(),t.attentionEncodeSurroundingInfo={after:p.outside,before:h.outside},l+s+g}function nn(e,r,t){return t.options.emphasis||"*"}function an(e,r,t,n){let i,o,a;typeof r=="function"&&typeof t!="function"?(o=void 0,a=r,i=t):(o=r,a=t,i=n),Ze(e,o,l,i);function l(s,c){const h=c[c.length-1],u=h?h.children.indexOf(s):void 0;return a(s,u,h)}}const on={};function tt(e,r){const t=on,n=typeof t.includeImageAlt=="boolean"?t.includeImageAlt:!0,i=typeof t.includeHtml=="boolean"?t.includeHtml:!0;return rt(e,n,i)}function rt(e,r,t){if(sn(e)){if("value"in e)return e.type==="html"&&!t?"":e.value;if(r&&"alt"in e&&e.alt)return e.alt;if("children"in e)return _e(e.children,r,t)}return Array.isArray(e)?_e(e,r,t):""}function _e(e,r,t){const n=[];let i=-1;for(;++i<e.length;)n[i]=rt(e[i],r,t);return n.join("")}function sn(e){return!!(e&&typeof e=="object")}function ln(e,r){let t=!1;return an(e,function(n){if("value"in n&&/\r?\n|\r/.test(n.value)||n.type==="break")return t=!0,ke}),!!((!e.depth||e.depth<3)&&tt(e)&&(r.options.setext||t))}function un(e,r,t,n){const i=Math.max(Math.min(6,e.depth||1),1),o=t.createTracker(n);if(ln(e,t)){const h=t.enter("headingSetext"),u=t.enter("phrasing"),p=t.containerPhrasing(e,{...o.current(),before:`
12
12
  `,after:`
13
13
  `});return u(),h(),p+`
14
14
  `+(i===1?"=":"-").repeat(p.length-(Math.max(p.lastIndexOf("\r"),p.lastIndexOf(`
15
15
  `))+1))}const a="#".repeat(i),l=t.enter("headingAtx"),s=t.enter("phrasing");o.move(a+" ");let c=t.containerPhrasing(e,{before:"# ",after:`
16
- `,...o.current()});return/^[\t ]/.test(c)&&(c=Y(c.charCodeAt(0))+c.slice(1)),c=c?a+" "+c:a,t.options.closeAtx&&(c+=" "+a),s(),l(),c}nt.peek=cn;function nt(e){return e.value||""}function cn(){return"<"}at.peek=dn;function at(e,r,t,n){const i=Ce(t),o=i==='"'?"Quote":"Apostrophe",a=t.enter("image");let l=t.enter("label");const s=t.createTracker(n);let c=s.move("![");return c+=s.move(t.safe(e.alt,{before:c,after:"]",...s.current()})),c+=s.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=t.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(t.safe(e.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=t.enter("destinationRaw"),c+=s.move(t.safe(e.url,{before:c,after:e.title?" ":")",...s.current()}))),l(),e.title&&(l=t.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(t.safe(e.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),c+=s.move(")"),a(),c}function dn(){return"!"}it.peek=fn;function it(e,r,t,n){const i=e.referenceType,o=t.enter("imageReference");let a=t.enter("label");const l=t.createTracker(n);let s=l.move("![");const c=t.safe(e.alt,{before:s,after:"]",...l.current()});s+=l.move(c+"]["),a();const h=t.stack;t.stack=[],a=t.enter("reference");const u=t.safe(t.associationId(e),{before:s,after:"]",...l.current()});return a(),t.stack=h,o(),i==="full"||!c||c!==u?s+=l.move(u+"]"):i==="shortcut"?s=s.slice(0,-1):s+=l.move("]"),s}function fn(){return"!"}ot.peek=hn;function ot(e,r,t){let n=e.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(n);)i+="`";for(/[^ \r\n]/.test(n)&&(/^[ \r\n]/.test(n)&&/[ \r\n]$/.test(n)||/^`|`$/.test(n))&&(n=" "+n+" ");++o<t.unsafe.length;){const a=t.unsafe[o],l=t.compilePattern(a);let s;if(a.atBreak)for(;s=l.exec(n);){let c=s.index;n.charCodeAt(c)===10&&n.charCodeAt(c-1)===13&&c--,n=n.slice(0,c)+" "+n.slice(s.index+1)}}return i+n+i}function hn(){return"`"}function st(e,r){const t=tt(e);return!!(!r.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(t===e.url||"mailto:"+t===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}lt.peek=mn;function lt(e,r,t,n){const i=Ce(t),o=i==='"'?"Quote":"Apostrophe",a=t.createTracker(n);let l,s;if(st(e,t)){const h=t.stack;t.stack=[],l=t.enter("autolink");let u=a.move("<");return u+=a.move(t.containerPhrasing(e,{before:u,after:">",...a.current()})),u+=a.move(">"),l(),t.stack=h,u}l=t.enter("link"),s=t.enter("label");let c=a.move("[");return c+=a.move(t.containerPhrasing(e,{before:c,after:"](",...a.current()})),c+=a.move("]("),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=t.enter("destinationLiteral"),c+=a.move("<"),c+=a.move(t.safe(e.url,{before:c,after:">",...a.current()})),c+=a.move(">")):(s=t.enter("destinationRaw"),c+=a.move(t.safe(e.url,{before:c,after:e.title?" ":")",...a.current()}))),s(),e.title&&(s=t.enter(`title${o}`),c+=a.move(" "+i),c+=a.move(t.safe(e.title,{before:c,after:i,...a.current()})),c+=a.move(i),s()),c+=a.move(")"),l(),c}function mn(e,r,t){return st(e,t)?"<":"["}ut.peek=pn;function ut(e,r,t,n){const i=e.referenceType,o=t.enter("linkReference");let a=t.enter("label");const l=t.createTracker(n);let s=l.move("[");const c=t.containerPhrasing(e,{before:s,after:"]",...l.current()});s+=l.move(c+"]["),a();const h=t.stack;t.stack=[],a=t.enter("reference");const u=t.safe(t.associationId(e),{before:s,after:"]",...l.current()});return a(),t.stack=h,o(),i==="full"||!c||c!==u?s+=l.move(u+"]"):i==="shortcut"?s=s.slice(0,-1):s+=l.move("]"),s}function pn(){return"["}function ve(e){const r=e.options.bullet||"*";if(r!=="*"&&r!=="+"&&r!=="-")throw new Error("Cannot serialize items with `"+r+"` for `options.bullet`, expected `*`, `+`, or `-`");return r}function gn(e){const r=ve(e),t=e.options.bulletOther;if(!t)return r==="*"?"-":"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(t===r)throw new Error("Expected `bullet` (`"+r+"`) and `bulletOther` (`"+t+"`) to be different");return t}function xn(e){const r=e.options.bulletOrdered||".";if(r!=="."&&r!==")")throw new Error("Cannot serialize items with `"+r+"` for `options.bulletOrdered`, expected `.` or `)`");return r}function ct(e){const r=e.options.rule||"*";if(r!=="*"&&r!=="-"&&r!=="_")throw new Error("Cannot serialize rules with `"+r+"` for `options.rule`, expected `*`, `-`, or `_`");return r}function bn(e,r,t,n){const i=t.enter("list"),o=t.bulletCurrent;let a=e.ordered?xn(t):ve(t);const l=e.ordered?a==="."?")":".":gn(t);let s=r&&t.bulletLastUsed?a===t.bulletLastUsed:!1;if(!e.ordered){const h=e.children?e.children[0]:void 0;if((a==="*"||a==="-")&&h&&(!h.children||!h.children[0])&&t.stack[t.stack.length-1]==="list"&&t.stack[t.stack.length-2]==="listItem"&&t.stack[t.stack.length-3]==="list"&&t.stack[t.stack.length-4]==="listItem"&&t.indexStack[t.indexStack.length-1]===0&&t.indexStack[t.indexStack.length-2]===0&&t.indexStack[t.indexStack.length-3]===0&&(s=!0),ct(t)===a&&h){let u=-1;for(;++u<e.children.length;){const p=e.children[u];if(p&&p.type==="listItem"&&p.children&&p.children[0]&&p.children[0].type==="thematicBreak"){s=!0;break}}}}s&&(a=l),t.bulletCurrent=a;const c=t.containerFlow(e,n);return t.bulletLastUsed=a,t.bulletCurrent=o,i(),c}function kn(e){const r=e.options.listItemIndent||"one";if(r!=="tab"&&r!=="one"&&r!=="mixed")throw new Error("Cannot serialize items with `"+r+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return r}function wn(e,r,t,n){const i=kn(t);let o=t.bulletCurrent||ve(t);r&&r.type==="list"&&r.ordered&&(o=(typeof r.start=="number"&&r.start>-1?r.start:1)+(t.options.incrementListMarker===!1?0:r.children.indexOf(e))+o);let a=o.length+1;(i==="tab"||i==="mixed"&&(r&&r.type==="list"&&r.spread||e.spread))&&(a=Math.ceil(a/4)*4);const l=t.createTracker(n);l.move(o+" ".repeat(a-o.length)),l.shift(a);const s=t.enter("listItem"),c=t.indentLines(t.containerFlow(e,l.current()),h);return s(),c;function h(u,p,g){return p?(g?"":" ".repeat(a))+u:(g?o:o+" ".repeat(a-o.length))+u}}function yn(e,r,t,n){const i=t.enter("paragraph"),o=t.enter("phrasing"),a=t.containerPhrasing(e,n);return o(),i(),a}const Cn=le(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function vn(e,r,t,n){return(e.children.some(function(a){return Cn(a)})?t.containerPhrasing:t.containerFlow).call(t,e,n)}function jn(e){const r=e.options.strong||"*";if(r!=="*"&&r!=="_")throw new Error("Cannot serialize strong with `"+r+"` for `options.strong`, expected `*`, or `_`");return r}dt.peek=Tn;function dt(e,r,t,n){const i=jn(t),o=t.enter("strong"),a=t.createTracker(n),l=a.move(i+i);let s=a.move(t.containerPhrasing(e,{after:i,before:l,...a.current()}));const c=s.charCodeAt(0),h=ie(n.before.charCodeAt(n.before.length-1),c,i);h.inside&&(s=Y(c)+s.slice(1));const u=s.charCodeAt(s.length-1),p=ie(n.after.charCodeAt(0),u,i);p.inside&&(s=s.slice(0,-1)+Y(u));const g=a.move(i+i);return o(),t.attentionEncodeSurroundingInfo={after:p.outside,before:h.outside},l+s+g}function Tn(e,r,t){return t.options.strong||"*"}function In(e,r,t,n){return t.safe(e.value,n)}function An(e){const r=e.options.ruleRepetition||3;if(r<3)throw new Error("Cannot serialize rules with repetition `"+r+"` for `options.ruleRepetition`, expected `3` or more");return r}function Sn(e,r,t){const n=(ct(t)+(t.options.ruleSpaces?" ":"")).repeat(An(t));return t.options.ruleSpaces?n.slice(0,-1):n}const ft={blockquote:Vr,break:Re,code:Yr,definition:tn,emphasis:et,hardBreak:Re,heading:un,html:nt,image:at,imageReference:it,inlineCode:ot,link:lt,linkReference:ut,list:bn,listItem:wn,paragraph:yn,root:vn,strong:dt,text:In,thematicBreak:Sn};function Nn(){return{enter:{table:Ln,tableData:Fe,tableHeader:Fe,tableRow:Pn},exit:{codeText:Dn,table:Mn,tableData:pe,tableHeader:pe,tableRow:pe}}}function Ln(e){const r=e._align;this.enter({type:"table",align:r.map(function(t){return t==="none"?null:t}),children:[]},e),this.data.inTable=!0}function Mn(e){this.exit(e),this.data.inTable=void 0}function Pn(e){this.enter({type:"tableRow",children:[]},e)}function pe(e){this.exit(e)}function Fe(e){this.enter({type:"tableCell",children:[]},e)}function Dn(e){let r=this.resume();this.data.inTable&&(r=r.replace(/\\([\\|])/g,En));const t=this.stack[this.stack.length-1];t.type,t.value=r,this.exit(e)}function En(e,r){return r==="|"?r:e}function Rn(e){const r=e||{},t=r.tableCellPadding,n=r.tablePipeAlign,i=r.stringLength,o=t?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
16
+ `,...o.current()});return/^[\t ]/.test(c)&&(c=X(c.charCodeAt(0))+c.slice(1)),c=c?a+" "+c:a,t.options.closeAtx&&(c+=" "+a),s(),l(),c}nt.peek=cn;function nt(e){return e.value||""}function cn(){return"<"}at.peek=dn;function at(e,r,t,n){const i=Ce(t),o=i==='"'?"Quote":"Apostrophe",a=t.enter("image");let l=t.enter("label");const s=t.createTracker(n);let c=s.move("![");return c+=s.move(t.safe(e.alt,{before:c,after:"]",...s.current()})),c+=s.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=t.enter("destinationLiteral"),c+=s.move("<"),c+=s.move(t.safe(e.url,{before:c,after:">",...s.current()})),c+=s.move(">")):(l=t.enter("destinationRaw"),c+=s.move(t.safe(e.url,{before:c,after:e.title?" ":")",...s.current()}))),l(),e.title&&(l=t.enter(`title${o}`),c+=s.move(" "+i),c+=s.move(t.safe(e.title,{before:c,after:i,...s.current()})),c+=s.move(i),l()),c+=s.move(")"),a(),c}function dn(){return"!"}it.peek=fn;function it(e,r,t,n){const i=e.referenceType,o=t.enter("imageReference");let a=t.enter("label");const l=t.createTracker(n);let s=l.move("![");const c=t.safe(e.alt,{before:s,after:"]",...l.current()});s+=l.move(c+"]["),a();const h=t.stack;t.stack=[],a=t.enter("reference");const u=t.safe(t.associationId(e),{before:s,after:"]",...l.current()});return a(),t.stack=h,o(),i==="full"||!c||c!==u?s+=l.move(u+"]"):i==="shortcut"?s=s.slice(0,-1):s+=l.move("]"),s}function fn(){return"!"}ot.peek=hn;function ot(e,r,t){let n=e.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(n);)i+="`";for(/[^ \r\n]/.test(n)&&(/^[ \r\n]/.test(n)&&/[ \r\n]$/.test(n)||/^`|`$/.test(n))&&(n=" "+n+" ");++o<t.unsafe.length;){const a=t.unsafe[o],l=t.compilePattern(a);let s;if(a.atBreak)for(;s=l.exec(n);){let c=s.index;n.charCodeAt(c)===10&&n.charCodeAt(c-1)===13&&c--,n=n.slice(0,c)+" "+n.slice(s.index+1)}}return i+n+i}function hn(){return"`"}function st(e,r){const t=tt(e);return!!(!r.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(t===e.url||"mailto:"+t===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}lt.peek=mn;function lt(e,r,t,n){const i=Ce(t),o=i==='"'?"Quote":"Apostrophe",a=t.createTracker(n);let l,s;if(st(e,t)){const h=t.stack;t.stack=[],l=t.enter("autolink");let u=a.move("<");return u+=a.move(t.containerPhrasing(e,{before:u,after:">",...a.current()})),u+=a.move(">"),l(),t.stack=h,u}l=t.enter("link"),s=t.enter("label");let c=a.move("[");return c+=a.move(t.containerPhrasing(e,{before:c,after:"](",...a.current()})),c+=a.move("]("),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=t.enter("destinationLiteral"),c+=a.move("<"),c+=a.move(t.safe(e.url,{before:c,after:">",...a.current()})),c+=a.move(">")):(s=t.enter("destinationRaw"),c+=a.move(t.safe(e.url,{before:c,after:e.title?" ":")",...a.current()}))),s(),e.title&&(s=t.enter(`title${o}`),c+=a.move(" "+i),c+=a.move(t.safe(e.title,{before:c,after:i,...a.current()})),c+=a.move(i),s()),c+=a.move(")"),l(),c}function mn(e,r,t){return st(e,t)?"<":"["}ut.peek=pn;function ut(e,r,t,n){const i=e.referenceType,o=t.enter("linkReference");let a=t.enter("label");const l=t.createTracker(n);let s=l.move("[");const c=t.containerPhrasing(e,{before:s,after:"]",...l.current()});s+=l.move(c+"]["),a();const h=t.stack;t.stack=[],a=t.enter("reference");const u=t.safe(t.associationId(e),{before:s,after:"]",...l.current()});return a(),t.stack=h,o(),i==="full"||!c||c!==u?s+=l.move(u+"]"):i==="shortcut"?s=s.slice(0,-1):s+=l.move("]"),s}function pn(){return"["}function ve(e){const r=e.options.bullet||"*";if(r!=="*"&&r!=="+"&&r!=="-")throw new Error("Cannot serialize items with `"+r+"` for `options.bullet`, expected `*`, `+`, or `-`");return r}function gn(e){const r=ve(e),t=e.options.bulletOther;if(!t)return r==="*"?"-":"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(t===r)throw new Error("Expected `bullet` (`"+r+"`) and `bulletOther` (`"+t+"`) to be different");return t}function xn(e){const r=e.options.bulletOrdered||".";if(r!=="."&&r!==")")throw new Error("Cannot serialize items with `"+r+"` for `options.bulletOrdered`, expected `.` or `)`");return r}function ct(e){const r=e.options.rule||"*";if(r!=="*"&&r!=="-"&&r!=="_")throw new Error("Cannot serialize rules with `"+r+"` for `options.rule`, expected `*`, `-`, or `_`");return r}function bn(e,r,t,n){const i=t.enter("list"),o=t.bulletCurrent;let a=e.ordered?xn(t):ve(t);const l=e.ordered?a==="."?")":".":gn(t);let s=r&&t.bulletLastUsed?a===t.bulletLastUsed:!1;if(!e.ordered){const h=e.children?e.children[0]:void 0;if((a==="*"||a==="-")&&h&&(!h.children||!h.children[0])&&t.stack[t.stack.length-1]==="list"&&t.stack[t.stack.length-2]==="listItem"&&t.stack[t.stack.length-3]==="list"&&t.stack[t.stack.length-4]==="listItem"&&t.indexStack[t.indexStack.length-1]===0&&t.indexStack[t.indexStack.length-2]===0&&t.indexStack[t.indexStack.length-3]===0&&(s=!0),ct(t)===a&&h){let u=-1;for(;++u<e.children.length;){const p=e.children[u];if(p&&p.type==="listItem"&&p.children&&p.children[0]&&p.children[0].type==="thematicBreak"){s=!0;break}}}}s&&(a=l),t.bulletCurrent=a;const c=t.containerFlow(e,n);return t.bulletLastUsed=a,t.bulletCurrent=o,i(),c}function kn(e){const r=e.options.listItemIndent||"one";if(r!=="tab"&&r!=="one"&&r!=="mixed")throw new Error("Cannot serialize items with `"+r+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return r}function wn(e,r,t,n){const i=kn(t);let o=t.bulletCurrent||ve(t);r&&r.type==="list"&&r.ordered&&(o=(typeof r.start=="number"&&r.start>-1?r.start:1)+(t.options.incrementListMarker===!1?0:r.children.indexOf(e))+o);let a=o.length+1;(i==="tab"||i==="mixed"&&(r&&r.type==="list"&&r.spread||e.spread))&&(a=Math.ceil(a/4)*4);const l=t.createTracker(n);l.move(o+" ".repeat(a-o.length)),l.shift(a);const s=t.enter("listItem"),c=t.indentLines(t.containerFlow(e,l.current()),h);return s(),c;function h(u,p,g){return p?(g?"":" ".repeat(a))+u:(g?o:o+" ".repeat(a-o.length))+u}}function yn(e,r,t,n){const i=t.enter("paragraph"),o=t.enter("phrasing"),a=t.containerPhrasing(e,n);return o(),i(),a}const Cn=le(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function vn(e,r,t,n){return(e.children.some(function(a){return Cn(a)})?t.containerPhrasing:t.containerFlow).call(t,e,n)}function jn(e){const r=e.options.strong||"*";if(r!=="*"&&r!=="_")throw new Error("Cannot serialize strong with `"+r+"` for `options.strong`, expected `*`, or `_`");return r}dt.peek=Tn;function dt(e,r,t,n){const i=jn(t),o=t.enter("strong"),a=t.createTracker(n),l=a.move(i+i);let s=a.move(t.containerPhrasing(e,{after:i,before:l,...a.current()}));const c=s.charCodeAt(0),h=ie(n.before.charCodeAt(n.before.length-1),c,i);h.inside&&(s=X(c)+s.slice(1));const u=s.charCodeAt(s.length-1),p=ie(n.after.charCodeAt(0),u,i);p.inside&&(s=s.slice(0,-1)+X(u));const g=a.move(i+i);return o(),t.attentionEncodeSurroundingInfo={after:p.outside,before:h.outside},l+s+g}function Tn(e,r,t){return t.options.strong||"*"}function An(e,r,t,n){return t.safe(e.value,n)}function Sn(e){const r=e.options.ruleRepetition||3;if(r<3)throw new Error("Cannot serialize rules with repetition `"+r+"` for `options.ruleRepetition`, expected `3` or more");return r}function In(e,r,t){const n=(ct(t)+(t.options.ruleSpaces?" ":"")).repeat(Sn(t));return t.options.ruleSpaces?n.slice(0,-1):n}const ft={blockquote:Vr,break:Re,code:Yr,definition:tn,emphasis:et,hardBreak:Re,heading:un,html:nt,image:at,imageReference:it,inlineCode:ot,link:lt,linkReference:ut,list:bn,listItem:wn,paragraph:yn,root:vn,strong:dt,text:An,thematicBreak:In};function Nn(){return{enter:{table:Ln,tableData:Fe,tableHeader:Fe,tableRow:Pn},exit:{codeText:Dn,table:Mn,tableData:pe,tableHeader:pe,tableRow:pe}}}function Ln(e){const r=e._align;this.enter({type:"table",align:r.map(function(t){return t==="none"?null:t}),children:[]},e),this.data.inTable=!0}function Mn(e){this.exit(e),this.data.inTable=void 0}function Pn(e){this.enter({type:"tableRow",children:[]},e)}function pe(e){this.exit(e)}function Fe(e){this.enter({type:"tableCell",children:[]},e)}function Dn(e){let r=this.resume();this.data.inTable&&(r=r.replace(/\\([\\|])/g,En));const t=this.stack[this.stack.length-1];t.type,t.value=r,this.exit(e)}function En(e,r){return r==="|"?r:e}function Rn(e){const r=e||{},t=r.tableCellPadding,n=r.tablePipeAlign,i=r.stringLength,o=t?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
17
17
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:p,table:a,tableCell:s,tableRow:l}};function a(g,f,b,x){return c(h(g,b,x),g.align)}function l(g,f,b,x){const k=u(g,b,x),y=c([k]);return y.slice(0,y.indexOf(`
18
- `))}function s(g,f,b,x){const k=b.enter("tableCell"),y=b.enter("phrasing"),C=b.containerPhrasing(g,{...x,before:o,after:o});return y(),k(),C}function c(g,f){return qr(g,{align:f,alignDelimiters:n,padding:t,stringLength:i})}function h(g,f,b){const x=g.children;let k=-1;const y=[],C=f.enter("table");for(;++k<x.length;)y[k]=u(x[k],f,b);return C(),y}function u(g,f,b){const x=g.children;let k=-1;const y=[],C=f.enter("tableRow");for(;++k<x.length;)y[k]=s(x[k],g,f,b);return C(),y}function p(g,f,b){let x=ft.inlineCode(g,f,b);return b.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function _n(){return{exit:{taskListCheckValueChecked:ze,taskListCheckValueUnchecked:ze,paragraph:zn}}}function Fn(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:$n}}}function ze(e){const r=this.stack[this.stack.length-2];r.type,r.checked=e.type==="taskListCheckValueChecked"}function zn(e){const r=this.stack[this.stack.length-2];if(r&&r.type==="listItem"&&typeof r.checked=="boolean"){const t=this.stack[this.stack.length-1];t.type;const n=t.children[0];if(n&&n.type==="text"){const i=r.children;let o=-1,a;for(;++o<i.length;){const l=i[o];if(l.type==="paragraph"){a=l;break}}a===t&&(n.value=n.value.slice(1),n.value.length===0?t.children.shift():t.position&&n.position&&typeof n.position.start.offset=="number"&&(n.position.start.column++,n.position.start.offset++,t.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function $n(e,r,t,n){const i=e.children[0],o=typeof e.checked=="boolean"&&i&&i.type==="paragraph",a="["+(e.checked?"x":" ")+"] ",l=t.createTracker(n);o&&l.move(a);let s=ft.listItem(e,r,t,{...n,...l.current()});return o&&(s=s.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),s;function c(h){return h+a}}function On(){return[mr(),Rr(),$r(),Nn(),_n()]}function Un(e){return{extensions:[pr(),_r(e),Or(),Rn(e),Fn()]}}function ne(e,r,t,n){const i=e.length;let o=0,a;if(r<0?r=-r>i?0:i+r:r=r>i?i:r,t=t>0?t:0,n.length<1e4)a=Array.from(n),a.unshift(r,t),e.splice(...a);else for(t&&e.splice(r,t);o<n.length;)a=n.slice(o,o+1e4),a.unshift(r,0),e.splice(...a),o+=1e4,r+=1e4}const $e={}.hasOwnProperty;function Bn(e){const r={};let t=-1;for(;++t<e.length;)Wn(r,e[t]);return r}function Wn(e,r){let t;for(t in r){const i=($e.call(e,t)?e[t]:void 0)||(e[t]={}),o=r[t];let a;if(o)for(a in o){$e.call(i,a)||(i[a]=[]);const l=o[a];Hn(i[a],Array.isArray(l)?l:l?[l]:[])}}}function Hn(e,r){let t=-1;const n=[];for(;++t<r.length;)(r[t].add==="after"?e:n).push(r[t]);ne(e,0,0,n)}const qn={tokenize:Jn,partial:!0},ht={tokenize:Qn,partial:!0},mt={tokenize:Yn,partial:!0},pt={tokenize:ea,partial:!0},Kn={tokenize:ta,partial:!0},gt={name:"wwwAutolink",tokenize:Gn,previous:bt},xt={name:"protocolAutolink",tokenize:Zn,previous:kt},F={name:"emailAutolink",tokenize:Xn,previous:wt},P={};function Vn(){return{text:P}}let U=48;for(;U<123;)P[U]=F,U++,U===58?U=65:U===91&&(U=97);P[43]=F;P[45]=F;P[46]=F;P[95]=F;P[72]=[F,xt];P[104]=[F,xt];P[87]=[F,gt];P[119]=[F,gt];function Xn(e,r,t){const n=this;let i,o;return a;function a(u){return!we(u)||!wt.call(n,n.previous)||je(n.events)?t(u):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(u))}function l(u){return we(u)?(e.consume(u),l):u===64?(e.consume(u),s):t(u)}function s(u){return u===46?e.check(Kn,h,c)(u):u===45||u===95||ye(u)?(o=!0,e.consume(u),s):h(u)}function c(u){return e.consume(u),i=!0,s}function h(u){return o&&i&&Q(n.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),r(u)):t(u)}}function Gn(e,r,t){const n=this;return i;function i(a){return a!==87&&a!==119||!bt.call(n,n.previous)||je(n.events)?t(a):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(qn,e.attempt(ht,e.attempt(mt,o),t),t)(a))}function o(a){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),r(a)}}function Zn(e,r,t){const n=this;let i="",o=!1;return a;function a(u){return(u===72||u===104)&&kt.call(n,n.previous)&&!je(n.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(u),e.consume(u),l):t(u)}function l(u){if(Q(u)&&i.length<5)return i+=String.fromCodePoint(u),e.consume(u),l;if(u===58){const p=i.toLowerCase();if(p==="http"||p==="https")return e.consume(u),s}return t(u)}function s(u){return u===47?(e.consume(u),o?c:(o=!0,s)):t(u)}function c(u){return u===null||er(u)||N(u)||B(u)||oe(u)?t(u):e.attempt(ht,e.attempt(mt,h),t)(u)}function h(u){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),r(u)}}function Jn(e,r,t){let n=0;return i;function i(a){return(a===87||a===119)&&n<3?(n++,e.consume(a),i):a===46&&n===3?(e.consume(a),o):t(a)}function o(a){return a===null?t(a):r(a)}}function Qn(e,r,t){let n,i,o;return a;function a(c){return c===46||c===95?e.check(pt,s,l)(c):c===null||N(c)||B(c)||c!==45&&oe(c)?s(c):(o=!0,e.consume(c),a)}function l(c){return c===95?n=!0:(i=n,n=void 0),e.consume(c),a}function s(c){return i||n||!o?t(c):r(c)}}function Yn(e,r){let t=0,n=0;return i;function i(a){return a===40?(t++,e.consume(a),i):a===41&&n<t?o(a):a===33||a===34||a===38||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===60||a===63||a===93||a===95||a===126?e.check(pt,r,o)(a):a===null||N(a)||B(a)?r(a):(e.consume(a),i)}function o(a){return a===41&&n++,e.consume(a),i}}function ea(e,r,t){return n;function n(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),n):l===38?(e.consume(l),o):l===93?(e.consume(l),i):l===60||l===null||N(l)||B(l)?r(l):t(l)}function i(l){return l===null||l===40||l===91||N(l)||B(l)?r(l):n(l)}function o(l){return Q(l)?a(l):t(l)}function a(l){return l===59?(e.consume(l),n):Q(l)?(e.consume(l),a):t(l)}}function ta(e,r,t){return n;function n(o){return e.consume(o),i}function i(o){return ye(o)?t(o):r(o)}}function bt(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||N(e)}function kt(e){return!Q(e)}function wt(e){return!(e===47||we(e))}function we(e){return e===43||e===45||e===46||e===95||ye(e)}function je(e){let r=e.length,t=!1;for(;r--;){const n=e[r][1];if((n.type==="labelLink"||n.type==="labelImage")&&!n._balanced){t=!0;break}if(n._gfmAutolinkLiteralWalkedInto){t=!1;break}}return e.length>0&&!t&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),t}function ra(e,r,t){const n=[];let i=-1;for(;++i<e.length;){const o=e[i].resolveAll;o&&!n.includes(o)&&(r=o(r,t),n.push(o))}return r}function R(e,r,t,n){const i=n?n-1:Number.POSITIVE_INFINITY;let o=0;return a;function a(s){return E(s)?(e.enter(t),l(s)):r(s)}function l(s){return E(s)&&o++<i?(e.consume(s),l):(e.exit(t),r(s))}}const na={partial:!0,tokenize:aa};function aa(e,r,t){return n;function n(o){return E(o)?R(e,i,"linePrefix")(o):i(o)}function i(o){return o===null||K(o)?r(o):t(o)}}const ia={tokenize:ha,partial:!0};function oa(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:ca,continuation:{tokenize:da},exit:fa}},text:{91:{name:"gfmFootnoteCall",tokenize:ua},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:sa,resolveTo:la}}}}function sa(e,r,t){const n=this;let i=n.events.length;const o=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let a;for(;i--;){const s=n.events[i][1];if(s.type==="labelImage"){a=s;break}if(s.type==="gfmFootnoteCall"||s.type==="labelLink"||s.type==="label"||s.type==="image"||s.type==="link")break}return l;function l(s){if(!a||!a._balanced)return t(s);const c=ee(n.sliceSerialize({start:a.end,end:n.now()}));return c.codePointAt(0)!==94||!o.includes(c.slice(1))?t(s):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(s),e.exit("gfmFootnoteCallLabelMarker"),r(s))}}function la(e,r){let t=e.length;for(;t--;)if(e[t][1].type==="labelImage"&&e[t][0]==="enter"){e[t][1];break}e[t+1][1].type="data",e[t+3][1].type="gfmFootnoteCallLabelMarker";const n={type:"gfmFootnoteCall",start:Object.assign({},e[t+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[t+3][1].end),end:Object.assign({},e[t+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const o={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},o.start),end:Object.assign({},o.end)},l=[e[t+1],e[t+2],["enter",n,r],e[t+3],e[t+4],["enter",i,r],["exit",i,r],["enter",o,r],["enter",a,r],["exit",a,r],["exit",o,r],e[e.length-2],e[e.length-1],["exit",n,r]];return e.splice(t,e.length-t+1,...l),e}function ua(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o=0,a;return l;function l(u){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),s}function s(u){return u!==94?t(u):(e.enter("gfmFootnoteCallMarker"),e.consume(u),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(u){if(o>999||u===93&&!a||u===null||u===91||N(u))return t(u);if(u===93){e.exit("chunkString");const p=e.exit("gfmFootnoteCallString");return i.includes(ee(n.sliceSerialize(p)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),r):t(u)}return N(u)||(a=!0),o++,e.consume(u),u===92?h:c}function h(u){return u===91||u===92||u===93?(e.consume(u),o++,c):c(u)}}function ca(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o,a=0,l;return s;function s(f){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(f),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(f){return f===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(f),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",h):t(f)}function h(f){if(a>999||f===93&&!l||f===null||f===91||N(f))return t(f);if(f===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return o=ee(n.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(f),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),p}return N(f)||(l=!0),a++,e.consume(f),f===92?u:h}function u(f){return f===91||f===92||f===93?(e.consume(f),a++,h):h(f)}function p(f){return f===58?(e.enter("definitionMarker"),e.consume(f),e.exit("definitionMarker"),i.includes(o)||i.push(o),R(e,g,"gfmFootnoteDefinitionWhitespace")):t(f)}function g(f){return r(f)}}function da(e,r,t){return e.check(na,r,e.attempt(ia,r,t))}function fa(e){e.exit("gfmFootnoteDefinition")}function ha(e,r,t){const n=this;return R(e,i,"gfmFootnoteDefinitionIndent",5);function i(o){const a=n.events[n.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?r(o):t(o)}}function ma(e){let t=(e||{}).singleTilde;const n={name:"strikethrough",tokenize:o,resolveAll:i};return t==null&&(t=!0),{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function i(a,l){let s=-1;for(;++s<a.length;)if(a[s][0]==="enter"&&a[s][1].type==="strikethroughSequenceTemporary"&&a[s][1]._close){let c=s;for(;c--;)if(a[c][0]==="exit"&&a[c][1].type==="strikethroughSequenceTemporary"&&a[c][1]._open&&a[s][1].end.offset-a[s][1].start.offset===a[c][1].end.offset-a[c][1].start.offset){a[s][1].type="strikethroughSequence",a[c][1].type="strikethroughSequence";const h={type:"strikethrough",start:Object.assign({},a[c][1].start),end:Object.assign({},a[s][1].end)},u={type:"strikethroughText",start:Object.assign({},a[c][1].end),end:Object.assign({},a[s][1].start)},p=[["enter",h,l],["enter",a[c][1],l],["exit",a[c][1],l],["enter",u,l]],g=l.parser.constructs.insideSpan.null;g&&ne(p,p.length,0,ra(g,a.slice(c+1,s),l)),ne(p,p.length,0,[["exit",u,l],["enter",a[s][1],l],["exit",a[s][1],l],["exit",h,l]]),ne(a,c-1,s-c+3,p),s=c+p.length-2;break}}for(s=-1;++s<a.length;)a[s][1].type==="strikethroughSequenceTemporary"&&(a[s][1].type="data");return a}function o(a,l,s){const c=this.previous,h=this.events;let u=0;return p;function p(f){return c===126&&h[h.length-1][1].type!=="characterEscape"?s(f):(a.enter("strikethroughSequenceTemporary"),g(f))}function g(f){const b=ae(c);if(f===126)return u>1?s(f):(a.consume(f),u++,g);if(u<2&&!t)return s(f);const x=a.exit("strikethroughSequenceTemporary"),k=ae(f);return x._open=!k||k===2&&!!b,x._close=!b||b===2&&!!k,l(f)}}}class pa{constructor(){this.map=[]}add(r,t,n){ga(this,r,t,n)}consume(r){if(this.map.sort(function(o,a){return o[0]-a[0]}),this.map.length===0)return;let t=this.map.length;const n=[];for(;t>0;)t-=1,n.push(r.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),r.length=this.map[t][0];n.push(r.slice()),r.length=0;let i=n.pop();for(;i;){for(const o of i)r.push(o);i=n.pop()}this.map.length=0}}function ga(e,r,t,n){let i=0;if(!(t===0&&n.length===0)){for(;i<e.map.length;){if(e.map[i][0]===r){e.map[i][1]+=t,e.map[i][2].push(...n);return}i+=1}e.map.push([r,t,n])}}function xa(e,r){let t=!1;const n=[];for(;r<e.length;){const i=e[r];if(t){if(i[0]==="enter")i[1].type==="tableContent"&&n.push(e[r+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[r-1][1].type==="tableDelimiterMarker"){const o=n.length-1;n[o]=n[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(t=!0);r+=1}return n}function ba(){return{flow:{null:{name:"table",tokenize:ka,resolveAll:wa}}}}function ka(e,r,t){const n=this;let i=0,o=0,a;return l;function l(m){let M=n.events.length-1;for(;M>-1;){const X=n.events[M][1].type;if(X==="lineEnding"||X==="linePrefix")M--;else break}const V=M>-1?n.events[M][1].type:null,$=V==="tableHead"||V==="tableRow"?T:s;return $===T&&n.parser.lazy[n.now().line]?t(m):$(m)}function s(m){return e.enter("tableHead"),e.enter("tableRow"),c(m)}function c(m){return m===124||(a=!0,o+=1),h(m)}function h(m){return m===null?t(m):K(m)?o>1?(o=0,n.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(m),e.exit("lineEnding"),g):t(m):E(m)?R(e,h,"whitespace")(m):(o+=1,a&&(a=!1,i+=1),m===124?(e.enter("tableCellDivider"),e.consume(m),e.exit("tableCellDivider"),a=!0,h):(e.enter("data"),u(m)))}function u(m){return m===null||m===124||N(m)?(e.exit("data"),h(m)):(e.consume(m),m===92?p:u)}function p(m){return m===92||m===124?(e.consume(m),u):u(m)}function g(m){return n.interrupt=!1,n.parser.lazy[n.now().line]?t(m):(e.enter("tableDelimiterRow"),a=!1,E(m)?R(e,f,"linePrefix",n.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(m):f(m))}function f(m){return m===45||m===58?x(m):m===124?(a=!0,e.enter("tableCellDivider"),e.consume(m),e.exit("tableCellDivider"),b):v(m)}function b(m){return E(m)?R(e,x,"whitespace")(m):x(m)}function x(m){return m===58?(o+=1,a=!0,e.enter("tableDelimiterMarker"),e.consume(m),e.exit("tableDelimiterMarker"),k):m===45?(o+=1,k(m)):m===null||K(m)?j(m):v(m)}function k(m){return m===45?(e.enter("tableDelimiterFiller"),y(m)):v(m)}function y(m){return m===45?(e.consume(m),y):m===58?(a=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(m),e.exit("tableDelimiterMarker"),C):(e.exit("tableDelimiterFiller"),C(m))}function C(m){return E(m)?R(e,j,"whitespace")(m):j(m)}function j(m){return m===124?f(m):m===null||K(m)?!a||i!==o?v(m):(e.exit("tableDelimiterRow"),e.exit("tableHead"),r(m)):v(m)}function v(m){return t(m)}function T(m){return e.enter("tableRow"),L(m)}function L(m){return m===124?(e.enter("tableCellDivider"),e.consume(m),e.exit("tableCellDivider"),L):m===null||K(m)?(e.exit("tableRow"),r(m)):E(m)?R(e,L,"whitespace")(m):(e.enter("data"),O(m))}function O(m){return m===null||m===124||N(m)?(e.exit("data"),L(m)):(e.consume(m),m===92?z:O)}function z(m){return m===92||m===124?(e.consume(m),O):O(m)}}function wa(e,r){let t=-1,n=!0,i=0,o=[0,0,0,0],a=[0,0,0,0],l=!1,s=0,c,h,u;const p=new pa;for(;++t<e.length;){const g=e[t],f=g[1];g[0]==="enter"?f.type==="tableHead"?(l=!1,s!==0&&(Oe(p,r,s,c,h),h=void 0,s=0),c={type:"table",start:Object.assign({},f.start),end:Object.assign({},f.end)},p.add(t,0,[["enter",c,r]])):f.type==="tableRow"||f.type==="tableDelimiterRow"?(n=!0,u=void 0,o=[0,0,0,0],a=[0,t+1,0,0],l&&(l=!1,h={type:"tableBody",start:Object.assign({},f.start),end:Object.assign({},f.end)},p.add(t,0,[["enter",h,r]])),i=f.type==="tableDelimiterRow"?2:h?3:1):i&&(f.type==="data"||f.type==="tableDelimiterMarker"||f.type==="tableDelimiterFiller")?(n=!1,a[2]===0&&(o[1]!==0&&(a[0]=a[1],u=re(p,r,o,i,void 0,u),o=[0,0,0,0]),a[2]=t)):f.type==="tableCellDivider"&&(n?n=!1:(o[1]!==0&&(a[0]=a[1],u=re(p,r,o,i,void 0,u)),o=a,a=[o[1],t,0,0])):f.type==="tableHead"?(l=!0,s=t):f.type==="tableRow"||f.type==="tableDelimiterRow"?(s=t,o[1]!==0?(a[0]=a[1],u=re(p,r,o,i,t,u)):a[1]!==0&&(u=re(p,r,a,i,t,u)),i=0):i&&(f.type==="data"||f.type==="tableDelimiterMarker"||f.type==="tableDelimiterFiller")&&(a[3]=t)}for(s!==0&&Oe(p,r,s,c,h),p.consume(r.events),t=-1;++t<r.events.length;){const g=r.events[t];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=xa(r.events,t))}return e}function re(e,r,t,n,i,o){const a=n===1?"tableHeader":n===2?"tableDelimiter":"tableData",l="tableContent";t[0]!==0&&(o.end=Object.assign({},q(r.events,t[0])),e.add(t[0],0,[["exit",o,r]]));const s=q(r.events,t[1]);if(o={type:a,start:Object.assign({},s),end:Object.assign({},s)},e.add(t[1],0,[["enter",o,r]]),t[2]!==0){const c=q(r.events,t[2]),h=q(r.events,t[3]),u={type:l,start:Object.assign({},c),end:Object.assign({},h)};if(e.add(t[2],0,[["enter",u,r]]),n!==2){const p=r.events[t[2]],g=r.events[t[3]];if(p[1].end=Object.assign({},g[1].end),p[1].type="chunkText",p[1].contentType="text",t[3]>t[2]+1){const f=t[2]+1,b=t[3]-t[2]-1;e.add(f,b,[])}}e.add(t[3]+1,0,[["exit",u,r]])}return i!==void 0&&(o.end=Object.assign({},q(r.events,i)),e.add(i,0,[["exit",o,r]]),o=void 0),o}function Oe(e,r,t,n,i){const o=[],a=q(r.events,t);i&&(i.end=Object.assign({},a),o.push(["exit",i,r])),n.end=Object.assign({},a),o.push(["exit",n,r]),e.add(t+1,0,o)}function q(e,r){const t=e[r],n=t[0]==="enter"?"start":"end";return t[1][n]}const ya={name:"tasklistCheck",tokenize:va};function Ca(){return{text:{91:ya}}}function va(e,r,t){const n=this;return i;function i(s){return n.previous!==null||!n._gfmTasklistFirstContentOfListItem?t(s):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),o)}function o(s){return N(s)?(e.enter("taskListCheckValueUnchecked"),e.consume(s),e.exit("taskListCheckValueUnchecked"),a):s===88||s===120?(e.enter("taskListCheckValueChecked"),e.consume(s),e.exit("taskListCheckValueChecked"),a):t(s)}function a(s){return s===93?(e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),l):t(s)}function l(s){return K(s)?r(s):E(s)?e.check({tokenize:ja},r,t)(s):t(s)}}function ja(e,r,t){return R(e,n,"whitespace");function n(i){return i===null?t(i):r(i)}}function Ta(e){return Bn([Vn(),oa(),ma(e),ba(),Ca()])}const Ia={};function Aa(e){const r=this,t=e||Ia,n=r.data(),i=n.micromarkExtensions||(n.micromarkExtensions=[]),o=n.fromMarkdownExtensions||(n.fromMarkdownExtensions=[]),a=n.toMarkdownExtensions||(n.toMarkdownExtensions=[]);i.push(Ta(t)),o.push(On()),a.push(Un(t))}function A(...e){return e.filter(Boolean).join(" ")}const Sa=({content:e})=>d.jsx(be.MarkdownTextPrimitive,{remarkPlugins:[Aa],className:"cuadra-aui-md",components:Ma,children:e}),yt=w.memo(Sa),Na=({language:e,code:r})=>{const{isCopied:t,copyToClipboard:n}=La(),i=()=>{!r||t||n(r)};return d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-gap-4 cuadra-mt-4 cuadra-rounded-t-lg cuadra-bg-muted/50 cuadra-border-b cuadra-border-border cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-font-brand",children:[d.jsx("span",{className:"cuadra-lowercase [&>span]:cuadra-text-xs cuadra-font-brand",children:e}),d.jsxs("button",{onClick:i,className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-muted cuadra-transition-colors","aria-label":"Copy code",children:[!t&&d.jsx(Ot,{className:"cuadra-h-4 cuadra-w-4"}),t&&d.jsx(Et,{className:"cuadra-h-4 cuadra-w-4"})]})]})},La=({copiedDuration:e=3e3}={})=>{const[r,t]=w.useState(!1);return{isCopied:r,copyToClipboard:i=>{i&&navigator.clipboard.writeText(i).then(()=>{t(!0),setTimeout(()=>t(!1),e)})}}},Ma=be.unstable_memoizeMarkdownComponents({h1:({className:e,...r})=>d.jsx("h1",{className:A("cuadra-mb-6 cuadra-scroll-m-20 cuadra-text-2xl cuadra-font-normal cuadra-tracking-tight last:cuadra-mb-0 font-brand",e),...r}),h2:({className:e,...r})=>d.jsx("h2",{className:A("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h3:({className:e,...r})=>d.jsx("h3",{className:A("cuadra-mb-3 cuadra-mt-5 cuadra-scroll-m-20 cuadra-text-lg cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h4:({className:e,...r})=>d.jsx("h4",{className:A("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h5:({className:e,...r})=>d.jsx("h5",{className:A("cuadra-my-4 cuadra-text-lg cuadra-font-normal first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h6:({className:e,...r})=>d.jsx("h6",{className:A("cuadra-my-4 cuadra-font-normal first:cuadra-mb-0 font-brand",e),...r}),p:({className:e,...r})=>d.jsx("p",{className:A("cuadra-mb-5 cuadra-mt-5 cuadra-leading-7 first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),a:({className:e,...r})=>d.jsx("a",{className:A("cuadra-text-primary cuadra-font-medium cuadra-underline cuadra-underline-offset-4 font-brand",e),...r}),blockquote:({className:e,...r})=>d.jsx("blockquote",{className:A("cuadra-border-l-2 cuadra-pl-6 cuadra-italic font-brand",e),...r}),ul:({className:e,...r})=>d.jsx("ul",{className:A("cuadra-my-5 cuadra-ml-6 cuadra-list-disc [&>li]:cuadra-mt-2 font-brand",e),...r}),ol:({className:e,...r})=>d.jsx("ol",{className:A("cuadra-my-5 cuadra-ml-6 cuadra-list-decimal [&>li]:cuadra-mt-2 font-brand",e),...r}),hr:({className:e,...r})=>d.jsx("hr",{className:A("cuadra-my-5 cuadra-border-b",e),...r}),table:({className:e,...r})=>d.jsx("table",{className:A("cuadra-my-5 cuadra-w-full cuadra-border-separate cuadra-border-spacing-0 cuadra-overflow-y-auto font-brand",e),...r}),th:({className:e,...r})=>d.jsx("th",{className:A("cuadra-bg-muted cuadra-px-4 cuadra-py-2 cuadra-text-left cuadra-font-normal first:cuadra-rounded-tl-lg last:cuadra-rounded-tr-lg [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),td:({className:e,...r})=>d.jsx("td",{className:A("cuadra-border-b cuadra-border-l cuadra-px-4 cuadra-py-2 cuadra-text-left last:cuadra-border-r [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),tr:({className:e,...r})=>d.jsx("tr",{className:A("cuadra-m-0 cuadra-border-b cuadra-p-0 first:cuadra-border-t [&:last-child>td:first-child]:cuadra-rounded-bl-lg [&:last-child>td:last-child]:cuadra-rounded-br-lg",e),...r}),sup:({className:e,...r})=>d.jsx("sup",{className:A("[&>a]:cuadra-text-xs [&>a]:cuadra-no-underline font-brand",e),...r}),pre:({className:e,...r})=>d.jsx("pre",{className:A("cuadra-overflow-x-auto cuadra-rounded-b-lg !cuadra-rounded-t-none cuadra-bg-muted cuadra-p-4 cuadra-text-foreground font-brand",e),...r}),code:function({className:r,...t}){const n=be.useIsMarkdownCodeBlock();return d.jsx("code",{className:A(!n&&"cuadra-bg-muted cuadra-rounded cuadra-border cuadra-font-normal font-brand",r),...t})},CodeHeader:Na}),Ue=["Sending question…","Understanding your need…","Scanning data…","Comparing results…","Composing answer…"];function Pa({active:e}){const[r,t]=w.useState(0);return w.useEffect(()=>{if(!e){t(0);return}const n=window.setInterval(()=>{t(i=>i>=Ue.length-1?(window.clearInterval(n),i):i+1)},2500);return()=>window.clearInterval(n)},[e]),e?d.jsxs("span",{className:"cuadra-text-xs cuadra-text-muted-foreground cuadra-font-brand",children:["Thinking… ",Ue[r]]}):null}function Be({welcomeTitle:e="Hi, how can I help you today?",welcomeSubtitle:r="Start exploring our platform and discover what you can build.",extraTopPadding:t,suggestions:n}={}){const i=I.useThreadRuntime(),[o,a]=w.useState(!1),[l,s]=w.useState(null),[c,h]=w.useState(!1);return w.useEffect(()=>{if(!i){a(!1);return}try{const u=i?.store;if(!u){a(!1);return}const p=u.subscribe?.(f=>{const b=f?.threadId,x=f?.messages||[],k=f?.isLoadingHistory||!1,y=x.length;b&&b!==l&&s(b),a(k&&y===0);const j=x.some(v=>v.role==="assistant"&&!!v.content&&(Array.isArray(v.content)?v.content.some(T=>typeof T=="object"&&T?.text?T.text.trim().length>0:!1):typeof v.content=="string"?v.content.trim().length>0:!1));h(j)}),g=u.getState?.();if(g){const f=g?.threadId,b=g?.messages||[],x=g?.isLoadingHistory||!1,k=b.length;f&&f!==l&&s(f),a(x&&k===0);const C=b.some(j=>j.role==="assistant"&&!!j.content&&(Array.isArray(j.content)?j.content.some(v=>typeof v=="object"&&v?.text?v.text.trim().length>0:!1):typeof j.content=="string"?j.content.trim().length>0:!1));h(C)}return()=>{p&&p()}}catch{a(!1)}},[i,l]),d.jsxs(I.ThreadPrimitive.Root,{className:"cuadra-bg-inherit cuadra-flex cuadra-flex-col cuadra-w-full cuadra-h-full",children:[d.jsx(I.ThreadPrimitive.Viewport,{className:"cuadra-w-full cuadra-bg-inherit cuadra-px-4 cuadra-flex-1 cuadra-min-h-0 cuadra-overflow-y-auto cuadra-relative scrollbar-thin cuadra-pt-4",style:t?{paddingTop:t}:void 0,children:o?d.jsx("div",{className:"cuadra-absolute cuadra-inset-0 cuadra-flex cuadra-items-center cuadra-justify-center",children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:[d.jsx(Ke,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"}),d.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground font-brand",children:"Loading messages..."})]})}):d.jsxs(d.Fragment,{children:[d.jsx(I.ThreadPrimitive.Empty,{children:d.jsx(Da,{title:e,subtitle:r,suggestions:n})}),d.jsx(I.ThreadPrimitive.Messages,{components:{UserMessage:Ea,AssistantMessage:Ra}}),d.jsx(I.ThreadPrimitive.If,{running:!0,children:!c&&d.jsx("div",{className:"cuadra-mt-2 cuadra-max-w-2xl",children:d.jsx(Pa,{active:!0})})})]})}),d.jsx("div",{className:"cuadra-w-full cuadra-mt-3 cuadra-border-t cuadra-border-border cuadra-pt-4",children:d.jsxs(I.ComposerPrimitive.Root,{className:"cuadra-relative !cuadra-relative cuadra-flex-1 cuadra-w-full",children:[d.jsx(I.ComposerPrimitive.Input,{asChild:!0,children:d.jsx("textarea",{rows:3,placeholder:"Type your message...",className:"cuadra-flex cuadra-min-h-[80px] cuadra-w-full cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-base placeholder:cuadra-text-muted-foreground focus-visible:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-resize-none cuadra-pr-10 font-brand",style:{paddingRight:"2.5rem",fontSize:"1rem"}})}),d.jsx(I.ComposerPrimitive.Send,{asChild:!0,children:d.jsx("button",{className:"!cuadra-absolute !cuadra-bottom-2 !cuadra-right-2 cuadra-size-8 cuadra-bg-secondary cuadra-text-secondary-foreground cuadra-rounded-md cuadra-shadow-sm hover:cuadra-bg-secondary/90 disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed cuadra-flex cuadra-items-center cuadra-justify-center",style:{position:"absolute",bottom:"0.5rem",right:"0.5rem"},"aria-label":"Send message",type:"button",children:d.jsx(Pt,{className:"cuadra-h-4 cuadra-w-4"})})})]})})]})}function Da({title:e,subtitle:r,suggestions:t}){const n=I.useAssistantApi(),i=async o=>{try{n.composer().setText(o),await new Promise(a=>setTimeout(a,10)),n.composer().send()}catch{}};return d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-h-full cuadra-py-12 cuadra-px-4 cuadra-overflow-y-auto scrollbar-hide",children:d.jsxs("div",{className:"cuadra-text-center cuadra-max-w-3xl cuadra-w-full cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-min-h-full",children:[d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-mb-8",children:[d.jsx("h2",{className:"cuadra-text-lg cuadra-font-normal cuadra-text-foreground cuadra-mb-2 font-brand",children:e}),d.jsx("p",{className:"cuadra-text-muted-foreground font-brand",children:r})]}),t&&t.length>0&&d.jsx("div",{className:"cuadra-grid cuadra-grid-cols-2 cuadra-gap-2 cuadra-pb-4 cuadra-w-full cuadra-max-w-2xl",children:t.map((o,a)=>d.jsx("button",{type:"button",onClick:()=>i(o.prompt),className:"cuadra-w-full cuadra-text-center cuadra-px-4 cuadra-py-3 cuadra-rounded-lg cuadra-border cuadra-border-border cuadra-bg-background cuadra-text-sm font-brand cuadra-cursor-pointer focus:cuadra-outline-none focus:cuadra-ring-0",style:{borderWidth:"1px"},children:o.prompt},`suggestion-${a}`))})]})})}function Ea(){return d.jsx(I.MessagePrimitive.Root,{className:"cuadra-grid cuadra-w-full cuadra-auto-rows-auto cuadra-grid-cols-[minmax(72px,1fr)_auto] cuadra-gap-y-2 cuadra-py-3 [&:where(>*)]:cuadra-col-start-2",children:d.jsx("div",{className:"cuadra-bg-muted cuadra-text-foreground cuadra-col-start-2 cuadra-row-start-2 cuadra-max-w-[calc(42rem*0.8)] cuadra-break-words cuadra-rounded-3xl cuadra-px-5 cuadra-py-2.5 font-brand",style:{maxWidth:"calc(42rem * 0.8)",borderRadius:"1.5rem",backgroundColor:"hsl(var(--muted))",color:"hsl(var(--foreground))",paddingLeft:"1.25rem",paddingRight:"1.25rem",paddingTop:"0.625rem",paddingBottom:"0.625rem",wordBreak:"break-word"},children:d.jsx(I.MessagePrimitive.Parts,{components:{Text:({text:e})=>d.jsx(yt,{content:e||""})}})})})}function Ra(){return d.jsx(I.MessagePrimitive.Root,{className:"cuadra-relative cuadra-grid cuadra-w-full cuadra-grid-cols-[auto_auto_1fr] cuadra-grid-rows-[auto_1fr] cuadra-py-3",children:d.jsx("div",{className:"cuadra-text-foreground cuadra-col-span-2 cuadra-col-start-2 cuadra-row-start-1 cuadra-my-1.5 cuadra-max-w-[90%] cuadra-break-words cuadra-leading-7 font-brand",style:{maxWidth:"90%",marginTop:"0.375rem",marginBottom:"0.375rem"},children:d.jsx(I.MessagePrimitive.Parts,{components:{Text:({text:e})=>d.jsx(yt,{content:e||""})}})})})}function _a({onThreadSelect:e}){const r=I.useThreadListItem(),t=I.useThread(x=>x.threadId),[n,i]=w.useState(null),o=r?.id===t,a=n===r?.id,[l,s]=w.useState(!1),[c,h]=w.useState(r?.title||""),[u,p]=w.useState(!1),[g,f]=w.useState(!1),b=async()=>{if(!r?.remoteId||!c||c===r.title){s(!1);return}try{f(!0);const x=window.__cuadraThreadListAdapter;x&&typeof x.rename=="function"&&await x.rename(r.remoteId,c),s(!1),p(!1)}catch{s(!1),p(!1)}finally{f(!1)}};return w.useEffect(()=>{r?.title&&!l&&h(r.title)},[r?.title,l]),r?d.jsx(I.ThreadListItemPrimitive.Root,{className:`group cuadra-relative cuadra-flex cuadra-items-center cuadra-gap-3 cuadra-rounded-lg cuadra-transition-colors cuadra-cursor-pointer cuadra-border cuadra-mb-2 ${o?"cuadra-bg-muted cuadra-border-border":"cuadra-border-transparent hover:cuadra-bg-muted hover:cuadra-border-border"}`,style:{marginBottom:"0.5rem"},onMouseEnter:()=>i(r.id),onMouseLeave:()=>i(null),children:d.jsxs(I.ThreadListItemPrimitive.Trigger,{className:"cuadra-p-3 cuadra-flex-1 cuadra-flex cuadra-items-center cuadra-justify-between cuadra-w-full cuadra-min-w-0 cuadra-cursor-pointer",onClick:()=>e?.(),children:[d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-min-w-0 cuadra-flex-1 cuadra-items-start cuadra-text-left",children:l?d.jsx("input",{className:"cuadra-flex cuadra-w-full cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-sm placeholder:cuadra-text-muted-foreground focus-visible:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 font-brand",value:c,onChange:x=>h(x.target.value),onKeyDown:x=>{x.key==="Enter"&&b(),x.key==="Escape"&&(s(!1),h(r.title||""))},disabled:g,autoFocus:!0,onClick:x=>x.stopPropagation()}):d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-truncate font-brand",children:(r.title?.length||0)>60?`${r.title?.slice(0,60)}…`:r.title||"Chat"}),r.updatedAt&&d.jsx("span",{className:"cuadra-text-xs cuadra-text-muted-foreground cuadra-mt-1 font-brand",children:new Date(r.updatedAt).toLocaleDateString()})]})}),d.jsx("div",{className:"cuadra-ml-2 cuadra-flex-shrink-0 cuadra-w-6 cuadra-h-6 cuadra-flex cuadra-items-center cuadra-justify-center",children:(a||o||u)&&d.jsxs("div",{className:"cuadra-relative",children:[d.jsx("button",{className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-background/50 cuadra-transition-colors",onClick:x=>{x.stopPropagation(),p(!u)},"aria-label":"Thread options",children:d.jsx(Bt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"})}),u&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:()=>p(!1)}),d.jsx("div",{className:"cuadra-absolute cuadra-right-0 cuadra-top-8 cuadra-z-50 cuadra-bg-background cuadra-border cuadra-border-border cuadra-rounded-lg cuadra-shadow-lg cuadra-min-w-[120px] cuadra-overflow-hidden",children:l?d.jsx("button",{className:"cuadra-w-full cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted cuadra-transition-colors font-brand",onClick:x=>{x.stopPropagation(),b()},disabled:g,children:"Save"}):d.jsxs(d.Fragment,{children:[d.jsx("button",{className:"cuadra-w-full cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted cuadra-transition-colors font-brand",onClick:x=>{x.stopPropagation(),s(!0),h(r.title||""),p(!1)},children:"Rename"}),d.jsx("div",{className:"cuadra-border-t cuadra-border-border"}),d.jsx(I.ThreadListItemPrimitive.Delete,{asChild:!0,children:d.jsx("button",{className:"cuadra-w-full cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left cuadra-text-destructive hover:cuadra-bg-muted cuadra-transition-colors font-brand",onClick:x=>{x.stopPropagation(),p(!1)},children:"Delete"})})]})})]})]})})]})}):null}function We({onThreadSelect:e}){return d.jsxs(I.ThreadListPrimitive.Root,{className:"!cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-full cuadra-w-80",style:{borderRightWidth:"1px"},children:[d.jsx("div",{className:"cuadra-border-b cuadra-border-border cuadra-flex cuadra-items-center cuadra-justify-between cuadra-transition-all cuadra-duration-300 cuadra-h-16 cuadra-px-4",children:d.jsx("h3",{className:"cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-text-nowrap font-brand",children:"Chat History"})}),d.jsxs("div",{className:"cuadra-flex-1 cuadra-overflow-y-auto cuadra-p-2 scrollbar-thin",children:[d.jsx(I.ThreadListPrimitive.New,{className:"group cuadra-relative cuadra-flex cuadra-items-center cuadra-gap-3 cuadra-p-3 cuadra-rounded-lg cuadra-cursor-pointer cuadra-transition-colors cuadra-border cuadra-border-transparent hover:cuadra-bg-muted hover:cuadra-border-border",onClick:()=>e?.(),children:d.jsx("div",{className:"cuadra-flex-1 cuadra-min-w-0",children:d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[d.jsx(Vt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"}),d.jsx("h4",{className:"cuadra-text-sm cuadra-font-normal cuadra-text-foreground font-brand",children:"New Chat"})]})})}),d.jsx("div",{className:"cuadra-my-2 cuadra-border-t cuadra-border-border"}),d.jsx(I.ThreadListPrimitive.Items,{components:{ThreadListItem:r=>d.jsx(_a,{...r,onThreadSelect:e})}})]})]})}const Fa=`
18
+ `))}function s(g,f,b,x){const k=b.enter("tableCell"),y=b.enter("phrasing"),C=b.containerPhrasing(g,{...x,before:o,after:o});return y(),k(),C}function c(g,f){return qr(g,{align:f,alignDelimiters:n,padding:t,stringLength:i})}function h(g,f,b){const x=g.children;let k=-1;const y=[],C=f.enter("table");for(;++k<x.length;)y[k]=u(x[k],f,b);return C(),y}function u(g,f,b){const x=g.children;let k=-1;const y=[],C=f.enter("tableRow");for(;++k<x.length;)y[k]=s(x[k],g,f,b);return C(),y}function p(g,f,b){let x=ft.inlineCode(g,f,b);return b.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function _n(){return{exit:{taskListCheckValueChecked:ze,taskListCheckValueUnchecked:ze,paragraph:zn}}}function Fn(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:$n}}}function ze(e){const r=this.stack[this.stack.length-2];r.type,r.checked=e.type==="taskListCheckValueChecked"}function zn(e){const r=this.stack[this.stack.length-2];if(r&&r.type==="listItem"&&typeof r.checked=="boolean"){const t=this.stack[this.stack.length-1];t.type;const n=t.children[0];if(n&&n.type==="text"){const i=r.children;let o=-1,a;for(;++o<i.length;){const l=i[o];if(l.type==="paragraph"){a=l;break}}a===t&&(n.value=n.value.slice(1),n.value.length===0?t.children.shift():t.position&&n.position&&typeof n.position.start.offset=="number"&&(n.position.start.column++,n.position.start.offset++,t.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function $n(e,r,t,n){const i=e.children[0],o=typeof e.checked=="boolean"&&i&&i.type==="paragraph",a="["+(e.checked?"x":" ")+"] ",l=t.createTracker(n);o&&l.move(a);let s=ft.listItem(e,r,t,{...n,...l.current()});return o&&(s=s.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,c)),s;function c(h){return h+a}}function On(){return[mr(),Rr(),$r(),Nn(),_n()]}function Un(e){return{extensions:[pr(),_r(e),Or(),Rn(e),Fn()]}}function ne(e,r,t,n){const i=e.length;let o=0,a;if(r<0?r=-r>i?0:i+r:r=r>i?i:r,t=t>0?t:0,n.length<1e4)a=Array.from(n),a.unshift(r,t),e.splice(...a);else for(t&&e.splice(r,t);o<n.length;)a=n.slice(o,o+1e4),a.unshift(r,0),e.splice(...a),o+=1e4,r+=1e4}const $e={}.hasOwnProperty;function Bn(e){const r={};let t=-1;for(;++t<e.length;)Wn(r,e[t]);return r}function Wn(e,r){let t;for(t in r){const i=($e.call(e,t)?e[t]:void 0)||(e[t]={}),o=r[t];let a;if(o)for(a in o){$e.call(i,a)||(i[a]=[]);const l=o[a];Hn(i[a],Array.isArray(l)?l:l?[l]:[])}}}function Hn(e,r){let t=-1;const n=[];for(;++t<r.length;)(r[t].add==="after"?e:n).push(r[t]);ne(e,0,0,n)}const qn={tokenize:Qn,partial:!0},ht={tokenize:Xn,partial:!0},mt={tokenize:Yn,partial:!0},pt={tokenize:ea,partial:!0},Kn={tokenize:ta,partial:!0},gt={name:"wwwAutolink",tokenize:Zn,previous:bt},xt={name:"protocolAutolink",tokenize:Jn,previous:kt},F={name:"emailAutolink",tokenize:Gn,previous:wt},M={};function Vn(){return{text:M}}let U=48;for(;U<123;)M[U]=F,U++,U===58?U=65:U===91&&(U=97);M[43]=F;M[45]=F;M[46]=F;M[95]=F;M[72]=[F,xt];M[104]=[F,xt];M[87]=[F,gt];M[119]=[F,gt];function Gn(e,r,t){const n=this;let i,o;return a;function a(u){return!we(u)||!wt.call(n,n.previous)||je(n.events)?t(u):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(u))}function l(u){return we(u)?(e.consume(u),l):u===64?(e.consume(u),s):t(u)}function s(u){return u===46?e.check(Kn,h,c)(u):u===45||u===95||ye(u)?(o=!0,e.consume(u),s):h(u)}function c(u){return e.consume(u),i=!0,s}function h(u){return o&&i&&Q(n.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),r(u)):t(u)}}function Zn(e,r,t){const n=this;return i;function i(a){return a!==87&&a!==119||!bt.call(n,n.previous)||je(n.events)?t(a):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(qn,e.attempt(ht,e.attempt(mt,o),t),t)(a))}function o(a){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),r(a)}}function Jn(e,r,t){const n=this;let i="",o=!1;return a;function a(u){return(u===72||u===104)&&kt.call(n,n.previous)&&!je(n.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(u),e.consume(u),l):t(u)}function l(u){if(Q(u)&&i.length<5)return i+=String.fromCodePoint(u),e.consume(u),l;if(u===58){const p=i.toLowerCase();if(p==="http"||p==="https")return e.consume(u),s}return t(u)}function s(u){return u===47?(e.consume(u),o?c:(o=!0,s)):t(u)}function c(u){return u===null||er(u)||N(u)||B(u)||oe(u)?t(u):e.attempt(ht,e.attempt(mt,h),t)(u)}function h(u){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),r(u)}}function Qn(e,r,t){let n=0;return i;function i(a){return(a===87||a===119)&&n<3?(n++,e.consume(a),i):a===46&&n===3?(e.consume(a),o):t(a)}function o(a){return a===null?t(a):r(a)}}function Xn(e,r,t){let n,i,o;return a;function a(c){return c===46||c===95?e.check(pt,s,l)(c):c===null||N(c)||B(c)||c!==45&&oe(c)?s(c):(o=!0,e.consume(c),a)}function l(c){return c===95?n=!0:(i=n,n=void 0),e.consume(c),a}function s(c){return i||n||!o?t(c):r(c)}}function Yn(e,r){let t=0,n=0;return i;function i(a){return a===40?(t++,e.consume(a),i):a===41&&n<t?o(a):a===33||a===34||a===38||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===60||a===63||a===93||a===95||a===126?e.check(pt,r,o)(a):a===null||N(a)||B(a)?r(a):(e.consume(a),i)}function o(a){return a===41&&n++,e.consume(a),i}}function ea(e,r,t){return n;function n(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),n):l===38?(e.consume(l),o):l===93?(e.consume(l),i):l===60||l===null||N(l)||B(l)?r(l):t(l)}function i(l){return l===null||l===40||l===91||N(l)||B(l)?r(l):n(l)}function o(l){return Q(l)?a(l):t(l)}function a(l){return l===59?(e.consume(l),n):Q(l)?(e.consume(l),a):t(l)}}function ta(e,r,t){return n;function n(o){return e.consume(o),i}function i(o){return ye(o)?t(o):r(o)}}function bt(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||N(e)}function kt(e){return!Q(e)}function wt(e){return!(e===47||we(e))}function we(e){return e===43||e===45||e===46||e===95||ye(e)}function je(e){let r=e.length,t=!1;for(;r--;){const n=e[r][1];if((n.type==="labelLink"||n.type==="labelImage")&&!n._balanced){t=!0;break}if(n._gfmAutolinkLiteralWalkedInto){t=!1;break}}return e.length>0&&!t&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),t}function ra(e,r,t){const n=[];let i=-1;for(;++i<e.length;){const o=e[i].resolveAll;o&&!n.includes(o)&&(r=o(r,t),n.push(o))}return r}function R(e,r,t,n){const i=n?n-1:Number.POSITIVE_INFINITY;let o=0;return a;function a(s){return E(s)?(e.enter(t),l(s)):r(s)}function l(s){return E(s)&&o++<i?(e.consume(s),l):(e.exit(t),r(s))}}const na={partial:!0,tokenize:aa};function aa(e,r,t){return n;function n(o){return E(o)?R(e,i,"linePrefix")(o):i(o)}function i(o){return o===null||K(o)?r(o):t(o)}}const ia={tokenize:ha,partial:!0};function oa(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:ca,continuation:{tokenize:da},exit:fa}},text:{91:{name:"gfmFootnoteCall",tokenize:ua},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:sa,resolveTo:la}}}}function sa(e,r,t){const n=this;let i=n.events.length;const o=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let a;for(;i--;){const s=n.events[i][1];if(s.type==="labelImage"){a=s;break}if(s.type==="gfmFootnoteCall"||s.type==="labelLink"||s.type==="label"||s.type==="image"||s.type==="link")break}return l;function l(s){if(!a||!a._balanced)return t(s);const c=Y(n.sliceSerialize({start:a.end,end:n.now()}));return c.codePointAt(0)!==94||!o.includes(c.slice(1))?t(s):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(s),e.exit("gfmFootnoteCallLabelMarker"),r(s))}}function la(e,r){let t=e.length;for(;t--;)if(e[t][1].type==="labelImage"&&e[t][0]==="enter"){e[t][1];break}e[t+1][1].type="data",e[t+3][1].type="gfmFootnoteCallLabelMarker";const n={type:"gfmFootnoteCall",start:Object.assign({},e[t+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[t+3][1].end),end:Object.assign({},e[t+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const o={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},o.start),end:Object.assign({},o.end)},l=[e[t+1],e[t+2],["enter",n,r],e[t+3],e[t+4],["enter",i,r],["exit",i,r],["enter",o,r],["enter",a,r],["exit",a,r],["exit",o,r],e[e.length-2],e[e.length-1],["exit",n,r]];return e.splice(t,e.length-t+1,...l),e}function ua(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o=0,a;return l;function l(u){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),s}function s(u){return u!==94?t(u):(e.enter("gfmFootnoteCallMarker"),e.consume(u),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",c)}function c(u){if(o>999||u===93&&!a||u===null||u===91||N(u))return t(u);if(u===93){e.exit("chunkString");const p=e.exit("gfmFootnoteCallString");return i.includes(Y(n.sliceSerialize(p)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),r):t(u)}return N(u)||(a=!0),o++,e.consume(u),u===92?h:c}function h(u){return u===91||u===92||u===93?(e.consume(u),o++,c):c(u)}}function ca(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o,a=0,l;return s;function s(f){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(f),e.exit("gfmFootnoteDefinitionLabelMarker"),c}function c(f){return f===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(f),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",h):t(f)}function h(f){if(a>999||f===93&&!l||f===null||f===91||N(f))return t(f);if(f===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return o=Y(n.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(f),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),p}return N(f)||(l=!0),a++,e.consume(f),f===92?u:h}function u(f){return f===91||f===92||f===93?(e.consume(f),a++,h):h(f)}function p(f){return f===58?(e.enter("definitionMarker"),e.consume(f),e.exit("definitionMarker"),i.includes(o)||i.push(o),R(e,g,"gfmFootnoteDefinitionWhitespace")):t(f)}function g(f){return r(f)}}function da(e,r,t){return e.check(na,r,e.attempt(ia,r,t))}function fa(e){e.exit("gfmFootnoteDefinition")}function ha(e,r,t){const n=this;return R(e,i,"gfmFootnoteDefinitionIndent",5);function i(o){const a=n.events[n.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?r(o):t(o)}}function ma(e){let t=(e||{}).singleTilde;const n={name:"strikethrough",tokenize:o,resolveAll:i};return t==null&&(t=!0),{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function i(a,l){let s=-1;for(;++s<a.length;)if(a[s][0]==="enter"&&a[s][1].type==="strikethroughSequenceTemporary"&&a[s][1]._close){let c=s;for(;c--;)if(a[c][0]==="exit"&&a[c][1].type==="strikethroughSequenceTemporary"&&a[c][1]._open&&a[s][1].end.offset-a[s][1].start.offset===a[c][1].end.offset-a[c][1].start.offset){a[s][1].type="strikethroughSequence",a[c][1].type="strikethroughSequence";const h={type:"strikethrough",start:Object.assign({},a[c][1].start),end:Object.assign({},a[s][1].end)},u={type:"strikethroughText",start:Object.assign({},a[c][1].end),end:Object.assign({},a[s][1].start)},p=[["enter",h,l],["enter",a[c][1],l],["exit",a[c][1],l],["enter",u,l]],g=l.parser.constructs.insideSpan.null;g&&ne(p,p.length,0,ra(g,a.slice(c+1,s),l)),ne(p,p.length,0,[["exit",u,l],["enter",a[s][1],l],["exit",a[s][1],l],["exit",h,l]]),ne(a,c-1,s-c+3,p),s=c+p.length-2;break}}for(s=-1;++s<a.length;)a[s][1].type==="strikethroughSequenceTemporary"&&(a[s][1].type="data");return a}function o(a,l,s){const c=this.previous,h=this.events;let u=0;return p;function p(f){return c===126&&h[h.length-1][1].type!=="characterEscape"?s(f):(a.enter("strikethroughSequenceTemporary"),g(f))}function g(f){const b=ae(c);if(f===126)return u>1?s(f):(a.consume(f),u++,g);if(u<2&&!t)return s(f);const x=a.exit("strikethroughSequenceTemporary"),k=ae(f);return x._open=!k||k===2&&!!b,x._close=!b||b===2&&!!k,l(f)}}}class pa{constructor(){this.map=[]}add(r,t,n){ga(this,r,t,n)}consume(r){if(this.map.sort(function(o,a){return o[0]-a[0]}),this.map.length===0)return;let t=this.map.length;const n=[];for(;t>0;)t-=1,n.push(r.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),r.length=this.map[t][0];n.push(r.slice()),r.length=0;let i=n.pop();for(;i;){for(const o of i)r.push(o);i=n.pop()}this.map.length=0}}function ga(e,r,t,n){let i=0;if(!(t===0&&n.length===0)){for(;i<e.map.length;){if(e.map[i][0]===r){e.map[i][1]+=t,e.map[i][2].push(...n);return}i+=1}e.map.push([r,t,n])}}function xa(e,r){let t=!1;const n=[];for(;r<e.length;){const i=e[r];if(t){if(i[0]==="enter")i[1].type==="tableContent"&&n.push(e[r+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[r-1][1].type==="tableDelimiterMarker"){const o=n.length-1;n[o]=n[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(t=!0);r+=1}return n}function ba(){return{flow:{null:{name:"table",tokenize:ka,resolveAll:wa}}}}function ka(e,r,t){const n=this;let i=0,o=0,a;return l;function l(m){let L=n.events.length-1;for(;L>-1;){const G=n.events[L][1].type;if(G==="lineEnding"||G==="linePrefix")L--;else break}const V=L>-1?n.events[L][1].type:null,$=V==="tableHead"||V==="tableRow"?A:s;return $===A&&n.parser.lazy[n.now().line]?t(m):$(m)}function s(m){return e.enter("tableHead"),e.enter("tableRow"),c(m)}function c(m){return m===124||(a=!0,o+=1),h(m)}function h(m){return m===null?t(m):K(m)?o>1?(o=0,n.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(m),e.exit("lineEnding"),g):t(m):E(m)?R(e,h,"whitespace")(m):(o+=1,a&&(a=!1,i+=1),m===124?(e.enter("tableCellDivider"),e.consume(m),e.exit("tableCellDivider"),a=!0,h):(e.enter("data"),u(m)))}function u(m){return m===null||m===124||N(m)?(e.exit("data"),h(m)):(e.consume(m),m===92?p:u)}function p(m){return m===92||m===124?(e.consume(m),u):u(m)}function g(m){return n.interrupt=!1,n.parser.lazy[n.now().line]?t(m):(e.enter("tableDelimiterRow"),a=!1,E(m)?R(e,f,"linePrefix",n.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(m):f(m))}function f(m){return m===45||m===58?x(m):m===124?(a=!0,e.enter("tableCellDivider"),e.consume(m),e.exit("tableCellDivider"),b):v(m)}function b(m){return E(m)?R(e,x,"whitespace")(m):x(m)}function x(m){return m===58?(o+=1,a=!0,e.enter("tableDelimiterMarker"),e.consume(m),e.exit("tableDelimiterMarker"),k):m===45?(o+=1,k(m)):m===null||K(m)?j(m):v(m)}function k(m){return m===45?(e.enter("tableDelimiterFiller"),y(m)):v(m)}function y(m){return m===45?(e.consume(m),y):m===58?(a=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(m),e.exit("tableDelimiterMarker"),C):(e.exit("tableDelimiterFiller"),C(m))}function C(m){return E(m)?R(e,j,"whitespace")(m):j(m)}function j(m){return m===124?f(m):m===null||K(m)?!a||i!==o?v(m):(e.exit("tableDelimiterRow"),e.exit("tableHead"),r(m)):v(m)}function v(m){return t(m)}function A(m){return e.enter("tableRow"),P(m)}function P(m){return m===124?(e.enter("tableCellDivider"),e.consume(m),e.exit("tableCellDivider"),P):m===null||K(m)?(e.exit("tableRow"),r(m)):E(m)?R(e,P,"whitespace")(m):(e.enter("data"),O(m))}function O(m){return m===null||m===124||N(m)?(e.exit("data"),P(m)):(e.consume(m),m===92?z:O)}function z(m){return m===92||m===124?(e.consume(m),O):O(m)}}function wa(e,r){let t=-1,n=!0,i=0,o=[0,0,0,0],a=[0,0,0,0],l=!1,s=0,c,h,u;const p=new pa;for(;++t<e.length;){const g=e[t],f=g[1];g[0]==="enter"?f.type==="tableHead"?(l=!1,s!==0&&(Oe(p,r,s,c,h),h=void 0,s=0),c={type:"table",start:Object.assign({},f.start),end:Object.assign({},f.end)},p.add(t,0,[["enter",c,r]])):f.type==="tableRow"||f.type==="tableDelimiterRow"?(n=!0,u=void 0,o=[0,0,0,0],a=[0,t+1,0,0],l&&(l=!1,h={type:"tableBody",start:Object.assign({},f.start),end:Object.assign({},f.end)},p.add(t,0,[["enter",h,r]])),i=f.type==="tableDelimiterRow"?2:h?3:1):i&&(f.type==="data"||f.type==="tableDelimiterMarker"||f.type==="tableDelimiterFiller")?(n=!1,a[2]===0&&(o[1]!==0&&(a[0]=a[1],u=re(p,r,o,i,void 0,u),o=[0,0,0,0]),a[2]=t)):f.type==="tableCellDivider"&&(n?n=!1:(o[1]!==0&&(a[0]=a[1],u=re(p,r,o,i,void 0,u)),o=a,a=[o[1],t,0,0])):f.type==="tableHead"?(l=!0,s=t):f.type==="tableRow"||f.type==="tableDelimiterRow"?(s=t,o[1]!==0?(a[0]=a[1],u=re(p,r,o,i,t,u)):a[1]!==0&&(u=re(p,r,a,i,t,u)),i=0):i&&(f.type==="data"||f.type==="tableDelimiterMarker"||f.type==="tableDelimiterFiller")&&(a[3]=t)}for(s!==0&&Oe(p,r,s,c,h),p.consume(r.events),t=-1;++t<r.events.length;){const g=r.events[t];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=xa(r.events,t))}return e}function re(e,r,t,n,i,o){const a=n===1?"tableHeader":n===2?"tableDelimiter":"tableData",l="tableContent";t[0]!==0&&(o.end=Object.assign({},q(r.events,t[0])),e.add(t[0],0,[["exit",o,r]]));const s=q(r.events,t[1]);if(o={type:a,start:Object.assign({},s),end:Object.assign({},s)},e.add(t[1],0,[["enter",o,r]]),t[2]!==0){const c=q(r.events,t[2]),h=q(r.events,t[3]),u={type:l,start:Object.assign({},c),end:Object.assign({},h)};if(e.add(t[2],0,[["enter",u,r]]),n!==2){const p=r.events[t[2]],g=r.events[t[3]];if(p[1].end=Object.assign({},g[1].end),p[1].type="chunkText",p[1].contentType="text",t[3]>t[2]+1){const f=t[2]+1,b=t[3]-t[2]-1;e.add(f,b,[])}}e.add(t[3]+1,0,[["exit",u,r]])}return i!==void 0&&(o.end=Object.assign({},q(r.events,i)),e.add(i,0,[["exit",o,r]]),o=void 0),o}function Oe(e,r,t,n,i){const o=[],a=q(r.events,t);i&&(i.end=Object.assign({},a),o.push(["exit",i,r])),n.end=Object.assign({},a),o.push(["exit",n,r]),e.add(t+1,0,o)}function q(e,r){const t=e[r],n=t[0]==="enter"?"start":"end";return t[1][n]}const ya={name:"tasklistCheck",tokenize:va};function Ca(){return{text:{91:ya}}}function va(e,r,t){const n=this;return i;function i(s){return n.previous!==null||!n._gfmTasklistFirstContentOfListItem?t(s):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),o)}function o(s){return N(s)?(e.enter("taskListCheckValueUnchecked"),e.consume(s),e.exit("taskListCheckValueUnchecked"),a):s===88||s===120?(e.enter("taskListCheckValueChecked"),e.consume(s),e.exit("taskListCheckValueChecked"),a):t(s)}function a(s){return s===93?(e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),l):t(s)}function l(s){return K(s)?r(s):E(s)?e.check({tokenize:ja},r,t)(s):t(s)}}function ja(e,r,t){return R(e,n,"whitespace");function n(i){return i===null?t(i):r(i)}}function Ta(e){return Bn([Vn(),oa(),ma(e),ba(),Ca()])}const Aa={};function Sa(e){const r=this,t=e||Aa,n=r.data(),i=n.micromarkExtensions||(n.micromarkExtensions=[]),o=n.fromMarkdownExtensions||(n.fromMarkdownExtensions=[]),a=n.toMarkdownExtensions||(n.toMarkdownExtensions=[]);i.push(Ta(t)),o.push(On()),a.push(Un(t))}function S(...e){return e.filter(Boolean).join(" ")}const Ia=({content:e})=>d.jsx(be.MarkdownTextPrimitive,{remarkPlugins:[Sa],className:"cuadra-aui-md",components:Ma,children:e}),yt=w.memo(Ia),Na=({language:e,code:r})=>{const{isCopied:t,copyToClipboard:n}=La(),i=()=>{!r||t||n(r)};return d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-gap-4 cuadra-mt-4 cuadra-rounded-t-lg cuadra-bg-muted/50 cuadra-border-b cuadra-border-border cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-font-brand",children:[d.jsx("span",{className:"cuadra-lowercase [&>span]:cuadra-text-xs cuadra-font-brand",children:e}),d.jsxs("button",{onClick:i,className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-muted cuadra-transition-colors","aria-label":"Copy code",children:[!t&&d.jsx(Ot,{className:"cuadra-h-4 cuadra-w-4"}),t&&d.jsx(Et,{className:"cuadra-h-4 cuadra-w-4"})]})]})},La=({copiedDuration:e=3e3}={})=>{const[r,t]=w.useState(!1);return{isCopied:r,copyToClipboard:i=>{i&&navigator.clipboard.writeText(i).then(()=>{t(!0),setTimeout(()=>t(!1),e)})}}},Ma=be.unstable_memoizeMarkdownComponents({h1:({className:e,...r})=>d.jsx("h1",{className:S("cuadra-mb-6 cuadra-scroll-m-20 cuadra-text-2xl cuadra-font-normal cuadra-tracking-tight last:cuadra-mb-0 font-brand",e),...r}),h2:({className:e,...r})=>d.jsx("h2",{className:S("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h3:({className:e,...r})=>d.jsx("h3",{className:S("cuadra-mb-3 cuadra-mt-5 cuadra-scroll-m-20 cuadra-text-lg cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h4:({className:e,...r})=>d.jsx("h4",{className:S("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h5:({className:e,...r})=>d.jsx("h5",{className:S("cuadra-my-4 cuadra-text-lg cuadra-font-normal first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h6:({className:e,...r})=>d.jsx("h6",{className:S("cuadra-my-4 cuadra-font-normal first:cuadra-mb-0 font-brand",e),...r}),p:({className:e,...r})=>d.jsx("p",{className:S("cuadra-mb-5 cuadra-mt-5 cuadra-leading-7 first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),a:({className:e,...r})=>d.jsx("a",{className:S("cuadra-text-primary cuadra-font-medium cuadra-underline cuadra-underline-offset-4 font-brand",e),...r}),blockquote:({className:e,...r})=>d.jsx("blockquote",{className:S("cuadra-border-l-2 cuadra-pl-6 cuadra-italic font-brand",e),...r}),ul:({className:e,...r})=>d.jsx("ul",{className:S("cuadra-my-5 cuadra-ml-6 cuadra-list-disc [&>li]:cuadra-mt-2 font-brand",e),...r}),ol:({className:e,...r})=>d.jsx("ol",{className:S("cuadra-my-5 cuadra-ml-6 cuadra-list-decimal [&>li]:cuadra-mt-2 font-brand",e),...r}),hr:({className:e,...r})=>d.jsx("hr",{className:S("cuadra-my-5 cuadra-border-b",e),...r}),table:({className:e,...r})=>d.jsx("table",{className:S("cuadra-my-5 cuadra-w-full cuadra-border-separate cuadra-border-spacing-0 cuadra-overflow-y-auto font-brand",e),...r}),th:({className:e,...r})=>d.jsx("th",{className:S("cuadra-bg-muted cuadra-px-4 cuadra-py-2 cuadra-text-left cuadra-font-normal first:cuadra-rounded-tl-lg last:cuadra-rounded-tr-lg [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),td:({className:e,...r})=>d.jsx("td",{className:S("cuadra-border-b cuadra-border-l cuadra-px-4 cuadra-py-2 cuadra-text-left last:cuadra-border-r [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),tr:({className:e,...r})=>d.jsx("tr",{className:S("cuadra-m-0 cuadra-border-b cuadra-p-0 first:cuadra-border-t [&:last-child>td:first-child]:cuadra-rounded-bl-lg [&:last-child>td:last-child]:cuadra-rounded-br-lg",e),...r}),sup:({className:e,...r})=>d.jsx("sup",{className:S("[&>a]:cuadra-text-xs [&>a]:cuadra-no-underline font-brand",e),...r}),pre:({className:e,...r})=>d.jsx("pre",{className:S("cuadra-overflow-x-auto cuadra-rounded-b-lg !cuadra-rounded-t-none cuadra-bg-muted cuadra-p-4 cuadra-text-foreground font-brand",e),...r}),code:function({className:r,...t}){const n=be.useIsMarkdownCodeBlock();return d.jsx("code",{className:S(!n&&"cuadra-bg-muted cuadra-rounded cuadra-border cuadra-font-normal font-brand",r),...t})},CodeHeader:Na}),Ue=["Sending question…","Understanding your need…","Scanning data…","Comparing results…","Composing answer…"];function Pa({active:e}){const[r,t]=w.useState(0);return w.useEffect(()=>{if(!e){t(0);return}const n=window.setInterval(()=>{t(i=>i>=Ue.length-1?(window.clearInterval(n),i):i+1)},2500);return()=>window.clearInterval(n)},[e]),e?d.jsxs("span",{className:"cuadra-text-xs cuadra-text-muted-foreground cuadra-font-brand",children:["Thinking… ",Ue[r]]}):null}function Be({welcomeTitle:e="Hi, how can I help you today?",welcomeSubtitle:r="Start exploring our platform and discover what you can build.",extraTopPadding:t,suggestions:n}={}){const i=T.useThreadRuntime(),[o,a]=w.useState(!1),[l,s]=w.useState(null),[c,h]=w.useState(!1);return w.useEffect(()=>{if(!i){a(!1);return}try{const u=i?.store;if(!u){a(!1);return}const p=u.subscribe?.(f=>{const b=f?.threadId,x=f?.messages||[],k=f?.isLoadingHistory||!1,y=x.length;b&&b!==l&&s(b),a(k&&y===0);const j=x.some(v=>v.role==="assistant"&&!!v.content&&(Array.isArray(v.content)?v.content.some(A=>typeof A=="object"&&A?.text?A.text.trim().length>0:!1):typeof v.content=="string"?v.content.trim().length>0:!1));h(j)}),g=u.getState?.();if(g){const f=g?.threadId,b=g?.messages||[],x=g?.isLoadingHistory||!1,k=b.length;f&&f!==l&&s(f),a(x&&k===0);const C=b.some(j=>j.role==="assistant"&&!!j.content&&(Array.isArray(j.content)?j.content.some(v=>typeof v=="object"&&v?.text?v.text.trim().length>0:!1):typeof j.content=="string"?j.content.trim().length>0:!1));h(C)}return()=>{p&&p()}}catch{a(!1)}},[i,l]),d.jsxs(T.ThreadPrimitive.Root,{className:"cuadra-bg-inherit cuadra-flex cuadra-flex-col cuadra-w-full cuadra-h-full",children:[d.jsx(T.ThreadPrimitive.Viewport,{className:"cuadra-w-full cuadra-bg-inherit cuadra-px-4 cuadra-flex-1 cuadra-min-h-0 cuadra-overflow-y-auto cuadra-relative scrollbar-thin cuadra-pt-4",style:t?{paddingTop:t}:void 0,children:o?d.jsx("div",{className:"cuadra-absolute cuadra-inset-0 cuadra-flex cuadra-items-center cuadra-justify-center",children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:[d.jsx(Ke,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"}),d.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground font-brand",children:"Loading messages..."})]})}):d.jsxs(d.Fragment,{children:[d.jsx(T.ThreadPrimitive.Empty,{children:d.jsx(Da,{title:e,subtitle:r,suggestions:n})}),d.jsx(T.ThreadPrimitive.Messages,{components:{UserMessage:Ea,AssistantMessage:Ra}}),d.jsx(T.ThreadPrimitive.If,{running:!0,children:!c&&d.jsx("div",{className:"cuadra-mt-2 cuadra-max-w-2xl",children:d.jsx(Pa,{active:!0})})})]})}),d.jsx("div",{className:"cuadra-w-full cuadra-mt-3 cuadra-border-t cuadra-border-border cuadra-pt-4",children:d.jsxs(T.ComposerPrimitive.Root,{className:"cuadra-relative !cuadra-relative cuadra-flex-1 cuadra-w-full",children:[d.jsx(T.ComposerPrimitive.Input,{asChild:!0,children:d.jsx("textarea",{rows:3,placeholder:"Type your message...",className:"cuadra-flex cuadra-min-h-[80px] cuadra-w-full cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-base placeholder:cuadra-text-muted-foreground focus-visible:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-resize-none cuadra-pr-10 font-brand",style:{paddingRight:"2.5rem",fontSize:"1rem"}})}),d.jsx(T.ComposerPrimitive.Send,{asChild:!0,children:d.jsx("button",{className:"!cuadra-absolute !cuadra-bottom-2 !cuadra-right-2 cuadra-size-8 cuadra-bg-secondary cuadra-text-secondary-foreground cuadra-rounded-md cuadra-shadow-sm hover:cuadra-bg-secondary/90 disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed cuadra-flex cuadra-items-center cuadra-justify-center",style:{position:"absolute",bottom:"0.5rem",right:"0.5rem"},"aria-label":"Send message",type:"button",children:d.jsx(Pt,{className:"cuadra-h-4 cuadra-w-4"})})})]})})]})}function Da({title:e,subtitle:r,suggestions:t}){const n=T.useAssistantApi(),i=async o=>{try{n.composer().setText(o),await new Promise(a=>setTimeout(a,10)),n.composer().send()}catch{}};return d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-h-full cuadra-py-12 cuadra-px-4 cuadra-overflow-y-auto scrollbar-hide",children:d.jsxs("div",{className:"cuadra-text-center cuadra-max-w-3xl cuadra-w-full cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-min-h-full",children:[d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-mb-8",children:[d.jsx("h2",{className:"cuadra-text-lg cuadra-font-normal cuadra-text-foreground cuadra-mb-2 font-brand",children:e}),d.jsx("p",{className:"cuadra-text-muted-foreground font-brand",children:r})]}),t&&t.length>0&&d.jsx("div",{className:"cuadra-grid cuadra-grid-cols-2 cuadra-gap-2 cuadra-pb-4 cuadra-w-full cuadra-max-w-2xl",children:t.map((o,a)=>d.jsx("button",{type:"button",onClick:()=>i(o.prompt),className:"cuadra-w-full cuadra-text-center cuadra-px-4 cuadra-py-3 cuadra-rounded-lg cuadra-border cuadra-border-border cuadra-bg-background cuadra-text-sm font-brand cuadra-cursor-pointer focus:cuadra-outline-none focus:cuadra-ring-0",style:{borderWidth:"1px"},children:o.prompt},`suggestion-${a}`))})]})})}function Ea(){return d.jsx(T.MessagePrimitive.Root,{className:"cuadra-grid cuadra-w-full cuadra-auto-rows-auto cuadra-grid-cols-[minmax(72px,1fr)_auto] cuadra-gap-y-2 cuadra-py-3 [&:where(>*)]:cuadra-col-start-2",children:d.jsx("div",{className:"cuadra-bg-muted cuadra-text-foreground cuadra-col-start-2 cuadra-row-start-2 cuadra-max-w-[calc(42rem*0.8)] cuadra-break-words cuadra-rounded-3xl cuadra-px-5 cuadra-py-2.5 font-brand",style:{maxWidth:"calc(42rem * 0.8)",borderRadius:"1.5rem",backgroundColor:"hsl(var(--muted))",color:"hsl(var(--foreground))",paddingLeft:"1.25rem",paddingRight:"1.25rem",paddingTop:"0.625rem",paddingBottom:"0.625rem",wordBreak:"break-word"},children:d.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:e})=>d.jsx(yt,{content:e||""})}})})})}function Ra(){return d.jsx(T.MessagePrimitive.Root,{className:"cuadra-relative cuadra-grid cuadra-w-full cuadra-grid-cols-[auto_auto_1fr] cuadra-grid-rows-[auto_1fr] cuadra-py-3",children:d.jsx("div",{className:"cuadra-text-foreground cuadra-col-span-2 cuadra-col-start-2 cuadra-row-start-1 cuadra-my-1.5 cuadra-max-w-[90%] cuadra-break-words cuadra-leading-7 font-brand",style:{maxWidth:"90%",marginTop:"0.375rem",marginBottom:"0.375rem"},children:d.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:e})=>d.jsx(yt,{content:e||""})}})})})}function _a({onThreadSelect:e}){const r=T.useThreadListItem(),t=T.useThread(x=>x.threadId),[n,i]=w.useState(null),o=r?.id===t,a=n===r?.id,[l,s]=w.useState(!1),[c,h]=w.useState(r?.title||""),[u,p]=w.useState(!1),[g,f]=w.useState(!1),b=async()=>{if(!r?.remoteId||!c||c===r.title){s(!1);return}try{f(!0);const x=window.__cuadraThreadListAdapter;x&&typeof x.rename=="function"&&await x.rename(r.remoteId,c),s(!1),p(!1)}catch{s(!1),p(!1)}finally{f(!1)}};return w.useEffect(()=>{r?.title&&!l&&h(r.title)},[r?.title,l]),r?d.jsx(T.ThreadListItemPrimitive.Root,{className:`group cuadra-relative cuadra-flex cuadra-items-center cuadra-gap-3 cuadra-rounded-lg cuadra-transition-colors cuadra-cursor-pointer cuadra-border cuadra-mb-2 ${o?"cuadra-bg-muted cuadra-border-border":"cuadra-border-transparent hover:cuadra-bg-muted hover:cuadra-border-border"}`,style:{marginBottom:"0.5rem"},onMouseEnter:()=>i(r.id),onMouseLeave:()=>i(null),children:d.jsxs(T.ThreadListItemPrimitive.Trigger,{className:"cuadra-p-3 cuadra-flex-1 cuadra-flex cuadra-items-center cuadra-justify-between cuadra-w-full cuadra-min-w-0 cuadra-cursor-pointer",onClick:()=>e?.(),children:[d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-min-w-0 cuadra-flex-1 cuadra-items-start cuadra-text-left",children:l?d.jsx("input",{className:"cuadra-flex cuadra-w-full cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-sm placeholder:cuadra-text-muted-foreground focus-visible:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 font-brand",value:c,onChange:x=>h(x.target.value),onKeyDown:x=>{x.key==="Enter"&&b(),x.key==="Escape"&&(s(!1),h(r.title||""))},disabled:g,autoFocus:!0,onClick:x=>x.stopPropagation()}):d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-truncate font-brand",children:(r.title?.length||0)>60?`${r.title?.slice(0,60)}…`:r.title||"Chat"}),r.updatedAt&&d.jsx("span",{className:"cuadra-text-xs cuadra-text-muted-foreground cuadra-mt-1 font-brand",children:new Date(r.updatedAt).toLocaleDateString()})]})}),d.jsx("div",{className:"cuadra-ml-2 cuadra-flex-shrink-0 cuadra-w-6 cuadra-h-6 cuadra-flex cuadra-items-center cuadra-justify-center",children:(a||o||u)&&d.jsxs("div",{className:"cuadra-relative",children:[d.jsx("button",{className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-background/50 cuadra-transition-colors",onClick:x=>{x.stopPropagation(),p(!u)},"aria-label":"Thread options",children:d.jsx(Bt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"})}),u&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:()=>p(!1)}),d.jsx("div",{className:"cuadra-absolute cuadra-right-0 cuadra-top-8 cuadra-z-50 cuadra-bg-background cuadra-border cuadra-border-border cuadra-rounded-lg cuadra-shadow-lg cuadra-min-w-[120px] cuadra-overflow-hidden",children:l?d.jsx("button",{className:"cuadra-w-full cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted cuadra-transition-colors font-brand",onClick:x=>{x.stopPropagation(),b()},disabled:g,children:"Save"}):d.jsxs(d.Fragment,{children:[d.jsx("button",{className:"cuadra-w-full cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted cuadra-transition-colors font-brand",onClick:x=>{x.stopPropagation(),s(!0),h(r.title||""),p(!1)},children:"Rename"}),d.jsx("div",{className:"cuadra-border-t cuadra-border-border"}),d.jsx(T.ThreadListItemPrimitive.Delete,{asChild:!0,children:d.jsx("button",{className:"cuadra-w-full cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left cuadra-text-destructive hover:cuadra-bg-muted cuadra-transition-colors font-brand",onClick:x=>{x.stopPropagation(),p(!1)},children:"Delete"})})]})})]})]})})]})}):null}function We({onThreadSelect:e}){return d.jsxs(T.ThreadListPrimitive.Root,{className:"!cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-full cuadra-w-80",style:{borderRightWidth:"1px"},children:[d.jsx("div",{className:"cuadra-border-b cuadra-border-border cuadra-flex cuadra-items-center cuadra-justify-between cuadra-transition-all cuadra-duration-300 cuadra-h-16 cuadra-px-4",children:d.jsx("h3",{className:"cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-text-nowrap font-brand",children:"Chat History"})}),d.jsxs("div",{className:"cuadra-flex-1 cuadra-overflow-y-auto cuadra-p-2 scrollbar-thin",children:[d.jsx(T.ThreadListPrimitive.New,{className:"group cuadra-relative cuadra-flex cuadra-items-center cuadra-gap-3 cuadra-p-3 cuadra-rounded-lg cuadra-cursor-pointer cuadra-transition-colors cuadra-border cuadra-border-transparent hover:cuadra-bg-muted hover:cuadra-border-border",onClick:()=>e?.(),children:d.jsx("div",{className:"cuadra-flex-1 cuadra-min-w-0",children:d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[d.jsx(Vt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"}),d.jsx("h4",{className:"cuadra-text-sm cuadra-font-normal cuadra-text-foreground font-brand",children:"New Chat"})]})})}),d.jsx("div",{className:"cuadra-my-2 cuadra-border-t cuadra-border-border"}),d.jsx(T.ThreadListPrimitive.Items,{components:{ThreadListItem:r=>d.jsx(_a,{...r,onThreadSelect:e})}})]})]})}const Fa=`
19
19
  @keyframes rotate {
20
20
  100% { transform: rotate(1turn); }
21
21
  }
22
- `,ge=({children:e,className:r="",paddingX:t="px-0",paddingY:n="py-0",borderSizePx:i=4,style:o,contentStyle:a,rotating:l=!1})=>d.jsxs(d.Fragment,{children:[d.jsx("style",{children:Fa}),d.jsxs("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-xl cuadra-overflow-hidden ${r}`,style:{padding:i,...o},children:[d.jsx("div",{className:"cuadra-absolute md:cuadra-rounded-xl",style:l?{left:"-100%",top:"-100%",width:"300%",height:"300%",backgroundImage:"conic-gradient(#ff8308, #ff5043, #392bd5, #ff8308)",backgroundRepeat:"no-repeat",backgroundSize:"cover",backgroundPosition:"center",animation:"rotate 4s linear infinite"}:{backgroundImage:"linear-gradient(to right, #ff8308, #ff5043, #392bd5)",backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat",top:"0",left:"0",width:"100%",height:"100%"}}),d.jsx("div",{className:`cuadra-relative cuadra-bg-background cuadra-h-full cuadra-z-10 cuadra-flex cuadra-flex-col cuadra-overflow-hidden ${t} ${n}`,style:{borderRadius:"calc(0.75rem - 4px)",...a},children:e})]})]}),za=({className:e="",theme:r="system"})=>{const t=()=>{if(typeof window>"u")return"light";if(r==="system"){const a=localStorage.getItem("theme");return a||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")}return r},[n,i]=w.useState(t);w.useEffect(()=>{r!=="system"&&i(r)},[r]),w.useEffect(()=>{const a=document.documentElement;a.classList.remove("light","dark"),a.classList.add(n),r==="system"&&localStorage.setItem("theme",n)},[n,r]);const o=()=>{r==="system"&&i(a=>a==="light"?"dark":"light")};return d.jsx("button",{type:"button","aria-label":"Toggle theme",onClick:o,disabled:r!=="system",className:`cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-8 cuadra-w-8 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-transition-colors disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed ${e}`,children:d.jsx(zt,{className:`cuadra-h-4 cuadra-w-4 cuadra-transition-colors ${n==="dark"?"cuadra-text-primary":"cuadra-text-gray-400"}`})})},He=({currentModel:e,models:r,modelsLoading:t,modelsError:n,onModelChange:i,hideModelSelector:o=!1,showThemeToggle:a=!0,theme:l="system",onMobileMenuClick:s,showMobileMenuButton:c=!1})=>{const[h,u]=w.useState(!1),p=w.useRef(null);w.useEffect(()=>{const f=b=>{p.current&&!p.current.contains(b.target)&&u(!1)};return h&&document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f)}},[h]);const g=r.find(f=>f.id===e);return d.jsxs("div",{className:"cuadra-h-16 cuadra-px-4 cuadra-border-b cuadra-border-border cuadra-flex cuadra-items-center cuadra-justify-between cuadra-bg-background",children:[d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[c&&d.jsx("button",{type:"button",onClick:s,className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-8 cuadra-w-8 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-transition-colors disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed md:cuadra-hidden","aria-label":"Toggle thread list",children:d.jsx(qt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-foreground"})}),a&&d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:d.jsx(za,{theme:l})})]}),d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 md:cuadra-ml-0 cuadra-ml-auto",children:[!o&&d.jsx("label",{className:"cuadra-hidden md:cuadra-inline cuadra-text-sm cuadra-text-muted-foreground cuadra-font-brand",children:"Model"}),o?null:t?d.jsx("div",{className:"cuadra-w-48 cuadra-rounded-md cuadra-border cuadra-border-border cuadra-px-3 cuadra-py-2 cuadra-bg-muted",children:d.jsx("span",{className:"cuadra-text-muted-foreground cuadra-text-sm cuadra-font-brand",children:"Loading..."})}):n?d.jsx("div",{className:"cuadra-w-48 cuadra-rounded-md cuadra-border cuadra-border-destructive cuadra-px-3 cuadra-py-2 cuadra-bg-destructive/10",children:d.jsx("span",{className:"cuadra-text-destructive cuadra-text-sm cuadra-font-brand",children:"Failed to load models"})}):d.jsxs("div",{ref:p,className:"cuadra-relative cuadra-w-48",children:[d.jsxs("button",{type:"button",onClick:()=>u(!h),disabled:t||r.length===0||!!n,className:"cuadra-flex cuadra-h-10 cuadra-w-full cuadra-items-center cuadra-justify-between cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-sm placeholder:cuadra-text-muted-foreground focus:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-font-brand",children:[d.jsx("span",{className:g?"cuadra-text-foreground":"cuadra-text-muted-foreground",children:g?.name||"Select model"}),d.jsx(_t,{className:"cuadra-ml-2 cuadra-h-4 cuadra-w-4 cuadra-opacity-50"})]}),h&&r.length>0&&d.jsx("div",{className:"cuadra-absolute cuadra-z-50 cuadra-mt-1 cuadra-w-full cuadra-min-w-[8rem] cuadra-overflow-hidden cuadra-rounded-md glass-popover cuadra-text-popover-foreground cuadra-animate-in fade-in-80 cuadra-border cuadra-border-border cuadra-bg-popover cuadra-shadow-md",children:d.jsx("div",{className:"cuadra-p-1",children:r.map(f=>d.jsxs("button",{type:"button",onClick:()=>{i(f.id),u(!1)},className:`cuadra-relative cuadra-flex cuadra-w-full cuadra-cursor-pointer cuadra-select-none cuadra-items-center cuadra-rounded-sm cuadra-py-1.5 cuadra-pl-8 cuadra-pr-2 cuadra-text-sm cuadra-outline-none focus:cuadra-bg-secondary focus:cuadra-text-secondary-foreground font-brand cuadra-transition-colors ${e===f.id?"cuadra-bg-secondary cuadra-text-secondary-foreground":"hover:cuadra-bg-secondary/50"}`,children:[e===f.id&&d.jsx("span",{className:"cuadra-absolute cuadra-left-2 cuadra-flex cuadra-h-3.5 cuadra-w-3.5 cuadra-items-center cuadra-justify-center",children:d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",fill:"none",viewBox:"0 0 16 16",children:d.jsx("path",{fill:"currentColor",fillRule:"evenodd",d:"M6.47 10.03a.75.75 0 0 1-1.06-1.06l2-2a.75.75 0 0 1 1.06 0l2 2a.75.75 0 1 1-1.06 1.06L8 9.06l-1.53 1.53Z",clipRule:"evenodd"})})}),d.jsx("span",{children:f.name})]},f.id))})})]})]})]})},$a=w.createContext(void 0),xe=({children:e,value:r})=>d.jsx($a.Provider,{value:r,children:e});function Oa(){w.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const r=document.createElement("div");r.className="cuadra-flex",document.body.appendChild(r);const t=window.getComputedStyle(r).display==="flex";if(document.body.removeChild(r),t)return;const n=document.createElement("link");n.setAttribute("data-cuadra-uikit","true"),n.rel="stylesheet",n.type="text/css";const i=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:de&&de.tagName.toUpperCase()==="SCRIPT"&&de.src||new URL("index.cjs",document.baseURI).href).href];let o=!1;for(const a of i)if(n.href=a,n.onload=()=>{o=!0},n.onerror=()=>{},document.head.appendChild(n),o)break},[])}const Ua=({config:e})=>{Oa();const{baseUrl:r,proxyUrl:t,sessionToken:n,mode:i="multiChat",modelMode:o="fixed",modelId:a,onModelChange:l,ephemeral:s=!1,systemPrompt:c,initialThreadId:h,welcomeTitle:u,welcomeSubtitle:p,extraTopPadding:g,suggestions:f,showThemeToggle:b=!0,theme:x="system",onError:k,onChatCreated:y,onThreadIdUpdate:C}=e,[j,v]=w.useState(!1),T=t||r||"",L=!!t,O=w.useMemo(()=>new Ve(T,n||void 0,L,e.tenantId),[T,n,L,e.tenantId]),[z,m]=w.useState(null),[M,V]=w.useState(!1),[$,X]=w.useState(null),[Ct,Te]=w.useState(!1);w.useEffect(()=>{i==="multiChat"&&Te(!0)},[i]);const W=w.useCallback(async()=>{if(o==="selector"){V(!0),X(null);try{const S=await O.listModels();m(S)}catch(S){X(S instanceof Error?S:new Error("Failed to load models"))}finally{V(!1)}}},[O,o]);w.useEffect(()=>{o==="selector"&&W()},[o,W]),w.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=W),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[W]);const[D,Ie]=w.useState(o==="fixed"&&a||null),Ae=w.useRef(D),G=w.useCallback(S=>{const Z=Ae.current;Ie(S),Ae.current=S,l?.(S),Z!==null&&Z!==S&&i==="multiChat"&&setTimeout(()=>{const H=window.__cuadraThreadListRuntime;if(H?.threads?.switchToNewThread)try{H.threads.switchToNewThread()}catch{}else if(H?.threads?.createThread)try{H.threads.createThread()}catch{}else if(H?.switchToNewThread)try{H.switchToNewThread()}catch{}},100)},[l,i]);w.useEffect(()=>{if(o==="selector"&&z?.items&&z.items.length>0&&!D){const S=z.items[0];if(S?.id){const Z=S.id;Ie(Z),l?.(Z)}}},[o,z?.items,D,l]);const vt=o==="fixed"?!!a:!!D,te=w.useMemo(()=>(z?.items||[]).filter(S=>S?.id&&S?.displayName).map(S=>({id:S.id,name:S.displayName})),[z]),ce=w.useMemo(()=>({currentModelId:D||"",models:te,modelsLoading:M,modelsError:$,onModelChange:G,refetchModels:W}),[D,te,M,$,G,W]);return o==="selector"&&M||i==="multiChat"&&Ct?d.jsx(xe,{value:ce,children:d.jsx(ge,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx(Ke,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):o==="selector"&&!vt&&$?d.jsx(xe,{value:ce,children:d.jsx(ge,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:d.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):d.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:d.jsx(xe,{value:ce,children:d.jsx(Qt,{baseUrl:L?T:r||T,sessionToken:n,isProxyMode:L,tenantId:e.tenantId,mode:i,modelMode:o,modelId:D||a||void 0,onModelChange:G,ephemeral:s,systemPrompt:c,initialThreadId:h,onError:k,onChatCreated:y,onThreadIdUpdate:C,onChatsLoaded:()=>{i==="multiChat"&&Te(!1)},children:d.jsx(ge,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${e.containerClass||""}`,borderSizePx:4,style:{height:"100%"},children:d.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},children:i==="multiChat"?d.jsxs(d.Fragment,{children:[j&&typeof document<"u"&&Ne.createPortal(d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-bg-black/50 cuadra-z-40 md:cuadra-hidden",onClick:()=>v(!1)}),document.body),typeof document<"u"&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-hidden md:cuadra-block !cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-full cuadra-w-80 cuadra-relative",style:{borderRightWidth:"1px",height:"100%"},children:d.jsx(We,{onThreadSelect:()=>v(!1)})}),j&&Ne.createPortal(d.jsx("div",{className:"cuadra-block md:cuadra-hidden !cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-screen cuadra-w-80 cuadra-fixed cuadra-z-50 cuadra-top-0 cuadra-left-0 cuadra-translate-x-0",style:{borderRightWidth:"1px"},children:d.jsx(We,{onThreadSelect:()=>v(!1)})}),document.body)]}),d.jsxs("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:[o==="selector"&&d.jsx(He,{currentModel:D||"",models:te,modelsLoading:M,modelsError:$,onModelChange:G,showThemeToggle:b,theme:x,onMobileMenuClick:()=>v(!j),showMobileMenuButton:i==="multiChat"}),d.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0 cuadra-space-y-4 cuadra-p-4",children:d.jsx(Be,{welcomeTitle:u,welcomeSubtitle:p,extraTopPadding:g,suggestions:f})})]})]}):d.jsxs("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:[o==="selector"&&d.jsx(He,{currentModel:D||"",models:te,modelsLoading:M,modelsError:$,onModelChange:G,showThemeToggle:b,theme:x}),d.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0 cuadra-space-y-4 cuadra-p-4",children:d.jsx(Be,{welcomeTitle:u,welcomeSubtitle:p,extraTopPadding:g,suggestions:f})})]})})})})})})};function Ba(e){const r={baseUrl:e.baseUrl,proxyUrl:e.proxyUrl,sessionToken:e.sessionToken||null,tenantId:e.tenantId,mode:e.mode||"multiChat",modelMode:e.modelMode||"fixed",modelId:e.modelId,onModelChange:e.onModelChange,ephemeral:e.ephemeral,systemPrompt:e.systemPrompt,initialThreadId:e.initialThreadId,language:e.language,welcomeTitle:e.welcomeTitle,welcomeSubtitle:e.welcomeSubtitle,extraTopPadding:e.extraTopPadding,suggestions:e.suggestions,onError:e.onError,onChatCreated:e.onChatCreated,onThreadIdUpdate:e.onThreadIdUpdate,showThemeToggle:e.showThemeToggle,theme:e.theme,containerClass:e.className};return d.jsx(Ua,{config:r})}exports.CuadraChat=Ba;
22
+ `,ge=({children:e,className:r="",paddingX:t="px-0",paddingY:n="py-0",borderSizePx:i=4,style:o,contentStyle:a,rotating:l=!1})=>d.jsxs(d.Fragment,{children:[d.jsx("style",{children:Fa}),d.jsxs("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-xl cuadra-overflow-hidden ${r}`,style:{padding:i,...o},children:[d.jsx("div",{className:"cuadra-absolute md:cuadra-rounded-xl",style:l?{left:"-100%",top:"-100%",width:"300%",height:"300%",backgroundImage:"conic-gradient(#ff8308, #ff5043, #392bd5, #ff8308)",backgroundRepeat:"no-repeat",backgroundSize:"cover",backgroundPosition:"center",animation:"rotate 4s linear infinite"}:{backgroundImage:"linear-gradient(to right, #ff8308, #ff5043, #392bd5)",backgroundSize:"cover",backgroundPosition:"center",backgroundRepeat:"no-repeat",top:"0",left:"0",width:"100%",height:"100%"}}),d.jsx("div",{className:`cuadra-relative cuadra-bg-background cuadra-h-full cuadra-z-10 cuadra-flex cuadra-flex-col cuadra-overflow-hidden ${t} ${n}`,style:{borderRadius:"calc(0.75rem - 4px)",...a},children:e})]})]}),za=({className:e="",theme:r="system"})=>{const t=()=>{if(typeof window>"u")return"light";if(r==="system"){const a=localStorage.getItem("theme");return a||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")}return r},[n,i]=w.useState(t);w.useEffect(()=>{r!=="system"&&i(r)},[r]),w.useEffect(()=>{const a=document.documentElement;a.classList.remove("light","dark"),a.classList.add(n),r==="system"&&localStorage.setItem("theme",n)},[n,r]);const o=()=>{r==="system"&&i(a=>a==="light"?"dark":"light")};return d.jsx("button",{type:"button","aria-label":"Toggle theme",onClick:o,disabled:r!=="system",className:`cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-8 cuadra-w-8 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-transition-colors disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed ${e}`,children:d.jsx(zt,{className:`cuadra-h-4 cuadra-w-4 cuadra-transition-colors ${n==="dark"?"cuadra-text-primary":"cuadra-text-gray-400"}`})})},He=({currentModel:e,models:r,modelsLoading:t,modelsError:n,onModelChange:i,hideModelSelector:o=!1,showThemeToggle:a=!0,theme:l="system",onMobileMenuClick:s,showMobileMenuButton:c=!1})=>{const[h,u]=w.useState(!1),p=w.useRef(null);w.useEffect(()=>{const f=b=>{p.current&&!p.current.contains(b.target)&&u(!1)};return h&&document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f)}},[h]);const g=r.find(f=>f.id===e);return d.jsxs("div",{className:"cuadra-h-16 cuadra-px-4 cuadra-border-b cuadra-border-border cuadra-flex cuadra-items-center cuadra-justify-between cuadra-bg-background",children:[d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[c&&d.jsx("button",{type:"button",onClick:s,className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-8 cuadra-w-8 cuadra-rounded-full cuadra-bg-muted hover:cuadra-bg-muted/80 cuadra-transition-colors disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed md:cuadra-hidden","aria-label":"Toggle thread list",children:d.jsx(qt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-foreground"})}),a&&d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:d.jsx(za,{theme:l})})]}),d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 md:cuadra-ml-0 cuadra-ml-auto",children:[!o&&d.jsx("label",{className:"cuadra-hidden md:cuadra-inline cuadra-text-sm cuadra-text-muted-foreground cuadra-font-brand",children:"Model"}),o?null:t?d.jsx("div",{className:"cuadra-w-48 cuadra-rounded-md cuadra-border cuadra-border-border cuadra-px-3 cuadra-py-2 cuadra-bg-muted",children:d.jsx("span",{className:"cuadra-text-muted-foreground cuadra-text-sm cuadra-font-brand",children:"Loading..."})}):n?d.jsx("div",{className:"cuadra-w-48 cuadra-rounded-md cuadra-border cuadra-border-destructive cuadra-px-3 cuadra-py-2 cuadra-bg-destructive/10",children:d.jsx("span",{className:"cuadra-text-destructive cuadra-text-sm cuadra-font-brand",children:"Failed to load models"})}):d.jsxs("div",{ref:p,className:"cuadra-relative cuadra-w-48",children:[d.jsxs("button",{type:"button",onClick:()=>u(!h),disabled:t||r.length===0||!!n,className:"cuadra-flex cuadra-h-10 cuadra-w-full cuadra-items-center cuadra-justify-between cuadra-rounded-md cuadra-border cuadra-border-input cuadra-bg-background cuadra-px-3 cuadra-py-2 cuadra-text-sm placeholder:cuadra-text-muted-foreground focus:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-font-brand",children:[d.jsx("span",{className:g?"cuadra-text-foreground":"cuadra-text-muted-foreground",children:g?.name||"Select model"}),d.jsx(_t,{className:"cuadra-ml-2 cuadra-h-4 cuadra-w-4 cuadra-opacity-50"})]}),h&&r.length>0&&d.jsx("div",{className:"cuadra-absolute cuadra-z-50 cuadra-mt-1 cuadra-w-full cuadra-min-w-[8rem] cuadra-overflow-hidden cuadra-rounded-md glass-popover cuadra-text-popover-foreground cuadra-animate-in fade-in-80 cuadra-border cuadra-border-border cuadra-bg-popover cuadra-shadow-md",children:d.jsx("div",{className:"cuadra-p-1",children:r.map(f=>d.jsxs("button",{type:"button",onClick:()=>{i(f.id),u(!1)},className:`cuadra-relative cuadra-flex cuadra-w-full cuadra-cursor-pointer cuadra-select-none cuadra-items-center cuadra-rounded-sm cuadra-py-1.5 cuadra-pl-8 cuadra-pr-2 cuadra-text-sm cuadra-outline-none focus:cuadra-bg-secondary focus:cuadra-text-secondary-foreground font-brand cuadra-transition-colors ${e===f.id?"cuadra-bg-secondary cuadra-text-secondary-foreground":"hover:cuadra-bg-secondary/50"}`,children:[e===f.id&&d.jsx("span",{className:"cuadra-absolute cuadra-left-2 cuadra-flex cuadra-h-3.5 cuadra-w-3.5 cuadra-items-center cuadra-justify-center",children:d.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",fill:"none",viewBox:"0 0 16 16",children:d.jsx("path",{fill:"currentColor",fillRule:"evenodd",d:"M6.47 10.03a.75.75 0 0 1-1.06-1.06l2-2a.75.75 0 0 1 1.06 0l2 2a.75.75 0 1 1-1.06 1.06L8 9.06l-1.53 1.53Z",clipRule:"evenodd"})})}),d.jsx("span",{children:f.name})]},f.id))})})]})]})]})},$a=w.createContext(void 0),xe=({children:e,value:r})=>d.jsx($a.Provider,{value:r,children:e});function Oa(){w.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const r=document.createElement("div");r.className="cuadra-flex",document.body.appendChild(r);const t=window.getComputedStyle(r).display==="flex";if(document.body.removeChild(r),t)return;const n=document.createElement("link");n.setAttribute("data-cuadra-uikit","true"),n.rel="stylesheet",n.type="text/css";const i=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:de&&de.tagName.toUpperCase()==="SCRIPT"&&de.src||new URL("index.cjs",document.baseURI).href).href];let o=!1;for(const a of i)if(n.href=a,n.onload=()=>{o=!0},n.onerror=()=>{},document.head.appendChild(n),o)break},[])}const Ua=({config:e})=>{Oa();const{baseUrl:r,proxyUrl:t,sessionToken:n,mode:i="multiChat",modelMode:o="fixed",modelId:a,onModelChange:l,ephemeral:s=!1,systemPrompt:c,initialThreadId:h,welcomeTitle:u,welcomeSubtitle:p,extraTopPadding:g,suggestions:f,showThemeToggle:b=!0,theme:x="system",onError:k,onChatCreated:y,onThreadIdUpdate:C}=e,[j,v]=w.useState(!1),A=t||r||"",P=!!t,O=w.useMemo(()=>new Ve(A,n||void 0,P),[A,n,P]),[z,m]=w.useState(null),[L,V]=w.useState(!1),[$,G]=w.useState(null),[Ct,Te]=w.useState(!1);w.useEffect(()=>{i==="multiChat"&&Te(!0)},[i]);const W=w.useCallback(async()=>{if(o==="selector"){V(!0),G(null);try{const I=await O.listModels();m(I)}catch(I){G(I instanceof Error?I:new Error("Failed to load models"))}finally{V(!1)}}},[O,o]);w.useEffect(()=>{o==="selector"&&W()},[o,W]),w.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=W),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[W]);const[D,Ae]=w.useState(o==="fixed"&&a||null),Se=w.useRef(D),Z=w.useCallback(I=>{const J=Se.current;Ae(I),Se.current=I,l?.(I),J!==null&&J!==I&&i==="multiChat"&&setTimeout(()=>{const H=window.__cuadraThreadListRuntime;if(H?.threads?.switchToNewThread)try{H.threads.switchToNewThread()}catch{}else if(H?.threads?.createThread)try{H.threads.createThread()}catch{}else if(H?.switchToNewThread)try{H.switchToNewThread()}catch{}},100)},[l,i]);w.useEffect(()=>{if(o==="selector"&&z?.items&&z.items.length>0&&!D){const I=z.items[0];if(I?.id){const J=I.id;Ae(J),l?.(J)}}},[o,z?.items,D,l]);const vt=o==="fixed"?!!a:!!D,ee=w.useMemo(()=>(z?.items||[]).filter(I=>I?.id&&I?.displayName).map(I=>({id:I.id,name:I.displayName})),[z]),ce=w.useMemo(()=>({currentModelId:D||"",models:ee,modelsLoading:L,modelsError:$,onModelChange:Z,refetchModels:W}),[D,ee,L,$,Z,W]);return o==="selector"&&L||i==="multiChat"&&Ct?d.jsx(xe,{value:ce,children:d.jsx(ge,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx(Ke,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):o==="selector"&&!vt&&$?d.jsx(xe,{value:ce,children:d.jsx(ge,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:d.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):d.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:d.jsx(xe,{value:ce,children:d.jsx(Xt,{baseUrl:P?A:r||A,sessionToken:n,isProxyMode:P,mode:i,modelMode:o,modelId:D||a||void 0,onModelChange:Z,ephemeral:s,systemPrompt:c,initialThreadId:h,onError:k,onChatCreated:y,onThreadIdUpdate:C,onChatsLoaded:()=>{i==="multiChat"&&Te(!1)},children:d.jsx(ge,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${e.containerClass||""}`,borderSizePx:4,style:{height:"100%"},children:d.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},children:i==="multiChat"?d.jsxs(d.Fragment,{children:[j&&typeof document<"u"&&Ne.createPortal(d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-bg-black/50 cuadra-z-40 md:cuadra-hidden",onClick:()=>v(!1)}),document.body),typeof document<"u"&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-hidden md:cuadra-block !cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-full cuadra-w-80 cuadra-relative",style:{borderRightWidth:"1px",height:"100%"},children:d.jsx(We,{onThreadSelect:()=>v(!1)})}),j&&Ne.createPortal(d.jsx("div",{className:"cuadra-block md:cuadra-hidden !cuadra-border-r cuadra-border-border cuadra-flex cuadra-flex-col cuadra-bg-background cuadra-transition-all cuadra-duration-300 cuadra-ease-in-out cuadra-h-screen cuadra-w-80 cuadra-fixed cuadra-z-50 cuadra-top-0 cuadra-left-0 cuadra-translate-x-0",style:{borderRightWidth:"1px"},children:d.jsx(We,{onThreadSelect:()=>v(!1)})}),document.body)]}),d.jsxs("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:[o==="selector"&&d.jsx(He,{currentModel:D||"",models:ee,modelsLoading:L,modelsError:$,onModelChange:Z,showThemeToggle:b,theme:x,onMobileMenuClick:()=>v(!j),showMobileMenuButton:i==="multiChat"}),d.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0 cuadra-space-y-4 cuadra-p-4",children:d.jsx(Be,{welcomeTitle:u,welcomeSubtitle:p,extraTopPadding:g,suggestions:f})})]})]}):d.jsxs("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:[o==="selector"&&d.jsx(He,{currentModel:D||"",models:ee,modelsLoading:L,modelsError:$,onModelChange:Z,showThemeToggle:b,theme:x}),d.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0 cuadra-space-y-4 cuadra-p-4",children:d.jsx(Be,{welcomeTitle:u,welcomeSubtitle:p,extraTopPadding:g,suggestions:f})})]})})})})})})};function Ba(e){const r={baseUrl:e.baseUrl,proxyUrl:e.proxyUrl,sessionToken:e.sessionToken||null,mode:e.mode||"multiChat",modelMode:e.modelMode||"fixed",modelId:e.modelId,onModelChange:e.onModelChange,ephemeral:e.ephemeral,systemPrompt:e.systemPrompt,initialThreadId:e.initialThreadId,language:e.language,welcomeTitle:e.welcomeTitle,welcomeSubtitle:e.welcomeSubtitle,extraTopPadding:e.extraTopPadding,suggestions:e.suggestions,onError:e.onError,onChatCreated:e.onChatCreated,onThreadIdUpdate:e.onThreadIdUpdate,showThemeToggle:e.showThemeToggle,theme:e.theme,containerClass:e.className};return d.jsx(Ua,{config:r})}exports.CuadraChat=Ba;
23
23
  //# sourceMappingURL=index.cjs.map