@clappstore/connect 0.7.28 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +212 -9
- package/dist/defaults.js.map +1 -1
- package/dist/index.js +84 -5
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +193 -11
- package/dist/server.js.map +1 -1
- package/dist/settings-handler.d.ts +10 -2
- package/dist/settings-handler.d.ts.map +1 -1
- package/dist/settings-handler.js +126 -57
- package/dist/settings-handler.js.map +1 -1
- package/dist/slack-handler.d.ts +1 -0
- package/dist/slack-handler.d.ts.map +1 -1
- package/dist/slack-handler.js +1 -1
- package/dist/slack-handler.js.map +1 -1
- package/package.json +7 -2
- package/web-app/assets/index-BF3hBHjp.css +1 -0
- package/web-app/assets/{index-CTMPu3bz.js → index-DoakjYY6.js} +1 -1
- package/web-app/index.html +2 -2
- package/web-app/assets/index-Nvc15t2m.css +0 -1
|
@@ -280,4 +280,4 @@ return `+str.trim()+`;
|
|
|
280
280
|
`))+1))}const d="#".repeat(u),m=l.enter("headingAtx"),p=l.enter("phrasing");c.move(d+" ");let g=l.containerPhrasing(t,{before:"# ",after:`
|
|
281
281
|
`,...c.current()});return/^[\t ]/.test(g)&&(g=encodeCharacterReference(g.charCodeAt(0))+g.slice(1)),g=g?d+" "+g:d,l.options.closeAtx&&(g+=" "+d),p(),m(),g}html.peek=htmlPeek;function html(t){return t.value||""}function htmlPeek(){return"<"}image.peek=imagePeek;function image(t,a,l,o){const u=checkQuote(l),c=u==='"'?"Quote":"Apostrophe",d=l.enter("image");let m=l.enter("label");const p=l.createTracker(o);let g=p.move("![");return g+=p.move(l.safe(t.alt,{before:g,after:"]",...p.current()})),g+=p.move("]("),m(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(m=l.enter("destinationLiteral"),g+=p.move("<"),g+=p.move(l.safe(t.url,{before:g,after:">",...p.current()})),g+=p.move(">")):(m=l.enter("destinationRaw"),g+=p.move(l.safe(t.url,{before:g,after:t.title?" ":")",...p.current()}))),m(),t.title&&(m=l.enter(`title${c}`),g+=p.move(" "+u),g+=p.move(l.safe(t.title,{before:g,after:u,...p.current()})),g+=p.move(u),m()),g+=p.move(")"),d(),g}function imagePeek(){return"!"}imageReference.peek=imageReferencePeek;function imageReference(t,a,l,o){const u=t.referenceType,c=l.enter("imageReference");let d=l.enter("label");const m=l.createTracker(o);let p=m.move("![");const g=l.safe(t.alt,{before:p,after:"]",...m.current()});p+=m.move(g+"]["),d();const x=l.stack;l.stack=[],d=l.enter("reference");const b=l.safe(l.associationId(t),{before:p,after:"]",...m.current()});return d(),l.stack=x,c(),u==="full"||!g||g!==b?p+=m.move(b+"]"):u==="shortcut"?p=p.slice(0,-1):p+=m.move("]"),p}function imageReferencePeek(){return"!"}inlineCode.peek=inlineCodePeek;function inlineCode(t,a,l){let o=t.value||"",u="`",c=-1;for(;new RegExp("(^|[^`])"+u+"([^`]|$)").test(o);)u+="`";for(/[^ \r\n]/.test(o)&&(/^[ \r\n]/.test(o)&&/[ \r\n]$/.test(o)||/^`|`$/.test(o))&&(o=" "+o+" ");++c<l.unsafe.length;){const d=l.unsafe[c],m=l.compilePattern(d);let p;if(d.atBreak)for(;p=m.exec(o);){let g=p.index;o.charCodeAt(g)===10&&o.charCodeAt(g-1)===13&&g--,o=o.slice(0,g)+" "+o.slice(p.index+1)}}return u+o+u}function inlineCodePeek(){return"`"}function formatLinkAsAutolink(t,a){const l=toString$1(t);return!!(!a.options.resourceLink&&t.url&&!t.title&&t.children&&t.children.length===1&&t.children[0].type==="text"&&(l===t.url||"mailto:"+l===t.url)&&/^[a-z][a-z+.-]+:/i.test(t.url)&&!/[\0- <>\u007F]/.test(t.url))}link.peek=linkPeek;function link(t,a,l,o){const u=checkQuote(l),c=u==='"'?"Quote":"Apostrophe",d=l.createTracker(o);let m,p;if(formatLinkAsAutolink(t,l)){const x=l.stack;l.stack=[],m=l.enter("autolink");let b=d.move("<");return b+=d.move(l.containerPhrasing(t,{before:b,after:">",...d.current()})),b+=d.move(">"),m(),l.stack=x,b}m=l.enter("link"),p=l.enter("label");let g=d.move("[");return g+=d.move(l.containerPhrasing(t,{before:g,after:"](",...d.current()})),g+=d.move("]("),p(),!t.url&&t.title||/[\0- \u007F]/.test(t.url)?(p=l.enter("destinationLiteral"),g+=d.move("<"),g+=d.move(l.safe(t.url,{before:g,after:">",...d.current()})),g+=d.move(">")):(p=l.enter("destinationRaw"),g+=d.move(l.safe(t.url,{before:g,after:t.title?" ":")",...d.current()}))),p(),t.title&&(p=l.enter(`title${c}`),g+=d.move(" "+u),g+=d.move(l.safe(t.title,{before:g,after:u,...d.current()})),g+=d.move(u),p()),g+=d.move(")"),m(),g}function linkPeek(t,a,l){return formatLinkAsAutolink(t,l)?"<":"["}linkReference.peek=linkReferencePeek;function linkReference(t,a,l,o){const u=t.referenceType,c=l.enter("linkReference");let d=l.enter("label");const m=l.createTracker(o);let p=m.move("[");const g=l.containerPhrasing(t,{before:p,after:"]",...m.current()});p+=m.move(g+"]["),d();const x=l.stack;l.stack=[],d=l.enter("reference");const b=l.safe(l.associationId(t),{before:p,after:"]",...m.current()});return d(),l.stack=x,c(),u==="full"||!g||g!==b?p+=m.move(b+"]"):u==="shortcut"?p=p.slice(0,-1):p+=m.move("]"),p}function linkReferencePeek(){return"["}function checkBullet(t){const a=t.options.bullet||"*";if(a!=="*"&&a!=="+"&&a!=="-")throw new Error("Cannot serialize items with `"+a+"` for `options.bullet`, expected `*`, `+`, or `-`");return a}function checkBulletOther(t){const a=checkBullet(t),l=t.options.bulletOther;if(!l)return a==="*"?"-":"*";if(l!=="*"&&l!=="+"&&l!=="-")throw new Error("Cannot serialize items with `"+l+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(l===a)throw new Error("Expected `bullet` (`"+a+"`) and `bulletOther` (`"+l+"`) to be different");return l}function checkBulletOrdered(t){const a=t.options.bulletOrdered||".";if(a!=="."&&a!==")")throw new Error("Cannot serialize items with `"+a+"` for `options.bulletOrdered`, expected `.` or `)`");return a}function checkRule(t){const a=t.options.rule||"*";if(a!=="*"&&a!=="-"&&a!=="_")throw new Error("Cannot serialize rules with `"+a+"` for `options.rule`, expected `*`, `-`, or `_`");return a}function list(t,a,l,o){const u=l.enter("list"),c=l.bulletCurrent;let d=t.ordered?checkBulletOrdered(l):checkBullet(l);const m=t.ordered?d==="."?")":".":checkBulletOther(l);let p=a&&l.bulletLastUsed?d===l.bulletLastUsed:!1;if(!t.ordered){const x=t.children?t.children[0]:void 0;if((d==="*"||d==="-")&&x&&(!x.children||!x.children[0])&&l.stack[l.stack.length-1]==="list"&&l.stack[l.stack.length-2]==="listItem"&&l.stack[l.stack.length-3]==="list"&&l.stack[l.stack.length-4]==="listItem"&&l.indexStack[l.indexStack.length-1]===0&&l.indexStack[l.indexStack.length-2]===0&&l.indexStack[l.indexStack.length-3]===0&&(p=!0),checkRule(l)===d&&x){let b=-1;for(;++b<t.children.length;){const C=t.children[b];if(C&&C.type==="listItem"&&C.children&&C.children[0]&&C.children[0].type==="thematicBreak"){p=!0;break}}}}p&&(d=m),l.bulletCurrent=d;const g=l.containerFlow(t,o);return l.bulletLastUsed=d,l.bulletCurrent=c,u(),g}function checkListItemIndent(t){const a=t.options.listItemIndent||"one";if(a!=="tab"&&a!=="one"&&a!=="mixed")throw new Error("Cannot serialize items with `"+a+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return a}function listItem(t,a,l,o){const u=checkListItemIndent(l);let c=l.bulletCurrent||checkBullet(l);a&&a.type==="list"&&a.ordered&&(c=(typeof a.start=="number"&&a.start>-1?a.start:1)+(l.options.incrementListMarker===!1?0:a.children.indexOf(t))+c);let d=c.length+1;(u==="tab"||u==="mixed"&&(a&&a.type==="list"&&a.spread||t.spread))&&(d=Math.ceil(d/4)*4);const m=l.createTracker(o);m.move(c+" ".repeat(d-c.length)),m.shift(d);const p=l.enter("listItem"),g=l.indentLines(l.containerFlow(t,m.current()),x);return p(),g;function x(b,C,R){return C?(R?"":" ".repeat(d))+b:(R?c:c+" ".repeat(d-c.length))+b}}function paragraph(t,a,l,o){const u=l.enter("paragraph"),c=l.enter("phrasing"),d=l.containerPhrasing(t,o);return c(),u(),d}const phrasing=convert(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function root(t,a,l,o){return(t.children.some(function(d){return phrasing(d)})?l.containerPhrasing:l.containerFlow).call(l,t,o)}function checkStrong(t){const a=t.options.strong||"*";if(a!=="*"&&a!=="_")throw new Error("Cannot serialize strong with `"+a+"` for `options.strong`, expected `*`, or `_`");return a}strong.peek=strongPeek;function strong(t,a,l,o){const u=checkStrong(l),c=l.enter("strong"),d=l.createTracker(o),m=d.move(u+u);let p=d.move(l.containerPhrasing(t,{after:u,before:m,...d.current()}));const g=p.charCodeAt(0),x=encodeInfo(o.before.charCodeAt(o.before.length-1),g,u);x.inside&&(p=encodeCharacterReference(g)+p.slice(1));const b=p.charCodeAt(p.length-1),C=encodeInfo(o.after.charCodeAt(0),b,u);C.inside&&(p=p.slice(0,-1)+encodeCharacterReference(b));const R=d.move(u+u);return c(),l.attentionEncodeSurroundingInfo={after:C.outside,before:x.outside},m+p+R}function strongPeek(t,a,l){return l.options.strong||"*"}function text$1(t,a,l,o){return l.safe(t.value,o)}function checkRuleRepetition(t){const a=t.options.ruleRepetition||3;if(a<3)throw new Error("Cannot serialize rules with repetition `"+a+"` for `options.ruleRepetition`, expected `3` or more");return a}function thematicBreak(t,a,l){const o=(checkRule(l)+(l.options.ruleSpaces?" ":"")).repeat(checkRuleRepetition(l));return l.options.ruleSpaces?o.slice(0,-1):o}const handle={blockquote,break:hardBreak,code:code$1,definition,emphasis,hardBreak,heading,html,image,imageReference,inlineCode,link,linkReference,list,listItem,paragraph,root,strong,text:text$1,thematicBreak};function gfmTableFromMarkdown(){return{enter:{table:enterTable,tableData:enterCell,tableHeader:enterCell,tableRow:enterRow},exit:{codeText:exitCodeText,table:exitTable,tableData:exit,tableHeader:exit,tableRow:exit}}}function enterTable(t){const a=t._align;this.enter({type:"table",align:a.map(function(l){return l==="none"?null:l}),children:[]},t),this.data.inTable=!0}function exitTable(t){this.exit(t),this.data.inTable=void 0}function enterRow(t){this.enter({type:"tableRow",children:[]},t)}function exit(t){this.exit(t)}function enterCell(t){this.enter({type:"tableCell",children:[]},t)}function exitCodeText(t){let a=this.resume();this.data.inTable&&(a=a.replace(/\\([\\|])/g,replace));const l=this.stack[this.stack.length-1];l.type,l.value=a,this.exit(t)}function replace(t,a){return a==="|"?a:t}function gfmTableToMarkdown(t){const a=t||{},l=a.tableCellPadding,o=a.tablePipeAlign,u=a.stringLength,c=l?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
282
282
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:C,table:d,tableCell:p,tableRow:m}};function d(R,j,B,L){return g(x(R,B,L),R.align)}function m(R,j,B,L){const D=b(R,B,L),$=g([D]);return $.slice(0,$.indexOf(`
|
|
283
|
-
`))}function p(R,j,B,L){const D=B.enter("tableCell"),$=B.enter("phrasing"),F=B.containerPhrasing(R,{...L,before:c,after:c});return $(),D(),F}function g(R,j){return markdownTable(R,{align:j,alignDelimiters:o,padding:l,stringLength:u})}function x(R,j,B){const L=R.children;let D=-1;const $=[],F=j.enter("table");for(;++D<L.length;)$[D]=b(L[D],j,B);return F(),$}function b(R,j,B){const L=R.children;let D=-1;const $=[],F=j.enter("tableRow");for(;++D<L.length;)$[D]=p(L[D],R,j,B);return F(),$}function C(R,j,B){let L=handle.inlineCode(R,j,B);return B.stack.includes("tableCell")&&(L=L.replace(/\|/g,"\\$&")),L}}function gfmTaskListItemFromMarkdown(){return{exit:{taskListCheckValueChecked:exitCheck,taskListCheckValueUnchecked:exitCheck,paragraph:exitParagraphWithTaskListItem}}}function gfmTaskListItemToMarkdown(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:listItemWithTaskListItem}}}function exitCheck(t){const a=this.stack[this.stack.length-2];a.type,a.checked=t.type==="taskListCheckValueChecked"}function exitParagraphWithTaskListItem(t){const a=this.stack[this.stack.length-2];if(a&&a.type==="listItem"&&typeof a.checked=="boolean"){const l=this.stack[this.stack.length-1];l.type;const o=l.children[0];if(o&&o.type==="text"){const u=a.children;let c=-1,d;for(;++c<u.length;){const m=u[c];if(m.type==="paragraph"){d=m;break}}d===l&&(o.value=o.value.slice(1),o.value.length===0?l.children.shift():l.position&&o.position&&typeof o.position.start.offset=="number"&&(o.position.start.column++,o.position.start.offset++,l.position.start=Object.assign({},o.position.start)))}}this.exit(t)}function listItemWithTaskListItem(t,a,l,o){const u=t.children[0],c=typeof t.checked=="boolean"&&u&&u.type==="paragraph",d="["+(t.checked?"x":" ")+"] ",m=l.createTracker(o);c&&m.move(d);let p=handle.listItem(t,a,l,{...o,...m.current()});return c&&(p=p.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,g)),p;function g(x){return x+d}}function gfmFromMarkdown(){return[gfmAutolinkLiteralFromMarkdown(),gfmFootnoteFromMarkdown(),gfmStrikethroughFromMarkdown(),gfmTableFromMarkdown(),gfmTaskListItemFromMarkdown()]}function gfmToMarkdown(t){return{extensions:[gfmAutolinkLiteralToMarkdown(),gfmFootnoteToMarkdown(t),gfmStrikethroughToMarkdown(),gfmTableToMarkdown(t),gfmTaskListItemToMarkdown()]}}const wwwPrefix={tokenize:tokenizeWwwPrefix,partial:!0},domain={tokenize:tokenizeDomain,partial:!0},path={tokenize:tokenizePath,partial:!0},trail={tokenize:tokenizeTrail,partial:!0},emailDomainDotTrail={tokenize:tokenizeEmailDomainDotTrail,partial:!0},wwwAutolink={name:"wwwAutolink",tokenize:tokenizeWwwAutolink,previous:previousWww},protocolAutolink={name:"protocolAutolink",tokenize:tokenizeProtocolAutolink,previous:previousProtocol},emailAutolink={name:"emailAutolink",tokenize:tokenizeEmailAutolink,previous:previousEmail},text={};function gfmAutolinkLiteral(){return{text}}let code=48;for(;code<123;)text[code]=emailAutolink,code++,code===58?code=65:code===91&&(code=97);text[43]=emailAutolink;text[45]=emailAutolink;text[46]=emailAutolink;text[95]=emailAutolink;text[72]=[emailAutolink,protocolAutolink];text[104]=[emailAutolink,protocolAutolink];text[87]=[emailAutolink,wwwAutolink];text[119]=[emailAutolink,wwwAutolink];function tokenizeEmailAutolink(t,a,l){const o=this;let u,c;return d;function d(b){return!gfmAtext(b)||!previousEmail.call(o,o.previous)||previousUnbalanced(o.events)?l(b):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),m(b))}function m(b){return gfmAtext(b)?(t.consume(b),m):b===64?(t.consume(b),p):l(b)}function p(b){return b===46?t.check(emailDomainDotTrail,x,g)(b):b===45||b===95||asciiAlphanumeric(b)?(c=!0,t.consume(b),p):x(b)}function g(b){return t.consume(b),u=!0,p}function x(b){return c&&u&&asciiAlpha(o.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),a(b)):l(b)}}function tokenizeWwwAutolink(t,a,l){const o=this;return u;function u(d){return d!==87&&d!==119||!previousWww.call(o,o.previous)||previousUnbalanced(o.events)?l(d):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(wwwPrefix,t.attempt(domain,t.attempt(path,c),l),l)(d))}function c(d){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),a(d)}}function tokenizeProtocolAutolink(t,a,l){const o=this;let u="",c=!1;return d;function d(b){return(b===72||b===104)&&previousProtocol.call(o,o.previous)&&!previousUnbalanced(o.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),u+=String.fromCodePoint(b),t.consume(b),m):l(b)}function m(b){if(asciiAlpha(b)&&u.length<5)return u+=String.fromCodePoint(b),t.consume(b),m;if(b===58){const C=u.toLowerCase();if(C==="http"||C==="https")return t.consume(b),p}return l(b)}function p(b){return b===47?(t.consume(b),c?g:(c=!0,p)):l(b)}function g(b){return b===null||asciiControl(b)||markdownLineEndingOrSpace(b)||unicodeWhitespace(b)||unicodePunctuation(b)?l(b):t.attempt(domain,t.attempt(path,x),l)(b)}function x(b){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),a(b)}}function tokenizeWwwPrefix(t,a,l){let o=0;return u;function u(d){return(d===87||d===119)&&o<3?(o++,t.consume(d),u):d===46&&o===3?(t.consume(d),c):l(d)}function c(d){return d===null?l(d):a(d)}}function tokenizeDomain(t,a,l){let o,u,c;return d;function d(g){return g===46||g===95?t.check(trail,p,m)(g):g===null||markdownLineEndingOrSpace(g)||unicodeWhitespace(g)||g!==45&&unicodePunctuation(g)?p(g):(c=!0,t.consume(g),d)}function m(g){return g===95?o=!0:(u=o,o=void 0),t.consume(g),d}function p(g){return u||o||!c?l(g):a(g)}}function tokenizePath(t,a){let l=0,o=0;return u;function u(d){return d===40?(l++,t.consume(d),u):d===41&&o<l?c(d):d===33||d===34||d===38||d===39||d===41||d===42||d===44||d===46||d===58||d===59||d===60||d===63||d===93||d===95||d===126?t.check(trail,a,c)(d):d===null||markdownLineEndingOrSpace(d)||unicodeWhitespace(d)?a(d):(t.consume(d),u)}function c(d){return d===41&&o++,t.consume(d),u}}function tokenizeTrail(t,a,l){return o;function o(m){return m===33||m===34||m===39||m===41||m===42||m===44||m===46||m===58||m===59||m===63||m===95||m===126?(t.consume(m),o):m===38?(t.consume(m),c):m===93?(t.consume(m),u):m===60||m===null||markdownLineEndingOrSpace(m)||unicodeWhitespace(m)?a(m):l(m)}function u(m){return m===null||m===40||m===91||markdownLineEndingOrSpace(m)||unicodeWhitespace(m)?a(m):o(m)}function c(m){return asciiAlpha(m)?d(m):l(m)}function d(m){return m===59?(t.consume(m),o):asciiAlpha(m)?(t.consume(m),d):l(m)}}function tokenizeEmailDomainDotTrail(t,a,l){return o;function o(c){return t.consume(c),u}function u(c){return asciiAlphanumeric(c)?l(c):a(c)}}function previousWww(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||markdownLineEndingOrSpace(t)}function previousProtocol(t){return!asciiAlpha(t)}function previousEmail(t){return!(t===47||gfmAtext(t))}function gfmAtext(t){return t===43||t===45||t===46||t===95||asciiAlphanumeric(t)}function previousUnbalanced(t){let a=t.length,l=!1;for(;a--;){const o=t[a][1];if((o.type==="labelLink"||o.type==="labelImage")&&!o._balanced){l=!0;break}if(o._gfmAutolinkLiteralWalkedInto){l=!1;break}}return t.length>0&&!l&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),l}const indent={tokenize:tokenizeIndent,partial:!0};function gfmFootnote(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:tokenizeDefinitionStart,continuation:{tokenize:tokenizeDefinitionContinuation},exit:gfmFootnoteDefinitionEnd}},text:{91:{name:"gfmFootnoteCall",tokenize:tokenizeGfmFootnoteCall},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:tokenizePotentialGfmFootnoteCall,resolveTo:resolveToPotentialGfmFootnoteCall}}}}function tokenizePotentialGfmFootnoteCall(t,a,l){const o=this;let u=o.events.length;const c=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let d;for(;u--;){const p=o.events[u][1];if(p.type==="labelImage"){d=p;break}if(p.type==="gfmFootnoteCall"||p.type==="labelLink"||p.type==="label"||p.type==="image"||p.type==="link")break}return m;function m(p){if(!d||!d._balanced)return l(p);const g=normalizeIdentifier(o.sliceSerialize({start:d.end,end:o.now()}));return g.codePointAt(0)!==94||!c.includes(g.slice(1))?l(p):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(p),t.exit("gfmFootnoteCallLabelMarker"),a(p))}}function resolveToPotentialGfmFootnoteCall(t,a){let l=t.length;for(;l--;)if(t[l][1].type==="labelImage"&&t[l][0]==="enter"){t[l][1];break}t[l+1][1].type="data",t[l+3][1].type="gfmFootnoteCallLabelMarker";const o={type:"gfmFootnoteCall",start:Object.assign({},t[l+3][1].start),end:Object.assign({},t[t.length-1][1].end)},u={type:"gfmFootnoteCallMarker",start:Object.assign({},t[l+3][1].end),end:Object.assign({},t[l+3][1].end)};u.end.column++,u.end.offset++,u.end._bufferIndex++;const c={type:"gfmFootnoteCallString",start:Object.assign({},u.end),end:Object.assign({},t[t.length-1][1].start)},d={type:"chunkString",contentType:"string",start:Object.assign({},c.start),end:Object.assign({},c.end)},m=[t[l+1],t[l+2],["enter",o,a],t[l+3],t[l+4],["enter",u,a],["exit",u,a],["enter",c,a],["enter",d,a],["exit",d,a],["exit",c,a],t[t.length-2],t[t.length-1],["exit",o,a]];return t.splice(l,t.length-l+1,...m),t}function tokenizeGfmFootnoteCall(t,a,l){const o=this,u=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let c=0,d;return m;function m(b){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(b),t.exit("gfmFootnoteCallLabelMarker"),p}function p(b){return b!==94?l(b):(t.enter("gfmFootnoteCallMarker"),t.consume(b),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",g)}function g(b){if(c>999||b===93&&!d||b===null||b===91||markdownLineEndingOrSpace(b))return l(b);if(b===93){t.exit("chunkString");const C=t.exit("gfmFootnoteCallString");return u.includes(normalizeIdentifier(o.sliceSerialize(C)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(b),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),a):l(b)}return markdownLineEndingOrSpace(b)||(d=!0),c++,t.consume(b),b===92?x:g}function x(b){return b===91||b===92||b===93?(t.consume(b),c++,g):g(b)}}function tokenizeDefinitionStart(t,a,l){const o=this,u=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let c,d=0,m;return p;function p(j){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(j),t.exit("gfmFootnoteDefinitionLabelMarker"),g}function g(j){return j===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(j),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",x):l(j)}function x(j){if(d>999||j===93&&!m||j===null||j===91||markdownLineEndingOrSpace(j))return l(j);if(j===93){t.exit("chunkString");const B=t.exit("gfmFootnoteDefinitionLabelString");return c=normalizeIdentifier(o.sliceSerialize(B)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(j),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),C}return markdownLineEndingOrSpace(j)||(m=!0),d++,t.consume(j),j===92?b:x}function b(j){return j===91||j===92||j===93?(t.consume(j),d++,x):x(j)}function C(j){return j===58?(t.enter("definitionMarker"),t.consume(j),t.exit("definitionMarker"),u.includes(c)||u.push(c),factorySpace(t,R,"gfmFootnoteDefinitionWhitespace")):l(j)}function R(j){return a(j)}}function tokenizeDefinitionContinuation(t,a,l){return t.check(blankLine,a,t.attempt(indent,a,l))}function gfmFootnoteDefinitionEnd(t){t.exit("gfmFootnoteDefinition")}function tokenizeIndent(t,a,l){const o=this;return factorySpace(t,u,"gfmFootnoteDefinitionIndent",5);function u(c){const d=o.events[o.events.length-1];return d&&d[1].type==="gfmFootnoteDefinitionIndent"&&d[2].sliceSerialize(d[1],!0).length===4?a(c):l(c)}}function gfmStrikethrough(t){let l=(t||{}).singleTilde;const o={name:"strikethrough",tokenize:c,resolveAll:u};return l==null&&(l=!0),{text:{126:o},insideSpan:{null:[o]},attentionMarkers:{null:[126]}};function u(d,m){let p=-1;for(;++p<d.length;)if(d[p][0]==="enter"&&d[p][1].type==="strikethroughSequenceTemporary"&&d[p][1]._close){let g=p;for(;g--;)if(d[g][0]==="exit"&&d[g][1].type==="strikethroughSequenceTemporary"&&d[g][1]._open&&d[p][1].end.offset-d[p][1].start.offset===d[g][1].end.offset-d[g][1].start.offset){d[p][1].type="strikethroughSequence",d[g][1].type="strikethroughSequence";const x={type:"strikethrough",start:Object.assign({},d[g][1].start),end:Object.assign({},d[p][1].end)},b={type:"strikethroughText",start:Object.assign({},d[g][1].end),end:Object.assign({},d[p][1].start)},C=[["enter",x,m],["enter",d[g][1],m],["exit",d[g][1],m],["enter",b,m]],R=m.parser.constructs.insideSpan.null;R&&splice(C,C.length,0,resolveAll(R,d.slice(g+1,p),m)),splice(C,C.length,0,[["exit",b,m],["enter",d[p][1],m],["exit",d[p][1],m],["exit",x,m]]),splice(d,g-1,p-g+3,C),p=g+C.length-2;break}}for(p=-1;++p<d.length;)d[p][1].type==="strikethroughSequenceTemporary"&&(d[p][1].type="data");return d}function c(d,m,p){const g=this.previous,x=this.events;let b=0;return C;function C(j){return g===126&&x[x.length-1][1].type!=="characterEscape"?p(j):(d.enter("strikethroughSequenceTemporary"),R(j))}function R(j){const B=classifyCharacter(g);if(j===126)return b>1?p(j):(d.consume(j),b++,R);if(b<2&&!l)return p(j);const L=d.exit("strikethroughSequenceTemporary"),D=classifyCharacter(j);return L._open=!D||D===2&&!!B,L._close=!B||B===2&&!!D,m(j)}}}class EditMap{constructor(){this.map=[]}add(a,l,o){addImplementation(this,a,l,o)}consume(a){if(this.map.sort(function(c,d){return c[0]-d[0]}),this.map.length===0)return;let l=this.map.length;const o=[];for(;l>0;)l-=1,o.push(a.slice(this.map[l][0]+this.map[l][1]),this.map[l][2]),a.length=this.map[l][0];o.push(a.slice()),a.length=0;let u=o.pop();for(;u;){for(const c of u)a.push(c);u=o.pop()}this.map.length=0}}function addImplementation(t,a,l,o){let u=0;if(!(l===0&&o.length===0)){for(;u<t.map.length;){if(t.map[u][0]===a){t.map[u][1]+=l,t.map[u][2].push(...o);return}u+=1}t.map.push([a,l,o])}}function gfmTableAlign(t,a){let l=!1;const o=[];for(;a<t.length;){const u=t[a];if(l){if(u[0]==="enter")u[1].type==="tableContent"&&o.push(t[a+1][1].type==="tableDelimiterMarker"?"left":"none");else if(u[1].type==="tableContent"){if(t[a-1][1].type==="tableDelimiterMarker"){const c=o.length-1;o[c]=o[c]==="left"?"center":"right"}}else if(u[1].type==="tableDelimiterRow")break}else u[0]==="enter"&&u[1].type==="tableDelimiterRow"&&(l=!0);a+=1}return o}function gfmTable(){return{flow:{null:{name:"table",tokenize:tokenizeTable,resolveAll:resolveTable}}}}function tokenizeTable(t,a,l){const o=this;let u=0,c=0,d;return m;function m(G){let Ee=o.events.length-1;for(;Ee>-1;){const ye=o.events[Ee][1].type;if(ye==="lineEnding"||ye==="linePrefix")Ee--;else break}const be=Ee>-1?o.events[Ee][1].type:null,_e=be==="tableHead"||be==="tableRow"?H:p;return _e===H&&o.parser.lazy[o.now().line]?l(G):_e(G)}function p(G){return t.enter("tableHead"),t.enter("tableRow"),g(G)}function g(G){return G===124||(d=!0,c+=1),x(G)}function x(G){return G===null?l(G):markdownLineEnding(G)?c>1?(c=0,o.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(G),t.exit("lineEnding"),R):l(G):markdownSpace(G)?factorySpace(t,x,"whitespace")(G):(c+=1,d&&(d=!1,u+=1),G===124?(t.enter("tableCellDivider"),t.consume(G),t.exit("tableCellDivider"),d=!0,x):(t.enter("data"),b(G)))}function b(G){return G===null||G===124||markdownLineEndingOrSpace(G)?(t.exit("data"),x(G)):(t.consume(G),G===92?C:b)}function C(G){return G===92||G===124?(t.consume(G),b):b(G)}function R(G){return o.interrupt=!1,o.parser.lazy[o.now().line]?l(G):(t.enter("tableDelimiterRow"),d=!1,markdownSpace(G)?factorySpace(t,j,"linePrefix",o.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(G):j(G))}function j(G){return G===45||G===58?L(G):G===124?(d=!0,t.enter("tableCellDivider"),t.consume(G),t.exit("tableCellDivider"),B):ie(G)}function B(G){return markdownSpace(G)?factorySpace(t,L,"whitespace")(G):L(G)}function L(G){return G===58?(c+=1,d=!0,t.enter("tableDelimiterMarker"),t.consume(G),t.exit("tableDelimiterMarker"),D):G===45?(c+=1,D(G)):G===null||markdownLineEnding(G)?oe(G):ie(G)}function D(G){return G===45?(t.enter("tableDelimiterFiller"),$(G)):ie(G)}function $(G){return G===45?(t.consume(G),$):G===58?(d=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(G),t.exit("tableDelimiterMarker"),F):(t.exit("tableDelimiterFiller"),F(G))}function F(G){return markdownSpace(G)?factorySpace(t,oe,"whitespace")(G):oe(G)}function oe(G){return G===124?j(G):G===null||markdownLineEnding(G)?!d||u!==c?ie(G):(t.exit("tableDelimiterRow"),t.exit("tableHead"),a(G)):ie(G)}function ie(G){return l(G)}function H(G){return t.enter("tableRow"),xe(G)}function xe(G){return G===124?(t.enter("tableCellDivider"),t.consume(G),t.exit("tableCellDivider"),xe):G===null||markdownLineEnding(G)?(t.exit("tableRow"),a(G)):markdownSpace(G)?factorySpace(t,xe,"whitespace")(G):(t.enter("data"),W(G))}function W(G){return G===null||G===124||markdownLineEndingOrSpace(G)?(t.exit("data"),xe(G)):(t.consume(G),G===92?ve:W)}function ve(G){return G===92||G===124?(t.consume(G),W):W(G)}}function resolveTable(t,a){let l=-1,o=!0,u=0,c=[0,0,0,0],d=[0,0,0,0],m=!1,p=0,g,x,b;const C=new EditMap;for(;++l<t.length;){const R=t[l],j=R[1];R[0]==="enter"?j.type==="tableHead"?(m=!1,p!==0&&(flushTableEnd(C,a,p,g,x),x=void 0,p=0),g={type:"table",start:Object.assign({},j.start),end:Object.assign({},j.end)},C.add(l,0,[["enter",g,a]])):j.type==="tableRow"||j.type==="tableDelimiterRow"?(o=!0,b=void 0,c=[0,0,0,0],d=[0,l+1,0,0],m&&(m=!1,x={type:"tableBody",start:Object.assign({},j.start),end:Object.assign({},j.end)},C.add(l,0,[["enter",x,a]])),u=j.type==="tableDelimiterRow"?2:x?3:1):u&&(j.type==="data"||j.type==="tableDelimiterMarker"||j.type==="tableDelimiterFiller")?(o=!1,d[2]===0&&(c[1]!==0&&(d[0]=d[1],b=flushCell(C,a,c,u,void 0,b),c=[0,0,0,0]),d[2]=l)):j.type==="tableCellDivider"&&(o?o=!1:(c[1]!==0&&(d[0]=d[1],b=flushCell(C,a,c,u,void 0,b)),c=d,d=[c[1],l,0,0])):j.type==="tableHead"?(m=!0,p=l):j.type==="tableRow"||j.type==="tableDelimiterRow"?(p=l,c[1]!==0?(d[0]=d[1],b=flushCell(C,a,c,u,l,b)):d[1]!==0&&(b=flushCell(C,a,d,u,l,b)),u=0):u&&(j.type==="data"||j.type==="tableDelimiterMarker"||j.type==="tableDelimiterFiller")&&(d[3]=l)}for(p!==0&&flushTableEnd(C,a,p,g,x),C.consume(a.events),l=-1;++l<a.events.length;){const R=a.events[l];R[0]==="enter"&&R[1].type==="table"&&(R[1]._align=gfmTableAlign(a.events,l))}return t}function flushCell(t,a,l,o,u,c){const d=o===1?"tableHeader":o===2?"tableDelimiter":"tableData",m="tableContent";l[0]!==0&&(c.end=Object.assign({},getPoint(a.events,l[0])),t.add(l[0],0,[["exit",c,a]]));const p=getPoint(a.events,l[1]);if(c={type:d,start:Object.assign({},p),end:Object.assign({},p)},t.add(l[1],0,[["enter",c,a]]),l[2]!==0){const g=getPoint(a.events,l[2]),x=getPoint(a.events,l[3]),b={type:m,start:Object.assign({},g),end:Object.assign({},x)};if(t.add(l[2],0,[["enter",b,a]]),o!==2){const C=a.events[l[2]],R=a.events[l[3]];if(C[1].end=Object.assign({},R[1].end),C[1].type="chunkText",C[1].contentType="text",l[3]>l[2]+1){const j=l[2]+1,B=l[3]-l[2]-1;t.add(j,B,[])}}t.add(l[3]+1,0,[["exit",b,a]])}return u!==void 0&&(c.end=Object.assign({},getPoint(a.events,u)),t.add(u,0,[["exit",c,a]]),c=void 0),c}function flushTableEnd(t,a,l,o,u){const c=[],d=getPoint(a.events,l);u&&(u.end=Object.assign({},d),c.push(["exit",u,a])),o.end=Object.assign({},d),c.push(["exit",o,a]),t.add(l+1,0,c)}function getPoint(t,a){const l=t[a],o=l[0]==="enter"?"start":"end";return l[1][o]}const tasklistCheck={name:"tasklistCheck",tokenize:tokenizeTasklistCheck};function gfmTaskListItem(){return{text:{91:tasklistCheck}}}function tokenizeTasklistCheck(t,a,l){const o=this;return u;function u(p){return o.previous!==null||!o._gfmTasklistFirstContentOfListItem?l(p):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(p),t.exit("taskListCheckMarker"),c)}function c(p){return markdownLineEndingOrSpace(p)?(t.enter("taskListCheckValueUnchecked"),t.consume(p),t.exit("taskListCheckValueUnchecked"),d):p===88||p===120?(t.enter("taskListCheckValueChecked"),t.consume(p),t.exit("taskListCheckValueChecked"),d):l(p)}function d(p){return p===93?(t.enter("taskListCheckMarker"),t.consume(p),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),m):l(p)}function m(p){return markdownLineEnding(p)?a(p):markdownSpace(p)?t.check({tokenize:spaceThenNonSpace},a,l)(p):l(p)}}function spaceThenNonSpace(t,a,l){return factorySpace(t,o,"whitespace");function o(u){return u===null?l(u):a(u)}}function gfm(t){return combineExtensions([gfmAutolinkLiteral(),gfmFootnote(),gfmStrikethrough(t),gfmTable(),gfmTaskListItem()])}const emptyOptions={};function remarkGfm(t){const a=this,l=t||emptyOptions,o=a.data(),u=o.micromarkExtensions||(o.micromarkExtensions=[]),c=o.fromMarkdownExtensions||(o.fromMarkdownExtensions=[]),d=o.toMarkdownExtensions||(o.toMarkdownExtensions=[]);u.push(gfm(l)),c.push(gfmFromMarkdown()),d.push(gfmToMarkdown(l))}function parseViewMd(t){const{data:a,content:l}=matter(t),o=unified().use(remarkParse).use(remarkGfm).parse(l),u=splitByH2$1(o);return{name:a.name??"",domain:a.domain??"",version:a.version??"0.1.0",stateBindings:parseStateBindings(u["State Bindings"]),layout:parseLayoutSection$1(u.Layout),intents:parseIntentsTable(u.Intents)}}function splitByH2$1(t){var o;const a={};let l="__intro__";a[l]=[];for(const u of t.children)u.type==="heading"&&u.depth===2?(l=getTextContent(u),a[l]=[]):(o=a[l])==null||o.push(u);return a}function getTextContent(t){return t.children.map(a=>a.type==="text"?a.value:"").join("")}function parseStateBindings(t){if(!t)return[];const a=[];for(const l of t){if(l.type!=="list")continue;const o=l;for(const u of o.children){const d=extractListItemText(u).match(/`([^`]+)`\s*->\s*(.+)/);d&&a.push({path:d[1],type:d[2].trim()})}}return a}function extractListItemText(t){return t.children.map(a=>a.type==="paragraph"?a.children.map(l=>l.type==="text"?l.value:l.type==="inlineCode"?`\`${l.value}\``:"").join(""):"").join("")}function parseLayoutSection$1(t){if(!t)throw new Error("Missing Layout section in VIEW.md");for(const a of t)if(a.type==="code"){const l=a;if(l.lang==="clapp-layout")return parseLayoutDSL(l.value)}throw new Error("No clapp-layout code block found in Layout section")}function parseIntentsTable(t){if(!t)return[];const a=[];for(const l of t){if(l.type!=="table")continue;const o=l;for(let u=1;u<o.children.length;u++){const d=o.children[u].children;d.length>=3&&a.push({name:getCellText(d[0]),payload:getCellText(d[1]),description:getCellText(d[2])})}}return a}function getCellText(t){return t.children.map(a=>a.type==="text"||a.type==="inlineCode"?a.value:"").join("")}function parseAppMd(t){const{data:a,content:l}=matter(t),o=unified().use(remarkParse).parse(l),u=splitByH2(o);return{name:a.name??"",domain:a.domain??"",modules:parseModulesList(u.Modules),layout:parseLayoutSection(u.Layout)}}function splitByH2(t){var o;const a={};let l="__intro__";a[l]=[];for(const u of t.children)u.type==="heading"&&u.depth===2?(l=u.children.map(d=>d.type==="text"?d.value:"").join(""),a[l]=[]):(o=a[l])==null||o.push(u);return a}function parseModulesList(t){if(!t)return[];const a=[];for(const l of t){if(l.type!=="list")continue;const o=l;for(const u of o.children){const c=u.children.map(d=>d.type==="paragraph"?d.children.map(m=>m.type==="text"?m.value:"").join(""):"").join("").trim();c&&a.push(c)}}return a}function parseLayoutSection(t){if(!t)throw new Error("Missing Layout section in APP.md");for(const a of t)if(a.type==="code"){const l=a;if(l.lang==="clapp-layout")return parseLayoutDSL(l.value)}throw new Error("No clapp-layout code block found in Layout section")}var util;(function(t){t.assertEqual=u=>{};function a(u){}t.assertIs=a;function l(u){throw new Error}t.assertNever=l,t.arrayToEnum=u=>{const c={};for(const d of u)c[d]=d;return c},t.getValidEnumValues=u=>{const c=t.objectKeys(u).filter(m=>typeof u[u[m]]!="number"),d={};for(const m of c)d[m]=u[m];return t.objectValues(d)},t.objectValues=u=>t.objectKeys(u).map(function(c){return u[c]}),t.objectKeys=typeof Object.keys=="function"?u=>Object.keys(u):u=>{const c=[];for(const d in u)Object.prototype.hasOwnProperty.call(u,d)&&c.push(d);return c},t.find=(u,c)=>{for(const d of u)if(c(d))return d},t.isInteger=typeof Number.isInteger=="function"?u=>Number.isInteger(u):u=>typeof u=="number"&&Number.isFinite(u)&&Math.floor(u)===u;function o(u,c=" | "){return u.map(d=>typeof d=="string"?`'${d}'`:d).join(c)}t.joinValues=o,t.jsonStringifyReplacer=(u,c)=>typeof c=="bigint"?c.toString():c})(util||(util={}));var objectUtil;(function(t){t.mergeShapes=(a,l)=>({...a,...l})})(objectUtil||(objectUtil={}));const ZodParsedType=util.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),getParsedType=t=>{switch(typeof t){case"undefined":return ZodParsedType.undefined;case"string":return ZodParsedType.string;case"number":return Number.isNaN(t)?ZodParsedType.nan:ZodParsedType.number;case"boolean":return ZodParsedType.boolean;case"function":return ZodParsedType.function;case"bigint":return ZodParsedType.bigint;case"symbol":return ZodParsedType.symbol;case"object":return Array.isArray(t)?ZodParsedType.array:t===null?ZodParsedType.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?ZodParsedType.promise:typeof Map<"u"&&t instanceof Map?ZodParsedType.map:typeof Set<"u"&&t instanceof Set?ZodParsedType.set:typeof Date<"u"&&t instanceof Date?ZodParsedType.date:ZodParsedType.object;default:return ZodParsedType.unknown}},ZodIssueCode=util.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ZodError extends Error{get errors(){return this.issues}constructor(a){super(),this.issues=[],this.addIssue=o=>{this.issues=[...this.issues,o]},this.addIssues=(o=[])=>{this.issues=[...this.issues,...o]};const l=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,l):this.__proto__=l,this.name="ZodError",this.issues=a}format(a){const l=a||function(c){return c.message},o={_errors:[]},u=c=>{for(const d of c.issues)if(d.code==="invalid_union")d.unionErrors.map(u);else if(d.code==="invalid_return_type")u(d.returnTypeError);else if(d.code==="invalid_arguments")u(d.argumentsError);else if(d.path.length===0)o._errors.push(l(d));else{let m=o,p=0;for(;p<d.path.length;){const g=d.path[p];p===d.path.length-1?(m[g]=m[g]||{_errors:[]},m[g]._errors.push(l(d))):m[g]=m[g]||{_errors:[]},m=m[g],p++}}};return u(this),o}static assert(a){if(!(a instanceof ZodError))throw new Error(`Not a ZodError: ${a}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,util.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(a=l=>l.message){const l={},o=[];for(const u of this.issues)if(u.path.length>0){const c=u.path[0];l[c]=l[c]||[],l[c].push(a(u))}else o.push(a(u));return{formErrors:o,fieldErrors:l}}get formErrors(){return this.flatten()}}ZodError.create=t=>new ZodError(t);const errorMap=(t,a)=>{let l;switch(t.code){case ZodIssueCode.invalid_type:t.received===ZodParsedType.undefined?l="Required":l=`Expected ${t.expected}, received ${t.received}`;break;case ZodIssueCode.invalid_literal:l=`Invalid literal value, expected ${JSON.stringify(t.expected,util.jsonStringifyReplacer)}`;break;case ZodIssueCode.unrecognized_keys:l=`Unrecognized key(s) in object: ${util.joinValues(t.keys,", ")}`;break;case ZodIssueCode.invalid_union:l="Invalid input";break;case ZodIssueCode.invalid_union_discriminator:l=`Invalid discriminator value. Expected ${util.joinValues(t.options)}`;break;case ZodIssueCode.invalid_enum_value:l=`Invalid enum value. Expected ${util.joinValues(t.options)}, received '${t.received}'`;break;case ZodIssueCode.invalid_arguments:l="Invalid function arguments";break;case ZodIssueCode.invalid_return_type:l="Invalid function return type";break;case ZodIssueCode.invalid_date:l="Invalid date";break;case ZodIssueCode.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(l=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(l=`${l} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?l=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?l=`Invalid input: must end with "${t.validation.endsWith}"`:util.assertNever(t.validation):t.validation!=="regex"?l=`Invalid ${t.validation}`:l="Invalid";break;case ZodIssueCode.too_small:t.type==="array"?l=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?l=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?l=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?l=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?l=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:l="Invalid input";break;case ZodIssueCode.too_big:t.type==="array"?l=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?l=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?l=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?l=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?l=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:l="Invalid input";break;case ZodIssueCode.custom:l="Invalid input";break;case ZodIssueCode.invalid_intersection_types:l="Intersection results could not be merged";break;case ZodIssueCode.not_multiple_of:l=`Number must be a multiple of ${t.multipleOf}`;break;case ZodIssueCode.not_finite:l="Number must be finite";break;default:l=a.defaultError,util.assertNever(t)}return{message:l}};let overrideErrorMap=errorMap;function getErrorMap(){return overrideErrorMap}const makeIssue=t=>{const{data:a,path:l,errorMaps:o,issueData:u}=t,c=[...l,...u.path||[]],d={...u,path:c};if(u.message!==void 0)return{...u,path:c,message:u.message};let m="";const p=o.filter(g=>!!g).slice().reverse();for(const g of p)m=g(d,{data:a,defaultError:m}).message;return{...u,path:c,message:m}};function addIssueToContext(t,a){const l=getErrorMap(),o=makeIssue({issueData:a,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,l,l===errorMap?void 0:errorMap].filter(u=>!!u)});t.common.issues.push(o)}class ParseStatus{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(a,l){const o=[];for(const u of l){if(u.status==="aborted")return INVALID;u.status==="dirty"&&a.dirty(),o.push(u.value)}return{status:a.value,value:o}}static async mergeObjectAsync(a,l){const o=[];for(const u of l){const c=await u.key,d=await u.value;o.push({key:c,value:d})}return ParseStatus.mergeObjectSync(a,o)}static mergeObjectSync(a,l){const o={};for(const u of l){const{key:c,value:d}=u;if(c.status==="aborted"||d.status==="aborted")return INVALID;c.status==="dirty"&&a.dirty(),d.status==="dirty"&&a.dirty(),c.value!=="__proto__"&&(typeof d.value<"u"||u.alwaysSet)&&(o[c.value]=d.value)}return{status:a.value,value:o}}}const INVALID=Object.freeze({status:"aborted"}),DIRTY=t=>({status:"dirty",value:t}),OK=t=>({status:"valid",value:t}),isAborted=t=>t.status==="aborted",isDirty=t=>t.status==="dirty",isValid=t=>t.status==="valid",isAsync=t=>typeof Promise<"u"&&t instanceof Promise;var errorUtil;(function(t){t.errToObj=a=>typeof a=="string"?{message:a}:a||{},t.toString=a=>typeof a=="string"?a:a==null?void 0:a.message})(errorUtil||(errorUtil={}));class ParseInputLazyPath{constructor(a,l,o,u){this._cachedPath=[],this.parent=a,this.data=l,this._path=o,this._key=u}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const handleResult=(t,a)=>{if(isValid(a))return{success:!0,data:a.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const l=new ZodError(t.common.issues);return this._error=l,this._error}}};function processCreateParams(t){if(!t)return{};const{errorMap:a,invalid_type_error:l,required_error:o,description:u}=t;if(a&&(l||o))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return a?{errorMap:a,description:u}:{errorMap:(d,m)=>{const{message:p}=t;return d.code==="invalid_enum_value"?{message:p??m.defaultError}:typeof m.data>"u"?{message:p??o??m.defaultError}:d.code!=="invalid_type"?{message:m.defaultError}:{message:p??l??m.defaultError}},description:u}}class ZodType{get description(){return this._def.description}_getType(a){return getParsedType(a.data)}_getOrReturnCtx(a,l){return l||{common:a.parent.common,data:a.data,parsedType:getParsedType(a.data),schemaErrorMap:this._def.errorMap,path:a.path,parent:a.parent}}_processInputParams(a){return{status:new ParseStatus,ctx:{common:a.parent.common,data:a.data,parsedType:getParsedType(a.data),schemaErrorMap:this._def.errorMap,path:a.path,parent:a.parent}}}_parseSync(a){const l=this._parse(a);if(isAsync(l))throw new Error("Synchronous parse encountered promise.");return l}_parseAsync(a){const l=this._parse(a);return Promise.resolve(l)}parse(a,l){const o=this.safeParse(a,l);if(o.success)return o.data;throw o.error}safeParse(a,l){const o={common:{issues:[],async:(l==null?void 0:l.async)??!1,contextualErrorMap:l==null?void 0:l.errorMap},path:(l==null?void 0:l.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:a,parsedType:getParsedType(a)},u=this._parseSync({data:a,path:o.path,parent:o});return handleResult(o,u)}"~validate"(a){var o,u;const l={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:a,parsedType:getParsedType(a)};if(!this["~standard"].async)try{const c=this._parseSync({data:a,path:[],parent:l});return isValid(c)?{value:c.value}:{issues:l.common.issues}}catch(c){(u=(o=c==null?void 0:c.message)==null?void 0:o.toLowerCase())!=null&&u.includes("encountered")&&(this["~standard"].async=!0),l.common={issues:[],async:!0}}return this._parseAsync({data:a,path:[],parent:l}).then(c=>isValid(c)?{value:c.value}:{issues:l.common.issues})}async parseAsync(a,l){const o=await this.safeParseAsync(a,l);if(o.success)return o.data;throw o.error}async safeParseAsync(a,l){const o={common:{issues:[],contextualErrorMap:l==null?void 0:l.errorMap,async:!0},path:(l==null?void 0:l.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:a,parsedType:getParsedType(a)},u=this._parse({data:a,path:o.path,parent:o}),c=await(isAsync(u)?u:Promise.resolve(u));return handleResult(o,c)}refine(a,l){const o=u=>typeof l=="string"||typeof l>"u"?{message:l}:typeof l=="function"?l(u):l;return this._refinement((u,c)=>{const d=a(u),m=()=>c.addIssue({code:ZodIssueCode.custom,...o(u)});return typeof Promise<"u"&&d instanceof Promise?d.then(p=>p?!0:(m(),!1)):d?!0:(m(),!1)})}refinement(a,l){return this._refinement((o,u)=>a(o)?!0:(u.addIssue(typeof l=="function"?l(o,u):l),!1))}_refinement(a){return new ZodEffects({schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"refinement",refinement:a}})}superRefine(a){return this._refinement(a)}constructor(a){this.spa=this.safeParseAsync,this._def=a,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:l=>this["~validate"](l)}}optional(){return ZodOptional.create(this,this._def)}nullable(){return ZodNullable.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ZodArray.create(this)}promise(){return ZodPromise.create(this,this._def)}or(a){return ZodUnion.create([this,a],this._def)}and(a){return ZodIntersection.create(this,a,this._def)}transform(a){return new ZodEffects({...processCreateParams(this._def),schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"transform",transform:a}})}default(a){const l=typeof a=="function"?a:()=>a;return new ZodDefault({...processCreateParams(this._def),innerType:this,defaultValue:l,typeName:ZodFirstPartyTypeKind.ZodDefault})}brand(){return new ZodBranded({typeName:ZodFirstPartyTypeKind.ZodBranded,type:this,...processCreateParams(this._def)})}catch(a){const l=typeof a=="function"?a:()=>a;return new ZodCatch({...processCreateParams(this._def),innerType:this,catchValue:l,typeName:ZodFirstPartyTypeKind.ZodCatch})}describe(a){const l=this.constructor;return new l({...this._def,description:a})}pipe(a){return ZodPipeline.create(this,a)}readonly(){return ZodReadonly.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const cuidRegex=/^c[^\s-]{8,}$/i,cuid2Regex=/^[0-9a-z]+$/,ulidRegex=/^[0-9A-HJKMNP-TV-Z]{26}$/i,uuidRegex=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,nanoidRegex=/^[a-z0-9_-]{21}$/i,jwtRegex=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,durationRegex=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,emailRegex=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,_emojiRegex="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let emojiRegex;const ipv4Regex=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4CidrRegex=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6Regex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ipv6CidrRegex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64Regex=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64urlRegex=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,dateRegexSource="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",dateRegex=new RegExp(`^${dateRegexSource}$`);function timeRegexSource(t){let a="[0-5]\\d";t.precision?a=`${a}\\.\\d{${t.precision}}`:t.precision==null&&(a=`${a}(\\.\\d+)?`);const l=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${a})${l}`}function timeRegex(t){return new RegExp(`^${timeRegexSource(t)}$`)}function datetimeRegex(t){let a=`${dateRegexSource}T${timeRegexSource(t)}`;const l=[];return l.push(t.local?"Z?":"Z"),t.offset&&l.push("([+-]\\d{2}:?\\d{2})"),a=`${a}(${l.join("|")})`,new RegExp(`^${a}$`)}function isValidIP(t,a){return!!((a==="v4"||!a)&&ipv4Regex.test(t)||(a==="v6"||!a)&&ipv6Regex.test(t))}function isValidJWT(t,a){if(!jwtRegex.test(t))return!1;try{const[l]=t.split(".");if(!l)return!1;const o=l.replace(/-/g,"+").replace(/_/g,"/").padEnd(l.length+(4-l.length%4)%4,"="),u=JSON.parse(atob(o));return!(typeof u!="object"||u===null||"typ"in u&&(u==null?void 0:u.typ)!=="JWT"||!u.alg||a&&u.alg!==a)}catch{return!1}}function isValidCidr(t,a){return!!((a==="v4"||!a)&&ipv4CidrRegex.test(t)||(a==="v6"||!a)&&ipv6CidrRegex.test(t))}class ZodString extends ZodType{_parse(a){if(this._def.coerce&&(a.data=String(a.data)),this._getType(a)!==ZodParsedType.string){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.string,received:c.parsedType}),INVALID}const o=new ParseStatus;let u;for(const c of this._def.checks)if(c.kind==="min")a.data.length<c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_small,minimum:c.value,type:"string",inclusive:!0,exact:!1,message:c.message}),o.dirty());else if(c.kind==="max")a.data.length>c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_big,maximum:c.value,type:"string",inclusive:!0,exact:!1,message:c.message}),o.dirty());else if(c.kind==="length"){const d=a.data.length>c.value,m=a.data.length<c.value;(d||m)&&(u=this._getOrReturnCtx(a,u),d?addIssueToContext(u,{code:ZodIssueCode.too_big,maximum:c.value,type:"string",inclusive:!0,exact:!0,message:c.message}):m&&addIssueToContext(u,{code:ZodIssueCode.too_small,minimum:c.value,type:"string",inclusive:!0,exact:!0,message:c.message}),o.dirty())}else if(c.kind==="email")emailRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"email",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="emoji")emojiRegex||(emojiRegex=new RegExp(_emojiRegex,"u")),emojiRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"emoji",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="uuid")uuidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"uuid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="nanoid")nanoidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"nanoid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="cuid")cuidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"cuid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="cuid2")cuid2Regex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"cuid2",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="ulid")ulidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"ulid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="url")try{new URL(a.data)}catch{u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"url",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()}else c.kind==="regex"?(c.regex.lastIndex=0,c.regex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"regex",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty())):c.kind==="trim"?a.data=a.data.trim():c.kind==="includes"?a.data.includes(c.value,c.position)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:{includes:c.value,position:c.position},message:c.message}),o.dirty()):c.kind==="toLowerCase"?a.data=a.data.toLowerCase():c.kind==="toUpperCase"?a.data=a.data.toUpperCase():c.kind==="startsWith"?a.data.startsWith(c.value)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:{startsWith:c.value},message:c.message}),o.dirty()):c.kind==="endsWith"?a.data.endsWith(c.value)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:{endsWith:c.value},message:c.message}),o.dirty()):c.kind==="datetime"?datetimeRegex(c).test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:"datetime",message:c.message}),o.dirty()):c.kind==="date"?dateRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:"date",message:c.message}),o.dirty()):c.kind==="time"?timeRegex(c).test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:"time",message:c.message}),o.dirty()):c.kind==="duration"?durationRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"duration",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="ip"?isValidIP(a.data,c.version)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"ip",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="jwt"?isValidJWT(a.data,c.alg)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"jwt",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="cidr"?isValidCidr(a.data,c.version)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"cidr",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="base64"?base64Regex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"base64",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="base64url"?base64urlRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"base64url",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):util.assertNever(c);return{status:o.value,value:a.data}}_regex(a,l,o){return this.refinement(u=>a.test(u),{validation:l,code:ZodIssueCode.invalid_string,...errorUtil.errToObj(o)})}_addCheck(a){return new ZodString({...this._def,checks:[...this._def.checks,a]})}email(a){return this._addCheck({kind:"email",...errorUtil.errToObj(a)})}url(a){return this._addCheck({kind:"url",...errorUtil.errToObj(a)})}emoji(a){return this._addCheck({kind:"emoji",...errorUtil.errToObj(a)})}uuid(a){return this._addCheck({kind:"uuid",...errorUtil.errToObj(a)})}nanoid(a){return this._addCheck({kind:"nanoid",...errorUtil.errToObj(a)})}cuid(a){return this._addCheck({kind:"cuid",...errorUtil.errToObj(a)})}cuid2(a){return this._addCheck({kind:"cuid2",...errorUtil.errToObj(a)})}ulid(a){return this._addCheck({kind:"ulid",...errorUtil.errToObj(a)})}base64(a){return this._addCheck({kind:"base64",...errorUtil.errToObj(a)})}base64url(a){return this._addCheck({kind:"base64url",...errorUtil.errToObj(a)})}jwt(a){return this._addCheck({kind:"jwt",...errorUtil.errToObj(a)})}ip(a){return this._addCheck({kind:"ip",...errorUtil.errToObj(a)})}cidr(a){return this._addCheck({kind:"cidr",...errorUtil.errToObj(a)})}datetime(a){return typeof a=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:a}):this._addCheck({kind:"datetime",precision:typeof(a==null?void 0:a.precision)>"u"?null:a==null?void 0:a.precision,offset:(a==null?void 0:a.offset)??!1,local:(a==null?void 0:a.local)??!1,...errorUtil.errToObj(a==null?void 0:a.message)})}date(a){return this._addCheck({kind:"date",message:a})}time(a){return typeof a=="string"?this._addCheck({kind:"time",precision:null,message:a}):this._addCheck({kind:"time",precision:typeof(a==null?void 0:a.precision)>"u"?null:a==null?void 0:a.precision,...errorUtil.errToObj(a==null?void 0:a.message)})}duration(a){return this._addCheck({kind:"duration",...errorUtil.errToObj(a)})}regex(a,l){return this._addCheck({kind:"regex",regex:a,...errorUtil.errToObj(l)})}includes(a,l){return this._addCheck({kind:"includes",value:a,position:l==null?void 0:l.position,...errorUtil.errToObj(l==null?void 0:l.message)})}startsWith(a,l){return this._addCheck({kind:"startsWith",value:a,...errorUtil.errToObj(l)})}endsWith(a,l){return this._addCheck({kind:"endsWith",value:a,...errorUtil.errToObj(l)})}min(a,l){return this._addCheck({kind:"min",value:a,...errorUtil.errToObj(l)})}max(a,l){return this._addCheck({kind:"max",value:a,...errorUtil.errToObj(l)})}length(a,l){return this._addCheck({kind:"length",value:a,...errorUtil.errToObj(l)})}nonempty(a){return this.min(1,errorUtil.errToObj(a))}trim(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(a=>a.kind==="datetime")}get isDate(){return!!this._def.checks.find(a=>a.kind==="date")}get isTime(){return!!this._def.checks.find(a=>a.kind==="time")}get isDuration(){return!!this._def.checks.find(a=>a.kind==="duration")}get isEmail(){return!!this._def.checks.find(a=>a.kind==="email")}get isURL(){return!!this._def.checks.find(a=>a.kind==="url")}get isEmoji(){return!!this._def.checks.find(a=>a.kind==="emoji")}get isUUID(){return!!this._def.checks.find(a=>a.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(a=>a.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(a=>a.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(a=>a.kind==="cuid2")}get isULID(){return!!this._def.checks.find(a=>a.kind==="ulid")}get isIP(){return!!this._def.checks.find(a=>a.kind==="ip")}get isCIDR(){return!!this._def.checks.find(a=>a.kind==="cidr")}get isBase64(){return!!this._def.checks.find(a=>a.kind==="base64")}get isBase64url(){return!!this._def.checks.find(a=>a.kind==="base64url")}get minLength(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a}get maxLength(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a}}ZodString.create=t=>new ZodString({checks:[],typeName:ZodFirstPartyTypeKind.ZodString,coerce:(t==null?void 0:t.coerce)??!1,...processCreateParams(t)});function floatSafeRemainder(t,a){const l=(t.toString().split(".")[1]||"").length,o=(a.toString().split(".")[1]||"").length,u=l>o?l:o,c=Number.parseInt(t.toFixed(u).replace(".","")),d=Number.parseInt(a.toFixed(u).replace(".",""));return c%d/10**u}class ZodNumber extends ZodType{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(a){if(this._def.coerce&&(a.data=Number(a.data)),this._getType(a)!==ZodParsedType.number){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.number,received:c.parsedType}),INVALID}let o;const u=new ParseStatus;for(const c of this._def.checks)c.kind==="int"?util.isInteger(a.data)||(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:"integer",received:"float",message:c.message}),u.dirty()):c.kind==="min"?(c.inclusive?a.data<c.value:a.data<=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_small,minimum:c.value,type:"number",inclusive:c.inclusive,exact:!1,message:c.message}),u.dirty()):c.kind==="max"?(c.inclusive?a.data>c.value:a.data>=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_big,maximum:c.value,type:"number",inclusive:c.inclusive,exact:!1,message:c.message}),u.dirty()):c.kind==="multipleOf"?floatSafeRemainder(a.data,c.value)!==0&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.not_multiple_of,multipleOf:c.value,message:c.message}),u.dirty()):c.kind==="finite"?Number.isFinite(a.data)||(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.not_finite,message:c.message}),u.dirty()):util.assertNever(c);return{status:u.value,value:a.data}}gte(a,l){return this.setLimit("min",a,!0,errorUtil.toString(l))}gt(a,l){return this.setLimit("min",a,!1,errorUtil.toString(l))}lte(a,l){return this.setLimit("max",a,!0,errorUtil.toString(l))}lt(a,l){return this.setLimit("max",a,!1,errorUtil.toString(l))}setLimit(a,l,o,u){return new ZodNumber({...this._def,checks:[...this._def.checks,{kind:a,value:l,inclusive:o,message:errorUtil.toString(u)}]})}_addCheck(a){return new ZodNumber({...this._def,checks:[...this._def.checks,a]})}int(a){return this._addCheck({kind:"int",message:errorUtil.toString(a)})}positive(a){return this._addCheck({kind:"min",value:0,inclusive:!1,message:errorUtil.toString(a)})}negative(a){return this._addCheck({kind:"max",value:0,inclusive:!1,message:errorUtil.toString(a)})}nonpositive(a){return this._addCheck({kind:"max",value:0,inclusive:!0,message:errorUtil.toString(a)})}nonnegative(a){return this._addCheck({kind:"min",value:0,inclusive:!0,message:errorUtil.toString(a)})}multipleOf(a,l){return this._addCheck({kind:"multipleOf",value:a,message:errorUtil.toString(l)})}finite(a){return this._addCheck({kind:"finite",message:errorUtil.toString(a)})}safe(a){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:errorUtil.toString(a)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:errorUtil.toString(a)})}get minValue(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a}get maxValue(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a}get isInt(){return!!this._def.checks.find(a=>a.kind==="int"||a.kind==="multipleOf"&&util.isInteger(a.value))}get isFinite(){let a=null,l=null;for(const o of this._def.checks){if(o.kind==="finite"||o.kind==="int"||o.kind==="multipleOf")return!0;o.kind==="min"?(l===null||o.value>l)&&(l=o.value):o.kind==="max"&&(a===null||o.value<a)&&(a=o.value)}return Number.isFinite(l)&&Number.isFinite(a)}}ZodNumber.create=t=>new ZodNumber({checks:[],typeName:ZodFirstPartyTypeKind.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...processCreateParams(t)});class ZodBigInt extends ZodType{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(a){if(this._def.coerce)try{a.data=BigInt(a.data)}catch{return this._getInvalidInput(a)}if(this._getType(a)!==ZodParsedType.bigint)return this._getInvalidInput(a);let o;const u=new ParseStatus;for(const c of this._def.checks)c.kind==="min"?(c.inclusive?a.data<c.value:a.data<=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_small,type:"bigint",minimum:c.value,inclusive:c.inclusive,message:c.message}),u.dirty()):c.kind==="max"?(c.inclusive?a.data>c.value:a.data>=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_big,type:"bigint",maximum:c.value,inclusive:c.inclusive,message:c.message}),u.dirty()):c.kind==="multipleOf"?a.data%c.value!==BigInt(0)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.not_multiple_of,multipleOf:c.value,message:c.message}),u.dirty()):util.assertNever(c);return{status:u.value,value:a.data}}_getInvalidInput(a){const l=this._getOrReturnCtx(a);return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.bigint,received:l.parsedType}),INVALID}gte(a,l){return this.setLimit("min",a,!0,errorUtil.toString(l))}gt(a,l){return this.setLimit("min",a,!1,errorUtil.toString(l))}lte(a,l){return this.setLimit("max",a,!0,errorUtil.toString(l))}lt(a,l){return this.setLimit("max",a,!1,errorUtil.toString(l))}setLimit(a,l,o,u){return new ZodBigInt({...this._def,checks:[...this._def.checks,{kind:a,value:l,inclusive:o,message:errorUtil.toString(u)}]})}_addCheck(a){return new ZodBigInt({...this._def,checks:[...this._def.checks,a]})}positive(a){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:errorUtil.toString(a)})}negative(a){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:errorUtil.toString(a)})}nonpositive(a){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:errorUtil.toString(a)})}nonnegative(a){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:errorUtil.toString(a)})}multipleOf(a,l){return this._addCheck({kind:"multipleOf",value:a,message:errorUtil.toString(l)})}get minValue(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a}get maxValue(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a}}ZodBigInt.create=t=>new ZodBigInt({checks:[],typeName:ZodFirstPartyTypeKind.ZodBigInt,coerce:(t==null?void 0:t.coerce)??!1,...processCreateParams(t)});class ZodBoolean extends ZodType{_parse(a){if(this._def.coerce&&(a.data=!!a.data),this._getType(a)!==ZodParsedType.boolean){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.boolean,received:o.parsedType}),INVALID}return OK(a.data)}}ZodBoolean.create=t=>new ZodBoolean({typeName:ZodFirstPartyTypeKind.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...processCreateParams(t)});class ZodDate extends ZodType{_parse(a){if(this._def.coerce&&(a.data=new Date(a.data)),this._getType(a)!==ZodParsedType.date){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.date,received:c.parsedType}),INVALID}if(Number.isNaN(a.data.getTime())){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_date}),INVALID}const o=new ParseStatus;let u;for(const c of this._def.checks)c.kind==="min"?a.data.getTime()<c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_small,message:c.message,inclusive:!0,exact:!1,minimum:c.value,type:"date"}),o.dirty()):c.kind==="max"?a.data.getTime()>c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_big,message:c.message,inclusive:!0,exact:!1,maximum:c.value,type:"date"}),o.dirty()):util.assertNever(c);return{status:o.value,value:new Date(a.data.getTime())}}_addCheck(a){return new ZodDate({...this._def,checks:[...this._def.checks,a]})}min(a,l){return this._addCheck({kind:"min",value:a.getTime(),message:errorUtil.toString(l)})}max(a,l){return this._addCheck({kind:"max",value:a.getTime(),message:errorUtil.toString(l)})}get minDate(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a!=null?new Date(a):null}get maxDate(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a!=null?new Date(a):null}}ZodDate.create=t=>new ZodDate({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:ZodFirstPartyTypeKind.ZodDate,...processCreateParams(t)});class ZodSymbol extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.symbol){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.symbol,received:o.parsedType}),INVALID}return OK(a.data)}}ZodSymbol.create=t=>new ZodSymbol({typeName:ZodFirstPartyTypeKind.ZodSymbol,...processCreateParams(t)});class ZodUndefined extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.undefined){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.undefined,received:o.parsedType}),INVALID}return OK(a.data)}}ZodUndefined.create=t=>new ZodUndefined({typeName:ZodFirstPartyTypeKind.ZodUndefined,...processCreateParams(t)});class ZodNull extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.null){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.null,received:o.parsedType}),INVALID}return OK(a.data)}}ZodNull.create=t=>new ZodNull({typeName:ZodFirstPartyTypeKind.ZodNull,...processCreateParams(t)});class ZodAny extends ZodType{constructor(){super(...arguments),this._any=!0}_parse(a){return OK(a.data)}}ZodAny.create=t=>new ZodAny({typeName:ZodFirstPartyTypeKind.ZodAny,...processCreateParams(t)});class ZodUnknown extends ZodType{constructor(){super(...arguments),this._unknown=!0}_parse(a){return OK(a.data)}}ZodUnknown.create=t=>new ZodUnknown({typeName:ZodFirstPartyTypeKind.ZodUnknown,...processCreateParams(t)});class ZodNever extends ZodType{_parse(a){const l=this._getOrReturnCtx(a);return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.never,received:l.parsedType}),INVALID}}ZodNever.create=t=>new ZodNever({typeName:ZodFirstPartyTypeKind.ZodNever,...processCreateParams(t)});class ZodVoid extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.undefined){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.void,received:o.parsedType}),INVALID}return OK(a.data)}}ZodVoid.create=t=>new ZodVoid({typeName:ZodFirstPartyTypeKind.ZodVoid,...processCreateParams(t)});class ZodArray extends ZodType{_parse(a){const{ctx:l,status:o}=this._processInputParams(a),u=this._def;if(l.parsedType!==ZodParsedType.array)return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:l.parsedType}),INVALID;if(u.exactLength!==null){const d=l.data.length>u.exactLength.value,m=l.data.length<u.exactLength.value;(d||m)&&(addIssueToContext(l,{code:d?ZodIssueCode.too_big:ZodIssueCode.too_small,minimum:m?u.exactLength.value:void 0,maximum:d?u.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:u.exactLength.message}),o.dirty())}if(u.minLength!==null&&l.data.length<u.minLength.value&&(addIssueToContext(l,{code:ZodIssueCode.too_small,minimum:u.minLength.value,type:"array",inclusive:!0,exact:!1,message:u.minLength.message}),o.dirty()),u.maxLength!==null&&l.data.length>u.maxLength.value&&(addIssueToContext(l,{code:ZodIssueCode.too_big,maximum:u.maxLength.value,type:"array",inclusive:!0,exact:!1,message:u.maxLength.message}),o.dirty()),l.common.async)return Promise.all([...l.data].map((d,m)=>u.type._parseAsync(new ParseInputLazyPath(l,d,l.path,m)))).then(d=>ParseStatus.mergeArray(o,d));const c=[...l.data].map((d,m)=>u.type._parseSync(new ParseInputLazyPath(l,d,l.path,m)));return ParseStatus.mergeArray(o,c)}get element(){return this._def.type}min(a,l){return new ZodArray({...this._def,minLength:{value:a,message:errorUtil.toString(l)}})}max(a,l){return new ZodArray({...this._def,maxLength:{value:a,message:errorUtil.toString(l)}})}length(a,l){return new ZodArray({...this._def,exactLength:{value:a,message:errorUtil.toString(l)}})}nonempty(a){return this.min(1,a)}}ZodArray.create=(t,a)=>new ZodArray({type:t,minLength:null,maxLength:null,exactLength:null,typeName:ZodFirstPartyTypeKind.ZodArray,...processCreateParams(a)});function deepPartialify(t){if(t instanceof ZodObject){const a={};for(const l in t.shape){const o=t.shape[l];a[l]=ZodOptional.create(deepPartialify(o))}return new ZodObject({...t._def,shape:()=>a})}else return t instanceof ZodArray?new ZodArray({...t._def,type:deepPartialify(t.element)}):t instanceof ZodOptional?ZodOptional.create(deepPartialify(t.unwrap())):t instanceof ZodNullable?ZodNullable.create(deepPartialify(t.unwrap())):t instanceof ZodTuple?ZodTuple.create(t.items.map(a=>deepPartialify(a))):t}class ZodObject extends ZodType{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const a=this._def.shape(),l=util.objectKeys(a);return this._cached={shape:a,keys:l},this._cached}_parse(a){if(this._getType(a)!==ZodParsedType.object){const g=this._getOrReturnCtx(a);return addIssueToContext(g,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:g.parsedType}),INVALID}const{status:o,ctx:u}=this._processInputParams(a),{shape:c,keys:d}=this._getCached(),m=[];if(!(this._def.catchall instanceof ZodNever&&this._def.unknownKeys==="strip"))for(const g in u.data)d.includes(g)||m.push(g);const p=[];for(const g of d){const x=c[g],b=u.data[g];p.push({key:{status:"valid",value:g},value:x._parse(new ParseInputLazyPath(u,b,u.path,g)),alwaysSet:g in u.data})}if(this._def.catchall instanceof ZodNever){const g=this._def.unknownKeys;if(g==="passthrough")for(const x of m)p.push({key:{status:"valid",value:x},value:{status:"valid",value:u.data[x]}});else if(g==="strict")m.length>0&&(addIssueToContext(u,{code:ZodIssueCode.unrecognized_keys,keys:m}),o.dirty());else if(g!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const g=this._def.catchall;for(const x of m){const b=u.data[x];p.push({key:{status:"valid",value:x},value:g._parse(new ParseInputLazyPath(u,b,u.path,x)),alwaysSet:x in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const g=[];for(const x of p){const b=await x.key,C=await x.value;g.push({key:b,value:C,alwaysSet:x.alwaysSet})}return g}).then(g=>ParseStatus.mergeObjectSync(o,g)):ParseStatus.mergeObjectSync(o,p)}get shape(){return this._def.shape()}strict(a){return errorUtil.errToObj,new ZodObject({...this._def,unknownKeys:"strict",...a!==void 0?{errorMap:(l,o)=>{var c,d;const u=((d=(c=this._def).errorMap)==null?void 0:d.call(c,l,o).message)??o.defaultError;return l.code==="unrecognized_keys"?{message:errorUtil.errToObj(a).message??u}:{message:u}}}:{}})}strip(){return new ZodObject({...this._def,unknownKeys:"strip"})}passthrough(){return new ZodObject({...this._def,unknownKeys:"passthrough"})}extend(a){return new ZodObject({...this._def,shape:()=>({...this._def.shape(),...a})})}merge(a){return new ZodObject({unknownKeys:a._def.unknownKeys,catchall:a._def.catchall,shape:()=>({...this._def.shape(),...a._def.shape()}),typeName:ZodFirstPartyTypeKind.ZodObject})}setKey(a,l){return this.augment({[a]:l})}catchall(a){return new ZodObject({...this._def,catchall:a})}pick(a){const l={};for(const o of util.objectKeys(a))a[o]&&this.shape[o]&&(l[o]=this.shape[o]);return new ZodObject({...this._def,shape:()=>l})}omit(a){const l={};for(const o of util.objectKeys(this.shape))a[o]||(l[o]=this.shape[o]);return new ZodObject({...this._def,shape:()=>l})}deepPartial(){return deepPartialify(this)}partial(a){const l={};for(const o of util.objectKeys(this.shape)){const u=this.shape[o];a&&!a[o]?l[o]=u:l[o]=u.optional()}return new ZodObject({...this._def,shape:()=>l})}required(a){const l={};for(const o of util.objectKeys(this.shape))if(a&&!a[o])l[o]=this.shape[o];else{let c=this.shape[o];for(;c instanceof ZodOptional;)c=c._def.innerType;l[o]=c}return new ZodObject({...this._def,shape:()=>l})}keyof(){return createZodEnum(util.objectKeys(this.shape))}}ZodObject.create=(t,a)=>new ZodObject({shape:()=>t,unknownKeys:"strip",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject,...processCreateParams(a)});ZodObject.strictCreate=(t,a)=>new ZodObject({shape:()=>t,unknownKeys:"strict",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject,...processCreateParams(a)});ZodObject.lazycreate=(t,a)=>new ZodObject({shape:t,unknownKeys:"strip",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject,...processCreateParams(a)});class ZodUnion extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a),o=this._def.options;function u(c){for(const m of c)if(m.result.status==="valid")return m.result;for(const m of c)if(m.result.status==="dirty")return l.common.issues.push(...m.ctx.common.issues),m.result;const d=c.map(m=>new ZodError(m.ctx.common.issues));return addIssueToContext(l,{code:ZodIssueCode.invalid_union,unionErrors:d}),INVALID}if(l.common.async)return Promise.all(o.map(async c=>{const d={...l,common:{...l.common,issues:[]},parent:null};return{result:await c._parseAsync({data:l.data,path:l.path,parent:d}),ctx:d}})).then(u);{let c;const d=[];for(const p of o){const g={...l,common:{...l.common,issues:[]},parent:null},x=p._parseSync({data:l.data,path:l.path,parent:g});if(x.status==="valid")return x;x.status==="dirty"&&!c&&(c={result:x,ctx:g}),g.common.issues.length&&d.push(g.common.issues)}if(c)return l.common.issues.push(...c.ctx.common.issues),c.result;const m=d.map(p=>new ZodError(p));return addIssueToContext(l,{code:ZodIssueCode.invalid_union,unionErrors:m}),INVALID}}get options(){return this._def.options}}ZodUnion.create=(t,a)=>new ZodUnion({options:t,typeName:ZodFirstPartyTypeKind.ZodUnion,...processCreateParams(a)});function mergeValues(t,a){const l=getParsedType(t),o=getParsedType(a);if(t===a)return{valid:!0,data:t};if(l===ZodParsedType.object&&o===ZodParsedType.object){const u=util.objectKeys(a),c=util.objectKeys(t).filter(m=>u.indexOf(m)!==-1),d={...t,...a};for(const m of c){const p=mergeValues(t[m],a[m]);if(!p.valid)return{valid:!1};d[m]=p.data}return{valid:!0,data:d}}else if(l===ZodParsedType.array&&o===ZodParsedType.array){if(t.length!==a.length)return{valid:!1};const u=[];for(let c=0;c<t.length;c++){const d=t[c],m=a[c],p=mergeValues(d,m);if(!p.valid)return{valid:!1};u.push(p.data)}return{valid:!0,data:u}}else return l===ZodParsedType.date&&o===ZodParsedType.date&&+t==+a?{valid:!0,data:t}:{valid:!1}}class ZodIntersection extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a),u=(c,d)=>{if(isAborted(c)||isAborted(d))return INVALID;const m=mergeValues(c.value,d.value);return m.valid?((isDirty(c)||isDirty(d))&&l.dirty(),{status:l.value,value:m.data}):(addIssueToContext(o,{code:ZodIssueCode.invalid_intersection_types}),INVALID)};return o.common.async?Promise.all([this._def.left._parseAsync({data:o.data,path:o.path,parent:o}),this._def.right._parseAsync({data:o.data,path:o.path,parent:o})]).then(([c,d])=>u(c,d)):u(this._def.left._parseSync({data:o.data,path:o.path,parent:o}),this._def.right._parseSync({data:o.data,path:o.path,parent:o}))}}ZodIntersection.create=(t,a,l)=>new ZodIntersection({left:t,right:a,typeName:ZodFirstPartyTypeKind.ZodIntersection,...processCreateParams(l)});class ZodTuple extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.array)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:o.parsedType}),INVALID;if(o.data.length<this._def.items.length)return addIssueToContext(o,{code:ZodIssueCode.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),INVALID;!this._def.rest&&o.data.length>this._def.items.length&&(addIssueToContext(o,{code:ZodIssueCode.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),l.dirty());const c=[...o.data].map((d,m)=>{const p=this._def.items[m]||this._def.rest;return p?p._parse(new ParseInputLazyPath(o,d,o.path,m)):null}).filter(d=>!!d);return o.common.async?Promise.all(c).then(d=>ParseStatus.mergeArray(l,d)):ParseStatus.mergeArray(l,c)}get items(){return this._def.items}rest(a){return new ZodTuple({...this._def,rest:a})}}ZodTuple.create=(t,a)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ZodTuple({items:t,typeName:ZodFirstPartyTypeKind.ZodTuple,rest:null,...processCreateParams(a)})};class ZodRecord extends ZodType{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.object)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:o.parsedType}),INVALID;const u=[],c=this._def.keyType,d=this._def.valueType;for(const m in o.data)u.push({key:c._parse(new ParseInputLazyPath(o,m,o.path,m)),value:d._parse(new ParseInputLazyPath(o,o.data[m],o.path,m)),alwaysSet:m in o.data});return o.common.async?ParseStatus.mergeObjectAsync(l,u):ParseStatus.mergeObjectSync(l,u)}get element(){return this._def.valueType}static create(a,l,o){return l instanceof ZodType?new ZodRecord({keyType:a,valueType:l,typeName:ZodFirstPartyTypeKind.ZodRecord,...processCreateParams(o)}):new ZodRecord({keyType:ZodString.create(),valueType:a,typeName:ZodFirstPartyTypeKind.ZodRecord,...processCreateParams(l)})}}class ZodMap extends ZodType{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.map)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.map,received:o.parsedType}),INVALID;const u=this._def.keyType,c=this._def.valueType,d=[...o.data.entries()].map(([m,p],g)=>({key:u._parse(new ParseInputLazyPath(o,m,o.path,[g,"key"])),value:c._parse(new ParseInputLazyPath(o,p,o.path,[g,"value"]))}));if(o.common.async){const m=new Map;return Promise.resolve().then(async()=>{for(const p of d){const g=await p.key,x=await p.value;if(g.status==="aborted"||x.status==="aborted")return INVALID;(g.status==="dirty"||x.status==="dirty")&&l.dirty(),m.set(g.value,x.value)}return{status:l.value,value:m}})}else{const m=new Map;for(const p of d){const g=p.key,x=p.value;if(g.status==="aborted"||x.status==="aborted")return INVALID;(g.status==="dirty"||x.status==="dirty")&&l.dirty(),m.set(g.value,x.value)}return{status:l.value,value:m}}}}ZodMap.create=(t,a,l)=>new ZodMap({valueType:a,keyType:t,typeName:ZodFirstPartyTypeKind.ZodMap,...processCreateParams(l)});class ZodSet extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.set)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.set,received:o.parsedType}),INVALID;const u=this._def;u.minSize!==null&&o.data.size<u.minSize.value&&(addIssueToContext(o,{code:ZodIssueCode.too_small,minimum:u.minSize.value,type:"set",inclusive:!0,exact:!1,message:u.minSize.message}),l.dirty()),u.maxSize!==null&&o.data.size>u.maxSize.value&&(addIssueToContext(o,{code:ZodIssueCode.too_big,maximum:u.maxSize.value,type:"set",inclusive:!0,exact:!1,message:u.maxSize.message}),l.dirty());const c=this._def.valueType;function d(p){const g=new Set;for(const x of p){if(x.status==="aborted")return INVALID;x.status==="dirty"&&l.dirty(),g.add(x.value)}return{status:l.value,value:g}}const m=[...o.data.values()].map((p,g)=>c._parse(new ParseInputLazyPath(o,p,o.path,g)));return o.common.async?Promise.all(m).then(p=>d(p)):d(m)}min(a,l){return new ZodSet({...this._def,minSize:{value:a,message:errorUtil.toString(l)}})}max(a,l){return new ZodSet({...this._def,maxSize:{value:a,message:errorUtil.toString(l)}})}size(a,l){return this.min(a,l).max(a,l)}nonempty(a){return this.min(1,a)}}ZodSet.create=(t,a)=>new ZodSet({valueType:t,minSize:null,maxSize:null,typeName:ZodFirstPartyTypeKind.ZodSet,...processCreateParams(a)});class ZodLazy extends ZodType{get schema(){return this._def.getter()}_parse(a){const{ctx:l}=this._processInputParams(a);return this._def.getter()._parse({data:l.data,path:l.path,parent:l})}}ZodLazy.create=(t,a)=>new ZodLazy({getter:t,typeName:ZodFirstPartyTypeKind.ZodLazy,...processCreateParams(a)});class ZodLiteral extends ZodType{_parse(a){if(a.data!==this._def.value){const l=this._getOrReturnCtx(a);return addIssueToContext(l,{received:l.data,code:ZodIssueCode.invalid_literal,expected:this._def.value}),INVALID}return{status:"valid",value:a.data}}get value(){return this._def.value}}ZodLiteral.create=(t,a)=>new ZodLiteral({value:t,typeName:ZodFirstPartyTypeKind.ZodLiteral,...processCreateParams(a)});function createZodEnum(t,a){return new ZodEnum({values:t,typeName:ZodFirstPartyTypeKind.ZodEnum,...processCreateParams(a)})}class ZodEnum extends ZodType{_parse(a){if(typeof a.data!="string"){const l=this._getOrReturnCtx(a),o=this._def.values;return addIssueToContext(l,{expected:util.joinValues(o),received:l.parsedType,code:ZodIssueCode.invalid_type}),INVALID}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(a.data)){const l=this._getOrReturnCtx(a),o=this._def.values;return addIssueToContext(l,{received:l.data,code:ZodIssueCode.invalid_enum_value,options:o}),INVALID}return OK(a.data)}get options(){return this._def.values}get enum(){const a={};for(const l of this._def.values)a[l]=l;return a}get Values(){const a={};for(const l of this._def.values)a[l]=l;return a}get Enum(){const a={};for(const l of this._def.values)a[l]=l;return a}extract(a,l=this._def){return ZodEnum.create(a,{...this._def,...l})}exclude(a,l=this._def){return ZodEnum.create(this.options.filter(o=>!a.includes(o)),{...this._def,...l})}}ZodEnum.create=createZodEnum;class ZodNativeEnum extends ZodType{_parse(a){const l=util.getValidEnumValues(this._def.values),o=this._getOrReturnCtx(a);if(o.parsedType!==ZodParsedType.string&&o.parsedType!==ZodParsedType.number){const u=util.objectValues(l);return addIssueToContext(o,{expected:util.joinValues(u),received:o.parsedType,code:ZodIssueCode.invalid_type}),INVALID}if(this._cache||(this._cache=new Set(util.getValidEnumValues(this._def.values))),!this._cache.has(a.data)){const u=util.objectValues(l);return addIssueToContext(o,{received:o.data,code:ZodIssueCode.invalid_enum_value,options:u}),INVALID}return OK(a.data)}get enum(){return this._def.values}}ZodNativeEnum.create=(t,a)=>new ZodNativeEnum({values:t,typeName:ZodFirstPartyTypeKind.ZodNativeEnum,...processCreateParams(a)});class ZodPromise extends ZodType{unwrap(){return this._def.type}_parse(a){const{ctx:l}=this._processInputParams(a);if(l.parsedType!==ZodParsedType.promise&&l.common.async===!1)return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.promise,received:l.parsedType}),INVALID;const o=l.parsedType===ZodParsedType.promise?l.data:Promise.resolve(l.data);return OK(o.then(u=>this._def.type.parseAsync(u,{path:l.path,errorMap:l.common.contextualErrorMap})))}}ZodPromise.create=(t,a)=>new ZodPromise({type:t,typeName:ZodFirstPartyTypeKind.ZodPromise,...processCreateParams(a)});class ZodEffects extends ZodType{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===ZodFirstPartyTypeKind.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(a){const{status:l,ctx:o}=this._processInputParams(a),u=this._def.effect||null,c={addIssue:d=>{addIssueToContext(o,d),d.fatal?l.abort():l.dirty()},get path(){return o.path}};if(c.addIssue=c.addIssue.bind(c),u.type==="preprocess"){const d=u.transform(o.data,c);if(o.common.async)return Promise.resolve(d).then(async m=>{if(l.value==="aborted")return INVALID;const p=await this._def.schema._parseAsync({data:m,path:o.path,parent:o});return p.status==="aborted"?INVALID:p.status==="dirty"||l.value==="dirty"?DIRTY(p.value):p});{if(l.value==="aborted")return INVALID;const m=this._def.schema._parseSync({data:d,path:o.path,parent:o});return m.status==="aborted"?INVALID:m.status==="dirty"||l.value==="dirty"?DIRTY(m.value):m}}if(u.type==="refinement"){const d=m=>{const p=u.refinement(m,c);if(o.common.async)return Promise.resolve(p);if(p instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return m};if(o.common.async===!1){const m=this._def.schema._parseSync({data:o.data,path:o.path,parent:o});return m.status==="aborted"?INVALID:(m.status==="dirty"&&l.dirty(),d(m.value),{status:l.value,value:m.value})}else return this._def.schema._parseAsync({data:o.data,path:o.path,parent:o}).then(m=>m.status==="aborted"?INVALID:(m.status==="dirty"&&l.dirty(),d(m.value).then(()=>({status:l.value,value:m.value}))))}if(u.type==="transform")if(o.common.async===!1){const d=this._def.schema._parseSync({data:o.data,path:o.path,parent:o});if(!isValid(d))return INVALID;const m=u.transform(d.value,c);if(m instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:l.value,value:m}}else return this._def.schema._parseAsync({data:o.data,path:o.path,parent:o}).then(d=>isValid(d)?Promise.resolve(u.transform(d.value,c)).then(m=>({status:l.value,value:m})):INVALID);util.assertNever(u)}}ZodEffects.create=(t,a,l)=>new ZodEffects({schema:t,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:a,...processCreateParams(l)});ZodEffects.createWithPreprocess=(t,a,l)=>new ZodEffects({schema:a,effect:{type:"preprocess",transform:t},typeName:ZodFirstPartyTypeKind.ZodEffects,...processCreateParams(l)});class ZodOptional extends ZodType{_parse(a){return this._getType(a)===ZodParsedType.undefined?OK(void 0):this._def.innerType._parse(a)}unwrap(){return this._def.innerType}}ZodOptional.create=(t,a)=>new ZodOptional({innerType:t,typeName:ZodFirstPartyTypeKind.ZodOptional,...processCreateParams(a)});class ZodNullable extends ZodType{_parse(a){return this._getType(a)===ZodParsedType.null?OK(null):this._def.innerType._parse(a)}unwrap(){return this._def.innerType}}ZodNullable.create=(t,a)=>new ZodNullable({innerType:t,typeName:ZodFirstPartyTypeKind.ZodNullable,...processCreateParams(a)});class ZodDefault extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a);let o=l.data;return l.parsedType===ZodParsedType.undefined&&(o=this._def.defaultValue()),this._def.innerType._parse({data:o,path:l.path,parent:l})}removeDefault(){return this._def.innerType}}ZodDefault.create=(t,a)=>new ZodDefault({innerType:t,typeName:ZodFirstPartyTypeKind.ZodDefault,defaultValue:typeof a.default=="function"?a.default:()=>a.default,...processCreateParams(a)});class ZodCatch extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a),o={...l,common:{...l.common,issues:[]}},u=this._def.innerType._parse({data:o.data,path:o.path,parent:{...o}});return isAsync(u)?u.then(c=>({status:"valid",value:c.status==="valid"?c.value:this._def.catchValue({get error(){return new ZodError(o.common.issues)},input:o.data})})):{status:"valid",value:u.status==="valid"?u.value:this._def.catchValue({get error(){return new ZodError(o.common.issues)},input:o.data})}}removeCatch(){return this._def.innerType}}ZodCatch.create=(t,a)=>new ZodCatch({innerType:t,typeName:ZodFirstPartyTypeKind.ZodCatch,catchValue:typeof a.catch=="function"?a.catch:()=>a.catch,...processCreateParams(a)});class ZodNaN extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.nan){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.nan,received:o.parsedType}),INVALID}return{status:"valid",value:a.data}}}ZodNaN.create=t=>new ZodNaN({typeName:ZodFirstPartyTypeKind.ZodNaN,...processCreateParams(t)});class ZodBranded extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a),o=l.data;return this._def.type._parse({data:o,path:l.path,parent:l})}unwrap(){return this._def.type}}class ZodPipeline extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.common.async)return(async()=>{const c=await this._def.in._parseAsync({data:o.data,path:o.path,parent:o});return c.status==="aborted"?INVALID:c.status==="dirty"?(l.dirty(),DIRTY(c.value)):this._def.out._parseAsync({data:c.value,path:o.path,parent:o})})();{const u=this._def.in._parseSync({data:o.data,path:o.path,parent:o});return u.status==="aborted"?INVALID:u.status==="dirty"?(l.dirty(),{status:"dirty",value:u.value}):this._def.out._parseSync({data:u.value,path:o.path,parent:o})}}static create(a,l){return new ZodPipeline({in:a,out:l,typeName:ZodFirstPartyTypeKind.ZodPipeline})}}class ZodReadonly extends ZodType{_parse(a){const l=this._def.innerType._parse(a),o=u=>(isValid(u)&&(u.value=Object.freeze(u.value)),u);return isAsync(l)?l.then(u=>o(u)):o(l)}unwrap(){return this._def.innerType}}ZodReadonly.create=(t,a)=>new ZodReadonly({innerType:t,typeName:ZodFirstPartyTypeKind.ZodReadonly,...processCreateParams(a)});var ZodFirstPartyTypeKind;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(ZodFirstPartyTypeKind||(ZodFirstPartyTypeKind={}));const stringType=ZodString.create,numberType=ZodNumber.create,booleanType=ZodBoolean.create,unknownType=ZodUnknown.create;ZodNever.create;const arrayType=ZodArray.create,objectType=ZodObject.create;ZodUnion.create;ZodIntersection.create;ZodTuple.create;const recordType=ZodRecord.create;ZodEnum.create;ZodPromise.create;ZodOptional.create;ZodNullable.create;objectType({id:stringType(),agentId:stringType(),clappId:stringType(),intent:stringType(),payload:recordType(unknownType()),timestamp:stringType()});objectType({agentId:stringType(),clappId:stringType(),version:numberType(),timestamp:stringType(),state:recordType(unknownType())});const AppEntrySchema=objectType({id:stringType(),name:stringType(),description:stringType().default(""),emoji:stringType().default("📦"),icon:stringType().default(""),tags:arrayType(stringType()).default([]),pinned:booleanType().default(!1)});objectType({agentId:stringType(),apps:arrayType(AppEntrySchema)});objectType({agentId:stringType(),viewId:stringType(),content:stringType()});const Card$1=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("rounded-lg border border-border bg-card text-card-foreground shadow-sm",t),...a}));Card$1.displayName="Card";const CardHeader=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("flex flex-col space-y-1.5 p-4 pb-2",t),...a}));CardHeader.displayName="CardHeader";const CardTitle=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("h3",{ref:l,className:cn("text-base font-semibold leading-none tracking-tight",t),...a}));CardTitle.displayName="CardTitle";const CardDescription=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("p",{ref:l,className:cn("text-sm text-muted-foreground",t),...a}));CardDescription.displayName="CardDescription";const CardContent=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("p-4 pt-0",t),...a}));CardContent.displayName="CardContent";const CardFooter=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("flex items-center p-4 pt-0",t),...a}));CardFooter.displayName="CardFooter";function Card({title:t,children:a}){return jsxRuntimeExports.jsxs(Card$1,{children:[t&&jsxRuntimeExports.jsx(CardHeader,{children:jsxRuntimeExports.jsx(CardTitle,{children:t})}),jsxRuntimeExports.jsx(CardContent,{className:t?"":"pt-4",children:a})]})}function Column({gap:t=2,children:a,className:l}){const o=`gap-${t}`;return jsxRuntimeExports.jsx("div",{className:cn("flex flex-col",o,l),children:a})}const alignMap={start:"items-start",center:"items-center",end:"items-end",stretch:"items-stretch"},justifyMap={start:"justify-start",center:"justify-center",end:"justify-end",between:"justify-between",around:"justify-around"};function Row({gap:t=2,align:a="center",justify:l="start",children:o,className:u}){return jsxRuntimeExports.jsx("div",{className:cn("flex flex-row",`gap-${t}`,alignMap[a],justifyMap[l],u),children:o})}const levelStyles={1:"text-2xl font-bold tracking-tight",2:"text-xl font-semibold tracking-tight",3:"text-lg font-semibold",4:"text-base font-medium",5:"text-sm font-medium",6:"text-sm font-medium text-muted-foreground"};function Heading({level:t=2,children:a,className:l}){const o=`h${t}`;return jsxRuntimeExports.jsx(o,{className:cn(levelStyles[t],l),children:a})}const Input=reactExports.forwardRef(({className:t,type:a,...l},o)=>jsxRuntimeExports.jsx("input",{type:a,className:cn("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:o,...l}));Input.displayName="Input";const FormContext=reactExports.createContext(null);function useFormContext(){const t=reactExports.useContext(FormContext);return t||{values:{},setValue:()=>{},reset:()=>{}}}function FormProvider({children:t}){const[a,l]=reactExports.useState({}),o=(c,d)=>{l(m=>({...m,[c]:d}))},u=()=>{l({})};return jsxRuntimeExports.jsx(FormContext.Provider,{value:{values:a,setValue:o,reset:u},children:t})}function TextInput({name:t,type:a="text",placeholder:l}){const{values:o,setValue:u}=useFormContext(),c=o[t]??"";return jsxRuntimeExports.jsx(Input,{type:a,name:t,placeholder:l,value:c,onChange:d=>u(t,d.target.value)})}function IntentFormInner({intent:t,submitLabel:a="Submit",children:l}){const{values:o,reset:u}=useFormContext(),{sendIntent:c}=useClappContext(),d=m=>{m.preventDefault(),c(t,o),u()};return jsxRuntimeExports.jsxs("form",{onSubmit:d,className:"flex flex-col gap-3",children:[l,jsxRuntimeExports.jsx(Button,{type:"submit",className:"self-start",children:a})]})}function IntentForm(t){return jsxRuntimeExports.jsx(FormProvider,{children:jsxRuntimeExports.jsx(IntentFormInner,{...t})})}function IntentButton({intent:t,payload:a={},variant:l="outline",size:o="default",label:u,children:c}){const{emit:d}=useIntent(),m=l==="primary"?"default":l;return jsxRuntimeExports.jsx(Button,{variant:m,size:o,onClick:()=>d(t,a),children:c||u})}function Skeleton$1({className:t,...a}){return jsxRuntimeExports.jsx("div",{className:cn("animate-pulse rounded-md bg-muted",t),...a})}function Skeleton(){return jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2 py-2",children:[jsxRuntimeExports.jsx(Skeleton$1,{className:"h-4 w-4/5"}),jsxRuntimeExports.jsx(Skeleton$1,{className:"h-4 w-3/5"}),jsxRuntimeExports.jsx(Skeleton$1,{className:"h-4 w-4/5"})]})}function List({data:t,onItemClick:a,active:l,children:o,className:u}){const c=useClappState(t||"_empty_")??[],d=useClappState(l||"_empty_"),{emit:m}=useIntent();return t?c.length===0?jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground py-4 text-center",children:"No items"}):jsxRuntimeExports.jsx("ul",{className:cn("flex flex-col gap-1",u),children:c.map((p,g)=>{const x=typeof p=="object"&&p!==null,b=x?p:null,C=String(b?b.text??JSON.stringify(p):p),R=b!=null&&b.role?String(b.role):void 0,j=b!=null&&b.id?String(b.id):`${g}`,B=p===d;return jsxRuntimeExports.jsx("li",{className:cn("flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors",a&&"cursor-pointer",B?"bg-accent text-accent-foreground":"hover:bg-accent/50",R==="assistant"&&"bg-muted/50",R==="user"&&"bg-primary/10"),onClick:a?()=>m(a,x?p:{value:p}):void 0,role:a?"button":void 0,children:C},j)})}):jsxRuntimeExports.jsx("ul",{className:cn("flex flex-col gap-1",u),children:o})}function ListItem({active:t,children:a,className:l,onClick:o}){return jsxRuntimeExports.jsx("li",{className:cn("flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors cursor-pointer",t?"bg-accent text-accent-foreground":"hover:bg-accent/50",l),onClick:o,children:a})}function Conditional({when:t,children:a}){const l=(t==null?void 0:t.startsWith("!"))??!1,o=l?t.slice(1):t??"",u=useClappState(o||"_empty_");return(l?!u:!!u)?jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment,{children:a}):null}function MarkdownContent({source:t,content:a,className:l}){const o=useClappState(t||"_empty_"),u=a??o??"";return u?jsxRuntimeExports.jsx("div",{className:cn("prose prose-invert prose-sm max-w-none",l),children:jsxRuntimeExports.jsx(Markdown,{components:{h1:({children:c})=>jsxRuntimeExports.jsx("h1",{className:"text-xl font-bold mt-4 mb-2",children:c}),h2:({children:c})=>jsxRuntimeExports.jsx("h2",{className:"text-lg font-semibold mt-3 mb-2",children:c}),h3:({children:c})=>jsxRuntimeExports.jsx("h3",{className:"text-base font-semibold mt-2 mb-1",children:c}),p:({children:c})=>jsxRuntimeExports.jsx("p",{className:"my-2 text-sm leading-relaxed",children:c}),ul:({children:c})=>jsxRuntimeExports.jsx("ul",{className:"list-disc list-inside my-2 text-sm",children:c}),ol:({children:c})=>jsxRuntimeExports.jsx("ol",{className:"list-decimal list-inside my-2 text-sm",children:c}),li:({children:c})=>jsxRuntimeExports.jsx("li",{className:"my-0.5",children:c}),code:({children:c,className:d})=>!d?jsxRuntimeExports.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-mono",children:c}):jsxRuntimeExports.jsx("code",{className:d,children:c}),pre:({children:c})=>jsxRuntimeExports.jsx("pre",{className:"bg-card border border-border rounded-md p-3 overflow-x-auto my-2 text-xs",children:c}),blockquote:({children:c})=>jsxRuntimeExports.jsx("blockquote",{className:"border-l-2 border-primary pl-3 my-2 text-muted-foreground italic",children:c}),a:({href:c,children:d})=>jsxRuntimeExports.jsx("a",{href:c,className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",children:d}),strong:({children:c})=>jsxRuntimeExports.jsx("strong",{className:"font-semibold",children:c}),em:({children:c})=>jsxRuntimeExports.jsx("em",{className:"italic",children:c})},children:u})}):null}function Icon({name:t,emoji:a,className:l}){return a?jsxRuntimeExports.jsx("span",{className:cn("text-base leading-none",l),children:a}):t?jsxRuntimeExports.jsx("span",{className:cn("text-base leading-none",l),children:"•"}):null}function ChatMessages({messages:t,loading:a,loadingText:l="Thinking...",hasMore:o=!1,loadingOlder:u=!1,onLoadOlder:c}){const d=reactExports.useRef(null),m=reactExports.useRef(null),p=reactExports.useRef(!0);reactExports.useEffect(()=>{t.length===0&&(p.current=!0)},[t.length]),reactExports.useEffect(()=>{var C,R;const x=d.current;if(!x)return;if(p.current&&t.length>0){p.current=!1,(C=m.current)==null||C.scrollIntoView({behavior:"instant"});return}(x.scrollHeight-x.scrollTop-x.clientHeight<200||a)&&((R=m.current)==null||R.scrollIntoView({behavior:"smooth",block:"end"}))},[t,a]);const g=()=>{const x=d.current;!x||!o||u||!c||x.scrollTop<120&&c()};return t.length===0&&!a?jsxRuntimeExports.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:jsxRuntimeExports.jsxs("div",{className:"text-center max-w-md",children:[jsxRuntimeExports.jsx("h2",{className:"text-2xl font-semibold mb-2",children:"What can I do for you?"}),jsxRuntimeExports.jsx("p",{className:"text-muted-foreground",children:"Start a conversation by typing a message below."})]})}):jsxRuntimeExports.jsx("div",{ref:d,onScroll:g,className:"flex-1 overflow-y-auto",children:jsxRuntimeExports.jsxs("div",{className:"max-w-3xl mx-auto px-4 py-6 space-y-6",children:[u&&jsxRuntimeExports.jsx("div",{className:"text-center text-xs text-muted-foreground",children:"Loading older messages…"}),o&&!u&&jsxRuntimeExports.jsx("div",{className:"text-center text-xs text-muted-foreground",children:"Scroll up to load older messages"}),t.map(x=>jsxRuntimeExports.jsx(MessageBubble,{message:x},x.id)),a&&jsxRuntimeExports.jsxs("div",{className:"flex items-start gap-4",children:[jsxRuntimeExports.jsx("div",{className:"shrink-0 w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:jsxRuntimeExports.jsx(Bot,{className:"h-4 w-4 text-primary"})}),jsxRuntimeExports.jsx("div",{className:"flex-1 pt-1",children:jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),jsxRuntimeExports.jsx("span",{className:"text-sm line-clamp-2",children:l})]})})]}),jsxRuntimeExports.jsx("div",{ref:m})]})})}function MessageBubble({message:t}){const a=t.role==="user";return t.role==="system"?jsxRuntimeExports.jsx("div",{className:"text-center",children:jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground bg-muted px-3 py-1 rounded-full",children:t.content})}):jsxRuntimeExports.jsxs("div",{className:cn("flex items-start gap-4",a&&"flex-row-reverse"),children:[jsxRuntimeExports.jsx("div",{className:cn("shrink-0 w-8 h-8 rounded-full flex items-center justify-center",a?"bg-primary text-primary-foreground":"bg-primary/10"),children:a?jsxRuntimeExports.jsx(User,{className:"h-4 w-4"}):jsxRuntimeExports.jsx(Bot,{className:"h-4 w-4 text-primary"})}),jsxRuntimeExports.jsx("div",{className:cn("flex-1 min-w-0 pt-1",a&&"text-right"),children:jsxRuntimeExports.jsxs("div",{className:cn("inline-block text-left rounded-2xl px-4 py-2 max-w-full",a?"bg-primary text-primary-foreground rounded-tr-sm":"bg-muted rounded-tl-sm"),children:[t.attachments&&t.attachments.length>0&&jsxRuntimeExports.jsxs("div",{className:"mb-2 space-y-2",children:[jsxRuntimeExports.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.attachments.filter(o=>o.type==="image").map(o=>jsxRuntimeExports.jsx("a",{href:o.url,target:"_blank",rel:"noreferrer",children:jsxRuntimeExports.jsx("img",{src:o.url,alt:o.name,className:"rounded-md border border-black/10 dark:border-white/10 max-h-52 object-cover",loading:"lazy"})},o.id))}),t.attachments.filter(o=>o.type==="file").map(o=>jsxRuntimeExports.jsxs("a",{href:o.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 rounded-md border border-black/10 dark:border-white/10 px-2 py-1.5 text-xs hover:bg-black/5 dark:hover:bg-white/5",children:[jsxRuntimeExports.jsx(Paperclip,{className:"h-3.5 w-3.5"}),jsxRuntimeExports.jsx("span",{className:"truncate",children:o.name})]},o.id))]}),t.content&&jsxRuntimeExports.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none break-words",children:jsxRuntimeExports.jsx(Markdown,{components:{code:({className:o,children:u,...c})=>o?jsxRuntimeExports.jsx("pre",{className:"bg-black/10 dark:bg-white/10 p-3 rounded-lg overflow-x-auto my-2",children:jsxRuntimeExports.jsx("code",{className:"text-sm",...c,children:u})}):jsxRuntimeExports.jsx("code",{className:"bg-black/10 dark:bg-white/10 px-1 py-0.5 rounded text-sm",...c,children:u}),p:({children:o})=>jsxRuntimeExports.jsx("p",{className:"mb-2 last:mb-0",children:o})},children:t.content})})]})})]})}function ChatInput({onSend:t,disabled:a=!1,placeholder:l="Message..."}){const[o,u]=reactExports.useState(""),[c,d]=reactExports.useState([]),m=reactExports.useRef(null),p=reactExports.useRef(null);reactExports.useEffect(()=>{const L=m.current;L&&(L.style.height="auto",L.style.height=`${Math.min(L.scrollHeight,200)}px`)},[o]);const g=L=>new Promise((D,$)=>{const F=new FileReader;F.onload=()=>D(String(F.result??"")),F.onerror=()=>$(new Error(`Failed to read file: ${L.name}`)),F.readAsDataURL(L)}),x=async L=>{if(!L.length)return;const D=await Promise.all(L.map(async($,F)=>{const oe=await g($);return{id:`file-${Date.now()}-${F}`,name:$.name||`attachment-${Date.now()}`,mimeType:$.type||"application/octet-stream",size:$.size,dataUrl:oe,isImage:$.type.startsWith("image/")}}));d($=>[...$,...D])},b=async L=>{var oe;const $=Array.from(((oe=L.clipboardData)==null?void 0:oe.items)??[]).filter(ie=>ie.type.startsWith("image/"));if(!$.length)return;L.preventDefault();const F=$.map(ie=>ie.getAsFile()).filter(Boolean);await x(F)},C=async L=>{const D=Array.from(L.target.files??[]);await x(D),L.target.value=""},R=()=>{const L=o.trim();!L&&c.length===0||a||(t(L,c.map(({id:D,isImage:$,...F})=>F)),u(""),d([]),m.current&&(m.current.style.height="auto"))},j=L=>d(D=>D.filter($=>$.id!==L)),B=L=>{L.key==="Enter"&&!L.shiftKey&&(L.preventDefault(),R())};return jsxRuntimeExports.jsx("div",{className:"shrink-0 border-t border-border bg-background",children:jsxRuntimeExports.jsxs("div",{className:"max-w-3xl mx-auto p-4",children:[!!c.length&&jsxRuntimeExports.jsx("div",{className:"mb-2 flex flex-wrap gap-2",children:c.map(L=>jsxRuntimeExports.jsxs("div",{className:"relative rounded-md border bg-muted/40 overflow-hidden",children:[L.isImage?jsxRuntimeExports.jsx("img",{src:L.dataUrl,alt:L.name,className:"h-16 w-16 object-cover"}):jsxRuntimeExports.jsxs("div",{className:"h-16 min-w-40 px-2 flex items-center gap-2 text-xs",children:[jsxRuntimeExports.jsx(Paperclip,{className:"h-3.5 w-3.5"}),jsxRuntimeExports.jsx("span",{className:"truncate max-w-28",children:L.name})]}),jsxRuntimeExports.jsx("button",{onClick:()=>j(L.id),className:"absolute top-0.5 right-0.5 rounded-full bg-black/70 text-white p-0.5",title:"Remove",children:jsxRuntimeExports.jsx(X,{className:"h-3 w-3"})})]},L.id))}),jsxRuntimeExports.jsxs("div",{className:cn("flex items-end gap-2 rounded-2xl border border-border bg-muted/30 p-2","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/20",a&&"opacity-60"),children:[jsxRuntimeExports.jsx("input",{ref:p,type:"file",multiple:!0,onChange:C,className:"hidden",accept:"image/*,.pdf,.txt,.md,.csv,.json,.doc,.docx,.xls,.xlsx,.ppt,.pptx"}),jsxRuntimeExports.jsx("button",{onClick:()=>{var L;return(L=p.current)==null?void 0:L.click()},className:"shrink-0 p-2 rounded-xl bg-background border border-border hover:bg-muted transition-colors",title:"Add photos & files",children:jsxRuntimeExports.jsx(Plus,{className:"h-4 w-4"})}),jsxRuntimeExports.jsx("textarea",{ref:m,value:o,onChange:L=>u(L.target.value),onKeyDown:B,onPaste:b,placeholder:l,disabled:a,rows:1,className:cn("flex-1 resize-none bg-transparent px-2 py-1.5 text-sm","placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed")}),jsxRuntimeExports.jsx("button",{onClick:R,disabled:a||!o.trim()&&c.length===0,className:cn("shrink-0 p-2 rounded-xl transition-colors","bg-primary text-primary-foreground hover:bg-primary/90","disabled:opacity-50 disabled:cursor-not-allowed"),children:jsxRuntimeExports.jsx(Send,{className:"h-4 w-4"})})]}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground text-center mt-2",children:"Enter to send • Shift+Enter newline • Paste images or use + for files"})]})})}function ChatLayout(){const t=useClappState("chat"),a=(t==null?void 0:t.sessions)??[],l=t==null?void 0:t.activeSession,o=(t==null?void 0:t.messages)??[],u=(t==null?void 0:t.loading)??!1,c=(t==null?void 0:t.loadingText)??"Thinking...",d=(t==null?void 0:t.loadingOlder)??!1,m=(t==null?void 0:t.hasMore)??!1,{emit:p}=useIntent(),[g,x]=reactExports.useState(!1),[b,C]=reactExports.useState(null),R=reactExports.useRef(!1);reactExports.useEffect(()=>{l&&x(!1)},[l]),reactExports.useEffect(()=>{R.current||(R.current=!0,p("chat.init",{}))},[p]);const j=()=>{p("chat.newSession",{}),x(!1)},B=W=>{W!==l&&p("chat.switchSession",{sessionKey:W}),x(!1)},L=(W,ve)=>{ve.stopPropagation(),C(W),p("chat.deleteSession",{sessionKey:W}),setTimeout(()=>C(null),1e3)},[D,$]=reactExports.useState(null),F=(W,ve)=>{W.trim()&&$({id:`pending-${Date.now()}`,role:"user",content:W,timestamp:new Date().toISOString()}),p("chat.send",{text:W,attachments:ve??[]})};reactExports.useEffect(()=>{D&&o.some(W=>W.role==="user"&&W.content===D.content)&&$(null)},[o,D]);const oe=D?[...o,D]:o,ie=u||!!D,H=()=>{!d&&m&&p("chat.loadOlder",{})},xe=a.find(W=>W.key===l);return jsxRuntimeExports.jsxs("div",{className:"flex h-full bg-background",children:[g&&jsxRuntimeExports.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:()=>x(!1)}),jsxRuntimeExports.jsxs("aside",{className:cn("fixed lg:static inset-y-0 left-0 z-50 w-72 bg-muted/50 border-r border-border","transform transition-transform duration-200 ease-in-out","flex flex-col",g?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[jsxRuntimeExports.jsx("h2",{className:"font-semibold text-sm",children:"Chats"}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("button",{onClick:j,className:"p-2 rounded-md hover:bg-muted transition-colors",title:"New chat",children:jsxRuntimeExports.jsx(Plus,{className:"h-4 w-4"})}),jsxRuntimeExports.jsx("button",{onClick:()=>x(!1),className:"p-2 rounded-md hover:bg-muted transition-colors lg:hidden",children:jsxRuntimeExports.jsx(X,{className:"h-4 w-4"})})]})]}),jsxRuntimeExports.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:a.length===0?jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No conversations yet"}):jsxRuntimeExports.jsx("div",{className:"space-y-1",children:a.map(W=>jsxRuntimeExports.jsx("button",{onClick:()=>B(W.key),className:cn("w-full text-left p-3 rounded-lg transition-colors group","hover:bg-muted",W.key===l&&"bg-muted"),children:jsxRuntimeExports.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntimeExports.jsx(MessageSquare,{className:"h-4 w-4 mt-0.5 shrink-0 text-muted-foreground"}),jsxRuntimeExports.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntimeExports.jsx("div",{className:"text-sm font-medium truncate",children:W.title||"New conversation"}),jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:W.preview||"No messages"})]}),jsxRuntimeExports.jsx("button",{onClick:ve=>L(W.key,ve),className:cn("p-1 rounded opacity-0 group-hover:opacity-100 transition-opacity","hover:bg-destructive/20 hover:text-destructive",b===W.key&&"opacity-100"),title:"Delete conversation",children:jsxRuntimeExports.jsx(Trash2,{className:"h-3.5 w-3.5"})})]})},W.key))})})]}),jsxRuntimeExports.jsxs("main",{className:"flex-1 flex flex-col min-w-0",children:[jsxRuntimeExports.jsxs("header",{className:"flex items-center gap-3 px-4 py-3 border-b border-border shrink-0",children:[jsxRuntimeExports.jsx("button",{onClick:()=>x(!0),className:"p-2 -ml-2 rounded-md hover:bg-muted transition-colors lg:hidden",children:jsxRuntimeExports.jsx(Menu,{className:"h-5 w-5"})}),jsxRuntimeExports.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntimeExports.jsx("h1",{className:"font-semibold truncate",children:(xe==null?void 0:xe.title)||"New conversation"})})]}),jsxRuntimeExports.jsx(ChatMessages,{messages:oe,loading:ie,loadingText:c,hasMore:m,loadingOlder:d,onLoadOlder:H}),jsxRuntimeExports.jsx(ChatInput,{onSend:F,disabled:u})]})]})}const PROVIDER_CONFIGS=[{type:"anthropic",name:"Anthropic",description:"Claude models via API or subscription",authModes:[{mode:"api-key",label:"API Key",description:"Use your Anthropic API key (usage-based billing)",helpUrl:"https://console.anthropic.com/settings/keys",fields:[{name:"apiKey",label:"API Key",type:"password",placeholder:"sk-ant-api03-...",helpText:"Get your API key from the Anthropic Console"}]},{mode:"subscription",label:"Claude Subscription",description:"Use your Claude Pro/Max subscription",helpUrl:"https://docs.openclaw.ai/providers/anthropic#option-b-claude-setup-token",fields:[{name:"setupToken",label:"Setup Token",type:"textarea",placeholder:"Paste your setup token here...",helpText:"Run 'claude setup-token' in your terminal to generate this"}]}]},{type:"openai",name:"OpenAI",description:"GPT models via API or Codex subscription",authModes:[{mode:"api-key",label:"API Key",description:"Use your OpenAI API key (usage-based billing)",helpUrl:"https://platform.openai.com/api-keys",fields:[{name:"apiKey",label:"API Key",type:"password",placeholder:"sk-...",helpText:"Get your API key from the OpenAI dashboard"}]},{mode:"subscription",label:"Codex Subscription",description:"Use your ChatGPT Plus/Pro subscription via Codex",helpUrl:"https://docs.openclaw.ai/providers/openai#option-b-openai-code-codex-subscription",fields:[]}]},{type:"kimi-coding",name:"Kimi Coding",description:"Moonshot's Kimi K2 models for coding",authModes:[{mode:"api-key",label:"API Key",description:"Use your Kimi Coding API key",helpUrl:"https://platform.moonshot.cn/console/api-keys",fields:[{name:"apiKey",label:"API Key",type:"password",placeholder:"sk-...",helpText:"Get your API key from the Moonshot platform"}]}]}];function ProviderEditor({isOpen:t,onClose:a,editingProvider:l}){const{emit:o}=useIntent(),[u,c]=reactExports.useState("select"),[d,m]=reactExports.useState(null),[p,g]=reactExports.useState(null),[x,b]=reactExports.useState(""),[C,R]=reactExports.useState({}),[j,B]=reactExports.useState({}),[L,D]=reactExports.useState(!1),[$,F]=reactExports.useState(null);reactExports.useEffect(()=>{if(t){if(l){m(l.type);const T=l.authType==="subscription"||l.authType==="oauth"||l.mode==="oauth"?"subscription":"api-key";g(T),b(l.name),c("configure")}else c("select"),m(null),g(null),b("");R({}),B({}),F(null),D(!1),Ee(null),_e(""),ee(!1),de(!1)}},[t,l]);const oe=d?PROVIDER_CONFIGS.find(T=>T.type===d):null,ie=oe&&p?oe.authModes.find(T=>T.mode===p):null,H=T=>{m(T);const ue=PROVIDER_CONFIGS.find(pe=>pe.type===T);ue&&(g(ue.authModes[0].mode),b(ue.name)),c("configure")},xe=(T,ue)=>{R(pe=>({...pe,[T]:ue})),F(null)},W=T=>{B(ue=>({...ue,[T]:!ue[T]}))},ve=async()=>{var T,ue;if(!(!d||!p||!oe)){if(ie!=null&&ie.fields.length){for(const pe of ie.fields)if(!((T=C[pe.name])!=null&&T.trim())){F(`${pe.label} is required`);return}}D(!0),F(null);try{const pe=getIntentName(d,p),Se={customName:x.trim()||oe.name,profileId:l==null?void 0:l.id};for(const je of(ie==null?void 0:ie.fields)??[])Se[je.name]=(ue=C[je.name])==null?void 0:ue.trim();o(pe,Se),await new Promise(je=>setTimeout(je,1e3)),a()}catch(pe){F(pe instanceof Error?pe.message:"Failed to save provider")}finally{D(!1)}}},[G,Ee]=reactExports.useState(null),[be,_e]=reactExports.useState(""),[ye,ee]=reactExports.useState(!1),[P,de]=reactExports.useState(!1),se=async()=>{if(d){D(!0),F(null);try{const ue=await fetch("/api/oauth/init",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:d==="openai"?"openai-codex":d,customName:x.trim()||(oe==null?void 0:oe.name)})});if(!ue.ok){const Se=await ue.json();throw new Error(Se.error||"Failed to initiate OAuth")}const{authUrl:pe}=await ue.json();Ee(pe)}catch(T){console.error("[oauth] Failed:",T),F(T instanceof Error?T.message:"OAuth failed")}finally{D(!1)}}},Te=async()=>{G&&(await navigator.clipboard.writeText(G),ee(!0),setTimeout(()=>ee(!1),2e3))},O=async()=>{if(!be.trim()){F("Please paste the callback URL");return}D(!0),F(null);try{const T=await fetch("/api/oauth/callback",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({callbackUrl:be.trim()})}),ue=await T.json();if(!T.ok||!ue.success)throw new Error(ue.error||"OAuth callback failed");de(!0),setTimeout(()=>a(),2e3)}catch(T){console.error("[oauth] Callback failed:",T),F(T instanceof Error?T.message:"Failed to complete sign in")}finally{D(!1)}},q=()=>{Ee(null),_e(""),F(null)},ae=()=>{l&&confirm(`Delete "${l.name}"? This cannot be undone.`)&&(o("settings.deleteProvider",{profileId:l.id}),a())};return t?jsxRuntimeExports.jsxs("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center",children:[jsxRuntimeExports.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),jsxRuntimeExports.jsxs("div",{className:"relative w-full sm:max-w-md bg-background rounded-t-2xl sm:rounded-2xl shadow-xl max-h-[90vh] overflow-hidden flex flex-col animate-in slide-in-from-bottom-4 sm:slide-in-from-bottom-0 sm:zoom-in-95",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[jsxRuntimeExports.jsx("h2",{className:"text-lg font-semibold",children:l?"Edit Provider":"Add Provider"}),jsxRuntimeExports.jsx("button",{onClick:a,className:"p-1 rounded-full hover:bg-muted transition-colors","aria-label":"Close",children:jsxRuntimeExports.jsx(X,{className:"h-5 w-5"})})]}),jsxRuntimeExports.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[u==="select"&&jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Choose a provider to add:"}),PROVIDER_CONFIGS.map(T=>jsxRuntimeExports.jsxs("button",{onClick:()=>H(T.type),className:"w-full text-left p-4 rounded-lg border border-border hover:border-primary hover:bg-muted/50 transition-colors",children:[jsxRuntimeExports.jsx("div",{className:"font-medium",children:T.name}),jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground",children:T.description})]},T.type))]}),u==="configure"&&oe&&jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Display Name"}),jsxRuntimeExports.jsx("input",{type:"text",value:x,onChange:T=>b(T.target.value),placeholder:oe.name,className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-primary"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground",children:'Give this configuration a custom name (e.g., "Work Account", "Personal")'})]}),oe.authModes.length>1&&jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Authentication Method"}),jsxRuntimeExports.jsx("div",{className:"grid grid-cols-2 gap-2",children:oe.authModes.map(T=>jsxRuntimeExports.jsxs("button",{onClick:()=>g(T.mode),className:cn("p-3 rounded-lg border text-left transition-colors",p===T.mode?"border-primary bg-primary/10":"border-border hover:border-muted-foreground"),children:[jsxRuntimeExports.jsx("div",{className:"text-sm font-medium",children:T.label}),jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:T.description})]},T.mode))})]}),ie&&jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[ie.fields.length>0?ie.fields.map(T=>jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:T.label}),(l==null?void 0:l.maskedCredential)&&!C[T.name]&&jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 px-2 py-1 rounded mb-1",children:["Current: ",l.maskedCredential]}),T.type==="textarea"?jsxRuntimeExports.jsx("textarea",{value:C[T.name]??"",onChange:ue=>xe(T.name,ue.target.value),placeholder:l?"Enter new value to replace...":T.placeholder,rows:4,className:"w-full px-3 py-2 rounded-md border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary resize-none"}):jsxRuntimeExports.jsxs("div",{className:"relative",children:[jsxRuntimeExports.jsx("input",{type:T.type==="password"&&!j[T.name]?"password":"text",value:C[T.name]??"",onChange:ue=>xe(T.name,ue.target.value),placeholder:l?"Enter new value to replace...":T.placeholder,className:"w-full h-10 px-3 pr-10 rounded-md border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary"}),T.type==="password"&&jsxRuntimeExports.jsx("button",{type:"button",onClick:()=>W(T.name),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground",children:j[T.name]?jsxRuntimeExports.jsx(EyeOff,{className:"h-4 w-4"}):jsxRuntimeExports.jsx(Eye,{className:"h-4 w-4"})})]}),T.helpText&&jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground",children:T.helpText})]},T.name)):jsxRuntimeExports.jsx("div",{className:"space-y-3",children:P?jsxRuntimeExports.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[jsxRuntimeExports.jsx(CircleCheckBig,{className:"h-10 w-10 text-green-500"}),jsxRuntimeExports.jsx("p",{className:"text-sm font-medium",children:"Successfully connected!"}),jsxRuntimeExports.jsxs("p",{className:"text-xs text-muted-foreground",children:["Your ",oe.name," account has been linked."]})]}):G?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Step 1: Open this URL and sign in"}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[jsxRuntimeExports.jsx("input",{type:"text",value:G,readOnly:!0,className:"flex-1 h-9 px-3 rounded-md border border-input bg-muted text-xs font-mono truncate"}),jsxRuntimeExports.jsx(Button,{variant:"outline",size:"sm",onClick:Te,className:"shrink-0 h-9",children:ye?jsxRuntimeExports.jsx(Check,{className:"h-4 w-4"}):jsxRuntimeExports.jsx(Copy,{className:"h-4 w-4"})})]}),jsxRuntimeExports.jsxs("a",{href:G,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Open in new tab",jsxRuntimeExports.jsx(ExternalLink,{className:"h-3 w-3"})]})]}),jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Step 2: Paste the callback URL"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground",children:"After signing in, your browser will redirect to a page that may not load. Copy the full URL from your browser's address bar and paste it here."}),jsxRuntimeExports.jsx("input",{type:"text",value:be,onChange:T=>{_e(T.target.value),F(null)},placeholder:"http://127.0.0.1:1455/auth/callback?code=...&state=...",className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary"})]}),jsxRuntimeExports.jsx(Button,{onClick:O,disabled:L||!be.trim(),className:"w-full",children:L?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Completing..."]}):"Complete Sign In"}),jsxRuntimeExports.jsx("button",{onClick:q,className:"text-xs text-muted-foreground hover:text-foreground underline",children:"Start over"})]}):jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("p",{className:"text-sm text-muted-foreground",children:["Click the button below to start signing in with your ",oe.name," account."]}),jsxRuntimeExports.jsx(Button,{onClick:se,disabled:L,className:"w-full",children:L?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Preparing..."]}):`Sign in with ${oe.name}`})]})}),ie.helpUrl&&jsxRuntimeExports.jsxs("a",{href:ie.helpUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Learn more",jsxRuntimeExports.jsx(ExternalLink,{className:"h-3 w-3"})]})]}),$&&jsxRuntimeExports.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:$})]})]}),u==="configure"&&(ie==null?void 0:ie.fields.length)!==0&&jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-t border-border shrink-0",children:[l&&jsxRuntimeExports.jsx(Button,{variant:"destructive",onClick:ae,disabled:L,className:"mr-auto",children:"Delete"}),jsxRuntimeExports.jsx(Button,{variant:"outline",onClick:()=>l?a():c("select"),disabled:L,children:l?"Cancel":"Back"}),jsxRuntimeExports.jsx(Button,{onClick:ve,disabled:L,children:L?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Saving..."]}):l?"Update":"Add Provider"})]})]})]}):null}function getIntentName(t,a){var o;return((o={anthropic:{"api-key":"settings.setAnthropicKey",subscription:"settings.setClaudeToken"},openai:{"api-key":"settings.setOpenAIKey",subscription:"settings.startOAuth"},"kimi-coding":{"api-key":"settings.setKimiCodingKey",subscription:"settings.setKimiCodingKey"}}[t])==null?void 0:o[a])??"settings.addProvider"}function getProviderIdentifier(t){const[,a]=t.split(":");return a||t}function providerOptionLabel(t){return`${t.name} · ${getProviderIdentifier(t.id)}`}function ProviderList({data:t="configuredProviders"}){const a=useClappState(t)??[],l=useClappState("active.model")??"",o=useClappState("active.profileId")??"",{emit:u}=useIntent(),c=a.find(ee=>ee.active)??a[0],[d,m]=reactExports.useState(o||(c==null?void 0:c.id)||""),[p,g]=reactExports.useState(l??""),[x,b]=reactExports.useState(!1),[C,R]=reactExports.useState(!1),[j,B]=reactExports.useState(null),[L,D]=reactExports.useState(!1),[$,F]=reactExports.useState(null),oe=d!==(o||(c==null?void 0:c.id)||"")||p!==(l??"");reactExports.useEffect(()=>{!c&&!o||(!d||!x&&!oe)&&m(o||(c==null?void 0:c.id)||"")},[c,o,x,oe,d]),reactExports.useEffect(()=>{l&&(!p||!x&&!oe)&&g(l)},[l,x,p,oe]);const ie=reactExports.useMemo(()=>{const ee=a.find(P=>P.id===d);return(ee==null?void 0:ee.models)??[]},[a,d]);reactExports.useEffect(()=>{if(!ie.length)return;ie.some(P=>P.id===p)||g(ie[0].id)},[ie,p]);const H=d!==(o||(c==null?void 0:c.id)||""),xe=!!(p&&p!==l),W=H||xe;reactExports.useEffect(()=>{if(!x)return;const ee=o||(c==null?void 0:c.id)||"",P=ee.split(":")[0],de=d.split(":")[0],se=P===de||ee===d,Te=!xe||l===p&&l.length>0;se&&Te&&(b(!1),R(!1),B(null),m(ee),g(l??""))},[l,p,d,o,c,xe,x]),reactExports.useEffect(()=>{if(!x)return;const ee=setTimeout(()=>R(!0),1e4),P=setTimeout(()=>{b(!1),R(!1),B("Still applying took too long. Changes may still complete in the background.")},3e4);return()=>{clearTimeout(ee),clearTimeout(P)}},[x]);const ve=a.find(ee=>ee.id===d),G=ee=>{var se,Te;if(x)return;m(ee);const P=a.find(O=>O.id===ee),de=(Te=(se=P==null?void 0:P.models)==null?void 0:se[0])==null?void 0:Te.id;g(de||"")},Ee=()=>{!W||!p||x||(b(!0),R(!1),B(null),H&&u("settings.setActiveProfile",{profileId:d}),xe&&u("settings.setActiveModel",{model:p}))},be=()=>{F(null),D(!0)},_e=ee=>{const P=ee.id.split(":")[0],de={anthropic:"anthropic",openai:"openai","openai-codex":"openai","kimi-coding":"kimi-coding",moonshot:"kimi-coding"};F({id:ee.id,name:ee.name,type:de[P]??"anthropic",mode:ee.mode,authType:ee.authType,maskedCredential:ee.maskedCredential}),D(!0)},ye=()=>{D(!1),F(null)};return jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-3",children:[jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[jsxRuntimeExports.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"System Default"}),jsxRuntimeExports.jsx("p",{className:"text-sm font-medium",children:"Default model for new sessions"})]}),jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[jsxRuntimeExports.jsx("label",{className:"text-xs text-muted-foreground",children:"Provider"}),jsxRuntimeExports.jsxs("div",{className:"relative flex gap-2",children:[jsxRuntimeExports.jsxs("div",{className:"relative flex-1",children:[jsxRuntimeExports.jsx("select",{value:d,onChange:ee=>G(ee.target.value),disabled:x||a.length===0,className:"h-10 w-full appearance-none rounded-md border border-input bg-background pl-3 pr-10 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-70",children:a.length===0?jsxRuntimeExports.jsx("option",{value:"",children:"No providers configured"}):a.map(ee=>jsxRuntimeExports.jsx("option",{value:ee.id,children:providerOptionLabel(ee)},ee.id))}),jsxRuntimeExports.jsx(ChevronDown,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"})]}),ve&&jsxRuntimeExports.jsx("button",{type:"button",onClick:()=>_e(ve),disabled:x,className:cn("flex items-center justify-center h-10 w-10 rounded-md border border-input bg-background","hover:bg-muted transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),title:`Edit ${ve.name}`,children:jsxRuntimeExports.jsx(Pencil,{className:"h-4 w-4"})})]})]}),jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[jsxRuntimeExports.jsx("label",{className:"text-xs text-muted-foreground",children:"Model"}),jsxRuntimeExports.jsxs("div",{className:"relative",children:[jsxRuntimeExports.jsx("select",{value:p,onChange:ee=>g(ee.target.value),disabled:x||ie.length===0,className:"h-10 w-full appearance-none rounded-md border border-input bg-background pl-3 pr-10 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-70",children:ie.length===0?jsxRuntimeExports.jsx("option",{value:"",children:"No models available"}):ie.map(ee=>jsxRuntimeExports.jsx("option",{value:ee.id,children:ee.label},ee.id))}),jsxRuntimeExports.jsx(ChevronDown,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"})]})]}),ve&&jsxRuntimeExports.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground",children:[jsxRuntimeExports.jsxs("div",{children:[providerOptionLabel(ve),": ",ve.maskedCredential??"No credential"]}),jsxRuntimeExports.jsxs("div",{className:"opacity-70",children:["id: ",ve.id]})]}),jsxRuntimeExports.jsx("button",{type:"button",onClick:Ee,disabled:!W||!p||x,className:cn("inline-flex h-10 items-center justify-center gap-2 rounded-md border px-4 text-sm font-medium transition-colors","border-primary bg-primary text-primary-foreground hover:bg-primary/90","disabled:cursor-not-allowed disabled:opacity-60"),children:x?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),C?"Still applying…":"Updating model…"]}):W?"Save changes":jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(Check,{className:"h-4 w-4"}),"Up to date"]})}),j&&jsxRuntimeExports.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:j}),jsxRuntimeExports.jsx("div",{className:"pt-2 border-t border-border",children:jsxRuntimeExports.jsxs("button",{type:"button",onClick:be,className:cn("inline-flex h-10 w-full items-center justify-center gap-2 rounded-md border border-dashed border-border","text-sm font-medium text-muted-foreground","hover:border-primary hover:text-foreground hover:bg-muted/50 transition-colors"),children:[jsxRuntimeExports.jsx(Plus,{className:"h-4 w-4"}),"Add Provider"]})})]}),jsxRuntimeExports.jsx(ProviderEditor,{isOpen:L,onClose:ye,editingProvider:$})]})}function SessionList(){const t=useClappState("sessions"),a=(t==null?void 0:t.sessions)??[],l=t==null?void 0:t.globalModel,{emit:o}=useIntent(),[u,c]=reactExports.useState(!1),[d,m]=reactExports.useState(null),[p,g]=reactExports.useState(!1);reactExports.useEffect(()=>{o("settings.listSessions",{})},[o]);const x=()=>{c(!0),o("settings.listSessions",{}),setTimeout(()=>c(!1),1500)},b=L=>{m(L),o("settings.resetSessionModel",{sessionKey:L}),setTimeout(()=>m(null),2e3)},C=()=>{g(!0),o("settings.applyDefaultToAll",{}),setTimeout(()=>g(!1),3e3)},R=a.filter(L=>L.isOverride).length,j=a.find(L=>L.key==="agent:main:main")??a[0],B=!!(j!=null&&j.isOverride);return a.length===0?jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-3",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsx("div",{className:"space-y-1",children:jsxRuntimeExports.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Active Sessions"})}),jsxRuntimeExports.jsx("button",{onClick:x,disabled:u,className:"p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-50",title:"Refresh sessions",children:jsxRuntimeExports.jsx(RefreshCw,{className:cn("h-4 w-4",u&&"animate-spin")})})]}),jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground py-4 text-center border border-dashed border-border rounded-md",children:"No active sessions found"})]}):jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-3",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[jsxRuntimeExports.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Active Sessions"}),jsxRuntimeExports.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.length," session",a.length!==1?"s":"",R>0&&jsxRuntimeExports.jsxs("span",{className:"text-amber-500 ml-1",children:["• ",R," override",R!==1?"s":""]})]})]}),jsxRuntimeExports.jsx("button",{onClick:x,disabled:u,className:"p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-50",title:"Refresh sessions",children:jsxRuntimeExports.jsx(RefreshCw,{className:cn("h-4 w-4",u&&"animate-spin")})})]}),jsxRuntimeExports.jsxs("div",{className:cn("rounded-lg border p-3 space-y-2",B?"border-amber-500/50 bg-amber-500/5":"border-border bg-muted/30"),children:[jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground",children:"Model source of truth"}),jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[jsxRuntimeExports.jsxs("div",{className:"min-w-0",children:[jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-xs",children:"Global default"}),jsxRuntimeExports.jsx("div",{className:"font-medium truncate",children:l??"unknown"})]}),jsxRuntimeExports.jsxs("div",{className:"min-w-0 text-right",children:[jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-xs",children:"This session"}),jsxRuntimeExports.jsx("div",{className:"font-medium truncate",children:(j==null?void 0:j.model)??"unknown"})]})]}),j&&jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsx("span",{className:cn("text-xs",B?"text-amber-500":"text-green-600 dark:text-green-400"),children:B?"Session override is active":"Session matches global default"}),B&&jsxRuntimeExports.jsx("button",{onClick:()=>b(j.key),disabled:d===j.key,className:"shrink-0 px-2 py-1 text-xs rounded-md border border-border hover:bg-muted transition-colors disabled:opacity-50",children:d===j.key?"Resetting…":"Reset this session"})]})]}),jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:a.map(L=>jsxRuntimeExports.jsxs("div",{className:cn("flex items-start justify-between gap-2 p-3 rounded-lg border",L.isOverride?"border-amber-500/50 bg-amber-500/5":"border-border bg-muted/30"),children:[jsxRuntimeExports.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[L.isOverride?jsxRuntimeExports.jsx(TriangleAlert,{className:"h-4 w-4 text-amber-500 shrink-0"}):jsxRuntimeExports.jsx(Check,{className:"h-4 w-4 text-green-500 shrink-0"}),jsxRuntimeExports.jsx("span",{className:"text-sm font-medium truncate",children:L.label})]}),jsxRuntimeExports.jsxs("div",{className:"mt-1 ml-6",children:[jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:L.modelLabel}),L.isOverride&&jsxRuntimeExports.jsx("span",{className:"text-xs text-amber-500 ml-2",children:"(override)"})]})]}),L.isOverride&&jsxRuntimeExports.jsx("button",{onClick:()=>b(L.key),disabled:d===L.key,className:cn("shrink-0 px-2 py-1 text-xs rounded-md border border-border","hover:bg-muted transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),title:"Reset to system default",children:d===L.key?jsxRuntimeExports.jsx(LoaderCircle,{className:"h-3 w-3 animate-spin"}):jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-1",children:[jsxRuntimeExports.jsx(RotateCcw,{className:"h-3 w-3"}),"Reset"]})})]},L.key))}),R>0&&jsxRuntimeExports.jsx("button",{onClick:C,disabled:p,className:cn("w-full py-2 px-4 text-sm font-medium rounded-md","border border-amber-500/50 text-amber-600 dark:text-amber-400","hover:bg-amber-500/10 transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),children:p?jsxRuntimeExports.jsxs("span",{className:"flex items-center justify-center gap-2",children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Applying to all sessions..."]}):`Apply default to all ${R} override${R!==1?"s":""}`})]})}function AccountCard({item:t}){const{emit:a}=useIntent(),[l,o]=reactExports.useState(!1);return jsxRuntimeExports.jsx(Card$1,{className:cn("p-4",!t.enabled&&"opacity-60"),children:jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsxs("div",{className:"flex-1",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("span",{className:"font-semibold",children:t.id}),!t.enabled&&jsxRuntimeExports.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",children:"Disabled"})]}),jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground",children:t.mode==="socket"?"Socket Mode":"HTTP Mode"}),jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Token: ",t.botToken]})]}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("button",{onClick:()=>a("slack.disableAccount",{accountId:t.id}),className:"px-3 py-1 text-sm rounded-md bg-muted hover:bg-muted/80",children:t.enabled?"Disable":"Enable"}),l?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx("button",{onClick:()=>{a("slack.deleteAccount",{accountId:t.id}),o(!1)},className:"px-3 py-1 text-sm rounded-md bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Confirm"}),jsxRuntimeExports.jsx("button",{onClick:()=>o(!1),className:"px-3 py-1 text-sm rounded-md bg-muted hover:bg-muted/80",children:"Cancel"})]}):jsxRuntimeExports.jsx("button",{onClick:()=>o(!0),className:"px-3 py-1 text-sm rounded-md bg-destructive/20 text-destructive hover:bg-destructive/30",children:"Remove"})]})]})})}function AccountEditor({account:t}){const{emit:a}=useIntent(),l=useClappState("slack.saving")??!1,o=useClappState("slack.saveError")??null,u=useClappState("slack.saveSuccess")??null,[c,d]=reactExports.useState(!1),m=reactExports.useRef(l),[p,g]=reactExports.useState((t==null?void 0:t.id)||""),[x,b]=reactExports.useState((t==null?void 0:t.mode)||"socket"),[C,R]=reactExports.useState((t==null?void 0:t.botToken)||""),[j,B]=reactExports.useState((t==null?void 0:t.appToken)||""),[L,D]=reactExports.useState((t==null?void 0:t.signingSecret)||""),[$,F]=reactExports.useState((t==null?void 0:t.webhookPath)||"/slack/events");reactExports.useEffect(()=>{l&&!m.current||!l&&m.current&&d(!1),m.current=l},[l]),reactExports.useEffect(()=>{if(!c)return;const H=setTimeout(()=>d(!1),2e4);return()=>clearTimeout(H)},[c]);const oe=()=>{d(!0),a("slack.saveAccount",{accountId:p||"default",mode:x,botToken:C,appToken:x==="socket"?j:void 0,signingSecret:x==="http"?L:void 0,webhookPath:x==="http"?$:void 0})},ie=()=>{g(""),b("socket"),R(""),B(""),D(""),F("/slack/events")};return u?jsxRuntimeExports.jsx(Card$1,{className:"p-6",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsx("p",{className:"text-sm text-green-600 font-medium",children:u}),jsxRuntimeExports.jsx("div",{className:"flex justify-end",children:jsxRuntimeExports.jsx(Button,{type:"button",onClick:()=>a("slack.cancelEdit"),children:"Done"})})]})}):jsxRuntimeExports.jsx(Card$1,{className:"p-6",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Account ID"}),jsxRuntimeExports.jsx(Input,{value:p,onChange:H=>g(H.target.value),placeholder:"default",disabled:c})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Mode"}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2 mt-2",children:[jsxRuntimeExports.jsx(Button,{type:"button",variant:x==="socket"?"default":"outline",onClick:()=>b("socket"),disabled:c,children:"Socket Mode"}),jsxRuntimeExports.jsx(Button,{type:"button",variant:x==="http"?"default":"outline",onClick:()=>b("http"),disabled:c,children:"HTTP Events API"})]})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Bot Token"}),jsxRuntimeExports.jsx(Input,{value:C,onChange:H=>R(H.target.value),placeholder:"xoxb-...",type:"password",disabled:c})]}),x==="socket"&&jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"App Token"}),jsxRuntimeExports.jsx(Input,{value:j,onChange:H=>B(H.target.value),placeholder:"xapp-...",type:"password",disabled:c})]}),x==="http"&&jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Signing Secret"}),jsxRuntimeExports.jsx(Input,{value:L,onChange:H=>D(H.target.value),placeholder:"Signing secret",type:"password",disabled:c})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Webhook Path"}),jsxRuntimeExports.jsx(Input,{value:$,onChange:H=>F(H.target.value),placeholder:"/slack/events",disabled:c})]})]}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2 justify-end pt-2",children:[jsxRuntimeExports.jsx(Button,{type:"button",variant:"outline",onClick:ie,disabled:c,children:"Clear"}),jsxRuntimeExports.jsx(Button,{type:"button",onClick:oe,disabled:!C||c,children:c?"Saving…":"Save Account"})]}),o&&jsxRuntimeExports.jsx("p",{className:"text-xs text-rose-500",children:o})]})})}function ChannelList({channels:t}){const{emit:a}=useIntent();return!Array.isArray(t)||t.length===0?jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground text-center py-4",children:"No channels configured"}):jsxRuntimeExports.jsx("div",{className:"space-y-2",children:t.map(l=>jsxRuntimeExports.jsx(Card$1,{className:"p-4",children:jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsxs("div",{className:"flex-1",children:[jsxRuntimeExports.jsx("div",{className:"font-semibold",children:l.name||l.id}),jsxRuntimeExports.jsxs("div",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[l.requireMention!==void 0&&jsxRuntimeExports.jsxs("div",{children:["Require mention: ",l.requireMention?"Yes":"No"]}),l.users&&l.users.length>0&&jsxRuntimeExports.jsxs("div",{children:["Users: ",l.users.join(", ")]}),l.skills&&l.skills.length>0&&jsxRuntimeExports.jsxs("div",{children:["Skills: ",l.skills.join(", ")]})]})]}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx(Button,{size:"sm",variant:"outline",onClick:()=>a("slack.editChannel",{channelId:l.id}),children:jsxRuntimeExports.jsx(SquarePen,{className:"h-4 w-4"})}),jsxRuntimeExports.jsx(Button,{size:"sm",variant:"destructive",onClick:()=>a("slack.removeChannel",{channelId:l.id}),children:jsxRuntimeExports.jsx(Trash2,{className:"h-4 w-4"})})]})]})},l.id))})}function ChannelEditor({channel:t,onClose:a}){const{emit:l}=useIntent(),[o,u]=reactExports.useState((t==null?void 0:t.id)||""),[c,d]=reactExports.useState((t==null?void 0:t.requireMention)??!0),[m,p]=reactExports.useState(((t==null?void 0:t.users)||[]).join(", ")),[g,x]=reactExports.useState(((t==null?void 0:t.skills)||[]).join(", ")),b=()=>{l("slack.saveChannel",{channelId:o,requireMention:c,users:m.split(",").map(C=>C.trim()).filter(Boolean),skills:g.split(",").map(C=>C.trim()).filter(Boolean)}),a==null||a()};return jsxRuntimeExports.jsx(Card$1,{className:"p-6 max-w-2xl mx-auto",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsx("h2",{className:"text-xl font-semibold",children:t?"Edit Channel":"Add Channel"}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Channel ID"}),jsxRuntimeExports.jsx(Input,{value:o,onChange:C=>u(C.target.value),placeholder:"C1234567890",disabled:!!t}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Use Slack channel ID or name"})]}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("input",{type:"checkbox",checked:c,onChange:C=>d(C.target.checked),id:"requireMention",className:"rounded border-gray-300"}),jsxRuntimeExports.jsx("label",{htmlFor:"requireMention",className:"text-sm font-medium cursor-pointer",children:"Require mention to respond"})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Allowed Users (optional)"}),jsxRuntimeExports.jsx(Input,{value:m,onChange:C=>p(C.target.value),placeholder:"user:U123, user:U456"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of user IDs or names"})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Custom Skills (optional)"}),jsxRuntimeExports.jsx(Input,{value:g,onChange:C=>x(C.target.value),placeholder:"weather, calendar"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of skill IDs"})]}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2 justify-end pt-4",children:[a&&jsxRuntimeExports.jsx(Button,{variant:"outline",onClick:a,children:"Cancel"}),jsxRuntimeExports.jsx(Button,{onClick:b,disabled:!o,children:"Save Channel"})]})]})})}function PolicySelector({value:t,type:a}){const{emit:l}=useIntent(),o=a==="dm"?[{value:"pairing",label:"Pairing (default)"},{value:"allowlist",label:"Allowlist"},{value:"open",label:"Open"},{value:"disabled",label:"Disabled"}]:[{value:"open",label:"Open"},{value:"allowlist",label:"Allowlist (recommended)"},{value:"disabled",label:"Disabled"}],u=c=>{a==="dm"?l("slack.setDmPolicy",{policy:c}):l("slack.setGroupPolicy",{policy:c})};return jsxRuntimeExports.jsx("select",{value:t,onChange:c=>u(c.target.value),className:"w-full px-3 py-2 border rounded-md bg-background",children:o.map(c=>jsxRuntimeExports.jsx("option",{value:c.value,children:c.label},c.value))})}function FeatureToggles({actions:t}){const{emit:a}=useIntent(),l=[{key:"messages",label:"Messages"},{key:"reactions",label:"Reactions"},{key:"pins",label:"Pins"},{key:"memberInfo",label:"Member Info"},{key:"emojiList",label:"Emoji List"}],o=(u,c)=>{a("slack.toggleAction",{group:u,enabled:c})};return jsxRuntimeExports.jsx("div",{className:"space-y-3",children:l.map(u=>{const c=t[u.key]!==!1;return jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsx("span",{className:"text-sm font-medium",children:u.label}),jsxRuntimeExports.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[jsxRuntimeExports.jsx("input",{type:"checkbox",checked:c,onChange:d=>o(u.key,d.target.checked),className:"sr-only peer"}),jsxRuntimeExports.jsx("div",{className:"w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"})]})]},u.key)})})}function SlashCommandConfig({config:t}){const{emit:a}=useIntent(),[l,o]=reactExports.useState((t==null?void 0:t.enabled)||!1),[u,c]=reactExports.useState((t==null?void 0:t.name)||"openclaw"),d=()=>{a("slack.setSlashCommand",{enabled:l,name:u})};return jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("input",{type:"checkbox",checked:l,onChange:m=>o(m.target.checked),id:"slashEnabled",className:"rounded border-gray-300"}),jsxRuntimeExports.jsx("label",{htmlFor:"slashEnabled",className:"text-sm font-medium cursor-pointer",children:"Enable single slash command"})]}),l&&jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Command Name"}),jsxRuntimeExports.jsx(Input,{value:u,onChange:m=>c(m.target.value),placeholder:"openclaw"}),jsxRuntimeExports.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Register /",u," in Slack app settings"]})]}),jsxRuntimeExports.jsx(Button,{onClick:d,size:"sm",children:"Save"}),jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground mt-4 p-3 bg-muted rounded-md",children:[jsxRuntimeExports.jsx("p",{className:"font-medium mb-1",children:"Note:"}),jsxRuntimeExports.jsxs("p",{children:["For native command support, set"," ",jsxRuntimeExports.jsx("code",{className:"bg-background px-1 py-0.5 rounded",children:"channels.slack.commands.native: true"})," ","and register matching slash commands in Slack (use /agentstatus for the status command)."]})]})]})}function ConnectionStatus({status:t}){var o,u;if(!t)return jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),jsxRuntimeExports.jsx("span",{className:"text-sm",children:"Loading status..."})]});const a=((o=t.accounts)==null?void 0:o.filter(c=>c.connected).length)||0,l=((u=t.accounts)==null?void 0:u.length)||0;return jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:t.connected?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(CircleCheckBig,{className:"h-5 w-5 text-green-600"}),jsxRuntimeExports.jsx("span",{className:"font-medium",children:"Connected"})]}):jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(CircleX,{className:"h-5 w-5 text-red-600"}),jsxRuntimeExports.jsx("span",{className:"font-medium",children:"Disconnected"})]})}),t.accounts&&t.accounts.length>0&&jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsxs("div",{className:"text-sm text-muted-foreground",children:[a," of ",l," accounts connected"]}),jsxRuntimeExports.jsx("div",{className:"space-y-1",children:t.accounts.map(c=>jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.connected?jsxRuntimeExports.jsx(CircleCheckBig,{className:"h-3 w-3 text-green-600"}):jsxRuntimeExports.jsx(CircleX,{className:"h-3 w-3 text-red-600"}),jsxRuntimeExports.jsx("span",{children:c.id})]},c.id))})]})]})}const componentMap={Card,Column,Row,Heading,TextInput,IntentForm,IntentButton,Skeleton,List,ListItem,Conditional,MarkdownContent,Icon,ChatLayout,ChatMessages,ChatInput,ProviderList,ProviderEditor,SessionList,AccountCard,AccountEditor,ChannelList,ChannelEditor,PolicySelector,FeatureToggles,SlashCommandConfig,ConnectionStatus};function LayoutNodeRenderer({node:t,moduleMap:a}){if(t.component==="Module"&&t.props.ref&&a){const u=String(t.props.ref),c=a.get(u);return c?jsxRuntimeExports.jsx(LayoutNodeRenderer,{node:c,moduleMap:a}):jsxRuntimeExports.jsxs("div",{className:"text-destructive text-sm p-2",children:["Module not found: ",u]})}const l=componentMap[t.component];if(!l)return jsxRuntimeExports.jsxs("div",{className:"text-destructive text-sm p-2",children:["Unknown component: ",t.component]});const o=t.children.map((u,c)=>typeof u=="string"?jsxRuntimeExports.jsx("span",{children:u},c):jsxRuntimeExports.jsx(LayoutNodeRenderer,{node:u,moduleMap:a},c));return jsxRuntimeExports.jsx(l,{...t.props,children:o})}function AppRenderer({spec:t,modules:a}){const l=reactExports.useMemo(()=>{const o=new Map;for(const u of a)o.set(`${u.domain}/${u.name}`,u.layout);return o},[a]);return jsxRuntimeExports.jsx("div",{className:"h-full overflow-y-auto p-4","data-app":t.name,children:jsxRuntimeExports.jsx(LayoutNodeRenderer,{node:t.layout,moduleMap:l})})}function ClappRenderer({clappId:t,transport:a}){const l=window.location.origin;return jsxRuntimeExports.jsx(ClappProvider,{serverUrl:l,clappId:t,transport:a,children:jsxRuntimeExports.jsx("div",{className:"flex flex-col h-full",children:jsxRuntimeExports.jsx(DynamicView,{clappId:t,transport:a})})})}function DynamicView({clappId:t,transport:a}){const[l,o]=reactExports.useState({status:"loading"});reactExports.useEffect(()=>{a.sendIntent(t,`${t}.init`,{})},[t,a]);const u=reactExports.useCallback(async()=>{try{const c=await a.fetchView(`${t}.app`);if(!c){o({status:"no-view"});return}const d=parseAppMd(c),p=(await Promise.all(d.modules.map(async g=>{const x=g.replace("/","."),b=await a.fetchView(`${x}.view`);return b?parseViewMd(b):null}))).filter(g=>g!==null);o({status:"ready",appSpec:d,modules:p})}catch(c){o({status:"error",message:c instanceof Error?c.message:"Failed to load views"})}},[t,a]);switch(reactExports.useEffect(()=>(u(),a.onView(d=>{(d===`${t}.app`||d.endsWith(".view"))&&u()})),[u,a,t]),l.status){case"loading":return jsxRuntimeExports.jsx("div",{className:"h-full p-4 animate-pulse",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsx("div",{className:"h-8 w-40 rounded-md bg-muted"}),jsxRuntimeExports.jsxs("div",{className:"rounded-xl border border-border p-4 space-y-3",children:[jsxRuntimeExports.jsx("div",{className:"h-4 w-32 rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-10 w-full rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-10 w-full rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-10 w-36 rounded bg-muted"})]}),jsxRuntimeExports.jsxs("div",{className:"rounded-xl border border-border p-4 space-y-3",children:[jsxRuntimeExports.jsx("div",{className:"h-4 w-28 rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-20 w-full rounded bg-muted"})]})]})});case"no-view":return jsxRuntimeExports.jsx(StateInspector,{});case"error":return jsxRuntimeExports.jsxs("div",{className:"p-4",children:[jsxRuntimeExports.jsx("div",{className:"p-3 bg-destructive/10 text-destructive rounded-md text-sm",children:l.message}),jsxRuntimeExports.jsx("div",{className:"mt-4",children:jsxRuntimeExports.jsx(StateInspector,{})})]});case"ready":return jsxRuntimeExports.jsx(AppRenderer,{spec:l.appSpec,modules:l.modules})}}function StateInspector(){return jsxRuntimeExports.jsxs("div",{className:"p-4",children:[jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground mb-3 italic",children:"No view definition found. Showing raw state:"}),jsxRuntimeExports.jsx(StateTree,{})]})}function StateTree(){const{store:t}=useClappContext(),a=useStore(t,o=>o.state);return useClappLoading()?jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-sm",children:"Waiting for state..."}):!a||Object.keys(a).length===0?jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-sm",children:"No state available."}):jsxRuntimeExports.jsx("div",{className:"font-mono text-xs leading-relaxed",children:renderEntries(a,"")})}function renderEntries(t,a){return Object.entries(t).map(([l,o])=>{const u=a?`${a}.${l}`:l;return o!==null&&typeof o=="object"&&!Array.isArray(o)?jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"text-muted-foreground font-semibold",children:u}),jsxRuntimeExports.jsx("div",{className:"pl-4",children:renderEntries(o,u)})]},u):jsxRuntimeExports.jsxs("div",{className:"flex gap-2 py-0.5",children:[jsxRuntimeExports.jsxs("span",{className:"text-muted-foreground",children:[u,":"]}),jsxRuntimeExports.jsx("span",{children:typeof o=="string"?o:JSON.stringify(o)})]},u)})}function getServerUrl(){return window.location.origin}function AppRoutes({transport:t,apps:a}){return jsxRuntimeExports.jsxs(Routes,{children:[jsxRuntimeExports.jsx(Route,{path:"/",element:jsxRuntimeExports.jsx(AppLauncher,{transport:t,apps:a})}),jsxRuntimeExports.jsx(Route,{path:"/apps/:appId",element:jsxRuntimeExports.jsx(AppView,{transport:t,apps:a})})]})}function AppLauncher({transport:t,apps:a}){const l=useNavigate(),o=u=>{l(`/apps/${u}`)};return jsxRuntimeExports.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-y-auto",children:[jsxRuntimeExports.jsx("header",{className:"flex items-center justify-center px-4 py-3 border-b border-border shrink-0",children:jsxRuntimeExports.jsx("h1",{className:"text-lg font-bold tracking-tight",children:"clapps"})}),jsxRuntimeExports.jsx(HomeScreen,{apps:a,transport:t,onOpenApp:o})]})}function AppView({transport:t,apps:a}){const{appId:l}=useParams(),o=useNavigate(),u=()=>{o("/")},c=a.find(d=>d.id===l);return jsxRuntimeExports.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-hidden",children:[jsxRuntimeExports.jsxs("header",{className:"flex items-center px-4 py-3 border-b border-border shrink-0 min-h-[52px]",children:[jsxRuntimeExports.jsxs("button",{onClick:u,className:"flex items-center gap-0.5 text-primary text-sm font-medium -ml-1 pr-2","aria-label":"Back to home",children:[jsxRuntimeExports.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",className:"shrink-0",children:jsxRuntimeExports.jsx("path",{d:"M12.5 15L7.5 10L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Home"]}),jsxRuntimeExports.jsx("div",{className:"flex-1 text-center",children:jsxRuntimeExports.jsxs("span",{className:"text-sm font-semibold",children:[(c==null?void 0:c.emoji)&&jsxRuntimeExports.jsx("span",{className:"mr-1.5",children:c.emoji}),(c==null?void 0:c.name)??l]})}),jsxRuntimeExports.jsx("div",{className:"w-[60px]"})]}),l&&jsxRuntimeExports.jsx("div",{className:"flex-1 overflow-hidden",children:jsxRuntimeExports.jsx(ClappRenderer,{clappId:l,transport:t})})]})}function App(){const t=reactExports.useRef(void 0);t.current||(t.current=new ClappTransport({serverUrl:getServerUrl(),context:{platform:"web"}}));const a=t.current,[l,o]=reactExports.useState([]);return reactExports.useEffect(()=>{a.connect();const u=a.onApps(c=>{o(c)});return a.fetchApps().then(o).catch(()=>{}),()=>{u(),a.disconnect()}},[a]),jsxRuntimeExports.jsx("div",{className:"relative h-screen overflow-hidden bg-background",children:jsxRuntimeExports.jsx(BrowserRouter,{children:jsxRuntimeExports.jsx(AppRoutes,{transport:a,apps:l})})})}clientExports.createRoot(document.getElementById("root")).render(jsxRuntimeExports.jsx(reactExports.StrictMode,{children:jsxRuntimeExports.jsx(App,{})}));
|
|
283
|
+
`))}function p(R,j,B,L){const D=B.enter("tableCell"),$=B.enter("phrasing"),F=B.containerPhrasing(R,{...L,before:c,after:c});return $(),D(),F}function g(R,j){return markdownTable(R,{align:j,alignDelimiters:o,padding:l,stringLength:u})}function x(R,j,B){const L=R.children;let D=-1;const $=[],F=j.enter("table");for(;++D<L.length;)$[D]=b(L[D],j,B);return F(),$}function b(R,j,B){const L=R.children;let D=-1;const $=[],F=j.enter("tableRow");for(;++D<L.length;)$[D]=p(L[D],R,j,B);return F(),$}function C(R,j,B){let L=handle.inlineCode(R,j,B);return B.stack.includes("tableCell")&&(L=L.replace(/\|/g,"\\$&")),L}}function gfmTaskListItemFromMarkdown(){return{exit:{taskListCheckValueChecked:exitCheck,taskListCheckValueUnchecked:exitCheck,paragraph:exitParagraphWithTaskListItem}}}function gfmTaskListItemToMarkdown(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:listItemWithTaskListItem}}}function exitCheck(t){const a=this.stack[this.stack.length-2];a.type,a.checked=t.type==="taskListCheckValueChecked"}function exitParagraphWithTaskListItem(t){const a=this.stack[this.stack.length-2];if(a&&a.type==="listItem"&&typeof a.checked=="boolean"){const l=this.stack[this.stack.length-1];l.type;const o=l.children[0];if(o&&o.type==="text"){const u=a.children;let c=-1,d;for(;++c<u.length;){const m=u[c];if(m.type==="paragraph"){d=m;break}}d===l&&(o.value=o.value.slice(1),o.value.length===0?l.children.shift():l.position&&o.position&&typeof o.position.start.offset=="number"&&(o.position.start.column++,o.position.start.offset++,l.position.start=Object.assign({},o.position.start)))}}this.exit(t)}function listItemWithTaskListItem(t,a,l,o){const u=t.children[0],c=typeof t.checked=="boolean"&&u&&u.type==="paragraph",d="["+(t.checked?"x":" ")+"] ",m=l.createTracker(o);c&&m.move(d);let p=handle.listItem(t,a,l,{...o,...m.current()});return c&&(p=p.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,g)),p;function g(x){return x+d}}function gfmFromMarkdown(){return[gfmAutolinkLiteralFromMarkdown(),gfmFootnoteFromMarkdown(),gfmStrikethroughFromMarkdown(),gfmTableFromMarkdown(),gfmTaskListItemFromMarkdown()]}function gfmToMarkdown(t){return{extensions:[gfmAutolinkLiteralToMarkdown(),gfmFootnoteToMarkdown(t),gfmStrikethroughToMarkdown(),gfmTableToMarkdown(t),gfmTaskListItemToMarkdown()]}}const wwwPrefix={tokenize:tokenizeWwwPrefix,partial:!0},domain={tokenize:tokenizeDomain,partial:!0},path={tokenize:tokenizePath,partial:!0},trail={tokenize:tokenizeTrail,partial:!0},emailDomainDotTrail={tokenize:tokenizeEmailDomainDotTrail,partial:!0},wwwAutolink={name:"wwwAutolink",tokenize:tokenizeWwwAutolink,previous:previousWww},protocolAutolink={name:"protocolAutolink",tokenize:tokenizeProtocolAutolink,previous:previousProtocol},emailAutolink={name:"emailAutolink",tokenize:tokenizeEmailAutolink,previous:previousEmail},text={};function gfmAutolinkLiteral(){return{text}}let code=48;for(;code<123;)text[code]=emailAutolink,code++,code===58?code=65:code===91&&(code=97);text[43]=emailAutolink;text[45]=emailAutolink;text[46]=emailAutolink;text[95]=emailAutolink;text[72]=[emailAutolink,protocolAutolink];text[104]=[emailAutolink,protocolAutolink];text[87]=[emailAutolink,wwwAutolink];text[119]=[emailAutolink,wwwAutolink];function tokenizeEmailAutolink(t,a,l){const o=this;let u,c;return d;function d(b){return!gfmAtext(b)||!previousEmail.call(o,o.previous)||previousUnbalanced(o.events)?l(b):(t.enter("literalAutolink"),t.enter("literalAutolinkEmail"),m(b))}function m(b){return gfmAtext(b)?(t.consume(b),m):b===64?(t.consume(b),p):l(b)}function p(b){return b===46?t.check(emailDomainDotTrail,x,g)(b):b===45||b===95||asciiAlphanumeric(b)?(c=!0,t.consume(b),p):x(b)}function g(b){return t.consume(b),u=!0,p}function x(b){return c&&u&&asciiAlpha(o.previous)?(t.exit("literalAutolinkEmail"),t.exit("literalAutolink"),a(b)):l(b)}}function tokenizeWwwAutolink(t,a,l){const o=this;return u;function u(d){return d!==87&&d!==119||!previousWww.call(o,o.previous)||previousUnbalanced(o.events)?l(d):(t.enter("literalAutolink"),t.enter("literalAutolinkWww"),t.check(wwwPrefix,t.attempt(domain,t.attempt(path,c),l),l)(d))}function c(d){return t.exit("literalAutolinkWww"),t.exit("literalAutolink"),a(d)}}function tokenizeProtocolAutolink(t,a,l){const o=this;let u="",c=!1;return d;function d(b){return(b===72||b===104)&&previousProtocol.call(o,o.previous)&&!previousUnbalanced(o.events)?(t.enter("literalAutolink"),t.enter("literalAutolinkHttp"),u+=String.fromCodePoint(b),t.consume(b),m):l(b)}function m(b){if(asciiAlpha(b)&&u.length<5)return u+=String.fromCodePoint(b),t.consume(b),m;if(b===58){const C=u.toLowerCase();if(C==="http"||C==="https")return t.consume(b),p}return l(b)}function p(b){return b===47?(t.consume(b),c?g:(c=!0,p)):l(b)}function g(b){return b===null||asciiControl(b)||markdownLineEndingOrSpace(b)||unicodeWhitespace(b)||unicodePunctuation(b)?l(b):t.attempt(domain,t.attempt(path,x),l)(b)}function x(b){return t.exit("literalAutolinkHttp"),t.exit("literalAutolink"),a(b)}}function tokenizeWwwPrefix(t,a,l){let o=0;return u;function u(d){return(d===87||d===119)&&o<3?(o++,t.consume(d),u):d===46&&o===3?(t.consume(d),c):l(d)}function c(d){return d===null?l(d):a(d)}}function tokenizeDomain(t,a,l){let o,u,c;return d;function d(g){return g===46||g===95?t.check(trail,p,m)(g):g===null||markdownLineEndingOrSpace(g)||unicodeWhitespace(g)||g!==45&&unicodePunctuation(g)?p(g):(c=!0,t.consume(g),d)}function m(g){return g===95?o=!0:(u=o,o=void 0),t.consume(g),d}function p(g){return u||o||!c?l(g):a(g)}}function tokenizePath(t,a){let l=0,o=0;return u;function u(d){return d===40?(l++,t.consume(d),u):d===41&&o<l?c(d):d===33||d===34||d===38||d===39||d===41||d===42||d===44||d===46||d===58||d===59||d===60||d===63||d===93||d===95||d===126?t.check(trail,a,c)(d):d===null||markdownLineEndingOrSpace(d)||unicodeWhitespace(d)?a(d):(t.consume(d),u)}function c(d){return d===41&&o++,t.consume(d),u}}function tokenizeTrail(t,a,l){return o;function o(m){return m===33||m===34||m===39||m===41||m===42||m===44||m===46||m===58||m===59||m===63||m===95||m===126?(t.consume(m),o):m===38?(t.consume(m),c):m===93?(t.consume(m),u):m===60||m===null||markdownLineEndingOrSpace(m)||unicodeWhitespace(m)?a(m):l(m)}function u(m){return m===null||m===40||m===91||markdownLineEndingOrSpace(m)||unicodeWhitespace(m)?a(m):o(m)}function c(m){return asciiAlpha(m)?d(m):l(m)}function d(m){return m===59?(t.consume(m),o):asciiAlpha(m)?(t.consume(m),d):l(m)}}function tokenizeEmailDomainDotTrail(t,a,l){return o;function o(c){return t.consume(c),u}function u(c){return asciiAlphanumeric(c)?l(c):a(c)}}function previousWww(t){return t===null||t===40||t===42||t===95||t===91||t===93||t===126||markdownLineEndingOrSpace(t)}function previousProtocol(t){return!asciiAlpha(t)}function previousEmail(t){return!(t===47||gfmAtext(t))}function gfmAtext(t){return t===43||t===45||t===46||t===95||asciiAlphanumeric(t)}function previousUnbalanced(t){let a=t.length,l=!1;for(;a--;){const o=t[a][1];if((o.type==="labelLink"||o.type==="labelImage")&&!o._balanced){l=!0;break}if(o._gfmAutolinkLiteralWalkedInto){l=!1;break}}return t.length>0&&!l&&(t[t.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),l}const indent={tokenize:tokenizeIndent,partial:!0};function gfmFootnote(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:tokenizeDefinitionStart,continuation:{tokenize:tokenizeDefinitionContinuation},exit:gfmFootnoteDefinitionEnd}},text:{91:{name:"gfmFootnoteCall",tokenize:tokenizeGfmFootnoteCall},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:tokenizePotentialGfmFootnoteCall,resolveTo:resolveToPotentialGfmFootnoteCall}}}}function tokenizePotentialGfmFootnoteCall(t,a,l){const o=this;let u=o.events.length;const c=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let d;for(;u--;){const p=o.events[u][1];if(p.type==="labelImage"){d=p;break}if(p.type==="gfmFootnoteCall"||p.type==="labelLink"||p.type==="label"||p.type==="image"||p.type==="link")break}return m;function m(p){if(!d||!d._balanced)return l(p);const g=normalizeIdentifier(o.sliceSerialize({start:d.end,end:o.now()}));return g.codePointAt(0)!==94||!c.includes(g.slice(1))?l(p):(t.enter("gfmFootnoteCallLabelMarker"),t.consume(p),t.exit("gfmFootnoteCallLabelMarker"),a(p))}}function resolveToPotentialGfmFootnoteCall(t,a){let l=t.length;for(;l--;)if(t[l][1].type==="labelImage"&&t[l][0]==="enter"){t[l][1];break}t[l+1][1].type="data",t[l+3][1].type="gfmFootnoteCallLabelMarker";const o={type:"gfmFootnoteCall",start:Object.assign({},t[l+3][1].start),end:Object.assign({},t[t.length-1][1].end)},u={type:"gfmFootnoteCallMarker",start:Object.assign({},t[l+3][1].end),end:Object.assign({},t[l+3][1].end)};u.end.column++,u.end.offset++,u.end._bufferIndex++;const c={type:"gfmFootnoteCallString",start:Object.assign({},u.end),end:Object.assign({},t[t.length-1][1].start)},d={type:"chunkString",contentType:"string",start:Object.assign({},c.start),end:Object.assign({},c.end)},m=[t[l+1],t[l+2],["enter",o,a],t[l+3],t[l+4],["enter",u,a],["exit",u,a],["enter",c,a],["enter",d,a],["exit",d,a],["exit",c,a],t[t.length-2],t[t.length-1],["exit",o,a]];return t.splice(l,t.length-l+1,...m),t}function tokenizeGfmFootnoteCall(t,a,l){const o=this,u=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let c=0,d;return m;function m(b){return t.enter("gfmFootnoteCall"),t.enter("gfmFootnoteCallLabelMarker"),t.consume(b),t.exit("gfmFootnoteCallLabelMarker"),p}function p(b){return b!==94?l(b):(t.enter("gfmFootnoteCallMarker"),t.consume(b),t.exit("gfmFootnoteCallMarker"),t.enter("gfmFootnoteCallString"),t.enter("chunkString").contentType="string",g)}function g(b){if(c>999||b===93&&!d||b===null||b===91||markdownLineEndingOrSpace(b))return l(b);if(b===93){t.exit("chunkString");const C=t.exit("gfmFootnoteCallString");return u.includes(normalizeIdentifier(o.sliceSerialize(C)))?(t.enter("gfmFootnoteCallLabelMarker"),t.consume(b),t.exit("gfmFootnoteCallLabelMarker"),t.exit("gfmFootnoteCall"),a):l(b)}return markdownLineEndingOrSpace(b)||(d=!0),c++,t.consume(b),b===92?x:g}function x(b){return b===91||b===92||b===93?(t.consume(b),c++,g):g(b)}}function tokenizeDefinitionStart(t,a,l){const o=this,u=o.parser.gfmFootnotes||(o.parser.gfmFootnotes=[]);let c,d=0,m;return p;function p(j){return t.enter("gfmFootnoteDefinition")._container=!0,t.enter("gfmFootnoteDefinitionLabel"),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(j),t.exit("gfmFootnoteDefinitionLabelMarker"),g}function g(j){return j===94?(t.enter("gfmFootnoteDefinitionMarker"),t.consume(j),t.exit("gfmFootnoteDefinitionMarker"),t.enter("gfmFootnoteDefinitionLabelString"),t.enter("chunkString").contentType="string",x):l(j)}function x(j){if(d>999||j===93&&!m||j===null||j===91||markdownLineEndingOrSpace(j))return l(j);if(j===93){t.exit("chunkString");const B=t.exit("gfmFootnoteDefinitionLabelString");return c=normalizeIdentifier(o.sliceSerialize(B)),t.enter("gfmFootnoteDefinitionLabelMarker"),t.consume(j),t.exit("gfmFootnoteDefinitionLabelMarker"),t.exit("gfmFootnoteDefinitionLabel"),C}return markdownLineEndingOrSpace(j)||(m=!0),d++,t.consume(j),j===92?b:x}function b(j){return j===91||j===92||j===93?(t.consume(j),d++,x):x(j)}function C(j){return j===58?(t.enter("definitionMarker"),t.consume(j),t.exit("definitionMarker"),u.includes(c)||u.push(c),factorySpace(t,R,"gfmFootnoteDefinitionWhitespace")):l(j)}function R(j){return a(j)}}function tokenizeDefinitionContinuation(t,a,l){return t.check(blankLine,a,t.attempt(indent,a,l))}function gfmFootnoteDefinitionEnd(t){t.exit("gfmFootnoteDefinition")}function tokenizeIndent(t,a,l){const o=this;return factorySpace(t,u,"gfmFootnoteDefinitionIndent",5);function u(c){const d=o.events[o.events.length-1];return d&&d[1].type==="gfmFootnoteDefinitionIndent"&&d[2].sliceSerialize(d[1],!0).length===4?a(c):l(c)}}function gfmStrikethrough(t){let l=(t||{}).singleTilde;const o={name:"strikethrough",tokenize:c,resolveAll:u};return l==null&&(l=!0),{text:{126:o},insideSpan:{null:[o]},attentionMarkers:{null:[126]}};function u(d,m){let p=-1;for(;++p<d.length;)if(d[p][0]==="enter"&&d[p][1].type==="strikethroughSequenceTemporary"&&d[p][1]._close){let g=p;for(;g--;)if(d[g][0]==="exit"&&d[g][1].type==="strikethroughSequenceTemporary"&&d[g][1]._open&&d[p][1].end.offset-d[p][1].start.offset===d[g][1].end.offset-d[g][1].start.offset){d[p][1].type="strikethroughSequence",d[g][1].type="strikethroughSequence";const x={type:"strikethrough",start:Object.assign({},d[g][1].start),end:Object.assign({},d[p][1].end)},b={type:"strikethroughText",start:Object.assign({},d[g][1].end),end:Object.assign({},d[p][1].start)},C=[["enter",x,m],["enter",d[g][1],m],["exit",d[g][1],m],["enter",b,m]],R=m.parser.constructs.insideSpan.null;R&&splice(C,C.length,0,resolveAll(R,d.slice(g+1,p),m)),splice(C,C.length,0,[["exit",b,m],["enter",d[p][1],m],["exit",d[p][1],m],["exit",x,m]]),splice(d,g-1,p-g+3,C),p=g+C.length-2;break}}for(p=-1;++p<d.length;)d[p][1].type==="strikethroughSequenceTemporary"&&(d[p][1].type="data");return d}function c(d,m,p){const g=this.previous,x=this.events;let b=0;return C;function C(j){return g===126&&x[x.length-1][1].type!=="characterEscape"?p(j):(d.enter("strikethroughSequenceTemporary"),R(j))}function R(j){const B=classifyCharacter(g);if(j===126)return b>1?p(j):(d.consume(j),b++,R);if(b<2&&!l)return p(j);const L=d.exit("strikethroughSequenceTemporary"),D=classifyCharacter(j);return L._open=!D||D===2&&!!B,L._close=!B||B===2&&!!D,m(j)}}}class EditMap{constructor(){this.map=[]}add(a,l,o){addImplementation(this,a,l,o)}consume(a){if(this.map.sort(function(c,d){return c[0]-d[0]}),this.map.length===0)return;let l=this.map.length;const o=[];for(;l>0;)l-=1,o.push(a.slice(this.map[l][0]+this.map[l][1]),this.map[l][2]),a.length=this.map[l][0];o.push(a.slice()),a.length=0;let u=o.pop();for(;u;){for(const c of u)a.push(c);u=o.pop()}this.map.length=0}}function addImplementation(t,a,l,o){let u=0;if(!(l===0&&o.length===0)){for(;u<t.map.length;){if(t.map[u][0]===a){t.map[u][1]+=l,t.map[u][2].push(...o);return}u+=1}t.map.push([a,l,o])}}function gfmTableAlign(t,a){let l=!1;const o=[];for(;a<t.length;){const u=t[a];if(l){if(u[0]==="enter")u[1].type==="tableContent"&&o.push(t[a+1][1].type==="tableDelimiterMarker"?"left":"none");else if(u[1].type==="tableContent"){if(t[a-1][1].type==="tableDelimiterMarker"){const c=o.length-1;o[c]=o[c]==="left"?"center":"right"}}else if(u[1].type==="tableDelimiterRow")break}else u[0]==="enter"&&u[1].type==="tableDelimiterRow"&&(l=!0);a+=1}return o}function gfmTable(){return{flow:{null:{name:"table",tokenize:tokenizeTable,resolveAll:resolveTable}}}}function tokenizeTable(t,a,l){const o=this;let u=0,c=0,d;return m;function m(G){let Ee=o.events.length-1;for(;Ee>-1;){const ye=o.events[Ee][1].type;if(ye==="lineEnding"||ye==="linePrefix")Ee--;else break}const be=Ee>-1?o.events[Ee][1].type:null,_e=be==="tableHead"||be==="tableRow"?H:p;return _e===H&&o.parser.lazy[o.now().line]?l(G):_e(G)}function p(G){return t.enter("tableHead"),t.enter("tableRow"),g(G)}function g(G){return G===124||(d=!0,c+=1),x(G)}function x(G){return G===null?l(G):markdownLineEnding(G)?c>1?(c=0,o.interrupt=!0,t.exit("tableRow"),t.enter("lineEnding"),t.consume(G),t.exit("lineEnding"),R):l(G):markdownSpace(G)?factorySpace(t,x,"whitespace")(G):(c+=1,d&&(d=!1,u+=1),G===124?(t.enter("tableCellDivider"),t.consume(G),t.exit("tableCellDivider"),d=!0,x):(t.enter("data"),b(G)))}function b(G){return G===null||G===124||markdownLineEndingOrSpace(G)?(t.exit("data"),x(G)):(t.consume(G),G===92?C:b)}function C(G){return G===92||G===124?(t.consume(G),b):b(G)}function R(G){return o.interrupt=!1,o.parser.lazy[o.now().line]?l(G):(t.enter("tableDelimiterRow"),d=!1,markdownSpace(G)?factorySpace(t,j,"linePrefix",o.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(G):j(G))}function j(G){return G===45||G===58?L(G):G===124?(d=!0,t.enter("tableCellDivider"),t.consume(G),t.exit("tableCellDivider"),B):ie(G)}function B(G){return markdownSpace(G)?factorySpace(t,L,"whitespace")(G):L(G)}function L(G){return G===58?(c+=1,d=!0,t.enter("tableDelimiterMarker"),t.consume(G),t.exit("tableDelimiterMarker"),D):G===45?(c+=1,D(G)):G===null||markdownLineEnding(G)?oe(G):ie(G)}function D(G){return G===45?(t.enter("tableDelimiterFiller"),$(G)):ie(G)}function $(G){return G===45?(t.consume(G),$):G===58?(d=!0,t.exit("tableDelimiterFiller"),t.enter("tableDelimiterMarker"),t.consume(G),t.exit("tableDelimiterMarker"),F):(t.exit("tableDelimiterFiller"),F(G))}function F(G){return markdownSpace(G)?factorySpace(t,oe,"whitespace")(G):oe(G)}function oe(G){return G===124?j(G):G===null||markdownLineEnding(G)?!d||u!==c?ie(G):(t.exit("tableDelimiterRow"),t.exit("tableHead"),a(G)):ie(G)}function ie(G){return l(G)}function H(G){return t.enter("tableRow"),xe(G)}function xe(G){return G===124?(t.enter("tableCellDivider"),t.consume(G),t.exit("tableCellDivider"),xe):G===null||markdownLineEnding(G)?(t.exit("tableRow"),a(G)):markdownSpace(G)?factorySpace(t,xe,"whitespace")(G):(t.enter("data"),W(G))}function W(G){return G===null||G===124||markdownLineEndingOrSpace(G)?(t.exit("data"),xe(G)):(t.consume(G),G===92?ve:W)}function ve(G){return G===92||G===124?(t.consume(G),W):W(G)}}function resolveTable(t,a){let l=-1,o=!0,u=0,c=[0,0,0,0],d=[0,0,0,0],m=!1,p=0,g,x,b;const C=new EditMap;for(;++l<t.length;){const R=t[l],j=R[1];R[0]==="enter"?j.type==="tableHead"?(m=!1,p!==0&&(flushTableEnd(C,a,p,g,x),x=void 0,p=0),g={type:"table",start:Object.assign({},j.start),end:Object.assign({},j.end)},C.add(l,0,[["enter",g,a]])):j.type==="tableRow"||j.type==="tableDelimiterRow"?(o=!0,b=void 0,c=[0,0,0,0],d=[0,l+1,0,0],m&&(m=!1,x={type:"tableBody",start:Object.assign({},j.start),end:Object.assign({},j.end)},C.add(l,0,[["enter",x,a]])),u=j.type==="tableDelimiterRow"?2:x?3:1):u&&(j.type==="data"||j.type==="tableDelimiterMarker"||j.type==="tableDelimiterFiller")?(o=!1,d[2]===0&&(c[1]!==0&&(d[0]=d[1],b=flushCell(C,a,c,u,void 0,b),c=[0,0,0,0]),d[2]=l)):j.type==="tableCellDivider"&&(o?o=!1:(c[1]!==0&&(d[0]=d[1],b=flushCell(C,a,c,u,void 0,b)),c=d,d=[c[1],l,0,0])):j.type==="tableHead"?(m=!0,p=l):j.type==="tableRow"||j.type==="tableDelimiterRow"?(p=l,c[1]!==0?(d[0]=d[1],b=flushCell(C,a,c,u,l,b)):d[1]!==0&&(b=flushCell(C,a,d,u,l,b)),u=0):u&&(j.type==="data"||j.type==="tableDelimiterMarker"||j.type==="tableDelimiterFiller")&&(d[3]=l)}for(p!==0&&flushTableEnd(C,a,p,g,x),C.consume(a.events),l=-1;++l<a.events.length;){const R=a.events[l];R[0]==="enter"&&R[1].type==="table"&&(R[1]._align=gfmTableAlign(a.events,l))}return t}function flushCell(t,a,l,o,u,c){const d=o===1?"tableHeader":o===2?"tableDelimiter":"tableData",m="tableContent";l[0]!==0&&(c.end=Object.assign({},getPoint(a.events,l[0])),t.add(l[0],0,[["exit",c,a]]));const p=getPoint(a.events,l[1]);if(c={type:d,start:Object.assign({},p),end:Object.assign({},p)},t.add(l[1],0,[["enter",c,a]]),l[2]!==0){const g=getPoint(a.events,l[2]),x=getPoint(a.events,l[3]),b={type:m,start:Object.assign({},g),end:Object.assign({},x)};if(t.add(l[2],0,[["enter",b,a]]),o!==2){const C=a.events[l[2]],R=a.events[l[3]];if(C[1].end=Object.assign({},R[1].end),C[1].type="chunkText",C[1].contentType="text",l[3]>l[2]+1){const j=l[2]+1,B=l[3]-l[2]-1;t.add(j,B,[])}}t.add(l[3]+1,0,[["exit",b,a]])}return u!==void 0&&(c.end=Object.assign({},getPoint(a.events,u)),t.add(u,0,[["exit",c,a]]),c=void 0),c}function flushTableEnd(t,a,l,o,u){const c=[],d=getPoint(a.events,l);u&&(u.end=Object.assign({},d),c.push(["exit",u,a])),o.end=Object.assign({},d),c.push(["exit",o,a]),t.add(l+1,0,c)}function getPoint(t,a){const l=t[a],o=l[0]==="enter"?"start":"end";return l[1][o]}const tasklistCheck={name:"tasklistCheck",tokenize:tokenizeTasklistCheck};function gfmTaskListItem(){return{text:{91:tasklistCheck}}}function tokenizeTasklistCheck(t,a,l){const o=this;return u;function u(p){return o.previous!==null||!o._gfmTasklistFirstContentOfListItem?l(p):(t.enter("taskListCheck"),t.enter("taskListCheckMarker"),t.consume(p),t.exit("taskListCheckMarker"),c)}function c(p){return markdownLineEndingOrSpace(p)?(t.enter("taskListCheckValueUnchecked"),t.consume(p),t.exit("taskListCheckValueUnchecked"),d):p===88||p===120?(t.enter("taskListCheckValueChecked"),t.consume(p),t.exit("taskListCheckValueChecked"),d):l(p)}function d(p){return p===93?(t.enter("taskListCheckMarker"),t.consume(p),t.exit("taskListCheckMarker"),t.exit("taskListCheck"),m):l(p)}function m(p){return markdownLineEnding(p)?a(p):markdownSpace(p)?t.check({tokenize:spaceThenNonSpace},a,l)(p):l(p)}}function spaceThenNonSpace(t,a,l){return factorySpace(t,o,"whitespace");function o(u){return u===null?l(u):a(u)}}function gfm(t){return combineExtensions([gfmAutolinkLiteral(),gfmFootnote(),gfmStrikethrough(t),gfmTable(),gfmTaskListItem()])}const emptyOptions={};function remarkGfm(t){const a=this,l=t||emptyOptions,o=a.data(),u=o.micromarkExtensions||(o.micromarkExtensions=[]),c=o.fromMarkdownExtensions||(o.fromMarkdownExtensions=[]),d=o.toMarkdownExtensions||(o.toMarkdownExtensions=[]);u.push(gfm(l)),c.push(gfmFromMarkdown()),d.push(gfmToMarkdown(l))}function parseViewMd(t){const{data:a,content:l}=matter(t),o=unified().use(remarkParse).use(remarkGfm).parse(l),u=splitByH2$1(o);return{name:a.name??"",domain:a.domain??"",version:a.version??"0.1.0",stateBindings:parseStateBindings(u["State Bindings"]),layout:parseLayoutSection$1(u.Layout),intents:parseIntentsTable(u.Intents)}}function splitByH2$1(t){var o;const a={};let l="__intro__";a[l]=[];for(const u of t.children)u.type==="heading"&&u.depth===2?(l=getTextContent(u),a[l]=[]):(o=a[l])==null||o.push(u);return a}function getTextContent(t){return t.children.map(a=>a.type==="text"?a.value:"").join("")}function parseStateBindings(t){if(!t)return[];const a=[];for(const l of t){if(l.type!=="list")continue;const o=l;for(const u of o.children){const d=extractListItemText(u).match(/`([^`]+)`\s*->\s*(.+)/);d&&a.push({path:d[1],type:d[2].trim()})}}return a}function extractListItemText(t){return t.children.map(a=>a.type==="paragraph"?a.children.map(l=>l.type==="text"?l.value:l.type==="inlineCode"?`\`${l.value}\``:"").join(""):"").join("")}function parseLayoutSection$1(t){if(!t)throw new Error("Missing Layout section in VIEW.md");for(const a of t)if(a.type==="code"){const l=a;if(l.lang==="clapp-layout")return parseLayoutDSL(l.value)}throw new Error("No clapp-layout code block found in Layout section")}function parseIntentsTable(t){if(!t)return[];const a=[];for(const l of t){if(l.type!=="table")continue;const o=l;for(let u=1;u<o.children.length;u++){const d=o.children[u].children;d.length>=3&&a.push({name:getCellText(d[0]),payload:getCellText(d[1]),description:getCellText(d[2])})}}return a}function getCellText(t){return t.children.map(a=>a.type==="text"||a.type==="inlineCode"?a.value:"").join("")}function parseAppMd(t){const{data:a,content:l}=matter(t),o=unified().use(remarkParse).parse(l),u=splitByH2(o);return{name:a.name??"",domain:a.domain??"",modules:parseModulesList(u.Modules),layout:parseLayoutSection(u.Layout)}}function splitByH2(t){var o;const a={};let l="__intro__";a[l]=[];for(const u of t.children)u.type==="heading"&&u.depth===2?(l=u.children.map(d=>d.type==="text"?d.value:"").join(""),a[l]=[]):(o=a[l])==null||o.push(u);return a}function parseModulesList(t){if(!t)return[];const a=[];for(const l of t){if(l.type!=="list")continue;const o=l;for(const u of o.children){const c=u.children.map(d=>d.type==="paragraph"?d.children.map(m=>m.type==="text"?m.value:"").join(""):"").join("").trim();c&&a.push(c)}}return a}function parseLayoutSection(t){if(!t)throw new Error("Missing Layout section in APP.md");for(const a of t)if(a.type==="code"){const l=a;if(l.lang==="clapp-layout")return parseLayoutDSL(l.value)}throw new Error("No clapp-layout code block found in Layout section")}var util;(function(t){t.assertEqual=u=>{};function a(u){}t.assertIs=a;function l(u){throw new Error}t.assertNever=l,t.arrayToEnum=u=>{const c={};for(const d of u)c[d]=d;return c},t.getValidEnumValues=u=>{const c=t.objectKeys(u).filter(m=>typeof u[u[m]]!="number"),d={};for(const m of c)d[m]=u[m];return t.objectValues(d)},t.objectValues=u=>t.objectKeys(u).map(function(c){return u[c]}),t.objectKeys=typeof Object.keys=="function"?u=>Object.keys(u):u=>{const c=[];for(const d in u)Object.prototype.hasOwnProperty.call(u,d)&&c.push(d);return c},t.find=(u,c)=>{for(const d of u)if(c(d))return d},t.isInteger=typeof Number.isInteger=="function"?u=>Number.isInteger(u):u=>typeof u=="number"&&Number.isFinite(u)&&Math.floor(u)===u;function o(u,c=" | "){return u.map(d=>typeof d=="string"?`'${d}'`:d).join(c)}t.joinValues=o,t.jsonStringifyReplacer=(u,c)=>typeof c=="bigint"?c.toString():c})(util||(util={}));var objectUtil;(function(t){t.mergeShapes=(a,l)=>({...a,...l})})(objectUtil||(objectUtil={}));const ZodParsedType=util.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),getParsedType=t=>{switch(typeof t){case"undefined":return ZodParsedType.undefined;case"string":return ZodParsedType.string;case"number":return Number.isNaN(t)?ZodParsedType.nan:ZodParsedType.number;case"boolean":return ZodParsedType.boolean;case"function":return ZodParsedType.function;case"bigint":return ZodParsedType.bigint;case"symbol":return ZodParsedType.symbol;case"object":return Array.isArray(t)?ZodParsedType.array:t===null?ZodParsedType.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?ZodParsedType.promise:typeof Map<"u"&&t instanceof Map?ZodParsedType.map:typeof Set<"u"&&t instanceof Set?ZodParsedType.set:typeof Date<"u"&&t instanceof Date?ZodParsedType.date:ZodParsedType.object;default:return ZodParsedType.unknown}},ZodIssueCode=util.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ZodError extends Error{get errors(){return this.issues}constructor(a){super(),this.issues=[],this.addIssue=o=>{this.issues=[...this.issues,o]},this.addIssues=(o=[])=>{this.issues=[...this.issues,...o]};const l=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,l):this.__proto__=l,this.name="ZodError",this.issues=a}format(a){const l=a||function(c){return c.message},o={_errors:[]},u=c=>{for(const d of c.issues)if(d.code==="invalid_union")d.unionErrors.map(u);else if(d.code==="invalid_return_type")u(d.returnTypeError);else if(d.code==="invalid_arguments")u(d.argumentsError);else if(d.path.length===0)o._errors.push(l(d));else{let m=o,p=0;for(;p<d.path.length;){const g=d.path[p];p===d.path.length-1?(m[g]=m[g]||{_errors:[]},m[g]._errors.push(l(d))):m[g]=m[g]||{_errors:[]},m=m[g],p++}}};return u(this),o}static assert(a){if(!(a instanceof ZodError))throw new Error(`Not a ZodError: ${a}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,util.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(a=l=>l.message){const l={},o=[];for(const u of this.issues)if(u.path.length>0){const c=u.path[0];l[c]=l[c]||[],l[c].push(a(u))}else o.push(a(u));return{formErrors:o,fieldErrors:l}}get formErrors(){return this.flatten()}}ZodError.create=t=>new ZodError(t);const errorMap=(t,a)=>{let l;switch(t.code){case ZodIssueCode.invalid_type:t.received===ZodParsedType.undefined?l="Required":l=`Expected ${t.expected}, received ${t.received}`;break;case ZodIssueCode.invalid_literal:l=`Invalid literal value, expected ${JSON.stringify(t.expected,util.jsonStringifyReplacer)}`;break;case ZodIssueCode.unrecognized_keys:l=`Unrecognized key(s) in object: ${util.joinValues(t.keys,", ")}`;break;case ZodIssueCode.invalid_union:l="Invalid input";break;case ZodIssueCode.invalid_union_discriminator:l=`Invalid discriminator value. Expected ${util.joinValues(t.options)}`;break;case ZodIssueCode.invalid_enum_value:l=`Invalid enum value. Expected ${util.joinValues(t.options)}, received '${t.received}'`;break;case ZodIssueCode.invalid_arguments:l="Invalid function arguments";break;case ZodIssueCode.invalid_return_type:l="Invalid function return type";break;case ZodIssueCode.invalid_date:l="Invalid date";break;case ZodIssueCode.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(l=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(l=`${l} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?l=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?l=`Invalid input: must end with "${t.validation.endsWith}"`:util.assertNever(t.validation):t.validation!=="regex"?l=`Invalid ${t.validation}`:l="Invalid";break;case ZodIssueCode.too_small:t.type==="array"?l=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?l=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?l=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?l=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?l=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:l="Invalid input";break;case ZodIssueCode.too_big:t.type==="array"?l=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?l=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?l=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?l=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?l=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:l="Invalid input";break;case ZodIssueCode.custom:l="Invalid input";break;case ZodIssueCode.invalid_intersection_types:l="Intersection results could not be merged";break;case ZodIssueCode.not_multiple_of:l=`Number must be a multiple of ${t.multipleOf}`;break;case ZodIssueCode.not_finite:l="Number must be finite";break;default:l=a.defaultError,util.assertNever(t)}return{message:l}};let overrideErrorMap=errorMap;function getErrorMap(){return overrideErrorMap}const makeIssue=t=>{const{data:a,path:l,errorMaps:o,issueData:u}=t,c=[...l,...u.path||[]],d={...u,path:c};if(u.message!==void 0)return{...u,path:c,message:u.message};let m="";const p=o.filter(g=>!!g).slice().reverse();for(const g of p)m=g(d,{data:a,defaultError:m}).message;return{...u,path:c,message:m}};function addIssueToContext(t,a){const l=getErrorMap(),o=makeIssue({issueData:a,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,l,l===errorMap?void 0:errorMap].filter(u=>!!u)});t.common.issues.push(o)}class ParseStatus{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(a,l){const o=[];for(const u of l){if(u.status==="aborted")return INVALID;u.status==="dirty"&&a.dirty(),o.push(u.value)}return{status:a.value,value:o}}static async mergeObjectAsync(a,l){const o=[];for(const u of l){const c=await u.key,d=await u.value;o.push({key:c,value:d})}return ParseStatus.mergeObjectSync(a,o)}static mergeObjectSync(a,l){const o={};for(const u of l){const{key:c,value:d}=u;if(c.status==="aborted"||d.status==="aborted")return INVALID;c.status==="dirty"&&a.dirty(),d.status==="dirty"&&a.dirty(),c.value!=="__proto__"&&(typeof d.value<"u"||u.alwaysSet)&&(o[c.value]=d.value)}return{status:a.value,value:o}}}const INVALID=Object.freeze({status:"aborted"}),DIRTY=t=>({status:"dirty",value:t}),OK=t=>({status:"valid",value:t}),isAborted=t=>t.status==="aborted",isDirty=t=>t.status==="dirty",isValid=t=>t.status==="valid",isAsync=t=>typeof Promise<"u"&&t instanceof Promise;var errorUtil;(function(t){t.errToObj=a=>typeof a=="string"?{message:a}:a||{},t.toString=a=>typeof a=="string"?a:a==null?void 0:a.message})(errorUtil||(errorUtil={}));class ParseInputLazyPath{constructor(a,l,o,u){this._cachedPath=[],this.parent=a,this.data=l,this._path=o,this._key=u}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const handleResult=(t,a)=>{if(isValid(a))return{success:!0,data:a.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const l=new ZodError(t.common.issues);return this._error=l,this._error}}};function processCreateParams(t){if(!t)return{};const{errorMap:a,invalid_type_error:l,required_error:o,description:u}=t;if(a&&(l||o))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return a?{errorMap:a,description:u}:{errorMap:(d,m)=>{const{message:p}=t;return d.code==="invalid_enum_value"?{message:p??m.defaultError}:typeof m.data>"u"?{message:p??o??m.defaultError}:d.code!=="invalid_type"?{message:m.defaultError}:{message:p??l??m.defaultError}},description:u}}class ZodType{get description(){return this._def.description}_getType(a){return getParsedType(a.data)}_getOrReturnCtx(a,l){return l||{common:a.parent.common,data:a.data,parsedType:getParsedType(a.data),schemaErrorMap:this._def.errorMap,path:a.path,parent:a.parent}}_processInputParams(a){return{status:new ParseStatus,ctx:{common:a.parent.common,data:a.data,parsedType:getParsedType(a.data),schemaErrorMap:this._def.errorMap,path:a.path,parent:a.parent}}}_parseSync(a){const l=this._parse(a);if(isAsync(l))throw new Error("Synchronous parse encountered promise.");return l}_parseAsync(a){const l=this._parse(a);return Promise.resolve(l)}parse(a,l){const o=this.safeParse(a,l);if(o.success)return o.data;throw o.error}safeParse(a,l){const o={common:{issues:[],async:(l==null?void 0:l.async)??!1,contextualErrorMap:l==null?void 0:l.errorMap},path:(l==null?void 0:l.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:a,parsedType:getParsedType(a)},u=this._parseSync({data:a,path:o.path,parent:o});return handleResult(o,u)}"~validate"(a){var o,u;const l={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:a,parsedType:getParsedType(a)};if(!this["~standard"].async)try{const c=this._parseSync({data:a,path:[],parent:l});return isValid(c)?{value:c.value}:{issues:l.common.issues}}catch(c){(u=(o=c==null?void 0:c.message)==null?void 0:o.toLowerCase())!=null&&u.includes("encountered")&&(this["~standard"].async=!0),l.common={issues:[],async:!0}}return this._parseAsync({data:a,path:[],parent:l}).then(c=>isValid(c)?{value:c.value}:{issues:l.common.issues})}async parseAsync(a,l){const o=await this.safeParseAsync(a,l);if(o.success)return o.data;throw o.error}async safeParseAsync(a,l){const o={common:{issues:[],contextualErrorMap:l==null?void 0:l.errorMap,async:!0},path:(l==null?void 0:l.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:a,parsedType:getParsedType(a)},u=this._parse({data:a,path:o.path,parent:o}),c=await(isAsync(u)?u:Promise.resolve(u));return handleResult(o,c)}refine(a,l){const o=u=>typeof l=="string"||typeof l>"u"?{message:l}:typeof l=="function"?l(u):l;return this._refinement((u,c)=>{const d=a(u),m=()=>c.addIssue({code:ZodIssueCode.custom,...o(u)});return typeof Promise<"u"&&d instanceof Promise?d.then(p=>p?!0:(m(),!1)):d?!0:(m(),!1)})}refinement(a,l){return this._refinement((o,u)=>a(o)?!0:(u.addIssue(typeof l=="function"?l(o,u):l),!1))}_refinement(a){return new ZodEffects({schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"refinement",refinement:a}})}superRefine(a){return this._refinement(a)}constructor(a){this.spa=this.safeParseAsync,this._def=a,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:l=>this["~validate"](l)}}optional(){return ZodOptional.create(this,this._def)}nullable(){return ZodNullable.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ZodArray.create(this)}promise(){return ZodPromise.create(this,this._def)}or(a){return ZodUnion.create([this,a],this._def)}and(a){return ZodIntersection.create(this,a,this._def)}transform(a){return new ZodEffects({...processCreateParams(this._def),schema:this,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:{type:"transform",transform:a}})}default(a){const l=typeof a=="function"?a:()=>a;return new ZodDefault({...processCreateParams(this._def),innerType:this,defaultValue:l,typeName:ZodFirstPartyTypeKind.ZodDefault})}brand(){return new ZodBranded({typeName:ZodFirstPartyTypeKind.ZodBranded,type:this,...processCreateParams(this._def)})}catch(a){const l=typeof a=="function"?a:()=>a;return new ZodCatch({...processCreateParams(this._def),innerType:this,catchValue:l,typeName:ZodFirstPartyTypeKind.ZodCatch})}describe(a){const l=this.constructor;return new l({...this._def,description:a})}pipe(a){return ZodPipeline.create(this,a)}readonly(){return ZodReadonly.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const cuidRegex=/^c[^\s-]{8,}$/i,cuid2Regex=/^[0-9a-z]+$/,ulidRegex=/^[0-9A-HJKMNP-TV-Z]{26}$/i,uuidRegex=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,nanoidRegex=/^[a-z0-9_-]{21}$/i,jwtRegex=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,durationRegex=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,emailRegex=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,_emojiRegex="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let emojiRegex;const ipv4Regex=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4CidrRegex=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6Regex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,ipv6CidrRegex=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64Regex=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64urlRegex=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,dateRegexSource="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",dateRegex=new RegExp(`^${dateRegexSource}$`);function timeRegexSource(t){let a="[0-5]\\d";t.precision?a=`${a}\\.\\d{${t.precision}}`:t.precision==null&&(a=`${a}(\\.\\d+)?`);const l=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${a})${l}`}function timeRegex(t){return new RegExp(`^${timeRegexSource(t)}$`)}function datetimeRegex(t){let a=`${dateRegexSource}T${timeRegexSource(t)}`;const l=[];return l.push(t.local?"Z?":"Z"),t.offset&&l.push("([+-]\\d{2}:?\\d{2})"),a=`${a}(${l.join("|")})`,new RegExp(`^${a}$`)}function isValidIP(t,a){return!!((a==="v4"||!a)&&ipv4Regex.test(t)||(a==="v6"||!a)&&ipv6Regex.test(t))}function isValidJWT(t,a){if(!jwtRegex.test(t))return!1;try{const[l]=t.split(".");if(!l)return!1;const o=l.replace(/-/g,"+").replace(/_/g,"/").padEnd(l.length+(4-l.length%4)%4,"="),u=JSON.parse(atob(o));return!(typeof u!="object"||u===null||"typ"in u&&(u==null?void 0:u.typ)!=="JWT"||!u.alg||a&&u.alg!==a)}catch{return!1}}function isValidCidr(t,a){return!!((a==="v4"||!a)&&ipv4CidrRegex.test(t)||(a==="v6"||!a)&&ipv6CidrRegex.test(t))}class ZodString extends ZodType{_parse(a){if(this._def.coerce&&(a.data=String(a.data)),this._getType(a)!==ZodParsedType.string){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.string,received:c.parsedType}),INVALID}const o=new ParseStatus;let u;for(const c of this._def.checks)if(c.kind==="min")a.data.length<c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_small,minimum:c.value,type:"string",inclusive:!0,exact:!1,message:c.message}),o.dirty());else if(c.kind==="max")a.data.length>c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_big,maximum:c.value,type:"string",inclusive:!0,exact:!1,message:c.message}),o.dirty());else if(c.kind==="length"){const d=a.data.length>c.value,m=a.data.length<c.value;(d||m)&&(u=this._getOrReturnCtx(a,u),d?addIssueToContext(u,{code:ZodIssueCode.too_big,maximum:c.value,type:"string",inclusive:!0,exact:!0,message:c.message}):m&&addIssueToContext(u,{code:ZodIssueCode.too_small,minimum:c.value,type:"string",inclusive:!0,exact:!0,message:c.message}),o.dirty())}else if(c.kind==="email")emailRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"email",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="emoji")emojiRegex||(emojiRegex=new RegExp(_emojiRegex,"u")),emojiRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"emoji",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="uuid")uuidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"uuid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="nanoid")nanoidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"nanoid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="cuid")cuidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"cuid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="cuid2")cuid2Regex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"cuid2",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="ulid")ulidRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"ulid",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty());else if(c.kind==="url")try{new URL(a.data)}catch{u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"url",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()}else c.kind==="regex"?(c.regex.lastIndex=0,c.regex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"regex",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty())):c.kind==="trim"?a.data=a.data.trim():c.kind==="includes"?a.data.includes(c.value,c.position)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:{includes:c.value,position:c.position},message:c.message}),o.dirty()):c.kind==="toLowerCase"?a.data=a.data.toLowerCase():c.kind==="toUpperCase"?a.data=a.data.toUpperCase():c.kind==="startsWith"?a.data.startsWith(c.value)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:{startsWith:c.value},message:c.message}),o.dirty()):c.kind==="endsWith"?a.data.endsWith(c.value)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:{endsWith:c.value},message:c.message}),o.dirty()):c.kind==="datetime"?datetimeRegex(c).test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:"datetime",message:c.message}),o.dirty()):c.kind==="date"?dateRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:"date",message:c.message}),o.dirty()):c.kind==="time"?timeRegex(c).test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.invalid_string,validation:"time",message:c.message}),o.dirty()):c.kind==="duration"?durationRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"duration",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="ip"?isValidIP(a.data,c.version)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"ip",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="jwt"?isValidJWT(a.data,c.alg)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"jwt",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="cidr"?isValidCidr(a.data,c.version)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"cidr",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="base64"?base64Regex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"base64",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):c.kind==="base64url"?base64urlRegex.test(a.data)||(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{validation:"base64url",code:ZodIssueCode.invalid_string,message:c.message}),o.dirty()):util.assertNever(c);return{status:o.value,value:a.data}}_regex(a,l,o){return this.refinement(u=>a.test(u),{validation:l,code:ZodIssueCode.invalid_string,...errorUtil.errToObj(o)})}_addCheck(a){return new ZodString({...this._def,checks:[...this._def.checks,a]})}email(a){return this._addCheck({kind:"email",...errorUtil.errToObj(a)})}url(a){return this._addCheck({kind:"url",...errorUtil.errToObj(a)})}emoji(a){return this._addCheck({kind:"emoji",...errorUtil.errToObj(a)})}uuid(a){return this._addCheck({kind:"uuid",...errorUtil.errToObj(a)})}nanoid(a){return this._addCheck({kind:"nanoid",...errorUtil.errToObj(a)})}cuid(a){return this._addCheck({kind:"cuid",...errorUtil.errToObj(a)})}cuid2(a){return this._addCheck({kind:"cuid2",...errorUtil.errToObj(a)})}ulid(a){return this._addCheck({kind:"ulid",...errorUtil.errToObj(a)})}base64(a){return this._addCheck({kind:"base64",...errorUtil.errToObj(a)})}base64url(a){return this._addCheck({kind:"base64url",...errorUtil.errToObj(a)})}jwt(a){return this._addCheck({kind:"jwt",...errorUtil.errToObj(a)})}ip(a){return this._addCheck({kind:"ip",...errorUtil.errToObj(a)})}cidr(a){return this._addCheck({kind:"cidr",...errorUtil.errToObj(a)})}datetime(a){return typeof a=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:a}):this._addCheck({kind:"datetime",precision:typeof(a==null?void 0:a.precision)>"u"?null:a==null?void 0:a.precision,offset:(a==null?void 0:a.offset)??!1,local:(a==null?void 0:a.local)??!1,...errorUtil.errToObj(a==null?void 0:a.message)})}date(a){return this._addCheck({kind:"date",message:a})}time(a){return typeof a=="string"?this._addCheck({kind:"time",precision:null,message:a}):this._addCheck({kind:"time",precision:typeof(a==null?void 0:a.precision)>"u"?null:a==null?void 0:a.precision,...errorUtil.errToObj(a==null?void 0:a.message)})}duration(a){return this._addCheck({kind:"duration",...errorUtil.errToObj(a)})}regex(a,l){return this._addCheck({kind:"regex",regex:a,...errorUtil.errToObj(l)})}includes(a,l){return this._addCheck({kind:"includes",value:a,position:l==null?void 0:l.position,...errorUtil.errToObj(l==null?void 0:l.message)})}startsWith(a,l){return this._addCheck({kind:"startsWith",value:a,...errorUtil.errToObj(l)})}endsWith(a,l){return this._addCheck({kind:"endsWith",value:a,...errorUtil.errToObj(l)})}min(a,l){return this._addCheck({kind:"min",value:a,...errorUtil.errToObj(l)})}max(a,l){return this._addCheck({kind:"max",value:a,...errorUtil.errToObj(l)})}length(a,l){return this._addCheck({kind:"length",value:a,...errorUtil.errToObj(l)})}nonempty(a){return this.min(1,errorUtil.errToObj(a))}trim(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ZodString({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(a=>a.kind==="datetime")}get isDate(){return!!this._def.checks.find(a=>a.kind==="date")}get isTime(){return!!this._def.checks.find(a=>a.kind==="time")}get isDuration(){return!!this._def.checks.find(a=>a.kind==="duration")}get isEmail(){return!!this._def.checks.find(a=>a.kind==="email")}get isURL(){return!!this._def.checks.find(a=>a.kind==="url")}get isEmoji(){return!!this._def.checks.find(a=>a.kind==="emoji")}get isUUID(){return!!this._def.checks.find(a=>a.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(a=>a.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(a=>a.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(a=>a.kind==="cuid2")}get isULID(){return!!this._def.checks.find(a=>a.kind==="ulid")}get isIP(){return!!this._def.checks.find(a=>a.kind==="ip")}get isCIDR(){return!!this._def.checks.find(a=>a.kind==="cidr")}get isBase64(){return!!this._def.checks.find(a=>a.kind==="base64")}get isBase64url(){return!!this._def.checks.find(a=>a.kind==="base64url")}get minLength(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a}get maxLength(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a}}ZodString.create=t=>new ZodString({checks:[],typeName:ZodFirstPartyTypeKind.ZodString,coerce:(t==null?void 0:t.coerce)??!1,...processCreateParams(t)});function floatSafeRemainder(t,a){const l=(t.toString().split(".")[1]||"").length,o=(a.toString().split(".")[1]||"").length,u=l>o?l:o,c=Number.parseInt(t.toFixed(u).replace(".","")),d=Number.parseInt(a.toFixed(u).replace(".",""));return c%d/10**u}class ZodNumber extends ZodType{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(a){if(this._def.coerce&&(a.data=Number(a.data)),this._getType(a)!==ZodParsedType.number){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.number,received:c.parsedType}),INVALID}let o;const u=new ParseStatus;for(const c of this._def.checks)c.kind==="int"?util.isInteger(a.data)||(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:"integer",received:"float",message:c.message}),u.dirty()):c.kind==="min"?(c.inclusive?a.data<c.value:a.data<=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_small,minimum:c.value,type:"number",inclusive:c.inclusive,exact:!1,message:c.message}),u.dirty()):c.kind==="max"?(c.inclusive?a.data>c.value:a.data>=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_big,maximum:c.value,type:"number",inclusive:c.inclusive,exact:!1,message:c.message}),u.dirty()):c.kind==="multipleOf"?floatSafeRemainder(a.data,c.value)!==0&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.not_multiple_of,multipleOf:c.value,message:c.message}),u.dirty()):c.kind==="finite"?Number.isFinite(a.data)||(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.not_finite,message:c.message}),u.dirty()):util.assertNever(c);return{status:u.value,value:a.data}}gte(a,l){return this.setLimit("min",a,!0,errorUtil.toString(l))}gt(a,l){return this.setLimit("min",a,!1,errorUtil.toString(l))}lte(a,l){return this.setLimit("max",a,!0,errorUtil.toString(l))}lt(a,l){return this.setLimit("max",a,!1,errorUtil.toString(l))}setLimit(a,l,o,u){return new ZodNumber({...this._def,checks:[...this._def.checks,{kind:a,value:l,inclusive:o,message:errorUtil.toString(u)}]})}_addCheck(a){return new ZodNumber({...this._def,checks:[...this._def.checks,a]})}int(a){return this._addCheck({kind:"int",message:errorUtil.toString(a)})}positive(a){return this._addCheck({kind:"min",value:0,inclusive:!1,message:errorUtil.toString(a)})}negative(a){return this._addCheck({kind:"max",value:0,inclusive:!1,message:errorUtil.toString(a)})}nonpositive(a){return this._addCheck({kind:"max",value:0,inclusive:!0,message:errorUtil.toString(a)})}nonnegative(a){return this._addCheck({kind:"min",value:0,inclusive:!0,message:errorUtil.toString(a)})}multipleOf(a,l){return this._addCheck({kind:"multipleOf",value:a,message:errorUtil.toString(l)})}finite(a){return this._addCheck({kind:"finite",message:errorUtil.toString(a)})}safe(a){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:errorUtil.toString(a)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:errorUtil.toString(a)})}get minValue(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a}get maxValue(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a}get isInt(){return!!this._def.checks.find(a=>a.kind==="int"||a.kind==="multipleOf"&&util.isInteger(a.value))}get isFinite(){let a=null,l=null;for(const o of this._def.checks){if(o.kind==="finite"||o.kind==="int"||o.kind==="multipleOf")return!0;o.kind==="min"?(l===null||o.value>l)&&(l=o.value):o.kind==="max"&&(a===null||o.value<a)&&(a=o.value)}return Number.isFinite(l)&&Number.isFinite(a)}}ZodNumber.create=t=>new ZodNumber({checks:[],typeName:ZodFirstPartyTypeKind.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...processCreateParams(t)});class ZodBigInt extends ZodType{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(a){if(this._def.coerce)try{a.data=BigInt(a.data)}catch{return this._getInvalidInput(a)}if(this._getType(a)!==ZodParsedType.bigint)return this._getInvalidInput(a);let o;const u=new ParseStatus;for(const c of this._def.checks)c.kind==="min"?(c.inclusive?a.data<c.value:a.data<=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_small,type:"bigint",minimum:c.value,inclusive:c.inclusive,message:c.message}),u.dirty()):c.kind==="max"?(c.inclusive?a.data>c.value:a.data>=c.value)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.too_big,type:"bigint",maximum:c.value,inclusive:c.inclusive,message:c.message}),u.dirty()):c.kind==="multipleOf"?a.data%c.value!==BigInt(0)&&(o=this._getOrReturnCtx(a,o),addIssueToContext(o,{code:ZodIssueCode.not_multiple_of,multipleOf:c.value,message:c.message}),u.dirty()):util.assertNever(c);return{status:u.value,value:a.data}}_getInvalidInput(a){const l=this._getOrReturnCtx(a);return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.bigint,received:l.parsedType}),INVALID}gte(a,l){return this.setLimit("min",a,!0,errorUtil.toString(l))}gt(a,l){return this.setLimit("min",a,!1,errorUtil.toString(l))}lte(a,l){return this.setLimit("max",a,!0,errorUtil.toString(l))}lt(a,l){return this.setLimit("max",a,!1,errorUtil.toString(l))}setLimit(a,l,o,u){return new ZodBigInt({...this._def,checks:[...this._def.checks,{kind:a,value:l,inclusive:o,message:errorUtil.toString(u)}]})}_addCheck(a){return new ZodBigInt({...this._def,checks:[...this._def.checks,a]})}positive(a){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:errorUtil.toString(a)})}negative(a){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:errorUtil.toString(a)})}nonpositive(a){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:errorUtil.toString(a)})}nonnegative(a){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:errorUtil.toString(a)})}multipleOf(a,l){return this._addCheck({kind:"multipleOf",value:a,message:errorUtil.toString(l)})}get minValue(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a}get maxValue(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a}}ZodBigInt.create=t=>new ZodBigInt({checks:[],typeName:ZodFirstPartyTypeKind.ZodBigInt,coerce:(t==null?void 0:t.coerce)??!1,...processCreateParams(t)});class ZodBoolean extends ZodType{_parse(a){if(this._def.coerce&&(a.data=!!a.data),this._getType(a)!==ZodParsedType.boolean){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.boolean,received:o.parsedType}),INVALID}return OK(a.data)}}ZodBoolean.create=t=>new ZodBoolean({typeName:ZodFirstPartyTypeKind.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...processCreateParams(t)});class ZodDate extends ZodType{_parse(a){if(this._def.coerce&&(a.data=new Date(a.data)),this._getType(a)!==ZodParsedType.date){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.date,received:c.parsedType}),INVALID}if(Number.isNaN(a.data.getTime())){const c=this._getOrReturnCtx(a);return addIssueToContext(c,{code:ZodIssueCode.invalid_date}),INVALID}const o=new ParseStatus;let u;for(const c of this._def.checks)c.kind==="min"?a.data.getTime()<c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_small,message:c.message,inclusive:!0,exact:!1,minimum:c.value,type:"date"}),o.dirty()):c.kind==="max"?a.data.getTime()>c.value&&(u=this._getOrReturnCtx(a,u),addIssueToContext(u,{code:ZodIssueCode.too_big,message:c.message,inclusive:!0,exact:!1,maximum:c.value,type:"date"}),o.dirty()):util.assertNever(c);return{status:o.value,value:new Date(a.data.getTime())}}_addCheck(a){return new ZodDate({...this._def,checks:[...this._def.checks,a]})}min(a,l){return this._addCheck({kind:"min",value:a.getTime(),message:errorUtil.toString(l)})}max(a,l){return this._addCheck({kind:"max",value:a.getTime(),message:errorUtil.toString(l)})}get minDate(){let a=null;for(const l of this._def.checks)l.kind==="min"&&(a===null||l.value>a)&&(a=l.value);return a!=null?new Date(a):null}get maxDate(){let a=null;for(const l of this._def.checks)l.kind==="max"&&(a===null||l.value<a)&&(a=l.value);return a!=null?new Date(a):null}}ZodDate.create=t=>new ZodDate({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:ZodFirstPartyTypeKind.ZodDate,...processCreateParams(t)});class ZodSymbol extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.symbol){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.symbol,received:o.parsedType}),INVALID}return OK(a.data)}}ZodSymbol.create=t=>new ZodSymbol({typeName:ZodFirstPartyTypeKind.ZodSymbol,...processCreateParams(t)});class ZodUndefined extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.undefined){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.undefined,received:o.parsedType}),INVALID}return OK(a.data)}}ZodUndefined.create=t=>new ZodUndefined({typeName:ZodFirstPartyTypeKind.ZodUndefined,...processCreateParams(t)});class ZodNull extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.null){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.null,received:o.parsedType}),INVALID}return OK(a.data)}}ZodNull.create=t=>new ZodNull({typeName:ZodFirstPartyTypeKind.ZodNull,...processCreateParams(t)});class ZodAny extends ZodType{constructor(){super(...arguments),this._any=!0}_parse(a){return OK(a.data)}}ZodAny.create=t=>new ZodAny({typeName:ZodFirstPartyTypeKind.ZodAny,...processCreateParams(t)});class ZodUnknown extends ZodType{constructor(){super(...arguments),this._unknown=!0}_parse(a){return OK(a.data)}}ZodUnknown.create=t=>new ZodUnknown({typeName:ZodFirstPartyTypeKind.ZodUnknown,...processCreateParams(t)});class ZodNever extends ZodType{_parse(a){const l=this._getOrReturnCtx(a);return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.never,received:l.parsedType}),INVALID}}ZodNever.create=t=>new ZodNever({typeName:ZodFirstPartyTypeKind.ZodNever,...processCreateParams(t)});class ZodVoid extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.undefined){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.void,received:o.parsedType}),INVALID}return OK(a.data)}}ZodVoid.create=t=>new ZodVoid({typeName:ZodFirstPartyTypeKind.ZodVoid,...processCreateParams(t)});class ZodArray extends ZodType{_parse(a){const{ctx:l,status:o}=this._processInputParams(a),u=this._def;if(l.parsedType!==ZodParsedType.array)return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:l.parsedType}),INVALID;if(u.exactLength!==null){const d=l.data.length>u.exactLength.value,m=l.data.length<u.exactLength.value;(d||m)&&(addIssueToContext(l,{code:d?ZodIssueCode.too_big:ZodIssueCode.too_small,minimum:m?u.exactLength.value:void 0,maximum:d?u.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:u.exactLength.message}),o.dirty())}if(u.minLength!==null&&l.data.length<u.minLength.value&&(addIssueToContext(l,{code:ZodIssueCode.too_small,minimum:u.minLength.value,type:"array",inclusive:!0,exact:!1,message:u.minLength.message}),o.dirty()),u.maxLength!==null&&l.data.length>u.maxLength.value&&(addIssueToContext(l,{code:ZodIssueCode.too_big,maximum:u.maxLength.value,type:"array",inclusive:!0,exact:!1,message:u.maxLength.message}),o.dirty()),l.common.async)return Promise.all([...l.data].map((d,m)=>u.type._parseAsync(new ParseInputLazyPath(l,d,l.path,m)))).then(d=>ParseStatus.mergeArray(o,d));const c=[...l.data].map((d,m)=>u.type._parseSync(new ParseInputLazyPath(l,d,l.path,m)));return ParseStatus.mergeArray(o,c)}get element(){return this._def.type}min(a,l){return new ZodArray({...this._def,minLength:{value:a,message:errorUtil.toString(l)}})}max(a,l){return new ZodArray({...this._def,maxLength:{value:a,message:errorUtil.toString(l)}})}length(a,l){return new ZodArray({...this._def,exactLength:{value:a,message:errorUtil.toString(l)}})}nonempty(a){return this.min(1,a)}}ZodArray.create=(t,a)=>new ZodArray({type:t,minLength:null,maxLength:null,exactLength:null,typeName:ZodFirstPartyTypeKind.ZodArray,...processCreateParams(a)});function deepPartialify(t){if(t instanceof ZodObject){const a={};for(const l in t.shape){const o=t.shape[l];a[l]=ZodOptional.create(deepPartialify(o))}return new ZodObject({...t._def,shape:()=>a})}else return t instanceof ZodArray?new ZodArray({...t._def,type:deepPartialify(t.element)}):t instanceof ZodOptional?ZodOptional.create(deepPartialify(t.unwrap())):t instanceof ZodNullable?ZodNullable.create(deepPartialify(t.unwrap())):t instanceof ZodTuple?ZodTuple.create(t.items.map(a=>deepPartialify(a))):t}class ZodObject extends ZodType{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const a=this._def.shape(),l=util.objectKeys(a);return this._cached={shape:a,keys:l},this._cached}_parse(a){if(this._getType(a)!==ZodParsedType.object){const g=this._getOrReturnCtx(a);return addIssueToContext(g,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:g.parsedType}),INVALID}const{status:o,ctx:u}=this._processInputParams(a),{shape:c,keys:d}=this._getCached(),m=[];if(!(this._def.catchall instanceof ZodNever&&this._def.unknownKeys==="strip"))for(const g in u.data)d.includes(g)||m.push(g);const p=[];for(const g of d){const x=c[g],b=u.data[g];p.push({key:{status:"valid",value:g},value:x._parse(new ParseInputLazyPath(u,b,u.path,g)),alwaysSet:g in u.data})}if(this._def.catchall instanceof ZodNever){const g=this._def.unknownKeys;if(g==="passthrough")for(const x of m)p.push({key:{status:"valid",value:x},value:{status:"valid",value:u.data[x]}});else if(g==="strict")m.length>0&&(addIssueToContext(u,{code:ZodIssueCode.unrecognized_keys,keys:m}),o.dirty());else if(g!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const g=this._def.catchall;for(const x of m){const b=u.data[x];p.push({key:{status:"valid",value:x},value:g._parse(new ParseInputLazyPath(u,b,u.path,x)),alwaysSet:x in u.data})}}return u.common.async?Promise.resolve().then(async()=>{const g=[];for(const x of p){const b=await x.key,C=await x.value;g.push({key:b,value:C,alwaysSet:x.alwaysSet})}return g}).then(g=>ParseStatus.mergeObjectSync(o,g)):ParseStatus.mergeObjectSync(o,p)}get shape(){return this._def.shape()}strict(a){return errorUtil.errToObj,new ZodObject({...this._def,unknownKeys:"strict",...a!==void 0?{errorMap:(l,o)=>{var c,d;const u=((d=(c=this._def).errorMap)==null?void 0:d.call(c,l,o).message)??o.defaultError;return l.code==="unrecognized_keys"?{message:errorUtil.errToObj(a).message??u}:{message:u}}}:{}})}strip(){return new ZodObject({...this._def,unknownKeys:"strip"})}passthrough(){return new ZodObject({...this._def,unknownKeys:"passthrough"})}extend(a){return new ZodObject({...this._def,shape:()=>({...this._def.shape(),...a})})}merge(a){return new ZodObject({unknownKeys:a._def.unknownKeys,catchall:a._def.catchall,shape:()=>({...this._def.shape(),...a._def.shape()}),typeName:ZodFirstPartyTypeKind.ZodObject})}setKey(a,l){return this.augment({[a]:l})}catchall(a){return new ZodObject({...this._def,catchall:a})}pick(a){const l={};for(const o of util.objectKeys(a))a[o]&&this.shape[o]&&(l[o]=this.shape[o]);return new ZodObject({...this._def,shape:()=>l})}omit(a){const l={};for(const o of util.objectKeys(this.shape))a[o]||(l[o]=this.shape[o]);return new ZodObject({...this._def,shape:()=>l})}deepPartial(){return deepPartialify(this)}partial(a){const l={};for(const o of util.objectKeys(this.shape)){const u=this.shape[o];a&&!a[o]?l[o]=u:l[o]=u.optional()}return new ZodObject({...this._def,shape:()=>l})}required(a){const l={};for(const o of util.objectKeys(this.shape))if(a&&!a[o])l[o]=this.shape[o];else{let c=this.shape[o];for(;c instanceof ZodOptional;)c=c._def.innerType;l[o]=c}return new ZodObject({...this._def,shape:()=>l})}keyof(){return createZodEnum(util.objectKeys(this.shape))}}ZodObject.create=(t,a)=>new ZodObject({shape:()=>t,unknownKeys:"strip",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject,...processCreateParams(a)});ZodObject.strictCreate=(t,a)=>new ZodObject({shape:()=>t,unknownKeys:"strict",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject,...processCreateParams(a)});ZodObject.lazycreate=(t,a)=>new ZodObject({shape:t,unknownKeys:"strip",catchall:ZodNever.create(),typeName:ZodFirstPartyTypeKind.ZodObject,...processCreateParams(a)});class ZodUnion extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a),o=this._def.options;function u(c){for(const m of c)if(m.result.status==="valid")return m.result;for(const m of c)if(m.result.status==="dirty")return l.common.issues.push(...m.ctx.common.issues),m.result;const d=c.map(m=>new ZodError(m.ctx.common.issues));return addIssueToContext(l,{code:ZodIssueCode.invalid_union,unionErrors:d}),INVALID}if(l.common.async)return Promise.all(o.map(async c=>{const d={...l,common:{...l.common,issues:[]},parent:null};return{result:await c._parseAsync({data:l.data,path:l.path,parent:d}),ctx:d}})).then(u);{let c;const d=[];for(const p of o){const g={...l,common:{...l.common,issues:[]},parent:null},x=p._parseSync({data:l.data,path:l.path,parent:g});if(x.status==="valid")return x;x.status==="dirty"&&!c&&(c={result:x,ctx:g}),g.common.issues.length&&d.push(g.common.issues)}if(c)return l.common.issues.push(...c.ctx.common.issues),c.result;const m=d.map(p=>new ZodError(p));return addIssueToContext(l,{code:ZodIssueCode.invalid_union,unionErrors:m}),INVALID}}get options(){return this._def.options}}ZodUnion.create=(t,a)=>new ZodUnion({options:t,typeName:ZodFirstPartyTypeKind.ZodUnion,...processCreateParams(a)});function mergeValues(t,a){const l=getParsedType(t),o=getParsedType(a);if(t===a)return{valid:!0,data:t};if(l===ZodParsedType.object&&o===ZodParsedType.object){const u=util.objectKeys(a),c=util.objectKeys(t).filter(m=>u.indexOf(m)!==-1),d={...t,...a};for(const m of c){const p=mergeValues(t[m],a[m]);if(!p.valid)return{valid:!1};d[m]=p.data}return{valid:!0,data:d}}else if(l===ZodParsedType.array&&o===ZodParsedType.array){if(t.length!==a.length)return{valid:!1};const u=[];for(let c=0;c<t.length;c++){const d=t[c],m=a[c],p=mergeValues(d,m);if(!p.valid)return{valid:!1};u.push(p.data)}return{valid:!0,data:u}}else return l===ZodParsedType.date&&o===ZodParsedType.date&&+t==+a?{valid:!0,data:t}:{valid:!1}}class ZodIntersection extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a),u=(c,d)=>{if(isAborted(c)||isAborted(d))return INVALID;const m=mergeValues(c.value,d.value);return m.valid?((isDirty(c)||isDirty(d))&&l.dirty(),{status:l.value,value:m.data}):(addIssueToContext(o,{code:ZodIssueCode.invalid_intersection_types}),INVALID)};return o.common.async?Promise.all([this._def.left._parseAsync({data:o.data,path:o.path,parent:o}),this._def.right._parseAsync({data:o.data,path:o.path,parent:o})]).then(([c,d])=>u(c,d)):u(this._def.left._parseSync({data:o.data,path:o.path,parent:o}),this._def.right._parseSync({data:o.data,path:o.path,parent:o}))}}ZodIntersection.create=(t,a,l)=>new ZodIntersection({left:t,right:a,typeName:ZodFirstPartyTypeKind.ZodIntersection,...processCreateParams(l)});class ZodTuple extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.array)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.array,received:o.parsedType}),INVALID;if(o.data.length<this._def.items.length)return addIssueToContext(o,{code:ZodIssueCode.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),INVALID;!this._def.rest&&o.data.length>this._def.items.length&&(addIssueToContext(o,{code:ZodIssueCode.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),l.dirty());const c=[...o.data].map((d,m)=>{const p=this._def.items[m]||this._def.rest;return p?p._parse(new ParseInputLazyPath(o,d,o.path,m)):null}).filter(d=>!!d);return o.common.async?Promise.all(c).then(d=>ParseStatus.mergeArray(l,d)):ParseStatus.mergeArray(l,c)}get items(){return this._def.items}rest(a){return new ZodTuple({...this._def,rest:a})}}ZodTuple.create=(t,a)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ZodTuple({items:t,typeName:ZodFirstPartyTypeKind.ZodTuple,rest:null,...processCreateParams(a)})};class ZodRecord extends ZodType{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.object)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.object,received:o.parsedType}),INVALID;const u=[],c=this._def.keyType,d=this._def.valueType;for(const m in o.data)u.push({key:c._parse(new ParseInputLazyPath(o,m,o.path,m)),value:d._parse(new ParseInputLazyPath(o,o.data[m],o.path,m)),alwaysSet:m in o.data});return o.common.async?ParseStatus.mergeObjectAsync(l,u):ParseStatus.mergeObjectSync(l,u)}get element(){return this._def.valueType}static create(a,l,o){return l instanceof ZodType?new ZodRecord({keyType:a,valueType:l,typeName:ZodFirstPartyTypeKind.ZodRecord,...processCreateParams(o)}):new ZodRecord({keyType:ZodString.create(),valueType:a,typeName:ZodFirstPartyTypeKind.ZodRecord,...processCreateParams(l)})}}class ZodMap extends ZodType{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.map)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.map,received:o.parsedType}),INVALID;const u=this._def.keyType,c=this._def.valueType,d=[...o.data.entries()].map(([m,p],g)=>({key:u._parse(new ParseInputLazyPath(o,m,o.path,[g,"key"])),value:c._parse(new ParseInputLazyPath(o,p,o.path,[g,"value"]))}));if(o.common.async){const m=new Map;return Promise.resolve().then(async()=>{for(const p of d){const g=await p.key,x=await p.value;if(g.status==="aborted"||x.status==="aborted")return INVALID;(g.status==="dirty"||x.status==="dirty")&&l.dirty(),m.set(g.value,x.value)}return{status:l.value,value:m}})}else{const m=new Map;for(const p of d){const g=p.key,x=p.value;if(g.status==="aborted"||x.status==="aborted")return INVALID;(g.status==="dirty"||x.status==="dirty")&&l.dirty(),m.set(g.value,x.value)}return{status:l.value,value:m}}}}ZodMap.create=(t,a,l)=>new ZodMap({valueType:a,keyType:t,typeName:ZodFirstPartyTypeKind.ZodMap,...processCreateParams(l)});class ZodSet extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.parsedType!==ZodParsedType.set)return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.set,received:o.parsedType}),INVALID;const u=this._def;u.minSize!==null&&o.data.size<u.minSize.value&&(addIssueToContext(o,{code:ZodIssueCode.too_small,minimum:u.minSize.value,type:"set",inclusive:!0,exact:!1,message:u.minSize.message}),l.dirty()),u.maxSize!==null&&o.data.size>u.maxSize.value&&(addIssueToContext(o,{code:ZodIssueCode.too_big,maximum:u.maxSize.value,type:"set",inclusive:!0,exact:!1,message:u.maxSize.message}),l.dirty());const c=this._def.valueType;function d(p){const g=new Set;for(const x of p){if(x.status==="aborted")return INVALID;x.status==="dirty"&&l.dirty(),g.add(x.value)}return{status:l.value,value:g}}const m=[...o.data.values()].map((p,g)=>c._parse(new ParseInputLazyPath(o,p,o.path,g)));return o.common.async?Promise.all(m).then(p=>d(p)):d(m)}min(a,l){return new ZodSet({...this._def,minSize:{value:a,message:errorUtil.toString(l)}})}max(a,l){return new ZodSet({...this._def,maxSize:{value:a,message:errorUtil.toString(l)}})}size(a,l){return this.min(a,l).max(a,l)}nonempty(a){return this.min(1,a)}}ZodSet.create=(t,a)=>new ZodSet({valueType:t,minSize:null,maxSize:null,typeName:ZodFirstPartyTypeKind.ZodSet,...processCreateParams(a)});class ZodLazy extends ZodType{get schema(){return this._def.getter()}_parse(a){const{ctx:l}=this._processInputParams(a);return this._def.getter()._parse({data:l.data,path:l.path,parent:l})}}ZodLazy.create=(t,a)=>new ZodLazy({getter:t,typeName:ZodFirstPartyTypeKind.ZodLazy,...processCreateParams(a)});class ZodLiteral extends ZodType{_parse(a){if(a.data!==this._def.value){const l=this._getOrReturnCtx(a);return addIssueToContext(l,{received:l.data,code:ZodIssueCode.invalid_literal,expected:this._def.value}),INVALID}return{status:"valid",value:a.data}}get value(){return this._def.value}}ZodLiteral.create=(t,a)=>new ZodLiteral({value:t,typeName:ZodFirstPartyTypeKind.ZodLiteral,...processCreateParams(a)});function createZodEnum(t,a){return new ZodEnum({values:t,typeName:ZodFirstPartyTypeKind.ZodEnum,...processCreateParams(a)})}class ZodEnum extends ZodType{_parse(a){if(typeof a.data!="string"){const l=this._getOrReturnCtx(a),o=this._def.values;return addIssueToContext(l,{expected:util.joinValues(o),received:l.parsedType,code:ZodIssueCode.invalid_type}),INVALID}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(a.data)){const l=this._getOrReturnCtx(a),o=this._def.values;return addIssueToContext(l,{received:l.data,code:ZodIssueCode.invalid_enum_value,options:o}),INVALID}return OK(a.data)}get options(){return this._def.values}get enum(){const a={};for(const l of this._def.values)a[l]=l;return a}get Values(){const a={};for(const l of this._def.values)a[l]=l;return a}get Enum(){const a={};for(const l of this._def.values)a[l]=l;return a}extract(a,l=this._def){return ZodEnum.create(a,{...this._def,...l})}exclude(a,l=this._def){return ZodEnum.create(this.options.filter(o=>!a.includes(o)),{...this._def,...l})}}ZodEnum.create=createZodEnum;class ZodNativeEnum extends ZodType{_parse(a){const l=util.getValidEnumValues(this._def.values),o=this._getOrReturnCtx(a);if(o.parsedType!==ZodParsedType.string&&o.parsedType!==ZodParsedType.number){const u=util.objectValues(l);return addIssueToContext(o,{expected:util.joinValues(u),received:o.parsedType,code:ZodIssueCode.invalid_type}),INVALID}if(this._cache||(this._cache=new Set(util.getValidEnumValues(this._def.values))),!this._cache.has(a.data)){const u=util.objectValues(l);return addIssueToContext(o,{received:o.data,code:ZodIssueCode.invalid_enum_value,options:u}),INVALID}return OK(a.data)}get enum(){return this._def.values}}ZodNativeEnum.create=(t,a)=>new ZodNativeEnum({values:t,typeName:ZodFirstPartyTypeKind.ZodNativeEnum,...processCreateParams(a)});class ZodPromise extends ZodType{unwrap(){return this._def.type}_parse(a){const{ctx:l}=this._processInputParams(a);if(l.parsedType!==ZodParsedType.promise&&l.common.async===!1)return addIssueToContext(l,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.promise,received:l.parsedType}),INVALID;const o=l.parsedType===ZodParsedType.promise?l.data:Promise.resolve(l.data);return OK(o.then(u=>this._def.type.parseAsync(u,{path:l.path,errorMap:l.common.contextualErrorMap})))}}ZodPromise.create=(t,a)=>new ZodPromise({type:t,typeName:ZodFirstPartyTypeKind.ZodPromise,...processCreateParams(a)});class ZodEffects extends ZodType{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===ZodFirstPartyTypeKind.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(a){const{status:l,ctx:o}=this._processInputParams(a),u=this._def.effect||null,c={addIssue:d=>{addIssueToContext(o,d),d.fatal?l.abort():l.dirty()},get path(){return o.path}};if(c.addIssue=c.addIssue.bind(c),u.type==="preprocess"){const d=u.transform(o.data,c);if(o.common.async)return Promise.resolve(d).then(async m=>{if(l.value==="aborted")return INVALID;const p=await this._def.schema._parseAsync({data:m,path:o.path,parent:o});return p.status==="aborted"?INVALID:p.status==="dirty"||l.value==="dirty"?DIRTY(p.value):p});{if(l.value==="aborted")return INVALID;const m=this._def.schema._parseSync({data:d,path:o.path,parent:o});return m.status==="aborted"?INVALID:m.status==="dirty"||l.value==="dirty"?DIRTY(m.value):m}}if(u.type==="refinement"){const d=m=>{const p=u.refinement(m,c);if(o.common.async)return Promise.resolve(p);if(p instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return m};if(o.common.async===!1){const m=this._def.schema._parseSync({data:o.data,path:o.path,parent:o});return m.status==="aborted"?INVALID:(m.status==="dirty"&&l.dirty(),d(m.value),{status:l.value,value:m.value})}else return this._def.schema._parseAsync({data:o.data,path:o.path,parent:o}).then(m=>m.status==="aborted"?INVALID:(m.status==="dirty"&&l.dirty(),d(m.value).then(()=>({status:l.value,value:m.value}))))}if(u.type==="transform")if(o.common.async===!1){const d=this._def.schema._parseSync({data:o.data,path:o.path,parent:o});if(!isValid(d))return INVALID;const m=u.transform(d.value,c);if(m instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:l.value,value:m}}else return this._def.schema._parseAsync({data:o.data,path:o.path,parent:o}).then(d=>isValid(d)?Promise.resolve(u.transform(d.value,c)).then(m=>({status:l.value,value:m})):INVALID);util.assertNever(u)}}ZodEffects.create=(t,a,l)=>new ZodEffects({schema:t,typeName:ZodFirstPartyTypeKind.ZodEffects,effect:a,...processCreateParams(l)});ZodEffects.createWithPreprocess=(t,a,l)=>new ZodEffects({schema:a,effect:{type:"preprocess",transform:t},typeName:ZodFirstPartyTypeKind.ZodEffects,...processCreateParams(l)});class ZodOptional extends ZodType{_parse(a){return this._getType(a)===ZodParsedType.undefined?OK(void 0):this._def.innerType._parse(a)}unwrap(){return this._def.innerType}}ZodOptional.create=(t,a)=>new ZodOptional({innerType:t,typeName:ZodFirstPartyTypeKind.ZodOptional,...processCreateParams(a)});class ZodNullable extends ZodType{_parse(a){return this._getType(a)===ZodParsedType.null?OK(null):this._def.innerType._parse(a)}unwrap(){return this._def.innerType}}ZodNullable.create=(t,a)=>new ZodNullable({innerType:t,typeName:ZodFirstPartyTypeKind.ZodNullable,...processCreateParams(a)});class ZodDefault extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a);let o=l.data;return l.parsedType===ZodParsedType.undefined&&(o=this._def.defaultValue()),this._def.innerType._parse({data:o,path:l.path,parent:l})}removeDefault(){return this._def.innerType}}ZodDefault.create=(t,a)=>new ZodDefault({innerType:t,typeName:ZodFirstPartyTypeKind.ZodDefault,defaultValue:typeof a.default=="function"?a.default:()=>a.default,...processCreateParams(a)});class ZodCatch extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a),o={...l,common:{...l.common,issues:[]}},u=this._def.innerType._parse({data:o.data,path:o.path,parent:{...o}});return isAsync(u)?u.then(c=>({status:"valid",value:c.status==="valid"?c.value:this._def.catchValue({get error(){return new ZodError(o.common.issues)},input:o.data})})):{status:"valid",value:u.status==="valid"?u.value:this._def.catchValue({get error(){return new ZodError(o.common.issues)},input:o.data})}}removeCatch(){return this._def.innerType}}ZodCatch.create=(t,a)=>new ZodCatch({innerType:t,typeName:ZodFirstPartyTypeKind.ZodCatch,catchValue:typeof a.catch=="function"?a.catch:()=>a.catch,...processCreateParams(a)});class ZodNaN extends ZodType{_parse(a){if(this._getType(a)!==ZodParsedType.nan){const o=this._getOrReturnCtx(a);return addIssueToContext(o,{code:ZodIssueCode.invalid_type,expected:ZodParsedType.nan,received:o.parsedType}),INVALID}return{status:"valid",value:a.data}}}ZodNaN.create=t=>new ZodNaN({typeName:ZodFirstPartyTypeKind.ZodNaN,...processCreateParams(t)});class ZodBranded extends ZodType{_parse(a){const{ctx:l}=this._processInputParams(a),o=l.data;return this._def.type._parse({data:o,path:l.path,parent:l})}unwrap(){return this._def.type}}class ZodPipeline extends ZodType{_parse(a){const{status:l,ctx:o}=this._processInputParams(a);if(o.common.async)return(async()=>{const c=await this._def.in._parseAsync({data:o.data,path:o.path,parent:o});return c.status==="aborted"?INVALID:c.status==="dirty"?(l.dirty(),DIRTY(c.value)):this._def.out._parseAsync({data:c.value,path:o.path,parent:o})})();{const u=this._def.in._parseSync({data:o.data,path:o.path,parent:o});return u.status==="aborted"?INVALID:u.status==="dirty"?(l.dirty(),{status:"dirty",value:u.value}):this._def.out._parseSync({data:u.value,path:o.path,parent:o})}}static create(a,l){return new ZodPipeline({in:a,out:l,typeName:ZodFirstPartyTypeKind.ZodPipeline})}}class ZodReadonly extends ZodType{_parse(a){const l=this._def.innerType._parse(a),o=u=>(isValid(u)&&(u.value=Object.freeze(u.value)),u);return isAsync(l)?l.then(u=>o(u)):o(l)}unwrap(){return this._def.innerType}}ZodReadonly.create=(t,a)=>new ZodReadonly({innerType:t,typeName:ZodFirstPartyTypeKind.ZodReadonly,...processCreateParams(a)});var ZodFirstPartyTypeKind;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(ZodFirstPartyTypeKind||(ZodFirstPartyTypeKind={}));const stringType=ZodString.create,numberType=ZodNumber.create,booleanType=ZodBoolean.create,unknownType=ZodUnknown.create;ZodNever.create;const arrayType=ZodArray.create,objectType=ZodObject.create;ZodUnion.create;ZodIntersection.create;ZodTuple.create;const recordType=ZodRecord.create;ZodEnum.create;ZodPromise.create;ZodOptional.create;ZodNullable.create;objectType({id:stringType(),agentId:stringType(),clappId:stringType(),intent:stringType(),payload:recordType(unknownType()),timestamp:stringType()});objectType({agentId:stringType(),clappId:stringType(),version:numberType(),timestamp:stringType(),state:recordType(unknownType())});const AppEntrySchema=objectType({id:stringType(),name:stringType(),description:stringType().default(""),emoji:stringType().default("📦"),icon:stringType().default(""),tags:arrayType(stringType()).default([]),pinned:booleanType().default(!1)});objectType({agentId:stringType(),apps:arrayType(AppEntrySchema)});objectType({agentId:stringType(),viewId:stringType(),content:stringType()});const Card$1=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("rounded-lg border border-border bg-card text-card-foreground shadow-sm",t),...a}));Card$1.displayName="Card";const CardHeader=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("flex flex-col space-y-1.5 p-4 pb-2",t),...a}));CardHeader.displayName="CardHeader";const CardTitle=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("h3",{ref:l,className:cn("text-base font-semibold leading-none tracking-tight",t),...a}));CardTitle.displayName="CardTitle";const CardDescription=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("p",{ref:l,className:cn("text-sm text-muted-foreground",t),...a}));CardDescription.displayName="CardDescription";const CardContent=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("p-4 pt-0",t),...a}));CardContent.displayName="CardContent";const CardFooter=reactExports.forwardRef(({className:t,...a},l)=>jsxRuntimeExports.jsx("div",{ref:l,className:cn("flex items-center p-4 pt-0",t),...a}));CardFooter.displayName="CardFooter";function Card({title:t,children:a}){return jsxRuntimeExports.jsxs(Card$1,{children:[t&&jsxRuntimeExports.jsx(CardHeader,{children:jsxRuntimeExports.jsx(CardTitle,{children:t})}),jsxRuntimeExports.jsx(CardContent,{className:t?"":"pt-4",children:a})]})}function Column({gap:t=2,children:a,className:l}){const o=`gap-${t}`;return jsxRuntimeExports.jsx("div",{className:cn("flex flex-col",o,l),children:a})}const alignMap={start:"items-start",center:"items-center",end:"items-end",stretch:"items-stretch"},justifyMap={start:"justify-start",center:"justify-center",end:"justify-end",between:"justify-between",around:"justify-around"};function Row({gap:t=2,align:a="center",justify:l="start",children:o,className:u}){return jsxRuntimeExports.jsx("div",{className:cn("flex flex-row",`gap-${t}`,alignMap[a],justifyMap[l],u),children:o})}const levelStyles={1:"text-2xl font-bold tracking-tight",2:"text-xl font-semibold tracking-tight",3:"text-lg font-semibold",4:"text-base font-medium",5:"text-sm font-medium",6:"text-sm font-medium text-muted-foreground"};function Heading({level:t=2,children:a,className:l}){const o=`h${t}`;return jsxRuntimeExports.jsx(o,{className:cn(levelStyles[t],l),children:a})}const Input=reactExports.forwardRef(({className:t,type:a,...l},o)=>jsxRuntimeExports.jsx("input",{type:a,className:cn("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:o,...l}));Input.displayName="Input";const FormContext=reactExports.createContext(null);function useFormContext(){const t=reactExports.useContext(FormContext);return t||{values:{},setValue:()=>{},reset:()=>{}}}function FormProvider({children:t}){const[a,l]=reactExports.useState({}),o=(c,d)=>{l(m=>({...m,[c]:d}))},u=()=>{l({})};return jsxRuntimeExports.jsx(FormContext.Provider,{value:{values:a,setValue:o,reset:u},children:t})}function TextInput({name:t,type:a="text",placeholder:l}){const{values:o,setValue:u}=useFormContext(),c=o[t]??"";return jsxRuntimeExports.jsx(Input,{type:a,name:t,placeholder:l,value:c,onChange:d=>u(t,d.target.value)})}function IntentFormInner({intent:t,submitLabel:a="Submit",children:l}){const{values:o,reset:u}=useFormContext(),{sendIntent:c}=useClappContext(),d=m=>{m.preventDefault(),c(t,o),u()};return jsxRuntimeExports.jsxs("form",{onSubmit:d,className:"flex flex-col gap-3",children:[l,jsxRuntimeExports.jsx(Button,{type:"submit",className:"self-start",children:a})]})}function IntentForm(t){return jsxRuntimeExports.jsx(FormProvider,{children:jsxRuntimeExports.jsx(IntentFormInner,{...t})})}function IntentButton({intent:t,payload:a={},variant:l="outline",size:o="default",label:u,children:c}){const{emit:d}=useIntent(),m=l==="primary"?"default":l;return jsxRuntimeExports.jsx(Button,{variant:m,size:o,onClick:()=>d(t,a),children:c||u})}function Skeleton$1({className:t,...a}){return jsxRuntimeExports.jsx("div",{className:cn("animate-pulse rounded-md bg-muted",t),...a})}function Skeleton(){return jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2 py-2",children:[jsxRuntimeExports.jsx(Skeleton$1,{className:"h-4 w-4/5"}),jsxRuntimeExports.jsx(Skeleton$1,{className:"h-4 w-3/5"}),jsxRuntimeExports.jsx(Skeleton$1,{className:"h-4 w-4/5"})]})}function List({data:t,onItemClick:a,active:l,children:o,className:u}){const c=useClappState(t||"_empty_")??[],d=useClappState(l||"_empty_"),{emit:m}=useIntent();return t?c.length===0?jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground py-4 text-center",children:"No items"}):jsxRuntimeExports.jsx("ul",{className:cn("flex flex-col gap-1",u),children:c.map((p,g)=>{const x=typeof p=="object"&&p!==null,b=x?p:null,C=String(b?b.text??JSON.stringify(p):p),R=b!=null&&b.role?String(b.role):void 0,j=b!=null&&b.id?String(b.id):`${g}`,B=p===d;return jsxRuntimeExports.jsx("li",{className:cn("flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors",a&&"cursor-pointer",B?"bg-accent text-accent-foreground":"hover:bg-accent/50",R==="assistant"&&"bg-muted/50",R==="user"&&"bg-primary/10"),onClick:a?()=>m(a,x?p:{value:p}):void 0,role:a?"button":void 0,children:C},j)})}):jsxRuntimeExports.jsx("ul",{className:cn("flex flex-col gap-1",u),children:o})}function ListItem({active:t,children:a,className:l,onClick:o}){return jsxRuntimeExports.jsx("li",{className:cn("flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors cursor-pointer",t?"bg-accent text-accent-foreground":"hover:bg-accent/50",l),onClick:o,children:a})}function Conditional({when:t,children:a}){const l=(t==null?void 0:t.startsWith("!"))??!1,o=l?t.slice(1):t??"",u=useClappState(o||"_empty_");return(l?!u:!!u)?jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment,{children:a}):null}function MarkdownContent({source:t,content:a,className:l}){const o=useClappState(t||"_empty_"),u=a??o??"";return u?jsxRuntimeExports.jsx("div",{className:cn("prose prose-invert prose-sm max-w-none",l),children:jsxRuntimeExports.jsx(Markdown,{components:{h1:({children:c})=>jsxRuntimeExports.jsx("h1",{className:"text-xl font-bold mt-4 mb-2",children:c}),h2:({children:c})=>jsxRuntimeExports.jsx("h2",{className:"text-lg font-semibold mt-3 mb-2",children:c}),h3:({children:c})=>jsxRuntimeExports.jsx("h3",{className:"text-base font-semibold mt-2 mb-1",children:c}),p:({children:c})=>jsxRuntimeExports.jsx("p",{className:"my-2 text-sm leading-relaxed",children:c}),ul:({children:c})=>jsxRuntimeExports.jsx("ul",{className:"list-disc list-inside my-2 text-sm",children:c}),ol:({children:c})=>jsxRuntimeExports.jsx("ol",{className:"list-decimal list-inside my-2 text-sm",children:c}),li:({children:c})=>jsxRuntimeExports.jsx("li",{className:"my-0.5",children:c}),code:({children:c,className:d})=>!d?jsxRuntimeExports.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs font-mono",children:c}):jsxRuntimeExports.jsx("code",{className:d,children:c}),pre:({children:c})=>jsxRuntimeExports.jsx("pre",{className:"bg-card border border-border rounded-md p-3 overflow-x-auto my-2 text-xs",children:c}),blockquote:({children:c})=>jsxRuntimeExports.jsx("blockquote",{className:"border-l-2 border-primary pl-3 my-2 text-muted-foreground italic",children:c}),a:({href:c,children:d})=>jsxRuntimeExports.jsx("a",{href:c,className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",children:d}),strong:({children:c})=>jsxRuntimeExports.jsx("strong",{className:"font-semibold",children:c}),em:({children:c})=>jsxRuntimeExports.jsx("em",{className:"italic",children:c})},children:u})}):null}function Icon({name:t,emoji:a,className:l}){return a?jsxRuntimeExports.jsx("span",{className:cn("text-base leading-none",l),children:a}):t?jsxRuntimeExports.jsx("span",{className:cn("text-base leading-none",l),children:"•"}):null}function ChatMessages({messages:t,loading:a,loadingText:l="Thinking...",hasMore:o=!1,loadingOlder:u=!1,onLoadOlder:c}){const d=reactExports.useRef(null),m=reactExports.useRef(null),p=reactExports.useRef(!0);reactExports.useEffect(()=>{t.length===0&&(p.current=!0)},[t.length]),reactExports.useEffect(()=>{var C,R;const x=d.current;if(!x)return;if(p.current&&t.length>0){p.current=!1,(C=m.current)==null||C.scrollIntoView({behavior:"instant"});return}(x.scrollHeight-x.scrollTop-x.clientHeight<200||a)&&((R=m.current)==null||R.scrollIntoView({behavior:"smooth",block:"end"}))},[t,a]);const g=()=>{const x=d.current;!x||!o||u||!c||x.scrollTop<120&&c()};return t.length===0&&!a?jsxRuntimeExports.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:jsxRuntimeExports.jsxs("div",{className:"text-center max-w-md",children:[jsxRuntimeExports.jsx("h2",{className:"text-2xl font-semibold mb-2",children:"What can I do for you?"}),jsxRuntimeExports.jsx("p",{className:"text-muted-foreground",children:"Start a conversation by typing a message below."})]})}):jsxRuntimeExports.jsx("div",{ref:d,onScroll:g,className:"flex-1 overflow-y-auto",children:jsxRuntimeExports.jsxs("div",{className:"max-w-3xl mx-auto px-4 py-6 space-y-6",children:[u&&jsxRuntimeExports.jsx("div",{className:"text-center text-xs text-muted-foreground",children:"Loading older messages…"}),o&&!u&&jsxRuntimeExports.jsx("div",{className:"text-center text-xs text-muted-foreground",children:"Scroll up to load older messages"}),t.map(x=>jsxRuntimeExports.jsx(MessageBubble,{message:x},x.id)),a&&jsxRuntimeExports.jsxs("div",{className:"flex items-start gap-4",children:[jsxRuntimeExports.jsx("div",{className:"shrink-0 w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:jsxRuntimeExports.jsx(Bot,{className:"h-4 w-4 text-primary"})}),jsxRuntimeExports.jsx("div",{className:"flex-1 pt-1",children:jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),jsxRuntimeExports.jsx("span",{className:"text-sm line-clamp-2",children:l})]})})]}),jsxRuntimeExports.jsx("div",{ref:m})]})})}function MessageBubble({message:t}){const a=t.role==="user";return t.role==="system"?jsxRuntimeExports.jsx("div",{className:"text-center",children:jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground bg-muted px-3 py-1 rounded-full",children:t.content})}):jsxRuntimeExports.jsxs("div",{className:cn("flex items-start gap-4",a&&"flex-row-reverse"),children:[jsxRuntimeExports.jsx("div",{className:cn("shrink-0 w-8 h-8 rounded-full flex items-center justify-center",a?"bg-primary text-primary-foreground":"bg-primary/10"),children:a?jsxRuntimeExports.jsx(User,{className:"h-4 w-4"}):jsxRuntimeExports.jsx(Bot,{className:"h-4 w-4 text-primary"})}),jsxRuntimeExports.jsx("div",{className:cn("flex-1 min-w-0 pt-1",a&&"text-right"),children:jsxRuntimeExports.jsxs("div",{className:cn("inline-block text-left rounded-2xl px-4 py-2 max-w-full",a?"bg-primary text-primary-foreground rounded-tr-sm":"bg-muted rounded-tl-sm"),children:[t.attachments&&t.attachments.length>0&&jsxRuntimeExports.jsxs("div",{className:"mb-2 space-y-2",children:[jsxRuntimeExports.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.attachments.filter(o=>o.type==="image").map(o=>jsxRuntimeExports.jsx("a",{href:o.url,target:"_blank",rel:"noreferrer",children:jsxRuntimeExports.jsx("img",{src:o.url,alt:o.name,className:"rounded-md border border-white/10 max-h-52 object-cover",loading:"lazy"})},o.id))}),t.attachments.filter(o=>o.type==="file").map(o=>jsxRuntimeExports.jsxs("a",{href:o.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-2 rounded-md border border-white/10 px-2 py-1.5 text-xs hover:bg-white/5",children:[jsxRuntimeExports.jsx(Paperclip,{className:"h-3.5 w-3.5"}),jsxRuntimeExports.jsx("span",{className:"truncate",children:o.name})]},o.id))]}),t.content&&jsxRuntimeExports.jsx("div",{className:"prose prose-sm prose-invert max-w-none break-words",children:jsxRuntimeExports.jsx(Markdown,{components:{code:({className:o,children:u,...c})=>o?jsxRuntimeExports.jsx("pre",{className:"bg-white/10 p-3 rounded-lg overflow-x-auto my-2",children:jsxRuntimeExports.jsx("code",{className:"text-sm",...c,children:u})}):jsxRuntimeExports.jsx("code",{className:"bg-white/10 px-1 py-0.5 rounded text-sm",...c,children:u}),p:({children:o})=>jsxRuntimeExports.jsx("p",{className:"mb-2 last:mb-0",children:o})},children:t.content})})]})})]})}function ChatInput({onSend:t,disabled:a=!1,placeholder:l="Message..."}){const[o,u]=reactExports.useState(""),[c,d]=reactExports.useState([]),m=reactExports.useRef(null),p=reactExports.useRef(null);reactExports.useEffect(()=>{const L=m.current;L&&(L.style.height="auto",L.style.height=`${Math.min(L.scrollHeight,200)}px`)},[o]);const g=L=>new Promise((D,$)=>{const F=new FileReader;F.onload=()=>D(String(F.result??"")),F.onerror=()=>$(new Error(`Failed to read file: ${L.name}`)),F.readAsDataURL(L)}),x=async L=>{if(!L.length)return;const D=await Promise.all(L.map(async($,F)=>{const oe=await g($);return{id:`file-${Date.now()}-${F}`,name:$.name||`attachment-${Date.now()}`,mimeType:$.type||"application/octet-stream",size:$.size,dataUrl:oe,isImage:$.type.startsWith("image/")}}));d($=>[...$,...D])},b=async L=>{var oe;const $=Array.from(((oe=L.clipboardData)==null?void 0:oe.items)??[]).filter(ie=>ie.type.startsWith("image/"));if(!$.length)return;L.preventDefault();const F=$.map(ie=>ie.getAsFile()).filter(Boolean);await x(F)},C=async L=>{const D=Array.from(L.target.files??[]);await x(D),L.target.value=""},R=()=>{const L=o.trim();!L&&c.length===0||a||(t(L,c.map(({id:D,isImage:$,...F})=>F)),u(""),d([]),m.current&&(m.current.style.height="auto"))},j=L=>d(D=>D.filter($=>$.id!==L)),B=L=>{L.key==="Enter"&&!L.shiftKey&&(L.preventDefault(),R())};return jsxRuntimeExports.jsx("div",{className:"shrink-0 border-t border-border bg-background",children:jsxRuntimeExports.jsxs("div",{className:"max-w-3xl mx-auto p-4",children:[!!c.length&&jsxRuntimeExports.jsx("div",{className:"mb-2 flex flex-wrap gap-2",children:c.map(L=>jsxRuntimeExports.jsxs("div",{className:"relative rounded-md border bg-muted/40 overflow-hidden",children:[L.isImage?jsxRuntimeExports.jsx("img",{src:L.dataUrl,alt:L.name,className:"h-16 w-16 object-cover"}):jsxRuntimeExports.jsxs("div",{className:"h-16 min-w-40 px-2 flex items-center gap-2 text-xs",children:[jsxRuntimeExports.jsx(Paperclip,{className:"h-3.5 w-3.5"}),jsxRuntimeExports.jsx("span",{className:"truncate max-w-28",children:L.name})]}),jsxRuntimeExports.jsx("button",{onClick:()=>j(L.id),className:"absolute top-0.5 right-0.5 rounded-full bg-black/70 text-white p-0.5",title:"Remove",children:jsxRuntimeExports.jsx(X,{className:"h-3 w-3"})})]},L.id))}),jsxRuntimeExports.jsxs("div",{className:cn("flex items-end gap-2 rounded-2xl border border-border bg-muted/30 p-2","focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/20",a&&"opacity-60"),children:[jsxRuntimeExports.jsx("input",{ref:p,type:"file",multiple:!0,onChange:C,className:"hidden",accept:"image/*,.pdf,.txt,.md,.csv,.json,.doc,.docx,.xls,.xlsx,.ppt,.pptx"}),jsxRuntimeExports.jsx("button",{onClick:()=>{var L;return(L=p.current)==null?void 0:L.click()},className:"shrink-0 p-2 rounded-xl bg-background border border-border hover:bg-muted transition-colors",title:"Add photos & files",children:jsxRuntimeExports.jsx(Plus,{className:"h-4 w-4"})}),jsxRuntimeExports.jsx("textarea",{ref:m,value:o,onChange:L=>u(L.target.value),onKeyDown:B,onPaste:b,placeholder:l,disabled:a,rows:1,className:cn("flex-1 resize-none bg-transparent px-2 py-1.5 text-sm","placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed")}),jsxRuntimeExports.jsx("button",{onClick:R,disabled:a||!o.trim()&&c.length===0,className:cn("shrink-0 p-2 rounded-xl transition-colors","bg-primary text-primary-foreground hover:bg-primary/90","disabled:opacity-50 disabled:cursor-not-allowed"),children:jsxRuntimeExports.jsx(Send,{className:"h-4 w-4"})})]}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground text-center mt-2",children:"Enter to send • Shift+Enter newline • Paste images or use + for files"})]})})}function ChatLayout(){const t=useClappState("chat"),a=(t==null?void 0:t.sessions)??[],l=t==null?void 0:t.activeSession,o=(t==null?void 0:t.messages)??[],u=(t==null?void 0:t.loading)??!1,c=(t==null?void 0:t.loadingText)??"Thinking...",d=(t==null?void 0:t.loadingOlder)??!1,m=(t==null?void 0:t.hasMore)??!1,{emit:p}=useIntent(),[g,x]=reactExports.useState(!1),[b,C]=reactExports.useState(null),R=reactExports.useRef(!1);reactExports.useEffect(()=>{l&&x(!1)},[l]),reactExports.useEffect(()=>{R.current||(R.current=!0,p("chat.init",{}))},[p]);const j=()=>{p("chat.newSession",{}),x(!1)},B=W=>{W!==l&&p("chat.switchSession",{sessionKey:W}),x(!1)},L=(W,ve)=>{ve.stopPropagation(),C(W),p("chat.deleteSession",{sessionKey:W}),setTimeout(()=>C(null),1e3)},[D,$]=reactExports.useState(null),F=(W,ve)=>{W.trim()&&$({id:`pending-${Date.now()}`,role:"user",content:W,timestamp:new Date().toISOString()}),p("chat.send",{text:W,attachments:ve??[]})};reactExports.useEffect(()=>{D&&o.some(W=>W.role==="user"&&W.content===D.content)&&$(null)},[o,D]);const oe=D?[...o,D]:o,ie=u||!!D,H=()=>{!d&&m&&p("chat.loadOlder",{})},xe=a.find(W=>W.key===l);return jsxRuntimeExports.jsxs("div",{className:"flex h-full bg-background",children:[g&&jsxRuntimeExports.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:()=>x(!1)}),jsxRuntimeExports.jsxs("aside",{className:cn("fixed lg:static inset-y-0 left-0 z-50 w-72 bg-muted/50 border-r border-border","transform transition-transform duration-200 ease-in-out","flex flex-col",g?"translate-x-0":"-translate-x-full lg:translate-x-0"),children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[jsxRuntimeExports.jsx("h2",{className:"font-semibold text-sm",children:"Chats"}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("button",{onClick:j,className:"p-2 rounded-md hover:bg-muted transition-colors",title:"New chat",children:jsxRuntimeExports.jsx(Plus,{className:"h-4 w-4"})}),jsxRuntimeExports.jsx("button",{onClick:()=>x(!1),className:"p-2 rounded-md hover:bg-muted transition-colors lg:hidden",children:jsxRuntimeExports.jsx(X,{className:"h-4 w-4"})})]})]}),jsxRuntimeExports.jsx("div",{className:"flex-1 overflow-y-auto p-2",children:a.length===0?jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground text-center py-8",children:"No conversations yet"}):jsxRuntimeExports.jsx("div",{className:"space-y-1",children:a.map(W=>jsxRuntimeExports.jsx("button",{onClick:()=>B(W.key),className:cn("w-full text-left p-3 rounded-lg transition-colors group","hover:bg-muted",W.key===l&&"bg-muted"),children:jsxRuntimeExports.jsxs("div",{className:"flex items-start gap-3",children:[jsxRuntimeExports.jsx(MessageSquare,{className:"h-4 w-4 mt-0.5 shrink-0 text-muted-foreground"}),jsxRuntimeExports.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntimeExports.jsx("div",{className:"text-sm font-medium truncate",children:W.title||"New conversation"}),jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:W.preview||"No messages"})]}),jsxRuntimeExports.jsx("button",{onClick:ve=>L(W.key,ve),className:cn("p-1 rounded opacity-0 group-hover:opacity-100 transition-opacity","hover:bg-destructive/20 hover:text-destructive",b===W.key&&"opacity-100"),title:"Delete conversation",children:jsxRuntimeExports.jsx(Trash2,{className:"h-3.5 w-3.5"})})]})},W.key))})})]}),jsxRuntimeExports.jsxs("main",{className:"flex-1 flex flex-col min-w-0",children:[jsxRuntimeExports.jsxs("header",{className:"flex items-center gap-3 px-4 py-3 border-b border-border shrink-0",children:[jsxRuntimeExports.jsx("button",{onClick:()=>x(!0),className:"p-2 -ml-2 rounded-md hover:bg-muted transition-colors lg:hidden",children:jsxRuntimeExports.jsx(Menu,{className:"h-5 w-5"})}),jsxRuntimeExports.jsx("div",{className:"flex-1 min-w-0",children:jsxRuntimeExports.jsx("h1",{className:"font-semibold truncate",children:(xe==null?void 0:xe.title)||"New conversation"})})]}),jsxRuntimeExports.jsx(ChatMessages,{messages:oe,loading:ie,loadingText:c,hasMore:m,loadingOlder:d,onLoadOlder:H}),jsxRuntimeExports.jsx(ChatInput,{onSend:F,disabled:u})]})]})}const PROVIDER_CONFIGS=[{type:"anthropic",name:"Anthropic",description:"Claude models via API or subscription",authModes:[{mode:"api-key",label:"API Key",description:"Use your Anthropic API key (usage-based billing)",helpUrl:"https://console.anthropic.com/settings/keys",fields:[{name:"apiKey",label:"API Key",type:"password",placeholder:"sk-ant-api03-...",helpText:"Get your API key from the Anthropic Console"}]},{mode:"subscription",label:"Claude Subscription",description:"Use your Claude Pro/Max subscription",helpUrl:"https://docs.openclaw.ai/providers/anthropic#option-b-claude-setup-token",fields:[{name:"setupToken",label:"Setup Token",type:"textarea",placeholder:"Paste your setup token here...",helpText:"Run 'claude setup-token' in your terminal to generate this"}]}]},{type:"openai",name:"OpenAI",description:"GPT models via API or Codex subscription",authModes:[{mode:"api-key",label:"API Key",description:"Use your OpenAI API key (usage-based billing)",helpUrl:"https://platform.openai.com/api-keys",fields:[{name:"apiKey",label:"API Key",type:"password",placeholder:"sk-...",helpText:"Get your API key from the OpenAI dashboard"}]},{mode:"subscription",label:"Codex Subscription",description:"Use your ChatGPT Plus/Pro subscription via Codex",helpUrl:"https://docs.openclaw.ai/providers/openai#option-b-openai-code-codex-subscription",fields:[]}]},{type:"kimi-coding",name:"Kimi Coding",description:"Moonshot's Kimi K2 models for coding",authModes:[{mode:"api-key",label:"API Key",description:"Use your Kimi Coding API key",helpUrl:"https://platform.moonshot.cn/console/api-keys",fields:[{name:"apiKey",label:"API Key",type:"password",placeholder:"sk-...",helpText:"Get your API key from the Moonshot platform"}]}]}];function ProviderEditor({isOpen:t,onClose:a,editingProvider:l}){const{emit:o}=useIntent(),[u,c]=reactExports.useState("select"),[d,m]=reactExports.useState(null),[p,g]=reactExports.useState(null),[x,b]=reactExports.useState(""),[C,R]=reactExports.useState({}),[j,B]=reactExports.useState({}),[L,D]=reactExports.useState(!1),[$,F]=reactExports.useState(null);reactExports.useEffect(()=>{if(t){if(l){m(l.type);const T=l.authType==="subscription"||l.authType==="oauth"||l.mode==="oauth"?"subscription":"api-key";g(T),b(l.name),c("configure")}else c("select"),m(null),g(null),b("");R({}),B({}),F(null),D(!1),Ee(null),_e(""),ee(!1),de(!1)}},[t,l]);const oe=d?PROVIDER_CONFIGS.find(T=>T.type===d):null,ie=oe&&p?oe.authModes.find(T=>T.mode===p):null,H=T=>{m(T);const ue=PROVIDER_CONFIGS.find(pe=>pe.type===T);ue&&(g(ue.authModes[0].mode),b(ue.name)),c("configure")},xe=(T,ue)=>{R(pe=>({...pe,[T]:ue})),F(null)},W=T=>{B(ue=>({...ue,[T]:!ue[T]}))},ve=async()=>{var T,ue;if(!(!d||!p||!oe)){if(ie!=null&&ie.fields.length){for(const pe of ie.fields)if(!((T=C[pe.name])!=null&&T.trim())){F(`${pe.label} is required`);return}}D(!0),F(null);try{const pe=getIntentName(d,p),Se={customName:x.trim()||oe.name,profileId:l==null?void 0:l.id};for(const je of(ie==null?void 0:ie.fields)??[])Se[je.name]=(ue=C[je.name])==null?void 0:ue.trim();o(pe,Se),await new Promise(je=>setTimeout(je,1e3)),a()}catch(pe){F(pe instanceof Error?pe.message:"Failed to save provider")}finally{D(!1)}}},[G,Ee]=reactExports.useState(null),[be,_e]=reactExports.useState(""),[ye,ee]=reactExports.useState(!1),[P,de]=reactExports.useState(!1),se=async()=>{if(d){D(!0),F(null);try{const ue=await fetch("/api/oauth/init",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({provider:d==="openai"?"openai-codex":d,customName:x.trim()||(oe==null?void 0:oe.name)})});if(!ue.ok){const Se=await ue.json();throw new Error(Se.error||"Failed to initiate OAuth")}const{authUrl:pe}=await ue.json();Ee(pe)}catch(T){console.error("[oauth] Failed:",T),F(T instanceof Error?T.message:"OAuth failed")}finally{D(!1)}}},Te=async()=>{G&&(await navigator.clipboard.writeText(G),ee(!0),setTimeout(()=>ee(!1),2e3))},O=async()=>{if(!be.trim()){F("Please paste the callback URL");return}D(!0),F(null);try{const T=await fetch("/api/oauth/callback",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({callbackUrl:be.trim()})}),ue=await T.json();if(!T.ok||!ue.success)throw new Error(ue.error||"OAuth callback failed");de(!0),setTimeout(()=>a(),2e3)}catch(T){console.error("[oauth] Callback failed:",T),F(T instanceof Error?T.message:"Failed to complete sign in")}finally{D(!1)}},q=()=>{Ee(null),_e(""),F(null)},ae=()=>{l&&confirm(`Delete "${l.name}"? This cannot be undone.`)&&(o("settings.deleteProvider",{profileId:l.id}),a())};return t?jsxRuntimeExports.jsxs("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center",children:[jsxRuntimeExports.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:a}),jsxRuntimeExports.jsxs("div",{className:"relative w-full sm:max-w-md bg-background rounded-t-2xl sm:rounded-2xl shadow-xl max-h-[90vh] overflow-hidden flex flex-col animate-in slide-in-from-bottom-4 sm:slide-in-from-bottom-0 sm:zoom-in-95",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[jsxRuntimeExports.jsx("h2",{className:"text-lg font-semibold",children:l?"Edit Provider":"Add Provider"}),jsxRuntimeExports.jsx("button",{onClick:a,className:"p-1 rounded-full hover:bg-muted transition-colors","aria-label":"Close",children:jsxRuntimeExports.jsx(X,{className:"h-5 w-5"})})]}),jsxRuntimeExports.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[u==="select"&&jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Choose a provider to add:"}),PROVIDER_CONFIGS.map(T=>jsxRuntimeExports.jsxs("button",{onClick:()=>H(T.type),className:"w-full text-left p-4 rounded-lg border border-border hover:border-primary hover:bg-muted/50 transition-colors",children:[jsxRuntimeExports.jsx("div",{className:"font-medium",children:T.name}),jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground",children:T.description})]},T.type))]}),u==="configure"&&oe&&jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Display Name"}),jsxRuntimeExports.jsx("input",{type:"text",value:x,onChange:T=>b(T.target.value),placeholder:oe.name,className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-primary"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground",children:'Give this configuration a custom name (e.g., "Work Account", "Personal")'})]}),oe.authModes.length>1&&jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Authentication Method"}),jsxRuntimeExports.jsx("div",{className:"grid grid-cols-2 gap-2",children:oe.authModes.map(T=>jsxRuntimeExports.jsxs("button",{onClick:()=>g(T.mode),className:cn("p-3 rounded-lg border text-left transition-colors",p===T.mode?"border-primary bg-primary/10":"border-border hover:border-muted-foreground"),children:[jsxRuntimeExports.jsx("div",{className:"text-sm font-medium",children:T.label}),jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:T.description})]},T.mode))})]}),ie&&jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[ie.fields.length>0?ie.fields.map(T=>jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:T.label}),(l==null?void 0:l.maskedCredential)&&!C[T.name]&&jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 px-2 py-1 rounded mb-1",children:["Current: ",l.maskedCredential]}),T.type==="textarea"?jsxRuntimeExports.jsx("textarea",{value:C[T.name]??"",onChange:ue=>xe(T.name,ue.target.value),placeholder:l?"Enter new value to replace...":T.placeholder,rows:4,className:"w-full px-3 py-2 rounded-md border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary resize-none"}):jsxRuntimeExports.jsxs("div",{className:"relative",children:[jsxRuntimeExports.jsx("input",{type:T.type==="password"&&!j[T.name]?"password":"text",value:C[T.name]??"",onChange:ue=>xe(T.name,ue.target.value),placeholder:l?"Enter new value to replace...":T.placeholder,className:"w-full h-10 px-3 pr-10 rounded-md border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary"}),T.type==="password"&&jsxRuntimeExports.jsx("button",{type:"button",onClick:()=>W(T.name),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground",children:j[T.name]?jsxRuntimeExports.jsx(EyeOff,{className:"h-4 w-4"}):jsxRuntimeExports.jsx(Eye,{className:"h-4 w-4"})})]}),T.helpText&&jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground",children:T.helpText})]},T.name)):jsxRuntimeExports.jsx("div",{className:"space-y-3",children:P?jsxRuntimeExports.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[jsxRuntimeExports.jsx(CircleCheckBig,{className:"h-10 w-10 text-green-500"}),jsxRuntimeExports.jsx("p",{className:"text-sm font-medium",children:"Successfully connected!"}),jsxRuntimeExports.jsxs("p",{className:"text-xs text-muted-foreground",children:["Your ",oe.name," account has been linked."]})]}):G?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Step 1: Open this URL and sign in"}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[jsxRuntimeExports.jsx("input",{type:"text",value:G,readOnly:!0,className:"flex-1 h-9 px-3 rounded-md border border-input bg-muted text-xs font-mono truncate"}),jsxRuntimeExports.jsx(Button,{variant:"outline",size:"sm",onClick:Te,className:"shrink-0 h-9",children:ye?jsxRuntimeExports.jsx(Check,{className:"h-4 w-4"}):jsxRuntimeExports.jsx(Copy,{className:"h-4 w-4"})})]}),jsxRuntimeExports.jsxs("a",{href:G,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Open in new tab",jsxRuntimeExports.jsx(ExternalLink,{className:"h-3 w-3"})]})]}),jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Step 2: Paste the callback URL"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground",children:"After signing in, your browser will redirect to a page that may not load. Copy the full URL from your browser's address bar and paste it here."}),jsxRuntimeExports.jsx("input",{type:"text",value:be,onChange:T=>{_e(T.target.value),F(null)},placeholder:"http://127.0.0.1:1455/auth/callback?code=...&state=...",className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-primary"})]}),jsxRuntimeExports.jsx(Button,{onClick:O,disabled:L||!be.trim(),className:"w-full",children:L?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Completing..."]}):"Complete Sign In"}),jsxRuntimeExports.jsx("button",{onClick:q,className:"text-xs text-muted-foreground hover:text-foreground underline",children:"Start over"})]}):jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("p",{className:"text-sm text-muted-foreground",children:["Click the button below to start signing in with your ",oe.name," account."]}),jsxRuntimeExports.jsx(Button,{onClick:se,disabled:L,className:"w-full",children:L?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Preparing..."]}):`Sign in with ${oe.name}`})]})}),ie.helpUrl&&jsxRuntimeExports.jsxs("a",{href:ie.helpUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Learn more",jsxRuntimeExports.jsx(ExternalLink,{className:"h-3 w-3"})]})]}),$&&jsxRuntimeExports.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:$})]})]}),u==="configure"&&(ie==null?void 0:ie.fields.length)!==0&&jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-t border-border shrink-0",children:[l&&jsxRuntimeExports.jsx(Button,{variant:"destructive",onClick:ae,disabled:L,className:"mr-auto",children:"Delete"}),jsxRuntimeExports.jsx(Button,{variant:"outline",onClick:()=>l?a():c("select"),disabled:L,children:l?"Cancel":"Back"}),jsxRuntimeExports.jsx(Button,{onClick:ve,disabled:L,children:L?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin mr-2"}),"Saving..."]}):l?"Update":"Add Provider"})]})]})]}):null}function getIntentName(t,a){var o;return((o={anthropic:{"api-key":"settings.setAnthropicKey",subscription:"settings.setClaudeToken"},openai:{"api-key":"settings.setOpenAIKey",subscription:"settings.startOAuth"},"kimi-coding":{"api-key":"settings.setKimiCodingKey",subscription:"settings.setKimiCodingKey"}}[t])==null?void 0:o[a])??"settings.addProvider"}function getProviderIdentifier(t){const[,a]=t.split(":");return a||t}function providerOptionLabel(t){return`${t.name} · ${getProviderIdentifier(t.id)}`}function ProviderList({data:t="configuredProviders"}){const a=useClappState(t)??[],l=useClappState("active.model")??"",o=useClappState("active.profileId")??"",{emit:u}=useIntent(),c=a.find(ee=>ee.active)??a[0],[d,m]=reactExports.useState(o||(c==null?void 0:c.id)||""),[p,g]=reactExports.useState(l??""),[x,b]=reactExports.useState(!1),[C,R]=reactExports.useState(!1),[j,B]=reactExports.useState(null),[L,D]=reactExports.useState(!1),[$,F]=reactExports.useState(null),oe=d!==(o||(c==null?void 0:c.id)||"")||p!==(l??"");reactExports.useEffect(()=>{!c&&!o||(!d||!x&&!oe)&&m(o||(c==null?void 0:c.id)||"")},[c,o,x,oe,d]),reactExports.useEffect(()=>{l&&(!p||!x&&!oe)&&g(l)},[l,x,p,oe]);const ie=reactExports.useMemo(()=>{const ee=a.find(P=>P.id===d);return(ee==null?void 0:ee.models)??[]},[a,d]);reactExports.useEffect(()=>{if(!ie.length)return;ie.some(P=>P.id===p)||g(ie[0].id)},[ie,p]);const H=d!==(o||(c==null?void 0:c.id)||""),xe=!!(p&&p!==l),W=H||xe;reactExports.useEffect(()=>{if(!x)return;const ee=o||(c==null?void 0:c.id)||"",P=ee.split(":")[0],de=d.split(":")[0],se=P===de||ee===d,Te=!xe||l===p&&l.length>0;se&&Te&&(b(!1),R(!1),B(null),m(ee),g(l??""))},[l,p,d,o,c,xe,x]),reactExports.useEffect(()=>{if(!x)return;const ee=setTimeout(()=>R(!0),1e4),P=setTimeout(()=>{b(!1),R(!1),B("Still applying took too long. Changes may still complete in the background.")},3e4);return()=>{clearTimeout(ee),clearTimeout(P)}},[x]);const ve=a.find(ee=>ee.id===d),G=ee=>{var se,Te;if(x)return;m(ee);const P=a.find(O=>O.id===ee),de=(Te=(se=P==null?void 0:P.models)==null?void 0:se[0])==null?void 0:Te.id;g(de||"")},Ee=()=>{!W||!p||x||(b(!0),R(!1),B(null),H&&u("settings.setActiveProfile",{profileId:d}),xe&&u("settings.setActiveModel",{model:p}))},be=()=>{F(null),D(!0)},_e=ee=>{const P=ee.id.split(":")[0],de={anthropic:"anthropic",openai:"openai","openai-codex":"openai","kimi-coding":"kimi-coding",moonshot:"kimi-coding"};F({id:ee.id,name:ee.name,type:de[P]??"anthropic",mode:ee.mode,authType:ee.authType,maskedCredential:ee.maskedCredential}),D(!0)},ye=()=>{D(!1),F(null)};return jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-3",children:[jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[jsxRuntimeExports.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"System Default"}),jsxRuntimeExports.jsx("p",{className:"text-sm font-medium",children:"Default model for new sessions"})]}),jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[jsxRuntimeExports.jsx("label",{className:"text-xs text-muted-foreground",children:"Provider"}),jsxRuntimeExports.jsxs("div",{className:"relative flex gap-2",children:[jsxRuntimeExports.jsxs("div",{className:"relative flex-1",children:[jsxRuntimeExports.jsx("select",{value:d,onChange:ee=>G(ee.target.value),disabled:x||a.length===0,className:"h-10 w-full appearance-none rounded-md border border-input bg-background pl-3 pr-10 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-70",children:a.length===0?jsxRuntimeExports.jsx("option",{value:"",children:"No providers configured"}):a.map(ee=>jsxRuntimeExports.jsx("option",{value:ee.id,children:providerOptionLabel(ee)},ee.id))}),jsxRuntimeExports.jsx(ChevronDown,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"})]}),ve&&jsxRuntimeExports.jsx("button",{type:"button",onClick:()=>_e(ve),disabled:x,className:cn("flex items-center justify-center h-10 w-10 rounded-md border border-input bg-background","hover:bg-muted transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),title:`Edit ${ve.name}`,children:jsxRuntimeExports.jsx(Pencil,{className:"h-4 w-4"})})]})]}),jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[jsxRuntimeExports.jsx("label",{className:"text-xs text-muted-foreground",children:"Model"}),jsxRuntimeExports.jsxs("div",{className:"relative",children:[jsxRuntimeExports.jsx("select",{value:p,onChange:ee=>g(ee.target.value),disabled:x||ie.length===0,className:"h-10 w-full appearance-none rounded-md border border-input bg-background pl-3 pr-10 text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-primary disabled:opacity-70",children:ie.length===0?jsxRuntimeExports.jsx("option",{value:"",children:"No models available"}):ie.map(ee=>jsxRuntimeExports.jsx("option",{value:ee.id,children:ee.label},ee.id))}),jsxRuntimeExports.jsx(ChevronDown,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"})]})]}),ve&&jsxRuntimeExports.jsxs("div",{className:"rounded-md border border-border bg-muted/30 px-3 py-2 text-xs text-muted-foreground",children:[jsxRuntimeExports.jsxs("div",{children:[providerOptionLabel(ve),": ",ve.maskedCredential??"No credential"]}),jsxRuntimeExports.jsxs("div",{className:"opacity-70",children:["id: ",ve.id]})]}),jsxRuntimeExports.jsx("button",{type:"button",onClick:Ee,disabled:!W||!p||x,className:cn("inline-flex h-10 items-center justify-center gap-2 rounded-md border px-4 text-sm font-medium transition-colors","border-primary bg-primary text-primary-foreground hover:bg-primary/90","disabled:cursor-not-allowed disabled:opacity-60"),children:x?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),C?"Still applying…":"Updating model…"]}):W?"Save changes":jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(Check,{className:"h-4 w-4"}),"Up to date"]})}),j&&jsxRuntimeExports.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:j}),jsxRuntimeExports.jsx("div",{className:"pt-2 border-t border-border",children:jsxRuntimeExports.jsxs("button",{type:"button",onClick:be,className:cn("inline-flex h-10 w-full items-center justify-center gap-2 rounded-md border border-dashed border-border","text-sm font-medium text-muted-foreground","hover:border-primary hover:text-foreground hover:bg-muted/50 transition-colors"),children:[jsxRuntimeExports.jsx(Plus,{className:"h-4 w-4"}),"Add Provider"]})})]}),jsxRuntimeExports.jsx(ProviderEditor,{isOpen:L,onClose:ye,editingProvider:$})]})}function SessionList(){const t=useClappState("sessions"),a=(t==null?void 0:t.sessions)??[],l=t==null?void 0:t.globalModel,{emit:o}=useIntent(),[u,c]=reactExports.useState(!1),[d,m]=reactExports.useState(null),[p,g]=reactExports.useState(!1);reactExports.useEffect(()=>{o("settings.listSessions",{})},[o]);const x=()=>{c(!0),o("settings.listSessions",{}),setTimeout(()=>c(!1),1500)},b=L=>{m(L),o("settings.resetSessionModel",{sessionKey:L}),setTimeout(()=>m(null),2e3)},C=()=>{g(!0),o("settings.applyDefaultToAll",{}),setTimeout(()=>g(!1),3e3)},R=a.filter(L=>L.isOverride).length,j=a.find(L=>L.key==="agent:main:main")??a[0],B=!!(j!=null&&j.isOverride);return a.length===0?jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-3",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsx("div",{className:"space-y-1",children:jsxRuntimeExports.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Active Sessions"})}),jsxRuntimeExports.jsx("button",{onClick:x,disabled:u,className:"p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-50",title:"Refresh sessions",children:jsxRuntimeExports.jsx(RefreshCw,{className:cn("h-4 w-4",u&&"animate-spin")})})]}),jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground py-4 text-center border border-dashed border-border rounded-md",children:"No active sessions found"})]}):jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-3",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[jsxRuntimeExports.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Active Sessions"}),jsxRuntimeExports.jsxs("p",{className:"text-sm text-muted-foreground",children:[a.length," session",a.length!==1?"s":"",R>0&&jsxRuntimeExports.jsxs("span",{className:"text-amber-500 ml-1",children:["• ",R," override",R!==1?"s":""]})]})]}),jsxRuntimeExports.jsx("button",{onClick:x,disabled:u,className:"p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-50",title:"Refresh sessions",children:jsxRuntimeExports.jsx(RefreshCw,{className:cn("h-4 w-4",u&&"animate-spin")})})]}),jsxRuntimeExports.jsxs("div",{className:cn("rounded-lg border p-3 space-y-2",B?"border-amber-500/50 bg-amber-500/5":"border-border bg-muted/30"),children:[jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground",children:"Model source of truth"}),jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[jsxRuntimeExports.jsxs("div",{className:"min-w-0",children:[jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-xs",children:"Global default"}),jsxRuntimeExports.jsx("div",{className:"font-medium truncate",children:l??"unknown"})]}),jsxRuntimeExports.jsxs("div",{className:"min-w-0 text-right",children:[jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-xs",children:"This session"}),jsxRuntimeExports.jsx("div",{className:"font-medium truncate",children:(j==null?void 0:j.model)??"unknown"})]})]}),j&&jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsx("span",{className:cn("text-xs",B?"text-amber-500":"text-green-600 dark:text-green-400"),children:B?"Session override is active":"Session matches global default"}),B&&jsxRuntimeExports.jsx("button",{onClick:()=>b(j.key),disabled:d===j.key,className:"shrink-0 px-2 py-1 text-xs rounded-md border border-border hover:bg-muted transition-colors disabled:opacity-50",children:d===j.key?"Resetting…":"Reset this session"})]})]}),jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:a.map(L=>jsxRuntimeExports.jsxs("div",{className:cn("flex items-start justify-between gap-2 p-3 rounded-lg border",L.isOverride?"border-amber-500/50 bg-amber-500/5":"border-border bg-muted/30"),children:[jsxRuntimeExports.jsxs("div",{className:"flex-1 min-w-0",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[L.isOverride?jsxRuntimeExports.jsx(TriangleAlert,{className:"h-4 w-4 text-amber-500 shrink-0"}):jsxRuntimeExports.jsx(Check,{className:"h-4 w-4 text-green-500 shrink-0"}),jsxRuntimeExports.jsx("span",{className:"text-sm font-medium truncate",children:L.label})]}),jsxRuntimeExports.jsxs("div",{className:"mt-1 ml-6",children:[jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:L.modelLabel}),L.isOverride&&jsxRuntimeExports.jsx("span",{className:"text-xs text-amber-500 ml-2",children:"(override)"})]})]}),L.isOverride&&jsxRuntimeExports.jsx("button",{onClick:()=>b(L.key),disabled:d===L.key,className:cn("shrink-0 px-2 py-1 text-xs rounded-md border border-border","hover:bg-muted transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),title:"Reset to system default",children:d===L.key?jsxRuntimeExports.jsx(LoaderCircle,{className:"h-3 w-3 animate-spin"}):jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-1",children:[jsxRuntimeExports.jsx(RotateCcw,{className:"h-3 w-3"}),"Reset"]})})]},L.key))}),R>0&&jsxRuntimeExports.jsx("button",{onClick:C,disabled:p,className:cn("w-full py-2 px-4 text-sm font-medium rounded-md","border border-amber-500/50 text-amber-600 dark:text-amber-400","hover:bg-amber-500/10 transition-colors","disabled:opacity-50 disabled:cursor-not-allowed"),children:p?jsxRuntimeExports.jsxs("span",{className:"flex items-center justify-center gap-2",children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Applying to all sessions..."]}):`Apply default to all ${R} override${R!==1?"s":""}`})]})}function AccountCard({item:t}){const{emit:a}=useIntent(),[l,o]=reactExports.useState(!1);return jsxRuntimeExports.jsx(Card$1,{className:cn("p-4",!t.enabled&&"opacity-60"),children:jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsxs("div",{className:"flex-1",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("span",{className:"font-semibold",children:t.id}),!t.enabled&&jsxRuntimeExports.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",children:"Disabled"})]}),jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground",children:t.mode==="socket"?"Socket Mode":"HTTP Mode"}),jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Token: ",t.botToken]})]}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("button",{onClick:()=>a("slack.disableAccount",{accountId:t.id}),className:"px-3 py-1 text-sm rounded-md bg-muted hover:bg-muted/80",children:t.enabled?"Disable":"Enable"}),l?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx("button",{onClick:()=>{a("slack.deleteAccount",{accountId:t.id}),o(!1)},className:"px-3 py-1 text-sm rounded-md bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Confirm"}),jsxRuntimeExports.jsx("button",{onClick:()=>o(!1),className:"px-3 py-1 text-sm rounded-md bg-muted hover:bg-muted/80",children:"Cancel"})]}):jsxRuntimeExports.jsx("button",{onClick:()=>o(!0),className:"px-3 py-1 text-sm rounded-md bg-destructive/20 text-destructive hover:bg-destructive/30",children:"Remove"})]})]})})}function AccountEditor({account:t}){const{emit:a}=useIntent(),l=useClappState("slack.saving")??!1,o=useClappState("slack.saveError")??null,u=useClappState("slack.saveSuccess")??null,[c,d]=reactExports.useState(!1),m=reactExports.useRef(l),[p,g]=reactExports.useState((t==null?void 0:t.id)||""),[x,b]=reactExports.useState((t==null?void 0:t.mode)||"socket"),[C,R]=reactExports.useState((t==null?void 0:t.botToken)||""),[j,B]=reactExports.useState((t==null?void 0:t.appToken)||""),[L,D]=reactExports.useState((t==null?void 0:t.signingSecret)||""),[$,F]=reactExports.useState((t==null?void 0:t.webhookPath)||"/slack/events");reactExports.useEffect(()=>{l&&!m.current||!l&&m.current&&d(!1),m.current=l},[l]),reactExports.useEffect(()=>{if(!c)return;const H=setTimeout(()=>d(!1),2e4);return()=>clearTimeout(H)},[c]);const oe=()=>{d(!0),a("slack.saveAccount",{accountId:p||"default",mode:x,botToken:C,appToken:x==="socket"?j:void 0,signingSecret:x==="http"?L:void 0,webhookPath:x==="http"?$:void 0})},ie=()=>{g(""),b("socket"),R(""),B(""),D(""),F("/slack/events")};return u?jsxRuntimeExports.jsx(Card$1,{className:"p-6",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsx("p",{className:"text-sm text-green-600 font-medium",children:u}),jsxRuntimeExports.jsx("div",{className:"flex justify-end",children:jsxRuntimeExports.jsx(Button,{type:"button",onClick:()=>a("slack.cancelEdit"),children:"Done"})})]})}):jsxRuntimeExports.jsx(Card$1,{className:"p-6",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Account ID"}),jsxRuntimeExports.jsx(Input,{value:p,onChange:H=>g(H.target.value),placeholder:"default",disabled:c})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Mode"}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2 mt-2",children:[jsxRuntimeExports.jsx(Button,{type:"button",variant:x==="socket"?"default":"outline",onClick:()=>b("socket"),disabled:c,children:"Socket Mode"}),jsxRuntimeExports.jsx(Button,{type:"button",variant:x==="http"?"default":"outline",onClick:()=>b("http"),disabled:c,children:"HTTP Events API"})]})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Bot Token"}),jsxRuntimeExports.jsx(Input,{value:C,onChange:H=>R(H.target.value),placeholder:"xoxb-...",type:"password",disabled:c})]}),x==="socket"&&jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"App Token"}),jsxRuntimeExports.jsx(Input,{value:j,onChange:H=>B(H.target.value),placeholder:"xapp-...",type:"password",disabled:c})]}),x==="http"&&jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Signing Secret"}),jsxRuntimeExports.jsx(Input,{value:L,onChange:H=>D(H.target.value),placeholder:"Signing secret",type:"password",disabled:c})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Webhook Path"}),jsxRuntimeExports.jsx(Input,{value:$,onChange:H=>F(H.target.value),placeholder:"/slack/events",disabled:c})]})]}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2 justify-end pt-2",children:[jsxRuntimeExports.jsx(Button,{type:"button",variant:"outline",onClick:ie,disabled:c,children:"Clear"}),jsxRuntimeExports.jsx(Button,{type:"button",onClick:oe,disabled:!C||c,children:c?"Saving…":"Save Account"})]}),o&&jsxRuntimeExports.jsx("p",{className:"text-xs text-rose-500",children:o})]})})}function ChannelList({channels:t}){const{emit:a}=useIntent();return!Array.isArray(t)||t.length===0?jsxRuntimeExports.jsx("div",{className:"text-sm text-muted-foreground text-center py-4",children:"No channels configured"}):jsxRuntimeExports.jsx("div",{className:"space-y-2",children:t.map(l=>jsxRuntimeExports.jsx(Card$1,{className:"p-4",children:jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsxs("div",{className:"flex-1",children:[jsxRuntimeExports.jsx("div",{className:"font-semibold",children:l.name||l.id}),jsxRuntimeExports.jsxs("div",{className:"text-sm text-muted-foreground mt-1 space-y-1",children:[l.requireMention!==void 0&&jsxRuntimeExports.jsxs("div",{children:["Require mention: ",l.requireMention?"Yes":"No"]}),l.users&&l.users.length>0&&jsxRuntimeExports.jsxs("div",{children:["Users: ",l.users.join(", ")]}),l.skills&&l.skills.length>0&&jsxRuntimeExports.jsxs("div",{children:["Skills: ",l.skills.join(", ")]})]})]}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx(Button,{size:"sm",variant:"outline",onClick:()=>a("slack.editChannel",{channelId:l.id}),children:jsxRuntimeExports.jsx(SquarePen,{className:"h-4 w-4"})}),jsxRuntimeExports.jsx(Button,{size:"sm",variant:"destructive",onClick:()=>a("slack.removeChannel",{channelId:l.id}),children:jsxRuntimeExports.jsx(Trash2,{className:"h-4 w-4"})})]})]})},l.id))})}function ChannelEditor({channel:t,onClose:a}){const{emit:l}=useIntent(),[o,u]=reactExports.useState((t==null?void 0:t.id)||""),[c,d]=reactExports.useState((t==null?void 0:t.requireMention)??!0),[m,p]=reactExports.useState(((t==null?void 0:t.users)||[]).join(", ")),[g,x]=reactExports.useState(((t==null?void 0:t.skills)||[]).join(", ")),b=()=>{l("slack.saveChannel",{channelId:o,requireMention:c,users:m.split(",").map(C=>C.trim()).filter(Boolean),skills:g.split(",").map(C=>C.trim()).filter(Boolean)}),a==null||a()};return jsxRuntimeExports.jsx(Card$1,{className:"p-6 max-w-2xl mx-auto",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsx("h2",{className:"text-xl font-semibold",children:t?"Edit Channel":"Add Channel"}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Channel ID"}),jsxRuntimeExports.jsx(Input,{value:o,onChange:C=>u(C.target.value),placeholder:"C1234567890",disabled:!!t}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Use Slack channel ID or name"})]}),jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("input",{type:"checkbox",checked:c,onChange:C=>d(C.target.checked),id:"requireMention",className:"rounded border-gray-300"}),jsxRuntimeExports.jsx("label",{htmlFor:"requireMention",className:"text-sm font-medium cursor-pointer",children:"Require mention to respond"})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Allowed Users (optional)"}),jsxRuntimeExports.jsx(Input,{value:m,onChange:C=>p(C.target.value),placeholder:"user:U123, user:U456"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of user IDs or names"})]}),jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Custom Skills (optional)"}),jsxRuntimeExports.jsx(Input,{value:g,onChange:C=>x(C.target.value),placeholder:"weather, calendar"}),jsxRuntimeExports.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of skill IDs"})]}),jsxRuntimeExports.jsxs("div",{className:"flex gap-2 justify-end pt-4",children:[a&&jsxRuntimeExports.jsx(Button,{variant:"outline",onClick:a,children:"Cancel"}),jsxRuntimeExports.jsx(Button,{onClick:b,disabled:!o,children:"Save Channel"})]})]})})}function PolicySelector({value:t,type:a}){const{emit:l}=useIntent(),o=a==="dm"?[{value:"pairing",label:"Pairing (default)"},{value:"allowlist",label:"Allowlist"},{value:"open",label:"Open"},{value:"disabled",label:"Disabled"}]:[{value:"open",label:"Open"},{value:"allowlist",label:"Allowlist (recommended)"},{value:"disabled",label:"Disabled"}],u=c=>{a==="dm"?l("slack.setDmPolicy",{policy:c}):l("slack.setGroupPolicy",{policy:c})};return jsxRuntimeExports.jsx("select",{value:t,onChange:c=>u(c.target.value),className:"w-full px-3 py-2 border rounded-md bg-background",children:o.map(c=>jsxRuntimeExports.jsx("option",{value:c.value,children:c.label},c.value))})}function FeatureToggles({actions:t}){const{emit:a}=useIntent(),l=[{key:"messages",label:"Messages"},{key:"reactions",label:"Reactions"},{key:"pins",label:"Pins"},{key:"memberInfo",label:"Member Info"},{key:"emojiList",label:"Emoji List"}],o=(u,c)=>{a("slack.toggleAction",{group:u,enabled:c})};return jsxRuntimeExports.jsx("div",{className:"space-y-3",children:l.map(u=>{const c=t[u.key]!==!1;return jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntimeExports.jsx("span",{className:"text-sm font-medium",children:u.label}),jsxRuntimeExports.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[jsxRuntimeExports.jsx("input",{type:"checkbox",checked:c,onChange:d=>o(u.key,d.target.checked),className:"sr-only peer"}),jsxRuntimeExports.jsx("div",{className:"w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"})]})]},u.key)})})}function SlashCommandConfig({config:t}){const{emit:a}=useIntent(),[l,o]=reactExports.useState((t==null?void 0:t.enabled)||!1),[u,c]=reactExports.useState((t==null?void 0:t.name)||"openclaw"),d=()=>{a("slack.setSlashCommand",{enabled:l,name:u})};return jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntimeExports.jsx("input",{type:"checkbox",checked:l,onChange:m=>o(m.target.checked),id:"slashEnabled",className:"rounded border-gray-300"}),jsxRuntimeExports.jsx("label",{htmlFor:"slashEnabled",className:"text-sm font-medium cursor-pointer",children:"Enable single slash command"})]}),l&&jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("label",{className:"text-sm font-medium",children:"Command Name"}),jsxRuntimeExports.jsx(Input,{value:u,onChange:m=>c(m.target.value),placeholder:"openclaw"}),jsxRuntimeExports.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Register /",u," in Slack app settings"]})]}),jsxRuntimeExports.jsx(Button,{onClick:d,size:"sm",children:"Save"}),jsxRuntimeExports.jsxs("div",{className:"text-xs text-muted-foreground mt-4 p-3 bg-muted rounded-md",children:[jsxRuntimeExports.jsx("p",{className:"font-medium mb-1",children:"Note:"}),jsxRuntimeExports.jsxs("p",{children:["For native command support, set"," ",jsxRuntimeExports.jsx("code",{className:"bg-background px-1 py-0.5 rounded",children:"channels.slack.commands.native: true"})," ","and register matching slash commands in Slack (use /agentstatus for the status command)."]})]})]})}function ConnectionStatus({status:t}){var o,u;if(!t)return jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[jsxRuntimeExports.jsx(LoaderCircle,{className:"h-4 w-4 animate-spin"}),jsxRuntimeExports.jsx("span",{className:"text-sm",children:"Loading status..."})]});const a=((o=t.accounts)==null?void 0:o.filter(c=>c.connected).length)||0,l=((u=t.accounts)==null?void 0:u.length)||0;return jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:t.connected?jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(CircleCheckBig,{className:"h-5 w-5 text-green-600"}),jsxRuntimeExports.jsx("span",{className:"font-medium",children:"Connected"})]}):jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx(CircleX,{className:"h-5 w-5 text-red-600"}),jsxRuntimeExports.jsx("span",{className:"font-medium",children:"Disconnected"})]})}),t.accounts&&t.accounts.length>0&&jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[jsxRuntimeExports.jsxs("div",{className:"text-sm text-muted-foreground",children:[a," of ",l," accounts connected"]}),jsxRuntimeExports.jsx("div",{className:"space-y-1",children:t.accounts.map(c=>jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.connected?jsxRuntimeExports.jsx(CircleCheckBig,{className:"h-3 w-3 text-green-600"}):jsxRuntimeExports.jsx(CircleX,{className:"h-3 w-3 text-red-600"}),jsxRuntimeExports.jsx("span",{children:c.id})]},c.id))})]})]})}const componentMap={Card,Column,Row,Heading,TextInput,IntentForm,IntentButton,Skeleton,List,ListItem,Conditional,MarkdownContent,Icon,ChatLayout,ChatMessages,ChatInput,ProviderList,ProviderEditor,SessionList,AccountCard,AccountEditor,ChannelList,ChannelEditor,PolicySelector,FeatureToggles,SlashCommandConfig,ConnectionStatus};function LayoutNodeRenderer({node:t,moduleMap:a}){if(t.component==="Module"&&t.props.ref&&a){const u=String(t.props.ref),c=a.get(u);return c?jsxRuntimeExports.jsx(LayoutNodeRenderer,{node:c,moduleMap:a}):jsxRuntimeExports.jsxs("div",{className:"text-destructive text-sm p-2",children:["Module not found: ",u]})}const l=componentMap[t.component];if(!l)return jsxRuntimeExports.jsxs("div",{className:"text-destructive text-sm p-2",children:["Unknown component: ",t.component]});const o=t.children.map((u,c)=>typeof u=="string"?jsxRuntimeExports.jsx("span",{children:u},c):jsxRuntimeExports.jsx(LayoutNodeRenderer,{node:u,moduleMap:a},c));return jsxRuntimeExports.jsx(l,{...t.props,children:o})}function AppRenderer({spec:t,modules:a}){const l=reactExports.useMemo(()=>{const o=new Map;for(const u of a)o.set(`${u.domain}/${u.name}`,u.layout);return o},[a]);return jsxRuntimeExports.jsx("div",{className:"h-full overflow-y-auto p-4","data-app":t.name,children:jsxRuntimeExports.jsx(LayoutNodeRenderer,{node:t.layout,moduleMap:l})})}function ClappRenderer({clappId:t,transport:a}){const l=window.location.origin;return jsxRuntimeExports.jsx(ClappProvider,{serverUrl:l,clappId:t,transport:a,children:jsxRuntimeExports.jsx("div",{className:"flex flex-col h-full",children:jsxRuntimeExports.jsx(DynamicView,{clappId:t,transport:a})})})}function DynamicView({clappId:t,transport:a}){const[l,o]=reactExports.useState({status:"loading"});reactExports.useEffect(()=>{a.sendIntent(t,`${t}.init`,{})},[t,a]);const u=reactExports.useCallback(async()=>{try{const c=await a.fetchView(`${t}.app`);if(!c){o({status:"no-view"});return}const d=parseAppMd(c),p=(await Promise.all(d.modules.map(async g=>{const x=g.replace("/","."),b=await a.fetchView(`${x}.view`);return b?parseViewMd(b):null}))).filter(g=>g!==null);o({status:"ready",appSpec:d,modules:p})}catch(c){o({status:"error",message:c instanceof Error?c.message:"Failed to load views"})}},[t,a]);switch(reactExports.useEffect(()=>(u(),a.onView(d=>{(d===`${t}.app`||d.endsWith(".view"))&&u()})),[u,a,t]),l.status){case"loading":return jsxRuntimeExports.jsx("div",{className:"h-full p-4 animate-pulse",children:jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[jsxRuntimeExports.jsx("div",{className:"h-8 w-40 rounded-md bg-muted"}),jsxRuntimeExports.jsxs("div",{className:"rounded-xl border border-border p-4 space-y-3",children:[jsxRuntimeExports.jsx("div",{className:"h-4 w-32 rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-10 w-full rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-10 w-full rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-10 w-36 rounded bg-muted"})]}),jsxRuntimeExports.jsxs("div",{className:"rounded-xl border border-border p-4 space-y-3",children:[jsxRuntimeExports.jsx("div",{className:"h-4 w-28 rounded bg-muted"}),jsxRuntimeExports.jsx("div",{className:"h-20 w-full rounded bg-muted"})]})]})});case"no-view":return jsxRuntimeExports.jsx(StateInspector,{});case"error":return jsxRuntimeExports.jsxs("div",{className:"p-4",children:[jsxRuntimeExports.jsx("div",{className:"p-3 bg-destructive/10 text-destructive rounded-md text-sm",children:l.message}),jsxRuntimeExports.jsx("div",{className:"mt-4",children:jsxRuntimeExports.jsx(StateInspector,{})})]});case"ready":return jsxRuntimeExports.jsx(AppRenderer,{spec:l.appSpec,modules:l.modules})}}function StateInspector(){return jsxRuntimeExports.jsxs("div",{className:"p-4",children:[jsxRuntimeExports.jsx("div",{className:"text-xs text-muted-foreground mb-3 italic",children:"No view definition found. Showing raw state:"}),jsxRuntimeExports.jsx(StateTree,{})]})}function StateTree(){const{store:t}=useClappContext(),a=useStore(t,o=>o.state);return useClappLoading()?jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-sm",children:"Waiting for state..."}):!a||Object.keys(a).length===0?jsxRuntimeExports.jsx("div",{className:"text-muted-foreground text-sm",children:"No state available."}):jsxRuntimeExports.jsx("div",{className:"font-mono text-xs leading-relaxed",children:renderEntries(a,"")})}function renderEntries(t,a){return Object.entries(t).map(([l,o])=>{const u=a?`${a}.${l}`:l;return o!==null&&typeof o=="object"&&!Array.isArray(o)?jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx("div",{className:"text-muted-foreground font-semibold",children:u}),jsxRuntimeExports.jsx("div",{className:"pl-4",children:renderEntries(o,u)})]},u):jsxRuntimeExports.jsxs("div",{className:"flex gap-2 py-0.5",children:[jsxRuntimeExports.jsxs("span",{className:"text-muted-foreground",children:[u,":"]}),jsxRuntimeExports.jsx("span",{children:typeof o=="string"?o:JSON.stringify(o)})]},u)})}function getServerUrl(){return window.location.origin}function AppRoutes({transport:t,apps:a}){return jsxRuntimeExports.jsxs(Routes,{children:[jsxRuntimeExports.jsx(Route,{path:"/",element:jsxRuntimeExports.jsx(AppLauncher,{transport:t,apps:a})}),jsxRuntimeExports.jsx(Route,{path:"/apps/:appId",element:jsxRuntimeExports.jsx(AppView,{transport:t,apps:a})})]})}function AppLauncher({transport:t,apps:a}){const l=useNavigate(),o=u=>{l(`/apps/${u}`)};return jsxRuntimeExports.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-y-auto",children:[jsxRuntimeExports.jsx("header",{className:"flex items-center justify-center px-4 py-3 border-b border-border shrink-0",children:jsxRuntimeExports.jsx("h1",{className:"text-lg font-bold tracking-tight",children:"clapps"})}),jsxRuntimeExports.jsx(HomeScreen,{apps:a,transport:t,onOpenApp:o})]})}function AppView({transport:t,apps:a}){const{appId:l}=useParams(),o=useNavigate(),u=()=>{o("/")},c=a.find(d=>d.id===l);return jsxRuntimeExports.jsxs("div",{className:"absolute inset-0 flex flex-col overflow-hidden",children:[jsxRuntimeExports.jsxs("header",{className:"flex items-center px-4 py-3 border-b border-border shrink-0 min-h-[52px]",children:[jsxRuntimeExports.jsxs("button",{onClick:u,className:"flex items-center gap-0.5 text-primary text-sm font-medium -ml-1 pr-2","aria-label":"Back to home",children:[jsxRuntimeExports.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",className:"shrink-0",children:jsxRuntimeExports.jsx("path",{d:"M12.5 15L7.5 10L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),"Home"]}),jsxRuntimeExports.jsx("div",{className:"flex-1 text-center",children:jsxRuntimeExports.jsxs("span",{className:"text-sm font-semibold",children:[(c==null?void 0:c.emoji)&&jsxRuntimeExports.jsx("span",{className:"mr-1.5",children:c.emoji}),(c==null?void 0:c.name)??l]})}),jsxRuntimeExports.jsx("div",{className:"w-[60px]"})]}),l&&jsxRuntimeExports.jsx("div",{className:"flex-1 overflow-hidden",children:jsxRuntimeExports.jsx(ClappRenderer,{clappId:l,transport:t})})]})}function App(){const t=reactExports.useRef(void 0);t.current||(t.current=new ClappTransport({serverUrl:getServerUrl(),context:{platform:"web"}}));const a=t.current,[l,o]=reactExports.useState([]);return reactExports.useEffect(()=>{a.connect();const u=a.onApps(c=>{o(c)});return a.fetchApps().then(o).catch(()=>{}),()=>{u(),a.disconnect()}},[a]),jsxRuntimeExports.jsx("div",{className:"relative h-screen overflow-hidden bg-background",children:jsxRuntimeExports.jsx(BrowserRouter,{children:jsxRuntimeExports.jsx(AppRoutes,{transport:a,apps:l})})})}clientExports.createRoot(document.getElementById("root")).render(jsxRuntimeExports.jsx(reactExports.StrictMode,{children:jsxRuntimeExports.jsx(App,{})}));
|