@theoremjs/studio 0.3.4-next.757.gde44a4d → 0.3.4-next.761.g22f8dca

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/compile.d.ts +3 -3
  2. package/compile.js +70 -101
  3. package/cookbooks/catalog.js +14 -28
  4. package/draft.d.ts +30 -28
  5. package/draft.js +26 -12
  6. package/guardrail-probe.js +1 -30
  7. package/mod.d.ts +2 -2
  8. package/mod.js +2 -2
  9. package/package.json +4 -4
  10. package/page/assets/{ConsoleFrame-D309UtSL.js → ConsoleFrame-BML2qu-M.js} +1 -1
  11. package/page/assets/{MenuBottomSheet-CVBLnUiO.js → MenuBottomSheet-CUd8PJUL.js} +1 -1
  12. package/page/assets/{SchemaFields-muOTQM8x.js → SchemaFields-BAqgDS0V.js} +1 -1
  13. package/page/assets/{ToolResultCharts-Bhesjbc4.js → ToolResultCharts-B89bOlhx.js} +1 -1
  14. package/page/assets/{Toolbar-t4I6MDV_.js → Toolbar-IjJyRVuq.js} +1 -1
  15. package/page/assets/{TraceInspector-BqEGN_46.js → TraceInspector-BPuA0rJm.js} +1 -1
  16. package/page/assets/{TraceOverview-DLEqvRF2.js → TraceOverview-D-fMveFI.js} +1 -1
  17. package/page/assets/{_virtual_studio-type-sources-Cc4WAdgD.js → _virtual_studio-type-sources-_88V0ngH.js} +37 -44
  18. package/page/assets/browser-connection-C1_PJcSQ.js +1 -0
  19. package/page/assets/browser-engine-C8QugF1C.js +16 -0
  20. package/page/assets/browser-transport-Dna_HxBt.js +45 -0
  21. package/page/assets/compile-BV0Yh4CT.js +2 -0
  22. package/page/assets/{encode-files-CeZxxjYd.js → encode-files-CCet4LKE.js} +1 -1
  23. package/page/assets/{export-agent-CYZqQ4ll.js → export-agent-C9RKqF8V.js} +8 -8
  24. package/page/assets/{guardrail-tester-D-_i4Zuj.js → guardrail-tester-B_NNaWwk.js} +1 -1
  25. package/page/assets/index-BYDlXF8Q.css +1 -0
  26. package/page/assets/{index-DuTrjzLN.js → index-DDOBYjLr.js} +73 -73
  27. package/page/assets/live-messages-tG47aB12.js +1 -0
  28. package/page/assets/{prompt-row-CIxkqX9Q.js → prompt-row-DmXTmPM0.js} +2 -2
  29. package/page/assets/reader-SzTjS7rw.js +5 -0
  30. package/page/assets/{registry-DP0ArymS.js → registry-BrmnEhgs.js} +1 -1
  31. package/page/assets/schema-BztznKB7.js +3 -0
  32. package/page/assets/{shaped-data-DCfLI4gb.js → shaped-data-D15FDUcH.js} +3 -3
  33. package/page/assets/{stub-REBz-ZC7.js → stub-CJG-5zBe.js} +1 -1
  34. package/page/assets/studio-code-pane-DrdLqe75.js +10 -0
  35. package/page/assets/{studio-console-DHgwXKne.js → studio-console-Qv_3jkIz.js} +1 -1
  36. package/page/assets/{studio-decision-B_EdxnvG.js → studio-decision-CX3MLpTH.js} +1 -1
  37. package/page/assets/{studio-embedding-mZIx4qHD.js → studio-embedding-CW_pjRjJ.js} +1 -1
  38. package/page/assets/{studio-host-console-BmB0sSsX.js → studio-host-console-B7Mx-m0f.js} +2 -2
  39. package/page/assets/{studio-labels-BRouZt4M.js → studio-labels-B_pBoFqS.js} +1 -1
  40. package/page/assets/studio-live-DdMC-L2A.js +5 -0
  41. package/page/assets/{studio-map-8aIk_pdY.js → studio-map-Dm7XWVyE.js} +1 -1
  42. package/page/assets/{studio-trace-replay-BaF2UAqT.js → studio-trace-replay-DHmsgLaT.js} +1 -1
  43. package/page/assets/{studio-type-checker-JZuu4iVI.js → studio-type-checker-o2Q6t4mP.js} +1 -1
  44. package/page/assets/{tool-schema-BwaPiLtT.js → tool-schema-D26IAEC3.js} +1 -1
  45. package/page/assets/trace-record-jocyYEPa.js +1 -0
  46. package/page/assets/tree-BCzsUTaF.js +3 -0
  47. package/page/assets/{turn-client-B3jV7UKH.js → turn-client-eM8VIbMd.js} +1 -1
  48. package/page/assets/{types-BDx4pnrt.js → types-CfC3vRXO.js} +1 -1
  49. package/page/assets/{use-one-call-BKLi6fk_.js → use-one-call-CRLKviQ-.js} +1 -1
  50. package/page/assets/{workspace-B6d08n7C.js → workspace-3igDw3Tv.js} +1 -1
  51. package/page/index.html +17 -17
  52. package/prompt-doc.d.ts +1 -1
  53. package/prompt-doc.js +2 -2
  54. package/read-source.js +26 -39
  55. package/section-notes.d.ts +1 -2
  56. package/section-notes.js +1 -2
  57. package/system-markup.d.ts +1 -1
  58. package/system-markup.js +1 -1
  59. package/ui/lib/export-agent.js +9 -26
  60. package/ui/lib/studio-page.d.ts +9 -16
  61. package/ui/lib/studio-page.js +28 -38
  62. package/ui/profile-editor.js +48 -104
  63. package/ui/prompt-editor.d.ts +1 -1
  64. package/ui/prompt-editor.js +11 -11
  65. package/ui/prompt-line-node.d.ts +5 -5
  66. package/ui/prompt-line-node.js +9 -9
  67. package/ui/prompt-row.d.ts +3 -3
  68. package/ui/prompt-row.js +3 -3
  69. package/ui/studio-compare.d.ts +4 -2
  70. package/ui/studio-compare.js +6 -5
  71. package/ui/studio-live.d.ts +1 -1
  72. package/ui/studio-live.js +2 -2
  73. package/ui/studio-runner.d.ts +4 -3
  74. package/ui/studio-runner.js +9 -9
  75. package/ui/studio-screen.js +5 -2
  76. package/ui/studio.css +3 -3
  77. package/page/assets/browser-connection-159CdeHX.js +0 -1
  78. package/page/assets/browser-engine-Fi7MROTb.js +0 -16
  79. package/page/assets/browser-transport-C_sHZVPa.js +0 -45
  80. package/page/assets/compile-iB2CAmRL.js +0 -2
  81. package/page/assets/index-DakRjE8R.css +0 -1
  82. package/page/assets/live-messages-D-SPyR3e.js +0 -1
  83. package/page/assets/reader-DtOL_I1x.js +0 -5
  84. package/page/assets/schema-Cv4HAfBT.js +0 -3
  85. package/page/assets/studio-code-pane-DEBuOivy.js +0 -10
  86. package/page/assets/studio-live-Cy09vyLv.js +0 -5
  87. package/page/assets/trace-record--uEnDt_D.js +0 -1
  88. package/page/assets/tree-CL4ETBd5.js +0 -3
  89. package/slot-values.d.ts +0 -2
  90. package/slot-values.js +0 -22
@@ -0,0 +1 @@
1
+ import{C as e,E as t,O as n,b as r,c as i,d as a,h as o,v as s,x as c}from"./schemas-D7cgkv3L.js";import{Jn as l,Vn as u,Zn as d,tr as f}from"./tool-schema-D26IAEC3.js";import{C as p,M as m,O as h,j as g}from"./reader-SzTjS7rw.js";import{n as _}from"./trace-schema--4IGmLeE.js";import{w as v}from"./turn-client-eM8VIbMd.js";var y=c({type:s(`open`),history:a(d).optional(),options:e(t(),t()).optional(),context:n().optional(),stated:h.optional(),model:t().optional(),effort:t().optional(),resume:c({providerState:f,awayMs:r().nonnegative()}).optional(),host:e(t(),n()).optional()}),b=o(`type`,[c({type:s(`audio`),data:t()}),c({type:s(`video`),data:t(),mimeType:t()}),c({type:s(`text`),text:t()}),c({type:s(`context`),context:n()}),c({type:s(`executeTool`),callId:t().min(1),operationId:t().min(1).max(256),decision:i(v).optional(),input:n().optional(),secret:t().optional(),output:n().optional(),grantId:t().min(1).optional(),unanswered:s(!0).optional()})]),x={ready:c({type:s(`ready`),profile:t().optional(),sessionId:t().optional()}),events:c({type:s(`events`),events:a(n())}),trace:c({type:s(`trace`),record:_}),error:c({type:s(`error`)}).and(p),executeToolResult:o(`status`,[c({type:s(`executeToolResult`),callId:t().min(1),operationId:t().min(1).max(256),status:s(`dispatched`),grantId:t().min(1),arguments:e(t(),n())}),c({type:s(`executeToolResult`),callId:t(),status:s(`settled`),operationId:t().min(1).max(256)}),c({type:s(`executeToolResult`),callId:t(),status:s(`gated`),operationId:t().min(1).max(256),gate:l}),c({type:s(`executeToolResult`),callId:t(),status:s(`refused`),operationId:t().min(1).max(256),body:p})])};function S(e){let t=g(x,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>m(u,e))}:t}export{y as n,S as r,b as t};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{g as a,m as o}from"./tokens.stylex-BpCwr7Mf.js";import{a as s,i as c}from"./useAnnounceRenderedText-aqUr1P16.js";import{n as l}from"./VStack-CkVMcNiK.js";import{n as u}from"./StackItem-CQviqAfM.js";import{t as d}from"./mergeProps-ptS-gIMz.js";import{a as f,c as p,i as m,o as h,s as g,u as _}from"./fieldParts-Dtp1EoJQ.js";import{S as v,c as y,r as b,t as x}from"./Icon-3c9WmPTH.js";import{f as ee}from"./useResolvedRequired-68GOSl0j.js";import{d as te}from"./useTooltip-BaCjTHk-.js";import{l as ne,n as re,o as ie,t as ae}from"./IconButton-BeI1pXEZ.js";import{c as oe,t as se}from"./CheckboxInput-MMjt4mDv.js";import{t as ce}from"./Dialog-DUNBjHOI.js";import{t as le}from"./Tooltip-DrSpWxD8.js";import{t as ue}from"./createReactComponent-CZwsv6DD.js";import{h as de}from"./compile-iB2CAmRL.js";import{i as fe,n as pe,r as me,t as he}from"./TextInput-D1GkClqk.js";import{t as ge}from"./IconFilter-BO98ezum.js";import{i as _e}from"./types-BDx4pnrt.js";import{t as ve}from"./useClipboard-BC4cMFBa.js";import{l as ye,n as be,r as xe}from"./highlightRanges-yrVxbmkN.js";import{t as Se}from"./Toolbar-t4I6MDV_.js";import{$ as Ce,F as we,Q as Te,V as Ee,X as De,Z as Oe,d as ke,f as Ae,ft as je,i as Me,lt as Ne,p as Pe,u as Fe}from"./index-DuTrjzLN.js";var Ie=ue(`outline`,`share-off`,`ShareOff`,[[`path`,{d:`M3 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-0`}],[`path`,{d:`M15 6a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-1`}],[`path`,{d:`M15.861 15.896a3 3 0 0 0 4.265 4.22m.578 -3.417a3.012 3.012 0 0 0 -1.507 -1.45`,key:`svg-2`}],[`path`,{d:`M8.7 10.7l1.336 -.688m2.624 -1.352l2.64 -1.36`,key:`svg-3`}],[`path`,{d:`M8.7 13.3l6.6 3.4`,key:`svg-4`}],[`path`,{d:`M3 3l18 18`,key:`svg-5`}]]),S=e(i(),1);function Le(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function C(e,...t){throw Le(e,...t)}function Re(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);n.search=r.toString(),console.warn(`Minified Lexical warning #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function ze(){return typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0}var Be=ze();function Ve(){return Be&&`documentMode`in document?document.documentMode:null}var He=Ve();function Ue(e){return Be&&e.test(navigator.platform)}function We(e){return Be&&e.test(navigator.userAgent)}var Ge=Ue(/Mac|iPod|iPhone|iPad/),Ke=We(/^(?!.*Seamonkey)(?=.*Firefox).*/i);function qe(){return!(!Be||!(`InputEvent`in window)||He)&&`getTargetRanges`in new window.InputEvent(`input`)}var Je=qe();function Ye(){return Be&&!window.MSStream&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&navigator.maxTouchPoints>1)}var Xe=Ye(),Ze=We(/Android/),Qe=We(/Version\/[\d.]+.*Safari/)&&!Ze,$e=We(/^(?=.*Chrome).*/i),et=Be&&Ze&&$e,tt=We(/AppleWebKit\/[\d.]+/)&&Ge&&!$e;function nt(){return 2047}var rt=nt(),it=Qe||Xe||tt?`\xA0`:`​`,at=`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{g as a,m as o}from"./tokens.stylex-BpCwr7Mf.js";import{a as s,i as c}from"./useAnnounceRenderedText-aqUr1P16.js";import{n as l}from"./VStack-CkVMcNiK.js";import{n as u}from"./StackItem-CQviqAfM.js";import{t as d}from"./mergeProps-ptS-gIMz.js";import{a as f,c as p,i as m,o as h,s as g,u as _}from"./fieldParts-Dtp1EoJQ.js";import{S as v,c as y,r as b,t as x}from"./Icon-3c9WmPTH.js";import{f as ee}from"./useResolvedRequired-68GOSl0j.js";import{d as te}from"./useTooltip-BaCjTHk-.js";import{l as ne,n as re,o as ie,t as ae}from"./IconButton-BeI1pXEZ.js";import{c as oe,t as se}from"./CheckboxInput-MMjt4mDv.js";import{t as ce}from"./Dialog-DUNBjHOI.js";import{t as le}from"./Tooltip-DrSpWxD8.js";import{t as ue}from"./createReactComponent-CZwsv6DD.js";import{m as de}from"./compile-BV0Yh4CT.js";import{i as fe,n as pe,r as me,t as he}from"./TextInput-D1GkClqk.js";import{t as ge}from"./IconFilter-BO98ezum.js";import{i as _e}from"./types-CfC3vRXO.js";import{t as ve}from"./useClipboard-BC4cMFBa.js";import{l as ye,n as be,r as xe}from"./highlightRanges-yrVxbmkN.js";import{t as Se}from"./Toolbar-IjJyRVuq.js";import{$ as Ce,F as we,Q as Te,V as Ee,X as De,Z as Oe,d as ke,f as Ae,ft as je,i as Me,lt as Ne,p as Pe,u as Fe}from"./index-DDOBYjLr.js";var Ie=ue(`outline`,`share-off`,`ShareOff`,[[`path`,{d:`M3 12a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-0`}],[`path`,{d:`M15 6a3 3 0 1 0 6 0a3 3 0 1 0 -6 0`,key:`svg-1`}],[`path`,{d:`M15.861 15.896a3 3 0 0 0 4.265 4.22m.578 -3.417a3.012 3.012 0 0 0 -1.507 -1.45`,key:`svg-2`}],[`path`,{d:`M8.7 10.7l1.336 -.688m2.624 -1.352l2.64 -1.36`,key:`svg-3`}],[`path`,{d:`M8.7 13.3l6.6 3.4`,key:`svg-4`}],[`path`,{d:`M3 3l18 18`,key:`svg-5`}]]),S=e(i(),1);function Le(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function C(e,...t){throw Le(e,...t)}function Re(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);n.search=r.toString(),console.warn(`Minified Lexical warning #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function ze(){return typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0}var Be=ze();function Ve(){return Be&&`documentMode`in document?document.documentMode:null}var He=Ve();function Ue(e){return Be&&e.test(navigator.platform)}function We(e){return Be&&e.test(navigator.userAgent)}var Ge=Ue(/Mac|iPod|iPhone|iPad/),Ke=We(/^(?!.*Seamonkey)(?=.*Firefox).*/i);function qe(){return!(!Be||!(`InputEvent`in window)||He)&&`getTargetRanges`in new window.InputEvent(`input`)}var Je=qe();function Ye(){return Be&&!window.MSStream&&(/iPad|iPhone|iPod/.test(navigator.userAgent)||/Macintosh/.test(navigator.userAgent)&&navigator.maxTouchPoints>1)}var Xe=Ye(),Ze=We(/Android/),Qe=We(/Version\/[\d.]+.*Safari/)&&!Ze,$e=We(/^(?=.*Chrome).*/i),et=Be&&Ze&&$e,tt=We(/AppleWebKit\/[\d.]+/)&&Ge&&!$e;function nt(){return 2047}var rt=nt(),it=Qe||Xe||tt?`\xA0`:`​`,at=`
2
2
 
3
3
  `,ot=Ke?`\xA0`:it,st={bold:1,capitalize:1024,code:16,highlight:128,italic:2,lowercase:256,strikethrough:4,subscript:32,superscript:64,underline:8,uppercase:512},ct={directionless:1,unmergeable:2},lt={center:2,end:6,justify:4,left:1,right:3,start:5};function ut(e){let t={};for(let n of Object.keys(e))t[e[n]]=n;return t}var dt=ut(lt),ft={normal:0,segmented:2,token:1},pt=ut(ft),mt=Symbol.for(`@lexical/ctrlOrOtherKey`),ht=`$config`;function gt(){return Bu()._blockCursorElement}function _t(e){return e!==null&&e.nodeType===1&&e.hasAttribute(`data-lexical-slot`)}var vt=tt||Xe||Qe;function yt(){let e=H().createElement(`img`);e.setAttribute(`data-lexical-decorator-boundary`,`true`),e.alt=``;for(let[t,n]of[[`position`,`absolute`],[`width`,`0px`],[`height`,`0px`],[`border`,`0px`],[`margin`,`0px`],[`padding`,`0px`]])e.style.setProperty(t,n,`important`);return e}function bt(e){return e!==null&&e.nodeType===1&&e.hasAttribute(`data-lexical-decorator-boundary`)}var xt=class e{element;before;after;constructor(e,t,n){this.element=e,this.before=t||null,this.after=n||null}withBefore(t){return new e(this.element,t,this.after)}withAfter(t){return new e(this.element,this.before,t)}withElement(t){return this.element===t?this:new e(t,this.before,this.after)}insertChild(e){let t=this.getInsertionAnchor();return t!==null&&t.parentElement!==this.element&&C(357),this.element.insertBefore(e,t),this}removeChild(e){return e.parentElement!==this.element&&C(358),this.element.removeChild(e),this}replaceChild(e,t){return t.parentElement!==this.element&&C(359),this.element.replaceChild(e,t),this}getFirstChild(){let e=this.getFirstChildAnchor(),t=e?e.nextSibling:this.element.firstChild;return t===this.getInsertionAnchor()?null:t}getFirstChildAnchor(){return this.after}resolveLeafPosition(e,t,n){if(this.element===e)return t===e&&n===0?`before`:`after`;let r=St(e,this.element);if(r===null)return`after`;let i=Array.prototype.indexOf.call(e.childNodes,r);if(i<0)return`after`;if(t===e)return n<=i?`before`:`after`;let a=St(e,t);if(a===null)return`after`;let o=Array.prototype.indexOf.call(e.childNodes,a);return o>=0&&o<=i?`before`:`after`}getInsertionAnchor(){return this.before}};function St(e,t){let n=t;for(;n!==null&&n.parentNode!==e;)n=n.parentNode;return n}var Ct=class e extends xt{withBefore(t){return new e(this.element,t,this.after)}withAfter(t){return new e(this.element,this.before,t)}withElement(t){return this.element===t?this:new e(t,this.before,this.after)}getInsertionAnchor(){return super.getInsertionAnchor()||this.getManagedLineBreak()||this.getDecoratorBoundaryAnchor(`trailing`)}getFirstChildAnchor(){let e=super.getFirstChildAnchor(),t=e?e.nextSibling:this.element.firstChild;for(;_t(t);)e=t,t=t.nextSibling;bt(t)&&(e=t,t=t.nextSibling);let n=e?e.nextSibling:this.element.firstChild;return n!==null&&n===gt()?n:e}getDecoratorBoundaryAnchor(e){let t;if(e===`leading`){let e=super.getFirstChildAnchor();for(t=e?e.nextSibling:this.element.firstChild;_t(t);)t=t.nextSibling}else t=this.before?this.before.previousSibling:this.element.lastChild,t!==null&&t===gt()&&(t=t.previousSibling);return bt(t)?t:null}setDecoratorBoundaryAnchor(e,t){let n=this.getDecoratorBoundaryAnchor(e);if(t!==(n!==null)){if(n!==null)this.element.removeChild(n);else if(e===`leading`){let e=this.getFirstChildAnchor();this.element.insertBefore(yt(),e?e.nextSibling:this.element.firstChild)}else this.element.insertBefore(yt(),this.before)}}getManagedLineBreak(){return this.element.__lexicalLineBreak||null}setManagedLineBreak(e){let t=this.element,n=this.after===null?t.firstChild:this.after.nextSibling,r=e===`empty`&&_t(n)?null:e;if(t.__lexicalLastChildKind!==r){if(t.__lexicalLastChildKind=r,r===null)this.removeManagedLineBreak();else{let e=r===`decorator`&&vt;this.insertManagedLineBreak(e)}}}removeManagedLineBreak(){let e=this.getManagedLineBreak();if(e){let t=this.element,n=e.nodeName===`IMG`?e.nextSibling:null;n&&t.removeChild(n),t.removeChild(e),t.__lexicalLineBreak=void 0}}insertManagedLineBreak(e){let t=this.getManagedLineBreak();if(t){if(e===(t.nodeName===`IMG`))return;this.removeManagedLineBreak()}let n=this.element,r=this.before||this.getDecoratorBoundaryAnchor(`trailing`),i=H().createElement(`br`);if(i.setAttribute(`data-lexical-managed-linebreak`,`true`),n.insertBefore(i,r),e){let e=H().createElement(`img`);e.setAttribute(`data-lexical-managed-linebreak`,`true`),e.style.setProperty(`display`,`inline`,`important`),e.style.setProperty(`border`,`0px`,`important`),e.style.setProperty(`margin`,`0px`,`important`),e.alt=``,n.insertBefore(e,i),n.__lexicalLineBreak=e}else n.__lexicalLineBreak=i}getFirstChildOffset(){let e=this.getFirstChild(),t=this.getInsertionAnchor(),n=0;for(let r=this.element.firstChild;r!==null&&r!==e&&r!==t;r=r.nextSibling)n++;return n}resolveChildIndex(e,t,n,r){if(n===this.element){let t=this.getFirstChildOffset(),n=gt(),i=this.element.childNodes,a=Math.min(r,i.length),o=0;for(let e=t;e<a;e++)i[e]!==n&&o++;return[e,Math.min(o,e.getChildrenSize())]}let i=wt(t,n);i.push(r);let a=wt(t,this.element),o=e.getIndexWithinParent();for(let e=0;e<a.length;e++){let t=i[e],n=a[e];if(t===void 0||t<n)break;if(t>n){o+=1;break}}return[e.getParentOrThrow(),o]}};function wt(e,t){let n=[],r=t;for(;r!==e&&r!==null;r=r.parentNode){let e=0;for(let t=r.previousSibling;t!==null;t=t.previousSibling)e++;n.push(e)}return r!==e&&C(225),n.reverse()}function Tt(){let e;try{e=`0.52.0+prod.esm`}catch{}return e??`"<unknown>+source"`}var Et=Tt(),Dt=class{_front=new Set;_back=new Set;_cache;get size(){return this._front.size+this._back.size}addBack(e){return delete this._cache,this._front.has(e)||this._back.add(e),this}addFront(e){return delete this._cache,this._back.has(e)||this._front.add(e),this}delete(e){return delete this._cache,this._front.delete(e)||this._back.delete(e)}toArray(){let e=Array.from(this._front).reverse();for(let t of this._back)e.push(t);return e}toReadonlyArray(){return this._cache=this._cache||this.toArray(),this._cache}[Symbol.iterator](){return this.toReadonlyArray()[Symbol.iterator]()}},Ot=null;function kt(e,t=1e3){return e instanceof At?e.clone():e.size<t?new Map(e):new At().init(new Map(e),void 0,e.size)}var At=class e{_mutable=!1;_old=void 0;_nursery=void 0;_size=0;clone(){return this._mutable=!1,new e().init(this._old,this._nursery,this._size)}init(e,t,n){return this._old=e,this._nursery=t,this._size=n,this}get size(){return this._size}has(e){return this.get(e)!==void 0}getWithTombstone(e){let t=this._nursery&&this._nursery.get(e);return t===void 0?this._old&&this._old.get(e):t}get(e){let t=this.getWithTombstone(e);return t===Ot?void 0:t}shouldCompact(){return this._nursery!==void 0&&2*this._nursery.size>this._size}getNursery(){return this._mutable&&this._nursery||(this.compact(),this._nursery=new Map(this._nursery),this._mutable=!0),this._nursery}compact(e=!1){if(this._nursery&&this._nursery.size>0&&(e||this.shouldCompact())){let e=new Map(this._old);for(let[t,n]of this._nursery)n===Ot?e.delete(t):e.set(t,n);this._old=e,this._nursery=void 0}return this._mutable=!1,this}set(e,t){let n=this.getWithTombstone(e);if(n===t)return this;let r=this.getNursery();return n!==Ot&&n!==void 0||(this._size++,n===Ot&&r.delete(e)),r.set(e,t),this}delete(e){let t=this.has(e);return t&&(this.getNursery().set(e,Ot),this._size--),t}getOrInsert(e,t){let n=this.get(e);return n===void 0?(this.set(e,t),t):n}getOrInsertComputed(e,t){let n=this.get(e);if(n!==void 0)return n;let r=t(e);return this.set(e,r),r}clear(){this._mutable=!1,this._old=void 0,this._nursery=void 0,this._size=0}*keys(){for(let e of this.entries())yield e[0]}*values(){for(let e of this.entries())yield e[1]}*entries(){let e=this._nursery,t=this._old;if(e){if(t)for(let n of t){let t=n[0],r=e.get(t);r!==Ot&&(r!==void 0&&(n[1]=r),yield n)}for(let n of e)n[1]===Ot||t&&t.has(n[0])||(yield n)}else t&&(yield*t)}forEach(e,t){t!==void 0&&(e=e.bind(t));for(let[t,n]of this.entries())e(n,t,this)}get[Symbol.toStringTag](){return`GenMap`}[Symbol.iterator](){return this.entries()}},jt=!1;function Mt(e,t,...n){let r=jt,i;try{jt=e,i=t()}finally{jt=r}var a;return(a=i)===null||typeof a!=`object`&&typeof a!=`function`||typeof a.then!=`function`||C(421),i}function Nt(){return jt}function Pt(e){let t=e.exportJSON(jt),n=e.constructor;return t.type!==n.getType()&&C(130,n.name),N(e)&&!Array.isArray(t.children)&&C(59,n.name),t}function Ft(e,t,n,r,i,a){if(N(e)){let o=e.getFirstChild();for(;o!==null;){let e=o.__key;o.__parent===t&&((N(o)||Pd(o)&&o.__slots!==null)&&Ft(o,e,n,r,i,a),n.has(e)||a.delete(e),i.push(e)),o=o.getNextSibling()}}for(let o of Pd(e)&&e.__slots!==null?e.__slots.values():[]){let e=r.get(o);e!==void 0&&Fd(e)&&e.__slotHost===t&&((N(e)||Pd(e)&&e.__slots!==null)&&Ft(e,o,n,r,i,a),n.has(o)||a.delete(o),i.push(o))}}var It=!1,Lt=0;function Rt(e){Lt=e.timeStamp}function zt(e,t,n){let r=e.nodeName===`BR`,i=t.__lexicalLineBreak;return i&&(e===i||r&&e.previousSibling===i)||r&&wl(e,n)!==void 0}function Bt(e,t,n){let r=hu(au(n)),i=r&&wu(r,n._rootElement),a=null,o=null;i!==null&&i.anchorNode===e&&(a=i.anchorOffset,o=i.focusOffset);let s=e.nodeValue;s!==null&&Il(t,s,a,o,!1)}function Vt(e,t,n){if(k(e)){let t=e.anchor.getNode();if(t.is(n)&&e.format!==t.getFormat())return!1}return fl(t)&&n.isAttached()}function Ht(e,t,n){for(let r=e;r&&!ed(r);r=Zl(r)){let e=wl(r,t);if(e!==void 0){let t=L(e,n);if(t)return P(t)||!U(r)?void 0:[r,t]}}}function Ut(e,t,n){It=!0;let r=performance.now()-Lt>100;try{Qs(e,()=>{let i=j()||function(e){return e.read(`latest`,()=>{let e=j();return e===null?null:e.clone()})}(e),a=new Map,o=e._editorState,s=e._blockCursorElement,c=!1,l=``;for(let n=0;n<t.length;n++){let u=t[n],d=u.type,f=u.target,p=Ht(f,e,o);if(!p)continue;let[m,h]=p;if(d===`characterData`)r&&O(h)&&fl(f)&&Vt(i,f,h)&&Bt(f,h,e);else if(d===`childList`){c=!0;let t=u.addedNodes;for(let n=0;n<t.length;n++){let r=t[n],i=Sl(r),a=r.parentNode;if(!(a==null||r===s||i!==null||zt(r,a,e)||bt(r)||e._slotsUsed&&U(r)&&r.hasAttribute(`data-lexical-slot`)||ed(r))){if(Ke){let e=(U(r)?r.innerText:null)||r.nodeValue;e&&(l+=e)}a.removeChild(r)}}let n=u.removedNodes,r=n.length;if(r>0){let t=0;for(let i=0;i<r;i++){let r=n[i];zt(r,f,e)||s===r?(f.appendChild(r),t++):bt(r)&&t++}r!==t&&a.set(m,h)}}}if(a.size>0)for(let[t,n]of a)n.reconcileObservedMutation(t,e);let u=n.takeRecords();if(u.length>0){for(let t=0;t<u.length;t++){let n=u[t],r=n.addedNodes,i=n.target;for(let t=0;t<r.length;t++){let n=r[t],a=n.parentNode;a==null||n.nodeName!==`BR`||zt(n,i,e)||a.removeChild(n)}}n.takeRecords()}i!==null&&(c&&z(i),Ke&&Yl(e)&&i.insertRawText(l))})}finally{It=!1}}function Wt(e){let t=e._observer;t!==null&&Ut(e,t.takeRecords(),t)}function Gt(e){(function(e){Lt===0&&au(e).addEventListener(`textInput`,Rt,!0)})(e),e._observer=new MutationObserver((t,n)=>{Ut(e,t,n)})}function Kt(e,t,n){let{isEqual:r}=e;return t===n||r!==void 0&&r(t,n)}function qt(e,t){return Kt(e,t,e.defaultValue)}function Jt(e){return typeof e==`object`&&!!e}function Yt(e,t){let n=en(e,t).getter;return Jt(n)&&n.getterTable!==void 0||C(405,t),$t(n.getterTable)}function Xt(e,t){let n=en(e,t).setter;return Jt(n)&&n.setterTable!==void 0||C(406,t),$t(n.setterTable)}function Zt(e,t,n){let{meta:r}=en(e,t);for(let e=0;;)if(r.kind===`aliased`){if(e===n)return $t(r.aliases);e++,r=r.inner.meta}else r.kind===`nullable`||r.kind===`optional`?r=r.inner.meta:r.kind===`array`?r=r.item.meta:C(407,t,String(n))}function Qt(e,t){let n=en(e,t),{setter:r}=n;Jt(r)&&r.setterTable!==void 0||C(408,t);let i=String(n.defaultValue);return un(r.setterTable,i)||C(409,t,i),r.setterTable[i]}function $t(e){return Object.assign(Object.create(null),e)}function en(e,t){let n=e.get(t);return n===void 0&&C(410,t),n}function tn(e,t,n,r,i){i!==void 0&&nn.add(i);let a=n===void 0,o=a?e(void 0):n;return a&&on(o),Object.assign(e,{accepts:i,defaultValue:o,isEqual:r,meta:t})}var nn=new WeakSet,rn=new WeakSet;function an(e){return typeof e==`object`&&e&&rn.add(e),e}function on(e){if(typeof e==`object`&&e&&!Object.isFrozen(e)&&!rn.has(e)){Object.freeze(e);for(let t of Object.values(e))on(t)}}function sn(e){let{isEqual:t}=e;return t===void 0?void 0:(e,n)=>e==null||n==null?e===n:t(e,n)}function cn(e,t){return n=>t(n)||ln(e,n)}function ln(e,t){let{accepts:n}=e;return n===void 0?function(e,t){let{accepts:n}=e;if(n!==void 0)return ln(e,t)?{parsed:e(t)}:void 0;let r=e(t);return qt(e,r)&&t!==e.defaultValue?void 0:{parsed:r}}(e,t)!==void 0:n.call(e,t)}function un(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function dn(e=``){return tn(t=>typeof t==`string`?t:e,{kind:`string`},void 0,void 0,e=>typeof e==`string`)}var fn=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function pn(e=0,t={}){let{integer:n,clamp:r}=t,i=n&&t.min!==void 0?Math.ceil(t.min):t.min,a=n&&t.max!==void 0?Math.floor(t.max):t.max,o=e=>typeof e==`string`&&fn.test(e)?Number(e):e,s=e=>typeof e==`number`&&Number.isFinite(e)&&(!n||Number.isInteger(e)),c=e=>s(e)&&(i===void 0||e>=i)&&(a===void 0||e<=a);return tn(t=>{let n=o(t);return r&&s(n)?i!==void 0&&n<i?i:a!==void 0&&n>a?a:n:c(n)?n:e},{clamp:r,integer:n,kind:`number`,max:a,min:i},void 0,void 0,e=>r?s(o(e)):c(o(e)))}function mn(e=!1){return tn(t=>typeof t==`boolean`?t:e,{kind:`boolean`},void 0,void 0,e=>typeof e==`boolean`)}function hn(e,...t){let n=an(t.length===0?e[0]:t[0]),r=new Set(e);return tn(e=>e!==void 0&&r.has(e)?e:n,{kind:`enum`,values:e},n,void 0,e=>r.has(e)&&(e!==void 0||n===void 0))}function gn(e,t={}){let{defaultAsNull:n}=t;return tn(t=>{if(t==null)return null;let r=e(t);return n&&qt(e,r)?null:r},{defaultAsNull:n,inner:e,kind:`nullable`},void 0,sn(e),cn(e,e=>e==null))}function _n(e,t={}){let{omitDefault:n}=t;return tn(t=>{if(t===void 0)return;let r=e(t);return n&&qt(e,r)?void 0:r},{inner:e,kind:`optional`,omitDefault:n},void 0,sn(e),cn(e,e=>e===void 0))}function vn(){return e=>function(e){return{meta:{fields:e,kind:`node`}}}(e)}function yn(e,t){let n=e=>typeof e==`string`&&un(t,e);return tn(r=>n(r)?t[r]:e(r),{aliases:t,inner:e,kind:`aliased`},e.defaultValue,e.isEqual,t=>n(t)||ln(e,t))}function bn(e){return tn(t=>{if(!Array.isArray(t))return[];let n=Array(t.length);for(let r=0;r<t.length;r++)n[r]=e(t[r]);return n},{item:e,kind:`array`},void 0,(t,n)=>{if(!Array.isArray(t)||!Array.isArray(n)||t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!Kt(e,t[r],n[r]))return!1;return!0},e=>Array.isArray(e))}function xn(e,t){return Cn(0,e,{getter:{field:t.field,getterTable:t.getterTable,method:t.getter,when:t.when},setter:{field:t.field,method:t.setter,setterTable:t.setterTable}})}function Sn(e,t){return Cn(0,e,t)}function Cn(e,t,n){return Object.assign(e=>t(e),{accepts:t.accepts,defaultValue:t.defaultValue,getter:n.getter,isEqual:t.isEqual,meta:t.meta,setter:n.setter})}var wn=`latest`,Tn=class{key;parse;unparse;isEqual;defaultValue;resetOnCopyNode;schema;constructor(e,t){this.key=e;let n=`meta`in(r=t.parse)&&typeof r.meta==`object`&&r.meta!==null&&`kind`in r.meta&&typeof r.meta.kind==`string`&&`defaultValue`in r?t.parse:void 0;var r;this.schema=n,this.parse=t.parse.bind(t),this.unparse=(t.unparse||Fn).bind(t),this.isEqual=t.isEqual?t.isEqual.bind(t):n!==void 0&&n.isEqual!==void 0?(e,t)=>Kt(n,e,t):Object.is,this.defaultValue=n===void 0?this.parse(void 0):n.defaultValue,this.resetOnCopyNode=t.resetOnCopyNode||!1}};function En(e,t){return new Tn(e,t)}function Dn(e,t,n=wn){let r=(n===`latest`?e.getLatest():e).__state;return r?r.getValue(t):t.defaultValue}function On(e,t,n){let r;if(js(),typeof n==`function`){let i=e.getLatest(),a=Dn(i,t);if(r=n(a),t.isEqual(a,r))return i}else r=n;let i=e.getWritable();return Mn(i).updateFromKnown(t,r),i}function kn(e){let t=new Map,n=new Set;for(let{ownNodeConfig:r}of Od(typeof e==`function`?e:e.replace))if(r&&r.stateConfigs)for(let e of r.stateConfigs){let r;`stateConfig`in e?(r=e.stateConfig,e.flat&&n.add(r.key)):r=e,t.set(r.key,r)}return{flatKeys:n,sharedConfigMap:t}}var An=new Set([`__proto__`,`constructor`,`prototype`]),jn=class e{node;knownState;unknownState;sharedNodeState;size;constructor(e,t,n=void 0,r=new Map,i=void 0){this.node=e,this.sharedNodeState=t,this.unknownState=n,this.knownState=r;let{sharedConfigMap:a}=this.sharedNodeState,o=i===void 0?function(e,t,n){let r=n.size;if(t)for(let i in t){let t=e.get(i);t&&n.has(t)||r++}return r}(a,n,r):i;this.size=o}getValue(e){let t=this.knownState.get(e);if(t!==void 0)return t;this.sharedNodeState.sharedConfigMap.set(e.key,e);let n=e.defaultValue;if(this.unknownState&&e.key in this.unknownState){let t=this.unknownState[e.key];t!==void 0&&(n=e.parse(t)),this.updateFromKnown(e,n)}return n}getInternalState(){return[this.unknownState,this.knownState]}toJSON(){let e={...this.unknownState},t={};for(let[t,n]of this.knownState)t.isEqual(n,t.defaultValue)?delete e[t.key]:e[t.key]=t.unparse(n);for(let n of this.sharedNodeState.flatKeys)n in e&&(t[n]=e[n],delete e[n]);return Pn(e)&&(t.$=e),t}getWritable(t){if(this.node===t)return this;let{sharedNodeState:n,unknownState:r}=this,i=new Map(this.knownState);return new e(t,n,function(e,t,n){let r;if(n)for(let[i,a]of Object.entries(n)){if(An.has(i))continue;let n=e.get(i);n?t.has(n)||t.set(n,n.parse(a)):(r||={},r[i]=a)}return r}(n.sharedConfigMap,i,r),i,this.size)}resetOnCopyNode(){for(let e of this.knownState.keys())e.resetOnCopyNode&&this.knownState.set(e,e.defaultValue);return this}updateFromKnown(e,t){let n=e.key;this.sharedNodeState.sharedConfigMap.set(n,e);let{knownState:r,unknownState:i}=this;r.has(e)||i&&n in i||(i&&(delete i[n],this.unknownState=Pn(i)),this.size++),r.set(e,t)}updateFromUnknown(e,t){if(An.has(e))return;let n=this.sharedNodeState.sharedConfigMap.get(e);n?this.updateFromKnown(n,n.parse(t)):(this.unknownState=this.unknownState||{},e in this.unknownState||this.size++,this.unknownState[e]=t)}updateFromJSON(e){let{knownState:t}=this;for(let e of t.keys())t.set(e,e.defaultValue);if(this.size=t.size,this.unknownState=void 0,e)for(let[t,n]of Object.entries(e))this.updateFromUnknown(t,n)}};function Mn(e){let t=e.getWritable(),n=t.__state?t.__state.getWritable(t):new jn(t,function(e){return e.__state?e.__state.sharedNodeState:nl(Bu(),e.getType()).sharedNodeState}(t));return t.__state=n,n}function Nn(e,t){let n=e.getWritable(),r=t.$;return(n.__state||r)&&Mn(e).updateFromJSON(r),n}function Pn(e){if(e)for(let t in e)return e}function Fn(e){return e}function In(e,t,n){for(let[r,i]of t.knownState){if(e.has(r.key))continue;e.add(r.key);let t=n?n.getValue(r):r.defaultValue;if(t!==i&&!r.isEqual(t,i))return!0}return!1}function Ln(e,t,n){let{unknownState:r}=t,i=n?n.unknownState:void 0;if(r){for(let[t,n]of Object.entries(r))if(!e.has(t)&&(e.add(t),n!==(i?i[t]:void 0)))return!0}return!1}function Rn(e,t){let n=e.__state;return n&&n.node===e?n.getWritable(t):n}function zn(e,t){let n=e.__mode,r=e.__format,i=e.__style,a=t.__mode,o=t.__format,s=t.__style,c=e.__state,l=t.__state;return(n===null||n===a)&&(r===null||r===o)&&(i===null||i===s)&&(e.__state===null||c===l||function(e,t){if(e===t)return!0;let n=new Set;return!(e&&In(n,e,t)||t&&In(n,t,e)||e&&Ln(n,e,t)||t&&Ln(n,t,e))}(c,l))}function Bn(e,t){let n=e.mergeWithSibling(t),r=M()._normalizedNodes;return r.add(e.__key),r.add(t.__key),n}function Vn(e){let t,n,r=e;if(r.__text!==``||!r.isSimpleText()||r.isUnmergeable()){for(;(t=r.getPreviousSibling())!==null&&O(t)&&t.isSimpleText()&&!t.isUnmergeable();){if(t.__text!==``){if(zn(t,r)){r=Bn(t,r);break}break}t.remove()}for(;(n=r.getNextSibling())!==null&&O(n)&&n.isSimpleText()&&!n.isUnmergeable();){if(n.__text!==``){if(zn(r,n)){r=Bn(r,n);break}break}n.remove()}}else r.remove()}function Hn(e){return Un(e.anchor),Un(e.focus),e}function Un(e){for(;e.type===`element`;){let t=e.getNode(),n=e.offset,r,i;if(n===t.getChildrenSize()?(r=t.getChildAtIndex(n-1),i=!0):(r=t.getChildAtIndex(n),i=!1),O(r)){e.set(r.__key,i?r.getTextContentSize():0,`text`,!0);break}if(!N(r))break;e.set(r.__key,i?r.getChildrenSize():0,`element`,!0)}}var Wn=Symbol.for(`@lexical/CachedTextSize`);function Gn(e,t){return or.read(()=>{let n=0,r=e;for(let e=0;e<t&&r!==null;e++){let i=ar.get(r);if(i===void 0&&C(345,r),N(i)){let a=sr.get(r);if(a!==void 0&&N(a)&&a.__parent!==i.__parent)n+=i.getTextContentSize();else{let e=cr.get(r),t=e&&e.__lexicalTextContent;typeof t!=`string`&&C(346,i.getType()),n+=t.length}e<t-1&&!i.isInline()&&(n+=2)}else{let e=i[Wn];e===void 0&&C(347,i.getType(),r),n+=e}r=i.__next}return n},{editor:w})}function Kn(e){N(e)||e[Wn]===void 0&&(e[Wn]=O(e)?e.__text.length:e.getTextContentSize())}var qn=4,Jn,w,Yn,T=``,Xn=null,Zn=null,Qn=null;function $n(){return{firstTextKey:Qn,format:Xn,style:Zn}}function er(e){e.firstTextKey!==null&&(Xn=e.format,Zn=e.style,Qn=e.firstTextKey)}function tr(e){if(Qn!==null)return;let t=e.__lexicalFirstTextKey;if(t===void 0&&C(348),t===null)return;let n=sr.get(t);O(n)&&(Xn=n.getFormat(),Zn=n.getStyle(),Qn=t)}var nr,rr,ir,ar,or,sr,cr,lr,ur,dr,fr=!1,pr=!1;function mr(e,t){let n=ar.get(e),r=sr.has(e);if(t!==null){let n=zr(e);n.parentNode===t&&t.removeChild(n)}if(!r){if(w._keyToDOMMap.delete(e),N(n)){let e=jd(n,ar);hr(e,0,e.length-1,null)}if(n!==void 0){for(let e of wr(n).values()){let t=Er(e);mr(e,null),t!==null&&t.remove()}Kl(ur,Yn,nr,n,`destroyed`)}}}function hr(e,t,n,r){for(let i=t;i<=n;++i){let t=e[i];t!==void 0&&mr(t,r)}}function gr(e,t){e.setProperty(`text-align`,t)}var _r=`40px`;function vr(e,t){let n=Jn.theme.indent;if(typeof n==`string`){let r=e.classList.contains(n);t>0&&!r?e.classList.add(n):t<1&&r&&e.classList.remove(n)}e.style.setProperty(`padding-inline-start`,t===0?``:`calc(${t} * var(--lexical-indent-base-value, ${_r}))`),Wl(e,`class`),Wl(e,`style`)}function yr(e,t){let n=e.style;t===0?gr(n,``):t===1?gr(n,`left`):t===2?gr(n,`center`):t===3?gr(n,`right`):t===4?gr(n,`justify`):t===5?gr(n,`start`):t===6&&gr(n,`end`),Wl(e,`style`)}function br(e,t){let n=function(e){let t=e.__dir;if(t!==null)return t;if(F(e))return null;let n=e.getParent();return n===null||V(n)&&n.__dir===null?`auto`:null}(t);n===null?e.removeAttribute(`dir`):e.dir=n}function xr(e){let t=H().createElement(`div`);return t.setAttribute(`data-lexical-slot`,e),t.style.display=`none`,t}function Sr(e,t,n){t||e.contentEditable===`false`?td(n,w):n.removeAttribute(`contenteditable`)}function Cr(e,t,n){let r=T,i=$n();T=``;let a=``,o=P(e);for(let[r,i]of n){let n=xr(r);Sr(t,o,n),t.appendChild(n),T=``;let s=$n();Or(i,Hu(e,n,w)),er(s),Tr(e,r,t,n),a+=T}return er(i),T=r,a}function wr(e){return Pd(e)&&e.__slots!==null?e.__slots:Nd}function Tr(e,t,n,r){let i=dr.$getSlotTargetElement(e,t,n,w);i!==null&&(r.parentElement!==i&&i.appendChild(r),r.style.display=``)}function Er(e){let t=cr.get(e);return t===void 0?null:t.parentElement}function Dr(e,t,n){let r=wr(e),i=wr(t);for(let[e,t]of r)if(!i.has(e)){let e=Er(t);mr(t,null),e!==null&&e.remove()}let a=T,o=$n(),s=``,c=null,l=P(t);for(let[e,a]of i){let i=r.get(e),o=i===void 0?null:Er(i);T=``;let u=$n();if(o===null){o=xr(e);let r=null;for(let e of n.children)if(!e.hasAttribute(`data-lexical-slot`)){r=e;break}n.insertBefore(o,r),Or(a,Hu(t,o,w))}else i===a?Pr(a,o):(i!==void 0&&mr(i,o),Or(a,Hu(t,o,w)));if(er(u),Sr(n,l,o),Tr(t,e,n,o),s+=T,o.parentElement===n){let e=c===null?n.firstChild:c.nextSibling;e!==o&&n.insertBefore(o,e),c=o}}return er(o),T=a,s}function Or(e,t){let n=sr.get(e);if(n===void 0&&C(60),t!==null){let r=ar.get(e);if(r!==void 0){let i=cr.get(e);if(i!==void 0){let a=Fd(r)?r.__slotHost:null,o=Fd(n)?n.__slotHost:null,s=r.__parent!==n.__parent||a!==o,c=o!==null&&i.parentElement!==t.element;if(s||c)return t.insertChild(i),Pr(e,t.element)}}}let r=dr.$createDOM(n,w);if(function(e,t,n){let r=n._keyToDOMMap;Cl(t,n,e),r.set(e,t)}(e,r,w),O(n)?r.setAttribute(`data-lexical-text`,`true`):P(n)&&(r.setAttribute(`data-lexical-decorator`,`true`),$u(r,{captureSelection:!0})),N(n)){let e=n.__indent,t=n.__size;br(r,n),e!==0&&vr(r,e);let i=wr(n),a=i.size>0?Cr(n,r,i):``;if(t===0)r.__lexicalTextContent=a,r.__lexicalFirstTextKey=null,T+=a,i.size>0&&(r.__lexicalSlotTextLength=a.length);else{let e=T,o=t-1;if(kr(jd(n,sr),n,0,o,Hu(n,r,w)),a!==``){let t=r.__lexicalTextContent||``;r.__lexicalTextContent=a+t,T=e+a+t}i.size>0&&(r.__lexicalSlotTextLength=a.length)}let o=n.__format;o!==0&&yr(r,o),n.isInline()||(Mr(0,n,r),jr(n,r))}else{let t=n.getTextContent();if(P(n)){let t=n.decorate(w,Jn);t!==null&&Fr(e,t),r.contentEditable=`false`;let i=wr(n);i.size>0&&Cr(n,r,i)}T+=t}return t!==null&&t.insertChild(r),dr.$decorateDOM(n,null,r,w),Kn(n),Kl(ur,Yn,nr,n,`created`),r}function kr(e,t,n,r,i){let a=T,o=$n();T=``,Xn=null,Zn=null,Qn=null;let s=n;for(;s<=r;++s){let t=$n();Or(e[s],i);let n=sr.get(e[s]);n!==null&&O(n)?Xn===null&&(Xn=n.getFormat(),Zn=n.getStyle(),Qn=n.__key):N(n)&&s<r&&!n.isInline()&&(T+=at),er(t)}let c=w._keyToDOMMap.get(t.__key);c===void 0&&C(349,t.__key),c.__lexicalTextContent=T,c.__lexicalFirstTextKey=Qn,T=a+T,er(o)}function Ar(e,t){if(!e)return!1;let n=t.get(e);return P(n)&&!n.isInline()}function jr(e,t){let n=Hu(e,t,w);n.setDecoratorBoundaryAnchor(`leading`,Ar(e.__first,sr)),n.setDecoratorBoundaryAnchor(`trailing`,Ar(e.__last,sr))}function Mr(e,t,n){let r=Hu(t,n,w),i=function(e,t){if(e){let n=e.__last;if(n){let e=t.get(n);if(e)return vc(e)?`line-break`:P(e)&&e.isInline()?`decorator`:null}return`empty`}return null}(t,sr);r.setManagedLineBreak(i)}function Nr(e,t,n){let r=t.__lexicalFirstTextKey;if(r!=null){let t=e.__key,i=r;for(;i!==null;){let e=sr.get(i);if(e===void 0){i=null;break}if(e.__parent===t)break;i=e.__parent}if(i!==null&&!n.has(i)){let e=sr.get(r);if(O(e))return Xn=e.getFormat(),void(Zn=e.getStyle())}}t.__lexicalFirstTextKey=Qn}function Pr(e,t){let n=ar.get(e),r=sr.get(e);n!==void 0&&r!==void 0||C(61);let i=fr||ir.has(e)||rr.has(e),a=Xl(w,e);if(n===r&&!i){let e;if(N(n)){let t=a.__lexicalTextContent;typeof t!=`string`&&C(355,n.getType()),e=t,tr(a)}else e=n.getTextContent();return T+=e,a}if(n!==r&&i&&Kl(ur,Yn,nr,r,`updated`),dr.$updateDOM(r,n,a,w)){let n=Or(e,null);return t===null&&C(62),t.replaceChild(n,a),mr(e,null),n}if(N(n)){N(r)||C(334,e);let t=r.__indent;(fr||t!==n.__indent)&&vr(a,t);let o=r.__format;(fr||o!==n.__format)&&yr(a,o);let s=i&&(wr(r).size>0||wr(n).size>0)?Dr(n,r,a):``;if(i){let e=T;if(function(e,t,n){var r;Xn=null,Zn=null,Qn=null,function(e,t,n){let r=T,i=e.__size,a=t.__size;T=``;let o=n.element,s=w._keyToDOMMap.get(t.__key);s===void 0&&C(351,t.__key);let c=a-i;if(!fr&&Math.abs(c)<=1&&i>=qn&&e.__first===t.__first&&(c!==0||!w._cloneNotNeeded.has(e.__key))){let i=s.__lexicalTextContent,l=lr.get(e.__key);if(!fr&&typeof i==`string`&&l!==void 0){let a=function(e,t){let n=t.size;if(n===0||n>=e.__size)return null;let r=e.__last,i=null,a=0;for(;r!==null&&a<n;){if(!t.has(r))return null;i=r;let e=sr.get(r);if(e===void 0)return null;r=e.__prev,a++}return a!==n||r!==null&&t.has(r)?null:i}(t,l);if(a!==null){let u=l.size;if(c===0){let e=Gn(a,u),n=a,c=0;for(;n!==null&&c<u;){let e=sr.get(n);if(e===void 0)break;let t=$n();Pr(n,o),O(e)&&Xn===null&&(Xn=e.getFormat(),Zn=e.getStyle(),Qn=e.__key),er(t),n=e.__next,c++}let d=``;for(n=a,c=0;n!==null&&c<u;){let e=sr.get(n);if(e===void 0)break;let t;if(N(e)){let r=w._keyToDOMMap.get(n),i=r&&r.__lexicalTextContent;typeof i!=`string`&&C(352,e.getType()),t=i}else t=e.getTextContent();d+=t,c<u-1&&N(e)&&!e.isInline()&&(d+=at),n=e.__next,c++}let f=s.__lexicalSlotTextLength||0,p=f>0?i.slice(f):i,m=p.slice(0,p.length-e)+d;s.__lexicalTextContent=m,T=r+m,Nr(t,s,l);return}if(function(e,t,n,r,i,a,o,s){if(s!==1&&s!==-1||o!==(s===1?2:1))return!1;let c=o-s,l=e.__last;for(let e=0;e<c-1;e++){if(l===null)return!1;let e=ar.get(l);if(e===void 0)return!1;l=e.__prev}if(l===null)return!1;let u=sr.get(a),d=ar.get(l);if(u===void 0||d===void 0||u.__prev!==d.__prev)return!1;let f=[],p=a;for(let e=0;e<o;e++){if(p===null)return!1;f.push(p);let e=sr.get(p);p=e?e.__next:null}let m=[];p=l;for(let e=0;e<c;e++){if(p===null)return!1;m.push(p);let e=ar.get(p);p=e?e.__next:null}let h=new Set(m),g=new Set(f),_=[],v=0,y=0;for(;v<c&&y<o;)if(f[y]===m[v])_.push({key:f[y],kind:`reconcile`}),v++,y++;else if(g.has(m[v])){if(h.has(f[y]))return!1;_.push({key:f[y],kind:`create`,nextIndex:y}),y++}else _.push({key:m[v],kind:`destroy`}),v++;for(;v<c;)_.push({key:m[v++],kind:`destroy`});for(;y<o;)_.push({key:f[y],kind:`create`,nextIndex:y}),y++;let b=Gn(l,c);for(let e of _){let t=$n();if(e.kind===`reconcile`)Pr(e.key,n.element);else if(e.kind===`destroy`)mr(e.key,n.element);else{let t=null;for(let n=e.nextIndex+1;n<o;n++){let e=w._keyToDOMMap.get(f[n]);if(e!==void 0){t=e;break}}Or(e.key,n.withBefore(t??n.before))}if(e.kind!==`destroy`){let t=sr.get(e.key);t&&O(t)&&Xn===null&&(Xn=t.getFormat(),Zn=t.getStyle(),Qn=t.__key)}er(t)}let x=``;for(let e=0;e<o;e++){let t=sr.get(f[e]);if(t===void 0)return!1;let n;if(N(t)){let r=w._keyToDOMMap.get(f[e]),i=r&&r.__lexicalTextContent;typeof i!=`string`&&C(350,t.getType()),n=i}else n=t.getTextContent();x+=n,e<o-1&&N(t)&&!t.isInline()&&(x+=at)}let ee=r.__lexicalSlotTextLength||0,te=ee>0?i.slice(ee):i;return r.__lexicalTextContent=te.slice(0,te.length-b)+x,!0}(e,0,n,s,i,a,u,c)){let e=s.__lexicalTextContent;typeof e!=`string`&&C(353),T=r+e,Nr(t,s,l);return}}}if(c===0){let t=e.__first,n=0;for(;t!==null;){let e=sr.get(t);if(e===void 0)break;let r=fr||ir.has(t)||rr.has(t),i=$n();if(r)Pr(t,o);else{let n,r;if(N(e)){r=cr.get(t);let i=r&&r.__lexicalTextContent;typeof i!=`string`&&C(354,e.getType()),n=i}else n=e.getTextContent();T+=n,r!==void 0&&tr(r)}O(e)?Xn===null&&(Xn=e.getFormat(),Zn=e.getStyle(),Qn=e.__key):N(e)&&n<a-1&&!e.isInline()&&(T+=at),er(i),t=e.__next,n++}s.__lexicalTextContent=T,s.__lexicalFirstTextKey=Qn,T=r+T;return}}if(i===1&&a===1){let r=e.__first,i=t.__first;if(r===i)Pr(r,o);else{let e=zr(r),t=Or(i,null);try{e.parentNode===o?o.replaceChild(t,e):n.insertChild(t)}catch(n){if(typeof n==`object`&&n){let a=`${n.toString()} Parent: ${o.tagName}, new child: {tag: ${t.tagName} key: ${i}}, old child: {tag: ${e.tagName}, key: ${r}}.`;throw Error(a)}throw n}mr(r,null)}let a=sr.get(i);O(a)&&Xn===null&&(Xn=a.getFormat(),Zn=a.getStyle(),Qn=a.__key)}else{let r=jd(e,ar),s=jd(t,sr);if(r.length!==i&&C(227),s.length!==a&&C(228),i===0)a!==0&&kr(s,t,0,a-1,n);else if(a===0){if(i!==0){let e=n.after==null&&n.before==null&&wr(t).size===0&&n.element.__lexicalLineBreak==null;hr(r,0,i-1,e?null:o),e&&(o.textContent=``)}}else(function(e,t,n,r,i,a){let o=r-1,s=i-1,c,l,u=a.getFirstChild(),d=0,f=0;for(;d<=o&&f<=s;){let e=t[d],r=n[f],i=$n();if(e===r)u=Ir(Pr(r,a.element)),d++,f++;else{if(l===void 0&&(l=Lr(n,f)),c===void 0)c=Lr(t,d);else if(!c.has(e)){d++,er(i);continue}if(!l.has(e)){u=Ir(zr(e)),mr(e,a.element),d++,c.delete(e),er(i);continue}if(c.has(r)){let e=Xl(w,r);e!==u&&a.withBefore(u??a.before).insertChild(e),u=Ir(Pr(r,a.element)),d++,f++}else Or(r,a.withBefore(u??a.before)),f++}let o=sr.get(r);o!==null&&O(o)?Xn===null&&(Xn=o.getFormat(),Zn=o.getStyle(),Qn=o.__key):N(o)&&f<=s&&!o.isInline()&&(T+=at),er(i)}let p=d>o,m=f>s;if(p&&!m){let t=n[s+1],r=t===void 0?null:w.getElementByKey(t);kr(n,e,f,s,a.withBefore(r??a.before))}else m&&!p&&hr(t,d,o,a.element)})(t,r,s,i,a,n)}s.__lexicalTextContent=T,s.__lexicalFirstTextKey=Qn,T=r+T}(e,t,Hu(t,n,w)),V(t)||(r=t,Xn==null||Xn===r.__textFormat||pr||r.setTextFormat(Xn),function(e){Zn==null||Zn===e.__textStyle||pr||e.setTextStyle(Zn)}(t))}(n,r,a),r.isInline()||(F(r)||Mr(0,r,a),jr(r,a)),s!==``){let t=a.__lexicalTextContent||``;a.__lexicalTextContent=s+t,T=e+s+t,a.__lexicalSlotTextLength=s.length}else(wr(r).size>0||wr(n).size>0)&&(a.__lexicalSlotTextLength=0)}else{let e=a.__lexicalTextContent;typeof e!=`string`&&C(356,n.getType()),T+=e,tr(a)}if((fr||r.__dir!==n.__dir||r.__parent!==n.__parent)&&(br(a,r),F(r)&&!fr))for(let e of r.getChildren())N(e)&&br(Xl(w,e.getKey()),e)}else{let t=r.getTextContent();if(P(r)){let t=r.decorate(w,Jn);t!==null&&Fr(e,t),i&&(wr(r).size>0||wr(n).size>0)&&Dr(n,r,a)}T+=t}if(!pr&&F(r)){let e=r.getLatest();if(e.__cachedText!==T){let t=e.getWritable();t.__cachedText=T,r=t}}return dr.$decorateDOM(r,n,a,w),Kn(r),a}function Fr(e,t){let n=w._pendingDecorators,r=w._decorators;if(n===null){if(r[e]===t)return;n=El(w)}n[e]=t}function Ir(e){let t=e.nextSibling;return t!==null&&t===w._blockCursorElement&&(t=t.nextSibling),t}function Lr(e,t){let n=new Set;for(let r=t;r<e.length;r++)n.add(e[r]);return n}function Rr(e,t,n,r,i,a){T=``,Xn=null,Zn=null,Qn=null,fr=r===2,w=n,Jn=n._config,dr=n._config.dom||qc,Yn=n._nodes,nr=w._listeners.mutation,rr=i,ir=a,ar=e._nodeMap,or=e,sr=t._nodeMap,pr=t._readOnly,cr=kt(n._keyToDOMMap),lr=function(){let e=new Map,t=t=>{for(let n of t){let t=sr.get(n);if(t===void 0)continue;let r=t.__parent;if(r===null)continue;let i=e.get(r);i===void 0&&(i=new Set,e.set(r,i)),i.add(n)}};return t(rr.keys()),t(ir),e}();let o=new Map;return ur=o,Pr(`root`,null),w=void 0,Yn=void 0,rr=void 0,ir=void 0,ar=void 0,or=void 0,sr=void 0,Jn=void 0,cr=void 0,lr=void 0,ur=void 0,dr=qc,o}function zr(e){let t=cr.get(e);return t===void 0&&C(75,e),t}function Br(e){return()=>{}}function E(e){return{type:e}}var Vr=E(`SELECTION_CHANGE_COMMAND`),Hr=E(`SELECTION_INSERT_CLIPBOARD_NODES_COMMAND`),Ur=E(`CLICK_COMMAND`),Wr=E(`BEFORE_INPUT_COMMAND`),Gr=E(`INPUT_COMMAND`),Kr=E(`COMPOSITION_START_COMMAND`),qr=E(`COMPOSITION_END_COMMAND`),Jr=E(`DELETE_CHARACTER_COMMAND`),Yr=E(`INSERT_LINE_BREAK_COMMAND`),Xr=E(`INSERT_PARAGRAPH_COMMAND`),Zr=E(`CONTROLLED_TEXT_INSERTION_COMMAND`),Qr=E(`PASTE_COMMAND`),$r=E(`REMOVE_TEXT_COMMAND`),ei=E(`DELETE_WORD_COMMAND`),ti=E(`DELETE_LINE_COMMAND`),ni=E(`FORMAT_TEXT_COMMAND`),ri=E(`SET_TEXT_FORMAT_COMMAND`),ii=E(`UNDO_COMMAND`),ai=E(`REDO_COMMAND`),oi=E(`KEYDOWN_COMMAND`),si=E(`KEY_ARROW_RIGHT_COMMAND`),ci=E(`MOVE_TO_END`),li=E(`KEY_ARROW_LEFT_COMMAND`),ui=E(`MOVE_TO_START`),di=E(`KEY_ARROW_UP_COMMAND`),fi=E(`KEY_ARROW_DOWN_COMMAND`),pi=E(`KEY_ENTER_COMMAND`),mi=E(`KEY_SPACE_COMMAND`),hi=E(`KEY_BACKSPACE_COMMAND`),gi=E(`KEY_ESCAPE_COMMAND`),_i=E(`KEY_DELETE_COMMAND`),vi=E(`KEY_TAB_COMMAND`),yi=E(`INSERT_TAB_COMMAND`),bi=E(`INDENT_CONTENT_COMMAND`),xi=E(`OUTDENT_CONTENT_COMMAND`),Si=E(`DROP_COMMAND`),Ci=E(`FORMAT_ELEMENT_COMMAND`),wi=E(`DRAGSTART_COMMAND`),Ti=E(`DRAGOVER_COMMAND`),Ei=E(`DRAGEND_COMMAND`),Di=E(`COPY_COMMAND`),Oi=E(`CUT_COMMAND`),ki=E(`SELECT_ALL_COMMAND`),Ai=E(`CLEAR_EDITOR_COMMAND`),ji=E(`CLEAR_HISTORY_COMMAND`),Mi=E(`CAN_REDO_COMMAND`),Ni=E(`CAN_UNDO_COMMAND`),Pi=E(`FOCUS_COMMAND`),Fi=E(`BLUR_COMMAND`),Ii=E(`KEY_MODIFIER_COMMAND`);function Li(e,t){return{...t,[mt]:e}}var Ri=Li(`metaKey`,{ctrlKey:!Ge,metaKey:Ge}),zi=Li(`altKey`,{altKey:Ge,ctrlKey:!Ge}),Bi=[[`altKey`,1],[`ctrlKey`,2],[`metaKey`,4],[`shiftKey`,8]];function Vi(e,t,n){let r=e.get(t);r?r.push(n):e.set(t,[n])}var Hi=class{byKey=new Map;byCode=new Map;add(e){let{key:t,modifiers:n={}}=e;t.length>0||C(399);let r=t.toLowerCase();for(let i of function(e){let t=[0];for(let[n,r]of Bi){let i=e[n]||!1;i===`any`?t=t.concat(t.map(e=>e|r)):i&&(t=t.map(e=>e|r))}return t}(n))Vi(this.byKey,`${i}:${r}`,e),t.length===1&&(/[0-9]/.test(t)?Vi(this.byCode,`${i}:Digit${t}`,e):/[a-z]/.test(r)&&Vi(this.byCode,`${i}:Key${r.toUpperCase()}`,e));return this}matches(e){let t=e.key;if(!t)return[];let n=function(e){let t=0;for(let[n,r]of Bi)e[n]&&(t|=r);return t}(e),r=this.byKey.get(`${n}:${t.toLowerCase()}`),i=r?r.slice():[];if(this.byCode.size>0&&!(t.length===1&&t.charCodeAt(0)<=127)){let t=this.byCode.get(`${n}:${e.code}`);t&&i.push(...t)}return i}match(e){return this.matches(e)[0]}};function Ui(e){let t=new Hi;for(let n of e)t.add(n);return t}function Wi(e){let t=new Map;return{dispose(){for(let e of t.values())e.dispose();t.clear()},register(n,r){let i=t.get(n);i===void 0&&(i={dispose:e(n,r),holders:new Set},t.set(n,i));let a=()=>{let e=t.get(n);e&&e.holders.delete(a)&&e.holders.size===0&&(t.delete(n),e.dispose())};return i.holders.add(a),a}}}function Gi(e,t,n,r){return e.addEventListener(t,n,r),e.removeEventListener.bind(e,t,n,r)}var Ki=Object.freeze({}),qi,Ji=new WeakMap,Yi=new WeakMap,Xi=Wi(e=>(e.addEventListener(`selectionchange`,Da),()=>e.removeEventListener(`selectionchange`,Da)));function Zi(e,t,n,r,i,a){let o=e.anchor,s=e.focus,c=o.getNode(),l=M(),u;if(a!==void 0)u=a;else{let e=hu(au(l));u=e===null?null:wu(e,l._rootElement)}let d=u===null?null:u.anchorNode,f=o.key,p=l.getElementByKey(f),m=n.length;return f!==s.key||!O(c)||(!i&&(!Je||l._inputState.lastBeforeInputInsertTextTimeStamp<r+50)||c.isDirty()&&m<2||jl(n))&&o.offset!==s.offset&&!c.isComposing()||dl(c)||c.isDirty()&&m>1||(i||!Je)&&p!==null&&!c.isComposing()&&d!==Wu(c,p,l)||u!==null&&t!==null&&(!t.collapsed||t.startContainer!==u.anchorNode||t.startOffset!==u.anchorOffset)||!c.isComposing()&&(c.getFormat()!==e.format||c.getStyle()!==e.style)||function(e,t){if(t.isSegmented())return!0;if(!e.isCollapsed())return!1;let n=e.anchor.offset,r=t.getParentOrThrow(),i=ul(t);return n===0?!t.canInsertTextBefore()||!r.canInsertTextBefore()&&!t.isComposing()||i||function(e){let t=e.getPreviousSibling();return(O(t)||N(t)&&t.isInline())&&!t.canInsertTextAfter()}(t):n===t.getTextContentSize()&&(!t.canInsertTextAfter()||!r.canInsertTextAfter()&&!t.isComposing()||i)}(e,c)}function Qi(e,t){return fl(e)&&e.nodeValue!==null&&t!==0&&t!==e.nodeValue.length}function $i(e,t,n){let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=wu(e,t._rootElement),s=t._inputState;if(s.isSelectionChangeFromDOMUpdate){s.isSelectionChangeFromDOMUpdate=!1;let e=s.selectionChangeFromDOMUpdatePoints;if(s.selectionChangeFromDOMUpdatePoints=null,Qi(r,i)&&Qi(a,o)&&!s.postDeleteSelectionToRestore&&(e===null||e.anchorNode===r&&e.anchorOffset===i&&e.focusNode===a&&e.focusOffset===o))return}Qs(t,()=>{if(!n)return void z(null);if(!ol(t,r,a))return;let c=j();if(s.postDeleteSelectionToRestore&&k(c)&&c.isCollapsed()){let e=c.anchor,t=s.postDeleteSelectionToRestore.anchor;(e.key===t.key&&e.offset===t.offset+1||e.offset===1&&t.getNode().is(e.getNode().getPreviousSibling()))&&(c=s.postDeleteSelectionToRestore.clone(),z(c))}if(s.postDeleteSelectionToRestore=null,k(c)){let n=c.anchor,l=n.getNode();if(c.isCollapsed()){e.type===`Range`&&r===a&&(c.dirty=!0);let i=au(t).event,o=i?i.timeStamp:performance.now(),{format:u,style:d,offset:f,key:p,timeStamp:m}=s.collapsedSelectionFormat,h=R(),g=!1===t.isComposing()&&h.getTextContent()===``;if(o<m+200&&n.offset===f&&n.key===p)ea(c,u,d);else if(n.type===`text`)O(l)||C(141),ta(c,l);else if(n.type===`element`&&!g){N(l)||C(259);let e=n.getNode();e.isEmpty()?function(e,t){ea(e,t.getTextFormat(),t.getTextStyle())}(c,e):ea(c,c.format,``)}}else{let e=n.key,t=c.focus.key,r=c.getNodes(),a=r.length,s=c.isBackward(),l=s?o:i,u=s?i:o,d=s?t:e,f=s?e:t,p=rt,m=!1;for(let e=0;e<a;e++){let t=r[e],n=t.getTextContentSize();if(O(t)&&n!==0&&!(e===0&&t.__key===d&&l===n||e===a-1&&t.__key===f&&u===0)&&(m=!0,p&=t.getFormat(),p===0))break}c.format=m?p:0}}(function(e,t,n=!1){(n||Ks(e,t))&&e.dispatchCommand(Vr)})(t,c,c!==null&&(c.dirty||!k(c)))})}function ea(e,t,n){e.format===t&&e.style===n||(e.format=t,e.style=n,e.dirty=!0)}function ta(e,t){ea(e,t.getFormat(),t.getStyle())}function na(e,t){Qs(t,()=>{let n=j(),r=hu(au(t)),i=rs();if(r){if(k(n)){let e=n.anchor,t=e.getNode();e.type===`element`&&e.offset===0&&n.isCollapsed()&&!F(t)&&R().getChildrenSize()===1&&t.getTopLevelElementOrThrow().isEmpty()&&i!==null&&n.is(i)&&(r.removeAllRanges(),n.dirty=!0)}else if(e.pointerType===`touch`||e.pointerType===`pen`){let n=wu(r,t._rootElement).anchorNode;(U(n)||fl(n))&&z(ns(i,r,t,e))}}if(Ke&&r!==null&&r.rangeCount===0){let n=t._rootElement;if(n!==null&&e.target===n){let a=e.clientY,o=n.childNodes.length;for(let e=0;e<n.childNodes.length;e++){let t=n.childNodes[e];if(U(t)){let n=t.getBoundingClientRect();if(a<=(n.top+n.bottom)/2){o=e;break}}}r.setBaseAndExtent(n,o,n,o);let s=ns(i,r,t,e);s===null?r.removeAllRanges():z(s)}}B(t,Ur,e)})}function ra(e,t){let n=Au(e),r=e.pointerType;Nu(n)&&r!==`touch`&&r!==`pen`&&e.button===0&&Qs(t,()=>{nd(n,t)||(t._inputState.isSelectionChangeFromMouseDown=!0)})}function ia(e){if(!e.getTargetRanges)return null;let t=e.getTargetRanges();return t.length===0?null:t[0]}function aa(e){let{lastKeyCode:t}=M()._inputState;if(e==null||e.length<=1||t==null)return;let n=t.length===1?t:t===`Enter`?`
4
4
  `:t===`Tab`?` `:null;if(!n)return;let r=j();if(!k(r)||!r.isCollapsed())return;let i=r.anchor.getNode();if(!O(i))return;let{offset:a}=r.anchor;if(i.getTextContentSize()===a){let e=i.getNextSibling();if(n===`
@@ -68,4 +68,4 @@ ${l}`:l)}return o.join(`
68
68
  `)}function AT(e){let t=[],n=(e,n)=>{let r=t.at(-1);r?.isPrivate===n?r.text+=e:e&&t.push({text:e,isPrivate:n})};return(typeof e==`string`?[e]:e).forEach((e,t)=>{if(typeof e==`string`){n(e,!1);return}let r=t===0?gT.exec(e.private)?.[0]??``:``,i=e.private.slice(r.length),a=fT.exec(i)?.[1]??``;n(`${r}${a}`,!1),n(i.slice(a.length),!0)}),t}var jT=e=>e?e.split(` and `):[];function MT(e,t,n){let r=`${t} is ${n}`,i=jT(e),a=i.filter(e=>!e.startsWith(`${t} is `));return(i.includes(r)?a:[...a,r]).join(` and `)||null}var NT=(e,t)=>jT(e).filter(e=>e!==t).join(` and `)||null;function PT(e,t){if(e===t)return!0;let n=_e(e),r=_e(t);return!n.ok||!r.ok?e===t:JSON.stringify(n.lines.map(AT))===JSON.stringify(r.lines.map(AT))}function FT(e){let t=_e(e);if(!t.ok)return t.message;if(!PT(kT(CT(t.lines)),e))return`This prompt holds text the formatted view would change, so it stays in code.`}var IT=(0,S.createContext)(null);function Q(){let e=(0,S.useContext)(IT);return e??function(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)}(8),e}var LT=`astryx-richtext-code`,RT=!1;function zT(){if(RT||typeof document>`u`)return;RT=!0;let e=document.createElement(`style`);e.setAttribute(`data-astryx-richtext-code-syntax`,``),e.textContent=xe.map(e=>`.${LT}::highlight(astryx-${e}) { color: var(--color-syntax-${e}); }`).join(`
69
69
  `),document.head.append(e)}function BT(){return typeof CSS<`u`&&`highlights`in CSS&&typeof Highlight<`u`}function VT(e,t,n){let r=ye(e,t);if(n===e)return r;if(n!==e.replaceAll(`
70
70
  `,``))return null;let i=[],a=0;return e.split(`
71
- `).forEach((e,t)=>{for(let e of r[t]??[])i.push({type:e.type,start:a+e.start,end:a+e.end});a+=e.length}),[i]}function HT(){let[e]=Q();return(0,S.useEffect)(()=>{if(!BT())return;zT();let t=new Set,n=new Map,r=e=>{n.get(e)?.cleanup(),n.delete(e)},i=t=>{let i=e.getEditorState().read(()=>{let e=L(t);return Ev(e)?{code:e.getTextContent(),language:e.getLanguage()??``}:null}),a=e.getElementByKey(t);if(i==null||a==null){r(t);return}let o=n.get(t);if(o!=null&&o.element===a&&o.code===i.code&&o.language===i.language)return;o?.cleanup();let s=VT(i.code,i.language,a.textContent??``);s==null?n.delete(t):n.set(t,{element:a,...i,cleanup:be(a,s)})},a=e.registerMutationListener(wv,e=>{for(let[n,a]of e)a===`destroyed`?(t.delete(n),r(n)):(t.add(n),i(n))},{skipInitialization:!1}),o=e.registerUpdateListener(()=>{for(let e of t)i(e)});return()=>{a(),o();for(let e of[...n.keys()])r(e);t.clear()}},[e]),null}`${a[`--spacing-6`]}`,`${a[`--spacing-3`]}`,`${a[`--spacing-4`]}`,`${a[`--spacing-2`]}`,`${a[`--spacing-3`]}`,`${a[`--spacing-4`]}`,`${a[`--spacing-1`]}`,`${a[`--spacing-0-5`]}`,`${a[`--spacing-0`]}`,`${a[`--spacing-2`]}`,`${a[`--spacing-6`]}`,`${a[`--spacing-3`]}`,`${a[`--spacing-2`]}${o[`--size-element-sm`]}${a[`--spacing-3`]}`;var UT={providerDirection:{ksoyAI:`x1epdd7z`,$$css:!0},paragraph:{keoZOQ:`x1ftnraw xnhvf09 xe66n16`,k1K539:`x18pneqc xfo59cc x1vugyqv`,ks0D6T:`x7ep2pv`,k63SB2:`x1pd3egz`,kMwMTN:`x1heor9g`,$$css:!0},h1:{kMv6JI:`x1g81bgm`,kGuDYH:`xcg7oai`,k63SB2:`x1v68xuy`,kLWn49:`xfmsba7`,keoZOQ:`x13xmvwt xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h2:{kMv6JI:`x1g81bgm`,kGuDYH:`x1xvnhcw`,k63SB2:`x12yy4cs`,kLWn49:`x1cpk1wn`,keoZOQ:`x13xmvwt xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h3:{kMv6JI:`x1g81bgm`,kGuDYH:`xii13ha`,k63SB2:`x1jcxfy8`,kLWn49:`xwjzt0u`,keoZOQ:`x13xmvwt xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h4:{kMv6JI:`x1g81bgm`,kGuDYH:`x8tkxat`,k63SB2:`x2hcmsi`,kLWn49:`xqerer`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1hws3vx xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h5:{kMv6JI:`x1g81bgm`,kGuDYH:`xsgqta0`,k63SB2:`xno150v`,kLWn49:`xo3gurs`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1hws3vx xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h6:{kMv6JI:`x1g81bgm`,kGuDYH:`xw5ohdf`,k63SB2:`x1pw4frv`,kLWn49:`xeixjfn`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1hws3vx xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},quote:{keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1u2y747 xfo59cc`,kUOVxO:`xrxpjvj`,ks0D6T:`x7ep2pv`,kZCmMZ:`x1rey3nv`,k2ei4v:`xyumdvf`,kVhnKS:`x1t7ytsu`,kGJrpR:`x14ydlgx`,kMwMTN:`xv1l7n4`,$$css:!0},ul:{keoZOQ:`x1ftnraw xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,kZCmMZ:`x31w388`,kpqbRz:`x43c9pm`,$$css:!0},ol:{keoZOQ:`x1ftnraw xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,kZCmMZ:`x31w388`,kpqbRz:`x43c9pm`,$$css:!0},ulMarker0:{kH6xsr:`xtaz4m5`,$$css:!0},ulMarker1:{kH6xsr:`xrylv2j`,$$css:!0},ulMarker2:{kH6xsr:`x152237o`,$$css:!0},olMarker0:{kH6xsr:`x3yw8vx`,$$css:!0},olMarker1:{kH6xsr:`x1rrqm6h`,$$css:!0},olMarker2:{kH6xsr:`x19k9dhg`,$$css:!0},tableScrollableWrapper:{kXHlph:`xw2csxc`,ks0D6T:`x193iq5w`,k1xSpc:`xrvj5dj`,kumcoG:`x1mkdm3x`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1u2y747 xfo59cc`,$$css:!0},table:{kLvRdT:`x1mwwwfo`,kzqmXN:`xh8yej3`,kMzoRj:`x1litavf`,ksu8eU:`x1y0btm7`,kVAM5u:`x14i3s5s`,$$css:!0},tableRow:{kt9PQ7:`xso031l`,kfdmCh:`x1q0q8m5`,kL6WhQ:`xw8gpjh x1bta2m4`,$$css:!0},tableCell:{kB7OPa:`x1afcbsf`,k8WAf4:`xce4md1`,kg3NbH:`xf314gf`,k9WMMc:`x1yc453h`,kXLuUW:`xxymvpz`,kHjlTd:`x1mzt3pk`,ke9TFa:`xw8tdv1 x1qlsc9e`,k8ry5P:`x18b5jzi`,kBCPoo:`x1gejf6u`,$$css:!0},tableCellHeader:{k63SB2:`x2mo6ok`,kMwMTN:`xv1l7n4`,$$css:!0},tableCellSelected:{kMeerF:`xak0ai5`,k3XXqK:`x9ssot5`,kjBf7l:`x19bwoy8`,kInvED:`x1c097ug`,$$css:!0},code:{k1xSpc:`x1lliihq`,kMv6JI:`x9m5x89`,kGuDYH:`xp03k98`,kLWn49:`x17iicif`,kWkggS:`xzyc27v`,kMzoRj:`x1litavf`,ksu8eU:`x1y0btm7`,kVAM5u:`x14i3s5s`,kaIpWk:`xh6dtrn`,kLKAdn:`xekneqv x2w4pp4`,kGO01o:`xvmdzux`,kg3NbH:`x1pzlopt`,kB7OPa:`x9f619`,kzqmXN:`xeq5yr9`,k7Eaqz:`xejm5pw`,ks0D6T:`x193iq5w`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1u2y747 xfo59cc`,khDVqt:`x126k92a`,kTgw9:`x1yn0g08`,kHjlTd:`x1mzt3pk`,$$css:!0}};function WT(){let e=(...e)=>n(...e,UT.providerDirection).className??``,t=e=>n(e).className??``;return{paragraph:e(UT.paragraph),markdownExtensionBlock:e(UT.paragraph),heading:{h1:e(UT.h1),h2:e(UT.h2),h3:e(UT.h3),h4:e(UT.h4),h5:e(UT.h5),h6:e(UT.h6)},quote:e(UT.quote),list:{ul:e(UT.ul),ol:e(UT.ol),listitem:{className:`x1f3mx8c xmvvslv x1uerj9w x13xdy6z x1wqhfsw xkuhcwz xsgnyjk x10j6jf0 xfo59cc x1sle589 x81k3mc xovwveo x2i8j16 x8yim9t x1pvqllw xbj1ybn x1kuvm45`}.className,nested:{listitem:{className:`x1f3mx8c xmvvslv x1uerj9w x13xdy6z x1wqhfsw xkuhcwz xsgnyjk x10j6jf0 xfo59cc x1sle589 x81k3mc xovwveo x2i8j16 x8yim9t x1pvqllw xbj1ybn x1kuvm45`}.className},ulDepth:[t(UT.ulMarker0),t(UT.ulMarker1),t(UT.ulMarker2)],olDepth:[t(UT.olMarker0),t(UT.olMarker1),t(UT.olMarker2)]},link:{className:`xjse4m1 x1bvjpef x1ypdohk x16khyan`}.className,text:{bold:{className:`x2mo6ok`}.className,italic:{className:`x1k4tb9n`}.className,underline:{className:`x1bvjpef`}.className,strikethrough:{className:`xmqliwb`}.className,code:{className:`x9m5x89 xwmxj5m x7a5moj xx3sua9`}.className},code:`${e(UT.code)} ${LT}`,hr:{className:`xc342km x11xkdxz x13fuv20 x1pc3f07 x13xmvwt xnhvf09 xe66n16 x1qaki06 xfo59cc x1vugyqv`}.className,hrSelected:{className:`xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu`}.className,markdownExtensionSelected:{className:`xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu`}.className,table:e(UT.table),tableRow:e(UT.tableRow),tableCell:e(UT.tableCell),tableCellHeader:e(UT.tableCellHeader),tableCellSelected:t(UT.tableCellSelected),tableScrollableWrapper:e(UT.tableScrollableWrapper)}}function GT(){return R().getTextContent()}function KT(e,t=!0){if(e)return!1;let n=GT();return t&&(n=n.trim()),n===``}function qT(e){if(!KT(e,!1))return!1;let t=R().getChildren(),n=t.length;if(n>1)return!1;for(let e=0;e<n;e++){let n=t[e];if(P(n))return!1;if(N(n)){if(!Uc(n)||n.__indent!==0)return!1;let e=n.getChildren(),t=e.length;for(let n=0;n<t;n++){let t=e[n];if(!O(t))return!1}}}return!0}function JT(e){return()=>qT(e)}var $=t(),YT=Be?S.useLayoutEffect:S.useEffect;function XT({editor:e,ariaActiveDescendant:t,ariaAutoComplete:n,ariaControls:r,ariaDescribedBy:i,ariaErrorMessage:a,ariaExpanded:o,ariaInvalid:s,ariaLabel:c,ariaLabelledBy:l,ariaMultiline:u,ariaOwns:d,ariaRequired:f,autoCapitalize:p,className:m,id:h,role:g=`textbox`,spellCheck:_=!0,style:v,tabIndex:y,"data-testid":b,...x},ee){let[te,ne]=(0,S.useState)(e.isEditable()),re=(0,S.useCallback)(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),ie=(0,S.useMemo)(()=>function(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}(ee,re),[re,ee]);return YT(()=>(ne(e.isEditable()),e.registerEditableListener(e=>{ne(e)})),[e]),(0,$.jsx)(`div`,{"aria-activedescendant":te?t:void 0,"aria-autocomplete":te?n:`none`,"aria-controls":te?r:void 0,"aria-describedby":i,...a==null?{}:{"aria-errormessage":a},"aria-expanded":te&&g===`combobox`?!!o:void 0,...s==null?{}:{"aria-invalid":s},"aria-label":c,"aria-labelledby":l,"aria-multiline":u,"aria-owns":te?d:void 0,"aria-readonly":!te||void 0,"aria-required":f,autoCapitalize:p,className:m,contentEditable:te,"data-testid":b,id:h,ref:ie,role:g,spellCheck:_,style:v,tabIndex:y??(te?void 0:-1),...x})}var ZT=(0,S.forwardRef)(XT);function QT(e){return e.read(`latest`,JT(e.isComposing()))}var $T=(0,S.forwardRef)(eE);function eE(e,t){let{placeholder:n,...r}=e,[i]=Q();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ZT,{editor:i,...r,ref:t}),n!=null&&(0,$.jsx)(tE,{editor:i,content:n})]})}function tE({content:e,editor:t}){let n=function(e){let[t,n]=(0,S.useState)(()=>QT(e));return YT(()=>{function t(){let t=QT(e);n(t)}return t(),zf(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),t}(t),[r,i]=(0,S.useState)(t.isEditable());if(YT(()=>(i(t.isEditable()),t.registerEditableListener(e=>{i(e)})),[t]),!n)return null;let a=null;return typeof e==`function`?a=e(r):e!==null&&(a=e),a===null?null:(0,$.jsx)(`div`,{"aria-hidden":!0,children:a})}var nE=class extends S.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.props.onError(e instanceof Error?e:Error(String(e),{cause:e}),t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function rE({children:e,fallback:t,onError:n}){return(0,$.jsx)(nE,{fallback:t===void 0?(0,$.jsx)(`div`,{style:{border:`1px solid #f00`,color:`#f00`,padding:`8px`},children:`An error was thrown.`}):t,onError:n,children:e})}var iE={name:`@lexical/react/ReactProvider`},aE=te();function oE({contentEditable:e,children:t}){return(0,$.jsxs)($.Fragment,{children:[e,t]})}var sE={build(e,t,n){n.getPeer(iE.name)||function(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)}(321,[...n.getDirectDependentNames()].join(` `));let r=[e,{getTheme:()=>e._config.theme}];return{Component:function(e,t){let[n]=t,r=e.decorators.map(e=>typeof e==`function`?(0,$.jsx)(e,{context:t}):e);return function(i){let{EditorChildrenComponent:a=e.EditorChildrenComponent,ErrorBoundary:o=e.ErrorBoundary,contentEditable:s=e.contentEditable,children:c}=i,l=function(e,t){let[n,r]=(0,S.useMemo)(()=>[t=>e.registerDecoratorListener(t),()=>e.getDecorators()],[e]),i=(0,S.useSyncExternalStore)(n,r,r),a=function(e){let[t,n]=(0,S.useMemo)(()=>[e.registerRootListener.bind(e),e.getRootElement.bind(e)],[e]);return(0,S.useSyncExternalStore)(t,n,n)}(e);return(0,S.useMemo)(()=>{let n=t=>e._onError(t),r=[];for(let a in i){let o=e.getElementByKey(a);if(o!==null){let e=(0,$.jsx)(t,{onError:n,children:(0,$.jsx)(S.Suspense,{fallback:null,children:i[a]})});r.push((0,aE.createPortal)(e,o,a))}}return r},[t,i,e,a])}(n,o),u=(0,S.useMemo)(()=>r.map((e,t)=>(0,$.jsx)(o,{onError:e=>{n._onError(e)},children:(0,$.jsx)(S.Suspense,{fallback:null,children:e})},t)),[o]);return(0,$.jsx)(IT.Provider,{value:t,children:(0,$.jsxs)(a,{context:t,contentEditable:s,children:[c,u,l]})})}}(t,r),context:r}},config:{EditorChildrenComponent:oE,ErrorBoundary:rE,contentEditable:(0,$.jsx)($T,{}),decorators:[]},mergeConfig(e,t){let n=Ff(e,t);return t.decorators&&(n.decorators=t.decorators.length>0?[...e.decorators,...t.decorators]:e.decorators),n},name:`@lexical/react/React`,peerDependencies:[[`@lexical/react/ReactProvider`]]};function cE({extension:e,children:t,contentEditable:n}){let r=(0,S.useMemo)(()=>ym.fromExtensions([iE,Pf(sE,n===void 0?{}:{contentEditable:n}),e]).buildEditor(),[n,e]);(0,S.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{e=!0}),()=>{e&&r.dispose()}},[r]);let{Component:i}=jm(r,sE).output;return(0,$.jsx)(i,{children:t})}var lE=Be?S.useLayoutEffect:S.useEffect;function uE(e){let[t]=Q(),n=(0,S.useMemo)(()=>e(t),[t,e]),[r,i]=(0,S.useState)(()=>n.initialValueFn()),a=(0,S.useRef)(r);return lE(()=>{let{initialValueFn:e,subscribe:t}=n,r=e();return a.current!==r&&(a.current=r,i(r)),t(e=>{a.current=e,i(e)})},[n,e]),r}function dE(e){return{initialValueFn:()=>e.isEditable(),subscribe:t=>e.registerEditableListener(t)}}function fE(){return uE(dE)}function pE(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)}function mE({editor:e,ErrorBoundary:t}){return function(e,t){let[n,r]=(0,S.useMemo)(()=>[t=>e.registerDecoratorListener(t),()=>e.getDecorators()],[e]),i=(0,S.useSyncExternalStore)(n,r,r),a=function(e){let[t,n]=(0,S.useMemo)(()=>[e.registerRootListener.bind(e),e.getRootElement.bind(e)],[e]);return(0,S.useSyncExternalStore)(t,n,n)}(e);return(0,S.useMemo)(()=>{let n=t=>e._onError(t),r=[];for(let a in i){let o=e.getElementByKey(a);if(o!==null){let e=(0,$.jsx)(t,{onError:n,children:(0,$.jsx)(S.Suspense,{fallback:null,children:i[a]})});r.push((0,aE.createPortal)(e,o,a))}}return r},[t,i,e,a])}(e,t)}function hE({editor:e,ErrorBoundary:t}){return function(e){let t=ym.maybeFromEditor(e);if(t&&t.hasExtensionByName(iE.name)){for(let e of[`@lexical/plain-text`,`@lexical/rich-text`])t.hasExtensionByName(e)&&pE(320,e);return!0}return!1}(e)?null:(0,$.jsx)(mE,{editor:e,ErrorBoundary:t})}var gE=Be?S.useLayoutEffect:S.useEffect;function _E(e){return e.read(`latest`,JT(e.isComposing()))}function vE({contentEditable:e,placeholder:t=null,ErrorBoundary:n}){let[r]=Q();return function(e){gE(()=>zf(R_(e),n_(e)),[e])}(r),(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(yE,{content:t}),(0,$.jsx)(hE,{editor:r,ErrorBoundary:n})]})}function yE({content:e}){let[t]=Q(),n=function(e){let[t,n]=(0,S.useState)(()=>_E(e));return gE(()=>{function t(){let t=_E(e);n(t)}return t(),zf(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),t}(t),r=fE();return n?typeof e==`function`?e(r):e:null}function bE(e,t,n){let r=n(),i=0,a=r,o=0,s=null;return(c,l,u,d,f,p)=>{let m=n();if(p.has(`composition-start`)&&(a=r,o=i,s=c),p.has(`historic`))return i=0,r=m,2;p.has(`composition-end`)&&s&&(r=a,i=o,c=s);let h=p.has(`paste`)||p.has(`cut`)?0:function(e,t,n,r,i){if(e===null||n.size===0&&r.size===0&&!i)return 0;let a=t._selection,o=e._selection;if(i)return 1;if(!(k(a)&&k(o)&&o.isCollapsed()&&a.isCollapsed()))return 0;let s=function(e,t,n){let r=e._nodeMap,i=[];for(let e of t){let t=r.get(e);t!==void 0&&i.push(t)}for(let[e,t]of n){if(!t)continue;let n=r.get(e);n===void 0||F(n)||i.push(n)}return i}(t,n,r);if(s.length===0)return 0;if(s.length>1){let n=t._nodeMap,r=n.get(a.anchor.key),i=n.get(o.anchor.key);return r&&i&&!e._nodeMap.has(r.__key)&&O(r)&&r.__text.length===1&&a.anchor.offset===1?2:0}let c=s[0],l=e._nodeMap.get(c.__key);if(!O(l)||!O(c)||l.__mode!==c.__mode)return 0;let u=l.__text,d=c.__text;if(u===d)return 0;let f=a.anchor,p=o.anchor;if(f.key!==p.key||f.type!==`text`)return 0;let m=f.offset,h=p.offset,g=d.length-u.length;return g===1&&h===m-1?2:g===-1&&h===m+1?3:g===-1&&h===m?4:0}(c,l,d,f,e.isComposing()),g=(()=>{let n=u===null||u.editor===e,a=p.has(Ra);if(!a&&n&&p.has(`history-merge`))return 0;if(h===1)return 2;if(c===null)return 1;let o=l._selection;if(!(d.size>0||f.size>0))return o===null?2:0;let s=typeof t==`number`?t:t.peek();return!1===a&&h!==0&&h===i&&m<r+s&&n||d.size===1&&function(e,t,n){let r=t._nodeMap.get(e),i=n._nodeMap.get(e),a=t._selection,o=n._selection;return!(k(a)&&k(o)&&a.anchor.type===`element`&&a.focus.type===`element`&&o.anchor.type===`text`&&o.focus.type===`text`||!O(r)||!O(i)||r.__parent!==i.__parent)&&JSON.stringify(t.read(()=>r.exportJSON()))===JSON.stringify(n.read(()=>i.exportJSON()))}(Array.from(d)[0],c,l)?0:1})();return r=m,i=h,g}}function xE(e,t){if(t!==null&&t.editor===e.editor)return t;let{editor:n}=e,r=n.getEditorState();return r.isEmpty()?null:{editor:n,editorState:r}}function SE(e,t){e.undoStack=[],e.redoStack=[],e.current=null,t&&t(e)}function CE(e,t,n,r=Date.now,i,a=null){let o=bE(e,n,r),s=()=>{i&&i(t)};return s(),zf(e.registerCommand(ii,()=>(function(e,t,n){let r=t.redoStack,i=t.undoStack;if(i.length!==0){let a=t.current,o=i.pop();if(o){let t=xE(o,a);t!==null&&(r.push(t),e.dispatchCommand(Mi,!0))}i.length===0&&e.dispatchCommand(Ni,!1),t.current=o||null,n&&n(t),o&&o.editor.setEditorState(o.editorState,{tag:`historic`})}}(e,t,i),!0),0),e.registerCommand(ai,()=>(function(e,t,n){let r=t.redoStack,i=t.undoStack;if(r.length!==0){let a=t.current,o=r.pop();if(o){let t=xE(o,a);t!==null&&(i.push(t),e.dispatchCommand(Ni,!0))}r.length===0&&e.dispatchCommand(Mi,!1),t.current=o||null,n&&n(t),o&&o.editor.setEditorState(o.editorState,{tag:`historic`})}}(e,t,i),!0),0),e.registerCommand(Ai,()=>(SE(t,i),!1),0),e.registerCommand(ji,()=>(SE(t,i),e.dispatchCommand(Mi,!1),e.dispatchCommand(Ni,!1),!0),0),e.registerUpdateListener(({editorState:n,prevEditorState:r,dirtyLeaves:i,dirtyElements:c,tags:l})=>{let u=t.current,d=t.redoStack,f=t.undoStack,p=u===null?null:u.editorState;if(u!==null&&n===p)return;let m=o(r,n,u,i,c,l);if(m===1){d.length!==0&&(t.redoStack=[],e.dispatchCommand(Mi,!1));let n=function(e,t,n){return n===null?null:n.editor===e?{...n}:t.isEmpty()?null:{editor:e,editorState:t}}(e,r,u);if(n!==null){f.push(n);let t=typeof a==`number`||a===null?a:a.peek();t!==null&&f.length>t&&f.splice(0,f.length-t),e.dispatchCommand(Ni,!0)}}else if(m===2)return;t.current={editor:e,editorState:n},s()}))}function wE(){return{current:null,redoStack:[],undoStack:[]}}function TE({delay:e,externalHistoryState:t}){let[n]=Q();return function(e,t,n=1e3){let r=(0,S.useMemo)(()=>t||wE(),[t]);(0,S.useEffect)(()=>CE(e,r,n),[n,e,r])}(n,t,e),null}function EE({hasStrictIndent:e=!1,shouldPreserveNumbering:t=!1}){let[n]=Q();return(0,S.useEffect)(()=>{if(!n.hasNodes([lg,ng]))throw Error(`ListPlugin: ListNode and/or ListItemNode not registered on editor`)},[n]),(0,S.useEffect)(()=>zf(_g(n,{restoreNumbering:t}),e?vg(n):()=>{}),[n,e,t]),function(e){(0,S.useEffect)(()=>_g(e),[e])}(n),null}function DE({validateUrl:e,attributes:t}){let[n]=Q();return(0,S.useEffect)(()=>{if(!n.hasNodes([J_]))throw Error(`LinkPlugin: LinkNode not registered on editor`)}),(0,S.useEffect)(()=>lv(n,$p({attributes:t,validateUrl:e})),[n,e,t]),null}function OE({maxIndent:e,$canIndent:t}){let[n]=Q();return(0,S.useEffect)(()=>Pb(n,e,t),[n,e,t]),null}var kE={dependencies:[Em],export:e=>km(e)?`***`:null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(e,t,n,r)=>{let i=Om();r||e.getNextSibling()!=null?e.replace(i):e.insertBefore(i),i.selectNext()},triggerOnEnter:!0,type:`element`};function AE(){return[kE,...Qx]}var jE=AE();function ME({transformers:e=jE}){let[t]=Q();return(0,S.useEffect)(()=>SS(t,e),[t,e]),null}var NE=Be?S.useLayoutEffect:S.useEffect;function PE({ignoreHistoryMergeTagChange:e=!0,ignoreSelectionChange:t=!1,onChange:n}){let[r]=Q();return NE(()=>{if(n)return r.registerUpdateListener(({editorState:i,dirtyElements:a,dirtyLeaves:o,prevEditorState:s,tags:c})=>{t&&a.size===0&&o.size===0||e&&c.has(`history-merge`)||s.isEmpty()||n(i,r,c)})},[r,e,t,n]),null}function FE({hasCellMerge:e=!0,hasCellBackgroundColor:t=!0,hasTabHandler:n=!0,hasHorizontalScroll:r=!1,hasNestedTables:i=!1}){let[a]=Q();(0,S.useEffect)(()=>{vb(a)!==r&&(bb(a,r),a.update(Fs))},[a,r]);let o=function(e){let[t]=(0,S.useState)(()=>Hp(e));return t.peek()!==e&&(t.value=e),t}(i);return(0,S.useEffect)(()=>Mb(a,{hasNestedTables:o}),[a,o]),(0,S.useEffect)(()=>jb(a,n),[a,n]),(0,S.useEffect)(()=>{if(!e)return Ab(a)},[a,e]),(0,S.useEffect)(()=>{if(!t)return a.registerNodeTransform(Xv,e=>{e.getBackgroundColor()!==null&&e.setBackgroundColor(null)})},[a,t,e]),null}var IE=st.strikethrough,LE=st.bold|st.italic;function RE(e){let t=e.__format,n=[];return(t&IE)!==0&&n.push(`del`),(t&LE)===LE&&n.push(`em`),n}function zE(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var BE=Pf(Th,{overrides:[th([co],{$createDOM(e,t){let n=t();for(let t of[...RE(e)].reverse()){let e=document.createElement(t);e.append(n),n=e}return n},$updateDOM(e,t,n,r,i){let a=RE(e);if(!zE(a,RE(t)))return!0;if(a.length===0)return r();let o=n;for(let e of a){if(o?.tagName.toLowerCase()!==e)return!0;o=o.firstElementChild}return o==null||e.updateDOM(t,o,i._config)}})]}),VE=4,HE=24,UE=2,WE=20;function GE(e){let[t,...n]=e;return t==null?[]:t.map((e,t)=>{let r=Math.max(e,...n.map(e=>e[t]??0)),i=Math.ceil(r/UE);return Math.min(HE,Math.max(VE,i,Math.min(e,WE)))})}function KE(){let[e]=Q();return(0,S.useEffect)(()=>{let t=0,n=()=>{t=0,e.getEditorState().read(()=>{for(let t of R().getChildren().filter(Z)){let n=t.getChildren().filter(ay).map(e=>e.getChildren().filter(Y)),r=GE(n.map(e=>e.map(e=>e.getTextContentSize())));n[0]?.forEach((t,n)=>{let i=e.getElementByKey(t.getKey()),a=`${r[n]}ch`;i!=null&&i.style.minWidth!==a&&(i.style.minWidth=a)})}})},r=()=>{t===0&&(t=requestAnimationFrame(n))},i=e.registerUpdateListener(r);return r(),()=>{cancelAnimationFrame(t),i()}},[e]),null}var qE={header:{kVAEAm:`x10l6tqk`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`x1qughib`,k8WAf4:`xce4md1`,kg3NbH:`x1pzlopt`,kB7OPa:`x9f619`,$$css:!0},corner:{kVAEAm:`x10l6tqk`,k1xSpc:`x78zum5`,kjj79g:`x13a6bvl`,kmVPX3:`xlsj2fj`,kB7OPa:`x9f619`,kfzvcC:`x47corl`,$$css:!0},cornerButton:{kfzvcC:`x67bb7w`,$$css:!0},copyButton:{kMwMTN:`x1mjzq1q`,$$css:!0},placement:(e,t,n)=>[{k87sOh:e==null?e:`xjbys53`,kbCHJM:t==null?t:`xgq9j65`,kzqmXN:n==null?n:`x5lhr3w`,$$css:!0},{"--x-top":(e=>typeof e==`number`?e+`px`:e??void 0)(e),"--x-left":(e=>typeof e==`number`?e+`px`:e??void 0)(t),"--x-width":(e=>typeof e==`number`?e+`px`:e??void 0)(n)}]};function JE(e){return e==null||e===``||e===YE?null:e}var YE=`plaintext`;function XE(e,t){return e.length===t.length&&e.every((e,n)=>e.key===t[n].key&&e.language===t[n].language&&e.top===t[n].top&&e.left===t[n].left&&e.width===t[n].width)}function ZE({placement:e}){let[t]=Q(),r=v(),{copy:i,isCopied:a}=ve({announce:r(`@astryx.codeBlock.copied`)}),o=(0,$.jsx)(ae,{variant:`ghost`,size:`sm`,icon:(0,$.jsx)(x,{icon:a?`check`:`copy`,size:`sm`,color:`inherit`}),tooltip:r(`@astryx.codeBlock.copyCode`),label:r(a?`@astryx.codeBlock.copied`:`@astryx.codeBlock.copyCode`),onClick:()=>{let n=t.getEditorState().read(()=>L(e.key)?.getTextContent()??``);i(n)},xstyle:[qE.copyButton,e.language==null&&qE.cornerButton]}),s=qE.placement(e.top,e.left,e.width);return e.language==null?(0,$.jsx)(`div`,{"data-richtext-code-header":``,...n(qE.corner,s),children:o}):(0,$.jsxs)(`div`,{"data-richtext-code-header":``,...n(qE.header,s),children:[(0,$.jsx)(`span`,{className:`x141an7d x9m5x89 x1e4wzip x1ltkj2j x1mjzq1q xeuugli xb3r6kr xlyipyv xuxw1ft`,children:e.language}),o]})}function QE(){let[e]=Q(),[t,n]=(0,S.useState)([]);return(0,S.useEffect)(()=>{let t=0,r=()=>{t=0;let r=e.getRootElement(),i=r?.parentElement;if(r==null||i==null){n(e=>e.length===0?e:[]);return}let a=i.getBoundingClientRect(),o=e.getEditorState().read(()=>R().getChildren().filter(Ev).flatMap(t=>{let n=e.getElementByKey(t.getKey());if(n==null)return[];let r=n.getBoundingClientRect();return[{key:t.getKey(),language:JE(t.getLanguage()),top:r.top-a.top+n.clientTop,left:r.left-a.left+n.clientLeft,width:n.clientWidth}]}));n(e=>XE(e,o)?e:o)},i=()=>{t===0&&(t=requestAnimationFrame(r))},a=typeof ResizeObserver>`u`?null:new ResizeObserver(i),o=e.registerRootListener(e=>{a?.disconnect(),e!=null&&a?.observe(e),i()}),s=e.registerUpdateListener(i);return window.addEventListener(`resize`,i),i(),()=>{cancelAnimationFrame(t),a?.disconnect(),o(),s(),window.removeEventListener(`resize`,i)}},[e]),(0,$.jsx)($.Fragment,{children:t.map(e=>(0,$.jsx)(ZE,{placement:e},e.key))})}function $E(e,t){return e.read(`latest`,()=>{let e=L(t);return e!==null&&e.isSelected()})}function eD(e){let[t]=Q(),[n,r]=(0,S.useState)(()=>$E(t,e));return(0,S.useEffect)(()=>{let n=!0,i=t.registerUpdateListener(()=>{n&&r($E(t,e))});return()=>{n=!1,i()}},[t,e]),[n,(0,S.useCallback)(n=>{t.update(()=>{let t=j();if(!A(t)){let r=n?null:L(e);if(r!==null&&!r.isSelected())return;t=es(),z(t)}A(t)&&(n?t.add(e):t.delete(e))})},[t,e]),(0,S.useCallback)(()=>{t.update(()=>{let e=j();A(e)&&e.clear()})},[t])]}function tD(e,t){let n=t.find(t=>t.name===e.plugin);if(n==null||n.apiVersion!==e.apiVersion)return null;let r=e.display===`inline`?Oe(e.source,{plugins:[n]}):Te(e.source,{plugins:[n]}).children,[i]=r;if(r.length!==1||i?.type!==`extension`)return null;let a=i;return a.plugin===e.plugin&&a.name===e.name&&a.display===e.display&&a.source===e.source?a:null}var nD=[[`strikethrough`,`del`],[`italic`,`em`],[`bold`,`strong`]],rD=new Set(nD.map(([e])=>e));function iD({facts:e,format:t,nodeKey:n,plugins:r}){let[i]=Q(),[a,o,s]=eD(n);(0,S.useEffect)(()=>i.registerCommand(Ur,e=>{let t=i.getElementByKey(n);return!i.isEditable()||t==null||!(e.target instanceof Node)||!t.contains(e.target)?!1:(s(),o(!0),!0)},1),[s,i,n,o]),(0,S.useEffect)(()=>{let e=i.getElementByKey(n),t=i._config.theme.markdownExtensionSelected;e!=null&&typeof t==`string`&&t!==``&&(a?Lf(e,t):Rf(e,t))},[i,a,n]);let c=(0,S.useMemo)(()=>tD(e,r),[e,r]),l=c==null?e.source:(0,$.jsx)(De,{plugins:r,node:c});for(let[e,n]of[...nD].reverse())(t&st[e])!==0&&(l=(0,$.jsx)(n,{children:l}));return l}function aD(e){e.update(()=>{for(let{node:e}of up())Wb(e)&&e.markDirty()},{tag:za})}function oD(e,t){let n=Gb(e);return n==null?null:(n.getFormatFlags(t,null)&st[t])!==0}function sD({extensions:e,transformers:t}){let[n]=Q(),r=(0,S.useMemo)(()=>sC(e,t),[e,t]);return(0,S.useEffect)(()=>{let e=Lb(n,(e,t,n)=>(0,$.jsx)(iD,{facts:e,format:t,nodeKey:n,plugins:r}));return aD(n),()=>{e(),aD(n)}},[n,r]),(0,S.useEffect)(()=>n.registerCommand(ni,e=>{let t=j();if(!rD.has(e)||t==null)return!1;let n=t.getNodes().filter(e=>Wb(e)&&e.isInline());if(n.length===0)return!1;let r=k(t)?oD(t,e):null;k(t)&&t.formatText(e);let i=r??!n.every(t=>t.hasFormat(e));for(let t of n)t.setFormatFlag(e,i);return!0},1),[n]),null}var cD={checkbox:{kVAEAm:`x10l6tqk`,$$css:!0},placement:(e,t)=>[{k87sOh:e==null?e:`xjbys53`,kbCHJM:t==null?t:`xgq9j65`,$$css:!0},{"--x-top":(e=>typeof e==`number`?e+`px`:e??void 0)(e),"--x-left":(e=>typeof e==`number`?e+`px`:e??void 0)(t)}]},lD=20,uD=`data-richtext-task`;function dD(){let e=[],t=n=>{if(q(n))for(let r of n.getChildren())K(r)&&(!(r.getChildrenSize()===1&&q(r.getFirstChild()))&&n.getListType()!==`number`&&e.push({item:r,task:bw(r)}),r.getChildren().forEach(t))};return R().getChildren().forEach(t),e}function fD(e,t){return e.length===t.length&&e.every((e,n)=>e.key===t[n].key&&e.checked===t[n].checked&&e.label===t[n].label&&e.top===t[n].top&&e.left===t[n].left)}function pD({isReadOnly:e}){let[t]=Q(),r=(0,S.useId)(),[i,a]=(0,S.useState)([]);return(0,S.useEffect)(()=>e?void 0:Ew(t),[t,e]),(0,S.useEffect)(()=>{let e=0,n=()=>{e=0;let n=t.getRootElement(),i=n?.parentElement;if(n==null||i==null){a(e=>e.length===0?e:[]);return}let o=i.getBoundingClientRect(),s=t.getEditorState().read(()=>dD().flatMap(({item:e,task:n})=>{let i=t.getElementByKey(e.getKey());if(i==null)return[];if(n==null)return i.removeAttribute(uD),i.removeAttribute(`aria-owns`),[];i.setAttribute(uD,``),i.removeAttribute(`role`),i.removeAttribute(`aria-checked`),i.removeAttribute(`tabindex`),i.setAttribute(`aria-owns`,`${r}-task-${e.getKey()}`);let a=i.getBoundingClientRect(),s=getComputedStyle(i),c=s.direction===`rtl`;return[{key:e.getKey(),checked:n===`checked`,label:e.getTextContent(),top:a.top-o.top+parseFloat(s.paddingTop||`0`),left:(c?a.right-lD:a.left)-o.left}]}));a(e=>fD(e,s)?e:s)},i=()=>{e===0&&(e=requestAnimationFrame(n))},o=typeof ResizeObserver>`u`?null:new ResizeObserver(i),s=t.registerRootListener(e=>{o?.disconnect(),e!=null&&o?.observe(e),i()}),c=t.registerUpdateListener(i);return window.addEventListener(`resize`,i),i(),()=>{cancelAnimationFrame(e),o?.disconnect(),s(),c(),window.removeEventListener(`resize`,i)}},[t,r]),(0,$.jsx)($.Fragment,{children:i.map(i=>(0,$.jsx)(`div`,{id:`${r}-task-${i.key}`,"data-richtext-task-checkbox":``,...n(cD.checkbox,cD.placement(i.top,i.left)),children:(0,$.jsx)(se,{ref:e=>{e!=null&&(e.tabIndex=-1)},size:`sm`,label:i.label,isLabelHidden:!0,value:i.checked,isReadOnly:e,onChange:e=>{t.update(()=>{let t=L(i.key);K(t)&&xw(t,e?`checked`:`unchecked`)})}})},i.key))})}var mD=JSON.stringify({root:{children:[{children:[],direction:null,format:``,indent:0,type:`paragraph`,version:1}],direction:null,format:``,indent:0,type:`root`,version:1}}),hD={wrapper:{"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,kXwgrk:`xdt5ytf`,kGNEyG:`x1qjc9v5`,kOIVth:`xsn7fz1`,k8WAf4:`x1hp7d8q`,kg3NbH:`x17a0aqu`,kAzted:`x65nank`,$$css:!0},contentEditable:{k1xSpc:`x1lliihq`,kzqmXN:`xh8yej3`,kMzoRj:`xc342km`,ksu8eU:`xng3xce`,kmVPX3:`x1717udv`,kI3sdo:`x1a2a7pz`,kMwMTN:`x1tgivj0`,$$css:!0},disabled:{kkrTdU:`xt0e3qv x16khyan`,$$css:!0}},gD={contentEditableMinHeight:e=>[{kAzted:e==null?e:`x82snj4`,$$css:!0},{"--x-minHeight":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]},_D=.8,vD=function({label:e,isLabelHidden:t=!1,description:i,isOptional:a=!1,isRequired:o=!1,defaultValue:s,onChange:c,placeholder:l,isReadOnly:u=!1,isDisabled:_=!1,status:y,statusVariant:b=`attached`,width:x,minHeight:ee=`4.5rem`,labelTooltip:te,size:re,nodes:ae,toolbar:oe,plugins:se,hasMarkdownShortcuts:ce=!0,transformers:le=nT,markdownExtensions:ue,hasAutoFocus:de=!1,tabEscapeHint:fe,maxLength:me,namespace:he=`astryx-editor`,xstyle:ge,className:_e,style:ve,ref:ye,...be}){let xe=ie(re,`md`),Se=v(),Ce=fe??Se(`@astryx.richTextEditor.tabEscapeHint`),we=(0,S.useId)(),Te=(0,S.useId)(),Ee=(0,S.useId)(),De=(0,S.useId)(),Oe=(0,S.useId)(),ke=(0,S.useId)(),Ae=(0,S.useId)(),[je,Me]=(0,S.useState)(0),Ne=(0,S.useRef)(null);Ne.current===null&&(Ne.current=WT());let Pe=!u&&!_,Fe=(0,S.useMemo)(()=>[...le],[le]),Ie=(0,S.useRef)(null);Ie.current===null&&(Ie.current=Nf({name:`@astryxdesign/richtext/RichTextEditor`,namespace:he,theme:Ne.current,editable:Pe,nodes:ae?[...qb,...ae]:[...qb],dependencies:[Am,BE],$initialEditorState:s??void 0,onError(e){throw e}}));let Le=Pe&&Ce!==``,C=oe!=null&&typeof oe!=`boolean`,{statusIcon:Re,describedBy:ze}=pe({status:y,statusVariant:b}),Be=[i?Ee:null,b!==`tooltip`&&y?.message?De:null,ze,l?Oe:null,me==null?null:ke,Le?Ae:null].filter(Boolean).join(` `)||void 0;return(0,$.jsxs)(p,{label:e,isLabelHidden:t,description:i,inputID:we,labelID:Te,descriptionID:i?Ee:void 0,isOptional:a,isRequired:o,isDisabled:_,status:y?{type:y.type,message:y.message,messageID:y.message?De:void 0}:void 0,statusVariant:b,labelTooltip:te,width:x,children:[(0,$.jsxs)(`div`,{...d(r(`rich-text-editor`,{size:xe,status:y?.type??null}),n(g.base,hD.wrapper,_&&g.disabled,_&&hD.disabled,y&&m[y.type],y&&!_&&!u&&h[y.type],y&&f[y.type],ge),_e,ve),children:[(0,$.jsxs)(cE,{extension:Ie.current,contentEditable:null,children:[C?oe:null,(0,$.jsxs)(`div`,{...{0:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf`},4:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf x178xt8z x13fuv20 x1pc3f07`},2:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf xp74n0j`},6:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf x178xt8z x13fuv20 x1pc3f07 xp74n0j`},1:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf xce4md1`},5:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf x178xt8z x13fuv20 x1pc3f07 xce4md1`},3:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf xp74n0j xce4md1`},7:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf x178xt8z x13fuv20 x1pc3f07 xp74n0j xce4md1`}}[!!C<<2|!!Re<<1|xe===`lg`],children:[(0,$.jsxs)(`div`,{className:`x1n2onr6 xh8yej3 x9ynric xjm74w1 xf9zqsd xw6l6zx`,children:[(0,$.jsx)(vE,{contentEditable:(0,$.jsx)(wD,{id:we,ariaLabel:t?e:void 0,ariaLabelledBy:t?void 0:Te,ariaDescribedBy:Be,ariaRequired:o&&!a,ariaInvalid:y?.type===`error`,isReadOnly:u,isDisabled:_,placeholderText:l,placeholderID:Oe,minHeight:ee,rest:be}),placeholder:null,ErrorBoundary:rE}),(0,$.jsx)(TE,{}),(0,$.jsx)(EE,{}),(0,$.jsx)(pD,{isReadOnly:u||_}),(0,$.jsx)(DE,{}),(0,$.jsx)(FE,{hasCellMerge:!1,hasCellBackgroundColor:!1,hasTabHandler:!1,hasHorizontalScroll:!0}),(0,$.jsx)(KE,{}),(0,$.jsx)(QE,{}),(0,$.jsx)(HT,{}),ue!=null&&ue.length>0?(0,$.jsx)(sD,{extensions:ue,transformers:Fe}):null,(0,$.jsx)(OE,{}),(0,$.jsx)(bD,{}),ce&&(0,$.jsx)(ME,{transformers:Fe}),de&&(0,$.jsx)(xD,{}),c&&(0,$.jsx)(PE,{onChange:c,ignoreHistoryMergeTagChange:!0,ignoreSelectionChange:!0}),se,(0,$.jsx)(SD,{editorRef:ye,editable:Pe,transformers:Fe}),me!=null&&(0,$.jsx)(CD,{onCountChange:Me})]}),Re&&(0,$.jsx)(`div`,{className:`x10l6tqk xctzyg x72tfeb x1vjfegm x78zum5 x6s0dn4`,children:Re})]})]}),Le&&(0,$.jsx)(ne,{id:Ae,children:Ce})]}),me!=null&&(0,$.jsxs)(`div`,{id:ke,...{0:{className:`x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d xv1l7n4`},1:{className:`x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d xjt36v0`}}[je>me|0],children:[je,`/`,me,(0,$.jsx)(ne,{"aria-live":`polite`,children:je>=me*_D?je>me?Se(`@astryx.textArea.charactersOverLimit`,{count:je-me}):Se(`@astryx.textArea.charactersRemaining`,{count:me-je}):``})]})]})};vD.displayName=`RichTextEditor`;var yD=new Set([`Escape`,`Tab`,`Shift`,`Control`,`Alt`,`Meta`]);function bD(){let[e]=Q();return(0,S.useEffect)(()=>{let t=!1;return zf(e.registerCommand(gi,()=>(t=!0,!0),1),e.registerCommand(vi,()=>t?(t=!1,!0):!1,1),e.registerCommand(oi,e=>(t&&!yD.has(e.key)&&(t=!1),!1),1),e.registerCommand(Fi,()=>(t=!1,!1),1))},[e]),null}function xD(){let[e]=Q();return(0,S.useEffect)(()=>{e.focus()},[e]),null}function SD({editorRef:e,editable:t,transformers:n}){let[r]=Q(),i=(0,S.useRef)(t);return(0,S.useEffect)(()=>{i.current!==t&&(i.current=t,r.setEditable(t))},[r,t]),(0,S.useImperativeHandle)(e,()=>({focus:()=>{t&&r.focus()},clear:()=>{t&&r.setEditorState(r.parseEditorState(mD))},getEditorState:()=>r.getEditorState(),getMarkdown:()=>r.getEditorState().read(()=>uw(n)),getHTML:()=>r.getEditorState().read(()=>kh(r,null)),getEditor:()=>r}),[r,t,n]),null}function CD({onCountChange:e}){let[t]=Q();return(0,S.useEffect)(()=>(e(t.getRootElement()?.textContent?.length??0),t.registerTextContentListener(t=>{e(t.length)})),[t,e]),null}function wD({id:e,ariaLabel:t,ariaLabelledBy:r,ariaDescribedBy:i,ariaRequired:a,ariaInvalid:o,isReadOnly:s,isDisabled:c,placeholderText:l,placeholderID:u,minHeight:d,rest:f}){let p={id:e,role:`textbox`,"aria-multiline":`true`,"aria-label":t,"aria-labelledby":r,"aria-describedby":i,"aria-required":a?`true`:void 0,"aria-invalid":o?`true`:void 0,...c?{"aria-disabled":`true`,"aria-readonly":void 0}:s?{tabIndex:0,"aria-readonly":`true`}:null,...n(hD.contentEditable,gD.contentEditableMinHeight(d)),...f};return l?(0,$.jsx)($T,{...p,"aria-placeholder":l,placeholder:()=>(0,$.jsx)(`div`,{id:u,"aria-hidden":`true`,className:`x10l6tqk x4xegtk x1o0tod x47corl x87ps6o xv1l7n4`,children:l})}):(0,$.jsx)($T,{...p})}var TD=new Set([`http:`,`https:`,`mailto:`,`tel:`]),ED=/^[a-z][a-z0-9+.-]*:/i;function DD(e){return ED.test(e)?e:`https://${e}`}function OD(e){let t=e.trim();if(t===``)return`about:blank`;try{let e=new URL(DD(t));return TD.has(e.protocol.toLowerCase())?e.href:`about:blank`}catch{return`about:blank`}}var kD={ctrlKey:!Ge,metaKey:Ge},AD={vertical:{kSGwAc:`xkh2ocl`,kZKoxP:`xt7dq6l`,$$css:!0}},jD={directional:{k1xSpc:`x3nfvp2`,$$css:!0}},MD={compactToolbar:{"--astryx-section-padding-inline-start":`xcfn0br`,"--astryx-section-padding-inline-end":`x1qgjean`,keoZOQ:`x1uy92hs`,k1K539:`x199tud`,$$css:!0},actions:{kUk6DE:`x845mor`,kzqmXN:`xnalus7`,ks0D6T:`x193iq5w`,k7Eaqz:`xeuugli`,kXHlph:`xw2csxc`,kORKVm:`x10wlt62`,kvh3hx:`x7p5m3t`,k5wCbM:`x1597r2g`,$$css:!0}};function ND(e){return Bl(e,`k`,kD)}var PD={bold:`richtext:bold`,italic:`richtext:italic`,underline:`richtext:underline`,strikethrough:`richtext:strikethrough`,code:`richtext:code`,link:`richtext:link`,paragraph:`richtext:paragraph`,h1:`richtext:h1`,h2:`richtext:h2`,h3:`richtext:h3`,quote:`richtext:quote`,bullet:`richtext:bullet`,number:`richtext:number`,undo:`richtext:undo`,redo:`richtext:redo`},FD=[{format:`bold`,icon:`bold`},{format:`italic`,icon:`italic`},{format:`underline`,icon:`underline`},{format:`strikethrough`,icon:`strikethrough`},{format:`code`,icon:`code`}],ID={bold:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M6 4h7a4 4 0 0 1 0 8H6zM6 12h8a4 4 0 0 1 0 8H6z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinejoin:`round`})}),italic:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M10 4h6M8 20h6M14 4l-4 16`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})}),underline:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4M5 21h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})}),strikethrough:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M4 12h16M8 6a4 3 0 0 1 8 0M8 16a4 3 0 0 0 8 0`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})}),code:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M9 8l-4 4 4 4M15 8l4 4-4 4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),link:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1.5 1.5M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1.5-1.5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),paragraph:(0,$.jsx)(LD,{label:`¶`}),h1:(0,$.jsx)(LD,{label:`H1`}),h2:(0,$.jsx)(LD,{label:`H2`}),h3:(0,$.jsx)(LD,{label:`H3`}),quote:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M6 17h3l2-4V7H5v6h3zM15 17h3l2-4V7h-6v6h3z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinejoin:`round`})}),bullet:(0,$.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M9 6h11M9 12h11M9 18h11`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`}),(0,$.jsx)(`circle`,{cx:`4.5`,cy:`6`,r:`1.5`,fill:`currentColor`}),(0,$.jsx)(`circle`,{cx:`4.5`,cy:`12`,r:`1.5`,fill:`currentColor`}),(0,$.jsx)(`circle`,{cx:`4.5`,cy:`18`,r:`1.5`,fill:`currentColor`})]}),number:(0,$.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M10 6h10M10 12h10M10 18h10`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`}),(0,$.jsx)(`text`,{x:`2`,y:`8`,fontSize:`6`,fill:`currentColor`,children:`1`}),(0,$.jsx)(`text`,{x:`2`,y:`14`,fontSize:`6`,fill:`currentColor`,children:`2`}),(0,$.jsx)(`text`,{x:`2`,y:`20`,fontSize:`6`,fill:`currentColor`,children:`3`})]}),undo:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M9 7L4 12l5 5M4 12h11a5 5 0 0 1 0 10`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),redo:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M15 7l5 5-5 5M20 12H9a5 5 0 0 0 0 10`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})};function LD({label:e}){return(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`x141an7d x1lvx875 xss6m8b`,children:e})}function RD(e,t){return b(PD[e],ID[e],t)}function zD({children:e}){return(0,$.jsx)(`span`,{"aria-hidden":`true`,...n(jD.directional,ee.mirror),children:e})}function BD({label:e,headingLevels:t=[`h1`,`h2`,`h3`],size:n=`sm`,hasLink:r=!0,promptForUrl:i,hasNewTabLinks:a=!0,endContent:o,xstyle:d,ref:f,...p}){let[m]=Q(),h=y(),g=e=>RD(e,h),_=v(),b=e??_(`@astryx.richTextEditor.toolbar.label`),x={h1:_(`@astryx.richTextEditor.toolbar.heading1`),h2:_(`@astryx.richTextEditor.toolbar.heading2`),h3:_(`@astryx.richTextEditor.toolbar.heading3`)},ee={bold:_(`@astryx.richTextEditor.toolbar.bold`),italic:_(`@astryx.richTextEditor.toolbar.italic`),underline:_(`@astryx.richTextEditor.toolbar.underline`),strikethrough:_(`@astryx.richTextEditor.toolbar.strikethrough`),code:_(`@astryx.richTextEditor.toolbar.inlineCode`)},[te,ne]=(0,S.useState)(new Set),[ie,se]=(0,S.useState)(`paragraph`),[le,ue]=(0,S.useState)(!1),[de,fe]=(0,S.useState)(!1),[pe,me]=(0,S.useState)(!1),[ge,_e]=(0,S.useState)(()=>m.isEditable()),ve=(0,S.useRef)(null),ye=(0,S.useRef)({selectedText:``,url:``,isLink:!1}),[be,xe]=(0,S.useState)(!1),[Ce,Te]=(0,S.useState)(!1),[De,Oe]=(0,S.useState)(``),[ke,Ae]=(0,S.useState)(``),je=(0,S.useCallback)(()=>{let e=j();if(!k(e)&&!A(e))return;let t=new Set,n=Kb(e);for(let r of[`bold`,`italic`,`underline`,`strikethrough`,`code`])(n==null?k(e)&&e.hasFormat(r):n.every(e=>e.hasFormat(r)))&&t.add(r);if(ne(t),!k(e))return;let r=e.anchor.getNode(),i=r.getParent(),a=ev(r)?r:ev(i)?i:null,o=a!=null;ue(o),ve.current=e.clone(),ye.current={selectedText:e.getTextContent(),url:a?.getURL()??``,isLink:o};let s=e.anchor.getNode(),c=s.getKey()===`root`?s:s.getTopLevelElementOrThrow();if(q(c)){let e=hp(s,lg),t=e?e.getListType():c.getListType();se(t===`number`?`number`:`bullet`)}else x_(c)?se(c.getTag()):m_(c)?se(`quote`):se(`paragraph`)},[]),Pe=(0,S.useCallback)(()=>{let e=ye.current;return m.getEditorState().read(()=>{let t=j();if(!k(t))return;let n=t.anchor.getNode(),r=n.getParent(),i=ev(n)?n:ev(r)?r:null;ve.current=t.clone(),e={selectedText:t.getTextContent(),url:i?.getURL()??``,isLink:i!=null},ye.current=e}),e},[m]),Fe=(0,S.useCallback)(()=>{let e=ve.current;e&&m.update(()=>{z(e.clone())})},[m]),Ie=(0,S.useCallback)(e=>{let t=e.trim(),n=OD(t);if(n===`about:blank`)return!1;Fe();let r=a?{target:`_blank`,rel:`noopener noreferrer`}:{};return m.dispatchCommand(iv,{url:n,...r})||m.update(()=>{let e=j();if(k(e)&&e.isCollapsed()){let i=$_(n,r);i.append(D(t)),e.insertNodes([i])}}),!0},[m,a,Fe]),Le=(0,S.useCallback)(()=>{if(!m.isEditable())return;let e=Pe();if(i){if(e.isLink){Fe(),m.dispatchCommand(iv,null);return}let t=i(e.selectedText);t!=null&&t.trim()!==``&&Ie(t)}else Oe(e.url||(e.selectedText.startsWith(`http`)?e.selectedText:`https://`)),Te(e.isLink),Ae(``),xe(!0)},[Ie,m,i,Pe,Fe]),C=(0,S.useCallback)(e=>{xe(e),Ae(``)},[]),Re=(0,S.useCallback)(()=>{xe(!1),Ae(``),requestAnimationFrame(()=>m.focus())},[m]),ze=(0,S.useCallback)(e=>{e.preventDefault(),Ie(De)?Re():Ae(_(`@astryx.richTextEditor.link.invalidUrl`))},[Ie,Re,De,_]),Be=(0,S.useCallback)(()=>{Fe(),m.dispatchCommand(iv,null),Re()},[Re,m,Fe]);(0,S.useEffect)(()=>zf(m.registerUpdateListener(({editorState:e})=>{e.read(je)}),m.registerCommand(Vr,()=>(je(),!1),4),m.registerCommand(Ni,e=>(fe(e),!1),4),m.registerCommand(Mi,e=>(me(e),!1),4),m.registerEditableListener(e=>{_e(e)}),r?m.registerCommand(oi,e=>ND(e)?(e.preventDefault(),Le(),!0):!1,2):()=>{}),[m,je,r,Le]);let Ve=e=>{m.dispatchCommand(ni,e)},He=e=>{ge&&ie!==e&&(e===`bullet`?m.dispatchCommand(mg,void 0):e===`number`?m.dispatchCommand(hg,void 0):m.update(()=>{let t=j();k(t)&&ep(t,()=>e===`quote`?p_():e===`h1`||e===`h2`||e===`h3`?b_(e):I())}))},Ue=[{value:`paragraph`,label:_(`@astryx.richTextEditor.toolbar.paragraph`),icon:g(`paragraph`)},...t.map(e=>({value:e,label:x[e],icon:g(e)})),{value:`bullet`,label:_(`@astryx.richTextEditor.toolbar.bulletedList`),icon:g(`bullet`)},{value:`number`,label:_(`@astryx.richTextEditor.toolbar.numberedList`),icon:g(`number`)},{value:`quote`,label:_(`@astryx.richTextEditor.toolbar.blockQuote`),icon:g(`quote`)}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Se,{...p,ref:f,label:b,size:n,xstyle:[MD.compactToolbar,d],startContent:(0,$.jsxs)(u,{gap:1,role:`group`,"aria-label":_(`@astryx.richTextEditor.toolbar.actions`),xstyle:MD.actions,children:[(0,$.jsx)(ae,{label:_(`@astryx.richTextEditor.toolbar.undo`),icon:(0,$.jsx)(zD,{children:g(`undo`)}),variant:`ghost`,tooltip:_(`@astryx.richTextEditor.toolbar.undo`),isDisabled:!ge||!de,onClick:()=>m.dispatchCommand(ii,void 0)}),(0,$.jsx)(ae,{label:_(`@astryx.richTextEditor.toolbar.redo`),icon:(0,$.jsx)(zD,{children:g(`redo`)}),variant:`ghost`,tooltip:_(`@astryx.richTextEditor.toolbar.redo`),isDisabled:!ge||!pe,onClick:()=>m.dispatchCommand(ai,void 0)}),(0,$.jsx)(oe,{orientation:`vertical`,"aria-label":_(`@astryx.richTextEditor.toolbar.historyDivider`),xstyle:AD.vertical}),(0,$.jsx)(`div`,{className:`x78zum5 x2lah0s`,children:(0,$.jsx)(Ne,{label:_(`@astryx.richTextEditor.toolbar.blockFormat`),isLabelHidden:!0,variant:`ghost`,size:n,value:ie,options:Ue,startIcon:g(ie),isDisabled:!ge,onChange:e=>He(e)})}),(0,$.jsx)(oe,{orientation:`vertical`,"aria-label":_(`@astryx.richTextEditor.toolbar.formatDivider`),xstyle:AD.vertical}),FD.map(e=>(0,$.jsx)(Ee,{label:ee[e.format],icon:g(e.icon),size:n,isIconOnly:!0,isPressed:te.has(e.format),isDisabled:!ge,onPressedChange:()=>Ve(e.format)},e.format)),r&&(0,$.jsx)(Ee,{label:_(`@astryx.richTextEditor.toolbar.link`),icon:g(`link`),size:n,isIconOnly:!0,isPressed:le||be,isDisabled:!ge,"aria-haspopup":`dialog`,"aria-expanded":be,onMouseDown:e=>e.preventDefault(),onPressedChange:Le},`link`),o!=null&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(oe,{orientation:`vertical`}),o]})]})}),r&&(0,$.jsx)(ce,{isOpen:be,onOpenChange:C,purpose:`form`,width:400,children:(0,$.jsx)(l,{as:`form`,onSubmit:ze,children:(0,$.jsx)(s,{height:`auto`,header:(0,$.jsx)(Me,{title:_(Ce?`@astryx.richTextEditor.link.editTitle`:`@astryx.richTextEditor.link.insertTitle`),onOpenChange:C}),content:(0,$.jsx)(c,{children:(0,$.jsx)(he,{label:_(`@astryx.richTextEditor.link.url`),value:De,width:`100%`,hasAutoFocus:!0,status:ke?{type:`error`,message:ke}:void 0,statusVariant:`detached`,onChange:e=>{Oe(e),Ae(``)}})}),footer:(0,$.jsx)(we,{children:(0,$.jsxs)(u,{gap:2,hAlign:`end`,children:[Ce&&(0,$.jsx)(re,{label:_(`@astryx.richTextEditor.link.remove`),variant:`destructive`,onClick:Be}),(0,$.jsx)(re,{label:_(`@astryx.richTextEditor.link.cancel`),variant:`secondary`,onClick:()=>C(!1)}),(0,$.jsx)(re,{label:_(Ce?`@astryx.richTextEditor.link.update`:`@astryx.richTextEditor.link.add`),variant:`primary`,type:`submit`})]})})})})})]})}BD.displayName=`RichTextEditorToolbar`;var VD=(0,S.createContext)([]);function HD(e,t,n){let r=jT(t);return[...r.length>0?[{label:`Remove condition`,onClick:()=>{n(null)}}]:[],...e.map(({name:e,values:i})=>({type:`section`,title:e,items:i.map(i=>({label:`${e} is ${i}`,onClick:()=>{n(MT(t,e,i))},endContent:r.includes(`${e} is ${i}`)?(0,$.jsx)(x,{icon:de,size:`sm`}):void 0}))}))]}function UD({check:e,when:t,set:n}){let r=(0,S.useContext)(VD),[i,a]=(0,S.useState)(!1);return(0,$.jsx)(je,{label:e,isMenuOpen:i,onOpenChange:a,items:HD(r,t,n),renderTrigger:({ref:r,id:o})=>(0,$.jsx)(le,{content:`Sent only on turns where ${t??e}. Press to change it.`,children:(0,$.jsx)(_,{ref:r,id:o,size:`sm`,label:e,icon:(0,$.jsx)(x,{icon:ge,size:`xsm`}),"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>{a(!i)},onRemove:()=>{n(NT(t,e))}})})})}function WD({nodeKey:e,when:t}){let[n]=Q(),r=t=>{n.update(()=>{let n=L(e);KD(n)&&n.setWhen(t)})},i=jT(t);return i.length===0?null:(0,$.jsx)(`div`,{className:`prompt-line-head`,contentEditable:!1,children:i.map(e=>(0,$.jsx)(UD,{check:e,when:t,set:r},e))})}var GD=class e extends sc{__when;static getType(){return oT}static clone(t){return new e(t.__when,t.__key)}static importJSON(t){return new e(t.when??null)}constructor(e,t){super(t),this.__when=e}exportJSON(){return{type:oT,version:1,when:this.__when}}getWhen(){return this.getLatest().__when}setWhen(e){return this.getWritable().__when=e,this}createDOM(){let e=document.createElement(`div`);return e.className=`prompt-line-slot`,e}updateDOM(){return!1}isInline(){return!1}isKeyboardSelectable(){return!1}decorate(){return(0,$.jsx)(WD,{nodeKey:this.getKey(),when:this.getWhen()})}},KD=e=>e instanceof GD,qD=[GD],JD=`16rem`,YD=`Private: the model reads this, and a reply that repeats it is stopped.`,XD=200,ZD=`Text style: paragraph, heading, list or quote`,QD=new Set([`Bold`,`Italic`,`Underline`,`Strikethrough`,`Inline code`]),$D=e=>{e.preventDefault()};function eO(e){let t=e;for(let e=t.getParent();e&&!F(e);e=t.getParent()){if(K(t)&&F(e.getParent()))return t;t=e}return t}var tO=e=>{let t=e.getParent();return K(e)&&t?t:e};function nO(e){for(let t=e;t;t=t.getPreviousSibling())if(KD(t))return t;return null}function rO(e,t){let n=e.getParent();q(n)&&ju(n,t)}function iO(e){let[t,n]=e.isBackward()?[e.focus,e.anchor]:[e.anchor,e.focus];return{first:eO(t.getNode()),last:eO(n.getNode())}}var aO=e=>nO(tO(e))?.getWhen()??null;function oO(e,t){K(t)&&t.getNextSibling()&&rO(t,t.getIndexWithinParent()+1),K(e)&&e.getPreviousSibling()&&rO(e,e.getIndexWithinParent())}function sO(e,t,n){for(let n=e;n&&!n.is(t);){let e=n.getNextSibling();KD(n)&&n.remove(),n=e}let r=t.getNextSibling();r&&!KD(r)&&t.insertAfter(new GD(n))}function cO(e,t,n){let r=e.getPreviousSibling(),i=KD(r)?r.setWhen(n):new GD(n);if(KD(r)||e.insertBefore(i),!n)return;let a=t.getNextSibling();KD(a)&&a.getWhen()===n&&a.remove();let o=i.getPreviousSibling();o&&nO(o)?.getWhen()===n&&i.remove()}function lO(e){let t=j();if(!k(t))return;let{first:n,last:r}=iO(t),i=aO(n),a=aO(r);if(e===i&&i===a)return;oO(n,r);let o=tO(n),s=tO(r);sO(o,s,a),cO(o,s,e)}function uO(){let[e]=Q(),t=(0,S.useContext)(VD),[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(null);return(0,S.useEffect)(()=>e.registerUpdateListener(({editorState:e})=>{e.read(()=>{let e=j(),t=k(e);r(t&&cp(e,`--private`,``)===`1`);let n=t?tO(eO(e.anchor.getNode())):null;a(nO(n)?.getWhen()??null)})}),[e]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ee,{label:`Private`,tooltip:YD,size:`sm`,isIconOnly:!0,icon:(0,$.jsx)(x,{icon:Ie,size:`sm`}),isPressed:n,onMouseDown:$D,onPressedChange:()=>{e.update(()=>{let e=j();k(e)&&Yf(e,{[sT]:n?null:`1`})})}}),t.length>0&&(0,$.jsx)(je,{label:`Condition`,renderTrigger:e=>(0,$.jsx)(Ee,{...e,label:`Condition`,tooltip:`Send this part only on turns where a condition fits`,size:`sm`,isIconOnly:!0,icon:(0,$.jsx)(x,{icon:ge,size:`sm`}),isPressed:!!i,onMouseDown:$D}),items:HD(t,i,t=>{e.update(()=>{lO(t)})})})]})}function dO(e){if(!e||KD(e)||!N(e))return!1;let t=e.getAllTextNodes().filter(e=>e.getTextContent().trim()!==``);return t.length>0&&t.every(e=>e.getStyle().includes(`--private`))}function fO(){let[e]=Q();return(0,S.useEffect)(()=>e.registerUpdateListener(({editorState:t})=>{t.read(()=>{for(let t of R().getChildren()){let n=dO(t),r=e.getElementByKey(t.getKey());r?.toggleAttribute(`data-private`,n),r?.toggleAttribute(`data-private-start`,n&&!dO(t.getPreviousSibling())),r?.toggleAttribute(`data-private-end`,n&&!dO(t.getNextSibling()))}})}),[e]),null}var pO=e=>e instanceof Element?e.closest(`[data-private]`)??e.closest(`[style*="--private"]`):null;function mO(){let e=(0,S.useRef)(null),t=(0,S.useRef)(void 0),[n,r]=(0,S.useState)(null),i=(0,S.useCallback)(()=>{clearTimeout(t.current),r(null)},[]),a=(0,S.useCallback)((n,{left:a,top:o,width:s,height:c})=>{i();let l=e.current?.offsetParent?.getBoundingClientRect();l&&(t.current=setTimeout(()=>{let e={left:a-l.left,top:o-l.top,width:s,height:c};r({text:n,place:e})},XD))},[i]);return(0,S.useEffect)(()=>i,[i]),{hint:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{ref:e,className:`prompt-hint-anchor`,style:n?.place}),(0,$.jsx)(le,{anchorRef:e,content:n?.text,isOpen:n!==null})]}),show:a,hide:i}}function hO(e){if(e.matches(`.astryx-selector`))return ZD;let t=e.getAttribute(`aria-label`);return t&&QD.has(t)?t:void 0}function gO({show:e,hide:t}){let n=null;return{onMouseOver:r=>{let i=r.target instanceof Element?r.target.closest(`.astryx-selector, button`):null;if(i===n)return;n=i,t();let a=i&&hO(i);i&&a&&e(a,i.getBoundingClientRect())},onMouseLeave:()=>{n=null,t()}}}function _O({show:e,hide:t}){let[n]=Q();return(0,S.useEffect)(()=>{let r=null,i=n=>{let i=pO(n.target);i!==r&&(r=i,t(),i&&e(YD,{left:n.clientX,top:n.clientY,width:1,height:1}))},a=()=>{},o=n.registerRootListener(e=>{if(a(),a=()=>{},!e)return;let n=e.ownerDocument;n.addEventListener(`mousemove`,i),e.addEventListener(`mousedown`,t),e.addEventListener(`keydown`,t),a=()=>{n.removeEventListener(`mousemove`,i),e.removeEventListener(`mousedown`,t),e.removeEventListener(`keydown`,t)}});return()=>{o(),a()}},[n,e,t]),null}function vO(){let[e]=Q(),t=(0,S.useContext)(Pe),n=(0,S.useRef)(null);return(0,S.useEffect)(()=>{if(t){n.current=e.getEditorState().read(()=>j()?.clone()??null);return}let r=n.current;n.current=null,r&&e.update(()=>{z(r)})},[e,t]),null}function yO({opened:e,placeholder:t,status:n,onEdit:r}){let[i]=(0,S.useState)(()=>OT(e)),a=mO(),[o]=(0,S.useState)(()=>gO(a));return(0,$.jsxs)(`div`,{className:`prompt-editor`,children:[a.hint,(0,$.jsx)(vD,{label:`Prompt`,isLabelHidden:!0,width:`100%`,size:`sm`,minHeight:JD,placeholder:t,status:n,defaultValue:i,nodes:qD,toolbar:(0,$.jsx)(BD,{size:`sm`,hasLink:!1,endContent:(0,$.jsx)(uO,{}),...o}),plugins:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fO,{}),(0,$.jsx)(_O,{...a}),(0,$.jsx)(vO,{})]}),onChange:e=>{r(kT(JSON.stringify(e.toJSON())))}})]})}function bO({value:e,placeholder:t,status:n,onChange:r}){let[i,a]=(0,S.useState)(e),[o,s]=(0,S.useState)(0);return!(0,S.useContext)(Pe)&&!PT(e,i)&&(a(e),s(o+1)),(0,$.jsx)(yO,{opened:e,placeholder:t,status:n,onEdit:e=>{PT(e,i)||(a(e),r(e))}},o)}var xO=`identity.system`;function SO({value:e,conditions:t,rows:n,placeholder:r,onChange:i}){let a={label:`Prompt`,path:xO,field:`system`},{status:o,required:s}=Ae(a),[c,l]=(0,S.useState)(!1),u=(0,S.useDeferredValue)(e),d=(0,S.useMemo)(()=>FT(u),[u]),f=c||d!==void 0,p=(0,$.jsx)(Ee,{label:`Code`,tooltip:d??(f?`Show formatted`:`Show code`),size:`sm`,isIconOnly:!0,isDisabled:d!==void 0,icon:(0,$.jsx)(x,{icon:me,size:`sm`}),pressedIcon:(0,$.jsx)(x,{icon:fe,size:`sm`}),isPressed:f,onPressedChange:l});return f?(0,$.jsx)(Fe,{...a,rows:n,value:e,placeholder:r,status:d?{type:`warning`,message:d}:void 0,action:p,onChange:i}):(0,$.jsx)(ke,{label:a.label,path:a.path,isRequired:s,hasIssue:o!==void 0,action:p,children:(0,$.jsx)(VD.Provider,{value:t,children:(0,$.jsx)(bO,{value:e,placeholder:r,status:o,onChange:i})})})}export{SO as PromptRow};
71
+ `).forEach((e,t)=>{for(let e of r[t]??[])i.push({type:e.type,start:a+e.start,end:a+e.end});a+=e.length}),[i]}function HT(){let[e]=Q();return(0,S.useEffect)(()=>{if(!BT())return;zT();let t=new Set,n=new Map,r=e=>{n.get(e)?.cleanup(),n.delete(e)},i=t=>{let i=e.getEditorState().read(()=>{let e=L(t);return Ev(e)?{code:e.getTextContent(),language:e.getLanguage()??``}:null}),a=e.getElementByKey(t);if(i==null||a==null){r(t);return}let o=n.get(t);if(o!=null&&o.element===a&&o.code===i.code&&o.language===i.language)return;o?.cleanup();let s=VT(i.code,i.language,a.textContent??``);s==null?n.delete(t):n.set(t,{element:a,...i,cleanup:be(a,s)})},a=e.registerMutationListener(wv,e=>{for(let[n,a]of e)a===`destroyed`?(t.delete(n),r(n)):(t.add(n),i(n))},{skipInitialization:!1}),o=e.registerUpdateListener(()=>{for(let e of t)i(e)});return()=>{a(),o();for(let e of[...n.keys()])r(e);t.clear()}},[e]),null}`${a[`--spacing-6`]}`,`${a[`--spacing-3`]}`,`${a[`--spacing-4`]}`,`${a[`--spacing-2`]}`,`${a[`--spacing-3`]}`,`${a[`--spacing-4`]}`,`${a[`--spacing-1`]}`,`${a[`--spacing-0-5`]}`,`${a[`--spacing-0`]}`,`${a[`--spacing-2`]}`,`${a[`--spacing-6`]}`,`${a[`--spacing-3`]}`,`${a[`--spacing-2`]}${o[`--size-element-sm`]}${a[`--spacing-3`]}`;var UT={providerDirection:{ksoyAI:`x1epdd7z`,$$css:!0},paragraph:{keoZOQ:`x1ftnraw xnhvf09 xe66n16`,k1K539:`x18pneqc xfo59cc x1vugyqv`,ks0D6T:`x7ep2pv`,k63SB2:`x1pd3egz`,kMwMTN:`x1heor9g`,$$css:!0},h1:{kMv6JI:`x1g81bgm`,kGuDYH:`xcg7oai`,k63SB2:`x1v68xuy`,kLWn49:`xfmsba7`,keoZOQ:`x13xmvwt xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h2:{kMv6JI:`x1g81bgm`,kGuDYH:`x1xvnhcw`,k63SB2:`x12yy4cs`,kLWn49:`x1cpk1wn`,keoZOQ:`x13xmvwt xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h3:{kMv6JI:`x1g81bgm`,kGuDYH:`xii13ha`,k63SB2:`x1jcxfy8`,kLWn49:`xwjzt0u`,keoZOQ:`x13xmvwt xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h4:{kMv6JI:`x1g81bgm`,kGuDYH:`x8tkxat`,k63SB2:`x2hcmsi`,kLWn49:`xqerer`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1hws3vx xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h5:{kMv6JI:`x1g81bgm`,kGuDYH:`xsgqta0`,k63SB2:`xno150v`,kLWn49:`xo3gurs`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1hws3vx xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},h6:{kMv6JI:`x1g81bgm`,kGuDYH:`xw5ohdf`,k63SB2:`x1pw4frv`,kLWn49:`xeixjfn`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1hws3vx xfo59cc`,ks0D6T:`x7ep2pv`,$$css:!0},quote:{keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1u2y747 xfo59cc`,kUOVxO:`xrxpjvj`,ks0D6T:`x7ep2pv`,kZCmMZ:`x1rey3nv`,k2ei4v:`xyumdvf`,kVhnKS:`x1t7ytsu`,kGJrpR:`x14ydlgx`,kMwMTN:`xv1l7n4`,$$css:!0},ul:{keoZOQ:`x1ftnraw xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,kZCmMZ:`x31w388`,kpqbRz:`x43c9pm`,$$css:!0},ol:{keoZOQ:`x1ftnraw xnhvf09`,k1K539:`x18pneqc xfo59cc`,ks0D6T:`x7ep2pv`,kZCmMZ:`x31w388`,kpqbRz:`x43c9pm`,$$css:!0},ulMarker0:{kH6xsr:`xtaz4m5`,$$css:!0},ulMarker1:{kH6xsr:`xrylv2j`,$$css:!0},ulMarker2:{kH6xsr:`x152237o`,$$css:!0},olMarker0:{kH6xsr:`x3yw8vx`,$$css:!0},olMarker1:{kH6xsr:`x1rrqm6h`,$$css:!0},olMarker2:{kH6xsr:`x19k9dhg`,$$css:!0},tableScrollableWrapper:{kXHlph:`xw2csxc`,ks0D6T:`x193iq5w`,k1xSpc:`xrvj5dj`,kumcoG:`x1mkdm3x`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1u2y747 xfo59cc`,$$css:!0},table:{kLvRdT:`x1mwwwfo`,kzqmXN:`xh8yej3`,kMzoRj:`x1litavf`,ksu8eU:`x1y0btm7`,kVAM5u:`x14i3s5s`,$$css:!0},tableRow:{kt9PQ7:`xso031l`,kfdmCh:`x1q0q8m5`,kL6WhQ:`xw8gpjh x1bta2m4`,$$css:!0},tableCell:{kB7OPa:`x1afcbsf`,k8WAf4:`xce4md1`,kg3NbH:`xf314gf`,k9WMMc:`x1yc453h`,kXLuUW:`xxymvpz`,kHjlTd:`x1mzt3pk`,ke9TFa:`xw8tdv1 x1qlsc9e`,k8ry5P:`x18b5jzi`,kBCPoo:`x1gejf6u`,$$css:!0},tableCellHeader:{k63SB2:`x2mo6ok`,kMwMTN:`xv1l7n4`,$$css:!0},tableCellSelected:{kMeerF:`xak0ai5`,k3XXqK:`x9ssot5`,kjBf7l:`x19bwoy8`,kInvED:`x1c097ug`,$$css:!0},code:{k1xSpc:`x1lliihq`,kMv6JI:`x9m5x89`,kGuDYH:`xp03k98`,kLWn49:`x17iicif`,kWkggS:`xzyc27v`,kMzoRj:`x1litavf`,ksu8eU:`x1y0btm7`,kVAM5u:`x14i3s5s`,kaIpWk:`xh6dtrn`,kLKAdn:`xekneqv x2w4pp4`,kGO01o:`xvmdzux`,kg3NbH:`x1pzlopt`,kB7OPa:`x9f619`,kzqmXN:`xeq5yr9`,k7Eaqz:`xejm5pw`,ks0D6T:`x193iq5w`,keoZOQ:`x1w2a574 xnhvf09`,k1K539:`x1u2y747 xfo59cc`,khDVqt:`x126k92a`,kTgw9:`x1yn0g08`,kHjlTd:`x1mzt3pk`,$$css:!0}};function WT(){let e=(...e)=>n(...e,UT.providerDirection).className??``,t=e=>n(e).className??``;return{paragraph:e(UT.paragraph),markdownExtensionBlock:e(UT.paragraph),heading:{h1:e(UT.h1),h2:e(UT.h2),h3:e(UT.h3),h4:e(UT.h4),h5:e(UT.h5),h6:e(UT.h6)},quote:e(UT.quote),list:{ul:e(UT.ul),ol:e(UT.ol),listitem:{className:`x1f3mx8c xmvvslv x1uerj9w x13xdy6z x1wqhfsw xkuhcwz xsgnyjk x10j6jf0 xfo59cc x1sle589 x81k3mc xovwveo x2i8j16 x8yim9t x1pvqllw xbj1ybn x1kuvm45`}.className,nested:{listitem:{className:`x1f3mx8c xmvvslv x1uerj9w x13xdy6z x1wqhfsw xkuhcwz xsgnyjk x10j6jf0 xfo59cc x1sle589 x81k3mc xovwveo x2i8j16 x8yim9t x1pvqllw xbj1ybn x1kuvm45`}.className},ulDepth:[t(UT.ulMarker0),t(UT.ulMarker1),t(UT.ulMarker2)],olDepth:[t(UT.olMarker0),t(UT.olMarker1),t(UT.olMarker2)]},link:{className:`xjse4m1 x1bvjpef x1ypdohk x16khyan`}.className,text:{bold:{className:`x2mo6ok`}.className,italic:{className:`x1k4tb9n`}.className,underline:{className:`x1bvjpef`}.className,strikethrough:{className:`xmqliwb`}.className,code:{className:`x9m5x89 xwmxj5m x7a5moj xx3sua9`}.className},code:`${e(UT.code)} ${LT}`,hr:{className:`xc342km x11xkdxz x13fuv20 x1pc3f07 x13xmvwt xnhvf09 xe66n16 x1qaki06 xfo59cc x1vugyqv`}.className,hrSelected:{className:`xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu`}.className,markdownExtensionSelected:{className:`xak0ai5 x9ssot5 x19bwoy8 x1eqjuhu`}.className,table:e(UT.table),tableRow:e(UT.tableRow),tableCell:e(UT.tableCell),tableCellHeader:e(UT.tableCellHeader),tableCellSelected:t(UT.tableCellSelected),tableScrollableWrapper:e(UT.tableScrollableWrapper)}}function GT(){return R().getTextContent()}function KT(e,t=!0){if(e)return!1;let n=GT();return t&&(n=n.trim()),n===``}function qT(e){if(!KT(e,!1))return!1;let t=R().getChildren(),n=t.length;if(n>1)return!1;for(let e=0;e<n;e++){let n=t[e];if(P(n))return!1;if(N(n)){if(!Uc(n)||n.__indent!==0)return!1;let e=n.getChildren(),t=e.length;for(let n=0;n<t;n++){let t=e[n];if(!O(t))return!1}}}return!0}function JT(e){return()=>qT(e)}var $=t(),YT=Be?S.useLayoutEffect:S.useEffect;function XT({editor:e,ariaActiveDescendant:t,ariaAutoComplete:n,ariaControls:r,ariaDescribedBy:i,ariaErrorMessage:a,ariaExpanded:o,ariaInvalid:s,ariaLabel:c,ariaLabelledBy:l,ariaMultiline:u,ariaOwns:d,ariaRequired:f,autoCapitalize:p,className:m,id:h,role:g=`textbox`,spellCheck:_=!0,style:v,tabIndex:y,"data-testid":b,...x},ee){let[te,ne]=(0,S.useState)(e.isEditable()),re=(0,S.useCallback)(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),ie=(0,S.useMemo)(()=>function(...e){return t=>{for(let n of e)typeof n==`function`?n(t):n!=null&&(n.current=t)}}(ee,re),[re,ee]);return YT(()=>(ne(e.isEditable()),e.registerEditableListener(e=>{ne(e)})),[e]),(0,$.jsx)(`div`,{"aria-activedescendant":te?t:void 0,"aria-autocomplete":te?n:`none`,"aria-controls":te?r:void 0,"aria-describedby":i,...a==null?{}:{"aria-errormessage":a},"aria-expanded":te&&g===`combobox`?!!o:void 0,...s==null?{}:{"aria-invalid":s},"aria-label":c,"aria-labelledby":l,"aria-multiline":u,"aria-owns":te?d:void 0,"aria-readonly":!te||void 0,"aria-required":f,autoCapitalize:p,className:m,contentEditable:te,"data-testid":b,id:h,ref:ie,role:g,spellCheck:_,style:v,tabIndex:y??(te?void 0:-1),...x})}var ZT=(0,S.forwardRef)(XT);function QT(e){return e.read(`latest`,JT(e.isComposing()))}var $T=(0,S.forwardRef)(eE);function eE(e,t){let{placeholder:n,...r}=e,[i]=Q();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ZT,{editor:i,...r,ref:t}),n!=null&&(0,$.jsx)(tE,{editor:i,content:n})]})}function tE({content:e,editor:t}){let n=function(e){let[t,n]=(0,S.useState)(()=>QT(e));return YT(()=>{function t(){let t=QT(e);n(t)}return t(),zf(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),t}(t),[r,i]=(0,S.useState)(t.isEditable());if(YT(()=>(i(t.isEditable()),t.registerEditableListener(e=>{i(e)})),[t]),!n)return null;let a=null;return typeof e==`function`?a=e(r):e!==null&&(a=e),a===null?null:(0,$.jsx)(`div`,{"aria-hidden":!0,children:a})}var nE=class extends S.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){this.props.onError(e instanceof Error?e:Error(String(e),{cause:e}),t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function rE({children:e,fallback:t,onError:n}){return(0,$.jsx)(nE,{fallback:t===void 0?(0,$.jsx)(`div`,{style:{border:`1px solid #f00`,color:`#f00`,padding:`8px`},children:`An error was thrown.`}):t,onError:n,children:e})}var iE={name:`@lexical/react/ReactProvider`},aE=te();function oE({contentEditable:e,children:t}){return(0,$.jsxs)($.Fragment,{children:[e,t]})}var sE={build(e,t,n){n.getPeer(iE.name)||function(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)}(321,[...n.getDirectDependentNames()].join(` `));let r=[e,{getTheme:()=>e._config.theme}];return{Component:function(e,t){let[n]=t,r=e.decorators.map(e=>typeof e==`function`?(0,$.jsx)(e,{context:t}):e);return function(i){let{EditorChildrenComponent:a=e.EditorChildrenComponent,ErrorBoundary:o=e.ErrorBoundary,contentEditable:s=e.contentEditable,children:c}=i,l=function(e,t){let[n,r]=(0,S.useMemo)(()=>[t=>e.registerDecoratorListener(t),()=>e.getDecorators()],[e]),i=(0,S.useSyncExternalStore)(n,r,r),a=function(e){let[t,n]=(0,S.useMemo)(()=>[e.registerRootListener.bind(e),e.getRootElement.bind(e)],[e]);return(0,S.useSyncExternalStore)(t,n,n)}(e);return(0,S.useMemo)(()=>{let n=t=>e._onError(t),r=[];for(let a in i){let o=e.getElementByKey(a);if(o!==null){let e=(0,$.jsx)(t,{onError:n,children:(0,$.jsx)(S.Suspense,{fallback:null,children:i[a]})});r.push((0,aE.createPortal)(e,o,a))}}return r},[t,i,e,a])}(n,o),u=(0,S.useMemo)(()=>r.map((e,t)=>(0,$.jsx)(o,{onError:e=>{n._onError(e)},children:(0,$.jsx)(S.Suspense,{fallback:null,children:e})},t)),[o]);return(0,$.jsx)(IT.Provider,{value:t,children:(0,$.jsxs)(a,{context:t,contentEditable:s,children:[c,u,l]})})}}(t,r),context:r}},config:{EditorChildrenComponent:oE,ErrorBoundary:rE,contentEditable:(0,$.jsx)($T,{}),decorators:[]},mergeConfig(e,t){let n=Ff(e,t);return t.decorators&&(n.decorators=t.decorators.length>0?[...e.decorators,...t.decorators]:e.decorators),n},name:`@lexical/react/React`,peerDependencies:[[`@lexical/react/ReactProvider`]]};function cE({extension:e,children:t,contentEditable:n}){let r=(0,S.useMemo)(()=>ym.fromExtensions([iE,Pf(sE,n===void 0?{}:{contentEditable:n}),e]).buildEditor(),[n,e]);(0,S.useEffect)(()=>{let e=!1;return queueMicrotask(()=>{e=!0}),()=>{e&&r.dispose()}},[r]);let{Component:i}=jm(r,sE).output;return(0,$.jsx)(i,{children:t})}var lE=Be?S.useLayoutEffect:S.useEffect;function uE(e){let[t]=Q(),n=(0,S.useMemo)(()=>e(t),[t,e]),[r,i]=(0,S.useState)(()=>n.initialValueFn()),a=(0,S.useRef)(r);return lE(()=>{let{initialValueFn:e,subscribe:t}=n,r=e();return a.current!==r&&(a.current=r,i(r)),t(e=>{a.current=e,i(e)})},[n,e]),r}function dE(e){return{initialValueFn:()=>e.isEditable(),subscribe:t=>e.registerEditableListener(t)}}function fE(){return uE(dE)}function pE(e,...t){throw function(e,...t){let n=new URL(`https://lexical.dev/docs/error`),r=new URLSearchParams;r.append(`code`,e);for(let e of t)r.append(`v`,e);return n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(e,...t)}function mE({editor:e,ErrorBoundary:t}){return function(e,t){let[n,r]=(0,S.useMemo)(()=>[t=>e.registerDecoratorListener(t),()=>e.getDecorators()],[e]),i=(0,S.useSyncExternalStore)(n,r,r),a=function(e){let[t,n]=(0,S.useMemo)(()=>[e.registerRootListener.bind(e),e.getRootElement.bind(e)],[e]);return(0,S.useSyncExternalStore)(t,n,n)}(e);return(0,S.useMemo)(()=>{let n=t=>e._onError(t),r=[];for(let a in i){let o=e.getElementByKey(a);if(o!==null){let e=(0,$.jsx)(t,{onError:n,children:(0,$.jsx)(S.Suspense,{fallback:null,children:i[a]})});r.push((0,aE.createPortal)(e,o,a))}}return r},[t,i,e,a])}(e,t)}function hE({editor:e,ErrorBoundary:t}){return function(e){let t=ym.maybeFromEditor(e);if(t&&t.hasExtensionByName(iE.name)){for(let e of[`@lexical/plain-text`,`@lexical/rich-text`])t.hasExtensionByName(e)&&pE(320,e);return!0}return!1}(e)?null:(0,$.jsx)(mE,{editor:e,ErrorBoundary:t})}var gE=Be?S.useLayoutEffect:S.useEffect;function _E(e){return e.read(`latest`,JT(e.isComposing()))}function vE({contentEditable:e,placeholder:t=null,ErrorBoundary:n}){let[r]=Q();return function(e){gE(()=>zf(R_(e),n_(e)),[e])}(r),(0,$.jsxs)($.Fragment,{children:[e,(0,$.jsx)(yE,{content:t}),(0,$.jsx)(hE,{editor:r,ErrorBoundary:n})]})}function yE({content:e}){let[t]=Q(),n=function(e){let[t,n]=(0,S.useState)(()=>_E(e));return gE(()=>{function t(){let t=_E(e);n(t)}return t(),zf(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),t}(t),r=fE();return n?typeof e==`function`?e(r):e:null}function bE(e,t,n){let r=n(),i=0,a=r,o=0,s=null;return(c,l,u,d,f,p)=>{let m=n();if(p.has(`composition-start`)&&(a=r,o=i,s=c),p.has(`historic`))return i=0,r=m,2;p.has(`composition-end`)&&s&&(r=a,i=o,c=s);let h=p.has(`paste`)||p.has(`cut`)?0:function(e,t,n,r,i){if(e===null||n.size===0&&r.size===0&&!i)return 0;let a=t._selection,o=e._selection;if(i)return 1;if(!(k(a)&&k(o)&&o.isCollapsed()&&a.isCollapsed()))return 0;let s=function(e,t,n){let r=e._nodeMap,i=[];for(let e of t){let t=r.get(e);t!==void 0&&i.push(t)}for(let[e,t]of n){if(!t)continue;let n=r.get(e);n===void 0||F(n)||i.push(n)}return i}(t,n,r);if(s.length===0)return 0;if(s.length>1){let n=t._nodeMap,r=n.get(a.anchor.key),i=n.get(o.anchor.key);return r&&i&&!e._nodeMap.has(r.__key)&&O(r)&&r.__text.length===1&&a.anchor.offset===1?2:0}let c=s[0],l=e._nodeMap.get(c.__key);if(!O(l)||!O(c)||l.__mode!==c.__mode)return 0;let u=l.__text,d=c.__text;if(u===d)return 0;let f=a.anchor,p=o.anchor;if(f.key!==p.key||f.type!==`text`)return 0;let m=f.offset,h=p.offset,g=d.length-u.length;return g===1&&h===m-1?2:g===-1&&h===m+1?3:g===-1&&h===m?4:0}(c,l,d,f,e.isComposing()),g=(()=>{let n=u===null||u.editor===e,a=p.has(Ra);if(!a&&n&&p.has(`history-merge`))return 0;if(h===1)return 2;if(c===null)return 1;let o=l._selection;if(!(d.size>0||f.size>0))return o===null?2:0;let s=typeof t==`number`?t:t.peek();return!1===a&&h!==0&&h===i&&m<r+s&&n||d.size===1&&function(e,t,n){let r=t._nodeMap.get(e),i=n._nodeMap.get(e),a=t._selection,o=n._selection;return!(k(a)&&k(o)&&a.anchor.type===`element`&&a.focus.type===`element`&&o.anchor.type===`text`&&o.focus.type===`text`||!O(r)||!O(i)||r.__parent!==i.__parent)&&JSON.stringify(t.read(()=>r.exportJSON()))===JSON.stringify(n.read(()=>i.exportJSON()))}(Array.from(d)[0],c,l)?0:1})();return r=m,i=h,g}}function xE(e,t){if(t!==null&&t.editor===e.editor)return t;let{editor:n}=e,r=n.getEditorState();return r.isEmpty()?null:{editor:n,editorState:r}}function SE(e,t){e.undoStack=[],e.redoStack=[],e.current=null,t&&t(e)}function CE(e,t,n,r=Date.now,i,a=null){let o=bE(e,n,r),s=()=>{i&&i(t)};return s(),zf(e.registerCommand(ii,()=>(function(e,t,n){let r=t.redoStack,i=t.undoStack;if(i.length!==0){let a=t.current,o=i.pop();if(o){let t=xE(o,a);t!==null&&(r.push(t),e.dispatchCommand(Mi,!0))}i.length===0&&e.dispatchCommand(Ni,!1),t.current=o||null,n&&n(t),o&&o.editor.setEditorState(o.editorState,{tag:`historic`})}}(e,t,i),!0),0),e.registerCommand(ai,()=>(function(e,t,n){let r=t.redoStack,i=t.undoStack;if(r.length!==0){let a=t.current,o=r.pop();if(o){let t=xE(o,a);t!==null&&(i.push(t),e.dispatchCommand(Ni,!0))}r.length===0&&e.dispatchCommand(Mi,!1),t.current=o||null,n&&n(t),o&&o.editor.setEditorState(o.editorState,{tag:`historic`})}}(e,t,i),!0),0),e.registerCommand(Ai,()=>(SE(t,i),!1),0),e.registerCommand(ji,()=>(SE(t,i),e.dispatchCommand(Mi,!1),e.dispatchCommand(Ni,!1),!0),0),e.registerUpdateListener(({editorState:n,prevEditorState:r,dirtyLeaves:i,dirtyElements:c,tags:l})=>{let u=t.current,d=t.redoStack,f=t.undoStack,p=u===null?null:u.editorState;if(u!==null&&n===p)return;let m=o(r,n,u,i,c,l);if(m===1){d.length!==0&&(t.redoStack=[],e.dispatchCommand(Mi,!1));let n=function(e,t,n){return n===null?null:n.editor===e?{...n}:t.isEmpty()?null:{editor:e,editorState:t}}(e,r,u);if(n!==null){f.push(n);let t=typeof a==`number`||a===null?a:a.peek();t!==null&&f.length>t&&f.splice(0,f.length-t),e.dispatchCommand(Ni,!0)}}else if(m===2)return;t.current={editor:e,editorState:n},s()}))}function wE(){return{current:null,redoStack:[],undoStack:[]}}function TE({delay:e,externalHistoryState:t}){let[n]=Q();return function(e,t,n=1e3){let r=(0,S.useMemo)(()=>t||wE(),[t]);(0,S.useEffect)(()=>CE(e,r,n),[n,e,r])}(n,t,e),null}function EE({hasStrictIndent:e=!1,shouldPreserveNumbering:t=!1}){let[n]=Q();return(0,S.useEffect)(()=>{if(!n.hasNodes([lg,ng]))throw Error(`ListPlugin: ListNode and/or ListItemNode not registered on editor`)},[n]),(0,S.useEffect)(()=>zf(_g(n,{restoreNumbering:t}),e?vg(n):()=>{}),[n,e,t]),function(e){(0,S.useEffect)(()=>_g(e),[e])}(n),null}function DE({validateUrl:e,attributes:t}){let[n]=Q();return(0,S.useEffect)(()=>{if(!n.hasNodes([J_]))throw Error(`LinkPlugin: LinkNode not registered on editor`)}),(0,S.useEffect)(()=>lv(n,$p({attributes:t,validateUrl:e})),[n,e,t]),null}function OE({maxIndent:e,$canIndent:t}){let[n]=Q();return(0,S.useEffect)(()=>Pb(n,e,t),[n,e,t]),null}var kE={dependencies:[Em],export:e=>km(e)?`***`:null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(e,t,n,r)=>{let i=Om();r||e.getNextSibling()!=null?e.replace(i):e.insertBefore(i),i.selectNext()},triggerOnEnter:!0,type:`element`};function AE(){return[kE,...Qx]}var jE=AE();function ME({transformers:e=jE}){let[t]=Q();return(0,S.useEffect)(()=>SS(t,e),[t,e]),null}var NE=Be?S.useLayoutEffect:S.useEffect;function PE({ignoreHistoryMergeTagChange:e=!0,ignoreSelectionChange:t=!1,onChange:n}){let[r]=Q();return NE(()=>{if(n)return r.registerUpdateListener(({editorState:i,dirtyElements:a,dirtyLeaves:o,prevEditorState:s,tags:c})=>{t&&a.size===0&&o.size===0||e&&c.has(`history-merge`)||s.isEmpty()||n(i,r,c)})},[r,e,t,n]),null}function FE({hasCellMerge:e=!0,hasCellBackgroundColor:t=!0,hasTabHandler:n=!0,hasHorizontalScroll:r=!1,hasNestedTables:i=!1}){let[a]=Q();(0,S.useEffect)(()=>{vb(a)!==r&&(bb(a,r),a.update(Fs))},[a,r]);let o=function(e){let[t]=(0,S.useState)(()=>Hp(e));return t.peek()!==e&&(t.value=e),t}(i);return(0,S.useEffect)(()=>Mb(a,{hasNestedTables:o}),[a,o]),(0,S.useEffect)(()=>jb(a,n),[a,n]),(0,S.useEffect)(()=>{if(!e)return Ab(a)},[a,e]),(0,S.useEffect)(()=>{if(!t)return a.registerNodeTransform(Xv,e=>{e.getBackgroundColor()!==null&&e.setBackgroundColor(null)})},[a,t,e]),null}var IE=st.strikethrough,LE=st.bold|st.italic;function RE(e){let t=e.__format,n=[];return(t&IE)!==0&&n.push(`del`),(t&LE)===LE&&n.push(`em`),n}function zE(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var BE=Pf(Th,{overrides:[th([co],{$createDOM(e,t){let n=t();for(let t of[...RE(e)].reverse()){let e=document.createElement(t);e.append(n),n=e}return n},$updateDOM(e,t,n,r,i){let a=RE(e);if(!zE(a,RE(t)))return!0;if(a.length===0)return r();let o=n;for(let e of a){if(o?.tagName.toLowerCase()!==e)return!0;o=o.firstElementChild}return o==null||e.updateDOM(t,o,i._config)}})]}),VE=4,HE=24,UE=2,WE=20;function GE(e){let[t,...n]=e;return t==null?[]:t.map((e,t)=>{let r=Math.max(e,...n.map(e=>e[t]??0)),i=Math.ceil(r/UE);return Math.min(HE,Math.max(VE,i,Math.min(e,WE)))})}function KE(){let[e]=Q();return(0,S.useEffect)(()=>{let t=0,n=()=>{t=0,e.getEditorState().read(()=>{for(let t of R().getChildren().filter(Z)){let n=t.getChildren().filter(ay).map(e=>e.getChildren().filter(Y)),r=GE(n.map(e=>e.map(e=>e.getTextContentSize())));n[0]?.forEach((t,n)=>{let i=e.getElementByKey(t.getKey()),a=`${r[n]}ch`;i!=null&&i.style.minWidth!==a&&(i.style.minWidth=a)})}})},r=()=>{t===0&&(t=requestAnimationFrame(n))},i=e.registerUpdateListener(r);return r(),()=>{cancelAnimationFrame(t),i()}},[e]),null}var qE={header:{kVAEAm:`x10l6tqk`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`x1qughib`,k8WAf4:`xce4md1`,kg3NbH:`x1pzlopt`,kB7OPa:`x9f619`,$$css:!0},corner:{kVAEAm:`x10l6tqk`,k1xSpc:`x78zum5`,kjj79g:`x13a6bvl`,kmVPX3:`xlsj2fj`,kB7OPa:`x9f619`,kfzvcC:`x47corl`,$$css:!0},cornerButton:{kfzvcC:`x67bb7w`,$$css:!0},copyButton:{kMwMTN:`x1mjzq1q`,$$css:!0},placement:(e,t,n)=>[{k87sOh:e==null?e:`xjbys53`,kbCHJM:t==null?t:`xgq9j65`,kzqmXN:n==null?n:`x5lhr3w`,$$css:!0},{"--x-top":(e=>typeof e==`number`?e+`px`:e??void 0)(e),"--x-left":(e=>typeof e==`number`?e+`px`:e??void 0)(t),"--x-width":(e=>typeof e==`number`?e+`px`:e??void 0)(n)}]};function JE(e){return e==null||e===``||e===YE?null:e}var YE=`plaintext`;function XE(e,t){return e.length===t.length&&e.every((e,n)=>e.key===t[n].key&&e.language===t[n].language&&e.top===t[n].top&&e.left===t[n].left&&e.width===t[n].width)}function ZE({placement:e}){let[t]=Q(),r=v(),{copy:i,isCopied:a}=ve({announce:r(`@astryx.codeBlock.copied`)}),o=(0,$.jsx)(ae,{variant:`ghost`,size:`sm`,icon:(0,$.jsx)(x,{icon:a?`check`:`copy`,size:`sm`,color:`inherit`}),tooltip:r(`@astryx.codeBlock.copyCode`),label:r(a?`@astryx.codeBlock.copied`:`@astryx.codeBlock.copyCode`),onClick:()=>{let n=t.getEditorState().read(()=>L(e.key)?.getTextContent()??``);i(n)},xstyle:[qE.copyButton,e.language==null&&qE.cornerButton]}),s=qE.placement(e.top,e.left,e.width);return e.language==null?(0,$.jsx)(`div`,{"data-richtext-code-header":``,...n(qE.corner,s),children:o}):(0,$.jsxs)(`div`,{"data-richtext-code-header":``,...n(qE.header,s),children:[(0,$.jsx)(`span`,{className:`x141an7d x9m5x89 x1e4wzip x1ltkj2j x1mjzq1q xeuugli xb3r6kr xlyipyv xuxw1ft`,children:e.language}),o]})}function QE(){let[e]=Q(),[t,n]=(0,S.useState)([]);return(0,S.useEffect)(()=>{let t=0,r=()=>{t=0;let r=e.getRootElement(),i=r?.parentElement;if(r==null||i==null){n(e=>e.length===0?e:[]);return}let a=i.getBoundingClientRect(),o=e.getEditorState().read(()=>R().getChildren().filter(Ev).flatMap(t=>{let n=e.getElementByKey(t.getKey());if(n==null)return[];let r=n.getBoundingClientRect();return[{key:t.getKey(),language:JE(t.getLanguage()),top:r.top-a.top+n.clientTop,left:r.left-a.left+n.clientLeft,width:n.clientWidth}]}));n(e=>XE(e,o)?e:o)},i=()=>{t===0&&(t=requestAnimationFrame(r))},a=typeof ResizeObserver>`u`?null:new ResizeObserver(i),o=e.registerRootListener(e=>{a?.disconnect(),e!=null&&a?.observe(e),i()}),s=e.registerUpdateListener(i);return window.addEventListener(`resize`,i),i(),()=>{cancelAnimationFrame(t),a?.disconnect(),o(),s(),window.removeEventListener(`resize`,i)}},[e]),(0,$.jsx)($.Fragment,{children:t.map(e=>(0,$.jsx)(ZE,{placement:e},e.key))})}function $E(e,t){return e.read(`latest`,()=>{let e=L(t);return e!==null&&e.isSelected()})}function eD(e){let[t]=Q(),[n,r]=(0,S.useState)(()=>$E(t,e));return(0,S.useEffect)(()=>{let n=!0,i=t.registerUpdateListener(()=>{n&&r($E(t,e))});return()=>{n=!1,i()}},[t,e]),[n,(0,S.useCallback)(n=>{t.update(()=>{let t=j();if(!A(t)){let r=n?null:L(e);if(r!==null&&!r.isSelected())return;t=es(),z(t)}A(t)&&(n?t.add(e):t.delete(e))})},[t,e]),(0,S.useCallback)(()=>{t.update(()=>{let e=j();A(e)&&e.clear()})},[t])]}function tD(e,t){let n=t.find(t=>t.name===e.plugin);if(n==null||n.apiVersion!==e.apiVersion)return null;let r=e.display===`inline`?Oe(e.source,{plugins:[n]}):Te(e.source,{plugins:[n]}).children,[i]=r;if(r.length!==1||i?.type!==`extension`)return null;let a=i;return a.plugin===e.plugin&&a.name===e.name&&a.display===e.display&&a.source===e.source?a:null}var nD=[[`strikethrough`,`del`],[`italic`,`em`],[`bold`,`strong`]],rD=new Set(nD.map(([e])=>e));function iD({facts:e,format:t,nodeKey:n,plugins:r}){let[i]=Q(),[a,o,s]=eD(n);(0,S.useEffect)(()=>i.registerCommand(Ur,e=>{let t=i.getElementByKey(n);return!i.isEditable()||t==null||!(e.target instanceof Node)||!t.contains(e.target)?!1:(s(),o(!0),!0)},1),[s,i,n,o]),(0,S.useEffect)(()=>{let e=i.getElementByKey(n),t=i._config.theme.markdownExtensionSelected;e!=null&&typeof t==`string`&&t!==``&&(a?Lf(e,t):Rf(e,t))},[i,a,n]);let c=(0,S.useMemo)(()=>tD(e,r),[e,r]),l=c==null?e.source:(0,$.jsx)(De,{plugins:r,node:c});for(let[e,n]of[...nD].reverse())(t&st[e])!==0&&(l=(0,$.jsx)(n,{children:l}));return l}function aD(e){e.update(()=>{for(let{node:e}of up())Wb(e)&&e.markDirty()},{tag:za})}function oD(e,t){let n=Gb(e);return n==null?null:(n.getFormatFlags(t,null)&st[t])!==0}function sD({extensions:e,transformers:t}){let[n]=Q(),r=(0,S.useMemo)(()=>sC(e,t),[e,t]);return(0,S.useEffect)(()=>{let e=Lb(n,(e,t,n)=>(0,$.jsx)(iD,{facts:e,format:t,nodeKey:n,plugins:r}));return aD(n),()=>{e(),aD(n)}},[n,r]),(0,S.useEffect)(()=>n.registerCommand(ni,e=>{let t=j();if(!rD.has(e)||t==null)return!1;let n=t.getNodes().filter(e=>Wb(e)&&e.isInline());if(n.length===0)return!1;let r=k(t)?oD(t,e):null;k(t)&&t.formatText(e);let i=r??!n.every(t=>t.hasFormat(e));for(let t of n)t.setFormatFlag(e,i);return!0},1),[n]),null}var cD={checkbox:{kVAEAm:`x10l6tqk`,$$css:!0},placement:(e,t)=>[{k87sOh:e==null?e:`xjbys53`,kbCHJM:t==null?t:`xgq9j65`,$$css:!0},{"--x-top":(e=>typeof e==`number`?e+`px`:e??void 0)(e),"--x-left":(e=>typeof e==`number`?e+`px`:e??void 0)(t)}]},lD=20,uD=`data-richtext-task`;function dD(){let e=[],t=n=>{if(q(n))for(let r of n.getChildren())K(r)&&(!(r.getChildrenSize()===1&&q(r.getFirstChild()))&&n.getListType()!==`number`&&e.push({item:r,task:bw(r)}),r.getChildren().forEach(t))};return R().getChildren().forEach(t),e}function fD(e,t){return e.length===t.length&&e.every((e,n)=>e.key===t[n].key&&e.checked===t[n].checked&&e.label===t[n].label&&e.top===t[n].top&&e.left===t[n].left)}function pD({isReadOnly:e}){let[t]=Q(),r=(0,S.useId)(),[i,a]=(0,S.useState)([]);return(0,S.useEffect)(()=>e?void 0:Ew(t),[t,e]),(0,S.useEffect)(()=>{let e=0,n=()=>{e=0;let n=t.getRootElement(),i=n?.parentElement;if(n==null||i==null){a(e=>e.length===0?e:[]);return}let o=i.getBoundingClientRect(),s=t.getEditorState().read(()=>dD().flatMap(({item:e,task:n})=>{let i=t.getElementByKey(e.getKey());if(i==null)return[];if(n==null)return i.removeAttribute(uD),i.removeAttribute(`aria-owns`),[];i.setAttribute(uD,``),i.removeAttribute(`role`),i.removeAttribute(`aria-checked`),i.removeAttribute(`tabindex`),i.setAttribute(`aria-owns`,`${r}-task-${e.getKey()}`);let a=i.getBoundingClientRect(),s=getComputedStyle(i),c=s.direction===`rtl`;return[{key:e.getKey(),checked:n===`checked`,label:e.getTextContent(),top:a.top-o.top+parseFloat(s.paddingTop||`0`),left:(c?a.right-lD:a.left)-o.left}]}));a(e=>fD(e,s)?e:s)},i=()=>{e===0&&(e=requestAnimationFrame(n))},o=typeof ResizeObserver>`u`?null:new ResizeObserver(i),s=t.registerRootListener(e=>{o?.disconnect(),e!=null&&o?.observe(e),i()}),c=t.registerUpdateListener(i);return window.addEventListener(`resize`,i),i(),()=>{cancelAnimationFrame(e),o?.disconnect(),s(),c(),window.removeEventListener(`resize`,i)}},[t,r]),(0,$.jsx)($.Fragment,{children:i.map(i=>(0,$.jsx)(`div`,{id:`${r}-task-${i.key}`,"data-richtext-task-checkbox":``,...n(cD.checkbox,cD.placement(i.top,i.left)),children:(0,$.jsx)(se,{ref:e=>{e!=null&&(e.tabIndex=-1)},size:`sm`,label:i.label,isLabelHidden:!0,value:i.checked,isReadOnly:e,onChange:e=>{t.update(()=>{let t=L(i.key);K(t)&&xw(t,e?`checked`:`unchecked`)})}})},i.key))})}var mD=JSON.stringify({root:{children:[{children:[],direction:null,format:``,indent:0,type:`paragraph`,version:1}],direction:null,format:``,indent:0,type:`root`,version:1}}),hD={wrapper:{"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,kXwgrk:`xdt5ytf`,kGNEyG:`x1qjc9v5`,kOIVth:`xsn7fz1`,k8WAf4:`x1hp7d8q`,kg3NbH:`x17a0aqu`,kAzted:`x65nank`,$$css:!0},contentEditable:{k1xSpc:`x1lliihq`,kzqmXN:`xh8yej3`,kMzoRj:`xc342km`,ksu8eU:`xng3xce`,kmVPX3:`x1717udv`,kI3sdo:`x1a2a7pz`,kMwMTN:`x1tgivj0`,$$css:!0},disabled:{kkrTdU:`xt0e3qv x16khyan`,$$css:!0}},gD={contentEditableMinHeight:e=>[{kAzted:e==null?e:`x82snj4`,$$css:!0},{"--x-minHeight":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]},_D=.8,vD=function({label:e,isLabelHidden:t=!1,description:i,isOptional:a=!1,isRequired:o=!1,defaultValue:s,onChange:c,placeholder:l,isReadOnly:u=!1,isDisabled:_=!1,status:y,statusVariant:b=`attached`,width:x,minHeight:ee=`4.5rem`,labelTooltip:te,size:re,nodes:ae,toolbar:oe,plugins:se,hasMarkdownShortcuts:ce=!0,transformers:le=nT,markdownExtensions:ue,hasAutoFocus:de=!1,tabEscapeHint:fe,maxLength:me,namespace:he=`astryx-editor`,xstyle:ge,className:_e,style:ve,ref:ye,...be}){let xe=ie(re,`md`),Se=v(),Ce=fe??Se(`@astryx.richTextEditor.tabEscapeHint`),we=(0,S.useId)(),Te=(0,S.useId)(),Ee=(0,S.useId)(),De=(0,S.useId)(),Oe=(0,S.useId)(),ke=(0,S.useId)(),Ae=(0,S.useId)(),[je,Me]=(0,S.useState)(0),Ne=(0,S.useRef)(null);Ne.current===null&&(Ne.current=WT());let Pe=!u&&!_,Fe=(0,S.useMemo)(()=>[...le],[le]),Ie=(0,S.useRef)(null);Ie.current===null&&(Ie.current=Nf({name:`@astryxdesign/richtext/RichTextEditor`,namespace:he,theme:Ne.current,editable:Pe,nodes:ae?[...qb,...ae]:[...qb],dependencies:[Am,BE],$initialEditorState:s??void 0,onError(e){throw e}}));let Le=Pe&&Ce!==``,C=oe!=null&&typeof oe!=`boolean`,{statusIcon:Re,describedBy:ze}=pe({status:y,statusVariant:b}),Be=[i?Ee:null,b!==`tooltip`&&y?.message?De:null,ze,l?Oe:null,me==null?null:ke,Le?Ae:null].filter(Boolean).join(` `)||void 0;return(0,$.jsxs)(p,{label:e,isLabelHidden:t,description:i,inputID:we,labelID:Te,descriptionID:i?Ee:void 0,isOptional:a,isRequired:o,isDisabled:_,status:y?{type:y.type,message:y.message,messageID:y.message?De:void 0}:void 0,statusVariant:b,labelTooltip:te,width:x,children:[(0,$.jsxs)(`div`,{...d(r(`rich-text-editor`,{size:xe,status:y?.type??null}),n(g.base,hD.wrapper,_&&g.disabled,_&&hD.disabled,y&&m[y.type],y&&!_&&!u&&h[y.type],y&&f[y.type],ge),_e,ve),children:[(0,$.jsxs)(cE,{extension:Ie.current,contentEditable:null,children:[C?oe:null,(0,$.jsxs)(`div`,{...{0:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf`},4:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf x178xt8z x13fuv20 x1pc3f07`},2:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf xp74n0j`},6:{className:`x1n2onr6 x9f619 xh8yej3 xu0wf1k xf314gf x178xt8z x13fuv20 x1pc3f07 xp74n0j`},1:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf xce4md1`},5:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf x178xt8z x13fuv20 x1pc3f07 xce4md1`},3:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf xp74n0j xce4md1`},7:{className:`x1n2onr6 x9f619 xh8yej3 xf314gf x178xt8z x13fuv20 x1pc3f07 xp74n0j xce4md1`}}[!!C<<2|!!Re<<1|xe===`lg`],children:[(0,$.jsxs)(`div`,{className:`x1n2onr6 xh8yej3 x9ynric xjm74w1 xf9zqsd xw6l6zx`,children:[(0,$.jsx)(vE,{contentEditable:(0,$.jsx)(wD,{id:we,ariaLabel:t?e:void 0,ariaLabelledBy:t?void 0:Te,ariaDescribedBy:Be,ariaRequired:o&&!a,ariaInvalid:y?.type===`error`,isReadOnly:u,isDisabled:_,placeholderText:l,placeholderID:Oe,minHeight:ee,rest:be}),placeholder:null,ErrorBoundary:rE}),(0,$.jsx)(TE,{}),(0,$.jsx)(EE,{}),(0,$.jsx)(pD,{isReadOnly:u||_}),(0,$.jsx)(DE,{}),(0,$.jsx)(FE,{hasCellMerge:!1,hasCellBackgroundColor:!1,hasTabHandler:!1,hasHorizontalScroll:!0}),(0,$.jsx)(KE,{}),(0,$.jsx)(QE,{}),(0,$.jsx)(HT,{}),ue!=null&&ue.length>0?(0,$.jsx)(sD,{extensions:ue,transformers:Fe}):null,(0,$.jsx)(OE,{}),(0,$.jsx)(bD,{}),ce&&(0,$.jsx)(ME,{transformers:Fe}),de&&(0,$.jsx)(xD,{}),c&&(0,$.jsx)(PE,{onChange:c,ignoreHistoryMergeTagChange:!0,ignoreSelectionChange:!0}),se,(0,$.jsx)(SD,{editorRef:ye,editable:Pe,transformers:Fe}),me!=null&&(0,$.jsx)(CD,{onCountChange:Me})]}),Re&&(0,$.jsx)(`div`,{className:`x10l6tqk xctzyg x72tfeb x1vjfegm x78zum5 x6s0dn4`,children:Re})]})]}),Le&&(0,$.jsx)(ne,{id:Ae,children:Ce})]}),me!=null&&(0,$.jsxs)(`div`,{id:ke,...{0:{className:`x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d xv1l7n4`},1:{className:`x78zum5 x13a6bvl xcsaf9d x9ynric x141an7d xjt36v0`}}[je>me|0],children:[je,`/`,me,(0,$.jsx)(ne,{"aria-live":`polite`,children:je>=me*_D?je>me?Se(`@astryx.textArea.charactersOverLimit`,{count:je-me}):Se(`@astryx.textArea.charactersRemaining`,{count:me-je}):``})]})]})};vD.displayName=`RichTextEditor`;var yD=new Set([`Escape`,`Tab`,`Shift`,`Control`,`Alt`,`Meta`]);function bD(){let[e]=Q();return(0,S.useEffect)(()=>{let t=!1;return zf(e.registerCommand(gi,()=>(t=!0,!0),1),e.registerCommand(vi,()=>t?(t=!1,!0):!1,1),e.registerCommand(oi,e=>(t&&!yD.has(e.key)&&(t=!1),!1),1),e.registerCommand(Fi,()=>(t=!1,!1),1))},[e]),null}function xD(){let[e]=Q();return(0,S.useEffect)(()=>{e.focus()},[e]),null}function SD({editorRef:e,editable:t,transformers:n}){let[r]=Q(),i=(0,S.useRef)(t);return(0,S.useEffect)(()=>{i.current!==t&&(i.current=t,r.setEditable(t))},[r,t]),(0,S.useImperativeHandle)(e,()=>({focus:()=>{t&&r.focus()},clear:()=>{t&&r.setEditorState(r.parseEditorState(mD))},getEditorState:()=>r.getEditorState(),getMarkdown:()=>r.getEditorState().read(()=>uw(n)),getHTML:()=>r.getEditorState().read(()=>kh(r,null)),getEditor:()=>r}),[r,t,n]),null}function CD({onCountChange:e}){let[t]=Q();return(0,S.useEffect)(()=>(e(t.getRootElement()?.textContent?.length??0),t.registerTextContentListener(t=>{e(t.length)})),[t,e]),null}function wD({id:e,ariaLabel:t,ariaLabelledBy:r,ariaDescribedBy:i,ariaRequired:a,ariaInvalid:o,isReadOnly:s,isDisabled:c,placeholderText:l,placeholderID:u,minHeight:d,rest:f}){let p={id:e,role:`textbox`,"aria-multiline":`true`,"aria-label":t,"aria-labelledby":r,"aria-describedby":i,"aria-required":a?`true`:void 0,"aria-invalid":o?`true`:void 0,...c?{"aria-disabled":`true`,"aria-readonly":void 0}:s?{tabIndex:0,"aria-readonly":`true`}:null,...n(hD.contentEditable,gD.contentEditableMinHeight(d)),...f};return l?(0,$.jsx)($T,{...p,"aria-placeholder":l,placeholder:()=>(0,$.jsx)(`div`,{id:u,"aria-hidden":`true`,className:`x10l6tqk x4xegtk x1o0tod x47corl x87ps6o xv1l7n4`,children:l})}):(0,$.jsx)($T,{...p})}var TD=new Set([`http:`,`https:`,`mailto:`,`tel:`]),ED=/^[a-z][a-z0-9+.-]*:/i;function DD(e){return ED.test(e)?e:`https://${e}`}function OD(e){let t=e.trim();if(t===``)return`about:blank`;try{let e=new URL(DD(t));return TD.has(e.protocol.toLowerCase())?e.href:`about:blank`}catch{return`about:blank`}}var kD={ctrlKey:!Ge,metaKey:Ge},AD={vertical:{kSGwAc:`xkh2ocl`,kZKoxP:`xt7dq6l`,$$css:!0}},jD={directional:{k1xSpc:`x3nfvp2`,$$css:!0}},MD={compactToolbar:{"--astryx-section-padding-inline-start":`xcfn0br`,"--astryx-section-padding-inline-end":`x1qgjean`,keoZOQ:`x1uy92hs`,k1K539:`x199tud`,$$css:!0},actions:{kUk6DE:`x845mor`,kzqmXN:`xnalus7`,ks0D6T:`x193iq5w`,k7Eaqz:`xeuugli`,kXHlph:`xw2csxc`,kORKVm:`x10wlt62`,kvh3hx:`x7p5m3t`,k5wCbM:`x1597r2g`,$$css:!0}};function ND(e){return Bl(e,`k`,kD)}var PD={bold:`richtext:bold`,italic:`richtext:italic`,underline:`richtext:underline`,strikethrough:`richtext:strikethrough`,code:`richtext:code`,link:`richtext:link`,paragraph:`richtext:paragraph`,h1:`richtext:h1`,h2:`richtext:h2`,h3:`richtext:h3`,quote:`richtext:quote`,bullet:`richtext:bullet`,number:`richtext:number`,undo:`richtext:undo`,redo:`richtext:redo`},FD=[{format:`bold`,icon:`bold`},{format:`italic`,icon:`italic`},{format:`underline`,icon:`underline`},{format:`strikethrough`,icon:`strikethrough`},{format:`code`,icon:`code`}],ID={bold:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M6 4h7a4 4 0 0 1 0 8H6zM6 12h8a4 4 0 0 1 0 8H6z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinejoin:`round`})}),italic:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M10 4h6M8 20h6M14 4l-4 16`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})}),underline:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M6 4v6a6 6 0 0 0 12 0V4M5 21h14`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})}),strikethrough:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M4 12h16M8 6a4 3 0 0 1 8 0M8 16a4 3 0 0 0 8 0`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`})}),code:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M9 8l-4 4 4 4M15 8l4 4-4 4`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),link:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1.5 1.5M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1.5-1.5`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),paragraph:(0,$.jsx)(LD,{label:`¶`}),h1:(0,$.jsx)(LD,{label:`H1`}),h2:(0,$.jsx)(LD,{label:`H2`}),h3:(0,$.jsx)(LD,{label:`H3`}),quote:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M6 17h3l2-4V7H5v6h3zM15 17h3l2-4V7h-6v6h3z`,stroke:`currentColor`,strokeWidth:`2`,strokeLinejoin:`round`})}),bullet:(0,$.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M9 6h11M9 12h11M9 18h11`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`}),(0,$.jsx)(`circle`,{cx:`4.5`,cy:`6`,r:`1.5`,fill:`currentColor`}),(0,$.jsx)(`circle`,{cx:`4.5`,cy:`12`,r:`1.5`,fill:`currentColor`}),(0,$.jsx)(`circle`,{cx:`4.5`,cy:`18`,r:`1.5`,fill:`currentColor`})]}),number:(0,$.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M10 6h10M10 12h10M10 18h10`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`}),(0,$.jsx)(`text`,{x:`2`,y:`8`,fontSize:`6`,fill:`currentColor`,children:`1`}),(0,$.jsx)(`text`,{x:`2`,y:`14`,fontSize:`6`,fill:`currentColor`,children:`2`}),(0,$.jsx)(`text`,{x:`2`,y:`20`,fontSize:`6`,fill:`currentColor`,children:`3`})]}),undo:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M9 7L4 12l5 5M4 12h11a5 5 0 0 1 0 10`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),redo:(0,$.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{d:`M15 7l5 5-5 5M20 12H9a5 5 0 0 0 0 10`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})})};function LD({label:e}){return(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`x141an7d x1lvx875 xss6m8b`,children:e})}function RD(e,t){return b(PD[e],ID[e],t)}function zD({children:e}){return(0,$.jsx)(`span`,{"aria-hidden":`true`,...n(jD.directional,ee.mirror),children:e})}function BD({label:e,headingLevels:t=[`h1`,`h2`,`h3`],size:n=`sm`,hasLink:r=!0,promptForUrl:i,hasNewTabLinks:a=!0,endContent:o,xstyle:d,ref:f,...p}){let[m]=Q(),h=y(),g=e=>RD(e,h),_=v(),b=e??_(`@astryx.richTextEditor.toolbar.label`),x={h1:_(`@astryx.richTextEditor.toolbar.heading1`),h2:_(`@astryx.richTextEditor.toolbar.heading2`),h3:_(`@astryx.richTextEditor.toolbar.heading3`)},ee={bold:_(`@astryx.richTextEditor.toolbar.bold`),italic:_(`@astryx.richTextEditor.toolbar.italic`),underline:_(`@astryx.richTextEditor.toolbar.underline`),strikethrough:_(`@astryx.richTextEditor.toolbar.strikethrough`),code:_(`@astryx.richTextEditor.toolbar.inlineCode`)},[te,ne]=(0,S.useState)(new Set),[ie,se]=(0,S.useState)(`paragraph`),[le,ue]=(0,S.useState)(!1),[de,fe]=(0,S.useState)(!1),[pe,me]=(0,S.useState)(!1),[ge,_e]=(0,S.useState)(()=>m.isEditable()),ve=(0,S.useRef)(null),ye=(0,S.useRef)({selectedText:``,url:``,isLink:!1}),[be,xe]=(0,S.useState)(!1),[Ce,Te]=(0,S.useState)(!1),[De,Oe]=(0,S.useState)(``),[ke,Ae]=(0,S.useState)(``),je=(0,S.useCallback)(()=>{let e=j();if(!k(e)&&!A(e))return;let t=new Set,n=Kb(e);for(let r of[`bold`,`italic`,`underline`,`strikethrough`,`code`])(n==null?k(e)&&e.hasFormat(r):n.every(e=>e.hasFormat(r)))&&t.add(r);if(ne(t),!k(e))return;let r=e.anchor.getNode(),i=r.getParent(),a=ev(r)?r:ev(i)?i:null,o=a!=null;ue(o),ve.current=e.clone(),ye.current={selectedText:e.getTextContent(),url:a?.getURL()??``,isLink:o};let s=e.anchor.getNode(),c=s.getKey()===`root`?s:s.getTopLevelElementOrThrow();if(q(c)){let e=hp(s,lg),t=e?e.getListType():c.getListType();se(t===`number`?`number`:`bullet`)}else x_(c)?se(c.getTag()):m_(c)?se(`quote`):se(`paragraph`)},[]),Pe=(0,S.useCallback)(()=>{let e=ye.current;return m.getEditorState().read(()=>{let t=j();if(!k(t))return;let n=t.anchor.getNode(),r=n.getParent(),i=ev(n)?n:ev(r)?r:null;ve.current=t.clone(),e={selectedText:t.getTextContent(),url:i?.getURL()??``,isLink:i!=null},ye.current=e}),e},[m]),Fe=(0,S.useCallback)(()=>{let e=ve.current;e&&m.update(()=>{z(e.clone())})},[m]),Ie=(0,S.useCallback)(e=>{let t=e.trim(),n=OD(t);if(n===`about:blank`)return!1;Fe();let r=a?{target:`_blank`,rel:`noopener noreferrer`}:{};return m.dispatchCommand(iv,{url:n,...r})||m.update(()=>{let e=j();if(k(e)&&e.isCollapsed()){let i=$_(n,r);i.append(D(t)),e.insertNodes([i])}}),!0},[m,a,Fe]),Le=(0,S.useCallback)(()=>{if(!m.isEditable())return;let e=Pe();if(i){if(e.isLink){Fe(),m.dispatchCommand(iv,null);return}let t=i(e.selectedText);t!=null&&t.trim()!==``&&Ie(t)}else Oe(e.url||(e.selectedText.startsWith(`http`)?e.selectedText:`https://`)),Te(e.isLink),Ae(``),xe(!0)},[Ie,m,i,Pe,Fe]),C=(0,S.useCallback)(e=>{xe(e),Ae(``)},[]),Re=(0,S.useCallback)(()=>{xe(!1),Ae(``),requestAnimationFrame(()=>m.focus())},[m]),ze=(0,S.useCallback)(e=>{e.preventDefault(),Ie(De)?Re():Ae(_(`@astryx.richTextEditor.link.invalidUrl`))},[Ie,Re,De,_]),Be=(0,S.useCallback)(()=>{Fe(),m.dispatchCommand(iv,null),Re()},[Re,m,Fe]);(0,S.useEffect)(()=>zf(m.registerUpdateListener(({editorState:e})=>{e.read(je)}),m.registerCommand(Vr,()=>(je(),!1),4),m.registerCommand(Ni,e=>(fe(e),!1),4),m.registerCommand(Mi,e=>(me(e),!1),4),m.registerEditableListener(e=>{_e(e)}),r?m.registerCommand(oi,e=>ND(e)?(e.preventDefault(),Le(),!0):!1,2):()=>{}),[m,je,r,Le]);let Ve=e=>{m.dispatchCommand(ni,e)},He=e=>{ge&&ie!==e&&(e===`bullet`?m.dispatchCommand(mg,void 0):e===`number`?m.dispatchCommand(hg,void 0):m.update(()=>{let t=j();k(t)&&ep(t,()=>e===`quote`?p_():e===`h1`||e===`h2`||e===`h3`?b_(e):I())}))},Ue=[{value:`paragraph`,label:_(`@astryx.richTextEditor.toolbar.paragraph`),icon:g(`paragraph`)},...t.map(e=>({value:e,label:x[e],icon:g(e)})),{value:`bullet`,label:_(`@astryx.richTextEditor.toolbar.bulletedList`),icon:g(`bullet`)},{value:`number`,label:_(`@astryx.richTextEditor.toolbar.numberedList`),icon:g(`number`)},{value:`quote`,label:_(`@astryx.richTextEditor.toolbar.blockQuote`),icon:g(`quote`)}];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Se,{...p,ref:f,label:b,size:n,xstyle:[MD.compactToolbar,d],startContent:(0,$.jsxs)(u,{gap:1,role:`group`,"aria-label":_(`@astryx.richTextEditor.toolbar.actions`),xstyle:MD.actions,children:[(0,$.jsx)(ae,{label:_(`@astryx.richTextEditor.toolbar.undo`),icon:(0,$.jsx)(zD,{children:g(`undo`)}),variant:`ghost`,tooltip:_(`@astryx.richTextEditor.toolbar.undo`),isDisabled:!ge||!de,onClick:()=>m.dispatchCommand(ii,void 0)}),(0,$.jsx)(ae,{label:_(`@astryx.richTextEditor.toolbar.redo`),icon:(0,$.jsx)(zD,{children:g(`redo`)}),variant:`ghost`,tooltip:_(`@astryx.richTextEditor.toolbar.redo`),isDisabled:!ge||!pe,onClick:()=>m.dispatchCommand(ai,void 0)}),(0,$.jsx)(oe,{orientation:`vertical`,"aria-label":_(`@astryx.richTextEditor.toolbar.historyDivider`),xstyle:AD.vertical}),(0,$.jsx)(`div`,{className:`x78zum5 x2lah0s`,children:(0,$.jsx)(Ne,{label:_(`@astryx.richTextEditor.toolbar.blockFormat`),isLabelHidden:!0,variant:`ghost`,size:n,value:ie,options:Ue,startIcon:g(ie),isDisabled:!ge,onChange:e=>He(e)})}),(0,$.jsx)(oe,{orientation:`vertical`,"aria-label":_(`@astryx.richTextEditor.toolbar.formatDivider`),xstyle:AD.vertical}),FD.map(e=>(0,$.jsx)(Ee,{label:ee[e.format],icon:g(e.icon),size:n,isIconOnly:!0,isPressed:te.has(e.format),isDisabled:!ge,onPressedChange:()=>Ve(e.format)},e.format)),r&&(0,$.jsx)(Ee,{label:_(`@astryx.richTextEditor.toolbar.link`),icon:g(`link`),size:n,isIconOnly:!0,isPressed:le||be,isDisabled:!ge,"aria-haspopup":`dialog`,"aria-expanded":be,onMouseDown:e=>e.preventDefault(),onPressedChange:Le},`link`),o!=null&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(oe,{orientation:`vertical`}),o]})]})}),r&&(0,$.jsx)(ce,{isOpen:be,onOpenChange:C,purpose:`form`,width:400,children:(0,$.jsx)(l,{as:`form`,onSubmit:ze,children:(0,$.jsx)(s,{height:`auto`,header:(0,$.jsx)(Me,{title:_(Ce?`@astryx.richTextEditor.link.editTitle`:`@astryx.richTextEditor.link.insertTitle`),onOpenChange:C}),content:(0,$.jsx)(c,{children:(0,$.jsx)(he,{label:_(`@astryx.richTextEditor.link.url`),value:De,width:`100%`,hasAutoFocus:!0,status:ke?{type:`error`,message:ke}:void 0,statusVariant:`detached`,onChange:e=>{Oe(e),Ae(``)}})}),footer:(0,$.jsx)(we,{children:(0,$.jsxs)(u,{gap:2,hAlign:`end`,children:[Ce&&(0,$.jsx)(re,{label:_(`@astryx.richTextEditor.link.remove`),variant:`destructive`,onClick:Be}),(0,$.jsx)(re,{label:_(`@astryx.richTextEditor.link.cancel`),variant:`secondary`,onClick:()=>C(!1)}),(0,$.jsx)(re,{label:_(Ce?`@astryx.richTextEditor.link.update`:`@astryx.richTextEditor.link.add`),variant:`primary`,type:`submit`})]})})})})})]})}BD.displayName=`RichTextEditorToolbar`;var VD=(0,S.createContext)([]);function HD(e,t,n){let r=jT(t);return[...r.length>0?[{label:`Remove`,onClick:()=>{n(null)}}]:[],...e.map(({name:e,choices:i})=>({type:`section`,title:e,items:i.map(({value:i})=>({label:`${e} is ${i}`,onClick:()=>{n(MT(t,e,i))},endContent:r.includes(`${e} is ${i}`)?(0,$.jsx)(x,{icon:de,size:`sm`}):void 0}))}))]}function UD({check:e,when:t,set:n}){let r=(0,S.useContext)(VD),[i,a]=(0,S.useState)(!1);return(0,$.jsx)(je,{label:e,isMenuOpen:i,onOpenChange:a,items:HD(r,t,n),renderTrigger:({ref:r,id:o})=>(0,$.jsx)(le,{content:`Sent only on turns where ${t??e}. Press to change it.`,children:(0,$.jsx)(_,{ref:r,id:o,size:`sm`,label:e,icon:(0,$.jsx)(x,{icon:ge,size:`xsm`}),"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>{a(!i)},onRemove:()=>{n(NT(t,e))}})})})}function WD({nodeKey:e,when:t}){let[n]=Q(),r=t=>{n.update(()=>{let n=L(e);KD(n)&&n.setWhen(t)})},i=jT(t);return i.length===0?null:(0,$.jsx)(`div`,{className:`prompt-line-head`,contentEditable:!1,children:i.map(e=>(0,$.jsx)(UD,{check:e,when:t,set:r},e))})}var GD=class e extends sc{__when;static getType(){return oT}static clone(t){return new e(t.__when,t.__key)}static importJSON(t){return new e(t.when??null)}constructor(e,t){super(t),this.__when=e}exportJSON(){return{type:oT,version:1,when:this.__when}}getWhen(){return this.getLatest().__when}setWhen(e){return this.getWritable().__when=e,this}createDOM(){let e=document.createElement(`div`);return e.className=`prompt-line-slot`,e}updateDOM(){return!1}isInline(){return!1}isKeyboardSelectable(){return!1}decorate(){return(0,$.jsx)(WD,{nodeKey:this.getKey(),when:this.getWhen()})}},KD=e=>e instanceof GD,qD=[GD],JD=`16rem`,YD=`Private: the model reads this, and a reply that repeats it is stopped.`,XD=200,ZD=`Text style: paragraph, heading, list or quote`,QD=new Set([`Bold`,`Italic`,`Underline`,`Strikethrough`,`Inline code`]),$D=e=>{e.preventDefault()};function eO(e){let t=e;for(let e=t.getParent();e&&!F(e);e=t.getParent()){if(K(t)&&F(e.getParent()))return t;t=e}return t}var tO=e=>{let t=e.getParent();return K(e)&&t?t:e};function nO(e){for(let t=e;t;t=t.getPreviousSibling())if(KD(t))return t;return null}function rO(e,t){let n=e.getParent();q(n)&&ju(n,t)}function iO(e){let[t,n]=e.isBackward()?[e.focus,e.anchor]:[e.anchor,e.focus];return{first:eO(t.getNode()),last:eO(n.getNode())}}var aO=e=>nO(tO(e))?.getWhen()??null;function oO(e,t){K(t)&&t.getNextSibling()&&rO(t,t.getIndexWithinParent()+1),K(e)&&e.getPreviousSibling()&&rO(e,e.getIndexWithinParent())}function sO(e,t,n){for(let n=e;n&&!n.is(t);){let e=n.getNextSibling();KD(n)&&n.remove(),n=e}let r=t.getNextSibling();r&&!KD(r)&&t.insertAfter(new GD(n))}function cO(e,t,n){let r=e.getPreviousSibling(),i=KD(r)?r.setWhen(n):new GD(n);if(KD(r)||e.insertBefore(i),!n)return;let a=t.getNextSibling();KD(a)&&a.getWhen()===n&&a.remove();let o=i.getPreviousSibling();o&&nO(o)?.getWhen()===n&&i.remove()}function lO(e){let t=j();if(!k(t))return;let{first:n,last:r}=iO(t),i=aO(n),a=aO(r);if(e===i&&i===a)return;oO(n,r);let o=tO(n),s=tO(r);sO(o,s,a),cO(o,s,e)}function uO(){let[e]=Q(),t=(0,S.useContext)(VD),[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(null);return(0,S.useEffect)(()=>e.registerUpdateListener(({editorState:e})=>{e.read(()=>{let e=j(),t=k(e);r(t&&cp(e,`--private`,``)===`1`);let n=t?tO(eO(e.anchor.getNode())):null;a(nO(n)?.getWhen()??null)})}),[e]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ee,{label:`Private`,tooltip:YD,size:`sm`,isIconOnly:!0,icon:(0,$.jsx)(x,{icon:Ie,size:`sm`}),isPressed:n,onMouseDown:$D,onPressedChange:()=>{e.update(()=>{let e=j();k(e)&&Yf(e,{[sT]:n?null:`1`})})}}),t.length>0&&(0,$.jsx)(je,{label:`Option`,renderTrigger:e=>(0,$.jsx)(Ee,{...e,label:`Option`,tooltip:`Send this part only on turns where an option fits`,size:`sm`,isIconOnly:!0,icon:(0,$.jsx)(x,{icon:ge,size:`sm`}),isPressed:!!i,onMouseDown:$D}),items:HD(t,i,t=>{e.update(()=>{lO(t)})})})]})}function dO(e){if(!e||KD(e)||!N(e))return!1;let t=e.getAllTextNodes().filter(e=>e.getTextContent().trim()!==``);return t.length>0&&t.every(e=>e.getStyle().includes(`--private`))}function fO(){let[e]=Q();return(0,S.useEffect)(()=>e.registerUpdateListener(({editorState:t})=>{t.read(()=>{for(let t of R().getChildren()){let n=dO(t),r=e.getElementByKey(t.getKey());r?.toggleAttribute(`data-private`,n),r?.toggleAttribute(`data-private-start`,n&&!dO(t.getPreviousSibling())),r?.toggleAttribute(`data-private-end`,n&&!dO(t.getNextSibling()))}})}),[e]),null}var pO=e=>e instanceof Element?e.closest(`[data-private]`)??e.closest(`[style*="--private"]`):null;function mO(){let e=(0,S.useRef)(null),t=(0,S.useRef)(void 0),[n,r]=(0,S.useState)(null),i=(0,S.useCallback)(()=>{clearTimeout(t.current),r(null)},[]),a=(0,S.useCallback)((n,{left:a,top:o,width:s,height:c})=>{i();let l=e.current?.offsetParent?.getBoundingClientRect();l&&(t.current=setTimeout(()=>{let e={left:a-l.left,top:o-l.top,width:s,height:c};r({text:n,place:e})},XD))},[i]);return(0,S.useEffect)(()=>i,[i]),{hint:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{ref:e,className:`prompt-hint-anchor`,style:n?.place}),(0,$.jsx)(le,{anchorRef:e,content:n?.text,isOpen:n!==null})]}),show:a,hide:i}}function hO(e){if(e.matches(`.astryx-selector`))return ZD;let t=e.getAttribute(`aria-label`);return t&&QD.has(t)?t:void 0}function gO({show:e,hide:t}){let n=null;return{onMouseOver:r=>{let i=r.target instanceof Element?r.target.closest(`.astryx-selector, button`):null;if(i===n)return;n=i,t();let a=i&&hO(i);i&&a&&e(a,i.getBoundingClientRect())},onMouseLeave:()=>{n=null,t()}}}function _O({show:e,hide:t}){let[n]=Q();return(0,S.useEffect)(()=>{let r=null,i=n=>{let i=pO(n.target);i!==r&&(r=i,t(),i&&e(YD,{left:n.clientX,top:n.clientY,width:1,height:1}))},a=()=>{},o=n.registerRootListener(e=>{if(a(),a=()=>{},!e)return;let n=e.ownerDocument;n.addEventListener(`mousemove`,i),e.addEventListener(`mousedown`,t),e.addEventListener(`keydown`,t),a=()=>{n.removeEventListener(`mousemove`,i),e.removeEventListener(`mousedown`,t),e.removeEventListener(`keydown`,t)}});return()=>{o(),a()}},[n,e,t]),null}function vO(){let[e]=Q(),t=(0,S.useContext)(Pe),n=(0,S.useRef)(null);return(0,S.useEffect)(()=>{if(t){n.current=e.getEditorState().read(()=>j()?.clone()??null);return}let r=n.current;n.current=null,r&&e.update(()=>{z(r)})},[e,t]),null}function yO({opened:e,placeholder:t,status:n,onEdit:r}){let[i]=(0,S.useState)(()=>OT(e)),a=mO(),[o]=(0,S.useState)(()=>gO(a));return(0,$.jsxs)(`div`,{className:`prompt-editor`,children:[a.hint,(0,$.jsx)(vD,{label:`Prompt`,isLabelHidden:!0,width:`100%`,size:`sm`,minHeight:JD,placeholder:t,status:n,defaultValue:i,nodes:qD,toolbar:(0,$.jsx)(BD,{size:`sm`,hasLink:!1,endContent:(0,$.jsx)(uO,{}),...o}),plugins:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fO,{}),(0,$.jsx)(_O,{...a}),(0,$.jsx)(vO,{})]}),onChange:e=>{r(kT(JSON.stringify(e.toJSON())))}})]})}function bO({value:e,placeholder:t,status:n,onChange:r}){let[i,a]=(0,S.useState)(e),[o,s]=(0,S.useState)(0);return!(0,S.useContext)(Pe)&&!PT(e,i)&&(a(e),s(o+1)),(0,$.jsx)(yO,{opened:e,placeholder:t,status:n,onEdit:e=>{PT(e,i)||(a(e),r(e))}},o)}var xO=`identity.system`;function SO({value:e,options:t,rows:n,placeholder:r,onChange:i}){let a={label:`Prompt`,path:xO,field:`system`},{status:o,required:s}=Ae(a),[c,l]=(0,S.useState)(!1),u=(0,S.useDeferredValue)(e),d=(0,S.useMemo)(()=>FT(u),[u]),f=c||d!==void 0,p=(0,$.jsx)(Ee,{label:`Code`,tooltip:d??(f?`Show formatted`:`Show code`),size:`sm`,isIconOnly:!0,isDisabled:d!==void 0,icon:(0,$.jsx)(x,{icon:me,size:`sm`}),pressedIcon:(0,$.jsx)(x,{icon:fe,size:`sm`}),isPressed:f,onPressedChange:l});return f?(0,$.jsx)(Fe,{...a,rows:n,value:e,placeholder:r,status:d?{type:`warning`,message:d}:void 0,action:p,onChange:i}):(0,$.jsx)(ke,{label:a.label,path:a.path,isRequired:s,hasIssue:o!==void 0,action:p,children:(0,$.jsx)(VD.Provider,{value:t,children:(0,$.jsx)(bO,{value:e,placeholder:r,status:o,onChange:i})})})}export{SO as PromptRow};
@@ -0,0 +1,5 @@
1
+ import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,D as n,E as r,O as i,S as a,T as o,b as s,c,d as l,g as u,h as d,l as f,m as p,p as m,u as h,v as g,x as _}from"./schemas-D7cgkv3L.js";import{$n as v,Cn as y,En as b,Hn as x,Kn as S,Tn as ee,U as te,Vn as C,X as w,Xn as T,Zn as E,ar as D,bn as O,en as ne,or as re,pn as ie,qt as ae,s as oe,sr as se,tn as ce,wn as le,xn as ue}from"./tool-schema-D26IAEC3.js";import{c as k}from"./host-patterns-F-KZIzkF.js";import{$ as de,Ar as fe,At as pe,Br as me,Bt as he,Dr as ge,Et as _e,F as ve,Fr as ye,Ft as be,G as xe,Gt as Se,Hr as A,Ht as Ce,I as we,Ir as Te,It as Ee,Jt as De,Kt as Oe,L as ke,Lr as Ae,Lt as je,N as Me,Ot as Ne,P as Pe,R as Fe,Tr as Ie,Ut as Le,V as Re,Vt as ze,Wn as Be,Wt as Ve,Yn as He,Yt as Ue,Z as We,_n as Ge,an as Ke,at as qe,bn as Je,cr as Ye,dn as Xe,dt as Ze,fn as Qe,in as $e,it as et,j as tt,jr as nt,kn as rt,mr as it,nt as at,pr as ot,pt as st,qt as ct,rn as lt,rt as ut,sr as dt,tn as ft,tt as pt,un as mt,vt as j,wn as ht,wt as gt,xn as _t,xr as vt,yn as yt,zn as bt,zr as xt,zt as St}from"./shaped-data-D15FDUcH.js";import{S as Ct,_ as wt,b as Tt,x as Et}from"./browser-connection-C1_PJcSQ.js";import{C as Dt,D as Ot,F as kt,I as At,M as jt,O as Mt,P as Nt,T as Pt,b as Ft,v as It,y as Lt}from"./schema-BztznKB7.js";import{a as Rt}from"./live-ingress-OuSlQ6q7.js";import{n as zt,t as Bt}from"./trace-schema--4IGmLeE.js";import{n as Vt}from"./stub-CJG-5zBe.js";function Ht(e){return{type:`guardrail`,guardrail:e}}function Ut(e,t,n,r=`redact`,i){if(n.length!==0)return Ht({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Wt(e,t){return e.type===`guardrail`?{...e,guardrail:Ye(e.guardrail,t)}:e}var M=65536;function N(e){let t=e.classStarts.length,n=new Uint16Array(M);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??M);let r=e.charsets.map(e=>{let n=new Uint8Array(t);for(let t of e)n[t]=1;return n}),i=e.nodes.length,a=new Int32Array(i),o=new Uint8Array(i),s=[];return e.nodes.forEach((e,t)=>{a[t]=e[0],o[t]=e[1],s.push(Int32Array.from(e.slice(2)))}),{classOf:n,has:r,pattern:a,final:o,edges:s,initials:e.initials,leads:e.leads,size:i}}var P,F,Gt;async function Kt(){if(P)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);P={forward:t,reversed:n}}function qt(){if(!P)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return P}var I;function Jt(e){let t=String.fromCharCode(e).toUpperCase();if(t.length!==1)return e;let n=t.charCodeAt(0);return e>=128&&n<128?e:n}function Yt(e){if(!I){I=new Map;for(let e=0;e<M;e++){let t=Jt(e),n=I.get(t);n?n.push(e):I.set(t,[e])}}return I.get(Jt(e))??[e]}function Xt(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<M&&t.push(n+1);return t}var Zt=new Map;function Qt(e){let t=Zt.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>Yt(e.charCodeAt(n))),r=Xt([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=N({classStarts:r,charsets:n.map(e=>e.map(i)),initials:[0],leads:[-1],nodes:[...n.map((e,t)=>[0,0,t+1,t]),[0,1]]});return Zt.set(e,a),a}function $t(e){let t=JSON.stringify(e),n=Zt.get(t);if(n)return n;let r=[...new Set(e.flatMap(e=>Array.from(e,e=>e.charCodeAt(0))))];r.sort((e,t)=>e-t);let i=Xt(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=N({classStarts:i,charsets:a,initials:e.map((e,t)=>{let n=o.length;for(let n=0;n<e.length;n++)o.push([t,0,o.length+1,r.indexOf(e.charCodeAt(n))]);return o.push([t,1]),n}),leads:e.map(()=>-1),nodes:o});return Zt.set(t,s),s}function en(e,t){let n=e.has[0]?.length??0,r=Array.from({length:n},()=>[]);for(let i of t){let t=e.edges[e.initials[i]];for(let i=0;i<t.length;i+=2){let a=e.has[t[i+1]];for(let e=0;e<n;e++)a[e]&&r[e]?.push(t[i])}}return r.map(e=>Int32Array.from(e))}function tn(e,t){e.text+=t,e.fresh+=t}function nn(e){return e.text.length-e.fresh.length}function L(e,t){let n=nn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function rn(e,t,n=e.text.length){let r=nn(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function an(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function on(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,tn(n,t(rn(e,n.text.length)))}};return n}var sn=/\w/,cn=Math.max(...ze.map(e=>e.length));function ln(e){return e.length<=cn+1&&/^[A-Za-z]*$/.test(e)}function un(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{tn(o,e);for(let r=0;r<e.length;r++)i.push(t+Math.min(r,n-1))},o={text:``,fresh:``,rawAt:r=>e.rawAt(r<i.length?i[r]:t-(n?.length??0)),update(){o.fresh=``;for(let i=e.text.length;t<i;t++){let i=String.fromCharCode(L(e,t)),o=sn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Se(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!ln(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function dn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function R(e,t,n){tn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var fn=55296,pn=56319,mn=/[A-Za-z]/,hn=56320,gn=57343;function _n(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=dn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(mn.test(e)||R(c,`\\`,s),s=-1),e===`\\`?s=t:R(c,e,t)}function u(e,t){if(Oe(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!mn.test(e))for(let e=0;e<i.length;e++)l(i[e],a[e]);i=``,a=[]}for(let n=0;n<e.length;n++)l(e[n],t);o=mn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=fn&&t<=pn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=hn&&a<=gn?2:1;u(n.slice(e,e+o),r[e]),e+=o}n=n.slice(e),r=r.slice(e)}return c.update=()=>{c.fresh=``;let i=e.text.length;for(;t<i;){let a=L(e,t),o=a>=fn&&a<=pn;if(o&&t+1>=i)break;let s=L(e,t+1),c=o&&s>=hn&&s<=gn?2:1,l=ct(rn(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var vn=/[0-9A-Fa-f]/;function yn(e){let t=0,n=-1,r=dn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(L(e,t));if(n<0){a===`%`?n=t:(R(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:vn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)R(r,String.fromCharCode(L(e,n)),n)}}};function i(t){t>n&&R(r,Ce(rn(e,n,t)),n),n=-1}return r}var bn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),xn=new Map(he.map(({pattern:e,hit:t})=>[e,t])),Sn=new Map(at.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function z(e){return{rule:ot(e),severity:`high`,detector:e}}var Cn=z(`injection`),wn=z(`marker_leak`),Tn=z(`tool_leak`);function En({kind:e,group:t}){if(bn.has(e))return Cn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:z(t);case`boundary`:return wn;case`image`:return z(`ungiven_images`);default:return z(`ungiven_links`)}}function Dn(e,t,n){if(e===`card`)return{hit:ut};if(e===`image`||e===`link`){let r=(e===`image`?et:qe).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=xn.get(t)??Sn.get(t);return r?{hit:r}:{}}function On(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:Ze(i(n?.ungiven_images)),link:st(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return de.forEach((t,n)=>{let r=En(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Ue(t.pattern),...Dn(t.kind,t.pattern,a)})}),o}function kn(){let e=[];return de.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=xn.get(n);e.push({...Cn,id:r,regex:Ue(n),...i?{hit:i}:{}})}),e}function An(){return De.map((e,t)=>({...Cn,id:t,regex:new RegExp(e.source,e.flags)}))}function jn(e,t,n){let r=en(t,n.map(e=>e.id)),i=new Int32Array(t.initials.length).fill(-1);n.forEach((e,t)=>{i[e.id]=t});let a=new Int32Array(t.size),o=new Int32Array(t.size),s=new Int32Array(t.size),c=new Int32Array(t.size),l=0,u=new Int32Array(t.size),d=new Int32Array(t.size),f=0,p=0,m=new Uint8Array(n.length),h=new Uint8Array(n.length),g=new Int32Array(n.length),_=new Int32Array(n.length),v=new Uint8Array(n.length),y=Uint8Array.from(n,e=>+!!e.find),b=new Int32Array(n.length).fill(-1),x=new Int32Array(n.length).fill(-1),S=Int32Array.from(n,e=>t.leads[e.id]??-1),ee=[...new Set(S)].filter(e=>e>=0),te=n.flatMap((e,t)=>S[t]<0?[]:[t]),C=new Int32Array(t.has.length).fill(-1);function w(){let{text:n,fresh:h}=e,g=nn(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function ne(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function re(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):ne(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=re();e;e=re())t.push(e);return e.rawAt(n)}}}var Mn=new WeakMap;function Nn(e){let t=Mn.get(e);return t||(t=N(e),Mn.set(e,t)),t}function Pn(e={}){let t={text:``,fresh:``},n=an(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),jn(e,t,n)),a=[],o=e.detect??[],s=On(o,e);if(s.length>0&&(F??=N(qt().forward),a.push(i(n,F,s))),o.includes(`injection`)){F??=N(qt().forward),Gt??=N(qt().reversed);let e=_n(t),r=kn();a.push(i(n,Gt,An()),i(un(n),F,r),i(e,F,r),i(un(e),F,r),i(on(n,Ve),F,r),i(on(n,e=>Le(e)??e),F,r),i(yn(t),F,r))}if(o.includes(`marker_leak`)&&e.note){let t=pt(e.note);a.push(i(n,Qt(e.note),[{...wn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=xe(e.tools),r=t.map(({regex:e},t)=>({...Tn,id:t,regex:e}));t.length>0&&a.push(i(n,$t(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...z(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Nn(r.automaton),e))}let c=0;return{push(e){t.text+=e,t.fresh=e;for(let e of r)e.update();let n=[],i=t.text.length;for(let e of a)i=Math.min(i,e.run(n));return c=i,n},holdFrom:()=>c}}function Fn(e,t,n={},r=[]){let i=we(e,t).filter(e=>!(Fe(e)||r.includes(e))),a=ke(e,t);if(i.length===0&&a.length===0)return;let o=[...i,...a.map(({id:e})=>e)],s=t.sources??{},c=[...i.map(e=>({detector:e,...s[e]})),...a.map(({id:e,matchers:t,compiled:n})=>({detector:e,matchers:t,compiled:n}))],l=c.some(({matchers:e,compiled:t})=>e?.length&&!t),u=Pn({detect:i.filter(e=>s[e]?.theorem!==!1),own:c.flatMap(({detector:e,compiled:t,matchers:n=[]})=>t?[{detector:e,compiled:t,matchers:n}]:[]),skipImages:t.ungiven_images[e]!==`ignore`,...n.allow?{allow:n.allow}:{},...n.givenUrls?{given:n.givenUrls}:{},...n.note?{note:n.note}:{},...n.ownTools?{tools:n.ownTools}:{}}),d=a.some(({find:e})=>e),f=e===`live_reply`?96:256,p=``,m=[];return{push(e){p+=e;for(let{start:t,detector:n}of u.push(e))n&&m.push({start:t,detector:n})},holdFrom(){if(l)return 0;let e=u.holdFrom();return d?Math.min(e,Math.max(0,p.length-f)):e},take(r,i,a=!1){let s=m.filter(({start:e})=>e<i);if(s.length===0&&!a&&!d)return{action:`allow`,text:p.slice(r,i),hits:[],taken:i-r};let c={from:r,to:i,settled:s.map(({detector:e})=>e)},l=ve(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function In(e){let{context:t}=e,n=e.detect,r=n?Fn(n.boundary,n.matrix,n.scope):void 0,i=e=>n?n.matrix[e][n.boundary]:`block`,a=i(`canary_leak`),o=i(`prompt_leak`),s=t.canaryGiven||a===`ignore`?void 0:t.canary,c=o===`ignore`?void 0:t.privateSystem,l=s!==void 0||c!==void 0,u=l?e.carry??``:``,d=[],f=new Set,p=``,m=0,h=``,g=u.slice(-j),_=u,v=0,y=u,b=0,x=0,S=s?_e(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,dt]),c){let r=_.length;_+=e;let i=St(_,r);_=_.slice(i),v+=i;let[a]=We(_,c,t.canary);a&&n.push([o,a])}for(let[e,t]of n)e!==`flag`||f.has(t.rule)||(f.add(t.rule),d.push(t));return n.filter(([e])=>e!==`flag`).map(([,e])=>e)}function te(e){let t=l?ee(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function C(){let e=s&&a!==`flag`?T(s):h.length,n=c&&o!==`flag`?E(c,t.canary):h.length;return m+Math.min(e,n)}function w(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function T(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-j),i=r+gt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+gt(y,e)),x=Math.min(i,u.length+p.length-j);let a=Math.max(b,Math.max(t,x)-j);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function E(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+je(i,e,t)-u.length-m)}function D(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(C(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return w({blocked:!1,emit:O(o)});let s=r.take(m,m+o,i);return s.action===`block`||s.action===`redact`&&!n.rewrite?{blocked:!0,hits:s.hits,boundary:n.boundary}:(O(s.taken),w({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function O(e){let t=h.slice(0,e);return h=h.slice(e),m+=t.length,l&&(g=(g+t).slice(-j)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),D(e)):{blocked:!1,emit:``}},flush:()=>D(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?pe(u+p,s,c):``}}function B(e,t,n){return Pe(t,e.detect,n)}async function Ln(e,t,n,r){return B(e,[n],t)?(await Kt(),Rn(e,t,n,r)):null}function Rn(e,t,n,r){return B(e,[n],t)?In({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:Re(e,t)},...r?{carry:r}:{}}):null}async function zn(e,t,n,r){return B(e,[n],r??t)?(await Kt(),In({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??Re(e,t)}})):null}var Bn=class{open;gate;constructor(e){this.open=e}async read(e){if(this.gate===void 0&&(this.gate=await this.open()),this.gate===`stopped`)return``;if(!this.gate)return e;let t=this.gate.process(e);return t.blocked?(this.gate=`stopped`,``):t.emit}end(){if(!this.gate||this.gate===`stopped`)return``;let e=this.gate.flush();return e.blocked?``:e.emit}},Vn=[`user`,`options`,`repair`,`attachment`,`voice`,`history`,`system`];function Hn(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Un={client:`untrusted`,server:`assembled`};function Wn(e){return typeof e==`string`?e:JSON.stringify(e)}function Gn(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of $e){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Wn(o));let c=s.found(),l=Me(`context`,c);l&&n.push({...l,trust:Un[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Kn=/^[A-Za-z0-9._-]+$/;function qn(e){let t=e?.trim();return t&&Kn.test(t)?t:void 0}function Jn(e,t){if(!e)return e;let n=e.guidance?t.read(e.guidance):void 0;return{previousOutput:t.read(e.previousOutput),rejection:t.read(e.rejection),...n?{guidance:n}:{}}}function Yn(e,t){return e.map(e=>{let n=e.content===void 0?void 0:t.read(e.content),r=e.parts?.map(e=>e.type===`text`?{...e,text:t.read(e.text)}:e);return{role:e.role,...n===void 0?{}:{content:n},...r?{parts:r}:{},...e.tool_calls?{tool_calls:e.tool_calls}:{},...e.tool_call_id?{tool_call_id:e.tool_call_id}:{},...e.name?{name:e.name}:{},...e.metadata?{metadata:e.metadata}:{},...e.reasoning?{reasoning:e.reasoning}:{}}})}function Xn(e,t){let n=t?`: ${t}`:``;return new k(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function Zn(e,t){let{detect:n}=b(t.guardrails),r=Ie(Vn,e=>tt(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:kt(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=Hn(i.options,r.options),c=Gn(i.context,()=>tt(`context`,n)),l=Jn(i.repair,r.repair),u=i.history?Yn(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?Ct(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Vn){let t=r[e].found(),n=Me(e,t);n&&p.push(Ht(n)),t.action===`block`&&(m??=Xn(e,t.errorInternal))}return p.push(...c.events.map(Ht)),c.blocked&&(m??=Xn(`context`)),{request:{...e,system:o,projectId:qn(e.projectId),input:{...i,text:a,options:s,...c.context?{context:c.context}:{},repair:l,history:u,attachments:d,voice:f}},events:p,...m?{refusal:m}:{}}}function Qn(e,t){let{request:n,refusal:r}=Zn(e,t);if(r)throw r;return n}function $n(e,t){return[...new Set([...t.filter(t=>ue(e,t)),...e.filter(e=>ue(t,e))])]}function er(e,t){let n=e.attachments?t?$n(e.attachments.accept,t.media.flatMap(e=>e.accept)):[...e.attachments.accept]:[],r=(t?.media??[]).flatMap(e=>e.maxPerInput===void 0?[]:[{accept:[...e.accept],max:e.maxPerInput}]);return{text:e.text!==!1,...n.length>0?{attachments:{accept:n}}:{},...e.maxFiles===void 0?{}:{maxFiles:e.maxFiles},...e.maxBytes===void 0?{}:{maxBytes:e.maxBytes},...e.maxTurnBytes===void 0?{}:{maxTurnBytes:e.maxTurnBytes},...e.limitsByMime===void 0?{}:{limitsByMime:{...e.limitsByMime}},...t?.maxInputs===void 0?{}:{maxInputs:t.maxInputs},...r.length>0?{perInput:r}:{}}}function tr(e){let t=ee(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function nr(e,t){let n=Et(e),r=wt({attachments:e.attachments?.accept,...n?{limits:{...n,maxFiles:2**53-1}}:{}},t.flat(),[]);if(n)for(let i of t){i.length>n.maxFiles&&r.push({code:`too_many_files`,params:{maxFiles:n.maxFiles}});for(let t of e.perInput??[])i.filter(e=>ue(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:tr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var rr=`final_answer`;function ir(e){return e.structured!==null&&e.tools.wire.length>0}function ar(e,t,n){let{structured:r}=t;if(!r||!ir(t))return e;let i={type:`function`,name:rr,description:A(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function or(e,t){return e.get(t)||{name:t,missing:!0}}function sr(e){let t=new Set;if(e.type===`host`||e.type===`decision`||e.type===`embedding`)return[];for(let n of Object.values(e.models))for(let e of n.builtInTools??[])t.add(e);return[...t]}function cr(e,t){return[...It(t),...sr(t)].map(t=>or(e,t))}function V(e,t){if(Array.isArray(e)){for(let n of e)V(n,t);return}if(typeof e!=`object`||!e)return;let{properties:n,...r}=e;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n))t.add(e),V(r,t);for(let e of Object.values(r))V(e,t)}function lr(e,t){let n=cr(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&V(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function ur(e){return!e||e.length===0?[]:e.slice(-4)}function dr(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${A(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
2
+ `)}\n\n`}function fr(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||A(`repair.default_guidance`,{},t.labels),a=dr(ur(r),t.labels),o=`${A(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${A(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${A(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${A(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${A(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${A(`repair.section_instructions`,{},t.labels)}\n`,o+=A(`repair.prompt_instructions`,{},t.labels),o}function pr(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function mr(e,t){let n=pr(e,t);if(!(n.length<=1))throw new k(`config`,`Profile ${e.id} declares multiple output wire formats (${n.join(`, `)}). Only one of a structured JSON schema (outputs.structured), image, or speech may be active.`)}function hr(e,t){if(e.type!==`speech`){if(t.speech)throw new k(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new k(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function gr(e,t){if(e.type===`transcription`){if(t.system)throw new k(`config`,`Profile ${e.id} (transcription) takes no system prompt — the input is the clip`);if(!t.input?.voice?.length)throw new k(`request`,`Profile ${e.id} (transcription) requires a voice clip`)}}function _r(e,t){return e.type===`speech`?{...e.speech,...vr(t.speech)}:void 0}function vr(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function yr(e){if(e.type!==`image`)return null;let t=e.image;return{type:`image`,mimeType:t.mimeType,aspectRatio:t.aspectRatio,resolution:t.resolution,quality:t.quality,background:t.background,n:t.n,seed:t.seed,outputCompression:t.outputCompression,includeText:t.includeText===!0}}function br(e){let t=O(e);if(!t)throw new k(`input`,`MIME '${e}' is not a supported media input type`);return t}function xr(e){return e.map(e=>{let t=br(e.mimeType),n=ee(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return Tt(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Sr(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new k(`request`,`Profile ${e.id} (speech) requires text input`);if(y(e)?.text===!1&&n)throw new k(`request`,`Profile ${e.id} does not accept text input`);let a=r?fr({profile:e,repair:r,history:i}):wr(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Cr(t),...a?[Ee(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
3
+
4
+ `)}:null}function Cr(e){let t=e.input?.context??{};return[...$e].reverse().filter(e=>t[e]!==void 0).map(e=>be(e,Wn(t[e])))}function wr(e,t){if(t.continueFrom&&ae.includes(e.type)){if(t.input?.text)throw new k(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return A(`continue.instruction`,{},e.labels)}}function Tr(e){return e.type===`image`&&e.image.references?xr(e.image.references):[]}function Er(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Tr(e),...xr(n),...xr(r)]}function Dr(e,t){let n=[],r=Sr(e,t);return r&&n.push(r),n.push(...Er(e,t)),n}function Or(e,t){let n=t.input?.context;if(!n)return;let r=y(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!$e.includes(t)||!r?.from.some(e=>e===t))throw new k(`request`,`Profile ${e.id} takes no context from '${t}'`);if(Wn(i).length>r.maxChars)throw new k(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}function kr(e,t){if(e.type===`speech`||e.type===`transcription`)return[];let n=e.identity.system;if(!n)return[];let r=jt(e,t);return Pt(n,r,t=>Mt(e,t,r))}function Ar(e,t){let n=kr(e,t);return{pieces:Nt([...n.map(({pieces:e})=>e),t.system===void 0?[]:At(t.system)]),lines:n.map(({line:e})=>e)}}function jr(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function Mr(e,t){if(jr(e))return e;throw e.type===`host`?new k(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new k(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new k(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function Nr(e,t){if(t){if(!e.allowModelSelect)throw new k(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new k(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function Pr(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new k(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new k(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new k(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function Fr(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function Ir(e,t){if(e.type===`live`)return null;let n=e.outputs?.structured;if(!n)return null;if(typeof n==`string`)return n;let r=t[n.by];if(r){let e=n.map[r];if(e)return e}return n.fallback}function Lr(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function Rr(e,t){return e.type===`live`?`live`:`turn`}function zr(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new k(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=ce(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new k(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new k(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new k(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function Br(e,t){return B(b(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function Vr(e){let{detect:t}=b(e.guardrails);return e.type!==`speech`&&e.type!==`transcription`&&He(t,`canary_leak`)?Ne():``}function Hr(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new k(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function Ur(e,t,n){let r=Mr(e.profiles.get(t.profile),`resolveTurn`);Ot(r,t),Or(r,t);let i=Qn(t,r),a=i.input??{};zr(r,i);let o=n??Nr(r,i.model),s=le(r,o),c=Dt(e.tools,r,i,o),l=c.builtins,u=Ir(r,jt(r,i));if(mr(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new k(`config`,`Profile ${r.id}: a structured turn answers through '${rr}', so no tool of its own may take that name`);hr(r,i),gr(r,i);let d=Hr(r,o,s,i.builtInArgs),f=Rr(r,s),p=e.providers.get(s.provider),m=p&&ie(p,s,r.type),h=Ar(r,i);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,...m?{operationName:m}:{},stream:Lr(r),thinking:Pr(r,s,o,i.effort),summaries:Fr(s),maxOutputTokens:s.maxOutputTokens,temperature:s.temperature,builtins:l,builtInArgs:d,sessionId:i.sessionId,tools:c,sessionPermissions:i.sessionPermissions,execution:i.execution,pageExecution:i.pageExecution,history:a.history,maxSteps:r.maxSteps??20,structured:u?{id:u,jsonSchema:e.schemas.get(u).jsonSchema}:null,image:yr(r),speech:_r(r,i),live:r.type===`live`?Br(r.live,r.guardrails):void 0,input:Dr(r,i),canary:Vr(r),resolvedSystem:h.pieces,systemLines:h.lines,host:i.host}}}function Wr(e){return e.type===`image`?e.image:null}function Gr(e,t){let n=Mr(t,`projectProfile`),{identity:r}=n,i=y(n)??null,a=n.type===`live`?null:n.outputs??null;return{id:n.id,type:n.type,handle:r.handle,models:n.models,defaultModel:n.defaultModel,allowModelSelect:n.allowModelSelect,maxSteps:n.maxSteps,tools:cr(e,n),inputs:i,outputs:a,image:Wr(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function Kr(e,t){return Gr(e.tools,e.profiles.get(t))}var qr=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function Jr(e){return e.join(`,`)}function Yr(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:Jr(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,options:e?.options,context:e?.context}}function Xr(e){return{text:e.text,attachments:e.attachments?{accept:e.attachments.accept}:void 0,voice:e.voice?{accept:e.voice.accept}:void 0,maxFiles:e.maxFiles,maxBytes:e.maxBytes,maxTurnBytes:e.maxTurnBytes,limitsByMime:e.limitsByMime,options:e.options,context:e.context}}function Zr(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=wt({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:Et(Xr(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function Qr(e){let t=globalThis.MediaRecorder;if(t===void 0)return;let n=e=>t.isTypeSupported(e),r=e=>e.find(n);return e?.length?r(qr.filter(t=>ue(e,t)))??e.find(n):r(qr)}var $r=_({protocol:r(),provider:r(),apiId:r(),options:t(r(),u()).optional(),keySlot:r().optional(),fallbackKeySlot:r().optional(),efforts:t(r(),c(_t)).optional(),defaultEffort:r().optional(),allowEffortSelect:m().optional(),summaries:m().optional(),maxOutputTokens:s().optional(),temperature:s().optional(),builtInTools:l(r()).optional(),compaction:_({maxTokens:s(),compactAt:s(),previousExchanges:s(),profile:r().optional(),timing:c(lt),meter:c(ft).optional()}).optional(),limits:_({operationTimeoutMs:s().optional(),connectTimeoutMs:s().optional(),liveStepTimeoutMs:s().optional(),maxWireRecordBytes:s().optional(),maxWireResponseBytes:s().optional(),maxEventBytes:s().optional(),maxStepBytes:s().optional(),maxStepEvents:s().optional(),maxPendingToolCalls:s().optional()}).optional()}),ei=_({structured:n([r(),_({by:r(),map:t(r(),r()),fallback:r()}),f()]).optional(),streaming:_({mode:c(Je).optional(),streamThoughts:m().optional()}).optional()}),ti=_(Ie(vt,()=>c(Be))),ni=_(Ie(bt,()=>ti)),ri=_({id:r(),label:r(),actions:ti,names:l(r()),find:m()}),ii=_({hosts:l(r()),fromTools:m()}),ai=_({quota:_({perDay:s()}).optional(),detect:ni,patterns:a(c(bt),_({theorem:m(),names:l(r())})).optional(),host:l(ri).optional(),allow:_({ungiven_images:ii,ungiven_links:ii}),blockedReply:_({onBlock:c(it),maxRetries:s()})}),oi=n([m(),_({theorem:m(),host:m()})]),si=_({record:m(),writeTo:n([g(!1),r()]).optional(),sampleRate:s(),include:_({upstreamLog:m(),outboundWire:m(),evidenceRaw:m(),usage:m(),guardrailDecisions:m(),guardrailMatchPreview:m()}),scrub:_({sensitive:oi,injection:oi,canary:oi}),resource:Bt,retainForDays:s(),rotateAfterMiB:s(),hasOnWriteError:m()}),ci=t(r(),_({label:r().optional(),choices:l(_({value:r(),description:r().optional()}))})),H=_({text:m(),attachments:_({accept:l(r()),acceptAttr:r()}).nullable(),voice:_({accept:l(r())}).nullable(),maxFiles:s().optional(),maxBytes:s().optional(),maxTurnBytes:s().optional(),limitsByMime:t(r(),s()).optional(),options:ci.optional(),context:_({from:l(c($e)),maxChars:s()}).optional()}),li=_({allowContinue:l(c(Ke)).optional(),autoContinue:l(c(Ke)).optional(),maxContinues:s().optional()}),ui=_({resumption:li.optional()}),di=_({allow:l(r()),page:l(r()),t2Loader:r().optional(),parallel:m().optional()}),U={providerContinuation:_({history:c([`host`,`stateless`,`provider`]).optional()}).optional(),id:r(),models:t(r(),$r),defaultModel:r(),allowModelSelect:m().optional(),maxSteps:s().optional(),labels:a(c(xt),r()),guardrails:ai.optional(),observability:si.optional()},fi=n([r(),o({private:r().min(1)})]),pi=n([r(),l(n([r(),l(fi).readonly()])).min(1).readonly()]),mi=_({handle:r(),options:ci.optional(),system:pi.optional()}),W=d(`type`,[_({...U,type:g(`text`),identity:mi,outputs:ei.optional(),inputs:H,tools:di,turnBehaviour:_({resumption:li.optional(),allowSteering:m().optional(),atStepLimit:c(yt).optional()}).optional(),canStop:g(!0),allowSteering:m()}),_({...U,type:g(`image`),identity:mi,outputs:ei.optional(),image:_({aspectRatio:r().optional(),resolution:r().optional(),mimeType:r().optional(),quality:r().optional(),background:r().optional(),n:s().int().min(1).optional(),seed:s().int().optional(),outputCompression:s().int().min(0).max(100).optional(),references:l(n([_({mimeType:r(),data:r(),name:r().optional()}),_({mimeType:r(),uri:r(),name:r().optional()})])).optional(),includeText:m().optional()}),inputs:H,tools:di,turnBehaviour:ui.optional(),canStop:g(!0)}),_({...U,type:g(`transcription`),identity:_({handle:r()}),maxSteps:h().optional(),outputs:ei.optional(),inputs:H,canStop:g(!0)}),_({...U,type:g(`speech`),identity:_({handle:r()}),outputs:ei.optional(),speech:_({voice:r().optional(),style:r().optional(),speed:s().optional(),format:c(Ge).optional()}),inputs:H,turnBehaviour:ui.optional(),canStop:g(!0)}),_({...U,type:g(`live`),identity:mi,inputs:H.pick({options:!0,context:!0}).optional(),live:_({ingress:_({audio:m().optional(),video:m().optional(),text:m().optional()}).optional(),voice:r().optional(),vad:_({activityHandling:c(mt).optional(),startSensitivity:c(Qe).optional(),endSensitivity:c(Xe).optional(),prefixPaddingMs:s().optional(),silenceDurationMs:s().optional()}).optional(),sessionResumption:m().optional(),contextCompression:_({triggerTokens:s().optional(),slidingWindow:_({targetTokens:s().optional()})}).optional(),transcription:_({input:m().optional(),output:m().optional()}).optional()}),tools:di.pick({allow:!0,page:!0}),turnBehaviour:_({allowSteering:m().optional()}).optional()})]);function hi(e){let t=b(e),{sources:n,host:r,...i}=t.detect;return{quota:t.quota,detect:i,...n?{patterns:Object.fromEntries(Object.entries(n).map(([e,{theorem:t,matchers:n}])=>[e,{theorem:t,names:n.map(({name:e})=>e)}]))}:{},...r?{host:r.map(({id:e,label:t,actions:n,matchers:r,find:i})=>({id:e,label:t,actions:n,names:r.map(({name:e})=>e),find:!!i}))}:{},allow:{ungiven_images:gi(t.allow.ungiven_images),ungiven_links:gi(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function gi(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function _i(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function vi(e){if(!e)return;let t=Rt(e);return{record:t.record,writeTo:_i(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function yi(e){let{greeting:t,resumed:n,...r}=e??{};return r}function bi(e,t){let n=e.tools.filter(e=>`type`in e&&e.type===`function`&&e.answeredBy===`page`).map(e=>e.name);if(t){let e=Ft(t),r=Lt(t);return{allow:[...It(t)],page:n,...e?.t2Loader?{t2Loader:e.t2Loader}:{},...r===void 0?{}:{parallel:r}}}return{allow:e.tools.filter(e=>!(`type`in e&&e.type===`builtin`)).map(e=>e.name),page:n}}function xi({allow:e,page:t}){return{allow:e,page:t}}function Si(e,t){let n=Yr(e.inputs),r=t?.identity??{handle:e.handle},i=t?hi(t.guardrails):void 0,a=t?vi(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:me(t?.labels)};switch(e.type){case`text`:return W.parse({...s,type:`text`,inputs:n,tools:bi(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||ne(t)});case`image`:return W.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:bi(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return W.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`transcription`:return W.parse({...s,type:`transcription`,inputs:n,canStop:!0});case`live`:return W.parse({...s,type:`live`,live:yi(e.live),...e.inputs?{inputs:{options:n.options,context:n.context}}:{},tools:xi(bi(e,t))});default:return e.type}}function Ci(e,t){let n=Mr(e,`interfaceFromProfile`);return Si(Gr(t,n),n)}function wi(e){return p(t=>T.safeParse(e(t)).success)}var Ti=[`running`,`gate`,`background`,`complete`,`error`,`cancel`],Ei=p(e=>{let t=T.safeParse({type:`tool`,tool:e});if(!t.success||t.data.type!==`tool`||!(`phase`in t.data.tool))return!1;let{phase:n}=t.data.tool;return Ti.some(e=>e===n)}),Di=t(r(),i()),Oi=_({operationId:r().optional(),name:r(),callId:r(),arguments:Di,draft:r().optional(),reasoning:l(S).optional(),stepId:r().optional(),edited:_({from:Di,to:Di}).optional(),activity:r().optional(),activityPast:r().optional(),outputDraft:r().optional(),state:Ei.optional(),startedAt:s().optional(),endedAt:s().optional(),artifacts:l(i()),get steps(){return l(Oi).optional()}}),ki=_({kind:c(rt),native:r().optional()}),G={id:r()},K=d(`kind`,[_({...G,kind:g(`user-text`),text:r()}),_({...G,kind:c([`user-attachment`,`user-voice`]),name:r(),mimeType:r(),sizeBytes:s(),data:r().optional()}),_({...G,kind:g(`thought`),text:r()}),_({...G,kind:g(`text`),text:r()}),_({...G,kind:g(`tool`),tool:Oi}),_({...G,kind:g(`structured`),value:i(),draft:r().optional()}),_({...G,kind:g(`media`),mimeType:r(),data:r().optional(),url:r().optional(),previewUrl:r().optional()}),_({...G,kind:g(`grounding`),grounding:wi(e=>({type:`grounding`,grounding:e}))}),_({...G,kind:g(`citation`),sources:wi(e=>({type:`citation`,sources:e})),callId:r().optional()}),_({...G,kind:g(`evidence`),evidence:wi(e=>({type:`evidence`,evidence:e}))}),_({...G,kind:g(`guardrail`),guardrail:se}),_({...G,kind:g(`late-results`),text:r()}),_({...G,kind:g(`error`),message:r()}),_({...G,kind:g(`turn-done`),stop:ki.optional(),tokens:wi(e=>({type:`tokens`,tokens:e})).optional(),interactionId:r().optional(),compaction:m().optional(),workedMs:s().optional(),endedAt:s().optional()})]),Ai=_({type:r()});function ji(e,t){return Object.hasOwn(e,t)}function Mi(e,t){return e.map(e=>{let n=[...t,...e.path],r=`${n.map(String).join(`.`)||`(root)`} ${e.code}`;return e.code!==`invalid_union`||e.errors.length===0?r:`${r} [${e.errors.map(e=>Mi(e,n)).join(` | `)}]`}).join(`; `)}function Ni(e){return Mi(e.issues,[])}function Pi(e,t){return new k(`bad_response`,`${e} failed its wire check: ${Ni(t)}`)}function q(e,t,n){let r=e.safeParse(t);if(!r.success)throw Pi(n,r.error);return r.data}function Fi(e){return{type:`malformed`,error:new k(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Ii(e,t){let n=Ai.safeParse(t);if(!n.success)return Fi(`a line without a kind failed its wire check: ${Ni(n.error)}`);let{type:r}=n.data;if(!ji(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:Fi(`a '${r}' line failed its wire check: ${Ni(i.error)}`)}function Li(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Ri(e,t){let n=Li(t);return n?Ii(e,n.value):Fi(`a line is not JSON`)}function zi(e){let t=Li(e);if(!t)throw new k(`bad_response`,`a line is not JSON`);return t.value}var Bi=_({name:r(),mimeType:r(),data:r()}),Vi=_({options:t(r(),r()).optional(),context:i().optional(),text:r().optional(),attachments:l(Bi).optional(),voice:l(Bi).optional()}),Hi=_({gateKind:c(ht).optional(),sessionPermissions:l(r()).optional(),name:r().optional(),input:i().optional(),snapshot:v.optional(),promoted:l(r()).optional(),model:r().optional(),effort:r().optional()}),J=r().trim().min(1),Ui=_({path:r().optional(),options:t(r(),r()).optional()}),Wi=Ui;_({input:Vi,conversation:r().min(1).optional(),model:r().optional(),effort:r().optional(),stated:Ui.optional(),turnId:J.optional(),abandon:l(x).min(1).optional(),replay:Hi.pick({sessionPermissions:!0}).optional(),transcript:l(K).optional()});var Gi=[`approve`,`deny`],Ki=n([o({unanswered:g(!0)}),o({output:i()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);_({gateId:r().min(1),operationId:r().min(1).max(256),decision:c(Gi),input:i().optional(),secret:r().optional(),page:Ki.optional(),conversation:r().min(1).optional(),turnId:J.optional(),replay:Hi.optional()}),_({turnId:J,id:J,inject:l(E).min(1)}),_({turnId:J});var qi=_({type:g(`conversation`),ref:r().min(1),posted:g(!0).optional()}),Ji={...C,conversation:qi},Yi=_({transcript:l(K),paused:_({events:l(T),blocks:l(K)}).optional(),notify:_({retryMs:s().optional()}).optional()});_({conversation:r().min(1)}),o({});var Xi={changed:_({type:g(`changed`)})};_({conversation:r().min(1),at:s().int().min(-1)}),_({blocks:l(K)});var Zi=_({conversation:r().min(1),view:Yi}),Qi=class extends Error{kind;publicMessage;internalMessage;copy;constructor(e,t,n,r){super(n??t??e),this.name=`TheoremStreamError`,this.kind=e,t&&(this.publicMessage=t),n&&(this.internalMessage=n),r&&(this.copy=r)}};function $i(e){return e instanceof Qi}function ea(e){return e?.trim()||void 0}var ta=_({error:r().optional(),errorKind:re.optional(),errorCopy:D.optional(),errorInternal:r().optional()}),na=ta;function ra(e,t){let n=ea(e.error),r=ea(e.errorInternal);return new Qi(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function ia(e){return!$i(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function aa(e,t){let n=Ri(e,t);if(n.type===`error`)throw ra(ta.parse(n),`internal`);return n}function oa(e,t,n){let r=e.split(`
5
+ `),i=r.pop()??``;for(let e of r)e.trim()&&n(aa(t,e));return i}async function sa(e,t,n,r){if(!e.body)throw new k(`bad_response`,`stream reply has no body`);let i=e.body.getReader(),a=new TextDecoder,o=``,s=()=>{i.cancel()};r?.addEventListener(`abort`,s,{once:!0});try{for(;;){ye(r);let{done:e,value:s}=await i.read();if(e)break;o=oa(o+a.decode(s,{stream:!0}),t,n)}let e=o.trim();e&&n(aa(t,e))}finally{r?.removeEventListener(`abort`,s)}}async function ca(e){let t=typeof e.headers==`function`?await e.headers():e.headers,n=new Headers(t);return n.set(`content-type`,`application/json`),n}async function la(e,t){let n=await e.text(),r;try{r=JSON.parse(n),t?.(r)}catch{return ra({errorInternal:`HTTP ${String(e.status)}`},nt(e.status))}let i=ta.safeParse(r);return i.success?ra({...i.data,errorInternal:i.data.errorInternal??`HTTP ${String(e.status)}`},nt(e.status)):new k(`bad_response`,`HTTP ${String(e.status)} error body failed its wire check`)}async function ua(e,t,n){let r=n.fetch??globalThis.fetch.bind(globalThis);try{return await r(e,{...t,headers:await ca(n),credentials:n.credentials??`same-origin`})}catch(e){throw fe(e)?e:new k(`network`,ge(e),{cause:e})}}async function da(e,t,n,r,i={}){await sa(await fa(e,t,i),n,r,i.signal)}async function fa(e,t,n){let r=await ua(e,{method:`POST`,body:JSON.stringify(t),signal:n.signal},n);if(!r.ok)throw await la(r);return r}async function pa(e,t,n={}){await fa(e,t,n)}async function Y(e,t,n={}){let r=await ua(e,{...t.body===void 0?{method:`GET`}:{method:`POST`,body:JSON.stringify(t.body)},signal:t.signal},n);if(!r.ok)throw await la(r,t.failed);return zi(await r.text())}async function ma(e,t,n={}){let{signal:r,...i}=n;return q(Yi,await Y(e,{body:t,signal:r},i),`the conversation`)}async function ha(e,t,n,r){let{signal:i,...a}=n;return q(Zi,await Y(e,{body:t,signal:i},a),r)}function ga(e,t,n={}){return ha(e,t,n,`the rewound conversation`)}function _a(e,t,n={}){return ha(e,t,n,`the started conversation`)}function va(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)}var ya=_({interface:W});function ba(e={}){let t=va(e.endpoint??`/api/theorem`);return{async describe(n){let r=await ua(t,{method:`GET`,signal:n},e);if(!r.ok)throw await la(r);return q(ya,zi(await r.text()),`the profile description`).interface},turn:({replay:n,...r},i,a)=>da(`${t}/turn`,r,Ji,i,{...e,signal:a}),invoke:({replay:n,...r},i,a)=>da(`${t}/invoke`,r,Ji,i,{...e,signal:a}),conversation:(n,r)=>ma(`${t}/conversation`,n,{...e,signal:r}),notify:(n,r)=>da(`${t}/notify`,{},Xi,e=>{e.type===`changed`&&n()},{...e,signal:r}),rewind:(n,r)=>ga(`${t}/rewind`,n,{...e,signal:r}),pageResult:(n,r)=>pa(`${t}/page-result`,n,{...e,signal:r}),steer:n=>pa(`${t}/steer`,n,e),stop:n=>pa(`${t}/stop`,n,e)}}function xa(e,t){if(typeof e==`string`)return e;let n=Array.isArray(e)?e:Object.keys(e);return n.length?xa(n[0],t):t}function Sa(e){return Object.entries(e).map(([e,t])=>({id:e,type:t.type,labels:t.type===`choice`?Object.keys(t.criteria):t.type===`score`?t.criteria.map((e,t)=>xa(e,String(t))):[],...t.type===`box`&&t.image!==void 0?{image:t.image}:{}}))}function Ca(e,t,n){return{type:`decision`,identity:{handle:e.identity.handle},contract:e.decision.contract,...e.inputs.maxStateBytes===void 0?{}:{maxStateBytes:e.inputs.maxStateBytes},questions:Sa(t),...n&&Object.keys(n).length>0?{images:n}:{},...e.observability?{observability:{record:Rt(e.observability).record}}:{}}}function wa(e,t){let n=Object.keys(t??{}).find(t=>e&&Object.hasOwn(e,t));if(n!==void 0)throw new k(`request`,`the image ${n} is the host's, so the page's needs another name`);let r={...e,...t};return Object.keys(r).length>0?r:void 0}var X=s().min(0).max(1),Ta=t(r(),X),Ea=d(`type`,[_({type:g(`choice`),choice:r(),confidence:X,probabilities:Ta}),_({type:g(`noul`),noul:X}),_({type:g(`box`),box:_({top:X,bottom:X,left:X,right:X}),confidence:X}),_({type:g(`score`),score:s().nonnegative(),confidence:X,legend:t(r(),r().min(1)),probabilities:Ta})]),Da=_({id:r(),type:c([`choice`,`noul`,`score`,`box`]),labels:l(r()),image:r().optional()}),Oa=_({result:_({model:r().min(1),questions:l(Da).optional(),answers:t(r(),Ea),usage:_({inputTokens:s().int().nonnegative(),outputTokens:s().int().nonnegative(),costUsd:s().nonnegative().optional()}).optional()}),traces:l(zt).optional()}),ka=new WeakMap;function Aa(e,t){return t.length>0&&typeof e==`object`&&e&&ka.set(e,t),e}function ja(e){return typeof e==`object`&&!!e&&ka.get(e)||[]}var Ma=_({traces:l(zt)});async function Na(e,t,n,r,i){let a=[],o=e=>{let t=Ma.safeParse(e);t.success&&(a=t.data.traces)};try{return i(await Y(e,{body:t,signal:n,failed:o},r))}catch(e){throw Aa(e,a)}}function Pa(e,t,n,r={}){return Na(e,t,n,r,Fa)}function Fa(e){return q(Oa,e,`the decision`)}var Ia=_({interface:_({type:g(`decision`),identity:_({handle:r()}),contract:r(),maxStateBytes:s().optional(),questions:l(Da),build:_({input:t(r(),i()).optional()}).optional(),images:t(r(),_({mimeType:c([`image/png`,`image/jpeg`]),data:r()})).optional(),observability:_({record:m()}).optional()})});function La(e={}){let t=(e.endpoint??`/api/decision`).replace(/\/$/,``);return{async describe(n){return q(Ia,await Y(t,{signal:n},e),`the decision description`).interface},decide:(n,r,i,a)=>Pa(`${t}/decide`,{state:n,...i?{assets:i}:{},...a===void 0?{}:{input:a}},r,e)}}function Ra(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n.trim():void 0}function Q(e,t){if(!URL.canParse(t))return;let n=new URL(t);if(n.protocol===`http:`||n.protocol===`https:`)return{title:e.trim()||n.hostname.replace(/^www\./,``),uri:n.href,type:`web`}}function za(e){let t=new Set;return e.filter(e=>!t.has(e.uri)&&(t.add(e.uri),!0))}function Ba(e){let t=[...e.matchAll(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g)].flatMap(e=>Q(e[1]??``,e[2]??``)??[]),n=[...e.matchAll(/https?:\/\/[^\s"'<>\]]+/g)].flatMap(e=>{let t=(e[0]??``).replace(/[),.;:]+$/,``);return Q(t,t)??[]});return za([...t,...n])}function Va(e){if(Array.isArray(e))return e;if(!Ra(e))return[];for(let t of[`items`,`results`,`search_results`,`models`,`datasets`]){let n=e[t];if(Array.isArray(n))return n}return[]}function Ha(e,t){return za(e.flatMap(e=>Ra(e)?t(e)??[]:[]))}function Ua(e,t){let n=t===`dataset`?`https://huggingface.co/datasets/`:`https://huggingface.co/`;return Ha(Va(e),e=>{let t=Z(e,`id`)??Z(e,`modelId`);return t?Q(t,`${n}${t}`):void 0})}function Wa(e){return Ha(Va(e),e=>{let t=Z(e,`html_url`),n=Z(e,`full_name`)??Z(e,`name`);return t?Q(n??t,t):void 0})}function Ga(e){let t=e,n;do n=t,t=t.replace(/<[^>]+>/g,``);while(t!==n);return t.replace(/\s+/g,` `).trim()}function Ka(e){if(typeof e!=`string`)return Ba(JSON.stringify(e));let t=[...e.matchAll(/<entry\b[\s\S]*?<\/entry>/g)];return t.length===0?Ba(e):za(t.flatMap(e=>{let t=/<id>(https?:\/\/[^<]+)<\/id>/.exec(e[0]??``)?.[1],n=/<title>([\s\S]*?)<\/title>/.exec(e[0]??``)?.[1];return t?Q(Ga(n??t),t)??[]:[]}))}function $(e){if(typeof e==`string`)return Ba(e);if(Array.isArray(e)||Ra(e)){let t=Ha(Va(e),e=>{let t=Z(e,`html_url`)??Z(e,`url`)??Z(e,`source_url`)??Z(e,`contentUrl`),n=Z(e,`title`)??Z(e,`name`)??t;return t?Q(n??t,t):void 0});return t.length>0?t:Ba(JSON.stringify(e))}return[]}var qa={search_models:e=>Ua(e,`model`),search_datasets:e=>Ua(e,`dataset`),search_github:Wa,list_arxiv:Ka,search_web:$,read_pages:$,read_model_card:$,read_dataset_card:$,read_readme:$,find_library:$,read_library_docs:$,ask_repo_docs:$};function Ja(e){return qa[e]}function Ya(e,t){let n=Ja(e);return n?{...t,sources:n}:t}function Xa(e,t,n={}){let r={name:t.name,description:t.description,category:t.category,access:t.access,paths:t.paths,loadTier:t.loadTier,permission:t.permission,...t.labels?{labels:t.labels}:{},...t.after?{after:!0}:{},...t.background?{background:t.background}:{}};if(t.type===`agent`){e.register({...r,type:`agent`,profile:t.profile,...t.maxCallsPerTurn===void 0?{}:{maxCallsPerTurn:t.maxCallsPerTurn}});return}let i={...r,input:oe(t.inputSchema),output:oe(t.outputSchema)};if(t.type===`http`){e.register(Ya(t.name,{...i,type:`http`,endpoint:t.endpoint,method:t.method,headers:t.headers,mapping:t.mapping,auth:t.auth,maxResponseBytes:t.maxResponseBytes}));return}if(t.type===`mcp`){e.register(Ya(t.name,{...i,type:`mcp`,serverUrl:t.serverUrl,mcpToolName:t.mcpToolName,headers:t.headers,auth:t.auth,maxResponseBytes:t.maxResponseBytes,session:t.session}));return}if(t.answeredBy===`page`){e.register({...i,type:`function`,answeredBy:`page`});return}let a=t.stubResponse||!Object.hasOwn(n,t.name)?void 0:n[t.name],o=t.stubResponse??Vt(t.outputSchema);e.register({...i,type:`function`,handler:a?e=>{try{return Promise.resolve(a(e))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}}:()=>Promise.resolve(o)})}function Za(e,t,n){e.registerMany([...te,...w]);for(let r of t)Xa(e,r,n)}function Qa(e,t,n,r,i){if(Za(e.tools,n,i),r&&t.type!==`live`)for(let{id:t,spec:n}of[r,...r.also??[]])e.schemas.register(t,n);return e.profiles.register(t),t}function $a(e){if(e.type===`error`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,error:t}}if(e.type===`session`&&e.session.kind===`ended`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,session:{...e.session,message:t}}}if(e.type===`tool`&&e.tool.phase===`error`&&e.tool.failure.error!==void 0){let{failure:t}=e.tool;return{...e,tool:{...e.tool,failure:{...t,error:t.message}}}}return e}function eo(e){if(e.type!==`error`&&e.type!==`session`&&e.type!==`tool`||e.errorInternal===void 0)return e;let{errorInternal:t,...n}=e;return n}function to(e){if(e.type!==`compaction`||e.failure?.errorInternal===void 0)return e;let{errorInternal:t,...n}=e.failure;return{...e,failure:n}}function no(e){if(e.type!==`guardrail`||!(e.guardrail?.errorInternal||e.guardrail?.errorSummary))return e;let{errorInternal:t,errorSummary:n,...r}=e.guardrail;return{...e,guardrail:r}}function ro(e){if(e.type!==`done`||e.mediaRefused===void 0)return e;let{mediaRefused:t,...n}=e;return n}function io(e){if(e.type!==`evidence`||!e.evidence?.raw)return e;let{raw:t,...n}=e.evidence;return{...e,evidence:n}}function ao(e,t){let n=t?.reader===`builder`?$a(e):ro(to(no(eo(e))));return t?.includeEvidenceRaw||(n=io(n)),n=Wt(n,!1),n}function oo(e,t){return e.map(e=>ao(e,t))}function so(e,t,n){let{error:r=``,errorKind:i,errorCopy:a}=ao(Ae(Te(e),t),n);return{error:r,errorKind:i,...a?{errorCopy:a}:{}}}var co={reader:`builder`};function lo(e){return e.mode===`demo`?{reader:`visitor`}:co}export{Bn as $,Ni as A,Or as B,na as C,da as D,pa as E,Qr as F,ar as G,lr as H,Zr as I,Xn as J,nr as K,Nr as L,Ii as M,K as N,Wi as O,Ci as P,Zn as Q,Kr as R,ra as S,ia as T,rr as U,Dr as V,ir as W,Yn as X,Gn as Y,Qn as Z,ba as _,oo as a,Pn as at,ga as b,La as c,Ht as ct,ja as d,zn as et,Pa as f,Qi as g,Ji as h,ao as i,Fn as it,Ri as j,q as k,wa as l,Wt as lt,Aa as m,lo as n,Rn as nt,Qa as o,Kt as ot,Na as p,er as q,so as r,B as rt,Za as s,Ut as st,co as t,Ln as tt,Ca as u,ma as v,$i as w,_a as x,Y as y,Ur as z};
@@ -1 +1 @@
1
- import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as ee,t as u,v as te}from"./schemas-D7cgkv3L.js";import{Cn as ne,Ct as re,Un as ie,Vn as d,Zn as ae,_t as f,cr as p,ir as m,lr as h,mt as g,or as oe,rr as se}from"./tool-schema-BwaPiLtT.js";import{c as _}from"./host-patterns-F-KZIzkF.js";import{Hr as v,Pn as ce}from"./shaped-data-DCfLI4gb.js";import{d as le,f as ue,i as y,l as de,n as b,s as fe,t as x}from"./schema-Cv4HAfBT.js";var pe=n({accepted:se,preparedInput:m});function S(e){return new _(`internal`,e)}function C(e,t,n){return new _(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function w(e){return C(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function T(e){let t=e=>Array.isArray(e)?e.map(t):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,n])=>[e,t(n)])):e,n=m.parse(t(j(e))),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(n)));return Array.from(new Uint8Array(r),e=>e.toString(16).padStart(2,`0`)).join(``)}var E=d.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),D=n({finding:t(),data:m.optional(),parts:a(ie).optional(),modelText:t().optional(),provenance:h.optional(),suspicious:a(p).optional()}),O=d.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),k=n({event:O,replay:n({modelResult:D})}),A=n({event:E,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:D.optional(),outputRaw:m.optional(),failure:n({code:t(),kind:oe,message:t(),error:t().optional(),details:m.optional()}).optional(),awaiting:c().optional(),denied:te(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(ae),released:r().int().nonnegative().optional()})).optional()})});function j(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw S(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw S(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw S(`Tool operation value has an own __proto__ key`);t.add(e);try{if(Array.isArray(e))return e.map(n);let t=Object.entries(Object.getOwnPropertyDescriptors(e)),r=t.find(([,e])=>e.get||e.set);if(r)throw S(`Tool operation value has a getter or setter at '${r[0]}'`);return Object.fromEntries(t.filter(([,e])=>e.enumerable&&e.value!==void 0).map(([e,t])=>[e,n(t.value)]))}finally{t.delete(e)}};return m.parse(n(e))}var M=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),N=`background`;function P(){return c().optional().describe(v(`tool.background_field`))}function F(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[N]:n,...r}=t;return{input:r,asked:n===!0}}function I(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?F(e,t).asked?`claim`:void 0:n}function L(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||!n)return;let a=I(t,e.input);if(a!==void 0)return{at:a,support:n,trace:n.openTrace(r.callId),reply:()=>{let e={finding:v(`tool.background_started`,{tool:t.name},i)},n=f(e),a=g(r,{phase:`background`,readBack:n});return k.parse(j({event:a,replay:{modelResult:e}}))}}}function R(e,t){if(e&&!t?.detach)throw new _(`config`,`A request with a background service needs a coordinator with detach`)}function z(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new _(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!M.safeParse(n).success)throw new _(`config`,typeof n==`object`?`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`:`Tool '${t}' sets background to ${JSON.stringify(n)}; it takes 'always', 'ask', 'never' or { afterMs }`)}}var B=/^[\x21-\x7E]{1,256}$/;function V(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function me(e){return e!==null&&B.test(e)}async function he(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var H=`after`;function ge(){return a(t()).optional().describe(v(`tool.after_field`))}function U(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new _(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof u){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof ee)return e(n.options.map(a));throw new _(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function W(e,t){return U(e,t,H,ge)}function _e(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[H]:n,...r}=t;return{input:r,names:n??[]}}function ve(e,t,n){return n?e.flatMap(e=>{let r=n.filter(n=>n.tool===e&&n.callId!==t).map(e=>e.callId);return r.length>0?r:[e]}):[]}var G=class{value;constructor(e){this.value=e}};function ye(e){return new G(e)}function be(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return ye(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(v(`tool.page_timed_out`,{},i)):Error(v(`tool.page_no_answer`,{tool:e},i))}}var K=new WeakMap;function q(e,t){let n=K.get(e);n||(n=new WeakMap,K.set(e,n));let r=n.get(t);if(!r){let i=b(e,`input`);y(i,`input`);let a=b(t,`output`);y(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function J(e){let{inputSchema:t,outputSchema:n}=q(e.input,e.output),r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?re(n,r[t]):void 0;if(i)throw new _(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function xe(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new _(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function Y(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new _(`config`,`Tool "${e}" auth.queryParam ${r}`)}function Se(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new _(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function X(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new _(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Z(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new _(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Ce(e){Z(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Z(e.name,`imageLimits.count`,t.count),Z(e.name,`imageLimits.bytes`,t.bytes),Z(e.name,`imageLimits.totalBytes`,t.totalBytes),X(e.name,t.timeoutMs))}function Q(e){if(e.type!==`builtin`&&z({name:e.name,...e.background===void 0?{}:{background:e.background},...e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.type===`builtin`||e.type===`agent`)return;xe(e.name,e.auth),e.type===`http`?(e.endpoint?.trim()&&x(e.endpoint),Y(e.name,e.auth,e.mapping?.queryParams),Se(e.name,e.limit),X(e.name,e.timeoutMs)):Y(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Ce(e),e.type===`mcp`&&(Z(e.name,`session.idleMs`,e.session?.idleMs),Z(e.name,`session.max`,e.session?.max));let[t]=ce(e);if(t)throw new _(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function $(e){return x(e.endpoint),{...e,type:`http`,...J(e)}}function we(e){return{...e,type:`mcp`,...J(e)}}function Te(e){let t=e.answeredBy===`page`?be(e.name):e.handler;if(typeof t!=`function`)throw new _(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...J(e)}}function Ee(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=U(e.name,t,`background`,P);return{...e,askInputSchema:q(n,e.output).inputSchema}}function De(e,t,n){return Q(e),Ee(Oe(e,t,n))}function Oe(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=le(e,t,n),i=ne(r),a=fe({type:r.type,...i?{inputs:i}:{}},e),o=e.after?W(e.name,a):a,s=J({...e,input:o,output:de});return ue(e,o,s)}let r=e.after?{...e,input:W(e.name,e.input)}:e;return r.type===`http`?$(r):r.type===`mcp`?we(r):Te(r)}function ke(e=()=>void 0){let t=new Map,n=V(),r=e=>t.get(e),i=n=>{let i=De(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new _(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}export{A as _,ve as a,he as c,F as d,w as f,T as g,pe as h,_e as i,R as l,j as m,ke as n,V as o,S as p,G as r,me as s,Q as t,L as u,k as v,C as y};
1
+ import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as ee,t as u,v as te}from"./schemas-D7cgkv3L.js";import{Cn as ne,Ct as re,Un as ie,Vn as d,Zn as ae,_t as f,cr as p,ir as m,lr as h,mt as g,or as oe,rr as se}from"./tool-schema-D26IAEC3.js";import{c as _}from"./host-patterns-F-KZIzkF.js";import{Hr as v,Pn as ce}from"./shaped-data-D15FDUcH.js";import{d as le,f as ue,i as y,l as de,n as b,s as fe,t as x}from"./schema-BztznKB7.js";var pe=n({accepted:se,preparedInput:m});function S(e){return new _(`internal`,e)}function C(e,t,n){return new _(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function w(e){return C(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function T(e){let t=e=>Array.isArray(e)?e.map(t):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,n])=>[e,t(n)])):e,n=m.parse(t(j(e))),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(n)));return Array.from(new Uint8Array(r),e=>e.toString(16).padStart(2,`0`)).join(``)}var E=d.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),D=n({finding:t(),data:m.optional(),parts:a(ie).optional(),modelText:t().optional(),provenance:h.optional(),suspicious:a(p).optional()}),O=d.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),k=n({event:O,replay:n({modelResult:D})}),A=n({event:E,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:D.optional(),outputRaw:m.optional(),failure:n({code:t(),kind:oe,message:t(),error:t().optional(),details:m.optional()}).optional(),awaiting:c().optional(),denied:te(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(ae),released:r().int().nonnegative().optional()})).optional()})});function j(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw S(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw S(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw S(`Tool operation value has an own __proto__ key`);t.add(e);try{if(Array.isArray(e))return e.map(n);let t=Object.entries(Object.getOwnPropertyDescriptors(e)),r=t.find(([,e])=>e.get||e.set);if(r)throw S(`Tool operation value has a getter or setter at '${r[0]}'`);return Object.fromEntries(t.filter(([,e])=>e.enumerable&&e.value!==void 0).map(([e,t])=>[e,n(t.value)]))}finally{t.delete(e)}};return m.parse(n(e))}var M=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),N=`background`;function P(){return c().optional().describe(v(`tool.background_field`))}function F(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[N]:n,...r}=t;return{input:r,asked:n===!0}}function I(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?F(e,t).asked?`claim`:void 0:n}function L(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||!n)return;let a=I(t,e.input);if(a!==void 0)return{at:a,support:n,trace:n.openTrace(r.callId),reply:()=>{let e={finding:v(`tool.background_started`,{tool:t.name},i)},n=f(e),a=g(r,{phase:`background`,readBack:n});return k.parse(j({event:a,replay:{modelResult:e}}))}}}function R(e,t){if(e&&!t?.detach)throw new _(`config`,`A request with a background service needs a coordinator with detach`)}function z(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new _(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!M.safeParse(n).success)throw new _(`config`,typeof n==`object`?`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`:`Tool '${t}' sets background to ${JSON.stringify(n)}; it takes 'always', 'ask', 'never' or { afterMs }`)}}var B=/^[\x21-\x7E]{1,256}$/;function V(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function me(e){return e!==null&&B.test(e)}async function he(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var H=`after`;function ge(){return a(t()).optional().describe(v(`tool.after_field`))}function U(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new _(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof u){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof ee)return e(n.options.map(a));throw new _(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function W(e,t){return U(e,t,H,ge)}function _e(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[H]:n,...r}=t;return{input:r,names:n??[]}}function ve(e,t,n){return n?e.flatMap(e=>{let r=n.filter(n=>n.tool===e&&n.callId!==t).map(e=>e.callId);return r.length>0?r:[e]}):[]}var G=class{value;constructor(e){this.value=e}};function ye(e){return new G(e)}function be(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return ye(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(v(`tool.page_timed_out`,{},i)):Error(v(`tool.page_no_answer`,{tool:e},i))}}var K=new WeakMap;function q(e,t){let n=K.get(e);n||(n=new WeakMap,K.set(e,n));let r=n.get(t);if(!r){let i=b(e,`input`);y(i,`input`);let a=b(t,`output`);y(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function J(e){let{inputSchema:t,outputSchema:n}=q(e.input,e.output),r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?re(n,r[t]):void 0;if(i)throw new _(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function xe(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new _(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function Y(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new _(`config`,`Tool "${e}" auth.queryParam ${r}`)}function Se(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new _(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function X(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new _(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Z(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new _(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Ce(e){Z(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Z(e.name,`imageLimits.count`,t.count),Z(e.name,`imageLimits.bytes`,t.bytes),Z(e.name,`imageLimits.totalBytes`,t.totalBytes),X(e.name,t.timeoutMs))}function Q(e){if(e.type!==`builtin`&&z({name:e.name,...e.background===void 0?{}:{background:e.background},...e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.type===`builtin`||e.type===`agent`)return;xe(e.name,e.auth),e.type===`http`?(e.endpoint?.trim()&&x(e.endpoint),Y(e.name,e.auth,e.mapping?.queryParams),Se(e.name,e.limit),X(e.name,e.timeoutMs)):Y(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Ce(e),e.type===`mcp`&&(Z(e.name,`session.idleMs`,e.session?.idleMs),Z(e.name,`session.max`,e.session?.max));let[t]=ce(e);if(t)throw new _(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function $(e){return x(e.endpoint),{...e,type:`http`,...J(e)}}function we(e){return{...e,type:`mcp`,...J(e)}}function Te(e){let t=e.answeredBy===`page`?be(e.name):e.handler;if(typeof t!=`function`)throw new _(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...J(e)}}function Ee(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=U(e.name,t,`background`,P);return{...e,askInputSchema:q(n,e.output).inputSchema}}function De(e,t,n){return Q(e),Ee(Oe(e,t,n))}function Oe(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=le(e,t,n),i=ne(r),a=fe({type:r.type,...i?{inputs:i}:{}},e),o=e.after?W(e.name,a):a,s=J({...e,input:o,output:de});return ue(e,o,s)}let r=e.after?{...e,input:W(e.name,e.input)}:e;return r.type===`http`?$(r):r.type===`mcp`?we(r):Te(r)}function ke(e=()=>void 0){let t=new Map,n=V(),r=e=>t.get(e),i=n=>{let i=De(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new _(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}export{A as _,ve as a,he as c,F as d,w as f,T as g,pe as h,_e as i,R as l,j as m,ke as n,V as o,S as p,G as r,me as s,Q as t,L as u,k as v,C as y};