@agentdocumentformat/cli 0.8.4 → 0.8.5
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/adf.mjs +2 -2
- package/dist/chunks/{chunk-2WIFHJV2.mjs → chunk-IHARCBZH.mjs} +8 -1
- package/dist/chunks/{claude-subscription-42L4YM5L.mjs → claude-subscription-X5EVR3Q4.mjs} +1 -1
- package/dist/chunks/{daemon-DK3KUDZJ.mjs → daemon-YRG2QUF4.mjs} +3 -3
- package/package.json +1 -1
- package/web/assets/{EditorPanel-5ZGWvexa.js → EditorPanel-YXnanvaL.js} +3 -3
- package/web/assets/{MeshGraphView-Vp2R5TLK.js → MeshGraphView-ChgwUT3O.js} +9 -9
- package/web/assets/{SettingsPage-_uHkBERV.js → SettingsPage-BTu2-Yon.js} +1 -1
- package/web/assets/{agent-window-B8X7FV4_.js → agent-window-DlJbRHzy.js} +1 -1
- package/web/assets/{agent.store-BHweGGTh.js → agent.store-CGzsE0VA.js} +1 -1
- package/web/assets/{app.store-j_-OuVPe.js → app.store-hw-ZYpyz.js} +1 -1
- package/web/assets/{document.store-CMD3_OM0.js → document.store-BcN3UW-e.js} +1 -1
- package/web/assets/{edit-recovery-Ce8tPQZl.js → edit-recovery-uWM2umPk.js} +1 -1
- package/web/assets/{index-DS9H-PJI.js → index-B0BKR-7b.js} +1 -1
- package/web/assets/{index-Ca6bEWGu.js → index-Ba28S-D0.js} +1 -1
- package/web/assets/{index-BQIEMvvt.js → index-BxmMf4oH.js} +1 -1
- package/web/assets/{index-DBFkrLao.js → index-BxrG4na5.js} +1 -1
- package/web/assets/{index-B5Eot_tL.js → index-C0ujp8ua.js} +1 -1
- package/web/assets/{index-KNnHrO8-.js → index-CBCcou8F.js} +1 -1
- package/web/assets/{index-nM_Q5x7Q.js → index-Cuc6TCV0.js} +1 -1
- package/web/assets/{index-B5FYMbFc.js → index-DlQ8IXY2.js} +1 -1
- package/web/assets/{index-C_gf4L3q.js → index-Dms-d0wP.js} +1 -1
- package/web/assets/{index-DF1leTEa.js → index-LwIi-F1W.js} +2 -2
- package/web/assets/{index-DkhbLs9K.js → index-mW7p_CTU.js} +1 -1
- package/web/assets/{main-o2ocfqUC.js → main-CR7cfmOT.js} +3 -3
- package/web/assets/{message-queue.store-ke_rFZAb.js → message-queue.store-BMjJTJTP.js} +1 -1
- package/web/assets/{react-D-F9gHrJ.js → react-wKFncLeZ.js} +1 -1
- package/web/assets/{window-kind-mxlpdE1l.js → window-kind-35FHmfEB.js} +1 -1
- package/web/assets/{with-selector-Ot-ZoUn0.js → with-selector-CBB0rjuB.js} +1 -1
- package/web/index.html +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{P as st,a as Q,b as v,v as it,N as Ee,s as Ie,T as H,r as ot,t as m,h as X,j as P,w as z,c as fe,x as at,y as lt,E as ht,z as ft,A as ut,B as dt,p as pt,C as ct,F as mt,f as Me,i as gt,G as kt,H as ue,J as Lt}from"./EditorPanel-5ZGWvexa.js";import{html as bt,htmlCompletionSource as wt}from"./index-DBFkrLao.js";import"./index-DF1leTEa.js";import"./edit-recovery-Ce8tPQZl.js";import"./react-D-F9gHrJ.js";import"./agent.store-BHweGGTh.js";import"./document.store-CMD3_OM0.js";import"./window-kind-mxlpdE1l.js";import"./app.store-j_-OuVPe.js";import"./main-o2ocfqUC.js";import"./message-queue.store-ke_rFZAb.js";import"./agent-window-B8X7FV4_.js";import"./with-selector-Ot-ZoUn0.js";import"./index-C_gf4L3q.js";import"./index-nM_Q5x7Q.js";import"./index-KNnHrO8-.js";class U{static create(e,r,n,s,i){let o=s+(s<<8)+e+(r<<4)|0;return new U(e,r,n,o,i,[],[])}constructor(e,r,n,s,i,o,a){this.type=e,this.value=r,this.from=n,this.hash=s,this.end=i,this.children=o,this.positions=a,this.hashProp=[[v.contextHash,s]]}addChild(e,r){e.prop(v.contextHash)!=this.hash&&(e=new H(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(r)}toTree(e,r=this.end){let n=this.children.length-1;return n>=0&&(r=Math.max(r,this.positions[n]+this.children[n].length+this.from)),new H(e.types[this.type],this.children,this.positions,r-this.from).balance({makeTree:(s,i,o)=>new H(Q.none,s,i,o,this.hashProp)})}}var u;(function(t){t[t.Document=1]="Document",t[t.CodeBlock=2]="CodeBlock",t[t.FencedCode=3]="FencedCode",t[t.Blockquote=4]="Blockquote",t[t.HorizontalRule=5]="HorizontalRule",t[t.BulletList=6]="BulletList",t[t.OrderedList=7]="OrderedList",t[t.ListItem=8]="ListItem",t[t.ATXHeading1=9]="ATXHeading1",t[t.ATXHeading2=10]="ATXHeading2",t[t.ATXHeading3=11]="ATXHeading3",t[t.ATXHeading4=12]="ATXHeading4",t[t.ATXHeading5=13]="ATXHeading5",t[t.ATXHeading6=14]="ATXHeading6",t[t.SetextHeading1=15]="SetextHeading1",t[t.SetextHeading2=16]="SetextHeading2",t[t.HTMLBlock=17]="HTMLBlock",t[t.LinkReference=18]="LinkReference",t[t.Paragraph=19]="Paragraph",t[t.CommentBlock=20]="CommentBlock",t[t.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",t[t.Escape=22]="Escape",t[t.Entity=23]="Entity",t[t.HardBreak=24]="HardBreak",t[t.Emphasis=25]="Emphasis",t[t.StrongEmphasis=26]="StrongEmphasis",t[t.Link=27]="Link",t[t.Image=28]="Image",t[t.InlineCode=29]="InlineCode",t[t.HTMLTag=30]="HTMLTag",t[t.Comment=31]="Comment",t[t.ProcessingInstruction=32]="ProcessingInstruction",t[t.Autolink=33]="Autolink",t[t.HeaderMark=34]="HeaderMark",t[t.QuoteMark=35]="QuoteMark",t[t.ListMark=36]="ListMark",t[t.LinkMark=37]="LinkMark",t[t.EmphasisMark=38]="EmphasisMark",t[t.CodeMark=39]="CodeMark",t[t.CodeText=40]="CodeText",t[t.CodeInfo=41]="CodeInfo",t[t.LinkTitle=42]="LinkTitle",t[t.LinkLabel=43]="LinkLabel",t[t.URL=44]="URL"})(u||(u={}));class St{constructor(e,r){this.start=e,this.content=r,this.marks=[],this.parsers=[]}}class Ct{constructor(){this.text="",this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return O(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,r=0,n=0){for(let s=r;s<e;s++)n+=this.text.charCodeAt(s)==9?4-n%4:1;return n}findColumn(e){let r=0;for(let n=0;r<this.text.length&&n<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return r}scrub(){if(!this.baseIndent)return this.text;let e="";for(let r=0;r<this.basePos;r++)e+=" ";return e+this.text.slice(this.basePos)}}function de(t,e,r){if(r.pos==r.text.length||t!=e.block&&r.indent>=e.stack[r.depth+1].value+r.baseIndent)return!0;if(r.indent>=r.baseIndent+4)return!1;let n=(t.type==u.OrderedList?oe:ie)(r,e,!1);return n>0&&(t.type!=u.BulletList||se(r,e,!1)<0)&&r.text.charCodeAt(r.pos+n-1)==t.value}const He={[u.Blockquote](t,e,r){return r.next!=62?!1:(r.markers.push(k(u.QuoteMark,e.lineStart+r.pos,e.lineStart+r.pos+1)),r.moveBase(r.pos+(A(r.text.charCodeAt(r.pos+1))?2:1)),t.end=e.lineStart+r.text.length,!0)},[u.ListItem](t,e,r){return r.indent<r.baseIndent+t.value&&r.next>-1?!1:(r.moveBaseColumn(r.baseIndent+t.value),!0)},[u.OrderedList]:de,[u.BulletList]:de,[u.Document](){return!0}};function A(t){return t==32||t==9||t==10||t==13}function O(t,e=0){for(;e<t.length&&A(t.charCodeAt(e));)e++;return e}function pe(t,e,r){for(;e>r&&A(t.charCodeAt(e-1));)e--;return e}function Pe(t){if(t.next!=96&&t.next!=126)return-1;let e=t.pos+1;for(;e<t.text.length&&t.text.charCodeAt(e)==t.next;)e++;if(e<t.pos+3)return-1;if(t.next==96){for(let r=e;r<t.text.length;r++)if(t.text.charCodeAt(r)==96)return-1}return e}function ve(t){return t.next!=62?-1:t.text.charCodeAt(t.pos+1)==32?2:1}function se(t,e,r){if(t.next!=42&&t.next!=45&&t.next!=95)return-1;let n=1;for(let s=t.pos+1;s<t.text.length;s++){let i=t.text.charCodeAt(s);if(i==t.next)n++;else if(!A(i))return-1}return r&&t.next==45&&Re(t)>-1&&t.depth==e.stack.length&&e.parser.leafBlockParsers.indexOf(De.SetextHeading)>-1||n<3?-1:1}function Ne(t,e){for(let r=t.stack.length-1;r>=0;r--)if(t.stack[r].type==e)return!0;return!1}function ie(t,e,r){return(t.next==45||t.next==43||t.next==42)&&(t.pos==t.text.length-1||A(t.text.charCodeAt(t.pos+1)))&&(!r||Ne(e,u.BulletList)||t.skipSpace(t.pos+2)<t.text.length)?1:-1}function oe(t,e,r){let n=t.pos,s=t.next;for(;s>=48&&s<=57;){n++;if(n==t.text.length)return-1;s=t.text.charCodeAt(n)}return n==t.pos||n>t.pos+9||s!=46&&s!=41||n<t.text.length-1&&!A(t.text.charCodeAt(n+1))||r&&!Ne(e,u.OrderedList)&&(t.skipSpace(n+1)==t.text.length||n>t.pos+1||t.next!=49)?-1:n+1-t.pos}function ye(t){if(t.next!=35)return-1;let e=t.pos+1;for(;e<t.text.length&&t.text.charCodeAt(e)==35;)e++;if(e<t.text.length&&t.text.charCodeAt(e)!=32)return-1;let r=e-t.pos;return r>6?-1:r}function Re(t){if(t.next!=45&&t.next!=61||t.indent>=t.baseIndent+4)return-1;let e=t.pos+1;for(;e<t.text.length&&t.text.charCodeAt(e)==t.next;)e++;let r=e;for(;e<t.text.length&&A(t.text.charCodeAt(e));)e++;return e==t.text.length?r:-1}const W=/^[ \t]*$/,Oe=/-->/,Te=/\?>/,ee=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,Oe],[/^\s*<\?/,Te],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,W],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,W]];function ze(t,e,r){if(t.next!=60)return-1;let n=t.text.slice(t.pos);for(let s=0,i=ee.length-(r?1:0);s<i;s++)if(ee[s][0].test(n))return s;return-1}function ce(t,e){let r=t.countIndent(e,t.pos,t.indent),n=t.countIndent(t.skipSpace(e),e,r);return n>=r+5?r+1:n}function x(t,e,r){let n=t.length-1;n>=0&&t[n].to==e&&t[n].type==u.CodeText?t[n].to=r:t.push(k(u.CodeText,e,r))}const $={LinkReference:void 0,IndentedCode(t,e){let r=e.baseIndent+4;if(e.indent<r)return!1;let n=e.findColumn(r),s=t.lineStart+n,i=t.lineStart+e.text.length,o=[],a=[];for(x(o,s,i);t.nextLine()&&e.depth>=t.stack.length;)if(e.pos==e.text.length){x(a,t.lineStart-1,t.lineStart);for(let l of e.markers)a.push(l)}else{if(e.indent<r)break;{if(a.length){for(let h of a)h.type==u.CodeText?x(o,h.from,h.to):o.push(h);a=[]}x(o,t.lineStart-1,t.lineStart);for(let h of e.markers)o.push(h);i=t.lineStart+e.text.length;let l=t.lineStart+e.findColumn(e.baseIndent+4);l<i&&x(o,l,i)}}return a.length&&(a=a.filter(l=>l.type!=u.CodeText),a.length&&(e.markers=a.concat(e.markers))),t.addNode(t.buffer.writeElements(o,-s).finish(u.CodeBlock,i-s),s),!0},FencedCode(t,e){let r=Pe(e);if(r<0)return!1;let n=t.lineStart+e.pos,s=e.next,i=r-e.pos,o=e.skipSpace(r),a=pe(e.text,e.text.length,o),l=[k(u.CodeMark,n,n+i)];o<a&&l.push(k(u.CodeInfo,t.lineStart+o,t.lineStart+a));for(let h=!0,f=!0,p=!1;t.nextLine()&&e.depth>=t.stack.length;h=!1){let d=e.pos;if(e.indent-e.baseIndent<4)for(;d<e.text.length&&e.text.charCodeAt(d)==s;)d++;if(d-e.pos>=i&&e.skipSpace(d)==e.text.length){for(let c of e.markers)l.push(c);f&&p&&x(l,t.lineStart-1,t.lineStart),l.push(k(u.CodeMark,t.lineStart+e.pos,t.lineStart+d)),t.nextLine();break}else{p=!0,h||(x(l,t.lineStart-1,t.lineStart),f=!1);for(let g of e.markers)l.push(g);let c=t.lineStart+e.basePos,L=t.lineStart+e.text.length;c<L&&(x(l,c,L),f=!1)}}return t.addNode(t.buffer.writeElements(l,-n).finish(u.FencedCode,t.prevLineEnd()-n),n),!0},Blockquote(t,e){let r=ve(e);return r<0?!1:(t.startContext(u.Blockquote,e.pos),t.addNode(u.QuoteMark,t.lineStart+e.pos,t.lineStart+e.pos+1),e.moveBase(e.pos+r),null)},HorizontalRule(t,e){if(se(e,t,!1)<0)return!1;let r=t.lineStart+e.pos;return t.nextLine(),t.addNode(u.HorizontalRule,r),!0},BulletList(t,e){let r=ie(e,t,!1);if(r<0)return!1;t.block.type!=u.BulletList&&t.startContext(u.BulletList,e.basePos,e.next);let n=ce(e,e.pos+1);return t.startContext(u.ListItem,e.basePos,n-e.baseIndent),t.addNode(u.ListMark,t.lineStart+e.pos,t.lineStart+e.pos+r),e.moveBaseColumn(n),null},OrderedList(t,e){let r=oe(e,t,!1);if(r<0)return!1;t.block.type!=u.OrderedList&&t.startContext(u.OrderedList,e.basePos,e.text.charCodeAt(e.pos+r-1));let n=ce(e,e.pos+r);return t.startContext(u.ListItem,e.basePos,n-e.baseIndent),t.addNode(u.ListMark,t.lineStart+e.pos,t.lineStart+e.pos+r),e.moveBaseColumn(n),null},ATXHeading(t,e){let r=ye(e);if(r<0)return!1;let n=e.pos,s=t.lineStart+n,i=pe(e.text,e.text.length,n),o=i;for(;o>n&&e.text.charCodeAt(o-1)==e.next;)o--;(o==i||o==n||!A(e.text.charCodeAt(o-1)))&&(o=e.text.length);let a=t.buffer.write(u.HeaderMark,0,r).writeElements(t.parser.parseInline(e.text.slice(n+r+1,o),s+r+1),-s);o<e.text.length&&a.write(u.HeaderMark,o-n,i-n);let l=a.finish(u.ATXHeading1-1+r,e.text.length-n);return t.nextLine(),t.addNode(l,s),!0},HTMLBlock(t,e){let r=ze(e,t,!1);if(r<0)return!1;let n=t.lineStart+e.pos,s=ee[r][1],i=[],o=s!=W;for(;!s.test(e.text)&&t.nextLine();){if(e.depth<t.stack.length){o=!1;break}for(let h of e.markers)i.push(h)}o&&t.nextLine();let a=s==Oe?u.CommentBlock:s==Te?u.ProcessingInstructionBlock:u.HTMLBlock,l=t.prevLineEnd();return t.addNode(t.buffer.writeElements(i,-n).finish(a,l-n),n),!0},SetextHeading:void 0};class At{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,r,n){if(this.stage==-1)return!1;let s=n.content+`
|
|
1
|
+
import{P as st,a as Q,b as v,v as it,N as Ee,s as Ie,T as H,r as ot,t as m,h as X,j as P,w as z,c as fe,x as at,y as lt,E as ht,z as ft,A as ut,B as dt,p as pt,C as ct,F as mt,f as Me,i as gt,G as kt,H as ue,J as Lt}from"./EditorPanel-YXnanvaL.js";import{html as bt,htmlCompletionSource as wt}from"./index-BxrG4na5.js";import"./index-LwIi-F1W.js";import"./edit-recovery-uWM2umPk.js";import"./react-wKFncLeZ.js";import"./agent.store-CGzsE0VA.js";import"./document.store-BcN3UW-e.js";import"./window-kind-35FHmfEB.js";import"./app.store-hw-ZYpyz.js";import"./main-CR7cfmOT.js";import"./message-queue.store-BMjJTJTP.js";import"./agent-window-DlJbRHzy.js";import"./with-selector-CBB0rjuB.js";import"./index-Dms-d0wP.js";import"./index-Cuc6TCV0.js";import"./index-CBCcou8F.js";class U{static create(e,r,n,s,i){let o=s+(s<<8)+e+(r<<4)|0;return new U(e,r,n,o,i,[],[])}constructor(e,r,n,s,i,o,a){this.type=e,this.value=r,this.from=n,this.hash=s,this.end=i,this.children=o,this.positions=a,this.hashProp=[[v.contextHash,s]]}addChild(e,r){e.prop(v.contextHash)!=this.hash&&(e=new H(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(r)}toTree(e,r=this.end){let n=this.children.length-1;return n>=0&&(r=Math.max(r,this.positions[n]+this.children[n].length+this.from)),new H(e.types[this.type],this.children,this.positions,r-this.from).balance({makeTree:(s,i,o)=>new H(Q.none,s,i,o,this.hashProp)})}}var u;(function(t){t[t.Document=1]="Document",t[t.CodeBlock=2]="CodeBlock",t[t.FencedCode=3]="FencedCode",t[t.Blockquote=4]="Blockquote",t[t.HorizontalRule=5]="HorizontalRule",t[t.BulletList=6]="BulletList",t[t.OrderedList=7]="OrderedList",t[t.ListItem=8]="ListItem",t[t.ATXHeading1=9]="ATXHeading1",t[t.ATXHeading2=10]="ATXHeading2",t[t.ATXHeading3=11]="ATXHeading3",t[t.ATXHeading4=12]="ATXHeading4",t[t.ATXHeading5=13]="ATXHeading5",t[t.ATXHeading6=14]="ATXHeading6",t[t.SetextHeading1=15]="SetextHeading1",t[t.SetextHeading2=16]="SetextHeading2",t[t.HTMLBlock=17]="HTMLBlock",t[t.LinkReference=18]="LinkReference",t[t.Paragraph=19]="Paragraph",t[t.CommentBlock=20]="CommentBlock",t[t.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",t[t.Escape=22]="Escape",t[t.Entity=23]="Entity",t[t.HardBreak=24]="HardBreak",t[t.Emphasis=25]="Emphasis",t[t.StrongEmphasis=26]="StrongEmphasis",t[t.Link=27]="Link",t[t.Image=28]="Image",t[t.InlineCode=29]="InlineCode",t[t.HTMLTag=30]="HTMLTag",t[t.Comment=31]="Comment",t[t.ProcessingInstruction=32]="ProcessingInstruction",t[t.Autolink=33]="Autolink",t[t.HeaderMark=34]="HeaderMark",t[t.QuoteMark=35]="QuoteMark",t[t.ListMark=36]="ListMark",t[t.LinkMark=37]="LinkMark",t[t.EmphasisMark=38]="EmphasisMark",t[t.CodeMark=39]="CodeMark",t[t.CodeText=40]="CodeText",t[t.CodeInfo=41]="CodeInfo",t[t.LinkTitle=42]="LinkTitle",t[t.LinkLabel=43]="LinkLabel",t[t.URL=44]="URL"})(u||(u={}));class St{constructor(e,r){this.start=e,this.content=r,this.marks=[],this.parsers=[]}}class Ct{constructor(){this.text="",this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return O(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,r=0,n=0){for(let s=r;s<e;s++)n+=this.text.charCodeAt(s)==9?4-n%4:1;return n}findColumn(e){let r=0;for(let n=0;r<this.text.length&&n<e;r++)n+=this.text.charCodeAt(r)==9?4-n%4:1;return r}scrub(){if(!this.baseIndent)return this.text;let e="";for(let r=0;r<this.basePos;r++)e+=" ";return e+this.text.slice(this.basePos)}}function de(t,e,r){if(r.pos==r.text.length||t!=e.block&&r.indent>=e.stack[r.depth+1].value+r.baseIndent)return!0;if(r.indent>=r.baseIndent+4)return!1;let n=(t.type==u.OrderedList?oe:ie)(r,e,!1);return n>0&&(t.type!=u.BulletList||se(r,e,!1)<0)&&r.text.charCodeAt(r.pos+n-1)==t.value}const He={[u.Blockquote](t,e,r){return r.next!=62?!1:(r.markers.push(k(u.QuoteMark,e.lineStart+r.pos,e.lineStart+r.pos+1)),r.moveBase(r.pos+(A(r.text.charCodeAt(r.pos+1))?2:1)),t.end=e.lineStart+r.text.length,!0)},[u.ListItem](t,e,r){return r.indent<r.baseIndent+t.value&&r.next>-1?!1:(r.moveBaseColumn(r.baseIndent+t.value),!0)},[u.OrderedList]:de,[u.BulletList]:de,[u.Document](){return!0}};function A(t){return t==32||t==9||t==10||t==13}function O(t,e=0){for(;e<t.length&&A(t.charCodeAt(e));)e++;return e}function pe(t,e,r){for(;e>r&&A(t.charCodeAt(e-1));)e--;return e}function Pe(t){if(t.next!=96&&t.next!=126)return-1;let e=t.pos+1;for(;e<t.text.length&&t.text.charCodeAt(e)==t.next;)e++;if(e<t.pos+3)return-1;if(t.next==96){for(let r=e;r<t.text.length;r++)if(t.text.charCodeAt(r)==96)return-1}return e}function ve(t){return t.next!=62?-1:t.text.charCodeAt(t.pos+1)==32?2:1}function se(t,e,r){if(t.next!=42&&t.next!=45&&t.next!=95)return-1;let n=1;for(let s=t.pos+1;s<t.text.length;s++){let i=t.text.charCodeAt(s);if(i==t.next)n++;else if(!A(i))return-1}return r&&t.next==45&&Re(t)>-1&&t.depth==e.stack.length&&e.parser.leafBlockParsers.indexOf(De.SetextHeading)>-1||n<3?-1:1}function Ne(t,e){for(let r=t.stack.length-1;r>=0;r--)if(t.stack[r].type==e)return!0;return!1}function ie(t,e,r){return(t.next==45||t.next==43||t.next==42)&&(t.pos==t.text.length-1||A(t.text.charCodeAt(t.pos+1)))&&(!r||Ne(e,u.BulletList)||t.skipSpace(t.pos+2)<t.text.length)?1:-1}function oe(t,e,r){let n=t.pos,s=t.next;for(;s>=48&&s<=57;){n++;if(n==t.text.length)return-1;s=t.text.charCodeAt(n)}return n==t.pos||n>t.pos+9||s!=46&&s!=41||n<t.text.length-1&&!A(t.text.charCodeAt(n+1))||r&&!Ne(e,u.OrderedList)&&(t.skipSpace(n+1)==t.text.length||n>t.pos+1||t.next!=49)?-1:n+1-t.pos}function ye(t){if(t.next!=35)return-1;let e=t.pos+1;for(;e<t.text.length&&t.text.charCodeAt(e)==35;)e++;if(e<t.text.length&&t.text.charCodeAt(e)!=32)return-1;let r=e-t.pos;return r>6?-1:r}function Re(t){if(t.next!=45&&t.next!=61||t.indent>=t.baseIndent+4)return-1;let e=t.pos+1;for(;e<t.text.length&&t.text.charCodeAt(e)==t.next;)e++;let r=e;for(;e<t.text.length&&A(t.text.charCodeAt(e));)e++;return e==t.text.length?r:-1}const W=/^[ \t]*$/,Oe=/-->/,Te=/\?>/,ee=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,Oe],[/^\s*<\?/,Te],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,W],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,W]];function ze(t,e,r){if(t.next!=60)return-1;let n=t.text.slice(t.pos);for(let s=0,i=ee.length-(r?1:0);s<i;s++)if(ee[s][0].test(n))return s;return-1}function ce(t,e){let r=t.countIndent(e,t.pos,t.indent),n=t.countIndent(t.skipSpace(e),e,r);return n>=r+5?r+1:n}function x(t,e,r){let n=t.length-1;n>=0&&t[n].to==e&&t[n].type==u.CodeText?t[n].to=r:t.push(k(u.CodeText,e,r))}const $={LinkReference:void 0,IndentedCode(t,e){let r=e.baseIndent+4;if(e.indent<r)return!1;let n=e.findColumn(r),s=t.lineStart+n,i=t.lineStart+e.text.length,o=[],a=[];for(x(o,s,i);t.nextLine()&&e.depth>=t.stack.length;)if(e.pos==e.text.length){x(a,t.lineStart-1,t.lineStart);for(let l of e.markers)a.push(l)}else{if(e.indent<r)break;{if(a.length){for(let h of a)h.type==u.CodeText?x(o,h.from,h.to):o.push(h);a=[]}x(o,t.lineStart-1,t.lineStart);for(let h of e.markers)o.push(h);i=t.lineStart+e.text.length;let l=t.lineStart+e.findColumn(e.baseIndent+4);l<i&&x(o,l,i)}}return a.length&&(a=a.filter(l=>l.type!=u.CodeText),a.length&&(e.markers=a.concat(e.markers))),t.addNode(t.buffer.writeElements(o,-s).finish(u.CodeBlock,i-s),s),!0},FencedCode(t,e){let r=Pe(e);if(r<0)return!1;let n=t.lineStart+e.pos,s=e.next,i=r-e.pos,o=e.skipSpace(r),a=pe(e.text,e.text.length,o),l=[k(u.CodeMark,n,n+i)];o<a&&l.push(k(u.CodeInfo,t.lineStart+o,t.lineStart+a));for(let h=!0,f=!0,p=!1;t.nextLine()&&e.depth>=t.stack.length;h=!1){let d=e.pos;if(e.indent-e.baseIndent<4)for(;d<e.text.length&&e.text.charCodeAt(d)==s;)d++;if(d-e.pos>=i&&e.skipSpace(d)==e.text.length){for(let c of e.markers)l.push(c);f&&p&&x(l,t.lineStart-1,t.lineStart),l.push(k(u.CodeMark,t.lineStart+e.pos,t.lineStart+d)),t.nextLine();break}else{p=!0,h||(x(l,t.lineStart-1,t.lineStart),f=!1);for(let g of e.markers)l.push(g);let c=t.lineStart+e.basePos,L=t.lineStart+e.text.length;c<L&&(x(l,c,L),f=!1)}}return t.addNode(t.buffer.writeElements(l,-n).finish(u.FencedCode,t.prevLineEnd()-n),n),!0},Blockquote(t,e){let r=ve(e);return r<0?!1:(t.startContext(u.Blockquote,e.pos),t.addNode(u.QuoteMark,t.lineStart+e.pos,t.lineStart+e.pos+1),e.moveBase(e.pos+r),null)},HorizontalRule(t,e){if(se(e,t,!1)<0)return!1;let r=t.lineStart+e.pos;return t.nextLine(),t.addNode(u.HorizontalRule,r),!0},BulletList(t,e){let r=ie(e,t,!1);if(r<0)return!1;t.block.type!=u.BulletList&&t.startContext(u.BulletList,e.basePos,e.next);let n=ce(e,e.pos+1);return t.startContext(u.ListItem,e.basePos,n-e.baseIndent),t.addNode(u.ListMark,t.lineStart+e.pos,t.lineStart+e.pos+r),e.moveBaseColumn(n),null},OrderedList(t,e){let r=oe(e,t,!1);if(r<0)return!1;t.block.type!=u.OrderedList&&t.startContext(u.OrderedList,e.basePos,e.text.charCodeAt(e.pos+r-1));let n=ce(e,e.pos+r);return t.startContext(u.ListItem,e.basePos,n-e.baseIndent),t.addNode(u.ListMark,t.lineStart+e.pos,t.lineStart+e.pos+r),e.moveBaseColumn(n),null},ATXHeading(t,e){let r=ye(e);if(r<0)return!1;let n=e.pos,s=t.lineStart+n,i=pe(e.text,e.text.length,n),o=i;for(;o>n&&e.text.charCodeAt(o-1)==e.next;)o--;(o==i||o==n||!A(e.text.charCodeAt(o-1)))&&(o=e.text.length);let a=t.buffer.write(u.HeaderMark,0,r).writeElements(t.parser.parseInline(e.text.slice(n+r+1,o),s+r+1),-s);o<e.text.length&&a.write(u.HeaderMark,o-n,i-n);let l=a.finish(u.ATXHeading1-1+r,e.text.length-n);return t.nextLine(),t.addNode(l,s),!0},HTMLBlock(t,e){let r=ze(e,t,!1);if(r<0)return!1;let n=t.lineStart+e.pos,s=ee[r][1],i=[],o=s!=W;for(;!s.test(e.text)&&t.nextLine();){if(e.depth<t.stack.length){o=!1;break}for(let h of e.markers)i.push(h)}o&&t.nextLine();let a=s==Oe?u.CommentBlock:s==Te?u.ProcessingInstructionBlock:u.HTMLBlock,l=t.prevLineEnd();return t.addNode(t.buffer.writeElements(i,-n).finish(a,l-n),n),!0},SetextHeading:void 0};class At{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,r,n){if(this.stage==-1)return!1;let s=n.content+`
|
|
2
2
|
`+r.scrub(),i=this.advance(s);return i>-1&&i<s.length?this.complete(e,n,i):!1}finish(e,r){return(this.stage==2||this.stage==3)&&O(r.content,this.pos)==r.content.length?this.complete(e,r,r.content.length):!1}complete(e,r,n){return e.addLeafElement(r,k(u.LinkReference,this.start,this.start+n,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;){if(this.stage==-1)return-1;if(this.stage==0){if(!this.nextStage(Ze(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(k(u.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(qe(e,O(e,this.pos),this.start)))return-1}else if(this.stage==2){let r=O(e,this.pos),n=0;if(r>this.pos){let s=Qe(e,r,this.start);if(s){let i=G(e,s.to-this.start);i>0&&(this.nextStage(s),n=i)}}return n||(n=G(e,this.pos)),n>0&&n<e.length?n:-1}else return G(e,this.pos)}}}function G(t,e){for(;e<t.length;e++){let r=t.charCodeAt(e);if(r==10)break;if(!A(r))return-1}return e}class xt{nextLine(e,r,n){let s=r.depth<e.stack.length?-1:Re(r),i=r.next;if(s<0)return!1;let o=k(u.HeaderMark,e.lineStart+r.pos,e.lineStart+s);return e.nextLine(),e.addLeafElement(n,k(i==61?u.SetextHeading1:u.SetextHeading2,n.start,e.prevLineEnd(),[...e.parser.parseInline(n.content,n.start),o])),!0}finish(){return!1}}const De={LinkReference(t,e){return e.content.charCodeAt(0)==91?new At(e):null},SetextHeading(){return new xt}},Bt=[(t,e)=>ye(e)>=0,(t,e)=>Pe(e)>=0,(t,e)=>ve(e)>=0,(t,e)=>ie(e,t,!0)>=0,(t,e)=>oe(e,t,!0)>=0,(t,e)=>se(e,t,!0)>=0,(t,e)=>ze(e,t,!0)>=0],Et={text:"",end:0};class It{constructor(e,r,n,s){this.parser=e,this.input=r,this.ranges=s,this.line=new Ct,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=s[s.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=s[0].from,this.block=U.create(u.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=n.length?new Pt(n,r):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(let n=0;;){let s=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;n<e.markers.length&&(!s||e.markers[n].from<s.end);){let i=e.markers[n++];this.addNode(i.type,i.from,i.to)}if(!s)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;e:for(;;){for(let n of this.parser.blockParsers)if(n){let s=n(this,e);if(s!=!1){if(s==!0)return null;e.forward();continue e}}break}let r=new St(this.lineStart+e.pos,e.text.slice(e.pos));for(let n of this.parser.leafBlockParsers)if(n){let s=n(this,r);s&&r.parsers.push(s)}e:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let n of this.parser.endLeafBlock)if(n(this,e,r))break e}for(let n of r.parsers)if(n.nextLine(this,e,r))return null;r.content+=`
|
|
3
3
|
`+e.scrub();for(let n of e.markers)r.marks.push(n)}return this.finishLeaf(r),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let r=this.fragments.takeNodes(this);return r?(this.absoluteLineStart+=r,this.lineStart=Ge(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let r=Et;if(r.end=e,e>=this.to)r.text="";else if(r.text=this.lineChunkAt(e),r.end+=r.text.length,this.ranges.length>1){let n=this.absoluteLineStart,s=this.rangeI;for(;this.ranges[s].to<r.end;){s++;let i=this.ranges[s].from,o=this.lineChunkAt(i);r.end=i+o.length,r.text=r.text.slice(0,this.ranges[s-1].to-n)+o,n=r.end-r.text.length}}return r}readLine(){let{line:e}=this,{text:r,end:n}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=n,e.reset(r);e.depth<this.stack.length;e.depth++){let s=this.stack[e.depth],i=this.parser.skipContextMarkup[s.type];if(!i)throw new Error("Unhandled block context "+u[s.type]);let o=this.line.markers.length;if(!i(s,this,e)){this.line.markers.length>o&&(s.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let r=this.input.chunk(e),n;if(this.input.lineChunks)n=r==`
|
|
4
4
|
`?"":r;else{let s=r.indexOf(`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/html-BlS82ilI.js","assets/javascript-wDzz0qaB.js","assets/css-Z72CF80r.js","assets/SettingsPage-
|
|
2
|
-
import{a as u,j as t,b as Lb,g as $b,n as Ws,L as ze,m as Xm,W as Ob,c as Db,_ as kt,d as Fb,R as Bb}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/html-BlS82ilI.js","assets/javascript-wDzz0qaB.js","assets/css-Z72CF80r.js","assets/SettingsPage-BTu2-Yon.js","assets/index-LwIi-F1W.js","assets/index-CuTaWSEs.css","assets/app.store-hw-ZYpyz.js","assets/window-kind-35FHmfEB.js","assets/react-wKFncLeZ.js","assets/agent-window-DlJbRHzy.js","assets/document.store-BcN3UW-e.js","assets/agent.store-CGzsE0VA.js","assets/message-queue.store-BMjJTJTP.js","assets/edit-recovery-uWM2umPk.js","assets/MeshGraphView-ChgwUT3O.js","assets/with-selector-CBB0rjuB.js","assets/MeshGraphView-BZV40eAE.css","assets/EditorPanel-YXnanvaL.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{a as u,j as t,b as Lb,g as $b,n as Ws,L as ze,m as Xm,W as Ob,c as Db,_ as kt,d as Fb,R as Bb}from"./index-LwIi-F1W.js";import{useDocumentStore as de}from"./document.store-BcN3UW-e.js";import{u as Z,M as Tt,s as Pt}from"./agent.store-CGzsE0VA.js";import{c as zb,u as F,S as Wb,d as xa,e as uf,f as Hb,g as Mc,h as ff,i as Jm,l as Qm,j as Rl,k as Ub,m as Kb,p as qb,s as Zm,n as ex,b as tx,L as Vb,o as Gb,q as hf,r as pf,R as Pl,t as mf,v as xf,w as gf,x as Yb}from"./app.store-hw-ZYpyz.js";import{i as Ud,u as ft,b as $r,e as Or,r as Xb,w as Jb,a as Qb,s as Ii,c as Zb}from"./edit-recovery-uWM2umPk.js";import{n as St,a as fn,b as Kd,u as us,s as ev,M as tv,i as nx,p as ll}from"./message-queue.store-BMjJTJTP.js";import{u as Ks,o as V,c as va,d as nv,w as Ra,p as sx,a as st,e as Oa,f as ln,g as sv,h as av,i as rv,q as ov,j as iv,k as lv,l as cv,b as Ic,m as dv,n as Lc,r as bf,t as ax,v as rx,x as uv,y as fv}from"./agent-window-DlJbRHzy.js";import{c as Pn}from"./react-wKFncLeZ.js";import{r as Yt,w as yn,i as Ve,c as cl,e as ox,d as qs,b as Ea,f as hv,u as $c,a as pv}from"./window-kind-35FHmfEB.js";const vf=e=>typeof e=="function"?e():e;function dl(e){const n=u.useRef(e);n.current=e;const s=u.useRef(null);return u.useEffect(()=>()=>s.current?.(),[]),u.useCallback(a=>{if(a.button!==0)return;a.preventDefault();const{axis:r,grow:o,getStart:i}=n.current,l=r==="x"?a.clientX:a.clientY,c=i(),f=vf(n.current.min),h=Math.max(f,vf(n.current.max));let m=null,p=0;const d=()=>{p=0,m!==null&&n.current.onDrag(m)};document.body.style.cursor=r==="x"?"col-resize":"row-resize",document.body.style.userSelect="none",document.body.classList.add("panel-resizing");const b=j=>{const y=((r==="x"?j.clientX:j.clientY)-l)*o,S=zb(c+y,f,h);S!==m&&(m=S,p||(p=requestAnimationFrame(d)))},g=()=>{p&&(cancelAnimationFrame(p),p=0),document.body.style.cursor="",document.body.style.userSelect="",document.body.classList.remove("panel-resizing"),document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",w),s.current=null},w=()=>{g(),m!==null&&(n.current.onDrag(m),n.current.onCommit?.(m))};s.current=g,document.addEventListener("mousemove",b),document.addEventListener("mouseup",w)},[])}const qd="--adf-sidebar-width";function kf(e){document.documentElement.style.setProperty(qd,`${e}px`)}function mv({children:e}){const n=F(i=>i.sidebarCollapsed),s=F(i=>i.sidebarWidth),a=F(i=>i.setSidebarWidth);u.useLayoutEffect(()=>kf(s),[s]);const r=dl({axis:"x",grow:1,min:Wb,max:()=>Math.min(Hb,Math.round(window.innerWidth*Mc/100)),getStart:()=>s,onDrag:kf,onCommit:i=>{a(i),xa(uf,i)}}),o=()=>{a(ff),xa(uf,ff)};return t.jsxs("div",{className:"relative shrink-0 flex",style:n?void 0:{width:`var(${qd})`,maxWidth:`${Mc}vw`},children:[e,!n&&t.jsx("div",{onMouseDown:r,onDoubleClick:o,className:"absolute inset-y-0 -right-0.5 z-10 w-1 cursor-col-resize hover:bg-blue-300 active:bg-blue-400 transition-colors bg-transparent"})]})}const Oc="[Owner command] ";function xv(e,n){return`${Oc}${JSON.stringify(e)}
|
|
3
3
|
${n}`}function ix(e){if(!e.startsWith(Oc))return null;const n=e.indexOf(`
|
|
4
4
|
`);try{const s=JSON.parse(e.slice(Oc.length,n<0?void 0:n));return!s||s.v!==1||typeof s.id!="string"||typeof s.command!="string"||typeof s.lambda!="string"||typeof s.authorized!="boolean"||typeof s.duration_ms!="number"||!Number.isFinite(s.duration_ms)||s.duration_ms<0||!["ok","error","denied"].includes(s.status)?null:{header:s,body:n<0?"":e.slice(n+1)}}catch{return null}}function gv(e){return ix(e)!==null}const bv=["active","idle","hibernate","suspended","off"],vv=["proactive","respond_only","listen_only"],kv=["none","append_only","authorized"],wa={auto_retry:!0,max_attempts:5,base_delay_ms:15e3,max_delay_ms:3e5},yv=["off","directory","localhost","lan","public"],Dr={model_invoke:!0,sys_lambda:!0,task_resolve:!0,loop_inject:!0,identity_status:!0,get_identity:!0,set_identity:!0,emit_event:!0,attestation_list:!0,attestation_add:!0,attestation_issue:!0,network:!1,restricted_methods:["attestation_issue"]},yf=["debug","info","warn","error"],wv=["active","idle","hibernate"],jv=["loop_send","loop_list","sys_set_state"],wf=16;function lx(e){return!!e.goal?.trim()}const Nv=["sys_update_config","loop_manage","sys_create_adf"],Sv=["none","readonly","increment"],_v=["pending","pending_approval","running","completed","failed","denied","cancelled"];function Dc(e){const n=e.match(/^\[from loop:([a-z0-9][a-z0-9_-]{0,31})\] ([\s\S]*)$/);return n?{fromLoop:n[1],body:n[2]}:null}const Cv=["[System]","[System notice:","[Provider unavailable (","[Provider error (","[Turn error (","[Continue working autonomously","[You have responded ","Context is about to be compacted."];function Av(e){return Cv.some(n=>e.startsWith(n))}function cx(e){return e==="owner_command"||e==="runtime"||e==="status"}function Ev(e){const n=ix(e);if(n)return{content:n.body,metadata:{category:"owner_command",ownerCommand:n.header}};const s=e.match(/^\[Context: ([^\]]+)\] ?([\s\S]*)$/);if(s){const[r,...o]=s[1].split(" | "),i=c=>o.find(f=>f.startsWith(`${c}=`))?.slice(c.length+1),l=s[2];if(o.includes("loop_inject=v2"))return{content:l,metadata:{category:"injected",injectCategory:r,origin:i("origin")??"system:unknown"}};if(r==="System"||r==="status")return{content:l,metadata:{category:"status"}};if(r==="provider_context"){const c=i("from");return{content:l,metadata:{category:"provider_context",...c?{addedBy:c}:{}}}}return{content:l,metadata:{category:r}}}const a=Dc(e);return a?{content:a.body,metadata:{category:"loop",fromLoop:a.fromLoop}}:Av(e)?{content:e,metadata:{category:"runtime"}}:null}function Tv(e){return e.startsWith("The user has edited the document.")?"document_edit":e.startsWith("You received a message from agent")?"message_received":e.startsWith("A scheduled timer has fired")?"timer":e.startsWith("[Inbox notification]")?"inbox":e==="Go."?"autonomous_start":e==="The user has manually triggered you. Review the document and respond."?"manual_invoke":e.startsWith("Agent started. Review your mind")?"startup":e.startsWith("A batch of ")&&e.includes(" events fired: ")?"batch":e.startsWith("A file has been ")?"file_change":e.startsWith("An outbound message was sent")?"outbox":e.startsWith("A tool call has been intercepted")||e.startsWith("A tool call was intercepted")?"tool_call":e.startsWith("A task has been created.")?"task_create":e.startsWith("A task has completed")?"task_complete":e.startsWith("A log entry has been recorded.")?"log_entry":e.startsWith("An LLM call completed.")?"llm_call":e.startsWith("You have been triggered. Review the current state")?"unknown":null}function jf(e){let n=e.trim().replace(/\\/g,"/");for(;n.startsWith("./");)n=n.slice(2);return n.startsWith("/")&&(n=n.slice(1)),n.toLowerCase()}const Nf=new Set(["readme.md","document.md"]);function Rv(e,n){const s=jf(e),a=jf(n);return s===a?!0:Nf.has(s)&&Nf.has(a)}function Pv(e){const{name:n,targetPaths:s,documentPath:a}=e;return s?s.length===0?!1:a?s.some(r=>Rv(r,a)):!0:n==="fs_write"}function Mv(e,n,s){for(let a=e.length-1;a>=0;a--){const r=e[a];if(r.type==="tool_result")return null;if(r.type==="tool_call"&&r.metadata?.name===n&&!s(r.id))return r.id}return null}function Vd(e){return typeof e.metadata?.seq!="number"}function dx(e){const n=[];for(let s=e.length-1;s>=0;s--){const a=e[s];if(a.type!=="text"&&a.type!=="thinking"||!Vd(a))break;n.push(s)}return n.reverse()}function Iv(e){let n=e.length-1;for(;n>=0&&e[n].type==="context"&&cx(e[n].metadata?.category);)n--;return dx(e.slice(0,n+1))}function Lv(e,n){if(n.length===0)return[];const s=new Set(n),a=[];for(let r=e.length-1;r>=0&&s.size>0;r--){const o=e[r];if(o.type!=="tool_result")continue;const i=o.metadata?.tool_use_id;typeof i!="string"||!s.has(i)||(s.delete(i),Vd(o)&&a.push(r))}return a.reverse()}function $v(e){for(const n of e){const s=n.metadata?.seq;if(typeof s=="number")return s}}function ul(){const{filePath:e,runtimeId:n,viewGeneration:s}=de.getState();return{filePath:e,runtimeId:n,viewGeneration:s}}function zs(e){const n=de.getState();return!Ud()&&e.filePath===n.filePath&&e.runtimeId===n.runtimeId&&e.viewGeneration===n.viewGeneration}function Fo(e,n){const s=e.length>0?e[e.length-1]:void 0;return!s||s.type!==n||s.metadata?.quietTurn?-1:e.length-1}function Sf(e,n){for(let s=e.length-1;s>=0;s--)if(n(e[s]))return s;return-1}function Pa(e){switch(e){case"thinking":case"tool_use":return"active";case"idle":return"idle";case"awaiting_approval":case"awaiting_ask":case"suspended":return"suspended";case"error":return"error";case"stopped":return"off";case"active":case"hibernate":case"off":return e;default:return"off"}}function _f(e,n){const s=de.getState();s.documentContent!==e&&s.setDocumentContent(e,n!==void 0?{revision:n,writer:{kind:"agent"}}:void 0)}function Ov(e){const n=Z.getState();n.config!==e&&(n.config&&e&&JSON.stringify(n.config)===JSON.stringify(e)||n.setConfig(e))}function Dv(){const e=new Map,n=l=>`${de.getState().filePath??""}:${l}`,s=l=>Fo(l,"text")>=0||Fo(l,"thinking")>=0,a=(l,c,f,h)=>{if(f&&s(h)){const m=n(c),p=e.get(m)??[];p.push(l),e.set(m,p)}else Z.getState().addLogEntry(l,c)},r=l=>{const c=n(l),f=e.get(c);if(!f||f.length===0)return;e.delete(c);const h=Z.getState();for(const m of f)h.addLogEntry(m,l)},o=(l,c)=>{if(typeof l!="number")return;const f=Z.getState(),h=Pt(f,c).log;f.stampSeq(dx(h),l,c)},i=l=>typeof l.seq=="number"?{seq:l.seq}:void 0;return l=>{const c=ul(),f=Z.getState(),h=l.loop??Tt,m=Pt(f,h);switch(l.type){case"state_changed":{const p=l.payload,d=Pa(p.state);if(f.setState(d,h),p.state!=="awaiting_ask"&&f.clearPendingAsks(h),(d==="idle"||d==="error"||d==="off")&&r(h),d==="idle"){const b=va();b&&nv(b,h,{automatic:!0})}break}case"trigger_message":{const p=l.payload,d=Dc(p.content);if(d){a({id:St(),type:"context",content:d.body,timestamp:l.timestamp,metadata:{...i(p),category:"loop",fromLoop:d.fromLoop}},h,m.state==="active",m.log);break}if(p.triggerType==="chat"){const b=p.attachments??[];f.addLogEntry({id:St(),type:"user",content:p.content,timestamp:l.timestamp,metadata:{...i(p),...b.length>0?{attachments:b}:{}}},h)}else p.triggerType!=="manual_invoke"&&f.addLogEntry({id:St(),type:"trigger",content:p.content,timestamp:l.timestamp,metadata:{...i(p),triggerType:Tv(p.content)??p.triggerType}},h);break}case"thinking_delta":case"thinking_delta_batch":{const p=l.payload,d=p.deltas?p.deltas.join(""):p.delta,b=Fo(m.log,"thinking");b>=0?f.updateEntryAt(b,g=>{g.content+=d},h):f.addLogEntry({id:St(),type:"thinking",content:d,timestamp:l.timestamp},h);break}case"text_delta":case"text_delta_batch":{const p=l.payload,d=p.deltas?p.deltas.join(""):p.delta,b=Fo(m.log,"text");b>=0?f.updateEntryAt(b,g=>{g.content+=d},h):f.addLogEntry({id:St(),type:"text",content:d,timestamp:l.timestamp},h);break}case"tool_call_start":{const p=l.payload;o(p.seq,h),r(h),f.addLogEntry({id:St(),type:"tool_call",content:`Calling ${p.name}`,timestamp:l.timestamp,metadata:{...i(p),name:p.name,input:p.input,...p.id?{tool_id:p.id}:{}}},h);break}case"loop_seq":{const p=l.payload;if(typeof p?.seq!="number"||!Array.isArray(p.toolUseIds))break;const d=Pt(Z.getState(),h).log;f.stampSeq(Lv(d,p.toolUseIds),p.seq,h);break}case"tool_call_result":{const p=l.payload;f.addLogEntry({id:St(),type:"tool_result",content:p.result.content,timestamp:l.timestamp,metadata:{name:p.name,isError:p.result.isError,...p.id?{tool_use_id:p.id}:{},...p.imageUrl?{imageUrl:p.imageUrl}:{}}},h),Pv(p)&&V().getDocument().then(d=>{zs(c)&&_f(d.content,d.revision)}).catch(d=>console.warn("[Agent] Document refresh failed:",d)),p.name==="sys_update_config"&&V().getAgentConfig().then(d=>{zs(c)&&Z.getState().setConfig(d)}).catch(d=>console.warn("[Agent] Config refresh failed:",d)),(p.name==="sys_set_meta"||p.name==="sys_delete_meta")&&V().getHeader().then(d=>{zs(c)&&Z.getState().setStatusText(d.statusText??"")}).catch(d=>console.warn("[Agent] Status refresh failed:",d));break}case"response_metadata":{const p=l.payload;if(p.estimated){f.setTokenEstimate((p.usage.input??0)+(p.usage.output??0),h);break}f.setTokenUsage({...p.usage,input:p.usage.input??0,output:p.usage.output??0},h),f.setTokenEstimate(null,h);const d=m.log;let b=null;for(let g=d.length-1;g>=0;g--){const w=d[g];if(w.type==="user"||w.type==="system"||w.type==="tool_result")break;if(w.type!=="text"&&w.type!=="thinking"&&w.type!=="tool_call")continue;b===null&&(b=g);const j={...w.metadata,model:p.model};w.type==="thinking"&&typeof p.usage.reasoning=="number"&&(j.reasoningTokens=p.usage.reasoning),g===b&&(j.tokens=p.usage),d[g]={...w,metadata:j}}f.setLog([...d],void 0,h);break}case"turn_complete":{const p=l.payload;if(p.interrupted&&p.partial&&typeof p.seq=="number"){const j=p.seq;for(const y of Iv(Pt(Z.getState(),h).log))f.updateEntryAt(y,S=>{S.metadata={...S.metadata,seq:j,interrupted:!0}},h)}else o(p.seq,h);const d=Pt(Z.getState(),h).log;let b=d.length-1;for(;b>=0&&d[b].type==="thinking";)b--;const g=b>=0?d[b]:void 0;if(!g||p.interrupted===!0||g.type!=="user"&&g.type!=="trigger"&&g.type!=="context"||f.addLogEntry({id:St(),type:"text",content:"",timestamp:l.timestamp,metadata:{quietTurn:!0}},h),r(h),p.targetState){const j=p.targetState;[...bv,"error"].includes(j)&&f.setState(j,h)}h===Tt&&V()?.getHeader().then(j=>{zs(c)&&(_f(j.document),Ov(j.agentConfig),Z.getState().setStatusText(j.statusText??""))}).catch(j=>console.warn("[Agent] Header refresh failed:",j));break}case"error":{const p=l.payload;f.addLogEntry({id:St(),type:"error",content:p.error,timestamp:l.timestamp,metadata:p.details?{details:p.details}:void 0},h);break}case"autosaved":{de.getState().setDirty(!1);break}case"document_updated":{const p=l.payload;de.getState().setDocumentContent(p.content,p.revision!==void 0?{revision:p.revision,writer:p.writer}:void 0);break}case"chat_updated":{const p=l.payload;f.setLog(p.uiLog,typeof p.earlierCount=="number"?p.earlierCount:0,h),typeof p.contextBaseline=="number"&&(f.setTokenUsage({input:0,output:0},h),f.setTokenEstimate(p.contextBaseline,h));break}case"tool_approval_request":{const p=l.payload,d={reason:p.reason,protection:p.protection,canAlwaysApprove:p.canAlwaysApprove,alwaysApproveBlockedReason:p.alwaysApproveBlockedReason};let b=Mv(m.log,p.name,g=>m.pendingApprovals.has(g))??void 0;b||(b=St(),f.addLogEntry({id:b,type:"tool_call",content:`Calling ${p.name}`,timestamp:l.timestamp,metadata:{name:p.name,input:p.input,outOfBand:!0}},h)),f.addPendingApproval(b,p.requestId,d,h);break}case"tool_approval_resolved":{const p=l.payload;for(const[d,b]of m.pendingApprovals)if(b.requestId===p.requestId){p.endedBy?f.markApprovalEnded(d,p.endedBy,h):f.markApprovalOutcome(d,p.settled?"completed":p.approved,h),f.removePendingApproval(d,h);break}break}case"ask_request":{const{requestId:p,questions:d}=l.payload,b=Sf(m.log,g=>g.type==="tool_call"&&g.metadata?.name==="ask");if(b>=0)f.addPendingAsk(m.log[b].id,p,d,h);else{const g=St();f.addLogEntry({id:g,type:"system",content:"",timestamp:l.timestamp,metadata:{isAsk:!0,questions:d}},h),f.addPendingAsk(g,p,d,h)}break}case"ask_response":{const{requestId:p,result:d}=l.payload,b=Sf(m.log,g=>g.metadata?.askRequestId===p);b>=0&&f.updateEntryAt(b,g=>{g.metadata={...g.metadata,askAnswer:d}},h);for(const[g,w]of m.pendingAsks)w.requestId===p&&f.removePendingAsk(g,h);break}case"suspend_request":{const p=St();f.addLogEntry({id:p,type:"system",content:"Agent reached max active turns limit and has been suspended.",timestamp:l.timestamp,metadata:{isSuspend:!0}},h),f.setPendingSuspend(p,h);break}case"context_injected":{const p=l.payload,d=Dc(p.content),b=d||gv(p.content)||p.content.startsWith("[Context: ")?Ev(p.content):null,g={id:St(),type:"context",content:b?b.content:p.content,timestamp:l.timestamp,metadata:b?{...i(p),...b.metadata}:{...i(p),category:p.category,...p.addedBy?{addedBy:p.addedBy}:{}}};d?a(g,h,m.state==="active",m.log):g.metadata?.category==="owner_command"?f.settleOwnerCommand(g,h):f.addLogEntry(g,h);break}case"file_updated":{const p=l.payload;ft.getState().updateTabFromExternal(p.path,p.content,p.revision!==void 0?{revision:p.revision,writer:p.writer}:void 0);break}}}}function Fv(){const e=Ks();u.useEffect(()=>{if(!V())return;const n=V(),s=n.onAgentEvent(Dv()),a=n.onMcpServerStatusChanged?.(o=>{if(o.status==="connected"){const i=ul();n.getAgentConfig().then(l=>{zs(i)&&l&&Z.getState().setConfig(l)}).catch(l=>console.warn("[Agent] MCP config refresh failed:",l))}}),r=n.onAgentConfigChanged?.(o=>{const i=de.getState().filePath;if(i&&o.filePath&&i!==o.filePath||!o.config)return;const l=Z.getState(),c=new Set((o.config.loops??[]).map(f=>f.name));for(const f of Object.keys(l.sideLoops))c.has(f)||l.dropLoop(f);o.revision!==void 0&&l.setConfigRevision(o.revision),l.setConfig(o.config)});return()=>{s(),a?.(),r?.()}},[e])}async function fl(e={}){const{hasUserMessage:n,skipReviewGate:s,announce:a=!0}=e,r=e.filePath!==void 0?e.filePath:de.getState().filePath,o=F.getState(),i=Z.getState();if(!s)try{const h=await V()?.checkAgentReview();if(h?.needsReview)return o.setAgentReviewDialog(!0,h.configSummary),{success:!1,error:"Agent needs review",cancelled:!0}}catch{}const l=de.getState().runtimeId,c=r?Ra(l,r):null,f=()=>va()===c;c&&o.addStartingFilePath(c);try{let h=await V()?.startAgent(r??void 0,n);if(h&&!h.success&&(h.code==="provider_missing"||h.code==="provider_unconfigured")&&sx(l)){if(!await F.getState().requestProviderSetup(h.code,r))return{success:!1,error:h.error,cancelled:!0};if(!f()){const b="Agent file changed — start it again";return i.addLogEntry({id:`error-${Date.now()}`,type:"error",content:b,timestamp:Date.now()}),{success:!1,error:b}}h=await V()?.startAgent(r??void 0,n)}const m=f();if(h?.code==="credentials_locked"&&m&&r&&(F.getState().setPasswordDialogOpen(!0,r),!h?.success))return{success:!1,error:h?.error,cancelled:!0};if(h?.success)return m&&(i.setState(Pa(h.agentState??"idle")),i.setSessionId(h.sessionId??null),a&&i.addLogEntry({id:`system-${Date.now()}`,type:"system",content:"Agent started",timestamp:Date.now()})),{success:!0};const p=h?.error??"Unknown error";return m&&i.addLogEntry({id:`error-${Date.now()}`,type:"error",content:p,timestamp:Date.now()}),!h?.code&&(/API key/i.test(p)||/\b401\b/.test(p))&&F.getState().openSettingsAt("providers"),{success:!1,error:p}}catch(h){const m=h instanceof Error?h.message:String(h);return f()&&i.addLogEntry({id:`error-${Date.now()}`,type:"error",content:m,timestamp:Date.now()}),{success:!1,error:m}}finally{c&&F.getState().removeStartingFilePath(c)}}var Da=Lb();const YT=$b(Da);function go(e){const n=globalThis.adfApi,s=e||"local";return(typeof n?.runtimeId=="string"&&n.runtimeId?n.runtimeId:"local")===s||typeof n?.runtime!="function"?n:n.runtime(s)}const on=Pn(e=>({approvals:[],history:[],panelOpen:!1,toasts:[],setSnapshot:({pending:n,history:s})=>e(a=>({approvals:n,history:s,toasts:a.toasts.filter(r=>n.some(o=>Ws(o.runtimeId,o.id)===r.id))})),setPanelOpen:n=>e({panelOpen:n}),togglePanel:()=>e(n=>({panelOpen:!n.panelOpen})),pushToast:n=>e(s=>s.toasts.some(a=>a.id===n.id)?s:{toasts:[...s.toasts,n].slice(-3)}),dismissToast:n=>e(s=>({toasts:s.toasts.filter(a=>a.id!==n)})),reset:()=>e({approvals:[],history:[],panelOpen:!1,toasts:[]})})),ro="adf-open-tabs:",oo=new Map;let Gd=!1;function Bv(){Gd=!0}function Cf(){Gd=!1}function zv(e,n,s){if(Gd)return;const a=JSON.stringify({paths:n,active:s});if(oo.get(e)!==a){oo.set(e,a);try{localStorage.setItem(ro+e,a)}catch{}}}function Wv(e,n){if(e===n)return;try{const a=localStorage.getItem(ro+e);a!=null&&(localStorage.setItem(ro+n,a),localStorage.removeItem(ro+e))}catch{}const s=oo.get(e);s!==void 0&&oo.set(n,s),oo.delete(e)}function ux(e){try{const n=localStorage.getItem(ro+e);if(!n)return null;const s=JSON.parse(n);return Array.isArray(s.paths)?{paths:s.paths.filter(a=>typeof a=="string"),active:typeof s.active=="string"?s.active:null}:null}catch{return null}}function Hv(e,n){return n.success||!n.error||n.error==="Cancelled"?null:`Failed to ${e} file:
|
|
5
5
|
|
|
@@ -312,7 +312,7 @@ ${n}`:n}const T4=5e3,R4=300;function wc(e){e&&(e.scrollLeft=(e.scrollWidth-e.cli
|
|
|
312
312
|
This will permanently delete all stored keys and secrets. The file will open with an empty identity table.
|
|
313
313
|
|
|
314
314
|
This cannot be undone.`)&&(await V().wipeAllIdentity(),p.current=!0,a(""),o(""),f(!1),n(!1),await h({reattach:!1}))},[n,h]),g=u.useCallback(async()=>{a(""),o(""),f(!1),n(!1),await m()},[n,m]),w=u.useCallback(async()=>{if(p.current){p.current=!1;return}await g()},[g]),j=u.useCallback(y=>{y.key==="Enter"&&(y.preventDefault(),d())},[d]);return t.jsxs(_t,{lightDismiss:!1,open:e,onClose:w,title:"This agent is password-protected",children:[t.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 mb-4",children:"Enter the password from the sender."}),t.jsx(en,{id:"password-dialog-password",type:"password",autoComplete:"current-password",value:s,onChange:y=>a(y.target.value),onKeyDown:j,placeholder:"Enter password",autoFocus:!0,"aria-invalid":!!r,"aria-describedby":r?"password-dialog-error":void 0,className:"mb-2 text-sm"}),r&&t.jsx("p",{id:"password-dialog-error",className:"mb-3 text-xs text-[var(--adf-ui-danger)]",children:r}),t.jsxs("div",{className:"flex justify-between items-center mt-4",children:[c?t.jsx(ye,{onClick:b,variant:"danger",size:"compact",children:"Wipe All Keys"}):t.jsx("button",{type:"button",onClick:()=>f(!0),className:"text-xs text-[var(--adf-ui-text-muted)] underline hover:text-[var(--adf-ui-text)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]",children:"Forgot password?"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ye,{onClick:g,children:"Cancel"}),t.jsx(ye,{onClick:d,disabled:!s||i,loading:i,variant:"primary",children:i?"Unlocking...":"Unlock"})]})]})]})}function wA(){const e=F(p=>p.ownerMismatchDialogOpen),n=F(p=>p.ownerMismatchFileOwnerDid),s=F(p=>p.setOwnerMismatchDialogOpen),[a,r]=u.useState(!1),{completeFileOpen:o,closeFile:i}=ms(),l=u.useRef(!1),c=u.useCallback(async()=>{r(!0);try{(await V().claimAgent()).success&&(l.current=!0,s(!1),await o())}catch{await i()}finally{r(!1)}},[s,o,i]),f=u.useCallback(async()=>{l.current=!0,s(!1),await o()},[s,o]),h=u.useCallback(async()=>{s(!1),await i()},[s,i]),m=u.useCallback(async()=>{if(l.current){l.current=!1;return}await h()},[h]);return t.jsxs(_t,{open:e,onClose:m,title:"Different Owner",children:[t.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 mb-3",children:"This ADF was created by a different owner. You can claim it as your own (regenerates identity keys) or open it without changing ownership."}),n&&t.jsxs("div",{className:"mb-4 rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-canvas)] p-2 ring-1 ring-inset ring-[var(--adf-ui-separator)]",children:[t.jsx("p",{className:"mb-1 text-[11px] text-[var(--adf-ui-text-subtle)]",children:"File owner DID"}),t.jsx("code",{className:"select-all break-all text-[11px] text-[var(--adf-ui-text)]",children:n})]}),t.jsxs("div",{className:"flex justify-between items-center mt-4",children:[t.jsx(ye,{onClick:h,children:"Cancel"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ye,{onClick:f,children:"Open Anyway"}),t.jsx(ye,{onClick:c,disabled:a,loading:a,variant:"primary",children:a?"Claiming...":"Claim as Mine"})]})]})]})}const jA={shared:{badge:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",label:"Shared",description:"Runs in shared container with other agents"},isolated:{badge:"bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",label:"Isolated",description:"Runs in its own isolated container"},host:{badge:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",label:"Host Access",description:"Can run processes on your host machine"}},ub={mine:{badge:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",label:"Yours",monogram:"from-green-400 to-emerald-600"},recognized:{badge:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",label:"Yours · another install",monogram:"from-blue-400 to-indigo-600"},foreign:{badge:"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400",label:"From another owner",monogram:"from-violet-400 to-blue-600"},unclaimed:{badge:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",label:"No identity",monogram:"from-amber-400 to-orange-500"}};function fb({name:e,icon:n,seed:s,scenario:a,size:r}){const o=Nr()==="emoji";if(s&&!o)return t.jsx(Ba,{seed:s,size:r==="lg"?56:32});const i=(o?tx(n,s):null)||(e||"?").charAt(0).toUpperCase(),l=r==="lg"?"w-14 h-14 text-2xl":"w-8 h-8 text-sm";return t.jsx("div",{className:`${l} shrink-0 rounded-full bg-gradient-to-br ${ub[a].monogram} flex items-center justify-center text-white font-semibold select-none`,children:i})}function ss({label:e,value:n,amber:s}){return n?t.jsxs("div",{className:"flex items-start gap-3 py-1.5",children:[t.jsxs("span",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 w-20 shrink-0 text-right",children:[s&&t.jsx("span",{className:"text-amber-500 mr-1",children:"!"}),e]}),t.jsx("span",{className:`text-[11px] flex-1 ${s?"text-amber-700 dark:text-amber-400":"text-neutral-700 dark:text-neutral-300"}`,children:n})]}):null}function hb(){const[e,n]=u.useState(null);return u.useEffect(()=>{let s=!1;return V().getSettings().then(a=>{s||n((a?.providers??[]).map(r=>({id:r.id,name:r.name||r.id,defaultModel:r.defaultModel})))}).catch(()=>{s||n([])}),()=>{s=!0}},[]),e}function NA({summary:e}){const n=hb(),s=jA[e.computeTier],a=e.identity,r=ub[a.scenario],o=e.tools.filter(N=>N.enabled),i=o.filter(N=>N.notable),l=i.length>0?`${o.length} enabled — ${i.map(N=>N.name).join(", ")}`:`${o.length} enabled`,c=e.mcpServers.length>0?e.mcpServers.map(N=>`${N.name} (${N.transport==="http"?"remote":N.runLocation==="host"?"host":"container"})`).join(", "):"",f=e.triggers.filter(N=>N.enabled),h=f.length>0?f.map(N=>N.type).join(", "):"",m=e.messaging.mode,p=e.provider,d=p?.status==="unchecked"?" — not checked (provider checks are off in Settings)":n&&n.length===0?" — connect a provider when you run it":" — no API key on this computer",b=p?[p.configuredId||"no provider set",p.modelId].filter(Boolean).join(" · "):"",g=p?`${b}${p.status!=="ok"?d:""}`:"",w=e.network.wsConnections.length,j=w>0?`${w} outbound: ${e.network.wsConnections.map(N=>N.did??N.url).join(", ")}`:"",y=e.network.adapters.length>0?e.network.adapters.join(", "):"",S=e.network.serving?`${e.network.serving.routeCount} API route${e.network.serving.routeCount>1?"s":""}`:"",k=e.autostart?w>0||e.network.adapters.length>0?"Yes — connects on boot":"Yes":"",v=j||y||S||k,C=e.security.tableProtections.length>0?e.security.tableProtections.map(N=>`${N.table}: ${N.protection==="append_only"?"append-only":"authorized only"}`).join(", "):"";return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[t.jsx(fb,{name:e.name,icon:e.icon,seed:a.agentDid,scenario:a.scenario,size:"sm"}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[t.jsx("h3",{className:"text-sm font-medium text-neutral-800 dark:text-neutral-200",children:e.name}),t.jsx("span",{className:`inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full ${r.badge}`,children:r.label})]}),e.description&&t.jsx("p",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 mb-1",children:e.description}),a.fileOwnerDid&&!a.ownerIsYou&&t.jsxs("div",{className:"mb-0.5",children:[t.jsx("p",{className:"text-[10px] text-neutral-500 dark:text-neutral-400",children:"From: another owner"}),t.jsx("p",{className:"text-[9px] text-[var(--adf-ui-text-subtle)] font-mono truncate",children:a.fileOwnerDid})]}),a.agentDid&&t.jsxs("p",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] font-mono truncate",children:["Agent: ",a.agentDid]})]})]}),a.scenario==="unclaimed"&&t.jsx("p",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] px-3 py-2 text-[11px] text-[var(--adf-ui-warning)]",children:"This agent has no identity, so its origin can't be verified — anyone could have made it. Give its capabilities a careful look before accepting."}),a.seedUnavailable&&t.jsx("p",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] px-3 py-2 text-[11px] text-[var(--adf-ui-warning)]",children:"This file is yours, but its keys can't be unlocked here — import your seed phrase in Settings → Identity to use it on this machine."}),t.jsxs("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:`inline-flex items-center px-2 py-0.5 text-[10px] font-medium rounded-full ${s.badge}`,children:s.label}),t.jsx("span",{className:"text-[11px] text-neutral-500 dark:text-neutral-400",children:"Compute Environment"})]}),t.jsx("p",{className:"text-[11px] text-neutral-600 dark:text-neutral-400",children:s.description})]}),t.jsxs("div",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-neutral-500 dark:text-neutral-400 uppercase tracking-wide mb-1",children:"Capabilities"}),t.jsxs("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] px-3 py-1",children:[t.jsx(ss,{label:"Tools",value:l,amber:i.length>0}),t.jsx(ss,{label:"MCP",value:c}),t.jsx(ss,{label:"Triggers",value:h}),e.codeExecution&&t.jsx(ss,{label:"Code",value:"Code execution enabled",amber:!0}),t.jsx(ss,{label:"Messaging",value:m}),t.jsx(ss,{label:"Provider",value:g,amber:!!p&&p.status!=="ok"&&p.status!=="unchecked"})]})]}),v&&t.jsxs("div",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-neutral-500 dark:text-neutral-400 uppercase tracking-wide mb-1",children:"Network"}),t.jsxs("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] px-3 py-1",children:[t.jsx(ss,{label:"WebSocket",value:j,amber:w>0}),t.jsx(ss,{label:"Channels",value:y,amber:e.network.adapters.length>0}),t.jsx(ss,{label:"Serving",value:S}),t.jsx(ss,{label:"Autostart",value:k,amber:e.autostart&&(w>0||e.network.adapters.length>0)})]})]}),C&&t.jsxs("div",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-neutral-500 dark:text-neutral-400 uppercase tracking-wide mb-1",children:"Security"}),t.jsx("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] px-3 py-1",children:t.jsx(ss,{label:"Tables",value:C,amber:!0})})]})]})}function SA({configuredLabel:e,providers:n,selected:s,onSelect:a}){const[r,o]=u.useState([]),[i,l]=u.useState(null),[c,f]=u.useState(!1),[h,m]=u.useState(!1),p=u.useCallback(async d=>{if(!d){a(null),o([]),l(null),m(!1);return}const b=n.find(g=>g.id===d);a({provider:d,model_id:b?.defaultModel??""}),f(!0),l(null),m(!1);try{const{models:g,error:w}=await V().listModels(d);o(g??[]),w&&l(w),g?.length||m(!0)}catch{o([]),m(!0)}finally{f(!1)}},[n,a]);return t.jsxs("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] p-3 space-y-2",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-[11px] text-neutral-500 dark:text-neutral-400 mb-0.5",children:"Provider"}),t.jsxs(Fi,{"aria-label":"Provider for this computer",value:s?.provider??"",onChange:d=>p(d.target.value),className:"text-xs",children:[t.jsxs("option",{value:"",children:["Keep configured — ",e]}),n.map(d=>t.jsx("option",{value:d.id,children:d.name},d.id))]})]}),s&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-[11px] text-neutral-500 dark:text-neutral-400 mb-0.5",children:"Model"}),c?t.jsx("div",{className:"px-2 py-1.5 text-xs text-[var(--adf-ui-text-subtle)]",children:"Loading models..."}):h?t.jsxs("div",{className:"flex gap-1",children:[t.jsx(en,{"aria-label":"Model id",type:"text",value:s.model_id,onChange:d=>a({provider:s.provider,model_id:d.target.value}),placeholder:"Model id",className:"flex-1 text-xs"}),r.length>0&&t.jsx(ye,{variant:"ghost",size:"compact",className:"text-[10px] whitespace-nowrap",onClick:()=>m(!1),children:"Pick from list"})]}):t.jsxs(Fi,{"aria-label":"Model",value:r.includes(s.model_id)?s.model_id:"__custom__",onChange:d=>{d.target.value==="__custom__"?m(!0):a({provider:s.provider,model_id:d.target.value})},className:"text-xs",children:[r.map(d=>t.jsx("option",{value:d,children:d},d)),t.jsx("option",{value:"__custom__",children:"Custom..."})]}),i&&t.jsx("p",{className:"text-[10px] text-[var(--adf-ui-danger)] mt-0.5",children:i})]})]})}function _A({summary:e,password:n,setPassword:s,passwordError:a,setPasswordError:r,skipPassword:o,onToggleSkipPassword:i,onSubmit:l,model:c,setModel:f,templateMode:h=!1}){const m=e.identity,p=m.sharePasswordSet&&m.credentialsLocked,d=e.provider,b=hb(),g=d?.configuredId?b?.find(j=>j.id===d.configuredId)?.name??d.configuredId:"no provider set",w=d?[g,d.modelId].filter(Boolean).join(" · "):"nothing set";return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex flex-col items-center text-center pt-2 pb-1",children:[t.jsx(fb,{name:e.name,icon:e.icon,seed:m.agentDid,scenario:m.scenario,size:"lg"}),t.jsxs("h3",{className:"text-sm font-medium text-neutral-800 dark:text-neutral-200 mt-3",children:["Make ",e.name," yours"]}),t.jsx("p",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 mt-1 max-w-sm",children:h?"Claiming gives this template a fresh identity under your ownership. Agents you create from it never carry its identity or history.":m.scenario==="unclaimed"?"Claiming mints a brand-new identity for this agent under your ownership. Its files and memory come along as they are.":"Claiming gives this agent a fresh identity under your ownership. Its files, memory, and history are kept, and its previous identity is recorded as provenance."}),!h&&e.willRelocate&&t.jsxs("p",{className:"text-[11px] text-[var(--adf-ui-text-subtle)] mt-1",children:["It will be saved to ",e.relocateTo??"Documents/adf-agents","."]})]}),p&&t.jsx("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] p-3",children:o?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-[11px] font-medium text-neutral-700 dark:text-neutral-300 mb-1",children:"Claim without the password"}),t.jsx("p",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 mb-2",children:"Its stored credentials stay locked until you enter the sender's password in the Identity panel. Everything else becomes yours now."}),t.jsx("button",{type:"button",onClick:()=>i(!1),className:"text-[11px] text-[var(--adf-ui-text-muted)] underline hover:text-[var(--adf-ui-text)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]",children:"I have the password"})]}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-[11px] font-medium text-neutral-700 dark:text-neutral-300 mb-1",children:"Enter the password to claim this agent"}),t.jsx("p",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 mb-2",children:"The password stays with the agent — change or remove it in the Identity panel."}),t.jsx(en,{type:"password",value:n,onChange:j=>{s(j.target.value),r(null)},onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),l())},placeholder:"Password",autoFocus:!0,"aria-invalid":!!a,"aria-describedby":a?"agent-review-password-error":void 0,className:"text-xs"}),a&&t.jsx("p",{id:"agent-review-password-error",className:"mt-1.5 text-[11px] text-[var(--adf-ui-danger)]",children:a}),t.jsx("button",{type:"button",onClick:()=>i(!0),className:"mt-1.5 text-[11px] text-[var(--adf-ui-text-muted)] underline hover:text-[var(--adf-ui-text)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]",children:"Lost the password?"})]})}),!p&&m.filePasswordProtected&&t.jsx("p",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] px-3 py-2 text-[11px] text-[var(--adf-ui-text-muted)]",children:"The password becomes a share password when you claim."}),!m.sharePasswordSet&&m.credentialsLocked&&t.jsx("p",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] px-3 py-2 text-[11px] text-[var(--adf-ui-text-muted)]",children:"Any stored credentials are sealed to the previous owner without a share password, so they can't be recovered — claiming clears them. Re-enter API keys afterward if the agent needs them."}),!h&&b&&b.length>0&&t.jsx(SA,{configuredLabel:w,providers:b,selected:c,onSelect:f})]})}function CA(){const e=F(G=>G.agentReviewDialogOpen),n=F(G=>G.agentReviewSummary),s=F(G=>G.templateReview),a=s!==null,r=a||e,o=a?s.summary:n,i=F(G=>G.setAgentReviewDialog),l=F(G=>G.expandRightPanelToTab),{closeFile:c,loadFileContents:f}=ms(),[h,m]=u.useState(!1),[p,d]=u.useState("review"),[b,g]=u.useState(""),[w,j]=u.useState(null),[y,S]=u.useState(!1),[k,v]=u.useState(null),[C,N]=u.useState(null),E=u.useRef(!1),M=u.useRef(null);u.useEffect(()=>{e&&(M.current=de.getState().filePath)},[e]);const L=a||(o?.identity.needsClaim??!1),q=(o?.identity.sharePasswordSet??!1)&&(o?.identity.credentialsLocked??!1),A=u.useCallback(()=>{d("review"),g(""),j(null),S(!1),v(null),N(null)},[]),D=s?.id??null;u.useEffect(()=>{D&&A()},[D,A]);const U=u.useCallback(async()=>{try{const G=await V().checkAgentReview();G.needsReview&&G.configSummary&&F.getState().setAgentReviewDialog(!0,G.configSummary)}catch{}},[]),W=u.useCallback(async()=>{await fl({skipReviewGate:!0})},[]),K=u.useCallback(async(G,ke=!1)=>{m(!0),N(null);const le=M.current;try{const ge=await V().acceptAgentReview({claim:G||void 0,expectedPath:le??"",model:k??void 0});if(!ge.success){if(!F.getState().agentReviewDialogOpen)return;N(ge.error||(G?"Claim failed.":"Accept failed.")),await U();return}if(ge.movedTo){const je=de.getState(),ce=je.filePath;if(ce===le||ce===ge.movedTo){if(le&&le!==ge.movedTo){Wv(le,ge.movedTo);const Fe=Ra(je.runtimeId,le),Pe=je.draftInputs[Fe];Pe&&je.setDraftInput(Ra(je.runtimeId,ge.movedTo),Pe),je.removeDraftInput(Fe)}je.filePath!==ge.movedTo&&je.setFilePath(ge.movedTo)}}ge.moveError&&(console.warn("[AgentReviewDialog] File move after accept failed:",ge.moveError),F.getState().setFileMoveWarning("Couldn't move the file out of the temp folder — it may be deleted by the OS. Save it somewhere safe.")),await f(),E.current=!0,F.getState().setAgentNeedsReview(!1);const re=de.getState().filePath;re&&tn.getState().updateFileEntry(re,{reviewed:!0},Lc()),i(!1),A(),ke&&await W()}catch(ge){console.error("[AgentReviewDialog] Accept error:",ge),F.getState().agentReviewDialogOpen&&(N(ge instanceof Error?ge.message:G?"Claim failed.":"Accept failed."),await U())}finally{m(!1)}},[i,f,A,k,U,W]),ue=u.useCallback(()=>K(!1),[K]),ae=u.useCallback(async()=>{const G=F.getState().templateReview;if(!G)return;const ke=b.trim();if(q&&!y&&!ke){j("Enter the password to claim.");return}m(!0),N(null);try{const le=await(G.runtimeId?st(G.runtimeId):V()).acceptTemplateReview({id:G.id,password:ke||void 0});if(!le.success){N(le.error||"Claim failed.");return}E.current=!0,A(),F.getState().closeTemplateReview(!0)}catch(le){console.error("[AgentReviewDialog] Template claim error:",le),N(le instanceof Error?le.message:"Claim failed.")}finally{m(!1)}},[b,q,y,A]),I=u.useCallback(async G=>{const ke=b.trim();if(q&&!y&&!ke){j("Enter the password to claim.");return}if(ke){m(!0);try{if(!(await V().unlockEnvelopeWithPassword(ke,!1)).success){j("That password didn't unlock it — check with the sender."),m(!1);return}}catch(le){console.error("[AgentReviewDialog] Unlock error:",le),j(le instanceof Error?le.message:"Unlock failed."),m(!1);return}}await K(!0,G)},[b,q,y,K]),B=u.useCallback(async()=>{E.current=!0,i(!1),A(),l("agent","config")},[i,l,A]);u.useCallback(()=>{E.current=!0,i(!1),A()},[i,A]);const X=u.useCallback(async()=>{E.current=!0,i(!1),A(),await c()},[i,c,A]),oe=u.useCallback(()=>{E.current=!0,A(),F.getState().closeTemplateReview(!1)},[A]),z=u.useCallback(()=>{if(E.current){E.current=!1;return}if(F.getState().templateReview){A(),F.getState().closeTemplateReview(!1);return}i(!1),A()},[i,A]),H=a?`${o?.name??"This"} template`:L?`${o?.name??"An agent"} has arrived`:"Review Agent";return t.jsxs(_t,{lightDismiss:!1,open:r,onClose:z,title:H,preventClose:h,wide:!0,children:[o&&(p==="review"?t.jsx(NA,{summary:o}):t.jsx(_A,{summary:o,password:b,setPassword:g,passwordError:w,setPasswordError:j,skipPassword:y,onToggleSkipPassword:G=>{S(G),G&&g(""),j(null)},onSubmit:()=>{h||(a?ae():I(!0))},model:k,setModel:v,templateMode:a})),C&&t.jsx("p",{className:"mt-4 text-[11px] text-[var(--adf-ui-danger)]",role:"alert",children:C}),t.jsxs("div",{className:`flex justify-between items-center ${C?"mt-2":"mt-5"}`,children:[p==="review"?t.jsx(ye,{onClick:a?oe:X,variant:a?"ghost":"danger",disabled:h,children:a?"Cancel":"Reject & Close"}):t.jsx(ye,{onClick:()=>{N(null),d("review")},disabled:h,variant:"ghost",children:"← Back"}),t.jsxs("div",{className:"flex gap-2",children:[p==="review"&&!a&&t.jsx(ye,{onClick:B,disabled:h,children:"Review Config"}),p==="claim"&&a?t.jsx(ye,{onClick:()=>{ae()},disabled:h,loading:h,variant:"primary",children:h?"Claiming...":"Claim"}):p==="review"&&L?t.jsx(ye,{onClick:()=>{N(null),d("claim")},variant:"primary",children:"Continue"}):p==="review"?t.jsx(ye,{onClick:ue,disabled:h,loading:h,variant:"primary",children:h?"Accepting...":"Accept & Open"}):t.jsxs(t.Fragment,{children:[t.jsx(ye,{onClick:()=>I(!1),disabled:h,variant:"ghost",children:"Claim only"}),t.jsx(ye,{onClick:()=>I(!0),disabled:h,loading:h,variant:"primary",children:h?"Claiming...":"Claim & Run"})]})]})]})]})}function pb(e){const n=[];for(const s of e)s.isDirectory&&s.children?n.push(...pb(s.children)):!s.isDirectory&&s.fileName.endsWith(".adf")&&n.push({filePath:s.filePath,fileName:s.fileName,agentName:s.agentName});return n}async function AA(e=window.adfApi){const s=(await e?.getTrackedDirectories())?.directories??[],r=(await Promise.all(s.map(async i=>{try{const l=await e?.scanTrackedDirectory(i);return l?.files?pb(l.files):[]}catch{return[]}}))).flat(),o=new Set;return r.filter(i=>o.has(i.filePath)?!1:(o.add(i.filePath),!0))}function Fd(e){return e.agentName?.trim()||e.fileName.replace(/\.adf$/,"")}function L6(e,n){const s=n.find(r=>r.filePath===e);return s?Fd(s):(e.split(/[\\/]/).pop()??e).replace(/\.adf$/,"")}function EA({provider:e,apiKeyPlaceholder:n,onCountChange:s}){const a=nf(),[r,o]=u.useState([]),[i,l]=u.useState(!1),[c,f]=u.useState([]),[h,m]=u.useState(!1),[p,d]=u.useState(null),[b,g]=u.useState({}),[w,j]=u.useState({}),[y,S]=u.useState(null),[k,v]=u.useState({}),[C,N]=u.useState({}),[E,M]=u.useState(!1),L=u.useRef(new Set),q=u.useRef(s);q.current=s;const A=z=>Od(z,e).isOverride||L.current.has(z.filePath)||p===z.filePath,D=E?r:r.filter(A),U=r.length-r.filter(A).length,W=u.useCallback(async()=>{l(!0);try{const H=(await a?.listProviderCredentialFiles({providerId:e.id}))?.files??[];o(G=>{const ke=G.filter(le=>L.current.has(le.filePath)&&!H.some(ge=>ge.filePath===le.filePath));return[...H,...ke]}),q.current?.(Ti(H,e))}finally{l(!1)}},[e.id]);u.useEffect(()=>{W()},[W]),u.useEffect(()=>{AA(a).then(f).catch(()=>f([]))},[a]);const K=(z,H)=>{const G=c.find(ke=>ke.filePath===z);return G?Fd(G):H.replace(/\.adf$/,"")},ue=async z=>{if(p===z){d(null);return}d(z),N(H=>{const G={...H};return delete G[z],G});try{const H=L3(await a?.getProviderCredentials({filePath:z,providerId:e.id}));H.apiKey!==null&&g(G=>({...G,[z]:H.apiKey})),H.providerConfig&&j(G=>({...G,[z]:H.providerConfig})),H.error&&N(G=>({...G,[z]:H.error}))}catch(H){N(G=>({...G,[z]:H instanceof Error?H.message:String(H)}))}},ae=z=>{if(m(!1),!z||r.some(G=>G.filePath===z))return;const H=c.find(G=>G.filePath===z);L.current.add(z),o(G=>[...G,{filePath:z,fileName:H?.fileName??z.split("/").pop()??"agent.adf",hasCredentials:!1,populatedKeys:[]}]),d(z)},I=async z=>{S(z),v(H=>{const G={...H};return delete G[z],G});try{const H=b[z]??"",G=w[z]??{},{apiKey:ke,credentialStorage:le,...ge}=e,re=await a?.attachProvider({filePath:z,provider:{...ge,...G.defaultModel!==void 0?{defaultModel:G.defaultModel}:{},...G.params!==void 0?{params:G.params}:{},...G.requestDelayMs!==void 0?{requestDelayMs:G.requestDelayMs}:{}}});if(re&&!re.success)throw new Error(re.error??"Failed to attach provider");if(H){const je=await a?.setProviderCredential({filePath:z,providerId:e.id,value:H});if(je&&!je.success)throw new Error(je.error??"Failed to save key")}o(je=>je.map(ce=>ce.filePath===z?{...ce,hasCredentials:!!H||ce.hasCredentials,populatedKeys:H?["apiKey"]:ce.populatedKeys,providerConfig:{...ce.providerConfig,...G}}:ce)),v(je=>({...je,[z]:"ok"})),L.current.delete(z),q.current?.(Ti(r.map(je=>je.filePath===z?{...je,hasCredentials:!!H||je.hasCredentials,providerConfig:{...je.providerConfig,...G}}:je),e))}catch(H){v(G=>({...G,[z]:H instanceof Error?H.message:String(H)}))}finally{S(null)}},B=async z=>{if(!window.confirm(`Remove this agent's copy of ${e.name||"this provider"}? It goes back to the app values, and its own key for this provider is deleted.`))return;await a?.detachProvider({filePath:z,providerId:e.id}),L.current.delete(z);const H=r.filter(ke=>ke.filePath!==z);o(H),q.current?.(Ti(H,e)),p===z&&d(null);const G=ke=>{if(!(z in ke))return ke;const le={...ke};return delete le[z],le};g(G),j(G),v(G),N(G)},X=(z,H)=>j(G=>({...G,[z]:{...G[z],...H}})),oe=c.filter(z=>!r.some(H=>H.filePath===z.filePath));return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 text-[13px] font-medium text-[var(--adf-ui-text)]",children:["Agent overrides",t.jsx(ls,{href:ut.settingsProviderCopies})]}),t.jsx("p",{className:"mt-0.5 text-[12px] leading-5 text-[var(--adf-ui-text-muted)]",children:"Agents with their own key, model, params, or delay for this provider."})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[t.jsx(ye,{variant:"ghost",size:"compact",onClick:()=>{W()},disabled:i,children:i?"Scanning…":"Refresh"}),t.jsx(ye,{variant:"secondary",size:"compact",onClick:()=>m(!0),disabled:h,children:"+ Add agent override"})]})]}),h&&t.jsxs("div",{className:"flex items-center gap-1.5 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] p-1.5",children:[t.jsxs(Fi,{defaultValue:"",onChange:z=>ae(z.target.value),className:"text-[12px]","aria-label":"Agent to give a copy of this provider",children:[t.jsx("option",{value:"",disabled:!0,children:c.length===0?"No agents in tracked folders":"Pick an agent…"}),oe.map(z=>t.jsx("option",{value:z.filePath,children:Fd(z)},z.filePath))]}),t.jsx(fu,{"aria-label":"Cancel",onClick:()=>m(!1),children:"×"})]}),D.length===0&&!h?t.jsx("p",{className:"rounded-[var(--adf-ui-control-radius)] border border-dashed border-[var(--adf-ui-border)] px-3 py-2.5 text-[12px] text-[var(--adf-ui-text-subtle)]",children:"No overrides. Every agent uses the app values above."}):t.jsx("div",{className:"max-h-64 space-y-1.5 overflow-y-auto pr-1",children:D.map(z=>{const H=p===z.filePath,G=w[z.filePath]??{},ke=k[z.filePath],le=Od(z,e);return t.jsxs("div",{className:"overflow-hidden rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)]",children:[t.jsxs("div",{className:"flex items-center hover:bg-[var(--adf-ui-surface-hover)]",children:[t.jsxs("button",{type:"button",onClick:()=>{ue(z.filePath)},className:"flex min-w-0 flex-1 items-center gap-2 px-2.5 py-1.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--adf-ui-focus)]",children:[t.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)]",children:H?"▼":"▶"}),t.jsx("span",{className:"truncate text-[12px] font-medium text-[var(--adf-ui-text)]",children:K(z.filePath,z.fileName)}),le.isOverride?le.badges.map(ge=>t.jsx("span",{className:"truncate rounded bg-[var(--adf-ui-accent-subtle)] px-1 py-0.5 text-[9px] font-medium text-[var(--adf-ui-accent)]",children:ge},ge)):t.jsx(we,{tip:"Unchanged copy: same values as the app, runs on the app key. Studio adds one to every new agent.",children:t.jsx("span",{className:"rounded border border-[var(--adf-ui-border)] px-1 py-0.5 text-[9px] font-medium text-[var(--adf-ui-text-muted)]",children:"Same as app"})})]}),t.jsx(ye,{variant:"ghost",size:"compact",className:"mr-1 text-[var(--adf-ui-danger)]",onClick:()=>{B(z.filePath)},children:"Remove"})]}),H&&t.jsxs("div",{className:"space-y-2 border-t border-[var(--adf-ui-separator)] px-2.5 pb-2.5 pt-2",children:[t.jsx("p",{className:"truncate font-mono text-[10px] text-[var(--adf-ui-text-subtle)]",title:z.filePath,children:z.filePath}),t.jsxs("div",{children:[t.jsx("label",{className:"mb-0.5 block text-[11px] text-[var(--adf-ui-text-muted)]",children:"API key"}),t.jsx(en,{type:"password",value:b[z.filePath]??"",onChange:ge=>g(re=>({...re,[z.filePath]:ge.target.value})),placeholder:n??"API key",className:"font-mono text-[12px]"}),C[z.filePath]&&t.jsx("p",{className:"mt-0.5 text-[11px] text-[var(--adf-ui-danger)]",children:C[z.filePath]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"mb-0.5 block text-[11px] text-[var(--adf-ui-text-muted)]",children:"Default model"}),t.jsx(en,{type:"text",value:G.defaultModel??"",onChange:ge=>X(z.filePath,{defaultModel:ge.target.value}),placeholder:e.defaultModel?`Copied from the app value (${e.defaultModel})`:"Copied from the app value",className:"text-[12px]"})]}),t.jsxs("details",{className:"group",children:[t.jsx("summary",{className:"cursor-pointer select-none text-[11px] text-[var(--adf-ui-text-muted)] hover:text-[var(--adf-ui-text)]",children:"Advanced"}),t.jsxs("div",{className:"mt-1.5 space-y-2",children:[t.jsxs("div",{children:[t.jsx("label",{className:"mb-0.5 block text-[11px] text-[var(--adf-ui-text-muted)]",children:"Request delay (ms)"}),t.jsx(en,{type:"number",min:0,step:100,value:G.requestDelayMs??0,onChange:ge=>X(z.filePath,{requestDelayMs:Math.max(0,parseInt(ge.target.value)||0)}),className:"text-[12px]"})]}),t.jsx(mb,{params:G.params??[],onChange:ge=>X(z.filePath,{params:ge})})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ye,{variant:"secondary",size:"compact",loading:y===z.filePath,disabled:y===z.filePath,onClick:()=>{I(z.filePath)},children:y===z.filePath?"Saving…":"Save to agent"}),ke==="ok"&&t.jsx("span",{className:"text-[11px] text-[var(--adf-ui-success)]",children:"Saved"}),ke&&ke!=="ok"&&t.jsx("span",{className:"text-[11px] text-[var(--adf-ui-danger)]",children:ke})]})]})]},z.filePath)})}),U>0&&t.jsxs("button",{type:"button",onClick:()=>M(z=>!z),className:"text-[11px] text-[var(--adf-ui-text-subtle)] underline-offset-2 hover:text-[var(--adf-ui-text)] hover:underline",children:[E?"Hide":"Show"," ",U," agent",U===1?"":"s"," with an unchanged copy"]})]})}function mb({params:e,onChange:n,compact:s}){const a=(r,o)=>{const i=[...e];i[r]={...i[r],...o},n(i)};return t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[t.jsx("label",{className:"block text-[11px] text-[var(--adf-ui-text-muted)]",children:"Request parameters"}),t.jsx(ye,{variant:"ghost",size:"compact",className:"text-[11px]",onClick:()=>n([...e,{key:"",value:""}]),children:"+ Add"})]}),e.length===0?t.jsx("p",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:s?"None.":"None. Values are parsed as JSON and merged into every request body; a blank value sends null, which deletes that key."}):t.jsx("div",{className:"space-y-1.5",children:e.map((r,o)=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx(en,{"aria-label":`Parameter ${o+1} key`,type:"text",value:r.key,onChange:i=>a(o,{key:i.target.value}),placeholder:"key",className:"flex-1 font-mono text-[12px]"}),t.jsx(en,{"aria-label":`Parameter ${o+1} value`,type:"text",value:r.value,onChange:i=>a(o,{value:i.target.value}),placeholder:"blank = null",className:"flex-1 font-mono text-[12px]"}),t.jsx(fu,{onClick:()=>n(e.filter((i,l)=>l!==o)),"aria-label":`Remove parameter ${o+1}`,variant:"danger",children:"×"})]},o))})]})}const TA="__redacted__";function RA(e,n){if(e!==TA||n===e)return n;let s=0;for(;s<e.length&&s<n.length&&e[s]===n[s];)s++;let a=0;for(;a<e.length-s&&a<n.length-s&&e[e.length-1-a]===n[n.length-1-a];)a++;return n.slice(s,n.length-a)}function PA(e){const{open:n,onClose:s,provider:a}=e,r=a?To(a):void 0,o=a?a.name||r?.label||"Provider":"Add a provider";return t.jsxs(_t,{open:n,onClose:s,title:o,wide:!0,lightDismiss:!a,children:[e.intro&&t.jsx("p",{className:"mb-3 text-[12px] text-[var(--adf-ui-text-muted)]",children:e.intro}),a?t.jsx(LA,{...e,provider:a,entry:r},a.id):t.jsx(MA,{onPick:e.onPick})]})}function MA({onPick:e}){const[n,s]=u.useState(""),a=n.trim().toLowerCase(),r=u.useMemo(()=>a?Ld.filter(o=>`${o.label} ${o.description} ${o.type}`.toLowerCase().includes(a)):Ld,[a]);return t.jsxs("div",{className:"space-y-3",children:[t.jsx(en,{autoFocus:!0,type:"search",value:n,onChange:o=>s(o.target.value),placeholder:"Search providers…","aria-label":"Search providers"}),t.jsxs("div",{className:"max-h-[60vh] space-y-4 overflow-y-auto pr-1",children:[L4.map(o=>{const i=r.filter(l=>l.group===o.id);return i.length===0?null:t.jsxs("section",{children:[t.jsxs("div",{className:"mb-1.5 flex items-baseline gap-2",children:[t.jsx("h3",{className:"text-[12px] font-semibold uppercase tracking-wide text-[var(--adf-ui-text-muted)]",children:o.label}),t.jsx("span",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:o.hint})]}),t.jsx("div",{className:"grid grid-cols-2 gap-2",children:i.map(l=>t.jsxs("button",{type:"button",onClick:()=>e(l),className:"flex items-start gap-2 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] p-2.5 text-left transition-colors hover:border-[var(--adf-ui-accent)] hover:bg-[var(--adf-ui-surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--adf-ui-focus)]",children:[t.jsx(al,{iconKey:l.iconKey,label:l.label,size:28}),t.jsxs("span",{className:"min-w-0",children:[t.jsx("span",{className:"block truncate text-[12px] font-medium text-[var(--adf-ui-text)]",children:l.label}),t.jsx("span",{className:"mt-0.5 line-clamp-2 block text-[10.5px] leading-4 text-[var(--adf-ui-text-muted)]",children:l.description})]})]},l.key))})]},o.id)}),r.length===0&&t.jsx("p",{className:"py-6 text-center text-[12px] text-[var(--adf-ui-text-subtle)]",children:"Nothing matches. Any endpoint that speaks the OpenAI API works with the OpenAI-compatible tile."})]})]})}function En({label:e,hint:n,children:s}){return t.jsxs("div",{children:[t.jsx("label",{className:"mb-0.5 block text-[11px] text-[var(--adf-ui-text-muted)]",children:e}),s,n&&t.jsx("p",{className:"mt-0.5 text-[10.5px] text-[var(--adf-ui-text-subtle)]",children:n})]})}function IA({message:e}){return t.jsxs("p",{role:"alert",className:"rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-danger-subtle)] px-3 py-2 text-[12px] leading-5 text-[var(--adf-ui-danger)]",children:["Not saved: ",e]})}function LA({provider:e,entry:n,isDefault:s,status:a,saveError:r,onUpdate:o,onRemove:i,onMakeDefault:l,onTest:c,onClose:f,models:h,onFetchModels:m,onKeyEntered:p,chatgpt:d,grok:b,claude:g,onCarrierCountChange:w,onDone:j,requireDefaultModel:y}){const S=Cl(e.type),k=e.type==="chatgpt-subscription"?d:e.type==="grok-subscription"?b:e.type==="claude-subscription"?g:null,v=y?$A(e,a,k,n?.label??e.name):null,C=!!v,N=DA(e,!!n?.keyOptional,!!h?.models?.length,p),[E,M]=u.useState(!1),L=h?.models??[],q=L.length>0&&!E,A=e.baseUrl.match(/YOUR_[A-Z0-9_]+/)?.[0];return t.jsxs("div",{className:"space-y-4",children:[r&&t.jsx(IA,{message:r}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(al,{iconKey:n?.iconKey,label:n?.label??e.name,size:36}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-[12px]",children:[t.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--adf-ui-text-muted)]",children:[t.jsx("span",{className:`h-2 w-2 shrink-0 rounded-full ${$d(a)}`}),sb(a)]}),s?t.jsx("span",{className:"rounded bg-[var(--adf-ui-warning-subtle)] px-1.5 py-0.5 text-[10px] font-medium text-[var(--adf-ui-warning)]",children:"Default for new agents"}):t.jsx("button",{type:"button",onClick:l,className:"text-[11px] text-[var(--adf-ui-accent)] underline-offset-2 hover:underline",children:"Make default for new agents"})]}),t.jsx("p",{className:"mt-0.5 text-[10.5px] text-[var(--adf-ui-text-subtle)]",children:D4(e.type)})]}),t.jsx(ye,{variant:"secondary",size:"compact",onClick:c,disabled:a==="testing",loading:a==="testing",children:a==="testing"?"Testing…":"Test"})]}),t.jsxs("section",{className:"space-y-2.5",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-[13px] font-medium text-[var(--adf-ui-text)]",children:"App values"}),t.jsx("p",{className:"mt-0.5 text-[12px] leading-5 text-[var(--adf-ui-text-muted)]",children:"Used by every agent on this provider, unless the agent carries its own copy."})]}),t.jsx(En,{label:"Name",children:t.jsx(en,{"aria-label":"Provider name",type:"text",value:e.name,onChange:D=>o({name:D.target.value}),placeholder:n?.label})}),e.type==="openai-compatible"&&t.jsx(En,{label:"Base URL",hint:A?t.jsxs("span",{className:"text-[var(--adf-ui-warning)]",children:["Replace ",A," with your own value."]}):"The root the /chat/completions path is appended to.",children:t.jsx(en,{"aria-label":"Base URL",type:"text",value:e.baseUrl,onChange:D=>o({baseUrl:D.target.value}),onBlur:N.onUrlBlur,placeholder:n?.baseUrl??"http://localhost:1234/v1",className:"font-mono text-[12px]"})}),k?window.adfApi?.platform==="web"&&e.type==="chatgpt-subscription"&&!k.authenticated?t.jsx(En,{label:"Account",children:t.jsx("p",{className:"text-[12px] leading-5 text-[var(--adf-ui-text-muted)]",children:"Sign in to ChatGPT from the desktop app on the daemon host, then reload this page. Existing daemon sign-ins can be used here."})}):t.jsx(FA,{auth:k,label:n?.label??e.name}):e.apiKeyStorage==="secret-store"&&e.apiKeyStatus==="unavailable"&&!e.apiKey?t.jsx(En,{label:"API key",children:t.jsx("div",{role:"alert",className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-warning)]/40 bg-[var(--adf-ui-warning-subtle)] px-2.5 py-1.5 text-[12px] leading-5 text-[var(--adf-ui-warning)]",children:"This key was added from the ADF CLI and is kept in the OS keychain, which Studio can't open on this machine, so Studio's agents can't use it. Manage this provider's key with /provider in the ADF CLI."})}):t.jsx(En,{label:"API key",hint:N.checked&&OA(a,!!(e.apiKey??"").trim())||(e.apiKeyStorage==="secret-store"?e.apiKeyStatus==="missing"&&!e.apiKey?t.jsx("span",{className:"text-[var(--adf-ui-warning)]",children:"No key for this provider in the OS keychain. Enter one to store it there."}):"Kept in the OS keychain, shared with the ADF CLI.":n?.keysUrl?t.jsx(xb,{href:n.keysUrl,children:"Get a key ↗"}):n?.keyOptional?"Most local servers accept any value or none.":void 0),children:t.jsx(en,{"aria-label":"API key",type:"password",value:e.apiKey,onChange:D=>{N.onKeyChange(),o({apiKey:RA(e.apiKey??"",D.target.value)})},onPaste:N.onKeyPaste,onBlur:N.onKeyBlur,placeholder:n?.keyPlaceholder??"API key",className:"font-mono text-[12px]"})}),t.jsx(En,{label:"Default model",hint:h?.error?t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:h.error}):y??"Agents can pick another model; this is the starting point.",children:h?.loading?t.jsx("div",{className:"px-1 py-1.5 text-[12px] text-[var(--adf-ui-text-subtle)]",children:"Loading models…"}):q?t.jsxs(Fi,{"aria-label":"Default model",value:L.includes(e.defaultModel??"")?e.defaultModel:"__custom__",onChange:D=>{D.target.value==="__custom__"?M(!0):o({defaultModel:D.target.value})},children:[L.map(D=>t.jsx("option",{value:D,children:D},D)),e.defaultModel&&!L.includes(e.defaultModel)&&t.jsxs("option",{value:e.defaultModel,children:[e.defaultModel," (current)"]}),t.jsx("option",{value:"__custom__",children:"Type a model id…"})]}):t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx(en,{"aria-label":"Default model",type:"text",value:e.defaultModel??"",onChange:D=>o({defaultModel:D.target.value}),placeholder:n?.modelPlaceholder??"model id",className:"flex-1"}),L.length>0?t.jsx(ye,{variant:"ghost",size:"compact",className:"whitespace-nowrap",onClick:()=>M(!1),children:"Pick from list"}):t.jsx(ye,{variant:"ghost",size:"compact",className:"whitespace-nowrap",onClick:m,children:"Fetch models"})]})}),t.jsxs("details",{className:"group rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] px-2.5 py-1.5",children:[t.jsx("summary",{className:"cursor-pointer select-none text-[12px] text-[var(--adf-ui-text-muted)] hover:text-[var(--adf-ui-text)]",children:"Advanced"}),t.jsxs("div",{className:"mt-2 space-y-2.5",children:[t.jsx(En,{label:"Request delay (ms)",hint:"Pause before each request to stay under a rate limit. 0 = none.",children:t.jsx(en,{"aria-label":"Request delay in milliseconds",type:"number",min:0,step:100,value:e.requestDelayMs??0,onChange:D=>o({requestDelayMs:Math.max(0,parseInt(D.target.value)||0)})})}),t.jsx(mb,{params:e.params??[],onChange:D=>o({params:D})})]})]})]}),!S&&t.jsx("section",{className:"border-t border-[var(--adf-ui-separator)] pt-3",children:t.jsx(EA,{provider:e,apiKeyPlaceholder:n?.keyPlaceholder,onCountChange:w})}),S&&t.jsx("p",{className:"border-t border-[var(--adf-ui-separator)] pt-3 text-[11px] text-[var(--adf-ui-text-subtle)]",children:"Subscription sign-ins are shared by every agent; no per-agent copies."}),t.jsxs("div",{className:"flex items-center justify-between border-t border-[var(--adf-ui-separator)] pt-3",children:[t.jsx(ye,{variant:"ghost",size:"compact",className:"text-[var(--adf-ui-danger)]",onClick:i,children:"Remove provider"}),t.jsxs("span",{className:"flex items-center gap-2",children:[v&&t.jsx("span",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:v}),t.jsx(ye,{variant:"primary",onClick:j??f,disabled:C,children:"Done"})]})]})]})}function $A(e,n,s,a){return ab(e,n,!!s?.authenticated)?(e.defaultModel??"").trim()?null:"Pick a model first.":s?`Sign in with ${a} first.`:"Enter an API key first."}function OA(e,n){if(e==="testing")return"Checking…";if(e==="ok")return t.jsx("span",{className:"text-[var(--adf-ui-success)]",children:"Connected"});if(e==="failed")return t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:n?"Key rejected":"Connection failed"})}function DA(e,n,s,a){const r=e.apiKey??"",o=u.useRef(r),i=u.useRef(e.baseUrl),l=u.useRef(!1),[c,f]=u.useState(!1),h=u.useCallback(()=>{a&&(o.current=e.apiKey??"",i.current=e.baseUrl,f(!0),a())},[a,e.apiKey,e.baseUrl]),m=()=>!!r.trim()&&r!==o.current;return u.useEffect(()=>{l.current&&(l.current=!1,m()&&h())},[r]),u.useEffect(()=>{n&&!s&&h()},[]),{checked:c,onKeyChange:()=>f(!1),onKeyPaste:()=>{l.current=!0},onKeyBlur:()=>{m()&&h()},onUrlBlur:()=>{e.baseUrl.trim()&&e.baseUrl!==i.current&&h()}}}function FA({auth:e,label:n}){return e.version?t.jsxs(t.Fragment,{children:[t.jsx(BA,{auth:e}),t.jsx(Sm,{auth:e,label:n})]}):t.jsx(Sm,{auth:e,label:n})}function BA({auth:e}){const n=!!e.updateRequired;return t.jsx(En,{label:"Claude Code",hint:n?t.jsxs("span",{className:"text-[var(--adf-ui-danger)]",children:["ADF needs version ",e.minVersion," or newer."]}):e.minVersion?`ADF needs version ${e.minVersion} or newer.`:void 0,children:t.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] px-2.5 py-1.5",children:[t.jsx("span",{className:"font-mono text-[12px] text-[var(--adf-ui-text)]",children:e.version}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:`text-[11px] ${n?"text-[var(--adf-ui-danger)]":"text-[var(--adf-ui-success)]"}`,children:n?"Update required":"Supported"}),n&&e.recheck&&t.jsx(ye,{variant:"ghost",size:"compact",onClick:e.recheck,children:"Check again"})]})]})})}function Sm({auth:e,label:n}){if(e.updateRequired)return t.jsx(En,{label:"Account",hint:e.installError&&!e.installing?t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:e.installError}):void 0,children:e.install?t.jsx(ye,{variant:"primary",className:"w-full",onClick:e.install,disabled:e.installing,loading:e.installing,children:e.installing?"Updating Claude Code…":"Update Claude Code and sign in"}):t.jsxs("p",{className:"text-[12px] text-[var(--adf-ui-text-subtle)]",children:["Update Claude Code to sign in with ",n,"."]})});if(e.authenticated){const s=e.plan?` · ${e.plan.charAt(0).toUpperCase()}${e.plan.slice(1)} plan`:"";return t.jsx(En,{label:"Account",hint:e.flowError?t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:e.flowError}):e.signOutHint,children:t.jsxs("div",{className:"flex items-center justify-between rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-success)]/40 bg-[var(--adf-ui-success-subtle)] px-2.5 py-1.5",children:[t.jsxs("span",{className:"text-[12px] text-[var(--adf-ui-success)]",children:["Signed in",e.email?` as ${e.email}`:"",s]}),t.jsx(ye,{variant:"ghost",size:"compact",className:"text-[var(--adf-ui-danger)]",onClick:e.signOut,children:"Sign out"})]})})}if(e.installed===!1){const s=!!e.installError&&!e.installing;return t.jsx(En,{label:"Account",hint:s?t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:e.installError}):e.installing?"This can take a minute.":void 0,children:t.jsxs("div",{className:"space-y-2 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] px-3 py-2.5",children:[t.jsxs("p",{className:"text-[12px] leading-5 text-[var(--adf-ui-text)]",children:[n," uses your Claude Pro or Max plan via Claude Code."]}),e.install&&t.jsx(ye,{variant:"primary",className:"w-full",onClick:e.install,disabled:e.installing,loading:e.installing,children:e.installing?"Installing Claude Code…":"Install Claude Code and sign in"}),(s||!e.install)&&t.jsxs("div",{className:"flex gap-1.5",children:[e.installUrl&&t.jsx(ye,{variant:"secondary",className:"flex-1",onClick:()=>window.open(e.installUrl,"_blank","noopener,noreferrer"),children:"Install it yourself"}),e.recheck&&t.jsx(ye,{variant:"secondary",onClick:e.recheck,children:"Check again"})]})]})})}return e.flowPending?t.jsx(zA,{auth:e}):e.device?t.jsx(En,{label:"Account",children:t.jsxs("div",{className:"space-y-1.5 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] px-3 py-2.5",children:[t.jsx("p",{className:"text-[12px] text-[var(--adf-ui-text)]",children:window.adfApi?.platform==="web"?"Open the sign-in page below and confirm this code:":"A browser window opened. Confirm this code there:"}),t.jsx("div",{className:"select-all text-center font-mono text-lg tracking-widest text-[var(--adf-ui-text)]",children:e.device.userCode}),t.jsxs("p",{className:"text-[10.5px] text-[var(--adf-ui-text-subtle)]",children:["Waiting for approval… If no window opened, visit ",t.jsx("a",{href:e.device.verificationUri,target:"_blank",rel:"noopener noreferrer",className:"select-all break-all underline",children:e.device.verificationUri})," and enter the code."]})]})}):t.jsx(En,{label:"Account",hint:e.flowError?t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:e.flowError}):`Requires an eligible ${n} plan.`,children:t.jsx(ye,{variant:"primary",className:"w-full",onClick:e.signIn,disabled:e.loading,loading:e.loading,children:e.loading?"Signing in…":`Sign in with ${n}`})})}function zA({auth:e}){const[n,s]=u.useState(""),[a,r]=u.useState(!1),o=async()=>{if(!(!e.submitCode||!n.trim())){r(!0);try{await e.submitCode(n),s("")}finally{r(!1)}}};return t.jsx(En,{label:"Account",hint:e.flowError?t.jsx("span",{className:"text-[var(--adf-ui-danger)]",children:e.flowError}):void 0,children:t.jsxs("div",{className:"space-y-2 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] px-3 py-2.5",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("p",{className:"text-[12px] text-[var(--adf-ui-text)]",children:"Finish signing in in your browser…"}),e.cancel&&t.jsx(ye,{variant:"ghost",size:"compact",onClick:e.cancel,children:"Cancel"})]}),e.flowUrl&&t.jsx("p",{className:"text-[11px]",children:t.jsx(xb,{href:e.flowUrl,children:"Open sign-in page ↗"})}),e.submitCode&&t.jsxs("form",{className:"space-y-1",onSubmit:i=>{i.preventDefault(),o()},children:[t.jsx("p",{className:"text-[10.5px] text-[var(--adf-ui-text-subtle)]",children:"If the page shows a code, paste it here."}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx(en,{"aria-label":"Sign-in code",type:"text",value:n,onChange:i=>s(i.target.value),placeholder:"Code",className:"flex-1 font-mono text-[12px]"}),t.jsx(ye,{type:"submit",variant:"secondary",size:"compact",disabled:!n.trim()||a,loading:a,children:"Submit"})]})]})]})})}function xb({href:e,children:n}){return t.jsx("a",{href:e,target:"_blank",rel:"noreferrer",onClick:s=>{s.preventDefault(),window.open(e,"_blank","noopener,noreferrer")},className:"text-[var(--adf-ui-accent)] underline-offset-2 hover:underline",children:n})}function WA(){const e=F(A=>A.providerSetupRequest),n=F(A=>A.resolveProviderSetup),s=Z(A=>A.config?.name),a=Z(A=>A.config?.model?.provider),r=ob(),{providers:o,setProviders:i,defaultProviderId:l,setDefaultProviderId:c,load:f,flushSave:h,saveFailure:m}=r,[p,d]=u.useState(null),b=u.useRef(null),g=rb({providers:o,setProviders:i,defaultProviderId:l,setDefaultProviderId:c,flushSave:h,saveFailure:m}),{openPicker:w,closeModal:j,pick:y,remove:S}=g;u.useEffect(()=>{if(!e)return;let A=!1;return b.current=null,d(null),f().then(()=>{A||w()}).catch(D=>{A||d(D instanceof Error?D.message:String(D))}),()=>{A=!0}},[e,f,w]);const k=u.useCallback(A=>{y(A).then(D=>{b.current=D})},[y]),v=u.useCallback(async()=>{const A=b.current;if(A){S(A,!1),b.current=null;const D=o.filter(W=>W.id!==A),U=l===A?D[0]?.id:l;try{await window.adfApi.setSettings({providers:D,defaultProviderId:U??""})}catch{}}else j();n(null)},[j,l,o,S,n]),C=u.useCallback(async()=>{const A=g.editing;if(!A){await v();return}const D=(A.defaultModel??"").trim();if(!D){d("Pick a model first.");return}d(null);try{await h();const U=de.getState().filePath,W=e?.filePath;if(W&&W===U)await Ro(K=>({...K,model:{...K.model,provider:A.id,model_id:D}}));else if(W){const K=await window.adfApi.setAgentModelForFile(W,{provider:A.id,model_id:D});if(!K.success){d(K.error??"Could not update the agent");return}}b.current=null,j(),n(A.id)}catch(U){d(U instanceof Error?U.message:String(U))}},[v,j,h,g.editing,e?.filePath,n]);if(!e)return null;const N=e.reason==="no_provider",E=N?"The new agent":s??"This agent",M=de.getState().filePath,L=N||e.filePath===M&&!a,q=N?"Agents need a model to run.":L?`${E} needs a model to run.`:e.reason==="provider_unconfigured"?`${E}'s provider has no API key on this computer.`:`${E}'s model names a provider that is not configured on this computer.`;return t.jsx(PA,{...g.modalProps,open:g.modalOpen,onClose:()=>{v()},onPick:k,onDone:()=>{C()},requireDefaultModel:N?"New agents start on this model.":`Becomes ${E}'s model.`,intro:t.jsxs(t.Fragment,{children:[q," Credentials are stored in app settings, not in the agent file.",p&&t.jsx("span",{className:"block pt-1 text-[var(--adf-ui-danger)]",children:p})]})})}function _m(e){const n=e.prerequisites.find(s=>!s.installed);if(n)return{kind:"manual",reason:`Podman needs ${n.name} first. Set it up in Settings → Compute.`,url:n.docsUrl};if(!e.available){const s=e.installMethods.find(r=>r.autoRunnable&&r.command);return s?.command?{kind:"step",next:{step:"install",installCommand:s.command,label:"Installing Podman"}}:{kind:"manual",reason:"Install Podman with its installer, then check again.",url:e.installMethods.find(r=>r.url)?.url}}return e.machineRequired&&!e.machineExists?{kind:"step",next:{step:"machine_init",label:"Setting up Podman's machine (downloads about 1 GB)"}}:e.machineRequired&&!e.machineRunning?{kind:"step",next:{step:"machine_start",label:"Starting Podman's machine"}}:{kind:"ready"}}const HA=5;function UA({open:e,servers:n,api:s,onClose:a,onResolved:r,runOnHost:o,acceptMcpOnHost:i,remote:l}){const[c,f]=u.useState(null),[h,m]=u.useState(null),[p,d]=u.useState(null),[b,g]=No(),w=u.useCallback(async()=>{const C=await s?.computeSetup?.({step:"check"}),N=C?.availability?_m(C.availability):null;return f(N),N},[s]);u.useEffect(()=>{e&&(d(null),m(null),f(null),w().catch(C=>d(String(C))))},[e,w]);const j=async()=>{d(null);try{let C=c??await w();for(let N=0;N<HA&&C?.kind==="step";N++){const{next:E}=C;m(`${E.label}…`);const M=await s?.computeSetup?.(E.step==="install"?{step:"install",installCommand:E.installCommand}:{step:E.step});if(!M?.success){d(M?.error??`${E.label} failed.`),await w();return}C=M.availability?_m(M.availability):await w(),f(C)}C?.kind==="ready"&&r()}catch(C){d(String(C))}finally{m(null)}},y=n.length===1?`"${n[0]}"`:"These MCP servers",S=l?"the computer running this agent":"this computer",k=async()=>{if(!(!o||!await g({title:n.length===1?`Run ${n[0]} on the host`:"Run these servers on the host",body:t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:[y," will run directly on ",S," instead of in a container, with its files and network. Servers set up in Settings → MCP servers run on the host for every agent that uses them."]}),t.jsxs("p",{className:"mt-2",children:["This turns on Host access if it is off. ",ho.body]})]}),confirmLabel:"Run on the host",danger:!0}))){m("Saving…");try{await o()?r():d("Not saved.")}finally{m(null)}}},v=async()=>{if(!(!i||!await g(wN))){m("Saving…");try{await i()?r():d("Not saved.")}finally{m(null)}}};return t.jsxs(t.Fragment,{children:[t.jsx(_t,{open:e,onClose:a,title:"Set up a container for MCP servers",preventClose:!!h,children:t.jsxs("div",{className:"space-y-4 text-[13px] leading-5",children:[t.jsxs("p",{className:"text-[var(--adf-ui-text-muted)]",children:[y," ",n.length===1?"needs":"need"," Podman to run in a container, away from your files. Podman isn't set up on ",S," yet."]}),t.jsxs("div",{className:"space-y-2 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] px-3 py-2.5",children:[c===null&&!p&&t.jsx("p",{className:"text-[12px] text-[var(--adf-ui-text-subtle)]",children:"Checking Podman…"}),c?.kind==="manual"&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-[12px] text-[var(--adf-ui-text)]",children:c.reason}),t.jsxs("div",{className:"flex gap-1.5",children:[c.url&&t.jsx(ye,{variant:"primary",className:"flex-1",onClick:()=>window.open(c.url,"_blank","noopener,noreferrer"),children:"Download Podman"}),t.jsx(ye,{variant:"secondary",onClick:()=>{w()},disabled:!!h,children:"Check again"})]})]}),(c?.kind==="step"||c?.kind==="ready")&&t.jsx(ye,{variant:"primary",className:"w-full",onClick:()=>{c.kind==="ready"?r():j()},disabled:!!h,loading:!!h&&h!=="Saving…",children:h&&h!=="Saving…"?h:c.kind==="ready"?"Podman is ready: connect":"Set up Podman (recommended)"}),h&&h!=="Saving…"&&t.jsxs("p",{className:"text-[11px] text-[var(--adf-ui-text-subtle)]",children:["This can take a few minutes.",l?"":" Your system may ask for your password."]}),p&&t.jsx("p",{className:"text-[11px] text-[var(--adf-ui-danger)] break-words",role:"alert",children:p})]}),(o||i)&&t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("p",{className:"text-[12px] text-[var(--adf-ui-text-muted)]",children:["Or skip the container. Servers on the host can read and change the files on ",S,"."]}),t.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[o&&t.jsx(ye,{variant:"secondary",onClick:()=>{k()},disabled:!!h,children:n.length===1?`Run ${n[0]} on the host…`:"Run these on the host…"}),i&&t.jsx(ye,{variant:"ghost",onClick:()=>{v()},disabled:!!h,children:"Run all MCP servers on the host…"})]})]})]})}),b]})}function KA(){const e=de(j=>j.filePath),n=Ks(),s=Ai(j=>j.request),a=Ai(j=>j.open),r=Ai(j=>j.close),[o,i]=u.useState({filePath:null,byName:{}}),l=u.useRef({filePath:null,names:new Set});u.useEffect(()=>{if(i({filePath:e,byName:{}}),!e)return;let j=!1;Promise.resolve(V()?.getMcpServerStatus?.()).then(S=>{j||!S?.servers||i({filePath:e,byName:Object.fromEntries(S.servers.map(k=>[k.name,k.status]))})}).catch(()=>{});const y=V()?.onMcpServerStatusChanged?.(S=>{j||i(k=>k.filePath===e?{filePath:e,byName:{...k.byName,[S.name]:S.status}}:k)});return()=>{j=!0,y?.()}},[e,n]),u.useEffect(()=>{if(!e||o.filePath!==e)return;l.current.filePath!==e&&(l.current={filePath:e,names:new Set});const j=Object.entries(o.byName).filter(([,S])=>S==="needs_compute").map(([S])=>S),y=j.filter(S=>!l.current.names.has(S));if(y.length!==0){for(const S of y)l.current.names.add(S);a(e,j)}},[o,e,a]);const c=!!s&&s.filePath===e,f=c?s.servers:[],[h,m]=u.useState(null);u.useEffect(()=>{if(!c)return;let j=!1;return m(null),Promise.resolve(V()?.getSettings()).then(y=>{j||m(y??null)}).catch(()=>{}),()=>{j=!0}},[c]);const p=Z(j=>j.config),d=(()=>{if(!h||!p||h.compute?.mcpOnHost===!0&&h.compute.hostAccessEnabled===!0||p.compute?.enabled)return!1;const j=h.mcpServers??[];return f.some(y=>{const S=j.find(v=>v.name===y);return(S?S.runLocation:p.mcp?.servers?.find(v=>v.name===y)?.run_location)!=="shared"})})(),b=u.useCallback(()=>{r();for(const j of f)V()?.restartMcpServer?.({name:j})},[f,r]),g=u.useCallback(async()=>{const j=V(),y=await j?.getSettings(),S=Z.getState().config;if(!y||!S)return!1;const k=y.compute;let v={hostAccessEnabled:k?.hostAccessEnabled===!0,hostApproved:k?.hostApproved??[],hostApprovedSources:k?.hostApprovedSources},C={};const N=y.mcpServers??[];let E=null;const M=[];let L=0;for(const A of f){const D=N.find(U=>U.name===A);if(D){E=(E??N).map(W=>W.name===A?{...W,runLocation:"host"}:W);const U=_d(A,Qi(D),!0,v);v={...v,...U},C={...C,...U},L++}else{const U=S.mcp?.servers?.find(K=>K.name===A);if(!U)continue;const W=_d(A,Ku(U),!S.compute?.host_access,v);v={...v,...W},C={...C,...W},M.push(A),L++}}return!(L===0||!(await br({compute:C,...E?{mcpServers:E}:{}},j)).ok||M.length&&!await Ro(D=>({...D,mcp:D.mcp&&{...D.mcp,servers:D.mcp.servers.map(U=>{if(!M.includes(U.name))return U;const{host_requested:W,...K}=U;return{...K,run_location:"host"}})}})))},[f]),w=u.useCallback(async()=>(await br({compute:{hostAccessEnabled:!0,mcpOnHost:!0}},V())).ok,[]);return t.jsx(UA,{open:c,servers:f,api:V(),onClose:r,onResolved:b,runOnHost:g,acceptMcpOnHost:d?w:void 0,remote:n!==ze})}function gb(e,n=[]){for(const s of e)s.isDirectory?gb(s.children??[],n):n.push(s);return n}function of(e){return e.agentName??e.fileName.replace(/\.adf$/i,"")}function qA(){const e=F(w=>w.shareDialogFilePath),n=F(w=>w.closeShareDialog),s=tn(w=>w.filesByDir),[a,r]=u.useState(null),[o,i]=u.useState(null),[l,c]=u.useState(!1),f=u.useMemo(()=>gb(Object.values(s).flat()),[s]),h=u.useMemo(()=>e?f.find(w=>w.filePath===e)??null:null,[f,e]),m=u.useMemo(()=>h?f.filter(w=>w.filePath!==h.filePath):f,[f,h]),p=async w=>{c(!0),r(null),i(null);try{const j=await window.adfApi.saveShareCopy(w);j.success?r(j.filePath||(window.adfApi?.platform==="web"?"your browser downloads":"a copy")):j.error&&i(j.error)}catch(j){i(j instanceof Error?j.message:String(j))}finally{c(!1)}},d=h?of(h):"agent",b=h?wo({did:h.did,filePath:h.filePath}):null,g=h?tx(h.icon,h.agentId||h.filePath):null;return t.jsx(_t,{open:e!==null,onClose:n,title:"Share",wide:!0,children:t.jsxs("div",{className:"space-y-5",children:[t.jsx("p",{className:"text-[13px] leading-relaxed text-[var(--adf-ui-text-muted)]",children:window.adfApi?.platform==="web"?"Download a copy, then send it in Messages, Mail, Slack, or another app. Your agent stays here and does not change.":"Drag the file into Messages, Mail, Slack, or a folder. They get their own copy, like a PDF you sent. Yours stays here and does not change."}),t.jsx(YA,{name:d,seed:b,icon:g}),h?t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(VA,{file:h,seed:b,icon:g}),t.jsx("div",{className:"min-w-0 flex-1 text-[12px] text-[var(--adf-ui-text-subtle)]",children:window.adfApi?.platform==="web"?"Download this agent to share it.":"Grab this and drop it anywhere."}),t.jsx(ye,{size:"compact",onClick:()=>p(h.filePath),loading:l,children:window.adfApi?.platform==="web"?"Download copy":"Save copy…"})]}):null,m.length>0&&t.jsxs("div",{children:[h&&t.jsx("div",{className:"mb-1.5 text-[11px] font-medium uppercase tracking-wide text-[var(--adf-ui-text-subtle)]",children:"Other agents"}),t.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(w=>t.jsx(GA,{file:w,onSave:()=>p(w.filePath)},w.filePath))})]}),f.length===0&&t.jsx("p",{className:"text-[12px] text-[var(--adf-ui-text-subtle)]",children:"No agents."}),a&&t.jsxs("p",{className:"text-[12px] text-[var(--adf-ui-text-muted)]",children:["Saved to ",a]}),o&&t.jsx("p",{className:"text-[12px] text-[var(--adf-ui-danger)]",children:o}),t.jsxs("details",{className:"group text-[12px]",children:[t.jsx("summary",{className:"cursor-pointer select-none text-[var(--adf-ui-text-subtle)] hover:text-[var(--adf-ui-text)]",children:"What's in the copy"}),t.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2",children:[t.jsx(Cm,{title:"Included",tone:"ok",items:["Config and agent instructions","README, memory and files","Loop history","Lambdas, skills and tool settings","Provider names and base URLs (no keys)"]}),t.jsx(Cm,{title:"Left out",tone:"muted",items:["Identity keys. The receiver claims a new identity","Provider keys and sign-ins kept in app settings","Credentials sealed to you, unless you set a share password; then they travel sealed and open only with it"]})]})]})]})})}function VA({file:e,seed:n,icon:s}){const a=vu(e.filePath);return t.jsxs("div",{...a,className:"flex cursor-grab select-none items-center gap-3 rounded-xl border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] py-2 pl-2 pr-4 hover:border-[var(--adf-ui-accent)] active:cursor-grabbing",children:[t.jsx(ol,{seed:n,icon:s,size:40}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"text-[13px] font-semibold text-[var(--adf-ui-text)]",children:of(e)}),t.jsx("div",{className:"font-mono text-[10.5px] text-[var(--adf-ui-text-subtle)]",children:e.fileName})]})]})}function GA({file:e,onSave:n}){const s=vu(e.filePath);return t.jsxs("div",{...s,className:"flex cursor-grab select-none items-center gap-1.5 rounded-lg border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface-raised)] py-1 pl-1.5 pr-1 text-[12px] hover:border-[var(--adf-ui-accent)] active:cursor-grabbing",children:[t.jsx(ol,{size:20}),t.jsx("span",{className:"font-medium text-[var(--adf-ui-text)]",children:of(e)}),t.jsx("button",{type:"button",draggable:!1,onDragStart:a=>{a.preventDefault(),a.stopPropagation()},onClick:n,className:"ml-1 rounded px-1.5 py-0.5 text-[11px] text-[var(--adf-ui-accent)] hover:bg-[var(--adf-ui-accent-subtle)]",children:"Save…"})]})}function ol({seed:e,icon:n,size:s}){const a=Nr()==="emoji";return t.jsxs("span",{className:"relative inline-flex shrink-0 items-center justify-center",style:{width:s,height:s},"aria-hidden":!0,children:[t.jsxs("svg",{viewBox:"0 0 24 24",width:s,height:s,fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round",className:"text-[var(--adf-ui-accent)]",children:[t.jsx("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z",fill:"color-mix(in srgb, var(--adf-ui-accent) 12%, transparent)"}),t.jsx("path",{d:"M14 3v5h5"})]}),a&&n&&t.jsx("span",{className:"absolute",style:{fontSize:s*.42,bottom:s*.14},children:n}),!a&&e&&t.jsx("span",{className:"absolute flex",style:{bottom:s*.1},children:t.jsx(Ba,{seed:e,size:Math.round(s*.5)})})]})}function YA({name:e,seed:n,icon:s}){const a=`${e}.adf`;return t.jsx("div",{className:"relative overflow-hidden rounded-xl border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] px-6 py-5","aria-hidden":!0,children:t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("div",{className:"flex w-24 shrink-0 flex-col items-center gap-1.5",children:[t.jsx(ol,{seed:n,icon:s,size:52}),t.jsx("span",{className:"max-w-full truncate font-mono text-[10.5px] text-[var(--adf-ui-text-muted)]",children:a})]}),t.jsxs("svg",{className:"h-10 flex-1 text-[var(--adf-ui-text-subtle)]",viewBox:"0 0 160 40",fill:"none",preserveAspectRatio:"none",children:[t.jsx("path",{d:"M4 32 C 50 32, 70 8, 150 8",stroke:"currentColor",strokeWidth:"1.5",strokeDasharray:"4 5",strokeLinecap:"round"}),t.jsx("path",{d:"M143 3 l8 5 -8 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),t.jsxs("div",{className:"w-56 shrink-0 overflow-hidden rounded-lg border border-[var(--adf-ui-border)] bg-[var(--adf-ui-surface)] shadow-sm",children:[t.jsxs("div",{className:"flex items-center gap-1.5 border-b border-[var(--adf-ui-separator)] px-2.5 py-1.5",children:[t.jsx("span",{className:"h-2 w-2 rounded-full bg-[#ff5f57]"}),t.jsx("span",{className:"h-2 w-2 rounded-full bg-[#febc2e]"}),t.jsx("span",{className:"h-2 w-2 rounded-full bg-[#28c840]"}),t.jsx("span",{className:"ml-2 h-2 w-16 rounded bg-[var(--adf-ui-separator)]"})]}),t.jsxs("div",{className:"space-y-1.5 px-2.5 py-2.5",children:[t.jsx("div",{className:"h-5 w-28 rounded-2xl rounded-bl-sm bg-[var(--adf-ui-separator)]"}),t.jsxs("div",{className:"ml-auto flex w-fit items-center gap-1.5 rounded-2xl rounded-br-sm bg-[var(--adf-ui-accent)] px-2 py-1 text-[10.5px] font-medium text-[var(--adf-ui-on-accent)]",children:[t.jsx(ol,{size:14}),t.jsx("span",{className:"max-w-[110px] truncate",children:a})]}),t.jsx("div",{className:"h-5 w-20 rounded-2xl rounded-bl-sm bg-[var(--adf-ui-separator)]"})]})]})]})})}function Cm({title:e,items:n,tone:s}){return t.jsxs("div",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] bg-[var(--adf-ui-canvas)] p-3",children:[t.jsx("div",{className:`mb-1.5 text-[11px] font-medium uppercase tracking-wide ${s==="ok"?"text-green-600 dark:text-green-400":"text-[var(--adf-ui-text-subtle)]"}`,children:e}),t.jsx("ul",{className:"space-y-1 text-[12px] text-[var(--adf-ui-text-muted)]",children:n.map(a=>t.jsxs("li",{className:"flex gap-1.5",children:[t.jsx("span",{"aria-hidden":!0,children:s==="ok"?"✓":"–"}),t.jsx("span",{children:a})]},a))})]})}function XA(){const e=de(h=>h.filePath),n=F(h=>h.agentNeedsReview),s=F(h=>h.agentReviewDialogOpen),a=F(h=>h.fileMoveWarning),r=F(h=>h.setAgentReviewDialog),o=F(h=>h.setAgentNeedsReview),i=F(h=>h.setFileMoveWarning),[l,c]=u.useState(null),f=u.useCallback(async()=>{c(null);try{const h=await V().checkAgentReview();h.needsReview?r(!0,h.configSummary):o(!1)}catch(h){console.error("[AgentReviewBanner] Review check error:",h);const m=F.getState().agentReviewSummary;m?r(!0,m):c("Couldn't check review status.")}},[r,o]);return a?t.jsxs("div",{role:"alert",className:"w-full shrink-0 flex items-center justify-center gap-2 px-3 py-1.5 border-b border-[var(--adf-ui-danger)]/30 bg-[var(--adf-ui-danger)]/10 text-[11px] text-[var(--adf-ui-danger)]",children:[t.jsx("span",{children:a}),t.jsx("button",{type:"button",onClick:()=>i(null),"aria-label":"Dismiss",className:"rounded-[var(--adf-ui-control-radius)] p-0.5 hover:bg-[var(--adf-ui-surface-hover)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]",children:t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}):!e||!n||s?null:t.jsxs("div",{role:"status",className:"w-full shrink-0",children:[t.jsxs("button",{type:"button",onClick:f,className:"w-full flex items-center justify-center gap-2 px-3 py-1.5 border-b border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] text-[11px] text-[var(--adf-ui-warning)] cursor-pointer focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]",children:[t.jsx("span",{children:"This agent hasn't been reviewed yet — it can't run."}),t.jsx("span",{className:"font-medium underline",children:"Review"})]}),l&&t.jsx("p",{className:"w-full text-center px-3 py-1 text-[11px] text-[var(--adf-ui-danger)] border-b border-[var(--adf-ui-border)]",children:l})]})}function JA(){const[e,n]=u.useState([]),[s,a]=u.useState(!1);if(u.useEffect(()=>Jb(window.adfApi,(o,i)=>{n(o),i&&a(!0)}),[]),e.length===0)return null;const r="px-2 py-0.5 rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-warning)]/40 font-medium hover:bg-[var(--adf-ui-surface-hover)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]";return t.jsxs("div",{role:"status",className:"w-full shrink-0 flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] text-[11px] text-[var(--adf-ui-warning)]",children:[t.jsx("span",{className:"flex-1 min-w-0",children:Qb(e,{session:s})}),t.jsx("button",{type:"button",className:r,onClick:()=>{window.adfApi?.recoveryReveal?.()},children:window.adfApi?.platform==="web"?"Download copies":"Show folder"}),t.jsx("button",{type:"button",className:r,onClick:()=>{window.adfApi?.recoveryArchive?.().finally(()=>n([]))},children:"Dismiss"})]})}function QA(){const e=F(r=>r.openSettingsAt),[n,s]=u.useState(null);if(u.useEffect(()=>{const r=()=>{window.adfApi?.getOwnerIdentityStatus?.().then(o=>s(o?.restoreRequired?o.ownerDid:null)).catch(()=>s(null))};return r(),window.addEventListener("focus",r),()=>window.removeEventListener("focus",r)},[]),!n)return null;const a=n.length>24?`${n.slice(0,14)}…${n.slice(-4)}`:n;return t.jsx("div",{role:"status",className:"w-full shrink-0",children:t.jsxs("button",{type:"button",onClick:()=>e("identity","restore-identity"),className:"w-full flex items-center justify-center gap-2 px-3 py-1.5 border-b border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] text-[11px] text-[var(--adf-ui-warning)] cursor-pointer focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--adf-ui-accent)]",children:[t.jsxs("span",{children:["Your owner identity ",t.jsx("span",{className:"font-mono",children:a})," was set up in the terminal. Enter its 12 words to use it in Studio."]}),t.jsx("span",{className:"font-medium underline",children:"Restore your identity"})]})})}function ZA(){const e=F(c=>c.openSettingsAt),[n,s]=u.useState([]),[a,r]=u.useState(null),[o,i]=u.useState(null);u.useEffect(()=>{let c=!0;window.adfApi?.getNetworkNotices?.().then(h=>{c&&s(h)}).catch(()=>{});const f=window.adfApi?.onNetworkNoticesChanged?.(h=>s(h));return()=>{c=!1,f?.()}},[]);const l=async c=>{if(c.networkId){r(c.key),i(null);try{const f=await window.adfApi.allowNetwork(c.networkId);f.ok||i(f.error)}catch{i("Studio could not allow this network.")}finally{r(null)}}};return t.jsx(eE,{notices:n,busy:a,error:o,onAllow:c=>{l(c)},onDismiss:c=>{window.adfApi?.dismissNetworkNotice?.(c.key)},onOpenNetworking:()=>e("networking")})}function eE({notices:e,busy:n,error:s,onAllow:a,onDismiss:r,onOpenNetworking:o}){return e.length===0?null:t.jsx("div",{role:"status","aria-live":"polite",className:"w-full shrink-0",children:e.map(i=>t.jsxs("div",{className:"w-full flex flex-wrap items-center justify-center gap-x-3 gap-y-1 px-3 py-1.5 border-b border-[var(--adf-ui-warning)]/30 bg-[var(--adf-ui-warning-subtle)] text-[11px] text-[var(--adf-ui-warning)]",children:[t.jsxs("span",{children:[i.message,i.reason?` ${i.reason}`:""]}),i.canAllow&&t.jsx("button",{type:"button",disabled:n===i.key,onClick:()=>a(i),className:"font-medium underline cursor-pointer disabled:opacity-60",children:"Allow"}),!i.canAllow&&t.jsx("button",{type:"button",onClick:o,className:"underline cursor-pointer",children:"Networking"}),t.jsx("button",{type:"button",onClick:()=>r(i),className:"underline cursor-pointer",children:"Dismiss"}),i.warning&&t.jsx("span",{className:"w-full text-center",children:i.warning}),s&&n===null&&t.jsx("span",{className:"w-full text-center text-[var(--adf-ui-danger)]",children:s})]},i.key))})}function tE(){const e=F(r=>r.shuttingDown),n=F(r=>r.setShuttingDown),[s,a]=u.useState(!1);return u.useEffect(()=>window.adfApi.onShuttingDown(()=>n(!0)),[n]),u.useEffect(()=>window.adfApi?.onUpdateState(r=>a(r.status==="installing")),[]),e?t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-white/80 dark:bg-neutral-900/85 backdrop-blur-sm",children:t.jsxs("div",{className:"flex flex-col items-center gap-4",children:[t.jsxs("svg",{className:"h-8 w-8 animate-spin text-[var(--adf-ui-text-subtle)]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),t.jsx("span",{className:"text-sm font-medium text-neutral-500 dark:text-neutral-400",children:s?"Restarting to update...":"Shutting down..."})]})}):null}const gi=500,nE=2e3;function sE(e,n){const s=n.text.trim().toLowerCase();return n.level==="all"&&n.origin==="all"&&!s?e:e.filter(a=>!(n.level!=="all"&&a.level!==n.level||n.origin!=="all"&&(a.origin??"")!==n.origin||s&&!`${a.message}\0${a.origin??""}\0${a.event??""}\0${a.target??""}\0${a.data??""}`.toLowerCase().includes(s)))}function Am(e,n,s){const a=e.length>0?e[e.length-1].id:0,r=n.filter(i=>i.id>a);if(r.length===0)return{logs:e,added:0};const o=[...e,...r];return{logs:o.length>s?o.slice(o.length-s):o,added:r.length}}function aE(e,n){return`Showing ${e.toLocaleString()} of ${Math.max(n,e).toLocaleString()}`}const rE={debug:"text-neutral-500",info:"text-blue-600 dark:text-blue-400",warn:"text-amber-600 dark:text-yellow-400",error:"text-red-600 dark:text-red-400"},oE={debug:"DBG",info:"INF",warn:"WRN",error:"ERR"},Pi="bg-white dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 border border-neutral-300 dark:border-neutral-700 rounded px-1.5 py-0.5 text-[11px] outline-none",Bd="hover:bg-neutral-100 dark:hover:bg-neutral-800 text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-300 px-1.5 py-0.5 rounded text-[11px]",bb="bg-green-50 dark:bg-green-900/40 text-green-700 dark:text-green-400 border border-green-200 dark:border-green-800";function vb(e){const n=new Date(e),s=String(n.getHours()).padStart(2,"0"),a=String(n.getMinutes()).padStart(2,"0"),r=String(n.getSeconds()).padStart(2,"0"),o=String(n.getMilliseconds()).padStart(3,"0");return`${s}:${a}:${r}.${o}`}function iE(){const e=F(z=>z.logsAutoRefresh),n=F(z=>z.setLogsAutoRefresh),s=de(z=>z.filePath),[a,r]=u.useState([]),o=u.useRef(a);o.current=a;const[i,l]=u.useState(0),[c,f]=u.useState("all"),[h,m]=u.useState("all"),[p,d]=u.useState(""),[b,g]=u.useState(null),[w,j]=u.useState(!1),[y,S]=u.useState(null),[k,v]=u.useState(!1),C=u.useRef(null),N=u.useRef(0),E=u.useRef(gi),M=u.useRef(0),L=u.useRef(!1),q=u.useRef(!1),A=u.useRef(null);u.useEffect(()=>{const z=++M.current;r([]),l(0),g(null),m("all"),j(!1),S(null),N.current=0,E.current=gi,L.current=!1,s&&V()?.getLogs(gi).then(({logs:H,count:G})=>{if(z!==M.current)return;const ke=[...H].reverse();r(ke),l(G),S(Date.now()),ke.length>0&&(N.current=ke[ke.length-1].id),L.current=!0})},[s]);const D=u.useCallback(()=>{if(!L.current||q.current)return;const z=M.current;q.current=!0,V()?.getLogsAfterId(N.current).then(({logs:H})=>{if(z!==M.current||(S(Date.now()),H.length===0))return;N.current=Math.max(N.current,H[H.length-1].id);const{logs:G,added:ke}=Am(o.current,H,Math.max(nE,E.current));ke!==0&&(o.current=G,r(G),l(le=>le+ke))}).finally(()=>{q.current=!1})},[]);qu(D,2e3,{enabled:e,ref:C});const U=u.useCallback(()=>{if(k)return;const z=M.current,H=a.length+gi;v(!0),V()?.getLogs(H).then(({logs:G,count:ke})=>{if(z!==M.current)return;const le=[...G].reverse();E.current=Math.max(E.current,H);const ge=Am(le,o.current,Number.MAX_SAFE_INTEGER).logs;A.current=X.current?.getTotalSize()??null,o.current=ge,r(ge),l(ke),j(!0),le.length>0&&(N.current=Math.max(N.current,le[le.length-1].id))}).finally(()=>v(!1))},[a.length,k]),W=u.useCallback(()=>{window.confirm("Clear all logs? This cannot be undone.")&&V()?.clearLogs().then(()=>{r([]),l(0),N.current=0})},[]),K=u.useCallback(()=>{if(!C.current)return;const{scrollTop:z,scrollHeight:H,clientHeight:G}=C.current;j(H-z-G>40)},[]),ue=u.useMemo(()=>{const z=new Set;for(const H of a)H.origin&&z.add(H.origin);return[...z].sort()},[a]),ae=u.useMemo(()=>sE(a,{level:c,origin:h,text:p}),[a,c,h,p]),I=ae!==a,B=T0({count:ae.length,getScrollElement:()=>C.current,estimateSize:()=>18,getItemKey:z=>ae[z]?.id??z,overscan:20}),X=u.useRef(B);X.current=B,u.useLayoutEffect(()=>{const z=A.current;z===null||!C.current||(A.current=null,C.current.scrollTop+=B.getTotalSize()-z)},[a,B]),u.useEffect(()=>{!w&&ae.length>0&&B.scrollToIndex(ae.length-1,{align:"end"})},[ae.length,w,B]);const oe=a.length<i;return t.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1 text-xs text-neutral-500 dark:text-neutral-400 shrink-0",children:[t.jsxs("select",{value:c,onChange:z=>f(z.target.value),className:Pi,"aria-label":"Level",children:[t.jsx("option",{value:"all",children:"All Levels"}),t.jsx("option",{value:"debug",children:"Debug"}),t.jsx("option",{value:"info",children:"Info"}),t.jsx("option",{value:"warn",children:"Warn"}),t.jsx("option",{value:"error",children:"Error"})]}),t.jsxs("select",{value:h,onChange:z=>m(z.target.value),className:`${Pi} max-w-[140px]`,"aria-label":"Origin",children:[t.jsx("option",{value:"all",children:"All Origins"}),ue.map(z=>t.jsx("option",{value:z,children:z},z))]}),t.jsx("input",{value:p,onChange:z=>d(z.target.value),onKeyDown:z=>{z.key==="Escape"&&d("")},placeholder:"Filter…","aria-label":"Filter logs",className:`${Pi} w-40 min-w-0 placeholder:text-[var(--adf-ui-text-subtle)] focus:border-blue-400`}),t.jsxs("button",{onClick:()=>n(!e),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] ${e?bb:Bd}`,title:e?"Live: new entries appear every 2s while the panel is open. Click to pause.":"Paused. Click to follow new entries.","aria-pressed":e,children:[e&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 dark:bg-green-400 animate-pulse"}),"Live"]}),!e&&t.jsx(Vu,{at:y,onRefresh:D}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:W,className:Bd,title:"Clear all logs",children:"Clear"})]}),t.jsx("div",{ref:C,onScroll:K,className:"flex-1 overflow-auto font-mono text-[11px] leading-[18px] px-3 py-1",children:ae.length===0?t.jsx("div",{className:"text-[var(--adf-ui-text-subtle)] py-4 text-center",children:a.length>0&&I?"No entries match":"No log entries"}):t.jsx("div",{style:{height:B.getTotalSize(),position:"relative",width:"100%"},children:B.getVirtualItems().map(z=>{const H=ae[z.index];return t.jsx("div",{"data-index":z.index,ref:B.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${z.start}px)`},children:t.jsx(lE,{entry:H,expanded:b===H.id,onToggle:()=>g(b===H.id?null:H.id)})},z.key)})})}),i>0&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-0.5 text-[10px] text-[var(--adf-ui-text-subtle)] border-t border-neutral-200 dark:border-white/5 shrink-0",children:[t.jsxs("span",{className:"tabular-nums",children:[I?`${ae.length.toLocaleString()} match · `:"",aE(a.length,i)]}),oe&&t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{onClick:U,disabled:k,className:"text-blue-600 dark:text-blue-400 hover:underline disabled:opacity-50 disabled:no-underline",children:k?"Loading…":"Load older"})]})]})]})}function lE({entry:e,expanded:n,onToggle:s}){const a=e.level,r=e.data!==null;return t.jsxs("div",{children:[t.jsxs("div",{onClick:r?s:void 0,className:`flex gap-2 ${r?"cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-900/50":""}`,children:[t.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] shrink-0 select-none",title:new Date(e.created_at).toLocaleString(),children:["[",vb(e.created_at),"]"]}),t.jsx("span",{className:`shrink-0 font-semibold ${rE[a]||"text-neutral-500"}`,children:oE[a]||a.toUpperCase().slice(0,3)}),e.origin&&t.jsx("span",{className:"text-purple-600 dark:text-purple-400 shrink-0",children:e.origin}),e.event&&t.jsx("span",{className:"text-cyan-700 dark:text-cyan-400 shrink-0",children:e.event}),t.jsxs("span",{className:"text-neutral-800 dark:text-neutral-300 min-w-0 break-words",children:[e.origin||e.event?"— ":"",e.message]}),r&&t.jsx("span",{className:"text-[var(--adf-ui-text-subtle)] shrink-0 select-none",children:n?"▼":"▶"})]}),n&&e.data&&t.jsx("pre",{className:"ml-8 my-1 px-2 py-1.5 bg-neutral-50 dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded text-[10px] text-neutral-600 dark:text-neutral-400 overflow-x-auto whitespace-pre-wrap",children:cE(e.data)})]})}function cE(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}const dE={pending:"text-amber-600 dark:text-yellow-400",pending_approval:"text-orange-600 dark:text-orange-400",running:"text-blue-600 dark:text-blue-400",completed:"text-green-600 dark:text-green-400",failed:"text-red-600 dark:text-red-400",denied:"text-red-600 dark:text-red-400",cancelled:"text-neutral-500"};function uE(){const e=de(j=>j.filePath),[n,s]=u.useState([]),[a,r]=u.useState("all"),[o,i]=u.useState(null),[l,c]=u.useState(!1),[f,h]=u.useState(!1),[m,p]=u.useState(null),d=u.useRef(null),b=u.useCallback(()=>{V()?.getTasks(200).then(({tasks:j})=>{s([...j].reverse()),p(Date.now())})},[]);u.useEffect(()=>{s([]),i(null),h(!1),p(null),e&&b()},[e,b]),u.useEffect(()=>{!f&&d.current&&(d.current.scrollTop=d.current.scrollHeight)},[n,f]),qu(b,2e3,{enabled:l,ref:d});const g=u.useCallback(()=>{if(!d.current)return;const{scrollTop:j,scrollHeight:y,clientHeight:S}=d.current;h(y-j-S>40)},[]),w=a==="all"?n:n.filter(j=>j.status===a);return t.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1 text-xs text-neutral-500 dark:text-neutral-400 shrink-0",children:[t.jsxs("select",{value:a,onChange:j=>r(j.target.value),className:Pi,"aria-label":"Status",children:[t.jsx("option",{value:"all",children:"All Statuses"}),_v.map(j=>t.jsx("option",{value:j,children:j.replace("_"," ")},j))]}),t.jsxs("button",{onClick:()=>c(!l),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] ${l?bb:Bd}`,title:l?"Live: refreshes every 2s while the panel is open. Click to pause.":"Paused. Click to refresh every 2s.","aria-pressed":l,children:[l&&t.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 dark:bg-green-400 animate-pulse"}),"Live"]}),!l&&t.jsx(Vu,{at:m,onRefresh:b}),t.jsx("div",{className:"flex-1"}),t.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] text-[10px]",children:[w.length," tasks"]})]}),t.jsx("div",{ref:d,onScroll:g,className:"flex-1 overflow-auto font-mono text-[11px] leading-[18px] px-3 py-1",children:w.length===0?t.jsx("div",{className:"text-[var(--adf-ui-text-subtle)] py-4 text-center",children:"No tasks"}):w.map(j=>t.jsx(fE,{task:j,expanded:o===j.id,onToggle:()=>i(o===j.id?null:j.id)},j.id))})]})}function fE({task:e,expanded:n,onToggle:s}){const a=dE[e.status]||"text-neutral-500",o=e.completed_at&&e.created_at?((e.completed_at-e.created_at)/1e3).toFixed(1)+"s":null;return t.jsxs("div",{children:[t.jsxs("div",{onClick:s,className:"flex gap-2 cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-900/50",children:[t.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] shrink-0 select-none",children:["[",vb(e.created_at),"]"]}),t.jsx("span",{className:`shrink-0 font-semibold uppercase ${a}`,children:e.status.replace("_"," ")}),t.jsx("span",{className:"text-cyan-700 dark:text-cyan-400 shrink-0",children:e.tool}),e.requires_authorization&&t.jsx("span",{className:"text-orange-600 dark:text-orange-400 shrink-0",title:"Requires authorized code to resolve",children:"AUTH"}),e.approval_meta?.protection?.description?t.jsxs("span",{className:"text-neutral-600 dark:text-neutral-400 truncate",title:e.approval_meta.protection.description,children:["— ",e.approval_meta.protection.description]}):e.origin&&t.jsxs("span",{className:"text-neutral-500",children:["— ",e.origin]}),o&&t.jsxs("span",{className:"text-[var(--adf-ui-text-subtle)] shrink-0",children:["(",o,")"]}),t.jsx("span",{className:"text-[var(--adf-ui-text-subtle)] shrink-0 select-none ml-auto",children:n?"▼":"▶"})]}),n&&t.jsx("pre",{className:"ml-8 my-1 px-2 py-1.5 bg-neutral-50 dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded text-[10px] text-neutral-600 dark:text-neutral-400 overflow-x-auto whitespace-pre-wrap",children:hE(e)})]})}function hE(e){const n=[];if(e.approval_meta){const s=e.approval_meta;s.protection?n.push(`Approval: ${s.protection.description??`${s.reason} — ${s.protection.kind} ${s.protection.target} (${s.protection.level})`}`):n.push(`Approval: ${s.reason} tool call`)}if(e.args&&e.args!=="{}"&&n.push(`Args: ${Em(e.args)}`),e.result&&n.push(`Result: ${Em(e.result)}`),e.error&&n.push(`Error: ${e.error}`),e.completed_at&&e.created_at){const s=((e.completed_at-e.created_at)/1e3).toFixed(1);n.push(`Duration: ${s}s`)}return e.requires_authorization&&n.push("Requires Authorization: yes"),n.push(`ID: ${e.id}`),n.join(`
|
|
315
|
-
`)}function Em(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Tm(){const e=F(c=>c.toggleLogsPanel),n=F(c=>c.logsPanelHeight),s=F(c=>c.setLogsPanelHeight),a=F(c=>c.bottomPanelTab),r=F(c=>c.setBottomPanelTab),o=u.useRef(null),i=dl({axis:"y",grow:-1,min:Gb,max:Vb,getStart:()=>n,onDrag:c=>{o.current&&(o.current.style.height=`${c}px`)},onCommit:c=>{s(c),xa(hf,c)}}),l=()=>{s(pf),xa(hf,pf)};return t.jsxs("div",{ref:o,style:{height:n},className:"flex flex-col border-t border-hairline bg-[var(--adf-ui-surface)] shrink-0",children:[t.jsx("div",{onMouseDown:i,onDoubleClick:l,className:"h-1 cursor-row-resize hover:bg-blue-500/40 transition-colors bg-transparent shrink-0"}),t.jsxs("div",{className:"flex items-center gap-0 px-2 bg-neutral-50 dark:bg-neutral-900 border-b border-hairline text-xs shrink-0",children:[t.jsx(Rm,{label:"Logs",active:a==="logs",onClick:()=>r("logs")}),t.jsx(Rm,{label:"Tasks",active:a==="tasks",onClick:()=>r("tasks")}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:e,className:"hover:bg-neutral-200 dark:hover:bg-neutral-800 text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-300 px-1 py-0.5 rounded",title:"Close panel",children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),a==="logs"?t.jsx(iE,{}):t.jsx(uE,{})]})}function Rm({label:e,active:n,onClick:s}){return t.jsx("button",{onClick:s,className:`px-3 py-1.5 font-medium transition-colors ${n?"text-neutral-900 dark:text-neutral-100 border-b-2 border-blue-500":"text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-300 border-b-2 border-transparent"}`,children:e})}function pE(){const e=$c(s=>s.notices),n=$c(s=>s.dismiss);return e.length===0?null:t.jsx("div",{className:"fixed bottom-8 right-3 z-[60] flex flex-col gap-1.5 pointer-events-none",role:"alert","aria-live":"assertive",children:e.map(s=>t.jsxs("div",{className:"pointer-events-auto w-72 flex items-start gap-2 rounded-[var(--adf-ui-container-radius)] border border-[var(--adf-ui-danger)]/40 bg-surface-raised shadow-float px-3 py-2",children:[t.jsx("span",{className:"mt-1 h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--adf-ui-danger)]","aria-hidden":!0}),t.jsx("span",{className:"min-w-0 flex-1 text-[11px] leading-4 text-[var(--adf-ui-text)] [overflow-wrap:anywhere]",children:s.text}),t.jsx("button",{type:"button",onClick:()=>n(s.id),"aria-label":"Dismiss",className:"shrink-0 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 text-xs leading-none",children:"×"})]},s.id))})}function mE(){const e=bf(a=>a.status),n=bf(a=>a.error),{openFile:s}=ms();return t.jsx(xE,{status:e,error:n,onRetry:()=>{ax(s)},onClose:ox})}function xE({status:e,error:n,onRetry:s,onClose:a}){return e==="opening"?t.jsx("div",{className:"h-full w-full flex items-center justify-center",role:"status","aria-label":"Opening the agent",children:t.jsxs("svg",{className:"h-8 w-8 animate-spin text-[var(--adf-ui-text-subtle)]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):t.jsx("div",{className:"h-full w-full flex items-center justify-center p-8",role:"alert",children:t.jsxs("div",{className:"max-w-md flex flex-col items-center gap-4 text-center",children:[t.jsx("p",{className:"text-sm font-medium text-[var(--adf-ui-text)]",children:"The agent did not open."}),n&&t.jsx("p",{className:"text-xs text-[var(--adf-ui-text-muted)] break-words",children:n}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ye,{variant:"primary",onClick:s,children:"Retry"}),t.jsx(ye,{onClick:a,children:"Close window"})]})]})})}const Mi=260,kb=50,gE=2400,Cc=320,bE=()=>Math.max(Mi,Math.round(window.innerWidth*kb/100)),vE=u.lazy(()=>kt(()=>import("./SettingsPage-_uHkBERV.js"),__vite__mapDeps([3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.SettingsPage}))),kE=u.lazy(()=>kt(()=>import("./MeshGraphView-Vp2R5TLK.js"),__vite__mapDeps([14,4,5,15,9,8,10,7,11,12,6,13,16])).then(e=>({default:e.MeshGraphView}))),yE=u.lazy(()=>kt(()=>import("./EditorPanel-5ZGWvexa.js").then(e=>e.K),__vite__mapDeps([17,4,5,13,8,11,10,7,6,15,9,12])).then(e=>({default:e.EditorPanel})));function Pm(){return t.jsx("div",{className:"h-full w-full flex items-center justify-center",children:t.jsxs("svg",{className:"h-8 w-8 animate-spin text-[var(--adf-ui-text-subtle)]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})}function wE(){const e=F(k=>k.rightPanelCollapsed),n=F(k=>k.showSettings)&&!Ve,s=F(k=>k.showMeshGraph)&&!Ve,a=F(k=>k.showHome)&&!Ve,r=de(k=>k.filePath),o=!!r&&!a,[i,l]=u.useState(()=>Qm(Pl,Cc,Mi,gE)),c=u.useRef(null),f=dl({axis:"x",grow:-1,min:Mi,max:bE,getStart:()=>c.current?.getBoundingClientRect().width||i,onDrag:k=>{c.current&&(c.current.style.width=`${k}px`)},onCommit:k=>{l(k),xa(Pl,k)}}),h=u.useCallback(()=>{l(Cc),xa(Pl,Cc)},[]),m=pa(k=>k.setInboxData),p=pa(k=>k.clearMessages),d=pa(k=>k.setOutboxMessages),b=u.useCallback(k=>{k?m(k):p()},[m,p]),g=Ks();u.useEffect(()=>{if(!r)return;const k=V()?.onInboxUpdated?.(v=>{b(v.inbox)});return()=>k?.()},[r,g,b]);const w=u.useCallback(()=>{V()?.getOutbox?.().then(k=>{k?.outbox?.messages&&d(k.outbox.messages)})},[d]);u.useEffect(()=>{if(!r){p();return}V()?.getInbox().then(k=>{b(k?.inbox)}),w()},[r,g,p,b,w]),u.useEffect(()=>{if(!r)return;const k=V()?.onWorkspaceDataChanged?.(({scope:v})=>{v==="inbox"?V()?.getInbox().then(C=>{b(C?.inbox)}):v==="outbox"&&w()});return()=>k?.()},[r,g,b,w]);const j=wt(k=>k.enabled),y=F(k=>k.showLogsPanel);u.useEffect(()=>{const k=()=>{kt(()=>import("./EditorPanel-5ZGWvexa.js").then(N=>N.K),__vite__mapDeps([17,4,5,13,8,11,10,7,6,15,9,12])),kt(()=>import("./MeshGraphView-Vp2R5TLK.js"),__vite__mapDeps([14,4,5,15,9,8,10,7,11,12,6,13,16])),kt(()=>import("./SettingsPage-_uHkBERV.js"),__vite__mapDeps([3,4,5,6,7,8,9,10,11,12,13]))},v=window.requestIdleCallback;if(v){const N=v(k,{timeout:3e3});return()=>window.cancelIdleCallback?.(N)}const C=setTimeout(k,1e3);return()=>clearTimeout(C)},[]);const S=s&&window.adfApi?.platform==="win32";return t.jsxs("div",{className:"h-full flex flex-col",children:[!s&&t.jsx(Ry,{}),!s&&!n&&!a&&t.jsx(XA,{}),!s&&!n&&t.jsx(QA,{}),!s&&!Ve&&t.jsx(JA,{}),!s&&!Ve&&t.jsx(ZA,{}),t.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[!n&&!s&&!Ve&&t.jsx(mv,{children:t.jsx(nw,{})}),t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden",children:[t.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[s?t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-surface-1",children:[t.jsx("div",{className:"flex-1 overflow-hidden",children:t.jsx(u.Suspense,{fallback:t.jsx(Pm,{}),children:t.jsx(kE,{})})}),y&&r&&t.jsx(Tm,{})]}):t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-surface-1",children:[t.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:t.jsx(u.Suspense,{fallback:t.jsx(Pm,{}),children:n?t.jsx(vE,{}):o?t.jsx(yE,{}):Ve?t.jsx(mE,{}):t.jsx(bA,{})})}),y&&o&&!n&&t.jsx(Tm,{})]}),o&&!n&&e&&t.jsx(y4,{reserveWindowControls:S}),o&&!n&&!e&&t.jsxs(t.Fragment,{children:[t.jsx("div",{onMouseDown:f,onDoubleClick:h,className:"shrink-0 w-1 cursor-col-resize hover:bg-blue-300 active:bg-blue-400 transition-colors bg-transparent"}),t.jsx("div",{ref:c,style:{width:i,maxWidth:`max(${Mi}px, ${kb}vw)`},className:"shrink-0 flex flex-col bg-[var(--adf-ui-surface)] border-l border-hairline",children:t.jsx(v4,{reserveWindowControls:S})})]})]}),j&&!n&&!Ve&&t.jsx(Ow,{}),!n&&t.jsx(jw,{})]})]}),!Ve&&t.jsx($k,{}),t.jsx(pE,{}),t.jsx(yA,{}),t.jsx(wA,{}),t.jsx(CA,{}),t.jsx(WA,{}),t.jsx(KA,{}),t.jsx(qA,{}),t.jsx(tE,{})]})}function jE(){const e=Ks();u.useEffect(()=>{if(!(window.adfApi?.platform==="web"||!V()?.onBrowserSession))return V().onBrowserSession(n=>{de.getState().filePath&&V().getAgentConfig().then(s=>{!s||s.id!==n.agentId||ft.getState().openBrowserTab({agentFilePath:n.agentFilePath,containerName:n.containerName,agentId:n.agentId,agentName:n.agentName,hostPort:n.hostPort,phase:"ready"},{activate:!1})}).catch(()=>{})})},[e])}function NE(e){return e.handle??e.filePath.split("/").pop()?.replace(".adf","").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")??"agent"}function yb(e,n){let s=e;for(const a of n){const r=a.payload.filePath;switch(a.type){case"agent_started":{s=[...s.filter(o=>o.filePath!==r),{filePath:r,handle:NE(a.payload),state:a.payload.state??"idle",activeLoops:0}];break}case"agent_stopped":{if(!s.some(o=>o.filePath===r))break;s=s.filter(o=>o.filePath!==r);break}case"agent_state_changed":{const o=a.payload.state;if(!o)break;const i=s.findIndex(l=>l.filePath===r);if(i===-1||s[i].state===o)break;s=[...s],s[i]={...s[i],state:o};break}case"agent_loops_changed":{const o=a.payload.activeLoops??0,i=s.findIndex(l=>l.filePath===r);if(i===-1||s[i].activeLoops===o)break;s=[...s],s[i]={...s[i],activeLoops:o};break}}}return s}function SE(){u.useEffect(()=>window.adfApi?.onBackgroundAgentEvents?(window.adfApi.getBackgroundAgentStatus().then(n=>{ln.getState().setAgents(n.agents);for(const s of n.starting??[])F.getState().addStartingFilePath(s)}),window.adfApi.onBackgroundAgentEvents(n=>{const s=ln.getState().agents,a=yb(s,n),r=F.getState();let o=r.startingFilePaths,i=r.stoppingFilePaths,l=!1,c=!1;const f=m=>{o.has(m)&&(l||(o=new Set(o),l=!0),o.delete(m))},h=m=>{i.has(m)&&(c||(i=new Set(i),c=!0),i.delete(m))};for(const m of n){const p=m.payload.filePath;switch(m.type){case"agent_starting":{if(o.has(p))break;l||(o=new Set(o),l=!0),o.add(p);break}case"agent_start_failed":{f(p);break}case"agent_stopping":{if(i.has(p))break;c||(i=new Set(i),c=!0),i.add(p);break}case"agent_started":{f(p);break}case"agent_stopped":{p!==va()&&!mr.has(p)&&f(p),h(p);break}}}a!==s&&ln.setState({agents:a}),(l||c)&&F.setState({...l?{startingFilePaths:o}:{},...c?{stoppingFilePaths:i}:{}}),rx(a,n,m=>[...mr].some(p=>Kd(p,m)))})):void 0,[])}const _E=.02,Ac=["terrain","burn","model","health","lineage"],kr=Pn(e=>({burn:null,burnBaseline:{},selection:[],family:[],controlGroups:{},namedGroups:{},stewards:{},lens:"terrain",voicesOverride:null,composerOpen:!1,starting:{},peerAgentHover:null,peerReadout:null,readoutDir:null,agentReadout:null,hilModal:null,stationReadout:null,selectedStation:null,hoverDir:null,moveMode:null,cursorCell:null,dragGhost:null,placement:null,setMoveMode:n=>e({moveMode:n}),setCursorCell:n=>e(s=>{const a=s.cursorCell;return a===n||a&&n&&a.q===n.q&&a.r===n.r&&a.agent===n.agent?s:{cursorCell:n}}),setDragGhost:n=>e({dragGhost:n}),setPeerAgentHover:n=>e({peerAgentHover:n}),setPeerReadout:n=>e({peerReadout:n}),setReadoutDir:n=>e({readoutDir:n}),setAgentReadout:n=>e({agentReadout:n}),setHilModal:n=>e({hilModal:n}),setStationReadout:n=>e({stationReadout:n}),setSelectedStation:n=>e({selectedStation:n}),setHoverDir:n=>e({hoverDir:n}),markStarting:n=>e(s=>{const a=Date.now(),r={...s.starting};for(const o of n)r[o]=a;return{starting:r}}),clearStarting:n=>e(s=>{if(n.every(r=>!(r in s.starting)))return s;const a={...s.starting};for(const r of n)delete a[r];return{starting:a}}),setLens:n=>e({lens:n,voicesOverride:null}),cycleLens:()=>e(n=>({lens:Ac[(Ac.indexOf(n.lens)+1)%Ac.length],voicesOverride:null})),setVoicesOverride:n=>e({voicesOverride:n}),setComposerOpen:n=>e({composerOpen:n}),setBurn:n=>e(s=>{const a=JSON.stringify(s.burn)===JSON.stringify(n),r=a?s.burn:n;if(!n?.perAgent)return a?s:{burn:r};let o=null;for(const[i,l]of Object.entries(n.perAgent)){const c=s.burnBaseline[i]??l.tokensPerMin,f=c+_E*(l.tokensPerMin-c);f===c&&i in s.burnBaseline||(o||(o={...s.burnBaseline}),o[i]=f)}return a&&!o?s:{burn:r,...o?{burnBaseline:o}:{}}}),setSelection:n=>e(s=>s.selection.length===n.length&&s.selection.every((a,r)=>a===n[r])?s:{selection:n}),setFamily:n=>e(s=>s.family.length===n.length&&s.family.every((a,r)=>a===n[r])?s:{family:n}),assignControlGroup:(n,s)=>e(a=>({controlGroups:{...a.controlGroups,[n]:s}})),setNamedGroups:n=>e({namedGroups:n}),setStewards:n=>e({stewards:n}),setPlacement:n=>e({placement:n}),pinCell:(n,s)=>e(a=>({placement:{...a.placement??{regionOrigins:{},cellPins:{}},cellPins:{...a.placement?.cellPins??{},[n]:s}}})),updatePlacement:(n,s,a,r)=>e(o=>({placement:{regionOrigins:{...o.placement?.regionOrigins??{},...s??{}},cellPins:{...o.placement?.cellPins??{},...n},districtAnchors:{...o.placement?.districtAnchors??{},...a??{}},stationPins:{...o.placement?.stationPins??{},...r??{}}}})),reset:()=>e({burn:null,burnBaseline:{},selection:[],family:[],controlGroups:{},lens:"terrain",voicesOverride:null,composerOpen:!1,starting:{},moveMode:null,cursorCell:null,dragGhost:null,selectedStation:null})})),Us=`
|
|
315
|
+
`)}function Em(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Tm(){const e=F(c=>c.toggleLogsPanel),n=F(c=>c.logsPanelHeight),s=F(c=>c.setLogsPanelHeight),a=F(c=>c.bottomPanelTab),r=F(c=>c.setBottomPanelTab),o=u.useRef(null),i=dl({axis:"y",grow:-1,min:Gb,max:Vb,getStart:()=>n,onDrag:c=>{o.current&&(o.current.style.height=`${c}px`)},onCommit:c=>{s(c),xa(hf,c)}}),l=()=>{s(pf),xa(hf,pf)};return t.jsxs("div",{ref:o,style:{height:n},className:"flex flex-col border-t border-hairline bg-[var(--adf-ui-surface)] shrink-0",children:[t.jsx("div",{onMouseDown:i,onDoubleClick:l,className:"h-1 cursor-row-resize hover:bg-blue-500/40 transition-colors bg-transparent shrink-0"}),t.jsxs("div",{className:"flex items-center gap-0 px-2 bg-neutral-50 dark:bg-neutral-900 border-b border-hairline text-xs shrink-0",children:[t.jsx(Rm,{label:"Logs",active:a==="logs",onClick:()=>r("logs")}),t.jsx(Rm,{label:"Tasks",active:a==="tasks",onClick:()=>r("tasks")}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:e,className:"hover:bg-neutral-200 dark:hover:bg-neutral-800 text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-300 px-1 py-0.5 rounded",title:"Close panel",children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),a==="logs"?t.jsx(iE,{}):t.jsx(uE,{})]})}function Rm({label:e,active:n,onClick:s}){return t.jsx("button",{onClick:s,className:`px-3 py-1.5 font-medium transition-colors ${n?"text-neutral-900 dark:text-neutral-100 border-b-2 border-blue-500":"text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-300 border-b-2 border-transparent"}`,children:e})}function pE(){const e=$c(s=>s.notices),n=$c(s=>s.dismiss);return e.length===0?null:t.jsx("div",{className:"fixed bottom-8 right-3 z-[60] flex flex-col gap-1.5 pointer-events-none",role:"alert","aria-live":"assertive",children:e.map(s=>t.jsxs("div",{className:"pointer-events-auto w-72 flex items-start gap-2 rounded-[var(--adf-ui-container-radius)] border border-[var(--adf-ui-danger)]/40 bg-surface-raised shadow-float px-3 py-2",children:[t.jsx("span",{className:"mt-1 h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--adf-ui-danger)]","aria-hidden":!0}),t.jsx("span",{className:"min-w-0 flex-1 text-[11px] leading-4 text-[var(--adf-ui-text)] [overflow-wrap:anywhere]",children:s.text}),t.jsx("button",{type:"button",onClick:()=>n(s.id),"aria-label":"Dismiss",className:"shrink-0 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-200 text-xs leading-none",children:"×"})]},s.id))})}function mE(){const e=bf(a=>a.status),n=bf(a=>a.error),{openFile:s}=ms();return t.jsx(xE,{status:e,error:n,onRetry:()=>{ax(s)},onClose:ox})}function xE({status:e,error:n,onRetry:s,onClose:a}){return e==="opening"?t.jsx("div",{className:"h-full w-full flex items-center justify-center",role:"status","aria-label":"Opening the agent",children:t.jsxs("svg",{className:"h-8 w-8 animate-spin text-[var(--adf-ui-text-subtle)]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):t.jsx("div",{className:"h-full w-full flex items-center justify-center p-8",role:"alert",children:t.jsxs("div",{className:"max-w-md flex flex-col items-center gap-4 text-center",children:[t.jsx("p",{className:"text-sm font-medium text-[var(--adf-ui-text)]",children:"The agent did not open."}),n&&t.jsx("p",{className:"text-xs text-[var(--adf-ui-text-muted)] break-words",children:n}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ye,{variant:"primary",onClick:s,children:"Retry"}),t.jsx(ye,{onClick:a,children:"Close window"})]})]})})}const Mi=260,kb=50,gE=2400,Cc=320,bE=()=>Math.max(Mi,Math.round(window.innerWidth*kb/100)),vE=u.lazy(()=>kt(()=>import("./SettingsPage-BTu2-Yon.js"),__vite__mapDeps([3,4,5,6,7,8,9,10,11,12,13])).then(e=>({default:e.SettingsPage}))),kE=u.lazy(()=>kt(()=>import("./MeshGraphView-ChgwUT3O.js"),__vite__mapDeps([14,4,5,15,9,8,10,7,11,12,6,13,16])).then(e=>({default:e.MeshGraphView}))),yE=u.lazy(()=>kt(()=>import("./EditorPanel-YXnanvaL.js").then(e=>e.K),__vite__mapDeps([17,4,5,13,8,11,10,7,6,15,9,12])).then(e=>({default:e.EditorPanel})));function Pm(){return t.jsx("div",{className:"h-full w-full flex items-center justify-center",children:t.jsxs("svg",{className:"h-8 w-8 animate-spin text-[var(--adf-ui-text-subtle)]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true",children:[t.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),t.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})}function wE(){const e=F(k=>k.rightPanelCollapsed),n=F(k=>k.showSettings)&&!Ve,s=F(k=>k.showMeshGraph)&&!Ve,a=F(k=>k.showHome)&&!Ve,r=de(k=>k.filePath),o=!!r&&!a,[i,l]=u.useState(()=>Qm(Pl,Cc,Mi,gE)),c=u.useRef(null),f=dl({axis:"x",grow:-1,min:Mi,max:bE,getStart:()=>c.current?.getBoundingClientRect().width||i,onDrag:k=>{c.current&&(c.current.style.width=`${k}px`)},onCommit:k=>{l(k),xa(Pl,k)}}),h=u.useCallback(()=>{l(Cc),xa(Pl,Cc)},[]),m=pa(k=>k.setInboxData),p=pa(k=>k.clearMessages),d=pa(k=>k.setOutboxMessages),b=u.useCallback(k=>{k?m(k):p()},[m,p]),g=Ks();u.useEffect(()=>{if(!r)return;const k=V()?.onInboxUpdated?.(v=>{b(v.inbox)});return()=>k?.()},[r,g,b]);const w=u.useCallback(()=>{V()?.getOutbox?.().then(k=>{k?.outbox?.messages&&d(k.outbox.messages)})},[d]);u.useEffect(()=>{if(!r){p();return}V()?.getInbox().then(k=>{b(k?.inbox)}),w()},[r,g,p,b,w]),u.useEffect(()=>{if(!r)return;const k=V()?.onWorkspaceDataChanged?.(({scope:v})=>{v==="inbox"?V()?.getInbox().then(C=>{b(C?.inbox)}):v==="outbox"&&w()});return()=>k?.()},[r,g,b,w]);const j=wt(k=>k.enabled),y=F(k=>k.showLogsPanel);u.useEffect(()=>{const k=()=>{kt(()=>import("./EditorPanel-YXnanvaL.js").then(N=>N.K),__vite__mapDeps([17,4,5,13,8,11,10,7,6,15,9,12])),kt(()=>import("./MeshGraphView-ChgwUT3O.js"),__vite__mapDeps([14,4,5,15,9,8,10,7,11,12,6,13,16])),kt(()=>import("./SettingsPage-BTu2-Yon.js"),__vite__mapDeps([3,4,5,6,7,8,9,10,11,12,13]))},v=window.requestIdleCallback;if(v){const N=v(k,{timeout:3e3});return()=>window.cancelIdleCallback?.(N)}const C=setTimeout(k,1e3);return()=>clearTimeout(C)},[]);const S=s&&window.adfApi?.platform==="win32";return t.jsxs("div",{className:"h-full flex flex-col",children:[!s&&t.jsx(Ry,{}),!s&&!n&&!a&&t.jsx(XA,{}),!s&&!n&&t.jsx(QA,{}),!s&&!Ve&&t.jsx(JA,{}),!s&&!Ve&&t.jsx(ZA,{}),t.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[!n&&!s&&!Ve&&t.jsx(mv,{children:t.jsx(nw,{})}),t.jsxs("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden",children:[t.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[s?t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-surface-1",children:[t.jsx("div",{className:"flex-1 overflow-hidden",children:t.jsx(u.Suspense,{fallback:t.jsx(Pm,{}),children:t.jsx(kE,{})})}),y&&r&&t.jsx(Tm,{})]}):t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-surface-1",children:[t.jsx("div",{className:"flex-1 flex flex-col overflow-hidden",children:t.jsx(u.Suspense,{fallback:t.jsx(Pm,{}),children:n?t.jsx(vE,{}):o?t.jsx(yE,{}):Ve?t.jsx(mE,{}):t.jsx(bA,{})})}),y&&o&&!n&&t.jsx(Tm,{})]}),o&&!n&&e&&t.jsx(y4,{reserveWindowControls:S}),o&&!n&&!e&&t.jsxs(t.Fragment,{children:[t.jsx("div",{onMouseDown:f,onDoubleClick:h,className:"shrink-0 w-1 cursor-col-resize hover:bg-blue-300 active:bg-blue-400 transition-colors bg-transparent"}),t.jsx("div",{ref:c,style:{width:i,maxWidth:`max(${Mi}px, ${kb}vw)`},className:"shrink-0 flex flex-col bg-[var(--adf-ui-surface)] border-l border-hairline",children:t.jsx(v4,{reserveWindowControls:S})})]})]}),j&&!n&&!Ve&&t.jsx(Ow,{}),!n&&t.jsx(jw,{})]})]}),!Ve&&t.jsx($k,{}),t.jsx(pE,{}),t.jsx(yA,{}),t.jsx(wA,{}),t.jsx(CA,{}),t.jsx(WA,{}),t.jsx(KA,{}),t.jsx(qA,{}),t.jsx(tE,{})]})}function jE(){const e=Ks();u.useEffect(()=>{if(!(window.adfApi?.platform==="web"||!V()?.onBrowserSession))return V().onBrowserSession(n=>{de.getState().filePath&&V().getAgentConfig().then(s=>{!s||s.id!==n.agentId||ft.getState().openBrowserTab({agentFilePath:n.agentFilePath,containerName:n.containerName,agentId:n.agentId,agentName:n.agentName,hostPort:n.hostPort,phase:"ready"},{activate:!1})}).catch(()=>{})})},[e])}function NE(e){return e.handle??e.filePath.split("/").pop()?.replace(".adf","").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")??"agent"}function yb(e,n){let s=e;for(const a of n){const r=a.payload.filePath;switch(a.type){case"agent_started":{s=[...s.filter(o=>o.filePath!==r),{filePath:r,handle:NE(a.payload),state:a.payload.state??"idle",activeLoops:0}];break}case"agent_stopped":{if(!s.some(o=>o.filePath===r))break;s=s.filter(o=>o.filePath!==r);break}case"agent_state_changed":{const o=a.payload.state;if(!o)break;const i=s.findIndex(l=>l.filePath===r);if(i===-1||s[i].state===o)break;s=[...s],s[i]={...s[i],state:o};break}case"agent_loops_changed":{const o=a.payload.activeLoops??0,i=s.findIndex(l=>l.filePath===r);if(i===-1||s[i].activeLoops===o)break;s=[...s],s[i]={...s[i],activeLoops:o};break}}}return s}function SE(){u.useEffect(()=>window.adfApi?.onBackgroundAgentEvents?(window.adfApi.getBackgroundAgentStatus().then(n=>{ln.getState().setAgents(n.agents);for(const s of n.starting??[])F.getState().addStartingFilePath(s)}),window.adfApi.onBackgroundAgentEvents(n=>{const s=ln.getState().agents,a=yb(s,n),r=F.getState();let o=r.startingFilePaths,i=r.stoppingFilePaths,l=!1,c=!1;const f=m=>{o.has(m)&&(l||(o=new Set(o),l=!0),o.delete(m))},h=m=>{i.has(m)&&(c||(i=new Set(i),c=!0),i.delete(m))};for(const m of n){const p=m.payload.filePath;switch(m.type){case"agent_starting":{if(o.has(p))break;l||(o=new Set(o),l=!0),o.add(p);break}case"agent_start_failed":{f(p);break}case"agent_stopping":{if(i.has(p))break;c||(i=new Set(i),c=!0),i.add(p);break}case"agent_started":{f(p);break}case"agent_stopped":{p!==va()&&!mr.has(p)&&f(p),h(p);break}}}a!==s&&ln.setState({agents:a}),(l||c)&&F.setState({...l?{startingFilePaths:o}:{},...c?{stoppingFilePaths:i}:{}}),rx(a,n,m=>[...mr].some(p=>Kd(p,m)))})):void 0,[])}const _E=.02,Ac=["terrain","burn","model","health","lineage"],kr=Pn(e=>({burn:null,burnBaseline:{},selection:[],family:[],controlGroups:{},namedGroups:{},stewards:{},lens:"terrain",voicesOverride:null,composerOpen:!1,starting:{},peerAgentHover:null,peerReadout:null,readoutDir:null,agentReadout:null,hilModal:null,stationReadout:null,selectedStation:null,hoverDir:null,moveMode:null,cursorCell:null,dragGhost:null,placement:null,setMoveMode:n=>e({moveMode:n}),setCursorCell:n=>e(s=>{const a=s.cursorCell;return a===n||a&&n&&a.q===n.q&&a.r===n.r&&a.agent===n.agent?s:{cursorCell:n}}),setDragGhost:n=>e({dragGhost:n}),setPeerAgentHover:n=>e({peerAgentHover:n}),setPeerReadout:n=>e({peerReadout:n}),setReadoutDir:n=>e({readoutDir:n}),setAgentReadout:n=>e({agentReadout:n}),setHilModal:n=>e({hilModal:n}),setStationReadout:n=>e({stationReadout:n}),setSelectedStation:n=>e({selectedStation:n}),setHoverDir:n=>e({hoverDir:n}),markStarting:n=>e(s=>{const a=Date.now(),r={...s.starting};for(const o of n)r[o]=a;return{starting:r}}),clearStarting:n=>e(s=>{if(n.every(r=>!(r in s.starting)))return s;const a={...s.starting};for(const r of n)delete a[r];return{starting:a}}),setLens:n=>e({lens:n,voicesOverride:null}),cycleLens:()=>e(n=>({lens:Ac[(Ac.indexOf(n.lens)+1)%Ac.length],voicesOverride:null})),setVoicesOverride:n=>e({voicesOverride:n}),setComposerOpen:n=>e({composerOpen:n}),setBurn:n=>e(s=>{const a=JSON.stringify(s.burn)===JSON.stringify(n),r=a?s.burn:n;if(!n?.perAgent)return a?s:{burn:r};let o=null;for(const[i,l]of Object.entries(n.perAgent)){const c=s.burnBaseline[i]??l.tokensPerMin,f=c+_E*(l.tokensPerMin-c);f===c&&i in s.burnBaseline||(o||(o={...s.burnBaseline}),o[i]=f)}return a&&!o?s:{burn:r,...o?{burnBaseline:o}:{}}}),setSelection:n=>e(s=>s.selection.length===n.length&&s.selection.every((a,r)=>a===n[r])?s:{selection:n}),setFamily:n=>e(s=>s.family.length===n.length&&s.family.every((a,r)=>a===n[r])?s:{family:n}),assignControlGroup:(n,s)=>e(a=>({controlGroups:{...a.controlGroups,[n]:s}})),setNamedGroups:n=>e({namedGroups:n}),setStewards:n=>e({stewards:n}),setPlacement:n=>e({placement:n}),pinCell:(n,s)=>e(a=>({placement:{...a.placement??{regionOrigins:{},cellPins:{}},cellPins:{...a.placement?.cellPins??{},[n]:s}}})),updatePlacement:(n,s,a,r)=>e(o=>({placement:{regionOrigins:{...o.placement?.regionOrigins??{},...s??{}},cellPins:{...o.placement?.cellPins??{},...n},districtAnchors:{...o.placement?.districtAnchors??{},...a??{}},stationPins:{...o.placement?.stationPins??{},...r??{}}}})),reset:()=>e({burn:null,burnBaseline:{},selection:[],family:[],controlGroups:{},lens:"terrain",voicesOverride:null,composerOpen:!1,starting:{},moveMode:null,cursorCell:null,dragGhost:null,selectedStation:null})})),Us=`
|
|
316
316
|
`;function wb(e){return`${e}${Us}`}function $6(e){return e.endsWith(Us)&&e.indexOf(Us)===e.length-1?e.slice(0,-1):null}const jb=new Map;function O6(e){return jb.get(e)??""}const Nb=e=>!e.includes("/")&&e.includes("\\")?"\\":"/";function CE(e,n){if(!n)return"";const s=Nb(e),a=n.split(/[\\/]/).filter(Boolean).pop()??n,r=e.lastIndexOf(s),o=r>0?e.slice(0,r):"";return o===n?a:o.startsWith(n+s)?`${a}/${o.slice(n.length+1).split(/[\\/]/).join("/")}`:a}function D6(e){const{runtimeId:n,filePath:s}=ll(e),a=s.lastIndexOf(Nb(s));return fn({runtimeId:n,filePath:a>0?s.slice(0,a):s})}const Mm=new WeakMap;function AE(e,n){const s=Mm.get(n);if(s&&s.runtimeId===e)return s.agent;const a=fn({runtimeId:e,filePath:n.filePath}),r=CE(n.filePath,n.trackedDirRoot);jb.set(a,r);const o={...n,filePath:a,trackedDirRoot:wb(e),district:r,...n.trackedDirRoot?{sourceRoot:n.trackedDirRoot}:{}};return Mm.set(n,{runtimeId:e,agent:o}),o}function EE(e,n){if(n.length===0)return e;const s=[...e];for(const{runtimeId:a,agents:r}of n)for(const o of r)s.push(AE(a,o));return s}let Im=null,Lm=null,Ec=[];function TE(e){const n=Object.keys(e.byRuntime);return n.length===0?e.agents:(e.agents===Im&&e.byRuntime===Lm||(Im=e.agents,Lm=e.byRuntime,Ec=EE(e.agents,n.map(s=>({runtimeId:s,agents:za(e,s).agents})))),Ec)}function RE(e){if(!nx(e))return{runtimeId:ze,filePath:e,api:window.adfApi};const{runtimeId:n,filePath:s}=ll(e);return{runtimeId:n,filePath:s,api:st(n)}}function $m(e){return va()===e}async function F6(e){const n=RE(e),s=$m(e),a=de.getState().viewGeneration;if(!(s?await n.api.stopAgent():await n.api.stopBackgroundAgent(n.filePath)).success)throw new Error("Agent did not stop");s&&$m(e)&&de.getState().viewGeneration===a&&Z.getState().setState("off")}function PE(e){const n=new Map;for(const s of e){const{runtimeId:a,filePath:r}=nx(s)?ll(s):{runtimeId:ze,filePath:s},o=n.get(a)??[];o.push(r),n.set(a,o)}return n}function ME(e,n){const s={};for(const[a,r]of Object.entries(n?.perAgent??{}))s[fn({runtimeId:e,filePath:a})]=r;return s}function B6(e,n){if(n.length===0)return e;const s={...e?.fleet??{tokensPerMin:0,inPerMin:0,outPerMin:0,totalTokens:0}},a={...e?.perAgent??{}};for(const{runtimeId:r,burn:o}of n)o&&(Object.assign(a,ME(r,o)),s.tokensPerMin+=o.fleet.tokensPerMin,s.inPerMin+=o.fleet.inPerMin,s.outPerMin+=o.fleet.outPerMin,s.totalTokens+=o.fleet.totalTokens);return{perAgent:a,fleet:s}}function Sb(e){return e&&e.trim().toLowerCase().replace(/^\[|\]$/g,"")||null}function IE(e){if(!e)return null;try{return Sb(new URL(e).hostname)}catch{return null}}function LE(e){return[IE(e.url),Sb(typeof e.host=="string"?e.host:null)].filter(n=>!!n)}function $E(e,n){const s=LE(e),a=r=>{const o=n.hosts?.[r];return!!o&&s.some(i=>o.includes(i))};if(e.runtime_did){for(const[r,o]of Object.entries(n.dids))if(o&&o===e.runtime_did&&a(r))return r}if(e.fingerprint){const r=n.remotes.find(o=>o.fingerprint&&o.fingerprint===e.fingerprint&&a(o.id));if(r)return r.id}return null}function OE(e,n){return!e.agents||!e.agents.some(s=>s.did&&n.has(s.did))?e:{...e,agents:e.agents.filter(s=>!(s.did&&n.has(s.did)))}}function z6(e,n,s){const a=new Map;for(const i of e)for(const l of i){if(a.has(l.runtime_id))continue;const c=$E(l,n);c&&a.set(l.runtime_id,c)}for(const[i,l]of a)s?.(i,l);const r=new Set,o=[];for(const i of e)for(const l of i)a.has(l.runtime_id)||r.has(l.runtime_id)||(r.add(l.runtime_id),o.push(OE(l,n.agentDids)));return o}function W6(e){const n=new Map;for(const s of e)s.did&&n.set(s.did,lf(s.filePath)??ze);return n}const bi="station:peer:";let xo={};function H6(e){xo=e}const zd=new Set;function U6(e){return zd.add(e),()=>{zd.delete(e)}}function DE(e){const n=new Set(e);if(n.size!==0){for(const s of zd){for(const a of n)delete s.dids[a],delete s.seq[a],delete s.errors[a],s.didRetry&&delete s.didRetry[a];if(s.learned)for(const[a,r]of Object.entries(s.learned))n.has(r)&&delete s.learned[a]}Object.values(xo).some(s=>n.has(s))&&(xo=Object.fromEntries(Object.entries(xo).filter(([,s])=>!n.has(s))))}}const Om=new WeakMap;function FE(e,n){let s=Om.get(e);if(!s){s=new Map;for(const a of e)a.did&&s.set(a.did,a.filePath);for(const a of e)a.handle&&!s.has(a.handle)&&s.set(a.handle,a.filePath);Om.set(e,s)}return s.get(n)??null}function Dm(e,n,s){const a=xo[e];if(!a||!n)return null;const r=FE(s(a),n);return r===null?null:fn({runtimeId:a,filePath:r})}const Fm=15e3,Tc=new Map;function Bm(e,n,s){const a=Tc.get(e)??{out:[],in:[]};a.out=a.out.filter(i=>s-i<Fm),a.in=a.in.filter(i=>s-i<Fm);const r=n==="out"?a.in:a.out,o=r.length>0;return o?r.shift():a[n].push(s),a.out.length===0&&a.in.length===0?Tc.delete(e):Tc.set(e,a),o}function K6(e,n,s=Date.now()){if(e.type!=="message_routed")return e;const a=e.payload,r=a.toFilePaths??[];if(r.length===1&&r[0].startsWith(bi)&&a.toPeerAgent){const o=Dm(r[0].slice(bi.length),a.toPeerAgent.id,n);if(!o||o===a.filePath)return e;if(Bm(`${a.filePath}|${o}`,"out",s))return null;const{toPeerAgent:i,...l}=a;return{...e,payload:{...l,toFilePaths:[o]}}}if(typeof a.filePath=="string"&&a.filePath.startsWith(bi)&&a.fromPeerAgent&&r.length===1){const o=Dm(a.filePath.slice(bi.length),a.fromPeerAgent.id,n);if(!o||o===r[0])return e;if(Bm(`${o}|${r[0]}`,"in",s))return null;const{fromPeerAgent:i,...l}=a;return{...e,payload:{...l,filePath:o}}}return e}let Yn={};function BE(e){Yn=e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function zE(e){if(!(e in Yn))return;const{[e]:n,...s}=Yn;Yn=s}function WE(e,n){if(!(e in Yn))return;const{[e]:s,...a}=Yn;Yn=n in a?a:{...a,[n]:s}}async function HE(e,n=window.adfApi){let s;try{s=await n.getSettings()}catch(f){console.warn("[Mesh] runtimeFleet was not read again after the runtime set changed:",f);return}BE(s?.runtimeFleet);const a=kr.getState();if(!a.placement)return;const r=a.placement,o=f=>{const h=wb(f);return[...Object.values(a.namedGroups).flat(),...Object.keys(a.stewards),...Object.keys(r.regionOrigins),...Object.keys(r.cellPins),...Object.keys(r.districtAnchors??{})].some(p=>p.startsWith(h))},i=Eb(e).filter(f=>Yn[f]&&!o(f));if(i.length===0)return;const l=Object.fromEntries(i.map(f=>[f,Yn[f]])),c=f=>Object.assign({},...i.map(h=>Ab(h,l[h]?.fleetMapState?.placement?.[f])));console.log(`[Mesh] Saved groups, stewards and placement of ${i.join(", ")} added to the map`),kr.setState({namedGroups:qE(a.namedGroups,l),stewards:VE(a.stewards,l),placement:{...r,regionOrigins:{...r.regionOrigins,...c("regionOrigins")},cellPins:{...r.cellPins,...c("cellPins")},districtAnchors:{...r.districtAnchors??{},...c("districtAnchors")}}})}function lf(e){const n=e.indexOf(Us);return n<0?null:e.slice(0,n)}const _b=e=>e.slice(e.indexOf(Us)+1),Cb=(e,n)=>`${e}${Us}${n}`;function UE(e){if(!Object.keys(e).some(a=>a.includes(Us)))return{local:e,remote:{}};const n={},s={};for(const[a,r]of Object.entries(e)){const o=lf(a);o===null?n[a]=r:(s[o]??={})[_b(a)]=r}return{local:n,remote:s}}function Ab(e,n){const s={};for(const[a,r]of Object.entries(n??{}))s[Cb(e,a)]=r;return s}function KE(e){if(!Object.values(e).some(a=>a.some(r=>r.includes(Us))))return{local:e,remote:{}};const n={},s={};for(const[a,r]of Object.entries(e)){const o=r.filter(i=>!i.includes(Us));(o.length>0||r.length===0)&&(n[a]=o);for(const i of r){const l=lf(i);l!==null&&((s[l]??={})[a]??=[]).push(_b(i))}}return{local:n,remote:s}}function qE(e,n){const s=Object.keys(n).filter(r=>n[r]?.fleetGroups&&Object.keys(n[r].fleetGroups).length>0);if(s.length===0)return e;const a={};for(const[r,o]of Object.entries(e))a[r]=[...o];for(const r of s)for(const[o,i]of Object.entries(n[r].fleetGroups))a[o]=[...a[o]??[],...i.map(l=>Cb(r,l))];return a}function VE(e,n){let s=e;for(const[a,r]of Object.entries(n))!r?.fleetStewards||Object.keys(r.fleetStewards).length===0||(s={...s,...Ab(a,r.fleetStewards)});return s}function Eb(e){return e.length>1?e.filter(n=>n.id!==ze).map(n=>n.id):[]}function GE(e,n,s){const a=Eb(s);if(a.length===0)return e;const r=Object.keys(e),o={};for(const i of a){const l={};for(const c of r){const f=n[i]?.[c];f!==void 0?l[c]=f:(c==="fleetGroups"||c==="fleetStewards")&&(l[c]={})}Object.keys(l).length!==0&&(o[i]=l,Yn={...Yn,[i]:{...Yn[i]??{},...l}})}return Object.keys(o).length>0?{...e,runtimeFleet:o}:e}function q6(e,n){const s={},a={};if(e.groups){const{local:r,remote:o}=KE(e.groups);s.fleetGroups=r;for(const[i,l]of Object.entries(o))(a[i]??={}).fleetGroups=l}if(e.stewards){const{local:r,remote:o}=UE(e.stewards);s.fleetStewards=r;for(const[i,l]of Object.entries(o))(a[i]??={}).fleetStewards=l}return window.adfApi.setSettings(GE(s,a,n))}async function V6(e,n){const s=PE(e);if(s.size===1&&s.has(ze))return window.adfApi.messageFleetAgents(e,n);const a={delivered:[],failed:[]},r=(o,i)=>fn({runtimeId:o,filePath:i});return await Promise.all([...s].map(async([o,i])=>{try{const l=await st(o).messageFleetAgents(i,n);a.delivered.push(...l.delivered.map(c=>r(o,c))),a.failed.push(...l.failed.map(c=>({...c,filePath:r(o,c.filePath)})))}catch(l){Yt(`${Po(o)}: message not sent`,l);const c=l instanceof Error?l.message:String(l);a.failed.push(...i.map(f=>({filePath:r(o,f),error:c})))}})),a}const Jr=new Map,ao=new Map;let vi="";function YE(e){return(n,s)=>e(n,s,{kept:!0})}function ki(e){console.log(`[Runtimes] ${e}`),$c.getState().push(e)}function XE(e,n){const s=ln.getState(),a=Oa(s,e),r=yb(a,n);r!==a&&s.setAgents(r,e);const o=F.getState(),i=f=>fn({runtimeId:e,filePath:f});for(const f of n){const h=i(f.payload.filePath);switch(f.type){case"agent_starting":o.addStartingFilePath(h);break;case"agent_start_failed":case"agent_started":o.removeStartingFilePath(h);break;case"agent_stopping":o.addStoppingFilePath(h);break;case"agent_stopped":h!==va()&&!mr.has(h)&&o.removeStartingFilePath(h),o.removeStoppingFilePath(h);break}}const l=r.map(f=>({...f,filePath:i(f.filePath)})),c=n.map(f=>({...f,payload:{...f.payload,filePath:i(f.payload.filePath)}}));rx(l,c,f=>mr.has(f))}function JE(e,n,s){const a=wt.getState();switch(n.type){case"agent_state_changed":n.payload.state&&a.updateAgentState(n.payload.filePath,n.payload.state,e);break;case"agent_joined":s();break;case"agent_left":a.markAgentOffline(n.payload.filePath,e),s();break}}function QE(e){const n=e.id,s=st(n);ha(n).loadDirectories().catch(a=>Yt(`${e.name}: tracked folders not loaded`,a)),s.getBackgroundAgentStatus().then(a=>{ln.getState().setAgents(a.agents,n);for(const r of a.starting??[])F.getState().addStartingFilePath(fn({runtimeId:n,filePath:r}))}).catch(a=>Yt(`${e.name}: running agents not loaded`,a)),Tb(n,e.name)}function Tb(e,n){const s=za(wt.getState(),e).enabledRev;st(e).getMeshStatus().then(a=>{wt.getState().upsertAgents(a.agents??[],e),wt.getState().syncEnabled(a.running===!0,s,e)}).catch(a=>console.warn(`[Runtimes] ${n}: the mesh status was not read:`,a))}function ZE(e){const n=e.id,s=st(n),{onChanged:a}=ha(n);let r=null;const o=()=>{r&&clearTimeout(r),r=setTimeout(()=>{r=null,Tb(n,e.name)},250)};return[s.onTrackedDirsChanged(({dirPath:i})=>{a(i).catch(l=>Yt(`${e.name}: ${i} not rescanned`,l))}),s.onBackgroundAgentEvents(i=>XE(n,i)),s.onMeshEvent(i=>JE(n,i,o)),s.onFileRenamed(({oldPath:i,newPath:l})=>{const c=de.getState();c.runtimeId===n&&c.filePath===i&&c.setFilePath(l),us.getState().rekey(fn({runtimeId:n,filePath:i}),fn({runtimeId:n,filePath:l}))}),()=>{r&&clearTimeout(r)}]}function Rb(){de.getState().reset(),Z.getState().reset(),F.getState().resetAgentReview(),ft.getState().reset()}function eT(e){const n=c=>ll(c).runtimeId===e,s=us.getState().queues;let a=0;for(const[c,f]of Object.entries(s))if(n(c))for(const h of Object.values(f))a+=h.length;Object.keys(s).some(n)&&us.setState({queues:Object.fromEntries(Object.entries(s).filter(([c])=>!n(c)))});const r=de.getState().draftInputs;Object.keys(r).some(n)&&de.setState({draftInputs:Object.fromEntries(Object.entries(r).filter(([c])=>!n(c)))});const o=F.getState();([...o.startingFilePaths].some(n)||[...o.stoppingFilePaths].some(n))&&F.setState({startingFilePaths:new Set([...o.startingFilePaths].filter(c=>!n(c))),stoppingFilePaths:new Set([...o.stoppingFilePaths].filter(c=>!n(c)))});const i=kr.getState(),l=Object.entries(i.controlGroups);return(i.selection.some(n)||i.family.some(n)||Object.keys(i.starting).some(n)||l.some(([,c])=>c.some(n)))&&kr.setState({selection:i.selection.filter(c=>!n(c)),family:i.family.filter(c=>!n(c)),starting:Object.fromEntries(Object.entries(i.starting).filter(([c])=>!n(c))),controlGroups:Object.fromEntries(l.map(([c,f])=>[c,f.filter(h=>!n(h))]))}),a}function Pb(e){E5(e),m5(e),cr.getState().dropRuntime(e)}function tT(e,n){const s=`${e}
|
|
317
317
|
`,a=p=>p.startsWith(s),r=p=>a(p)?`${n}
|
|
318
318
|
${p.slice(s.length)}`:p;function o(p){if(!Object.keys(p).some(a))return p;const d={};for(const[b,g]of Object.entries(p))a(b)||(d[b]=g);for(const[b,g]of Object.entries(p))a(b)&&!(r(b)in d)&&(d[r(b)]=g);return d}const i=p=>p.some(a)?[...new Set(p.map(r))]:p,l=us.getState().queues;Object.keys(l).some(a)&&us.setState({queues:o(l)});const c=de.getState().draftInputs;Object.keys(c).some(a)&&de.setState({draftInputs:o(c)});const f=F.getState();([...f.startingFilePaths].some(a)||[...f.stoppingFilePaths].some(a))&&F.setState({startingFilePaths:new Set(i([...f.startingFilePaths])),stoppingFilePaths:new Set(i([...f.stoppingFilePaths]))});const h=kr.getState(),m=h.placement;kr.setState({selection:i(h.selection),family:i(h.family),starting:o(h.starting),controlGroups:Object.fromEntries(Object.entries(h.controlGroups).map(([p,d])=>[p,i(d)])),namedGroups:Object.fromEntries(Object.entries(h.namedGroups).map(([p,d])=>[p,i(d)])),stewards:o(h.stewards),...m?{placement:{...m,regionOrigins:o(m.regionOrigins),cellPins:o(m.cellPins),...m.districtAnchors?{districtAnchors:o(m.districtAnchors)}:{},...m.stationPins?{stationPins:o(m.stationPins)}:{}}}:{}}),WE(e,n)}async function zm(e,n){const{filePath:s,runtimeId:a}=de.getState();if(!s||a!==e.id)return null;let r=null;try{r=(await st(e.id).getCurrentFile())?.filePath??null}catch(m){console.warn(`[Runtimes] ${e.name}: its open file was not read:`,m)}const o=de.getState();if(r===s||o.filePath!==s||o.runtimeId!==e.id)return null;console.log(`[Runtimes] ${e.id} connected without ${s} open: opening it again`);const i=Z.getState().config?.name||qs(s),c=await Ii().catch(()=>0)>0?"; unsaved changes kept for recovery":"";let f=!1;if(n){const m=await n(s,e.id).catch(d=>({success:!1,error:d}));if(m?.overtaken)return console.log(`[Runtimes] The reopen of ${s} on ${e.id} was overtaken by a later open`),null;const p=de.getState();f=m?.success===!0&&p.filePath===s&&p.runtimeId===e.id}if(f)return{said:`${i} reopened${c}`};const h=de.getState();return h.filePath===s&&h.runtimeId===e.id&&Rb(),{said:`${i} closed${c}`}}async function nT(e,n){console.log(`[Runtimes] ${e} left the set: closing its open agent ${n}`);const s=`${Z.getState().config?.name||qs(n)} closed`,a=await Ii().catch(()=>0),r=de.getState();return r.runtimeId===e&&r.filePath===n&&Rb(),{closed:s,kept:a>0}}function sT(e){const n=[];for(const[s,a]of Object.entries(e.moves??{}))s&&a&&s!==a&&(ao.set(s,a),n.push(s));for(const s of e.replaced??[])console.log(`[Runtimes] ${s} is another computer now: its cached settings, model lists, templates and fleet map matches go`),Pb(s),n.push(s);DE(n)}function Rc(e,n=null){const s=e.length>1?e.filter(o=>o.id!==ze):[],a=[];for(const[o,i]of[...Jr]){if(s.some(p=>p.id===o))continue;for(const p of i.unsubscribe)p();if(Jr.delete(o),tn.getState().dropRuntime(o),ln.getState().dropRuntime(o),wt.getState().dropRuntime(o),Pb(o),e.length===0)continue;const l=ao.get(o);ao.delete(o);const c=l?s.find(p=>p.id===l):void 0;if(c){console.log(`[Runtimes] ${o} is ${c.id} now: its agents' queues, drafts, marks and fleet keys follow`),tT(o,c.id);const p=de.getState();p.runtimeId===o&&p.filePath?(de.setState({runtimeId:c.id}),a.push({from:i.name,to:c.id})):ki(`${i.name} is now ${c.name}.`);continue}const f=de.getState(),h=f.runtimeId===o&&f.filePath?nT(o,f.filePath):Promise.resolve(null),m=eT(o);zE(o),h.catch(()=>null).then(p=>{const d=[];p&&d.push(p.closed),m>0&&d.push(`${m} queued message${m===1?"":"s"} discarded`),p?.kept&&d.push("unsaved changes kept for recovery"),d.length>0&&ki(`${i.name} removed; ${d.join("; ")}.`)})}for(const o of[...ao.keys()])!Jr.has(o)&&!s.some(i=>i.id===o)&&ao.delete(o);for(const o of s){let i=Jr.get(o.id);i||(i={state:null,name:o.name,unsubscribe:ZE(o)},Jr.set(o.id,i)),i.name=o.name;const l=i.state;i.state=o.state;const c=a.find(f=>f.to===o.id);o.state==="connected"&&l!=="connected"&&(QE(o),c||zm(o,n).then(f=>{f&&ki(`${o.name} reconnected; ${f.said}.`)})),c&&(o.state==="connected"?zm(o,n):Promise.resolve(null)).then(h=>ki(`${c.from} is now ${o.name}${h?`; ${h.said}`:""}.`))}const r=e.map(o=>o.id).join(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{L as d}from"./index-
|
|
1
|
+
import{L as d}from"./index-LwIi-F1W.js";import{c as p}from"./react-wKFncLeZ.js";let w="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",y=(e=21)=>{let n="",o=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)n+=w[o[e]&63];return n};function O(e){return e?.runtimeId||d}const m=`
|
|
2
2
|
`;function S(e){const n=O(e);return n===d?e.filePath:`${n}${m}${e.filePath}`}function T(e){const n=e.indexOf(m);return n<0?{runtimeId:d,filePath:e}:{runtimeId:e.slice(0,n),filePath:e.slice(n+1)}}function _(e){return e.includes(m)}const A=3;function b(e){return e.some(n=>(n.failures??0)>=A)}function a(e){if(_(e))return e;const n=typeof window<"u"?window.adfApi?.platform:void 0,o=n==="win32"?e.replace(/\\/g,"/"):e;return n==="win32"||n==="darwin"?o.toLowerCase():o}function g(e,n){return!!e&&!!n&&a(e)===a(n)}const q=[];function l(e,n,o){return n?e.queues[a(n)]?.[o]??q:q}function M(e,n){return Object.keys(e.queues[a(n)]??{})}const h=p((e,n)=>{const o=(r,u,t)=>{const s=a(r),c=n().queues,i={...c[s]};t.length>0?i[u]=t:delete i[u];const f={...c};Object.keys(i).length>0?f[s]=i:delete f[s],e({queues:f})};return{queues:{},enqueue:(r,u,t)=>{o(r,u,[...l(n(),r,u),{...t,id:y()}])},remove:(r,u,t)=>{const s=l(n(),r,u),c=s.find(i=>i.id===t);return c&&o(r,u,s.filter(i=>i.id!==t)),c},take:(r,u)=>{const t=l(n(),r,u);return t.length>0&&o(r,u,[]),t},releaseHold:(r,u)=>{const t=l(n(),r,u);t.some(s=>s.failures)&&o(r,u,t.map(s=>s.failures?{...s,failures:0}:s))},restore:(r,u,t,s)=>{t.length!==0&&o(r,u,[...t.map(c=>({...c,error:s,failures:(c.failures??0)+1})),...l(n(),r,u)])},clearAgent:r=>{const u=a(r);if(!(u in n().queues))return;const t={...n().queues};delete t[u],e({queues:t})},rekey:(r,u)=>{const t=a(r),s=a(u),c=n().queues[t];if(!c||t===s)return;const i={...n().queues};delete i[t],i[s]=c,e({queues:i})}}}),x=Object.freeze(Object.defineProperty({__proto__:null,MAX_AUTOMATIC_SENDS:A,heldForOwner:b,queuePathKey:a,queuedLoops:M,sameAgentPath:g,selectQueue:l,useMessageQueueStore:h},Symbol.toStringTag,{value:"Module"}));export{A as M,S as a,g as b,b as h,_ as i,x as m,y as n,T as p,M as q,l as s,h as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as u}from"./index-
|
|
1
|
+
import{R as u}from"./index-LwIi-F1W.js";const S=t=>{let e;const n=new Set,o=(s,r)=>{const c=typeof s=="function"?s(e):s;if(!Object.is(c,e)){const g=e;e=r??(typeof c!="object"||c===null)?c:Object.assign({},e,c),n.forEach(f=>f(e,g))}},a=()=>e,i={setState:o,getState:a,getInitialState:()=>l,subscribe:s=>(n.add(s),()=>n.delete(s))},l=e=t(o,a,i);return i},d=(t=>t?S(t):S),I=t=>t;function j(t,e=I){const n=u.useSyncExternalStore(t.subscribe,u.useCallback(()=>e(t.getState()),[t,e]),u.useCallback(()=>e(t.getInitialState()),[t,e]));return u.useDebugValue(n),n}const b=t=>{const e=d(t),n=o=>j(e,o);return Object.assign(n,e),n},O=(t=>t?b(t):b);export{O as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as d}from"./react-
|
|
1
|
+
import{c as d}from"./react-wKFncLeZ.js";let w=0;const r=d(n=>({notices:[],push:e=>n(i=>({notices:[...i.notices.filter(c=>c.text!==e),{id:`failure-${++w}`,text:e}].slice(-3)})),dismiss:e=>n(i=>({notices:i.notices.filter(a=>a.id!==e)}))}));function l(n){return(n instanceof Error?n.message:typeof n=="string"?n:n==null?"":String(n)).replace(/^Error invoking remote method '[^']*':\s*/,"").replace(/^Error:\s*/,"").trim()}function p(n){return(n.split(/[\\/]/).pop()??n).replace(/\.adf$/i,"")}function s(n,e){const i=e===void 0?"":l(e);console.warn(`[failure] ${n}${i?`: ${i}`:""}`,e??""),r.getState().push(i?`${n}: ${i}`:n)}const o=typeof window<"u"&&window.location?new URLSearchParams(window.location.search):new URLSearchParams,t=o.get("window")==="agent",g=t&&o.get("runtime")||"local",u=t?o.get("file"):null,m=!t&&(o.get("agentWindows")==="1"||typeof window<"u"&&window.adfApi?.platform==="web");function A(n){if(n.runtimeId==="local"){const{runtimeId:e,...i}=n;n=i}window.adfApi?.openAgentWindow(n).then(e=>{e.success||s("Open in new window failed",e.error??void 0)}).catch(e=>s("Open in new window failed",e))}function W(){window.adfApi?.closeAgentWindow().catch(n=>console.error("[AgentWindow] Close window failed:",n))}function S(n,e){window.adfApi?.openMainSettings({...n?{section:n}:{},...e?{anchor:e}:{}}).catch(i=>console.error("[AgentWindow] Opening Settings in the main window failed:",i))}export{u as a,m as b,A as c,p as d,W as e,l as f,t as i,S as o,s as r,r as u,g as w};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as I,g as M}from"./index-
|
|
1
|
+
import{r as I,g as M}from"./index-LwIi-F1W.js";var R={exports:{}},b={},x={exports:{}},j={};var W;function U(){if(W)return j;W=1;var n=I();function S(e,r){return e===r&&(e!==0||1/e===1/r)||e!==e&&r!==r}var m=typeof Object.is=="function"?Object.is:S,h=n.useState,p=n.useEffect,E=n.useLayoutEffect,y=n.useDebugValue;function w(e,r){var u=r(),o=h({inst:{value:u,getSnapshot:r}}),t=o[0].inst,f=o[1];return E(function(){t.value=u,t.getSnapshot=r,l(t)&&f({inst:t})},[e,u,r]),p(function(){return l(t)&&f({inst:t}),e(function(){l(t)&&f({inst:t})})},[e]),y(u),u}function l(e){var r=e.getSnapshot;e=e.value;try{var u=r();return!m(e,u)}catch{return!0}}function i(e,r){return r()}var a=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?i:w;return j.useSyncExternalStore=n.useSyncExternalStore!==void 0?n.useSyncExternalStore:a,j}var g;function C(){return g||(g=1,x.exports=U()),x.exports}var O;function G(){if(O)return b;O=1;var n=I(),S=C();function m(i,a){return i===a&&(i!==0||1/i===1/a)||i!==i&&a!==a}var h=typeof Object.is=="function"?Object.is:m,p=S.useSyncExternalStore,E=n.useRef,y=n.useEffect,w=n.useMemo,l=n.useDebugValue;return b.useSyncExternalStoreWithSelector=function(i,a,e,r,u){var o=E(null);if(o.current===null){var t={hasValue:!1,value:null};o.current=t}else t=o.current;o=w(function(){function V(c){if(!_){if(_=!0,v=c,c=r(c),u!==void 0&&t.hasValue){var s=t.value;if(u(s,c))return d=s}return d=c}if(s=d,h(v,c))return s;var D=r(c);return u!==void 0&&u(s,D)?(v=c,s):(v=c,d=D)}var _=!1,v,d,q=e===void 0?null:e;return[function(){return V(a())},q===null?void 0:function(){return V(q())}]},[a,e,r,u]);var f=p(i,o[0],o[1]);return y(function(){t.hasValue=!0,t.value=f},[f]),l(f),f},b}var z;function L(){return z||(z=1,R.exports=G()),R.exports}var $=L();const F=M($);export{C as r,F as u,$ as w};
|
package/web/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta name="theme-color" content="#101319" />
|
|
7
7
|
<title>ADF Studio</title>
|
|
8
|
-
<script type="module" crossorigin src="/studio/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/studio/assets/index-LwIi-F1W.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/studio/assets/index-CuTaWSEs.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body class="antialiased">
|