@withbuddi/buddi 0.1.0-pre.26 → 0.1.0-pre.27
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/extension/manifest.json +2 -2
- package/node_modules/@buddi/cli/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/cli/dist/doctor-probes.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor-probes.js +8 -2
- package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor.d.ts +15 -0
- package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor.js +18 -0
- package/node_modules/@buddi/cli/dist/doctor.js.map +1 -1
- package/node_modules/@buddi/core/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/core/dist/backup/index.d.ts +1 -0
- package/node_modules/@buddi/core/dist/backup/index.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/backup/index.js +1 -0
- package/node_modules/@buddi/core/dist/backup/index.js.map +1 -1
- package/node_modules/@buddi/core/dist/backup/load.d.ts +18 -0
- package/node_modules/@buddi/core/dist/backup/load.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/backup/load.js +3 -2
- package/node_modules/@buddi/core/dist/backup/load.js.map +1 -1
- package/node_modules/@buddi/core/dist/backup/pending.d.ts +101 -0
- package/node_modules/@buddi/core/dist/backup/pending.d.ts.map +1 -0
- package/node_modules/@buddi/core/dist/backup/pending.js +340 -0
- package/node_modules/@buddi/core/dist/backup/pending.js.map +1 -0
- package/node_modules/@buddi/core/dist/backup/restore.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/backup/restore.js +54 -1
- package/node_modules/@buddi/core/dist/backup/restore.js.map +1 -1
- package/node_modules/@buddi/core/dist/home.d.ts +24 -0
- package/node_modules/@buddi/core/dist/home.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/home.js +3 -0
- package/node_modules/@buddi/core/dist/home.js.map +1 -1
- package/node_modules/@buddi/core/dist/plugin/index.d.ts +2 -2
- package/node_modules/@buddi/core/dist/plugin/index.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/plugin/index.js +1 -1
- package/node_modules/@buddi/core/dist/plugin/index.js.map +1 -1
- package/node_modules/@buddi/core/dist/postgres/binaries.d.ts +3 -1
- package/node_modules/@buddi/core/dist/postgres/binaries.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/postgres/binaries.js +15 -23
- package/node_modules/@buddi/core/dist/postgres/binaries.js.map +1 -1
- package/node_modules/@buddi/core/dist/postgres/cluster.js +1 -1
- package/node_modules/@buddi/core/dist/postgres/cluster.js.map +1 -1
- package/node_modules/@buddi/core/dist/postgres/index.d.ts +1 -0
- package/node_modules/@buddi/core/dist/postgres/index.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/postgres/index.js +1 -0
- package/node_modules/@buddi/core/dist/postgres/index.js.map +1 -1
- package/node_modules/@buddi/core/dist/postgres/links.d.ts +15 -0
- package/node_modules/@buddi/core/dist/postgres/links.d.ts.map +1 -0
- package/node_modules/@buddi/core/dist/postgres/links.js +98 -0
- package/node_modules/@buddi/core/dist/postgres/links.js.map +1 -0
- package/node_modules/@buddi/core/migrations/055_pending_plugin_data.sql +24 -0
- package/node_modules/@buddi/core/package.json +4 -0
- package/node_modules/@buddi/gateway/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/approve.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/approve.js +9 -1
- package/node_modules/@buddi/gateway/dist/plugins/approve.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/migrate.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/migrate.js +11 -1
- package/node_modules/@buddi/gateway/dist/plugins/migrate.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/main.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/main.js +2 -0
- package/node_modules/@buddi/gateway/dist/telegram/main.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts +26 -1
- package/node_modules/@buddi/gateway/dist/telegram/surface.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/telegram/surface.js +106 -3
- package/node_modules/@buddi/gateway/dist/telegram/surface.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/agents.d.ts +4 -0
- package/node_modules/@buddi/gateway/dist/web/agents.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/agents.js +12 -0
- package/node_modules/@buddi/gateway/dist/web/agents.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/read.d.ts +17 -0
- package/node_modules/@buddi/gateway/dist/web/read.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/read.js +36 -1
- package/node_modules/@buddi/gateway/dist/web/read.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/recovery.d.ts +21 -0
- package/node_modules/@buddi/gateway/dist/web/recovery.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/recovery.js +68 -12
- package/node_modules/@buddi/gateway/dist/web/recovery.js.map +1 -1
- package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/install/dist/postgres-check.d.ts +18 -0
- package/node_modules/@buddi/install/dist/postgres-check.d.ts.map +1 -0
- package/node_modules/@buddi/install/dist/postgres-check.js +66 -0
- package/node_modules/@buddi/install/dist/postgres-check.js.map +1 -0
- package/node_modules/@buddi/install/dist/upgrade.d.ts +3 -0
- package/node_modules/@buddi/install/dist/upgrade.d.ts.map +1 -1
- package/node_modules/@buddi/install/dist/upgrade.js +30 -0
- package/node_modules/@buddi/install/dist/upgrade.js.map +1 -1
- package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-artifacts/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-browser/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-host/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-mcp/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-memory/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-web/dist/.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/packages/cli/dist/.tsbuildinfo +1 -1
- package/packages/cli/dist/doctor-probes.d.ts.map +1 -1
- package/packages/cli/dist/doctor-probes.js +8 -2
- package/packages/cli/dist/doctor-probes.js.map +1 -1
- package/packages/cli/dist/doctor.d.ts +15 -0
- package/packages/cli/dist/doctor.d.ts.map +1 -1
- package/packages/cli/dist/doctor.js +18 -0
- package/packages/cli/dist/doctor.js.map +1 -1
- package/packages/core/dist/.tsbuildinfo +1 -1
- package/packages/core/dist/backup/index.d.ts +1 -0
- package/packages/core/dist/backup/index.d.ts.map +1 -1
- package/packages/core/dist/backup/index.js +1 -0
- package/packages/core/dist/backup/index.js.map +1 -1
- package/packages/core/dist/backup/load.d.ts +18 -0
- package/packages/core/dist/backup/load.d.ts.map +1 -1
- package/packages/core/dist/backup/load.js +3 -2
- package/packages/core/dist/backup/load.js.map +1 -1
- package/packages/core/dist/backup/pending.d.ts +101 -0
- package/packages/core/dist/backup/pending.d.ts.map +1 -0
- package/packages/core/dist/backup/pending.js +340 -0
- package/packages/core/dist/backup/pending.js.map +1 -0
- package/packages/core/dist/backup/restore.d.ts.map +1 -1
- package/packages/core/dist/backup/restore.js +54 -1
- package/packages/core/dist/backup/restore.js.map +1 -1
- package/packages/core/dist/home.d.ts +24 -0
- package/packages/core/dist/home.d.ts.map +1 -1
- package/packages/core/dist/home.js +3 -0
- package/packages/core/dist/home.js.map +1 -1
- package/packages/core/dist/plugin/index.d.ts +2 -2
- package/packages/core/dist/plugin/index.d.ts.map +1 -1
- package/packages/core/dist/plugin/index.js +1 -1
- package/packages/core/dist/plugin/index.js.map +1 -1
- package/packages/core/dist/postgres/binaries.d.ts +3 -1
- package/packages/core/dist/postgres/binaries.d.ts.map +1 -1
- package/packages/core/dist/postgres/binaries.js +15 -23
- package/packages/core/dist/postgres/binaries.js.map +1 -1
- package/packages/core/dist/postgres/cluster.js +1 -1
- package/packages/core/dist/postgres/cluster.js.map +1 -1
- package/packages/core/dist/postgres/index.d.ts +1 -0
- package/packages/core/dist/postgres/index.d.ts.map +1 -1
- package/packages/core/dist/postgres/index.js +1 -0
- package/packages/core/dist/postgres/index.js.map +1 -1
- package/packages/core/dist/postgres/links.d.ts +15 -0
- package/packages/core/dist/postgres/links.d.ts.map +1 -0
- package/packages/core/dist/postgres/links.js +98 -0
- package/packages/core/dist/postgres/links.js.map +1 -0
- package/packages/core/migrations/055_pending_plugin_data.sql +24 -0
- package/packages/core/package.json +4 -0
- package/packages/gateway/dist/.tsbuildinfo +1 -1
- package/packages/gateway/dist/plugins/approve.d.ts.map +1 -1
- package/packages/gateway/dist/plugins/approve.js +9 -1
- package/packages/gateway/dist/plugins/approve.js.map +1 -1
- package/packages/gateway/dist/plugins/migrate.d.ts.map +1 -1
- package/packages/gateway/dist/plugins/migrate.js +11 -1
- package/packages/gateway/dist/plugins/migrate.js.map +1 -1
- package/packages/gateway/dist/telegram/main.d.ts.map +1 -1
- package/packages/gateway/dist/telegram/main.js +2 -0
- package/packages/gateway/dist/telegram/main.js.map +1 -1
- package/packages/gateway/dist/telegram/surface.d.ts +26 -1
- package/packages/gateway/dist/telegram/surface.d.ts.map +1 -1
- package/packages/gateway/dist/telegram/surface.js +106 -3
- package/packages/gateway/dist/telegram/surface.js.map +1 -1
- package/packages/gateway/dist/web/agents.d.ts +4 -0
- package/packages/gateway/dist/web/agents.d.ts.map +1 -1
- package/packages/gateway/dist/web/agents.js +12 -0
- package/packages/gateway/dist/web/agents.js.map +1 -1
- package/packages/gateway/dist/web/read.d.ts +17 -0
- package/packages/gateway/dist/web/read.d.ts.map +1 -1
- package/packages/gateway/dist/web/read.js +36 -1
- package/packages/gateway/dist/web/read.js.map +1 -1
- package/packages/gateway/dist/web/recovery.d.ts +21 -0
- package/packages/gateway/dist/web/recovery.d.ts.map +1 -1
- package/packages/gateway/dist/web/recovery.js +68 -12
- package/packages/gateway/dist/web/recovery.js.map +1 -1
- package/packages/install/dist/.tsbuildinfo +1 -1
- package/packages/install/dist/postgres-check.d.ts +18 -0
- package/packages/install/dist/postgres-check.d.ts.map +1 -0
- package/packages/install/dist/postgres-check.js +66 -0
- package/packages/install/dist/postgres-check.js.map +1 -0
- package/packages/install/dist/upgrade.d.ts +3 -0
- package/packages/install/dist/upgrade.d.ts.map +1 -1
- package/packages/install/dist/upgrade.js +30 -0
- package/packages/install/dist/upgrade.js.map +1 -1
- package/packages/runtime/dist/.tsbuildinfo +1 -1
- package/packages/tools/artifacts/dist/.tsbuildinfo +1 -1
- package/packages/tools/browser/dist/.tsbuildinfo +1 -1
- package/packages/tools/email/dist/.tsbuildinfo +1 -1
- package/packages/tools/host/dist/.tsbuildinfo +1 -1
- package/packages/tools/mcp/dist/.tsbuildinfo +1 -1
- package/packages/tools/memory/dist/.tsbuildinfo +1 -1
- package/packages/tools/web/dist/.tsbuildinfo +1 -1
- package/packages/web/dist/assets/index-Cn-3X1OI.js +130 -0
- package/packages/web/dist/assets/{index-BxbiKNMS.css → index-bdj791NB.css} +1 -1
- package/packages/web/dist/assets/{lottie_light-7wQnGwdw.js → lottie_light-DmJaDM4A.js} +1 -1
- package/packages/web/dist/build.json +1 -1
- package/packages/web/dist/index.html +2 -2
- package/packages/web/dist/precache.json +4 -4
- package/packages/web/dist/assets/index-Rrze3bGo.js +0 -130
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var rj=e=>{throw TypeError(e)};var ij=(e,t,s)=>t.has(e)||rj("Cannot "+s);var sn=(e,t,s)=>(ij(e,t,"read from private field"),s?s.call(e):t.get(e)),aj=(e,t,s)=>t.has(e)?rj("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),ph=(e,t,s,r)=>(ij(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);function QA(e,t){for(var s=0;s<t.length;s++){const r=t[s];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const a=Object.getOwnPropertyDescriptor(r,i);a&&Object.defineProperty(e,i,a.get?a:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const a of i)if(a.type==="childList")for(const l of a.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(i){const a={};return i.integrity&&(a.integrity=i.integrity),i.referrerPolicy&&(a.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?a.credentials="include":i.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(i){if(i.ep)return;i.ep=!0;const a=s(i);fetch(i.href,a)}})();var uV=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function JA(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ib={exports:{}},pd={},Pb={exports:{}},We={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var Oo=Symbol.for("react.element"),XA=Symbol.for("react.portal"),ZA=Symbol.for("react.fragment"),eT=Symbol.for("react.strict_mode"),tT=Symbol.for("react.profiler"),nT=Symbol.for("react.provider"),sT=Symbol.for("react.context"),rT=Symbol.for("react.forward_ref"),iT=Symbol.for("react.suspense"),aT=Symbol.for("react.memo"),lT=Symbol.for("react.lazy"),lj=Symbol.iterator;function oT(e){return e===null||typeof e!="object"?null:(e=lj&&e[lj]||e["@@iterator"],typeof e=="function"?e:null)}var $b={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Mb=Object.assign,Ob={};function Xa(e,t,s){this.props=e,this.context=t,this.refs=Ob,this.updater=s||$b}Xa.prototype.isReactComponent={};Xa.prototype.setState=function(e,t){if(typeof e!="object"&&typeof e!="function"&&e!=null)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")};Xa.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function Db(){}Db.prototype=Xa.prototype;function eg(e,t,s){this.props=e,this.context=t,this.refs=Ob,this.updater=s||$b}var tg=eg.prototype=new Db;tg.constructor=eg;Mb(tg,Xa.prototype);tg.isPureReactComponent=!0;var oj=Array.isArray,_b=Object.prototype.hasOwnProperty,ng={current:null},Lb={key:!0,ref:!0,__self:!0,__source:!0};function Fb(e,t,s){var r,i={},a=null,l=null;if(t!=null)for(r in t.ref!==void 0&&(l=t.ref),t.key!==void 0&&(a=""+t.key),t)_b.call(t,r)&&!Lb.hasOwnProperty(r)&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=s;else if(1<o){for(var c=Array(o),u=0;u<o;u++)c[u]=arguments[u+2];i.children=c}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return{$$typeof:Oo,type:e,key:a,ref:l,props:i,_owner:ng.current}}function cT(e,t){return{$$typeof:Oo,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function sg(e){return typeof e=="object"&&e!==null&&e.$$typeof===Oo}function uT(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return t[s]})}var cj=/\/+/g;function gh(e,t){return typeof e=="object"&&e!==null&&e.key!=null?uT(""+e.key):t.toString(36)}function qc(e,t,s,r,i){var a=typeof e;(a==="undefined"||a==="boolean")&&(e=null);var l=!1;if(e===null)l=!0;else switch(a){case"string":case"number":l=!0;break;case"object":switch(e.$$typeof){case Oo:case XA:l=!0}}if(l)return l=e,i=i(l),e=r===""?"."+gh(l,0):r,oj(i)?(s="",e!=null&&(s=e.replace(cj,"$&/")+"/"),qc(i,t,s,"",function(u){return u})):i!=null&&(sg(i)&&(i=cT(i,s+(!i.key||l&&l.key===i.key?"":(""+i.key).replace(cj,"$&/")+"/")+e)),t.push(i)),1;if(l=0,r=r===""?".":r+":",oj(e))for(var o=0;o<e.length;o++){a=e[o];var c=r+gh(a,o);l+=qc(a,t,s,c,i)}else if(c=oT(e),typeof c=="function")for(e=c.call(e),o=0;!(a=e.next()).done;)a=a.value,c=r+gh(a,o++),l+=qc(a,t,s,c,i);else if(a==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return l}function lc(e,t,s){if(e==null)return e;var r=[],i=0;return qc(e,r,"","",function(a){return t.call(s,a,i++)}),r}function dT(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(s){(e._status===0||e._status===-1)&&(e._status=1,e._result=s)},function(s){(e._status===0||e._status===-1)&&(e._status=2,e._result=s)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var vn={current:null},Qc={transition:null},hT={ReactCurrentDispatcher:vn,ReactCurrentBatchConfig:Qc,ReactCurrentOwner:ng};function zb(){throw Error("act(...) is not supported in production builds of React.")}We.Children={map:lc,forEach:function(e,t,s){lc(e,function(){t.apply(this,arguments)},s)},count:function(e){var t=0;return lc(e,function(){t++}),t},toArray:function(e){return lc(e,function(t){return t})||[]},only:function(e){if(!sg(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};We.Component=Xa;We.Fragment=ZA;We.Profiler=tT;We.PureComponent=eg;We.StrictMode=eT;We.Suspense=iT;We.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=hT;We.act=zb;We.cloneElement=function(e,t,s){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=Mb({},e.props),i=e.key,a=e.ref,l=e._owner;if(t!=null){if(t.ref!==void 0&&(a=t.ref,l=ng.current),t.key!==void 0&&(i=""+t.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in t)_b.call(t,c)&&!Lb.hasOwnProperty(c)&&(r[c]=t[c]===void 0&&o!==void 0?o[c]:t[c])}var c=arguments.length-2;if(c===1)r.children=s;else if(1<c){o=Array(c);for(var u=0;u<c;u++)o[u]=arguments[u+2];r.children=o}return{$$typeof:Oo,type:e.type,key:i,ref:a,props:r,_owner:l}};We.createContext=function(e){return e={$$typeof:sT,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:nT,_context:e},e.Consumer=e};We.createElement=Fb;We.createFactory=function(e){var t=Fb.bind(null,e);return t.type=e,t};We.createRef=function(){return{current:null}};We.forwardRef=function(e){return{$$typeof:rT,render:e}};We.isValidElement=sg;We.lazy=function(e){return{$$typeof:lT,_payload:{_status:-1,_result:e},_init:dT}};We.memo=function(e,t){return{$$typeof:aT,type:e,compare:t===void 0?null:t}};We.startTransition=function(e){var t=Qc.transition;Qc.transition={};try{e()}finally{Qc.transition=t}};We.unstable_act=zb;We.useCallback=function(e,t){return vn.current.useCallback(e,t)};We.useContext=function(e){return vn.current.useContext(e)};We.useDebugValue=function(){};We.useDeferredValue=function(e){return vn.current.useDeferredValue(e)};We.useEffect=function(e,t){return vn.current.useEffect(e,t)};We.useId=function(){return vn.current.useId()};We.useImperativeHandle=function(e,t,s){return vn.current.useImperativeHandle(e,t,s)};We.useInsertionEffect=function(e,t){return vn.current.useInsertionEffect(e,t)};We.useLayoutEffect=function(e,t){return vn.current.useLayoutEffect(e,t)};We.useMemo=function(e,t){return vn.current.useMemo(e,t)};We.useReducer=function(e,t,s){return vn.current.useReducer(e,t,s)};We.useRef=function(e){return vn.current.useRef(e)};We.useState=function(e){return vn.current.useState(e)};We.useSyncExternalStore=function(e,t,s){return vn.current.useSyncExternalStore(e,t,s)};We.useTransition=function(){return vn.current.useTransition()};We.version="18.3.1";Pb.exports=We;var f=Pb.exports;const fT=JA(f),Za=QA({__proto__:null,default:fT},[f]);/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.production.min.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var mT=f,pT=Symbol.for("react.element"),gT=Symbol.for("react.fragment"),xT=Object.prototype.hasOwnProperty,vT=mT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,jT={key:!0,ref:!0,__self:!0,__source:!0};function Ub(e,t,s){var r,i={},a=null,l=null;s!==void 0&&(a=""+s),t.key!==void 0&&(a=""+t.key),t.ref!==void 0&&(l=t.ref);for(r in t)xT.call(t,r)&&!jT.hasOwnProperty(r)&&(i[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)i[r]===void 0&&(i[r]=t[r]);return{$$typeof:pT,type:e,key:a,ref:l,props:i,_owner:vT.current}}pd.Fragment=gT;pd.jsx=Ub;pd.jsxs=Ub;Ib.exports=pd;var n=Ib.exports,Bb={exports:{}},Kn={},Wb={exports:{}},Hb={};/**
|
|
18
|
+
* @license React
|
|
19
|
+
* scheduler.production.min.js
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*/(function(e){function t($,B){var O=$.length;$.push(B);e:for(;0<O;){var K=O-1>>>1,G=$[K];if(0<i(G,B))$[K]=B,$[O]=G,O=K;else break e}}function s($){return $.length===0?null:$[0]}function r($){if($.length===0)return null;var B=$[0],O=$.pop();if(O!==B){$[0]=O;e:for(var K=0,G=$.length,se=G>>>1;K<se;){var ue=2*(K+1)-1,ie=$[ue],ee=ue+1,X=$[ee];if(0>i(ie,O))ee<G&&0>i(X,ie)?($[K]=X,$[ee]=O,K=ee):($[K]=ie,$[ue]=O,K=ue);else if(ee<G&&0>i(X,O))$[K]=X,$[ee]=O,K=ee;else break e}}return B}function i($,B){var O=$.sortIndex-B.sortIndex;return O!==0?O:$.id-B.id}if(typeof performance=="object"&&typeof performance.now=="function"){var a=performance;e.unstable_now=function(){return a.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],d=1,h=null,m=3,p=!1,g=!1,y=!1,b=typeof setTimeout=="function"?setTimeout:null,x=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function j($){for(var B=s(u);B!==null;){if(B.callback===null)r(u);else if(B.startTime<=$)r(u),B.sortIndex=B.expirationTime,t(c,B);else break;B=s(u)}}function w($){if(y=!1,j($),!g)if(s(c)!==null)g=!0,D(S);else{var B=s(u);B!==null&&U(w,B.startTime-$)}}function S($,B){g=!1,y&&(y=!1,x(C),C=-1),p=!0;var O=m;try{for(j(B),h=s(c);h!==null&&(!(h.expirationTime>B)||$&&!_());){var K=h.callback;if(typeof K=="function"){h.callback=null,m=h.priorityLevel;var G=K(h.expirationTime<=B);B=e.unstable_now(),typeof G=="function"?h.callback=G:h===s(c)&&r(c),j(B)}else r(c);h=s(c)}if(h!==null)var se=!0;else{var ue=s(u);ue!==null&&U(w,ue.startTime-B),se=!1}return se}finally{h=null,m=O,p=!1}}var k=!1,N=null,C=-1,I=5,A=-1;function _(){return!(e.unstable_now()-A<I)}function z(){if(N!==null){var $=e.unstable_now();A=$;var B=!0;try{B=N(!0,$)}finally{B?L():(k=!1,N=null)}}else k=!1}var L;if(typeof v=="function")L=function(){v(z)};else if(typeof MessageChannel<"u"){var E=new MessageChannel,M=E.port2;E.port1.onmessage=z,L=function(){M.postMessage(null)}}else L=function(){b(z,0)};function D($){N=$,k||(k=!0,L())}function U($,B){C=b(function(){$(e.unstable_now())},B)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function($){$.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,D(S))},e.unstable_forceFrameRate=function($){0>$||125<$?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):I=0<$?Math.floor(1e3/$):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function($){switch(m){case 1:case 2:case 3:var B=3;break;default:B=m}var O=m;m=B;try{return $()}finally{m=O}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function($,B){switch($){case 1:case 2:case 3:case 4:case 5:break;default:$=3}var O=m;m=$;try{return B()}finally{m=O}},e.unstable_scheduleCallback=function($,B,O){var K=e.unstable_now();switch(typeof O=="object"&&O!==null?(O=O.delay,O=typeof O=="number"&&0<O?K+O:K):O=K,$){case 1:var G=-1;break;case 2:G=250;break;case 5:G=1073741823;break;case 4:G=1e4;break;default:G=5e3}return G=O+G,$={id:d++,callback:B,priorityLevel:$,startTime:O,expirationTime:G,sortIndex:-1},O>K?($.sortIndex=O,t(u,$),s(c)===null&&$===s(u)&&(y?(x(C),C=-1):y=!0,U(w,O-K))):($.sortIndex=G,t(c,$),g||p||(g=!0,D(S))),$},e.unstable_shouldYield=_,e.unstable_wrapCallback=function($){var B=m;return function(){var O=m;m=B;try{return $.apply(this,arguments)}finally{m=O}}}})(Hb);Wb.exports=Hb;var yT=Wb.exports;/**
|
|
26
|
+
* @license React
|
|
27
|
+
* react-dom.production.min.js
|
|
28
|
+
*
|
|
29
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
30
|
+
*
|
|
31
|
+
* This source code is licensed under the MIT license found in the
|
|
32
|
+
* LICENSE file in the root directory of this source tree.
|
|
33
|
+
*/var wT=f,Wn=yT;function ae(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)t+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var Kb=new Set,Zl={};function Ui(e,t){Ma(e,t),Ma(e+"Capture",t)}function Ma(e,t){for(Zl[e]=t,e=0;e<t.length;e++)Kb.add(t[e])}var ur=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Lf=Object.prototype.hasOwnProperty,bT=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,uj={},dj={};function kT(e){return Lf.call(dj,e)?!0:Lf.call(uj,e)?!1:bT.test(e)?dj[e]=!0:(uj[e]=!0,!1)}function ST(e,t,s,r){if(s!==null&&s.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:s!==null?!s.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function NT(e,t,s,r){if(t===null||typeof t>"u"||ST(e,t,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function jn(e,t,s,r,i,a,l){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=i,this.mustUseProperty=s,this.propertyName=e,this.type=t,this.sanitizeURL=a,this.removeEmptyString=l}var Jt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Jt[e]=new jn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Jt[t]=new jn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Jt[e]=new jn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Jt[e]=new jn(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){Jt[e]=new jn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Jt[e]=new jn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Jt[e]=new jn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Jt[e]=new jn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Jt[e]=new jn(e,5,!1,e.toLowerCase(),null,!1,!1)});var rg=/[\-:]([a-z])/g;function ig(e){return e[1].toUpperCase()}"accent-height alignment-baseline arabic-form baseline-shift cap-height clip-path clip-rule color-interpolation color-interpolation-filters color-profile color-rendering dominant-baseline enable-background fill-opacity fill-rule flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight glyph-name glyph-orientation-horizontal glyph-orientation-vertical horiz-adv-x horiz-origin-x image-rendering letter-spacing lighting-color marker-end marker-mid marker-start overline-position overline-thickness paint-order panose-1 pointer-events rendering-intent shape-rendering stop-color stop-opacity strikethrough-position strikethrough-thickness stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width text-anchor text-decoration text-rendering underline-position underline-thickness unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical vector-effect vert-adv-y vert-origin-x vert-origin-y word-spacing writing-mode xmlns:xlink x-height".split(" ").forEach(function(e){var t=e.replace(rg,ig);Jt[t]=new jn(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(rg,ig);Jt[t]=new jn(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(rg,ig);Jt[t]=new jn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Jt[e]=new jn(e,1,!1,e.toLowerCase(),null,!1,!1)});Jt.xlinkHref=new jn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Jt[e]=new jn(e,1,!1,e.toLowerCase(),null,!0,!0)});function ag(e,t,s,r){var i=Jt.hasOwnProperty(t)?Jt[t]:null;(i!==null?i.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(NT(t,s,i,r)&&(s=null),r||i===null?kT(t)&&(s===null?e.removeAttribute(t):e.setAttribute(t,""+s)):i.mustUseProperty?e[i.propertyName]=s===null?i.type===3?!1:"":s:(t=i.attributeName,r=i.attributeNamespace,s===null?e.removeAttribute(t):(i=i.type,s=i===3||i===4&&s===!0?"":""+s,r?e.setAttributeNS(r,t,s):e.setAttribute(t,s))))}var vr=wT.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,oc=Symbol.for("react.element"),oa=Symbol.for("react.portal"),ca=Symbol.for("react.fragment"),lg=Symbol.for("react.strict_mode"),Ff=Symbol.for("react.profiler"),Vb=Symbol.for("react.provider"),Gb=Symbol.for("react.context"),og=Symbol.for("react.forward_ref"),zf=Symbol.for("react.suspense"),Uf=Symbol.for("react.suspense_list"),cg=Symbol.for("react.memo"),Tr=Symbol.for("react.lazy"),Yb=Symbol.for("react.offscreen"),hj=Symbol.iterator;function jl(e){return e===null||typeof e!="object"?null:(e=hj&&e[hj]||e["@@iterator"],typeof e=="function"?e:null)}var wt=Object.assign,xh;function $l(e){if(xh===void 0)try{throw Error()}catch(s){var t=s.stack.trim().match(/\n( *(at )?)/);xh=t&&t[1]||""}return`
|
|
34
|
+
`+xh+e}var vh=!1;function jh(e,t){if(!e||vh)return"";vh=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(t,[])}catch(u){var r=u}Reflect.construct(e,[],t)}else{try{t.call()}catch(u){r=u}e.call(t.prototype)}else{try{throw Error()}catch(u){r=u}e()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var i=u.stack.split(`
|
|
35
|
+
`),a=r.stack.split(`
|
|
36
|
+
`),l=i.length-1,o=a.length-1;1<=l&&0<=o&&i[l]!==a[o];)o--;for(;1<=l&&0<=o;l--,o--)if(i[l]!==a[o]){if(l!==1||o!==1)do if(l--,o--,0>o||i[l]!==a[o]){var c=`
|
|
37
|
+
`+i[l].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=l&&0<=o);break}}}finally{vh=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?$l(e):""}function CT(e){switch(e.tag){case 5:return $l(e.type);case 16:return $l("Lazy");case 13:return $l("Suspense");case 19:return $l("SuspenseList");case 0:case 2:case 15:return e=jh(e.type,!1),e;case 11:return e=jh(e.type.render,!1),e;case 1:return e=jh(e.type,!0),e;default:return""}}function Bf(e){if(e==null)return null;if(typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case ca:return"Fragment";case oa:return"Portal";case Ff:return"Profiler";case lg:return"StrictMode";case zf:return"Suspense";case Uf:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Gb:return(e.displayName||"Context")+".Consumer";case Vb:return(e._context.displayName||"Context")+".Provider";case og:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case cg:return t=e.displayName||null,t!==null?t:Bf(e.type)||"Memo";case Tr:t=e._payload,e=e._init;try{return Bf(e(t))}catch{}}return null}function ET(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Bf(t);case 8:return t===lg?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function Xr(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function qb(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function AT(e){var t=qb(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var i=s.get,a=s.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return i.call(this)},set:function(l){r=""+l,a.call(this,l)}}),Object.defineProperty(e,t,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function cc(e){e._valueTracker||(e._valueTracker=AT(e))}function Qb(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var s=t.getValue(),r="";return e&&(r=qb(e)?e.checked?"true":"false":e.value),e=r,e!==s?(t.setValue(e),!0):!1}function wu(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}}function Wf(e,t){var s=t.checked;return wt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function fj(e,t){var s=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;s=Xr(t.value!=null?t.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function Jb(e,t){t=t.checked,t!=null&&ag(e,"checked",t,!1)}function Hf(e,t){Jb(e,t);var s=Xr(t.value),r=t.type;if(s!=null)r==="number"?(s===0&&e.value===""||e.value!=s)&&(e.value=""+s):e.value!==""+s&&(e.value=""+s);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Kf(e,t.type,s):t.hasOwnProperty("defaultValue")&&Kf(e,t.type,Xr(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function mj(e,t,s){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,s||t===e.value||(e.value=t),e.defaultValue=t}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function Kf(e,t,s){(t!=="number"||wu(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var Ml=Array.isArray;function ba(e,t,s,r){if(e=e.options,t){t={};for(var i=0;i<s.length;i++)t["$"+s[i]]=!0;for(s=0;s<e.length;s++)i=t.hasOwnProperty("$"+e[s].value),e[s].selected!==i&&(e[s].selected=i),i&&r&&(e[s].defaultSelected=!0)}else{for(s=""+Xr(s),t=null,i=0;i<e.length;i++){if(e[i].value===s){e[i].selected=!0,r&&(e[i].defaultSelected=!0);return}t!==null||e[i].disabled||(t=e[i])}t!==null&&(t.selected=!0)}}function Vf(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(ae(91));return wt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function pj(e,t){var s=t.value;if(s==null){if(s=t.children,t=t.defaultValue,s!=null){if(t!=null)throw Error(ae(92));if(Ml(s)){if(1<s.length)throw Error(ae(93));s=s[0]}t=s}t==null&&(t=""),s=t}e._wrapperState={initialValue:Xr(s)}}function Xb(e,t){var s=Xr(t.value),r=Xr(t.defaultValue);s!=null&&(s=""+s,s!==e.value&&(e.value=s),t.defaultValue==null&&e.defaultValue!==s&&(e.defaultValue=s)),r!=null&&(e.defaultValue=""+r)}function gj(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function Zb(e){switch(e){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function Gf(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?Zb(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var uc,e0=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(t,s,r,i){MSApp.execUnsafeLocalFunction(function(){return e(t,s,r,i)})}:e}(function(e,t){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=t;else{for(uc=uc||document.createElement("div"),uc.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=uc.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function eo(e,t){if(t){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=t;return}}e.textContent=t}var Fl={animationIterationCount:!0,aspectRatio:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,columns:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridArea:!0,gridRow:!0,gridRowEnd:!0,gridRowSpan:!0,gridRowStart:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnSpan:!0,gridColumnStart:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0},TT=["Webkit","ms","Moz","O"];Object.keys(Fl).forEach(function(e){TT.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Fl[t]=Fl[e]})});function t0(e,t,s){return t==null||typeof t=="boolean"||t===""?"":s||typeof t!="number"||t===0||Fl.hasOwnProperty(e)&&Fl[e]?(""+t).trim():t+"px"}function n0(e,t){e=e.style;for(var s in t)if(t.hasOwnProperty(s)){var r=s.indexOf("--")===0,i=t0(s,t[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,i):e[s]=i}}var RT=wt({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function Yf(e,t){if(t){if(RT[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(ae(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(ae(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(ae(61))}if(t.style!=null&&typeof t.style!="object")throw Error(ae(62))}}function qf(e,t){if(e.indexOf("-")===-1)return typeof t.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var Qf=null;function ug(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Jf=null,ka=null,Sa=null;function xj(e){if(e=Lo(e)){if(typeof Jf!="function")throw Error(ae(280));var t=e.stateNode;t&&(t=yd(t),Jf(e.stateNode,e.type,t))}}function s0(e){ka?Sa?Sa.push(e):Sa=[e]:ka=e}function r0(){if(ka){var e=ka,t=Sa;if(Sa=ka=null,xj(e),t)for(e=0;e<t.length;e++)xj(t[e])}}function i0(e,t){return e(t)}function a0(){}var yh=!1;function l0(e,t,s){if(yh)return e(t,s);yh=!0;try{return i0(e,t,s)}finally{yh=!1,(ka!==null||Sa!==null)&&(a0(),r0())}}function to(e,t){var s=e.stateNode;if(s===null)return null;var r=yd(s);if(r===null)return null;s=r[t];e:switch(t){case"onClick":case"onClickCapture":case"onDoubleClick":case"onDoubleClickCapture":case"onMouseDown":case"onMouseDownCapture":case"onMouseMove":case"onMouseMoveCapture":case"onMouseUp":case"onMouseUpCapture":case"onMouseEnter":(r=!r.disabled)||(e=e.type,r=!(e==="button"||e==="input"||e==="select"||e==="textarea")),e=!r;break e;default:e=!1}if(e)return null;if(s&&typeof s!="function")throw Error(ae(231,t,typeof s));return s}var Xf=!1;if(ur)try{var yl={};Object.defineProperty(yl,"passive",{get:function(){Xf=!0}}),window.addEventListener("test",yl,yl),window.removeEventListener("test",yl,yl)}catch{Xf=!1}function IT(e,t,s,r,i,a,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{t.apply(s,u)}catch(d){this.onError(d)}}var zl=!1,bu=null,ku=!1,Zf=null,PT={onError:function(e){zl=!0,bu=e}};function $T(e,t,s,r,i,a,l,o,c){zl=!1,bu=null,IT.apply(PT,arguments)}function MT(e,t,s,r,i,a,l,o,c){if($T.apply(this,arguments),zl){if(zl){var u=bu;zl=!1,bu=null}else throw Error(ae(198));ku||(ku=!0,Zf=u)}}function Bi(e){var t=e,s=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(s=t.return),e=t.return;while(e)}return t.tag===3?s:null}function o0(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function vj(e){if(Bi(e)!==e)throw Error(ae(188))}function OT(e){var t=e.alternate;if(!t){if(t=Bi(e),t===null)throw Error(ae(188));return t!==e?null:e}for(var s=e,r=t;;){var i=s.return;if(i===null)break;var a=i.alternate;if(a===null){if(r=i.return,r!==null){s=r;continue}break}if(i.child===a.child){for(a=i.child;a;){if(a===s)return vj(i),e;if(a===r)return vj(i),t;a=a.sibling}throw Error(ae(188))}if(s.return!==r.return)s=i,r=a;else{for(var l=!1,o=i.child;o;){if(o===s){l=!0,s=i,r=a;break}if(o===r){l=!0,r=i,s=a;break}o=o.sibling}if(!l){for(o=a.child;o;){if(o===s){l=!0,s=a,r=i;break}if(o===r){l=!0,r=a,s=i;break}o=o.sibling}if(!l)throw Error(ae(189))}}if(s.alternate!==r)throw Error(ae(190))}if(s.tag!==3)throw Error(ae(188));return s.stateNode.current===s?e:t}function c0(e){return e=OT(e),e!==null?u0(e):null}function u0(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=u0(e);if(t!==null)return t;e=e.sibling}return null}var d0=Wn.unstable_scheduleCallback,jj=Wn.unstable_cancelCallback,DT=Wn.unstable_shouldYield,_T=Wn.unstable_requestPaint,Tt=Wn.unstable_now,LT=Wn.unstable_getCurrentPriorityLevel,dg=Wn.unstable_ImmediatePriority,h0=Wn.unstable_UserBlockingPriority,Su=Wn.unstable_NormalPriority,FT=Wn.unstable_LowPriority,f0=Wn.unstable_IdlePriority,gd=null,Us=null;function zT(e){if(Us&&typeof Us.onCommitFiberRoot=="function")try{Us.onCommitFiberRoot(gd,e,void 0,(e.current.flags&128)===128)}catch{}}var gs=Math.clz32?Math.clz32:WT,UT=Math.log,BT=Math.LN2;function WT(e){return e>>>=0,e===0?32:31-(UT(e)/BT|0)|0}var dc=64,hc=4194304;function Ol(e){switch(e&-e){case 1:return 1;case 2:return 2;case 4:return 4;case 8:return 8;case 16:return 16;case 32:return 32;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return e&4194240;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return e&130023424;case 134217728:return 134217728;case 268435456:return 268435456;case 536870912:return 536870912;case 1073741824:return 1073741824;default:return e}}function Nu(e,t){var s=e.pendingLanes;if(s===0)return 0;var r=0,i=e.suspendedLanes,a=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~i;o!==0?r=Ol(o):(a&=l,a!==0&&(r=Ol(a)))}else l=s&~i,l!==0?r=Ol(l):a!==0&&(r=Ol(a));if(r===0)return 0;if(t!==0&&t!==r&&!(t&i)&&(i=r&-r,a=t&-t,i>=a||i===16&&(a&4194240)!==0))return t;if(r&4&&(r|=s&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)s=31-gs(t),i=1<<s,r|=e[s],t&=~i;return r}function HT(e,t){switch(e){case 1:case 2:case 4:return t+250;case 8:case 16:case 32:case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:return t+5e3;case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:return-1;case 134217728:case 268435456:case 536870912:case 1073741824:return-1;default:return-1}}function KT(e,t){for(var s=e.suspendedLanes,r=e.pingedLanes,i=e.expirationTimes,a=e.pendingLanes;0<a;){var l=31-gs(a),o=1<<l,c=i[l];c===-1?(!(o&s)||o&r)&&(i[l]=HT(o,t)):c<=t&&(e.expiredLanes|=o),a&=~o}}function em(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function m0(){var e=dc;return dc<<=1,!(dc&4194240)&&(dc=64),e}function wh(e){for(var t=[],s=0;31>s;s++)t.push(e);return t}function Do(e,t,s){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-gs(t),e[t]=s}function VT(e,t){var s=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var i=31-gs(s),a=1<<i;t[i]=0,r[i]=-1,e[i]=-1,s&=~a}}function hg(e,t){var s=e.entangledLanes|=t;for(e=e.entanglements;s;){var r=31-gs(s),i=1<<r;i&t|e[r]&t&&(e[r]|=t),s&=~i}}var st=0;function p0(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var g0,fg,x0,v0,j0,tm=!1,fc=[],Fr=null,zr=null,Ur=null,no=new Map,so=new Map,Ir=[],GT="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function yj(e,t){switch(e){case"focusin":case"focusout":Fr=null;break;case"dragenter":case"dragleave":zr=null;break;case"mouseover":case"mouseout":Ur=null;break;case"pointerover":case"pointerout":no.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":so.delete(t.pointerId)}}function wl(e,t,s,r,i,a){return e===null||e.nativeEvent!==a?(e={blockedOn:t,domEventName:s,eventSystemFlags:r,nativeEvent:a,targetContainers:[i]},t!==null&&(t=Lo(t),t!==null&&fg(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,i!==null&&t.indexOf(i)===-1&&t.push(i),e)}function YT(e,t,s,r,i){switch(t){case"focusin":return Fr=wl(Fr,e,t,s,r,i),!0;case"dragenter":return zr=wl(zr,e,t,s,r,i),!0;case"mouseover":return Ur=wl(Ur,e,t,s,r,i),!0;case"pointerover":var a=i.pointerId;return no.set(a,wl(no.get(a)||null,e,t,s,r,i)),!0;case"gotpointercapture":return a=i.pointerId,so.set(a,wl(so.get(a)||null,e,t,s,r,i)),!0}return!1}function y0(e){var t=Si(e.target);if(t!==null){var s=Bi(t);if(s!==null){if(t=s.tag,t===13){if(t=o0(s),t!==null){e.blockedOn=t,j0(e.priority,function(){x0(s)});return}}else if(t===3&&s.stateNode.current.memoizedState.isDehydrated){e.blockedOn=s.tag===3?s.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Jc(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var s=nm(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Qf=r,s.target.dispatchEvent(r),Qf=null}else return t=Lo(s),t!==null&&fg(t),e.blockedOn=s,!1;t.shift()}return!0}function wj(e,t,s){Jc(e)&&s.delete(t)}function qT(){tm=!1,Fr!==null&&Jc(Fr)&&(Fr=null),zr!==null&&Jc(zr)&&(zr=null),Ur!==null&&Jc(Ur)&&(Ur=null),no.forEach(wj),so.forEach(wj)}function bl(e,t){e.blockedOn===t&&(e.blockedOn=null,tm||(tm=!0,Wn.unstable_scheduleCallback(Wn.unstable_NormalPriority,qT)))}function ro(e){function t(i){return bl(i,e)}if(0<fc.length){bl(fc[0],e);for(var s=1;s<fc.length;s++){var r=fc[s];r.blockedOn===e&&(r.blockedOn=null)}}for(Fr!==null&&bl(Fr,e),zr!==null&&bl(zr,e),Ur!==null&&bl(Ur,e),no.forEach(t),so.forEach(t),s=0;s<Ir.length;s++)r=Ir[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Ir.length&&(s=Ir[0],s.blockedOn===null);)y0(s),s.blockedOn===null&&Ir.shift()}var Na=vr.ReactCurrentBatchConfig,Cu=!0;function QT(e,t,s,r){var i=st,a=Na.transition;Na.transition=null;try{st=1,mg(e,t,s,r)}finally{st=i,Na.transition=a}}function JT(e,t,s,r){var i=st,a=Na.transition;Na.transition=null;try{st=4,mg(e,t,s,r)}finally{st=i,Na.transition=a}}function mg(e,t,s,r){if(Cu){var i=nm(e,t,s,r);if(i===null)Ih(e,t,r,Eu,s),yj(e,r);else if(YT(i,e,t,s,r))r.stopPropagation();else if(yj(e,r),t&4&&-1<GT.indexOf(e)){for(;i!==null;){var a=Lo(i);if(a!==null&&g0(a),a=nm(e,t,s,r),a===null&&Ih(e,t,r,Eu,s),a===i)break;i=a}i!==null&&r.stopPropagation()}else Ih(e,t,r,null,s)}}var Eu=null;function nm(e,t,s,r){if(Eu=null,e=ug(r),e=Si(e),e!==null)if(t=Bi(e),t===null)e=null;else if(s=t.tag,s===13){if(e=o0(t),e!==null)return e;e=null}else if(s===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null);return Eu=e,null}function w0(e){switch(e){case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 1;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"toggle":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 4;case"message":switch(LT()){case dg:return 1;case h0:return 4;case Su:case FT:return 16;case f0:return 536870912;default:return 16}default:return 16}}var $r=null,pg=null,Xc=null;function b0(){if(Xc)return Xc;var e,t=pg,s=t.length,r,i="value"in $r?$r.value:$r.textContent,a=i.length;for(e=0;e<s&&t[e]===i[e];e++);var l=s-e;for(r=1;r<=l&&t[s-r]===i[a-r];r++);return Xc=i.slice(e,1<r?1-r:void 0)}function Zc(e){var t=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function mc(){return!0}function bj(){return!1}function Vn(e){function t(s,r,i,a,l){this._reactName=s,this._targetInst=i,this.type=r,this.nativeEvent=a,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(a):a[o]);return this.isDefaultPrevented=(a.defaultPrevented!=null?a.defaultPrevented:a.returnValue===!1)?mc:bj,this.isPropagationStopped=bj,this}return wt(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var s=this.nativeEvent;s&&(s.preventDefault?s.preventDefault():typeof s.returnValue!="unknown"&&(s.returnValue=!1),this.isDefaultPrevented=mc)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=mc)},persist:function(){},isPersistent:mc}),t}var el={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},gg=Vn(el),_o=wt({},el,{view:0,detail:0}),XT=Vn(_o),bh,kh,kl,xd=wt({},_o,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:xg,button:0,buttons:0,relatedTarget:function(e){return e.relatedTarget===void 0?e.fromElement===e.srcElement?e.toElement:e.fromElement:e.relatedTarget},movementX:function(e){return"movementX"in e?e.movementX:(e!==kl&&(kl&&e.type==="mousemove"?(bh=e.screenX-kl.screenX,kh=e.screenY-kl.screenY):kh=bh=0,kl=e),bh)},movementY:function(e){return"movementY"in e?e.movementY:kh}}),kj=Vn(xd),ZT=wt({},xd,{dataTransfer:0}),eR=Vn(ZT),tR=wt({},_o,{relatedTarget:0}),Sh=Vn(tR),nR=wt({},el,{animationName:0,elapsedTime:0,pseudoElement:0}),sR=Vn(nR),rR=wt({},el,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),iR=Vn(rR),aR=wt({},el,{data:0}),Sj=Vn(aR),lR={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},oR={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},cR={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function uR(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=cR[e])?!!t[e]:!1}function xg(){return uR}var dR=wt({},_o,{key:function(e){if(e.key){var t=lR[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=Zc(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?oR[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:xg,charCode:function(e){return e.type==="keypress"?Zc(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Zc(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),hR=Vn(dR),fR=wt({},xd,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Nj=Vn(fR),mR=wt({},_o,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:xg}),pR=Vn(mR),gR=wt({},el,{propertyName:0,elapsedTime:0,pseudoElement:0}),xR=Vn(gR),vR=wt({},xd,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),jR=Vn(vR),yR=[9,13,27,32],vg=ur&&"CompositionEvent"in window,Ul=null;ur&&"documentMode"in document&&(Ul=document.documentMode);var wR=ur&&"TextEvent"in window&&!Ul,k0=ur&&(!vg||Ul&&8<Ul&&11>=Ul),Cj=" ",Ej=!1;function S0(e,t){switch(e){case"keyup":return yR.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function N0(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ua=!1;function bR(e,t){switch(e){case"compositionend":return N0(t);case"keypress":return t.which!==32?null:(Ej=!0,Cj);case"textInput":return e=t.data,e===Cj&&Ej?null:e;default:return null}}function kR(e,t){if(ua)return e==="compositionend"||!vg&&S0(e,t)?(e=b0(),Xc=pg=$r=null,ua=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case"compositionend":return k0&&t.locale!=="ko"?null:t.data;default:return null}}var SR={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function Aj(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!SR[e.type]:t==="textarea"}function C0(e,t,s,r){s0(r),t=Au(t,"onChange"),0<t.length&&(s=new gg("onChange","change",null,s,r),e.push({event:s,listeners:t}))}var Bl=null,io=null;function NR(e){_0(e,0)}function vd(e){var t=fa(e);if(Qb(t))return e}function CR(e,t){if(e==="change")return t}var E0=!1;if(ur){var Nh;if(ur){var Ch="oninput"in document;if(!Ch){var Tj=document.createElement("div");Tj.setAttribute("oninput","return;"),Ch=typeof Tj.oninput=="function"}Nh=Ch}else Nh=!1;E0=Nh&&(!document.documentMode||9<document.documentMode)}function Rj(){Bl&&(Bl.detachEvent("onpropertychange",A0),io=Bl=null)}function A0(e){if(e.propertyName==="value"&&vd(io)){var t=[];C0(t,io,e,ug(e)),l0(NR,t)}}function ER(e,t,s){e==="focusin"?(Rj(),Bl=t,io=s,Bl.attachEvent("onpropertychange",A0)):e==="focusout"&&Rj()}function AR(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return vd(io)}function TR(e,t){if(e==="click")return vd(t)}function RR(e,t){if(e==="input"||e==="change")return vd(t)}function IR(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var ws=typeof Object.is=="function"?Object.is:IR;function ao(e,t){if(ws(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var i=s[r];if(!Lf.call(t,i)||!ws(e[i],t[i]))return!1}return!0}function Ij(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Pj(e,t){var s=Ij(e);e=0;for(var r;s;){if(s.nodeType===3){if(r=e+s.textContent.length,e<=t&&r>=t)return{node:s,offset:t-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=Ij(s)}}function T0(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?T0(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function R0(){for(var e=window,t=wu();t instanceof e.HTMLIFrameElement;){try{var s=typeof t.contentWindow.location.href=="string"}catch{s=!1}if(s)e=t.contentWindow;else break;t=wu(e.document)}return t}function jg(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function PR(e){var t=R0(),s=e.focusedElem,r=e.selectionRange;if(t!==s&&s&&s.ownerDocument&&T0(s.ownerDocument.documentElement,s)){if(r!==null&&jg(s)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in s)s.selectionStart=t,s.selectionEnd=Math.min(e,s.value.length);else if(e=(t=s.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var i=s.textContent.length,a=Math.min(r.start,i);r=r.end===void 0?a:Math.min(r.end,i),!e.extend&&a>r&&(i=r,r=a,a=i),i=Pj(s,a);var l=Pj(s,r);i&&l&&(e.rangeCount!==1||e.anchorNode!==i.node||e.anchorOffset!==i.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(t=t.createRange(),t.setStart(i.node,i.offset),e.removeAllRanges(),a>r?(e.addRange(t),e.extend(l.node,l.offset)):(t.setEnd(l.node,l.offset),e.addRange(t)))}}for(t=[],e=s;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s<t.length;s++)e=t[s],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var $R=ur&&"documentMode"in document&&11>=document.documentMode,da=null,sm=null,Wl=null,rm=!1;function $j(e,t,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;rm||da==null||da!==wu(r)||(r=da,"selectionStart"in r&&jg(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Wl&&ao(Wl,r)||(Wl=r,r=Au(sm,"onSelect"),0<r.length&&(t=new gg("onSelect","select",null,t,s),e.push({event:t,listeners:r}),t.target=da)))}function pc(e,t){var s={};return s[e.toLowerCase()]=t.toLowerCase(),s["Webkit"+e]="webkit"+t,s["Moz"+e]="moz"+t,s}var ha={animationend:pc("Animation","AnimationEnd"),animationiteration:pc("Animation","AnimationIteration"),animationstart:pc("Animation","AnimationStart"),transitionend:pc("Transition","TransitionEnd")},Eh={},I0={};ur&&(I0=document.createElement("div").style,"AnimationEvent"in window||(delete ha.animationend.animation,delete ha.animationiteration.animation,delete ha.animationstart.animation),"TransitionEvent"in window||delete ha.transitionend.transition);function jd(e){if(Eh[e])return Eh[e];if(!ha[e])return e;var t=ha[e],s;for(s in t)if(t.hasOwnProperty(s)&&s in I0)return Eh[e]=t[s];return e}var P0=jd("animationend"),$0=jd("animationiteration"),M0=jd("animationstart"),O0=jd("transitionend"),D0=new Map,Mj="abort auxClick cancel canPlay canPlayThrough click close contextMenu copy cut drag dragEnd dragEnter dragExit dragLeave dragOver dragStart drop durationChange emptied encrypted ended error gotPointerCapture input invalid keyDown keyPress keyUp load loadedData loadedMetadata loadStart lostPointerCapture mouseDown mouseMove mouseOut mouseOver mouseUp paste pause play playing pointerCancel pointerDown pointerMove pointerOut pointerOver pointerUp progress rateChange reset resize seeked seeking stalled submit suspend timeUpdate touchCancel touchEnd touchStart volumeChange scroll toggle touchMove waiting wheel".split(" ");function li(e,t){D0.set(e,t),Ui(t,[e])}for(var Ah=0;Ah<Mj.length;Ah++){var Th=Mj[Ah],MR=Th.toLowerCase(),OR=Th[0].toUpperCase()+Th.slice(1);li(MR,"on"+OR)}li(P0,"onAnimationEnd");li($0,"onAnimationIteration");li(M0,"onAnimationStart");li("dblclick","onDoubleClick");li("focusin","onFocus");li("focusout","onBlur");li(O0,"onTransitionEnd");Ma("onMouseEnter",["mouseout","mouseover"]);Ma("onMouseLeave",["mouseout","mouseover"]);Ma("onPointerEnter",["pointerout","pointerover"]);Ma("onPointerLeave",["pointerout","pointerover"]);Ui("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Ui("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Ui("onBeforeInput",["compositionend","keypress","textInput","paste"]);Ui("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Ui("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Ui("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Dl="abort canplay canplaythrough durationchange emptied encrypted ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange resize seeked seeking stalled suspend timeupdate volumechange waiting".split(" "),DR=new Set("cancel close invalid load scroll toggle".split(" ").concat(Dl));function Oj(e,t,s){var r=e.type||"unknown-event";e.currentTarget=s,MT(r,t,void 0,e),e.currentTarget=null}function _0(e,t){t=(t&4)!==0;for(var s=0;s<e.length;s++){var r=e[s],i=r.event;r=r.listeners;e:{var a=void 0;if(t)for(var l=r.length-1;0<=l;l--){var o=r[l],c=o.instance,u=o.currentTarget;if(o=o.listener,c!==a&&i.isPropagationStopped())break e;Oj(i,o,u),a=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,u=o.currentTarget,o=o.listener,c!==a&&i.isPropagationStopped())break e;Oj(i,o,u),a=c}}}if(ku)throw e=Zf,ku=!1,Zf=null,e}function ot(e,t){var s=t[cm];s===void 0&&(s=t[cm]=new Set);var r=e+"__bubble";s.has(r)||(L0(t,e,2,!1),s.add(r))}function Rh(e,t,s){var r=0;t&&(r|=4),L0(s,e,r,t)}var gc="_reactListening"+Math.random().toString(36).slice(2);function lo(e){if(!e[gc]){e[gc]=!0,Kb.forEach(function(s){s!=="selectionchange"&&(DR.has(s)||Rh(s,!1,e),Rh(s,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[gc]||(t[gc]=!0,Rh("selectionchange",!1,t))}}function L0(e,t,s,r){switch(w0(t)){case 1:var i=QT;break;case 4:i=JT;break;default:i=mg}s=i.bind(null,t,s,e),i=void 0,!Xf||t!=="touchstart"&&t!=="touchmove"&&t!=="wheel"||(i=!0),r?i!==void 0?e.addEventListener(t,s,{capture:!0,passive:i}):e.addEventListener(t,s,!0):i!==void 0?e.addEventListener(t,s,{passive:i}):e.addEventListener(t,s,!1)}function Ih(e,t,s,r,i){var a=r;if(!(t&1)&&!(t&2)&&r!==null)e:for(;;){if(r===null)return;var l=r.tag;if(l===3||l===4){var o=r.stateNode.containerInfo;if(o===i||o.nodeType===8&&o.parentNode===i)break;if(l===4)for(l=r.return;l!==null;){var c=l.tag;if((c===3||c===4)&&(c=l.stateNode.containerInfo,c===i||c.nodeType===8&&c.parentNode===i))return;l=l.return}for(;o!==null;){if(l=Si(o),l===null)return;if(c=l.tag,c===5||c===6){r=a=l;continue e}o=o.parentNode}}r=r.return}l0(function(){var u=a,d=ug(s),h=[];e:{var m=D0.get(e);if(m!==void 0){var p=gg,g=e;switch(e){case"keypress":if(Zc(s)===0)break e;case"keydown":case"keyup":p=hR;break;case"focusin":g="focus",p=Sh;break;case"focusout":g="blur",p=Sh;break;case"beforeblur":case"afterblur":p=Sh;break;case"click":if(s.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":p=kj;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=eR;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=pR;break;case P0:case $0:case M0:p=sR;break;case O0:p=xR;break;case"scroll":p=XT;break;case"wheel":p=jR;break;case"copy":case"cut":case"paste":p=iR;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=Nj}var y=(t&4)!==0,b=!y&&e==="scroll",x=y?m!==null?m+"Capture":null:m;y=[];for(var v=u,j;v!==null;){j=v;var w=j.stateNode;if(j.tag===5&&w!==null&&(j=w,x!==null&&(w=to(v,x),w!=null&&y.push(oo(v,w,j)))),b)break;v=v.return}0<y.length&&(m=new p(m,g,null,s,d),h.push({event:m,listeners:y}))}}if(!(t&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==Qf&&(g=s.relatedTarget||s.fromElement)&&(Si(g)||g[dr]))break e;if((p||m)&&(m=d.window===d?d:(m=d.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?Si(g):null,g!==null&&(b=Bi(g),g!==b||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(y=kj,w="onMouseLeave",x="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(y=Nj,w="onPointerLeave",x="onPointerEnter",v="pointer"),b=p==null?m:fa(p),j=g==null?m:fa(g),m=new y(w,v+"leave",p,s,d),m.target=b,m.relatedTarget=j,w=null,Si(d)===u&&(y=new y(x,v+"enter",g,s,d),y.target=j,y.relatedTarget=b,w=y),b=w,p&&g)t:{for(y=p,x=g,v=0,j=y;j;j=Zi(j))v++;for(j=0,w=x;w;w=Zi(w))j++;for(;0<v-j;)y=Zi(y),v--;for(;0<j-v;)x=Zi(x),j--;for(;v--;){if(y===x||x!==null&&y===x.alternate)break t;y=Zi(y),x=Zi(x)}y=null}else y=null;p!==null&&Dj(h,m,p,y,!1),g!==null&&b!==null&&Dj(h,b,g,y,!0)}}e:{if(m=u?fa(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var S=CR;else if(Aj(m))if(E0)S=RR;else{S=AR;var k=ER}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(S=TR);if(S&&(S=S(e,u))){C0(h,S,s,d);break e}k&&k(e,m,u),e==="focusout"&&(k=m._wrapperState)&&k.controlled&&m.type==="number"&&Kf(m,"number",m.value)}switch(k=u?fa(u):window,e){case"focusin":(Aj(k)||k.contentEditable==="true")&&(da=k,sm=u,Wl=null);break;case"focusout":Wl=sm=da=null;break;case"mousedown":rm=!0;break;case"contextmenu":case"mouseup":case"dragend":rm=!1,$j(h,s,d);break;case"selectionchange":if($R)break;case"keydown":case"keyup":$j(h,s,d)}var N;if(vg)e:{switch(e){case"compositionstart":var C="onCompositionStart";break e;case"compositionend":C="onCompositionEnd";break e;case"compositionupdate":C="onCompositionUpdate";break e}C=void 0}else ua?S0(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(k0&&s.locale!=="ko"&&(ua||C!=="onCompositionStart"?C==="onCompositionEnd"&&ua&&(N=b0()):($r=d,pg="value"in $r?$r.value:$r.textContent,ua=!0)),k=Au(u,C),0<k.length&&(C=new Sj(C,e,null,s,d),h.push({event:C,listeners:k}),N?C.data=N:(N=N0(s),N!==null&&(C.data=N)))),(N=wR?bR(e,s):kR(e,s))&&(u=Au(u,"onBeforeInput"),0<u.length&&(d=new Sj("onBeforeInput","beforeinput",null,s,d),h.push({event:d,listeners:u}),d.data=N))}_0(h,t)})}function oo(e,t,s){return{instance:e,listener:t,currentTarget:s}}function Au(e,t){for(var s=t+"Capture",r=[];e!==null;){var i=e,a=i.stateNode;i.tag===5&&a!==null&&(i=a,a=to(e,s),a!=null&&r.unshift(oo(e,a,i)),a=to(e,t),a!=null&&r.push(oo(e,a,i))),e=e.return}return r}function Zi(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function Dj(e,t,s,r,i){for(var a=t._reactName,l=[];s!==null&&s!==r;){var o=s,c=o.alternate,u=o.stateNode;if(c!==null&&c===r)break;o.tag===5&&u!==null&&(o=u,i?(c=to(s,a),c!=null&&l.unshift(oo(s,c,o))):i||(c=to(s,a),c!=null&&l.push(oo(s,c,o)))),s=s.return}l.length!==0&&e.push({event:t,listeners:l})}var _R=/\r\n?/g,LR=/\u0000|\uFFFD/g;function _j(e){return(typeof e=="string"?e:""+e).replace(_R,`
|
|
38
|
+
`).replace(LR,"")}function xc(e,t,s){if(t=_j(t),_j(e)!==t&&s)throw Error(ae(425))}function Tu(){}var im=null,am=null;function lm(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var om=typeof setTimeout=="function"?setTimeout:void 0,FR=typeof clearTimeout=="function"?clearTimeout:void 0,Lj=typeof Promise=="function"?Promise:void 0,zR=typeof queueMicrotask=="function"?queueMicrotask:typeof Lj<"u"?function(e){return Lj.resolve(null).then(e).catch(UR)}:om;function UR(e){setTimeout(function(){throw e})}function Ph(e,t){var s=t,r=0;do{var i=s.nextSibling;if(e.removeChild(s),i&&i.nodeType===8)if(s=i.data,s==="/$"){if(r===0){e.removeChild(i),ro(t);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=i}while(s);ro(t)}function Br(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?")break;if(t==="/$")return null}}return e}function Fj(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="$"||s==="$!"||s==="$?"){if(t===0)return e;t--}else s==="/$"&&t++}e=e.previousSibling}return null}var tl=Math.random().toString(36).slice(2),_s="__reactFiber$"+tl,co="__reactProps$"+tl,dr="__reactContainer$"+tl,cm="__reactEvents$"+tl,BR="__reactListeners$"+tl,WR="__reactHandles$"+tl;function Si(e){var t=e[_s];if(t)return t;for(var s=e.parentNode;s;){if(t=s[dr]||s[_s]){if(s=t.alternate,t.child!==null||s!==null&&s.child!==null)for(e=Fj(e);e!==null;){if(s=e[_s])return s;e=Fj(e)}return t}e=s,s=e.parentNode}return null}function Lo(e){return e=e[_s]||e[dr],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function fa(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(ae(33))}function yd(e){return e[co]||null}var um=[],ma=-1;function oi(e){return{current:e}}function ct(e){0>ma||(e.current=um[ma],um[ma]=null,ma--)}function lt(e,t){ma++,um[ma]=e.current,e.current=t}var Zr={},dn=oi(Zr),Cn=oi(!1),Ri=Zr;function Oa(e,t){var s=e.type.contextTypes;if(!s)return Zr;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in s)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function En(e){return e=e.childContextTypes,e!=null}function Ru(){ct(Cn),ct(dn)}function zj(e,t,s){if(dn.current!==Zr)throw Error(ae(168));lt(dn,t),lt(Cn,s)}function F0(e,t,s){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var i in r)if(!(i in t))throw Error(ae(108,ET(e)||"Unknown",i));return wt({},s,r)}function Iu(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Zr,Ri=dn.current,lt(dn,e),lt(Cn,Cn.current),!0}function Uj(e,t,s){var r=e.stateNode;if(!r)throw Error(ae(169));s?(e=F0(e,t,Ri),r.__reactInternalMemoizedMergedChildContext=e,ct(Cn),ct(dn),lt(dn,e)):ct(Cn),lt(Cn,s)}var tr=null,wd=!1,$h=!1;function z0(e){tr===null?tr=[e]:tr.push(e)}function HR(e){wd=!0,z0(e)}function ci(){if(!$h&&tr!==null){$h=!0;var e=0,t=st;try{var s=tr;for(st=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}tr=null,wd=!1}catch(i){throw tr!==null&&(tr=tr.slice(e+1)),d0(dg,ci),i}finally{st=t,$h=!1}}return null}var pa=[],ga=0,Pu=null,$u=0,ts=[],ns=0,Ii=null,rr=1,ir="";function yi(e,t){pa[ga++]=$u,pa[ga++]=Pu,Pu=e,$u=t}function U0(e,t,s){ts[ns++]=rr,ts[ns++]=ir,ts[ns++]=Ii,Ii=e;var r=rr;e=ir;var i=32-gs(r)-1;r&=~(1<<i),s+=1;var a=32-gs(t)+i;if(30<a){var l=i-i%5;a=(r&(1<<l)-1).toString(32),r>>=l,i-=l,rr=1<<32-gs(t)+i|s<<i|r,ir=a+e}else rr=1<<a|s<<i|r,ir=e}function yg(e){e.return!==null&&(yi(e,1),U0(e,1,0))}function wg(e){for(;e===Pu;)Pu=pa[--ga],pa[ga]=null,$u=pa[--ga],pa[ga]=null;for(;e===Ii;)Ii=ts[--ns],ts[ns]=null,ir=ts[--ns],ts[ns]=null,rr=ts[--ns],ts[ns]=null}var Un=null,Fn=null,ht=!1,ms=null;function B0(e,t){var s=is(5,null,null,0);s.elementType="DELETED",s.stateNode=t,s.return=e,t=e.deletions,t===null?(e.deletions=[s],e.flags|=16):t.push(s)}function Bj(e,t){switch(e.tag){case 5:var s=e.type;return t=t.nodeType!==1||s.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,Un=e,Fn=Br(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,Un=e,Fn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(s=Ii!==null?{id:rr,overflow:ir}:null,e.memoizedState={dehydrated:t,treeContext:s,retryLane:1073741824},s=is(18,null,null,0),s.stateNode=t,s.return=e,e.child=s,Un=e,Fn=null,!0):!1;default:return!1}}function dm(e){return(e.mode&1)!==0&&(e.flags&128)===0}function hm(e){if(ht){var t=Fn;if(t){var s=t;if(!Bj(e,t)){if(dm(e))throw Error(ae(418));t=Br(s.nextSibling);var r=Un;t&&Bj(e,t)?B0(r,s):(e.flags=e.flags&-4097|2,ht=!1,Un=e)}}else{if(dm(e))throw Error(ae(418));e.flags=e.flags&-4097|2,ht=!1,Un=e}}}function Wj(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Un=e}function vc(e){if(e!==Un)return!1;if(!ht)return Wj(e),ht=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!lm(e.type,e.memoizedProps)),t&&(t=Fn)){if(dm(e))throw W0(),Error(ae(418));for(;t;)B0(e,t),t=Br(t.nextSibling)}if(Wj(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(ae(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(t===0){Fn=Br(e.nextSibling);break e}t--}else s!=="$"&&s!=="$!"&&s!=="$?"||t++}e=e.nextSibling}Fn=null}}else Fn=Un?Br(e.stateNode.nextSibling):null;return!0}function W0(){for(var e=Fn;e;)e=Br(e.nextSibling)}function Da(){Fn=Un=null,ht=!1}function bg(e){ms===null?ms=[e]:ms.push(e)}var KR=vr.ReactCurrentBatchConfig;function Sl(e,t,s){if(e=s.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(s._owner){if(s=s._owner,s){if(s.tag!==1)throw Error(ae(309));var r=s.stateNode}if(!r)throw Error(ae(147,e));var i=r,a=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===a?t.ref:(t=function(l){var o=i.refs;l===null?delete o[a]:o[a]=l},t._stringRef=a,t)}if(typeof e!="string")throw Error(ae(284));if(!s._owner)throw Error(ae(290,e))}return e}function jc(e,t){throw e=Object.prototype.toString.call(t),Error(ae(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function Hj(e){var t=e._init;return t(e._payload)}function H0(e){function t(x,v){if(e){var j=x.deletions;j===null?(x.deletions=[v],x.flags|=16):j.push(v)}}function s(x,v){if(!e)return null;for(;v!==null;)t(x,v),v=v.sibling;return null}function r(x,v){for(x=new Map;v!==null;)v.key!==null?x.set(v.key,v):x.set(v.index,v),v=v.sibling;return x}function i(x,v){return x=Vr(x,v),x.index=0,x.sibling=null,x}function a(x,v,j){return x.index=j,e?(j=x.alternate,j!==null?(j=j.index,j<v?(x.flags|=2,v):j):(x.flags|=2,v)):(x.flags|=1048576,v)}function l(x){return e&&x.alternate===null&&(x.flags|=2),x}function o(x,v,j,w){return v===null||v.tag!==6?(v=zh(j,x.mode,w),v.return=x,v):(v=i(v,j),v.return=x,v)}function c(x,v,j,w){var S=j.type;return S===ca?d(x,v,j.props.children,w,j.key):v!==null&&(v.elementType===S||typeof S=="object"&&S!==null&&S.$$typeof===Tr&&Hj(S)===v.type)?(w=i(v,j.props),w.ref=Sl(x,v,j),w.return=x,w):(w=au(j.type,j.key,j.props,null,x.mode,w),w.ref=Sl(x,v,j),w.return=x,w)}function u(x,v,j,w){return v===null||v.tag!==4||v.stateNode.containerInfo!==j.containerInfo||v.stateNode.implementation!==j.implementation?(v=Uh(j,x.mode,w),v.return=x,v):(v=i(v,j.children||[]),v.return=x,v)}function d(x,v,j,w,S){return v===null||v.tag!==7?(v=Ai(j,x.mode,w,S),v.return=x,v):(v=i(v,j),v.return=x,v)}function h(x,v,j){if(typeof v=="string"&&v!==""||typeof v=="number")return v=zh(""+v,x.mode,j),v.return=x,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case oc:return j=au(v.type,v.key,v.props,null,x.mode,j),j.ref=Sl(x,null,v),j.return=x,j;case oa:return v=Uh(v,x.mode,j),v.return=x,v;case Tr:var w=v._init;return h(x,w(v._payload),j)}if(Ml(v)||jl(v))return v=Ai(v,x.mode,j,null),v.return=x,v;jc(x,v)}return null}function m(x,v,j,w){var S=v!==null?v.key:null;if(typeof j=="string"&&j!==""||typeof j=="number")return S!==null?null:o(x,v,""+j,w);if(typeof j=="object"&&j!==null){switch(j.$$typeof){case oc:return j.key===S?c(x,v,j,w):null;case oa:return j.key===S?u(x,v,j,w):null;case Tr:return S=j._init,m(x,v,S(j._payload),w)}if(Ml(j)||jl(j))return S!==null?null:d(x,v,j,w,null);jc(x,j)}return null}function p(x,v,j,w,S){if(typeof w=="string"&&w!==""||typeof w=="number")return x=x.get(j)||null,o(v,x,""+w,S);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case oc:return x=x.get(w.key===null?j:w.key)||null,c(v,x,w,S);case oa:return x=x.get(w.key===null?j:w.key)||null,u(v,x,w,S);case Tr:var k=w._init;return p(x,v,j,k(w._payload),S)}if(Ml(w)||jl(w))return x=x.get(j)||null,d(v,x,w,S,null);jc(v,w)}return null}function g(x,v,j,w){for(var S=null,k=null,N=v,C=v=0,I=null;N!==null&&C<j.length;C++){N.index>C?(I=N,N=null):I=N.sibling;var A=m(x,N,j[C],w);if(A===null){N===null&&(N=I);break}e&&N&&A.alternate===null&&t(x,N),v=a(A,v,C),k===null?S=A:k.sibling=A,k=A,N=I}if(C===j.length)return s(x,N),ht&&yi(x,C),S;if(N===null){for(;C<j.length;C++)N=h(x,j[C],w),N!==null&&(v=a(N,v,C),k===null?S=N:k.sibling=N,k=N);return ht&&yi(x,C),S}for(N=r(x,N);C<j.length;C++)I=p(N,x,C,j[C],w),I!==null&&(e&&I.alternate!==null&&N.delete(I.key===null?C:I.key),v=a(I,v,C),k===null?S=I:k.sibling=I,k=I);return e&&N.forEach(function(_){return t(x,_)}),ht&&yi(x,C),S}function y(x,v,j,w){var S=jl(j);if(typeof S!="function")throw Error(ae(150));if(j=S.call(j),j==null)throw Error(ae(151));for(var k=S=null,N=v,C=v=0,I=null,A=j.next();N!==null&&!A.done;C++,A=j.next()){N.index>C?(I=N,N=null):I=N.sibling;var _=m(x,N,A.value,w);if(_===null){N===null&&(N=I);break}e&&N&&_.alternate===null&&t(x,N),v=a(_,v,C),k===null?S=_:k.sibling=_,k=_,N=I}if(A.done)return s(x,N),ht&&yi(x,C),S;if(N===null){for(;!A.done;C++,A=j.next())A=h(x,A.value,w),A!==null&&(v=a(A,v,C),k===null?S=A:k.sibling=A,k=A);return ht&&yi(x,C),S}for(N=r(x,N);!A.done;C++,A=j.next())A=p(N,x,C,A.value,w),A!==null&&(e&&A.alternate!==null&&N.delete(A.key===null?C:A.key),v=a(A,v,C),k===null?S=A:k.sibling=A,k=A);return e&&N.forEach(function(z){return t(x,z)}),ht&&yi(x,C),S}function b(x,v,j,w){if(typeof j=="object"&&j!==null&&j.type===ca&&j.key===null&&(j=j.props.children),typeof j=="object"&&j!==null){switch(j.$$typeof){case oc:e:{for(var S=j.key,k=v;k!==null;){if(k.key===S){if(S=j.type,S===ca){if(k.tag===7){s(x,k.sibling),v=i(k,j.props.children),v.return=x,x=v;break e}}else if(k.elementType===S||typeof S=="object"&&S!==null&&S.$$typeof===Tr&&Hj(S)===k.type){s(x,k.sibling),v=i(k,j.props),v.ref=Sl(x,k,j),v.return=x,x=v;break e}s(x,k);break}else t(x,k);k=k.sibling}j.type===ca?(v=Ai(j.props.children,x.mode,w,j.key),v.return=x,x=v):(w=au(j.type,j.key,j.props,null,x.mode,w),w.ref=Sl(x,v,j),w.return=x,x=w)}return l(x);case oa:e:{for(k=j.key;v!==null;){if(v.key===k)if(v.tag===4&&v.stateNode.containerInfo===j.containerInfo&&v.stateNode.implementation===j.implementation){s(x,v.sibling),v=i(v,j.children||[]),v.return=x,x=v;break e}else{s(x,v);break}else t(x,v);v=v.sibling}v=Uh(j,x.mode,w),v.return=x,x=v}return l(x);case Tr:return k=j._init,b(x,v,k(j._payload),w)}if(Ml(j))return g(x,v,j,w);if(jl(j))return y(x,v,j,w);jc(x,j)}return typeof j=="string"&&j!==""||typeof j=="number"?(j=""+j,v!==null&&v.tag===6?(s(x,v.sibling),v=i(v,j),v.return=x,x=v):(s(x,v),v=zh(j,x.mode,w),v.return=x,x=v),l(x)):s(x,v)}return b}var _a=H0(!0),K0=H0(!1),Mu=oi(null),Ou=null,xa=null,kg=null;function Sg(){kg=xa=Ou=null}function Ng(e){var t=Mu.current;ct(Mu),e._currentValue=t}function fm(e,t,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===s)break;e=e.return}}function Ca(e,t){Ou=e,kg=xa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(Sn=!0),e.firstContext=null)}function os(e){var t=e._currentValue;if(kg!==e)if(e={context:e,memoizedValue:t,next:null},xa===null){if(Ou===null)throw Error(ae(308));xa=e,Ou.dependencies={lanes:0,firstContext:e}}else xa=xa.next=e;return t}var Ni=null;function Cg(e){Ni===null?Ni=[e]:Ni.push(e)}function V0(e,t,s,r){var i=t.interleaved;return i===null?(s.next=s,Cg(t)):(s.next=i.next,i.next=s),t.interleaved=s,hr(e,r)}function hr(e,t){e.lanes|=t;var s=e.alternate;for(s!==null&&(s.lanes|=t),s=e,e=e.return;e!==null;)e.childLanes|=t,s=e.alternate,s!==null&&(s.childLanes|=t),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Rr=!1;function Eg(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function G0(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function ar(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Wr(e,t,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,qe&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,hr(e,s)}return i=r.interleaved,i===null?(t.next=t,Cg(r)):(t.next=i.next,i.next=t),r.interleaved=t,hr(e,s)}function eu(e,t,s){if(t=t.updateQueue,t!==null&&(t=t.shared,(s&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,hg(e,s)}}function Kj(e,t){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var i=null,a=null;if(s=s.firstBaseUpdate,s!==null){do{var l={eventTime:s.eventTime,lane:s.lane,tag:s.tag,payload:s.payload,callback:s.callback,next:null};a===null?i=a=l:a=a.next=l,s=s.next}while(s!==null);a===null?i=a=t:a=a.next=t}else i=a=t;s={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=t:e.next=t,s.lastBaseUpdate=t}function Du(e,t,s,r){var i=e.updateQueue;Rr=!1;var a=i.firstBaseUpdate,l=i.lastBaseUpdate,o=i.shared.pending;if(o!==null){i.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?a=u:l.next=u,l=c;var d=e.alternate;d!==null&&(d=d.updateQueue,o=d.lastBaseUpdate,o!==l&&(o===null?d.firstBaseUpdate=u:o.next=u,d.lastBaseUpdate=c))}if(a!==null){var h=i.baseState;l=0,d=u=c=null,o=a;do{var m=o.lane,p=o.eventTime;if((r&m)===m){d!==null&&(d=d.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,y=o;switch(m=t,p=s,y.tag){case 1:if(g=y.payload,typeof g=="function"){h=g.call(p,h,m);break e}h=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=y.payload,m=typeof g=="function"?g.call(p,h,m):g,m==null)break e;h=wt({},h,m);break e;case 2:Rr=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=i.effects,m===null?i.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},d===null?(u=d=p,c=h):d=d.next=p,l|=m;if(o=o.next,o===null){if(o=i.shared.pending,o===null)break;m=o,o=m.next,m.next=null,i.lastBaseUpdate=m,i.shared.pending=null}}while(!0);if(d===null&&(c=h),i.baseState=c,i.firstBaseUpdate=u,i.lastBaseUpdate=d,t=i.shared.interleaved,t!==null){i=t;do l|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);$i|=l,e.lanes=l,e.memoizedState=h}}function Vj(e,t,s){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],i=r.callback;if(i!==null){if(r.callback=null,r=s,typeof i!="function")throw Error(ae(191,i));i.call(r)}}}var Fo={},Bs=oi(Fo),uo=oi(Fo),ho=oi(Fo);function Ci(e){if(e===Fo)throw Error(ae(174));return e}function Ag(e,t){switch(lt(ho,t),lt(uo,e),lt(Bs,Fo),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Gf(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Gf(t,e)}ct(Bs),lt(Bs,t)}function La(){ct(Bs),ct(uo),ct(ho)}function Y0(e){Ci(ho.current);var t=Ci(Bs.current),s=Gf(t,e.type);t!==s&&(lt(uo,e),lt(Bs,s))}function Tg(e){uo.current===e&&(ct(Bs),ct(uo))}var pt=oi(0);function _u(e){for(var t=e;t!==null;){if(t.tag===13){var s=t.memoizedState;if(s!==null&&(s=s.dehydrated,s===null||s.data==="$?"||s.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var Mh=[];function Rg(){for(var e=0;e<Mh.length;e++)Mh[e]._workInProgressVersionPrimary=null;Mh.length=0}var tu=vr.ReactCurrentDispatcher,Oh=vr.ReactCurrentBatchConfig,Pi=0,vt=null,Ot=null,Bt=null,Lu=!1,Hl=!1,fo=0,VR=0;function rn(){throw Error(ae(321))}function Ig(e,t){if(t===null)return!1;for(var s=0;s<t.length&&s<e.length;s++)if(!ws(e[s],t[s]))return!1;return!0}function Pg(e,t,s,r,i,a){if(Pi=a,vt=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,tu.current=e===null||e.memoizedState===null?QR:JR,e=s(r,i),Hl){a=0;do{if(Hl=!1,fo=0,25<=a)throw Error(ae(301));a+=1,Bt=Ot=null,t.updateQueue=null,tu.current=XR,e=s(r,i)}while(Hl)}if(tu.current=Fu,t=Ot!==null&&Ot.next!==null,Pi=0,Bt=Ot=vt=null,Lu=!1,t)throw Error(ae(300));return e}function $g(){var e=fo!==0;return fo=0,e}function Os(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Bt===null?vt.memoizedState=Bt=e:Bt=Bt.next=e,Bt}function cs(){if(Ot===null){var e=vt.alternate;e=e!==null?e.memoizedState:null}else e=Ot.next;var t=Bt===null?vt.memoizedState:Bt.next;if(t!==null)Bt=t,Ot=e;else{if(e===null)throw Error(ae(310));Ot=e,e={memoizedState:Ot.memoizedState,baseState:Ot.baseState,baseQueue:Ot.baseQueue,queue:Ot.queue,next:null},Bt===null?vt.memoizedState=Bt=e:Bt=Bt.next=e}return Bt}function mo(e,t){return typeof t=="function"?t(e):t}function Dh(e){var t=cs(),s=t.queue;if(s===null)throw Error(ae(311));s.lastRenderedReducer=e;var r=Ot,i=r.baseQueue,a=s.pending;if(a!==null){if(i!==null){var l=i.next;i.next=a.next,a.next=l}r.baseQueue=i=a,s.pending=null}if(i!==null){a=i.next,r=r.baseState;var o=l=null,c=null,u=a;do{var d=u.lane;if((Pi&d)===d)c!==null&&(c=c.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),r=u.hasEagerState?u.eagerState:e(r,u.action);else{var h={lane:d,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=h,l=r):c=c.next=h,vt.lanes|=d,$i|=d}u=u.next}while(u!==null&&u!==a);c===null?l=r:c.next=o,ws(r,t.memoizedState)||(Sn=!0),t.memoizedState=r,t.baseState=l,t.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){i=e;do a=i.lane,vt.lanes|=a,$i|=a,i=i.next;while(i!==e)}else i===null&&(s.lanes=0);return[t.memoizedState,s.dispatch]}function _h(e){var t=cs(),s=t.queue;if(s===null)throw Error(ae(311));s.lastRenderedReducer=e;var r=s.dispatch,i=s.pending,a=t.memoizedState;if(i!==null){s.pending=null;var l=i=i.next;do a=e(a,l.action),l=l.next;while(l!==i);ws(a,t.memoizedState)||(Sn=!0),t.memoizedState=a,t.baseQueue===null&&(t.baseState=a),s.lastRenderedState=a}return[a,r]}function q0(){}function Q0(e,t){var s=vt,r=cs(),i=t(),a=!ws(r.memoizedState,i);if(a&&(r.memoizedState=i,Sn=!0),r=r.queue,Mg(Z0.bind(null,s,r,e),[e]),r.getSnapshot!==t||a||Bt!==null&&Bt.memoizedState.tag&1){if(s.flags|=2048,po(9,X0.bind(null,s,r,i,t),void 0,null),Kt===null)throw Error(ae(349));Pi&30||J0(s,t,i)}return i}function J0(e,t,s){e.flags|=16384,e={getSnapshot:t,value:s},t=vt.updateQueue,t===null?(t={lastEffect:null,stores:null},vt.updateQueue=t,t.stores=[e]):(s=t.stores,s===null?t.stores=[e]:s.push(e))}function X0(e,t,s,r){t.value=s,t.getSnapshot=r,ek(t)&&tk(e)}function Z0(e,t,s){return s(function(){ek(t)&&tk(e)})}function ek(e){var t=e.getSnapshot;e=e.value;try{var s=t();return!ws(e,s)}catch{return!0}}function tk(e){var t=hr(e,1);t!==null&&xs(t,e,1,-1)}function Gj(e){var t=Os();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:mo,lastRenderedState:e},t.queue=e,e=e.dispatch=qR.bind(null,vt,e),[t.memoizedState,e]}function po(e,t,s,r){return e={tag:e,create:t,destroy:s,deps:r,next:null},t=vt.updateQueue,t===null?(t={lastEffect:null,stores:null},vt.updateQueue=t,t.lastEffect=e.next=e):(s=t.lastEffect,s===null?t.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,t.lastEffect=e)),e}function nk(){return cs().memoizedState}function nu(e,t,s,r){var i=Os();vt.flags|=e,i.memoizedState=po(1|t,s,void 0,r===void 0?null:r)}function bd(e,t,s,r){var i=cs();r=r===void 0?null:r;var a=void 0;if(Ot!==null){var l=Ot.memoizedState;if(a=l.destroy,r!==null&&Ig(r,l.deps)){i.memoizedState=po(t,s,a,r);return}}vt.flags|=e,i.memoizedState=po(1|t,s,a,r)}function Yj(e,t){return nu(8390656,8,e,t)}function Mg(e,t){return bd(2048,8,e,t)}function sk(e,t){return bd(4,2,e,t)}function rk(e,t){return bd(4,4,e,t)}function ik(e,t){if(typeof t=="function")return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function ak(e,t,s){return s=s!=null?s.concat([e]):null,bd(4,4,ik.bind(null,t,e),s)}function Og(){}function lk(e,t){var s=cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Ig(t,r[1])?r[0]:(s.memoizedState=[e,t],e)}function ok(e,t){var s=cs();t=t===void 0?null:t;var r=s.memoizedState;return r!==null&&t!==null&&Ig(t,r[1])?r[0]:(e=e(),s.memoizedState=[e,t],e)}function ck(e,t,s){return Pi&21?(ws(s,t)||(s=m0(),vt.lanes|=s,$i|=s,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Sn=!0),e.memoizedState=s)}function GR(e,t){var s=st;st=s!==0&&4>s?s:4,e(!0);var r=Oh.transition;Oh.transition={};try{e(!1),t()}finally{st=s,Oh.transition=r}}function uk(){return cs().memoizedState}function YR(e,t,s){var r=Kr(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},dk(e))hk(t,s);else if(s=V0(e,t,s,r),s!==null){var i=xn();xs(s,e,r,i),fk(s,t,r)}}function qR(e,t,s){var r=Kr(e),i={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(dk(e))hk(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var l=t.lastRenderedState,o=a(l,s);if(i.hasEagerState=!0,i.eagerState=o,ws(o,l)){var c=t.interleaved;c===null?(i.next=i,Cg(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}finally{}s=V0(e,t,i,r),s!==null&&(i=xn(),xs(s,e,r,i),fk(s,t,r))}}function dk(e){var t=e.alternate;return e===vt||t!==null&&t===vt}function hk(e,t){Hl=Lu=!0;var s=e.pending;s===null?t.next=t:(t.next=s.next,s.next=t),e.pending=t}function fk(e,t,s){if(s&4194240){var r=t.lanes;r&=e.pendingLanes,s|=r,t.lanes=s,hg(e,s)}}var Fu={readContext:os,useCallback:rn,useContext:rn,useEffect:rn,useImperativeHandle:rn,useInsertionEffect:rn,useLayoutEffect:rn,useMemo:rn,useReducer:rn,useRef:rn,useState:rn,useDebugValue:rn,useDeferredValue:rn,useTransition:rn,useMutableSource:rn,useSyncExternalStore:rn,useId:rn,unstable_isNewReconciler:!1},QR={readContext:os,useCallback:function(e,t){return Os().memoizedState=[e,t===void 0?null:t],e},useContext:os,useEffect:Yj,useImperativeHandle:function(e,t,s){return s=s!=null?s.concat([e]):null,nu(4194308,4,ik.bind(null,t,e),s)},useLayoutEffect:function(e,t){return nu(4194308,4,e,t)},useInsertionEffect:function(e,t){return nu(4,2,e,t)},useMemo:function(e,t){var s=Os();return t=t===void 0?null:t,e=e(),s.memoizedState=[e,t],e},useReducer:function(e,t,s){var r=Os();return t=s!==void 0?s(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=YR.bind(null,vt,e),[r.memoizedState,e]},useRef:function(e){var t=Os();return e={current:e},t.memoizedState=e},useState:Gj,useDebugValue:Og,useDeferredValue:function(e){return Os().memoizedState=e},useTransition:function(){var e=Gj(!1),t=e[0];return e=GR.bind(null,e[1]),Os().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,s){var r=vt,i=Os();if(ht){if(s===void 0)throw Error(ae(407));s=s()}else{if(s=t(),Kt===null)throw Error(ae(349));Pi&30||J0(r,t,s)}i.memoizedState=s;var a={value:s,getSnapshot:t};return i.queue=a,Yj(Z0.bind(null,r,a,e),[e]),r.flags|=2048,po(9,X0.bind(null,r,a,s,t),void 0,null),s},useId:function(){var e=Os(),t=Kt.identifierPrefix;if(ht){var s=ir,r=rr;s=(r&~(1<<32-gs(r)-1)).toString(32)+s,t=":"+t+"R"+s,s=fo++,0<s&&(t+="H"+s.toString(32)),t+=":"}else s=VR++,t=":"+t+"r"+s.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},JR={readContext:os,useCallback:lk,useContext:os,useEffect:Mg,useImperativeHandle:ak,useInsertionEffect:sk,useLayoutEffect:rk,useMemo:ok,useReducer:Dh,useRef:nk,useState:function(){return Dh(mo)},useDebugValue:Og,useDeferredValue:function(e){var t=cs();return ck(t,Ot.memoizedState,e)},useTransition:function(){var e=Dh(mo)[0],t=cs().memoizedState;return[e,t]},useMutableSource:q0,useSyncExternalStore:Q0,useId:uk,unstable_isNewReconciler:!1},XR={readContext:os,useCallback:lk,useContext:os,useEffect:Mg,useImperativeHandle:ak,useInsertionEffect:sk,useLayoutEffect:rk,useMemo:ok,useReducer:_h,useRef:nk,useState:function(){return _h(mo)},useDebugValue:Og,useDeferredValue:function(e){var t=cs();return Ot===null?t.memoizedState=e:ck(t,Ot.memoizedState,e)},useTransition:function(){var e=_h(mo)[0],t=cs().memoizedState;return[e,t]},useMutableSource:q0,useSyncExternalStore:Q0,useId:uk,unstable_isNewReconciler:!1};function hs(e,t){if(e&&e.defaultProps){t=wt({},t),e=e.defaultProps;for(var s in e)t[s]===void 0&&(t[s]=e[s]);return t}return t}function mm(e,t,s,r){t=e.memoizedState,s=s(r,t),s=s==null?t:wt({},t,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var kd={isMounted:function(e){return(e=e._reactInternals)?Bi(e)===e:!1},enqueueSetState:function(e,t,s){e=e._reactInternals;var r=xn(),i=Kr(e),a=ar(r,i);a.payload=t,s!=null&&(a.callback=s),t=Wr(e,a,i),t!==null&&(xs(t,e,i,r),eu(t,e,i))},enqueueReplaceState:function(e,t,s){e=e._reactInternals;var r=xn(),i=Kr(e),a=ar(r,i);a.tag=1,a.payload=t,s!=null&&(a.callback=s),t=Wr(e,a,i),t!==null&&(xs(t,e,i,r),eu(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var s=xn(),r=Kr(e),i=ar(s,r);i.tag=2,t!=null&&(i.callback=t),t=Wr(e,i,r),t!==null&&(xs(t,e,r,s),eu(t,e,r))}};function qj(e,t,s,r,i,a,l){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,a,l):t.prototype&&t.prototype.isPureReactComponent?!ao(s,r)||!ao(i,a):!0}function mk(e,t,s){var r=!1,i=Zr,a=t.contextType;return typeof a=="object"&&a!==null?a=os(a):(i=En(t)?Ri:dn.current,r=t.contextTypes,a=(r=r!=null)?Oa(e,i):Zr),t=new t(s,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=kd,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Qj(e,t,s,r){e=t.state,typeof t.componentWillReceiveProps=="function"&&t.componentWillReceiveProps(s,r),typeof t.UNSAFE_componentWillReceiveProps=="function"&&t.UNSAFE_componentWillReceiveProps(s,r),t.state!==e&&kd.enqueueReplaceState(t,t.state,null)}function pm(e,t,s,r){var i=e.stateNode;i.props=s,i.state=e.memoizedState,i.refs={},Eg(e);var a=t.contextType;typeof a=="object"&&a!==null?i.context=os(a):(a=En(t)?Ri:dn.current,i.context=Oa(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a=="function"&&(mm(e,t,a,s),i.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof i.getSnapshotBeforeUpdate=="function"||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(t=i.state,typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount(),t!==i.state&&kd.enqueueReplaceState(i,i.state,null),Du(e,s,i,r),i.state=e.memoizedState),typeof i.componentDidMount=="function"&&(e.flags|=4194308)}function Fa(e,t){try{var s="",r=t;do s+=CT(r),r=r.return;while(r);var i=s}catch(a){i=`
|
|
39
|
+
Error generating stack: `+a.message+`
|
|
40
|
+
`+a.stack}return{value:e,source:t,stack:i,digest:null}}function Lh(e,t,s){return{value:e,source:null,stack:s??null,digest:t??null}}function gm(e,t){try{console.error(t.value)}catch(s){setTimeout(function(){throw s})}}var ZR=typeof WeakMap=="function"?WeakMap:Map;function pk(e,t,s){s=ar(-1,s),s.tag=3,s.payload={element:null};var r=t.value;return s.callback=function(){Uu||(Uu=!0,Cm=r),gm(e,t)},s}function gk(e,t,s){s=ar(-1,s),s.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var i=t.value;s.payload=function(){return r(i)},s.callback=function(){gm(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch=="function"&&(s.callback=function(){gm(e,t),typeof r!="function"&&(Hr===null?Hr=new Set([this]):Hr.add(this));var l=t.stack;this.componentDidCatch(t.value,{componentStack:l!==null?l:""})}),s}function Jj(e,t,s){var r=e.pingCache;if(r===null){r=e.pingCache=new ZR;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(s)||(i.add(s),e=fI.bind(null,e,t,s),t.then(e,e))}function Xj(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function Zj(e,t,s,r,i){return e.mode&1?(e.flags|=65536,e.lanes=i,e):(e===t?e.flags|=65536:(e.flags|=128,s.flags|=131072,s.flags&=-52805,s.tag===1&&(s.alternate===null?s.tag=17:(t=ar(-1,1),t.tag=2,Wr(s,t,1))),s.lanes|=1),e)}var eI=vr.ReactCurrentOwner,Sn=!1;function pn(e,t,s,r){t.child=e===null?K0(t,null,s,r):_a(t,e.child,s,r)}function ey(e,t,s,r,i){s=s.render;var a=t.ref;return Ca(t,i),r=Pg(e,t,s,r,a,i),s=$g(),e!==null&&!Sn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,fr(e,t,i)):(ht&&s&&yg(t),t.flags|=1,pn(e,t,r,i),t.child)}function ty(e,t,s,r,i){if(e===null){var a=s.type;return typeof a=="function"&&!Wg(a)&&a.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(t.tag=15,t.type=a,xk(e,t,a,r,i)):(e=au(s.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,!(e.lanes&i)){var l=a.memoizedProps;if(s=s.compare,s=s!==null?s:ao,s(l,r)&&e.ref===t.ref)return fr(e,t,i)}return t.flags|=1,e=Vr(a,r),e.ref=t.ref,e.return=t,t.child=e}function xk(e,t,s,r,i){if(e!==null){var a=e.memoizedProps;if(ao(a,r)&&e.ref===t.ref)if(Sn=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Sn=!0);else return t.lanes=e.lanes,fr(e,t,i)}return xm(e,t,s,r,i)}function vk(e,t,s){var r=t.pendingProps,i=r.children,a=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},lt(ja,_n),_n|=s;else{if(!(s&1073741824))return e=a!==null?a.baseLanes|s:s,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,lt(ja,_n),_n|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a!==null?a.baseLanes:s,lt(ja,_n),_n|=r}else a!==null?(r=a.baseLanes|s,t.memoizedState=null):r=s,lt(ja,_n),_n|=r;return pn(e,t,i,s),t.child}function jk(e,t){var s=t.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(t.flags|=512,t.flags|=2097152)}function xm(e,t,s,r,i){var a=En(s)?Ri:dn.current;return a=Oa(t,a),Ca(t,i),s=Pg(e,t,s,r,a,i),r=$g(),e!==null&&!Sn?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,fr(e,t,i)):(ht&&r&&yg(t),t.flags|=1,pn(e,t,s,i),t.child)}function ny(e,t,s,r,i){if(En(s)){var a=!0;Iu(t)}else a=!1;if(Ca(t,i),t.stateNode===null)su(e,t),mk(t,s,r),pm(t,s,r,i),r=!0;else if(e===null){var l=t.stateNode,o=t.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=os(u):(u=En(s)?Ri:dn.current,u=Oa(t,u));var d=s.getDerivedStateFromProps,h=typeof d=="function"||typeof l.getSnapshotBeforeUpdate=="function";h||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Qj(t,l,r,u),Rr=!1;var m=t.memoizedState;l.state=m,Du(t,r,l,i),c=t.memoizedState,o!==r||m!==c||Cn.current||Rr?(typeof d=="function"&&(mm(t,s,d,r),c=t.memoizedState),(o=Rr||qj(t,s,o,r,m,c,u))?(h||typeof l.UNSAFE_componentWillMount!="function"&&typeof l.componentWillMount!="function"||(typeof l.componentWillMount=="function"&&l.componentWillMount(),typeof l.UNSAFE_componentWillMount=="function"&&l.UNSAFE_componentWillMount()),typeof l.componentDidMount=="function"&&(t.flags|=4194308)):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{l=t.stateNode,G0(e,t),o=t.memoizedProps,u=t.type===t.elementType?o:hs(t.type,o),l.props=u,h=t.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=os(c):(c=En(s)?Ri:dn.current,c=Oa(t,c));var p=s.getDerivedStateFromProps;(d=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==h||m!==c)&&Qj(t,l,r,c),Rr=!1,m=t.memoizedState,l.state=m,Du(t,r,l,i);var g=t.memoizedState;o!==h||m!==g||Cn.current||Rr?(typeof p=="function"&&(mm(t,s,p,r),g=t.memoizedState),(u=Rr||qj(t,s,u,r,m,g,c)||!1)?(d||typeof l.UNSAFE_componentWillUpdate!="function"&&typeof l.componentWillUpdate!="function"||(typeof l.componentWillUpdate=="function"&&l.componentWillUpdate(r,g,c),typeof l.UNSAFE_componentWillUpdate=="function"&&l.UNSAFE_componentWillUpdate(r,g,c)),typeof l.componentDidUpdate=="function"&&(t.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=g),l.props=r,l.state=g,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(t.flags|=1024),r=!1)}return vm(e,t,s,r,a,i)}function vm(e,t,s,r,i,a){jk(e,t);var l=(t.flags&128)!==0;if(!r&&!l)return i&&Uj(t,s,!1),fr(e,t,a);r=t.stateNode,eI.current=t;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&l?(t.child=_a(t,e.child,null,a),t.child=_a(t,null,o,a)):pn(e,t,o,a),t.memoizedState=r.state,i&&Uj(t,s,!0),t.child}function yk(e){var t=e.stateNode;t.pendingContext?zj(e,t.pendingContext,t.pendingContext!==t.context):t.context&&zj(e,t.context,!1),Ag(e,t.containerInfo)}function sy(e,t,s,r,i){return Da(),bg(i),t.flags|=256,pn(e,t,s,r),t.child}var jm={dehydrated:null,treeContext:null,retryLane:0};function ym(e){return{baseLanes:e,cachePool:null,transitions:null}}function wk(e,t,s){var r=t.pendingProps,i=pt.current,a=!1,l=(t.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(i&2)!==0),o?(a=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(i|=1),lt(pt,i&1),e===null)return hm(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(l=r.children,e=r.fallback,a?(r=t.mode,a=t.child,l={mode:"hidden",children:l},!(r&1)&&a!==null?(a.childLanes=0,a.pendingProps=l):a=Cd(l,r,0,null),e=Ai(e,r,s,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=ym(s),t.memoizedState=jm,e):Dg(t,l));if(i=e.memoizedState,i!==null&&(o=i.dehydrated,o!==null))return tI(e,t,l,r,o,i,s);if(a){a=r.fallback,l=t.mode,i=e.child,o=i.sibling;var c={mode:"hidden",children:r.children};return!(l&1)&&t.child!==i?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=Vr(i,c),r.subtreeFlags=i.subtreeFlags&14680064),o!==null?a=Vr(o,a):(a=Ai(a,l,s,null),a.flags|=2),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,l=e.child.memoizedState,l=l===null?ym(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},a.memoizedState=l,a.childLanes=e.childLanes&~s,t.memoizedState=jm,r}return a=e.child,e=a.sibling,r=Vr(a,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=s),r.return=t,r.sibling=null,e!==null&&(s=t.deletions,s===null?(t.deletions=[e],t.flags|=16):s.push(e)),t.child=r,t.memoizedState=null,r}function Dg(e,t){return t=Cd({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function yc(e,t,s,r){return r!==null&&bg(r),_a(t,e.child,null,s),e=Dg(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function tI(e,t,s,r,i,a,l){if(s)return t.flags&256?(t.flags&=-257,r=Lh(Error(ae(422))),yc(e,t,l,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(a=r.fallback,i=t.mode,r=Cd({mode:"visible",children:r.children},i,0,null),a=Ai(a,i,l,null),a.flags|=2,r.return=t,a.return=t,r.sibling=a,t.child=r,t.mode&1&&_a(t,e.child,null,l),t.child.memoizedState=ym(l),t.memoizedState=jm,a);if(!(t.mode&1))return yc(e,t,l,null);if(i.data==="$!"){if(r=i.nextSibling&&i.nextSibling.dataset,r)var o=r.dgst;return r=o,a=Error(ae(419)),r=Lh(a,r,void 0),yc(e,t,l,r)}if(o=(l&e.childLanes)!==0,Sn||o){if(r=Kt,r!==null){switch(l&-l){case 4:i=2;break;case 16:i=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:i=32;break;case 536870912:i=268435456;break;default:i=0}i=i&(r.suspendedLanes|l)?0:i,i!==0&&i!==a.retryLane&&(a.retryLane=i,hr(e,i),xs(r,e,i,-1))}return Bg(),r=Lh(Error(ae(421))),yc(e,t,l,r)}return i.data==="$?"?(t.flags|=128,t.child=e.child,t=mI.bind(null,e),i._reactRetry=t,null):(e=a.treeContext,Fn=Br(i.nextSibling),Un=t,ht=!0,ms=null,e!==null&&(ts[ns++]=rr,ts[ns++]=ir,ts[ns++]=Ii,rr=e.id,ir=e.overflow,Ii=t),t=Dg(t,r.children),t.flags|=4096,t)}function ry(e,t,s){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),fm(e.return,t,s)}function Fh(e,t,s,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:s,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=s,a.tailMode=i)}function bk(e,t,s){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(pn(e,t,r.children,s),r=pt.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&ry(e,s,t);else if(e.tag===19)ry(e,s,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(lt(pt,r),!(t.mode&1))t.memoizedState=null;else switch(i){case"forwards":for(s=t.child,i=null;s!==null;)e=s.alternate,e!==null&&_u(e)===null&&(i=s),s=s.sibling;s=i,s===null?(i=t.child,t.child=null):(i=s.sibling,s.sibling=null),Fh(t,!1,i,s,a);break;case"backwards":for(s=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&_u(e)===null){t.child=i;break}e=i.sibling,i.sibling=s,s=i,i=e}Fh(t,!0,s,null,a);break;case"together":Fh(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function su(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function fr(e,t,s){if(e!==null&&(t.dependencies=e.dependencies),$i|=t.lanes,!(s&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(ae(153));if(t.child!==null){for(e=t.child,s=Vr(e,e.pendingProps),t.child=s,s.return=t;e.sibling!==null;)e=e.sibling,s=s.sibling=Vr(e,e.pendingProps),s.return=t;s.sibling=null}return t.child}function nI(e,t,s){switch(t.tag){case 3:yk(t),Da();break;case 5:Y0(t);break;case 1:En(t.type)&&Iu(t);break;case 4:Ag(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;lt(Mu,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(lt(pt,pt.current&1),t.flags|=128,null):s&t.child.childLanes?wk(e,t,s):(lt(pt,pt.current&1),e=fr(e,t,s),e!==null?e.sibling:null);lt(pt,pt.current&1);break;case 19:if(r=(s&t.childLanes)!==0,e.flags&128){if(r)return bk(e,t,s);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),lt(pt,pt.current),r)break;return null;case 22:case 23:return t.lanes=0,vk(e,t,s)}return fr(e,t,s)}var kk,wm,Sk,Nk;kk=function(e,t){for(var s=t.child;s!==null;){if(s.tag===5||s.tag===6)e.appendChild(s.stateNode);else if(s.tag!==4&&s.child!==null){s.child.return=s,s=s.child;continue}if(s===t)break;for(;s.sibling===null;){if(s.return===null||s.return===t)return;s=s.return}s.sibling.return=s.return,s=s.sibling}};wm=function(){};Sk=function(e,t,s,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,Ci(Bs.current);var a=null;switch(s){case"input":i=Wf(e,i),r=Wf(e,r),a=[];break;case"select":i=wt({},i,{value:void 0}),r=wt({},r,{value:void 0}),a=[];break;case"textarea":i=Vf(e,i),r=Vf(e,r),a=[];break;default:typeof i.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Tu)}Yf(s,r);var l;s=null;for(u in i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null)if(u==="style"){var o=i[u];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Zl.hasOwnProperty(u)?a||(a=[]):(a=a||[]).push(u,null));for(u in r){var c=r[u];if(o=i!=null?i[u]:void 0,r.hasOwnProperty(u)&&c!==o&&(c!=null||o!=null))if(u==="style")if(o){for(l in o)!o.hasOwnProperty(l)||c&&c.hasOwnProperty(l)||(s||(s={}),s[l]="");for(l in c)c.hasOwnProperty(l)&&o[l]!==c[l]&&(s||(s={}),s[l]=c[l])}else s||(a||(a=[]),a.push(u,s)),s=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(a=a||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(a=a||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Zl.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&ot("scroll",e),a||o===c||(a=[])):(a=a||[]).push(u,c))}s&&(a=a||[]).push("style",s);var u=a;(t.updateQueue=u)&&(t.flags|=4)}};Nk=function(e,t,s,r){s!==r&&(t.flags|=4)};function Nl(e,t){if(!ht)switch(e.tailMode){case"hidden":t=e.tail;for(var s=null;t!==null;)t.alternate!==null&&(s=t),t=t.sibling;s===null?e.tail=null:s.sibling=null;break;case"collapsed":s=e.tail;for(var r=null;s!==null;)s.alternate!==null&&(r=s),s=s.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function an(e){var t=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(t)for(var i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)s|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=s,t}function sI(e,t,s){var r=t.pendingProps;switch(wg(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return an(t),null;case 1:return En(t.type)&&Ru(),an(t),null;case 3:return r=t.stateNode,La(),ct(Cn),ct(dn),Rg(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(vc(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,ms!==null&&(Tm(ms),ms=null))),wm(e,t),an(t),null;case 5:Tg(t);var i=Ci(ho.current);if(s=t.type,e!==null&&t.stateNode!=null)Sk(e,t,s,r,i),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(ae(166));return an(t),null}if(e=Ci(Bs.current),vc(t)){r=t.stateNode,s=t.type;var a=t.memoizedProps;switch(r[_s]=t,r[co]=a,e=(t.mode&1)!==0,s){case"dialog":ot("cancel",r),ot("close",r);break;case"iframe":case"object":case"embed":ot("load",r);break;case"video":case"audio":for(i=0;i<Dl.length;i++)ot(Dl[i],r);break;case"source":ot("error",r);break;case"img":case"image":case"link":ot("error",r),ot("load",r);break;case"details":ot("toggle",r);break;case"input":fj(r,a),ot("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!a.multiple},ot("invalid",r);break;case"textarea":pj(r,a),ot("invalid",r)}Yf(s,a),i=null;for(var l in a)if(a.hasOwnProperty(l)){var o=a[l];l==="children"?typeof o=="string"?r.textContent!==o&&(a.suppressHydrationWarning!==!0&&xc(r.textContent,o,e),i=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(a.suppressHydrationWarning!==!0&&xc(r.textContent,o,e),i=["children",""+o]):Zl.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&ot("scroll",r)}switch(s){case"input":cc(r),mj(r,a,!0);break;case"textarea":cc(r),gj(r);break;case"select":case"option":break;default:typeof a.onClick=="function"&&(r.onclick=Tu)}r=i,t.updateQueue=r,r!==null&&(t.flags|=4)}else{l=i.nodeType===9?i:i.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=Zb(s)),e==="http://www.w3.org/1999/xhtml"?s==="script"?(e=l.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=l.createElement(s,{is:r.is}):(e=l.createElement(s),s==="select"&&(l=e,r.multiple?l.multiple=!0:r.size&&(l.size=r.size))):e=l.createElementNS(e,s),e[_s]=t,e[co]=r,kk(e,t,!1,!1),t.stateNode=e;e:{switch(l=qf(s,r),s){case"dialog":ot("cancel",e),ot("close",e),i=r;break;case"iframe":case"object":case"embed":ot("load",e),i=r;break;case"video":case"audio":for(i=0;i<Dl.length;i++)ot(Dl[i],e);i=r;break;case"source":ot("error",e),i=r;break;case"img":case"image":case"link":ot("error",e),ot("load",e),i=r;break;case"details":ot("toggle",e),i=r;break;case"input":fj(e,r),i=Wf(e,r),ot("invalid",e);break;case"option":i=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},i=wt({},r,{value:void 0}),ot("invalid",e);break;case"textarea":pj(e,r),i=Vf(e,r),ot("invalid",e);break;default:i=r}Yf(s,i),o=i;for(a in o)if(o.hasOwnProperty(a)){var c=o[a];a==="style"?n0(e,c):a==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&e0(e,c)):a==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&eo(e,c):typeof c=="number"&&eo(e,""+c):a!=="suppressContentEditableWarning"&&a!=="suppressHydrationWarning"&&a!=="autoFocus"&&(Zl.hasOwnProperty(a)?c!=null&&a==="onScroll"&&ot("scroll",e):c!=null&&ag(e,a,c,l))}switch(s){case"input":cc(e),mj(e,r,!1);break;case"textarea":cc(e),gj(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Xr(r.value));break;case"select":e.multiple=!!r.multiple,a=r.value,a!=null?ba(e,!!r.multiple,a,!1):r.defaultValue!=null&&ba(e,!!r.multiple,r.defaultValue,!0);break;default:typeof i.onClick=="function"&&(e.onclick=Tu)}switch(s){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return an(t),null;case 6:if(e&&t.stateNode!=null)Nk(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(ae(166));if(s=Ci(ho.current),Ci(Bs.current),vc(t)){if(r=t.stateNode,s=t.memoizedProps,r[_s]=t,(a=r.nodeValue!==s)&&(e=Un,e!==null))switch(e.tag){case 3:xc(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&xc(r.nodeValue,s,(e.mode&1)!==0)}a&&(t.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[_s]=t,t.stateNode=r}return an(t),null;case 13:if(ct(pt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(ht&&Fn!==null&&t.mode&1&&!(t.flags&128))W0(),Da(),t.flags|=98560,a=!1;else if(a=vc(t),r!==null&&r.dehydrated!==null){if(e===null){if(!a)throw Error(ae(318));if(a=t.memoizedState,a=a!==null?a.dehydrated:null,!a)throw Error(ae(317));a[_s]=t}else Da(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;an(t),a=!1}else ms!==null&&(Tm(ms),ms=null),a=!0;if(!a)return t.flags&65536?t:null}return t.flags&128?(t.lanes=s,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||pt.current&1?Lt===0&&(Lt=3):Bg())),t.updateQueue!==null&&(t.flags|=4),an(t),null);case 4:return La(),wm(e,t),e===null&&lo(t.stateNode.containerInfo),an(t),null;case 10:return Ng(t.type._context),an(t),null;case 17:return En(t.type)&&Ru(),an(t),null;case 19:if(ct(pt),a=t.memoizedState,a===null)return an(t),null;if(r=(t.flags&128)!==0,l=a.rendering,l===null)if(r)Nl(a,!1);else{if(Lt!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(l=_u(e),l!==null){for(t.flags|=128,Nl(a,!1),r=l.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=s,s=t.child;s!==null;)a=s,e=r,a.flags&=14680066,l=a.alternate,l===null?(a.childLanes=0,a.lanes=e,a.child=null,a.subtreeFlags=0,a.memoizedProps=null,a.memoizedState=null,a.updateQueue=null,a.dependencies=null,a.stateNode=null):(a.childLanes=l.childLanes,a.lanes=l.lanes,a.child=l.child,a.subtreeFlags=0,a.deletions=null,a.memoizedProps=l.memoizedProps,a.memoizedState=l.memoizedState,a.updateQueue=l.updateQueue,a.type=l.type,e=l.dependencies,a.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return lt(pt,pt.current&1|2),t.child}e=e.sibling}a.tail!==null&&Tt()>za&&(t.flags|=128,r=!0,Nl(a,!1),t.lanes=4194304)}else{if(!r)if(e=_u(l),e!==null){if(t.flags|=128,r=!0,s=e.updateQueue,s!==null&&(t.updateQueue=s,t.flags|=4),Nl(a,!0),a.tail===null&&a.tailMode==="hidden"&&!l.alternate&&!ht)return an(t),null}else 2*Tt()-a.renderingStartTime>za&&s!==1073741824&&(t.flags|=128,r=!0,Nl(a,!1),t.lanes=4194304);a.isBackwards?(l.sibling=t.child,t.child=l):(s=a.last,s!==null?s.sibling=l:t.child=l,a.last=l)}return a.tail!==null?(t=a.tail,a.rendering=t,a.tail=t.sibling,a.renderingStartTime=Tt(),t.sibling=null,s=pt.current,lt(pt,r?s&1|2:s&1),t):(an(t),null);case 22:case 23:return Ug(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?_n&1073741824&&(an(t),t.subtreeFlags&6&&(t.flags|=8192)):an(t),null;case 24:return null;case 25:return null}throw Error(ae(156,t.tag))}function rI(e,t){switch(wg(t),t.tag){case 1:return En(t.type)&&Ru(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return La(),ct(Cn),ct(dn),Rg(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return Tg(t),null;case 13:if(ct(pt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(ae(340));Da()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return ct(pt),null;case 4:return La(),null;case 10:return Ng(t.type._context),null;case 22:case 23:return Ug(),null;case 24:return null;default:return null}}var wc=!1,on=!1,iI=typeof WeakSet=="function"?WeakSet:Set,ke=null;function va(e,t){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Nt(e,t,r)}else s.current=null}function bm(e,t,s){try{s()}catch(r){Nt(e,t,r)}}var iy=!1;function aI(e,t){if(im=Cu,e=R0(),jg(e)){if("selectionStart"in e)var s={start:e.selectionStart,end:e.selectionEnd};else e:{s=(s=e.ownerDocument)&&s.defaultView||window;var r=s.getSelection&&s.getSelection();if(r&&r.rangeCount!==0){s=r.anchorNode;var i=r.anchorOffset,a=r.focusNode;r=r.focusOffset;try{s.nodeType,a.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,d=0,h=e,m=null;t:for(;;){for(var p;h!==s||i!==0&&h.nodeType!==3||(o=l+i),h!==a||r!==0&&h.nodeType!==3||(c=l+r),h.nodeType===3&&(l+=h.nodeValue.length),(p=h.firstChild)!==null;)m=h,h=p;for(;;){if(h===e)break t;if(m===s&&++u===i&&(o=l),m===a&&++d===r&&(c=l),(p=h.nextSibling)!==null)break;h=m,m=h.parentNode}h=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(am={focusedElem:e,selectionRange:s},Cu=!1,ke=t;ke!==null;)if(t=ke,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,ke=e;else for(;ke!==null;){t=ke;try{var g=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var y=g.memoizedProps,b=g.memoizedState,x=t.stateNode,v=x.getSnapshotBeforeUpdate(t.elementType===t.type?y:hs(t.type,y),b);x.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var j=t.stateNode.containerInfo;j.nodeType===1?j.textContent="":j.nodeType===9&&j.documentElement&&j.removeChild(j.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(ae(163))}}catch(w){Nt(t,t.return,w)}if(e=t.sibling,e!==null){e.return=t.return,ke=e;break}ke=t.return}return g=iy,iy=!1,g}function Kl(e,t,s){var r=t.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&bm(t,s,a)}i=i.next}while(i!==r)}}function Sd(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var s=t=t.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==t)}}function km(e){var t=e.ref;if(t!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof t=="function"?t(e):t.current=e}}function Ck(e){var t=e.alternate;t!==null&&(e.alternate=null,Ck(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[_s],delete t[co],delete t[cm],delete t[BR],delete t[WR])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Ek(e){return e.tag===5||e.tag===3||e.tag===4}function ay(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Ek(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Sm(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.nodeType===8?s.parentNode.insertBefore(e,t):s.insertBefore(e,t):(s.nodeType===8?(t=s.parentNode,t.insertBefore(e,s)):(t=s,t.appendChild(e)),s=s._reactRootContainer,s!=null||t.onclick!==null||(t.onclick=Tu));else if(r!==4&&(e=e.child,e!==null))for(Sm(e,t,s),e=e.sibling;e!==null;)Sm(e,t,s),e=e.sibling}function Nm(e,t,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?s.insertBefore(e,t):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(Nm(e,t,s),e=e.sibling;e!==null;)Nm(e,t,s),e=e.sibling}var qt=null,fs=!1;function Er(e,t,s){for(s=s.child;s!==null;)Ak(e,t,s),s=s.sibling}function Ak(e,t,s){if(Us&&typeof Us.onCommitFiberUnmount=="function")try{Us.onCommitFiberUnmount(gd,s)}catch{}switch(s.tag){case 5:on||va(s,t);case 6:var r=qt,i=fs;qt=null,Er(e,t,s),qt=r,fs=i,qt!==null&&(fs?(e=qt,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):qt.removeChild(s.stateNode));break;case 18:qt!==null&&(fs?(e=qt,s=s.stateNode,e.nodeType===8?Ph(e.parentNode,s):e.nodeType===1&&Ph(e,s),ro(e)):Ph(qt,s.stateNode));break;case 4:r=qt,i=fs,qt=s.stateNode.containerInfo,fs=!0,Er(e,t,s),qt=r,fs=i;break;case 0:case 11:case 14:case 15:if(!on&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,l=a.destroy;a=a.tag,l!==void 0&&(a&2||a&4)&&bm(s,t,l),i=i.next}while(i!==r)}Er(e,t,s);break;case 1:if(!on&&(va(s,t),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Nt(s,t,o)}Er(e,t,s);break;case 21:Er(e,t,s);break;case 22:s.mode&1?(on=(r=on)||s.memoizedState!==null,Er(e,t,s),on=r):Er(e,t,s);break;default:Er(e,t,s)}}function ly(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new iI),t.forEach(function(r){var i=pI.bind(null,e,r);s.has(r)||(s.add(r),r.then(i,i))})}}function ds(e,t){var s=t.deletions;if(s!==null)for(var r=0;r<s.length;r++){var i=s[r];try{var a=e,l=t,o=l;e:for(;o!==null;){switch(o.tag){case 5:qt=o.stateNode,fs=!1;break e;case 3:qt=o.stateNode.containerInfo,fs=!0;break e;case 4:qt=o.stateNode.containerInfo,fs=!0;break e}o=o.return}if(qt===null)throw Error(ae(160));Ak(a,l,i),qt=null,fs=!1;var c=i.alternate;c!==null&&(c.return=null),i.return=null}catch(u){Nt(i,t,u)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)Tk(t,e),t=t.sibling}function Tk(e,t){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(ds(t,e),$s(e),r&4){try{Kl(3,e,e.return),Sd(3,e)}catch(y){Nt(e,e.return,y)}try{Kl(5,e,e.return)}catch(y){Nt(e,e.return,y)}}break;case 1:ds(t,e),$s(e),r&512&&s!==null&&va(s,s.return);break;case 5:if(ds(t,e),$s(e),r&512&&s!==null&&va(s,s.return),e.flags&32){var i=e.stateNode;try{eo(i,"")}catch(y){Nt(e,e.return,y)}}if(r&4&&(i=e.stateNode,i!=null)){var a=e.memoizedProps,l=s!==null?s.memoizedProps:a,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&a.type==="radio"&&a.name!=null&&Jb(i,a),qf(o,l);var u=qf(o,a);for(l=0;l<c.length;l+=2){var d=c[l],h=c[l+1];d==="style"?n0(i,h):d==="dangerouslySetInnerHTML"?e0(i,h):d==="children"?eo(i,h):ag(i,d,h,u)}switch(o){case"input":Hf(i,a);break;case"textarea":Xb(i,a);break;case"select":var m=i._wrapperState.wasMultiple;i._wrapperState.wasMultiple=!!a.multiple;var p=a.value;p!=null?ba(i,!!a.multiple,p,!1):m!==!!a.multiple&&(a.defaultValue!=null?ba(i,!!a.multiple,a.defaultValue,!0):ba(i,!!a.multiple,a.multiple?[]:"",!1))}i[co]=a}catch(y){Nt(e,e.return,y)}}break;case 6:if(ds(t,e),$s(e),r&4){if(e.stateNode===null)throw Error(ae(162));i=e.stateNode,a=e.memoizedProps;try{i.nodeValue=a}catch(y){Nt(e,e.return,y)}}break;case 3:if(ds(t,e),$s(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{ro(t.containerInfo)}catch(y){Nt(e,e.return,y)}break;case 4:ds(t,e),$s(e);break;case 13:ds(t,e),$s(e),i=e.child,i.flags&8192&&(a=i.memoizedState!==null,i.stateNode.isHidden=a,!a||i.alternate!==null&&i.alternate.memoizedState!==null||(Fg=Tt())),r&4&&ly(e);break;case 22:if(d=s!==null&&s.memoizedState!==null,e.mode&1?(on=(u=on)||d,ds(t,e),on=u):ds(t,e),$s(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(ke=e,d=e.child;d!==null;){for(h=ke=d;ke!==null;){switch(m=ke,p=m.child,m.tag){case 0:case 11:case 14:case 15:Kl(4,m,m.return);break;case 1:va(m,m.return);var g=m.stateNode;if(typeof g.componentWillUnmount=="function"){r=m,s=m.return;try{t=r,g.props=t.memoizedProps,g.state=t.memoizedState,g.componentWillUnmount()}catch(y){Nt(r,s,y)}}break;case 5:va(m,m.return);break;case 22:if(m.memoizedState!==null){cy(h);continue}}p!==null?(p.return=m,ke=p):cy(h)}d=d.sibling}e:for(d=null,h=e;;){if(h.tag===5){if(d===null){d=h;try{i=h.stateNode,u?(a=i.style,typeof a.setProperty=="function"?a.setProperty("display","none","important"):a.display="none"):(o=h.stateNode,c=h.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=t0("display",l))}catch(y){Nt(e,e.return,y)}}}else if(h.tag===6){if(d===null)try{h.stateNode.nodeValue=u?"":h.memoizedProps}catch(y){Nt(e,e.return,y)}}else if((h.tag!==22&&h.tag!==23||h.memoizedState===null||h===e)&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===e)break e;for(;h.sibling===null;){if(h.return===null||h.return===e)break e;d===h&&(d=null),h=h.return}d===h&&(d=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:ds(t,e),$s(e),r&4&&ly(e);break;case 21:break;default:ds(t,e),$s(e)}}function $s(e){var t=e.flags;if(t&2){try{e:{for(var s=e.return;s!==null;){if(Ek(s)){var r=s;break e}s=s.return}throw Error(ae(160))}switch(r.tag){case 5:var i=r.stateNode;r.flags&32&&(eo(i,""),r.flags&=-33);var a=ay(e);Nm(e,a,i);break;case 3:case 4:var l=r.stateNode.containerInfo,o=ay(e);Sm(e,o,l);break;default:throw Error(ae(161))}}catch(c){Nt(e,e.return,c)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function lI(e,t,s){ke=e,Rk(e)}function Rk(e,t,s){for(var r=(e.mode&1)!==0;ke!==null;){var i=ke,a=i.child;if(i.tag===22&&r){var l=i.memoizedState!==null||wc;if(!l){var o=i.alternate,c=o!==null&&o.memoizedState!==null||on;o=wc;var u=on;if(wc=l,(on=c)&&!u)for(ke=i;ke!==null;)l=ke,c=l.child,l.tag===22&&l.memoizedState!==null?uy(i):c!==null?(c.return=l,ke=c):uy(i);for(;a!==null;)ke=a,Rk(a),a=a.sibling;ke=i,wc=o,on=u}oy(e)}else i.subtreeFlags&8772&&a!==null?(a.return=i,ke=a):oy(e)}}function oy(e){for(;ke!==null;){var t=ke;if(t.flags&8772){var s=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:on||Sd(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!on)if(s===null)r.componentDidMount();else{var i=t.elementType===t.type?s.memoizedProps:hs(t.type,s.memoizedProps);r.componentDidUpdate(i,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var a=t.updateQueue;a!==null&&Vj(t,a,r);break;case 3:var l=t.updateQueue;if(l!==null){if(s=null,t.child!==null)switch(t.child.tag){case 5:s=t.child.stateNode;break;case 1:s=t.child.stateNode}Vj(t,l,s)}break;case 5:var o=t.stateNode;if(s===null&&t.flags&4){s=o;var c=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&s.focus();break;case"img":c.src&&(s.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var d=u.memoizedState;if(d!==null){var h=d.dehydrated;h!==null&&ro(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(ae(163))}on||t.flags&512&&km(t)}catch(m){Nt(t,t.return,m)}}if(t===e){ke=null;break}if(s=t.sibling,s!==null){s.return=t.return,ke=s;break}ke=t.return}}function cy(e){for(;ke!==null;){var t=ke;if(t===e){ke=null;break}var s=t.sibling;if(s!==null){s.return=t.return,ke=s;break}ke=t.return}}function uy(e){for(;ke!==null;){var t=ke;try{switch(t.tag){case 0:case 11:case 15:var s=t.return;try{Sd(4,t)}catch(c){Nt(t,s,c)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var i=t.return;try{r.componentDidMount()}catch(c){Nt(t,i,c)}}var a=t.return;try{km(t)}catch(c){Nt(t,a,c)}break;case 5:var l=t.return;try{km(t)}catch(c){Nt(t,l,c)}}}catch(c){Nt(t,t.return,c)}if(t===e){ke=null;break}var o=t.sibling;if(o!==null){o.return=t.return,ke=o;break}ke=t.return}}var oI=Math.ceil,zu=vr.ReactCurrentDispatcher,_g=vr.ReactCurrentOwner,as=vr.ReactCurrentBatchConfig,qe=0,Kt=null,Mt=null,Qt=0,_n=0,ja=oi(0),Lt=0,go=null,$i=0,Nd=0,Lg=0,Vl=null,kn=null,Fg=0,za=1/0,Zs=null,Uu=!1,Cm=null,Hr=null,bc=!1,Mr=null,Bu=0,Gl=0,Em=null,ru=-1,iu=0;function xn(){return qe&6?Tt():ru!==-1?ru:ru=Tt()}function Kr(e){return e.mode&1?qe&2&&Qt!==0?Qt&-Qt:KR.transition!==null?(iu===0&&(iu=m0()),iu):(e=st,e!==0||(e=window.event,e=e===void 0?16:w0(e.type)),e):1}function xs(e,t,s,r){if(50<Gl)throw Gl=0,Em=null,Error(ae(185));Do(e,s,r),(!(qe&2)||e!==Kt)&&(e===Kt&&(!(qe&2)&&(Nd|=s),Lt===4&&Pr(e,Qt)),An(e,r),s===1&&qe===0&&!(t.mode&1)&&(za=Tt()+500,wd&&ci()))}function An(e,t){var s=e.callbackNode;KT(e,t);var r=Nu(e,e===Kt?Qt:0);if(r===0)s!==null&&jj(s),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(s!=null&&jj(s),t===1)e.tag===0?HR(dy.bind(null,e)):z0(dy.bind(null,e)),zR(function(){!(qe&6)&&ci()}),s=null;else{switch(p0(r)){case 1:s=dg;break;case 4:s=h0;break;case 16:s=Su;break;case 536870912:s=f0;break;default:s=Su}s=Lk(s,Ik.bind(null,e))}e.callbackPriority=t,e.callbackNode=s}}function Ik(e,t){if(ru=-1,iu=0,qe&6)throw Error(ae(327));var s=e.callbackNode;if(Ea()&&e.callbackNode!==s)return null;var r=Nu(e,e===Kt?Qt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Wu(e,r);else{t=r;var i=qe;qe|=2;var a=$k();(Kt!==e||Qt!==t)&&(Zs=null,za=Tt()+500,Ei(e,t));do try{dI();break}catch(o){Pk(e,o)}while(!0);Sg(),zu.current=a,qe=i,Mt!==null?t=0:(Kt=null,Qt=0,t=Lt)}if(t!==0){if(t===2&&(i=em(e),i!==0&&(r=i,t=Am(e,i))),t===1)throw s=go,Ei(e,0),Pr(e,r),An(e,Tt()),s;if(t===6)Pr(e,r);else{if(i=e.current.alternate,!(r&30)&&!cI(i)&&(t=Wu(e,r),t===2&&(a=em(e),a!==0&&(r=a,t=Am(e,a))),t===1))throw s=go,Ei(e,0),Pr(e,r),An(e,Tt()),s;switch(e.finishedWork=i,e.finishedLanes=r,t){case 0:case 1:throw Error(ae(345));case 2:wi(e,kn,Zs);break;case 3:if(Pr(e,r),(r&130023424)===r&&(t=Fg+500-Tt(),10<t)){if(Nu(e,0)!==0)break;if(i=e.suspendedLanes,(i&r)!==r){xn(),e.pingedLanes|=e.suspendedLanes&i;break}e.timeoutHandle=om(wi.bind(null,e,kn,Zs),t);break}wi(e,kn,Zs);break;case 4:if(Pr(e,r),(r&4194240)===r)break;for(t=e.eventTimes,i=-1;0<r;){var l=31-gs(r);a=1<<l,l=t[l],l>i&&(i=l),r&=~a}if(r=i,r=Tt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*oI(r/1960))-r,10<r){e.timeoutHandle=om(wi.bind(null,e,kn,Zs),r);break}wi(e,kn,Zs);break;case 5:wi(e,kn,Zs);break;default:throw Error(ae(329))}}}return An(e,Tt()),e.callbackNode===s?Ik.bind(null,e):null}function Am(e,t){var s=Vl;return e.current.memoizedState.isDehydrated&&(Ei(e,t).flags|=256),e=Wu(e,t),e!==2&&(t=kn,kn=s,t!==null&&Tm(t)),e}function Tm(e){kn===null?kn=e:kn.push.apply(kn,e)}function cI(e){for(var t=e;;){if(t.flags&16384){var s=t.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var i=s[r],a=i.getSnapshot;i=i.value;try{if(!ws(a(),i))return!1}catch{return!1}}}if(s=t.child,t.subtreeFlags&16384&&s!==null)s.return=t,t=s;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function Pr(e,t){for(t&=~Lg,t&=~Nd,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var s=31-gs(t),r=1<<s;e[s]=-1,t&=~r}}function dy(e){if(qe&6)throw Error(ae(327));Ea();var t=Nu(e,0);if(!(t&1))return An(e,Tt()),null;var s=Wu(e,t);if(e.tag!==0&&s===2){var r=em(e);r!==0&&(t=r,s=Am(e,r))}if(s===1)throw s=go,Ei(e,0),Pr(e,t),An(e,Tt()),s;if(s===6)throw Error(ae(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,wi(e,kn,Zs),An(e,Tt()),null}function zg(e,t){var s=qe;qe|=1;try{return e(t)}finally{qe=s,qe===0&&(za=Tt()+500,wd&&ci())}}function Mi(e){Mr!==null&&Mr.tag===0&&!(qe&6)&&Ea();var t=qe;qe|=1;var s=as.transition,r=st;try{if(as.transition=null,st=1,e)return e()}finally{st=r,as.transition=s,qe=t,!(qe&6)&&ci()}}function Ug(){_n=ja.current,ct(ja)}function Ei(e,t){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,FR(s)),Mt!==null)for(s=Mt.return;s!==null;){var r=s;switch(wg(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Ru();break;case 3:La(),ct(Cn),ct(dn),Rg();break;case 5:Tg(r);break;case 4:La();break;case 13:ct(pt);break;case 19:ct(pt);break;case 10:Ng(r.type._context);break;case 22:case 23:Ug()}s=s.return}if(Kt=e,Mt=e=Vr(e.current,null),Qt=_n=t,Lt=0,go=null,Lg=Nd=$i=0,kn=Vl=null,Ni!==null){for(t=0;t<Ni.length;t++)if(s=Ni[t],r=s.interleaved,r!==null){s.interleaved=null;var i=r.next,a=s.pending;if(a!==null){var l=a.next;a.next=i,r.next=l}s.pending=r}Ni=null}return e}function Pk(e,t){do{var s=Mt;try{if(Sg(),tu.current=Fu,Lu){for(var r=vt.memoizedState;r!==null;){var i=r.queue;i!==null&&(i.pending=null),r=r.next}Lu=!1}if(Pi=0,Bt=Ot=vt=null,Hl=!1,fo=0,_g.current=null,s===null||s.return===null){Lt=1,go=t,Mt=null;break}e:{var a=e,l=s.return,o=s,c=t;if(t=Qt,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,d=o,h=d.tag;if(!(d.mode&1)&&(h===0||h===11||h===15)){var m=d.alternate;m?(d.updateQueue=m.updateQueue,d.memoizedState=m.memoizedState,d.lanes=m.lanes):(d.updateQueue=null,d.memoizedState=null)}var p=Xj(l);if(p!==null){p.flags&=-257,Zj(p,l,o,a,t),p.mode&1&&Jj(a,u,t),t=p,c=u;var g=t.updateQueue;if(g===null){var y=new Set;y.add(c),t.updateQueue=y}else g.add(c);break e}else{if(!(t&1)){Jj(a,u,t),Bg();break e}c=Error(ae(426))}}else if(ht&&o.mode&1){var b=Xj(l);if(b!==null){!(b.flags&65536)&&(b.flags|=256),Zj(b,l,o,a,t),bg(Fa(c,o));break e}}a=c=Fa(c,o),Lt!==4&&(Lt=2),Vl===null?Vl=[a]:Vl.push(a),a=l;do{switch(a.tag){case 3:a.flags|=65536,t&=-t,a.lanes|=t;var x=pk(a,c,t);Kj(a,x);break e;case 1:o=c;var v=a.type,j=a.stateNode;if(!(a.flags&128)&&(typeof v.getDerivedStateFromError=="function"||j!==null&&typeof j.componentDidCatch=="function"&&(Hr===null||!Hr.has(j)))){a.flags|=65536,t&=-t,a.lanes|=t;var w=gk(a,o,t);Kj(a,w);break e}}a=a.return}while(a!==null)}Ok(s)}catch(S){t=S,Mt===s&&s!==null&&(Mt=s=s.return);continue}break}while(!0)}function $k(){var e=zu.current;return zu.current=Fu,e===null?Fu:e}function Bg(){(Lt===0||Lt===3||Lt===2)&&(Lt=4),Kt===null||!($i&268435455)&&!(Nd&268435455)||Pr(Kt,Qt)}function Wu(e,t){var s=qe;qe|=2;var r=$k();(Kt!==e||Qt!==t)&&(Zs=null,Ei(e,t));do try{uI();break}catch(i){Pk(e,i)}while(!0);if(Sg(),qe=s,zu.current=r,Mt!==null)throw Error(ae(261));return Kt=null,Qt=0,Lt}function uI(){for(;Mt!==null;)Mk(Mt)}function dI(){for(;Mt!==null&&!DT();)Mk(Mt)}function Mk(e){var t=_k(e.alternate,e,_n);e.memoizedProps=e.pendingProps,t===null?Ok(e):Mt=t,_g.current=null}function Ok(e){var t=e;do{var s=t.alternate;if(e=t.return,t.flags&32768){if(s=rI(s,t),s!==null){s.flags&=32767,Mt=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Lt=6,Mt=null;return}}else if(s=sI(s,t,_n),s!==null){Mt=s;return}if(t=t.sibling,t!==null){Mt=t;return}Mt=t=e}while(t!==null);Lt===0&&(Lt=5)}function wi(e,t,s){var r=st,i=as.transition;try{as.transition=null,st=1,hI(e,t,s,r)}finally{as.transition=i,st=r}return null}function hI(e,t,s,r){do Ea();while(Mr!==null);if(qe&6)throw Error(ae(327));s=e.finishedWork;var i=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(ae(177));e.callbackNode=null,e.callbackPriority=0;var a=s.lanes|s.childLanes;if(VT(e,a),e===Kt&&(Mt=Kt=null,Qt=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||bc||(bc=!0,Lk(Su,function(){return Ea(),null})),a=(s.flags&15990)!==0,s.subtreeFlags&15990||a){a=as.transition,as.transition=null;var l=st;st=1;var o=qe;qe|=4,_g.current=null,aI(e,s),Tk(s,e),PR(am),Cu=!!im,am=im=null,e.current=s,lI(s),_T(),qe=o,st=l,as.transition=a}else e.current=s;if(bc&&(bc=!1,Mr=e,Bu=i),a=e.pendingLanes,a===0&&(Hr=null),zT(s.stateNode),An(e,Tt()),t!==null)for(r=e.onRecoverableError,s=0;s<t.length;s++)i=t[s],r(i.value,{componentStack:i.stack,digest:i.digest});if(Uu)throw Uu=!1,e=Cm,Cm=null,e;return Bu&1&&e.tag!==0&&Ea(),a=e.pendingLanes,a&1?e===Em?Gl++:(Gl=0,Em=e):Gl=0,ci(),null}function Ea(){if(Mr!==null){var e=p0(Bu),t=as.transition,s=st;try{if(as.transition=null,st=16>e?16:e,Mr===null)var r=!1;else{if(e=Mr,Mr=null,Bu=0,qe&6)throw Error(ae(331));var i=qe;for(qe|=4,ke=e.current;ke!==null;){var a=ke,l=a.child;if(ke.flags&16){var o=a.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(ke=u;ke!==null;){var d=ke;switch(d.tag){case 0:case 11:case 15:Kl(8,d,a)}var h=d.child;if(h!==null)h.return=d,ke=h;else for(;ke!==null;){d=ke;var m=d.sibling,p=d.return;if(Ck(d),d===u){ke=null;break}if(m!==null){m.return=p,ke=m;break}ke=p}}}var g=a.alternate;if(g!==null){var y=g.child;if(y!==null){g.child=null;do{var b=y.sibling;y.sibling=null,y=b}while(y!==null)}}ke=a}}if(a.subtreeFlags&2064&&l!==null)l.return=a,ke=l;else e:for(;ke!==null;){if(a=ke,a.flags&2048)switch(a.tag){case 0:case 11:case 15:Kl(9,a,a.return)}var x=a.sibling;if(x!==null){x.return=a.return,ke=x;break e}ke=a.return}}var v=e.current;for(ke=v;ke!==null;){l=ke;var j=l.child;if(l.subtreeFlags&2064&&j!==null)j.return=l,ke=j;else e:for(l=v;ke!==null;){if(o=ke,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:Sd(9,o)}}catch(S){Nt(o,o.return,S)}if(o===l){ke=null;break e}var w=o.sibling;if(w!==null){w.return=o.return,ke=w;break e}ke=o.return}}if(qe=i,ci(),Us&&typeof Us.onPostCommitFiberRoot=="function")try{Us.onPostCommitFiberRoot(gd,e)}catch{}r=!0}return r}finally{st=s,as.transition=t}}return!1}function hy(e,t,s){t=Fa(s,t),t=pk(e,t,1),e=Wr(e,t,1),t=xn(),e!==null&&(Do(e,1,t),An(e,t))}function Nt(e,t,s){if(e.tag===3)hy(e,e,s);else for(;t!==null;){if(t.tag===3){hy(t,e,s);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Hr===null||!Hr.has(r))){e=Fa(s,e),e=gk(t,e,1),t=Wr(t,e,1),e=xn(),t!==null&&(Do(t,1,e),An(t,e));break}}t=t.return}}function fI(e,t,s){var r=e.pingCache;r!==null&&r.delete(t),t=xn(),e.pingedLanes|=e.suspendedLanes&s,Kt===e&&(Qt&s)===s&&(Lt===4||Lt===3&&(Qt&130023424)===Qt&&500>Tt()-Fg?Ei(e,0):Lg|=s),An(e,t)}function Dk(e,t){t===0&&(e.mode&1?(t=hc,hc<<=1,!(hc&130023424)&&(hc=4194304)):t=1);var s=xn();e=hr(e,t),e!==null&&(Do(e,t,s),An(e,s))}function mI(e){var t=e.memoizedState,s=0;t!==null&&(s=t.retryLane),Dk(e,s)}function pI(e,t){var s=0;switch(e.tag){case 13:var r=e.stateNode,i=e.memoizedState;i!==null&&(s=i.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(ae(314))}r!==null&&r.delete(t),Dk(e,s)}var _k;_k=function(e,t,s){if(e!==null)if(e.memoizedProps!==t.pendingProps||Cn.current)Sn=!0;else{if(!(e.lanes&s)&&!(t.flags&128))return Sn=!1,nI(e,t,s);Sn=!!(e.flags&131072)}else Sn=!1,ht&&t.flags&1048576&&U0(t,$u,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;su(e,t),e=t.pendingProps;var i=Oa(t,dn.current);Ca(t,s),i=Pg(null,t,r,e,i,s);var a=$g();return t.flags|=1,typeof i=="object"&&i!==null&&typeof i.render=="function"&&i.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,En(r)?(a=!0,Iu(t)):a=!1,t.memoizedState=i.state!==null&&i.state!==void 0?i.state:null,Eg(t),i.updater=kd,t.stateNode=i,i._reactInternals=t,pm(t,r,e,s),t=vm(null,t,r,!0,a,s)):(t.tag=0,ht&&a&&yg(t),pn(null,t,i,s),t=t.child),t;case 16:r=t.elementType;e:{switch(su(e,t),e=t.pendingProps,i=r._init,r=i(r._payload),t.type=r,i=t.tag=xI(r),e=hs(r,e),i){case 0:t=xm(null,t,r,e,s);break e;case 1:t=ny(null,t,r,e,s);break e;case 11:t=ey(null,t,r,e,s);break e;case 14:t=ty(null,t,r,hs(r.type,e),s);break e}throw Error(ae(306,r,""))}return t;case 0:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),xm(e,t,r,i,s);case 1:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),ny(e,t,r,i,s);case 3:e:{if(yk(t),e===null)throw Error(ae(387));r=t.pendingProps,a=t.memoizedState,i=a.element,G0(e,t),Du(t,r,null,s);var l=t.memoizedState;if(r=l.element,a.isDehydrated)if(a={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},t.updateQueue.baseState=a,t.memoizedState=a,t.flags&256){i=Fa(Error(ae(423)),t),t=sy(e,t,r,s,i);break e}else if(r!==i){i=Fa(Error(ae(424)),t),t=sy(e,t,r,s,i);break e}else for(Fn=Br(t.stateNode.containerInfo.firstChild),Un=t,ht=!0,ms=null,s=K0(t,null,r,s),t.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(Da(),r===i){t=fr(e,t,s);break e}pn(e,t,r,s)}t=t.child}return t;case 5:return Y0(t),e===null&&hm(t),r=t.type,i=t.pendingProps,a=e!==null?e.memoizedProps:null,l=i.children,lm(r,i)?l=null:a!==null&&lm(r,a)&&(t.flags|=32),jk(e,t),pn(e,t,l,s),t.child;case 6:return e===null&&hm(t),null;case 13:return wk(e,t,s);case 4:return Ag(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=_a(t,null,r,s):pn(e,t,r,s),t.child;case 11:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),ey(e,t,r,i,s);case 7:return pn(e,t,t.pendingProps,s),t.child;case 8:return pn(e,t,t.pendingProps.children,s),t.child;case 12:return pn(e,t,t.pendingProps.children,s),t.child;case 10:e:{if(r=t.type._context,i=t.pendingProps,a=t.memoizedProps,l=i.value,lt(Mu,r._currentValue),r._currentValue=l,a!==null)if(ws(a.value,l)){if(a.children===i.children&&!Cn.current){t=fr(e,t,s);break e}}else for(a=t.child,a!==null&&(a.return=t);a!==null;){var o=a.dependencies;if(o!==null){l=a.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(a.tag===1){c=ar(-1,s&-s),c.tag=2;var u=a.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?c.next=c:(c.next=d.next,d.next=c),u.pending=c}}a.lanes|=s,c=a.alternate,c!==null&&(c.lanes|=s),fm(a.return,s,t),o.lanes|=s;break}c=c.next}}else if(a.tag===10)l=a.type===t.type?null:a.child;else if(a.tag===18){if(l=a.return,l===null)throw Error(ae(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),fm(l,s,t),l=a.sibling}else l=a.child;if(l!==null)l.return=a;else for(l=a;l!==null;){if(l===t){l=null;break}if(a=l.sibling,a!==null){a.return=l.return,l=a;break}l=l.return}a=l}pn(e,t,i.children,s),t=t.child}return t;case 9:return i=t.type,r=t.pendingProps.children,Ca(t,s),i=os(i),r=r(i),t.flags|=1,pn(e,t,r,s),t.child;case 14:return r=t.type,i=hs(r,t.pendingProps),i=hs(r.type,i),ty(e,t,r,i,s);case 15:return xk(e,t,t.type,t.pendingProps,s);case 17:return r=t.type,i=t.pendingProps,i=t.elementType===r?i:hs(r,i),su(e,t),t.tag=1,En(r)?(e=!0,Iu(t)):e=!1,Ca(t,s),mk(t,r,i),pm(t,r,i,s),vm(null,t,r,!0,e,s);case 19:return bk(e,t,s);case 22:return vk(e,t,s)}throw Error(ae(156,t.tag))};function Lk(e,t){return d0(e,t)}function gI(e,t,s,r){this.tag=e,this.key=s,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function is(e,t,s,r){return new gI(e,t,s,r)}function Wg(e){return e=e.prototype,!(!e||!e.isReactComponent)}function xI(e){if(typeof e=="function")return Wg(e)?1:0;if(e!=null){if(e=e.$$typeof,e===og)return 11;if(e===cg)return 14}return 2}function Vr(e,t){var s=e.alternate;return s===null?(s=is(e.tag,t,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=t,s.type=e.type,s.flags=0,s.subtreeFlags=0,s.deletions=null),s.flags=e.flags&14680064,s.childLanes=e.childLanes,s.lanes=e.lanes,s.child=e.child,s.memoizedProps=e.memoizedProps,s.memoizedState=e.memoizedState,s.updateQueue=e.updateQueue,t=e.dependencies,s.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function au(e,t,s,r,i,a){var l=2;if(r=e,typeof e=="function")Wg(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case ca:return Ai(s.children,i,a,t);case lg:l=8,i|=8;break;case Ff:return e=is(12,s,t,i|2),e.elementType=Ff,e.lanes=a,e;case zf:return e=is(13,s,t,i),e.elementType=zf,e.lanes=a,e;case Uf:return e=is(19,s,t,i),e.elementType=Uf,e.lanes=a,e;case Yb:return Cd(s,i,a,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Vb:l=10;break e;case Gb:l=9;break e;case og:l=11;break e;case cg:l=14;break e;case Tr:l=16,r=null;break e}throw Error(ae(130,e==null?e:typeof e,""))}return t=is(l,s,t,i),t.elementType=e,t.type=r,t.lanes=a,t}function Ai(e,t,s,r){return e=is(7,e,r,t),e.lanes=s,e}function Cd(e,t,s,r){return e=is(22,e,r,t),e.elementType=Yb,e.lanes=s,e.stateNode={isHidden:!1},e}function zh(e,t,s){return e=is(6,e,null,t),e.lanes=s,e}function Uh(e,t,s){return t=is(4,e.children!==null?e.children:[],e.key,t),t.lanes=s,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function vI(e,t,s,r,i){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=wh(0),this.expirationTimes=wh(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=wh(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function Hg(e,t,s,r,i,a,l,o,c){return e=new vI(e,t,s,o,c),t===1?(t=1,a===!0&&(t|=8)):t=0,a=is(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Eg(a),e}function jI(e,t,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:oa,key:r==null?null:""+r,children:e,containerInfo:t,implementation:s}}function Fk(e){if(!e)return Zr;e=e._reactInternals;e:{if(Bi(e)!==e||e.tag!==1)throw Error(ae(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(En(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(ae(171))}if(e.tag===1){var s=e.type;if(En(s))return F0(e,s,t)}return t}function zk(e,t,s,r,i,a,l,o,c){return e=Hg(s,r,!0,e,i,a,l,o,c),e.context=Fk(null),s=e.current,r=xn(),i=Kr(s),a=ar(r,i),a.callback=t??null,Wr(s,a,i),e.current.lanes=i,Do(e,i,r),An(e,r),e}function Ed(e,t,s,r){var i=t.current,a=xn(),l=Kr(i);return s=Fk(s),t.context===null?t.context=s:t.pendingContext=s,t=ar(a,l),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=Wr(i,t,l),e!==null&&(xs(e,i,l,a),eu(e,i,l)),l}function Hu(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function fy(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<t?s:t}}function Kg(e,t){fy(e,t),(e=e.alternate)&&fy(e,t)}function yI(){return null}var Uk=typeof reportError=="function"?reportError:function(e){console.error(e)};function Vg(e){this._internalRoot=e}Ad.prototype.render=Vg.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(ae(409));Ed(e,t,null,null)};Ad.prototype.unmount=Vg.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Mi(function(){Ed(null,e,null,null)}),t[dr]=null}};function Ad(e){this._internalRoot=e}Ad.prototype.unstable_scheduleHydration=function(e){if(e){var t=v0();e={blockedOn:null,target:e,priority:t};for(var s=0;s<Ir.length&&t!==0&&t<Ir[s].priority;s++);Ir.splice(s,0,e),s===0&&y0(e)}};function Gg(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Td(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function my(){}function wI(e,t,s,r,i){if(i){if(typeof r=="function"){var a=r;r=function(){var u=Hu(l);a.call(u)}}var l=zk(t,r,e,0,null,!1,!1,"",my);return e._reactRootContainer=l,e[dr]=l.current,lo(e.nodeType===8?e.parentNode:e),Mi(),l}for(;i=e.lastChild;)e.removeChild(i);if(typeof r=="function"){var o=r;r=function(){var u=Hu(c);o.call(u)}}var c=Hg(e,0,!1,null,null,!1,!1,"",my);return e._reactRootContainer=c,e[dr]=c.current,lo(e.nodeType===8?e.parentNode:e),Mi(function(){Ed(t,c,s,r)}),c}function Rd(e,t,s,r,i){var a=s._reactRootContainer;if(a){var l=a;if(typeof i=="function"){var o=i;i=function(){var c=Hu(l);o.call(c)}}Ed(t,l,e,i)}else l=wI(s,t,e,i,r);return Hu(l)}g0=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var s=Ol(t.pendingLanes);s!==0&&(hg(t,s|1),An(t,Tt()),!(qe&6)&&(za=Tt()+500,ci()))}break;case 13:Mi(function(){var r=hr(e,1);if(r!==null){var i=xn();xs(r,e,1,i)}}),Kg(e,1)}};fg=function(e){if(e.tag===13){var t=hr(e,134217728);if(t!==null){var s=xn();xs(t,e,134217728,s)}Kg(e,134217728)}};x0=function(e){if(e.tag===13){var t=Kr(e),s=hr(e,t);if(s!==null){var r=xn();xs(s,e,t,r)}Kg(e,t)}};v0=function(){return st};j0=function(e,t){var s=st;try{return st=e,t()}finally{st=s}};Jf=function(e,t,s){switch(t){case"input":if(Hf(e,s),t=s.name,s.type==="radio"&&t!=null){for(s=e;s.parentNode;)s=s.parentNode;for(s=s.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<s.length;t++){var r=s[t];if(r!==e&&r.form===e.form){var i=yd(r);if(!i)throw Error(ae(90));Qb(r),Hf(r,i)}}}break;case"textarea":Xb(e,s);break;case"select":t=s.value,t!=null&&ba(e,!!s.multiple,t,!1)}};i0=zg;a0=Mi;var bI={usingClientEntryPoint:!1,Events:[Lo,fa,yd,s0,r0,zg]},Cl={findFiberByHostInstance:Si,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},kI={bundleType:Cl.bundleType,version:Cl.version,rendererPackageName:Cl.rendererPackageName,rendererConfig:Cl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:vr.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=c0(e),e===null?null:e.stateNode},findFiberByHostInstance:Cl.findFiberByHostInstance||yI,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var kc=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!kc.isDisabled&&kc.supportsFiber)try{gd=kc.inject(kI),Us=kc}catch{}}Kn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=bI;Kn.createPortal=function(e,t){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Gg(t))throw Error(ae(200));return jI(e,t,null,s)};Kn.createRoot=function(e,t){if(!Gg(e))throw Error(ae(299));var s=!1,r="",i=Uk;return t!=null&&(t.unstable_strictMode===!0&&(s=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),t=Hg(e,1,!1,null,null,s,!1,r,i),e[dr]=t.current,lo(e.nodeType===8?e.parentNode:e),new Vg(t)};Kn.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(ae(188)):(e=Object.keys(e).join(","),Error(ae(268,e)));return e=c0(t),e=e===null?null:e.stateNode,e};Kn.flushSync=function(e){return Mi(e)};Kn.hydrate=function(e,t,s){if(!Td(t))throw Error(ae(200));return Rd(null,e,t,!0,s)};Kn.hydrateRoot=function(e,t,s){if(!Gg(e))throw Error(ae(405));var r=s!=null&&s.hydratedSources||null,i=!1,a="",l=Uk;if(s!=null&&(s.unstable_strictMode===!0&&(i=!0),s.identifierPrefix!==void 0&&(a=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),t=zk(t,null,e,1,s??null,i,!1,a,l),e[dr]=t.current,lo(e),r)for(e=0;e<r.length;e++)s=r[e],i=s._getVersion,i=i(s._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[s,i]:t.mutableSourceEagerHydrationData.push(s,i);return new Ad(t)};Kn.render=function(e,t,s){if(!Td(t))throw Error(ae(200));return Rd(null,e,t,!1,s)};Kn.unmountComponentAtNode=function(e){if(!Td(e))throw Error(ae(40));return e._reactRootContainer?(Mi(function(){Rd(null,null,e,!1,function(){e._reactRootContainer=null,e[dr]=null})}),!0):!1};Kn.unstable_batchedUpdates=zg;Kn.unstable_renderSubtreeIntoContainer=function(e,t,s,r){if(!Td(s))throw Error(ae(200));if(e==null||e._reactInternals===void 0)throw Error(ae(38));return Rd(e,t,s,!1,r)};Kn.version="18.3.1-next-f1338f8080-20240426";function Bk(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Bk)}catch(e){console.error(e)}}Bk(),Bb.exports=Kn;var zo=Bb.exports,Wk,py=zo;Wk=py.createRoot,py.hydrateRoot;var SI=Object.defineProperty,nl=(e,t)=>SI(e,"name",{value:t,configurable:!0}),Hk=!!(typeof window<"u"&&window.document&&window.document.createElement);function Re(e,t,{checkForDefaultPrevented:s=!0}={}){return nl(function(i){if(e==null||e(i),s===!1||!i||!i.defaultPrevented)return t==null?void 0:t(i)},"handleEvent")}nl(Re,"composeEventHandlers");function NI(e){var t;if(!Hk)throw new Error("Cannot access window outside of the DOM");return((t=e==null?void 0:e.ownerDocument)==null?void 0:t.defaultView)??window}nl(NI,"getOwnerWindow");function Rm(e){if(!Hk)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}nl(Rm,"getOwnerDocument");function Kk(e,t=!1){const{activeElement:s}=Rm(e);if(!(s!=null&&s.nodeName))return null;if(Vk(s)&&s.contentDocument)return Kk(s.contentDocument.body,t);if(t){const r=s.getAttribute("aria-activedescendant");if(r){const i=Rm(s).getElementById(r);if(i)return i}}return s}nl(Kk,"getActiveElement");function Vk(e){return e.tagName==="IFRAME"}nl(Vk,"isFrame");var CI=Object.defineProperty,Yg=(e,t)=>CI(e,"name",{value:t,configurable:!0});function Im(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}Yg(Im,"setRef");function Gk(...e){return t=>{let s=!1;const r=e.map(i=>{const a=Im(i,t);return!s&&typeof a=="function"&&(s=!0),a});if(s)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Im(e[i],null)}}}}Yg(Gk,"composeRefs");function ut(...e){return f.useCallback(Gk(...e),e)}Yg(ut,"useComposedRefs");var EI=Object.defineProperty,rs=(e,t)=>EI(e,"name",{value:t,configurable:!0});function AI(e,t){const s=f.createContext(t);s.displayName=e+"Context";const r=rs(a=>{const{children:l,...o}=a,c=f.useMemo(()=>o,Object.values(o));return n.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function i(a,l={}){const{optional:o=!1}=l,c=f.useContext(s);if(c)return c;if(t!==void 0)return t;if(!o)throw new Error(`\`${a}\` must be used within \`${e}\``)}return rs(i,"useContext"),[r,i]}rs(AI,"createContext");function Ns(e,t=[]){let s=[];function r(a,l){const o=f.createContext(l);o.displayName=a+"Context";const c=s.length;s=[...s,l];const u=rs(h=>{var x;const{scope:m,children:p,...g}=h,y=((x=m==null?void 0:m[e])==null?void 0:x[c])||o,b=f.useMemo(()=>g,Object.values(g));return n.jsx(y.Provider,{value:b,children:p})},"Provider");u.displayName=a+"Provider";function d(h,m,p={}){var x;const{optional:g=!1}=p,y=((x=m==null?void 0:m[e])==null?void 0:x[c])||o,b=f.useContext(y);if(b)return b;if(l!==void 0)return l;if(!g)throw new Error(`\`${h}\` must be used within \`${a}\``)}return rs(d,"useContext"),[u,d]}rs(r,"createContext");const i=rs(()=>{const a=s.map(l=>f.createContext(l));return rs(function(o){const c=(o==null?void 0:o[e])||a;return f.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return i.scopeName=e,[r,Yk(i,...t)]}rs(Ns,"createContextScope");function Yk(...e){const t=e[0];if(e.length===1)return t;const s=rs(()=>{const r=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return rs(function(a){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const h=c(a)[`__scope${u}`];return{...o,...h}},{});return f.useMemo(()=>({[`__scope${t.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=t.scopeName,s}rs(Yk,"composeContextScopes");var TI=Object.defineProperty,Cs=(e,t)=>TI(e,"name",{value:t,configurable:!0});function ei(e){const t=f.forwardRef((s,r)=>{let{children:i,...a}=s,l=null,o=!1;const c=[];Pm(i)&&typeof Sc=="function"&&(i=Sc(i._payload)),f.Children.forEach(i,m=>{var p;if(Zk(m)){o=!0;const g=m;let y="child"in g.props?g.props.child:g.props.children;Pm(y)&&typeof Sc=="function"&&(y=Sc(y._payload)),l=RI(g,y),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=f.cloneElement(l,void 0,c):!o&&f.Children.count(i)===1&&f.isValidElement(i)&&(l=i);const u=l?Xk(l):void 0,d=ut(r,u);if(!l){if(i||i===0)throw new Error(o?$I(e):PI(e));return i}const h=Jk(a,l.props??{});return l.type!==f.Fragment&&(h.ref=r?d:u),f.cloneElement(l,h)});return t.displayName=`${e}.Slot`,t}Cs(ei,"createSlot");var qk=Symbol.for("radix.slottable");function Qk(e){const t=Cs(s=>"child"in s?s.children(s.child):s.children,"Slottable");return t.displayName=`${e}.Slottable`,t.__radixId=qk,t}Cs(Qk,"createSlottable");var RI=Cs((e,t)=>{if("child"in e.props){const s=e.props.child;return f.isValidElement(s)?f.cloneElement(s,void 0,e.props.children(s.props.children)):null}return f.isValidElement(t)?t:null},"getSlottableElementFromSlottable");function Jk(e,t){const s={...t};for(const r in t){const i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?s[r]=(...o)=>{const c=a(...o);return i(...o),c}:i&&(s[r]=i):r==="style"?s[r]={...i,...a}:r==="className"&&(s[r]=[i,a].filter(Boolean).join(" "))}return{...e,...s}}Cs(Jk,"mergeProps");function Xk(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}Cs(Xk,"getElementRef");function Zk(e){return f.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===qk}Cs(Zk,"isSlottable");var II=Symbol.for("react.lazy");function Pm(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===II&&"_payload"in e&&eS(e._payload)}Cs(Pm,"isLazyComponent");function eS(e){return typeof e=="object"&&e!==null&&"then"in e}Cs(eS,"isPromiseLike");var PI=Cs(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),$I=Cs(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Sc=Za[" use ".trim().toString()],MI=Object.defineProperty,Wt=(e,t)=>MI(e,"name",{value:t,configurable:!0});function Id(e){const t=e+"CollectionProvider",[s,r]=Ns(t),[i,a]=s(t,{collectionRef:{current:null},itemMap:new Map}),l=Wt(y=>{const{scope:b,children:x}=y,v=f.useRef(null),j=f.useRef(new Map).current;return n.jsx(i,{scope:b,itemMap:j,collectionRef:v,children:x})},"CollectionProvider");l.displayName=t;const o=e+"CollectionSlot",c=ei(o),u=f.forwardRef((y,b)=>{const{scope:x,children:v}=y,j=a(o,x),w=ut(b,j.collectionRef);return n.jsx(c,{ref:w,children:v})});u.displayName=o;const d=e+"CollectionItemSlot",h="data-radix-collection-item",m=ei(d),p=f.forwardRef((y,b)=>{const{scope:x,children:v,...j}=y,w=f.useRef(null),S=ut(b,w),k=a(d,x);return f.useEffect(()=>(k.itemMap.set(w,{ref:w,...j}),()=>void k.itemMap.delete(w))),n.jsx(m,{[h]:"",ref:S,children:v})});p.displayName=d;function g(y){const b=a(e+"CollectionConsumer",y);return f.useCallback(()=>{const v=b.collectionRef.current;if(!v)return[];const j=Array.from(v.querySelectorAll(`[${h}]`));return Array.from(b.itemMap.values()).sort((k,N)=>j.indexOf(k.ref.current)-j.indexOf(N.ref.current))},[b.collectionRef,b.itemMap])}return Wt(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}Wt(Id,"createCollection");var gy=new WeakMap,$t,Ln,Bh=(Ln=class extends Map{constructor(s){super(s);aj(this,$t);ph(this,$t,[...super.keys()]),gy.set(this,!0)}set(s,r){return gy.get(this)&&(this.has(s)?sn(this,$t)[sn(this,$t).indexOf(s)]=s:sn(this,$t).push(s)),super.set(s,r),this}insert(s,r,i){const a=this.has(r),l=sn(this,$t).length,o=qg(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||a&&u===this.size-1||u===-1)return this.set(r,i),this;const d=this.size+(a?0:1);o<0&&c++;const h=[...sn(this,$t)];let m,p=!1;for(let g=c;g<d;g++)if(c===g){let y=h[g];h[g]===r&&(y=h[g+1]),a&&this.delete(r),m=this.get(y),this.set(r,i)}else{!p&&h[g-1]===r&&(p=!0);const y=h[p?g:g-1],b=m;m=this.get(y),this.delete(y),this.set(y,b)}return this}with(s,r,i){const a=new Ln(this);return a.insert(s,r,i),a}before(s){const r=sn(this,$t).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,i){const a=sn(this,$t).indexOf(s);return a===-1?this:this.insert(a,r,i)}after(s){let r=sn(this,$t).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,i){const a=sn(this,$t).indexOf(s);return a===-1?this:this.insert(a+1,r,i)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return ph(this,$t,[]),super.clear()}delete(s){const r=super.delete(s);return r&&sn(this,$t).splice(sn(this,$t).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=lu(sn(this,$t),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=lu(sn(this,$t),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return sn(this,$t).indexOf(s)}keyAt(s){return lu(sn(this,$t),s)}from(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.at(a)}keyFrom(s,r){const i=this.indexOf(s);if(i===-1)return;let a=i+r;return a<0&&(a=0),a>=this.size&&(a=this.size-1),this.keyAt(a)}find(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return a;i++}}findIndex(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return i;i++}return-1}filter(s,r){const i=[];let a=0;for(const l of this)Reflect.apply(s,r,[l,a,this])&&i.push(l),a++;return new Ln(i)}map(s,r){const i=[];let a=0;for(const l of this)i.push([l[0],Reflect.apply(s,r,[l,a,this])]),a++;return new Ln(i)}reduce(...s){const[r,i]=s;let a=0,l=i??this.at(0);for(const o of this)a===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,a,this]),a++;return l}reduceRight(...s){const[r,i]=s;let a=i??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?a=o:a=Reflect.apply(r,this,[a,o,l,this])}return a}toSorted(s){const r=[...this.entries()].sort(s);return new Ln(r)}toReversed(){const s=new Ln;for(let r=this.size-1;r>=0;r--){const i=this.keyAt(r),a=this.get(i);s.set(i,a)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new Ln(r)}slice(s,r){const i=new Ln;let a=this.size-1;if(s===void 0)return i;s<0&&(s=s+this.size),r!==void 0&&r>0&&(a=r-1);for(let l=s;l<=a;l++){const o=this.keyAt(l),c=this.get(o);i.set(o,c)}return i}every(s,r){let i=0;for(const a of this){if(!Reflect.apply(s,r,[a,i,this]))return!1;i++}return!0}some(s,r){let i=0;for(const a of this){if(Reflect.apply(s,r,[a,i,this]))return!0;i++}return!1}},$t=new WeakMap,Wt(Ln,"OrderedDict"),Ln);function lu(e,t){if("at"in Array.prototype)return Array.prototype.at.call(e,t);const s=tS(e,t);return s===-1?void 0:e[s]}Wt(lu,"at");function tS(e,t){const s=e.length,r=qg(t),i=r>=0?r:s+r;return i<0||i>=s?-1:i}Wt(tS,"toSafeIndex");function qg(e){return e!==e||e===0?0:Math.trunc(e)}Wt(qg,"toSafeInteger");function OI(e){const t=e+"CollectionProvider",[s,r]=Ns(t),[i,a]=s(t,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new Bh,setItemMap:Wt(()=>{},"setItemMap")}),l=Wt(({state:j,...w})=>j?n.jsx(c,{...w,state:j}):n.jsx(o,{...w}),"CollectionProvider");l.displayName=t;const o=Wt(j=>{const w=b();return n.jsx(c,{...j,state:w})},"CollectionInit");o.displayName=t+"Init";const c=Wt(j=>{const{scope:w,children:S,state:k}=j,N=f.useRef(null),[C,I]=f.useState(null),A=ut(N,I),[_,z]=k;return f.useEffect(()=>{if(!C)return;const L=rS(()=>{});return L.observe(C,{childList:!0,subtree:!0}),()=>{L.disconnect()}},[C]),n.jsx(i,{scope:w,itemMap:_,setItemMap:z,collectionRef:A,collectionRefObject:N,collectionElement:C,children:S})},"CollectionProviderImpl");c.displayName=t+"Impl";const u=e+"CollectionSlot",d=ei(u),h=f.forwardRef((j,w)=>{const{scope:S,children:k}=j,N=a(u,S),C=ut(w,N.collectionRef);return n.jsx(d,{ref:C,children:k})});h.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=ei(m),y=f.forwardRef((j,w)=>{const{scope:S,children:k,...N}=j,C=f.useRef(null),[I,A]=f.useState(null),_=ut(w,C,A),z=a(m,S),{setItemMap:L}=z,E=f.useRef(N);nS(E.current,N)||(E.current=N);const M=E.current;return f.useEffect(()=>{const D=M;return L(U=>I?U.has(I)?U.set(I,{...D,element:I}).toSorted($m):(U.set(I,{...D,element:I}),U.toSorted($m)):U),()=>{L(U=>!I||!U.has(I)?U:(U.delete(I),new Bh(U)))}},[I,M,L]),n.jsx(g,{[p]:"",ref:_,children:k})});y.displayName=m;function b(){return f.useState(new Bh)}Wt(b,"useInitCollection");function x(j){const{itemMap:w}=a(e+"CollectionConsumer",j);return w}return Wt(x,"useCollection"),[{Provider:l,Slot:h,ItemSlot:y},{createCollectionScope:r,useCollection:x,useInitCollection:b}]}Wt(OI,"createCollection");function nS(e,t){if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e==null||t==null)return!1;const s=Object.keys(e),r=Object.keys(t);if(s.length!==r.length)return!1;for(const i of s)if(!Object.prototype.hasOwnProperty.call(t,i)||e[i]!==t[i])return!1;return!0}Wt(nS,"shallowEqual");function sS(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Wt(sS,"isElementPreceding");function $m(e,t){return!e[1].element||!t[1].element?0:sS(e[1].element,t[1].element)?-1:1}Wt($m,"sortByDocumentPosition");function rS(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Wt(rS,"getChildListObserver");var DI=Object.defineProperty,_I=(e,t)=>DI(e,"name",{value:t,configurable:!0}),LI=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],bt=LI.reduce((e,t)=>{const s=ei(`Primitive.${t}`),r=f.forwardRef((i,a)=>{const{asChild:l,...o}=i,c=l?s:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),n.jsx(c,{...o,ref:a})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Pd(e,t){e&&zo.flushSync(()=>e.dispatchEvent(t))}_I(Pd,"dispatchDiscreteCustomEvent");var FI=Object.defineProperty,zI=(e,t)=>FI(e,"name",{value:t,configurable:!0});function us(e){const t=f.useRef(e);return f.useEffect(()=>{t.current=e}),f.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}zI(us,"useCallbackRef");var UI=Object.defineProperty,Dt=(e,t)=>UI(e,"name",{value:t,configurable:!0}),Mm="dismissableLayer.update",BI="dismissableLayer.pointerDownOutside",WI="dismissableLayer.focusOutside",xy,Qg=f.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Jg=f.forwardRef(Dt(function(t,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:i=!1,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...d}=t,h=f.useContext(Qg),[m,p]=f.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,y]=f.useState({}),b=ut(s,p),x=Array.from(h.layers),[v]=[...h.layersWithOutsidePointerEventsDisabled].slice(-1),j=v?x.indexOf(v):-1,w=m?x.indexOf(m):-1,S=h.layersWithOutsidePointerEventsDisabled.size>0,k=w>=j,N=f.useRef(!1),C=aS(z=>{l==null||l(z),c==null||c(z),z.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:i,isDeferredPointerDownOutsideRef:N,dismissableSurfaces:h.dismissableSurfaces,shouldHandlePointerDownOutside:f.useCallback(z=>{if(!(z instanceof Node))return!1;const L=[...h.branches].some(E=>E.contains(z));return k&&!L},[h.branches,k])}),I=lS(z=>{if(i&&N.current)return;const L=z.target;[...h.branches].some(M=>M.contains(L))||(o==null||o(z),c==null||c(z),z.defaultPrevented||u==null||u())},g),A=m?w===x.length-1:!1,_=us(z=>{z.key==="Escape"&&(a==null||a(z),!z.defaultPrevented&&u&&(z.preventDefault(),u()))});return f.useEffect(()=>{if(A)return g.addEventListener("keydown",_,{capture:!0}),()=>g.removeEventListener("keydown",_,{capture:!0})},[g,A,_]),f.useEffect(()=>{if(m)return r&&(h.layersWithOutsidePointerEventsDisabled.size===0&&(xy=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),h.layersWithOutsidePointerEventsDisabled.add(m)),h.layers.add(m),Om(),()=>{r&&(h.layersWithOutsidePointerEventsDisabled.delete(m),h.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=xy))}},[m,g,r,h]),f.useEffect(()=>()=>{m&&(h.layers.delete(m),h.layersWithOutsidePointerEventsDisabled.delete(m),Om())},[m,h]),f.useEffect(()=>{const z=Dt(()=>y({}),"handleUpdate");return document.addEventListener(Mm,z),()=>document.removeEventListener(Mm,z)},[]),n.jsx(bt.div,{...d,ref:b,style:{pointerEvents:S?k?"auto":"none":void 0,...t.style},onFocusCapture:Re(t.onFocusCapture,I.onFocusCapture),onBlurCapture:Re(t.onBlurCapture,I.onBlurCapture),onPointerDownCapture:Re(t.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),HI=f.forwardRef(Dt(function(t,s){const r=f.useContext(Qg),i=f.useRef(null),a=ut(s,i);return f.useEffect(()=>{const l=i.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),n.jsx(bt.div,{...t,ref:a})},"DismissableLayerBranch"));function iS(){const e=f.useContext(Qg),[t,s]=f.useState(null);return f.useEffect(()=>{if(t)return e.dismissableSurfaces.add(t),()=>{e.dismissableSurfaces.delete(t)}},[t,e.dismissableSurfaces]),s}Dt(iS,"useDismissableLayerSurface");var KI=Dt(()=>!0,"IS_TRUE");function aS(e,t){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:i,dismissableSurfaces:a,shouldHandlePointerDownOutside:l=KI}=t,o=us(e),c=f.useRef(!1),u=f.useRef(!1),d=f.useRef(new Map),h=f.useRef(()=>{});return f.useEffect(()=>{function m(){u.current=!1,i.current=!1,d.current.clear()}Dt(m,"resetOutsideInteraction");function p(){return Array.from(d.current.values()).some(Boolean)}Dt(p,"isOutsideInteractionIntercepted");function g(j){if(!u.current)return;const w=j.target;w instanceof Node&&[...a].some(k=>k.contains(w))||d.current.set(j.type,!0),j.type==="click"&&window.setTimeout(()=>{u.current&&h.current()},0)}Dt(g,"handleInteractionCapture");function y(j){u.current&&d.current.set(j.type,!1)}Dt(y,"handleInteractionBubble");const b=Dt(j=>{if(j.target&&!c.current){let w=function(){s.removeEventListener("click",h.current);const k=p();m(),k||Xg(BI,o,S,{discrete:!0})};if(Dt(w,"handleAndDispatchPointerDownOutsideEvent"),!l(j.target)){s.removeEventListener("click",h.current),m(),c.current=!1;return}const S={originalEvent:j};u.current=!0,i.current=r&&j.button===0,d.current.clear(),!r||j.button!==0?w():(s.removeEventListener("click",h.current),h.current=w,s.addEventListener("click",h.current,{once:!0}))}else s.removeEventListener("click",h.current),m();c.current=!1},"handlePointerDown"),x=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const j of x)s.addEventListener(j,g,!0),s.addEventListener(j,y);const v=window.setTimeout(()=>{s.addEventListener("pointerdown",b)},0);return()=>{window.clearTimeout(v),s.removeEventListener("pointerdown",b),s.removeEventListener("click",h.current);for(const j of x)s.removeEventListener(j,g,!0),s.removeEventListener(j,y)}},[s,o,r,i,a,l]),{onPointerDownCapture:Dt(()=>c.current=!0,"onPointerDownCapture")}}Dt(aS,"usePointerDownOutside");function lS(e,t=globalThis==null?void 0:globalThis.document){const s=us(e),r=f.useRef(!1);return f.useEffect(()=>{const i=Dt(a=>{a.target&&!r.current&&Xg(WI,s,{originalEvent:a},{discrete:!1})},"handleFocus");return t.addEventListener("focusin",i),()=>t.removeEventListener("focusin",i)},[t,s]),{onFocusCapture:Dt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:Dt(()=>r.current=!1,"onBlurCapture")}}Dt(lS,"useFocusOutside");function Om(){const e=new CustomEvent(Mm);document.dispatchEvent(e)}Dt(Om,"dispatchUpdate");function Xg(e,t,s,{discrete:r}){const i=s.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});t&&i.addEventListener(e,t,{once:!0}),r?Pd(i,a):i.dispatchEvent(a)}Dt(Xg,"handleAndDispatchCustomEvent");var VI=HI,Tn=globalThis!=null&&globalThis.document?f.useLayoutEffect:()=>{},GI=Object.defineProperty,YI=(e,t)=>GI(e,"name",{value:t,configurable:!0}),Zg=f.forwardRef(YI(function(t,s){var c;const{container:r,...i}=t,[a,l]=f.useState(!1);Tn(()=>l(!0),[]);const o=r||a&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?zo.createPortal(n.jsx(bt.div,{...i,ref:s}),o):null},"Portal")),qI=Object.defineProperty,mr=(e,t)=>qI(e,"name",{value:t,configurable:!0});function oS(e,t){return f.useReducer((s,r)=>t[s][r]??s,e)}mr(oS,"useStateMachine");var jr=mr(e=>{const{present:t,children:s}=e,r=cS(t),i=typeof s=="function"?s({present:r.isPresent}):f.Children.only(s),a=uS(r.ref,dS(i));return typeof s=="function"||r.isPresent?f.cloneElement(i,{ref:a}):null},"Presence");function cS(e){const[t,s]=f.useState(),r=f.useRef(null),i=f.useRef(e),a=f.useRef("none"),l=f.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=oS(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return f.useEffect(()=>{c==="mounted"?(a.current=l.current??aa(r.current),l.current=void 0):a.current="none"},[c]),Tn(()=>{const d=r.current,h=i.current;if(h!==e){const p=a.current,g=aa(d);e?(l.current=g,u("MOUNT")):g==="none"||(d==null?void 0:d.display)==="none"?u("UNMOUNT"):u(h&&p!==g?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),Tn(()=>{if(t){let d;const h=t.ownerDocument.defaultView??window,m=mr(g=>{const b=aa(r.current).includes(CSS.escape(g.animationName));if(g.target===t&&b&&(u("ANIMATION_END"),!i.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",d=h.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},"handleAnimationEnd"),p=mr(g=>{g.target===t&&(a.current=aa(r.current))},"handleAnimationStart");return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{h.clearTimeout(d),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:f.useCallback(d=>{if(d){const h=getComputedStyle(d);r.current=h,l.current=aa(h)}else r.current=null;s(d)},[])}}mr(cS,"usePresence");function Dm(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}mr(Dm,"setRef");function uS(...e){const t=f.useRef(e);return t.current=e,f.useCallback(s=>{const r=t.current;let i=!1;const a=r.map(l=>{const o=Dm(l,s);return!i&&typeof o=="function"&&(i=!0),o});if(i)return()=>{for(let l=0;l<a.length;l++){const o=a[l];typeof o=="function"?o():Dm(r[l],null)}}},[])}mr(uS,"useStableComposedRefs");function aa(e){return(e==null?void 0:e.animationName)||"none"}mr(aa,"getAnimationName");function dS(e){var r,i;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=t&&"isReactWarning"in t&&t.isReactWarning;return s?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,s=t&&"isReactWarning"in t&&t.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}mr(dS,"getElementRef");var QI=Object.defineProperty,JI=(e,t)=>QI(e,"name",{value:t,configurable:!0}),vy=Za[" useEffectEvent ".trim().toString()],jy=Za[" useInsertionEffect ".trim().toString()];function hS(e){if(typeof vy=="function")return vy(e);const t=f.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof jy=="function"?jy(()=>{t.current=e}):Tn(()=>{t.current=e}),f.useMemo(()=>(...s)=>{var r;return(r=t.current)==null?void 0:r.call(t,...s)},[])}JI(hS,"useEffectEvent");var XI=Object.defineProperty,Uo=(e,t)=>XI(e,"name",{value:t,configurable:!0}),ZI=Za[" useInsertionEffect ".trim().toString()]||Tn;function Wi({prop:e,defaultProp:t,onChange:s=Uo(()=>{},"onChange"),caller:r}){const[i,a,l]=fS({defaultProp:t,onChange:s}),o=e!==void 0,c=o?e:i,u=f.useCallback(d=>{var h;if(o){const m=mS(d)?d(e):d;m!==e&&((h=l.current)==null||h.call(l,m))}else a(d)},[o,e,a,l]);return[c,u]}Uo(Wi,"useControllableState");function fS({defaultProp:e,onChange:t}){const[s,r]=f.useState(e),i=f.useRef(s),a=f.useRef(t);return ZI(()=>{a.current=t},[t]),f.useEffect(()=>{var l;i.current!==s&&((l=a.current)==null||l.call(a,s),i.current=s)},[s,i]),[s,r,a]}Uo(fS,"useUncontrolledState");function mS(e){return typeof e=="function"}Uo(mS,"isFunction");var yy=Symbol("RADIX:SYNC_STATE");function eP(e,t,s,r){const{prop:i,defaultProp:a,onChange:l,caller:o}=t,c=i!==void 0,u=hS(l),d=[{...s,state:a}];r&&d.push(r);const[h,m]=f.useReducer((b,x)=>{if(x.type===yy)return{...b,state:x.state};const v=e(b,x);return c&&!Object.is(v.state,b.state)&&u(v.state),v},...d),p=h.state,g=f.useRef(p);f.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const y=f.useMemo(()=>i!==void 0?{...h,state:i}:h,[h,i]);return f.useEffect(()=>{c&&!Object.is(i,h.state)&&m({type:yy,state:i})},[i,h.state,c]),[y,m]}Uo(eP,"useControllableStateReducer");var tP=Object.defineProperty,nP=(e,t)=>tP(e,"name",{value:t,configurable:!0}),sP=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),pS=f.forwardRef(nP(function(t,s){return n.jsx(bt.span,{...t,ref:s,style:{...sP,...t.style}})},"VisuallyHidden")),rP=pS,iP=Object.defineProperty,ln=(e,t)=>iP(e,"name",{value:t,configurable:!0}),gS="ToastProvider",[xS,aP,lP]=Id("Toast"),[vS,dV]=Ns("Toast",[lP]),[oP,jS]=vS(gS),cP=ln(e=>{const{__scopeToast:t,label:s="Notification",duration:r=5e3,swipeDirection:i="right",swipeThreshold:a=50,announcerContainer:l,children:o}=e,[c,u]=f.useState(null),[d,h]=f.useState(0),m=f.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${gS}\`. Expected non-empty \`string\`.`),n.jsx(xS.Provider,{scope:t,children:n.jsx(oP,{scope:t,label:s,duration:r,swipeDirection:i,swipeThreshold:a,toastCount:d,viewport:c,onViewportChange:u,onToastAdd:f.useCallback(()=>h(p=>p+1),[]),onToastRemove:f.useCallback(()=>h(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),uP="ToastViewport",dP=["F8"],hP="toast.viewportPause",fP="toast.viewportResume",mP=f.forwardRef(ln(function(t,s){const{__scopeToast:r,hotkey:i=dP,label:a="Notifications ({hotkey})",...l}=t,o=jS(uP,r),c=aP(r),u=f.useRef(null),d=f.useRef(null),h=f.useRef(null),m=f.useRef(null),p=ut(s,m,o.onViewportChange),g=i.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=o.toastCount>0;f.useEffect(()=>{const x=ln(v=>{var w;i.length!==0&&i.every(S=>v[S]||v.code===S)&&((w=m.current)==null||w.focus())},"handleKeyDown");return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[i]),f.useEffect(()=>{const x=u.current,v=m.current;if(y&&x&&v){const j=ln(()=>{if(!o.isClosePausedRef.current){const N=new CustomEvent(hP);v.dispatchEvent(N),o.isClosePausedRef.current=!0}},"handlePause"),w=ln(()=>{if(o.isClosePausedRef.current){const N=new CustomEvent(fP);v.dispatchEvent(N),o.isClosePausedRef.current=!1}},"handleResume"),S=ln(N=>{!x.contains(N.relatedTarget)&&w()},"handleFocusOutResume"),k=ln(()=>{x.contains(document.activeElement)||w()},"handlePointerLeaveResume");return x.addEventListener("focusin",j),x.addEventListener("focusout",S),x.addEventListener("pointermove",j),x.addEventListener("pointerleave",k),window.addEventListener("blur",j),window.addEventListener("focus",w),()=>{x.removeEventListener("focusin",j),x.removeEventListener("focusout",S),x.removeEventListener("pointermove",j),x.removeEventListener("pointerleave",k),window.removeEventListener("blur",j),window.removeEventListener("focus",w)}}},[y,o.isClosePausedRef]);const b=f.useCallback(({tabbingDirection:x})=>{const j=c().map(w=>{const S=w.ref.current,k=[S,...bS(S)];return x==="forwards"?k:k.reverse()});return(x==="forwards"?j.reverse():j).flat()},[c]);return f.useEffect(()=>{const x=m.current;if(x){const v=ln(j=>{var k,N,C;const w=j.altKey||j.ctrlKey||j.metaKey;if(j.key==="Tab"&&!w){const I=document.activeElement,A=j.shiftKey;if(j.target===x&&A){(k=d.current)==null||k.focus();return}const L=b({tabbingDirection:A?"backwards":"forwards"}),E=L.findIndex(M=>M===I);ou(L.slice(E+1))?j.preventDefault():A?(N=d.current)==null||N.focus():(C=h.current)==null||C.focus()}},"handleKeyDown");return x.addEventListener("keydown",v),()=>x.removeEventListener("keydown",v)}},[c,b]),n.jsxs(VI,{ref:u,role:"region","aria-label":a.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:y?void 0:"none"},children:[y&&n.jsx(wy,{ref:d,onFocusFromOutsideViewport:()=>{const x=b({tabbingDirection:"forwards"});ou(x)}}),n.jsx(xS.Slot,{scope:r,children:n.jsx(bt.ol,{tabIndex:-1,...l,ref:p})}),y&&n.jsx(wy,{ref:h,onFocusFromOutsideViewport:()=>{const x=b({tabbingDirection:"backwards"});ou(x)}})]})},"ToastViewport")),pP="ToastFocusProxy",wy=f.forwardRef(ln(function(t,s){const{__scopeToast:r,onFocusFromOutsideViewport:i,...a}=t,l=jS(pP,r);return n.jsx(pS,{tabIndex:0,...a,ref:s,style:{position:"fixed"},onFocus:o=>{var d;const c=o.relatedTarget;!((d=l.viewport)!=null&&d.contains(c))&&i()}})},"ToastFocusProxy")),gP="Toast",[hV,fV]=vS(gP,{onClose(){}});function yS(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),wS(r)){const i=r.ariaHidden||r.hidden||r.style.display==="none",a=r.dataset.radixToastAnnounceExclude==="";if(!i)if(a){const l=r.dataset.radixToastAnnounceAlt;l&&t.push(l)}else t.push(...yS(r))}}),t}ln(yS,"getAnnounceTextContent");function xP(e,t,s,{discrete:r}){const i=s.originalEvent.currentTarget,a=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});t&&i.addEventListener(e,t,{once:!0}),r?Pd(i,a):i.dispatchEvent(a)}ln(xP,"handleAndDispatchCustomEvent");function vP(e=()=>{}){const t=us(e);Tn(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[t])}ln(vP,"useNextFrame");function wS(e){return e.nodeType===e.ELEMENT_NODE}ln(wS,"isHTMLElement");function bS(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:ln(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}ln(bS,"getTabbableCandidates");function ou(e){const t=document.activeElement;return e.some(s=>s===t?!0:(s.focus(),document.activeElement!==t))}ln(ou,"focusFirst");var by=cP,ky=mP,jP=Object.defineProperty,yP=(e,t)=>jP(e,"name",{value:t,configurable:!0}),wP=Za[" useId ".trim().toString()]||(()=>{}),bP=0;function vs(e){const[t,s]=f.useState(wP());return Tn(()=>{e||s(r=>r??String(bP++))},[e]),e||(t?`radix-${t}`:"")}yP(vs,"useId");const kP=["top","right","bottom","left"],ti=Math.min,lr=Math.max,Ku=Math.round,Nc=Math.floor,or=e=>({x:e,y:e}),SP={left:"right",right:"left",bottom:"top",top:"bottom"};function kS(e,t,s){return lr(e,ti(t,s))}function pr(e,t){return typeof e=="function"?e(t):e}function ni(e){return e.split("-")[0]}function sl(e){return e.split("-")[1]}function ex(e){return e==="x"?"y":"x"}function tx(e){return e==="y"?"height":"width"}function Fs(e){const t=e[0];return t==="t"||t==="b"?"y":"x"}function nx(e){return ex(Fs(e))}function NP(e,t,s){s===void 0&&(s=!1);const r=sl(e),i=nx(e),a=tx(i);let l=i==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[a]>t.floating[a]&&(l=Vu(l)),[l,Vu(l)]}function CP(e){const t=Vu(e);return[_m(e),t,_m(t)]}function _m(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const Sy=["left","right"],Ny=["right","left"],EP=["top","bottom"],AP=["bottom","top"];function TP(e,t,s){switch(e){case"top":case"bottom":return s?t?Ny:Sy:t?Sy:Ny;case"left":case"right":return t?EP:AP;default:return[]}}function RP(e,t,s,r){const i=sl(e);let a=TP(ni(e),s==="start",r);return i&&(a=a.map(l=>l+"-"+i),t&&(a=a.concat(a.map(_m)))),a}function Vu(e){const t=ni(e);return SP[t]+e.slice(t.length)}function IP(e){var t,s,r,i;return{top:(t=e.top)!=null?t:0,right:(s=e.right)!=null?s:0,bottom:(r=e.bottom)!=null?r:0,left:(i=e.left)!=null?i:0}}function SS(e){return typeof e!="number"?IP(e):{top:e,right:e,bottom:e,left:e}}function Gu(e){const{x:t,y:s,width:r,height:i}=e;return{width:r,height:i,top:s,left:t,right:t+r,bottom:s+i,x:t,y:s}}function Cy(e,t,s){let{reference:r,floating:i}=e;const a=Fs(t),l=nx(t),o=tx(l),c=ni(t),u=a==="y",d=r.x+r.width/2-i.width/2,h=r.y+r.height/2-i.height/2,m=r[o]/2-i[o]/2;let p;switch(c){case"top":p={x:d,y:r.y-i.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:h};break;case"left":p={x:r.x-i.width,y:h};break;default:p={x:r.x,y:r.y}}const g=sl(t);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function PP(e,t){var s;t===void 0&&(t={});const{x:r,y:i,platform:a,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:m=!1,padding:p=0}=pr(t,e),g=SS(p),b=o[m?h==="floating"?"reference":"floating":h],x=Gu(await a.getClippingRect({element:(s=await(a.isElement==null?void 0:a.isElement(b)))==null||s?b:b.contextElement||await(a.getDocumentElement==null?void 0:a.getDocumentElement(o.floating)),boundary:u,rootBoundary:d,strategy:c})),v=h==="floating"?{x:r,y:i,width:l.floating.width,height:l.floating.height}:l.reference,j=await(a.getOffsetParent==null?void 0:a.getOffsetParent(o.floating)),w=await(a.isElement==null?void 0:a.isElement(j))&&await(a.getScale==null?void 0:a.getScale(j))||{x:1,y:1},S=Gu(a.convertOffsetParentRelativeRectToViewportRelativeRect?await a.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:v,offsetParent:j,strategy:c}):v);return{top:(x.top-S.top+g.top)/w.y,bottom:(S.bottom-x.bottom+g.bottom)/w.y,left:(x.left-S.left+g.left)/w.x,right:(S.right-x.right+g.right)/w.x}}const $P=50,MP=async(e,t,s)=>{const{placement:r="bottom",strategy:i="absolute",middleware:a=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:PP},c=await(l.isRTL==null?void 0:l.isRTL(t));let u=await l.getElementRects({reference:e,floating:t,strategy:i}),{x:d,y:h}=Cy(u,r,c),m=r,p=0;const g={};for(let y=0;y<a.length;y++){const b=a[y];if(!b)continue;const{name:x,fn:v}=b,{x:j,y:w,data:S,reset:k}=await v({x:d,y:h,initialPlacement:r,placement:m,strategy:i,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:t}});d=j??d,h=w??h,g[x]={...g[x],...S},k&&p<$P&&(p++,typeof k=="object"&&(k.placement&&(m=k.placement),k.rects&&(u=k.rects===!0?await l.getElementRects({reference:e,floating:t,strategy:i}):k.rects),{x:d,y:h}=Cy(u,m,c)),y=-1)}return{x:d,y:h,placement:m,strategy:i,middlewareData:g}},OP=e=>({name:"arrow",options:e,async fn(t){const{x:s,y:r,placement:i,rects:a,platform:l,elements:o,middlewareData:c}=t,{element:u,padding:d=0}=pr(e,t)||{};if(u==null)return{};const h=SS(d),m={x:s,y:r},p=nx(i),g=tx(p),y=await l.getDimensions(u),b=p==="y",x=b?"top":"left",v=b?"bottom":"right",j=b?"clientHeight":"clientWidth",w=a.reference[g]+a.reference[p]-m[p]-a.floating[g],S=m[p]-a.reference[p],k=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let N=k?k[j]:0;(!N||!await(l.isElement==null?void 0:l.isElement(k)))&&(N=o.floating[j]||a.floating[g]);const C=w/2-S/2,I=N/2-y[g]/2-1,A=ti(h[x],I),_=ti(h[v],I),z=N-y[g]-_,L=N/2-y[g]/2+C,E=kS(A,L,z),M=!c.arrow&&sl(i)!=null&&L!==E&&a.reference[g]/2-(L<A?A:_)-y[g]/2<0,D=M?L<A?L-A:L-z:0;return{[p]:m[p]+D,data:{[p]:E,centerOffset:L-E-D,...M&&{alignmentOffset:D}},reset:M}}}),DP=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var s,r;const{placement:i,middlewareData:a,rects:l,initialPlacement:o,platform:c,elements:u}=t,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:y=!0,...b}=pr(e,t);if((s=a.arrow)!=null&&s.alignmentOffset)return{};const x=ni(i),v=Fs(o),j=ni(o)===o,w=await(c.isRTL==null?void 0:c.isRTL(u.floating)),S=m||(j||!y?[Vu(o)]:CP(o)),k=g!=="none";!m&&k&&S.push(...RP(o,y,g,w));const N=[o,...S],C=await c.detectOverflow(t,b),I=[];let A=((r=a.flip)==null?void 0:r.overflows)||[];if(d&&I.push(C[x]),h){const E=NP(i,l,w);I.push(C[E[0]],C[E[1]])}if(A=[...A,{placement:i,overflows:I}],!I.every(E=>E<=0)){var _,z;const E=(((_=a.flip)==null?void 0:_.index)||0)+1,M=N[E];if(M&&(!(h==="alignment"?v!==Fs(M):!1)||A.every($=>Fs($.placement)===v?$.overflows[0]>0:!0)))return{data:{index:E,overflows:A},reset:{placement:M}};let D=(z=A.filter(U=>U.overflows[0]<=0).sort((U,$)=>U.overflows[1]-$.overflows[1])[0])==null?void 0:z.placement;if(!D)switch(p){case"bestFit":{var L;const U=(L=A.filter($=>{if(k){const B=Fs($.placement);return B===v||B==="y"}return!0}).map($=>[$.placement,$.overflows.filter(B=>B>0).reduce((B,O)=>B+O,0)]).sort(($,B)=>$[1]-B[1])[0])==null?void 0:L[0];U&&(D=U);break}case"initialPlacement":D=o;break}if(i!==D)return{reset:{placement:D}}}return{}}}};function Ey(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ay(e){return kP.some(t=>e[t]>=0)}const _P=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:s,platform:r}=t,{strategy:i="referenceHidden",...a}=pr(e,t);switch(i){case"referenceHidden":{const l=await r.detectOverflow(t,{...a,elementContext:"reference"}),o=Ey(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:Ay(o)}}}case"escaped":{const l=await r.detectOverflow(t,{...a,altBoundary:!0}),o=Ey(l,s.floating);return{data:{escapedOffsets:o,escaped:Ay(o)}}}default:return{}}}}},NS=new Set(["left","top"]);async function LP(e,t){const{placement:s,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),l=ni(s),o=sl(s),c=Fs(s)==="y",u=NS.has(l)?-1:1,d=a&&c?-1:1,h=pr(t,e);let{mainAxis:m,crossAxis:p,alignmentAxis:g}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return o&&typeof g=="number"&&(p=o==="end"?g*-1:g),c?{x:p*d,y:m*u}:{x:m*u,y:p*d}}const FP=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var s,r;const{x:i,y:a,placement:l,middlewareData:o}=t,c=await LP(t,e);return l===((s=o.offset)==null?void 0:s.placement)&&(r=o.arrow)!=null&&r.alignmentOffset?{}:{x:i+c.x,y:a+c.y,data:{...c,placement:l}}}}},zP=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:s,y:r,placement:i,platform:a}=t,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:v=>{let{x:j,y:w}=v;return{x:j,y:w}}},...u}=pr(e,t),d={x:s,y:r},h=await a.detectOverflow(t,u),m=Fs(i),p=ex(m);let g=d[p],y=d[m];const b=(v,j)=>kS(j+h[v==="y"?"top":"left"],j,j-h[v==="y"?"bottom":"right"]);l&&(g=b(p,g)),o&&(y=b(m,y));const x=c.fn({...t,[p]:g,[m]:y});return{...x,data:{x:x.x-s,y:x.y-r,enabled:{[p]:l,[m]:o}}}}}},UP=function(e){return e===void 0&&(e={}),{options:e,fn(t){var s,r;const{x:i,y:a,placement:l,rects:o,middlewareData:c}=t,{offset:u=0,mainAxis:d=!0,crossAxis:h=!0}=pr(e,t),m={x:i,y:a},p=Fs(l),g=ex(p);let y=m[g],b=m[p];const x=pr(u,t),v=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:(s=x.mainAxis)!=null?s:0,crossAxis:(r=x.crossAxis)!=null?r:0};if(d){const S=g==="y"?"height":"width",k=o.reference[g]-o.floating[S]+v.mainAxis,N=o.reference[g]+o.reference[S]-v.mainAxis;y<k?y=k:y>N&&(y=N)}if(h){var j,w;const S=g==="y"?"width":"height",k=NS.has(ni(l)),N=o.reference[p]-o.floating[S]+(k&&((j=c.offset)==null?void 0:j[p])||0)+(k?0:v.crossAxis),C=o.reference[p]+o.reference[S]+(k?0:((w=c.offset)==null?void 0:w[p])||0)-(k?v.crossAxis:0);b<N?b=N:b>C&&(b=C)}return{[g]:y,[p]:b}}}},BP=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:s,rects:r,platform:i,elements:a}=t,{apply:l=()=>{},...o}=pr(e,t),c=await i.detectOverflow(t,o),u=ni(s),d=sl(s),h=Fs(s)==="y",{width:m,height:p}=r.floating;let g,y;u==="top"||u==="bottom"?(g=u,y=d===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=u,g=d==="end"?"top":"bottom");const b=p-c.top-c.bottom,x=m-c.left-c.right,v=ti(p-c[g],b),j=ti(m-c[y],x),w=t.middlewareData.shift,S=!w;let k=v,N=j;w!=null&&w.enabled.x&&(N=x),w!=null&&w.enabled.y&&(k=b),S&&!d&&(h?N=m-2*lr(c.left,c.right):k=p-2*lr(c.top,c.bottom)),await l({...t,availableWidth:N,availableHeight:k});const C=await i.getDimensions(a.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function $d(){return typeof window<"u"}function rl(e){return CS(e)?(e.nodeName||"").toLowerCase():"#document"}function Rn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function yr(e){var t;return(t=(CS(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function CS(e){return $d()?e instanceof Node||e instanceof Rn(e).Node:!1}function Hs(e){return $d()?e instanceof Element||e instanceof Rn(e).Element:!1}function ui(e){return $d()?e instanceof HTMLElement||e instanceof Rn(e).HTMLElement:!1}function Ty(e){return!$d()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Rn(e).ShadowRoot}function Md(e){const{overflow:t,overflowX:s,overflowY:r,display:i}=Ks(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+s)&&i!=="inline"&&i!=="contents"}function WP(e){return/^(table|td|th)$/.test(rl(e))}function Od(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const HP=/transform|translate|scale|rotate|perspective|filter/,KP=/paint|layout|strict|content/,xi=e=>!!e&&e!=="none";let Wh;function sx(e){const t=Hs(e)?Ks(e):e;return xi(t.transform)||xi(t.translate)||xi(t.scale)||xi(t.rotate)||xi(t.perspective)||!rx()&&(xi(t.backdropFilter)||xi(t.filter))||HP.test(t.willChange||"")||KP.test(t.contain||"")}function VP(e){let t=Oi(e);for(;ui(t)&&!xo(t);){if(sx(t))return t;if(Od(t))return null;t=Oi(t)}return null}function rx(){return Wh==null&&(Wh=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),Wh}function xo(e){return/^(html|body|#document)$/.test(rl(e))}function Ks(e){return Rn(e).getComputedStyle(e)}function Dd(e){return Hs(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Oi(e){if(rl(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Ty(e)&&e.host||yr(e);return Ty(t)?t.host:t}function ES(e){const t=Oi(e);return xo(t)?(e.ownerDocument||e).body:ui(t)&&Md(t)?t:ES(t)}function vo(e,t,s){var r;t===void 0&&(t=[]),s===void 0&&(s=!0);const i=ES(e),a=i===((r=e.ownerDocument)==null?void 0:r.body),l=Rn(i);if(a){const o=Lm(l);return t.concat(l,l.visualViewport||[],Md(i)?i:[],o&&s?vo(o):[])}else return t.concat(i,vo(i,[],s))}function Lm(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function AS(e){const t=Ks(e);let s=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const i=ui(e),a=i?e.offsetWidth:s,l=i?e.offsetHeight:r,o=Ku(s)!==a||Ku(r)!==l;return o&&(s=a,r=l),{width:s,height:r,$:o}}function ix(e){return Hs(e)?e:e.contextElement}function Aa(e){const t=ix(e);if(!ui(t))return or(1);const s=t.getBoundingClientRect(),{width:r,height:i,$:a}=AS(t);let l=(a?Ku(s.width):s.width)/r,o=(a?Ku(s.height):s.height)/i;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const GP=or(0);function TS(e){const t=Rn(e);return!rx()||!t.visualViewport?GP:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function YP(e,t,s){return t===void 0&&(t=!1),!!s&&t&&s===Rn(e)}function Di(e,t,s,r){t===void 0&&(t=!1),s===void 0&&(s=!1);const i=e.getBoundingClientRect(),a=ix(e);let l=or(1);t&&(r?Hs(r)&&(l=Aa(r)):l=Aa(e));const o=YP(a,s,r)?TS(a):or(0);let c=(i.left+o.x)/l.x,u=(i.top+o.y)/l.y,d=i.width/l.x,h=i.height/l.y;if(a&&r){const m=Rn(a),p=Hs(r)?Rn(r):r;let g=m,y=Lm(g);for(;y&&p!==g;){const b=Aa(y),x=y.getBoundingClientRect(),v=Ks(y),j=x.left+(y.clientLeft+parseFloat(v.paddingLeft))*b.x,w=x.top+(y.clientTop+parseFloat(v.paddingTop))*b.y;c*=b.x,u*=b.y,d*=b.x,h*=b.y,c+=j,u+=w,g=Rn(y),y=Lm(g)}}return Gu({width:d,height:h,x:c,y:u})}function _d(e,t){const s=Dd(e).scrollLeft;return t?t.left+s:Di(yr(e)).left+s}function RS(e,t){const s=e.getBoundingClientRect(),r=s.left+t.scrollLeft-_d(e,s),i=s.top+t.scrollTop;return{x:r,y:i}}function qP(e){let{elements:t,rect:s,offsetParent:r,strategy:i}=e;const a=i==="fixed",l=yr(r),o=t?Od(t.floating):!1;if(r===l||o&&a)return s;let c={scrollLeft:0,scrollTop:0},u=or(1);const d=or(0),h=ui(r);if((h||!a)&&((rl(r)!=="body"||Md(l))&&(c=Dd(r)),h)){const p=Di(r);u=Aa(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const m=l&&!h&&!a?RS(l,c):or(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+d.x+m.x,y:s.y*u.y-c.scrollTop*u.y+d.y+m.y}}function QP(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function JP(e){const t=Dd(e),s=e.ownerDocument.body,r=lr(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),i=lr(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let a=-t.scrollLeft+_d(e);const l=-t.scrollTop;return Ks(s).direction==="rtl"&&(a+=lr(e.clientWidth,s.clientWidth)-r),{width:r,height:i,x:a,y:l}}const XP=25;function ZP(e,t,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",i=Rn(e),a=yr(e),l=i.visualViewport;let o=a.clientWidth,c=a.clientHeight,u=0,d=0;if(l){const m=!rx()||t==="fixed";r?m||(u=-l.offsetLeft,d=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,d=l.offsetTop))}if(_d(a)<=0){const m=a.ownerDocument,p=m.body,g=getComputedStyle(p),y=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,b=Math.abs(a.clientWidth-p.clientWidth-y),x=getComputedStyle(a).scrollbarGutter==="stable both-edges"?b/2:b;x<=XP&&(o-=x)}return{width:o,height:c,x:u,y:d}}function e2(e,t){const s=Di(e,!0,t==="fixed"),r=s.top+e.clientTop,i=s.left+e.clientLeft,a=Aa(e),l=e.clientWidth*a.x,o=e.clientHeight*a.y,c=i*a.x,u=r*a.y;return{width:l,height:o,x:c,y:u}}function Ry(e,t,s){let r;if(t==="viewport"||t==="layoutViewport")r=ZP(e,s,t);else if(t==="document")r=JP(yr(e));else if(Hs(t))r=e2(t,s);else{const i=TS(e);r={x:t.x-i.x,y:t.y-i.y,width:t.width,height:t.height}}return Gu(r)}function t2(e,t){const s=t.get(e);if(s)return s;let r=vo(e,[],!1).filter(o=>Hs(o)&&rl(o)!=="body"),i=null;const a=Ks(e).position==="fixed";let l=a?Oi(e):e;for(;Hs(l)&&!xo(l);){const o=Ks(l),c=sx(l),u=i?i.position:a?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(h=>h!==l):i=o,l=Oi(l)}return t.set(e,r),r}function n2(e){let{element:t,boundary:s,rootBoundary:r,strategy:i}=e;const l=[...s==="clippingAncestors"?Od(t)?[]:t2(t,this._c):[].concat(s),r],o=Ry(t,l[0],i);let c=o.top,u=o.right,d=o.bottom,h=o.left;for(let m=1;m<l.length;m++){const p=Ry(t,l[m],i);c=lr(p.top,c),u=ti(p.right,u),d=ti(p.bottom,d),h=lr(p.left,h)}return{width:u-h,height:d-c,x:h,y:c}}function s2(e){const{width:t,height:s}=AS(e);return{width:t,height:s}}function r2(e,t,s){const r=ui(t),i=yr(t),a=s==="fixed",l=Di(e,!0,a,t);let o={scrollLeft:0,scrollTop:0};const c=or(0);if((r||!a)&&((rl(t)!=="body"||Md(i))&&(o=Dd(t)),r)){const m=Di(t,!0,a,t);c.x=m.x+t.clientLeft,c.y=m.y+t.clientTop}!r&&i&&(c.x=_d(i));const u=i&&!r&&!a?RS(i,o):or(0),d=l.left+o.scrollLeft-c.x-u.x,h=l.top+o.scrollTop-c.y-u.y;return{x:d,y:h,width:l.width,height:l.height}}function Hh(e){return Ks(e).position==="static"}function Iy(e,t){if(!ui(e)||Ks(e).position==="fixed")return null;if(t)return t(e);let s=e.offsetParent;return yr(e)===s&&(s=s.ownerDocument.body),s}function IS(e,t){const s=Rn(e);if(Od(e))return s;if(!ui(e)){let i=Oi(e);for(;i&&!xo(i);){if(Hs(i)&&!Hh(i))return i;i=Oi(i)}return s}let r=Iy(e,t);for(;r&&WP(r)&&Hh(r);)r=Iy(r,t);return r&&xo(r)&&Hh(r)&&!sx(r)?s:r||VP(e)||s}const i2=async function(e){const t=this.getOffsetParent||IS,s=this.getDimensions,r=await s(e.floating);return{reference:r2(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function a2(e){return Ks(e).direction==="rtl"}const l2={convertOffsetParentRelativeRectToViewportRelativeRect:qP,getDocumentElement:yr,getClippingRect:n2,getOffsetParent:IS,getElementRects:i2,getClientRects:QP,getDimensions:s2,getScale:Aa,isElement:Hs,isRTL:a2};function PS(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function o2(e,t,s){let r=null,i;const a=yr(e);function l(){var d;clearTimeout(i),(d=r)==null||d.disconnect(),r=null}function o(d,h){d===void 0&&(d=!1),h===void 0&&(h=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:y,height:b}=m;if(d||t(),!y||!b)return;const x=Nc(g),v=Nc(a.clientWidth-(p+y)),j=Nc(a.clientHeight-(g+b)),w=Nc(p),k={rootMargin:-x+"px "+-v+"px "+-j+"px "+-w+"px",threshold:lr(0,ti(1,h))||1};let N=!0;function C(I){const A=I[0].intersectionRatio;if(!PS(m,e.getBoundingClientRect()))return o();if(A!==h){if(!N)return o();A?o(!1,A):i=setTimeout(()=>{o(!1,1e-7)},1e3)}N=!1}try{r=new IntersectionObserver(C,{...k,root:a.ownerDocument})}catch{r=new IntersectionObserver(C,k)}r.observe(e)}const c=Rn(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function c2(e,t,s,r){r===void 0&&(r={});const{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:o=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=ix(e),d=i||a?[...u?vo(u):[],...t?vo(t):[]]:[];d.forEach(x=>{i&&x.addEventListener("scroll",s),a&&x.addEventListener("resize",s)});const h=u&&o?o2(u,s,a):null;let m=-1,p=null;l&&(p=new ResizeObserver(x=>{let[v]=x;v&&v.target===u&&p&&t&&(p.unobserve(t),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var j;(j=p)==null||j.observe(t)})),s()}),u&&!c&&p.observe(u),t&&p.observe(t));let g,y=c?Di(e):null;c&&b();function b(){const x=Di(e);y&&!PS(y,x)&&s(),y=x,g=requestAnimationFrame(b)}return s(),()=>{var x;d.forEach(v=>{i&&v.removeEventListener("scroll",s),a&&v.removeEventListener("resize",s)}),h==null||h(),(x=p)==null||x.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const u2=FP,d2=zP,h2=DP,f2=BP,m2=_P,Py=OP,p2=UP,g2=(e,t,s)=>{const r=new Map,i=s??{},a={...l2,...i.platform,_c:r};return MP(e,t,{...i,platform:a})};var x2=typeof document<"u",v2=function(){},cu=x2?f.useLayoutEffect:v2;function Yu(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let s,r,i;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(s=e.length,s!==t.length)return!1;for(r=s;r--!==0;)if(!Yu(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),s=i.length,s!==Object.keys(t).length)return!1;for(r=s;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=s;r--!==0;){const a=i[r];if(!(a==="_owner"&&e.$$typeof)&&!Yu(e[a],t[a]))return!1}return!0}return e!==e&&t!==t}function $S(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function $y(e,t){const s=$S(e);return Math.round(t*s)/s}function Kh(e){const t=f.useRef(e);return cu(()=>{t.current=e}),t}function j2(e){e===void 0&&(e={});const{placement:t="bottom",strategy:s="absolute",middleware:r=[],platform:i,elements:{reference:a,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[d,h]=f.useState({x:0,y:0,strategy:s,placement:t,middlewareData:{},isPositioned:!1}),[m,p]=f.useState(r);Yu(m,r)||p(r);const[g,y]=f.useState(null),[b,x]=f.useState(null),v=f.useCallback($=>{$!==k.current&&(k.current=$,y($))},[]),j=f.useCallback($=>{$!==N.current&&(N.current=$,x($))},[]),w=a||g,S=l||b,k=f.useRef(null),N=f.useRef(null),C=f.useRef(d),I=c!=null,A=Kh(c),_=Kh(i),z=Kh(u),L=f.useCallback(()=>{if(!k.current||!N.current)return;const $={placement:t,strategy:s,middleware:m};_.current&&($.platform=_.current),g2(k.current,N.current,$).then(B=>{const O={...B,isPositioned:z.current!==!1};E.current&&!Yu(C.current,O)&&(C.current=O,zo.flushSync(()=>{h(O)}))})},[m,t,s,_,z]);cu(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,h($=>({...$,isPositioned:!1})))},[u]);const E=f.useRef(!1);cu(()=>(E.current=!0,()=>{E.current=!1}),[]),cu(()=>{if(w&&(k.current=w),S&&(N.current=S),w&&S){if(A.current)return A.current(w,S,L);L()}},[w,S,L,A,I]);const M=f.useMemo(()=>({reference:k,floating:N,setReference:v,setFloating:j}),[v,j]),D=f.useMemo(()=>({reference:w,floating:S}),[w,S]),U=f.useMemo(()=>{const $={position:s,left:0,top:0};if(!D.floating)return $;const B=$y(D.floating,d.x),O=$y(D.floating,d.y);return o?{...$,transform:"translate("+B+"px, "+O+"px)",...$S(D.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:B,top:O}},[s,o,D.floating,d.x,d.y]);return f.useMemo(()=>({...d,update:L,refs:M,elements:D,floatingStyles:U}),[d,L,M,D,U])}const y2=e=>{function t(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:e,fn(s){const{element:r,padding:i}=typeof e=="function"?e(s):e;return r&&t(r)?r.current!=null?Py({element:r.current,padding:i}).fn(s):{}:r?Py({element:r,padding:i}).fn(s):{}}}},w2=(e,t)=>{const s=u2(e);return{name:s.name,fn:s.fn,options:[e,t]}},b2=(e,t)=>{const s=d2(e);return{name:s.name,fn:s.fn,options:[e,t]}},k2=(e,t)=>({fn:p2(e).fn,options:[e,t]}),S2=(e,t)=>{const s=h2(e);return{name:s.name,fn:s.fn,options:[e,t]}},N2=(e,t)=>{const s=f2(e);return{name:s.name,fn:s.fn,options:[e,t]}},C2=(e,t)=>{const s=m2(e);return{name:s.name,fn:s.fn,options:[e,t]}},E2=(e,t)=>{const s=y2(e);return{name:s.name,fn:s.fn,options:[e,t]}};var A2=Object.defineProperty,T2=(e,t)=>A2(e,"name",{value:t,configurable:!0});function MS(e){const[t,s]=f.useState(void 0);return Tn(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let l,o;if("borderBoxSize"in a){const c=a.borderBoxSize,u=Array.isArray(c)?c[0]:c;l=u.inlineSize,o=u.blockSize}else l=e.offsetWidth,o=e.offsetHeight;s({width:l,height:o})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else s(void 0)},[e]),t}T2(MS,"useSize");var R2=Object.defineProperty,Gr=(e,t)=>R2(e,"name",{value:t,configurable:!0}),OS="Popper",[DS,Ld]=Ns(OS),[I2,_S]=DS(OS),P2=Gr(e=>{const{__scopePopper:t,children:s}=e,[r,i]=f.useState(null),[a,l]=f.useState(void 0);return n.jsx(I2,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:l,children:s})},"Popper"),$2="PopperAnchor",M2=f.forwardRef(Gr(function(t,s){const{__scopePopper:r,virtualRef:i,...a}=t,l=_S($2,r),o=f.useRef(null),c=l.onAnchorChange,u=f.useCallback(y=>{o.current=y,y&&c(y)},[c]),d=ut(s,u),h=f.useRef(null);f.useEffect(()=>{if(!i)return;const y=h.current;h.current=i.current,y!==h.current&&c(h.current)});const m=l.placementState&&Fd(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return i?null:n.jsx(bt.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...a,ref:d})},"PopperAnchor")),LS="PopperContent",[O2,mV]=DS(LS),D2=f.forwardRef(Gr(function(t,s){var Ie,Se,we,Ce,mt,he,Me;const{__scopePopper:r,side:i="bottom",sideOffset:a=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:d=[],collisionPadding:h=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:y,...b}=t,x=_S(LS,r),[v,j]=f.useState(null),w=ut(s,j),[S,k]=f.useState(null),N=MS(S),C=(N==null?void 0:N.width)??0,I=(N==null?void 0:N.height)??0,A=i+(l!=="center"?"-"+l:""),_=typeof h=="number"?h:{top:0,right:0,bottom:0,left:0,...h},z=Array.isArray(d)?d:[d],L=z.length>0,E={padding:_,boundary:z.filter(FS),altBoundary:L},{refs:M,floatingStyles:D,placement:U,isPositioned:$,middlewareData:B}=j2({strategy:"fixed",placement:A,whileElementsMounted:Gr((...Pe)=>c2(...Pe,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:x.anchor},middleware:[w2({mainAxis:a+I,alignmentAxis:o}),u&&b2({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?k2():void 0,...E}),u&&S2({...E}),N2({...E,apply:Gr(({elements:Pe,rects:Ye,availableWidth:Y,availableHeight:me})=>{const{width:oe,height:Oe}=Ye.reference,Le=Pe.floating.style;Le.setProperty("--radix-popper-available-width",`${Y}px`),Le.setProperty("--radix-popper-available-height",`${me}px`),Le.setProperty("--radix-popper-anchor-width",`${oe}px`),Le.setProperty("--radix-popper-anchor-height",`${Oe}px`)},"apply")}),S&&E2({element:S,padding:c}),_2({arrowWidth:C,arrowHeight:I}),p&&C2({strategy:"referenceHidden",...E,boundary:L?E.boundary:void 0})]}),O=x.setPlacementState;Tn(()=>(O(U),()=>{O(void 0)}),[U,O]);const[K,G]=Fd(U),se=us(y);Tn(()=>{$&&(se==null||se())},[$,se]);const ue=(Ie=B.arrow)==null?void 0:Ie.x,ie=(Se=B.arrow)==null?void 0:Se.y,ee=((we=B.arrow)==null?void 0:we.centerOffset)!==0,[X,de]=f.useState();return Tn(()=>{v&&de(window.getComputedStyle(v).zIndex)},[v]),n.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:$?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:X,"--radix-popper-transform-origin":[(Ce=B.transformOrigin)==null?void 0:Ce.x,(mt=B.transformOrigin)==null?void 0:mt.y].join(" "),...((he=B.hide)==null?void 0:he.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:n.jsx(O2,{scope:r,placedSide:K,placedAlign:G,onArrowChange:k,arrowX:ue,arrowY:ie,shouldHideArrow:ee,children:n.jsx(bt.div,{"data-side":K,"data-align":G,...b,ref:w,style:{...b.style,animation:$?(Me=b.style)==null?void 0:Me.animation:"none"}})})})},"PopperContent"));function FS(e){return e!==null}Gr(FS,"isNotNull");var _2=Gr(e=>({name:"transformOrigin",options:e,fn(t){var b,x,v;const{placement:s,rects:r,middlewareData:i}=t,l=((b=i.arrow)==null?void 0:b.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,d]=Fd(s),h={start:"0%",center:"50%",end:"100%"}[d],m=(((x=i.arrow)==null?void 0:x.x)??0)+o/2,p=(((v=i.arrow)==null?void 0:v.y)??0)+c/2;let g="",y="";return u==="bottom"?(g=l?h:`${m}px`,y=`${-c}px`):u==="top"?(g=l?h:`${m}px`,y=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,y=l?h:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,y=l?h:`${p}px`),{data:{x:g,y}}}}),"transformOrigin");function Fd(e){const[t,s="center"]=e.split("-");return[t,s]}Gr(Fd,"getSideAndAlignFromPlacement");var ax=P2,zS=M2,US=D2,L2=Object.defineProperty,Ht=(e,t)=>L2(e,"name",{value:t,configurable:!0}),[lx,pV]=Ns("Tooltip",[Ld]),ox=Ld(),F2="TooltipProvider",z2=700,Fm="tooltip.open",[U2,cx]=lx(F2),B2=Ht(e=>{const{__scopeTooltip:t,delayDuration:s=z2,skipDelayDuration:r=300,disableHoverableContent:i=!1,children:a}=e,l=f.useRef(!0),o=f.useRef(!1),c=f.useRef(0);return f.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),n.jsx(U2,{scope:t,isOpenDelayedRef:l,delayDuration:s,onOpen:f.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:f.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:f.useCallback(u=>{o.current=u},[]),disableHoverableContent:i,children:a})},"TooltipProvider"),zm="Tooltip",[W2,Bo]=lx(zm),H2=Ht(e=>{const{__scopeTooltip:t,children:s,open:r,defaultOpen:i,onOpenChange:a,disableHoverableContent:l,delayDuration:o}=e,c=cx(zm,e.__scopeTooltip),u=ox(t),[d,h]=f.useState(null),[m,p]=f.useState(void 0),g=vs(),y=f.useRef(0),b=l??c.disableHoverableContent,x=o??c.delayDuration,v=f.useRef(!1),[j,w]=Wi({prop:r,defaultProp:i??!1,onChange:Ht(A=>{A?(c.onOpen(),document.dispatchEvent(new CustomEvent(Fm))):c.onClose(),a==null||a(A)},"onChange"),caller:zm}),S=f.useMemo(()=>j?v.current?"delayed-open":"instant-open":"closed",[j]),k=f.useCallback(()=>{window.clearTimeout(y.current),y.current=0,v.current=!1,w(!0)},[w]),N=f.useCallback(()=>{window.clearTimeout(y.current),y.current=0,w(!1)},[w]),C=f.useCallback(()=>{window.clearTimeout(y.current),y.current=window.setTimeout(()=>{v.current=!0,w(!0),y.current=0},x)},[x,w]);f.useEffect(()=>()=>{y.current&&(window.clearTimeout(y.current),y.current=0)},[]);const I=m??g;return n.jsx(ax,{...u,children:n.jsx(W2,{scope:t,contentId:I,setContentId:p,open:j,stateAttribute:S,trigger:d,onTriggerChange:h,onTriggerEnter:f.useCallback(()=>{c.isOpenDelayedRef.current?C():k()},[c.isOpenDelayedRef,C,k]),onTriggerLeave:f.useCallback(()=>{b?N():(window.clearTimeout(y.current),y.current=0)},[N,b]),onOpen:k,onClose:N,disableHoverableContent:b,children:s})})},"Tooltip"),My="TooltipTrigger",K2=f.forwardRef(Ht(function(t,s){const{__scopeTooltip:r,...i}=t,a=Bo(My,r),l=cx(My,r),o=ox(r),c=f.useRef(null),u=ut(s,c,a.onTriggerChange),d=f.useRef(!1),h=f.useRef(!1),m=f.useCallback(()=>d.current=!1,[]);return f.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),n.jsx(zS,{asChild:!0,...o,children:n.jsx(bt.button,{"aria-describedby":a.open?a.contentId:void 0,"data-state":a.stateAttribute,...i,ref:u,onPointerMove:Re(t.onPointerMove,p=>{p.pointerType!=="touch"&&!h.current&&!l.isPointerInTransitRef.current&&(a.onTriggerEnter(),h.current=!0)}),onPointerLeave:Re(t.onPointerLeave,()=>{a.onTriggerLeave(),h.current=!1}),onPointerDown:Re(t.onPointerDown,()=>{a.open&&a.onClose(),d.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Re(t.onFocus,()=>{d.current||a.onOpen()}),onBlur:Re(t.onBlur,a.onClose),onClick:Re(t.onClick,a.onClose)})})},"TooltipTrigger")),BS="TooltipPortal",[V2,G2]=lx(BS,{forceMount:void 0}),Y2=Ht(e=>{const{__scopeTooltip:t,forceMount:s,children:r,container:i}=e,a=Bo(BS,t);return n.jsx(V2,{scope:t,forceMount:s,children:n.jsx(jr,{present:s||a.open,children:n.jsx(Zg,{asChild:!0,container:i,children:r})})})},"TooltipPortal"),jo="TooltipContent",q2=f.forwardRef(Ht(function(t,s){const r=G2(jo,t.__scopeTooltip),{forceMount:i=r.forceMount,side:a="top",...l}=t,o=Bo(jo,t.__scopeTooltip);return n.jsx(jr,{present:i||o.open,children:o.disableHoverableContent?n.jsx(WS,{side:a,...l,ref:s}):n.jsx(Q2,{side:a,...l,ref:s})})},"TooltipContent")),Q2=f.forwardRef(Ht(function(t,s){const r=Bo(jo,t.__scopeTooltip),i=cx(jo,t.__scopeTooltip),a=f.useRef(null),l=ut(s,a),[o,c]=f.useState(null),{trigger:u,onClose:d}=r,h=a.current,{onPointerInTransitChange:m}=i,p=f.useCallback(()=>{c(null),m(!1)},[m]),g=f.useCallback((y,b)=>{const x=y.currentTarget,v={x:y.clientX,y:y.clientY},j=HS(v,x.getBoundingClientRect()),w=KS(v,j),S=VS(b.getBoundingClientRect()),k=YS([...w,...S]);c(k),m(!0)},[m]);return f.useEffect(()=>()=>p(),[p]),f.useEffect(()=>{if(u&&h){const y=Ht(x=>g(x,h),"handleTriggerLeave"),b=Ht(x=>g(x,u),"handleContentLeave");return u.addEventListener("pointerleave",y),h.addEventListener("pointerleave",b),()=>{u.removeEventListener("pointerleave",y),h.removeEventListener("pointerleave",b)}}},[u,h,g,p]),f.useEffect(()=>{if(o){const y=Ht(b=>{const x=b.target,v={x:b.clientX,y:b.clientY},j=(u==null?void 0:u.contains(x))||(h==null?void 0:h.contains(x)),w=!GS(v,o);j?p():w&&(p(),d())},"handleTrackPointerGrace");return document.addEventListener("pointermove",y),()=>document.removeEventListener("pointermove",y)}},[u,h,o,d,p]),n.jsx(WS,{...t,ref:l})},"TooltipContentHoverable")),J2=Qk("TooltipContent"),WS=f.forwardRef(Ht(function(t,s){const{__scopeTooltip:r,children:i,"aria-label":a,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=t,d=Bo(jo,r),h=ox(r),{onClose:m}=d;f.useEffect(()=>(document.addEventListener(Fm,m),()=>document.removeEventListener(Fm,m)),[m]),f.useEffect(()=>{if(d.trigger){const g=Ht(y=>{y.target instanceof Node&&y.target.contains(d.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[d.trigger,m]);const{setContentId:p}=d;return Tn(()=>(p(l),()=>{p(void 0)}),[l,p]),n.jsx(Jg,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:n.jsxs(US,{"data-state":d.stateAttribute,role:a?void 0:"tooltip",id:a?void 0:d.contentId,...h,...u,ref:s,style:{...u.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[n.jsx(J2,{children:i}),a?n.jsx(rP,{id:d.contentId,role:"tooltip",children:a}):null]})})},"TooltipContentImpl"));function HS(e,t){const s=Math.abs(t.top-e.y),r=Math.abs(t.bottom-e.y),i=Math.abs(t.right-e.x),a=Math.abs(t.left-e.x);switch(Math.min(s,r,i,a)){case a:return"left";case i:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}Ht(HS,"getExitSideFromRect");function KS(e,t,s=5){const r=[];switch(t){case"top":r.push({x:e.x-s,y:e.y+s},{x:e.x+s,y:e.y+s});break;case"bottom":r.push({x:e.x-s,y:e.y-s},{x:e.x+s,y:e.y-s});break;case"left":r.push({x:e.x+s,y:e.y-s},{x:e.x+s,y:e.y+s});break;case"right":r.push({x:e.x-s,y:e.y-s},{x:e.x-s,y:e.y+s});break}return r}Ht(KS,"getPaddedExitPoints");function VS(e){const{top:t,right:s,bottom:r,left:i}=e;return[{x:i,y:t},{x:s,y:t},{x:s,y:r},{x:i,y:r}]}Ht(VS,"getPointsFromRect");function GS(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,d=o.y,h=c.x,m=c.y;d>r!=m>r&&s<(h-u)*(r-d)/(m-d)+u&&(i=!i)}return i}Ht(GS,"isPointInPolygon");function YS(e){const t=e.slice();return t.sort((s,r)=>s.x<r.x?-1:s.x>r.x?1:s.y<r.y?-1:s.y>r.y?1:0),qS(t)}Ht(YS,"getHull");function qS(e){if(e.length<=1)return e.slice();const t=[];for(let r=0;r<e.length;r++){const i=e[r];for(;t.length>=2;){const a=t[t.length-1],l=t[t.length-2];if((a.x-l.x)*(i.y-l.y)>=(a.y-l.y)*(i.x-l.x))t.pop();else break}t.push(i)}t.pop();const s=[];for(let r=e.length-1;r>=0;r--){const i=e[r];for(;s.length>=2;){const a=s[s.length-1],l=s[s.length-2];if((a.x-l.x)*(i.y-l.y)>=(a.y-l.y)*(i.x-l.x))s.pop();else break}s.push(i)}return s.pop(),t.length===1&&s.length===1&&t[0].x===s[0].x&&t[0].y===s[0].y?t:t.concat(s)}Ht(qS,"getHullPresorted");var Oy=B2,yo=H2,wo=K2,bo=Y2,ko=q2;const Dy="buddi_csrf",il="x-buddi-csrf",So="buddi:agents-changed",X2="This page's sign-in no longer matches its cookies. Reload the page and try again.";class ge extends Error{constructor(t,s,r){super(s),this.status=t,this.detail=r,this.name="ApiError"}}function Hi(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),t=document.cookie.match(new RegExp(`(?:^|; )${Dy}_${e}=([^;]*)`));if(t!=null&&t[1])return decodeURIComponent(t[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${Dy}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const qu="buddi isn't answering.";let Um=null;const Bm=new Set;function Cc(e){if(e!==(Um===null)){Um=e?null:Date.now();for(const t of Bm)t()}}function Z2(){return Um}function e$(e){return Bm.add(e),()=>Bm.delete(e)}function t$(e){return e instanceof ge&&(e.status===0||e.status===502||e.status===503)&&e.message===qu}async function Ki(e,t={}){var l;let s;try{s=await fetch(e,{...t,credentials:"same-origin",redirect:"error",headers:{Accept:"application/json",...t.headers??{}}})}catch(o){throw(o==null?void 0:o.name)==="AbortError"||(l=t.signal)!=null&&l.aborted?o:(Cc(!1),new ge(0,qu,o))}if(s.status===401)throw Cc(!0),new ge(401,"This session has expired. Run `buddi dashboard` for a fresh link.");const r=await s.text(),i=r===""?null:n$(r),a=i&&typeof i=="object"&&"error"in i?String(i.error):void 0;if((s.status===502||s.status===503)&&a===void 0)throw Cc(!1),new ge(s.status,qu,i);if(Cc(!0),!s.ok){const o=(t.method??"GET").toUpperCase(),c=a??(s.status===403&&o!=="GET"&&o!=="HEAD"?X2:`request failed (${s.status})`);throw new ge(s.status,c,i)}return i}function n$(e){try{return JSON.parse(e)}catch{return null}}function fe(e,t={}){const s=new URLSearchParams;for(const[i,a]of Object.entries(t))a!==void 0&&a!==""&&s.set(i,String(a));const r=s.toString();return Ki(`/api${e}${r?`?${r}`:""}`)}function QS(e,t){return Ki(`/api${e}`,{method:"POST",headers:{[il]:Hi()},body:t})}function ya(e){return Ki(`/api${e}`,{method:"DELETE",headers:{[il]:Hi()}})}function ne(e,t={}){return Ki(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[il]:Hi()},body:JSON.stringify(t??{})})}function JS(e,t,s,r={}){const i=t.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return Ki(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[il]:Hi(),"X-Filename":i,...r},body:t})}function _y(e,t,s){return JS(e,t,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function s$(e,t={}){return Ki(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[il]:Hi()},body:JSON.stringify(t??{})})}function vi(e,t={}){return Ki(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[il]:Hi()},body:JSON.stringify(t??{})})}function r$(e){if(e.dismissedAt)return"You said no to this one.";switch(e.lapseReason){case"owner-moved-on":return"The conversation moved on.";case"rolled-over":return"That conversation ended.";case"agent-removed":return"That agent is no longer here.";default:return"It lapsed."}}const uu="gpt-oss:120b",i$=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Wm=["mon","tue","wed","thu","fri","sat","sun"],Fe={agents:()=>fe("/chat/agents"),views:()=>fe("/chat/views"),conversations:(e,t)=>fe(`/chat/${encodeURIComponent(e)}/conversations`,{limit:t}),startConversation:e=>ne(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>fe(`/chat/conversations/${encodeURIComponent(e)}`),send:(e,t)=>ne(`/chat/${encodeURIComponent(e)}/messages`,t),answerQuestion:(e,t)=>ne(`/chat/questions/${encodeURIComponent(e)}/answer`,t),cancel:e=>ne(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const t=new FormData;return t.append("file",e,e.name),QS("/chat/attachments",t)},transcribe:e=>ne("/speech/transcribe",e),say:e=>ne("/speech/say",e),discardAttachment:e=>ya(`/artifacts/${encodeURIComponent(e)}`),groups:()=>fe("/groups"),group:e=>fe(`/groups/${encodeURIComponent(e)}`),createGroup:e=>ne("/groups",e),updateGroup:(e,t)=>s$(`/groups/${encodeURIComponent(e)}`,t),archiveGroup:e=>ya(`/groups/${encodeURIComponent(e)}`),groupConversations:e=>fe(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>ne(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,t)=>ne(`/groups/${encodeURIComponent(e)}/messages`,t),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function ux(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const T={providers:()=>fe("/providers"),providerAccounts:()=>fe("/provider-accounts"),probeModels:e=>ne("/provider-accounts/probe-models",e),accountModels:(e,t=!1)=>ne(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:t}),saveProviderAccount:e=>ne("/provider-accounts/save",e),testProviderAccount:e=>ne(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:t}),codexAccountAction:(e,t,s)=>ne(`/provider-accounts/${encodeURIComponent(e)}/${t}`,{revision:s}),ollamaConnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:t}),ollamaPoll:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:t}),ollamaDisconnect:(e,t)=>ne(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:t}),anthropicAccountAction:(e,t,s,r)=>ne(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${t}`,{revision:s,...r}),assignProviderAccount:(e,t,s)=>ne(`/agents/${encodeURIComponent(e)}/account`,{accountId:t,model:s}),configureProvider:(e,t)=>ne(`/providers/${encodeURIComponent(e)}/settings`,t),saveCredential:(e,t)=>ne(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:t}),removeCredential:e=>ne(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>ne(`/providers/${encodeURIComponent(e)}/test`),browserProfiles:e=>fe("/host/browser-profiles",{app:e}),installedApps:()=>fe("/host/apps"),browser:e=>fe(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,t)=>ne(`/browser/${e}`,t===void 0?{}:{sessionId:t}),browserSettings:e=>ne("/browser/settings",e),computerPermissions:(e=!1)=>ne("/browser/permissions",{prompt:e}),browserInstall:()=>ne("/browser/install",{}),browserCheck:()=>ne("/browser/check",{}),previewLink:(e,t)=>fe(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/link`),previewCheck:(e,t)=>fe(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(t)}/check`),extension:()=>fe("/extension"),pairExtension:e=>ne("/extension/pair",{code:e}),forgetExtension:()=>ya("/extension/pair"),session:()=>fe("/session"),overview:()=>fe("/overview"),events:e=>fe("/events",e),eventKinds:()=>fe("/events/kinds"),conversations:()=>fe("/conversations"),conversation:e=>fe(`/conversations/${encodeURIComponent(e)}`),missions:()=>fe("/missions"),jobs:(e={})=>fe("/jobs",e),approvals:()=>fe("/approvals"),approval:e=>fe(`/approvals/${encodeURIComponent(e)}`).then(t=>t.action),offers:()=>fe("/offers"),dismissOffer:e=>ne(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>ne("/offers/dismiss-all",{ids:e}),agentOffers:()=>fe("/agent-offers"),teammates:()=>fe("/teammates"),dismissAgentOffer:(e,t)=>ne(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(t)}/dismiss`,{}),proposals:()=>fe("/proposals"),setDigestSchedule:(e,t)=>ne("/proposals/digest-schedule",{day:e,hour:t}),keepProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/keep`,t===void 0?{}:{text:t}),discardProposal:(e,t)=>ne(`/proposals/${encodeURIComponent(e)}/discard`,t?{reason:t}:{}),reminders:()=>fe("/reminders"),sentinels:()=>fe("/sentinels"),setSentinelEnabled:(e,t)=>ne(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:t}),setGlanceHidden:(e,t)=>ne(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:t}),rail:()=>fe("/rail"),setRailHidden:(e,t,s)=>ne(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}/hidden`,{hidden:s}),snoozeAlert:(e,t)=>ne(`/alerts/${encodeURIComponent(e)}/snooze`,{snoozed:t}),agents:()=>fe("/agents"),library:e=>fe("/artifacts",e),libraryEntry:(e,t=0)=>fe(`/artifacts/${encodeURIComponent(e)}`,t?{contexts:t}:{}),onboarding:()=>fe("/onboarding"),onboardingStep:(e,t={})=>ne("/onboarding/step",{step:e,...t}),takeOn:e=>ne("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>fe("/onboarding/take-on"),completeOnboarding:()=>ne("/onboarding/complete"),skipOnboarding:()=>ne("/onboarding/skip"),createFirstAgent:e=>ne("/onboarding/agent",e),ollama:()=>fe("/onboarding/ollama"),mlxh:()=>fe("/onboarding/mlxh"),firstAgentPersona:()=>fe("/onboarding/agent"),updateFirstAgent:e=>ne("/onboarding/agent/update",e),bindBrain:e=>ne("/onboarding/brain",e),pages:()=>fe("/pages"),pageQuery:(e,t,s={})=>fe(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,s),pageFileUrl:(e,t,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,i])=>i!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r?`?${r}`:""}`},pageAct:(e,t)=>ne(`/pages/${encodeURIComponent(e)}/act`,t),telegram:()=>fe("/telegram"),saveTelegramToken:e=>ne("/telegram/token",{token:e}),telegramPairing:()=>ne("/telegram/pairing"),telegramBot:()=>fe("/telegram/bot"),telegramDevices:()=>fe("/telegram/devices"),unpairTelegramDevice:e=>ya(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>fe("/notifications",{limit:e}),notificationSeen:e=>ne(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>fe("/notifications/settings"),saveNotificationSettings:e=>vi("/notifications/settings",e),focus:()=>fe("/notifications/focus"),setFocus:(e,t)=>vi("/notifications/focus",t?{mode:e,duration:t}:{mode:e}),testChannel:e=>ne("/notifications/test",{channel:e}),setAgentMuted:(e,t)=>ne("/notifications/agent-mute",{agentId:e,muted:t}),currentTip:e=>fe(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>fe("/tips"),restoreTip:e=>ne(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>ne(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>ne(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>ne("/tips/seen-page",{page:e}),tipsSettings:()=>fe("/tips/settings"),saveTipsSettings:e=>vi("/tips/settings",{enabled:e}),presence:e=>ne("/presence",{state:e}),owner:()=>fe("/owner"),setOwner:e=>ne("/owner",e),memory:e=>fe(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>ne("/memory/preferences",e),forgetPreference:e=>ne("/memory/preferences/forget",e),updateNote:(e,t)=>ne(`/memory/notes/${encodeURIComponent(e)}`,t),forgetNote:e=>ne(`/memory/notes/${encodeURIComponent(e)}/forget`),setDelegates:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:t}),agentProfile:e=>fe(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>fe(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(t)}/remove`,{}),host:(e,t)=>fe("/host",{agentId:e,conversationId:t}),connections:()=>fe("/connections"),connection:e=>fe(`/connections/${e}`),addConnection:(e,t)=>ne("/connections",{url:e,...t?{name:t}:{}}),addProgram:e=>ne("/connections",{transport:"stdio",...e}),updateProgram:(e,t)=>ne(`/connections/${e}/program`,t),connectionConsent:(e,t)=>ne(`/connections/${e}/consent`,t?{clientId:t}:{}),connectionToken:(e,t)=>ne(`/connections/${e}/token`,t),connectionDevice:e=>ne(`/connections/${e}/device`,{}),connectionCallback:e=>ne("/connections/callback",e),connectionReview:e=>fe(`/connections/${e}/review`),saveConnectionReview:(e,t)=>ne(`/connections/${e}/review`,t),grantConnection:(e,t,s=!1)=>ne(`/connections/${e}/grant`,s?{agents:t,exact:!0}:{agents:t}),setConnectionHolder:(e,t,s)=>ne(`/connections/${e}/holders/${encodeURIComponent(t)}`,{held:s}),disconnect:e=>ya(`/connections/${e}`),connectionSignals:()=>fe("/connections/signals"),connectionTools:e=>fe(`/connections/${e}/tools`),rememberedApprovals:e=>fe(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,t,s)=>ne("/connections/remembered",{agent:e,tool:t,remember:s}),secrets:()=>fe("/secrets"),secretUses:(e,t)=>fe("/secrets/uses",{name:e,limit:t}),secretsAct:(e,t)=>ne("/secrets/act",{tool:e,args:t}),stopHost:(e,t)=>ne("/host/stop",{agentId:e,conversationId:t}),revokeHost:e=>ne("/host/revoke",{id:e}),decide:(e,t,s,r)=>ne(`/approvals/${encodeURIComponent(e)}/${t}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>ne("/pause",{paused:e}),service:()=>fe("/service"),serviceAction:e=>ne(`/service/${e}`),version:()=>fe("/version"),checkVersion:()=>ne("/version/check"),setVersionCheck:e=>vi("/version/check",{enabled:e}),tailscale:()=>fe("/tailscale"),setTailscale:e=>vi("/tailscale",e),startUpgrade:e=>ne("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>fe(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>fe("/backups"),startBackup:e=>ne("/backups",{encrypt:e}),verifyArchive:e=>ne("/backups/verify",{name:e}),restoreArchive:e=>ne("/backups/restore",e),restoreUpload:(e,t)=>_y("/backups/restore",e,t),backupJob:e=>fe(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>fe("/backups/schedule"),setBackupSchedule:e=>vi("/backups/schedule",e),backupPassphrase:()=>fe("/backups/passphrase"),setBackupPassphrase:e=>vi("/backups/passphrase",{passphrase:e}),plugins:()=>fe("/plugins"),market:(e=!1)=>fe(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>fe("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>ne("/plugins/stage",{spec:e}),uploadPlugin:e=>JS("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>fe(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,t)=>ne(`/plugins/staged/${encodeURIComponent(e)}/approve`,t),rejectStaged:e=>ne(`/plugins/staged/${encodeURIComponent(e)}/reject`),updatePlugin:(e,t,s)=>ne(`/plugins/${encodeURIComponent(e)}/update`,{...t?{version:t}:{},...s?{from:s}:{}}),setPluginEnabled:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/${t?"enable":"disable"}`,{}),uninstallPlugin:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/uninstall`,t),acceptPluginAgent:(e,t)=>ne(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}/accept`),recovery:()=>fe("/recovery"),leaveRecovery:e=>ne("/recovery/leave",e),firstRunRestore:(e,t)=>_y("/onboarding/restore",e,{passphrase:t}),setMissionEnabled:(e,t)=>ne(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:t}),setMisfirePolicy:(e,t,s)=>ne(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:t,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>ne(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>ne(`/jobs/${encodeURIComponent(e)}/cancel`),setDefaultAgent:e=>ne("/agents/default",{agentId:e}),agentTools:e=>fe(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>fe(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,t)=>{const s=new FormData;return s.append("file",t,t.name),QS(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>ya(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/file`,t),setAgentEngine:(e,t)=>ne(`/agents/${encodeURIComponent(e)}/engine`,t),takeOffer:(e,t)=>ne(`/offers/${encodeURIComponent(e)}/take`,t?{conversationId:t}:{}),cancelReminder:e=>ne(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})};function XS(e){return e==="anthropic"||e==="openai"}function ZS(e,t){var i,a;if(!e)return null;const s=e.credentialEnv&&(t!=null&&t.accounts.some(l=>l.id===e.credentialEnv))?e.credentialEnv:(a=(i=t==null?void 0:t.bindings)==null?void 0:i.find(l=>l.agentId===e.id))==null?void 0:a.accountId,r=s?t==null?void 0:t.accounts.find(l=>l.id===s):void 0;return(r==null?void 0:r.kind)??e.provider}const a$="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var l$=Object.defineProperty,o$=(e,t)=>l$(e,"name",{value:t,configurable:!0}),c$=f.createContext(void 0);function zd(e){const t=f.useContext(c$);return e||t||"ltr"}o$(zd,"useDirection");var u$=Object.defineProperty,dx=(e,t)=>u$(e,"name",{value:t,configurable:!0}),Ec=0,Ms=null;function d$(e){return Ud(),e.children}dx(d$,"FocusGuards");function Ud(){f.useEffect(()=>{Ms||(Ms={start:Hm(),end:Hm()});const{start:e,end:t}=Ms;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement("beforeend",t),Ec++,()=>{Ec===1&&(Ms==null||Ms.start.remove(),Ms==null||Ms.end.remove(),Ms=null),Ec=Math.max(0,Ec-1)}},[])}dx(Ud,"useFocusGuards");function Hm(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}dx(Hm,"createFocusGuard");var h$=Object.defineProperty,gn=(e,t)=>h$(e,"name",{value:t,configurable:!0}),Vh="focusScope.autoFocusOnMount",Gh="focusScope.autoFocusOnUnmount",Ly={bubbles:!1,cancelable:!0},eN=f.forwardRef(gn(function(t,s){const{loop:r=!1,trapped:i=!1,onMountAutoFocus:a,onUnmountAutoFocus:l,...o}=t,[c,u]=f.useState(null),d=us(a),h=us(l),m=f.useRef(null),p=ut(s,u),g=f.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;f.useEffect(()=>{if(i){let b=function(w){if(g.paused||!c)return;const S=w.target;c.contains(S)?m.current=S:er(m.current,{select:!0})},x=function(w){if(g.paused||!c)return;const S=w.relatedTarget;S!==null&&(c.contains(S)||er(m.current,{select:!0}))},v=function(w){if(document.activeElement===document.body)for(const k of w)k.removedNodes.length>0&&er(c)};gn(b,"handleFocusIn"),gn(x,"handleFocusOut"),gn(v,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",x);const j=new MutationObserver(v);return c&&j.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",x),j.disconnect()}}},[i,c,g.paused]),f.useEffect(()=>{if(c){Fy.add(g);const b=document.activeElement;if(!c.contains(b)){const v=new CustomEvent(Vh,Ly);c.addEventListener(Vh,d),c.dispatchEvent(v),v.defaultPrevented||(tN(aN(hx(c)),{select:!0}),document.activeElement===b&&er(c))}return()=>{c.removeEventListener(Vh,d),setTimeout(()=>{const v=new CustomEvent(Gh,Ly);c.addEventListener(Gh,h),c.dispatchEvent(v),v.defaultPrevented||er(b??document.body,{select:!0}),c.removeEventListener(Gh,h),Fy.remove(g)},0)}}},[c,d,h,g]);const y=f.useCallback(b=>{if(!r&&!i||g.paused)return;const x=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,v=document.activeElement;if(x&&v){const j=b.currentTarget,[w,S]=nN(j);w&&S?!b.shiftKey&&v===S?(b.preventDefault(),r&&er(w,{select:!0})):b.shiftKey&&v===w&&(b.preventDefault(),r&&er(S,{select:!0})):v===j&&b.preventDefault()}},[r,i,g.paused]);return n.jsx(bt.div,{tabIndex:-1,...o,ref:p,onKeyDown:y})},"FocusScope"));function tN(e,{select:t=!1}={}){const s=document.activeElement;for(const r of e)if(er(r,{select:t}),document.activeElement!==s)return}gn(tN,"focusFirst");function nN(e){const t=hx(e),s=Km(t,e),r=Km(t.reverse(),e);return[s,r]}gn(nN,"getTabbableEdges");function hx(e){const t=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:gn(r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)t.push(s.currentNode);return t}gn(hx,"getTabbableCandidates");function Km(e,t){const s=typeof t.checkVisibility=="function"&&t.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):sN(r,{upTo:t})))return r}gn(Km,"findVisible");function sN(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}gn(sN,"isHidden");function rN(e){return e instanceof HTMLInputElement&&"select"in e}gn(rN,"isSelectableInput");function er(e,{select:t=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&rN(e)&&t&&e.select()}}gn(er,"focus");var Fy=iN();function iN(){let e=[];return{add(t){const s=e[0];t!==s&&(s==null||s.pause()),e=Vm(e,t),e.unshift(t)},remove(t){var s;e=Vm(e,t),(s=e[0])==null||s.resume()}}}gn(iN,"createFocusScopesStack");function Vm(e,t){const s=[...e],r=s.indexOf(t);return r!==-1&&s.splice(r,1),s}gn(Vm,"arrayRemove");function aN(e){return e.filter(t=>t.tagName!=="A")}gn(aN,"removeLinks");var f$=Object.defineProperty,fx=(e,t)=>f$(e,"name",{value:t,configurable:!0}),Yh=!1;function lN(){const[e,t]=f.useState(Yh);return f.useEffect(()=>{Yh||(Yh=!0,t(!0))},[]),e}fx(lN,"useIsHydrated");var oN=Za[" useSyncExternalStore ".trim().toString()];function cN(){return()=>{}}fx(cN,"subscribe");function uN(){return oN(cN,()=>!0,()=>!1)}fx(uN,"useIsHydratedModern");var m$=typeof oN=="function"?uN:lN,p$=Object.defineProperty,Vi=(e,t)=>p$(e,"name",{value:t,configurable:!0}),qh="rovingFocusGroup.onEntryFocus",g$={bubbles:!1,cancelable:!0},Bd="RovingFocusGroup",[Gm,dN,x$]=Id(Bd),[v$,Wd]=Ns(Bd,[x$]),[j$,y$]=v$(Bd),w$=f.forwardRef(Vi(function(t,s){return n.jsx(Gm.Provider,{scope:t.__scopeRovingFocusGroup,children:n.jsx(Gm.Slot,{scope:t.__scopeRovingFocusGroup,children:n.jsx(b$,{...t,ref:s})})})},"RovingFocusGroup")),b$=f.forwardRef(Vi(function(t,s){const{__scopeRovingFocusGroup:r,orientation:i,loop:a=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:d,preventScrollOnEntryFocus:h=!1,...m}=t,p=f.useRef(null),g=ut(s,p),y=zd(l),[b,x]=Wi({prop:o,defaultProp:c??null,onChange:u,caller:Bd}),[v,j]=f.useState(!1),w=us(d),S=dN(r),k=f.useRef(!1),[N,C]=f.useState(0);return f.useEffect(()=>{const I=p.current;if(I)return I.addEventListener(qh,w),()=>I.removeEventListener(qh,w)},[w]),n.jsx(j$,{scope:r,orientation:i,dir:y,loop:a,currentTabStopId:b,onItemFocus:f.useCallback(I=>x(I),[x]),onItemShiftTab:f.useCallback(()=>j(!0),[]),onFocusableItemAdd:f.useCallback(()=>C(I=>I+1),[]),onFocusableItemRemove:f.useCallback(()=>C(I=>I-1),[]),children:n.jsx(bt.div,{tabIndex:v||N===0?-1:0,"data-orientation":i,...m,ref:g,style:{outline:"none",...t.style},onMouseDown:Re(t.onMouseDown,()=>{k.current=!0}),onFocus:Re(t.onFocus,I=>{const A=!k.current;if(I.target===I.currentTarget&&A&&!v){const _=new CustomEvent(qh,g$);if(I.currentTarget.dispatchEvent(_),!_.defaultPrevented){const z=S().filter(U=>U.focusable),L=z.find(U=>U.active),E=z.find(U=>U.id===b),D=[L,E,...z].filter(Boolean).map(U=>U.ref.current);mx(D,h)}}k.current=!1}),onBlur:Re(t.onBlur,()=>j(!1))})})},"RovingFocusGroupImpl")),k$="RovingFocusGroupItem",S$=f.forwardRef(Vi(function(t,s){const{__scopeRovingFocusGroup:r,focusable:i=!0,active:a=!1,tabStopId:l,children:o,...c}=t,u=vs(),d=l||u,h=y$(k$,r),m=h.currentTabStopId===d,p=dN(r),{onFocusableItemAdd:g,onFocusableItemRemove:y,currentTabStopId:b}=h,x=m$();return Tn(()=>{if(!(!x||!i))return g(),()=>y()},[x,i,g,y]),f.useEffect(()=>{if(!(x||!i))return g(),()=>y()},[x,i,g,y]),n.jsx(Gm.ItemSlot,{scope:r,id:d,focusable:i,active:a,children:n.jsx(bt.span,{tabIndex:m?0:-1,"data-orientation":h.orientation,...c,ref:s,onMouseDown:Re(t.onMouseDown,v=>{i?h.onItemFocus(d):v.preventDefault()}),onFocus:Re(t.onFocus,()=>h.onItemFocus(d)),onKeyDown:Re(t.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){h.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const j=fN(v,h.orientation,h.dir);if(j!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let S=p().filter(k=>k.focusable).map(k=>k.ref.current);if(j==="last")S.reverse();else if(j==="prev"||j==="next"){j==="prev"&&S.reverse();const k=S.indexOf(v.currentTarget);S=h.loop?mN(S,k+1):S.slice(k+1)}setTimeout(()=>mx(S))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:b!=null}):o})})},"RovingFocusGroupItem")),N$={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function hN(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}Vi(hN,"getDirectionAwareKey");function fN(e,t,s){const r=hN(e.key,s);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return N$[r]}Vi(fN,"getFocusIntent");function mx(e,t=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:t}),document.activeElement!==s))return}Vi(mx,"focusFirst");function mN(e,t){return e.map((s,r)=>e[(t+r)%e.length])}Vi(mN,"wrapArray");var pN=w$,gN=S$,C$=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ea=new WeakMap,Ac=new WeakMap,Tc={},Qh=0,xN=function(e){return e&&(e.host||xN(e.parentNode))},E$=function(e,t){return t.map(function(s){if(e.contains(s))return s;var r=xN(s);return r&&e.contains(r)?r:(console.error("aria-hidden",s,"in not contained inside",e,". Doing nothing"),null)}).filter(function(s){return!!s})},A$=function(e,t,s,r){var i=E$(t,Array.isArray(e)?e:[e]);Tc[s]||(Tc[s]=new WeakMap);var a=Tc[s],l=[],o=new Set,c=new Set(i),u=function(h){!h||o.has(h)||(o.add(h),u(h.parentNode))};i.forEach(u);var d=function(h){!h||c.has(h)||Array.prototype.forEach.call(h.children,function(m){if(o.has(m))d(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",y=(ea.get(m)||0)+1,b=(a.get(m)||0)+1;ea.set(m,y),a.set(m,b),l.push(m),y===1&&g&&Ac.set(m,!0),b===1&&m.setAttribute(s,"true"),g||m.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",m,x)}})};return d(t),o.clear(),Qh++,function(){l.forEach(function(h){var m=ea.get(h)-1,p=a.get(h)-1;ea.set(h,m),a.set(h,p),m||(Ac.has(h)||h.removeAttribute(r),Ac.delete(h)),p||h.removeAttribute(s)}),Qh--,Qh||(ea=new WeakMap,ea=new WeakMap,Ac=new WeakMap,Tc={})}},vN=function(e,t,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),i=C$(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live], script"))),A$(r,i,s,"aria-hidden")):function(){return null}},Ls=function(){return Ls=Object.assign||function(t){for(var s,r=1,i=arguments.length;r<i;r++){s=arguments[r];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(t[a]=s[a])}return t},Ls.apply(this,arguments)};function jN(e,t){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(s[r[i]]=e[r[i]]);return s}function T$(e,t,s){if(s||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||(a=Array.prototype.slice.call(t,0,r)),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var du="right-scroll-bar-position",hu="width-before-scroll-bar",R$="with-scroll-bars-hidden",I$="--removed-body-scroll-bar-size";function Jh(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function P$(e,t){var s=f.useState(function(){return{value:e,callback:t,facade:{get current(){return s.value},set current(r){var i=s.value;i!==r&&(s.value=r,s.callback(r,i))}}}})[0];return s.callback=t,s.facade}var $$=typeof window<"u"?f.useLayoutEffect:f.useEffect,zy=new WeakMap;function M$(e,t){var s=P$(null,function(r){return e.forEach(function(i){return Jh(i,r)})});return $$(function(){var r=zy.get(s);if(r){var i=new Set(r),a=new Set(e),l=s.current;i.forEach(function(o){a.has(o)||Jh(o,null)}),a.forEach(function(o){i.has(o)||Jh(o,l)})}zy.set(s,e)},[e]),s}function O$(e){return e}function D$(e,t){t===void 0&&(t=O$);var s=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return s.length?s[s.length-1]:e},useMedium:function(a){var l=t(a,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(a){for(r=!0;s.length;){var l=s;s=[],l.forEach(a)}s={push:function(o){return a(o)},filter:function(){return s}}},assignMedium:function(a){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(a),l=s}var c=function(){var d=l;l=[],d.forEach(a)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(d){l.push(d),u()},filter:function(d){return l=l.filter(d),s}}}};return i}function _$(e){e===void 0&&(e={});var t=D$(null);return t.options=Ls({async:!0,ssr:!1},e),t}var yN=function(e){var t=e.sideCar,s=jN(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return f.createElement(r,Ls({},s))};yN.isSideCarExport=!0;function L$(e,t){return e.useMedium(t),yN}var wN=_$(),Xh=function(){},Hd=f.forwardRef(function(e,t){var s=f.useRef(null),r=f.useState({onScrollCapture:Xh,onWheelCapture:Xh,onTouchMoveCapture:Xh}),i=r[0],a=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,d=e.enabled,h=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,y=e.inert,b=e.allowPinchZoom,x=e.as,v=x===void 0?"div":x,j=e.gapMode,w=jN(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=m,k=M$([s,t]),N=Ls(Ls({},w),i);return f.createElement(f.Fragment,null,d&&f.createElement(S,{sideCar:wN,removeScrollBar:u,shards:h,noRelative:p,noIsolation:g,inert:y,setCallbacks:a,allowPinchZoom:!!b,lockRef:s,gapMode:j}),l?f.cloneElement(f.Children.only(o),Ls(Ls({},N),{ref:k})):f.createElement(v,Ls({},N,{className:c,ref:k}),o))});Hd.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Hd.classNames={fullWidth:hu,zeroRight:du};var F$=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function z$(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=F$();return t&&e.setAttribute("nonce",t),e}function U$(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function B$(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var W$=function(){var e=0,t=null;return{add:function(s){e==0&&(t=z$())&&(U$(t,s),B$(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},H$=function(){var e=W$();return function(t,s){f.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&s])}},bN=function(){var e=H$(),t=function(s){var r=s.styles,i=s.dynamic;return e(r,i),null};return t},K$={left:0,top:0,right:0,gap:0},Zh=function(e){return parseInt(e||"",10)||0},V$=function(e){var t=window.getComputedStyle(document.body),s=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],i=t[e==="padding"?"paddingRight":"marginRight"];return[Zh(s),Zh(r),Zh(i)]},G$=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return K$;var t=V$(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-s+t[2]-t[0])}},Y$=bN(),Ta="data-scroll-locked",q$=function(e,t,s,r){var i=e.left,a=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
|
|
41
|
+
.`.concat(R$,` {
|
|
42
|
+
overflow: hidden `).concat(r,`;
|
|
43
|
+
padding-right: `).concat(o,"px ").concat(r,`;
|
|
44
|
+
}
|
|
45
|
+
body[`).concat(Ta,`] {
|
|
46
|
+
overflow: hidden `).concat(r,`;
|
|
47
|
+
overscroll-behavior: contain;
|
|
48
|
+
`).concat([t&&"position: relative ".concat(r,";"),s==="margin"&&`
|
|
49
|
+
padding-left: `.concat(i,`px;
|
|
50
|
+
padding-top: `).concat(a,`px;
|
|
51
|
+
padding-right: `).concat(l,`px;
|
|
52
|
+
margin-left:0;
|
|
53
|
+
margin-top:0;
|
|
54
|
+
margin-right: `).concat(o,"px ").concat(r,`;
|
|
55
|
+
`),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.`).concat(du,` {
|
|
59
|
+
right: `).concat(o,"px ").concat(r,`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.`).concat(hu,` {
|
|
63
|
+
margin-right: `).concat(o,"px ").concat(r,`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.`).concat(du," .").concat(du,` {
|
|
67
|
+
right: 0 `).concat(r,`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.`).concat(hu," .").concat(hu,` {
|
|
71
|
+
margin-right: 0 `).concat(r,`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
body[`).concat(Ta,`] {
|
|
75
|
+
`).concat(I$,": ").concat(o,`px;
|
|
76
|
+
}
|
|
77
|
+
`)},Uy=function(){var e=parseInt(document.body.getAttribute(Ta)||"0",10);return isFinite(e)?e:0},Q$=function(){f.useEffect(function(){return document.body.setAttribute(Ta,(Uy()+1).toString()),function(){var e=Uy()-1;e<=0?document.body.removeAttribute(Ta):document.body.setAttribute(Ta,e.toString())}},[])},J$=function(e){var t=e.noRelative,s=e.noImportant,r=e.gapMode,i=r===void 0?"margin":r;Q$();var a=f.useMemo(function(){return G$(i)},[i]);return f.createElement(Y$,{styles:q$(a,!t,i,s?"":"!important")})},Ym=!1;if(typeof window<"u")try{var Rc=Object.defineProperty({},"passive",{get:function(){return Ym=!0,!0}});window.addEventListener("test",Rc,Rc),window.removeEventListener("test",Rc,Rc)}catch{Ym=!1}var ta=Ym?{passive:!1}:!1,X$=function(e){return e.tagName==="TEXTAREA"},kN=function(e,t){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[t]!=="hidden"&&!(s.overflowY===s.overflowX&&!X$(e)&&s[t]==="visible")},Z$=function(e){return kN(e,"overflowY")},eM=function(e){return kN(e,"overflowX")},By=function(e,t){var s=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=SN(e,r);if(i){var a=NN(e,r),l=a[1],o=a[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},tM=function(e){var t=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[t,s,r]},nM=function(e){var t=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[t,s,r]},SN=function(e,t){return e==="v"?Z$(t):eM(t)},NN=function(e,t){return e==="v"?tM(t):nM(t)},sM=function(e,t){return e==="h"&&t==="rtl"?-1:1},rM=function(e,t,s,r,i){var a=sM(e,window.getComputedStyle(t).direction),l=a*r,o=s.target,c=t.contains(o),u=!1,d=l>0,h=0,m=0;do{if(!o)break;var p=NN(e,o),g=p[0],y=p[1],b=p[2],x=y-b-a*g;(g||x)&&SN(e,o)&&(h+=x,m+=g);var v=o.parentNode;o=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!c&&o!==document.body||c&&(t.contains(o)||t===o));return(d&&Math.abs(h)<1||!d&&Math.abs(m)<1)&&(u=!0),u},Ic=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Wy=function(e){return[e.deltaX,e.deltaY]},Hy=function(e){return e&&"current"in e?e.current:e},iM=function(e,t){return e[0]===t[0]&&e[1]===t[1]},aM=function(e){return`
|
|
78
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
79
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
80
|
+
`)},lM=0,na=[];function oM(e){var t=f.useRef([]),s=f.useRef([0,0]),r=f.useRef(),i=f.useState(lM++)[0],a=f.useState(bN)[0],l=f.useRef(e);f.useEffect(function(){l.current=e},[e]),f.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(i));var y=T$([e.lockRef.current],(e.shards||[]).map(Hy),!0).filter(Boolean);return y.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),y.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[e.inert,e.lockRef.current,e.shards]);var o=f.useCallback(function(y,b){if("touches"in y&&y.touches.length===2||y.type==="wheel"&&y.ctrlKey)return!l.current.allowPinchZoom;var x=Ic(y),v=s.current,j="deltaX"in y?y.deltaX:v[0]-x[0],w="deltaY"in y?y.deltaY:v[1]-x[1],S,k=y.target,N=Math.abs(j)>Math.abs(w)?"h":"v";if("touches"in y&&N==="h"&&k.type==="range")return!1;var C=window.getSelection(),I=C&&C.anchorNode,A=I?I===k||I.contains(k):!1;if(A)return!1;var _=By(N,k);if(!_)return!0;if(_?S=N:(S=N==="v"?"h":"v",_=By(N,k)),!_)return!1;if(!r.current&&"changedTouches"in y&&(j||w)&&(r.current=S),!S)return!0;var z=r.current||S;return rM(z,b,y,z==="h"?j:w)},[]),c=f.useCallback(function(y){var b=y;if(!(!na.length||na[na.length-1]!==a)){var x="deltaY"in b?Wy(b):Ic(b),v=t.current.filter(function(S){return S.name===b.type&&(S.target===b.target||b.target===S.shadowParent)&&iM(S.delta,x)})[0];if(v&&v.should){b.cancelable&&b.preventDefault();return}if(!v){var j=(l.current.shards||[]).map(Hy).filter(Boolean).filter(function(S){return S.contains(b.target)}),w=j.length>0?o(b,j[0]):!l.current.noIsolation;w&&b.cancelable&&b.preventDefault()}}},[]),u=f.useCallback(function(y,b,x,v){var j={name:y,delta:b,target:x,should:v,shadowParent:cM(x)};t.current.push(j),setTimeout(function(){t.current=t.current.filter(function(w){return w!==j})},1)},[]),d=f.useCallback(function(y){s.current=Ic(y),r.current=void 0},[]),h=f.useCallback(function(y){u(y.type,Wy(y),y.target,o(y,e.lockRef.current))},[]),m=f.useCallback(function(y){u(y.type,Ic(y),y.target,o(y,e.lockRef.current))},[]);f.useEffect(function(){return na.push(a),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:m}),document.addEventListener("wheel",c,ta),document.addEventListener("touchmove",c,ta),document.addEventListener("touchstart",d,ta),function(){na=na.filter(function(y){return y!==a}),document.removeEventListener("wheel",c,ta),document.removeEventListener("touchmove",c,ta),document.removeEventListener("touchstart",d,ta)}},[]);var p=e.removeScrollBar,g=e.inert;return f.createElement(f.Fragment,null,g?f.createElement(a,{styles:aM(i)}):null,p?f.createElement(J$,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function cM(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const uM=L$(wN,oM);var px=f.forwardRef(function(e,t){return f.createElement(Hd,Ls({},e,{ref:t,sideCar:uM}))});px.classNames=Hd.classNames;var dM=Object.defineProperty,Qe=(e,t)=>dM(e,"name",{value:t,configurable:!0}),qm=["Enter"," "],hM=["ArrowDown","PageUp","Home"],CN=["ArrowUp","PageDown","End"],fM=[...hM,...CN],mM={ltr:[...qm,"ArrowRight"],rtl:[...qm,"ArrowLeft"]},pM={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Kd="Menu",[No,gM,xM]=Id(Kd),[Gi,EN]=Ns(Kd,[xM,Ld,Wd]),Vd=Ld(),AN=Wd(),[TN,di]=Gi(Kd),[vM,Wo]=Gi(Kd),jM=Qe(e=>{const{__scopeMenu:t,open:s=!1,children:r,dir:i,onOpenChange:a,modal:l=!0}=e,o=Vd(t),[c,u]=f.useState(null),d=f.useRef(!1),h=us(a),m=zd(i);return f.useEffect(()=>{const p=Qe(()=>{d.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=Qe(()=>d.current=!1,"handlePointer");return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),f.useEffect(()=>{if(!s)return;const p=Qe(()=>h(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,h]),n.jsx(ax,{...o,children:n.jsx(TN,{scope:t,open:s,onOpenChange:h,content:c,onContentChange:u,children:n.jsx(vM,{scope:t,onClose:f.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:d,dir:m,modal:l,children:r})})})},"Menu"),RN=f.forwardRef(Qe(function(t,s){const{__scopeMenu:r,...i}=t,a=Vd(r);return n.jsx(zS,{...a,...i,ref:s})},"MenuAnchor")),IN="MenuPortal",[yM,PN]=Gi(IN,{forceMount:void 0}),wM=Qe(e=>{const{__scopeMenu:t,forceMount:s,children:r,container:i}=e,a=di(IN,t);return n.jsx(yM,{scope:t,forceMount:s,children:n.jsx(jr,{present:s||a.open,children:n.jsx(Zg,{asChild:!0,container:i,children:r})})})},"MenuPortal"),js="MenuContent",[bM,gx]=Gi(js),kM=f.forwardRef(Qe(function(t,s){const r=PN(js,t.__scopeMenu),{forceMount:i=r.forceMount,...a}=t,l=di(js,t.__scopeMenu),o=Wo(js,t.__scopeMenu);return n.jsx(No.Provider,{scope:t.__scopeMenu,children:n.jsx(jr,{present:i||l.open,children:n.jsx(No.Slot,{scope:t.__scopeMenu,children:o.modal?n.jsx(SM,{...a,ref:s}):n.jsx(NM,{...a,ref:s})})})})},"MenuContent")),SM=f.forwardRef(Qe(function(t,s){const r=di(js,t.__scopeMenu),i=f.useRef(null),a=ut(s,i);return f.useEffect(()=>{const l=i.current;if(l)return vN(l)},[]),n.jsx(xx,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Re(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),NM=f.forwardRef(Qe(function(t,s){const r=di(js,t.__scopeMenu);return n.jsx(xx,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),CM=ei("MenuContent.ScrollLock"),xx=f.forwardRef(Qe(function(t,s){const{__scopeMenu:r,loop:i=!1,trapFocus:a,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:y,...b}=t,x=di(js,r),v=Wo(js,r),j=Vd(r),w=AN(r),S=gM(r),[k,N]=f.useState(null),C=f.useRef(null),I=ut(s,C,x.onContentChange),A=f.useRef(0),_=f.useRef(""),z=f.useRef(0),L=f.useRef(null),E=f.useRef("right"),M=f.useRef(0),D=y?px:f.Fragment,U=y?{as:CM,allowPinchZoom:!0}:void 0,$=Qe(O=>{var de,Ie;const K=_.current+O,G=S().filter(Se=>!Se.disabled),se=document.activeElement,ue=(de=G.find(Se=>Se.ref.current===se))==null?void 0:de.textValue,ie=G.map(Se=>Se.textValue),ee=BN(ie,K,ue),X=(Ie=G.find(Se=>Se.textValue===ee))==null?void 0:Ie.ref.current;Qe(function Se(we){_.current=we,window.clearTimeout(A.current),we!==""&&(A.current=window.setTimeout(()=>Se(""),1e3))},"updateSearch")(K),X&&setTimeout(()=>X.focus())},"handleTypeaheadSearch");f.useEffect(()=>()=>window.clearTimeout(A.current),[]),Ud();const B=f.useCallback(O=>{var G,se;return E.current===((G=L.current)==null?void 0:G.side)&&HN(O,(se=L.current)==null?void 0:se.area)},[]);return n.jsx(bM,{scope:r,searchRef:_,onItemEnter:f.useCallback(O=>{B(O)&&O.preventDefault()},[B]),onItemLeave:f.useCallback(O=>{var K;B(O)||((K=C.current)==null||K.focus(),N(null))},[B]),onTriggerLeave:f.useCallback(O=>{B(O)&&O.preventDefault()},[B]),pointerGraceTimerRef:z,onPointerGraceIntentChange:f.useCallback(O=>{L.current=O},[]),children:n.jsx(D,{...U,children:n.jsx(eN,{asChild:!0,trapped:a,onMountAutoFocus:Re(l,O=>{var K;O.preventDefault(),(K=C.current)==null||K.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:n.jsx(Jg,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:d,onPointerDownOutside:h,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:n.jsx(pN,{asChild:!0,...w,dir:v.dir,orientation:"vertical",loop:i,currentTabStopId:k,onCurrentTabStopIdChange:N,onEntryFocus:Re(u,O=>{v.isUsingKeyboardRef.current||O.preventDefault()}),preventScrollOnEntryFocus:!0,children:n.jsx(US,{role:"menu","aria-orientation":"vertical","data-state":vx(x.open),"data-radix-menu-content":"",dir:v.dir,...j,...b,ref:I,style:{outline:"none",...b.style},onKeyDown:Re(b.onKeyDown,O=>{const G=O.target.closest("[data-radix-menu-content]")===O.currentTarget,se=O.ctrlKey||O.altKey||O.metaKey,ue=O.key.length===1;G&&(O.key==="Tab"&&O.preventDefault(),!se&&ue&&$(O.key));const ie=C.current;if(O.target!==ie||!fM.includes(O.key))return;O.preventDefault();const X=S().filter(de=>!de.disabled).map(de=>de.ref.current);CN.includes(O.key)&&X.reverse(),zN(X)}),onBlur:Re(t.onBlur,O=>{O.currentTarget.contains(O.target)||(window.clearTimeout(A.current),_.current="")}),onPointerMove:Re(t.onPointerMove,Ua(O=>{const K=O.target,G=M.current!==O.clientX;if(O.currentTarget.contains(K)&&G){const se=O.clientX>M.current?"right":"left";E.current=se,M.current=O.clientX}}))})})})})})})},"MenuContentImpl")),$N=f.forwardRef(Qe(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(bt.div,{role:"group",...i,ref:s})},"MenuGroup")),EM=f.forwardRef(Qe(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(bt.div,{...i,ref:s})},"MenuLabel")),Qm="MenuItem",Ky="menu.itemSelect",MN=f.forwardRef(Qe(function(t,s){const{disabled:r=!1,onSelect:i,...a}=t,l=f.useRef(null),o=Wo(Qm,t.__scopeMenu),c=gx(Qm,t.__scopeMenu),u=ut(s,l),d=f.useRef(!1),h=Qe(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(Ky,{bubbles:!0,cancelable:!0});m.addEventListener(Ky,g=>i==null?void 0:i(g),{once:!0}),Pd(m,p),p.defaultPrevented?d.current=!1:o.onClose()}},"handleSelect");return n.jsx(ON,{...a,ref:u,disabled:r,onClick:Re(t.onClick,h),onPointerDown:m=>{var p;(p=t.onPointerDown)==null||p.call(t,m),d.current=!0},onPointerUp:Re(t.onPointerUp,m=>{var p;d.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Re(t.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||qm.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),ON=f.forwardRef(Qe(function(t,s){const{__scopeMenu:r,disabled:i=!1,textValue:a,...l}=t,o=gx(Qm,r),c=AN(r),u=f.useRef(null),d=ut(s,u),[h,m]=f.useState(!1),[p,g]=f.useState("");return f.useEffect(()=>{const y=u.current;y&&g((y.textContent??"").trim())},[l.children]),n.jsx(No.ItemSlot,{scope:r,disabled:i,textValue:a??p,children:n.jsx(gN,{asChild:!0,...c,focusable:!i,children:n.jsx(bt.div,{role:"menuitem","data-highlighted":h?"":void 0,"aria-disabled":i||void 0,"data-disabled":i?"":void 0,...l,ref:d,onPointerMove:Re(t.onPointerMove,Ua(y=>{i?o.onItemLeave(y):(o.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Re(t.onPointerLeave,Ua(y=>o.onItemLeave(y))),onFocus:Re(t.onFocus,()=>m(!0)),onBlur:Re(t.onBlur,()=>m(!1))})})})},"MenuItemImpl")),AM="MenuRadioGroup",[TM,RM]=Gi(AM,{value:void 0,onValueChange:Qe(()=>{},"onValueChange")}),IM=f.forwardRef(Qe(function(t,s){const{value:r,onValueChange:i,...a}=t,l=us(i);return n.jsx(TM,{scope:t.__scopeMenu,value:r,onValueChange:l,children:n.jsx($N,{...a,ref:s})})},"MenuRadioGroup")),PM="MenuRadioItem",$M=f.forwardRef(Qe(function(t,s){const{value:r,...i}=t,a=RM(PM,t.__scopeMenu),l=r===a.value;return n.jsx(OM,{scope:t.__scopeMenu,checked:l,children:n.jsx(MN,{role:"menuitemradio","aria-checked":l,...i,ref:s,"data-state":FN(l),onSelect:Re(i.onSelect,()=>{var o;return(o=a.onValueChange)==null?void 0:o.call(a,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),MM="MenuItemIndicator",[OM,gV]=Gi(MM,{checked:!1}),DM=f.forwardRef(Qe(function(t,s){const{__scopeMenu:r,...i}=t;return n.jsx(bt.div,{role:"separator","aria-orientation":"horizontal",...i,ref:s})},"MenuSeparator")),DN="MenuSub",[_M,_N]=Gi(DN),LM=Qe(e=>{const{__scopeMenu:t,children:s,open:r=!1,onOpenChange:i}=e,a=di(DN,t),l=Vd(t),[o,c]=f.useState(null),[u,d]=f.useState(null),h=us(i);return f.useEffect(()=>(a.open===!1&&h(!1),()=>h(!1)),[a.open,h]),n.jsx(ax,{...l,children:n.jsx(TN,{scope:t,open:r,onOpenChange:h,content:u,onContentChange:d,children:n.jsx(_M,{scope:t,contentId:vs(),triggerId:vs(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),Pc="MenuSubTrigger",FM=f.forwardRef(Qe(function(t,s){const r=di(Pc,t.__scopeMenu),i=Wo(Pc,t.__scopeMenu),a=_N(Pc,t.__scopeMenu),l=gx(Pc,t.__scopeMenu),o=f.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,d={__scopeMenu:t.__scopeMenu},h=f.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);f.useEffect(()=>h,[h]),f.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=ut(s,a.onTriggerChange);return n.jsx(RN,{asChild:!0,...d,children:n.jsx(ON,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?a.contentId:void 0,"data-state":vx(r.open),...t,ref:m,onClick:p=>{var g;(g=t.onClick)==null||g.call(t,p),!(t.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Re(t.onPointerMove,Ua(p=>{l.onItemEnter(p),!p.defaultPrevented&&!t.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),h()},100))})),onPointerLeave:Re(t.onPointerLeave,Ua(p=>{var y,b;h();const g=(y=r.content)==null?void 0:y.getBoundingClientRect();if(g){const x=(b=r.content)==null?void 0:b.dataset.side,v=x==="right",j=v?-5:5,w=g[v?"left":"right"],S=g[v?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+j,y:p.clientY},{x:w,y:g.top},{x:S,y:g.top},{x:S,y:g.bottom},{x:w,y:g.bottom}],side:x}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Re(t.onKeyDown,p=>{var y;t.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||mM[i.dir].includes(p.key)&&(r.onOpenChange(!0),(y=r.content)==null||y.focus(),p.preventDefault())})})})},"MenuSubTrigger")),zM="MenuSubContent",UM=f.forwardRef(Qe(function(t,s){const r=PN(js,t.__scopeMenu),{forceMount:i=r.forceMount,align:a="start",...l}=t,o=di(js,t.__scopeMenu),c=Wo(js,t.__scopeMenu),u=_N(zM,t.__scopeMenu),d=f.useRef(null),h=ut(s,d);return n.jsx(No.Provider,{scope:t.__scopeMenu,children:n.jsx(jr,{present:i||o.open,children:n.jsx(No.Slot,{scope:t.__scopeMenu,children:n.jsx(xx,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:h,align:a,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=d.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Re(t.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Re(t.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Re(t.onKeyDown,m=>{var y;const p=m.currentTarget.contains(m.target),g=pM[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(y=u.trigger)==null||y.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function vx(e){return e?"open":"closed"}Qe(vx,"getOpenState");function LN(e){return e==="indeterminate"}Qe(LN,"isIndeterminate");function FN(e){return LN(e)?"indeterminate":e?"checked":"unchecked"}Qe(FN,"getCheckedState");function zN(e){const t=document.activeElement;for(const s of e)if(s===t||(s.focus(),document.activeElement!==t))return}Qe(zN,"focusFirst");function UN(e,t){return e.map((s,r)=>e[(t+r)%e.length])}Qe(UN,"wrapArray");function BN(e,t,s){const i=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,a=s?e.indexOf(s):-1;let l=UN(e,Math.max(a,0));i.length===1&&(l=l.filter(u=>u!==s));const c=l.find(u=>u.toLowerCase().startsWith(i.toLowerCase()));return c!==s?c:void 0}Qe(BN,"getNextMatch");function WN(e,t){const{x:s,y:r}=e;let i=!1;for(let a=0,l=t.length-1;a<t.length;l=a++){const o=t[a],c=t[l],u=o.x,d=o.y,h=c.x,m=c.y;d>r!=m>r&&s<(h-u)*(r-d)/(m-d)+u&&(i=!i)}return i}Qe(WN,"isPointInPolygon");function HN(e,t){if(!t)return!1;const s={x:e.clientX,y:e.clientY};return WN(s,t)}Qe(HN,"isPointerInGraceArea");function Ua(e){return t=>t.pointerType==="mouse"?e(t):void 0}Qe(Ua,"whenMouse");var BM=jM,WM=RN,HM=wM,KM=kM,VM=$N,GM=EM,YM=MN,qM=IM,QM=$M,JM=DM,XM=LM,ZM=FM,eO=UM,tO=Object.defineProperty,Gn=(e,t)=>tO(e,"name",{value:t,configurable:!0}),jx="DropdownMenu",[nO,xV]=Ns(jx,[EN]),Yn=EN(),[sO,KN]=nO(jx),rO=Gn(e=>{const{__scopeDropdownMenu:t,children:s,dir:r,open:i,defaultOpen:a,onOpenChange:l,modal:o=!0}=e,c=Yn(t),u=f.useRef(null),[d,h]=Wi({prop:i,defaultProp:a??!1,onChange:l,caller:jx});return n.jsx(sO,{scope:t,triggerId:vs(),triggerRef:u,contentId:vs(),open:d,onOpenChange:h,onOpenToggle:f.useCallback(()=>h(m=>!m),[h]),modal:o,children:n.jsx(BM,{...c,open:d,onOpenChange:h,dir:r,modal:o,children:s})})},"DropdownMenu"),iO="DropdownMenuTrigger",aO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,disabled:i=!1,...a}=t,l=KN(iO,r),o=Yn(r),c=ut(s,l.triggerRef);return n.jsx(WM,{asChild:!0,...o,children:n.jsx(bt.button,{type:"button",id:l.triggerId,"aria-haspopup":"menu","aria-expanded":l.open,"aria-controls":l.open?l.contentId:void 0,"data-state":l.open?"open":"closed","data-disabled":i?"":void 0,disabled:i,...a,ref:c,onPointerDown:Re(t.onPointerDown,u=>{!i&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Re(t.onKeyDown,u=>{i||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),lO=Gn(e=>{const{__scopeDropdownMenu:t,...s}=e,r=Yn(t);return n.jsx(HM,{...r,...s})},"DropdownMenuPortal"),oO="DropdownMenuContent",cO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=KN(oO,r),l=Yn(r),o=f.useRef(!1);return n.jsx(KM,{id:a.contentId,"aria-labelledby":a.triggerId,...l,...i,ref:s,onCloseAutoFocus:Re(t.onCloseAutoFocus,c=>{var u;o.current||(u=a.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Re(t.onInteractOutside,c=>{const u=c.detail.originalEvent,d=u.button===0&&u.ctrlKey===!0,h=u.button===2||d;(!a.modal||h)&&(o.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),uO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(VM,{...a,...i,ref:s})},"DropdownMenuGroup")),dO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(GM,{...a,...i,ref:s})},"DropdownMenuLabel")),hO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(YM,{...a,...i,ref:s})},"DropdownMenuItem")),fO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(qM,{...a,...i,ref:s})},"DropdownMenuRadioGroup")),mO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(QM,{...a,...i,ref:s})},"DropdownMenuRadioItem")),pO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(JM,{...a,...i,ref:s})},"DropdownMenuSeparator")),gO=Gn(e=>{const{__scopeDropdownMenu:t,children:s,open:r,onOpenChange:i,defaultOpen:a}=e,l=Yn(t),[o,c]=Wi({prop:r,defaultProp:a??!1,onChange:i,caller:"DropdownMenuSub"});return n.jsx(XM,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),xO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(ZM,{...a,...i,ref:s})},"DropdownMenuSubTrigger")),vO=f.forwardRef(Gn(function(t,s){const{__scopeDropdownMenu:r,...i}=t,a=Yn(r);return n.jsx(eO,{...a,...i,ref:s,style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuSubContent")),Gd=rO,Yd=aO,Ho=lO,qd=cO,VN=uO,Qd=dO,Or=hO,jO=fO,yO=mO,Dr=pO,wO=gO,bO=xO,kO=vO,SO=Object.defineProperty,al=(e,t)=>SO(e,"name",{value:t,configurable:!0}),yx="Tabs",[NO,vV]=Ns(yx,[Wd]),GN=Wd(),[CO,wx]=NO(yx),EO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,value:i,onValueChange:a,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...d}=t,h=zd(c),[m,p]=Wi({prop:i,onChange:a,defaultProp:l??"",caller:yx});return n.jsx(CO,{scope:r,baseId:vs(),value:m,onValueChange:p,orientation:o,dir:h,activationMode:u,children:n.jsx(bt.div,{dir:h,"data-orientation":o,...d,ref:s})})},"Tabs")),AO="TabsList",TO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,loop:i=!0,...a}=t,l=wx(AO,r),o=GN(r);return n.jsx(pN,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:i,children:n.jsx(bt.div,{role:"tablist","aria-orientation":l.orientation,...a,ref:s})})},"TabsList")),RO="TabsTrigger",IO=f.forwardRef(al(function(t,s){const{__scopeTabs:r,value:i,disabled:a=!1,...l}=t,o=wx(RO,r),c=GN(r),u=bx(o.baseId,i),d=kx(o.baseId,i),h=i===o.value;return n.jsx(gN,{asChild:!0,...c,focusable:!a,active:h,children:n.jsx(bt.button,{type:"button",role:"tab","aria-selected":h,"aria-controls":d,"data-state":h?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...l,ref:s,onMouseDown:Re(t.onMouseDown,m=>{!a&&m.button===0&&m.ctrlKey===!1?o.onValueChange(i):m.preventDefault()}),onKeyDown:Re(t.onKeyDown,m=>{a||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(i)}),onFocus:Re(t.onFocus,()=>{const m=o.activationMode!=="manual";!h&&!a&&m&&o.onValueChange(i)})})})},"TabsTrigger")),PO="TabsContent",$O=f.forwardRef(al(function(t,s){const{__scopeTabs:r,value:i,forceMount:a,children:l,...o}=t,c=wx(PO,r),u=bx(c.baseId,i),d=kx(c.baseId,i),h=i===c.value,m=f.useRef(h);return f.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),n.jsx(jr,{present:a||h,children:({present:p})=>n.jsx(bt.div,{"data-state":h?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:d,tabIndex:0,...o,ref:s,style:{...t.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function bx(e,t){return`${e}-trigger-${t}`}al(bx,"makeTriggerId");function kx(e,t){return`${e}-content-${t}`}al(kx,"makeContentId");var MO=EO,OO=TO,DO=IO,_O=$O;function Ve(e,t){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):new Intl.DateTimeFormat("en-GB",{timeZone:t,year:"numeric",month:"short",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(s)}function ze(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-t)/1e3),i=Math.abs(r),[a,l]=i<60?[r,"second"]:i<3600?[Math.round(r/60),"minute"]:i<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(a,l)}function YN(e,t=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((t-s)/1e3));return r<60?"now":r<3600?`${Math.floor(r/60)} min`:r<86400?`${Math.floor(r/3600)} h`:`${Math.floor(r/86400)} d`}function LO(e,t=Date.now()){const s=YN(e,t);return s===""?"":s==="now"||new Date(e).getTime()>t?"just now":s==="1 d"?"yesterday":`${s} ago`}function FO(e,t){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function _t(e){return new Intl.NumberFormat("en-US").format(e)}function Jm(e){return[...e.cacheRead?[`cached ${_t(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${_t(e.cacheWrite)}`]:[]].join(", ")}function zO(e){const t=Jm(e);return`${_t(e.input)} in${t?` (${t})`:""} / ${_t(e.output)} out`}function In(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function Co(e,t=8){return e.length<=t?e:e.slice(0,t)}function Vs(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function Ba(e){return e.replace(/<<<[^<>]*>>>/g,"")}function Eo(e){if(e.kind!=="agent")return e.title;const t=e.title.replace(/^@[^\s:]+:\s+/,"");return t.trim()===""?e.title:t}function zt(e,t,s){if(e==null)return"—";switch(t){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?UO(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${Vy(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?_t(r):Vy(r):String(e)}case"date":return BO(String(e));default:return typeof e=="string"?e:typeof e=="number"?_t(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function UO(e,t){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return FO(e,t);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:t??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function BO(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return e;const s=new Date(`${t[0]}T00:00:00Z`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-GB",{timeZone:"UTC",day:"numeric",month:"short",year:"numeric"}).format(s)}function Xm(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!t)return e;const s=new Date(`${t[0]}T00:00:00Z`);return Number.isNaN(s.getTime())?e:new Intl.DateTimeFormat("en-GB",{timeZone:"UTC",day:"numeric",month:"short"}).format(s)}function Vy(e){return String(Math.round(e*100)/100)}function Qu(e,t,s=4){if(!Number.isFinite(e)||!Number.isFinite(t))return[];if(e===t)return[e];const r=(t-e)/Math.max(1,s),i=10**Math.floor(Math.log10(r)),a=[1,2,2.5,5,10].map(o=>o*i).find(o=>o>=r)??i*10,l=[];for(let o=Math.ceil(e/a)*a;o<=t+a/1e3;o+=a)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=t)}function WO({props:e}){if(e.bars.length===0)return n.jsx("p",{className:"wb-empty",children:"No categories came back."});const t=e.bars.map(a=>a.value),s=Math.max(0,...t),r=Math.min(0,...t),i=s-r||1;return n.jsx("div",{className:"wb-bars",children:e.bars.map(a=>{const l=Math.abs(a.value)/i;return n.jsxs("div",{className:"wb-bar-row",children:[n.jsx("div",{className:"wb-bar-cat",title:a.category,children:a.category}),n.jsx("div",{className:"wb-bar-track",children:n.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:a.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),n.jsx("div",{className:"wb-bar-val",children:zt(a.value,e.unit,e.currency)})]},a.category)})})}const HO=/^(diff --git |index [0-9a-f]|--- (a\/|\/dev\/null)|\+\+\+ (b\/|\/dev\/null)|new file mode|deleted file mode|similarity index|rename (from|to) |old mode|new mode|Binary files )/,KO=/^(… |\.\.\. |\(no change\)$|\)/;function VO(e){return e.replace(/\n$/,"").split(`
|
|
81
|
+
`).map(s=>({kind:GO(s),text:s}))}function GO(e){return e.startsWith("@@")?"hunk":HO.test(e)||KO.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function YO({text:e,marks:t}){const s=e.toLowerCase(),r=[];for(const l of t){const o=l.trim().toLowerCase();if(o!=="")for(let c=s.indexOf(o);c!==-1;c=s.indexOf(o,c+o.length))r.push([c,c+o.length])}if(r.length===0)return n.jsx(n.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const i=[];let a=0;for(const[l,o]of r)l<a||(l>a&&i.push(n.jsx("span",{children:e.slice(a,l)},`t${a}`)),i.push(n.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),a=o);return a<e.length&&i.push(n.jsx("span",{children:e.slice(a)},`t${a}`)),n.jsx(n.Fragment,{children:i})}function Ju({text:e,limit:t,more:s,label:r="Diff",marks:i}){const a=VO(e),l=t===void 0?a:a.slice(0,t),o=a.length-l.length;return n.jsxs("div",{className:"wb-diff-wrap",children:[n.jsx("pre",{className:"wb-diff","aria-label":r,"data-testid":"diff",children:l.map((c,u)=>n.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:i&&i.length>0?n.jsx(YO,{text:c.text,marks:i}):c.text===""?" ":c.text},u))}),o>0?n.jsxs("p",{className:"wb-diff-more",children:[o," more line",o===1?"":"s",s?n.jsxs(n.Fragment,{children:[" · ",n.jsx("button",{type:"button",className:"wb-diff-open",onClick:s.onClick,children:s.label})]}):null]}):null]})}function qO({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:zt(t.value,t.unit,null)})]},t.label))}):null,e.diff?n.jsx(Ju,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):n.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const Vt="#/",Yr="#/chat",gt="#/agents",dt="#/activity",cn="#/settings",_i="#/files",QO="#/welcome";function fu(e){const t=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!t)return null;try{return{step:new URLSearchParams(t[1]??"").get("step")}}catch{return{step:null}}}function $c(e,t={}){const s=new URLSearchParams;t.q&&s.set("q",t.q),t.origin&&s.set("origin",t.origin),t.family&&s.set("family",t.family);const r=s.toString();return`${_i}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function JO(e){const t=/^#\/files(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!t)return null;try{const s=new URLSearchParams(t[2]??""),r={};return s.get("q")&&(r.q=s.get("q")),s.get("origin")&&(r.origin=s.get("origin")),s.get("family")&&(r.family=s.get("family")),{...t[1]?{artifactId:decodeURIComponent(t[1])}:{},filters:r}}catch{return null}}function Je(e,t,s){return`#/chat/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function XO(e){if(qN(e))return null;const t=/^#\/chat\/([^/?]+)(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!t)return null;try{const s=new URLSearchParams(t[3]??"").get("tab");return{agentId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{},...s?{tab:s}:{}}}catch{return null}}function Yl(e,t){return`#/chat/g/${encodeURIComponent(e)}${t?`/${encodeURIComponent(t)}`:""}`}function qN(e){const t=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{groupId:decodeURIComponent(t[1]),...t[2]?{conversationId:decodeURIComponent(t[2])}:{}}}catch{return null}}function xt(e,t,s){return`${gt}/${encodeURIComponent(e)}${t?`/${t}${s?`/${s}`:""}`:""}`}function ZO(e){const t=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!t)return null;try{return{agentId:decodeURIComponent(t[1]),...t[2]?{tab:t[2]}:{},...t[3]?{section:t[3]}:{}}}catch{return null}}function Wa(e){return`${dt}/conversations/${encodeURIComponent(e)}`}const eD="#/p";function si(e,t,s){const r=`${eD}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function Sx(e){const t=/^#\/p\/([^/?]+)\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!t)return null;try{return{plugin:decodeURIComponent(t[1]),page:decodeURIComponent(t[2]),...t[3]?{item:decodeURIComponent(t[3])}:{}}}catch{return null}}const tD="p.";function ll(e,t){return`${cn}/${encodeURIComponent(QN(e,t))}`}function nD(e){const t=/^#\/settings\/p\.([^/?.]+)(?:\.([^/?.]+))?(?:\?.*)?$/.exec(e);if(!t)return null;const s=decodeURIComponent(t[1]);return{plugin:s,page:t[2]?decodeURIComponent(t[2]):s}}function QN(e,t){return`${tD}${e}${t===e?"":`.${t}`}`}function Be(e){return e?`${cn}/${e}`:cn}function sD(e){return`${Be("accounts")}?account=${encodeURIComponent(e)}`}function rD(e){const t=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("account")||null}catch{return null}}function iD(e){return`${Be("plugins")}?install=${encodeURIComponent(e)}`}const aD=`${Be("plugins")}?tab=browse`;function lD(e){return`${Be("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function oD(e){const t=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1]).get("plugin")||null}catch{return null}}function JN(e){const t=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!t)return null;try{return new URLSearchParams(t[1])}catch{return null}}function cD(e){var s,r;const t=(r=(s=JN(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return t||null}function Gy(e){const t=JN(e);return t!=null&&t.get("install")?"installed":(t==null?void 0:t.get("tab"))==="browse"?"browse":"installed"}const uD=[{route:Vt,label:"Home"},{route:Yr,label:"Chat"},{route:gt,label:"Agents"},{route:dt,label:"Activity"},{route:_i,label:"Files"},{route:cn,label:"Settings"}],dD=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],hD=[{id:"you",label:"Profile",group:"you"},{id:"appearance",label:"Appearance",group:"you"},{id:"notifications",label:"Notifications",group:"you"},{id:"telegram",label:"Telegram",group:"you"},{id:"memory",label:"Memory",group:"you"},{id:"proposals",label:"Proposals",group:"you"},{id:"accounts",label:"Model accounts",group:"access"},{id:"computer",label:"Computer & browser",group:"access"},{id:"secrets",label:"Keys and secrets",group:"access"},{id:"connections",label:"Connections",group:"access"},{id:"watchers",label:"Watchers",group:"running"},{id:"backup",label:"Backup",group:"running"},{id:"system",label:"System",group:"running"},{id:"plugins",label:"All plugins",group:"plugins"}];function fD(e){var t;return((t=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:t[1])??"you"}const Yy=Be("backup");function mD(e){const t=/^#\/conversations\/(.+)$/.exec(e);if(t)return Wa(decodeURIComponent(t[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return si("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return si("email","mail")}return e==="#/settings/email"?ll("email","settings"):{"#/overview":Vt,"#/approvals":Vt,"#/events":`${dt}/events`,"#/jobs":`${dt}/jobs`,"#/conversations":dt,"#/missions":`${gt}?tab=missions`,"#/offers":`${gt}?tab=offers`,"#/reminders":`${gt}?tab=reminders`,"#/providers":Be("accounts"),"#/browser":Be("computer"),"#/sentinels":Be("watchers"),"#/settings/sentinels":Be("watchers")}[e]??null}function XN(e){if(e===""||e==="#"||e===Vt)return Vt;if(e.startsWith(Yr))return Yr;if(e.startsWith(gt))return gt;if(e.startsWith(dt))return dt;if(e.startsWith(_i))return _i;if(e.startsWith(cn))return cn;const t=Sx(e);return t?si(t.plugin,t.page):Vt}const pD="#/chat?group=new";function gD(e){const t=e.replace(/^#\/?/,"").split("?")[0].toLowerCase();if(t==="")return"home";const[s,r]=t.split("/");return!s||!/^[a-z0-9-]+$/.test(s)?null:(s==="settings"||s==="p")&&r&&/^[a-z0-9.-]+$/.test(r)?`${s}/${r}`:s}const Nx="front-desk",Cx=[{id:Nx,label:"Front desk",meaning:"Where things go when you do not say who."},{id:"overview",label:"Overview",meaning:"Answers /status and speaks for the watchers."},{id:"recap",label:"Recap",meaning:"Runs /recap."},{id:"maker",label:"Maker",meaning:"/new opens its interview."}],ZN=new Set(Cx.map(e=>e.id)),qy=e=>ZN.has(e);function Qy(e,t){const s=t.filter(r=>!ZN.has(r));return[...Cx.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,i)=>s.indexOf(r)===i)]}function xD(e,t){return e.find(s=>(s.roles??[]).includes(t))}const Jy=["coding","finance","mail","research","calendar","files","memory"],vD={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[Nx]:"buddi"},jD=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function yD(e){const t=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of jD)if(r.some(i=>t.has(i)))return s;return t.size>0&&[...t].every(s=>s==="memory")?"memory":null}let Zm=null;function wD(e){Zm=e}function Ko(e){if(e.accent&&/^#[0-9a-fA-F]{6}$/.test(e.accent))return{key:"own",hex:e.accent.toLowerCase()};for(const s of e.roles??[]){const r=vD[s];if(r)return{key:r}}const t=yD(e.tools??[]);return t?{key:t}:Zm!==null&&e.id===Zm?{key:"buddi"}:{key:Jy[bD(e.id)%Jy.length]??"coding"}}function Vo(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function bD(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t}const kD=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","live","live.settle","live.snapshot","attention","ping"];function SD(e){const s=e.replace(/\r\n/g,`
|
|
82
|
+
`).split(`
|
|
83
|
+
|
|
84
|
+
`),r=s.pop()??"",i=[];for(const a of s){let l=null,o="message";const c=[];for(const u of a.split(`
|
|
85
|
+
`)){if(u===""||u.startsWith(":"))continue;const d=u.indexOf(":"),h=d===-1?u:u.slice(0,d),m=d===-1?"":u.slice(d+1).replace(/^ /,"");h==="id"?l=m:h==="event"?o=m:h==="data"&&c.push(m)}c.length===0&&o==="message"||i.push({id:l,name:kD.includes(o)?o:"ping",data:ND(c.join(`
|
|
86
|
+
`))})}return{events:i,rest:r}}function ND(e){if(e==="")return{};try{const t=JSON.parse(e);return t!==null&&typeof t=="object"?t:{value:t}}catch{return{value:e}}}function Jd(e){const t=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(d=>setTimeout(d,u))),r=e.retryMs??1500;let i=e.lastEventId??null,a=!1,l=!1,o=null;return(async()=>{var u,d,h,m,p;for(;!a;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const g=await t(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...i===null?{}:{"Last-Event-ID":i}}});if(!g.ok||!g.body)throw new Error(`stream ${g.status}`);(d=e.onStatus)==null||d.call(e,"open"),l&&((h=e.onReconnect)==null||h.call(e));const y=g.body.getReader(),b=new TextDecoder;let x="";for(;;){const{done:v,value:j}=await y.read();if(v)break;x+=b.decode(j,{stream:!0});const{events:w,rest:S}=SD(x);x=S;for(const k of w)e.onEvent(k),k.id!==null&&(i=k.id);if(a)break}}catch{}if(a)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{a=!0,o==null||o.abort()},lastEventId:()=>i}}const Ex="0.1.0+ae364ce";function Ax(e,t=Ex){return typeof e=="string"&&e!==""&&typeof t=="string"&&t!==""&&e!==t}function CD(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const ED=5*6e4,AD=6e4,TD=5e3,ep="buddi:stream-reconnected",e1="buddi.autoReloadedFor";function RD(){window.dispatchEvent(new Event(ep))}const Xy=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let Tx=Date.now(),Mc=0;const Zy=()=>{Tx=Date.now()};function ID(){if(Mc===0){Tx=Date.now();for(const e of Xy)window.addEventListener(e,Zy,{capture:!0,passive:!0})}return Mc+=1,()=>{if(Mc-=1,Mc===0)for(const e of Xy)window.removeEventListener(e,Zy,{capture:!0})}}function PD(e=Date.now()){return e-Tx}function $D(e=document){return e.querySelector('.wb-composer[data-busy="true"]')!==null||e.querySelector('.wb-listening, [data-recording="true"]')!==null||e.querySelector('[role="dialog"], [role="alertdialog"], dialog[open]')!==null}function MD(e){return e.hidden?!0:e.idleMs>=AD&&!e.busy}function OD(e){try{return window.sessionStorage.getItem(e1)===e}catch{return!1}}function DD(e){try{window.sessionStorage.setItem(e1,e)}catch{}}function _D(e){const t=f.useRef(e);t.current=e,f.useEffect(()=>{const s=()=>t.current();return window.addEventListener(ep,s),()=>window.removeEventListener(ep,s)},[])}function LD(e,t=()=>window.location.reload(),s=Ex){const r=Ax(e,s),i=f.useRef(t);i.current=t,f.useEffect(()=>ID(),[]),f.useEffect(()=>{if(!r||e===void 0||OD(e))return;let a=!1;const l=()=>{if(a)return;const c=document.visibilityState==="hidden";MD({hidden:c,idleMs:PD(),busy:$D()})&&(a=!0,DD(e),i.current())};l();const o=window.setInterval(l,TD);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const FD="/api/chat/attention/stream";function t1(e,t){const s=(a,l)=>a.name.localeCompare(l.name),r=a=>e.filter(l=>l.anchor===a).sort(s),i=e.filter(a=>a.anchor!=="top"&&a.anchor!=="bottom").sort((a,l)=>a.id===t?l.id===t?0:-1:l.id===t?1:s(a,l));return{top:r("top"),middle:i,bottom:r("bottom")}}function n1(e,t){const s=t1(e,t);return[...s.top,...s.middle,...s.bottom]}function Xd(e){if(!e)return null;const t=[];return e.approvals>0&&t.push(e.approvals===1?"one approval is waiting for you":`${e.approvals} approvals are waiting for you`),e.question&&t.push("asked you a question and is holding for the answer"),t.length===0?null:t.join(", and ")}function zD(e){if(!e)return null;const t=e.approvals,s=t===1?"1 approval":`${t} approvals`;return t>0&&e.question?`${s} and a question`:t>0?`${s} waiting`:e.question?"Has a question":null}function UD(e,t){return e&&(e.approvals>0||e.question)?"needs":t?"working":null}function BD(e){return new Map(((e==null?void 0:e.agents)??[]).map(t=>[t.agentId,t]))}function WD(){const[e,t]=f.useState(null);return f.useEffect(()=>{let s=!1;const r=()=>{fe("/chat/attention").then(a=>{s||t(a)}).catch(()=>{})};r();const i=Jd({url:FD,onEvent:()=>r(),onReconnect:RD});return()=>{s=!0,i.close()}},[]),BD(e)}const Zd="maker";function s1(e){return e.filter(t=>t.available&&!t.roles.includes(Zd))}function r1(e){return s1(e).length>=2}function HD(e){var t;return((t=e.find(s=>s.roles.includes(Zd)))==null?void 0:t.name)??"the agent maker"}const KD="{{default}}";function VD(e,t){return e.split(KD).join(t??"your assistant")}function GD(e,t){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>VD(s,t))}function YD(e){var s,r;const t=(s=e==null?void 0:e.intro)==null?void 0:s.trim();return t&&t!==""?t:((r=e==null?void 0:e.description)==null?void 0:r.trim())??""}function qD(e){const t=(e??"·").trim().split(/\s+/).filter(Boolean);return t.length===0?"·":t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[1][0]).toUpperCase()}function i1(e){var r,i;const t=(r=e.heldBack)==null?void 0:r.message.trim();if(t!==void 0&&t!=="")return`${e.name??"This agent"} is held back. ${t}`;const s=(i=e.unavailableReason)==null?void 0:i.trim();return s&&s!==""?`${e.name??"This agent"} cannot run: ${s}`:`${e.name??"This agent"} cannot run: it has no model account yet.`}const QD="Settings → Model accounts",JD="Install it in Settings → Plugins";function tp(e){return e!=null&&e.heldBack?{section:"plugins",label:JD}:{section:"accounts",label:QD}}const XD={home:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),n.jsx("path",{d:"M5.2 8.4v7.4a1 1 0 0 0 1 1h2.6v-4.6h2.4v4.6h2.6a1 1 0 0 0 1-1V8.4"})]})],chat:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M17 10.6a4.9 4.9 0 0 1-4.9 4.9H7.8L3.6 18l.9-3A4.9 4.9 0 0 1 3 11V8.2A4.9 4.9 0 0 1 7.9 3.3h4.2A4.9 4.9 0 0 1 17 8.2Z"}),n.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),n.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),n.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),n.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,n.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),n.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.5 2.8h5.2L16.5 6.6v8.6a1.2 1.2 0 0 1-1.2 1.2H7.5a1.2 1.2 0 0 1-1.2-1.2V4a1.2 1.2 0 0 1 1.2-1.2z"}),n.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),n.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),n.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),n.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),n.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,n.jsx("path",{d:"M3.2 16.4V8.6M8.4 16.4V3.9M13.6 16.4v-5.8M3.2 16.4h13.6"})],bell:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),n.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),n.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),n.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),n.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),n.jsx("path",{d:"M2.9 10h14.2M10 2.9c3.4 3.7 3.4 10.5 0 14.2-3.4-3.7-3.4-10.5 0-14.2Z"})]})],terminal:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),n.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),n.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],sun:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),n.jsx("path",{d:"M10 2.6v1.6M10 15.8v1.6M2.6 10h1.6M15.8 10h1.6M4.8 4.8l1.1 1.1M14.1 14.1l1.1 1.1M4.8 15.2l1.1-1.1M14.1 5.9l1.1-1.1"})]})],notebook:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M5.5 3.2h8.3a1 1 0 0 1 1 1v11.6a1 1 0 0 1-1 1H5.5a1 1 0 0 1-1-1V4.2a1 1 0 0 1 1-1Z"}),n.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),n.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),n.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],eye:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.4 10S5.2 4.8 10 4.8 17.6 10 17.6 10 14.8 15.2 10 15.2 2.4 10 2.4 10Z"}),n.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),n.jsx("path",{d:"M4 7.2v8a1.2 1.2 0 0 0 1.2 1.2h9.6a1.2 1.2 0 0 0 1.2-1.2v-8M8.2 10.4h3.6"})]})],chip:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),n.jsx("path",{d:"M8 2.8v2.6M12 2.8v2.6M8 14.6v2.6M12 14.6v2.6M2.8 8h2.6M2.8 12h2.6M14.6 8h2.6M14.6 12h2.6"})]})],"partly-cloudy":[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),n.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),n.jsx("path",{d:"M7.8 16.8h6.4a2.9 2.9 0 0 0 .3-5.8 4 4 0 0 0-7.6 1.1 2.4 2.4 0 0 0 .9 4.7Z"})]})],cloud:[20,1.6,n.jsx("path",{d:"M6 15.6h8.2a3.3 3.3 0 0 0 .4-6.6 4.6 4.6 0 0 0-8.9 1A2.8 2.8 0 0 0 6 15.6Z"})],rain:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M6 12.2h8.2a3 3 0 0 0 .4-6 4.3 4.3 0 0 0-8.3.9A2.6 2.6 0 0 0 6 12.2Z"}),n.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,n.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,n.jsx("path",{d:"M3 8h9.4a2.2 2.2 0 1 0-2.2-2.2M3 12h11.6a2.2 2.2 0 1 1-2.2 2.2M3 10h5.4"})],"moon-clear":[20,1.6,n.jsx("path",{d:"M15.8 12.2A6.2 6.2 0 0 1 7.8 4.2a6.2 6.2 0 1 0 8 8Z"})],dot:[20,1.6,n.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.6 6.2a1.4 1.4 0 0 1 1.4-1.4h2l1.1-1.6h2.8l1.1 1.6h2a1.4 1.4 0 0 1 1.4 1.4v6.4a1.4 1.4 0 0 1-1.4 1.4H4a1.4 1.4 0 0 1-1.4-1.4z"}),n.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,n.jsx("path",{d:"M13.2 8 8.4 12.8a3 3 0 0 1-4.2-4.2l5.1-5.1a2 2 0 1 1 2.8 2.8l-5 5"})],mic:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),n.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),n.jsx("path",{d:"M11.2 6.2a3.2 3.2 0 0 1 0 4.6M13.2 4.4a5.8 5.8 0 0 1 0 8.2"})]})],send:[16,1.8,n.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,n.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,n.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],thought:[13,1.4,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),n.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,n.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],copy:[16,1.5,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),n.jsx("path",{d:"M10.4 5.6V4a1.2 1.2 0 0 0-1.2-1.2H4A1.2 1.2 0 0 0 2.8 4v5.2A1.2 1.2 0 0 0 4 10.4h1.6"})]})],play:[16,1.5,n.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,n.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,n.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,n.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),n.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],"chevron-left":[14,1.6,n.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,n.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,n.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],more:[16,0,n.jsxs("g",{fill:"currentColor",stroke:"none",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})],folder:[20,1.6,n.jsx("path",{d:"M2.8 5.6a1.4 1.4 0 0 1 1.4-1.4h3.4l1.7 1.9h6.5a1.4 1.4 0 0 1 1.4 1.4v7.3a1.4 1.4 0 0 1-1.4 1.4H4.2a1.4 1.4 0 0 1-1.4-1.4Z"})],"chevron-down":[14,1.4,n.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),n.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),n.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,n.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,n.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,n.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,n.jsx("path",{d:"M2.6 4.6h4M9.4 4.6h4M2.6 8h4M9.4 8h4M2.6 11.4h4M9.4 11.4h4"})],"shape-tiles":[16,1.4,n.jsx("path",{d:"M2.4 3.4h4.8v4.2H2.4zM8.8 3.4h4.8v4.2H8.8zM2.4 9.2h4.8v4.2H2.4zM8.8 9.2h4.8v4.2H8.8z"})],"shape-document":[16,1.4,n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,n.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 11l3.6-3.4 2.6 2.4 2-1.8 3.4 3M10.6 6.2h.01"})],"shape-preview":[16,1.4,n.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM2.2 6h11.6M4.1 4.7h.01M6 4.7h.01"})],"shape-envelope":[16,1.4,n.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,n.jsx("path",{d:"M12.9 9.7A5.3 5.3 0 0 1 6.3 3.1a5.3 5.3 0 1 0 6.6 6.6z"})],"shape-structured":[16,1.4,n.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function ye({name:e,size:t,className:s,...r}){const[i,a,l,o]=XD[e],c=t??o??i;return n.jsx("svg",{className:s,width:c,height:c,viewBox:`0 0 ${i} ${i}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:a,strokeLinecap:"round",strokeLinejoin:"round","data-icon":e,...r,children:l})}const a1="buddi.rosterCollapsed";function ZD(){try{return window.localStorage.getItem(a1)==="1"}catch{return!1}}function e_(e){try{window.localStorage.setItem(a1,e?"1":"0")}catch{}}function l1({agents:e,currentId:t,attention:s,onSelect:r,orientation:i="vertical",lastActivity:a,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:d}){const h=[...e.top,...e.middle,...e.bottom],m=i==="vertical"?"right":"bottom",[p,g]=f.useState(ZD),y=b=>n.jsx(t_,{agent:b,active:b.id===t,attention:s.get(b.id),side:m,onSelect:r,lastAt:(a==null?void 0:a.get(b.id))??null,working:(l==null?void 0:l.has(b.id))??!1},b.id);return n.jsxs("nav",{className:i==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":i==="vertical"&&p?"true":void 0,children:[e.top.map(y),e.top.length>0&&e.middle.length>0?n.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,i==="vertical"&&!p&&e.middle.length>0?n.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,n.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(y),u&&r1(h)?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsxs("div",{className:"wb-groups-head",children:[n.jsx("span",{className:"wb-groups-label",children:"Groups"}),d?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:d,children:n.jsx(ye,{name:"plus"})}):null]}),o.map(b=>n.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":b.id===c?"true":void 0,"aria-current":b.id===c?"true":void 0,"aria-label":`${b.name}, ${b.members.length} agents`,onClick:()=>u(b.id),children:[n.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:b.members.slice(0,2).map(x=>{const v=h.find(j=>j.id===x);return n.jsx(Rx,{className:"wb-group-chip",id:x,name:(v==null?void 0:v.name)??"?",face:v,initials:1},x)})}),n.jsxs("span",{className:"wb-face-text",children:[n.jsx("span",{className:"wb-face-name",children:b.name}),n.jsx("span",{className:"wb-face-status",children:b.members.map(x=>{var v;return((v=h.find(j=>j.id===x))==null?void 0:v.name)??x}).join(", ")})]})]},b.id))]}):u?n.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[n.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),n.jsx("div",{className:"wb-groups-head",children:n.jsx("span",{className:"wb-groups-label",children:"Groups"})}),n.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",n.jsx("a",{href:gt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(y),i==="vertical"?n.jsx("button",{type:"button",className:"ui-icon-btn wb-roster-toggle","data-size":"sm","aria-label":p?"Show agent names":"Hide agent names","aria-pressed":p,onClick:()=>g(b=>(e_(!b),!b)),children:n.jsx(ye,{name:p?"chevron-right":"chevron-left"})}):null]})}function t_({agent:e,active:t,attention:s,side:r,onSelect:i,lastAt:a=null,working:l=!1}){const o=Xd(s),c=zD(s)??(e.available?a?LO(a):e.description:e.unavailableReason??"Cannot run right now"),u=UD(s,l&&e.available),d=e.unavailableReason??"This agent cannot run on this machine right now.",h=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,t?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("button",{className:"wb-face",...Vo(Ko(e)),"data-active":t?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":h,"aria-current":t?"true":void 0,disabled:!e.available,onClick:()=>e.available&&i(e.id),children:[n.jsxs("span",{className:"wb-face-frame",children:[n.jsx(Rx,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),u?n.jsx("span",{className:"wb-face-dot","data-state":u,"data-testid":`agent-dot-${e.id}`,"aria-hidden":"true"}):null]}),n.jsxs("span",{className:"wb-face-text","aria-hidden":"true",children:[n.jsx("span",{className:"wb-face-name",children:e.name}),n.jsx("span",{className:"wb-face-status","data-tone":o?"critical":void 0,children:c})]}),e.available?null:n.jsx("span",{className:"wb-face-out","aria-hidden":"true",children:n.jsx(ye,{name:"out"})})]})}),n.jsx(bo,{children:n.jsxs(ko,{className:"ui-tip",side:r,sideOffset:8,children:[n.jsx("span",{className:"ui-tip-title",children:e.name}),n.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:d}),o?n.jsx("span",{className:"ui-tip-alert",children:n_(o)}):null]})})]})}function n_(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function s_(e){let t=0;for(const s of e)t=(t*31+s.charCodeAt(0))%997;return t%6+1}const r_="modulepreload",i_=function(e,t){return new URL(e,t).href},ew={},a_=function(t,s,r){let i=Promise.resolve();if(s&&s.length>0){const l=document.getElementsByTagName("link"),o=document.querySelector("meta[property=csp-nonce]"),c=(o==null?void 0:o.nonce)||(o==null?void 0:o.getAttribute("nonce"));i=Promise.allSettled(s.map(u=>{if(u=i_(u,r),u in ew)return;ew[u]=!0;const d=u.endsWith(".css"),h=d?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const y=l[g];if(y.href===u&&(!d||y.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${h}`))return;const p=document.createElement("link");if(p.rel=d?"stylesheet":r_,d||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),d)return new Promise((g,y)=>{p.addEventListener("load",g),p.addEventListener("error",()=>y(new Error(`Unable to preload CSS for ${u}`)))})}))}function a(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return i.then(l=>{for(const o of l||[])o.status==="rejected"&&a(o.reason);return t().catch(a)})},l_="buddi",o_=["core","coding","finance","garage","mail","maker","playground","research"],Yi=e=>`./mascot/${e}.png`,c_=["core"],np=(e,t)=>c_.includes(e)?`./mascot/anim/${e}-${t}.json`:null,u_=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],d_="Introduce yourself by name and say one thing you can do today.",h_=["Hello","A brain","What I take on","Reach me","Your assistant"],El=(e,t=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${t&&e.length>2?", and ":" and "}${e[e.length-1]}`,ef=e=>e.charAt(0).toUpperCase()+e.slice(1),f_=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],Ra=[{id:"days",title:"My days",plugins:"Weather · Calendar",line:"Weather and your calendars. A morning brief from Planner.",mate:"Planner",note:"Weather needs nothing. Calendar asks for your calendar’s private link later, on its own page."},{id:"mail",title:"My mail",plugins:"Mail Triage (built in)",line:"Mail Triage reads new mail and brings you only what needs you.",mate:"Mail Triage",note:"Mail asks for a mailbox in chapter 4."},{id:"money",title:"My money",plugins:"Finance",line:"Accounts, cards and cash flow. Ledger answers “can I afford this?”.",mate:"Ledger",note:"Finance asks for your bank on its own page."},{id:"voice",title:"Voice",plugins:"Speech",line:"Talk to me and hear me back, here and on your phone. Runs on this computer.",note:"Speech needs nothing."},{id:"code",title:"My code",plugins:"Developer",line:"Developer works in one folder you name, and shows you what it changed.",mate:"Developer",note:"Developer asks for its folder the first time you talk."},{id:"pictures",title:"Pictures",plugins:"Image",line:"Illustrator makes one image from a prompt, with an account you pick.",mate:"Illustrator",note:"Image asks which account to draw with."}],m_=["days","mail"],tw=[{id:"buddi",role:"core",label:"Blue"},{id:"mail",role:"mail",label:"Orange"},{id:"finance",role:"finance",label:"Green"},{id:"coding",role:"coding",label:"Violet"},{id:"research",role:"research",label:"Purple"}],P={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:h_,mapNotes:["Two minutes. Everything can be changed later in Settings, and nothing leaves this computer until you say so.","One line decides which company sees your assistant’s conversations. You can add more brains later and give each agent its own.","Each choice installs a plugin from withbuddi.com and proposes an agent for it. Only plugins made by buddi are installed for you; you can remove any of them later.","All three are optional. The mailbox is what “My mail” needs; the phone is how I reach you when you are away.","The persona is a plain text file the assistant grows over time. Keep it, rewrite it, or let Agent Father write one after an interview."],count:e=>`Chapter ${e} of 5`,back:"Back",change:"change",later:"Set up later",startOver:{link:"Start over",said:e=>`Starting again. What you already connected stays in Settings: ${e}.`,telegram:"Telegram",browser:"the browser"},strip:(e,t)=>`${e} · ${t}`,hello:{title:"Hi. I’m buddi.",opening:["I live on this computer and I’m about to introduce you to your first assistant. Nothing you tell me leaves this machine, except what your assistant sends to the AI you pick next.","First, what should we call you, and what time is it where you are?"],foot:"Your agents use your name in every reply, and your clock for reminders and the morning brief.",submit:"That’s me",answer:e=>e},name:{label:"Your first name",placeholder:"Sam"},clock:{label:"Your clock",hint:e=>`What this browser says. ${e} right now.`,change:"Change"},brain:{title:"Which AI should your team think with?",ask:"Pick what you already have. I test it with one small call before we go on.",submit:"Use this brain",cards:{free:{title:"Free to start, no key",line:"Ollama Cloud, one tap. Good enough to meet your assistant today.",pill:"Recommended to begin"},claude:{title:"I pay for Claude",line:"Sign in with your Claude account. Uses its extra usage."},chatgpt:{title:"I pay for ChatGPT",line:"Sign in with a code on openai.com. Uses your plan."},key:{title:"I have an API key",line:"Anthropic, OpenAI, Google AI, or another service with an address."},local:{title:"On this computer",line:"Free and private. Looking on this computer…"}},keyKinds:{label:"Which key",key:"Anthropic or OpenAI",gemini:"Google AI",service:"Another service"},claude:{label:"Claude",start:"Sign in with Claude",open:"Open the Claude sign-in page",paste:"Paste what Claude gave you",finish:"Done",waiting:"Sign in on the claude.ai page that just opened, then paste the code Claude shows you."},chatgpt:{label:"ChatGPT",codeBefore:"Here is your code: ",codeAfter:". Type it on the openai.com page that just opened and approve buddi. I’ll notice.",code:"Your code",open:"Open openai.com",again:"Try again",failed:"The sign-in did not finish. Try again."},cloud:{label:"Ollama Cloud",waiting:"Press Connect on the ollama.com page that just opened. Sign in there first if it asks. I’ll notice.",open:"Open the ollama.com page",again:"Try again"},gemini:{label:"Gemini",field:"Your Google AI key",placeholder:"Paste it here",submit:"Use this key",get:"Get a key at aistudio.google.com"},key:{field:"Your key",placeholder:"Paste it here",hint:"I can tell which AI it belongs to from the key. It stays on this computer.",submit:"Use this key",which:"Not right?",anthropic:"Anthropic",openai:"OpenAI",refused:"That key was refused. Check it and paste it again."},local:{looking:"Free and private. Looking on this computer…",found:e=>{const t=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${t(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${t(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Nothing local answered; Ollama or mlxh, once installed, shows here."},mlxh:{label:"mlxh",connect:"Use mlxh",noBrain:"mlxh has no language model installed. Pull one with `mlxh pull`, then come back."},ollama:{label:"Ollama",connect:"Use Ollama",download:"Get Ollama"},model:{ask:"Which one should it think with?",label:"The model",submit:"Use this one",retry:"Try again",change:"Think with another"},checking:{key:"Checking that key…",service:"Asking the service…",ollama:"Asking the first model one small question. It can take a minute.",cloud:"Asking Ollama Cloud…",claude:"Checking with Claude…",chatgpt:"Asking ChatGPT…",gemini:"Asking Gemini…"},service:{label:"Another service",address:"Address",addressPlaceholder:"The address they gave you",key:"Key",submit:"Connect it"},works:e=>`That works. Your assistant will think with ${e}.`,worksOnFlash:e=>`That works. Google's free tier has no Pro allowance, so your assistant will think with ${e}; turn on billing at Google to use Pro.`,answer:e=>e},takeOn:{title:"What should I take on for you?",ask:"Pick a few. Each one brings a plugin and, for some, a teammate who owns that job. Skip this and I stay a plain assistant; you can add any of it later.",submit:"Take these on",none:"Just an assistant for now",nothing:"Nothing picked. I’ll be a plain assistant, and Home will offer these again.",builtIn:"Mail is built in.",nothingToFetch:"Nothing to fetch.",fetching:(e,t,s)=>`Fetching ${El(e)} from withbuddi.com and reading them. ${t} of ${s}.`,ready:e=>`${El(e)} ${e.length>1?"are":"is"} in, read and ready.`,failed:(e,t)=>`${e} did not come: ${t}.`,installing:(e,t)=>`Installing, ${e} of ${t} ready`,installed:"Installed",answer:e=>e.length===0?"Just an assistant":ef(e.join(", ").toLowerCase())},reach:{title:"How do we reach each other?",ask:"Three things, each a minute. Do the ones you want; the rest wait in Settings.",submit:"Continue",phone:{title:"Your phone, through Telegram",line:"Scan the code with your phone and press Start. Approvals, voice notes and the morning brief land there.",setUp:"Set up Telegram",paired:"Paired",hello:"✓ That is your phone, talking to me. Approvals reach you there from now on."},mailbox:{title:"A mailbox",forTriage:"A mailbox, for Mail Triage",line:"Gmail, iCloud, Fastmail or any IMAP account. Reading only; sending always stops at a card you approve.",add:"Add a mailbox",sheet:"Add a mailbox",added:"Mailbox added",unavailable:"Mail is not ready on this computer yet. Settings → Mail can add one later."},app:{title:"buddi as an app, and a browser of its own",line:"Keep buddi in your Dock; give your assistant Chrome or its own Chromium (150 MB) so it can look at websites.",install:"Install app",installed:"App installed",chrome:"Use Chrome",chromium:"Use its Chromium",fetch:"Fetch a browser",ready:e=>e==="chrome"?"Chrome, ready":"Chromium, ready"},answer:e=>e.length===0?"Later, in Settings":ef(e.join(", ")),done:{phone:"phone paired",mailbox:"mailbox added",app:"app and browser"}},browser:{chrome:"Your assistant will browse with Google Chrome.",chromium:"Your assistant will browse with its own Chromium.",needs:"Your assistant needs a browser of its own to look at websites. I am fetching one now, about 150 MB.",installing:"Fetching the browser…",launching:"Making sure it opens…",installed:"Installed.",failed:e=>`That did not work: ${e}`,retry:"Try again"},telegram:{sheet:"Your phone, through Telegram",how:"Two minutes: open Telegram, message @BotFather, send /newbot, paste the token it gives you here.",field:"The token",submit:"Save it",restart:"Saved. It will be ready the next time buddi starts.",scan:"Scan this with your phone and press Start.",expired:"That code has run out. I can make you another one.",newCode:"Show a new code",paired:"That is your phone, talking to me. You can close this and carry on.",close:"Done",notNow:"Not now"},assistant:{title:"Meet your assistant.",ask:"I’ve picked a name, a face and a way of working. Change any of it, or keep them.",team:e=>` Your team so far: ${El(e)}, waiting to be introduced.`,name:"Name",face:"A face",colour:"A colour for the face",swatch:e=>`Colour: ${e.toLowerCase()}`,mascot:e=>e==="core"?"Buddi Blob":`Buddi Blob, ${e}`,purpose:"How it works",purposeHint:"Plain text. It becomes the assistant’s file, which is yours from then on.",purposeValue:["You're not a chatbot. You're becoming someone this person can count on.","","Some starting truths:","",`- Help for real. No "Great question", no "I'd be happy to". Do the thing, then say what you did.`,"- Have a view. Prefer things, disagree when you should, say when something is a bad idea. A search engine with manners is not a colleague.","- Look before you ask. Read the file, check what you remember, try it. Come back with an answer and one question at most.","- You are a guest here. You can see messages, files and a calendar. Treat that with care, keep what you learn to yourself, and never lecture.","- Remember what matters. Names, preferences, the things they said once and expect you to keep.","- When you change how you work, say so. This file is yours to grow, and the owner should always know what it says."].join(`
|
|
87
|
+
`),submit:"Introduce us"},restore:{offer:"I have a backup",sheet:"Restore from a backup",lede:"Pick the backup file buddi made and type its passphrase. Your agents, memory and settings come back as they were; this chapter map is skipped.",file:"Backup file",passphrase:"Passphrase",passphraseHint:"The one you typed when you turned backups on, if it was locked with one. I can’t recover it.",submit:"Restore",cancel:"Never mind",title:"Bringing your buddi back.",started:"Right. Give me a couple of minutes.",phases:{stopping:"Putting everything down for a moment.",snapshot:"Keeping a copy of what is here now, just in case.",database:"Bringing back your conversations and everything you told it to remember.",recovery:"Almost there. Nothing will run on its own until you say so.",files:"Bringing back your files.",starting:"Starting back up.",done:"That is everything.","rolled-back":"That did not work, so I put everything back the way it was.",failed:"That did not work."},welcome:e=>`Welcome back, ${e}.`,keys:"A backup never carries keys, so the AI you think with needs its key one more time."},handover:{waiting:"One moment.",looking:e=>`${e} is looking around…`,slow:"Still waking up. A brain on this computer takes a minute the first time.",silent:"Your assistant isn't answering. The AI you picked may be down; try again, or pick another brain.",again:"Pick another brain",starters:(e,t)=>[e.days?"What’s my day like?":"What can you do?",t.length>0?`Meet ${El(t)}`:"Show me around",e.days?"Link my calendar":e.mail&&!e.mailbox?"Add my mailbox":"What do you know about me?","Remind me at 9 tomorrow"],starterLabel:"Ask first",waitingTitle:e=>`${f_[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${ef(El(e,!0))}. ${e.length>1?e.length===2?"Both are":"They are all":"It’s"} on Home whenever you like.`,home:"Open Home"},done:{open:"Open buddi"}};let Oc=null;const nw=new Map;function p_(){return Oc??(Oc=a_(()=>import("./lottie_light-DmJaDM4A.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),Oc.catch(()=>{Oc=null}),Oc}function g_(e){let t=nw.get(e);return t||(t=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),nw.set(e,t)),t}const sw="(prefers-reduced-motion: reduce)";function o1(){const[e,t]=f.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(sw).matches);return f.useEffect(()=>{var i;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(sw),r=()=>t(!s.matches);return(i=s.addEventListener)==null||i.call(s,"change",r),()=>{var a;return(a=s.removeEventListener)==null?void 0:a.call(s,"change",r)}},[]),e}function eh({role:e="core",state:t,size:s,still:r,className:i,onStillError:a}){const l=f.useRef(null),o=o1(),[c,u]=f.useState(!1),d=s==="xs"?null:np(e,t);return f.useEffect(()=>{if(u(!1),!o||!d)return;let h=!1,m=null;return Promise.all([p_(),g_(d)]).then(([p,g])=>{if(h||!g||!l.current)return;const y=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),b=()=>{document.hidden?y.pause():y.play()};document.addEventListener("visibilitychange",b),m=()=>{document.removeEventListener("visibilitychange",b),y.destroy()},u(!0)}).catch(()=>{}),()=>{h=!0,m==null||m()}},[o,d]),n.jsx("span",{ref:l,className:i?`ui-blob ${i}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":t,"aria-hidden":"true",children:c?null:n.jsx("img",{src:r??Yi(e),alt:"",onError:a})})}async function rw(e){const t=new Image;t.src=e,await t.decode();const s=document.createElement("canvas");s.width=8,s.height=8;const r=s.getContext("2d");return r?(r.fillStyle="#fff",r.fillRect(0,0,8,8),r.drawImage(t,0,0,8,8),Array.from(r.getImageData(0,0,8,8).data)):null}function c1(e,t="core"){const s=o1(),r=e!==null&&x_(e,t),[i,a]=f.useState(!1);return f.useEffect(()=>{if(a(!1),!e||r||!s||!np(t,"idle"))return;let l=!1;return Promise.all([rw(e),rw(Yi(t))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((d,h,m)=>d+Math.abs(h-c[m]),0)/o.length;a(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,t]),s&&np(t,"idle")!==null&&(r||i)}function x_(e,t){const s=Yi(t);if(e===s)return!0;try{const r=typeof window>"u"?"http://localhost/":window.location.href;return new URL(e,r).href===new URL(s,r).href}catch{return!1}}function Rx({className:e,id:t,name:s,face:r,tint:i,size:a,unavailable:l,initials:o=2}){const[c,u]=f.useState(null),d=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,h=r==null?void 0:r.avatar,m=d?"image":h==null?void 0:h.kind,p=t?Vo(Ko({id:t,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return n.jsx("span",{className:e,"data-tint":p?void 0:i,"data-size":a,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:d?n.jsx("img",{src:d,alt:"",onError:()=>u(d)}):(h==null?void 0:h.kind)==="image"?n.jsx("img",{src:h.url,alt:""}):(h==null?void 0:h.kind)==="emoji"?h.value:qD(s).slice(0,o)})}function Es({id:e,name:t,size:s,unavailable:r,face:i}){return n.jsx(Rx,{className:"ui-avatar",id:e,tint:s_(e),name:t,size:s,unavailable:r,face:i})}function Nn({agents:e,id:t,size:s}){const r=e.find(i=>i.id===t);return n.jsx(Es,{id:t,name:(r==null?void 0:r.name)??t,size:s,unavailable:r?!r.available:!1,face:r})}const u1=f.createContext(null);function v_({picture:e,children:t}){return n.jsx(u1.Provider,{value:e??null,children:t})}function sp({size:e,anim:t}){const s=f.useContext(u1),[r,i]=f.useState(null),a=c1(t?s:null);return!s||s===r?null:n.jsx("span",{className:"ui-mascot","data-size":e,"data-testid":"mascot","aria-hidden":"true",children:t&&a?n.jsx(eh,{state:t,still:s,className:"ui-mascot-blob",onStillError:()=>i(s)}):n.jsx("img",{src:s,alt:"",onError:()=>i(s)})})}const d1=f.createContext([]);function gr({text:e,className:t}){const s=rp(e.replace(/\r\n/g,`
|
|
88
|
+
`).split(`
|
|
89
|
+
`));return n.jsx("div",{className:t??"wb-md",children:s.map((r,i)=>n.jsx(ip,{block:r},i))})}const iw=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,aw=/^(#{1,6})\s+(.*?)\s*#*\s*$/,lw=/^\s*([-*_])(\s*\1){2,}\s*$/,Dc=/^(\s*)([-*+])\s+(.*)$/,Al=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,_c=/^\s*>\s?(.*)$/,tf=/^\s*\|.*\|\s*$/,ow=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function rp(e){const t=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const i=iw.exec(r);if(i){const o=i[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,t.push({type:"code",lang:i[3]||null,text:c.join(`
|
|
90
|
+
`)});continue}const a=aw.exec(r);if(a){t.push({type:"h",level:a[1].length,text:a[2]}),s+=1;continue}if(lw.test(r)){t.push({type:"hr"}),s+=1;continue}if(_c.test(r)){const o=[];for(;s<e.length&&_c.test(e[s]);)o.push(_c.exec(e[s])[1]),s+=1;t.push({type:"quote",blocks:rp(o),raw:o.join(`
|
|
91
|
+
`)});continue}if(tf.test(r)&&s+1<e.length&&ow.test(e[s+1])){const o=sf(r),c=sf(e[s+1]).map(d=>{const h=d.startsWith(":"),m=d.endsWith(":");return h&&m?"center":m?"right":h?"left":null});s+=2;const u=[];for(;s<e.length&&tf.test(e[s]);)u.push(sf(e[s])),s+=1;t.push({type:"table",head:o,rows:u,align:c});continue}if(Dc.test(r)||Al.test(r)){const o=Al.exec(r)??Dc.exec(r),c=Al.test(r),u=o[1].length,d=c?Number(o[2]):1,h=[];for(;s<e.length;){const m=c?Al.exec(e[s]):Dc.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],y=g.trim()!==""&&nf(g)>u,b=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&nf(e[s+1])>u;if(!y&&!b)break;p.push(g.trim()===""?"":g.slice(Math.min(nf(g),u+2))),s+=1}h.push(rp(p))}t.push({type:"list",ordered:c,start:d,items:h});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||iw.test(o)||aw.test(o)||lw.test(o)||_c.test(o)||Dc.test(o)||Al.test(o)||tf.test(o)&&s+1<e.length&&ow.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&t.push({type:"p",text:l.join(`
|
|
92
|
+
`)})}return t}function nf(e){return e.length-e.trimStart().length}function sf(e){const t=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let i=0;i<t.length;i+=1){const a=t[i];if(a==="\\"&&t[i+1]==="|"){r+="|",i+=1;continue}if(a==="|"){s.push(r.trim()),r="";continue}r+=a}return s.push(r.trim()),s}function ip({block:e}){switch(e.type){case"p":return n.jsx("p",{children:ps(e.text)});case"h":{const t=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(t+2,6)}`;return n.jsx(s,{className:"wb-md-h","data-level":t,children:ps(e.text)})}case"code":return n.jsxs("div",{className:"wb-md-code-frame",children:[n.jsxs("div",{className:"wb-md-code-head",children:[n.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),n.jsx(cw,{text:e.text,what:"code",always:!0})]}),n.jsx("pre",{className:"wb-md-code","data-lang":e.lang??void 0,children:n.jsx("code",{children:e.text})})]});case"quote":return n.jsxs("div",{className:"wb-md-copyable",children:[n.jsx("blockquote",{children:e.blocks.map((t,s)=>n.jsx(ip,{block:t},s))}),n.jsx(cw,{text:e.raw,what:"quote"})]});case"hr":return n.jsx("hr",{});case"list":{const t=e.items.map((s,r)=>n.jsx("li",{children:s.map((i,a)=>i.type==="p"?n.jsx(f.Fragment,{children:ps(i.text)},a):n.jsx(ip,{block:i},a))},r));return e.ordered?n.jsx("ol",{start:e.start,children:t}):n.jsx("ul",{children:t})}case"table":return n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table wb-md-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.head.map((t,s)=>n.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:ps(t)},s))})}),n.jsx("tbody",{children:e.rows.map((t,s)=>n.jsx("tr",{children:t.map((r,i)=>n.jsx("td",{style:e.align[i]?{textAlign:e.align[i]}:void 0,children:ps(r)},i))},s))})]})})}}function cw({text:e,what:t,always:s=!1}){const[r,i]=f.useState("idle"),a=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){i("failed");return}navigator.clipboard.writeText(e).then(()=>i("done"),()=>i("failed")),window.setTimeout(()=>i("idle"),1500)};return n.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${t}`,title:`Copy ${t}`,onClick:a,children:r==="done"?"Copied":r==="failed"?"Select to copy":n.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 13 13","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),n.jsx("path",{d:"M8.5 4.5V3a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v4.5a1 1 0 0 0 1 1h1.5"})]})})}function j_({handle:e}){const s=f.useContext(d1).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("a",{className:"wb-mention-link",href:Je(s.id),children:["@",s.handle]})}),n.jsx(bo,{children:n.jsxs(ko,{className:"wb-agent-card",sideOffset:6,children:[n.jsx(Es,{id:s.id,name:s.name,face:s,unavailable:!s.available}),n.jsxs("span",{className:"wb-agent-card-text",children:[n.jsx("span",{className:"wb-agent-card-name",children:s.name}),n.jsx("span",{className:"wb-agent-card-desc",children:s.description}),n.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):n.jsxs(n.Fragment,{children:["@",e]})}const y_=new RegExp("(`+)([\\s\\S]*?[^`])\\1(?!`)|\\*\\*([^*]+?)\\*\\*|__([^_]+?)__|~~([^~]+?)~~|(?<![\\w*])\\*([^*\\n]+?)\\*(?![\\w*])|(?<![\\w_])_([^_\\n]+?)_(?![\\w_])|\\[([^\\]\\n]+)\\]\\((https?:\\/\\/[^\\s)]+)\\)|<?(https?:\\/\\/[^\\s<>)\\]]+[^\\s<>)\\].,;:!?'\"])>?|(?<![\\w@/])@([a-z0-9][a-z0-9_-]{0,63})(?![\\w-])","i");function ps(e){const t=[];let s=e,r=0;for(;s!=="";){const i=y_.exec(s);if(!i){t.push(...uw(s,r));break}i.index>0&&t.push(...uw(s.slice(0,i.index),r)),r+=100,i[2]!==void 0?t.push(n.jsx("code",{children:i[2]},r)):i[3]!==void 0?t.push(n.jsx("strong",{children:ps(i[3])},r)):i[4]!==void 0?t.push(n.jsx("strong",{children:ps(i[4])},r)):i[5]!==void 0?t.push(n.jsx("s",{children:ps(i[5])},r)):i[6]!==void 0?t.push(n.jsx("em",{children:ps(i[6])},r)):i[7]!==void 0?t.push(n.jsx("em",{children:ps(i[7])},r)):i[8]!==void 0&&i[9]!==void 0?t.push(n.jsx("a",{href:i[9],target:"_blank",rel:"noopener noreferrer",children:ps(i[8])},r)):i[10]!==void 0?t.push(n.jsx("a",{href:i[10],target:"_blank",rel:"noopener noreferrer",children:i[10]},r)):i[11]!==void 0&&t.push(n.jsx(j_,{handle:i[11]},r)),s=s.slice(i.index+i[0].length)}return t}function uw(e,t){return e.split(`
|
|
93
|
+
`).flatMap((r,i)=>i===0?[r]:[n.jsx("br",{},`${t}-br-${i}`),r])}function w_({props:e}){return n.jsxs("div",{children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:zt(t.value,t.unit,null)})]},t.label))}):null,e.kind==="image"&&e.src?n.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?n.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:n.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?n.jsx("div",{className:"wb-doc",children:n.jsx(gr,{text:e.text})}):n.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const b_=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear"];function je(e,t){if(t===""||t==="$")return e;let s=e;for(const r of t.split(".")){const i=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!i)return;const[,a="",l=""]=i;if(a!==""){if(s===null||typeof s!="object")return;s=s[a]}for(const o of l.match(/\d+/g)??[]){if(!Array.isArray(s))return;s=s[Number(o)]}if(s===void 0)return}return s}function $e(e,t){if(t)return"const"in t?t.const:je(e,t.path)}function Bn(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const t=Number(e);return Number.isFinite(t)?t:null}return null}function tt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function qr(e){return Array.isArray(e)?e:[]}function k_(e,t){const s=qr(je(e,t.points)).map(i=>{const a=Bn(je(i,t.y)),l=tt(je(i,t.x));return a===null||l===null?null:{x:l,y:a}}).filter(i=>i!==null),r=(t.referenceLines??[]).map(i=>{const a=Bn($e(e,i.value));return a===null?null:{value:a,label:i.label,tone:i.tone??"neutral"}}).filter(i=>i!==null);return{points:s,unit:t.unit??"number",currency:tt($e(e,t.currency)),label:tt($e(e,t.label)),referenceLines:r,mark:t.mark??null,shadeBelow:Bn($e(e,t.shadeBelow)),events:S_(e,t)}}function S_(e,t){const s=t.events;if(!s)return[];const r=[],i=(a,l)=>{const o=tt(je(a,s.label));if(o===null)return;const c=tt(je(a,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Bn(je(a,s.amount)):null})};if(s.parent){for(const a of qr(je(e,t.points))){const l=tt(je(a,t.x));for(const o of qr(je(a,s.parent)))i(o,l)}return r}for(const a of qr(je(e,s.path??t.points)))i(a,null);return r}function N_(e,t){const s=(t.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(t.columns??[]).map(c=>{const u=je(o,c.key);let d=null;if(c.bar){const h=Bn($e(o,c.bar.max))??Bn($e(e,c.bar.max)),m=Bn(u);if(h!==null&&h>0&&m!==null){const p=Math.max(0,Math.min(1,m/h));d={fraction:p,tone:E_(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:tt($e(o,c.currency))??tt($e(e,c.currency)),bar:d}}),i=qr(je(e,t.rows)),a=t.groupBy?C_(i,t.groupBy,r):[{label:null,rows:i.map(r)}],l=(t.summary??[]).map(o=>({label:o.label,value:$e(e,o.value),unit:o.unit??"text",currency:tt($e(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:a,summary:l,empty:t.empty??"Nothing to show."}}function C_(e,t,s){const r=new Map;for(const i of e){const a=String(je(i,t.key)??""),l=r.get(a);l?l.push(i):r.set(a,[i])}return[...r.entries()].map(([i,a])=>{var l;return{label:((l=t.labels)==null?void 0:l[i])??i,rows:a.map(s)}})}function E_(e,t){var r;return!t||t.length===0?"neutral":((r=[...t].sort((i,a)=>a.atLeast-i.atLeast).find(i=>e>=i.atLeast))==null?void 0:r.tone)??"neutral"}function A_(e,t){return{bars:qr(je(e,t.bars)).map(r=>{const i=Bn(je(r,t.value)),a=tt(je(r,t.category));return i===null||a===null?null:{category:a,value:i}}).filter(r=>r!==null),unit:t.unit??"number",currency:tt($e(e,t.currency))}}function T_(e,t){if(t.pairs)return{pairs:t.pairs.map(r=>({label:r.label,value:$e(e,r.value),unit:r.unit??"text",currency:tt($e(e,r.currency)),tone:r.tone??"neutral"}))};const s=je(e,t.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,i])=>({label:un(r),value:i,unit:"text",currency:null,tone:"neutral"}))}}const R_=new Set(["good","warning","critical","neutral","accent"]),I_=new Set(b_);function ap(e){return typeof e=="string"&&I_.has(e)?e:null}function Ix(e,t,s=""){const r=t.empty??"Nothing to show.",i=s.split(".")[0]??"";if(t.notice){const l=tt(je(e,t.notice.text));if(l!==null&&l.trim()!==""){const o=t.notice.link&&i!==""?{plugin:i,page:t.notice.link.page}:null;return{tiles:[{icon:ap(t.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:qr(je(e,t.items)).map(l=>{const o=tt(je(l,t.value))??"",c=tt(je(l,t.label))??"";if(o===""&&c==="")return null;const u=t.tone?tt(je(l,t.tone)):null;return{icon:ap($e(l,t.icon)),value:o,label:c,lines:(t.lines??[]).slice(0,2).map(d=>tt(je(l,d))).filter(d=>d!==null&&d.trim()!==""),tone:u!==null&&R_.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function P_(e,t){const s=tt($e(e,t.kind)),r=s==="image"||s==="pdf"?s:"text",i=t.src?tt(je(e,t.src)):null;return{kind:r,text:t.text?tt(je(e,t.text)):null,src:i&&f1(i)?i:null,title:tt($e(e,t.title)),metadata:(t.metadata??[]).map(a=>({label:a.label,value:$e(e,a.value),unit:a.unit??"text"}))}}function $_(e,t){const s=t.diff?je(e,t.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:tt($e(e,t.title)),metadata:(t.metadata??[]).map(r=>({label:r.label,value:$e(e,r.value),unit:r.unit??"text"}))}}function M_(e,t){const s=t.output?je(e,t.output):void 0,r=l=>{const o=l?je(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},i=r(t.omittedBytes),a=t.elapsedMs?je(e,t.elapsedMs):void 0;return{command:tt($e(e,t.command)),output:typeof s=="string"?s:null,exitCode:r(t.exitCode),elapsedMs:typeof a=="number"&&Number.isFinite(a)&&a>=0?a:null,omittedBytes:i!==null&&i>0?i:null,metadata:(t.metadata??[]).map(l=>({label:l.label,value:$e(e,l.value),unit:l.unit??"text"}))}}const O_=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function h1(e){const t=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof t=="string"&&O_.test(t)?t.toLowerCase():null}function D_(e,t){return{artifactId:t.src?h1(je(e,t.src)):null,title:tt($e(e,t.title)),caption:tt($e(e,t.caption)),...t.captionLabel?{captionLabel:tt($e(e,t.captionLabel))}:{}}}function dw(e){if(!f1(e))return null;let t;try{t=new URL(e,"file:///").pathname}catch{return null}const s=/^\/preview\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/([A-Za-z0-9][A-Za-z0-9_.-]*)\/?$/.exec(t);return s?{plugin:s[1],name:s[2]}:null}function __(e,t){const s=t.src?tt(je(e,t.src)):null,r=t.port?je(e,t.port):null,i=t.awaiting?tt(je(e,t.awaiting)):null;return{target:s?dw(s):null,title:tt($e(e,t.title)),output:t.output?tt(je(e,t.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:i?dw(i):null,reloadsItself:t.reloadsItself?je(e,t.reloadsItself)===!0:!1,ports:t.ports?L_(je(e,t.ports)):[]}}function L_(e){const t=qr(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(t)].sort((s,r)=>s-r)}function f1(e){return e.startsWith("/")&&!e.startsWith("//")}function un(e){const t=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function m1(e,t){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:k_(t,s)};case"table":return{renderer:"table",props:N_(t,s)};case"bars":return{renderer:"bars",props:A_(t,s)};case"keyvalue":return{renderer:"keyvalue",props:T_(t,s)};case"tiles":return{renderer:"tiles",props:Ix(t,s,e.tool)};case"document":return{renderer:"document",props:P_(t,s)};case"diff":return{renderer:"diff",props:$_(t,s)};case"terminal":return{renderer:"terminal",props:M_(t,s)};case"image":return{renderer:"image",props:D_(t,s)};case"preview":return{renderer:"preview",props:__(t,s)};default:return{renderer:"structured",props:{value:t}}}}var F_=Object.defineProperty,As=(e,t)=>F_(e,"name",{value:t,configurable:!0}),Px="Dialog",[p1,jV]=Ns(Px),[z_,wr]=p1(Px),$x=As(e=>{const{__scopeDialog:t,children:s,open:r,defaultOpen:i,onOpenChange:a,modal:l=!0}=e,o=f.useRef(null),c=f.useRef(null),[u,d]=Wi({prop:r,defaultProp:i??!1,onChange:a,caller:Px}),[h,m]=f.useState(0),[p,g]=f.useState(0);return n.jsx(z_,{scope:t,triggerRef:o,contentRef:c,contentId:vs(),titleId:vs(),descriptionId:vs(),titlePresent:h>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:d,onOpenToggle:f.useCallback(()=>d(y=>!y),[d]),modal:l,children:s})},"Dialog"),g1="DialogPortal",[U_,x1]=p1(g1,{forceMount:void 0}),Mx=As(e=>{const{__scopeDialog:t,forceMount:s,children:r,container:i}=e,a=wr(g1,t);return n.jsx(U_,{scope:t,forceMount:s,children:f.Children.map(r,l=>n.jsx(jr,{present:s||a.open,children:n.jsx(Zg,{asChild:!0,container:i,children:l})}))})},"DialogPortal"),lp="DialogOverlay",v1=f.forwardRef(As(function(t,s){const r=x1(lp,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=wr(lp,t.__scopeDialog);return l.modal?n.jsx(jr,{present:i||l.open,children:n.jsx(W_,{...a,ref:s})}):null},"DialogOverlay")),B_=ei("DialogOverlay.RemoveScroll"),W_=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=wr(lp,r),l=iS(),o=ut(s,l);return n.jsx(px,{as:B_,allowPinchZoom:!0,shards:[a.contentRef],children:n.jsx(bt.div,{"data-state":_x(a.open),...i,ref:o,style:{pointerEvents:"auto",...i.style}})})},"DialogOverlayImpl")),Ao="DialogContent",Ox=f.forwardRef(As(function(t,s){const r=x1(Ao,t.__scopeDialog),{forceMount:i=r.forceMount,...a}=t,l=wr(Ao,t.__scopeDialog);return n.jsx(jr,{present:i||l.open,children:l.modal?n.jsx(H_,{...a,ref:s}):n.jsx(K_,{...a,ref:s})})},"DialogContent")),H_=f.forwardRef(As(function(t,s){const r=wr(Ao,t.__scopeDialog),i=f.useRef(null),a=ut(s,r.contentRef,i);return f.useEffect(()=>{const l=i.current;if(l)return vN(l)},[]),n.jsx(j1,{...t,ref:a,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Re(t.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Re(t.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Re(t.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),K_=f.forwardRef(As(function(t,s){const r=wr(Ao,t.__scopeDialog),i=f.useRef(!1),a=f.useRef(!1);return n.jsx(j1,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=t.onCloseAutoFocus)==null||o.call(t,l),l.defaultPrevented||(i.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),i.current=!1,a.current=!1},onInteractOutside:l=>{var u,d;(u=t.onInteractOutside)==null||u.call(t,l),l.defaultPrevented||(i.current=!0,l.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const o=l.target;((d=r.triggerRef.current)==null?void 0:d.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&a.current&&l.preventDefault()}})},"DialogContentNonModal")),j1=f.forwardRef(As(function(t,s){const{__scopeDialog:r,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:l,...o}=t,c=wr(Ao,r);return Ud(),n.jsx(n.Fragment,{children:n.jsx(eN,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:a,onUnmountAutoFocus:l,children:n.jsx(Jg,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":_x(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),V_="DialogTitle",Dx=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=wr(V_,r),{setTitleCount:l}=a;return Tn(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),n.jsx(bt.h2,{id:a.titleId,...i,ref:s})},"DialogTitle")),G_="DialogClose",y1=f.forwardRef(As(function(t,s){const{__scopeDialog:r,...i}=t,a=wr(G_,r);return n.jsx(bt.button,{type:"button",...i,ref:s,onClick:Re(t.onClick,()=>a.onOpenChange(!1))})},"DialogClose"));function _x(e){return e?"open":"closed"}As(_x,"getState");const Y_=5;function le(e,t,s){const[r,i]=f.useState(void 0),[a,l]=f.useState(null),[o,c]=f.useState(!0),[u,d]=f.useState(0),[h,m]=f.useState(0),p=f.useRef(e);return p.current=e,f.useEffect(()=>{let g=!1;return c(!0),p.current().then(y=>{g||(i(y),l(null),m(0))}).catch(y=>{g||(l(y instanceof ge?y.message:String(y)),m(b=>b+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...t,u]),f.useEffect(()=>{if(!s||h>=Y_)return;const g=window.setTimeout(()=>d(y=>y+1),s*2**h);return()=>window.clearTimeout(g)},[s,h,u]),{data:r,error:a,loading:o,reload:()=>{m(0),d(g=>g+1)}}}const w1={width:480,height:160,top:10,right:10,bottom:22,left:40},b1={width:1200,height:180,top:10,right:40,bottom:22,left:40};function q_({xs:e,series:t}){const s=b1,r=s.width-s.left-s.right,i=s.height-s.top-s.bottom,a=L=>L.filter(E=>E!==null&&Number.isFinite(E)),l=t.filter(L=>L.type!=="bar"),o=t.filter(L=>L.type==="bar"),c=l.flatMap(L=>a(L.values)),u=c.length>0?Math.min(...c):0,d=c.length>0?Math.max(...c):1;let h=u,m=d;if(h===m)h-=1,m+=1;else{const L=(m-h)*.08;h-=L,m+=L}const p=L=>ss(s.top+i-(L-h)/(m-h)*i),g=o.length>0&&o.every(L=>L.unit==="percent"),y=g?100:Math.max(1,...o.flatMap(L=>a(L.values))),b=L=>ss(s.top+i-Math.max(0,L)/y*i),x=e.length,v=x>0?r/x:r,j=L=>ss(s.left+v*(L+.5)),w=t.map(L=>{if(L.type==="bar")return"";let E="M";const M=[];return L.values.forEach((D,U)=>{if(D===null||!Number.isFinite(D)){E="M";return}M.push(`${E}${j(U)},${p(D)}`),E="L"}),M.join(" ")}),S=[],k=v*.6/Math.max(1,o.length),N=s.height-s.bottom;let C=0;t.forEach((L,E)=>{if(L.type!=="bar")return;const M=C++;L.values.forEach((D,U)=>{if(D===null||!Number.isFinite(D)||D<=0)return;const $=b(D);S.push({series:E,index:U,x:ss(j(U)-v*.3+k*M),y:$,width:ss(k),height:ss(N-$)})})});const I=c.length>0?Qu(u,d,2).map(L=>({value:L,y:p(L)})):[],A=o.length===0?[]:(g?[0,50,100]:Qu(0,y,2)).map(L=>({value:L,y:b(L),percent:g})),_=Math.max(1,Math.ceil(x/8)),z=e.flatMap((L,E)=>E%_===0?[{index:E,x:j(E)}]:[]);return{lines:w,bars:S,targetY:null,ticks:I,xLabels:z,rightTicks:A}}function Q_({xs:e,series:t,type:s="line",target:r=null}){const i=w1,a=i.width-i.left-i.right,l=i.height-i.top-i.bottom,o=t.flatMap(j=>j.values.filter(w=>w!==null&&Number.isFinite(w)));r!==null&&Number.isFinite(r)&&o.push(r),s==="bar"&&o.push(0);let c=o.length>0?Math.min(...o):0,u=o.length>0?Math.max(...o):1;if(c===u)c-=1,u+=1;else if(s==="line"){const j=(u-c)*.08;c-=j,u+=j}const d=j=>ss(i.top+l-(j-c)/(u-c)*l),h=e.length,m=h>0?a/h:a,p=j=>ss(s==="bar"?i.left+m*(j+.5):i.left+(h<=1?a/2:j/(h-1)*a)),g=s==="line"?t.map(j=>{let w="M";const S=[];return j.values.forEach((k,N)=>{if(k===null||!Number.isFinite(k)){w="M";return}S.push(`${w}${p(N)},${d(k)}`),w="L"}),S.join(" ")}):[],y=[];if(s==="bar"&&h>0){const j=m*.7,w=j/Math.max(1,t.length),S=d(0);t.forEach((k,N)=>{k.values.forEach((C,I)=>{if(C===null||!Number.isFinite(C))return;const A=d(C);y.push({series:N,index:I,x:ss(i.left+m*I+(m-j)/2+w*N),y:Math.min(A,S),width:ss(w),height:ss(Math.abs(S-A))})})})}const x=(o.length>0?Qu(Math.min(...o),Math.max(...o),2):[]).map(j=>({value:j,y:d(j)})),v=h===0?[]:h===1?[0]:h<5?[0,h-1]:[0,Math.floor((h-1)/2),h-1];return{lines:g,bars:y,targetY:r!==null&&Number.isFinite(r)?d(r):null,ticks:x,xLabels:v.map(j=>({index:j,x:p(j)}))}}function J_(e){const t=e.formatX??(o=>o),s=e.formatY??(o=>String(o)),r=e.xs.length;if(r===0)return`${e.label??"Chart"}: nothing recorded yet.`;const i=r===1?`on ${t(e.xs[0])}`:`from ${t(e.xs[0])} to ${t(e.xs[r-1])}`,a=e.series.map(o=>{const c=o.values.filter(d=>d!==null&&Number.isFinite(d));if(c.length===0)return`${o.label}: no values`;const u=c[c.length-1];return`${o.label}: latest ${s(u)}, lowest ${s(Math.min(...c))}, highest ${s(Math.max(...c))}`}),l=e.target!==null&&e.target!==void 0&&Number.isFinite(e.target)?` Target ${s(e.target)}.`:"";return`${e.label??"Chart"}, ${r} ${r===1?"point":"points"} ${i}. ${a.join("; ")}.${l}`}function X_({xs:e,series:t,type:s="line",target:r=null,label:i,formatX:a=o=>o,formatY:l=o=>String(o)}){const o=s==="mixed",c=o?b1:w1,u=o?q_({xs:e,series:t}):Q_({xs:e,series:t,type:s,target:r}),d=J_({xs:e,series:t,target:r,...i?{label:i}:{},formatX:a,formatY:l});return n.jsxs("figure",{className:"ui-chart","data-type":s,children:[n.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(h=>n.jsxs("g",{children:[n.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:h.y,y2:h.y}),n.jsx("text",{x:c.left-6,y:h.y,textAnchor:"end",dominantBaseline:"middle",children:l(h.value)})]},h.value)),(u.rightTicks??[]).map(h=>n.jsx("text",{x:c.width-c.right+6,y:h.y,textAnchor:"start",dominantBaseline:"middle",children:h.percent?`${h.value}%`:l(h.value)},`r-${h.value}`)),n.jsx("line",{className:"ui-chart-axis",x1:c.left,x2:c.width-c.right,y1:c.height-c.bottom,y2:c.height-c.bottom}),u.bars.map(h=>n.jsx("rect",{className:"ui-chart-bar","data-series":h.series,x:h.x,y:h.y,width:h.width,height:h.height},`${h.series}-${h.index}`)),u.lines.map((h,m)=>h?n.jsx("path",{className:"ui-chart-line","data-series":m,d:h},m):null),u.targetY!==null?n.jsx("line",{className:"ui-chart-target","data-testid":"chart-target",x1:c.left,x2:c.width-c.right,y1:u.targetY,y2:u.targetY}):null,u.xLabels.map(h=>n.jsx("text",{x:h.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&h.index===0?"start":h.index===e.length-1&&e.length>1?"end":"middle",children:a(e[h.index])},h.index))]}),n.jsx("figcaption",{className:"sr-only",children:d}),t.length>1?n.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:t.map((h,m)=>n.jsx("li",{"data-series":m,"data-type":o?h.type??"line":void 0,children:h.label},h.label))}):null]})}function ss(e){return Math.round(e*10)/10}function hi(...e){return e.filter(Boolean).join(" ")}function R({variant:e,size:t,className:s,type:r="button",...i}){return n.jsx("button",{type:r,className:hi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...i})}function Ut({variant:e,size:t,className:s,...r}){return n.jsx("a",{className:hi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":t,...r})}function J({children:e,align:t,valign:s,className:r}){return n.jsx("div",{className:hi("ui-toolbar",r),"data-align":t,"data-valign":s,children:e})}function Xt(){return n.jsx("span",{className:"ui-toolbar-spacer"})}function Z({label:e,hint:t,inline:s,grow:r,wide:i,group:a,action:l,after:o,children:c}){const u=f.useId();return n.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":i?"true":void 0,children:[l?n.jsxs("div",{className:"ui-field-row",children:[n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):a?n.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[n.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):n.jsxs("label",{className:"ui-field-control",children:[n.jsx("span",{className:"ui-field-label",children:e}),c]}),t?n.jsx("span",{className:"ui-field-hint",children:t}):null,o]})}function bs({children:e,dense:t,columns:s}){return n.jsx("div",{className:"ui-formgrid","data-dense":t?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function ve({tone:e,mono:t,dot:s,children:r,className:i,title:a}){return n.jsxs("span",{className:hi("ui-pill",t&&"mono",i),"data-tone":e,title:a,children:[s?n.jsx("span",{className:"ui-pill-dot","aria-hidden":"true"}):null,r]})}function Ia({children:e}){return n.jsx("span",{className:"ui-tag",children:e})}function Go({state:e}){const t=e==="succeeded"||e==="approved"||e==="fired"||e==="running"||e==="leased"?"good":e==="failed"||e==="rejected"||e==="unknown"||e==="error"||e==="refused"?"critical":e==="pending"||e==="suspended"||e==="expired"||e==="paused"?"warning":void 0;return n.jsx(ve,{tone:t,children:e})}function W({tone:e,title:t,children:s,role:r,action:i}){return i?n.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:n.jsxs("div",{className:"ui-notice-row",children:[n.jsxs("div",{className:"ui-notice-body",children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]}),i]})}):n.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[t?n.jsx("div",{className:"ui-notice-title",children:t}):null,s]})}function re({message:e}){return e?n.jsx(W,{tone:"critical",role:"alert",children:e}):null}function ce({mascot:e,warm:t,title:s,action:r,children:i}){return t||s?n.jsxs("div",{className:"ui-empty","data-warm":t?"true":void 0,children:[s?n.jsx("div",{className:"ui-empty-title",children:s}):null,n.jsx("div",{children:i}),r]}):e?n.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[n.jsx(sp,{size:"sm"}),n.jsx("p",{children:i})]}):n.jsx("p",{className:"ui-empty",children:i})}function Zt({icon:e,title:t,action:s,children:r}){return n.jsxs("div",{className:"ui-empty-state",children:[e?n.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?n.jsx(ye,{name:e}):e}):null,n.jsx("div",{className:"ui-empty-state-title",children:t}),r?n.jsx("p",{className:"ui-empty-state-line",children:r}):null,s?n.jsx("div",{className:"ui-empty-state-action",children:s}):null]})}function Z_({children:e}){return n.jsx("div",{className:"ui-page",children:e})}function th({title:e,lede:t,actions:s,before:r}){return n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[r,n.jsx("span",{children:e})]}),s?n.jsx("div",{className:"ui-page-actions",children:s}):null]}),t?n.jsx("p",{className:"ui-page-lede",children:t}):null]})}function yn({embedded:e,title:t,lede:s,actions:r,children:i}){return e?n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[r?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:r}):null,i]}):n.jsxs(Z_,{children:[n.jsx(th,{title:t,lede:s,actions:r}),i]})}function te({title:e,aside:t,actions:s,panel:r,flush:i,foot:a,children:l}){const o=e||t||s?n.jsxs("div",{className:"ui-section-head",children:[e?n.jsx("h3",{className:"ui-section-title",children:e}):n.jsx("span",{}),t||s?n.jsxs("div",{className:"ui-section-side",children:[t?n.jsx("span",{className:"ui-section-aside",children:t}):null,s?n.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return n.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?n.jsxs("div",{className:"ui-panel","data-flush":i?"true":void 0,children:[l,a?n.jsx("div",{className:"ui-panel-foot",children:a}):null]}):n.jsxs(n.Fragment,{children:[l,a?n.jsx("div",{className:"ui-toolbar","data-align":"end",children:a}):null]})]})}function Ze({title:e,tool:t,actions:s,flush:r,children:i}){return n.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||t||s?n.jsxs("header",{className:"ui-panel-head",children:[e?n.jsx("h3",{className:"ui-panel-title",children:e}):n.jsx("span",{}),t?n.jsx("span",{className:"ui-panel-tool",children:t}):null,s?n.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,i]})}function ks({tone:e,title:t,meta:s,actions:r,children:i,foot:a,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),l())}}:{};return n.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[t||s||r?n.jsxs("div",{className:"ui-card-head",children:[t?n.jsx("h3",{className:"ui-card-title",children:t}):null,s,r?n.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,i,a?n.jsx("div",{className:"ui-card-foot",children:a}):null]})}function Q({gap:e,divided:t,children:s}){return n.jsx("div",{className:"ui-stack","data-gap":e,"data-divided":t?"true":void 0,children:s})}function eL({children:e}){return n.jsx("div",{className:"ui-row",children:e})}function nh({inline:e,children:t}){return n.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:t})}function zs({label:e,value:t,note:s,tone:r,size:i}){return n.jsxs("div",{className:"ui-stat",children:[n.jsx("div",{className:"ui-stat-k",children:e}),n.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":i,children:t}),s?n.jsx("div",{className:"ui-stat-n",children:s}):null]})}function Gt({items:e}){return n.jsx("dl",{className:"ui-kv",children:e.map((t,s)=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{children:t.value})]},t.key??s))})}function Pn({children:e}){return n.jsx("div",{className:"ui-table-wrap",children:n.jsx("table",{className:"ui-table",children:e})})}function k1({value:e,label:t}){const s=Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));return n.jsx("div",{className:"ui-progress",role:"progressbar","aria-label":t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-valuetext":`${s}%`,children:n.jsx("div",{className:"ui-progress-fill",style:{inlineSize:`${s}%`}})})}function jt({children:e,label:t}){return n.jsx("pre",{className:"ui-code","aria-label":t,children:e})}function Ct({summary:e,boxed:t,open:s,className:r,onToggle:i,children:a}){return n.jsxs("details",{className:hi("ui-details",r),"data-boxed":t?"true":void 0,open:s,onToggle:i?l=>i(l.currentTarget.open):void 0,children:[n.jsx("summary",{children:e}),a]})}function kt({title:e,onClose:t,size:s,foot:r,children:i}){return n.jsx($x,{open:!0,onOpenChange:a=>{a||t()},children:n.jsxs(Mx,{children:[n.jsx(v1,{className:"ui-sheet-overlay"}),n.jsxs(Ox,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[n.jsxs("div",{className:"ui-sheet-head",children:[n.jsx(Dx,{className:"ui-sheet-title",children:e}),n.jsx(y1,{asChild:!0,children:n.jsx(R,{size:"sm",children:"Close"})})]}),i,r?n.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Xu({title:e,onClose:t,foot:s,children:r}){return n.jsx($x,{open:!0,onOpenChange:i=>{i||t()},children:n.jsxs(Mx,{children:[n.jsx(v1,{className:"ui-sheet-overlay","data-layer":"modal"}),n.jsxs(Ox,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[n.jsx(Dx,{className:"ui-modal-title",children:e}),r,s?n.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function tL({label:e,items:t}){const s=i=>i.stopPropagation(),r=f.useRef(!1);return n.jsxs(Gd,{modal:!1,onOpenChange:i=>{i&&(r.current=!1)},children:[n.jsx(Yd,{asChild:!0,children:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:s,children:n.jsx(ye,{name:"more"})})}),n.jsx(Ho,{children:n.jsx(qd,{className:"ui-menu",align:"end",sideOffset:4,onClick:s,onKeyDown:s,onCloseAutoFocus:i=>{r.current&&i.preventDefault()},children:t.map((i,a)=>i?i==="separator"?n.jsx(Dr,{className:"ui-menu-sep"},`sep-${a}`):n.jsxs(Or,{className:"ui-menu-item","data-tone":i.tone,onSelect:()=>{r.current=!0,i.onSelect()},children:[n.jsx("span",{children:i.label}),i.hint?n.jsx("span",{className:"ui-menu-item-hint",children:i.hint}):null]},a):null)})})]})}function nL({title:e,actions:t,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:i,label:a,children:l}){return n.jsx($x,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:n.jsx(Mx,{children:n.jsxs(Ox,{className:"ui-dock","aria-describedby":void 0,...a?{"aria-label":a}:{},onInteractOutside:o=>o.preventDefault(),...r?{onCloseAutoFocus:r}:{},...i?{onOpenAutoFocus:i}:{},children:[n.jsxs("div",{className:"ui-dock-head",children:[n.jsx(Dx,{className:"ui-dock-title",children:e}),n.jsxs("div",{className:"ui-dock-actions",children:[t,n.jsx(y1,{asChild:!0,children:n.jsx(R,{size:"sm",variant:"ghost",children:"Close"})})]})]}),n.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Yo({level:e,label:t,children:s}){return n.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":t,children:s})}function Ha({href:e,active:t,count:s,onClick:r,children:i}){return n.jsxs("a",{className:"ui-tab",href:e,"aria-current":t?"page":void 0,onClick:r,children:[i,s?n.jsx("span",{className:"ui-count",children:s}):null]})}function ls({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function yt({children:e}){return n.jsx("div",{className:"ui-list",children:e})}function ft({href:e,onClick:t,lead:s,title:r,sub:i,side:a,dimmed:l,label:o}){const c=n.jsxs(n.Fragment,{children:[s,n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:r}),i?n.jsx("span",{className:"ui-list-sub",children:i}):null]}),a?n.jsx("span",{className:"ui-list-side",children:a}):null]}),u=l?"true":void 0;return e?n.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:t?d=>{d.preventDefault(),t()}:void 0,children:c}):t?n.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:t,onKeyDown:d=>{d.target!==d.currentTarget||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),t())},children:c}):n.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function S1({href:e,onClick:t,current:s,lead:r,title:i,meta:a,sub:l,snippet:o,side:c}){return n.jsxs("a",{className:"ui-pick",href:e,"aria-current":s?"true":void 0,onClick:t?u=>{u.preventDefault(),t()}:void 0,children:[r?n.jsx("span",{className:"ui-pick-lead",children:r}):null,n.jsxs("span",{className:"ui-pick-main",children:[n.jsxs("span",{className:"ui-pick-top",children:[n.jsx("span",{className:"ui-pick-title",children:i}),a?n.jsx("span",{className:"ui-pick-meta",children:a}):null]}),l||c?n.jsxs("span",{className:"ui-pick-line",children:[l?n.jsx("span",{className:"ui-pick-sub",children:l}):null,c?n.jsx("span",{className:"ui-pick-side",children:c}):null]}):null,o?n.jsx("span",{className:"ui-pick-snippet",children:o}):null]})]})}function N1({list:e,detail:t,empty:s,label:r,className:i}){return n.jsxs("div",{className:hi("ui-split",i),"data-open":t?"true":void 0,children:[n.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),n.jsx("section",{className:"ui-split-detail","data-empty":t?void 0:"true",children:t??n.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function Zu({children:e,onRemove:t,label:s,disabled:r}){return n.jsxs("span",{className:"ui-chip",children:[e,n.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:t,disabled:r,children:"×"})]})}const sL=8;function rL({label:e,options:t,value:s,onChange:r,max:i,disabled:a,id:l}){const[o,c]=f.useState(!1),[u,d]=f.useState(""),[h,m]=f.useState(0),p=f.useRef(null),g=f.useRef(null),y=f.useRef(null),b=f.useRef(null),x=f.useId(),v=E=>{var M;return((M=t.find(D=>D.value===E))==null?void 0:M.label)??E},j=i!==void 0&&s.length>=i,w=t.filter(E=>!s.includes(E.value)),S=t.length>sL,k=u.trim().toLowerCase(),N=k===""?w:w.filter(E=>E.label.toLowerCase().includes(k)),C=Math.min(h,Math.max(0,N.length-1)),I=E=>{var M;c(!1),d(""),m(0),E&&((M=g.current)==null||M.focus())};f.useEffect(()=>{var M;if(!o)return;(M=S?y.current:b.current)==null||M.focus();const E=D=>{p.current&&!p.current.contains(D.target)&&I(!1)};return document.addEventListener("mousedown",E),()=>document.removeEventListener("mousedown",E)},[o,S]);const A=E=>{const M=[...s,E];r(M),d(""),m(0);const D=i!==void 0&&M.length>=i;(D||M.length>=t.length)&&I(!D)},_=E=>{if(E.key==="Escape")E.preventDefault(),I(!0);else if(E.key==="ArrowDown")E.preventDefault(),m(N.length===0?0:(C+1)%N.length);else if(E.key==="ArrowUp")E.preventDefault(),m(N.length===0?0:(C-1+N.length)%N.length);else if(E.key==="Enter"){E.preventDefault();const M=N[C];M&&A(M.value)}else E.key==="Backspace"&&u===""&&s.length>0&&(E.preventDefault(),r(s.slice(0,-1)))},z=E=>`${x}-${E}`,L=o&&N.length>0?z(C):void 0;return n.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(E=>n.jsx(Zu,{label:v(E),disabled:a,onRemove:()=>r(s.filter(M=>M!==E)),children:v(E)},E)),n.jsxs("div",{className:"ui-chippicker-add",children:[n.jsx("button",{ref:g,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?x:void 0,disabled:a||j||w.length===0,onClick:()=>o?I(!1):c(!0),children:"Add…"}),o?n.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:_,children:[S?n.jsx("input",{ref:y,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":x,"aria-activedescendant":L,value:u,onChange:E=>{d(E.target.value),m(0)}}):null,n.jsxs("div",{ref:b,id:x,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":S?void 0:L,tabIndex:S?-1:0,className:"ui-chippicker-list",children:[N.map((E,M)=>n.jsx("div",{id:z(M),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":M===C?"":void 0,onMouseEnter:()=>m(M),onMouseDown:D=>D.preventDefault(),onClick:()=>A(E.value),children:E.label},E.value)),N.length===0?n.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function iL({label:e,options:t,value:s,onChange:r}){return n.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:t.map(i=>n.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":i.value===s,onClick:()=>r(i.value),children:i.label},i.value))})}function C1({label:e,value:t,onChange:s,placeholder:r,grow:i}){return n.jsx("span",{className:"ui-search","data-grow":i?"true":void 0,children:n.jsx("input",{type:"search","aria-label":e,value:t,placeholder:r,onChange:a=>s(a.target.value)})})}function Ka({svg:e,icon:t="plug",letter:s,size:r}){return n.jsx("span",{className:"ui-app-icon","data-size":r,"data-tone":e||s?"accent":void 0,"aria-hidden":"true",children:e?n.jsx("span",{className:"ui-app-icon-svg",dangerouslySetInnerHTML:{__html:e}}):s?n.jsx("span",{className:"ui-app-icon-letter",children:s}):n.jsx(ye,{name:t})})}function E1({items:e,label:t="Where this is",inline:s}){const r=e.map((i,a)=>{const l=i.key??String(a);if(i.current)return n.jsx("span",{className:"ui-crumb","aria-current":"page",children:i.label},l);const o=i.href?n.jsx("a",{className:"ui-crumb",href:i.href,onClick:i.onClick?c=>{var u;c.preventDefault(),(u=i.onClick)==null||u.call(i)}:void 0,children:i.label}):n.jsx("button",{type:"button",className:"ui-crumb",onClick:i.onClick,children:i.label});return n.jsxs("span",{className:"ui-crumb-step",children:[o,n.jsx(ye,{name:"chevron-right",size:12})]},l)});return s?n.jsx("span",{className:"ui-crumbs","aria-label":t,children:r}):n.jsx("nav",{className:"ui-crumbs","aria-label":t,children:r})}function A1({main:e,filters:t,filtersOpen:s,onToggleFilters:r,active:i,chips:a,actions:l,onSubmit:o,label:c}){return n.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[n.jsxs("div",{className:"ui-searchbar-row",children:[e?n.jsx("div",{className:"ui-searchbar-main",children:e}):null,t&&r?n.jsxs(R,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",i?n.jsx("span",{className:"ui-count",children:i}):null]}):null,!r&&t?n.jsx("div",{className:"ui-searchbar-inline",children:t}):null,l?n.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),t&&r&&s?n.jsx("div",{className:"ui-searchbar-filters",children:t}):null,a?n.jsx("div",{className:"ui-searchbar-chips",children:a}):null]})}function ed({size:e}){return n.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function T1({quiet:e,still:t,className:s,children:r}){return n.jsx("div",{className:hi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":t?"true":void 0,children:r})}function aL({dock:e,className:t,children:s}){return n.jsxs("div",{className:hi("ui-float",t),children:[n.jsx("div",{className:"ui-float-body",children:s}),e?n.jsx("div",{className:"ui-float-dock",children:e}):null]})}function lL(e){const t={};for(const s of e??[])t[s.key]=s.default;return t}function Lx(e){const[t,s]=f.useState({}),r=e??[],i={...lL(r),...t};return r.length===0?{values:void 0,controls:null}:{values:i,controls:n.jsx("div",{className:"ui-choices",children:r.map(a=>n.jsx(Z,{label:a.label,inline:!0,children:n.jsx("select",{value:i[a.key],onChange:l=>s(o=>({...o,[a.key]:l.target.value})),children:a.options.map(l=>n.jsx("option",{value:l,children:l},l))})},a.key))})}}function oL({props:e,timezone:t="UTC",onDecided:s}){var j;const[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,d]=f.useState(null);f.useEffect(()=>{let w=!1;return i(null),l(null),T.approval(e.approvalId).then(S=>{w||i(S)}).catch(S=>{w||l(S instanceof ge?S.message:String(S))}),()=>{w=!0}},[e.approvalId]);const{values:h,controls:m}=Lx(r==null?void 0:r.choices),p=(w,S)=>{d(w),l(null),(h&&w==="approve"?T.decide(e.approvalId,w,S,h):T.decide(e.approvalId,w,S)).then(k=>{i(k.action),s==null||s(k.action)}).catch(k=>l(k instanceof ge?k.message:String(k))).finally(()=>d(null))};if(a&&!r)return n.jsx("p",{className:"wb-empty",children:a});if(!r)return n.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",y=(j=r.permissionScopes)==null?void 0:j.includes("always"),b=cL(r),x=(r.preview??"").split(`
|
|
94
|
+
`).length>12||(r.preview??"").length>900,v=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"Action"}),n.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(w=>un(w)).join(" · ")}),n.jsx("dt",{children:"Status"}),n.jsxs("dd",{children:[g?n.jsx(ve,{tone:"warning",dot:!0,children:"waiting for you"}):n.jsx(Go,{state:r.state}),!g&&v?n.jsxs("span",{className:"wb-envelope-note",children:[" ",v]}):null]}),n.jsx("dt",{children:g?"Expires":"Decided"}),n.jsx("dd",{children:Ve(g?r.expiresAt:r.decidedAt,t)})]}),n.jsxs("div",{className:"envelope-body","data-clamp":x&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",x&&!o?n.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),n.jsx(re,{message:a}),g?m:null,g?n.jsxs("div",{className:"wb-envelope-decide",children:[n.jsx("p",{className:"wb-envelope-note",children:y?"Auto and Always also approve later calls to this tool in that scope; you can take it back on the agent's Tools tab.":"This runs the action exactly as shown above."}),n.jsxs("div",{className:"wb-envelope-buttons",children:[n.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),y?n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),n.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,n.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":y?"Allow once":"Approve"})]})]}):null,n.jsxs("details",{className:"ui-details",children:[n.jsx("summary",{children:"The envelope, field by field"}),n.jsx("dl",{className:"ui-kv wb-envelope-fields",children:b.map(w=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:w.label}),w.block?n.jsx("dd",{className:"wb-envelope-block",children:n.jsx("pre",{className:"mono",children:w.value})}):n.jsx("dd",{className:w.mono?"mono":void 0,children:w.value})]},w.label))})]})]})}function cL(e){const t=[],s=e.envelope;if(s!==null&&typeof s=="object"&&!Array.isArray(s))for(const[i,a]of Object.entries(s))t.push(hw(un(i),a));else s!=null&&t.push({label:"Envelope",value:Fx(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[i,a]of Object.entries(r)){const l=`Argument · ${un(i)}`;t.some(o=>o.label===l)||t.push(hw(l,a))}return t.push({label:"Action id",value:e.id,mono:!0},{label:"Tool version",value:e.toolVersion,mono:!0},{label:"Agent",value:e.agentId,mono:!0},{label:"Args hash",value:e.argsHash,mono:!0},{label:"Policy version",value:String(e.policyVersion)}),e.conversationId&&t.push({label:"Conversation",value:e.conversationId,mono:!0}),e.jobId&&t.push({label:"Job",value:e.jobId,mono:!0}),t}function hw(e,t){return t!==null&&typeof t=="object"&&(!Array.isArray(t)||t.some(r=>r!==null&&typeof r=="object"))?{label:e,value:JSON.stringify(t,null,2),block:!0}:{label:e,value:Fx(t)}}function Fx(e){return e==null?"—":Array.isArray(e)?e.map(t=>Fx(t)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):zt(e,"text",null)}const uL=new Set(["image/png","image/jpeg","image/gif","image/webp"]),dL=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function td(e){const t=e!==null&&typeof e=="object"?e.artifacts:null;return Array.isArray(t)?t.flatMap(s=>{if(s===null||typeof s!="object")return[];const r=s;return typeof r.id!="string"||!dL.test(r.id)?[]:[{type:"attachment",artifactId:r.id,filename:typeof r.filename=="string"?r.filename:null,mime:typeof r.mime=="string"?r.mime:"application/octet-stream",kind:typeof r.kind=="string"?r.kind:"other",sizeBytes:null}]}):[]}function zx(e){return uL.has(e.toLowerCase())}function xr(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function ri(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function $n(e){return e==null||!Number.isFinite(e)?"":e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(e<10*1024?1:0)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ux(e,t){const s=e.toLowerCase(),r=(t??"").toLowerCase().split(".").pop()??"";return s.startsWith("image/")?"image":s==="application/pdf"?"pdf":s.startsWith("audio/")?"audio":s.startsWith("video/")?"video":s==="text/csv"||s==="text/tab-separated-values"||s.includes("spreadsheet")||s.includes("excel")||["csv","tsv","xls","xlsx","numbers"].includes(r)?"table":s.includes("zip")||s.includes("tar")||s.includes("compressed")||["zip","gz","tgz","rar","7z"].includes(r)?"archive":s==="application/json"||s.includes("javascript")||s.includes("xml")||["ts","tsx","js","py","rb","go","rs","swift","json","yaml","yml","toml","sh","sql","html","css"].includes(r)?"code":s.startsWith("text/")||["md","txt","rtf","doc","docx"].includes(r)?"text":"file"}const Ti={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function mu(e){return`artifact:${e}`}function hL(e){const t=Ux(e.mime,e.filename);return{id:mu(e.artifactId),tool:Ti[t],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function fL({props:e}){const t=h1(e.artifactId),[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1);if(f.useEffect(()=>{if(t===null)return;let d=!0;return r(null),a(null),o(!1),T.libraryEntry(t).then(h=>{d&&r({filename:h.entry.filename,sizeBytes:h.entry.sizeBytes})}).catch(()=>{}),()=>{d=!1}},[t]),t===null)return n.jsx("p",{className:"wb-empty",children:"This result names no file in the Files library."});const c=e.title??(s==null?void 0:s.filename)??"Image",u=[i?`${i.width} × ${i.height}`:null,s!=null&&s.sizeBytes?$n(s.sizeBytes):null].filter(d=>d!==null);return n.jsxs("figure",{className:"wb-image",children:[n.jsx("div",{className:"wb-image-frame",children:l?n.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):n.jsx("a",{href:xr(t),className:"wb-image-link",title:"Open at full size",children:n.jsx("img",{src:xr(t),alt:e.caption??c,onLoad:d=>{const h=d.currentTarget;h.naturalWidth>0&&a({width:h.naturalWidth,height:h.naturalHeight})},onError:()=>o(!0)})})}),n.jsxs("figcaption",{className:"wb-image-caption",children:[n.jsxs(J,{children:[n.jsx("span",{className:"wb-image-name",children:c}),u.length>0?n.jsx("span",{className:"wb-image-facts",children:u.join(" · ")}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(Ut,{size:"sm",href:ri(t),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?n.jsx(Ct,{summary:e.captionLabel,className:"wb-image-note",children:n.jsx("p",{className:"wb-image-note-body",children:e.caption})}):e.caption?n.jsx("p",{className:"wb-image-note",children:e.caption}):null]})]})}function mL({props:e}){return e.pairs.length===0?n.jsx("p",{className:"wb-empty",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.pairs.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:"tnum",style:t.tone==="neutral"?void 0:{color:`var(--${t.tone})`},children:zt(t.value,t.unit,t.currency)})]},t.label))})}const pL=8;function R1({text:e,label:t="Output",className:s}){const r=f.useRef(null),i=f.useRef(!0);return f.useLayoutEffect(()=>{const a=r.current;a&&i.current&&(a.scrollTop=a.scrollHeight)},[e]),n.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":t,tabIndex:0,onScroll:a=>{const l=a.currentTarget;i.current=l.scrollHeight-l.scrollTop-l.clientHeight<=pL},children:e})}function gL(e){if(e<1e3)return`${Math.round(e)} ms`;const t=e/1e3;if(t<60)return`${t.toFixed(t<10?1:0)} s`;const s=Math.floor(t/60);return`${s} min ${Math.round(t-s*60)} s`}function xL({text:e}){const[t,s]=f.useState("");return n.jsxs(n.Fragment,{children:[t?n.jsx("span",{role:"status",className:"wb-hint",children:t}):null,n.jsx(R,{size:"sm",onClick:()=>{var r;if(s(""),!((r=navigator.clipboard)!=null&&r.writeText)){s("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>s("Copied"),()=>s("Copy failed; select the text to copy."))},children:"Copy"})]})}function vL({props:e}){const t=e.output??"";return n.jsxs("div",{className:"wb-terminal",children:[n.jsxs(J,{className:"wb-terminal-head",children:[e.command!==null?n.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?n.jsxs(ve,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?n.jsx("span",{className:"wb-terminal-fact",children:gL(e.elapsedMs)}):null,n.jsx("span",{className:"ui-toolbar-spacer"}),t!==""?n.jsx(xL,{text:t}):null]}),e.omittedBytes!==null?n.jsxs("p",{className:"wb-terminal-note",children:["First ",$n(e.omittedBytes)," not shown."]}):null,t!==""?n.jsx(R1,{text:t}):n.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?n.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:s.label}),n.jsx("dd",{children:zt(s.value,s.unit,null)})]},s.label))}):null]})}function jL(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function fw(e){try{const t=new URL(e);return t.searchParams.delete("ticket"),t.toString()}catch{return e}}function yL(e){const t=new Set(e.ports??[]);return e.port!==null&&t.add(e.port),[...t].sort((s,r)=>s-r)}function wL({props:e}){var S;const[t,s]=f.useState(null),[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=((S=e.target)==null?void 0:S.plugin)??null,d=yL(e),[h,m]=f.useState(null),p=h!==null&&d.includes(h)?h:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,y=e.changes??0,b=f.useRef(y),[x,v]=f.useState(0);f.useEffect(()=>{y<=b.current||(b.current=y,e.reloadsItself||v(k=>k+1))},[y,e.reloadsItself]),f.useEffect(()=>{if(u===null||g===null)return;let k=!0;return s(null),i(null),l(null),v(0),T.previewLink(u,g).then(N=>{k&&(s(N.url),i(fw(N.url)))}).catch(N=>{k&&l(N instanceof Error?N.message:"That preview could not be opened.")}),()=>{k=!1}},[u,g]);const j=()=>{u===null||g===null||T.previewLink(u,g).then(k=>i(k.url)).catch(()=>{})};if(e.target===null)return n.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",n.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const w=!(e.output===null||e.output==="");return n.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[n.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?n.jsx("h4",{className:"wb-doc-title",children:e.title}):null,d.length>1?n.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:k=>m(Number(k.target.value)),children:d.map(k=>n.jsxs("option",{value:k,children:[":",k]},k))}):null,w?n.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(k=>!k),children:o?"Hide output":"Output"}):null,r?n.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:j,onFocus:j,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&jL()?n.jsxs("a",{className:"wb-preview-direct",href:`http://localhost:${p}/`,target:"_blank",rel:"noreferrer noopener",title:"The process itself, on this machine only.",children:["localhost:",p]}):null]}),n.jsxs("div",{className:"wb-preview-body",children:[t?n.jsx("iframe",{className:"wb-preview-frame",src:x===0?t:fw(t),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},x):n.jsx("p",{className:"wb-empty wb-preview-frame",children:a??"Opening the preview…"}),w&&o?n.jsx(R1,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const bL=50,kL=9,SL=24,NL=.6,CL=48,EL=/(amount|total|balance|price|cost|paid|pay|payment|net|spend|spent|due|limit|owed|fee|income|charge|burn|minimum|principal|interest|worth|cash|debt|deposit|credit|debit|value|revenue|budget|floor|avg|mean|median)/i,AL=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,TL=/^id$|(^|[a-z0-9])Id$|_id$/;function wa(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function zn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function I1(...e){for(const t of e)if(zn(t))for(const s of["currency","currencyCode"]){const r=t[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function P1(e,t,s){const r=t.filter(i=>i!=null&&i!=="");return r.length===0?"text":r.every(i=>typeof i=="boolean")?"boolean":r.every(i=>typeof i=="number"&&Number.isFinite(i))?s!==null&&EL.test(e)?"currency":"number":r.every(i=>typeof i=="string"&&AL.test(i))?"date":"text"}function RL(e,t){if(!TL.test(e))return!1;const s=t.filter(r=>!ol(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function ol(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:zn(e)?Object.keys(e).length===0:!1}function mw(e,t){const s=e.filter(zn);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,bL),i=new Map,a=[];for(const d of r)for(const h of Object.keys(d))i.has(h)||a.push(h),i.set(h,(i.get(h)??0)+1);if(i.size===0||i.size>SL||[...i.values()].reduce((d,h)=>d+h,0)/(i.size*r.length)<NL)return null;const o=[...i.keys()].sort((d,h)=>{const m=(i.get(h)??0)-(i.get(d)??0);return m!==0?m:a.indexOf(d)-a.indexOf(h)}),c=[],u=[];for(const d of o){const h=r.map(y=>y[d]),m=h.filter(y=>!ol(y));if(m.length===0||RL(d,h))continue;const p=I1(r[0],t),g=P1(d,h,p);if(r.length>=4&&m.length===h.length&&h.every(y=>wa(y)&&y===h[0])){u.push({label:un(d),value:h[0],type:g,currency:p});continue}if(c.push({key:d,label:un(d),type:g,currency:g==="currency"?p:null}),c.length===kL)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function IL(e,t,s){const r=I1(s);return{label:un(e),value:t,type:P1(e,[t],r),currency:r}}function $1(e){return typeof e=="string"&&e.length>CL}function PL(e){return e==null?"This tool returned nothing.":typeof e=="string"&&e.trim()===""?"This tool returned an empty string.":Array.isArray(e)&&e.length===0?"This tool returned no items.":zn(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function op(e){if(typeof e=="string"&&e.trim()!=="")return e;if(zn(e))for(const t of["message","error","reason","detail","description"]){const s=e[t];if(typeof s=="string"&&s.trim()!=="")return s;if(zn(s)){const r=op(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function Bx(e,t={}){if(t.failed){let h=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));zn(m)&&(h=m)}catch{}return{kind:"error",summary:op(h),detail:pw(h)}}if(zn(e)){const h=e.error,m=e.ok;if(typeof h=="string"&&h.trim()!==""||m===!1)return{kind:"error",summary:op(e),detail:pw(e)}}const s=PL(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const h=mw(e,e);return h?{kind:"table",label:null,columns:h.columns,rows:h.rows,total:h.rows.length,stats:h.constants,notes:[],asides:[]}:e.every(wa)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!zn(e))return{kind:"tree",value:e};const r=Object.entries(e);let i=null,a=null;for(const[h,m]of r){if(!Array.isArray(m))continue;const p=mw(m,e);if(p){(!i||p.rows.length>i.candidate.rows.length)&&(i={key:h,candidate:p});continue}m.length>0&&m.every(wa)&&(!a||m.length>a.items.length)&&(a={key:h,items:m})}const l=(i==null?void 0:i.key)??(a==null?void 0:a.key)??null,o=[],c=[],u=[];for(const[h,m]of r)if(h!==l){if($1(m)){c.push(m);continue}if(wa(m)){if(m==="")continue;o.push(IL(h,m,e));continue}m!==void 0&&u.push({label:un(h),value:m})}if(i)return{kind:"table",label:un(i.key),columns:i.candidate.columns,rows:i.candidate.rows,total:i.candidate.rows.length,stats:[...o,...i.candidate.constants],notes:c,asides:u};if(a)return{kind:"list",label:un(a.key),items:a.items,total:a.items.length,stats:o,notes:c,asides:u};const d=r.filter(([,h])=>Array.isArray(h)&&h.length===0);return d.length>0&&d.length===r.filter(([,h])=>Array.isArray(h)).length?{kind:"empty",note:`No ${d.map(([m])=>un(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,h])=>wa(h)||zn(h)||Array.isArray(h))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function pw(e){if(!zn(e))return null;const t=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return t.length===0?null:Object.fromEntries(t)}const nd=25,$L=3,cp=8,M1=6;function up(e,t=0){if(t>M1||ol(e)||$1(e))return 0;if(wa(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=up(r,t+1),s>=cp)return s;return s}if(zn(e)){let s=0;for(const r of Object.values(e))if(s+=up(r,t+1),s>=cp)return s;return s}return 0}function dp(e,t=0){if(t>M1)return!1;if(Array.isArray(e))return e.some(a=>dp(a,t+1));if(!zn(e))return!1;const s=e.artifactId??e.artifact_id;if(typeof s=="string"&&s.trim()!=="")return!0;const r=e.mime??e.mimeType??e.contentType,i=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof i=="string"&&i.trim()!==""?!0:Object.values(e).some(a=>dp(a,t+1))}function ML(e){if(dp(e))return!0;const t=Bx(e);switch(t.kind){case"table":return t.rows.length>0;case"list":return t.items.length>=$L;case"record":case"tree":return up(e)>=cp;default:return!1}}function rf(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function Wx(e){const t=rf(e);if(!t)return null;const s=rf(t.output)??t;if(typeof s.state!="string"||typeof s.stdout!="string"||typeof s.stderr!="string"||!(s.exitCode===null||typeof s.exitCode=="number"&&Number.isFinite(s.exitCode)))return null;const r=s===t?null:rf(t.input),i=(r==null?void 0:r.command)??s.command;return{command:typeof i=="string"?i:null,input:r,result:s}}function OL({text:e,label:t}){const[s,r]=f.useState("");return n.jsxs("span",{className:"wb-command-copy",children:[n.jsx("button",{className:"ui-btn",onClick:()=>{var i;if(r(""),!((i=navigator.clipboard)!=null&&i.writeText)){r("Copy unavailable; select the text to copy.");return}navigator.clipboard.writeText(e).then(()=>r("Copied"),()=>r("Copy failed; select the text to copy."))},children:t}),s&&n.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function af({title:e,text:t,error:s=!1}){return n.jsxs("section",{className:"wb-command-stream","data-error":s||void 0,children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("h4",{children:e}),n.jsx(OL,{text:t,label:`Copy ${e.toLowerCase()}`})]}),n.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:t})]})}function DL({value:e,children:t}){const{result:s,command:r,input:i}=e,a=s.state==="completed"&&s.exitCode!==null&&s.exitCode!==0,l=typeof s.signal=="string"&&s.signal?s.signal:null,o=s.state==="completed"&&s.exitCode===0,c=Object.fromEntries(Object.entries(s).filter(([d,h])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(d)&&h!==null&&h!==void 0&&h!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(d=>typeof d=="string"):[];return n.jsxs("div",{className:"wb-command-result",children:[n.jsxs("div",{className:"wb-command-bar",children:[n.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:a?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&n.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&n.jsxs("span",{className:"mono",children:["Signal ",l]}),n.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&n.jsx(af,{title:"Command",text:r}),s.state==="output-limit"&&n.jsx("p",{className:"wb-fail",children:"Output limit reached. The command was stopped and the captured output may be incomplete."}),s.state==="timed-out"&&n.jsx("p",{className:"wb-fail",children:"The command exceeded its time limit. Output below may be partial."}),s.state==="cancelled"&&n.jsx("p",{className:"wb-note",children:"The command was cancelled. Completed changes were not undone."}),s.stdout?n.jsx(af,{title:"Output",text:s.stdout}):n.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?n.jsx(af,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"File export errors"}),u.map((d,h)=>n.jsx("p",{className:"wb-fail",children:d},h))]}),t,(Object.keys(c).length>0||i!==null)&&n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Execution details"}),n.jsx("pre",{children:In({...c,...i?{input:i}:{}})})]})]})}const Lc=2,gw=64;function _L({props:e}){const[t,s]=f.useState(!1),r=Wx(e.value),i=LL((r==null?void 0:r.result)??e.value),a=f.useMemo(()=>Bx(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return n.jsxs("div",{children:[!r&&n.jsx(xw,{files:i}),t?n.jsx("pre",{className:"ui-code",children:In(e.value)}):r?n.jsx(DL,{value:r,children:i.length>0&&n.jsxs("section",{children:[n.jsx("h4",{children:"Generated files"}),n.jsx(xw,{files:i})]})}):i.length?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"Tool details"}),n.jsx(vw,{shape:a})]}):n.jsx(vw,{shape:a}),n.jsx("div",{className:"wb-row-end wb-section",children:n.jsx("button",{className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>s(l=>!l),"aria-pressed":t,children:t?"Readable":"Raw JSON"})})]})}function LL(e){const t=e&&typeof e=="object"&&"artifacts"in e?e.artifacts:null;return Array.isArray(t)?t.filter(s=>s&&typeof s.id=="string"&&/^[0-9a-f-]{36}$/i.test(s.id)&&typeof s.filename=="string"):[]}function xw({files:e}){return e.length?n.jsx("div",{className:"wb-artifacts",children:e.map(t=>{var s;return n.jsxs("div",{children:[["image/png","image/jpeg","image/gif","image/webp"].includes(t.mime??"")?n.jsx(FL,{file:t}):null,n.jsx("a",{className:"ui-btn",href:`/api/artifacts/${encodeURIComponent(t.id)}/download`,download:!0,children:(s=t.mime)!=null&&s.startsWith("image/")?`Download ${t.filename}`:t.filename})]},t.id)})}):null}function FL({file:e}){const[t,s]=f.useState(!1);return t?n.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):n.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function vw({shape:e}){switch(e.kind){case"error":return n.jsxs("div",{children:[n.jsx("p",{className:"wb-fail",role:"status",children:e.summary}),e.detail===null?null:n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:"What came back with it"}),n.jsx("div",{className:"wb-tree",children:To(e.detail,1)})]})]});case"empty":return n.jsxs("div",{children:[n.jsx(lf,{stats:e.stats}),n.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const t=KL(e.columns,e.rows);return n.jsxs("div",{children:[n.jsx(lf,{stats:e.stats}),n.jsx(of,{notes:e.notes}),t?n.jsx(VL,{label:e.label,plan:t,rows:e.rows,total:e.total}):n.jsx(UL,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),n.jsx(cf,{asides:e.asides})]})}case"list":return n.jsxs("div",{children:[n.jsx(lf,{stats:e.stats}),n.jsx(of,{notes:e.notes}),e.label?n.jsx("h4",{className:"wb-sub",children:e.label}):null,n.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((t,s)=>n.jsx("li",{children:zt(t,"text",null)},s))}),e.total>100?n.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,n.jsx(cf,{asides:e.asides})]});case"record":return n.jsxs("div",{children:[n.jsx(of,{notes:e.notes}),n.jsx(zL,{pairs:e.pairs}),n.jsx(cf,{asides:e.asides})]});default:return n.jsx("div",{className:"wb-tree",children:To(e.value,0)})}}function lf({stats:e}){return e.length===0?null:n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.map(t=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:t.label}),n.jsx("div",{className:"ui-stat-v",children:Hx(t.value,t.type,t.currency)})]},t.label))})}const jw=200;function of({notes:e}){if(e.length===0)return null;const t=e.filter(r=>r.length<=jw),s=e.filter(r=>r.length>jw);return n.jsxs(n.Fragment,{children:[t.map(r=>n.jsx("p",{className:"wb-note",children:r},r)),s.length>0?n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:s.length===1?"A note that came with this result":`${s.length} notes that came with this result`}),s.map(r=>n.jsx("p",{className:"wb-note",children:r},r))]}):null]})}function zL({pairs:e}){return e.length===0?n.jsx("p",{className:"wb-note",children:"Nothing to show."}):n.jsx("dl",{className:"ui-kv",children:e.map(t=>n.jsxs("div",{className:"contents",children:[n.jsx("dt",{children:t.label}),n.jsx("dd",{className:t.type==="text"?void 0:"tnum",children:Hx(t.value,t.type,t.currency)})]},t.label))})}function cf({asides:e}){return e.length===0?null:n.jsx("div",{className:"wb-section",children:e.map(t=>n.jsxs("details",{className:"wb-aside",children:[n.jsx("summary",{children:t.label}),n.jsx("div",{className:"wb-tree",children:To(t.value,1)})]},t.label))})}function UL({label:e,columns:t,rows:s,total:r}){const[i,a]=f.useState(!1),l=r<=nd+5?r:nd,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:t.map(c=>n.jsx("th",{className:D1(c.type)?"num":void 0,children:c.label},c.key))})}),n.jsx("tbody",{children:o.map((c,u)=>n.jsx("tr",{children:t.map(d=>n.jsx(GL,{value:c[d.key],column:d},d.key))},u))})]})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}const BL=/^(title|name|headline|subject|label|heading)$/i,WL=/^(url|link|href|uri|permalink)$/i;function sd(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function HL(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function O1(e,t=48){try{const s=new URL(e),r=s.pathname==="/"?"":s.pathname,i=`${s.hostname.replace(/^www\./,"")}${r}${s.search}`;return i.length>t?`${i.slice(0,t-1)}…`:i}catch{return e.length>t?`${e.slice(0,t-1)}…`:e}}function Fc(e,t){const s=e.map(r=>r[t]).filter(r=>typeof r=="string"&&r.trim()!=="");return s.length===0?0:s.reduce((r,i)=>r+i.length,0)/s.length}function KL(e,t){if(t.length===0)return null;const s=e.filter(d=>d.type==="text"),r=s.find(d=>WL.test(d.key)&&t.some(h=>sd(h[d.key])))??s.find(d=>{const h=t.map(m=>m[d.key]).filter(m=>!ol(m));return h.length>0&&h.filter(sd).length/h.length>=.6});if(!r)return null;const i=s.filter(d=>d.key!==r.key),a=i.find(d=>BL.test(d.key))??i.find(d=>Fc(t,d.key)>0);if(!a)return null;const o=[...i.filter(d=>d.key!==a.key)].sort((d,h)=>Fc(t,h.key)-Fc(t,d.key)),c=o[0]&&Fc(t,o[0].key)>40?o[0]:null,u=e.filter(d=>d.key!==r.key&&d.key!==a.key&&d.key!==(c==null?void 0:c.key)).map(d=>d.key);return{url:r.key,title:a.key,description:(c==null?void 0:c.key)??null,meta:u}}function VL({label:e,plan:t,rows:s,total:r}){const[i,a]=f.useState(!1),l=r<=nd+5?r:nd,o=i?s:s.slice(0,l);return n.jsxs("div",{children:[e?n.jsx("h4",{className:"wb-sub",children:e}):null,n.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const d=c[t.url],h=sd(d)?d.trim():null,m=typeof c[t.title]=="string"&&c[t.title].trim()!==""?c[t.title]:h?O1(h):"Untitled",p=t.description&&typeof c[t.description]=="string"?c[t.description]:null,g=h?HL(h):null,y=t.meta.map(b=>c[b]).filter(b=>!ol(b)&&typeof b!="object").map(b=>String(b)).filter(b=>g===null||b.replace(/^www\./,"")!==g);return n.jsxs("li",{className:"wb-record",children:[h?n.jsx("a",{className:"wb-record-title",href:h,target:"_blank",rel:"noopener noreferrer",children:m}):n.jsx("span",{className:"wb-record-title",children:m}),n.jsxs("div",{className:"wb-record-meta",children:[g?n.jsx("span",{className:"wb-record-host",title:h??void 0,children:g}):null,y.map((b,x)=>n.jsx("span",{children:b.length>60?`${b.slice(0,59)}…`:b},x))]}),p?n.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?n.jsxs("p",{className:"wb-note wb-note-row",children:[n.jsxs("span",{children:["Showing ",o.length," of ",r]}),n.jsxs("button",{className:"ui-btn",onClick:()=>a(!0),children:["Show all ",r]})]}):null]})}function GL({value:e,column:t}){if(ol(e))return n.jsx("td",{className:"wb-cell-soft",children:"—"});if(sd(e)){const i=e.trim();return n.jsx("td",{className:"wb-cell-link",children:n.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",title:i,children:O1(i)})})}if(e!==null&&typeof e=="object"){const i=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return n.jsx("td",{className:"wb-cell-soft",title:In(e),children:i})}const s=Hx(e,t.type,t.currency),r=s.length>gw?`${s.slice(0,gw-1)}…`:s;return n.jsx("td",{className:D1(t.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function D1(e){return e==="number"||e==="currency"}function Hx(e,t,s){return e==null?"—":t==="boolean"?e?"yes":"no":zt(e,t==="text"?"text":t,s)}function To(e,t){if(e===null)return n.jsx("span",{className:"wb-tree-null",children:"null"});if(e===void 0)return n.jsx("span",{className:"wb-tree-null",children:"—"});if(typeof e=="number")return n.jsx("span",{className:"wb-tree-num",children:e});if(typeof e=="boolean")return n.jsx("span",{className:"wb-tree-bool",children:e?"true":"false"});if(typeof e=="string")return n.jsx("span",{children:e===""?n.jsx("em",{className:"wb-tree-null",children:"empty"}):e});if(Array.isArray(e)){if(e.length===0)return n.jsx("span",{className:"wb-tree-null",children:"none"});const i=n.jsxs("div",{className:"wb-tree-branch",children:[e.slice(0,50).map((a,l)=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[l,". "]}),To(a,t+1)]},l)),e.length>50?n.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return t>=Lc?n.jsx(yw,{summary:`${e.length} items`,open:t===Lc,children:i}):i}const s=Object.entries(e);if(s.length===0)return n.jsx("span",{className:"wb-tree-null",children:"empty"});const r=n.jsx("div",{className:t===0?void 0:"wb-tree-branch",children:s.map(([i,a])=>n.jsxs("div",{children:[n.jsxs("span",{className:"wb-tree-key",children:[un(i),": "]}),To(a,t+1)]},i))});return t>=Lc?n.jsx(yw,{summary:`${s.length} fields`,open:t===Lc,children:r}):r}function yw({summary:e,open:t,children:s}){return n.jsxs("details",{open:t,children:[n.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function YL({props:e}){const t=e.groups.every(s=>s.rows.length===0);return n.jsxs("div",{children:[e.summary.length>0?n.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>n.jsxs("div",{children:[n.jsx("div",{className:"ui-stat-k",children:s.label}),n.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:zt(s.value,s.unit,s.currency)})]},s.label))}):null,t?n.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>n.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?n.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,n.jsx("div",{className:"ui-table-wrap",children:n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:e.columns.map(i=>n.jsx("th",{className:_1(i.type)?"num":void 0,"data-type":i.type,children:i.label},i.key))})}),n.jsx("tbody",{children:s.rows.map((i,a)=>n.jsx("tr",{children:i.map((l,o)=>{var c;return n.jsx(qL,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},a))})]})})]},s.label??r))]})}function qL({cell:e}){const t=zt(e.value,e.type,e.currency);return e.bar?n.jsx("td",{className:"num",children:n.jsxs("div",{className:"wb-row wb-row-end",children:[n.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t,children:n.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),n.jsx("span",{className:"tnum",children:t})]})}):n.jsx("td",{className:_1(e.type)?"num":void 0,"data-type":e.type,title:t.length>40?t:void 0,children:t})}function _1(e){return e==="number"||e==="currency"||e==="percent"}const ww={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun","partly-cloudy":"partly-cloudy",cloud:"cloud",rain:"rain",drizzle:"drizzle",snow:"snow",storm:"storm",fog:"fog",wind:"wind","moon-clear":"moon-clear"};function qo(e){return(e&&Object.prototype.hasOwnProperty.call(ww,e)?ww[e]:void 0)??"dot"}function bw(e,t){return(e??[]).filter(s=>s.place===t).map((s,r)=>({page:s,index:r})).sort((s,r)=>(s.page.order??0)-(r.page.order??0)||s.index-r.index).map(s=>s.page)}const rd="buddi:plugin-pages-changed";function QL(){window.dispatchEvent(new Event(rd))}function L1(e=!1){const[t,s]=f.useState([]);return f.useEffect(()=>{if(e)return;let r=!1;const i=()=>{Promise.resolve().then(()=>T.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};i();const a=()=>{document.visibilityState==="visible"&&i()};return window.addEventListener(rd,i),document.addEventListener("visibilitychange",a),()=>{r=!0,window.removeEventListener(rd,i),document.removeEventListener("visibilitychange",a)}},[e]),{all:t,rail:bw(t,"rail"),settings:bw(t,"settings"),find:(r,i)=>t.find(a=>a.plugin===r&&a.id===i)}}let pu=null;typeof window<"u"&&window.addEventListener(rd,()=>{pu=null});function JL(){return pu??(pu=Promise.resolve().then(()=>T.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(pu=null,[]))),pu}function F1(e,t,s){return s==="settings"?ll(e,t):si(e,t)}function XL(e){const[t,s]=f.useState(null),r=e==null?void 0:e.plugin,i=e==null?void 0:e.page;return f.useEffect(()=>{if(!r||!i)return;let a=!1;return JL().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===i);a||s(o?{href:F1(r,i,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{a=!0}},[r,i]),t}function z1({props:e,layout:t,selected:s,onPick:r}){return e.tiles.length===0?n.jsx("p",{className:"wb-empty",children:e.empty}):n.jsx("ul",{className:"wb-tiles","data-notice":e.notice?"true":void 0,"data-layout":t&&t!=="grid"?t:void 0,style:t==="row"?{"--tiles-n":e.tiles.length}:void 0,children:e.tiles.map((i,a)=>n.jsx(ZL,{tile:i,...r?{picked:a===s,onPick:()=>r(a)}:{}},`${a}-${i.label}`))})}function ZL({tile:e,picked:t,onPick:s}){const r=XL(e.link),i=[e.label,e.value,...e.lines].filter(l=>l!=="").join(", "),a=n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:n.jsx(ye,{name:qo(e.icon),size:22})}),e.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,n.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>n.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-tone":t?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":t?"true":void 0,"aria-pressed":t===!0,"aria-label":i,onClick:s,children:a})}):n.jsxs("li",{className:"wb-tile",children:[n.jsx("span",{className:"sr-only",children:i}),n.jsxs(ks,{tone:e.tone==="neutral"?void 0:e.tone,children:[a,r?n.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const sa=760,uf=400,At={top:18,right:18,bottom:36,left:66},eF=5;function tF({props:e}){const{points:t,referenceLines:s,unit:r,currency:i}=e;if(t.length===0)return n.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const a=[...t.map(w=>w.y),...s.map(w=>w.value)],l=Math.min(...a),o=Math.max(...a),c=o-l||Math.abs(o)||1,u=l-c*.08,d=o+c*.08,h=sa-At.left-At.right,m=uf-At.top-At.bottom,p=w=>At.left+(t.length===1?h/2:w/(t.length-1)*h),g=w=>At.top+m-(w-u)/(d-u)*m,y=Qu(l,o,4),b=sF(t.map(w=>w.y),e.mark),x=e.shadeBelow===null?[]:rF(t.map(w=>w.y),e.shadeBelow),v=t.map((w,S)=>`${S===0?"M":"L"}${p(S)},${g(w.y)}`).join(" "),j=w=>zt(w,r,i);return n.jsxs("div",{children:[e.label?n.jsx("p",{className:"ui-panel-sub",children:e.label}):null,n.jsxs("div",{className:"wb-chart-layout",children:[n.jsx("div",{className:"wb-chart-plot",children:n.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${sa} ${uf}`,role:"img","aria-label":nF(e,j),preserveAspectRatio:"xMidYMid meet",children:[x.map(w=>n.jsx("rect",{className:"wb-chart-breach",x:p(w.from),width:Math.max(2,p(w.to)-p(w.from)),y:At.top,height:m},`band-${w.from}`)),y.map(w=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-grid",x1:At.left,x2:sa-At.right,y1:g(w),y2:g(w)}),n.jsx("text",{x:At.left-8,y:g(w)+4,textAnchor:"end",children:j(w)})]},`tick-${w}`)),s.map(w=>n.jsxs("g",{children:[n.jsx("line",{className:"wb-chart-floor",x1:At.left,x2:sa-At.right,y1:g(w.value),y2:g(w.value)}),n.jsxs("text",{x:sa-At.right,y:g(w.value)-6,textAnchor:"end",children:[w.label," ",j(w.value)]})]},`rule-${w.label}`)),n.jsx("line",{className:"wb-chart-axis",x1:At.left,x2:At.left,y1:At.top,y2:At.top+m}),n.jsx("line",{className:"wb-chart-axis",x1:At.left,x2:sa-At.right,y1:At.top+m,y2:At.top+m}),n.jsx("path",{className:"wb-chart-series",d:v}),b!==null?n.jsxs("g",{children:[n.jsx("circle",{className:"wb-chart-min",cx:p(b),cy:g(t[b].y),r:4.5}),n.jsx("text",{x:p(b),y:g(t[b].y)+20,textAnchor:"middle",children:j(t[b].y)})]}):null,iF(t.length).map(w=>n.jsx("text",{x:p(w),y:uf-10,textAnchor:"middle",children:Xm(t[w].x)},`x-${w}`))]})}),e.events.length>0?n.jsxs("aside",{className:"wb-chart-events",children:[n.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),n.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((w,S)=>n.jsxs("li",{className:"wb-chart-event",children:[n.jsxs("span",{children:[n.jsx("span",{className:"wb-chart-event-day",children:Xm(w.at)}),w.label]}),w.amount===null?null:n.jsx("span",{className:w.amount<0?"tnum critical":"tnum good",children:zt(w.amount,r,i)})]},`${w.at}-${w.label}-${S}`))})]}):null]})]})}function nF(e,t){const s=e.points.map(l=>l.y),r=e.points[0],i=e.points[e.points.length-1],a=e.referenceLines.map(l=>`${l.label} at ${t(l.value)}`).join(", ");return[`${e.points.length} points from ${r==null?void 0:r.x} to ${i==null?void 0:i.x}`,`low ${t(Math.min(...s))}, high ${t(Math.max(...s))}`,a].filter(Boolean).join("; ")}function sF(e,t){if(!t||e.length===0)return null;let s=0;for(let r=1;r<e.length;r+=1)(t==="min"?e[r]<e[s]:e[r]>e[s])&&(s=r);return s}function rF(e,t){const s=[];let r=null;return e.forEach((i,a)=>{i<t?r===null&&(r=a):r!==null&&(s.push({from:r,to:a}),r=null)}),r!==null&&s.push({from:r,to:e.length-1}),s}function iF(e,t=eF){if(e<=0)return[];if(e<=t)return[...Array(e).keys()];const s=e-1,r=new Set;for(let i=0;i<t;i+=1)r.add(Math.round(i/(t-1)*s));return[...r].sort((i,a)=>i-a)}const Xn=e=>e,hp={timeseries:Xn(tF),table:Xn(YL),bars:Xn(WO),keyvalue:Xn(mL),tiles:Xn(z1),document:Xn(w_),diff:Xn(qO),terminal:Xn(vL),image:Xn(fL),preview:Xn(wL),envelope:Xn(oL),structured:Xn(_L)},aF="structured";function lF(e){return(id(e)?hp[e]:void 0)??hp[aF]}function id(e){return Object.prototype.hasOwnProperty.call(hp,e)}function oF({renderer:e,props:t,timezone:s,onDecided:r}){const i=lF(e),l=id(e)?t:{value:t};return n.jsx(i,{props:l,timezone:s,onDecided:r})}function cF({profile:e,onChange:t}){return n.jsxs("div",{className:"wb-prof","data-testid":"agent-profile",children:[n.jsx("p",{className:"wb-prof-lead",children:e.description}),n.jsxs("div",{className:"wb-prof-tags",children:[e.isDefault?n.jsx(df,{children:"Opens by default"}):null,n.jsx(df,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>n.jsx(df,{title:`A surface command that asks for "${s}" lands on this agent.`,children:un(s)},s))]}),e.available?null:n.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[n.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>n.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),n.jsx(Tl,{title:"How it works with you",note:"Live decisions stay in the conversation; this page explains the standing rules.",children:n.jsxs("ul",{className:"wb-prof-list",children:[n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name",children:"Quick questions"}),n.jsx("span",{className:"wb-prof-row-desc",children:"When it knows the likely answers, it can show one-tap choices in the dashboard and Telegram. You can still write a different answer when the question allows it."})]}),n.jsx("span",{className:"wb-prof-auto",children:"Answers only"})]}),n.jsxs("li",{className:"wb-prof-row","data-gated":"true",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name",children:"Action approvals"}),n.jsx("span",{className:"wb-prof-row-desc",children:"A request to send, spend, publish or otherwise affect the world appears in the conversation with the exact action. Answering a question never approves it."})]}),n.jsxs("span",{className:"wb-prof-gate",children:[n.jsx(U1,{}),"Exact action"]})]})]})}),n.jsx(Tl,{title:"What it can do",note:uF(e),tone:e.gatedCount>0?"warning":void 0,children:e.tools.length===0?n.jsx("p",{className:"wb-prof-empty",children:"No tools at all. It answers from the conversation and from what it remembers, and it can change nothing."}):[...e.tools].sort((s,r)=>+(r.gated>0)-+(s.gated>0)).map(s=>n.jsx(dF,{family:s},s.family))}),n.jsx(Tl,{title:"What it runs on",children:n.jsxs("dl",{className:"wb-prof-kv",children:[n.jsx(Rl,{label:"Provider",children:e.engine.provider}),n.jsx(Rl,{label:"Model",children:n.jsx("span",{className:"mono",children:e.engine.model})}),n.jsxs(Rl,{label:"Credential",children:[e.engine.credentialKind," from"," ",n.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),n.jsxs(Rl,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),n.jsx(Rl,{label:"Language",children:gF(e.engine.language)})]})}),e.skills.length>0?n.jsx(Tl,{title:"What it has read",note:`${e.skills.length} ${e.skills.length===1?"skill":"skills"}, composed into every run`,children:n.jsx("ul",{className:"wb-prof-list",children:e.skills.map(s=>n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name mono",children:s.name}),s.description?n.jsx("span",{className:"wb-prof-row-desc",children:s.description}):null]}),n.jsxs("span",{className:"wb-prof-row-side",title:s.file,children:[s.scope==="private"?"its own":"shared"," · ",s.provenance]})]},s.file))})}):null,e.delegates.length>0?n.jsx(Tl,{title:"Who it can hand work to",note:"A colleague's tools are reached through the colleague, never held here",children:n.jsx("ul",{className:"wb-prof-list",children:e.delegates.map(s=>n.jsxs("li",{className:"wb-prof-row",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsxs("span",{className:"wb-prof-row-name mono",children:["@",s.handle]}),n.jsx("span",{className:"wb-prof-row-desc",children:s.description})]}),n.jsx("span",{className:"wb-prof-row-side",children:s.available?s.name:`${s.name} · cannot run`})]},s.id))})}):null,n.jsxs("footer",{className:"wb-prof-foot",children:[n.jsx("p",{className:"wb-prof-note",children:e.note}),n.jsx("p",{className:"wb-prof-file mono",title:e.file,children:e.file}),e.changeVia&&t?n.jsxs("button",{className:"ui-btn","data-testid":"agent-profile-change",title:e.changeVia.prompt,onClick:()=>t({agentId:e.changeVia.agentId,prompt:e.changeVia.prompt}),children:["Ask @",e.changeVia.handle," to change this"]}):null]})]})}function uF(e){if(e.toolCount===0)return"Nothing. This agent holds no tools.";const t=`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`;if(e.gatedCount===0)return`${t}, every one of them running without asking you. None of them can send, spend or write to the world.`;const s=e.gatedCount===1?"one of them stops and waits for you":`${e.gatedCount} of them stop and wait for you`;return`${t}, and ${s}.`}function dF({family:e}){const t=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return n.jsxs("section",{className:"wb-prof-family",children:[n.jsxs("h4",{className:"wb-prof-family-head",children:[n.jsx("span",{className:"wb-prof-family-name",children:un(e.family)}),n.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),n.jsx("ul",{className:"wb-prof-list",children:t.map(s=>n.jsx(hF,{tool:s},s.name))})]})}function hF({tool:e}){return n.jsxs("li",{className:"wb-prof-row","data-gated":e.gated?"true":void 0,"data-testid":"agent-profile-tool",children:[n.jsxs("span",{className:"wb-prof-row-main",children:[n.jsx("span",{className:"wb-prof-row-name mono",children:pF(e.name)}),n.jsx("span",{className:"wb-prof-row-desc","data-clamp":"true",title:e.description,children:e.description})]}),e.gated?n.jsxs("span",{className:"wb-prof-gate",title:"The call is recorded and waits; nothing happens until you approve it.",children:[n.jsx(U1,{}),"Needs your approval"]}):n.jsx("span",{className:"wb-prof-auto",title:mF(e.tier),children:fF(e.tier)})]})}function fF(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function mF(e){return e==="auto"?"Called during a run without asking you. It reads, or records something you can see.":`Tier "${e}" does not execute in this build; a call to it is refused.`}function pF(e){const t=e.split(".");return(t[t.length-1]??e).replace(/_/g," ")}function gF(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Tl({title:e,note:t,tone:s,children:r}){return n.jsxs("section",{className:"wb-prof-section",children:[n.jsx("h3",{className:"wb-prof-title",children:e}),t?n.jsx("p",{className:"wb-prof-note-lead","data-tone":s,children:t}):null,r]})}function Rl({label:e,children:t}){return n.jsxs(n.Fragment,{children:[n.jsx("dt",{className:"wb-prof-k",children:e}),n.jsx("dd",{className:"wb-prof-v",children:t})]})}function df({children:e,title:t}){return n.jsx("span",{className:"wb-prof-tag",title:t,children:e})}function U1(){return n.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 14 14","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"2.8",y:"6",width:"8.4",height:"6.2",rx:"1.4"}),n.jsx("path",{d:"M4.8 6V4.4a2.2 2.2 0 0 1 4.4 0V6"})]})}const kw=16e3,xF=10*6e4,vF="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",B1="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function jF(){const e=window;return e.AudioContext??e.webkitAudioContext}function yF(e){const t=e&&typeof e=="object"&&"name"in e?String(e.name):"";return t==="NotAllowedError"||t==="SecurityError"||t==="PermissionDeniedError"?vF:t==="NotFoundError"||t==="DevicesNotFoundError"?"No microphone was found on this computer.":t==="NotReadableError"?"The microphone is in use by another app.":B1}async function wF(e){var c;const t=jF();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!t)throw Object.assign(new Error(B1),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new t,i=r.createMediaStreamSource(s),a=r.createScriptProcessor(4096,1,1),l=[];a.onaudioprocess=u=>{const d=u.inputBuffer.getChannelData(0);l.push(new Float32Array(d));let h=0;for(let m=0;m<d.length;m++)h+=d[m]*d[m];e(Math.min(1,Math.sqrt(h/d.length)*6))},i.connect(a),a.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{a.onaudioprocess=null;try{i.disconnect(),a.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),SF(kF(bF(l),u,kw),kw)},cancel:o}}function bF(e){const t=new Float32Array(e.reduce((r,i)=>r+i.length,0));let s=0;for(const r of e)t.set(r,s),s+=r.length;return t}function kF(e,t,s){if(t<=s)return e;const r=t/s,i=new Float32Array(Math.floor(e.length/r));for(let a=0;a<i.length;a++){const l=Math.floor(a*r),o=Math.min(e.length,Math.floor((a+1)*r));let c=0;for(let u=l;u<o;u++)c+=e[u];i[a]=o>l?c/(o-l):0}return i}function SF(e,t){const s=new ArrayBuffer(44+e.length*2),r=new DataView(s),i=(a,l)=>{for(let o=0;o<l.length;o++)r.setUint8(a+o,l.charCodeAt(o))};i(0,"RIFF"),r.setUint32(4,36+e.length*2,!0),i(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,"data"),r.setUint32(40,e.length*2,!0);for(let a=0;a<e.length;a++){const l=Math.max(-1,Math.min(1,e[a]));r.setInt16(44+a*2,Math.round(l<0?l*32768:l*32767),!0)}return new Blob([s],{type:"audio/wav"})}const fp="buddi.readAloud";function W1(){try{return window.localStorage.getItem(fp)==="on"}catch{return!1}}function H1(e){try{e?window.localStorage.setItem(fp,"on"):window.localStorage.removeItem(fp)}catch{}}let Ds=null,ql=null,Ro=0,mp=null;const pp=new Set;function ad(e){mp!==e&&(mp=e,pp.forEach(t=>t()))}function NF(){return mp}function CF(e){return pp.add(e),()=>pp.delete(e)}function K1(e){return cl(),ad(e),Ro}function Sw(e){return e===Ro}function cl(){Ro++,Ds&&(Ds.pause(),Ds.removeAttribute("src")),ql&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(ql),ql=null,ad(null)}async function EF(e,t,s=null){var i;const r=K1(s);try{const a=await fetch(e,{credentials:"same-origin"});if(!a.ok)throw new Error(`The spoken reply could not be fetched (${a.status}).`);const l=new Blob([await a.arrayBuffer()],{type:t});if(r!==Ro)return;Ds||(Ds=new Audio,(i=Ds.addEventListener)==null||i.call(Ds,"ended",()=>ad(null))),ql=URL.createObjectURL(l),Ds.src=ql,await Ds.play()}catch(a){throw r===Ro&&ad(null),a}}const AF=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function V1(e){return AF.has(e.toLowerCase().split(";")[0].trim())}function Nw(e){if(e===null||!Number.isFinite(e)||e<0)return"–:––";const t=Math.floor(e);return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function G1({artifactId:e,name:t,mime:s,sizeBytes:r}){const i=f.useRef(null),a=f.useRef(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),[d,h]=f.useState(!1),[m,p]=f.useState(0),[g,y]=f.useState(null);f.useEffect(()=>()=>{var v;(v=i.current)==null||v.pause(),a.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(a.current)},[]);const b=async()=>{const v=i.current;if(v){if(l){v.pause();return}cl(),h(!1);try{if(!a.current){u(!0);const j=await fetch(ri(e),{credentials:"same-origin"});if(!j.ok)throw new Error(String(j.status));a.current=URL.createObjectURL(new Blob([await j.arrayBuffer()],{type:s})),v.src=a.current}await v.play()}catch{h(!0)}finally{u(!1)}}},x=d?"Could not play. Download it instead.":`${Nw(m)} / ${Nw(g)}`;return n.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":l?"true":void 0,children:[n.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":l?`Pause ${t}`:`Play ${t}`,disabled:c,onClick:()=>void b(),children:n.jsx(ye,{name:l?"pause":"play",size:14})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:t,children:t}),n.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[c?"Loading…":x,!d&&$n(r)?` · ${$n(r)}`:""]})]}),n.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:ri(e),download:t,"aria-label":`Download ${t}`,title:"Download",children:n.jsx(ye,{name:"download",size:14})}),n.jsx("audio",{ref:i,preload:"none",onPlay:()=>o(!0),onPause:()=>o(!1),onEnded:()=>{o(!1),p(0)},onTimeUpdate:v=>p(v.currentTarget.currentTime),onLoadedMetadata:v=>y(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null),onDurationChange:v=>y(Number.isFinite(v.currentTarget.duration)?v.currentTarget.duration:null)})]})}const hf=1e5,ff=200,mf=30;function Y1({artifactId:e,filename:t,mime:s,family:r,available:i=!0}){const[a,l]=f.useState(!1);return i?r==="image"&&!a?n.jsx("figure",{className:"file-preview file-preview-image",children:n.jsx("img",{src:xr(e),alt:t??"Image",onError:()=>l(!0)})}):r==="audio"&&V1(s)?n.jsx("div",{className:"file-preview file-preview-audio",children:n.jsx(G1,{artifactId:e,name:t??"Audio",mime:s})}):r==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:xr(e),type:"application/pdf","aria-label":t??"PDF",children:n.jsx(W,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?n.jsx(TF,{artifactId:e,filename:t,mime:s,family:r}):n.jsx(W,{children:"Preview not supported for this kind of file. Download it to open it."}):n.jsx(W,{children:"The file is no longer available; its record is kept."})}function TF({artifactId:e,filename:t,mime:s,family:r}){const[i,a]=f.useState("loading");if(f.useEffect(()=>{let o=!1;return a("loading"),fetch(xr(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||a({text:u.slice(0,hf),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>hf})}).catch(()=>{o||a("failed")}),()=>{o=!0}},[e]),i==="loading")return n.jsx("div",{className:"file-preview",children:n.jsx(ce,{children:"Loading preview…"})});if(i==="failed")return n.jsx(W,{children:"The preview could not be loaded. Download the file to open it."});const l=r==="table"&&(/csv|tab-separated/.test(s)||/\.(csv|tsv)$/i.test(t??""));return n.jsxs("div",{className:"file-preview",children:[l?n.jsx(IF,{text:i.text,delimiter:/tab|\.tsv$/i.test(s+(t??""))?" ":","}):n.jsx("pre",{className:"file-preview-text",children:i.text}),i.truncated?n.jsxs("p",{className:"muted",children:["Showing the first ",hf.toLocaleString()," characters. The download has the whole file."]}):null]})}function RF(e,t,s,r){const i=[];let a=[],l="",o=!1,c=!1,u=!1;const d=()=>{a.length<r?a.push(l):c=!0,l=""},h=()=>{d(),i.push(a),a=[]};let m=0;for(;m<e.length;m+=1){if(i.length>=s){u=e.slice(m).trim()!=="";break}const p=e[m];if(o){p==='"'?e[m+1]==='"'?(l+='"',m+=1):o=!1:l+=p;continue}if(p==='"'){o=!0;continue}if(p===t){d();continue}if(p!=="\r"){if(p===`
|
|
95
|
+
`){h();continue}l+=p}}return i.length<s&&(l!==""||a.length>0)&&h(),{rows:i,truncatedRows:u,truncatedCols:c}}function IF({text:e,delimiter:t}){const s=f.useMemo(()=>RF(e,t,ff+1,mf),[e,t]),[r,...i]=s.rows;if(!r)return n.jsx("p",{className:"muted",children:"The file is empty."});const a=Math.min(mf,s.rows.reduce((o,c)=>Math.max(o,c.length),0)),l=Array.from({length:a},(o,c)=>c);return n.jsxs("div",{className:"ui-table-wrap file-preview-table",children:[n.jsxs("table",{className:"ui-table",children:[n.jsx("thead",{children:n.jsx("tr",{children:l.map(o=>n.jsx("th",{children:r[o]??""},o))})}),n.jsx("tbody",{children:i.slice(0,ff).map((o,c)=>n.jsx("tr",{children:l.map(u=>n.jsx("td",{children:o[u]??""},u))},c))})]}),s.truncatedRows||s.truncatedCols?n.jsxs("p",{className:"muted",children:["Showing the first ",ff," rows",s.truncatedCols?` and ${mf} columns`:"",". The download has the whole file."]}):null]})}function PF({attachment:e}){const t=Ux(e.mime,e.filename),s=e.filename??"Untitled file";return n.jsxs("div",{className:"wb-artifact","data-family":t,"data-testid":"artifact-view",children:[n.jsx(Y1,{artifactId:e.artifactId,filename:e.filename??null,mime:e.mime,family:t}),n.jsxs("dl",{className:"ui-kv",children:[n.jsx("dt",{children:"Type"}),n.jsxs("dd",{children:[Ti[t],n.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Size"}),n.jsx("dd",{children:$n(e.sizeBytes)})]}):null,n.jsx("dt",{children:"Id"}),n.jsx("dd",{className:"mono",children:e.artifactId})]}),n.jsx("div",{className:"ui-toolbar","data-align":"end",children:n.jsx("a",{className:"ui-btn",href:ri(e.artifactId),download:s,children:"Download"})})]})}const Cw=80,$F=["query","path","url","dir"],MF=["message","task"];function Kx(e,t){const s=OF(t);if(!s)return null;const r=ra(s.command);if(r!==null){const l=ra(s.name);return zc(l===null?r:`${l}: ${r}`)}for(const l of $F){const o=ra(s[l]);if(o!==null)return zc(o)}const i=ra(s.action);if(i!==null){const l=MF.map(o=>ra(s[o])).find(o=>o!==null)??null;return zc(l===null?i:`${i} · ${l}`)}const a=Object.values(s).filter(l=>typeof l=="string");return a.length===1?zc(ra(a[0])):null}function ra(e){if(typeof e!="string")return null;const t=e.replace(/\s+/g," ").trim();return t===""?null:t}function zc(e){return e===null?null:e.length>Cw?`${e.slice(0,Cw-1)}…`:e}function OF(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const q1="owner.notify",nr=e=>typeof e=="string"&&e.trim()!==""?e:null;function DF(e){const t=e!==null&&typeof e=="object"?e:{};return{title:nr(t.title)??"(no title)",text:nr(t.text),urgency:nr(t.urgency)??"now",key:nr(t.key),link:nr(t.link)}}function Q1(e){if(e===null||typeof e!="object")return nr(e);const t=e;return nr(t.delivered)??nr(t.message)??nr(t.error)}function _F(e,t){if(!t||!e)return"critical";const s=e.toLowerCase();return/^(refused|not sent)/.test(s)?"critical":/^sent\b/.test(s)?"good":"warning"}const ii="agent.delegate";function LF(e){if(e===null||typeof e!="object")return null;const t=e,s=t.conversationId;if(typeof s!="string"||s==="")return null;const r=t.agentId??t.agent;return{conversationId:s,agentId:typeof r=="string"?r:"",runId:typeof t.runId=="string"?t.runId:null}}function FF(e){if(typeof e=="string")return e;if(e===null||typeof e!="object")return null;const t=e.text;return typeof t=="string"?t:null}const gp="canvas.show",Ew="canvas.clear",Aw=12;function Pa(e){return`${e.plugin}/${e.name}`}function zF(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=e.diff;return typeof t=="string"&&t.trim()!==""}function UF({messages:e,descriptors:t}){const s=new Map(t.filter(a=>a.renderer==="preview").map(a=>[a.tool,a]));if(s.size===0)return[];const r=new Map,i=[];for(const a of e)for(const l of a.blocks??[]){if(l.type==="tool_use"&&r.set(l.id,l.name),l.type!=="tool_result"||l.ok===!1)continue;const o=s.get(l.name||r.get(l.toolUseId)||"");if(!o)continue;const c=m1(o,J1(l.output)).props;c.target===null&&c.awaiting!==null&&i.push({...c.awaiting,at:a.at??null})}return i}function BF({messages:e,descriptors:t,awaiting:s,folded:r,served:i}){var u;const a=new Map(t.map(d=>[d.tool,d])),l=new Map;let o=[],c=0;for(const d of e)for(const h of d.blocks??[]){if(h.type==="tool_use"){if(l.set(h.id,{name:h.name,input:h.input,at:d.at??null}),h.name===gp){const w=HF(h.id,h.input,d.at??null);w&&o.push(w)}if(h.name===Ew&&(o=[]),h.name===ii){const w=LF(h.input);w&&o.push({id:h.id,tool:ii,title:"Delegation",renderer:"delegate",props:{...w,result:null},at:d.at??null,source:"delegate",substantial:!0})}continue}if(h.type!=="tool_result"||h.name===gp||h.name===Ew)continue;const m=l.get(h.toolUseId),p=d.at??(m==null?void 0:m.at)??null,g=h.name||(m==null?void 0:m.name)||"tool",y=o.find(w=>w.source==="delegate"&&w.id===h.toolUseId);if(y&&((u=h.delegation)==null?void 0:u.state)==="waiting"){y.props={...y.props,result:null,waiting:{approvalId:h.delegation.approvalId}},h.delegation.approvalId&&(y.tone="warning");continue}if(y){y.props={...y.props,result:{ok:h.ok,text:FF(h.ok?h.output:h.error??h.output),...h.ok&&td(h.output).length>0?{files:td(h.output)}:{}}},h.ok||(y.tone="critical");continue}const b=h.approval?vp(h):(s==null?void 0:s.get(h.toolUseId))??vp(h);if(b){o.push({id:h.toolUseId,tool:g,title:"Approval",renderer:"envelope",props:{approvalId:b},at:p,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(g))continue;if(g===q1){o.push({id:h.toolUseId,tool:g,title:"Message to you",renderer:"notify",props:{input:(m==null?void 0:m.input)??null,output:h.output??null,ok:h.ok!==!1},at:p,tone:h.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const x=J1(h.output);if(h.ok===!1){o.push({id:h.toolUseId,tool:g,title:Ws(g),renderer:"structured",props:{value:h.error??x??null,failed:!0},at:p,tone:"critical",source:"fallback",substantial:!1});continue}zF(x)&&(c+=1);const v=a.get(g);if(v){const w=m1(v,x),{renderer:S}=w;let{props:k}=w;if(S==="preview"){const N=k,C=N.target??(N.awaiting&&(i!=null&&i.has(Pa(N.awaiting)))?N.awaiting:null);if(C===null)continue;k={...N,target:C,awaiting:null};const I=Pa(C);o=o.filter(A=>!(A.source==="descriptor"&&A.renderer==="preview"&&A.props.target!==null&&Pa(A.props.target)===I))}o.push({id:h.toolUseId,tool:g,title:v.title??Ws(g),renderer:S,props:k,at:p,source:"descriptor",substantial:xp(S,k)});continue}const j={value:Wx(x)?{input:m==null?void 0:m.input,output:x}:x};KF("structured",j)&&o.push({id:h.toolUseId,tool:g,title:Ws(g),renderer:"structured",props:j,at:p,source:"fallback",substantial:xp("structured",j)})}for(const d of o)d.source==="descriptor"&&d.renderer==="preview"&&(d.props={...d.props,changes:c});return WF(o)}const Tw="forAgent";function J1(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(Tw in e))return e;const{[Tw]:t,...s}=e;return s}function WF(e){if(e.length<=Aw)return e;const t=e.length-Aw;return[...e.slice(0,t).filter(r=>r.source==="approval"),...e.slice(t)]}function HF(e,t,s){if(t===null||typeof t!="object")return null;const{renderer:r,title:i,data:a}=t,l=typeof r=="string"&&id(r)?r:"structured";return{id:e,tool:gp,title:typeof i=="string"&&i.trim()!==""?i:"Shown",renderer:l,props:l==="structured"&&!id(String(r))?{value:a}:a,at:s,substantial:!0,source:"canvas"}}function KF(e,t){const s=t??{};return!!(s.failed===!0||xp(e,t)||Bx(s.value).kind==="error")}function xp(e,t){const s=t??{};switch(e){case"timeseries":return Il(s.points)>0;case"bars":return Il(s.bars)>0;case"keyvalue":return Il(s.pairs)>0;case"tiles":return s.notice!==!0&&Il(s.tiles)>0;case"document":return!!s.text||!!s.src;case"diff":return!!s.diff;case"terminal":return!!s.output||!!s.command;case"image":return!!s.artifactId;case"preview":return!!s.target;case"envelope":return!0;case"table":return(Array.isArray(s.groups)?s.groups:[]).some(i=>Il(i.rows)>0);default:return Wx(s.value)?!0:s.failed===!0?!1:ML(s.value)}}function Il(e){return Array.isArray(e)?e.length:0}function vp(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const t of[e.error,e.output]){const s=Z1(t,0);if(s)return s}return null}function VF(e,t,s={}){var o,c;const r=e.flatMap(u=>u.blocks),i=r.find(u=>u.type==="tool_use"&&u.id===t);if((i==null?void 0:i.type)!=="tool_use")return null;const a=r.find(u=>u.type==="tool_result"&&u.toolUseId===t),l=(o=s.redactInputOf)!=null&&o.has(i.name)?X1(i.input):i.input;return{id:t,tool:i.name,title:Ws(i.name),renderer:"structured",props:{value:{input:l,...(a==null?void 0:a.type)==="tool_result"?{status:((c=a.approval)==null?void 0:c.state)??(a.ok?"completed":"failed"),output:a.output,...a.error?{error:a.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const GF=new Set(["value","text","password","secret","code"]);function X1(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const t={};for(const[s,r]of Object.entries(e))t[s]=GF.has(s)&&typeof r=="string"?"— withheld —":X1(r);return t}function Z1(e,t){if(t>3||e===null||typeof e!="object")return null;const s=e,r=s.reason,i=s.actionId??s.approvalId;if(typeof i=="string"&&i!==""&&(r===void 0||r==="approval-required"))return i;for(const a of Object.values(s)){const l=Z1(a,t+1);if(l)return l}return null}function Ws(e){const t=e.split(".");return t.length===1?un(e):t.map(s=>un(s)).join(" · ")}function sh({name:e,mime:t,sizeBytes:s,thumbnail:r,state:i,error:a,onOpen:l,onRemove:o,size:c="md"}){const u=Ux(t,e),d=[Ti[u],$n(s)].filter(Boolean).join(" · "),h=n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-file-visual","data-family":u,children:r?n.jsx("img",{src:r,alt:""}):n.jsx(Vx,{family:u})}),n.jsxs("span",{className:"wb-file-text",children:[n.jsx("span",{className:"wb-file-name",title:e,children:e}),n.jsx("span",{className:"wb-file-meta",children:i==="uploading"?"Uploading…":i==="failed"?"Upload failed":d})]})]});return n.jsxs("span",{className:"wb-file","data-size":c,"data-state":i,"data-thumb":r?"true":void 0,title:i==="failed"?a:void 0,children:[l?n.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:h}):n.jsx("span",{className:"wb-file-open",children:h}),o?n.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:n.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function Vx({family:e}){const t={width:20,height:20,viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"};switch(e){case"image":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),n.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),n.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return n.jsxs("svg",{...t,children:[n.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M11.5 2.5V7H16"}),n.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),n.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return n.jsxs("svg",{...t,children:[n.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M11.5 2.5V7H16"}),n.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return n.jsx("svg",{...t,children:n.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return n.jsx("svg",{...t,children:n.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),n.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return n.jsxs("svg",{...t,children:[n.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),n.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return n.jsxs("svg",{...t,children:[n.jsx("path",{d:"M6 2.5h5.5L16 7v9.5a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-13a1 1 0 0 1 1-1z"}),n.jsx("path",{d:"M11.5 2.5V7H16"})]})}}function YF(e,t,s){const r=Iw(e),i=Iw(t==null?void 0:t.input),a=ji(r==null?void 0:r.name)??ZF(ji(r==null?void 0:r.handle))??ji(r==null?void 0:r.agent)??ji(i==null?void 0:i.agent),l=typeof e=="string"?e.trim()||null:ji(r==null?void 0:r.text)??ji(r==null?void 0:r.note),o=Rw(r==null?void 0:r.durationMs)??Rw(r==null?void 0:r.elapsedMs),c=t!=null&&t.at?Date.parse(t.at):NaN,u=s?Date.parse(s):NaN,d=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:a,question:ji(i==null?void 0:i.task),answer:l,files:td(e),durationMs:o??d}}function qF(e,t){var r;let s=null;for(const i of e)for(const a of i.blocks??[])a.type==="tool_result"&&a.name===ii&&((r=a.delegation)==null?void 0:r.approvalId)===t&&(s=a.toolUseId);if(s===null)return null;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===s)return{input:a.input,at:i.at||null};return null}function QF({block:e,messages:t,answeredAt:s}){const r=YF(e.output,qF(t,e.actionId),s),i=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${JF(r.durationMs)}`].filter(a=>a!==null);return n.jsxs("div",{className:"wb-delegation-result","data-testid":"delegation-result",children:[i.length>0?n.jsx("p",{className:"wb-delegation-facts",children:i.join(" · ")}):null,r.question?n.jsx("blockquote",{className:"wb-delegation-question",children:r.question}):null,r.answer?n.jsx("div",{className:"wb-delegation-answer","data-testid":"delegation-answer",children:n.jsx(gr,{text:r.answer})}):n.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(a=>n.jsx("a",{role:"listitem",href:ri(a.artifactId),download:!0,children:n.jsx(sh,{name:a.filename??"Untitled file",mime:a.mime,sizeBytes:a.sizeBytes,thumbnail:zx(a.mime)?xr(a.artifactId):null,size:"sm"})},a.artifactId))}):null,n.jsx(Ct,{summary:"Raw JSON",children:n.jsx("pre",{className:"wb-approval-output mono",children:XF(e.output)})})]})}function JF(e){if(e<1e3)return`${Math.round(e)}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const s=Math.floor(t/60);return s<60?`${s}m ${String(t%60).padStart(2,"0")}s`:`${Math.floor(s/60)}h ${String(s%60).padStart(2,"0")}m`}function XF(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function ZF(e){return e===null?null:`@${e.replace(/^@/,"")}`}function ji(e){return typeof e=="string"&&e.trim()!==""?e:null}function Rw(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Iw(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const e4=1e3;function t4({messageId:e,text:t,onReadAloud:s}){const[r,i]=f.useState(!1),a=f.useRef(null),l=f.useSyncExternalStore(CF,NF)===e;f.useEffect(()=>()=>{a.current&&clearTimeout(a.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(t).then(()=>{i(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(!1),e4)},()=>{})};return n.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":r?"Copied":"Copy",title:r?"Copied":"Copy",onClick:o,children:n.jsx(ye,{name:r?"check":"copy",size:14})}),r?n.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":l?"Stop reading aloud":"Read aloud",title:l?"Stop reading aloud":"Read aloud","aria-pressed":l,onClick:()=>l?cl():s(e,t),children:n.jsx(ye,{name:l?"stop":"play",size:14})}):null]})}function n4(e){const t=s4(e);if(!t)return null;const s=pf(t.diff);if(s!==null)return{kind:"diff",diff:s};const r=pf(t.command),i=pf(t.plain),a=gf(t.exitCode);return r!==null&&(i!==null||a!==null||gf(t.pid)!==null)?{kind:"command",command:r,output:i,exitCode:a,elapsedMs:gf(t.elapsedMs)}:null}function pf(e){return typeof e=="string"&&e.trim()!==""?e:null}function gf(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function s4(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const Pw="offer:",eC="owner:interjection";function r4(e){return e===eC}function i4(e){if(typeof e!="string"||!e.startsWith(Pw))return null;const t=e.slice(Pw.length).trim();return t===""?null:t}function Gx({messages:e,live:t,now:s,onOpen:r,working:i=!1,partial:a=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:d,onOpenFile:h,onReadAloud:m,children:p,agentName:g,emptyHint:y,empty:b,plain:x=!1,workingLine:v,runs:j,onContinue:w}){var ue;const S=f.useRef(null);f.useEffect(()=>{var ie;(ie=S.current)==null||ie.scrollIntoView({block:"end"})},[e.length,t.length,i,a==null?void 0:a.text.length,a==null?void 0:a.thinking.length,!!p]);const k=a&&!a.settled&&(a.text!==""||a.thinking!==""),N=e.filter(ie=>(ie.blocks??[]).some(g4)),C=m4(N,j??[]),I=c??l??[],A=ie=>(o&&!c?I.find(ee=>ee.id===o):void 0)??I.find(ee=>ee.name===ie)??null,_=o?I.find(ie=>ie.id===o)??null:null,z=i||t.length>0,L=z||!!k,E=!!k&&a.text!=="",M=z&&!E,D=N.at(-1),U=(D==null?void 0:D.role)!=="assistant"||!!d,$=d??g??"Assistant",B=N.filter((ie,ee)=>{var X;return ee===0||(c?(((X=N[ee-1])==null?void 0:X.speaker)??null)!==(ie.speaker??null):N[ee-1].role!==ie.role)}),O=L&&!U?((ue=B.at(-1))==null?void 0:ue.id)??null:null,K=(j??[]).reduce((ie,ee)=>ie===null||(ee.startedAt??"")>(ie.startedAt??"")?ee:ie,null),G=(j??[]).some(ie=>ie.finishedAt===null),se=w&&!L&&!G&&D&&(K==null?void 0:K.stopped)==="max_turns"&&C.get(D.id)===K?D.id:null;return n.jsx(d1.Provider,{value:l??c??[],children:n.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[N.length===0&&t.length===0?b??n.jsx("p",{className:"wb-chat-empty",children:y}):null,N.map((ie,ee)=>{const X=ie.speaker??null,de=c?X==="owner"||X===null&&ie.role==="user":ie.role==="user",Ie=c&&X==="room",Se=c&&X&&X!=="owner"&&X!=="room"?c.find(oe=>oe.id===X)??null:null,we=N[ee-1],Ce=ee===0||(c?((we==null?void 0:we.speaker)??null)!==X:we.role!==ie.role);if(Ie)return n.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(ie.blocks??[]).filter(oe=>oe.type==="text").map((oe,Oe)=>n.jsx("span",{children:oe.text},Oe))},ie.id);const mt=(ie.blocks??[]).filter(oe=>oe.type==="approval_result");if(mt.length>0)return n.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:mt.map((oe,Oe)=>n.jsx(x4,{block:oe,messages:e,at:ie.at||null},Oe))},ie.id);const he=ie.role==="user"&&r4(X),Me=ie.role==="user"?i4(X):null;if(Me){const oe=(ie.blocks??[]).filter(Oe=>Oe.type==="text").map(Oe=>Oe.text).join(`
|
|
96
|
+
`);return n.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:n.jsx("div",{className:"wb-bubble wb-bubble-offer",title:oe,children:Me})},ie.id)}const Pe=c&&Se&&ie.role==="user"?d4(ie):null;if(Pe){const oe=N.slice(ee+1).find(Le=>Le.role==="assistant"&&Le.speaker&&Le.speaker!==Se.id),Oe=oe!=null&&oe.speaker?c.find(Le=>Le.id===oe.speaker):void 0;return n.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[n.jsxs("summary",{children:[Se.name," asked ",(Oe==null?void 0:Oe.name)??"a member",Pe.request?`: ${Pe.request.length>120?`${Pe.request.slice(0,119)}…`:Pe.request}`:""]}),Pe.request?n.jsx("p",{children:Pe.request}):null]},ie.id)}const Ye=C.get(ie.id)??null,Y=f4(ie,e),me=!de&&!he&&!x?h4(ie):"";return n.jsxs("div",{className:"wb-msg","data-role":de||he?"user":"assistant",children:[he?n.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,Ce&&!de&&!he?n.jsx($w,{name:Se?Se.name:g??"Assistant",face:Se??_??A(g),moving:M&&O===ie.id,children:Se&&u===Se.id?n.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Y.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Y.map(oe=>n.jsx("span",{role:"listitem",children:V1(oe.mime)?n.jsx(G1,{artifactId:oe.artifactId,name:oe.filename??"Untitled file",mime:oe.mime,sizeBytes:oe.sizeBytes}):n.jsx(sh,{name:oe.filename??"Untitled file",mime:oe.mime,sizeBytes:oe.sizeBytes,thumbnail:zx(oe.mime)?xr(oe.artifactId):null,...h?{onOpen:()=>h(oe)}:{}})},oe.artifactId))}):null,(ie.blocks??[]).map((oe,Oe)=>{const Le=o4(ie.blocks??[],Oe,e);if(Le==="inside")return null;if(Le)return n.jsx(c4,{refusals:Le.refusals},Oe);if(oe.type==="thinking")return x||oe.text.trim()===""?null:n.jsx(jp,{text:oe.text},Oe);if(oe.type==="text")return oe.text.trim()===""?null:de?n.jsx("div",{className:"wb-bubble",children:oe.text},Oe):n.jsx("div",{className:"wb-bubble","data-rich":"true",children:n.jsx(gr,{text:oe.text})},Oe);if(oe.type==="attachment")return null;if(oe.type==="tool_use"){if(x)return null;const Ue=Yx(e,oe.id),at=Ue?y4(Ue):null,Rt=!at&&oe.name===q1&&Ue?Q1(Ue.output):null;return n.jsx(yp,{label:at&&!(Ue!=null&&Ue.delegation)?`Approval · ${oe.name}`:Ws(oe.name),tool:oe.name,ok:(Ue==null?void 0:Ue.ok)??null,running:Ue===null,...at?{status:at.status,waiting:at.waiting,approval:!0}:Rt?{status:Rt}:{},gist:Kx(oe.name,oe.input),body:Ue?n4(Ue.output):null,opens:!0,onOpen:()=>r(oe.id)},Oe)}return null}),Ye?n.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[n.jsx("span",{children:p4(Ye)}),se===ie.id?n.jsx(R,{size:"sm",variant:"ghost","data-testid":"budget-continue",onClick:w,children:"Continue"}):null]}):null,me!==""?n.jsx(t4,{messageId:ie.id,text:me,onReadAloud:m}):null]},ie.id)}),L?n.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[U?n.jsx($w,{name:$,face:A($)??_,moving:M}):null,k&&a.thinking!==""&&!x?n.jsx(jp,{text:a.thinking,live:a.text==="",seconds:u4(a.thinkingStartedAt,a.textStartedAt??s)}):null,E?n.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[n.jsx(gr,{text:a.text}),n.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,i&&t.length===0&&!k?n.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[v??`${d??g??"The agent"} is working`,n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):null,t.map(ie=>n.jsx(yp,{label:Ws(ie.name),tool:ie.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-ie.startedAt)/1e3)),opens:!1,onOpen:()=>r(ie.toolUseId)},ie.toolUseId))]}):null,p,n.jsx("div",{ref:S})]})})}function $w({name:e,face:t,moving:s=!1,children:r}){const i=(t==null?void 0:t.picture)??null,a=c1(s?i:null);return n.jsxs("div",{className:"wb-msg-who","data-testid":"turn-head",children:[n.jsx("span",{className:"wb-msg-mark","data-moving":s?a&&i?"blob":"ring":void 0,children:s&&a&&i?n.jsx(eh,{state:"working",size:"sm",still:i,className:"wb-msg-blob"}):n.jsx(Es,{id:(t==null?void 0:t.id)??e,name:(t==null?void 0:t.name)??e,unavailable:t?!t.available:!1,...t?{face:t}:{}})}),n.jsx("span",{children:e}),r]})}function a4(e){var t,s;return((s=(t=/ may delegate to ([^;]*);/.exec(e)??/\(allowed: ([^)]*)\)/.exec(e))==null?void 0:t[1])==null?void 0:s.trim())||null}const l4="delegation refused:";function o4(e,t,s){const r=a=>{const l=e[a];if(!l||l.type!=="tool_use"||l.name!==ii)return null;const o=Yx(s,l.id);if(!o||o.ok!==!1)return null;const c=typeof o.error=="string"?o.error:String(o.error??"");if(!c.trimStart().startsWith(l4))return null;const u=l.input??{};return{target:typeof u.agent=="string"&&u.agent!==""?u.agent:"a colleague",message:c}};if(!r(t))return null;if(r(t-1))return"inside";const i=[];for(let a=t;;a+=1){const l=r(a);if(!l)break;i.push(l)}return i.length<2?null:{refusals:i}}function c4({refusals:e}){const[t,s]=f.useState(!1),r=e.map(o=>a4(o.message)).find(o=>o!==null)??null,i=e.map(o=>o.target),a=i.slice(0,3),l=`Delegation refused ${e.length} times: ${a.join(", ")}${i.length>a.length?", …":""}`+(r?` (allowed: ${r})`:"");return n.jsxs("div",{className:"wb-refusals","data-testid":"delegation-refusals","data-open":t||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":!1,"aria-expanded":t,onClick:()=>s(o=>!o),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:l}),n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]}),t?n.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>n.jsxs("div",{className:"wb-refusal",children:[n.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[n.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),n.jsxs("span",{className:"wb-tool-label",children:[Ws(ii)," · ",o.target]}),n.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),n.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function u4(e,t){return e===null?null:Math.max(0,Math.round((t-e)/1e3))}function jp({text:e,live:t=!1,seconds:s=null}){const[r,i]=f.useState(!1),a=t?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return n.jsxs("div",{className:"wb-thought","data-live":t||void 0,"data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>i(l=>!l),children:[t?n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}):n.jsx(ye,{name:"thought"}),n.jsx("span",{children:a}),n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]}),r?n.jsx("div",{className:"wb-thought-text",children:n.jsx(gr,{text:e})}):null]})}function d4(e){var r;const t=((r=(e.blocks??[]).find(i=>i.type==="text"))==null?void 0:r.text)??"",s=/You are a member of the group "[^"]*"\. @([\w-]+), the coordinator, asks you now:\n\n([\s\S]*?)(?:\n\nAnswer for the room|$)/.exec(t);return s?{handle:s[1],request:s[2].trim()}:null}function h4(e){return(e.blocks??[]).filter(t=>t.type==="text").map(t=>t.text.trim()).filter(t=>t!=="").join(`
|
|
97
|
+
|
|
98
|
+
`)}function f4(e,t){const s=[],r=new Set,i=a=>{r.has(a.artifactId)||(r.add(a.artifactId),s.push(a))};for(const a of e.blocks??[])if(a.type==="attachment"&&i(a),a.type==="tool_use"&&a.name===ii){const l=Yx(t,a.id);l!=null&&l.ok&&td(l.output).forEach(i)}return s}function m4(e,t){const s=t.filter(l=>l.startedAt!==null&&l.finishedAt!==null),r=(l,o)=>o.at!==""&&o.at>=l.startedAt&&o.at<=l.finishedAt,i=(l,o)=>l!==o&&l.startedAt>=o.startedAt&&l.finishedAt<=o.finishedAt&&(l.startedAt>o.startedAt||l.finishedAt<o.finishedAt),a=new Map;for(const l of s){if(l.stopped!=="max_turns"&&l.stopped!=="max_tokens"||l.noticed!==!0||l.runId===null)continue;let o=null;for(const c of e)c.role!=="assistant"||!r(l,c)||(o=c);o===null||s.some(c=>i(c,l)&&r(c,o))||a.has(o.id)||a.set(o.id,l)}return a}function p4(e){if(e.stopped==="max_tokens")return"Length limit reached · answer cut off";const t=e.turns;return t===null?"Turn budget reached":`Turn budget reached · ${t} ${t===1?"step":"steps"}`}function g4(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function x4({block:e,messages:t,at:s}){const[r,i]=f.useState(!1),a=e.state==="succeeded";return n.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[n.jsxs("button",{type:"button",className:"wb-tool","data-ok":a,"aria-expanded":r,onClick:()=>i(l=>!l),children:[n.jsx("span",{className:"wb-tool-mark","data-ok":a?"true":"false","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":Ws(e.name)}),n.jsx("span",{className:"wb-tool-elapsed",children:e.state}),n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===ii?n.jsx(QF,{block:e,messages:t,answeredAt:s}):null,r&&e.name!==ii?n.jsx("pre",{className:"wb-approval-output mono",children:v4(e.output)}):null]})}function v4(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const j4=40;function y4(e){var s,r;if(((s=e.delegation)==null?void 0:s.state)==="waiting")return{status:e.delegation.approvalId?"waiting for your approval":"running",waiting:!0};if(vp(e))return{status:"waiting",waiting:!0};const t=(r=e.approval)==null?void 0:r.state;return t?t==="approved"||t==="executing"?{status:"approved",waiting:!0}:t==="succeeded"?{status:"approved",waiting:!1}:{status:t,waiting:!1}:null}function yp({label:e,tool:t,ok:s,running:r,elapsed:i,opens:a,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:d=null,body:h=null}){const[m,p]=f.useState(!1),g=n.jsxs(n.Fragment,{children:[r?n.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):n.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),n.jsx("span",{className:"wb-tool-label",children:e}),d?n.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:d}):null,i===void 0?null:n.jsxs("span",{className:"wb-tool-elapsed",children:[i,"s"]}),o||s===!1?n.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),y={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":d?!0:void 0,"data-approval":u||void 0};return h?n.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[n.jsxs("div",{className:"wb-tool","data-split":"true",...y,children:[n.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(b=>!b),children:[n.jsx(ye,{name:"chevron",className:"wb-tool-chevron"}),g]}),a?n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})})}),n.jsx(bo,{children:n.jsxs(ko,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):null]}),m?n.jsx(w4,{body:h,onOpen:a?l:null}):null]}):a?n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsxs("button",{className:"wb-tool",...y,onClick:l,children:[g,n.jsx(ye,{name:"arrow",className:"wb-tool-arrow"})]})}),n.jsx(bo,{children:n.jsxs(ko,{className:"ui-tip",sideOffset:6,children:[n.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),n.jsx("span",{className:"ui-tip-hint mono",children:t})]})})]}):n.jsx("span",{className:"wb-tool","data-static":"true",...y,children:g})}function w4({body:e,onOpen:t}){const s=t?{label:"Open on the canvas",onClick:t}:void 0;if(e.kind==="diff")return n.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:n.jsx(Ju,{text:e.diff,limit:j4,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:b4(e.elapsedMs)].filter(i=>i!==null);return n.jsxs("div",{className:"wb-tool-body","data-kind":"command","data-testid":"tool-body",children:[n.jsxs("div",{className:"wb-tool-command",children:[n.jsx("code",{className:"mono",children:e.command}),r.length>0?n.jsx("span",{className:"wb-tool-facts","data-failed":e.exitCode!==null&&e.exitCode!==0?!0:void 0,children:r.join(" · ")}):null]}),e.output?n.jsx("pre",{className:"wb-tool-output",children:e.output}):null]})}function b4(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function Yx(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}const tC="approval-dock";function k4(){var t;const e=document.getElementById(tC);e&&((t=e.scrollIntoView)==null||t.call(e,{block:"nearest"}),e.focus())}const S4=["workspace","cwd","workdir","root"];function N4({approvals:e,timezone:t,now:s,version:r,onDecided:i,onSay:a,onOpenFull:l}){const[o,c]=f.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),d=u[0];if(!d)return null;const h=m=>c(p=>p.includes(m)?p:[...p,m]);return n.jsx(C4,{item:d,count:u.length,timezone:t,now:s,version:r,onSettled:m=>{h(d.approvalId),m&&i(m)},onSay:a,onOpenFull:()=>l(d.toolUseId)},d.approvalId)}function C4({item:e,count:t,timezone:s,now:r,version:i,onSettled:a,onSay:l,onOpenFull:o}){var C;const[c,u]=f.useState(null),[d,h]=f.useState(null),[m,p]=f.useState(null),[g,y]=f.useState("");f.useEffect(()=>{let I=!1;return T.approval(e.approvalId).then(A=>{I||(u(A),A.state!=="pending"&&a(A))}).catch(A=>{I||h(A instanceof ge?A.message:String(A))}),()=>{I=!0}},[e.approvalId,i]);const b=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;f.useEffect(()=>{b&&c&&a({...c,state:"expired"})},[b]);const{values:x,controls:v}=Lx(c==null?void 0:c.choices),j=(I,A)=>{const _=g.trim();p(I),h(null),(x&&I==="approve"?T.decide(e.approvalId,I,A,x):T.decide(e.approvalId,I,A)).then(z=>{a(z.action),_&&l(_)}).catch(z=>{h(z instanceof ge?z.message:String(z)),p(null)})},w=m!==null||c===null||c.state!=="pending",S=((C=c==null?void 0:c.permissionScopes)==null?void 0:C.includes("always"))??!1,k=c?Kx(c.tool,c.canonicalArgs)??A4(c.preview):null,N=c?E4(c):null;return n.jsxs("section",{id:tC,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),t>1?n.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",t]}):null,n.jsx("strong",{children:c?Ws(c.tool):"Loading the request…"}),e.askedBy?n.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),k||N?n.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[k?n.jsx("code",{className:"wb-dock-gist",children:k}):null,N?n.jsxs("span",{className:"wb-dock-where",children:["in ",n.jsx("span",{className:"mono",children:N})]}):null]}):null,v?n.jsx("div",{className:"wb-dock-section",children:v}):null,n.jsx(re,{message:d}),n.jsx("div",{className:"wb-dock-section",children:n.jsx("input",{className:"wb-dock-instead",value:g,onChange:I=>y(I.target.value),onKeyDown:I=>{I.key==="Enter"&&I.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),n.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[n.jsxs("span",{className:"wb-dock-meta",children:[c?n.jsxs(n.Fragment,{children:["Expires ",Ve(c.expiresAt,s)," · "]}):null,n.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),n.jsx(R,{variant:"ghost",size:"sm",disabled:w,onClick:()=>j("reject"),children:m==="reject"?"Rejecting…":"Reject"}),S?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",size:"sm",disabled:w,onClick:()=>j("approve","conversation"),children:"Auto: this conversation"}),n.jsx(R,{size:"sm",disabled:w,onClick:()=>j("approve","always"),children:"Always: this agent"})]}):null,n.jsx(R,{variant:"good",size:"sm",disabled:w,onClick:()=>j("approve"),children:m==="approve"?"Approving…":S?"Allow once":"Approve"})]})]})}function E4(e){for(const t of[e.canonicalArgs,e.envelope])if(!(t===null||typeof t!="object"||Array.isArray(t)))for(const s of S4){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function A4(e){const t=(e??"").split(`
|
|
99
|
+
`).map(s=>s.trim()).find(Boolean);return t?t.length>160?`${t.slice(0,157)}…`:t:null}const T4=2e3;function R4({conversationId:e,agentId:t,runId:s=null,result:r=null,waiting:i=null,agents:a=[]}){const l=r!==null,[o,c]=f.useState(l),u=!o||i!==null,{data:d,error:h}=le(()=>Fe.conversation(e),[e,o,(i==null?void 0:i.approvalId)??null],u?T4:void 0),m=(d==null?void 0:d.runs)??[],p=s===null?null:m.find(w=>w.runId===s)??null,g=l||i===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(w=>w.finishedAt!==null));f.useEffect(()=>{g&&c(!0)},[g]);const y=r?r.ok?"done":"failed":i!=null&&i.approvalId?"waiting":g?"done":"working",b=a.find(w=>w.id===t)??null,x=(b==null?void 0:b.name)??(d==null?void 0:d.agentId)??t,v=(d==null?void 0:d.messages)??[],j=(r==null?void 0:r.text)??I4(v);return n.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":y,children:[n.jsxs("header",{className:"wb-delegate-head",children:[n.jsx(Nn,{agents:a,id:t}),n.jsxs("div",{className:"wb-delegate-who",children:[n.jsx("strong",{children:x}),n.jsx("span",{className:"wb-delegate-status","data-status":y,role:"status",children:y==="working"?n.jsxs(n.Fragment,{children:["Working",n.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]})]}):y==="waiting"?"Waiting for your approval":y==="failed"?"Failed":"Done"})]})]}),h?n.jsx("p",{className:"muted",children:h}):null,n.jsx("div",{className:"wb-delegate-work",children:v.map((w,S)=>n.jsx("div",{className:"wb-delegate-turn",children:(w.blocks??[]).map((k,N)=>{if(k.type==="thinking")return k.text.trim()===""?null:n.jsx(jp,{text:k.text},N);if(k.type==="tool_use"){const C=$4(P4(v,k.id));return n.jsx(yp,{label:Ws(k.name),tool:k.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:Kx(k.name,k.input),opens:!1,onOpen:()=>{}},N)}return null})},w.id??S))}),j?n.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:n.jsx(gr,{text:j})}):y==="working"||y==="waiting"?n.jsxs("p",{className:"muted",children:[x," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?n.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${x} made`,"data-testid":"delegate-files",children:r.files.map(w=>n.jsx("a",{role:"listitem",href:ri(w.artifactId),download:!0,children:n.jsx(sh,{name:w.filename??"Untitled file",mime:w.mime,sizeBytes:w.sizeBytes,thumbnail:zx(w.mime)?xr(w.artifactId):null})},w.artifactId))}):null,n.jsxs("div",{className:"wb-delegate-actions",children:[y==="waiting"?n.jsx(R,{variant:"accent",onClick:()=>k4(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,n.jsx("a",{className:"ui-btn",href:Je(t||(d==null?void 0:d.agentId)||"",e),children:"Open this conversation"})]})]})}function I4(e){for(let t=e.length-1;t>=0;t-=1){const s=e[t];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(i=>i.type==="text").map(i=>i.text.trim()).filter(i=>i!=="").join(`
|
|
100
|
+
|
|
101
|
+
`);if(r!=="")return r}return null}function P4(e,t){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===t)return r;return null}function $4(e){var s;if(e===null)return{running:!0,ok:null,waiting:!1,status:void 0};const t=(s=e.approval)==null?void 0:s.state;return t==="pending"?{running:!1,ok:null,waiting:!0,status:"waiting approval"}:t==="approved"||t==="executing"?{running:!0,ok:null,waiting:!1,status:"running"}:t==="succeeded"?{running:!1,ok:!0,waiting:!1,status:void 0}:t?{running:!1,ok:!1,waiting:!1,status:t}:{running:!1,ok:e.ok,waiting:!1,status:void 0}}const Mw=1024*1024;function M4({files:e,agentId:t,root:s,revision:r}){const[i,a]=f.useState({kind:"dir",path:""});return f.useEffect(()=>a({kind:"dir",path:""}),[e.plugin,t]),n.jsx("div",{className:"wb-files","data-testid":"files-view",children:i.kind==="dir"?n.jsx(O4,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a}):n.jsx(D4,{files:e,agentId:t,root:s,path:i.path,revision:r,go:a})})}function nC({root:e,path:t,go:s}){const r=t===""?[]:t.split("/"),i=[{label:e,path:""},...r.map((a,l)=>({label:a,path:r.slice(0,l+1).join("/")}))];return n.jsx("nav",{className:"wb-files-crumbs","aria-label":"Where you are in the workspace",children:i.map((a,l)=>{const o=l===i.length-1;return n.jsxs("span",{className:"wb-files-crumb",children:[l>0?n.jsx("span",{className:"wb-files-sep","aria-hidden":"true",children:"/"}):null,o?n.jsx("span",{className:"wb-files-here mono","aria-current":"location",children:a.label}):n.jsx("button",{type:"button",className:"wb-files-step mono",onClick:()=>s({kind:"dir",path:a.path}),children:a.label})]},a.path)})})}function O4({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(!1),[m,p]=f.useState(null);f.useEffect(()=>{let b=!1;return u(null),T.pageQuery(e.plugin,e.list,{agent:t,...r?{path:r}:{}}).then(x=>{b||o(x.data)}).catch(x=>{b||u(x instanceof Error?x.message:String(x))}),()=>{b=!0}},[e.plugin,e.list,t,r,i]),f.useEffect(()=>p(null),[r]);const g=async()=>{h(!0),p(null);try{const b=await fetch(T.pageFileUrl(e.plugin,e.archive,{agent:t,...r?{path:r}:{}}),{credentials:"same-origin"});if(!b.ok){const w=await b.json().catch(()=>null);p((w==null?void 0:w.error)??"The archive could not be made.");return}const x=await b.blob(),v=URL.createObjectURL(x),j=document.createElement("a");j.href=v,j.download=`${r===""?s:r.split("/").at(-1)}.zip`,j.click(),window.setTimeout(()=>URL.revokeObjectURL(v),1e4)}catch{p("The archive could not be made.")}finally{h(!1)}},y=l&&l.path===r?l.entries:null;return n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[n.jsx(nC,{root:s,path:r,go:a}),n.jsx(Xt,{}),n.jsx(R,{size:"sm",onClick:()=>void g(),disabled:d||y===null||y.length===0,children:d?"Packing…":"Download as archive"})]}),m?n.jsx(W,{tone:"warning",role:"alert",children:m}):null,c?n.jsx(W,{tone:"critical",role:"alert",children:c}):null,y===null?c?null:n.jsx(ce,{children:"Reading the folder…"}):y.length===0?n.jsx(ce,{children:r===""?n.jsxs(n.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",n.jsx("a",{href:_i,children:"Files library"})," and mention it here."]}):"This folder is empty."}):n.jsx(yt,{children:y.map(b=>n.jsx(ft,{href:"#",onClick:()=>a({kind:b.kind,path:b.path}),lead:n.jsx(L4,{kind:b.kind}),title:n.jsxs("span",{className:"mono",children:[b.name,b.kind==="dir"?"/":""]}),side:b.kind==="file"?$n(b.bytes):void 0},b.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?n.jsxs("p",{className:"wb-files-note",children:[l.truncated?`Only the first ${l.entries.length} entries are shown. `:"",l.skipped>0?`${l.skipped} ${l.skipped===1?"entry is":"entries are"} not shown: symbolic links and protected paths are never read.`:""]}):null]})}function D4({files:e,agentId:t,root:s,path:r,revision:i,go:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(!1);f.useEffect(()=>{let x=!1;return u(null),T.pageQuery(e.plugin,e.stat,{agent:t,path:r}).then(v=>{x||o(v.data)}).catch(v=>{x||u(v instanceof Error?v.message:String(v))}),()=>{x=!0}},[e.plugin,e.stat,t,r,i]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",g=m?T.pageFileUrl(e.plugin,e.read,{agent:t,path:r,v:p}):"",y=T.pageFileUrl(e.plugin,e.read,{agent:t,path:r,download:"1"}),b=(m==null?void 0:m.type)==="text"&&m.bytes<=Mw;return n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[n.jsx(nC,{root:s,path:r,go:a}),n.jsx(Xt,{}),b?n.jsx(R,{size:"sm","aria-pressed":d,onClick:()=>h(x=>!x),children:"Wrap"}):null,n.jsx(Ut,{size:"sm",href:y,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?n.jsx(W,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:n.jsx(ce,{children:"Reading the file…"}):m.type==="image"?n.jsx("figure",{className:"wb-files-picture",children:n.jsx("img",{src:g,alt:m.name})}):m.type==="pdf"?n.jsx("div",{className:"file-preview file-preview-pdf",children:n.jsx("object",{data:g,type:"application/pdf","aria-label":m.name,children:n.jsx(W,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):b?n.jsx(_4,{src:g,wrap:d}):n.jsxs(n.Fragment,{children:[n.jsx(W,{children:m.type==="text"?`This file is over ${$n(Mw)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),n.jsx(Gt,{items:[{label:"Size",value:$n(m.bytes)},{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function _4({src:e,wrap:t}){const[s,r]=f.useState(null),[i,a]=f.useState(!1);return f.useEffect(()=>{let l=!1;return a(!1),fetch(e,{credentials:"same-origin"}).then(async o=>{if(!o.ok)throw new Error(String(o.status));const c=await o.text();l||r(c)}).catch(()=>{l||a(!0)}),()=>{l=!0}},[e]),i?n.jsx(W,{tone:"critical",children:"The file could not be read."}):s===null?n.jsx(ce,{children:"Reading the file…"}):s===""?n.jsx(ce,{children:"This file is empty."}):n.jsx("pre",{className:"wb-files-text","data-wrap":t?"true":void 0,"data-testid":"files-text",children:s})}function L4({kind:e}){return n.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round",children:e==="dir"?n.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):n.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}function F4({input:e,output:t,ok:s}){const r=DF(e),i=Q1(t)??(s?"sent":"not sent");return n.jsxs("div",{className:"wb-envelope",children:[n.jsxs("div",{className:"envelope",children:[n.jsxs("dl",{className:"envelope-head",children:[n.jsx("dt",{children:"To"}),n.jsx("dd",{className:"wb-envelope-action",children:"You"}),n.jsx("dt",{children:"Status"}),n.jsx("dd",{children:n.jsx(ve,{tone:_F(i,s),dot:!0,children:i})})]}),n.jsxs("div",{className:"envelope-body",children:[n.jsx("strong",{children:r.title}),r.text?`
|
|
102
|
+
|
|
103
|
+
${r.text}`:null]})]}),n.jsx(Ct,{summary:"The call",children:n.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[n.jsx("dt",{children:"Urgency"}),n.jsx("dd",{children:r.urgency}),r.link?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Link"}),n.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?n.jsxs(n.Fragment,{children:[n.jsx("dt",{children:"Key"}),n.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const z4=3,U4=152,B4=104,W4=100,H4=2,Ow=5;function K4({renderables:e,activeId:t,onActivate:s,timezone:r,onDecided:i,onChangeAgent:a,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:d,browserPanel:h,agents:m,onClose:p,loading:g=!1}){const[y,b]=V4(d);if(e.length===0)return n.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[n.jsx("div",{className:"wb-canvas-tabs",ref:y,"aria-hidden":"true",children:n.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),n.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:g?null:n.jsxs("div",{className:"wb-empty",children:[l?n.jsx("span",{className:"wb-empty-face",children:l}):null,n.jsx("p",{className:"ui-empty wb-empty-line",children:J4(u,X4(o??[],c??[]))})]})})]});const x=e.some(w=>w.id===t)?t:e[e.length-1].id,{shown:v,hidden:j}=G4(e,x,b);return n.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:n.jsxs(MO,{value:x,onValueChange:s,className:"contents",children:[n.jsxs("div",{className:"wb-canvas-tabs",ref:y,children:[n.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),n.jsx(OO,{className:"wb-tabstrip","aria-label":"Canvas",children:v.map(w=>n.jsxs("div",{className:"wb-tab-item",children:[n.jsxs(DO,{value:w.id,className:"wb-tab","data-tone":w.tone,onKeyDown:S=>{S.key==="Delete"&&p&&Dw(w)&&(S.preventDefault(),p(w.id))},children:[w.tone==="warning"||w.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":w.tone,"aria-hidden":"true"}):null,n.jsx("span",{className:"wb-tab-text",children:w.title})]}),p&&Dw(w)?n.jsx("button",{className:"wb-tab-close","aria-label":`Close ${w.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>p(w.id),children:"×"}):null]},w.id))}),n.jsx(Y4,{items:j,onActivate:s,timezone:r})]}),e.map(w=>n.jsx(_O,{value:w.id,className:"wb-canvas-body","data-renderer":w.source==="descriptor"&&w.renderer==="preview"?"preview":void 0,"data-dense":e3.has(w.renderer)?"true":void 0,children:n.jsxs("section",{className:"ui-panel","data-flush":w.source==="descriptor"&&w.renderer==="preview"?"true":void 0,children:[w.source!=="browser"&&w.source!=="files"&&!(w.source==="descriptor"&&w.renderer==="preview")?n.jsxs("header",{className:"ui-panel-head",children:[n.jsx("h2",{className:"ui-panel-title",children:w.title}),n.jsx("span",{className:"ui-panel-tool mono",children:w.tool})]}):null,w.tone==="critical"?n.jsxs("p",{className:"muted",children:["Recorded tool failure",w.at?` · ${new Date(w.at).toLocaleString()}`:"",". This is history, not live session status."]}):null,w.source==="browser"?h:w.source==="profile"?n.jsx(cF,{...w.props,...a?{onChange:a}:{}}):w.source==="artifact"?n.jsx(PF,{...w.props}):w.source==="files"?n.jsx(M4,{...w.props}):w.source==="notify"?n.jsx(F4,{...w.props}):w.source==="delegate"?n.jsx(R4,{...w.props,agents:m??[]}):n.jsx(oF,{renderer:w.renderer,props:w.props,timezone:r,onDecided:i})]})},w.id))]})})}function Dw(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function V4(e){const[t,s]=f.useState(Ow),r=f.useRef(null);return[f.useCallback(a=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!a||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=a.clientWidth;if(c===0)return;const u=Math.floor((c-W4-B4)/U4);s(Math.max(H4,Math.min(Ow,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(a)},[e]),e??t]}function G4(e,t,s){const r=new Set(e.filter(a=>a.id===t||a.source==="approval"||a.pinned===!0).map(a=>a.id)),i=new Set(r);for(let a=e.length-1;a>=0&&i.size<s;a-=1)i.add(e[a].id);return{shown:e.filter(a=>i.has(a.id)),hidden:e.filter(a=>!i.has(a.id))}}function Y4({items:e,onActivate:t,timezone:s}){if(e.length===0)return null;const r=e.some(i=>i.tone==="critical")?"critical":e.some(i=>i.tone==="warning")?"warning":null;return n.jsxs(Gd,{modal:!1,children:[n.jsx(Yd,{asChild:!0,children:n.jsxs("button",{className:"wb-tab wb-tab-more","data-tone":r??void 0,"aria-label":`${e.length} more ${e.length===1?"view":"views"} in this conversation`,children:[r?n.jsx("span",{className:"wb-tab-dot","data-tone":r,"aria-hidden":"true"}):null,n.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}),n.jsx(ye,{name:"chevron-down"})]})}),n.jsx(Ho,{children:n.jsxs(qd,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[n.jsx(Qd,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(i=>n.jsxs(Or,{className:"ui-menu-item",onSelect:()=>t(i.id),children:[n.jsxs("span",{className:"ui-menu-item-text",children:[i.tone==="warning"||i.tone==="critical"?n.jsx("span",{className:"wb-tab-dot","data-tone":i.tone,"aria-hidden":"true"}):null,i.title]}),n.jsx("span",{className:"ui-menu-note mono",children:q4(i.at,s)??i.tool})]},i.id))]})})]})}function q4(e,t){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:new Intl.DateTimeFormat("en-GB",{timeZone:t,hour:"2-digit",minute:"2-digit"}).format(s)}const Q4={timeseries:"charts",table:"tables",bars:"comparisons",keyvalue:"figures",tiles:"cards",document:"pages it read",diff:"diffs",terminal:"command output",image:"pictures",preview:"running apps",envelope:"drafts",structured:"results"};function J4(e,t){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(t.map(i=>Q4[i.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function X4(e,t){const s=new Set(t),r=new Set,i=e.filter(c=>{if(!s.has(c.tool))return!1;const u=Z4(c);return r.has(u)?!1:(r.add(u),!0)}),a=new Set,l=i.filter(c=>a.has(c.renderer)?!1:(a.add(c.renderer),!0)),o=i.filter(c=>!l.includes(c));return[...l,...o].slice(0,z4)}function Z4(e){return e.title&&e.title.trim()!==""?e.title:e.tool.split(".").map(t=>t.replace(/[_-]+/g," ")).join(" · ").replace(/\b\w/,t=>t.toUpperCase())}const e3=new Set(["table","diff","files"]),t3=3.5*6e4,n3=2e3;function s3(e,t,s={}){const[r,i]=f.useState({served:new Set,live:new Set,scope:t}),a=f.useRef(r.served);if(r.scope!==t){const u={served:new Set,live:new Set,scope:t};a.current=u.served,i(u)}const l=s.check??T.previewCheck,o=s.everyMs??n3,c=e.map(u=>`${Pa(u)}@${u.at??""}`).join("|");return f.useEffect(()=>{const u=new Map;for(const p of e){const g=Pa(p);if(a.current.has(g))continue;const y=p.at===null?Number.NaN:Date.parse(p.at),b=Number.isNaN(y)?0:y+t3,x=u.get(g);(!x||b>x.until)&&u.set(g,{plugin:p.plugin,name:p.name,until:b})}if(u.size===0)return;let d=!1,h;const m=async()=>{const p=Date.now();for(const[g,y]of[...u]){const b=await l(y.plugin,y.name).catch(()=>null);if(d)return;const x=p<=y.until;b!=null&&b.ok?(u.delete(g),i(v=>{const j={served:new Set(v.served).add(g),live:x?new Set(v.live).add(g):v.live,scope:v.scope};return a.current=j.served,j})):x||u.delete(g)}!d&&u.size>0&&(h=setTimeout(()=>void m(),o))};return m(),()=>{d=!0,h!==void 0&&clearTimeout(h)}},[c,t,l,o]),r}const wp="workspace-files";function r3(e){let t=0;for(const s of e)for(const r of s.blocks??[]){if(r.type!=="tool_result"||r.ok===!1)continue;const i=r.output;if(i===null||typeof i!="object"||Array.isArray(i))continue;const{diff:a,path:l}=i;typeof a=="string"&&a.trim()!==""&&typeof l=="string"&&l!==""&&(t+=1)}return t}function i3(e){const[t,s]=f.useState(null);return f.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var a;const i=await T.pages();for(const l of Array.isArray(i==null?void 0:i.files)?i.files:[]){const o=await T.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(a=o==null?void 0:o.data)==null?void 0:a.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(i=>{r||s(i)}).catch(()=>{}),()=>{r=!0}},[e]),t&&t.agentId===e?t:null}function a3(e,t){return{id:wp,tool:"",title:"Files",renderer:"files",props:{files:e.files,agentId:e.agentId,root:e.root,revision:t},at:null,source:"files",pinned:!0,substantial:!1}}function bp(e){return`agent-properties:${e}`}function l3(e){return{id:bp(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function o3(e){return!e||e.download===0?"Fetching the browser…":e.phase==="downloading"?`Fetching ${e.what}… ${e.percent}%`:e.phase==="installing"?`Setting up ${e.what}…`:e.phase==="done"?"Installed.":"The install stopped."}function sC({progress:e}){return n.jsxs(Q,{gap:"sm",children:[n.jsx("span",{role:"status",children:o3(e)}),n.jsx(k1,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}function c3(e,t,s,r){const i=e.width||1,a=e.height||1,l=t.pageScaleFactor||1,o=(s-e.left)*(t.deviceWidth/i)/l,c=((r-e.top)*(t.deviceHeight/a)-t.offsetTop)/l,u=(d,h)=>Math.max(0,Math.min(Math.round(d),Math.round(h)));return{x:u(o,t.deviceWidth),y:u(c,t.deviceHeight)}}function xf(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function _w(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const u3=4e3;function d3(e){return e.replace(/\r\n?/g,`
|
|
104
|
+
`).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,u3)}const h3=["left","middle","right"],f3=33;function m3(e,t){return e.deviceWidth===t.deviceWidth&&e.deviceHeight===t.deviceHeight&&e.pageScaleFactor===t.pageScaleFactor&&e.offsetTop===t.offsetTop}function p3(e){if(e.byteLength<3)return null;const t=new DataView(e);if(t.getUint8(0)!==1)return null;const s=t.getUint16(1);if(e.byteLength<3+s)return null;try{return{metadata:JSON.parse(new TextDecoder().decode(new Uint8Array(e,3,s))),jpeg:new Blob([new Uint8Array(e,3+s)],{type:"image/jpeg"})}}catch{return null}}function g3(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}function x3({sessionId:e,csrf:t,onGiveBack:s,connect:r}){const[i,a]=f.useState("connecting"),[l,o]=f.useState(null),[c,u]=f.useState(!1),[d,h]=f.useState(null),[m,p]=f.useState(!1),[g,y]=f.useState(0),b=f.useRef(null),x=f.useRef(null),v=f.useRef(null),j=f.useRef({at:0});f.useEffect(()=>{const E=r??(U=>new WebSocket(U));let M=!0,D;try{D=E(g3())}catch{a("lost");return}return D.binaryType="arraybuffer",b.current=D,D.onopen=()=>D.send(JSON.stringify({type:"hello",csrf:t,sessionId:e})),D.onmessage=U=>{if(!M)return;if(typeof U.data!="string"){const B=p3(U.data);if(!B||(h(O=>O&&m3(O,B.metadata)?O:B.metadata),u(!0),typeof createImageBitmap!="function"))return;createImageBitmap(B.jpeg).then(O=>{var G,se,ue;const K=x.current;if(!M||!K){(G=O.close)==null||G.call(O);return}(K.width!==O.width||K.height!==O.height)&&(K.width=O.width,K.height=O.height),(se=K.getContext("2d"))==null||se.drawImage(O,0,0),(ue=O.close)==null||ue.call(O)}).catch(()=>{});return}const $=JSON.parse(U.data);if($.type==="driving"){a("driving"),o(null);return}($.type==="refused"||$.type==="ended")&&(o($.error??"The screen cannot be driven from here."),a("refused"))},D.onclose=()=>{M&&a(U=>U==="refused"?U:"lost")},D.onerror=()=>{M&&a(U=>U==="refused"?U:"lost")},()=>{M=!1,b.current=null;try{D.close()}catch{}}},[e,t,g,r]),f.useEffect(()=>()=>{clearTimeout(j.current.timer)},[]);const w=f.useCallback(E=>{const M=b.current;if(M)try{M.send(JSON.stringify({type:"input",input:E}))}catch{}},[]),S=E=>{var U;const M=x.current;if(!M||!d)return null;const D=(U=M.getBoundingClientRect)==null?void 0:U.call(M);return D?c3(D,d,E.clientX,E.clientY):null},k=E=>{const M=j.current,D=Date.now();clearTimeout(M.timer),M.timer=void 0;const U=M.at+f3-D;if(U<=0){M.at=D,M.pending=void 0,w(E);return}M.pending=E,M.timer=setTimeout(()=>{const $=j.current.pending;j.current.timer=void 0,j.current.pending=void 0,j.current.at=Date.now(),$&&w($)},U)},N=()=>{const E=j.current;clearTimeout(E.timer),E.timer=void 0;const M=E.pending;E.pending=void 0,M&&(E.at=Date.now(),w(M))},C=E=>M=>{var $,B;const D=S(M);if(!D)return;E==="mousePressed"&&(M.preventDefault(),(B=($=x.current)==null?void 0:$.focus)==null||B.call($));const U={kind:"mouse",type:E,x:D.x,y:D.y,button:h3[M.button]??"left",clickCount:E==="mouseMoved"?0:Math.min(3,Math.max(1,M.detail||1)),modifiers:xf(M)};if(E==="mouseMoved"){k(U);return}N(),w(U)},I=E=>{const M=S(E);M&&(N(),w({kind:"wheel",x:M.x,y:M.y,deltaX:Math.round(E.deltaX),deltaY:Math.round(E.deltaY)}))},A=E=>E.ctrlKey||E.metaKey||E.altKey,_=E=>{var D,U;if(E.key==="Escape"&&A(E)){p(!1),(U=(D=E.target).blur)==null||U.call(D);return}if(E.preventDefault(),(E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))return;const M=xf(E);if(_w(E.key)&&!A(E)){w({kind:"key",type:"char",key:E.key,code:E.code,text:E.key,modifiers:M});return}w({kind:"key",type:"keyDown",key:E.key,code:E.code,modifiers:M})},z=E=>{E.key==="Escape"&&A(E)||(E.preventDefault(),!((E.metaKey||E.ctrlKey)&&(E.key==="v"||E.key==="V"))&&(_w(E.key)&&!A(E)||w({kind:"key",type:"keyUp",key:E.key,code:E.code,modifiers:xf(E)})))},L=E=>{var D;E.preventDefault();const M=d3(((D=E.clipboardData)==null?void 0:D.getData("text/plain"))??"");M!==""&&w({kind:"text",text:M})};return n.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":i,"aria-label":"Driving the host browser",children:[n.jsxs("div",{className:"hand-bar",children:[n.jsx("span",{className:"hand-said",role:"status",children:"You are driving. Nothing you type here is kept."}),n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",variant:m?"accent":"ghost","aria-pressed":m,onClick:()=>{var M,D,U,$;const E=!m;p(E),E?(D=(M=v.current)==null?void 0:M.focus)==null||D.call(M):($=(U=v.current)==null?void 0:U.blur)==null||$.call(U)},children:"Keyboard"}),n.jsx(R,{size:"sm",variant:"accent",onClick:s,children:"Give it back"})]})]}),i==="lost"?n.jsxs(W,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",n.jsx(J,{align:"end",children:n.jsx(R,{size:"sm",variant:"accent",onClick:()=>{a("connecting"),y(E=>E+1)},children:"Reconnect"})})]}):null,i==="refused"&&l?n.jsx(W,{tone:"warning",role:"status",children:l}):null,n.jsx("div",{className:"hand-screen",children:c?n.jsx("canvas",{ref:x,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:C("mousePressed"),onMouseUp:C("mouseReleased"),onMouseMove:C("mouseMoved"),onWheel:I,onKeyDown:_,onKeyUp:z,onPaste:L,onContextMenu:E=>E.preventDefault()}):n.jsx("p",{className:"muted hand-waiting",children:i==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),n.jsx("input",{ref:v,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:_,onKeyUp:z,onPaste:L,onBlur:()=>p(!1)})]})}function v3(e){return e==="darwin"?"this Mac":"this computer"}let vf=null;function qx(){const[e,t]=f.useState(void 0);return f.useEffect(()=>{let s=!0;return vf??(vf=T.session().then(r=>r.platform,()=>{vf=null})),vf.then(r=>{s&&t(r)}),()=>{s=!1}},[]),v3(e)}function j3({embedded:e,timezone:t}={}){var c;const{data:s,error:r,reload:i}=le(()=>T.browser(),[],3e3),a=le(()=>T.session(),[]),l=(c=a.data)!=null&&c.platform?a.data.platform==="darwin":!0,o=!!a.data||!!a.error;return n.jsxs(yn,{embedded:e,title:"Computer & browser",children:[n.jsx(re,{message:r}),!s||!o?n.jsx(ce,{children:"Checking the host…"}):n.jsx(y3,{data:s,macOS:l,reload:i,timezone:t},JSON.stringify(s.settings??null))]})}function y3({data:e,macOS:t,reload:s,timezone:r}){var N,C,I;const[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1),d=e.settings&&!t&&e.settings.mode==="computer"?{...e.settings,mode:"playwright"}:e.settings,h=(d==null?void 0:d.mode)??(!t&&e.mode==="computer"?"playwright":e.mode),m=h==="computer",p=(N=e.sessions)!=null&&N.length?e.sessions:e.session?[e]:[],g=p.length>0||e.busy,y=async A=>{a(!0),o(null);try{await A()}catch(_){o(_ instanceof Error?_.message:String(_))}finally{a(!1),s()}},b=A=>void y(()=>T.browserSettings(A)),x=e.permissions,v=h==="playwright"?e.browser:void 0,j=((C=v==null?void 0:v.install)==null?void 0:C.state)==="running",w=(v==null?void 0:v.engine)==="none",S=!!e.enabled&&!w&&!(v!=null&&v.problem)&&(!m||!(x!=null&&x.supported)||x.accessibility&&x.screenRecording),k=m?"Ready. Agents can use your computer within the apps you allow below.":h==="extension"?"Ready. Agents work in your Chrome, in background tabs, through the buddi extension.":(v==null?void 0:v.engine)==="chrome"?"Ready. Agents work in their own browser, a separate Google Chrome profile. Your apps are never touched.":"Ready. Agents work in their own browser. Your apps are never touched.";return n.jsxs(Q,{gap:"lg",children:[n.jsx(re,{message:l}),n.jsx(te,{title:"Status",panel:!0,actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",disabled:i,onClick:()=>void y(()=>T.computerPermissions(!1)),children:"Check again"}),m&&!S&&(x!=null&&x.supported)?n.jsx(R,{size:"sm",variant:"accent",disabled:i||g,onClick:()=>void y(()=>T.computerPermissions(!0)),children:"Request macOS permissions"}):null,w||j?n.jsx(R,{size:"sm",variant:"accent",disabled:i||j,onClick:()=>void y(()=>T.browserInstall()),children:j?"Installing…":"Install Chromium"}):null]}),children:n.jsxs(Q,{children:[e.enabled?w?n.jsxs(W,{tone:"warning",title:"No browser installed for the agents yet",children:["Install Chromium here (about 150 MB), or run ",n.jsx("code",{children:"buddi browser install"})," on this machine."]}):v!=null&&v.problem?n.jsx(W,{tone:"warning",children:v.message}):S?n.jsx(W,{tone:"good",children:k}):n.jsx(W,{tone:"warning",children:"macOS has not granted everything yet. Grant the permissions below, then check again."}):n.jsx(W,{tone:"warning",children:"The host is not available. Start buddi serve on a machine with a desktop session."}),m?x!=null&&x.supported?n.jsxs("ul",{className:"perm-list",children:[n.jsxs("li",{className:"perm-row",children:[n.jsx(ve,{tone:x.accessibility?"good":"warning",children:x.accessibility?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Accessibility"}),n.jsx("span",{className:"muted",children:"Lets agents click and type in the apps you allow."})]}),n.jsxs("li",{className:"perm-row",children:[n.jsx(ve,{tone:x.screenRecording?"good":"warning",children:x.screenRecording?"Granted":"Needed"}),n.jsx("span",{className:"perm-name",children:"Screen Recording"}),n.jsx("span",{className:"muted",children:"Lets agents see the window they are working in."})]})]}):x?n.jsx("p",{className:"muted",children:"Computer control requires macOS 14 or later."}):null:null,((I=v==null?void 0:v.install)==null?void 0:I.state)==="running"?n.jsx(sC,{progress:v.install.progress}):v!=null&&v.install?n.jsx("p",{className:"muted",role:"status",children:v.install.state==="done"?"Chromium is installed. Agents can open their browser now.":`The install did not finish: ${v.install.line??"no reason given"}`}):null,v!=null&&v.headless&&!w?n.jsx("p",{className:"muted",children:"The agents’ browser runs headless on this machine, since it has no display. Watch it and take over from the conversation’s Canvas."}):null,m&&(x!=null&&x.message)?n.jsx("p",{className:"muted",children:x.message}):null,m&&(x!=null&&x.supported)&&!S?n.jsx("p",{className:"muted",children:"macOS may ask you to restart buddi after granting them."}):null]})}),n.jsx(te,{title:"Who is driving",panel:!0,actions:p.length>0?n.jsx(R,{variant:"danger",size:"sm",disabled:i,onClick:()=>void y(()=>T.browserControl("stop")),children:m?"Stop computer control":"Stop all browsers"}):void 0,children:p.length===0?n.jsx("p",{className:"ui-card-meta",children:"Nobody right now. Ask an agent to open a website or one of the allowed apps, and you will see it working on that conversation’s Canvas."}):n.jsx("div",{className:"ui-list",children:p.map(A=>n.jsxs("a",{className:"ui-list-row",href:Je(A.session.agentId,A.session.conversationId),children:[n.jsx(Es,{id:A.session.agentId,name:A.session.agentId,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:A.session.task}),n.jsxs("span",{className:"ui-list-sub",children:[A.session.agentId,", ",A.busy?"working":A.state,", ",A.session.steps," of ",A.session.maxSteps," steps"]})]}),n.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},A.session.id))})}),d?n.jsxs(n.Fragment,{children:[n.jsx(te,{title:"How agents get a screen",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsxs("div",{className:"mode-choice",role:"radiogroup","aria-label":"Control mode",children:[t?n.jsx(jf,{current:d.mode,value:"computer",disabled:i||g||!e.enabled,title:"Use my apps",body:"Agents work in your own windows, signed in as you, in the browser profile you choose below. One agent at a time. Releasing control leaves everything open.",onPick:()=>b({...d,mode:"computer"})}):null,n.jsx(jf,{current:d.mode,value:"playwright",disabled:i||g||!e.enabled,title:"Give agents their own browser",body:"A separate browser profile with its own tabs, one per conversation. Your apps are never touched.",onPick:()=>b({...d,mode:"playwright"})}),n.jsx(jf,{current:d.mode,value:"extension",disabled:i||g||!e.enabled,title:"Your browser",body:"Uses the Chrome you are signed in to, in background tabs, through the buddi extension.",onPick:()=>b({...d,mode:"extension"})})]}),t?null:n.jsx("p",{className:"muted",children:"Using your own apps is macOS-only."}),g?n.jsx("p",{className:"muted",children:"Finish or stop the current session before changing this."}):null,d.mode==="extension"?n.jsx(E3,{busy:i,timezone:r}):null]})}),t?n.jsx(te,{title:"Apps agents may use",panel:!0,children:n.jsxs(Q,{children:[d.mode!=="computer"?n.jsx("p",{className:"muted",children:"Only used by “Use my apps”. The list is kept for when you switch back."}):null,n.jsx(A3,{settings:d,disabled:i||g||!e.enabled,onChange:b,onAdd:()=>u(!0)}),n.jsx(Ct,{summary:"Details",children:n.jsxs("div",{className:"ui-prose muted",children:[n.jsx("p",{children:"Agents see what is on screen in these apps, and what they see goes to the agent’s model provider. Allow only apps you want operated."}),n.jsx("p",{children:"Never type a password or a sign-in code in chat. Sign in yourself, in the app, while you have taken over."}),n.jsx("p",{children:"This is an allow list, not a sandbox: an allowed app’s own network traffic is not inspected."})]})})]})}):null,c?n.jsx($3,{chosen:d.allowedApps,onClose:()=>u(!1),onPick:A=>{u(!1),d.allowedApps.includes(A)||b({...d,allowedApps:[...d.allowedApps,A]})}}):null]}):null]})}const w3="kmbckpnnjfggeffkkbmkggojnolkdokb",b3="",k3=[w3,b3].filter(Boolean);function S3(e){const t=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(e.trim());if(!t)return e;const s=t[4]?/^pre\.(\d+)$/.exec(t[4]):null;return[t[1],t[2],t[3],...s?[s[1]]:[]].map(Number).join(".")}async function N3(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const t of k3)try{const s=await chrome.runtime.sendMessage(t,{type:"buddi.status"});if(s!=null&&s.installed)return s}catch{}return null}catch{return null}}function C3(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}function E3({busy:e,timezone:t}){const{data:s,error:r,reload:i}=le(()=>T.extension(),[],3e3),a=qx(),l=le(()=>N3(),[],3e3).data??null,[o,c]=f.useState(""),[u,d]=f.useState(!1),[h,m]=f.useState(null),p=(l==null?void 0:l.state)==="pairing"?l.code??"":"";f.useEffect(()=>{p&&c(p)},[p]);const g=async v=>{d(!0),m(null);try{await v()}catch(j){m(j instanceof Error?j.message:String(j))}finally{d(!1),i()}},y=e||u,b=t??Intl.DateTimeFormat().resolvedOptions().timeZone,x=n.jsxs("div",{className:"ui-prose muted",children:[n.jsx("p",{children:"Open chrome://extensions, turn on Developer mode, choose Load unpacked, and pick this folder."}),n.jsx(jt,{label:"The unpacked extension",children:(s==null?void 0:s.path)??"…"})]});return n.jsxs(Q,{divided:!0,children:[n.jsx(re,{message:r??h}),n.jsxs(J,{children:[n.jsx(ve,{tone:s!=null&&s.connected?"good":"warning",children:s!=null&&s.connected?"Connected":"Not connected"}),n.jsxs("span",{className:"muted",children:[s!=null&&s.connected&&s.pairedAt?`Paired with Chrome on ${a} since ${Ve(s.pairedAt,b)}`:s!=null&&s.pairedAt?"Paired, but Chrome is not running the extension right now.":"No browser is paired with this buddi yet.",s!=null&&s.extension?` · extension ${s.extension}`:""]})]}),n.jsxs(Q,{children:[n.jsxs("p",{className:"muted",children:[l?`The browser you are reading this in has the extension, version ${l.version}.`:s!=null&&s.connected?"The browser you are reading this in has no buddi extension. You only need it here to pair this browser instead.":"The browser you are reading this in has no buddi extension yet.",(l==null?void 0:l.state)==="paired"?" It is already paired with a buddi.":"",(l==null?void 0:l.state)==="disconnected"?" It is not connected yet: press Connect in its popup.":""]}),l&&(s!=null&&s.buddi)&&S3(s.buddi)!==l.version?n.jsx("p",{className:"muted",children:`buddi is ${s.buddi}; the extension is ${l.version}. Update it from chrome://extensions or the store.`}):null,l&&!C3(l.gateway)?n.jsx(W,{tone:"warning",children:`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in the popup.`}):null]}),s!=null&&s.pending?n.jsxs(J,{valign:"end",children:[n.jsx(Z,{grow:!0,label:"Pair your browser",hint:"Type the six digits the buddi extension is showing.",children:n.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",placeholder:"482 913",value:o,onChange:v=>c(v.target.value)})}),n.jsx(Xt,{}),n.jsx(R,{variant:"accent",disabled:y||o.replace(/[^0-9]/g,"").length!==6,onClick:()=>void g(async()=>{await T.pairExtension(o),c("")}),children:"Pair"})]}):null,s!=null&&s.connected?n.jsx(Ct,{summary:"Pair a different browser",children:x}):x,n.jsx(J,{align:"end",children:n.jsx(R,{variant:"danger",disabled:y||!(s!=null&&s.pairedAt),onClick:()=>void g(()=>T.forgetExtension()),children:"Forget this browser"})})]})}function jf({current:e,value:t,title:s,body:r,disabled:i,onPick:a}){const l=e===t;return n.jsxs("button",{type:"button",role:"radio","aria-checked":l,className:"mode-option",disabled:i,onClick:()=>{l||a()},children:[n.jsx("span",{className:"mode-option-dot","aria-hidden":"true"}),n.jsxs("span",{className:"mode-option-text",children:[n.jsx("span",{className:"mode-option-title",children:s}),n.jsx("span",{className:"mode-option-body",children:r})]})]})}function A3({settings:e,disabled:t,onChange:s,onAdd:r}){const i=le(()=>T.installedApps(),[]),a=l=>{var o,c;return((c=(o=i.data)==null?void 0:o.apps.find(u=>u.id===l))==null?void 0:c.name)??l};return n.jsxs(n.Fragment,{children:[e.allowedApps.length===0?n.jsx(ce,{children:"No apps yet. Agents cannot touch anything until you add one."}):n.jsx("ul",{className:"ui-list","aria-label":"Allowed apps",children:e.allowedApps.map(l=>n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Es,{id:l,name:a(l),size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[a(l),l===e.browserApp?n.jsx(ve,{tone:"accent",className:"app-role",children:"browser"}):null]}),n.jsx("span",{className:"ui-list-sub mono",children:l})]}),n.jsxs(J,{children:[l!==e.browserApp&&P3(l)?n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,browserApp:l}),children:"Use as browser"}):null,l===e.browserApp?n.jsx("span",{className:"muted",children:"In use as the browser"}):n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:()=>s({...e,allowedApps:e.allowedApps.filter(o=>o!==l)}),children:"Remove"})]})]},l))}),n.jsxs(J,{children:[n.jsx(R,{variant:"accent",disabled:t,onClick:r,children:"Add an app"}),n.jsx("span",{className:"muted",children:"The app marked as browser is the one agents open websites in."})]}),e.mode==="computer"&&T3.includes(e.browserApp)?n.jsx(R3,{settings:e,disabled:t,onChange:s}):null]})}const T3=["com.google.Chrome","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser"];function R3({settings:e,disabled:t,onChange:s}){var l;const i=((l=le(()=>T.browserProfiles(e.browserApp),[e.browserApp]).data)==null?void 0:l.profiles)??[],a=e.browserProfile?i.some(o=>o.directory===e.browserProfile):!0;return n.jsx(Z,{label:"Browser profile",hint:e.browserProfile?"Websites open in this profile, signed in as it is.":"Not chosen: websites open in whichever profile’s window is in front, or the last one you used.",children:n.jsxs("select",{value:e.browserProfile??"",disabled:t,onChange:o=>{const{browserProfile:c,...u}=e;s(o.target.value?{...u,browserProfile:o.target.value}:u)},children:[n.jsx("option",{value:"",children:"Whichever is in front"}),!a&&e.browserProfile?n.jsxs("option",{value:e.browserProfile,children:[e.browserProfile," (not found)"]}):null,i.map(o=>n.jsxs("option",{value:o.directory,children:[o.name,o.directory==="Default"?"":` (${o.directory})`]},o.directory))]})})}const I3=["com.google.Chrome","com.apple.Safari","org.chromium.Chromium","com.microsoft.edgemac","com.brave.Browser","org.mozilla.firefox","company.thebrowser.Browser"];function P3(e){return I3.includes(e)}function $3({chosen:e,onClose:t,onPick:s}){const r=le(()=>T.installedApps(),[]),[i,a]=f.useState(""),[l,o]=f.useState(""),c=f.useMemo(()=>{var h;const u=((h=r.data)==null?void 0:h.apps)??[],d=i.trim().toLowerCase();return u.filter(m=>!d||m.name.toLowerCase().includes(d)||m.id.toLowerCase().includes(d)).slice(0,60)},[r.data,i]);return n.jsxs(kt,{title:"Add an app",onClose:t,children:[n.jsx("input",{autoFocus:!0,"aria-label":"Search apps",placeholder:"Search installed apps",value:i,onChange:u=>a(u.target.value)}),n.jsx(re,{message:r.error}),r.data?c.length===0?n.jsx(ce,{children:"No app matches."}):n.jsx("ul",{className:"ui-list","aria-label":"Installed apps",children:c.map(u=>{const d=e.includes(u.id);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx(Es,{id:u.id,name:u.name,size:"sm"}),n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title",children:u.name}),n.jsx("span",{className:"ui-list-sub mono",children:u.id})]}),n.jsx(R,{size:"sm",disabled:d,onClick:()=>s(u.id),children:d?"Allowed":"Allow"})]},u.id)})}):n.jsx(ce,{children:"Reading your Applications folder…"}),n.jsx(Ct,{summary:"Add by bundle identifier instead",children:n.jsxs(J,{children:[n.jsx("input",{"aria-label":"Bundle identifier",placeholder:"com.apple.TextEdit",value:l,onChange:u=>o(u.target.value)}),n.jsx(R,{disabled:!l.trim(),onClick:()=>s(l.trim()),children:"Allow this identifier"})]})})]})}function M3({data:e,error:t,reload:s,compact:r=!1,refresh:i,screenshotSrc:a,onScreenshotError:l,onScreenshotLoad:o,controls:c=!0}){var I,A,_;const[u,d]=f.useState(!1),[h,m]=f.useState(null),[p,g]=f.useState(null),[y,b]=f.useState(null),x=async z=>{d(!0),m(null),b(null);try{const L=z!=="stop"&&(e!=null&&e.session)?await T.browserControl(z,e.session.id):await T.browserControl(z);z==="takeover"?L.hand&&L.session?g(L.session.id):b(L.handMessage??null):g(null)}catch(L){m(L instanceof Error?L.message:String(L))}finally{d(!1),s()}},v=p&&((I=e==null?void 0:e.session)==null?void 0:I.id)===p&&e.state==="paused"?p:null,j=!!(e!=null&&e.enabled)&&!u,w=(e==null?void 0:e.mode)==="computer",S=(e==null?void 0:e.mode)==="extension",k=w?"Stop computer control interrupts native input and revokes access. Take over pauses agent input. Release ends this conversation’s control without closing your apps. Already dispatched actions cannot be undone. Avoid using the same mouse and keyboard while the agent is working.":"Stop all browsers closes every session and revokes access until you resume. Take over, Resume and Close & release affect only the selected conversation. An in-flight action is interrupted by closing its tabs. Actions already submitted cannot be undone.",N=e!=null&&e.busy?"Working":(e==null?void 0:e.state)==="running"?"Ready":(e==null?void 0:e.state)??"Connecting",C=e!=null&&e.busy||(e==null?void 0:e.state)==="running"?"good":(e==null?void 0:e.state)==="stopped"||(e==null?void 0:e.state)==="error"?"critical":void 0;return n.jsxs("section",{className:"browser-panel","data-compact":r?"true":void 0,"aria-label":"Host browser",children:[n.jsxs("div",{className:"browser-heading",children:[n.jsxs("div",{children:[r?null:n.jsx("p",{className:"browser-eyebrow",children:"On your host machine"}),n.jsx("h2",{className:"browser-title",children:w?"Computer":S?"Your browser":"Browser"})]}),n.jsx(ve,{tone:C,children:n.jsx("span",{role:"status",children:N})})]}),r?n.jsx("a",{className:"browser-full-view",href:"#/browser",children:w?"Open computer view & settings ↗":"Open full browser view ↗"}):n.jsx("p",{className:"ui-page-lede",children:w?"Your apps, operated through macOS accessibility, screenshots and input. No browser debugging connection.":S?"Your own Chrome, signed in as you, working in background tabs grouped as “buddi”. You keep browsing.":"A real browser window, driven by your assistant. You stay in control."}),n.jsx(re,{message:t??h}),c?n.jsxs(J,{children:[n.jsx(R,{variant:"danger",disabled:!j||(e==null?void 0:e.state)==="stopped",onClick:()=>void x("stop"),children:w?"Stop computer control":"Stop all browsers"}),n.jsx(R,{disabled:!j||!(e!=null&&e.session)||(e==null?void 0:e.state)==="paused",onClick:()=>void x("takeover"),children:"Take over"}),n.jsx(R,{disabled:!j||(e==null?void 0:e.busy)||!["stopped","paused"].includes((e==null?void 0:e.state)??""),onClick:()=>void x("resume"),children:"Resume access"}),n.jsx(R,{disabled:!j||!(e!=null&&e.session),onClick:()=>void x("release"),children:w?"Release control":"Close & release"})]}):null,c?r?n.jsx(Ct,{summary:"About these controls",children:n.jsx("p",{className:"muted",children:k})}):n.jsx("p",{className:"muted",children:k}):null,y?n.jsx(W,{tone:"warning",role:"status",children:y}):null,e!=null&&e.message&&!v?n.jsx(W,{tone:"warning",role:"status",children:e.message}):null,e!=null&&e.session?n.jsxs("div",{className:"browser-task",children:[n.jsxs("div",{className:"ui-row",children:[n.jsx("strong",{children:e.session.agentId}),n.jsxs("span",{className:"muted",children:[e.session.steps," / ",e.session.maxSteps," steps"]})]}),r?null:n.jsx("p",{children:e.session.task}),n.jsxs("p",{className:"muted",children:["Last action: ",e.lastAction??"None"," · Access expires ",new Date(e.session.expiresAt).toLocaleTimeString()]})]}):n.jsx("p",{className:"browser-task muted",children:e!=null&&e.enabled?w?"No agent is driving. Ask an agent granted browser.* to open a website or an allowed native app.":"No agent is driving. Ask an agent granted browser.* to open a website.":"The host browser is unavailable. Start buddi serve on a machine with a desktop session."}),v?n.jsx(x3,{sessionId:v,csrf:Hi(),onGiveBack:()=>void x("resume")}):null,n.jsxs("div",{className:"browser-window",hidden:!!v,children:[n.jsxs("div",{className:"browser-address",children:[n.jsx("span",{"aria-hidden":"true",children:"◉"}),n.jsx("span",{children:((A=e==null?void 0:e.page)==null?void 0:A.url)??(w?"Waiting for an application":"Waiting for a website")})]}),e!=null&&e.hasScreenshot&&e.page?n.jsxs("figure",{children:[n.jsx("img",{src:a??`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:""}${i?`&tick=${i}`:""}`,alt:`Last browser observation: ${e.page.title||e.page.url}`,...l?{onError:l}:{},...o?{onLoad:o}:{}},a??e.page.id),n.jsxs("figcaption",{children:["Last observation · ",new Date(e.page.capturedAt).toLocaleTimeString()," · ",e.page.title||"Untitled page"]})]}):n.jsxs("div",{className:"browser-empty",children:[n.jsx("strong",{children:w?"Your selected app will appear here":"Your browser activity will appear here"}),n.jsx("p",{children:w?"Only the selected app window is captured, not the whole desktop. This preview is not interactive.":"This is a view of the host browser, not a second browser or a remote desktop."})]})]}),(((_=e==null?void 0:e.page)==null?void 0:_.tabs.length)??0)>1?n.jsx(Ct,{summary:`${e.page.tabs.length} open tabs`,children:n.jsx("ul",{className:"ui-prose",children:e.page.tabs.map(z=>n.jsxs("li",{children:[z.title||z.id," — ",z.url]},z.id))})}):null,n.jsxs("p",{className:"muted",children:[w?"Sign in directly in the host app during takeover. Don’t send passwords or MFA codes in chat. Native apps retain your existing logins and documents. Secure accessibility fields are masked; other sensitive window content can still appear in screenshots.":"Sign in directly in this conversation’s host tab during takeover. Don’t send passwords or MFA codes in chat. Agent tabs share saved logins and cookies."," ",v?"While you are driving this is a live view of the page; nothing you type is kept.":"Screenshots update after agent actions; this is not a live video feed."]})]})}const O3=2e3,D3=5;function _3(e,t){if(!e.hasScreenshot||!e.page)return null;const s=e.session?`&sessionId=${encodeURIComponent(e.session.id)}`:"";return`/api/browser/screenshot?v=${encodeURIComponent(e.page.id)}${s}`}function L3({status:e,error:t,reload:s,steps:r,live:i,focusedStepId:a=null}){var j;const[l,o]=f.useState(0),[c,u]=f.useState(0),d=c>=D3;f.useEffect(()=>{if(!i||d)return;const w=window.setInterval(()=>{typeof document<"u"&&document.hidden||o(S=>S+1)},O3);return()=>window.clearInterval(w)},[i,d]);const h=f.useRef(null);i&&(e!=null&&e.session)&&(h.current=e);const[m,p]=f.useState(null),g=f.useRef(null),y=((j=e==null?void 0:e.page)==null?void 0:j.id)??null;f.useEffect(()=>{const w=i&&e?_3(e):null;if(!w||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let S=!1;return(async()=>{try{const k=await fetch(w);if(!k.ok||S)return;const N=await k.blob();if(S)return;const C=URL.createObjectURL(N);g.current&&URL.revokeObjectURL(g.current),g.current=C,p(C)}catch{}})(),()=>{S=!0}},[i,y]),f.useEffect(()=>()=>{g.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(g.current)},[]);const b=h.current,x=i?e:b?m?b:{...b,hasScreenshot:!1}:e,v=r.at(-1)??null;return n.jsxs("div",{className:"wb-browser","data-testid":"browser-view","data-live":i?"true":"false",children:[n.jsx(M3,{data:x,error:t,reload:s,compact:!0,controls:i,...i?{refresh:l}:{},...!i&&m?{screenshotSrc:m}:{},onScreenshotError:()=>u(w=>w+1),onScreenshotLoad:()=>u(0)}),i?d?n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"The last observation could not be loaded. Showing what arrived before it."}):null:n.jsx("p",{className:"muted wb-browser-ended",role:"status",children:"This session has ended. What is on this panel is the last thing it showed."}),n.jsx(F3,{steps:r,newestId:(v==null?void 0:v.id)??null,focusedId:a??null,live:i})]})}function F3({steps:e,newestId:t,focusedId:s,live:r}){const i=f.useRef(null);return f.useEffect(()=>{var l;if(!s||!i.current)return;const a=i.current.querySelector(`[data-step="${CSS!=null&&CSS.escape?CSS.escape(s):s}"]`);(l=a==null?void 0:a.scrollIntoView)==null||l.call(a,{block:"nearest"})},[s]),e.length===0?n.jsx("p",{className:"muted wb-browser-empty",children:r?"No action taken on this screen yet.":"This conversation took no action on the screen."}):n.jsx("section",{className:"wb-browser-steps","aria-label":"Steps taken on this screen",children:n.jsx("ol",{className:"wb-browser-list",ref:i,children:e.map((a,l)=>{const o=a.awaiting?"awaiting":a.ok===null?"running":a.ok?"ok":"failed";return n.jsxs("li",{"data-step":a.id,className:"wb-browser-step","data-state":o,"data-newest":a.id===t?"true":void 0,"data-focused":a.id===s?"true":void 0,children:[n.jsx("span",{className:"wb-browser-index mono",children:l+1}),n.jsxs("span",{className:"wb-browser-what",children:[n.jsx("strong",{children:a.action}),a.target?n.jsx("span",{className:"muted wb-browser-target",children:a.target}):null,a.error?n.jsx("span",{className:"wb-browser-error",children:a.error}):null]}),n.jsx("span",{className:"wb-browser-outcome","data-state":o,children:o==="awaiting"?"Awaiting approval":o==="running"?"Working":o==="ok"?"Done":"Failed"})]},a.id)})})})}function z3({agentId:e,conversationId:t}){const{data:s,error:r,reload:i}=le(()=>T.host(e,t),[e,t],2e3),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=async p=>{c(!0),l(null);try{await p(),i()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},d=(s==null?void 0:s.permissions)??[],h=(s==null?void 0:s.runs)??[],m=d.some(p=>!p.conversationId)?"Always allowed":d.length?"Conversation auto-mode":"Ask each time";return n.jsx(Ct,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${h.length?` · ${h.length} running`:""}`,children:n.jsxs(Q,{gap:"sm",children:[n.jsx("p",{className:"muted",children:"Commands run as your user, not in a sandbox. Auto-mode covers all commands within its scope. Stop interrupts a command; revoke also ends the permission. Neither undoes completed changes."}),n.jsx(re,{message:a??r}),d.map(p=>n.jsxs(J,{children:[n.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),n.jsx(R,{size:"sm",disabled:o,onClick:()=>void u(()=>T.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),d.length?null:n.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),h.map(p=>n.jsxs(Q,{gap:"sm",children:[n.jsxs("p",{children:[p.agentId," · ",n.jsx("span",{className:"mono",children:p.cwd})]}),n.jsx(jt,{children:p.command}),n.jsx(jt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
|
|
105
|
+
${p.stderr}`:"Waiting for output…"}),n.jsx(J,{children:n.jsx(R,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>T.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const rC="browser.act",U3="browser.status",gu=new Set([rC,U3]);function B3(e,t,s){const r=e==null?void 0:e.session;return!r||!t||!s||r.agentId!==t||r.conversationId!==s?null:{id:`host-browser:${r.id}`,title:e.mode==="computer"?"Computer":"Browser",tool:"Host browser",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function W3(e,t){return{...e,title:`${t==="computer"?"Computer":"Browser"} (ended)`,pinned:!1}}function H3(e){var r;const t=[],s=new Map;for(const i of e)for(const a of i.blocks??[]){if(a.type==="tool_use"&&a.name===rC){const o={id:a.id,action:K3(a.input)??"act",target:V3(a.input),ok:null,awaiting:!1,error:null,at:i.at??null};t.push(o),s.set(a.id,o);continue}if(a.type!=="tool_result")continue;const l=s.get(a.toolUseId);if(l){if(((r=a.approval)==null?void 0:r.state)==="pending"){l.awaiting=!0,l.ok=null,l.error=null;continue}l.awaiting=!1,l.ok=a.ok,l.error=a.ok?null:G3(a)}}return t}function Lw(e,t){var r;let s=!1;for(const i of e)for(const a of i.blocks??[])if(a.type==="tool_use"&&a.id===t&&(s=gu.has(a.name)),a.type==="tool_result"&&a.toolUseId===t&&((r=a.approval)==null?void 0:r.state)==="pending")return null;return s?t:null}function K3(e){if(e===null||typeof e!="object")return null;const t=e.action;return typeof t=="string"&&t!==""?t:null}function V3(e){if(e===null||typeof e!="object")return null;const t=e;for(const r of["url","appId","direction","key","tabId"]){const i=t[r];if(typeof i=="string"&&i!=="")return i}const s=t.target;if(s!==null&&typeof s=="object"){const r=s,i=r.name;if(typeof i=="string"&&i!=="")return i;const a=r.ref;if(typeof a=="string"&&a!=="")return a;if(typeof r.x=="number"&&typeof r.y=="number")return`${r.x}, ${r.y}`}return null}function G3(e){for(const t of[e.error,e.output]){if(typeof t=="string"&&t.trim()!=="")return t.trim();if(t!==null&&typeof t=="object")for(const s of["message","error","reason"]){const r=t[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}}return null}function Y3({agentId:e,groupId:t,currentId:s,timezone:r,onSelect:i,onNew:a}){const[l,o]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(0);return f.useEffect(()=>{let m=!1;return o(null),u(null),(t?Fe.groupConversations(t):Fe.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,t,d]),n.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[n.jsxs("div",{className:"ui-toolbar",children:[n.jsx("strong",{children:"Past conversations"}),n.jsx("button",{className:"ui-btn",onClick:a,children:"New conversation"})]}),c?n.jsxs("p",{role:"alert",children:[c," ",n.jsx("button",{className:"ui-btn",onClick:()=>h(m=>m+1),children:"Retry"})]}):l===null?n.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?n.jsx("p",{className:"muted",children:"No conversations yet."}):n.jsx("ul",{children:l.map(m=>n.jsx("li",{children:n.jsxs("a",{href:t?Yl(t,m.id):Je(e,m.id),"aria-current":m.id===s?"page":void 0,onClick:p=>{p.button===0&&!p.metaKey&&!p.ctrlKey&&!p.shiftKey&&!p.altKey&&(p.preventDefault(),i(m.id))},children:[n.jsx("span",{children:m.preview||m.opening||"Untitled conversation"}),n.jsxs("small",{children:[Ve(m.lastMessageAt??m.startedAt??m.createdAt??null,r)," · ",m.messageCount," messages",m.id===s?" · Current":""]})]})},m.id))}),n.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?n.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const iC="buddi.dismissedTabs";function q3(){try{const e=JSON.parse(sessionStorage.getItem(iC)??"{}");return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,t])=>Array.isArray(t)&&t.every(s=>typeof s=="string")))}catch{return{}}}function Fw(e){try{sessionStorage.setItem(iC,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const Q3=350,J3=60;function X3({conversationId:e,onText:t,onNotice:s}){const[r,i]=f.useState("idle"),a=f.useRef("idle"),l=v=>{a.current=v,i(v)},o=f.useRef(null),c=f.useRef(null),u=f.useRef(null),d=f.useRef(null),h=f.useRef(null),m=f.useRef({onText:t,onNotice:s,conversationId:e});m.current={onText:t,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(a.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let v;try{v=await wF(S=>{var k;return(k=h.current)==null?void 0:k.call(h,S)})}catch(S){d.current=null,l("idle"),m.current.onNotice(yF(S));return}const j=c.current;c.current=null;const w=a.current;if(j==="discard"||w!=="starting"){v.cancel(),w==="starting"&&l("idle");return}o.current=v,l("recording"),u.current=window.setTimeout(()=>void y(!1),xF),j&&y(j.sendNow)},y=async v=>{d.current=null;const j=o.current;if(!j){a.current==="starting"&&(c.current={sendNow:v});return}o.current=null,p(),l("transcribing");try{const w=await j.stop();if(w.size<=44){m.current.onNotice("Nothing was recorded.");return}const S=new File([w],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),k=await Fe.attach(S),N=m.current.conversationId,C=await Fe.transcribe({artifactId:k.artifactId,...N?{conversationId:N}:{}});m.current.onText(C.text,v)}catch(w){m.current.onNotice(w instanceof ge||w instanceof Error?w.message:String(w))}finally{l("idle")}},b=()=>{d.current=null;const v=o.current;if(!v){a.current==="starting"&&(c.current="discard");return}o.current=null,p(),v.cancel(),l("idle")};f.useEffect(()=>{const v=j=>{if(d.current===null)return;const w=Date.now()-d.current;d.current=null,w>=Q3&&y(j.shiftKey)};return window.addEventListener("pointerup",v),()=>window.removeEventListener("pointerup",v)},[]);const x=r==="starting"||r==="recording";return f.useEffect(()=>{if(!x)return;const v=j=>{j.isComposing||j.repeat||(j.key==="Escape"?(j.preventDefault(),j.stopPropagation(),b()):j.key==="Enter"&&(j.preventDefault(),j.stopPropagation(),y(j.shiftKey)))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[x]),f.useEffect(()=>()=>{var v;(v=o.current)==null||v.cancel(),p()},[]),{state:r,hold:()=>{d.current=Date.now(),g()},start:()=>{d.current=null,g()},finish:v=>void y(v),discard:b,levels:h}}function Z3({disabled:e,voice:t}){const s=i=>{e||i.button>0||t.state!=="idle"||(i.preventDefault(),t.hold())},r=i=>{i.detail!==0||e||t.state!=="idle"||t.start()};return n.jsx("button",{type:"button",className:"ui-icon-btn wb-mic","data-size":"sm","aria-label":"Talk",title:"Talk: click to start, or hold to speak and let go to stop",disabled:e,onPointerDown:s,onClick:r,onContextMenu:i=>i.preventDefault(),children:n.jsx(ye,{name:"mic"})})}function ez({voice:e}){const t=f.useRef(null),s=e.state==="transcribing";return f.useEffect(()=>{var r;(r=t.current)==null||r.focus()},[]),n.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[n.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),n.jsxs("div",{className:"wb-listening-row",children:[n.jsx(tz,{sink:e.levels,frozen:s}),n.jsx("button",{type:"button",className:"wb-send","data-variant":"quiet","aria-label":"Discard recording",title:"Discard (Escape)",disabled:s,onClick:()=>e.discard(),children:n.jsx(ye,{name:"close"})}),n.jsx("button",{ref:t,type:"button",className:"wb-send","aria-label":"Stop and transcribe",title:"Stop and transcribe (Enter); Shift sends at once",disabled:s,onClick:r=>e.finish(r.shiftKey),children:n.jsx(ye,{name:"check"})})]})]})}function tz({sink:e,frozen:t}){const[s,r]=f.useState(()=>Array(J3).fill(0));return f.useEffect(()=>{if(!t)return e.current=i=>r(a=>[...a.slice(1),i]),()=>{e.current=null}},[t]),n.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((i,a)=>n.jsx("span",{className:"wb-wave-bar",style:{"--level":i.toFixed(3)}},a))})}const nz="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",Uc="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",sz=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function rz(e={}){var r;const t=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!t||typeof t.getDisplayMedia!="function")throw new Error(nz);let s;try{s=await t.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(i){if(sz(i))return null;throw new Error(Uc)}try{const i=e.document??document,a=i.createElement("video");a.muted=!0,a.playsInline=!0,a.srcObject=s,await new Promise((d,h)=>{a.onloadedmetadata=()=>d(),a.onerror=()=>h(new Error(Uc))}),await a.play(),await new Promise(d=>{const h=a.requestVideoFrameCallback;typeof h=="function"?h.call(a,()=>d()):setTimeout(d,120)});const l=i.createElement("canvas");l.width=a.videoWidth,l.height=a.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(Uc);o.drawImage(a,0,0);const c=await new Promise(d=>l.toBlob(d,"image/png"));if(!c)throw new Error(Uc);const u=(((r=e.now)==null?void 0:r.call(e))??new Date).toISOString().slice(0,19).replace("T"," ").replace(/:/g,".");return new File([c],`Tab ${u}.png`,{type:"image/png"})}finally{s.getTracks().forEach(i=>i.stop())}}const zw="Send files once the agent has answered.",kp="wb-composer-input",Qx=f.forwardRef(function({disabled:t,running:s,onSend:r,onStop:i,agentName:a,draft:l,model:o,setupHref:c,thinking:u,onThinking:d,onOpenFile:h,mentions:m,history:p,threadKey:g,conversationId:y,readAloud:b,onReadAloud:x,placeholder:v,slim:j},w){var Rs;const S=g?`buddi.draft.${g}`:null,k=H=>{if(!H)return"";try{return window.localStorage.getItem(H)??""}catch{return""}},[N,C]=f.useState(()=>k(S)),[I,A]=f.useState([]),[_,z]=f.useState(!1),[L,E]=f.useState(null),[M,D]=f.useState(!1),U=f.useRef(null),$=f.useRef(null),[B,O]=f.useState(null),[K,G]=f.useState(0),se=B&&m?m.filter(H=>H.handle.toLowerCase().startsWith(B.query.toLowerCase())||H.name.toLowerCase().startsWith(B.query.toLowerCase())).slice(0,6):[],ue=(H,Ee)=>{if(!m||m.length===0){O(null);return}const nt=H.slice(0,Ee),St=/(^|\s)@([\w-]*)$/.exec(nt);if(!St){O(null);return}O({start:Ee-St[2].length-1,query:St[2]}),G(0)},ie=H=>{if(!B)return;const Ee=$.current,nt=Ee?Ee.selectionStart:N.length,St=`${N.slice(0,B.start)}@${H} ${N.slice(nt)}`;C(St),X<0&&we(St),O(null),window.requestAnimationFrame(()=>{if(!Ee)return;const hn=B.start+H.length+2;Ee.focus(),Ee.setSelectionRange(hn,hn),Rt()})},ee=p??[],[X,de]=f.useState(-1),Ie=f.useRef(N),Se=f.useRef(S);if(Se.current!==S){Se.current=S;const H=k(S);Ie.current=H,H!==N&&(C(H),de(-1),O(null))}const we=H=>{if(Ie.current=H,!!S)try{H===""?window.localStorage.removeItem(S):window.localStorage.setItem(S,H)}catch{}},Ce=H=>{C(H),O(null);const Ee=$.current;Ee&&(Ee.value=H,Ee.setSelectionRange(H.length,H.length)),window.requestAnimationFrame(Rt)},mt=H=>!H.value.slice(0,H.selectionStart??H.value.length).includes(`
|
|
106
|
+
`),he=()=>N===""||X>=0&&N===ee[X],Me=()=>{X<0||(de(-1),Ce(Ie.current))},Pe=I.some(H=>H.state==="uploading"),Ye=I.length>0,Y=s&&Ye,me=!t&&!Pe&&!Y&&N.trim()!=="",oe=H=>{for(const Ee of Array.from(H??[])){const nt=`${Ee.name}:${Ee.size}:${Math.random().toString(36).slice(2,8)}`,St=Ee.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(Ee):null;A(hn=>[...hn,{key:nt,filename:Ee.name||"Pasted image",mime:Ee.type||"application/octet-stream",sizeBytes:Ee.size,thumbnail:St,state:"uploading"}]),Fe.attach(Ee).then(hn=>A(pe=>pe.map(He=>He.key===nt?{...He,state:"ready",uploaded:hn}:He))).catch(hn=>A(pe=>pe.map(He=>He.key===nt?{...He,state:"failed",error:hn instanceof ge?hn.message:String(hn)}:He)))}},Oe=H=>{H.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(H.thumbnail)},Le=H=>{const Ee=I.find(nt=>nt.key===H);Ee&&(Oe(Ee),Ee.state==="ready"&&Ee.uploaded&&Fe.discardAttachment(Ee.uploaded.artifactId).catch(()=>{})),A(nt=>nt.filter(St=>St.key!==H))};f.useImperativeHandle(w,()=>({addFiles:H=>{var Ee;oe(H),(Ee=$.current)==null||Ee.focus()},focus:()=>{var H;return(H=$.current)==null?void 0:H.focus()}}));const Ue=f.useRef(I);Ue.current=I,f.useEffect(()=>()=>Ue.current.forEach(Oe),[]);const at=f.useRef(0);f.useEffect(()=>{if(!l||l.at===at.current)return;at.current=l.at,C(Ee=>Ee.trim()===""?l.text:Ee),X<0&&N.trim()===""&&we(l.text);const H=$.current;H&&(H.focus(),window.requestAnimationFrame(()=>{H.style.height="auto",H.style.height=`${Math.min(H.scrollHeight,200)}px`,H.setSelectionRange(H.value.length,H.value.length)}))},[l]);const Rt=()=>{const H=$.current;H&&(H.style.height="auto",H.style.height=`${Math.min(H.scrollHeight,200)}px`)},bn=H=>{const Ee=(H??N).trim();if(H===void 0?!me:t||Pe||Y||Ee==="")return;const nt=I.filter(St=>St.state==="ready"&&St.uploaded).map(St=>St.uploaded);r(Ee,nt),I.forEach(Oe),de(-1),we(""),C(""),A([]),window.requestAnimationFrame(Rt)},V=H=>{if(B&&se.length>0){if(H.key==="ArrowDown"){H.preventDefault(),G(Ee=>(Ee+1)%se.length);return}if(H.key==="ArrowUp"){H.preventDefault(),G(Ee=>(Ee-1+se.length)%se.length);return}if(H.key==="Enter"||H.key==="Tab"){H.preventDefault(),ie(se[K].handle);return}if(H.key==="Escape"){H.preventDefault(),O(null);return}}if(H.key==="ArrowUp"&&!H.shiftKey&&!H.altKey&&!H.metaKey&&!H.ctrlKey){const Ee=H.currentTarget;if(ee.length>0&&X+1<ee.length&&mt(Ee)&&he()){H.preventDefault(),X<0&&(Ie.current=N),de(X+1),Ce(ee[X+1]);return}}if(H.key==="ArrowDown"&&!H.shiftKey&&!H.altKey&&!H.metaKey&&!H.ctrlKey&&X>=0&&N===ee[X]){if(H.preventDefault(),X===0){Me();return}de(X-1),Ce(ee[X-1]);return}if(H.key==="Escape"&&X>=0){H.preventDefault(),Me();return}H.key==="Enter"&&!H.shiftKey&&(H.preventDefault(),bn())},xe=H=>{var nt;const Ee=Array.from(((nt=H.clipboardData)==null?void 0:nt.files)??[]);Ee.length!==0&&(H.preventDefault(),oe(Ee))},De=I.filter(H=>H.state==="failed"),rt=De.length,It=X3({conversationId:y??null,onNotice:E,onText:(H,Ee)=>{const nt=N.trim()===""?H:`${N.replace(/\s+$/,"")} ${H}`;if(Ee){bn(nt);return}Ce(nt),X<0&&we(nt)}}),it=It.state!=="idle",en=f.useRef(!1);return f.useEffect(()=>{var H;en.current&&!it&&((H=$.current)==null||H.focus(),window.requestAnimationFrame(Rt)),en.current=it},[it]),n.jsx("div",{className:"wb-composer","data-testid":"composer","data-slim":j||void 0,"data-busy":N.trim()!==""||Ye||it?"true":void 0,children:n.jsxs("div",{className:"wb-composer-box","data-focused":M||it,"data-disabled":t,"data-listening":it||void 0,children:[I.length>0?n.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:I.map(H=>n.jsx("span",{role:"listitem",children:n.jsx(sh,{name:H.filename,mime:H.mime,sizeBytes:H.sizeBytes,thumbnail:H.thumbnail,state:H.state,error:H.error,onRemove:()=>Le(H.key),...h&&H.state==="ready"&&H.uploaded?{onOpen:()=>h(iz(H.uploaded))}:{},size:"sm"})},H.key))}):null,n.jsxs("label",{className:"sr-only",htmlFor:kp,children:["Message ",a]}),n.jsx("textarea",{id:kp,ref:$,value:N,rows:j?1:2,placeholder:s?`${a} is working…`:v??`Message ${a}`,onChange:H=>{C(H.target.value),X<0&&we(H.target.value),ue(H.target.value,H.target.selectionStart??H.target.value.length),Rt()},onFocus:()=>D(!0),onBlur:()=>D(!1),onKeyDown:V,onPaste:xe,disabled:t,hidden:it}),it?n.jsx(ez,{voice:It}):null,!it&&B&&se.length>0?n.jsx("div",{className:"wb-mentions",role:"listbox","aria-label":"Members",children:se.map((H,Ee)=>n.jsxs("button",{type:"button",role:"option","aria-selected":Ee===K,className:"wb-mention","data-active":Ee===K||void 0,onMouseDown:nt=>{nt.preventDefault(),ie(H.handle)},children:[n.jsxs("span",{className:"wb-mention-handle",children:["@",H.handle]}),n.jsx("span",{className:"wb-mention-name",children:H.name})]},H.handle))}):null,n.jsxs("div",{className:"wb-composer-row",hidden:it,children:[n.jsx("input",{ref:U,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:H=>{oe(H.target.files),H.target.value=""}}),n.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Attach a file",title:"Attach a file — or paste one, or drop it anywhere on the chat",onClick:()=>{var H;return(H=U.current)==null?void 0:H.click()},disabled:t,children:n.jsx(ye,{name:"clip"})}),n.jsx(Z3,{disabled:t,voice:It}),n.jsx("button",{className:"ui-icon-btn","data-size":"sm","aria-label":"Snap a tab",title:"Snap a tab — one picture of another tab in this browser, attached here",onClick:()=>{E(null),z(!0),rz().then(H=>{var Ee;H&&(oe([H]),(Ee=$.current)==null||Ee.focus())}).catch(H=>E(H instanceof Error?H.message:String(H))).finally(()=>z(!1))},disabled:t||_,children:n.jsx(ye,{name:"camera"})}),o?c?n.jsxs("a",{className:"wb-composer-model",href:c,title:"The model this agent runs on. Click to change it.",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):n.jsxs("span",{className:"wb-composer-model",title:"The model this agent runs on",children:[n.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),o]}):null,d?n.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":Bc(u),disabled:t||s,title:s?`Wait for ${a} to finish — this run started with thinking ${Bc(u)?"on":"off"}`:Bc(u)?"Reasoning before the answer is on. Click to turn it off — answers come back faster.":"Reasoning before the answer is off. Click to turn it on.",onClick:()=>d(Bc(u)?"off":"on"),children:[n.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),"Thinking"]}):null,x?n.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!b,title:b?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>x(!b),children:n.jsx(ye,{name:"speaker"})}):null,n.jsx("span",{className:"wb-hint","data-shown":N!==""&&!s||rt>0||Y||L!==null,"data-tone":rt>0||L!==null?"critical":void 0,children:rt>0?rt===1&&((Rs=De[0])!=null&&Rs.error)?De[0].error:`${rt} files failed to upload and will not be sent`:L!==null?L:Y?zw:"Enter sends, Shift+Enter for a new line"}),s?n.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:i,children:"Stop"}):null,n.jsx("button",{className:"wb-send","aria-label":"Send",title:Y?zw:Pe?"Waiting for the upload to finish":s?`Send — ${a} picks it up between steps`:"Send",onClick:()=>bn(),disabled:!me,children:n.jsx(ye,{name:"send"})})]})]})})});function Bc(e){return(e??"on")==="on"}function iz(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function az({question:e,disabled:t,onAnswer:s,onSkip:r}){const[i,a]=f.useState("");return f.useEffect(()=>{if(t)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[t,r]),n.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[n.jsxs("div",{className:"wb-question-head",children:[n.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),n.jsx(R,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:t,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),n.jsx("strong",{children:lz(e.question)})]}),e.options.length>0?n.jsx("div",{className:"wb-question-options",children:e.options.map((l,o)=>n.jsxs("button",{className:"wb-question-option","data-recommended":l.recommended||void 0,disabled:t,onClick:()=>s(l.label,l.id),children:[n.jsx("span",{className:"wb-question-number",children:o+1}),n.jsxs("span",{children:[n.jsxs("span",{className:"wb-question-label",children:[l.label,l.recommended?n.jsx("em",{children:"Recommended"}):null]}),l.hint?n.jsx("small",{children:l.hint}):null]})]},l.id))}):null,e.allowOther?n.jsxs("form",{className:"wb-question-other",onSubmit:l=>{l.preventDefault(),i.trim()&&s(i.trim())},children:[n.jsx("input",{value:i,onChange:l=>a(l.target.value),placeholder:e.options.length?"Something else…":"Type your answer…",disabled:t}),n.jsx("button",{className:"ui-btn","data-variant":"accent",disabled:t||!i.trim(),children:"Answer"})]}):null,n.jsx("p",{className:"wb-question-note",children:"This answers a question. It does not approve an action. Esc skips it."})]})}function lz(e){const t=[];let s=0;for(const r of e.matchAll(/https:\/\/[^\s<>"']+/g)){const i=r[0].replace(/[.,;:!?)\]]+$/,""),a=r.index??0;a>s&&t.push(e.slice(s,a)),t.push(n.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",children:i},a)),s=a+i.length}return s<e.length&&t.push(e.slice(s)),t}function oz(e,t){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null?!1:t-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function cz(e){const t=e/36e5;if(t>=1&&Number.isInteger(t))return`${t} hour${t===1?"":"s"}`;const s=Math.round(e/6e4);return`${s} minute${s===1?"":"s"}`}function uz(e){const{lifetime:t,startedAt:s,now:r,timezone:i}=e;if(!t||t.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const a=`A conversation ends after ${cz(t.idleTimeoutMs)} idle, or once its transcript grows past ${Math.round(t.maxChars/1e3)}k characters. What the agent remembers about you carries over.`,l=`${t.messages} message${t.messages===1?"":"s"}`;if(oz(t,r))return{text:`${l} · your next message starts a fresh one`,title:a,tone:"note"};const o=s?ze(s,r):"";return{text:o===""?l:`${l} · started ${o}`,title:s?`Started ${Ve(s,i)}. ${a}`:a,tone:"quiet"}}const xu=320,aC="buddi.chatWidth";function dz({timezone:e,agents:t,agentId:s,defaultAgentId:r=null,group:i=null,onEditGroup:a,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:d,canvasOpen:h,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:y,requestedTab:b,onConversationOpened:x}){var Xv,Zv,ej,tj,nj,sj;const v=qx(),[j,w]=f.useState([]),[S,k]=f.useState(null),[N,C]=f.useState(null),[I,A]=f.useState(null),[_,z]=f.useState([]),[L,E]=f.useState([]),[M,D]=f.useState(null),[U,$]=f.useState(!1),[B,O]=f.useState(new Map),[K,G]=f.useState(null),[se,ue]=f.useState(q3),[ie,ee]=f.useState([]),[X,de]=f.useState(!1),Ie=f.useRef(0),Se=f.useRef(null),[we,Ce]=f.useState(!1),mt=f.useRef(g??0),he=f.useRef(s),Me=f.useRef({agentId:s,conversationId:S});Me.current={agentId:s,conversationId:S};const Pe=se[S??""]??[],[Ye,Y]=f.useState(null),[me,oe]=f.useState(null),[Oe,Le]=f.useState(null),[Ue,at]=f.useState([]),[Rt,bn]=f.useState(!1),[V,xe]=f.useState(()=>Date.now()),[De,rt]=f.useState(hz),It=f.useRef(null),[it,en]=f.useState(null),[Rs,H]=f.useState(!1),[Ee,nt]=f.useState(null),[St,hn]=f.useState(W1),pe=f.useRef(St);pe.current=St;const He=f.useRef(null),[Te,tn]=f.useState(null),br=f.useCallback(F=>{hn(F),H1(F),F||cl()},[]),[Jn,kr]=f.useState(null),[Sr,Nr]=f.useState(null);f.useEffect(()=>{if(!s)return;const F=gz(s);F&&nt({text:F,at:Date.now()})},[s]);const Xe=i?`group:${i.id}`:s??null,fn=[...t.top,...t.middle,...t.bottom],Ne=fn.find(F=>F.id===s)??null,Zo=le(()=>T.providerAccounts(),[]),Qs=i?i.members.map(F=>fn.find(q=>q.id===F)).filter(F=>!!F):[],[mi,pl]=f.useState(null),pi=U?mi??s??null:null;f.useEffect(()=>{o==null||o(pi)},[pi,o]),f.useEffect(()=>()=>o==null?void 0:o(null),[o]),f.useEffect(()=>{let F=!1;return Fe.views().then(q=>{F||w(q.views??[])}).catch(()=>{}),()=>{F=!0}},[]),f.useEffect(()=>{if(!s)return;const F=he.current===s;if(he.current=s,F&&y&&y===Me.current.conversationId)return;let q=!1;return k(null),C(null),A(null),z([]),Y(null),$(!1),G(null),ee([]),ec(null),Ce(!1),en(null),y?(y!=="new"?k(y):A(Xe),()=>{q=!0}):((i?Fe.groupConversations(i.id):Fe.conversations(s)).then(be=>{if(q)return;const Ae=[...be.conversations??[]].sort(fz)[0];Ae?(k(Ae.id),x==null||x(s,Ae.id)):A(Xe)}).catch(()=>{q||A(Xe)}),()=>{q=!0})},[s,i==null?void 0:i.id,Xe,y,x]);const Mn=f.useCallback(F=>Fe.conversation(F).then(q=>{if(Me.current.conversationId===F){if(q.agentId!==Me.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(q),z(be=>be.filter(Ae=>!yf(q,Ae)))}}).catch(q=>{Me.current.conversationId===F&&Y(Ar(q))}),[]);f.useEffect(()=>{if(!S)return;let F=!1;return O(new Map),E([]),Fe.conversation(S).then(q=>{if(!F){if(q.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(q),z(be=>be.filter(Ae=>!yf(q,Ae)))}}).catch(q=>{F||Y(Ar(q))}),()=>{F=!0}},[S,s]),f.useEffect(()=>{if(!S)return;let F=!1;const q=window.setInterval(()=>{Fe.conversation(S).then(be=>{F||be.agentId!==Me.current.agentId||(C(be),z(Ae=>Ae.filter(Ke=>!yf(be,Ke))))}).catch(()=>{})},3e3);return()=>{F=!0,window.clearInterval(q)}},[S,s]),f.useEffect(()=>{if(!S)return;const F=Jd({url:Fe.streamUrl(S),onEvent:q=>{var be;switch(q.name){case"run.started":He.current=null,$(!0),D(null),pl(Yt(q.data.agentId));break;case"live":{const Ae=Yt(q.data.runId)??"",Ke=Number(q.data.turn??0),_e=q.data.kind==="thinking"?"thinking":"text",mn=Yt(q.data.text)??"",Xs=Date.now();if(_e==="text"){const Ps=He.current;He.current=Ps&&Ps.runId===Ae&&Ps.turn===Ke?{...Ps,text:Ps.text+mn}:{runId:Ae,turn:Ke,text:mn}}D(Ps=>{const Xi=Ps&&Ps.runId===Ae&&Ps.turn===Ke?Ps:{runId:Ae,turn:Ke,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return _e==="thinking"?{...Xi,thinking:Xi.thinking+mn,thinkingStartedAt:Xi.thinkingStartedAt??Xs}:{...Xi,text:Xi.text+mn,textStartedAt:Xi.textStartedAt??Xs}});break}case"live.snapshot":{const Ae=Yt(q.data.runId)??"",Ke=Number(q.data.turn??0),_e=Yt(q.data.text)??"",mn=Yt(q.data.thinking)??"",Xs=Number(q.data.startedAt??Date.now());He.current={runId:Ae,turn:Ke,text:_e},D({runId:Ae,turn:Ke,text:_e,thinking:mn,thinkingStartedAt:mn?Xs:null,textStartedAt:_e?Xs:null,settled:!1});break}case"live.settle":{const Ae=Yt(q.data.runId)??"",Ke=Number(q.data.turn??0);D(_e=>_e&&_e.runId===Ae&&_e.turn===Ke?{..._e,settled:!0}:_e);break}case"tool.called":{const Ae=Yt(q.data.toolUseId)??Yt(q.data.id),Ke=Yt(q.data.name)??Yt(q.data.tool)??"tool";Ae&&E(_e=>[..._e.filter(mn=>mn.toolUseId!==Ae),{toolUseId:Ae,name:Ke,startedAt:Date.now()}]);break}case"tool.result":{const Ae=Yt(q.data.toolUseId)??Yt(q.data.id);Ae&&E(Ke=>Ke.filter(_e=>_e.toolUseId!==Ae)),Mn(S);break}case"message.appended":Mn(S).then(()=>{D(Ae=>Ae!=null&&Ae.settled?null:Ae)});break;case"awaiting-approval":{const Ae=Yt(q.data.approvalId)??Yt(q.data.actionId),Ke=Yt(q.data.toolUseId);Ae&&Ke&&O(_e=>new Map(_e).set(Ke,Ae)),E(_e=>_e.filter(mn=>mn.toolUseId!==Ke)),Mn(S);break}case"run.finished":{$(!1),E([]),D(null),pl(null);const Ae=Yt(q.data.message);Y(Ae??null);const Ke=((be=He.current)==null?void 0:be.text.trim())??"";He.current=null,!Ae&&Ke!==""&&pe.current&&ld(Ke,S).then(_e=>{_e&&tn(_e)}),Mn(S);break}}}});return()=>F.close()},[S,Mn]),f.useEffect(()=>{const F=window.setInterval(()=>xe(Date.now()),L.length===0?6e4:1e3);return()=>window.clearInterval(F)},[L.length]);const gi=le(()=>s&&S?T.browser({agentId:s,conversationId:S}):Promise.resolve(void 0),[s,S],1500),Js=gi.error?void 0:gi.data,Cr=Js!=null&&Js.session&&Js.session.agentId===s&&Js.session.conversationId===S?Js:void 0,Pt=B3(Cr,s,S),Is=(Pt==null?void 0:Pt.id)??null,[gl,OA]=f.useState(null),Dv=Cr==null?void 0:Cr.mode;f.useEffect(()=>{Pt&&s&&S&&OA({agentId:s,conversationId:S,tab:W3(Pt,Dv)})},[Is,Dv,s,S]);const DA=gl&&gl.agentId===s&&gl.conversationId===S&&!Pe.includes(gl.tab.id)?gl.tab:null,nn=Pt??DA,_A=f.useMemo(()=>H3((N==null?void 0:N.messages)??[]),[N]),[LA,ec]=f.useState(null),FA=f.useMemo(()=>UF({messages:(N==null?void 0:N.messages)??[],descriptors:j}),[N,j]),Qi=s3(FA,S??null),uh=i3(i?null:s),_v=f.useMemo(()=>r3((N==null?void 0:N.messages)??[]),[N]),On=f.useMemo(()=>{const q=BF({messages:(N==null?void 0:N.messages)??[],descriptors:j,awaiting:B,served:Qi.served,...nn?{folded:gu}:{}}).filter(be=>be.source==="approval"||!Pe.includes(be.id));if(K&&!Pe.includes(K)&&!q.some(be=>be.id===K)){const be=VF((N==null?void 0:N.messages)??[],K,{redactInputOf:gu});be&&!gu.has(be.tool)&&q.push(be)}nn&&q.push(nn);for(const be of ie)q.push(hL(be));return uh&&q.unshift(a3(uh,_v)),it?[...q,l3(it)]:q},[N,j,B,it,Is,nn==null?void 0:nn.title,K,se,S,ie,Qi.served,uh,_v]),zA=f.useMemo(()=>{var q;const F=[];for(const be of(N==null?void 0:N.messages)??[]){if(be.role!=="user"||be.speaker&&be.speaker!=="owner")continue;const Ae=(q=be.blocks.find(Ke=>Ke.type==="text"))==null?void 0:q.text.trim();Ae&&F.unshift(Ae)}return F},[N]),dh=f.useMemo(()=>On.filter(F=>F.source==="approval"),[On]),tc=dh.at(-1)??null,nc=f.useMemo(()=>[...dh.map(F=>({approvalId:F.props.approvalId,toolUseId:F.id})),...((N==null?void 0:N.delegatedApprovals)??[]).map(F=>({approvalId:F.approvalId,toolUseId:F.toolUseId??"",askedBy:yz(F.chain,fn)}))],[dh,N==null?void 0:N.delegatedApprovals]),xl=f.useMemo(()=>{for(let F=On.length-1;F>=0;F-=1){const q=On[F];if(q!=null&&q.substantial)return q.id}return null},[On]),sc=f.useRef(null),hh=((Xv=On.filter(F=>(F.source!=="browser"||F.pinned===!0)&&F.id!==wp).at(-1))==null?void 0:Xv.id)??((Zv=On.filter(F=>F.id!==wp).at(-1))==null?void 0:Zv.id)??null;f.useEffect(()=>{if(xl&&xl!==sc.current){sc.current=xl,G(xl);return}K===null&&hh&&G(hh)},[xl,K,hh]);const Lv=f.useRef(Qi.live);f.useEffect(()=>{const F=Lv.current;Lv.current=Qi.live;const q=[...Qi.live].filter(Ke=>!F.has(Ke));if(q.length===0||tc||K!==null&&K!==sc.current)return;const Ae=[...On].reverse().find(Ke=>Ke.source==="descriptor"&&Ke.renderer==="preview"&&Ke.props.target!==null&&q.includes(Pa(Ke.props.target)));Ae&&G(Ae.id)},[Qi.live,On,tc,K]);const Fv=f.useRef(null);f.useEffect(()=>{Is!==Fv.current&&(Fv.current=Is,Is&&!tc&&G(Is))},[Is,tc]);const zv=f.useRef(null),vl=b==="browser"?(nn==null?void 0:nn.id)??null:null;f.useEffect(()=>{!vl||zv.current===vl||(zv.current=vl,G(vl))},[vl]);const fh=(nn==null?void 0:nn.id)??null;f.useEffect(()=>{!fh||!K||Lw((N==null?void 0:N.messages)??[],K)!==null&&(ec(K),G(fh))},[fh,K,N]);const Uv=F=>{ee(q=>q.some(be=>be.artifactId===F.artifactId)?q:[...q,F]),G(mu(F.artifactId)),d&&(m==null||m())},rc=!i&&Ne&&!Ne.available?i1(Ne):null,Bv=tp(i?null:Ne),Wv=((N==null?void 0:N.offers)??[]).filter(F=>!Ue.includes(F.id)&&Date.parse(F.expiresAt)>V),UA=Ne&&Sr===Ne.id?Jn:(Ne==null?void 0:Ne.thinking)??null,BA=F=>{if(!Ne)return;const q=Ne.id;Nr(q),kr(F),T.setAgentEngine(q,{thinking:F}).catch(be=>{Nr(null),Y(be instanceof ge?be.message:String(be))})},mh=(F,q)=>{if(!s)return;const be=q.map(_e=>_e.artifactId),Ae=U,Ke={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:F},...q.map(_e=>({type:"attachment",artifactId:_e.artifactId,filename:_e.filename,mime:_e.mime,kind:_e.kind,sizeBytes:_e.sizeBytes}))],...Ae?{speaker:eC}:{}};z(_e=>Ae?[..._e,Ke]:[Ke]),Y(null),oe(null),$(!0),(i?Fe.sendToGroup(i.id,{...S?{conversationId:S}:{},text:F,attachmentIds:be}):Fe.send(s,{...S?{conversationId:S}:{},text:F,attachmentIds:be})).then(async _e=>{Me.current.agentId!==s||Me.current.conversationId!==S||(oe(_e.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),_e.conversationId!==S?(C(null),k(_e.conversationId)):await Mn(_e.conversationId),_e.queued===!0&&z(mn=>mn.filter(Xs=>Xs.id!==Ke.id)),x==null||x(s,_e.conversationId))}).catch(_e=>{z(mn=>mn.filter(Xs=>Xs.id!==Ke.id)),Y(Ar(_e)),$(!1)})},WA=F=>{Y(null),Le(F),at(q=>[...q,F]),T.takeOffer(F,S??void 0).then(q=>{q.runId&&(oe(null),$(!0)),S&&Mn(S)}).catch(q=>{at(be=>be.filter(Ae=>Ae!==F)),Y(Ar(q)),S&&Mn(S)}).finally(()=>Le(null))},HA=(F,q)=>Hv({answer:F,...q?{optionId:q}:{}}),KA=()=>Hv({answer:"",skipped:!0}),Hv=F=>{const q=N==null?void 0:N.question;q&&(Y(null),bn(!0),$(!0),Fe.answerQuestion(q.id,F).then(()=>{if(S)return Mn(S)}).catch(be=>{Y(Ar(be)),$(!1)}).finally(()=>bn(!1)))},VA=()=>{if(s){if(it){en(null);return}H(!0),T.agentProfile(s).then(F=>{en(F),G(bp(F.id)),d&&(m==null||m())}).catch(F=>Y(Ar(F))).finally(()=>H(!1))}},GA=F=>{nt({text:F.prompt,at:Date.now()}),l(F.agentId),d&&(p==null||p())},YA=()=>{S&&Fe.cancel(S).catch(F=>Y(Ar(F))).finally(()=>{$(!1),E([])})},ic=f.useCallback(()=>{if(k(null),C(null),z([]),$(!1),Y(null),oe(null),E([]),O(new Map),G(null),ee([]),ec(null),sc.current=null,i){Fe.startGroupConversation(i.id).then(({conversationId:F})=>{k(F),s&&(x==null||x(s,F))}).catch(F=>Y(Ar(F)));return}A(Xe),s&&(x==null||x(s,"new"))},[s,i,Xe,x]);f.useEffect(()=>{g&&g!==mt.current&&(mt.current=g,ic())},[g,ic]);const Kv=F=>{S&&Mn(S),T.overview().catch(()=>{}),F.state!=="pending"&&O(q=>new Map([...q].filter(([,be])=>be!==F.id)))},ac=f.useRef(!1);f.useEffect(()=>{const F=be=>{if(!ac.current)return;const Ae=Math.max(xu,Math.min(720,be.clientX-52));rt(Ae)},q=()=>{if(ac.current){ac.current=!1;try{De!==null&&window.localStorage.setItem(aC,String(De))}catch{}}};return window.addEventListener("pointermove",F),window.addEventListener("pointerup",q),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",q)}},[De]);const qA=((ej=fn.find(F=>F.id===r))==null?void 0:ej.name)??null,Vv=i?[]:GD(Ne,qA),Gv=!(N&&N.conversationId===S)&&!(!S&&I!==null&&I===Xe),Yv=Gv?n.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!i&&Ne?n.jsx(T1,{quiet:!0,still:!0,className:"wb-chat-field",children:n.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[n.jsx(Nn,{agents:fn,id:Ne.id,size:"xl"}),n.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${Ne.name}.`}),n.jsx("p",{className:"wb-chat-intro",children:YD(Ne)}),Vv.length>0?n.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${Ne.name}`,children:Vv.map(F=>n.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var q;nt({text:F,at:Date.now()}),(q=Se.current)==null||q.focus()},children:F},F))}):null]})}):null,qv=n.jsx(K4,{renderables:On,activeId:K,onActivate:G,onClose:F=>{it&&F===bp(it.id)?en(null):ie.some(q=>mu(q.artifactId)===F)?ee(q=>q.filter(be=>mu(be.artifactId)!==F)):S&&ue(q=>{const be={...q,[S]:[...new Set([...q[S]??[],F])]};return Fw(be),be}),K===F&&G(null)},timezone:e,onDecided:Kv,onChangeAgent:GA,agents:fn,browserPanel:nn?n.jsx(L3,{status:Cr,error:gi.error,reload:gi.reload,steps:_A,live:Pt!==null,focusedStepId:LA},nn.id):null,descriptors:j,grantedTools:i?Qs.flatMap(F=>F.tools??[]):(Ne==null?void 0:Ne.tools)??[],...Ne?{agentName:Ne.name}:{},loading:Gv,...!i&&Ne?{face:n.jsx(Nn,{agents:fn,id:Ne.id,size:"xl"})}:{}}),Qv=(nj=(tj=[...(N==null?void 0:N.messages)??[],..._].find(F=>F.role==="user"))==null?void 0:tj.blocks.find(F=>F.type==="text"))==null?void 0:nj.text.trim(),Jv=Qv?Qv.split(`
|
|
107
|
+
`)[0]:"New conversation",Ji=uz({lifetime:(N==null?void 0:N.lifetime)??null,startedAt:(N==null?void 0:N.startedAt)??null,now:V,timezone:e});return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"wb-chat",ref:It,style:d||De===null?void 0:{width:De},"data-sized":!d&&De!==null?"true":void 0,"data-testid":"chat-column","data-dropping":X||void 0,onDragEnter:F=>{Wc(F)&&(F.preventDefault(),Ie.current+=1,de(!0))},onDragOver:F=>{Wc(F)&&(F.preventDefault(),F.dataTransfer.dropEffect="copy")},onDragLeave:F=>{Wc(F)&&(Ie.current=Math.max(0,Ie.current-1),Ie.current===0&&de(!1))},onDrop:F=>{var q;Wc(F)&&(F.preventDefault(),Ie.current=0,de(!1),s&&((q=Se.current)==null||q.addFiles(F.dataTransfer.files)))},children:[X?n.jsx("div",{className:"wb-drop","aria-hidden":"true",children:n.jsxs("div",{className:"wb-drop-card",children:[n.jsx(mz,{}),n.jsx("strong",{children:"Drop to attach"}),n.jsx("span",{children:Ne?`It goes with your next message to ${Ne.name}`:"Pick an agent first"})]})}):null,n.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!i&&Ne?Vo(Ko(Ne)):{},children:[n.jsxs("div",{className:"wb-head-row",children:[i?n.jsx("span",{className:"wb-head-face wb-head-group","aria-hidden":"true",children:Qs.slice(0,3).map(F=>n.jsx(Nn,{agents:fn,id:F.id,size:"sm"},F.id))}):Ne?n.jsx("a",{className:"wb-head-face",href:xt(Ne.id),"aria-label":`${Ne.name}'s page`,children:n.jsx(Nn,{agents:fn,id:Ne.id})}):null,n.jsxs("div",{className:"wb-head-text",children:[i?n.jsx("span",{className:"wb-head-title",children:i.name}):n.jsx("span",{className:"wb-head-title",title:Jv,children:Jv}),n.jsx("span",{className:"wb-head-meta","data-tone":Ji.tone,title:i?`${Qs.map(F=>F.name).join(", ")}. Coordinator: ${(Ne==null?void 0:Ne.name)??i.coordinator}.`:Ji.title,children:i?`${Qs.map(F=>F.name).join(", ")} · ${Ji.text}`:Ne?n.jsxs(n.Fragment,{children:[n.jsx("a",{className:"wb-head-name",href:xt(Ne.id),title:`${Ne.name}'s page`,children:Ne.name})," ",n.jsxs("span",{className:"wb-head-handle",children:["@",Ne.handle]}),` · ${Ji.tone==="quiet"&&Ji.text==="New conversation"?`on ${v}`:Ji.text}`]}):"No agent"})]}),n.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{Ce(!1),ic()},children:n.jsx(ye,{name:"plus",size:16})}),n.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":we,"data-open":we?"true":void 0,disabled:!s,onClick:()=>Ce(F=>!F),children:n.jsx(xz,{})}),d?n.jsxs("button",{className:"ui-btn",onClick:m,disabled:On.length===0,children:["Canvas",On.length>0?` (${On.length})`:""]}):null,n.jsx(jz,{disabled:!s,items:i?[...Qs.map(F=>({label:F.name,hint:F.id===i.coordinator?"Coordinator · open page":"Member · open page",href:xt(F.id)})),...a?[{label:"Members…",hint:"Name, coordinator, who is in the room",testId:"group-members",onSelect:a}]:[]]:[{label:it?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:Rs,onSelect:VA},...Ne?[{label:"Set up",hint:"Identity, model and access",href:xt(Ne.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:xt(Ne.id)}]:[]]})]}),u?n.jsx(l1,{agents:t,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...pi?{working:new Set([pi])}:{}}):null]}),we&&s?n.jsx(Y3,{agentId:s,...i?{groupId:i.id}:{},currentId:S,timezone:e,onNew:()=>{Ce(!1),ic()},onSelect:F=>{if(F===S){Ce(!1);return}Ce(!1),C(null),z([]),$(!1),G(null),Y(null),oe(null),ee([]),k(F),x==null||x(s,F,!1)}}):null,s&&S?n.jsx(z3,{agentId:s,conversationId:S},`${s}:${S}`):null,Ye?n.jsx("div",{className:"wb-chat-notice",children:n.jsx(re,{message:Ye})}):null,me?n.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:me}):null,N!=null&&N.carriedOver?n.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:N.carriedOver}):null,n.jsx(Gx,{messages:[...(N==null?void 0:N.messages)??[],..._],live:L,now:V,working:U,partial:M,agents:fn,...N!=null&&N.runs?{runs:N.runs}:{},...s&&S?{onContinue:()=>mh("continue",[])}:{},...i?{speakers:fn,coordinatorId:i.coordinator}:{},...mi?{workingAs:((sj=fn.find(F=>F.id===mi))==null?void 0:sj.name)??mi}:{},onOpenFile:Uv,onReadAloud:(F,q)=>{tn(null),ld(q,S??void 0,F).then(be=>{be&&tn(be)})},onOpen:F=>{if(nn){const q=Lw([...(N==null?void 0:N.messages)??[],..._],F);if(q){ec(q),G(nn.id),d&&(m==null||m());return}}S&&ue(q=>{const be={...q,[S]:(q[S]??[]).filter(Ae=>Ae!==F)};return Fw(be),be}),G(F),d&&(m==null||m())},...Ne?{agentName:Ne.name,agentId:Ne.id}:{},...Yv?{empty:Yv}:{},emptyHint:Ne?`Nothing here yet. Ask ${Ne.name} for something.`:"Loading agents…"}),Wv.length>0?n.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:Wv.map(F=>n.jsx("button",{className:"ui-btn",disabled:Oe!==null,title:F.prompt,onClick:()=>WA(F.id),children:F.label},F.id))}):null,rc?n.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:n.jsxs(W,{tone:"warning",role:"status",children:[rc," ",n.jsx("a",{href:Be(Bv.section),children:Bv.label})]})}):nc.length>0?n.jsx(N4,{approvals:nc,timezone:e,now:V,version:N,onDecided:Kv,onSay:F=>mh(F,[]),onOpenFull:F=>{G(F),d&&(m==null||m())}}):null,rc||nc.length>0?null:N!=null&&N.question?n.jsx(az,{question:N.question,disabled:Rt||U,onAnswer:HA,onSkip:KA},N.question.id):null,rc?null:n.jsxs("div",{hidden:nc.length>0||!!(N!=null&&N.question),"data-testid":"composer-slot",children:[n.jsx(Qx,{ref:Se,disabled:!s,running:U,onSend:mh,onStop:YA,agentName:i?i.name:(Ne==null?void 0:Ne.name)??"the agent",draft:Ee,history:zA,threadKey:S??(i?`group:${i.id}`:s),model:i?null:(Ne==null?void 0:Ne.model)??null,setupHref:i?null:Ne?xt(Ne.id,"setup","brain"):null,thinking:UA,...!i&&Ne&&XS(ZS(Ne,Zo.data))?{onThinking:BA}:{},...i?{mentions:Qs.map(F=>({handle:F.handle,name:F.name}))}:{},onOpenFile:Uv,conversationId:S??null,readAloud:St,onReadAloud:br}),Te?n.jsx("p",{className:"wb-voice-note",role:"status",children:Te}):null]})]}),d?h?n.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[n.jsxs("div",{className:"wb-sheet-head",children:[n.jsx("strong",{children:"Canvas"}),n.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),qv]}):null:n.jsxs(n.Fragment,{children:[n.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:F=>{var q,be;ac.current=!0,(be=(q=F.currentTarget).setPointerCapture)==null||be.call(q,F.pointerId)},onKeyDown:F=>{const q=be=>{var Ae;return be??((Ae=It.current)==null?void 0:Ae.offsetWidth)??xu};F.key==="ArrowLeft"&&rt(be=>Math.max(xu,q(be)-16)),F.key==="ArrowRight"&&rt(be=>Math.min(720,q(be)+16))}}),qv]})]})}function hz(){try{const e=window.localStorage.getItem(aC),t=Number(e);return e!==null&&Number.isFinite(t)&&t>=xu?t:null}catch{return null}}function fz(e,t){return Date.parse(t.lastMessageAt??t.startedAt??t.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function Yt(e){return typeof e=="string"&&e!==""?e:null}function Ar(e){return e instanceof ge||e instanceof Error?e.message:String(e)}function yf(e,t){var r;const s=(r=t.blocks.find(i=>i.type==="text"))==null?void 0:r.text.trim();if(!s)return!0;for(let i=e.messages.length-1;i>=0;i-=1){const a=e.messages[i];if(a.role!=="user")continue;const l=a.blocks.find(o=>o.type==="text");if(l)return l.text.trim()===s}return!1}function Wc(e){var s;const t=(s=e.dataTransfer)==null?void 0:s.types;return!!(t&&Array.from(t).includes("Files"))}function mz(){return n.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 28 28","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),n.jsx("path",{d:"M5 19.5v2a2.5 2.5 0 0 0 2.5 2.5h13a2.5 2.5 0 0 0 2.5-2.5v-2"})]})}const Sp="buddi.chatDraft";function pz(e,t){try{window.sessionStorage.setItem(Sp,JSON.stringify({agentId:e,text:t}))}catch{}}function gz(e){try{const t=window.sessionStorage.getItem(Sp);if(!t)return null;const s=JSON.parse(t);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(Sp),s.text)}catch{return null}}function xz(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M2.6 8a5.4 5.4 0 1 0 1.6-3.8"}),n.jsx("path",{d:"M2.4 2.6v2.6h2.6M8 5.2V8l2 1.3"})]})}function vz(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"currentColor",children:[n.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),n.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})}function jz({items:e,disabled:t}){const[s,r]=f.useState(!1),i=f.useRef(null);return f.useEffect(()=>{if(!s)return;const a=o=>{i.current&&!i.current.contains(o.target)&&r(!1)},l=o=>{o.key==="Escape"&&r(!1)};return window.addEventListener("mousedown",a),window.addEventListener("keydown",l),()=>{window.removeEventListener("mousedown",a),window.removeEventListener("keydown",l)}},[s]),n.jsxs("div",{className:"wb-head-menu",ref:i,children:[n.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":"More about this agent","aria-haspopup":"menu","aria-expanded":s,"data-open":s?"true":void 0,disabled:t,onClick:()=>r(a=>!a),children:n.jsx(vz,{})}),s?n.jsx("div",{className:"ui-menu wb-head-menu-list",role:"menu",children:e.map(a=>a.href?n.jsxs("a",{className:"ui-menu-item",role:"menuitem",href:a.href,onClick:()=>r(!1),children:[n.jsx("span",{className:"ui-menu-item-text",children:a.label}),a.hint?n.jsx("span",{className:"ui-menu-item-hint",children:a.hint}):null]},a.label):n.jsxs("button",{className:"ui-menu-item",role:"menuitem","data-testid":a.testId,disabled:a.disabled,onClick:()=>{var l;r(!1),(l=a.onSelect)==null||l.call(a)},children:[n.jsx("span",{className:"ui-menu-item-text",children:a.label}),a.hint?n.jsx("span",{className:"ui-menu-item-hint",children:a.hint}):null]},a.label))}):null]})}function yz(e,t){const s=a=>{var l;return`@${((l=t.find(o=>o.id===a))==null?void 0:l.handle)??a}`},[r,...i]=e;return r===void 0?"":[s(r),...i.map(a=>`asked by ${s(a)}`)].join(", ")}let Uw=!1;const wz=new Set(["missing","unconfigured","not-english"]);async function ld(e,t,s=null){const r=K1(s);try{const i=await Fe.say({text:e,...t?{conversationId:t}:{}});return Sw(r)&&await EF(i.audioUrl,i.mime,s),null}catch(i){Sw(r)&&cl();const a=i instanceof ge&&i.detail&&typeof i.detail=="object"?i.detail.reason:void 0;return typeof a=="string"&&wz.has(a)&&(s!==null||!Uw)?(Uw=!0,i.message):null}}let Zn=null;function bz(e){if(fu(e)!==null)return!1;const t=XN(e);return t!==Vt&&t!==Yr}function kz({agent:e,agents:t,open:s,onOpenChange:r,navigate:i}){const a=f.useRef(null),l=f.useRef(s),o=`Ask ${e.name}`,[c,u]=f.useState(!1);return f.useEffect(()=>{if(s||!c||!Zn)return;const d=Jd({url:Fe.streamUrl(Zn.conversationId),lastEventId:Zn.lastEventId??null,onEvent:h=>{h.name==="run.finished"&&u(!1)}});return()=>d.close()},[s,c]),f.useEffect(()=>{const d=h=>{!h.altKey||h.ctrlKey||h.metaKey||h.code!=="Slash"||(h.preventDefault(),r(!s))};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[s,r]),f.useEffect(()=>{var d;l.current&&!s&&((d=a.current)==null||d.focus()),l.current=s},[s]),s?n.jsx(Nz,{agent:e,agents:t,navigate:i,onClose:()=>r(!1),onBusy:u}):n.jsxs(yo,{children:[n.jsx(wo,{asChild:!0,children:n.jsx("button",{ref:a,type:"button",className:"wb-ask-fab","data-busy":c?"true":void 0,"aria-label":o,onClick:()=>r(!0),children:n.jsx(Sz,{busy:c})})}),n.jsx(bo,{children:n.jsx(ko,{className:"ui-tip",side:"left",sideOffset:8,children:o})})]})}function Sz({busy:e}){const[t,s]=f.useState(!1);return t?n.jsx(ed,{size:"lg"}):n.jsx(eh,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function Nz({agent:e,agents:t,navigate:s,onClose:r,onBusy:i}){const a=f.useRef(null),[l,o]=f.useState(Zn&&Zn.agentId===e.id?Zn.conversationId:null),[c,u]=f.useState(null),[d,h]=f.useState([]),[m,p]=f.useState([]),[g,y]=f.useState(null),[b,x]=f.useState(!1),[v,j]=f.useState(!1),[w,S]=f.useState(null),[k,N]=f.useState(null),[C,I]=f.useState(Date.now()),[A,_]=f.useState(W1),z=f.useRef(A);z.current=A;const[L,E]=f.useState(null),M=f.useRef(null),D=f.useCallback(async se=>{try{const ue=await Fe.conversation(se);u(ue),h(ie=>ie.filter(ee=>!Cz(ue,ee)))}catch{}},[]);f.useEffect(()=>{l&&D(l)},[l,D]),f.useEffect(()=>{if(!l)return;const se=Jd({url:Fe.streamUrl(l),onEvent:ue=>{var ie;switch(ue.name){case"run.started":M.current=null,x(!0),y(null);break;case"live":{const ee=Dn(ue.data.runId)??"",X=Number(ue.data.turn??0),de=ue.data.kind==="thinking"?"thinking":"text",Ie=Dn(ue.data.text)??"",Se=Date.now();if(de==="text"){const we=M.current;M.current=we&&we.runId===ee&&we.turn===X?{...we,text:we.text+Ie}:{runId:ee,turn:X,text:Ie}}y(we=>{const Ce=we&&we.runId===ee&&we.turn===X?we:{runId:ee,turn:X,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return de==="thinking"?{...Ce,thinking:Ce.thinking+Ie,thinkingStartedAt:Ce.thinkingStartedAt??Se}:{...Ce,text:Ce.text+Ie,textStartedAt:Ce.textStartedAt??Se}});break}case"live.snapshot":{const ee=Dn(ue.data.runId)??"",X=Number(ue.data.turn??0),de=Dn(ue.data.text)??"",Ie=Dn(ue.data.thinking)??"",Se=Number(ue.data.startedAt??Date.now());M.current={runId:ee,turn:X,text:de},x(!0),y({runId:ee,turn:X,text:de,thinking:Ie,thinkingStartedAt:Ie?Se:null,textStartedAt:de?Se:null,settled:!1});break}case"live.settle":{const ee=Dn(ue.data.runId)??"",X=Number(ue.data.turn??0);y(de=>de&&de.runId===ee&&de.turn===X?{...de,settled:!0}:de);break}case"tool.called":{const ee=Dn(ue.data.toolUseId)??Dn(ue.data.id),X=Dn(ue.data.name)??Dn(ue.data.tool)??"tool";ee&&p(de=>[...de.filter(Ie=>Ie.toolUseId!==ee),{toolUseId:ee,name:X,startedAt:Date.now()}]);break}case"tool.result":{const ee=Dn(ue.data.toolUseId)??Dn(ue.data.id);ee&&p(X=>X.filter(de=>de.toolUseId!==ee)),D(l);break}case"message.appended":case"awaiting-approval":D(l).then(()=>y(ee=>ee!=null&&ee.settled?null:ee));break;case"run.finished":{x(!1),p([]),y(null);const ee=Dn(ue.data.message);S(ee??null);const X=((ie=M.current)==null?void 0:ie.text.trim())??"";M.current=null,!ee&&X!==""&&z.current&&ld(X,l).then(de=>{de&&E(de)}),D(l);break}}}});return()=>{Zn&&Zn.conversationId===l&&(Zn.lastEventId=se.lastEventId()),se.close()}},[l,D]),f.useEffect(()=>{i(b||v)},[b,v,i]),f.useEffect(()=>{if(m.length===0)return;const se=window.setInterval(()=>I(Date.now()),1e3);return()=>window.clearInterval(se)},[m.length]);const U=(se,ue)=>{j(!0),S(null);const ie={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:se}]};h(ee=>[...ee,ie]),(async()=>{try{const ee=l??(await Fe.startConversation(e.id)).conversationId;ee!==l&&(Zn={agentId:e.id,conversationId:ee},o(ee));const X=await Fe.send(e.id,{conversationId:ee,text:se,...ue.length>0?{attachmentIds:ue.map(de=>de.artifactId)}:{}});X.conversationId!==ee&&(Zn={agentId:e.id,conversationId:X.conversationId},o(X.conversationId)),x(!0),D(X.conversationId)}catch(ee){h(X=>X.filter(de=>de.id!==ie.id)),S(ee instanceof ge?ee.message:String(ee)),N({text:se,at:Date.now()})}finally{j(!1)}})()},$=()=>{l&&Fe.cancel(l).catch(se=>S(String(se))).finally(()=>x(!1))},B=()=>{var se;Zn=null,o(null),u(null),h([]),p([]),y(null),x(!1),S(null),(se=a.current)==null||se.focus()},O=se=>{_(se),H1(se),se||cl()},K=l?Je(e.id,l):Je(e.id),G=[...(c==null?void 0:c.messages)??[],...d];return n.jsxs(nL,{title:e.name,label:`${e.name}, a quick chat`,onClose:r,onOpenAutoFocus:se=>{var ue;se.preventDefault(),(ue=a.current)==null||ue.focus()},onCloseAutoFocus:se=>se.preventDefault(),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",variant:"ghost",onClick:B,disabled:l===null&&d.length===0,children:"New"}),n.jsx(Ut,{size:"sm",variant:"ghost",href:K,onClick:se=>{se.preventDefault(),s(K)},children:"Open in Chat"})]}),children:[n.jsx("div",{className:"wb-ask-thread",children:n.jsx(Gx,{messages:G,live:m,now:C,working:b||v,partial:g,agents:t,agentName:e.name,agentId:e.id,onOpen:()=>s(K),onReadAloud:(se,ue)=>{E(null),ld(ue,l??void 0,se).then(ie=>{ie&&E(ie)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),n.jsxs("div",{className:"wb-ask-compose",children:[w?n.jsx(re,{message:w}):null,n.jsx(Qx,{ref:a,disabled:v||!e.available,running:b,onSend:U,onStop:$,agentName:e.name,placeholder:`Message ${e.name}…`,draft:k,threadKey:`dock.${l??e.id}`,conversationId:l,readAloud:A,onReadAloud:O}),L?n.jsx("p",{className:"wb-voice-note",role:"status",children:L}):null]})]})}function Dn(e){return typeof e=="string"?e:null}function Cz(e,t){var r;const s=(r=t.blocks)==null?void 0:r.find(i=>i.type==="text");return!s||s.type!=="text"?!1:e.messages.some(i=>i.role==="user"&&(i.blocks??[]).some(a=>a.type==="text"&&a.text.includes(s.text)))}const lC=3;function Ez(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function Az(e,t){return e?t?"above-dock":"above-button":"corner"}function Tz({placement:e,children:t}){return n.jsx("div",{className:"wb-toast-stack","data-placement":e,children:t})}function Rz(e){return e.state==="shown"&&e.seenAt===null}function Iz(e){const[t,s]=f.useState([]),r=f.useRef(new Set),i=f.useRef(new Set),a=f.useCallback(()=>{e&&T.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>Rz(u)&&!r.current.has(u.id));s(u=>{const d=new Set(u.map(m=>m.id)),h=c.filter(m=>!d.has(m.id));return h.length===0?u:[...u,...h].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);f.useEffect(()=>{for(const o of t.slice(0,lC))i.current.has(o.id)||(i.current.add(o.id),T.notificationSeen(o.id).catch(()=>{}))},[t]);const l=f.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:t,refresh:a,dismiss:l}}function Pz({queue:e,agents:t,navigate:s,onDismiss:r}){if(e.length===0)return null;const i=e.slice(0,lC),a=e.length-i.length;return n.jsxs("section",{className:"nt-toasts","aria-label":"Notifications",children:[i.map(l=>n.jsxs("div",{className:"ui-toast nt-toast","data-tone":Ez(l.kind),role:"status",children:[l.agentId?n.jsx(Nn,{agents:t,id:l.agentId,size:"sm"}):null,n.jsxs("div",{className:"nt-toast-main",children:[n.jsx("div",{className:"ui-toast-title",children:Eo(l)}),l.text?n.jsx("div",{className:"ui-toast-body nt-toast-line",children:$z(l.text)}):null,l.link?n.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),n.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${Eo(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),a>0?n.jsxs("p",{className:"nt-toasts-more",children:["and ",a," more"]}):null]})}function $z(e){var t;return((t=e.split(`
|
|
108
|
+
`).find(s=>s.trim()!==""))==null?void 0:t.trim())??""}const Mz=3e4,Oz=1e3;function Dz(e,t,s){const r=f.useRef(t);r.current=t;const i=f.useRef(s);i.current=s,f.useEffect(()=>{if(!e)return;let a=!1,l=-1/0,o=null,c=null,u=!0;const d=()=>document.visibilityState!=="hidden",h=x=>{var v;l=Date.now(),T.presence(x).catch(j=>{var w;j instanceof ge&&j.status===401&&(a=!0,(w=i.current)==null||w.call(i))}),x==="active"&&((v=r.current)==null||v.call(r))},m=x=>{if(a||(o=x,c!==null))return;const v=l+Oz-Date.now();if(v<=0){o=null,h(x);return}c=window.setTimeout(()=>{if(c=null,a||o===null)return;const j=o;o=null,h(j)},v)},p=()=>{u=!0,d()&&m("active")},g=()=>{u=!1,m("away")},y=()=>m(d()?"active":"away");d()&&m("active");const b=window.setInterval(()=>{d()&&u&&m("active")},Mz);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",y),()=>{a=!0,window.clearInterval(b),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",y)}},[e])}function Bw({agents:e,group:t,onClose:s,onCreated:r,onSaved:i,onArchived:a}){return!t&&!r1(e)?n.jsx(kt,{title:"A new group",onClose:s,children:n.jsxs(W,{children:["A group needs two agents. Make another one with ",HD(e)," first."]})}):n.jsx(Lz,{agents:_z(e,t),group:t??null,onClose:s,...r?{onCreated:r}:{},...i?{onSaved:i}:{},...a?{onArchived:a}:{}})}function _z(e,t){const s=s1(e),r=((t==null?void 0:t.members)??[]).filter(i=>!s.some(a=>a.id===i)).map(i=>e.find(a=>a.id===i)).filter(i=>i!==void 0);return[...s,...r]}function Lz({agents:e,group:t,onClose:s,onCreated:r,onSaved:i,onArchived:a}){var C,I;const l=t!==null,[o,c]=f.useState((t==null?void 0:t.name)??""),[u,d]=f.useState((t==null?void 0:t.members)??[]),[h,m]=f.useState((t==null?void 0:t.coordinator)??((C=e.find(A=>A.roles.includes(Nx)))==null?void 0:C.id)??((I=e[0])==null?void 0:I.id)??""),[p,g]=f.useState(!1),[y,b]=f.useState(!1),[x,v]=f.useState(null),j=[...new Set([h,...u])].filter(Boolean),w=o.trim()!==""&&h!==""&&j.length>=2,S=A=>d(_=>_.includes(A)?_.filter(z=>z!==A):[..._,A]),k=async()=>{g(!0),v(null);try{t?i==null||i(await Fe.updateGroup(t.id,{name:o.trim(),coordinator:h,members:j})):r==null||r(await Fe.createGroup({name:o.trim(),coordinator:h,members:j.filter(A=>A!==h)}))}catch(A){v(A instanceof ge?A.message:String(A))}finally{g(!1)}},N=async()=>{if(t){g(!0),v(null);try{await Fe.archiveGroup(t.id),a==null||a(t.id)}catch(A){v(A instanceof ge?A.message:String(A)),g(!1)}}};return n.jsx(kt,{title:l?`${t.name}: members`:"A new group",onClose:s,children:n.jsxs(Q,{children:[n.jsx(Z,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:n.jsx("input",{value:o,autoFocus:!0,maxLength:80,onChange:A=>c(A.target.value),placeholder:"Household finances"})}),n.jsx(Z,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:n.jsx("select",{value:h,onChange:A=>m(A.target.value),children:e.map(A=>n.jsx("option",{value:A.id,children:A.name},A.id))})}),n.jsx(Z,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:n.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(A=>A.id!==h).map(A=>n.jsxs("label",{className:"group-pick-row","data-on":u.includes(A.id)||void 0,children:[n.jsx("input",{type:"checkbox",checked:u.includes(A.id),onChange:()=>S(A.id)}),n.jsx(Nn,{agents:e,id:A.id,size:"sm"}),n.jsxs("span",{className:"group-pick-text",children:[n.jsx("span",{className:"group-pick-name",children:A.name}),n.jsx("span",{className:"group-pick-desc",children:A.description})]})]},A.id))})}),n.jsx(W,{children:"Members read what is said in this group and what they recall from shared and group memory. Nothing an agent knows privately is brought in on its own: what enters the room is seen by the room."}),l?n.jsx(W,{children:"Taking a member out leaves everything it already said in the transcript. It simply takes no new turns."}):null,x?n.jsx(W,{tone:"critical",children:x}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!w||p,onClick:()=>void k(),children:p?l?"Saving…":"Creating…":l?"Save":"Create group"})]}),l?n.jsx("div",{className:"group-archive",children:y?n.jsxs(Q,{children:[n.jsxs(W,{tone:"warning",children:["Archive ",t.name,"? It leaves the rail and takes no new requests. Everything said in it stays readable."]}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:()=>b(!1),children:"Keep it"}),n.jsx(R,{variant:"danger",disabled:p,"data-testid":"group-archive-confirm",onClick:()=>void N(),children:"Archive group"})]})]}):n.jsx(R,{variant:"ghost",disabled:p,"data-testid":"group-archive",onClick:()=>b(!0),children:"Archive group"})}):null]})})}function Jx(e){const[t,s]=f.useState(null),[r,i]=f.useState(null),[a,l]=f.useState(null);return{busy:t,note:r,failure:a,decide:async(c,u,d,h)=>{var p,g,y,b;s(c),l(null),i(null);let m;try{const x=h?await T.decide(c,u,d,h):await T.decide(c,u,d);m={decision:u,...(p=x.execution)!=null&&p.state?{state:x.execution.state}:{},...x.execution&&"result"in x.execution?{result:x.execution.result}:{}},i(u==="reject"?`Rejected ${x.action.tool}.`:((g=x.execution)==null?void 0:g.state)==="succeeded"?`Approved and done: ${x.action.tool}.`:`Approved ${x.action.tool}: ${((y=x.execution)==null?void 0:y.state)??"no execution"}${(b=x.execution)!=null&&b.message?` (${x.execution.message})`:""}`)}catch(x){l(x instanceof Error?x.message:String(x))}finally{s(null),e(m)}}}}function Xx({action:e,timezone:t,busy:s,onDecide:r,agentName:i}){var d,h;const[a,l]=f.useState(!1),{values:o,controls:c}=Lx(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return n.jsxs(ks,{tone:"accent",title:e.tool,meta:n.jsxs(n.Fragment,{children:[n.jsxs(ve,{children:["v",e.toolVersion]}),n.jsxs("span",{className:"muted",children:["asked by ",i??e.agentId]})]}),children:[n.jsx(jt,{children:e.preview}),n.jsxs("p",{className:"ui-card-meta",children:["Expires ",Ve(e.expiresAt,t)," (",ze(e.expiresAt),"). Policy v",e.policyVersion,", args ",Co(e.argsHash,12),e.jobId?`, job ${Co(e.jobId)}`:"","."]}),c,n.jsxs(J,{children:[n.jsx(R,{variant:"good",disabled:s,onClick:()=>u(),children:(d=e.permissionScopes)!=null&&d.length?"Allow once":"Approve"}),(h=e.permissionScopes)!=null&&h.length?n.jsxs(n.Fragment,{children:[n.jsx(R,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),n.jsx(R,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,n.jsx(R,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),n.jsx(R,{variant:"ghost",onClick:()=>l(m=>!m),"aria-expanded":a,children:a?"Hide envelope":"Show envelope"})]}),a?n.jsxs("div",{className:"ui-card-foot",children:[n.jsx(te,{title:"Envelope: everything that decides what the world will see",children:n.jsx(jt,{children:In(e.envelope)})}),n.jsx(te,{title:"Canonical arguments",children:n.jsx(jt,{children:In(e.canonicalArgs)})})]}):null]})}function Zx(e,t,s){const[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(null);return{accept:()=>{e&&(i(!0),c(null),T.acceptPluginAgent(e,t).then(d=>{l(d.agent)}).catch(d=>c(d instanceof ge?d.message:String(d))).finally(()=>i(!1)))},busy:r,created:a,failure:o}}function oC({agent:e}){return n.jsxs(W,{tone:"good",role:"status",children:["@",e.handle," is ready. ",n.jsxs("a",{href:Je(e.id),children:["Talk to @",e.handle]})]})}function cC(e,t,s){const r=e.canonicalArgs;return e.tool==="platform.accept_plugin_agent"&&(r==null?void 0:r.plugin)===t&&typeof r.agent=="string"&&r.agent.toLowerCase()===s.toLowerCase()}function Fz(e,t){var i;const s=le(()=>T.approvals(),[e,t],15e3);return{action:((i=s.data)==null?void 0:i.pending.find(a=>cC(a,e,t)))??null,reload:s.reload}}function zz({action:e,onDecided:t}){const{busy:s,failure:r,decide:i}=Jx(a=>t(a));return n.jsxs(Q,{gap:"sm",children:[n.jsx(Xx,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(a,l,o,c)=>{i(a,l,o,c)}}),n.jsx(re,{message:r})]})}function ev({plugin:e,agent:t,text:s,label:r,handle:i,onDismiss:a}){var h;const l=Zx(e,t),o=Fz(e,t),[c,u]=f.useState(null),d=l.created??c;if(d)return n.jsx(oC,{agent:d});if(o.action){const m=i??((h=/@(\S+)/.exec(r))==null?void 0:h[1])??t;return n.jsxs(Q,{gap:"sm",children:[n.jsx("span",{children:s}),n.jsx(zz,{action:o.action,onDecided:p=>{(p==null?void 0:p.decision)==="approve"&&p.state==="succeeded"?u({id:t,handle:m,name:m}):o.reload()}})]})}return n.jsxs(Q,{gap:"sm",children:[n.jsxs(J,{children:[n.jsx("span",{children:s}),n.jsx(Xt,{}),a?n.jsx(R,{variant:"ghost",disabled:l.busy,onClick:a,children:"Not now"}):null,n.jsx(R,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),n.jsx(re,{message:l.failure})]})}function uC(){var t;const e=le(()=>T.agentOffers(),[],6e4);return{offers:((t=e.data)==null?void 0:t.offers)??[],reload:e.reload}}function dC({offers:e,reload:t}){return e.length===0?null:n.jsx(te,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:n.jsx(Q,{gap:"sm",divided:!0,children:e.map(s=>n.jsx(ev,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{T.dismissAgentOffer(s.plugin,s.agent).then(t,t)}},`${s.plugin}/${s.agent}`))})})}const Uz=512*1024,Bz=/^[A-Za-z0-9+/]*={0,2}$/;function hC(e){const t=e==null?void 0:e.play;if(typeof t!="object"||t===null)return null;const{mime:s,data:r}=t;return typeof s!="string"||!/^audio\/[a-z0-9.+-]+$/i.test(s.split(";")[0].trim())||typeof r!="string"||r===""||!Bz.test(r)||Math.floor(r.length*3/4)>Uz+2?null:{mime:s,data:r}}function fC(e){const t=e==null?void 0:e.message;return typeof t=="string"&&t.trim()!==""?t:null}let sr=null,Ql=null,Io=null;const Np=new Set;function mC(){for(const e of Np)e()}function _l(){sr&&(sr.onended=null,sr.onerror=null,sr.pause()),Ql&&URL.revokeObjectURL(Ql),Ql=null,Io!==null&&(Io=null,mC())}async function pC(e,t){_l();const s=atob(e.data),r=new Uint8Array(s.length);for(let i=0;i<s.length;i+=1)r[i]=s.charCodeAt(i);sr??(sr=new Audio),Ql=URL.createObjectURL(new Blob([r],{type:e.mime})),Io=t,sr.onended=_l,sr.onerror=_l,sr.src=Ql,mC();try{await sr.play()}catch{throw _l(),new Error("The browser would not play the sound.")}}function Ww(e){e!==void 0&&Io!==e||_l()}function Wz(){return f.useSyncExternalStore(e=>(Np.add(e),()=>Np.delete(e)),()=>Io,()=>null)}const Hz=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],la=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Kz=["January","February","March","April","May","June","July","August","September","October","November","December"],Hw=/^\d{4}-\d{2}-\d{2}$/;function Qr(e){return e.split("-").map(Number)}function qi(e,t){const[s,r,i]=Qr(e);return new Date(Date.UTC(s,r-1,i+t)).toISOString().slice(0,10)}function gC(e){const[t,s,r]=Qr(e);return new Date(Date.UTC(t,s-1,r)).getUTCDay()}function tv(e){return Hz[gC(e)]}function xC(e){return Qr(e)[2]}function Kw(e){return qi(e,-((gC(e)+6)%7))}function cr(e){const[,t,s]=Qr(e);return`${tv(e)} ${s} ${la[t-1]}`}function Vz(e,t){return e===t?`Today · ${cr(e)}`:e===qi(t,1)?`Tomorrow · ${cr(e)}`:cr(e)}function bi(e){return`${String(Math.floor(e/60)).padStart(2,"0")}:${String(e%60).padStart(2,"0")}`}const Vw=new Map;function Cp(e,t){let s=Vw.get(t);s||(s=new Intl.DateTimeFormat("en-GB",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),Vw.set(t,s));const r=Object.fromEntries(s.formatToParts(e).map(i=>[i.type,i.value]));return{date:`${r.year}-${r.month}-${r.day}`,minutes:Number(r.hour)*60+Number(r.minute)}}function Gz(e,t=new Date){return Cp(t,e).date}function Yz(e,t){return e==="week"?{from:Kw(t),days:7}:e==="month"?{from:Kw(`${t.slice(0,8)}01`),days:42}:{from:t,days:7}}function qz(e,t,s){if(e!=="month")return qi(t,s*7);const[r,i]=Qr(t);return new Date(Date.UTC(r,i-1+s,1)).toISOString().slice(0,10)}function Qz(e,t,s,r){const[i,a]=Qr(t);if(e==="month")return`${Kz[a-1]} ${i}`;const l=qi(s,r-1),[o,c,u]=Qr(s),[d,h,m]=Qr(l);return c===h&&o===d?`${u} – ${m} ${la[h-1]} ${d}`:o===d?`${u} ${la[c-1]} – ${m} ${la[h-1]} ${d}`:`${u} ${la[c-1]} ${o} – ${m} ${la[h-1]} ${d}`}function ia(e){return e==null?"":String(e)}function Jz(e,t,s,r){const i=[],a=new Set;return e.forEach((l,o)=>{const c=ia(je(l,t.id)),u=ia(je(l,t.title)),d=ia(je(l,t.start)),h=ia(je(l,t.end));if(c===""||a.has(c)||d===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}a.add(c);const m=t.allDay===void 0?void 0:je(l,t.allDay),p=m===void 0?Hw.test(d):m===!0||m==="true",g=t.tone===void 0?0:Number(je(l,t.tone)),y=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,b={id:c,title:u,calendar:t.calendar===void 0?"":ia(je(l,t.calendar)),tone:y,location:t.location===void 0?"":ia(je(l,t.location))};if(p){const S=d.slice(0,10),k=Hw.test(h.slice(0,10))&&h.slice(0,10)>S?h.slice(0,10):qi(S,1);i.push({...b,allDay:!0,startDate:S,startMin:0,endDate:k,endMin:0});return}const x=new Date(d);if(Number.isNaN(x.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${d}", which is not a time — not drawn`);return}const v=new Date(h),j=Cp(x,s),w=Number.isNaN(v.getTime())||v<x?j:Cp(v,s);i.push({...b,allDay:!1,startDate:j.date,startMin:j.minutes,endDate:w.date,endMin:w.minutes})}),i}function Xz(e,t){if(e.allDay)return t>=e.startDate&&t<e.endDate?{from:0,to:1440,allDay:!0}:null;if(t<e.startDate||t>e.endDate)return null;const s=t===e.startDate?e.startMin:0,r=t===e.endDate?e.endMin:1440,i=e.startDate===e.endDate&&e.startMin===e.endMin;return r<=s&&!(i&&t===e.startDate)?null:{from:s,to:r,allDay:s===0&&r===1440}}function nv(e,t){return e.map(s=>({event:s,part:Xz(s,t)})).filter(s=>s.part!==null).sort((s,r)=>Number(r.part.allDay)-Number(s.part.allDay)||s.part.from-r.part.from||r.part.to-s.part.to)}function sv(e,t){if(t.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&t.from===0?`until ${bi(t.to)}`:s&&t.to===1440?`from ${bi(t.from)}`:t.from===t.to?bi(t.from):`${bi(t.from)}–${bi(t.to)}`}function Ep(e,t,s){return[sv(e,t),e.title,e.location,e.calendar,cr(s)].filter(Boolean).join(", ")}const vC=30;function Zz(e){const t=[];let s=[],r=-1;const i=[],a=()=>{const l=Math.max(1,...s.map(o=>o.lane+1));for(const o of s)t.push({...o,lanes:l});s=[],i.length=0};for(const l of e){const o=Math.max(l.part.to,l.part.from+vC);s.length>0&&l.part.from>=r&&a();let c=i.findIndex(u=>u<=l.part.from);c===-1?(c=i.length,i.push(o)):i[c]=o,s.push({...l,lane:c,lanes:1}),r=Math.max(r,o)}return s.length>0&&a(),t}const rv="(max-width: 900px)";function Li(e){const[t,s]=f.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return f.useEffect(()=>{var a;let r;try{r=window.matchMedia(e)}catch{return}const i=l=>s(l.matches);return(a=r.addEventListener)==null||a.call(r,"change",i),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",i)}},[e]),t}const eU={week:"Week",month:"Month",list:"List"},tU=["week","month","list"],nU="(max-width: 720px)";function sU(e){try{return window.localStorage.getItem(e)}catch{return null}}function rU(e,t){try{window.localStorage.setItem(e,t)}catch{}}function iU(e){const t=e.views&&e.views.length>0?e.views:tU,s=Li(nU),[r,i]=f.useState(()=>{const p=sU(e.storageKey);return p!==null&&t.includes(p)?p:null}),a=s&&t.includes("list")?"list":e.default&&t.includes(e.default)?e.default:t[0],l=r??a,[o,c]=f.useState(e.today),[u,d]=f.useState(null),{from:h,days:m}=Yz(l,o);return{views:t,view:l,setView:p=>{i(p),rU(e.storageKey,p),d(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:qz(l,o,p)),d(null)},from:h,days:m,to:qi(h,m),selected:u,select:d}}function aU({state:e,events:t,hours:s,empty:r,label:i}){const{view:a,anchor:l,today:o,from:c,days:u}=e,d=f.useMemo(()=>Array.from({length:u},(y,b)=>qi(c,b)),[c,u]),h=a==="month"?"month":"week",m=e.selected??(l.slice(0,7)===o.slice(0,7)?o:`${l.slice(0,8)}01`),p=a==="month"?m:a==="week"?e.selected:null,g=y=>{if(!y.target.closest('input, textarea, select, [contenteditable="true"]')&&!(y.altKey||y.ctrlKey||y.metaKey)){if(y.key==="ArrowLeft")e.go(-1);else if(y.key==="ArrowRight")e.go(1);else if(y.key==="t"||y.key==="T")e.go(0);else return;y.preventDefault()}};return n.jsxs("div",{className:"cal",role:"region","aria-label":i,tabIndex:0,onKeyDown:g,children:[n.jsxs("div",{className:"cal-bar",children:[n.jsx(R,{size:"sm","aria-label":`Previous ${h}`,onClick:()=>e.go(-1),children:n.jsx(ye,{name:"chevron-left",size:14})}),n.jsx(R,{size:"sm",onClick:()=>e.go(0),children:"Today"}),n.jsx(R,{size:"sm","aria-label":`Next ${h}`,onClick:()=>e.go(1),children:n.jsx(ye,{name:"chevron-right",size:14})}),n.jsx("h3",{className:"cal-title","aria-live":"polite",children:Qz(a,l,c,u)}),e.views.length>1?n.jsx(ls,{label:"View",options:e.views.map(y=>({value:y,label:eU[y]})),value:a,onChange:e.setView}):null]}),a==="week"?n.jsx(lU,{dates:d,today:o,events:t,hours:s??[7,21],onPick:e.select}):null,a==="month"?n.jsx(cU,{dates:d,month:l.slice(0,7),today:o,events:t,selected:m,onPick:e.select}):null,a==="list"?n.jsx("div",{className:"cal-list",children:d.map(y=>n.jsx(Gw,{date:y,today:o,events:t,empty:r},y))}):null,p?n.jsx(Gw,{date:p,today:o,events:t,empty:r}):null]})}function Gw({date:e,today:t,events:s,empty:r}){const i=nv(s,e);return n.jsx(Ze,{flush:!0,title:Vz(e,t),children:n.jsx(yt,{children:i.length===0?n.jsx(ft,{title:n.jsx("span",{className:"muted",children:r})}):i.map(({event:a,part:l})=>n.jsx(ft,{lead:n.jsx("span",{className:"cal-dot","data-tone":a.tone,"aria-hidden":"true"}),title:a.title,sub:a.location||void 0,side:sv(a,l)},a.id))})})}function lU({dates:e,today:t,events:s,hours:r,onPick:i}){const a=f.useRef(null);f.useLayoutEffect(()=>{const c=a.current;c&&(c.scrollTop=c.scrollHeight/24*r[0])},[r[0]]);const l=e.map(c=>({date:c,items:nv(s,c)})),o=c=>c===t?"true":void 0;return n.jsx(Ze,{flush:!0,children:n.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${cr(e[0])}`,style:{"--cal-span":r[1]-r[0]},children:[n.jsxs("div",{className:"cal-row",role:"row",children:[n.jsx("span",{className:"cal-gutter","aria-hidden":"true"}),e.map(c=>n.jsxs("div",{className:"cal-day-head",role:"columnheader","data-today":o(c),"aria-label":cr(c),children:[n.jsx("span",{className:"cal-wd",children:tv(c)}),n.jsx("span",{className:"cal-num",children:xC(c)})]},c))]}),n.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[n.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":o(c),children:u.filter(d=>d.part.allDay).map(({event:d,part:h})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":d.tone,"aria-label":Ep(d,h,c),onClick:()=>i(c),children:d.title},d.id))},c))]}),n.jsx("div",{className:"cal-scroll",ref:a,children:n.jsxs("div",{className:"cal-row cal-times",role:"row",children:[n.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(c,u)=>u+1).map(c=>n.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${c})`},children:bi(c*60)},c))}),l.map(({date:c,items:u})=>n.jsx("div",{className:"cal-col",role:"gridcell","aria-label":cr(c),"data-today":o(c),children:Zz(u.filter(d=>!d.part.allDay)).map(({event:d,part:h,lane:m,lanes:p})=>n.jsxs("button",{type:"button",className:"cal-event","data-tone":d.tone,"data-short":h.to-h.from<60?"true":void 0,"data-lane":m,"aria-label":Ep(d,h,c),onClick:()=>i(c),style:{top:`calc(var(--cal-hour) * ${h.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(h.to-h.from,vC)/60})`,left:`calc((100% - var(--space-1)) * ${m/p} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${p} - var(--space-0))`},children:[n.jsx("span",{className:"cal-event-time",children:sv(d,h)}),n.jsx("span",{className:"cal-event-title",children:d.title})]},d.id))},c))]})})]})})}const oU=3;function cU({dates:e,month:t,today:s,events:r,selected:i,onPick:a}){const l=Array.from({length:6},(d,h)=>e.slice(h*7,h*7+7)),[o,c]=t.split("-").map(Number),u=new Intl.DateTimeFormat("en-GB",{month:"long",year:"numeric",timeZone:"UTC"}).format(new Date(Date.UTC(o,c-1,1)));return n.jsx(Ze,{flush:!0,children:n.jsxs("div",{className:"cal-month",role:"grid","aria-label":u,children:[n.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(d=>n.jsx("div",{className:"cal-wd-head",role:"columnheader",children:tv(d)},d))}),l.map(d=>n.jsx("div",{className:"cal-row",role:"row",children:d.map(h=>{const m=nv(r,h),p=m.slice(0,oU),g=m.length-p.length,y=m.length===0?"nothing":m.length===1?"1 event":`${m.length} events`;return n.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":h===i,"data-date":h,"data-today":h===s?"true":void 0,"data-outside":h.slice(0,7)!==t?"true":void 0,"data-selected":h===i?"true":void 0,onClick:()=>a(h),children:[n.jsx("button",{type:"button",className:"cal-num","aria-label":`${cr(h)}, ${y}`,"aria-pressed":h===i,children:xC(h)}),p.map(({event:b,part:x})=>n.jsx("button",{type:"button",className:"cal-chip","data-tone":b.tone,"data-timed":x.allDay?void 0:"true","aria-label":Ep(b,x,h),children:x.allDay?b.title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"cal-dot","data-tone":b.tone,"aria-hidden":"true"}),n.jsx("span",{className:"cal-chip-time",children:bi(x.from)})," ",b.title]})},b.id)),g>0?n.jsxs("button",{type:"button",className:"cal-more","aria-label":`${g} more on ${cr(h)}`,children:["+",g]}):null]},h)})},d[0]))]})})}const jC={width:1200,height:200,top:28,right:12,bottom:24,left:36};function uU(e,t){if(t==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;t!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const i=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),a=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*i).find(c=>a(c)<=3)??i*10;a(l)<2&&(l>1?l/=2:r+=l);const o=[];for(let c=Math.floor(s/l)*l;c<=Math.ceil(r/l)*l+l/1e3;c+=l)o.push(Math.round(c*1e6)/1e6);return o}function Hc(e,t){return t==="temp"?`${e}°`:t==="percent"?`${e}%`:String(e)}function dU(e){const t=jC,s=e.values.length,r=t.width-t.left-t.right,i=t.height-t.top-t.bottom,a=t.height-t.bottom,l=s>0?r/s:r,o=x=>ki(t.left+l*(x+.5)),c=e.values.filter(x=>x!==null&&Number.isFinite(x)),u=uU(c,e.unit),d=u[0],h=u[u.length-1],m=x=>ki(t.top+i-(x-d)/(h-d)*i),p=e.values.map((x,v)=>{const j=x!==null&&Number.isFinite(x);return{index:v,x:o(v),y:j?m(x):null,value:j?x:null}}),g=[],y=[];if(e.kind==="area"){let x=[];const v=()=>{if(x.length===0)return;const j=x.map((w,S)=>`${S===0?"M":"L"}${w.x},${w.y}`).join(" ");g.push(j),y.push(`${j} L${x[x.length-1].x},${a} L${x[0].x},${a} Z`),x=[]};for(const j of p)j.y===null?v():x.push(j);v()}const b=e.kind==="bars"?p.flatMap(x=>x.y===null?[]:[{index:x.index,x:ki(x.x-l*.28),y:x.y,width:ki(l*.56),height:ki(a-x.y)}]):[];return{ticks:u.map(x=>({value:x,y:m(x)})),lines:g,areas:y,bars:b,points:p,slot:l,floor:a}}function hU({title:e,note:t,xs:s,series:r,tiles:i,labelEvery:a=3}){var S;const[l,o]=f.useState(((S=r[0])==null?void 0:S.id)??""),[c,u]=f.useState(null),[d,h]=f.useState(null),m=f.useRef(null),p=s.length,g=c??d,y=r.find(k=>k.id===l)??r[0],b=dU(y),x=jC,v=k=>k%a===0||k===g,j=y.values.filter(k=>k!==null&&Number.isFinite(k));f.useEffect(()=>{const k=m.current,N=g===null?null:k==null?void 0:k.children[g];!k||!N||typeof k.scrollTo!="function"||(N.offsetLeft<k.scrollLeft?k.scrollTo({left:N.offsetLeft,behavior:"smooth"}):N.offsetLeft+N.offsetWidth>k.scrollLeft+k.clientWidth&&k.scrollTo({left:N.offsetLeft+N.offsetWidth-k.clientWidth,behavior:"smooth"}))},[g]);const w=k=>{var I,A,_;const N=k.key==="ArrowRight"?1:k.key==="ArrowLeft"?-1:0,C=k.key==="Home"?0:k.key==="End"?p-1:N===0?null:Math.max(0,Math.min(p-1,(d??-N)+N));C!==null&&(k.preventDefault(),h(C),(_=(A=(I=m.current)==null?void 0:I.children[C])==null?void 0:A.querySelector("button"))==null||_.focus())};return n.jsxs(Ze,{...e?{title:e}:{},children:[t?n.jsx("p",{className:"ui-panel-sub",children:t}):null,n.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?n.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(k=>n.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":k.id===y.id,onClick:()=>o(k.id),children:k.label},k.id))}):null,n.jsxs("figure",{className:"pg-series-chart","data-kind":y.kind,children:[n.jsxs("svg",{viewBox:`0 0 ${x.width} ${x.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[b.ticks.map(k=>n.jsxs("g",{children:[n.jsx("line",{className:"pg-series-grid",x1:x.left,x2:x.width-x.right,y1:k.y,y2:k.y}),n.jsx("text",{className:"pg-series-tick",x:x.left-8,y:k.y,textAnchor:"end",dominantBaseline:"middle",children:Hc(k.value,y.unit)})]},k.value)),b.areas.map((k,N)=>n.jsx("path",{className:"pg-series-area",d:k},`a${N}`)),b.lines.map((k,N)=>n.jsx("path",{className:"pg-series-line",d:k},`l${N}`)),b.bars.map(k=>n.jsx("rect",{className:"pg-series-bar","data-index":k.index,"data-hover":k.index===g?"true":void 0,x:k.x,y:k.y,width:k.width,height:k.height},k.index)),g!==null&&b.points[g]?n.jsx("line",{className:"pg-series-guide","data-index":g,x1:b.points[g].x,x2:b.points[g].x,y1:x.top-4,y2:b.floor}):null,y.kind==="area"?b.points.map(k=>k.y!==null&&v(k.index)?n.jsx("circle",{className:"pg-series-dot","data-index":k.index,"data-hover":k.index===g?"true":void 0,cx:k.x,cy:k.y,r:k.index===g?5:3},k.index):null):null,b.points.map(k=>k.y!==null&&k.value!==null&&v(k.index)?n.jsx("text",{className:"pg-series-value","data-index":k.index,"data-hover":k.index===g?"true":void 0,x:k.x,y:k.y-(y.kind==="area"?10:6),textAnchor:"middle",children:Hc(k.value,y.unit)},k.index):null),b.points.map(k=>k.index%a===0?n.jsx("text",{className:"pg-series-x",x:k.x,y:x.height-6,textAnchor:"middle",children:s[k.index]},k.index):null),b.points.map(k=>n.jsx("rect",{className:"pg-series-hit","data-index":k.index,x:ki(x.left+b.slot*k.index),y:0,width:ki(b.slot),height:x.height,onMouseEnter:()=>u(k.index),onClick:()=>h(k.index)},k.index))]}),n.jsx("figcaption",{className:"sr-only",children:j.length===0?`${y.label}: no values.`:`${y.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Hc(Math.min(...j),y.unit)}, highest ${Hc(Math.max(...j),y.unit)}.`})]}),n.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:w,children:i.map((k,N)=>n.jsx("li",{className:"wb-tile",children:n.jsx("button",{type:"button",className:"ui-card","data-index":N,"data-hover":N===g?"true":void 0,"aria-pressed":N===d,"aria-label":[k.label,k.value,...k.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(N),onClick:()=>h(N),children:n.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[n.jsx("span",{className:"wb-tile-icon","data-icon":k.icon??"dot",children:n.jsx(ye,{name:qo(k.icon),size:22})}),k.value!==""?n.jsx("span",{className:"wb-tile-value tnum",children:k.value}):null,n.jsx("span",{className:"wb-tile-label",children:k.label}),k.lines.map((C,I)=>n.jsx("span",{className:"wb-tile-line",children:C},I))]})})},N))})]})]})}function ki(e){return Math.round(e*10)/10}const iv=f.createContext(null),od=f.createContext(!1);function Et(){const e=f.useContext(iv);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function Ap(e,t=new Set){if(Array.isArray(e))for(const s of e)Ap(s,t);else if(e&&typeof e=="object"){const s=e.query;typeof s=="string"&&t.add(s);for(const r of Object.values(e))Ap(r,t)}return t}function yC(e,t){if(t.size===0)return!1;for(const s of Ap(e))if(t.has(s))return!0;return!1}function wC(){const[e,t]=f.useState(!1);return f.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&t(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>t(s=>!s)]}function bC({revealed:e,onToggle:t}){return n.jsx(R,{size:"sm",variant:"ghost","aria-pressed":e,onClick:t,children:e?"Hide":"Show"})}function kC(){return n.jsx("p",{className:"muted",children:"Hidden until you show it."})}function SC({children:e}){const[t,s]=wC();return n.jsxs(Q,{gap:"sm",children:[n.jsx(J,{align:"end",children:n.jsx(bC,{revealed:t,onToggle:s})}),t?n.jsx(od.Provider,{value:!0,children:e}):n.jsx(kC,{})]})}function av(e){return e===void 0||e==="neutral"?void 0:e}function Tp(e){return av(e)}function fU(e){const t=av(e);return t==="accent"?void 0:t}function ys(e,t){if(!t)return!0;const s=je(e,t.path),r=t.in!==void 0?t.in.includes(s):s===t.equals;return t.not===!0?!r:r}function lv(e,t,s){if("chat"in t){const a=$e(s,t.chat);return a==null?"":Je(String(a))}if("proposals"in t)return lD(e.plugin);const r=e.pages.find(a=>a.id===t.page);if((r==null?void 0:r.place)==="settings")return ll(e.plugin,t.page);const i=t.item===void 0?null:$e(s,t.item);return si(e.plugin,t.page,i==null?null:String(i))}function mU(e,t){return e.replace(/\{count\}/g,String(t.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,i)=>(t.count??0)===1?r:i).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const i=je(t.row,r);return i==null?"":String(i)})}function Rp(e,t){if(e===void 0)return;if(typeof e=="string")return e;const s=$e(t,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function NC(e,t,s){const r={};for(const[i,a]of Object.entries(e??{})){let l;"param"in a?l=s.params[a.param]:"route"in a?l=a.route==="plugin"?s.plugin:a.route==="page"?s.page:s.item:l=$e(t,a),!(l==null||l==="")&&(r[i]=String(l))}return r}function Fi(e,t){var r,i,a;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=je(t.row,o.row);else if("field"in o){if((r=t.omit)!=null&&r.has(o.field))continue;const c=(i=t.fields)==null?void 0:i[o.field],u=(a=t.shape)==null?void 0:a.find(d=>d.name===o.field);if(c===""&&(u==null?void 0:u.required)!==!0&&(u===void 0||u.type==="number"))continue;s[l]=c}else"selected"in o?s[l]=t.selected??[]:"param"in o?s[l]=t.scope.params[o.param]:s[l]=$e(t.data,o);return s}function wn(e,t,s,r){const i=Et(),a=e?{...NC(e.params,t,i),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,a,i.version]),o=le(()=>e?T.pageQuery(i.plugin,e.query,a).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function Qo(){const e=Et(),t=f.useId(),[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(null),m=(b,x)=>{if(b.done===void 0)return null;if(typeof b.done=="string")return b.done;const v=$e(x,b.done);return v==null?null:String(v)},p=(b,x,v)=>{const j=b??"refresh";if(typeof j=="object"){const w=lv(e,j.route,x);w===""?e.refresh():e.navigate(w);return}j==="close"&&(v==null||v()),e.refresh()},g=async(b,x,v)=>{r(b.tool),a(null),o(null);try{const j=await T.pageAct(e.plugin,{tool:b.tool,args:x});if(j.approvalId){u(j.approvalId),h({then:b.then,ref:b,...v?{onDone:v}:{}});return}u(null),h(null);const w=hC(j.result);o(m(b,j.result)??(w?fC(j.result):null)),w&&await pC(w,t),p(b.then,j.result,v)}catch(j){a(j instanceof Error?j.message:String(j)),e.refresh()}finally{r(null)}},y=b=>{if(!b){e.refresh();return}const x=d;if(u(null),h(null),x&&b.decision==="approve"&&b.state==="succeeded"){o(m(x.ref,b.result)),p(x.then,void 0,x.onDone);return}e.refresh()};return{running:s,busy:s!==null,error:i,done:l,approvalId:c,waiting:(d==null?void 0:d.ref.pending)??null,settle:y,run:g}}function Va({action:e,args:t,disabled:s,running:r,count:i,row:a,onRun:l}){const[o,c]=f.useState(!1),u=h=>mU(h,{...i===void 0?{}:{count:i},row:a}),d=u(e.label);return o&&e.confirm?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),n.jsx(R,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),n.jsxs(R,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,t)},children:["Yes, ",d.toLowerCase()]})]}):n.jsx(R,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,t),children:r&&e.busy?e.busy:d})}function cd({id:e,onDecided:t}){const s=Et(),r=le(()=>T.approval(e),[e,s.version]),{busy:i,note:a,failure:l,decide:o}=Jx(c=>{t?t(c):s.refresh()});return r.error?n.jsx(re,{message:r.error}):r.data?n.jsxs(Q,{children:[n.jsx(Xx,{action:r.data,timezone:s.timezone,busy:i===e,onDecide:(c,u,d,h)=>{o(c,u,d,h)}}),a?n.jsx(W,{tone:"good",role:"status",children:a}):null,n.jsx(re,{message:l})]}):n.jsx(ce,{children:"Loading the approval…"})}function ul({act:e}){return e.error?n.jsx(re,{message:e.error}):e.approvalId?e.waiting?n.jsxs(Q,{children:[n.jsx(W,{role:"status",children:e.waiting}),n.jsx(cd,{id:e.approvalId,onDecided:e.settle})]}):n.jsx(cd,{id:e.approvalId,onDecided:e.settle}):e.done?n.jsx(W,{tone:"good",role:"status",children:e.done}):null}function ud(e,t){const s={};for(const r of e){const i=r.from===void 0?void 0:je(t,r.from);s[r.name]=r.multiple?Array.isArray(i)?i.map(String):[]:i!==void 0?i:r.type==="checkbox"?!1:""}return s}function CC(e,t,s){const r=Et(),i=e.optionsFrom,a=i?{...NC(i.query.params,s,r),...Object.fromEntries((i.dependsOn??[]).map(c=>[c,String(t[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(i==null?void 0:i.query.query)??null,a,r.version]),o=le(()=>i?T.pageQuery(r.plugin,i.query.query,a).then(c=>c.data):Promise.resolve(void 0),[l]);return i?{options:Ys(o.data,i.rows).map(c=>({value:String(je(c,i.value)??""),label:String(je(c,i.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function pU({field:e,fields:t,value:s,values:r,data:i,disabled:a,compact:l,onChange:o}){const c=CC(e,r,i),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:a,...l&&e.hint?{title:e.hint}:{}},d=l?void 0:e.hint;if(e.type==="select"&&e.multiple){const m=Array.isArray(s)?s.map(String):[],g=e.max!==void 0&&m.length>=e.max?`Up to ${e.max}; remove one to add another.`:void 0;return n.jsx(Z,{label:e.label,hint:l?void 0:[d,g].filter(Boolean).join(" ")||void 0,group:!0,children:n.jsx(rL,{id:u.id,label:e.label,options:c.options,value:m,max:e.max,disabled:a,onChange:o})})}if(e.type==="select"){const m=n.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[n.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>n.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?n.jsx(gU,{field:e,action:e.action,fields:t??[e],values:r,data:i,disabled:a,hint:d,children:m}):n.jsx(Z,{label:e.label,hint:d,children:m})}if(e.type==="textarea")return n.jsx(Z,{label:e.label,hint:d,wide:!0,children:n.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return n.jsx(Z,{label:e.label,hint:d,inline:!0,wide:!l,children:n.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const h=e.type==="secret"?"password":e.type==="number"?"number":e.type;return n.jsx(Z,{label:e.label,hint:d,children:n.jsx("input",{...u,type:h,value:s==null?"":String(s),min:e.min,max:e.max,step:e.step,...l&&e.hint?{placeholder:e.hint}:{},onChange:m=>o(e.type==="number"?xU(m.target.value):m.target.value)})})}function gU({field:e,action:t,fields:s,values:r,data:i,disabled:a,hint:l,children:o}){const c=Et(),u=f.useId(),d=Wz()===u,[h,m]=f.useState(!1),[p,g]=f.useState(null),[y,b]=f.useState(null),[x,v]=f.useState(null);f.useEffect(()=>()=>Ww(u),[u]);const j=ov(s,r,i),w=t.args!==void 0?Fi(t.args,{data:i,fields:r,shape:s,omit:j,scope:c}):Object.fromEntries(Object.entries(r).filter(([N,C])=>!j.has(N)&&C!=="")),S=async()=>{if(d){Ww(u);return}m(!0),g(null),b(null),v(null);try{const N=await T.pageAct(c.plugin,{tool:t.tool,args:w});if(N.approvalId){v(N.approvalId);return}g(fC(N.result));const C=hC(N.result);C&&await pC(C,u)}catch(N){b(N instanceof Error?N.message:String(N))}finally{m(!1)}},k=d?"Stop":t.label;return n.jsx(Z,{label:e.label,hint:l,action:n.jsx(R,{"data-shape":"icon","aria-label":h?`${t.label}: working`:k,title:k,"aria-busy":h||void 0,"aria-pressed":t.icon==="play"?d:void 0,disabled:a===!0||h,onClick:()=>void S(),children:h?n.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):n.jsx(ye,{name:d?"stop":t.icon??"arrow"})}),after:y?n.jsx(re,{message:y}):x?n.jsx(cd,{id:x,onDecided:()=>v(null)}):p?n.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function xU(e){if(e.trim()==="")return"";const t=Number(e);return Number.isFinite(t)?t:e}function EC(e,t){return{...typeof t=="object"&&t!==null?t:{},...e}}function ov(e,t,s){const r=EC(t,s);return new Set(e.filter(i=>i.when!==void 0&&!ys(r,i.when)||i.disabledWhen!==void 0&&ys(r,i.disabledWhen)).map(i=>i.name))}function cv({fields:e,values:t,data:s,disabled:r,compact:i,columns:a,onChange:l}){const o=EC(t,s);return n.jsx(bs,{dense:i,columns:a,children:e.filter(c=>c.when===void 0||ys(o,c.when)).map(c=>n.jsx(pU,{field:c,fields:e,compact:i,value:t[c.name],values:t,data:s,disabled:r===!0||c.disabledWhen!==void 0&&ys(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const Po=f.createContext(!1),AC=f.createContext(!1),TC=f.createContext(!1);function qn({title:e,note:t,actions:s,children:r}){const i=f.useContext(Po);return n.jsx(te,{title:e,aside:t,actions:s,panel:i,children:n.jsx(Po.Provider,{value:!1,children:n.jsx(AC.Provider,{value:i,children:r})})})}function Gs({component:e,data:t,choose:s,chosen:r}){const i=Et(),a=f.useContext(od);if(!ys(t,e.when))return null;if(e.kind!=="section"&&!a&&yC(e,i.sensitive))return n.jsx(SC,{children:n.jsx(Gs,{component:e,data:t,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return n.jsx(vU,{component:e,data:t});case"notice":return n.jsx(W,{tone:av(e.tone),title:e.title,children:typeof e.text=="string"?e.text:String($e(t,e.text)??"")});case"link":return n.jsx(jU,{component:e,data:t});case"progress":return n.jsx(wU,{component:e,data:t});case"chart":return n.jsx(bU,{component:e,data:t});case"stats":return n.jsx(kU,{component:e,data:t});case"list":return n.jsx(NU,{component:e,data:t,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return n.jsx(CU,{component:e,data:t});case"detail":return n.jsx(TU,{component:e,data:t});case"form":return n.jsx(RU,{component:e,data:t});case"search":return n.jsx($U,{component:e,data:t});case"list-detail":return n.jsx(MU,{component:e,data:t});case"repeat":return n.jsx(OU,{component:e,data:t});case"calendar":return n.jsx(DU,{component:e,data:t});case"tiles":return n.jsx(_U,{component:e,data:t});case"series-panel":return n.jsx(LU,{component:e,data:t});case"hero":return n.jsx(FU,{component:e,data:t});case"tabs":return n.jsx(zU,{component:e,data:t});case"expand":return n.jsx(UU,{component:e,data:t});case"button":return n.jsx(BU,{component:e,data:t});case"approval":return n.jsx(HU,{component:e,data:t});case"artifact":return n.jsx(KU,{component:e,data:t});case"editor":return n.jsx(VU,{component:e,data:t});case"agent-offer":return n.jsx(WU,{component:e});default:return n.jsx(W,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function vU({component:e,data:t}){const s=Et(),r=f.useContext(od),[i,a]=wC(),l=!r&&yC(e.body,s.sensitive),o=l&&!i,c=f.useContext(Po);let u=e.body.length;const d=p=>p.kind==="button"||p.kind==="link"||p.kind==="form"&&p.drawer!==void 0&&!p.title;for(;c&&u>0&&d(e.body[u-1]);)u-=1;const h=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)];return n.jsx(qn,{title:e.title,note:e.note,actions:m.length>0||l?n.jsxs(n.Fragment,{children:[m.map((p,g)=>n.jsx(Gs,{component:p,data:t},g)),l?n.jsx(bC,{revealed:i,onToggle:a}):null]}):void 0,children:n.jsx(Q,{gap:"lg",divided:c,children:o?n.jsx(kC,{}):n.jsx(od.Provider,{value:r||l,children:h.map((p,g)=>n.jsx(Gs,{component:p,data:t},g))})})})}function jU({component:e,data:t}){const s=Et(),r=lv(s,e.to,t);return r===""?null:n.jsx(J,{children:n.jsx(Ut,{href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})})}function Yw(e){return Math.round(e/1e6)}function yU(e,t){const s=Bn($e(t,e.value))??0,r=e.total?Bn($e(t,e.total)):null,i=e.total?r&&r>0?s/r:0:s,a=Math.max(0,Math.min(1,i)),l=Math.floor(a*100),o=i>=1,c=e.total&&r&&r>0?`${Yw(s)} of ${Math.max(1,Yw(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function wU({component:e,data:t}){const s=c=>c===void 0?"":typeof c=="string"?c:String($e(t,c)??""),r=s(e.label),i=s(e.done),{percent:a,full:l,line:o}=yU(e,t);return n.jsxs(Q,{gap:"sm",children:[r?n.jsx("span",{children:r}):null,l&&i?n.jsx("span",{role:"status",children:i}):n.jsxs(n.Fragment,{children:[n.jsx(k1,{value:a,label:r||"Progress"}),n.jsx("span",{role:"status",children:o})]})]})}function bU({component:e,data:t}){const s=wn(e.query,t),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:Ys(s.data,e.rows),i=r.map(d=>String(je(d,e.x)??"")),a=d=>r.map(h=>Bn(je(h,d))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(d=>({label:d.label,values:a(d.y),type:d.type,...d.unit?{unit:d.unit}:{}})):o.map(d=>({label:o.length===1?e.label??d:d,values:a(d)})),u=e.target?Bn($e(s.data,e.target))??null:null;return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),r.length===0?s.loading||s.data===void 0?n.jsx(ce,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing recorded yet."}):n.jsx(X_,{xs:i,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:d=>/^\d{4}-\d{2}-\d{2}/.test(d)?Xm(d):d,formatY:d=>zt(d,"number",null)})]})}function kU({component:e,data:t}){const s=wn(e.query,t);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),s.data===void 0?n.jsx(ce,{children:e.empty??"Loading…"}):n.jsx(nh,{children:e.items.map((r,i)=>n.jsx(zs,{label:r.label,value:zt($e(s.data,r.value),r.unit??"text",null),tone:fU(r.tone)},i))})]})}function RC(e,t,s,r){const i=(t.meta??[]).map(u=>String($e(s,u)??"")).filter(u=>u!==""),a=String($e(s,t.title)??""),l=t.to&&!r?lv(e,t.to,s):null,c=[...t.pill?[t.pill]:[],...t.pills??[]].map((u,d)=>{const h=$e(s,u.value);if(h==null||h==="")return null;const m=SU(u,h,s);return n.jsx(ve,{tone:Tp(m.tone),children:m.text},d)});return{text:a,href:l,pills:n.jsx(n.Fragment,{children:c}),meta:i.join(" · "),title:l?n.jsx("a",{href:l,onClick:u=>{u.preventDefault(),e.navigate(l)},children:a}):a,sub:t.sub?String($e(s,t.sub)??""):null,side:n.jsxs(n.Fragment,{children:[c,i.length>0?n.jsxs("span",{className:"muted",children:[" ",i.join(" · ")]}):null]})}}function SU(e,t,s){const r=String(t),i=e.labels??{},a=e.tones??{};return{text:Object.prototype.hasOwnProperty.call(i,r)?i[r]:r,tone:Object.prototype.hasOwnProperty.call(a,r)?a[r]:Rp(e.tone,s)}}function Ys(e,t){const s=je(e,t);return Array.isArray(s)?s:[]}function IC(e,t,s){const r=[],i=new Set;return e.forEach((a,l)=>{const o=t===void 0?void 0:je(a,t),c=o==null||o===""?null:String(o);if(c===null){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: row ${l} has no value at "${t??"(no key)"}" — not drawn`);return}if(i.has(c)){console.warn(`buddi: plugin ${s.plugin}, page ${s.page}, ${s.component}: two rows share the key "${c}" — the second is not drawn`);return}i.add(c),r.push({key:c,row:a})}),r}function NU({component:e,data:t,onChoose:s,chosen:r}){var S;const i=Et(),a=f.useContext(TC),l=wn(e.query,t),o=Qo(),[c,u]=f.useState([]),d=a&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,h=Ys(l.data,e.rows),m=e.collapsed?Ys(l.data,e.collapsed.rows):[],p={plugin:i.plugin,page:i.page,component:`list "${e.title??e.rows}"`},g=IC([...h,...m],e.key??((S=e.select)==null?void 0:S.key),p),y=new Map(g.map(k=>[k.row,k.key])),b=new Set(g.map(k=>k.row)),x=new Set(g.filter(({row:k})=>{var N;return((N=e.select)==null?void 0:N.disabledWhen)===void 0||!ys(k,e.select.disabledWhen)}).map(({key:k})=>k)),v=c.filter(k=>x.has(k)),j=f.useMemo(()=>{const k=h.filter(C=>b.has(C));if(!e.groupBy)return[{label:null,rows:k}];const N=new Map;for(const C of k){const I=String(je(C,e.groupBy.key)??"");N.set(I,[...N.get(I)??[],C])}return[...N].map(([C,I])=>{var A,_;return{label:((_=(A=e.groupBy)==null?void 0:A.labels)==null?void 0:_[C])??C,rows:I}})},[h,e.groupBy,g.length]),w=k=>k.map(N=>{var z;const C=RC(i,e.item,N,s),I=y.get(N);if(d&&(s||C.href))return n.jsx(S1,{href:C.href??"#",current:r===I,onClick:()=>s?s(I):i.navigate(C.href),title:C.text,meta:C.meta,sub:C.sub,side:C.pills},I);const A=((z=e.select)==null?void 0:z.disabledWhen)!==void 0&&ys(N,e.select.disabledWhen),_=(e.actions??[]).filter(L=>ys(N,L.when));return n.jsx(ft,{lead:e.select?n.jsx("input",{type:"checkbox","aria-label":`Select ${C.text}`,disabled:A,checked:c.includes(I),onClick:L=>L.stopPropagation(),onChange:L=>u(E=>L.target.checked?[...E,I]:E.filter(M=>M!==I))}):void 0,title:s?n.jsx("a",{href:"#","aria-current":r===I?"true":void 0,onClick:L=>{L.preventDefault(),s(I)},children:C.text}):C.title,sub:C.sub,side:n.jsxs(n.Fragment,{children:[C.side,_.map((L,E)=>n.jsx(Va,{action:L,args:Fi(L.args,{data:l.data,row:N,scope:i}),disabled:o.busy,running:o.running===L.tool,row:N,onRun:(M,D)=>void o.run(M,D)},E))]})},I)});return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:l.error}),n.jsx(ul,{act:o}),j.every(k=>k.rows.length===0)?l.loading?n.jsx(ce,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing here yet."}):n.jsxs(yt,{children:[e.select?n.jsx(ft,{lead:n.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:x.size>0&&v.length===x.size,disabled:x.size===0,onChange:k=>u(k.target.checked?[...x]:[])}),title:n.jsxs("span",{className:"muted",children:[x.size," to choose from"]})}):null,j.map((k,N)=>n.jsxs("div",{children:[k.label?n.jsx("div",{className:"ui-list-group",children:k.label}):null,w(k.rows)]},N))]}),e.collapsed&&m.some(k=>b.has(k))?n.jsx(Ct,{summary:`${e.collapsed.label} (${m.filter(k=>b.has(k)).length})`,children:n.jsx(yt,{children:w(m.filter(k=>b.has(k)))})}):null,e.bulk&&e.bulk.length>0?n.jsxs(J,{align:"end",children:[n.jsxs("span",{className:"ui-toolbar-note",children:[v.length," selected"]}),e.bulk.map((k,N)=>{const C=v.length>0||k.all!==!0?v:[...x];return n.jsx(Va,{action:k,args:Fi(k.args,{data:l.data,selected:C,scope:i}),count:C.length,disabled:o.busy||C.length===0,running:o.running===k.tool,onRun:(I,A)=>{u([]),o.run(I,A)}},N)})]}):null]})}function CU({component:e,data:t}){const s=Et(),r=wn(e.query,t),i=Qo(),a=Ys(r.data,e.rows);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:r.error}),n.jsx(ul,{act:i}),a.length===0?r.loading?n.jsx(ce,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing here yet."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[e.columns.map(l=>n.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?n.jsx("th",{"aria-label":"Actions"}):null]})}),n.jsx("tbody",{children:a.map((l,o)=>n.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:zt(je(l,c.key),c.type??"text",null);return n.jsx("td",{"data-fit":c.fit,title:EU(c,l,u),children:c.pill?n.jsx(AU,{column:c,row:l}):c.fit==="truncate"?n.jsx("span",{className:"ui-table-cut",children:u}):u},c.key)}),e.actions&&e.actions.length>0?n.jsx("td",{children:n.jsx(J,{align:"end",children:e.actions.filter(c=>ys(l,c.when)).map((c,u)=>n.jsx(Va,{action:c,args:Fi(c.args,{data:r.data,row:l,scope:s}),disabled:i.busy,running:i.running===c.tool,row:l,onRun:(d,h)=>void i.run(d,h)},u))})}):null]},o))})]})]})}function EU(e,t,s){if(e.hint){const r=je(t,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function AU({column:e,row:t}){var l,o;const s=je(t,e.key);if(Array.isArray(s))return n.jsx(n.Fragment,{children:s.map((c,u)=>{var y;const d=c,h=typeof d=="object"&&d!==null?d.value:c;if(h==null||h==="")return null;const m=typeof d=="object"&&d!==null?d.tone:void 0,p=(y=e.pill)==null?void 0:y.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(h))?p[String(h)]:zt(h,e.type??"text",null);return n.jsx(ve,{tone:Tp(Rp(typeof m=="string"?m:void 0,t)),children:g},u)})});const r=(l=e.pill)==null?void 0:l.labels,i=String(s),a=r&&Object.prototype.hasOwnProperty.call(r,i)?r[i]:zt(s,e.type??"text",null);return n.jsx(ve,{tone:Tp(Rp((o=e.pill)==null?void 0:o.tone,t)),children:a})}function TU({component:e,data:t}){const s=wn(e.query,t);return s.error?n.jsx(re,{message:s.error}):s.data===void 0?n.jsx(ce,{children:e.empty??"Loading…"}):n.jsx(qn,{title:e.title,note:e.note,children:n.jsxs(Q,{gap:"lg",children:[e.fields.length>0?n.jsx(Gt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:zt($e(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,i)=>n.jsx(Gs,{component:r,data:s.data},i))]})})}function RU({component:e,data:t}){const s=Et(),r=wn(e.initial,t),i=Qo(),[a,l]=f.useState(!1),o=JSON.stringify([r.data??null,s.version]),c=n.jsx(IU,{component:e,data:t,initialData:r.data,act:i,onDone:()=>l(!1)},o);return e.drawer?n.jsxs(te,{title:e.title,aside:e.note,actions:n.jsx(R,{variant:"accent",onClick:()=>l(!0),children:e.drawer.button}),children:[n.jsx(ul,{act:i}),a?n.jsx(kt,{title:e.drawer.title,onClose:()=>l(!1),children:c}):null]}):n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:r.error}),c]})}function IU({component:e,data:t,initialData:s,act:r,onDone:i}){const a=f.useContext(AC),l=Et(),[o,c]=f.useState(()=>ud(e.fields,s)),u=ov(e.fields,o,s),d=e.fields.some(h=>h.required&&!u.has(h.name)&&(o[h.name]===""||o[h.name]===void 0||Array.isArray(o[h.name])&&o[h.name].length===0));return n.jsxs(Q,{children:[n.jsx(cv,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(h,m)=>c(p=>({...p,[h]:m}))}),e.drawer?null:n.jsx(ul,{act:r}),n.jsx(J,{align:"end",className:a?"ui-panel-foot":void 0,children:n.jsx(Va,{action:e.submit,args:Fi(e.submit.args,{data:t,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||d,running:r.running===e.submit.tool,onRun:(h,m)=>void r.run(h,m,i)})})]})}function PU(e,t){var r;if(e.type==="checkbox")return e.label;const s=(r=e.options)==null?void 0:r.find(i=>i.value===t);return`${e.label}: ${s?s.label:t}`}function qw(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function $U({component:e,data:t}){const s=Et(),[r,i]=f.useState(()=>ud(e.fields,t)),[a,l]=f.useState(e.auto===!0),[o,c]=f.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),d=wn(a&&u?e.query:void 0,t),h=Ys(d.data,e.rows),m=e.count===void 0?void 0:je(d.data,e.count),p=e.note===void 0?void 0:je(d.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,y=e.fields.filter(C=>C!==g),b=C=>{s.setParams(Object.fromEntries(e.fields.map(I=>[I.name,String(C[I.name]??"")||null]))),l(!0)},x=(C,I)=>{const A={...r,[C]:I};i(A),e.auto&&b(A)},v=()=>{const C=ud(e.fields,null);i(C),e.auto?b(C):(s.setParams(Object.fromEntries(e.fields.map(I=>[I.name,null]))),l(!1))},j=a?y.filter(C=>qw(s.params[C.name])):[],w=g?j.map(C=>n.jsx(Zu,{label:C.label,onRemove:()=>{const I={...r,[C.name]:C.type==="checkbox"?!1:""};i(I),b(I)},children:PU(C,String(s.params[C.name]))},C.name)):[],S=y.filter(C=>qw(r[C.name])).length,k=e.auto&&!e.reset?null:n.jsxs(n.Fragment,{children:[e.reset?n.jsx(R,{variant:"ghost",onClick:v,children:"Clear"}):null,e.auto?null:n.jsx(R,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),N=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return n.jsx(qn,{title:e.title,children:n.jsxs(Q,{children:[n.jsx(A1,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&b(r)},main:g?n.jsx("input",{id:`f-${g.name}`,name:g.name,type:g.type==="email"?"email":"search","aria-label":g.label,placeholder:g.hint??g.label,title:g.hint,required:g.required,value:String(r[g.name]??""),onChange:C=>x(g.name,C.target.value)}):void 0,filters:y.length>0?n.jsx(cv,{fields:y,values:r,data:t,compact:!0,onChange:x}):void 0,...g&&y.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:S}:{},chips:w.length>0?w:void 0,actions:k}),n.jsx(re,{message:d.error}),a&&(m!==void 0||p!==void 0)?n.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${zt(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,a?h.length===0?n.jsx(ce,{children:d.loading?"Searching…":e.empty??"Nothing matches."}):n.jsx("div",{className:"ui-panel","data-flush":"true",children:n.jsx(yt,{children:h.map((C,I)=>{const A=RC(s,N,C);return n.jsx(ft,{title:A.title,sub:A.sub,side:A.side},I)})})}):null]})})}function MU({component:e,data:t}){const s=Et(),r=e.selection==="local",[i,a]=f.useState(null),l=r?i:s.params[e.param]??s.item,o=r&&i!==null?{...s,params:{...s.params,[e.param]:i}}:null,c=n.jsx(Q,{gap:"lg",divided:!0,children:e.detail.map((u,d)=>n.jsx(Gs,{component:u,data:t},d))});return n.jsx(Po.Provider,{value:!1,children:n.jsx(N1,{list:n.jsx(TC.Provider,{value:!0,children:n.jsx(Gs,{component:e.list,data:t,chosen:l??null,...r?{choose:a}:{}})}),detail:l?o?n.jsx(iv.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function OU({component:e,data:t}){const s=Et(),[r,i]=f.useState(!1),a=wn(e.query,t,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&a.data!==void 0&&ys(a.data,e.poll.while);f.useEffect(()=>i(l),[l]);const o=Ys(a.data,e.rows);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:a.error}),o.length===0?a.loading?n.jsx(ce,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing here yet."}):n.jsx(Q,{gap:"lg",divided:!0,children:IC(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:c,row:u})=>n.jsx(te,{children:n.jsx(Q,{children:e.body.map((d,h)=>n.jsx(Gs,{component:d,data:u},h))})},c))})]})}function DU({component:e,data:t}){const s=Et(),r=iU({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:Gz(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),i=wn(e.query,t,void 0,{from:r.from,to:r.to}),a=f.useMemo(()=>Jz(Ys(i.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[i.data,e.events,e.map,s.timezone,s.plugin,s.page]);return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:i.error}),n.jsx(aU,{state:r,events:a,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar"})]})}function _U({component:e,data:t}){var h;const s=Et(),r=wn(e.query,t),i={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},a=Ys(r.data,e.items).flatMap(m=>{const p=Ix([m],i).tiles[0];return p?[{tile:p,key:e.select?String(je(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,a.findIndex(m=>m.key===s.params[l.param])):null,c=((h=a[0])==null?void 0:h.key)??"",u=l?s.params[l.param]:void 0,d=a.some(m=>m.key===u);return f.useEffect(()=>{l&&c!==""&&!d&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,d]),n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:r.error}),r.data===void 0?n.jsx(ce,{children:"Loading…"}):a.length===0?n.jsx(dl,{text:e.empty??"Nothing to show."}):n.jsx(z1,{props:{tiles:a.map(m=>m.tile),notice:!1,empty:""},...e.layout?{layout:e.layout}:{},...l?{selected:o,onPick:m=>{var p;return s.setParams({[l.param]:((p=a[m])==null?void 0:p.key)||null})}}:{}})]})}function LU({component:e,data:t}){const s=wn(e.query,t),r=Ys(s.data,e.points);if(s.data===void 0||r.length===0)return n.jsxs(qn,{title:e.title,note:e.note,children:[n.jsx(re,{message:s.error}),s.data===void 0?n.jsx(ce,{children:"Loading…"}):n.jsx(dl,{text:e.empty??"Nothing to show."})]});const i=r.map(c=>String(je(c,e.x)??"")),a={items:"$",icon:e.tiles.icon,value:e.tiles.value,label:e.tiles.label,...e.tiles.lines?{lines:e.tiles.lines}:{}},l=r.map((c,u)=>Ix([c],a).tiles[0]??{icon:null,value:"",label:i[u]??"",lines:[],tone:"neutral",link:null}),o=e.series.map(c=>({id:c.id,label:c.label,kind:c.kind,...c.unit?{unit:c.unit}:{},values:r.map(u=>Bn(je(u,c.y))??null)}));return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:s.error}),n.jsx(hU,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:i,series:o,tiles:l})]})}function FU({component:e,data:t}){const s=wn(e.query,t),r=o=>{const c=je(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:s.error}),n.jsx(ce,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const i=r(e.value),a=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return n.jsxs("section",{className:"pg-hero","aria-label":[i,a,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", "),children:[n.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[n.jsx("span",{className:"pg-hero-icon",children:n.jsx(ye,{name:qo(ap($e(s.data,e.icon))),size:44})}),n.jsx("span",{className:"pg-hero-value",children:i}),a?n.jsx("span",{className:"pg-hero-title",children:a}):null]}),l.length>0?n.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>n.jsxs("div",{className:"pg-hero-fact",children:[n.jsx("dt",{children:o.label}),n.jsx("dd",{children:o.value})]},o.label))}):null]})}function zU({component:e,data:t}){var u;const s=Et(),[r,i]=f.useState(e.default??e.tabs[0].id),a=e.pick,{options:l}=CC({name:(a==null?void 0:a.param)??"",label:(a==null?void 0:a.label)??"",...a!=null&&a.options?{options:a.options}:{},...a!=null&&a.optionsFrom?{optionsFrom:a.optionsFrom}:{}},{},t),o=a?l.some(d=>d.value===s.params[a.param])?s.params[a.param]:((u=l[0])==null?void 0:u.value)??"":"",c=e.tabs.find(d=>d.id===r)??e.tabs[0];return n.jsxs("div",{className:"pg-tabs",children:[n.jsxs("div",{className:"pg-tabs-bar",children:[a&&l.length>1?n.jsx(ls,{label:a.label,options:l,value:o,onChange:d=>s.setParams({[a.param]:d})}):null,n.jsx(ls,{label:e.title??"View",options:e.tabs.map(d=>({value:d.id,label:d.label})),value:c.id,onChange:i})]}),c.body.map((d,h)=>n.jsx(Gs,{component:d,data:t},`${c.id}-${h}`))]})}function UU({component:e,data:t}){const[s,r]=f.useState(!1),i=wn(s?e.query:void 0,t),a=typeof e.label=="string"?e.label:String($e(t,e.label)??"");return n.jsxs(Ct,{summary:a,boxed:!0,onToggle:l=>r(l),children:[n.jsx(re,{message:i.error}),i.data===void 0?n.jsx(ce,{children:"Loading…"}):n.jsx(Q,{children:e.body.map((l,o)=>n.jsx(Gs,{component:l,data:i.data},o))})]})}function BU({component:e,data:t}){const s=Et(),r=Qo();return n.jsxs(n.Fragment,{children:[n.jsx(J,{align:"end",children:n.jsx(Va,{action:e.action,args:Fi(e.action.args,{data:t,row:t,scope:s}),disabled:r.busy,running:r.running===e.action.tool,row:t,onRun:(i,a)=>void r.run(i,a)})}),n.jsx(ul,{act:r})]})}function WU({component:e}){const t=Et();return n.jsx(ev,{plugin:t.plugin,agent:e.agent,text:e.text,label:e.label})}function HU({component:e,data:t}){const s=je(t,e.path);return typeof s!="string"||s===""?null:n.jsx(cd,{id:s})}function KU({component:e,data:t}){const s=je(t,e.path);return typeof s!="string"||s===""?null:n.jsx(J,{children:n.jsx("a",{href:ri(s),children:e.label})})}function VU({component:e,data:t}){const s=wn(e.query,t),r=Qo();return s.error?n.jsx(re,{message:s.error}):s.data===void 0?n.jsx(ce,{children:e.empty??"Loading…"}):n.jsxs(n.Fragment,{children:[n.jsx(ul,{act:r}),n.jsx(GU,{component:e,data:t,loaded:s.data,act:r},JSON.stringify(s.data))]})}function GU({component:e,data:t,loaded:s,act:r}){const i=Et(),[a,l]=f.useState(()=>ud(e.fields,s)),o={...a,version:je(s,e.version)},c=ov(e.fields,a,s),u=e.readOnlyWhen!==void 0&&ys(s,e.readOnlyWhen),d=(e.actions??[]).filter(p=>p.placement==="leading"),h=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>n.jsx(Va,{action:p,args:Fi(p.args,{data:t,fields:o,shape:e.fields,omit:c,scope:i}),disabled:r.busy,running:r.running===p.tool,onRun:(y,b)=>void r.run(y,b)},`${p.tool}-${g}`);return n.jsx(qn,{title:e.title,note:e.note,children:n.jsxs(Q,{children:[n.jsx(cv,{fields:e.fields,values:a,data:s,disabled:u,onChange:(p,g)=>l(y=>({...y,[p]:g}))}),u?null:n.jsxs(J,{align:"end",children:[d.map(m),d.length>0?n.jsx(Xt,{}):null,m(e.save,-1),h.map(m)]}),e.footnote?n.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function uv({page:e,item:t,navigate:s,timezone:r,embedded:i,siblings:a}){const[l,o]=f.useState({}),[c,u]=f.useState(0),d={plugin:e.plugin,page:e.id,pages:a??[e],item:t??null,params:{...l,...t?{item:t}:{},...qU(e,t)},setParams:g=>o(y=>{const b={...y};for(const[x,v]of Object.entries(g))v===null?delete b[x]:b[x]=v;return b}),navigate:s,timezone:r,version:c,refresh:()=>u(g=>g+1),sensitive:new Set(e.sensitive??[])},h=e.body[0],m=!i&&(h==null?void 0:h.kind)==="notice"&&typeof h.text=="string"&&h.when===void 0&&h.title===void 0&&(h.tone===void 0||h.tone==="neutral")?h.text:void 0,p=m===void 0?e:{...e,body:e.body.slice(1)};return n.jsx(iv.Provider,{value:d,children:n.jsx(yn,{embedded:i,title:e.title,lede:m,children:n.jsx(YU,{page:p,boxed:i===!0})})})}function YU({page:e,boxed:t}){const s=Et();return e.data&&s.sensitive.has(e.data.query)?n.jsx(SC,{children:n.jsx(Qw,{page:e,boxed:t})}):n.jsx(Qw,{page:e,boxed:t})}function Qw({page:e,boxed:t}){const s=wn(e.data,null);return n.jsxs(Q,{gap:"lg",divided:!t,children:[n.jsx(re,{message:s.error}),n.jsx(Po.Provider,{value:t,children:e.body.map((r,i)=>n.jsx(Gs,{component:r,data:s.data??null},i))})]})}function qU(e,t){if(!t)return{};const s=[],r=i=>{for(const a of i)a.kind==="list-detail"?(s.push(a.param),r(a.detail)):(a.kind==="section"||a.kind==="detail"||a.kind==="expand")&&r(a.body)};return r(e.body),Object.fromEntries(s.map(i=>[i,t]))}function QU(e){return n.jsx(uv,{...e,embedded:!0})}function dl({text:e}){const t=e.search(/[.!?]\s/),s=t===-1?e.replace(/[.]$/,""):e.slice(0,t+(e[t]==="."?0:1)),r=t===-1?"":e.slice(t+1).trim();return n.jsx(Zt,{title:s,children:r||null})}const Jw=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],JU=["","image","pdf","table","text","code","audio","video","archive","file"];function XU({hash:e,timezone:t,navigate:s,agents:r}){var L;const i=JO(e),a=(i==null?void 0:i.artifactId)??null,l=(i==null?void 0:i.filters.origin)??"",o=(i==null?void 0:i.filters.family)??"",c=(i==null?void 0:i.filters.q)??"",[u,d]=f.useState(c);f.useEffect(()=>{d(c)},[c]);const h=(E,M=!1)=>s($c(a,{q:c,origin:l,family:o,...E}),M);f.useEffect(()=>{if(u===c)return;const E=window.setTimeout(()=>h({q:u},!0),250);return()=>window.clearTimeout(E)},[u]);const[m,p]=f.useState(null),[g,y]=f.useState(null),[b,x]=f.useState(null),[v,j]=f.useState(!1),[w,S]=f.useState(!1),k=E=>{var M;return E?((M=r.find(D=>D.id===E))==null?void 0:M.name)??E:""},N=f.useRef(0);f.useEffect(()=>{const E=++N.current;p(null),y(null),j(!1),x(null),T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(M=>{N.current===E&&(p(M.entries),y(M.next))}).catch(M=>{N.current===E&&x(M instanceof ge?M.message:String(M))})},[c,l,o]);const C=()=>{if(!g||v)return;j(!0);const E=N.current;T.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(M=>{N.current===E&&(p(D=>{const U=new Set((D??[]).map($=>$.id));return[...D??[],...M.entries.filter($=>!U.has($.id))]}),y(M.next))}).catch(M=>{N.current===E&&x(M instanceof ge?M.message:String(M))}).finally(()=>{N.current===E&&j(!1)})},I=(l?1:0)+(o?1:0),A=((L=Jw.find(E=>E.id===l))==null?void 0:L.label)??l,_=n.jsxs(n.Fragment,{children:[m===null?n.jsx(ce,{children:"Loading…"}):m.length===0?n.jsx(ce,{children:"No file matches that."}):n.jsx(yt,{children:m.map(E=>n.jsx(S1,{href:$c(E.id,{q:c,origin:l,family:o}),current:E.id===a,onClick:()=>s($c(E.id,{q:c,origin:l,family:o})),lead:n.jsx("span",{className:"files-row-visual","data-family":E.family,children:E.family==="image"&&!E.deleted?n.jsx("img",{src:xr(E.id),alt:"",loading:"lazy"}):n.jsx(Vx,{family:E.family})}),title:E.filename??"Untitled file",meta:n.jsx("span",{title:Ve(E.createdAt,t),children:ze(E.createdAt)}),sub:`${Ti[E.family]} · ${$n(E.sizeBytes)} · ${PC(E,k)}${ZU(E,k)}`},E.id))}),g?n.jsx("div",{className:"files-more",children:n.jsx(R,{size:"sm",onClick:C,disabled:v,children:v?"Loading…":"Show more"})}):null]}),z=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return n.jsxs("div",{className:"ui-page files","data-selected":a?"true":void 0,children:[n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Files"}),n.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),z?n.jsx(Zt,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):n.jsxs(n.Fragment,{children:[n.jsx(A1,{label:"Files",onSubmit:()=>h({q:u},!0),main:n.jsx("input",{type:"search",value:u,placeholder:"Search by filename","aria-label":"Search files by name",onChange:E=>d(E.target.value)}),filters:n.jsxs(bs,{dense:!0,children:[n.jsx(Z,{label:"Origin",children:n.jsx("select",{value:l,"aria-label":"Origin",onChange:E=>h({origin:E.target.value}),children:Jw.map(E=>n.jsx("option",{value:E.id,children:E.label},E.id))})}),n.jsx(Z,{label:"Kind",children:n.jsx("select",{value:o,"aria-label":"Kind",onChange:E=>h({family:E.target.value}),children:JU.map(E=>n.jsx("option",{value:E,children:E===""?"Any kind":Ti[E]},E))})})]}),filtersOpen:w,onToggleFilters:()=>S(E=>!E),active:I,chips:I>0?n.jsxs(n.Fragment,{children:[l?n.jsx(Zu,{label:"Origin",onRemove:()=>h({origin:""}),children:A}):null,o?n.jsx(Zu,{label:"Kind",onRemove:()=>h({family:""}),children:Ti[o]}):null]}):void 0}),n.jsx(re,{message:b}),n.jsx(N1,{className:"files-split",label:"Files",list:_,detail:a?n.jsx(e6,{id:a,timezone:t,agents:r,navigate:s,onBack:()=>s($c(null,{q:c,origin:l,family:o}))},a):void 0,empty:"Choose a file to see it here."})]})]})}function ZU(e,t){var i,a;const s=(i=e.context)!=null&&i.groupName?`in ${e.context.groupName}`:(a=e.context)!=null&&a.agentId&&e.context.agentId!==e.agentId?`with ${t(e.context.agentId)}`:"",r=e.contexts>1?`${e.contexts} conversations`:"";return[s,r].filter(Boolean).map(l=>` · ${l}`).join("")}function PC(e,t){return e.origin==="uploaded"?"You sent it":e.origin==="produced"?`Made by ${t(e.agentId)||"an agent"}`:e.agentId?`Saved by ${t(e.agentId)}`:"Origin unknown"}function e6({id:e,timezone:t,agents:s,navigate:r,onBack:i}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,d]=f.useState(null);f.useEffect(()=>{let v=!1;return l(null),d(null),T.libraryEntry(e).then(j=>{v||l(j)}).catch(j=>{v||d(j instanceof ge&&j.status===404?"This file is no longer in the library.":j instanceof ge?j.message:String(j))}),()=>{v=!0}},[e]);const h=v=>{var j;return v?((j=s.find(w=>w.id===v))==null?void 0:j.name)??v:""};if(u)return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(R,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsx(W,{tone:"critical",children:u})]});if(!a)return n.jsx("div",{className:"files-detail-body",children:n.jsx(ce,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:y}=a,b=m.filename??"Untitled file",x=()=>{c(!0),T.libraryEntry(e,p.length).then(v=>l(j=>j&&{...j,contexts:[...j.contexts,...v.contexts],contextsTotal:v.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return n.jsxs("div",{className:"files-detail-body",children:[n.jsx(R,{size:"sm",onClick:i,className:"files-back",children:"Back to Files"}),n.jsxs("header",{className:"files-detail-head",children:[n.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:n.jsx(Vx,{family:m.family})}),n.jsxs("div",{className:"files-detail-text",children:[n.jsx("h3",{className:"files-detail-name",children:b}),n.jsxs("p",{className:"files-detail-meta",children:[Ti[m.family]," · ",$n(m.sizeBytes)," · ",Ve(m.createdAt,t)]})]}),y?n.jsx("a",{className:"ui-btn","data-variant":"accent",href:ri(m.id),download:b,children:"Download"}):null]}),y?null:n.jsx(W,{tone:"warning",children:"The file's bytes are no longer on this machine. What is known about it stays here; the download will not work."}),n.jsx(Y1,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:y}),n.jsx(Gt,{items:[{label:"Origin",value:PC(m,h)},...m.agentId&&m.origin==="produced"?[{label:"Made by",value:n.jsxs("span",{className:"files-agent",children:[n.jsx(Nn,{agents:s,id:m.agentId,size:"sm"}),h(m.agentId)]})}]:[],{label:"Type",value:n.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:n.jsx("span",{className:"mono",children:m.id})}]}),n.jsxs("section",{className:"files-conversations",children:[n.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?n.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):n.jsx("ul",{className:"files-ctx",role:"list",children:p.map(v=>{const j=v.groupId?Yl(v.groupId,v.conversationId):Je(v.conversationAgentId,v.conversationId),w=v.groupId?v.groupName??"a group":h(v.conversationAgentId);return n.jsxs("li",{className:"files-ctx-row",children:[n.jsxs("span",{className:"files-ctx-text",children:[n.jsx("span",{children:v.groupId?`Group: ${w}`:w}),n.jsxs("span",{className:"muted",children:[" · ",v.kind==="produced"?`made by ${h(v.agentId)||"an agent"}`:v.kind==="reused"?"sent again":"sent by you"," · ",ze(v.at)]})]}),n.jsx("a",{className:"ui-btn","data-size":"sm",href:j,onClick:S=>{S.preventDefault(),r(j)},children:"Open conversation"})]},`${v.conversationId}:${v.kind}`)})}),p.length<g?n.jsx(J,{align:"end",children:n.jsx(R,{size:"sm",onClick:x,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const t6={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun",cloud:"cloud"};function $C(e){return e&&t6[e]||"plug"}const MC="buddi.keepClose";let Ga=null;const Ip=new Set;function Pp(){for(const e of Ip)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),Ga=e,Pp()}),window.addEventListener("appinstalled",()=>{Ga=null,hv(),Pp()}));function rh(){const[e,t]=f.useState(Ga);return f.useEffect(()=>{const s=()=>t(Ga);return Ip.add(s),s(),()=>{Ip.delete(s)}},[]),OC()?null:e}async function dv(e){try{await e.prompt();const t=await e.userChoice;Ga===e&&(Ga=null);const s=(t==null?void 0:t.outcome)==="accepted";return s&&hv(),Pp(),s}catch{return!1}}function n6(){try{return window.localStorage.getItem(MC)!==null}catch{return!1}}function hv(){try{window.localStorage.setItem(MC,"dismissed")}catch{}}function OC(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function s6(e=window.location.hostname){const t=e.replace(/^\[|\]$/g,"").toLowerCase();return t==="127.0.0.1"||t==="::1"||t==="localhost"}function DC(e){return/Edg\//.test(e)?"In Edge, choose Apps → Install buddi from the … menu.":/(Chrome|CriOS)\//.test(e)?"In Chrome, click the install icon in the address bar.":/Safari\//.test(e)&&/Mac/.test(e)?"In Safari, choose File → Add to Dock.":null}function r6(e){return/Mac|iPhone|iPad/.test(e)}function i6(){const e=rh(),[t,s]=f.useState(n6);if(t||!e)return null;const r=()=>{hv(),s(!0)};return n.jsxs("div",{className:"home-install",role:"region","aria-label":"Install buddi",children:[n.jsx("p",{className:"home-install-text",children:"Install buddi as an app, one click from your dock."}),n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),n.jsx(R,{size:"sm",variant:"accent",onClick:()=>{dv(e).then(i=>{i&&s(!0)})},children:"Install"})]})]})}function a6(){const e=rh(),[t,s]=f.useState(void 0),[r]=f.useState(OC);if(f.useEffect(()=>{if(r)return;let o=!0;return T.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const i=typeof navigator>"u"?"":navigator.userAgent,a=s6(),l=e?null:DC(i);return n.jsx(te,{title:"The dashboard as an app",panel:!0,foot:e?n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>{dv(e)},children:"Install the app"})}):void 0,children:n.jsxs(Q,{children:[n.jsxs("p",{children:[e?"This browser can install buddi as an app: its own window, the Blob as its icon. ":l?`${l} `:null,"Or bookmark it with ",r6(i)?"⌘D":"Ctrl+D",".",a?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),a&&t==="darwin"?n.jsxs("p",{children:["On this Mac, ",n.jsx("span",{className:"mono",children:"buddi dashboard --install-app"})," puts a double-clickable app in ~/Applications that signs you in each time it opens (docs/cli.md, under Everyday)."]}):null]})})}const _C="a connection needs you";function l6({attention:e,place:t,onNavigate:s,theme:r,onTheme:i,plugins:a=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:d,timezone:h}){return n.jsxs("nav",{className:"rail","aria-label":"Places",children:[n.jsx("a",{className:"rail-mark",href:Vt,onClick:m=>{m.preventDefault(),s(Vt)},"aria-label":"buddi home",children:n.jsx(ed,{})}),uD.filter(m=>m.route!==cn).map(m=>n.jsx(wf,{label:m.label,href:m.route,active:t===m.route,badge:m.route===Vt?e:0,onClick:()=>s(m.route),children:Xw[m.route]},m.route)),a.map(m=>{const p=si(m.plugin,m.id);return n.jsx(wf,{label:m.title,href:p,active:t===p,badge:0,onClick:()=>s(p),children:n.jsx(ye,{name:$C(m.icon)})},p)}),n.jsx("div",{className:"rail-spacer"}),n.jsx(wf,{label:"Settings",href:cn,active:t===cn,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(cn),children:Xw[cn]}),n.jsx(c6,{theme:r,onTheme:i,onNavigate:s,version:c,stale:u,reload:d,timezone:h})]})}const o6=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function c6({theme:e,onTheme:t,onNavigate:s,version:r,stale:i,reload:a=()=>window.location.reload(),timezone:l}){var j,w,S;const o=le(()=>T.owner(),[]),c=le(()=>T.focus(),[],6e4),u=((j=c.data)==null?void 0:j.focus)??null,d=(k,N)=>{T.setFocus(k,N).finally(()=>c.reload())},h=((S=(w=o.data)==null?void 0:w.preferredName)==null?void 0:S.trim())||null,m=(h??"You").slice(0,1).toUpperCase(),[p]=f.useState(CD),[g]=f.useState(h6),y=rh(),b=h?`You: ${h}`:"You",x=u?`${Ll[u.mode]} ${LC(u,l)}`:null,v=[b,x,i?"reload to update":null].filter(Boolean).join(", ");return n.jsx("div",{className:"rail-owner",children:n.jsxs(Gd,{modal:!1,children:[n.jsx(Yd,{asChild:!0,children:n.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":v,children:[n.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:m}),i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,u?n.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:n.jsx(ye,{name:"moon",size:10})}):null]})}),n.jsx(Ho,{children:n.jsxs(qd,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[n.jsxs("div",{className:"rail-owner-head",children:[n.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:m}),n.jsxs("span",{className:"rail-owner-who",children:[n.jsx("span",{className:"rail-owner-name",children:h??"You"}),n.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(d6,{focus:u,timezone:l,onSwitch:d}),n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(Qd,{className:"ui-menu-label",children:"Theme"}),n.jsx("div",{className:"rail-owner-theme",children:n.jsx(ls,{label:"Theme",options:o6,value:e,onChange:t})}),n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(Or,{className:"ui-menu-item",onSelect:()=>s(Be("appearance")),children:"Change appearance"}),y?n.jsx(Or,{className:"ui-menu-item",onSelect:()=>{dv(y)},children:"Install the app"}):null,p||i?n.jsxs(Or,{className:"ui-menu-item rail-owner-reload","data-update":i?"true":void 0,onSelect:()=>a(),children:[n.jsx("span",{children:i?"Reload to update":"Reload"}),g?n.jsx("kbd",{className:"rail-owner-kbd",children:g}):null]}):null,r?n.jsxs(n.Fragment,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsxs(Or,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(Be("system")),children:[n.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?n.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const Ll={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},u6=[{value:"1h",label:"For 1 hour"},{value:"3h",label:"For 3 hours"},{value:"tomorrow",label:"Until tomorrow morning"},{value:"indefinite",label:"Until I turn it off"}];function LC(e,t,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),i=t?{timeZone:t}:{},a=c=>new Intl.DateTimeFormat("en-CA",{...i,dateStyle:"short"}).format(c),l=new Intl.DateTimeFormat("en-GB",{...i,hour:"2-digit",minute:"2-digit"}).format(r);return a(r)===a(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-GB",{...i,weekday:"short"}).format(r)} ${l}`}function d6({focus:e,timezone:t,onSwitch:s}){return n.jsxs(wO,{children:[n.jsxs(bO,{className:"ui-menu-item rail-owner-focus",children:[n.jsx("span",{children:"Focus"}),n.jsx("span",{className:"rail-owner-kbd",children:e?Ll[e.mode]:"Off"})]}),n.jsx(Ho,{children:n.jsxs(kO,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[n.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Ll[e.mode]} ${LC(e,t)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>n.jsxs(VN,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(Qd,{className:"ui-menu-label",children:Ll[r]}),u6.map(i=>n.jsx(Or,{className:"ui-menu-item","aria-label":`${Ll[r]} ${i.label.toLowerCase()}`,onSelect:()=>s(r,i.value),children:i.label},i.value))]},r)),e?n.jsxs(n.Fragment,{children:[n.jsx(Dr,{className:"ui-menu-sep"}),n.jsx(Or,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function h6(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function wf({label:e,href:t,active:s,badge:r,dot:i,onClick:a,children:l}){return n.jsxs("a",{className:"rail-link",href:t,"data-active":s?"true":void 0,"aria-current":s?"page":void 0,"aria-label":r>0?`${e}, ${r} waiting`:i?`${e}, ${i}`:e,onClick:o=>{o.preventDefault(),a()},children:[n.jsxs("span",{className:"rail-icon",children:[l,r>0?n.jsx("span",{className:"rail-badge","aria-hidden":"true",children:r>99?"99+":r}):null,r===0&&i?n.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"rail-dot","aria-hidden":"true"}):null]}),n.jsx("span",{className:"rail-label",children:e})]})}const Xw={[_i]:n.jsx(ye,{name:"files"}),[Vt]:n.jsx(ye,{name:"home"}),[Yr]:n.jsx(ye,{name:"chat"}),[gt]:n.jsx(ye,{name:"agents"}),[dt]:n.jsx(ye,{name:"activity"}),[cn]:n.jsx(ye,{name:"settings"})},$o=e=>`${e.plugin}:${e.id}`,f6=new Set;let fv=f6,Zw=!1;const $p=new Set;function Mp(e){fv=e;for(const t of $p)t()}function m6(e){return $p.add(e),()=>$p.delete(e)}const eb=()=>fv;function p6(){Zw||(Zw=!0,Promise.resolve().then(()=>T.rail()).then(e=>Mp(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(t=>typeof t=="string"):[]))).catch(()=>{}))}async function g6(e,t){const s=fv,r=new Set(s);t?r.add($o(e)):r.delete($o(e)),Mp(r);try{await T.setRailHidden(e.plugin,e.id,t)}catch(i){throw Mp(s),i}}function FC(){return f.useEffect(p6,[]),f.useSyncExternalStore(m6,eb,eb)}function x6(e,t){return e.filter(s=>!t.has($o(s)))}function v6(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function j6(e,t=!0,s){f.useEffect(()=>{if(!t)return;const r=i=>{if(i.key!=="/"||i.defaultPrevented||i.ctrlKey||i.metaKey||i.altKey||v6(i.target))return;i.preventDefault();const a=document.getElementById(kp);if(a instanceof HTMLTextAreaElement){!a.disabled&&!a.hidden&&a.focus();return}s?s():e(Vt)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t,s])}const zC="buddi.theme";function y6(e=UC()){try{const t=e==null?void 0:e.getItem(zC);return t==="light"||t==="dark"||t==="system"?t:"system"}catch{return"system"}}function w6(e,t=UC()){try{t==null||t.setItem(zC,e)}catch{}}function b6(e,t=document.documentElement){t&&(e==="system"?t.removeAttribute("data-theme"):t.setAttribute("data-theme",e))}function UC(){try{return window.localStorage}catch{return}}const BC="buddi.ground",WC="buddi.pageWidth";function k6(e=VC()){const t=i=>{try{return(e==null?void 0:e.getItem(i))??null}catch{return null}},s=t(BC),r=t(WC);return{theme:y6(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function HC(e,t=document.documentElement){t&&(b6(e.theme,t),e.ground==="sand"?t.setAttribute("data-ground","sand"):t.removeAttribute("data-ground"),e.width==="wide"?t.removeAttribute("data-width"):t.setAttribute("data-width",e.width))}function S6(e,t=VC()){w6(e.theme,t);try{t==null||t.setItem(BC,e.ground),t==null||t.setItem(WC,e.width)}catch{}}let $a=null;const Op=new Set;function Dp(){return $a||($a=k6()),$a}function N6(e){return Op.add(e),()=>Op.delete(e)}function C6(e){$a={...Dp(),...e},HC($a),S6($a);for(const t of Op)t()}function KC(){return[f.useSyncExternalStore(N6,Dp,Dp),C6]}function VC(){try{return window.localStorage}catch{return}}function E6({timezone:e,embedded:t}){var m,p;const{data:s,error:r,reload:i}=le(()=>T.sentinels(),[],3e4),a=le(()=>T.missions(),[]),[l,o]=f.useState(null),c=((p=(m=a.data)==null?void 0:m.missions.find(g=>g.id==="sentinel-wake"))==null?void 0:p.agentId)??null,u=async(g,y)=>{o(null);try{await T.snoozeAlert(g,y),i()}catch(b){o(b instanceof Error?b.message:String(b))}},d=((s==null?void 0:s.open)??[]).filter(g=>!g.snoozedAt),h=((s==null?void 0:s.open)??[]).filter(g=>g.snoozedAt);return n.jsxs(yn,{embedded:t,title:"Alerts",lede:"What the watchers found.",children:[n.jsx(re,{message:r??l}),n.jsx(W,{children:"An alert closes on its own once the fact behind it changes: record the payment, update the balance, and the watcher clears it on its next run. Snooze one you have decided to live with; it stays quiet until it resolves."}),n.jsx(bf,{title:"Open",findings:d,timezone:e,askAgentId:c,onSnooze:g=>u(g,!0),empty:"Nothing open. Your watchers are quiet."}),h.length>0?n.jsx(bf,{title:"Snoozed",findings:h,timezone:e,askAgentId:c,onSnooze:g=>u(g,!1),empty:""}):null,n.jsx(bf,{title:"Resolved",findings:(s==null?void 0:s.resolved)??[],timezone:e,empty:"Nothing has resolved yet."}),n.jsx(Ze,{title:"Waiting for the weekly recap",flush:!0,children:!s||s.digest.length===0?n.jsx(Zt,{icon:"bell",title:"Nothing waiting for the recap"}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Title"}),n.jsx("th",{children:"Severity"}),n.jsx("th",{children:"Noted"})]})}),n.jsx("tbody",{children:s.digest.map(g=>n.jsxs("tr",{children:[n.jsxs("td",{children:[Ba(g.title),n.jsx(YC,{text:Ba(g.detail)})]}),n.jsx("td",{children:n.jsx(GC,{severity:g.severity})}),n.jsx("td",{className:"nowrap",children:Ve(g.createdAt,e)})]},g.id))})]})})]})}function GC({severity:e}){return n.jsx(ve,{tone:e==="urgent"?"critical":void 0,children:e})}function YC({text:e}){const[t,s]=f.useState(!1),r=e.length>240||e.split(`
|
|
109
|
+
`).length>3;return n.jsxs("div",{className:"sub alert-detail","data-clamp":r&&!t?"true":void 0,children:[e,r?n.jsx("button",{type:"button",className:"wb-link alert-more",onClick:()=>s(i=>!i),children:t?"Less":"More"}):null]})}function A6(e){return`About this alert: "${Ba(e.title)}". ${Ba(e.detail)}
|
|
110
|
+
|
|
111
|
+
What should I do about it, and what do you need from me to clear it?`}function bf({title:e,findings:t,timezone:s,askAgentId:r,onSnooze:i,empty:a}){const l=e==="Snoozed";return n.jsx(Ze,{title:e,flush:!0,children:t.length===0?n.jsx(ce,{children:a}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Finding"}),n.jsx("th",{children:"Severity"}),n.jsx("th",{children:"Since"}),i?n.jsx("th",{}):null]})}),n.jsx("tbody",{children:t.map(o=>n.jsxs("tr",{children:[n.jsxs("td",{children:[n.jsx("strong",{children:Ba(o.title)}),n.jsx(YC,{text:Ba(o.detail)}),o.data?n.jsx(Ct,{summary:"evidence",children:n.jsx(jt,{children:In(o.data)})}):null]}),n.jsx("td",{children:n.jsx(GC,{severity:o.severity})}),n.jsxs("td",{className:"nowrap",children:[Ve(o.firstSeenAt,s),n.jsxs("div",{className:"sub",title:Ve(o.lastSeenAt,s),children:["last seen ",ze(o.lastSeenAt)]})]}),i?n.jsx("td",{children:n.jsxs(J,{align:"end",children:[r?n.jsx(Ut,{size:"sm",href:Je(r,"new"),onClick:()=>pz(r,A6(o)),children:"Ask about it"}):null,n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(o.key),children:l?"Wake":"Snooze"})]})}):null]},o.key))})]})})}const tb=5e3,nb=50;function T6({timezone:e,embedded:t}){var x;const[s,r]=f.useState(""),[i,a]=f.useState(""),[l,o]=f.useState(null),c=le(()=>T.eventKinds(),[]),{data:u,error:d}=le(()=>T.events({kind:s||void 0,q:i||void 0,limit:nb}),[s,i],tb),[h,m]=f.useState({events:[],cursor:null,busy:!1,error:null});f.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,i]);const p=h.events.length>0?h.cursor:(u==null?void 0:u.nextCursor)??null,g=async()=>{if(p){m(v=>({...v,busy:!0,error:null}));try{const v=await T.events({kind:s||void 0,q:i||void 0,before:p,limit:nb});m(j=>({events:[...j.events,...v.events],cursor:v.nextCursor,busy:!1,error:null}))}catch(v){m(j=>({...j,busy:!1,error:v instanceof Error?v.message:String(v)}))}}},y=new Set(((u==null?void 0:u.events)??[]).map(v=>v.id)),b=[...(u==null?void 0:u.events)??[],...h.events.filter(v=>!y.has(v.id))];return n.jsxs(yn,{embedded:t,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[n.jsxs(J,{children:[n.jsxs("select",{"aria-label":"Event kind",value:s,onChange:v=>r(v.target.value),children:[n.jsx("option",{value:"",children:"every kind"}),(((x=c.data)==null?void 0:x.kinds)??[]).map(v=>n.jsxs("option",{value:v.kind,children:[v.kind," (",v.count,")"]},v.kind))]}),n.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:i,onChange:v=>a(v.target.value),size:28}),s||i?n.jsx(R,{onClick:()=>{r(""),a("")},children:"Clear"}):null,n.jsxs("span",{className:"muted",children:["refreshes every ",tb/1e3,"s"]})]}),n.jsx(re,{message:d}),n.jsx(Ze,{flush:!0,children:!u||b.length===0?n.jsx(ce,{children:"No events match."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"#"}),n.jsx("th",{children:"When"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Payload"})]})}),n.jsx("tbody",{children:b.map(v=>n.jsxs("tr",{"data-clickable":"true",onClick:()=>o(v),children:[n.jsx("td",{className:"mono muted",children:v.id}),n.jsxs("td",{className:"nowrap",children:[Ve(v.createdAt,e),n.jsx("div",{className:"sub",children:ze(v.createdAt)})]}),n.jsx("td",{className:"mono nowrap",children:v.kind}),n.jsx("td",{className:"mono muted",children:Vs(In(v.payload).replace(/\s+/g," "),120)})]},v.id))})]})}),p||h.error?n.jsxs(J,{children:[n.jsxs("span",{className:"muted",children:[b.length," shown",p?", older ones are kept":"","."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),h.error?n.jsx("span",{className:"critical",children:h.error}):null,p?n.jsx(R,{disabled:h.busy,onClick:()=>void g(),children:h.busy?"Loading…":"Load older"}):null]}):null,l?n.jsxs(kt,{title:l.kind,onClose:()=>o(null),children:[n.jsxs("p",{className:"muted",children:["Event ",l.id," · ",Ve(l.createdAt,e),l.conversationId?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),n.jsx(jt,{children:In(l.payload)})]}):null]})}const R6=["pending","leased","suspended","failed","succeeded","cancelled"],Pl=50;function I6({timezone:e,embedded:t,initialState:s}){const[r,i]=f.useState(s??""),[a,l]=f.useState(null),[o,c]=f.useState(null),{data:u,error:d,reload:h}=le(()=>T.jobs({...r?{state:r}:{},limit:String(Pl)}),[r],1e4),[m,p]=f.useState({jobs:[],done:!1,busy:!1});f.useEffect(()=>{p({jobs:[],done:!1,busy:!1})},[r]);const g=async()=>{p(N=>({...N,busy:!0}));try{const N=await T.jobs({...r?{state:r}:{},limit:String(Pl),offset:String(Pl+m.jobs.length)});p(C=>({jobs:[...C.jobs,...N.jobs],done:N.jobs.length<Pl,busy:!1}))}catch(N){c(N instanceof Error?N.message:String(N)),p(C=>({...C,busy:!1}))}},y=new Set(((u==null?void 0:u.jobs)??[]).map(N=>N.id)),b=[...(u==null?void 0:u.jobs)??[],...m.jobs.filter(N=>!y.has(N.id))],x=r?(u==null?void 0:u.counts[r])??0:Object.values((u==null?void 0:u.counts)??{}).reduce((N,C)=>N+C,0),v=!m.done&&b.length<x&&((u==null?void 0:u.jobs.length)??0)>=Pl,[j,w]=f.useState(null),S=async N=>{c(null),w(N);try{const C=(await T.jobs({state:"failed",limit:"500"})).jobs;for(const I of C)await(N==="retry"?T.retryJob(I.id):T.cancelJob(I.id));h()}catch(C){c(C instanceof Error?C.message:String(C))}finally{w(null)}},k=async N=>{c(null);try{await N,l(null),h()}catch(C){c(C instanceof Error?C.message:String(C))}};return n.jsxs(yn,{embedded:t,title:"Jobs",lede:`${u!=null&&u.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:t?void 0:n.jsx(R,{size:"sm",variant:u!=null&&u.paused?"accent":void 0,onClick:()=>k(T.setPaused(!((u==null?void 0:u.paused)??!1))),children:u!=null&&u.paused?"Resume the queue":"Pause the queue"}),children:[n.jsxs(J,{children:[n.jsxs("select",{"aria-label":"Job state",value:r,onChange:N=>i(N.target.value),children:[n.jsx("option",{value:"",children:"every state"}),R6.map(N=>n.jsxs("option",{value:N,children:[N," (",(u==null?void 0:u.counts[N])??0,")"]},N))]}),((u==null?void 0:u.counts.failed)??0)>0?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("span",{className:"muted",children:[u.counts.failed," failed."]}),n.jsx(R,{size:"sm",disabled:j!==null,onClick:()=>void S("retry"),children:j==="retry"?"Retrying…":"Retry all failed"}),n.jsx(R,{size:"sm",variant:"danger",disabled:j!==null,onClick:()=>void S("cancel"),children:j==="cancel"?"Cancelling…":"Cancel all failed"})]}):null]}),n.jsx(re,{message:d??o}),n.jsx(Ze,{flush:!0,children:!u||b.length===0?n.jsx(ce,{children:"No jobs match."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"State"}),n.jsx("th",{className:"num",children:"Attempts"}),n.jsx("th",{children:"Last error"}),n.jsx("th",{children:"Updated"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:b.map(N=>n.jsxs("tr",{children:[n.jsxs("td",{className:"clickable",onClick:()=>l(N),children:[N.kind,n.jsx("div",{className:"sub mono",children:Co(N.id)})]}),n.jsxs("td",{children:[n.jsx(Go,{state:N.state}),N.suspendedReason?n.jsx("div",{className:"sub",children:Vs(N.suspendedReason,40)}):null]}),n.jsxs("td",{className:"num",children:[N.attempts,"/",N.maxAttempts]}),n.jsx("td",{className:N.lastError?"critical":"muted",children:N.lastError?Vs(N.lastError,80):"—"}),n.jsxs("td",{className:"nowrap",children:[Ve(N.updatedAt,e),n.jsx("div",{className:"sub",children:ze(N.updatedAt)})]}),n.jsx("td",{children:n.jsxs(J,{align:"end",children:[["failed","cancelled","suspended"].includes(N.state)?n.jsx(R,{size:"sm",onClick:()=>k(T.retryJob(N.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(N.state)?n.jsx(R,{size:"sm",variant:"danger",onClick:()=>k(T.cancelJob(N.id)),children:"Cancel"}):null]})})]},N.id))})]})}),v?n.jsxs(J,{children:[n.jsxs("span",{className:"muted",children:[b.length," of ",x," shown."]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{disabled:m.busy,onClick:()=>void g(),children:m.busy?"Loading…":"Load older"})]}):null,a?n.jsxs(kt,{title:a.kind,onClose:()=>l(null),children:[n.jsx("p",{className:"muted mono",children:a.id}),n.jsx(te,{title:"Payload",children:n.jsx(jt,{children:In(a.payload)})}),n.jsx(te,{title:"Result",children:n.jsx(jt,{children:In(a.result)})}),a.conversationId?n.jsx("p",{children:n.jsx("a",{href:`#/conversations/${a.conversationId}`,children:"open the transcript"})}):null]}):null]})}const P6=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function $6({hash:e,timezone:t,navigate:s,agents:r}){var u,d;const i=/^#\/activity\/conversations\/(.+)$/.exec(e),a=h=>{var m;return((m=r.find(p=>p.id===h))==null?void 0:m.name)??h};if(i){let h=i[1];try{h=decodeURIComponent(h)}catch{}return n.jsx(D6,{id:h,timezone:t,navigate:s,nameOf:a})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(d=/[?&]state=([a-z]+)/.exec(e))==null?void 0:d[1],c=h=>m=>{m.preventDefault(),s(h)};return n.jsxs("div",{className:"ui-page",children:[n.jsx(th,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:n.jsx(F6,{})}),n.jsx(z6,{}),n.jsx(Yo,{children:P6.map(h=>{const m=h.id==="conversations"?dt:`${dt}/${h.id}`;return n.jsx(Ha,{href:m,active:l===h.id,onClick:c(m),children:h.label},h.id)})}),l==="conversations"?n.jsx(M6,{timezone:t,navigate:s,nameOf:a,agents:r}):null,l==="jobs"?n.jsx(I6,{timezone:t,embedded:!0,initialState:o},o??""):null,l==="approvals"?n.jsx(O6,{timezone:t,nameOf:a}):null,l==="alerts"?n.jsx(E6,{timezone:t,embedded:!0}):null,l==="events"?n.jsx(T6,{timezone:t,embedded:!0}):null]})}function M6({timezone:e,navigate:t,nameOf:s,agents:r}){const{data:i,error:a}=le(()=>T.conversations(),[],3e4);return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:a}),n.jsx(Ze,{flush:!0,children:i?i.conversations.length===0?n.jsx(Zt,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):n.jsx(yt,{children:i.conversations.map(l=>n.jsx(ft,{href:Wa(l.id),onClick:()=>t(Wa(l.id)),lead:n.jsx(Nn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?Vs(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${zO(l.usage)}`,side:n.jsx("span",{title:Ve(l.lastMessageAt??l.createdAt,e),children:ze(l.lastMessageAt??l.createdAt)})},l.id))}):n.jsx(ce,{children:"Loading…"})})]})}function O6({timezone:e,nameOf:t}){const{data:s,error:r}=le(()=>T.approvals(),[],1e4),i=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return n.jsxs(n.Fragment,{children:[n.jsx(re,{message:r}),n.jsx(Ze,{flush:!0,children:s?i.length===0?n.jsx(Zt,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Tool"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Asked by"}),n.jsx("th",{children:"Decided"}),n.jsx("th",{children:"Created"})]})}),n.jsx("tbody",{children:i.map(a=>n.jsxs("tr",{children:[n.jsxs("td",{children:[a.tool,n.jsx("div",{className:"sub mono",children:Co(a.id)})]}),n.jsx("td",{children:n.jsx(Go,{state:a.state})}),n.jsx("td",{children:t(a.agentId)}),n.jsx("td",{className:"nowrap",children:a.decidedAt?n.jsxs(n.Fragment,{children:[Ve(a.decidedAt,e),n.jsxs("div",{className:"sub",children:["via ",a.decidedVia??"—"]})]}):n.jsx("span",{className:"muted",children:"—"})}),n.jsxs("td",{className:"nowrap",children:[Ve(a.createdAt,e),n.jsx("div",{className:"sub",children:ze(a.createdAt)})]})]},a.id))})]}):n.jsx(ce,{children:"Loading…"})})]})}function D6({id:e,timezone:t,navigate:s,nameOf:r}){const[i,a]=f.useState(null),[l,o]=f.useState(null);f.useEffect(()=>{let u=!1;return T.conversation(e).then(d=>{u||a(d)}).catch(d=>{u||o(d instanceof Error?d.message:String(d))}),()=>{u=!0}},[e]);const c=u=>d=>{d.preventDefault(),s(u)};return n.jsxs("div",{className:"ui-page",children:[n.jsx("p",{className:"page-crumbs",children:n.jsx("a",{href:dt,onClick:c(dt),children:"Activity"})}),n.jsxs("header",{className:"ui-page-head",children:[n.jsxs("div",{className:"ui-page-head-row",children:[n.jsxs("h2",{className:"ui-page-title",children:[n.jsx(R,{size:"sm",onClick:()=>s(dt),children:"← Back"}),n.jsx("span",{children:"Transcript"})]}),i?n.jsx("div",{className:"ui-page-actions",children:n.jsx(Ut,{size:"sm",href:Je(i.agentId,e),onClick:c(Je(i.agentId,e)),children:"Open in chat"})}):null]}),n.jsx("p",{className:"ui-page-lede mono",children:e})]}),n.jsx(re,{message:l}),i?n.jsxs(n.Fragment,{children:[n.jsxs(nh,{children:[n.jsx(zs,{label:"Agent",value:r(i.agentId),size:"sm"}),n.jsx(zs,{label:"Runs",value:i.runs.length}),n.jsx(zs,{label:"Tokens",value:`${_t(i.usage.input)} / ${_t(i.usage.output)}`,note:Jm(i.usage)?`input / output, ${Jm(i.usage)}`:"input / output"}),n.jsx(zs,{label:"Started",value:Ve(i.createdAt,t),size:"sm"})]}),i.runs.length>0?n.jsx(Ze,{title:"Runs",flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Started"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{className:"num",children:"Turns"}),n.jsx("th",{children:"Stopped"}),n.jsx("th",{className:"num",children:"Tokens"}),n.jsx("th",{className:"num",children:"Cached"})]})}),n.jsx("tbody",{children:i.runs.map((u,d)=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[Ve(u.startedAt,t)," ",u.resumed?n.jsx(ve,{children:"resumed"}):null]}),n.jsx("td",{className:"nowrap",children:Ve(u.finishedAt,t)}),n.jsx("td",{className:"num",children:u.turns??"—"}),n.jsxs("td",{children:[u.stopped??"—",u.actionId?n.jsxs("div",{className:"sub mono",children:["action ",Co(u.actionId)]}):null]}),n.jsxs("td",{className:"num muted nowrap",children:[_t(u.usage.input)," / ",_t(u.usage.output)]}),n.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?_t((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},d))})]})}):null,n.jsx(te,{title:"Messages",children:n.jsx(Q,{children:i.messages.map(u=>n.jsxs("article",{className:"transcript-msg",children:[n.jsxs("header",{className:"transcript-who",children:[u.speaker===sb?"approved action, result":u.role,", ",Ve(u.createdAt,t)]}),n.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?n.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===sb?u.blocks.map((d,h)=>n.jsx(_6,{block:d},h)):u.blocks.map((d,h)=>n.jsx(L6,{block:d},h))]})]},u.id))})})]}):n.jsx(ce,{children:"Loading…"})]})}const sb="approval:resume";function _6({block:e}){return n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),n.jsx(jt,{children:e.type==="text"?e.text??"":In(e)})]})}function L6({block:e}){return e.type==="text"?n.jsx("div",{className:"transcript-text",children:n.jsx(gr,{text:e.text??""})}):e.type==="thinking"?n.jsxs("details",{className:"transcript-thinking",children:[n.jsx("summary",{children:"Thoughts"}),n.jsx("div",{className:"transcript-thinking-text",children:n.jsx(gr,{text:e.text??""})})]}):e.type==="tool_use"?n.jsxs("div",{className:"transcript-tool",children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["→ ",e.name]}),n.jsx(jt,{children:In(e.input)})]}):e.type==="tool_result"?n.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[n.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),n.jsx(jt,{children:e.content??""})]}):n.jsxs("div",{className:"transcript-tool",children:[n.jsx("div",{className:"transcript-tool-name mono",children:e.type}),n.jsx(jt,{children:In(e.ref)})]})}function F6(){const{data:e,reload:t}=le(()=>T.overview(),[],1e4),[s,r]=f.useState(!1);if(!e)return null;const i=()=>{r(!0),T.setPaused(!e.paused).then(t,t).finally(()=>r(!1))};return n.jsx(R,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:i,children:e.paused?"Resume all":"Pause all"})}function z6(){const{data:e}=le(()=>T.overview(),[],1e4);if(!e)return null;const t=r=>e.jobs[r]??0,s=t("leased");return n.jsxs(nh,{children:[n.jsx(zs,{label:"Jobs done",value:_t(t("succeeded"))}),n.jsx(zs,{label:"Failed",value:_t(t("failed")),...t("failed")>0?{tone:"critical"}:{}}),n.jsx(zs,{label:"Queued",value:_t(t("pending")),note:`${s} running`}),n.jsx(zs,{label:"Approvals",value:_t(e.approvals.pending),note:"waiting for you"})]})}const U6=["replay-all","coalesce","latest-only","skip-after-deadline"];function qC({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=le(()=>T.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(d=>!s||d.agentId===s),[o,c]=f.useState(null),u=async d=>{c(null);try{await d,a()}catch(h){c(h instanceof Error?h.message:String(h))}};return n.jsxs(yn,{embedded:t,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[n.jsx(re,{message:i??o}),!r||l.length===0?n.jsxs(Zt,{icon:"calendar",title:"No missions yet",children:["Run ",n.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):n.jsx(Q,{children:l.map(d=>n.jsx(B6,{mission:d,timezone:e,onRun:u},d.id))})]})}function B6({mission:e,timezone:t,onRun:s}){const[r,i]=f.useState(!1);return n.jsxs(ks,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"mono muted",children:e.id})]}),meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{mono:!0,children:e.agentId}),e.alwaysDeliver?n.jsx(ve,{children:"always delivers"}):null,e.enabled?null:n.jsx(ve,{tone:"warning",children:"disabled"}),e.pausedReason?n.jsx(ve,{tone:"warning",children:e.pausedReason}):null]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",onClick:()=>s(T.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(a=>!a),"aria-expanded":r,children:r?"Less":"More"})]}),children:[n.jsxs("p",{className:"ui-card-meta",children:[e.schedule?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezone," · rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${Ve(e.nextRun,t)} (${ze(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",n.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${ze(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?n.jsxs("div",{className:"ui-card-foot",children:[e.schedule?n.jsxs(J,{children:[n.jsx(Z,{inline:!0,label:"Misfire policy",children:n.jsx("select",{value:e.schedule.misfirePolicy,onChange:a=>s(T.setMisfirePolicy(e.id,a.target.value)),children:U6.map(a=>n.jsx("option",{value:a,children:a},a))})}),n.jsx("span",{className:"muted",children:"What a week asleep does: replay every instant, coalesce into one, keep only the latest, or skip past a deadline."})]}):null,n.jsx(te,{title:"Prompt",children:n.jsx(jt,{children:e.prompt})}),n.jsx(te,{title:"Recent occurrences",children:n.jsx(Ze,{flush:!0,children:e.occurrences.length===0?n.jsx(ce,{children:"Never run."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Scheduled"}),n.jsx("th",{children:"State"}),n.jsx("th",{children:"Finished"}),n.jsx("th",{children:"Detail"})]})}),n.jsx("tbody",{children:e.occurrences.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"nowrap",children:Ve(a.scheduledAt,t)}),n.jsx("td",{children:n.jsx(Go,{state:a.state})}),n.jsx("td",{className:"nowrap",children:Ve(a.finishedAt,t)}),n.jsxs("td",{className:a.error?"critical":"muted",children:[a.error?Vs(a.error,120):null,a.runConversationId?n.jsx("a",{href:`#/conversations/${a.runConversationId}`,children:"transcript"}):null]})]},a.id))})]})})})]}):null]})}function W6(e,t){const s=`${e} offer${e===1?"":"s"}`,r=t?` from ${t}`:"";return`Dismiss ${s}${r}? They stop appearing everywhere. Nothing runs, and you can still see them under "Dismissed and lapsed" for a week.`}function QC({ids:e,agentName:t,onDone:s}){const r=e.length,[i,a]=f.useState(!1),[l,o]=f.useState(!1);return r<=0?null:i?n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:W6(r,t)}),n.jsx(R,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),T.dismissOffers(e).then(()=>{a(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),n.jsx(R,{size:"sm",variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Keep them"})]}):n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Dismiss all"})}function JC({embedded:e,agentId:t,agentName:s}){const{data:r,error:i,reload:a}=le(()=>T.offers(),[],2e4),l=x=>!t||x.agentId===t,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,d]=f.useState(null),[h,m]=f.useState(null),[p,g]=f.useState(null),y=async(x,v)=>{d(null),m(x);try{const j=await T.takeOffer(x);g(j.jobId?`On it — ${v}. Started as job ${j.jobId}.`:`Taken — ${v}. No worker is running here, so nothing has started yet.`),a()}catch(j){d(j instanceof Error?j.message:String(j))}finally{m(null)}},b=async(x,v)=>{d(null),m(x);try{await T.dismissOffer(x),g(`Dismissed — ${v}. It will not come back.`),a()}catch(j){d(j instanceof Error?j.message:String(j))}finally{m(null)}};return n.jsxs(yn,{embedded:e,title:"Offers",lede:"Things an agent already worked out that you might want done. Taking one asks that agent the sentence it wrote. It authorizes nothing, and anything that would leave this machine still comes back to you as an approval.",children:[n.jsx(re,{message:i??u}),p?n.jsx(W,{tone:"good",role:"status",children:p}):null,o.length>0?n.jsxs(J,{children:[n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(QC,{ids:o.map(x=>x.id),agentName:s,onDone:()=>{g(null),a()}})]}):null,!r||o.length===0?n.jsx(Zt,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):n.jsx(Q,{children:o.map(x=>n.jsx(ks,{tone:"accent",title:x.label,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{mono:!0,children:x.agentId}),n.jsxs("span",{className:"muted",children:["expires ",ze(x.expiresAt)]})]}),actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{size:"sm",variant:"ghost",disabled:h===x.id,onClick:()=>void b(x.id,x.label),children:"Not now"}),n.jsx(R,{variant:"accent",size:"sm",disabled:h===x.id,onClick:()=>void y(x.id,x.label),children:"Take"})]}),children:n.jsx("p",{className:"ui-card-meta",children:x.prompt})},x.id))}),c.length>0?n.jsxs(Ct,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[n.jsx(Ze,{flush:!0,children:n.jsx(yt,{children:c.map(x=>n.jsx(ft,{title:x.label,sub:`${x.agentId} — ${r$(x)}`,side:ze(x.dismissedAt??x.lapsedAt??x.createdAt)},x.id))})}),n.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const H6="Add a teammate",K6="Each one keeps its own memory and tools, and can work on a schedule. Add the ones you want; Agent Father can make others.",V6="front-desk";function XC(e,t){return e.length>0&&e.every(s=>s.id===t||s.roles.includes(V6)||s.roles.includes(Zd))}const G6={plugins:{label:"Plugins",route:Be("plugins")},mailbox:{label:"Add a mailbox",route:ll("email","settings")},accounts:{label:"Accounts",route:Be("accounts")}},Y6="Your starter team is complete. Agent Father can make others.";function _p({navigate:e,standing:t=!1}){var d;const s=le(()=>T.teammates(),[]),[r,i]=f.useState(new Set),a=(((d=s.data)==null?void 0:d.teammates)??[]).filter(h=>!r.has(`${h.plugin}/${h.agent}`));if(a.length===0)return null;const l=h=>{i(m=>new Set(m).add(`${h.plugin}/${h.agent}`)),T.dismissAgentOffer(h.plugin,h.agent).then(s.reload,s.reload)},o=h=>m=>{m.preventDefault(),e(h)},c=t?a.filter(h=>h.state!=="added"):a,u=t?a.filter(h=>h.state==="added"):[];return n.jsx(te,{title:H6,children:c.length===0?n.jsx("p",{className:"teammates-lede","data-testid":"teammates-complete",children:Y6}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"teammates-lede",children:K6}),n.jsx("div",{className:"teammates-grid","data-testid":"teammates",children:c.map(h=>n.jsx(q6,{row:h,navigate:e,onDismiss:()=>l(h)},`${h.plugin}/${h.agent}`))}),u.length>0?n.jsx("ul",{className:"teammates-added","data-testid":"teammates-added",children:u.map(h=>n.jsx("li",{children:n.jsxs("a",{className:"teammates-added-chip",href:xt(h.agent),onClick:o(xt(h.agent)),children:["Added · open @",h.handle]})},`${h.plugin}/${h.agent}`))}):null]})})}function q6({row:e,navigate:t,onDismiss:s}){const r=Zx(e.plugin,e.agent),i=c=>u=>{u.preventDefault(),t(c)},a=r.created??(e.state==="added"?{id:e.agent,handle:e.handle,name:e.name}:null),l=a?"added":e.state,o=e.fix?G6[e.fix]:null;return n.jsx("div",{className:"teammate","data-state":l,"data-testid":`teammate-${e.agent}`,children:n.jsxs(ks,{title:e.name,actions:n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Dismiss ${e.name}`,title:"Not now",onClick:s,children:n.jsx(ye,{name:"close"})}),foot:n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[l==="unavailable"?n.jsx("span",{className:"teammate-reason",children:e.reason}):null,n.jsx(Xt,{}),a?n.jsxs("a",{href:xt(a.id),onClick:i(xt(a.id)),children:["Added, open @",a.handle]}):l==="unavailable"?o?n.jsx("a",{href:o.route,onClick:i(o.route),children:o.label}):null:n.jsx(R,{variant:"accent",size:"sm",disabled:r.busy,onClick:r.accept,"aria-label":`Add ${e.name}`,children:"Add"})]}),n.jsx(re,{message:r.failure})]}),children:[n.jsx("p",{className:"ui-card-meta",children:e.text}),n.jsx("p",{className:"teammate-needs",children:e.needs})]})})}const Q6=["fact","observation","todo"];function ZC({embedded:e,agents:t,timezone:s,agentId:r}){const{data:i,error:a,reload:l}=le(()=>T.memory(r),[r],3e4),[o,c]=f.useState(null),[u,d]=f.useState(null),[h,m]=f.useState(null),p=w=>{var S;return w==="shared"?"Everyone":((S=t.find(k=>k.id===w))==null?void 0:S.name)??w},g=async w=>{m(null);try{await w,l()}catch(S){m(S instanceof ge?S.message:String(S))}},y={nameOf:p,timezone:s,onChangePreference:w=>c({key:w.key,scope:w.scope}),onForgetPreference:w=>void g(T.forgetPreference({key:w.key,scope:w.scope})),onEditNote:w=>d(w),onForgetNote:w=>void g(T.forgetNote(w.id))},b=r?p(r):"",x=r&&i?{preferences:i.preferences.filter(w=>w.scope===r),notes:i.notes.filter(w=>w.scope===r)}:null,v=r&&i?{preferences:i.preferences.filter(w=>w.scope==="shared"),notes:i.notes.filter(w=>w.scope==="shared")}:null,j=n.jsx(R,{variant:"accent",size:"sm",onClick:()=>c({key:"",scope:r??"shared"}),children:"Add a preference"});return n.jsxs(yn,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[n.jsx(re,{message:a??h}),x&&v?n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Preferences",aside:`what you told ${b} alone`,actions:j,panel:!0,flush:!0,children:n.jsx(kf,{preferences:x.preferences,empty:`Nothing stated to ${b} alone yet.`,...y})}),n.jsx(te,{title:"Notes",aside:`what ${b} wrote down for itself`,panel:!0,flush:!0,children:n.jsx(Sf,{notes:x.notes,empty:`${b} has kept no private notes yet.`,...y})}),n.jsx(Ct,{summary:`Shared with every agent, which ${b} also reads · ${v.preferences.length} preferences, ${v.notes.length} notes`,children:n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Shared preferences",panel:!0,flush:!0,children:n.jsx(kf,{preferences:v.preferences,empty:"No shared preferences.",...y})}),n.jsx(te,{title:"Shared notes",panel:!0,flush:!0,children:n.jsx(Sf,{notes:v.notes,empty:"No shared notes.",...y})})]})})]}):n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Preferences",aside:"what you said you want, one current value each",actions:j,panel:!0,flush:!0,children:i?n.jsx(kf,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...y}):n.jsx(ce,{children:"Loading…"})}),n.jsx(te,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?n.jsx(Sf,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...y}):n.jsx(ce,{children:"Loading…"})})]}),o?n.jsx(J6,{agents:t,existing:(i==null?void 0:i.preferences)??[],initial:o,onClose:()=>c(null),onSave:async w=>{await g((async()=>{await T.setPreference(w),o.key===w.key&&o.scope!==w.scope&&await T.forgetPreference({key:o.key,scope:o.scope})})()),c(null)}}):null,u?n.jsx(X6,{note:u,agents:t,onClose:()=>d(null),onSave:w=>g(T.updateNote(u.id,w)).then(()=>d(null))}):null]})}function kf({preferences:e,empty:t,nameOf:s,onChangePreference:r,onForgetPreference:i}){return e.length===0?n.jsx(ce,{children:t}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Preference"}),n.jsx("th",{children:"Value"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{className:"num",children:"Since"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(a=>n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:a.key}),n.jsx("td",{children:a.value}),n.jsx("td",{children:n.jsx(eE,{scope:a.scope,name:s(a.scope)})}),n.jsxs("td",{className:"num muted",title:a.updatedAt??"",children:[a.updatedAt?ze(a.updatedAt,Date.now()):"",a.revision>1?` · rev ${a.revision}`:""]}),n.jsx("td",{className:"num",children:n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",onClick:()=>r(a),title:"Store a new value for this key",children:"Change"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>i(a),children:"Forget"})]})})]},`${a.scope}:${a.key}`))})]})}function Sf({notes:e,empty:t,nameOf:s,timezone:r,onEditNote:i,onForgetNote:a}){return e.length===0?n.jsx(ce,{children:t}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Note"}),n.jsx("th",{children:"Kind"}),n.jsx("th",{children:"Who sees it"}),n.jsx("th",{children:"Written by"}),n.jsx("th",{className:"num",children:"When"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:e.map(l=>n.jsxs("tr",{children:[n.jsx("td",{className:"memory-note",children:l.content}),n.jsx("td",{children:n.jsx(ve,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),n.jsx("td",{children:n.jsx(eE,{scope:l.scope,name:s(l.scope)})}),n.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),n.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?ze(l.createdAt,Date.now()):"",l.expiresAt?n.jsxs("span",{className:"memory-expires",children:[" · until ",new Date(l.expiresAt).toLocaleDateString(void 0,{timeZone:r})]}):null]}),n.jsx("td",{className:"num",children:n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",onClick:()=>i(l),children:"Edit"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>a(l),children:"Forget"})]})})]},l.id))})]})}function eE({scope:e,name:t}){return n.jsx(ve,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${t} reads this`,children:t})}function tE({value:e,agents:t,onChange:s}){return n.jsxs("select",{value:e,onChange:r=>s(r.target.value),children:[n.jsx("option",{value:"shared",children:"Everyone"}),t.map(r=>n.jsxs("option",{value:r.id,children:["Only ",r.name]},r.id))]})}function J6({agents:e,existing:t,initial:s,onClose:r,onSave:i}){const a=t.find(v=>v.key===s.key&&v.scope===s.scope),[l,o]=f.useState(s.key),[c,u]=f.useState((a==null?void 0:a.value)??""),[d,h]=f.useState(s.scope),[m,p]=f.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),y=t.find(v=>v.key===g&&v.scope===d),b=!a||g!==a.key||c.trim()!==a.value||d!==a.scope,x=g!==""&&c.trim()!==""&&b;return n.jsx(kt,{title:"A preference",onClose:r,children:n.jsxs(Q,{children:[n.jsx(W,{children:'A preference is a standing choice, in your words: "paid biweekly on Thursdays", "answers short, numbers first". Storing the same key again records a correction and keeps the old value in the history.'}),n.jsx(Z,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:n.jsx("input",{value:l,autoFocus:s.key==="",onChange:v=>o(v.target.value),placeholder:"reporting_currency"})}),n.jsx(Z,{label:"Value",children:n.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:v=>u(v.target.value),placeholder:"EUR"})}),n.jsx(Z,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:n.jsx(tE,{value:d,agents:e,onChange:h})}),y&&y!==a?n.jsxs(W,{tone:"warning",children:['This replaces the value already stored for this key here, "',y.value,'" (revision ',y.revision,")."]}):null,a&&d!==a.scope?n.jsxs(W,{children:["It moves: the copy for ",a.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:r,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!x||m,onClick:()=>{p(!0),i({key:g,value:c.trim(),scope:d}).finally(()=>p(!1))},children:a?"Save change":"Save"})]})]})})}function X6({note:e,agents:t,onClose:s,onSave:r}){var p;const[i,a]=f.useState(e.content),[l,o]=f.useState(e.scope),[c,u]=f.useState(e.kind),[d,h]=f.useState(!1),m=i.trim()!==e.content||l!==e.scope||c!==e.kind;return n.jsx(kt,{title:"A note",onClose:s,children:n.jsxs(Q,{children:[n.jsx(Z,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:n.jsx("textarea",{rows:4,value:i,maxLength:2e3,autoFocus:!0,onChange:g=>a(g.target.value)})}),n.jsxs(bs,{children:[n.jsx(Z,{label:"Kind",children:n.jsx("select",{value:c,onChange:g=>u(g.target.value),children:Q6.map(g=>n.jsx("option",{value:g,children:g},g))})}),n.jsx(Z,{label:"Who sees it",children:n.jsx(tE,{value:l,agents:t,onChange:o})})]}),e.createdByAgent?n.jsxs("p",{className:"muted",children:["Written by ",((p=t.find(g=>g.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${ze(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!m||i.trim()===""||d,onClick:()=>{h(!0);const g={};i.trim()!==e.content&&(g.content=i.trim()),l!==e.scope&&(g.scope=l),c!==e.kind&&(g.kind=c),r(g).finally(()=>h(!1))},children:"Save"})]})]})})}function Z6({agentId:e,agentName:t}){const{data:s,error:r,reload:i}=le(()=>T.agentSkills(e),[e],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,d]=f.useState(null),h=async g=>{l(null),c(null),d(g.name);try{const y=await T.removeSkill(e,g.name);c(`Removed ${y.name}. Its versions are kept, and ${t} will not propose it again for 90 days.`),i()}catch(y){l(y instanceof ge?y.message:String(y))}finally{d(null)}};if(!s)return r?n.jsx(re,{message:r}):n.jsx(ce,{children:"Loading…"});const m=s.skills.filter(g=>g.learned!==null),p=s.skills.filter(g=>g.learned===null);return n.jsxs(Q,{divided:!0,children:[n.jsx(re,{message:r??a}),o?n.jsx(W,{tone:"good",role:"status",children:o}):null,n.jsx(te,{title:"Learned",aside:n.jsxs("span",{className:"muted",children:["what ",t," proposed and you kept"]}),children:m.length===0?n.jsx(Zt,{icon:"bulb",title:"Nothing learned yet",children:s.writable?`When ${t} proposes a procedure and you keep it on Settings → Proposals, it appears here.`:`${t} ships with buddi, so it keeps no learned skills of its own until it is yours.`}):n.jsx(Ze,{flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Skill"}),n.jsx("th",{children:"Version"}),n.jsx("th",{children:"Came from"}),n.jsx("th",{className:"num",children:"Kept"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:m.map(g=>n.jsx(tB,{skill:g,busy:u===g.name,onRemove:()=>void h(g)},g.name))})]})})}),n.jsx(te,{title:"From files and plugins",aside:n.jsx("span",{className:"muted",children:"read-only here"}),children:p.length===0?n.jsx(ce,{children:"No other skills."}):n.jsx(Ze,{flush:!0,children:n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Skill"}),n.jsx("th",{children:"What it is for"}),n.jsx("th",{children:"Whose"})]})}),n.jsx("tbody",{children:p.map(g=>n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(Ct,{summary:n.jsx("span",{className:"mono",children:g.name}),children:[n.jsx(jt,{children:g.body}),n.jsx("p",{className:"muted mono skill-file",children:g.file})]})}),n.jsx("td",{children:g.description}),n.jsx("td",{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(ve,{children:g.scope==="shared"?"shared":`${t} only`}),n.jsx("span",{className:"muted",children:eB(g)})]})})]},`${g.scope}:${g.name}`))})]})})})]})}function eB(e){return e.provenance==="imported"?e.source?`from ${e.source}`:"imported":e.provenance==="agent"?"written by an agent":"yours"}function tB({skill:e,busy:t,onRemove:s}){const r=e.learned;return n.jsxs("tr",{children:[n.jsx("td",{children:n.jsxs(Ct,{summary:n.jsxs("span",{children:[r.title," ",n.jsx("span",{className:"muted mono",children:e.name})]}),children:[n.jsxs("p",{className:"muted",children:["When: ",e.description]}),n.jsx(jt,{children:e.body}),n.jsxs("p",{className:"muted mono skill-file",children:[e.file,r.versions.length>1?` · earlier versions in ${r.versionsDir}`:""]})]})}),n.jsx("td",{children:n.jsxs(Q,{gap:"sm",children:[n.jsxs("span",{children:["v",r.version,r.edited?" · your correction":""]}),r.untrusted?n.jsx(ve,{tone:"warning",children:"untrusted text in view"}):null]})}),n.jsx("td",{children:n.jsxs(Q,{gap:"sm",children:[r.conversation?n.jsx("a",{href:Wa(r.conversation),children:r.turn?`conversation, turn ${r.turn}`:"conversation"}):n.jsx("span",{className:"muted",children:"no conversation"}),n.jsx("a",{href:Be("proposals"),children:"the proposal"}),r.sources.length>0?n.jsx("ul",{className:"proposal-sources",children:r.sources.map(i=>n.jsx("li",{className:"mono",children:i},i))}):null]})}),n.jsx("td",{className:"num muted",title:r.keptAt,children:r.keptAt?ze(r.keptAt,Date.now()):""}),n.jsx("td",{className:"num",children:n.jsx(J,{align:"end",children:n.jsx(R,{size:"sm",variant:"ghost",disabled:t,onClick:s,children:"Remove"})})})]})}function nE({timezone:e,embedded:t,agentId:s}){const{data:r,error:i,reload:a}=le(()=>T.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(d=>!s||d.agentId===s),[o,c]=f.useState(null),u=async d=>{c(null);try{await T.cancelReminder(d),a()}catch(h){c(h instanceof Error?h.message:String(h))}};return n.jsxs(yn,{embedded:t,title:"Reminders",lede:"A reminder wakes an agent with a note and the instruction to check before it speaks, never a message queued for delivery.",children:[n.jsx(re,{message:i??o}),n.jsx(Ze,{flush:!0,children:r?l.length===0?n.jsx(Zt,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Due"}),n.jsx("th",{children:"Agent"}),n.jsx("th",{children:"Note"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:l.map(d=>n.jsxs("tr",{children:[n.jsxs("td",{className:"nowrap",children:[Ve(d.dueAt,e),n.jsx("div",{className:"sub",children:ze(d.dueAt)})]}),n.jsx("td",{className:"mono",children:d.agentId}),n.jsxs("td",{children:[d.text,d.context?n.jsx(Ct,{summary:"context",children:n.jsx(jt,{children:In(d.context)})}):null]}),n.jsxs("td",{children:[n.jsx(Go,{state:d.state}),d.cancelReason?n.jsx("div",{className:"sub",children:d.cancelReason}):null]}),n.jsx("td",{children:d.state==="pending"?n.jsx(R,{size:"sm",variant:"danger",onClick:()=>u(d.id),children:"Cancel"}):null})]},d.id))})]}):n.jsx(ce,{children:"Loading…"})})]})}const nB=/(flux|klein|schnell|qwen[-_]?image|image)/i;function sE(e){return e.kind==="image"||e.kind===void 0&&nB.test(e.id)}function sB(e){const t=((e==null?void 0:e.models)??[]).filter(s=>!sE(s));return[...t.filter(s=>s.loaded),...t.filter(s=>!s.loaded)].map(s=>s.id)}function Lp(e){return sB(e)[0]}function mv(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function rB(e){return(e??0)<40960?"mlxh’s max_prompt_tokens; raise it with `mlxh config max_prompt_tokens 40960` for long conversations":"mlxh’s max_prompt_tokens"}function rE(e){let t=e;try{t=new URL(e).host}catch{}return`mlxh is not answering on ${t}. Start it with \`mlxh serve\`, or \`mlxh service install\` to keep it running.`}const iE="an image model; pick it in the Image plugin, not here";function pv({accountId:e,label:t,value:s,onChange:r,disabled:i=!1}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,d]=f.useState(""),[h,m]=f.useState(!1),p=f.useRef(0),g=async v=>{if(!e)return;const j=++p.current;c(!0),d("");try{const w=await T.accountModels(e,v);j===p.current&&l(w)}catch(w){j===p.current&&d(w instanceof Error?w.message:"Could not load models. Custom entry is still available.")}finally{j===p.current&&c(!1)}};if(f.useEffect(()=>(l(null),m(!1),d(""),g(!1),()=>{p.current++}),[e]),!e)return n.jsxs(n.Fragment,{children:[n.jsx(Z,{label:t,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),n.jsx("p",{className:"ui-toolbar-note",children:"Save and connect the account to load its model list. You can enter a model manually now."})]});const y=(a==null?void 0:a.models)??[],b=!!s&&!y.some(v=>v.id===s),x=[a&&!y.length?"This account returned no models. You can enter a custom model.":null,a!=null&&a.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,a?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return n.jsxs(n.Fragment,{children:[n.jsx(Z,{label:t,children:n.jsxs("select",{value:h?"__buddi_custom__":s,disabled:i,onChange:v=>{v.target.value==="__buddi_custom__"?m(!0):(m(!1),r(v.target.value))},children:[n.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),b&&n.jsxs("option",{value:s,children:[s," (current",a?", not listed":"",")"]}),y.map(v=>n.jsxs("option",{value:v.id,children:[v.name===v.id?v.id:`${v.name} — ${v.id}`,v.isDefault?" (provider default)":"",v.image?` — ${iE}`:""]},v.id)),n.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),n.jsx(R,{disabled:i||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),h&&n.jsx(Z,{label:`Custom ${t.toLowerCase()}`,children:n.jsx("input",{required:!0,maxLength:150,value:s,disabled:i,onChange:v=>r(v.target.value)})}),u&&n.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),x.length>0&&n.jsx("p",{className:"ui-toolbar-note",children:x.join(" ")})]})}function iB(e,t){const s=new Set(t),r=[],i=new Set;for(const a of e){for(const o of a.tools)i.add(o.name);const l=a.tools.filter(o=>s.has(o.name));l.length!==0&&(a.glob&&l.length===a.tools.length?r.push(a.glob):r.push(...l.map(o=>o.name)))}return r.push(...t.filter(a=>!i.has(a))),r}function aB(e,t){return[...e].sort().join(",")===[...t].sort().join(",")}const lB="This agent will not remember anything between conversations.";function oB({view:e,chosen:t,onChange:s,disabled:r}){var S;const[i,a]=f.useState(""),[l,o]=f.useState(null),[c,u]=f.useState(()=>new Set),d=k=>u(N=>{const C=new Set(N);return C.has(k)?C.delete(k):C.add(k),C}),h=k=>{a(k),u(new Set)},m=f.useId(),p=new Set(t),g=new Set(e.groups.flatMap(k=>k.tools.filter(N=>N.core).map(N=>N.name))),y=(k,N)=>{const C=N.filter(I=>p.has(I));if(C.length!==0){if(C.some(I=>g.has(I))){o({plugin:k,names:C});return}s(t.filter(I=>!C.includes(I)))}},b=k=>{s([...t,...k.filter(N=>!p.has(N))])},x=i.trim().toLowerCase(),v=(k,N)=>x===""||k.toLowerCase().includes(x)||N.toLowerCase().includes(x),j=e.groups.map(k=>({group:k,tools:k.tools.filter(N=>v(N.name,N.description))})).filter(k=>k.tools.length>0),w=(((S=e.suggested)==null?void 0:S.tools)??[]).filter(k=>!p.has(k.name));return n.jsxs("div",{className:"tool-picker",children:[e.suggested&&w.length>0?n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[n.jsx("div",{className:"tool-picker-head",children:n.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),n.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:w.map(k=>n.jsxs("li",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsx("span",{className:"ui-list-title mono",children:k.name}),n.jsx("span",{className:"ui-list-sub",children:k.description})]}),n.jsx(R,{size:"sm",disabled:r,"aria-label":`Add ${k.name}`,onClick:()=>b([k.name]),children:"Add"})]},k.name))})]}):null,n.jsxs("label",{className:"tool-picker-search",children:[n.jsx("span",{className:"ui-field-label",children:"Find a tool"}),n.jsx("input",{type:"search",value:i,placeholder:"Name or what it does",onChange:k=>h(k.target.value)})]}),j.length===0?n.jsxs(ce,{children:["No installed tool matches “",i.trim(),"”."]}):null,j.map(({group:k,tools:N})=>{const C=k.tools.filter(E=>E.grantable).map(E=>E.name),I=k.tools.filter(E=>p.has(E.name)).length,A=!!k.glob&&I===k.tools.length,_=`${m}-${k.plugin}`,z=`${m}-${k.plugin}-list`,L=x!==""?!c.has(k.plugin):c.has(k.plugin);return n.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":_,"data-open":L?"true":void 0,children:[n.jsxs("div",{className:"tool-picker-head",children:[n.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":L,"aria-controls":z,onClick:()=>d(k.plugin),children:[n.jsx(cB,{}),n.jsx("span",{id:_,className:"tool-picker-plugin",children:k.plugin}),n.jsx("span",{className:"muted",children:A?`all ${k.tools.length}`:`${I} of ${k.tools.length} granted`})]}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`All ${k.plugin} tools`,disabled:r||C.every(E=>p.has(E)),onClick:()=>b(C),children:"all"}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`No ${k.plugin} tools`,disabled:r||!C.some(E=>p.has(E)),onClick:()=>y(k.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===k.plugin?n.jsx(W,{tone:"warning",role:"alert",children:n.jsxs("div",{className:"tool-picker-confirm",children:[n.jsx("span",{children:lB}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{size:"sm",onClick:()=>o(null),children:"Keep"}),n.jsx(R,{size:"sm",variant:"danger",onClick:()=>{s(t.filter(E=>!l.names.includes(E))),o(null)},children:"Remove"})]})}):null,n.jsx("ul",{id:z,className:"ui-list tool-picker-list",hidden:!L,children:N.map(E=>{const M=`${m}-${E.name}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:M,checked:p.has(E.name),disabled:r||!E.grantable,onChange:D=>D.target.checked?b([E.name]):y(k.plugin,[E.name])}),n.jsxs("label",{htmlFor:M,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[n.jsx("span",{className:"mono",children:E.name}),E.core?n.jsx(ve,{tone:"accent",children:"core"}):null,E.gated?n.jsx(ve,{tone:"warning",children:"asks you"}):null]}),n.jsx("span",{className:"ui-list-sub",children:E.grantable?E.description:`${E.description} Granted only by editing the file by hand.`})]})]},E.name)})})]},k.plugin)})]})}function cB(){return n.jsx("svg",{className:"tool-picker-chevron",viewBox:"0 0 11 11","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})})}const es={json:"That is not JSON. Paste the whole block, braces included.",empty:"There is no server in it.",command:'It starts a program on this computer rather than naming an address. Use "A program on this computer" instead.',sse:"buddi speaks Streamable HTTP; this server is SSE-only.",url:"It has no url. buddi connects to a server by its https:// address."},_r=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function aE(e){let t;try{t=JSON.parse(e.trim())}catch{throw new Error(es.json)}if(!_r(t))throw new Error(es.json);let s,r=t;if("mcpServers"in t){const u=t.mcpServers;if(!_r(u))throw new Error(es.empty);const d=Object.keys(u);if(d.length===0)throw new Error(es.empty);if(d.length>1)throw new Error(`It names ${d.length} servers (${d.join(", ")}). Paste one at a time.`);s=d[0];const h=u[s];if(!_r(h))throw new Error(es.url);r=h}if("command"in r)throw new Error(es.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(es.sse);const i=typeof r.url=="string"?r.url.trim():"";if(i==="")throw new Error(es.url);const a=_r(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=a.find(([u])=>u.toLowerCase()==="authorization")??a[0];let o,c=!1;if(l){const[u,d]=l,h=/^(Bearer|Basic)\s+/i.exec(d.trim()),m=h?`${h[1].charAt(0).toUpperCase()}${h[1].slice(1).toLowerCase()} `:"";let p=h?d.trim().slice(h[0].length).trim():d.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:i,...s?{name:s}:{},...o?{header:o}:{},dropped:a.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const Jl={command:"It names no command to run.",claude:"That claude mcp add line names no server and no command. It looks like: claude mcp add <name> -- <command> <args…>",quote:"A quote in that line is never closed.",env:"An environment variable is written NAME=value."};function lE(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const oE=/^[A-Za-z_][A-Za-z0-9_]*$/;function uB(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function cE(e,t){const s=uB(t);return{name:e,value:s?"":t,secret:lE(e),placeholder:s}}function uE(e){const t=[];let s="",r=!1,i=null;for(let a=0;a<e.length;a+=1){const l=e[a];if(i==="'"){l==="'"?i=null:s+=l;continue}if(i==='"'){if(l==='"')i=null;else if(l==="\\"&&a+1<e.length&&'"\\$`\n'.includes(e[a+1])){const o=e[++a];o!==`
|
|
112
|
+
`&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[a+1];if(o===void 0)continue;if(a+=1,o===`
|
|
113
|
+
`||o==="\r"&&e[a+1]===`
|
|
114
|
+
`){o==="\r"&&(a+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){i=l,r=!0;continue}if(/\s/.test(l)){r&&(t.push(s),s="",r=!1);continue}s+=l,r=!0}if(i)throw new Error(Jl.quote);return r&&t.push(s),t}function dB(e){const t=uE(e.trim());let s=0;t[s]==="claude"&&(s+=1),t[s]==="mcp"&&(s+=1),t[s]==="add"&&(s+=1);const r=[],i=[];let a="stdio",l,o;const c=d=>{const h=d.indexOf("="),m=h>0?d.slice(0,h).trim():"";if(!oE.test(m))throw new Error(Jl.env);r.push(cE(m,d.slice(h+1)))},u=[];for(;s<t.length;s+=1){const d=t[s];if(d==="--"){o=t.slice(s+1);break}const[h,m]=d.startsWith("--")&&d.includes("=")?[d.slice(0,d.indexOf("=")),d.slice(d.indexOf("=")+1)]:[d,void 0];if(h==="-e"||h==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s+1]);)c(t[++s]),p=!0;if(!p)throw new Error(Jl.env);continue}if(h==="-s"||h==="--scope"){m===void 0&&(s+=1);continue}if(h==="-t"||h==="--transport"){a=(m??t[++s]??"stdio").toLowerCase();continue}if(h==="-H"||h==="--header"){const p=m??t[++s];p&&i.push(p);continue}if(!(h.startsWith("-")&&l===void 0)){if(l===void 0){l=d;continue}u.push(d)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),a==="http"||a==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const d=o[0];if(!d)throw new Error(es.url);const h={};for(const m of i){const p=m.indexOf(":");p>0&&(h[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:aE(JSON.stringify({mcpServers:{[l??"server"]:{type:a,url:d,headers:h}}}))}}if(!l||o.length===0)throw new Error(Jl.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function hB(e){const t=e.trim();if(/^claude\s+mcp\s+add\b/.test(t))return dB(t);let s;try{s=JSON.parse(t)}catch{throw new Error(es.json)}if(!_r(s))throw new Error(es.json);let r,i=s;if("mcpServers"in s){const c=s.mcpServers;if(!_r(c))throw new Error(es.empty);const u=Object.keys(c);u.length===1&&_r(c[u[0]])&&(r=u[0],i=c[r])}if(!("command"in i))return{kind:"remote",config:aE(t)};const a=typeof i.command=="string"?i.command.trim():"";if(a==="")throw new Error(Jl.command);const l=Array.isArray(i.args)?i.args.map(c=>String(c)):[],o=_r(i.env)?Object.entries(i.env).filter(([c])=>oE.test(c)).map(([c,u])=>cE(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:a,args:l,env:o}}}function gv({code:e,label:t="Your code",large:s=!1}){const[r,i]=f.useState(!1),a=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),i(!0)}catch{}};return n.jsxs(J,{valign:"end",children:[n.jsx(Z,{label:t,grow:!0,children:n.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),n.jsx(R,{onClick:()=>void a(),children:r?"Copied":"Copy"})]})}function dE(e){if(e.phase==="starting")return{label:"Starting",tone:"accent"};switch(e.state){case"connected":return{label:"Connected",tone:"good",dot:!0};case"needs-reconnect":return{label:"Sign in again",tone:"warning"};case"needs-review":return{label:"Needs review",tone:"warning"};case"unreachable":return{label:e.transport==="stdio"?"Failed":"Unreachable",tone:"critical"};default:return{label:"Not finished",tone:"muted"}}}const fB="It can delete or destroy something, so it asks you every time and is never remembered.";function mB(e){return e.tier==="auto"?{label:"Runs on its own",tone:"good"}:e.destructive?{label:"Asks you every time",tone:"critical"}:{label:"Asks you first",tone:"warning"}}const hE="buddi-connections",pB="/connections/callback",gB="This service does not let buddi register itself. Create an app in its developer settings with the redirect address below, and paste its client id here. A token is usually simpler.",fE="Services and programs your team can use, and the tools each one brings.",xv=(e,t,s)=>`${e} ${e===1?t:s}`;function rb(e,t){return e.transport==="stdio"?void 0:t.find(s=>jv(s.url,e.url))}function vv({connection:e,card:t,size:s}){return t?n.jsx(Ka,{letter:t.name.slice(0,1).toUpperCase(),size:s}):n.jsx(Ka,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function mE({connection:e}){const t=dE(e);return n.jsx(ve,{tone:t.tone,dot:t.dot,children:t.label})}const Nf=e=>t=>{t.stopPropagation(),e()},vu=[{value:"address",label:"An address",text:"Any server on the web, by its https:// address. buddi opens it and reads what it offers, and nothing else until you have read its tools.",button:"Give its address"},{value:"program",label:"A program",text:"A server buddi starts itself on this computer, like npx or uvx, with its arguments and variables.",button:"Describe it"},{value:"paste",label:"A config",text:"The mcpServers block another app uses for it, or the claude mcp add line its docs print.",button:"Paste it"}],pE="buddi.connections.add-way";function xB(){try{const e=window.localStorage.getItem(pE);return vu.some(t=>t.value===e)?e:"address"}catch{return"address"}}function vB({embedded:e,timezone:t}={}){const s=le(()=>T.connections(),[],3e4),[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,d]=f.useState(null),h=s.data,m=S=>{var k;return((k=h==null?void 0:h.agents.find(N=>N.id===S))==null?void 0:k.name)??S},p=t??Intl.DateTimeFormat().resolvedOptions().timeZone,g=(h==null?void 0:h.connections)??[],y=(h==null?void 0:h.catalog)??[],b=y.filter(S=>!g.some(k=>k.transport!=="stdio"&&jv(S.url,k.url))),x=a?g.find(S=>S.id===a):void 0,v=o?g.find(S=>S.id===o):void 0,j=u?g.find(S=>S.id===u):void 0,w=S=>{l(null),i(S)};return n.jsxs(yn,{embedded:e,title:"Connections",lede:fE,children:[n.jsxs(Q,{gap:"lg",children:[n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ye,{name:"plug",size:14}),n.jsxs("span",{children:["A connection is a service or program buddi talks to; a plugin is code buddi installs and runs."," ",n.jsx("a",{href:Be("plugins"),children:"Plugins"})]})]}),!h&&!s.error?n.jsx(ce,{children:"Reading your connections…"}):null,n.jsx(re,{message:s.error}),h&&!h.vault?n.jsx(W,{tone:"warning",children:"This installation has no vault, so a service that asks for a sign-in cannot be connected. Turn the vault on first."}):null,h?n.jsx(Ze,{flush:!0,title:"Your connections",tool:g.length>0?xv(g.length,"connection","connections"):void 0,children:g.length===0?n.jsx(ce,{title:"Nothing connected yet",children:"Pick a service below, or add your own: an address, a program on this computer, or a config you already have."}):n.jsx("div",{className:"connections-rows",children:n.jsx(yt,{children:g.map(S=>n.jsx(jB,{connection:S,card:rb(S,y),twin:S.slug!==null&&g.some(k=>k.id!==S.id&&k.name===S.name),onOpen:()=>l(S.id),onFlow:w},S.id))})})}):null,h&&b.length>0?n.jsx(Ze,{title:"Connect a service",children:n.jsx("div",{className:"connections-tiles",children:b.map(S=>n.jsxs("div",{className:"connections-tile",children:[n.jsx(vv,{card:S}),n.jsxs("span",{className:"connections-tile-main",children:[n.jsx("span",{className:"connections-tile-name",children:S.name}),n.jsx("span",{className:"connections-tile-blurb",children:S.blurb})]}),n.jsx(R,{size:"sm",onClick:()=>w({step:"address",card:S}),"aria-label":`Connect ${S.name}`,children:"Connect"})]},S.id))})}):null,h?n.jsx(SB,{onFlow:S=>w({step:S})}):null]}),x?n.jsx(wB,{connection:x,card:rb(x,y),agentName:m,timezone:p,onClose:()=>l(null),onFlow:w,onDisconnect:()=>c(x.id),onHolders:()=>d(x.id)}):null,j&&h?n.jsx(bB,{connection:j,agents:h.agents,onCancel:()=>d(null),onDone:()=>{d(null),s.reload()}},j.id):null,v?n.jsx(kB,{connection:v,agentName:m,onCancel:()=>c(null),onDone:()=>{c(null),l(null),s.reload()}},v.id):null,r&&h?n.jsx(NB,{start:r,agents:h.agents,catalog:h.catalog,tokens:h.tokens??h.vault,onClose:()=>{i(null),s.reload()}}):null]})}function jB({connection:e,card:t,twin:s,onOpen:r,onFlow:i}){const a=e.state==="pending-review",l=s?`${e.name} (${e.slug})`:e.name,o=e.transport==="stdio"?e.program:void 0,c=o?o.line:e.host,u=a?"its tools are not reviewed yet":xv(e.toolCount,"tool","tools");return n.jsx(ft,{onClick:r,label:`${l}: details`,lead:n.jsx(vv,{connection:e,card:t}),title:l,sub:n.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:n.jsxs("span",{className:"plugins-side",children:[a?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",variant:"accent",onClick:Nf(()=>i({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",onClick:Nf(()=>i({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?n.jsx("span",{className:"connections-act",children:n.jsx(R,{size:"sm",onClick:Nf(()=>i({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,n.jsx(mE,{connection:e}),n.jsx(ye,{name:"chevron-right",size:14})]})})}const yB={oauth:"Its own sign-in page. buddi keeps the sign-in in its vault.",token:"A token you pasted, kept in buddi’s vault and sent only here.",none:"Nothing; it asks for no sign-in."};function wB({connection:e,card:t,agentName:s,timezone:r,onClose:i,onFlow:a,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,d=()=>a({step:"consent",connection:e,keepGrants:!0}),h=()=>a({step:"review",connection:e,keepGrants:!0}),m=()=>a({step:e.signedIn?"review":"consent",connection:e});return n.jsxs(kt,{title:n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(vv,{connection:e,card:t,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsx("span",{children:e.name}),n.jsxs("span",{className:"plugins-sheet-by",children:[u?"A program on this computer":"A service at an address"," · ",n.jsx(mE,{connection:e})]})]})]}),onClose:i,foot:n.jsxs(J,{children:[n.jsx(R,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),n.jsx(Xt,{}),u?n.jsx(R,{onClick:()=>a({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?n.jsx(R,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:d,children:"Reconnect"}):null,c?n.jsx(R,{variant:"accent",onClick:m,children:"Finish"}):n.jsx(R,{variant:e.state==="needs-review"?"accent":void 0,onClick:h,children:"Review again"})]}),children:[c?n.jsx(W,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?n.jsx(W,{tone:"warning",action:e.authKind!=="none"?n.jsx(R,{size:"sm",variant:"accent",onClick:d,children:"Sign in again"}):void 0,children:"Its sign-in ran out or was refused. Until you reconnect, each of its tools answers with one sentence instead of running."}):null,e.state==="needs-review"?n.jsxs(W,{tone:"warning",action:n.jsx(R,{size:"sm",variant:"accent",onClick:h,children:"Review it"}),children:["It changed its tools since you reviewed them. The new and changed ones wait until you review it again",e.heldTools?` (${e.heldTools} of the ones you kept ${e.heldTools===1?"waits":"wait"})`:"","; the others keep working."]}):null,e.state==="unreachable"&&e.unreachableSince?n.jsx(W,{tone:"critical",children:u?`It stopped answering at ${Ve(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${Ve(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?n.jsx(W,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?n.jsx(W,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[u?{label:"Command",value:n.jsx("span",{className:"connections-line",children:u.line})}:{label:"Address",value:n.jsx("span",{className:"connections-line",children:e.url})},...u?[{label:"Runs",value:"On this computer as you, with your PATH and only the variables you named. It stops after ten quiet minutes."}]:[],...u&&u.env.length>0?[{label:"Variables",value:n.jsx("span",{className:"mono",children:u.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...u?[]:[{label:"Signs in with",value:yB[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${xv(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${ze(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:n.jsxs("span",{className:"connections-holders",children:[n.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),n.jsx(R,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?n.jsx(te,{title:"What the program last said",children:n.jsx(jt,{label:"Its last lines on stderr",children:e.stderr.join(`
|
|
115
|
+
`)})}):null,t&&!c?n.jsxs("div",{className:"connections-another",children:[n.jsxs("p",{children:["Another ",t.name," account or workspace? It connects beside this one, with its own sign-in and its own name. In the browser, sign in as that other account."]}),n.jsx(R,{size:"sm",onClick:()=>a({step:"address",card:t}),children:"Add another account"})]}):null]})}function bB({connection:e,agents:t,onCancel:s,onDone:r}){const[i,a]=f.useState(()=>new Set(e.agents)),[l,o]=f.useState(!1),[c,u]=f.useState(null),d=(p,g)=>a(y=>{const b=new Set(y);return g?b.add(p):b.delete(p),b}),h=i.size===e.agents.length&&e.agents.every(p=>i.has(p)),m=async()=>{o(!0),u(null);try{const p=await T.grantConnection(e.id,[...i],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(Ss(p))}finally{o(!1)}};return n.jsxs(Xu,{title:`Who holds ${e.name}`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:l||h,onClick:()=>void m(),children:"Save"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Each agent you tick can use its tools; untick one to take them away. Approvals still ask as before."}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(p=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(p.id),onChange:g=>d(p.id,g.target.checked)}),n.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),n.jsx(re,{message:c})]})}function kB({connection:e,agentName:t,onCancel:s,onDone:r}){const[i,a]=f.useState(!1),[l,o]=f.useState(null),c=e.agents.map(t),u=async()=>{a(!0),o(null);try{await T.disconnect(e.id),r()}catch(d){o(Ss(d))}finally{a(!1)}};return n.jsxs(Xu,{title:`Disconnect ${e.name}?`,onClose:s,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:i,onClick:s,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:i,onClick:()=>void u(),children:"Disconnect"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["buddi forgets its sign-in and its tools."," ",c.length>0?`${c.join(" and ")} ${c.length===1?"loses":"lose"} them.`:"No agent holds its tools."]}),n.jsx(re,{message:l})]})}function SB({onFlow:e}){const[t,s]=f.useState(xB),r=vu.find(a=>a.value===t)??vu[0],i=a=>{s(a);try{window.localStorage.setItem(pE,a)}catch{}};return n.jsx(Ze,{title:"Add your own",actions:n.jsx(ls,{label:"How to add it",options:vu.map(({value:a,label:l})=>({value:a,label:l})),value:t,onChange:i}),children:n.jsxs("div",{className:"connections-add",children:[n.jsx("p",{className:"connections-add-text",children:r.text}),n.jsx(R,{variant:"accent",onClick:()=>e(t),children:r.button})]})})}function NB({start:e,agents:t,catalog:s=[],tokens:r=!0,onClose:i,pollMs:a=2e3}){const[l,o]=f.useState(e.step),[c,u]=f.useState(e.connection),[d,h]=f.useState("unknown"),[m,p]=f.useState(null),[g,y]=f.useState(null),b=(m==null?void 0:m.url)??(c==null?void 0:c.url),x=e.card??s.find(w=>b!==void 0&&jv(w.url,b)),v=(c==null?void 0:c.name)??(x==null?void 0:x.name)??(m==null?void 0:m.name)??"the service",j=l==="paste"?"Paste a config":l==="address"?"Connect a service":l==="program"?c?`Change ${c.name}`:"A program on this computer":l==="consent"?`Sign in to ${v}`:l==="review"?`What ${v} brings`:"Who gets these tools";return n.jsxs(kt,{title:j,onClose:i,size:"wide",children:[l==="paste"?n.jsx(CB,{onRead:w=>{w.kind==="program"?(y(w.program),o("program")):(p(w.config),o("address"))}}):null,l==="address"?n.jsx(EB,{card:x,pasted:m,onDone:(w,S)=>{u(w),S==="none"?o("review"):(h(S),o("consent"))}}):null,l==="program"?n.jsx(OB,{connection:c,pasted:g,tokens:r,onDone:w=>{var S;y(null),u(w),e.keepGrants&&!((S=w.program)!=null&&S.changedSinceReview)&&w.state!=="pending-review"?i():o("review")}}):null,l==="consent"&&c?n.jsx(RB,{connection:c,signIn:d,card:x,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:a,onSignedIn:w=>{p(null),u(w),e.keepGrants?i():o("review")}}):null,l==="review"&&c?n.jsx(DB,{connection:c,onKept:w=>{u(w),e.keepGrants?i():o("grant")}}):null,l==="grant"&&c?n.jsx(_B,{connection:c,agents:t,onDone:i}):null]})}function jv(e,t){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(t)}function Ss(e){return e instanceof Error?e.message:String(e)}function CB({onRead:e}){const[t,s]=f.useState(""),[r,i]=f.useState(null),a=()=>{try{const l=hB(t);s(""),i(null),e(l)}catch(l){i(Ss(l))}};return n.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),a()},children:[n.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",n.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",n.jsx("span",{className:"mono",children:"claude mcp add"})," line its docs print. A remote server gives its address, name and one header; a program its command, arguments and variables. Nothing is kept before you have read it on the next screen."]}),n.jsx(Z,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:n.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:t,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),n.jsx(re,{message:r}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:t.trim()==="",children:"Read it"})})]})}function EB({card:e,pasted:t,onDone:s}){var m,p;const[r,i]=f.useState((t==null?void 0:t.url)??(e==null?void 0:e.url)??""),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=async()=>{l(!0),c(null);try{const g=await T.addConnection(r.trim(),(e==null?void 0:e.name)??(t==null?void 0:t.name));s(g.connection,g.signIn)}catch(g){c(Ss(g))}finally{l(!1)}},d=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",h=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return n.jsxs("form",{className:"ui-stack",onSubmit:g=>{g.preventDefault(),u()},children:[e?n.jsxs("p",{children:["buddi opens ",e.name,"’s server, reads its name and what it offers, and asks whether it wants you to sign in. Nothing else is sent."]}):n.jsx("p",{children:"Where is the server? buddi opens it, reads its name and what it offers, and nothing else until you have read its tools."}),n.jsx(Z,{label:"Address",hint:"An https:// address. A server you start with npx, uvx or a local command is “A program on this computer” instead.",children:n.jsx("input",{required:!0,autoFocus:!e&&!t,spellCheck:!1,value:r,placeholder:"https://",onChange:g=>i(g.target.value)})}),e&&!e.verified?n.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,h?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):d?n.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a token you make on its site. The next screen links to the page."]}):e!=null&&e.clientIdRequired?n.jsxs("p",{className:"ui-card-meta",children:[e.name," does not let buddi register itself: signing in needs a token, or a client id from its developer settings."]}):null,t!=null&&t.header?n.jsx("p",{className:"ui-card-meta",children:t.placeholder?`Your config has a placeholder where the ${t.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${t.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,t&&t.dropped.length>0?n.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",t.dropped.join(", ")," ",t.dropped.length===1?"was":"were"," left out."]}):null,n.jsx(re,{message:o}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:a||r.trim()==="",children:a?"Opening…":"Continue"})})]})}const AB={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function TB(e,t,s="none"){const r=e==="manual"?["token","client"]:["oauth","token"],i=t?r:r.filter(a=>a!=="token");return s==="first"?["device",...i]:s==="offered"?[...i.filter(a=>a!=="client"),"device",...i.filter(a=>a==="client")]:i}function RB({connection:e,signIn:t,card:s,pasted:r,placeholder:i,tokens:a,pollMs:l,onSignedIn:o}){var B,O;const[c,u]=f.useState(t),d=(B=s==null?void 0:s.auth)!=null&&B.device?s.auth.recommended==="device"?"first":"offered":"none",h=TB(c,a,d),m=r!==void 0||d!=="first"&&(e.authKind==="token"||((O=s==null?void 0:s.auth)==null?void 0:O.recommended)==="token"),[p,g]=f.useState(()=>m&&h.includes("token")?"token":h[0]),y=h.includes(p)?p:h[0],[b,x]=f.useState(gB),[v,j]=f.useState(""),[w,S]=f.useState(null),[k,N]=f.useState(!1),[C,I]=f.useState(null),[A,_]=f.useState(!1),[z,L]=f.useState(null),E=`${location.origin}${pB}`,M=f.useRef(o);M.current=o,f.useEffect(()=>{if(!A)return;let K=!1;const G=async()=>{if(!K){K=!0;try{M.current(await T.connection(e.id))}catch(X){I(Ss(X))}}},se=typeof BroadcastChannel=="function"?new BroadcastChannel(hE):null;se&&(se.onmessage=X=>{var de;((de=X.data)==null?void 0:de.id)===e.id&&G()});let ue;const ie=Date.now(),ee=async()=>{if(!K){try{const X=await T.connection(e.id);if((!e.signedIn||e.authKind==="token")&&X.signedIn&&X.authKind==="oauth"){G();return}}catch{}if(Date.now()-ie>10*6e4){_(!1),I("The sign-in did not come back within ten minutes. Start it again.");return}ue=window.setTimeout(()=>void ee(),l)}};return ue=window.setTimeout(()=>void ee(),l),()=>{K=!0,se==null||se.close(),window.clearTimeout(ue)}},[A,e,l]);const D=async K=>{var G;N(!0),I(null);try{const{authorizeUrl:se}=await T.connectionConsent(e.id,K);S(se)}catch(se){se instanceof ge&&((G=se.detail)==null?void 0:G.code)==="client-id"?(x(se.message),u("manual"),g("client")):I(Ss(se))}finally{N(!1)}};f.useEffect(()=>{y!=="oauth"||w!==null||D()},[y]);const U=K=>{const G=window.open(K,"_blank");G?(G.opener=null,L(null)):L(K),_(!0)},$=K=>{g(K),S(null),I(null),_(!1),L(null)};return n.jsxs("div",{className:"ui-stack",children:[h.length>1?n.jsx(ls,{label:"How to sign in",options:h.map(K=>({value:K,label:AB[K]})),value:y,onChange:$}):null,y==="oauth"?n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["buddi opens ",e.name,"’s own sign-in page in a new tab. You say yes there, the tab comes back here, and buddi keeps the sign-in in its vault. No agent ever sees it."]}),k?n.jsxs(ce,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,y==="client"?n.jsxs(n.Fragment,{children:[n.jsx(W,{tone:"warning",children:b}),n.jsx(Z,{label:"Client id",children:n.jsx("input",{required:!0,spellCheck:!1,value:v,onChange:K=>{j(K.target.value),S(null),_(!1)}})}),n.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",n.jsx("span",{className:"mono",children:E})]})]}):null,y==="token"?n.jsx($B,{connection:e,card:s,pasted:r,placeholder:i,onSignedIn:o}):null,y==="device"?n.jsx(PB,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(y==="oauth"||y==="client")&&A?n.jsxs(W,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(y==="oauth"||y==="client")&&z?n.jsx("p",{children:n.jsxs("a",{href:z,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,y==="oauth"||y==="client"?n.jsx(re,{message:C}):null,y==="oauth"?n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>{w&&U(w)},disabled:w===null,children:A?"Open it again":`Sign in to ${e.name}`})}):null,y==="client"?n.jsx(J,{align:"end",children:w===null?n.jsx(R,{variant:"accent",onClick:()=>void D(v.trim()),disabled:k||v.trim()==="",children:k?"Checking…":"Continue"}):n.jsx(R,{variant:"accent",onClick:()=>U(w),children:A?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function IB(e){try{const t=new URL(e);return`${t.host}${t.pathname==="/"?"":t.pathname.replace(/\/$/,"")}`}catch{return e}}function PB({connection:e,service:t,pollMs:s,onSignedIn:r}){const[i,a]=f.useState(null),[l,o]=f.useState(null),[c,u]=f.useState(0),[d,h]=f.useState(null),m=f.useRef(r);m.current=r,f.useEffect(()=>{let y=!1,b;a(null),o(null),h(null);const x=async()=>{var v,j;if(!y){try{const w=await T.connection(e.id);if(y)return;if(((v=w.device)==null?void 0:v.state)==="done"){m.current(w);return}if(((j=w.device)==null?void 0:j.state)==="failed"){o(w.device.reason??"The sign-in did not finish. Start again.");return}}catch{}b=window.setTimeout(()=>void x(),s)}};return(async()=>{try{const v=await T.connectionDevice(e.id);if(y)return;a({userCode:v.userCode,verificationUri:v.verificationUri}),b=window.setTimeout(()=>void x(),s)}catch(v){y||o(Ss(v))}})(),()=>{y=!0,window.clearTimeout(b)}},[e.id,s,c]);const p=y=>{const b=window.open(y,"_blank");b?(b.opener=null,h(null)):h(y)},g=i?IB(i.verificationUri):"";return n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:["Type this code on ",t,"’s site and say yes there. buddi keeps the sign-in in its vault and sends it only to"," ",n.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),i===null&&l===null?n.jsxs(ce,{children:["Asking ",t," for a code…"]}):null,i&&l===null?n.jsxs(n.Fragment,{children:[n.jsx(gv,{code:i.userCode,label:`Your code for ${t}`,large:!0}),n.jsxs(W,{tone:"accent",role:"status",children:["Waiting for you to approve on ",t,"…"]}),d?n.jsx("p",{children:n.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:["Open ",g]})}):null,n.jsx(J,{align:"end",children:n.jsxs(R,{variant:"accent",onClick:()=>p(i.verificationUri),children:["Open ",g]})})]}):null,l!==null?n.jsxs(n.Fragment,{children:[n.jsx(re,{message:l}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>u(y=>y+1),children:"Start again"})})]}):null]})}function $B({connection:e,card:t,pasted:s,placeholder:r,onSignedIn:i}){var x,v;const[a,l]=f.useState((s==null?void 0:s.value)??""),[o,c]=f.useState((s==null?void 0:s.name)??"Authorization"),[u,d]=f.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[h,m]=f.useState(!1),[p,g]=f.useState(null),y=async()=>{m(!0),g(null);try{const j=await T.connectionToken(e.id,{token:a.trim(),header:o.trim(),prefix:u});l(""),i(j.connection)}catch(j){g(Ss(j))}finally{m(!1)}},b=(x=t==null?void 0:t.auth)==null?void 0:x.tokenPage;return n.jsxs("form",{className:"ui-stack",onSubmit:j=>{j.preventDefault(),y()},children:[n.jsxs("p",{children:[b?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",n.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),b?n.jsx("p",{children:n.jsxs("a",{href:b,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?n.jsx(W,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,n.jsx(Z,{label:"Token",hint:(v=t==null?void 0:t.auth)==null?void 0:v.tokenHint,children:n.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:a,onChange:j=>l(j.target.value)})}),n.jsxs(bs,{columns:2,dense:!0,children:[n.jsx(Z,{label:"Header",hint:"Most services want Authorization.",children:n.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:j=>c(j.target.value)})}),n.jsx(Z,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:n.jsx("input",{spellCheck:!1,value:u,onChange:j=>d(j.target.value)})})]}),n.jsx(re,{message:p}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:h||a.trim()===""||o.trim()==="",children:h?"Trying it…":"Try it and keep it"})})]})}function MB(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function OB({connection:e,pasted:t,tokens:s=!0,onDone:r}){const i=e==null?void 0:e.program,a=f.useRef(0),l=()=>(a.current+=1,a.current),[o,c]=f.useState((e==null?void 0:e.name)??(t==null?void 0:t.name)??""),[u,d]=f.useState((i==null?void 0:i.command)??(t==null?void 0:t.command)??""),[h,m]=f.useState(()=>((i==null?void 0:i.args)??(t==null?void 0:t.args)??[]).map(E=>({key:l(),value:E}))),[p,g]=f.useState(()=>i?i.env.map(E=>({key:l(),name:E.name,value:E.value??"",secret:E.secret,kept:E.secret})):((t==null?void 0:t.env)??[]).map(E=>({key:l(),name:E.name,value:E.value,secret:E.secret,kept:!1}))),[y,b]=f.useState(!1),[x,v]=f.useState(null),j=/\s/.test(u.trim())?uE(u.trim()):[u.trim()],w=j[0]??"",S=[...j.slice(1),...h.map(E=>E.value)],k=[w,...S].filter((E,M)=>M>0||E!==""),N=()=>{j.length<2||(d(w),m(E=>[...j.slice(1).map(M=>({key:l(),value:M})),...E]))},C=k.map(MB).join(" "),I=p.filter(E=>E.secret&&E.value===""&&!E.kept).map(E=>E.name||"a variable"),A=((t==null?void 0:t.env)??[]).filter(E=>E.placeholder).map(E=>E.name),_=(E,M)=>m(D=>D.map(U=>U.key===E?{...U,value:M}:U)),z=(E,M)=>g(D=>D.map(U=>U.key===E?{...U,...M}:U)),L=async()=>{b(!0),v(null);const E={name:o.trim(),command:w,args:S,env:p.filter(M=>M.name.trim()!=="").map(M=>({name:M.name.trim(),value:M.value,secret:M.secret}))};try{r(e?await T.updateProgram(e.id,E):(await T.addProgram(E)).connection),g(M=>M.map(D=>D.secret?{...D,value:""}:D))}catch(M){v(Ss(M))}finally{b(!1)}};return n.jsxs("form",{className:"ui-stack",onSubmit:E=>{E.preventDefault(),L()},children:[n.jsx("p",{children:"A server buddi starts itself on this computer, as you, when an agent needs it, and stops after ten quiet minutes. It runs with your PATH and only the variables you name here. The review screen is the first time it runs, only to list its tools."}),n.jsxs(bs,{columns:2,children:[n.jsx(Z,{label:"Name",children:n.jsx("input",{required:!0,autoFocus:!t&&!e,maxLength:80,spellCheck:!1,value:o,onChange:E=>c(E.target.value)})}),n.jsx(Z,{label:"Command",hint:"The program that starts the server: npx, uvx, node, or a full path. A whole line is split into it and its arguments.",children:n.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:E=>d(E.target.value),onBlur:N})})]}),n.jsx(Z,{label:"Arguments",group:!0,hint:"One per row, exactly as the server's docs give them. No shell: quotes and $VARIABLES are passed as they are.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[h.map((E,M)=>n.jsxs("div",{className:"connections-row",children:[n.jsx("input",{"aria-label":`Argument ${M+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:E.value,onChange:D=>_(E.key,D.target.value)}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>m(D=>D.filter(U=>U.key!==E.key)),"aria-label":`Remove argument ${M+1}`,children:"Remove"})]},E.key)),n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>m(E=>[...E,{key:l(),value:""}]),children:"Add an argument"})})]})}),n.jsx(Z,{label:"Environment variables",group:!0,hint:"A secret is kept in buddi's vault and handed to the program only when it starts. Names with TOKEN, KEY, SECRET or PASSWORD start as secrets.",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((E,M)=>n.jsxs("div",{className:"connections-row","data-kind":"env",children:[n.jsx("input",{"aria-label":`Variable ${M+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:E.name,onChange:D=>{const U=D.target.value;z(E.key,E.value===""&&!E.kept?{name:U,secret:lE(U)}:{name:U})}}),n.jsx("input",{"aria-label":`Variable ${M+1} value`,type:E.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:E.kept&&E.value===""?"Kept. Type to replace it.":"value",value:E.value,onChange:D=>z(E.key,{value:D.target.value})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:E.secret,onChange:D=>z(E.key,{secret:D.target.checked,kept:D.target.checked&&E.kept})}),n.jsx("span",{children:"Secret"})]}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>g(D=>D.filter(U=>U.key!==E.key)),"aria-label":`Remove variable ${M+1}`,children:"Remove"})]},E.key)),n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>g(E=>[...E,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),A.length>0?n.jsxs(W,{tone:"accent",children:["Your config had a placeholder for ",A.join(", "),". Type the value itself."]}):null,!s&&p.some(E=>E.secret)?n.jsx(W,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,n.jsx("p",{className:"ui-card-meta",children:"A server that signs you in through a browser opens it on this computer, so it needs a screen. On a machine without one, give it a token as a secret variable instead."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"It will run"}),n.jsx(jt,{label:"The command line",children:C||"…"})]}),n.jsx(re,{message:x}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:y||o.trim()===""||u.trim()===""||I.length>0,title:I.length>0?`Give ${I.join(", ")} a value.`:void 0,children:y?"Saving…":e?"Save":"Continue"})})]})}function DB({connection:e,onKept:t}){const s=le(()=>T.connectionReview(e.id),[e.id]),[r,i]=f.useState(null),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=s.data,d=r??(u==null?void 0:u.slug)??"",h=async()=>{var p;if(u){l(!0),c(null);try{t(await T.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:d}:{}}))}catch(g){g instanceof ge&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(Ss(g))}finally{l(!1)}}};if(!u)return s.error?n.jsx(re,{message:s.error}):e.transport==="stdio"?n.jsxs(ce,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):n.jsxs(ce,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:["Read what ",e.name," brings before it brings it. Each tool gets a buddi name and a tier from what the server says it does; anything that changes something asks you first, on the same approval card as every other tool."]}),u.program?n.jsx(W,{tone:"warning",title:"This runs on this computer as you",children:n.jsxs(Q,{gap:"sm",children:[n.jsx(jt,{label:"The command",children:u.program.line}),n.jsx("p",{children:"It can read and change what you can, and reach the network. buddi starts it with only the variables below, stops it after ten quiet minutes, and asks you again if its command changes."}),u.program.env.length>0?n.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):n.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",n.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?n.jsxs(W,{tone:"warning",children:[e.name," says nothing about what its tools do, so every one of them asks you first."]}):null,u.changes&&u.changes.added.length+u.changes.changed.length+u.changes.removed.length>0?n.jsxs(W,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[n.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?n.jsxs("li",{children:["New: ",n.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?n.jsxs("li",{children:["Changed: ",n.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?n.jsxs("li",{children:["Gone: ",n.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),n.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?n.jsx(Z,{label:"Its name in buddi",hint:`Tools are called mcp.${d||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:n.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:d,onChange:p=>i(p.target.value.toLowerCase())})}):null,u.tools.length===0?n.jsxs(ce,{children:[e.name," lists no tools."]}):n.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=mB(p),y=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${d||u.slug}.`):p.fullName;return n.jsx("div",{className:"ui-list-row connections-tool",children:n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("span",{className:"mono",children:y}),p.problem?n.jsx(ve,{tone:"muted",children:"Cannot be used"}):n.jsx(ve,{tone:g.tone,children:g.label}),p.change==="added"?n.jsx(Ia,{children:"New"}):p.change==="changed"?n.jsx(Ia,{children:"Changed"}):null]}),p.description?n.jsx("p",{className:"ui-card-meta",children:p.description}):null,!p.problem&&p.tier==="gated"?n.jsx("p",{className:"ui-card-meta",children:p.destructive?fB:"You can remember its approval for an agent when you give it the tools, or later on the agent’s Tools tab."}):null,p.problem?n.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),n.jsx(re,{message:o}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",onClick:()=>void h(),disabled:a||u.slugEditable&&d.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function _B({connection:e,agents:t,onDone:s}){var b;const r=t.find(x=>x.frontDesk)??t[0],[i,a]=f.useState(()=>new Set(r?[r.id]:[])),o=(((b=le(()=>T.connectionTools(e.id),[e.id]).data)==null?void 0:b.tools)??[]).filter(x=>x.tier==="gated"),[c,u]=f.useState(()=>new Set),[d,h]=f.useState(!1),[m,p]=f.useState(null),g=(x,v)=>{a(j=>{const w=new Set(j);return v?w.add(x):w.delete(x),w})},y=async()=>{h(!0),p(null);try{const x=await T.grantConnection(e.id,[...i]);if(x.failed.length>0){p(x.failed.map(v=>`${v.agent}: ${v.message}`).join(" "));return}for(const v of x.granted)for(const j of c)await T.setRememberedApproval(v,j,!0);s()}catch(x){p(Ss(x))}finally{h(!1)}};return n.jsxs("div",{className:"ui-stack",children:[n.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",n.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:t.map(x=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.has(x.id),onChange:v=>g(x.id,v.target.checked)}),n.jsxs("span",{children:[x.name,x.frontDesk?" (front desk)":""]})]},x.id))}),n.jsx("p",{className:"ui-card-meta",children:"No one is fine too: the connection waits here until you give it to someone."}),o.length>0?n.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[n.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(x=>n.jsxs(Q,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",disabled:!x.rememberable,checked:c.has(x.tool),onChange:v=>u(j=>{const w=new Set(j);return v.target.checked?w.add(x.tool):w.delete(x.tool),w})}),n.jsx("span",{className:"mono",children:x.tool})]}),x.why?n.jsx("p",{className:"ui-card-meta",children:x.why}):null]},x.tool))]}):null,n.jsx(re,{message:m}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,disabled:d,children:"Not now"}),n.jsx(R,{variant:"accent",onClick:()=>void y(),disabled:d||i.size===0,children:"Give them"})]})]})}const LB=(e,t,s)=>`${e} ${e===1?t:s}`;function FB(e){return e.state==="pending-review"||!e.slug?"Not finished: its tools are not reviewed yet.":e.state==="needs-review"?"Its tools changed and need your review.":e.state==="needs-reconnect"?"Its sign-in ended; sign in again first.":null}function zB({agentId:e,agentName:t,readOnly:s,version:r,onSaved:i}){const[a,l]=f.useState({}),o=le(()=>T.connections().then(j=>(l({}),j)),[r]),[c,u]=f.useState(null),[d,h]=f.useState(null),m=Be("connections"),p=async(j,w)=>{u(j.id),h(null);try{const S=await T.setConnectionHolder(j.id,e,w);l(k=>({...k,[j.id]:S.held})),i==null||i()}catch(S){h(S instanceof Error?S.message:String(S))}finally{u(null)}},g=o.data,y=(g==null?void 0:g.connections)??[],b=j=>a[j.id]??j.agents.includes(e),x=g?g.agents.some(j=>j.id===e):!0,v=y.filter(b).length;return n.jsxs(te,{title:"Connections",aside:g&&y.length>0?`holds ${v} of ${y.length} · saved as you change them`:void 0,panel:!0,children:[n.jsx(re,{message:o.error??d}),g?y.length===0?n.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",n.jsx("a",{href:m,children:"Connect a service in Connections"})]}):x?n.jsxs(n.Fragment,{children:[s?n.jsx(W,{tone:"warning",children:"This agent ships with buddi, so its connections are read-only here. Ask Agent Father to make it yours, then it can change."}):null,n.jsx("ul",{className:"ui-list delegate-list","aria-label":`Connections ${t} holds`,children:y.map(j=>{const w=b(j),S=FB(j),k=j.transport==="stdio"?"on this computer":j.host,N=j.slug?LB(j.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${j.id}`;return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",role:"switch",id:C,checked:w,"aria-checked":w,disabled:s||c!==null||S!==null&&!w,onChange:I=>void p(j,I.target.checked)}),n.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[j.name,S?n.jsxs(n.Fragment,{children:[" ",n.jsx(ve,{tone:"warning",children:dE(j).label})]}):null]}),n.jsx("span",{className:"ui-list-sub",children:`${k} · ${N}`}),S?n.jsxs("span",{className:"ui-list-sub",children:[S," ",n.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},j.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[t," makes and changes agents, so it holds no connections."]}):o.error?null:n.jsx(ce,{children:"Loading the connections…"})]})}const UB=(e,t)=>!!e&&!!t&&e.kind===t.kind&&(e.kind==="mascot"?e.role===t.role:e.kind==="emoji"?e.value===t.value:!0);async function gE(e){const t=await fetch(Yi(e));if(!t.ok)throw new Error(`The picture could not be read (${t.status}).`);const s=await t.blob();return new File([s],`buddi-blob-${e}.png`,{type:"image/png"})}function BB({face:e,onPick:t,label:s=P.assistant.face,kept:r,disabled:i,disableEmoji:a,children:l}){return n.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[n.jsxs("div",{className:"meet-face-row",children:[r?n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":(e==null?void 0:e.kind)==="kept"?"true":void 0,"aria-pressed":(e==null?void 0:e.kind)==="kept","aria-label":"The current picture",disabled:i,onClick:()=>t({kind:"kept",url:r}),children:n.jsx("img",{src:r,alt:""})}):null,o_.map(o=>{const c={kind:"mascot",role:o},u=UB(e,c);return n.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":P.assistant.mascot(o),disabled:i,onClick:()=>t(c),children:n.jsx("img",{src:Yi(o),alt:""})},o)})]}),n.jsx("div",{className:"meet-face-row",children:u_.map(o=>{const c=(e==null?void 0:e.kind)==="emoji"&&e.value===o;return n.jsx("button",{type:"button",className:"meet-face","data-chosen":c?"true":void 0,"aria-pressed":c,disabled:i||a,onClick:()=>t({kind:"emoji",value:o}),children:o},o)})}),l]})}const WB=["mirror","en","fr"],Cf=10,Ef=500,xE=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],ib=e=>{var t;return e==="access"?"tools":((t=xE.find(s=>s.id===e))==null?void 0:t.id)??"identity"};function HB({agentId:e,section:t,navigate:s}){var y,b,x;const{data:r,error:i,reload:a}=le(()=>T.agents(),[]),[l,o]=f.useState(null),[c,u]=f.useState(null),[d,h]=f.useState(ib(t));f.useEffect(()=>h(ib(t)),[t]);const m=v=>{h(v),s==null||s(xt(e,"setup",v))},p=async v=>{o(null),u(null);try{const j=await v;u(j.changed.length===0?`No file change needed. ${j.note}.`:`Changed ${j.changed.join(", ")}. ${j.note}.`),a()}catch(j){o(j instanceof Error?j.message:String(j))}},g=r==null?void 0:r.agents.find(v=>v.id===e);return n.jsxs(Q,{gap:"lg",children:[n.jsx(Yo,{level:"secondary",label:"Setup",children:xE.map(v=>n.jsx(Ha,{href:xt(e,"setup",v.id),active:d===v.id,onClick:j=>{j.preventDefault(),m(v.id)},children:v.label},v.id))}),n.jsx(re,{message:i??l}),c?n.jsx(W,{tone:"good",role:"status",children:c}):null,r?g?n.jsx(KB,{agent:g,all:r.agents,engine:r.engines.find(v=>v.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:d,onShow:m,onRun:p,onSaved:a},`${g.id}:${(y=r.engines.find(v=>v.id===g.id))==null?void 0:y.model}:${(x=(b=r.providerAccounts)==null?void 0:b.bindings.find(v=>v.agentId===g.id))==null?void 0:x.accountId}`):n.jsx(ce,{children:"This agent is not installed as a file."}):n.jsx(ce,{children:"Loading…"})]})}function KB({agent:e,all:t,engine:s,providers:r,accounts:i,shown:a,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,d=r.find(k=>k.kind===u),h=(s==null?void 0:s.model)??e.model,[m,p]=f.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,y]=f.useState(null),b=k=>{o(T.setAgentEngine(e.id,k))},x=k=>{const N=r.find(C=>C.kind===k);b({provider:k,model:(N==null?void 0:N.defaultModel)??h})},v=(d==null?void 0:d.models.map(k=>k.id))??[],j=v.includes(h)?v:[h,...v],w=s?s.available:!0,S=(s==null?void 0:s.unavailableReason)??"no credential";return n.jsxs(n.Fragment,{children:[n.jsx("div",{hidden:a!=="identity",children:n.jsxs(Q,{gap:"lg",children:[w?null:n.jsxs(W,{tone:"warning",children:["This agent cannot run right now."," ",n.jsx("a",{href:xt(e.id,"setup","brain"),onClick:k=>{k.preventDefault(),l("brain")},children:"See Brain."})]}),n.jsx(VB,{agent:e,onSaved:c})]})}),n.jsx("div",{hidden:a!=="brain",children:n.jsxs(Q,{gap:"lg",children:[w?null:n.jsxs(W,{tone:"warning",children:["This agent cannot run right now: ",S,"."]}),n.jsx(te,{panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsxs(te,{title:"Runs on",children:[i?n.jsx(ZB,{agentId:e.id,accounts:i,onRun:o}):n.jsxs(bs,{children:[n.jsx(Z,{label:"Provider",children:n.jsx("select",{value:u,onChange:k=>x(k.target.value),children:r.map(k=>n.jsxs("option",{value:k.kind,children:[k.kind,k.usable?"":" (no credential)"]},k.kind))})}),n.jsxs(Z,{label:"Model",children:[n.jsx("input",{list:`models-${e.id}`,defaultValue:h,onBlur:k=>{k.target.value.trim()!==""&&k.target.value.trim()!==h&&b({model:k.target.value.trim()})}}),n.jsx("datalist",{id:`models-${e.id}`,children:j.map(k=>n.jsx("option",{value:k},k))})]})]}),i?null:n.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",n.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),d&&!d.usable?` · default model ${d.defaultModel} (${d.defaultFrom})`:""]}),s!=null&&s.restartRequired?n.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),n.jsx(te,{title:"Behaviour",aside:"saved as you change them",children:n.jsxs(bs,{children:[n.jsx(Z,{label:"Steps per reply",hint:`${s!=null&&s.maxTurnsIsDefault?`Default ${s.defaultMaxTurns??40}. `:""}Each tool call is a step; a reply that uses them all stops and offers Continue.`,after:g?n.jsx("span",{className:"critical save-error",role:"alert",children:g}):null,children:n.jsx("input",{type:"number",min:Cf,max:Ef,value:m,onChange:k=>{p(k.target.value),y(null)},onBlur:()=>{const k=Number(m);if(!Number.isInteger(k)||k<Cf||k>Ef){y(`Between ${Cf} and ${Ef}.`);return}k!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&b({maxTurns:k})}})}),n.jsx(Z,{label:"Language",hint:"Mirror answers in whatever language you write.",children:n.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:k=>b({language:k.target.value}),children:WB.map(k=>n.jsx("option",{value:k,children:k},k))})}),XS(ZS(s??{id:e.id,provider:u},i))?n.jsx(Z,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:n.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:k=>b({thinking:k.target.value==="default"?null:k.target.value}),children:[n.jsx("option",{value:"default",children:"Model default"}),n.jsx("option",{value:"on",children:"On"}),n.jsx("option",{value:"off",children:"Off"})]})}):n.jsx(Z,{label:"Thinking",hint:a$,children:n.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),n.jsx(Ct,{summary:"Built-in context",boxed:!0,children:n.jsx("p",{className:"ui-card-meta",children:"Every agent receives current time, owner timezone and server-host information. system.time and system.info are always available, without grants or approval. Host and browser access still require their own permissions."})})]})}),n.jsx("div",{hidden:a!=="tools",children:n.jsxs(Q,{gap:"lg",children:[n.jsx(GB,{agent:e,all:t,onSaved:c}),n.jsx(zB,{agentId:e.id,agentName:e.name,readOnly:e.isExample===!0,version:e.tools.join(","),onSaved:c})]})}),n.jsx("div",{hidden:a!=="team",children:n.jsx(Q,{gap:"lg",children:n.jsx(s5,{agent:e,all:t,onSaved:c})})})]})}function vE({dirty:e,busy:t,failure:s,label:r,onSave:i}){return n.jsxs(n.Fragment,{children:[s?n.jsx("span",{className:"critical save-error",role:"alert",children:s}):n.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{variant:"accent",disabled:!e||t,onClick:i,children:r})]})}const jE=n.jsx(W,{tone:"warning",children:"This agent ships with buddi, so its file is read-only here. Ask Agent Father to make it yours, then these fields can change."});function VB({agent:e,onSaved:t}){var L;const[s,r]=f.useState(e.name),[i,a]=f.useState(e.handle),[l,o]=f.useState(e.description),[c,u]=f.useState(e.avatar??""),[d,h]=f.useState(!1),m=le(()=>T.agentFile(e.id),[e.id]),[p,g]=f.useState(null),y=((L=m.data)==null?void 0:L.persona.trim())??"",b=p??y,x=m.data!==void 0&&p!==null&&p.trim()!==y,[v,j]=f.useState(!1),[w,S]=f.useState(null),[k,N]=f.useState(null),C=s.trim()!==e.name||i.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||x,I=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),A=Fp(I?{...e,avatar:c.trim()}:e),_={...A?{avatar:A}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!I&&e.picture?{picture:e.picture}:{}},z=async()=>{j(!0),S(null),N(null);try{const E=await T.updateAgentFile(e.id,{name:s.trim(),handle:i.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...x&&b.trim()!==""?{persona:b.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await T.removeAgentPicture(e.id),window.dispatchEvent(new Event(So))),g(null),m.reload(),N(E.message),t()}catch(E){S(E instanceof Error?E.message:String(E))}finally{j(!1)}};return n.jsx(te,{title:"Who it is",aside:n.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:n.jsx(vE,{dirty:C,busy:v,failure:w,label:"Save who it is",onSave:()=>void z()}),children:n.jsxs(Q,{children:[e.isExample?jE:null,k?n.jsx(W,{tone:"good",role:"status",children:k}):null,n.jsxs(bs,{children:[n.jsx(Z,{label:"Name",hint:"What it is called, everywhere.",children:n.jsx("input",{value:s,disabled:v||e.isExample,onChange:E=>r(E.target.value)})}),n.jsx(Z,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:n.jsx("input",{value:i,disabled:v||e.isExample,onChange:E=>a(E.target.value)})})]}),n.jsxs(J,{children:[n.jsx(Es,{id:e.id,name:s.trim()||e.name,size:"xl",face:_}),n.jsx(R,{"aria-expanded":d,onClick:()=>h(E=>!E),children:d?"Hide faces":"Change face"})]}),d?n.jsx(JB,{agent:e,avatar:c,onEmoji:u,onChanged:t,disabled:v}):null,n.jsx(Z,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:n.jsx("textarea",{rows:2,value:l,disabled:v||e.isExample,onChange:E=>o(E.target.value)})}),n.jsx(Z,{label:"Persona",hint:n.jsxs(n.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",n.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?n.jsx(re,{message:m.error}):m.data?n.jsx("textarea",{className:"setup-persona",value:b,rows:Math.max(6,b.split(`
|
|
116
|
+
`).length+1),disabled:v||e.isExample,onChange:E=>g(E.target.value)}):n.jsx(ce,{children:"Reading its file…"})})]})})}function GB({agent:e,all:t,onSaved:s}){var I;const r=le(()=>T.agentTools(e.id),[e.id,e.tools.join(",")]),[i,a]=f.useState(null),[l,o]=f.useState(()=>new Set((e.roles??[]).filter(qy))),[c,u]=f.useState((e.roles??[]).filter(A=>!qy(A)).join(", ")),[d,h]=f.useState(!1),[m,p]=f.useState(null),[g,y]=f.useState(null),b=(A,_)=>A.split(_).map(z=>z.trim()).filter(z=>z!==""),x=((I=r.data)==null?void 0:I.granted)??e.tools,v=i??x,j=r.data!==void 0&&!aB(v,x),w=Qy(l,b(c,/[\n,]/)),S=A=>o(_=>{const z=new Set(_);return z.has(A)?z.delete(A):z.add(A),z}),N=j||!((A,_)=>A.join(",")===_.join(","))(w,Qy(new Set(e.roles??[]),e.roles??[])),C=async()=>{h(!0),p(null),y(null);try{const A=await T.updateAgentFile(e.id,{...j&&r.data?{tools:iB(r.data.groups,v)}:{},roles:w});y(A.message),a(null),r.reload(),s()}catch(A){p(A instanceof Error?A.message:String(A))}finally{h(!1)}};return n.jsx(te,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:n.jsx(vE,{dirty:N,busy:d,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:n.jsxs(Q,{children:[e.isExample?jE:null,g?n.jsx(W,{tone:"good",role:"status",children:g}):null,n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),n.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:Cx.map(A=>{const _=xD(t,A.id),z=_&&_.id!==e.id?_:void 0;return n.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(A.id),"data-on":l.has(A.id)?"true":void 0,disabled:d||e.isExample,onClick:()=>S(A.id),children:[n.jsx("span",{className:"role-chip-label",children:A.label}),n.jsx("span",{className:"role-chip-meaning",children:A.meaning}),z?n.jsxs("span",{className:"role-chip-holder",children:["Held by ",z.name,". If both claim it, the one listed first keeps it."]}):null]},A.id)})}),n.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),n.jsx(Z,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:n.jsx("input",{value:c,disabled:d||e.isExample,onChange:A=>u(A.target.value)})}),n.jsxs("div",{className:"ui-field",children:[n.jsxs("span",{className:"ui-field-label",children:["Tools · ",x.length," granted"]}),r.error?n.jsx(re,{message:r.error}):r.data?n.jsx(oB,{view:r.data,chosen:v,onChange:a,disabled:d||e.isExample}):n.jsx(ce,{children:"Loading the installed tools…"})]}),n.jsx(YB,{agentId:e.id,version:x.join(","),disabled:d||e.isExample}),qB(x)?n.jsx(QB,{agentId:e.id}):null]})})}function YB({agentId:e,version:t,disabled:s}){var g;const r=le(()=>Promise.resolve().then(()=>T.rememberedApprovals(e)),[e,t]),i=le(()=>Promise.resolve().then(()=>T.connections()).catch(()=>null),[]),[a,l]=f.useState(null),[o,c]=f.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const d=async(y,b)=>{l(y),c(null);try{await T.setRememberedApproval(e,y,b),r.reload()}catch(x){c(x instanceof Error?x.message:String(x))}finally{l(null)}},h=new Map;for(const y of u)h.set(y.connection,[...h.get(y.connection)??[],y]);const m=y=>{var b,x;return((x=(b=i.data)==null?void 0:b.connections.find(v=>v.slug===y))==null?void 0:x.name)??y},p=y=>y.tool.split(".").slice(2).join(".")||y.tool;return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:[...h].map(([y,b])=>{const x=b.filter(S=>S.rememberable),v=b.filter(S=>!S.rememberable),j=x.filter(S=>S.remembered),w=n.jsxs("span",{className:"remembered-summary",children:[n.jsx("span",{className:"remembered-name",children:m(y)}),n.jsxs("span",{className:"ui-card-meta",children:[` · ${b.length} ask first`,j.length>0?` · ${j.length} remembered: ${j.map(p).join(", ")}`:""]})]});return n.jsxs(Ct,{summary:w,boxed:!0,children:[n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(y)}: remember my approval`,children:x.map(S=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:S.remembered,disabled:s||a!==null,onChange:k=>void d(S.tool,k.target.checked),"aria-label":`Remember my approval for ${S.tool}`}),n.jsx("span",{className:"mono",children:p(S)})]},S.tool))}),v.length>0?n.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",n.jsx("span",{className:"mono",children:v.map(p).join(", ")})]}):null]},y)})}),n.jsx(re,{message:o}),n.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function qB(e){return e.some(t=>t==="owner.notify"||t==="owner.*"||t==="owner.notify?"||t==="owner.*?")}function QB({agentId:e}){var d,h;const t=le(()=>T.notificationSettings(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(null),c=s??((h=(d=t.data)==null?void 0:d.settings.agents)==null?void 0:h.muted.includes(e))??!1,u=m=>{a(!0),o(null),r(m),T.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>a(!1))};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Messages to you"}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:c,disabled:i||!t.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),n.jsx("span",{children:"Mute its messages"})]}),n.jsx(re,{message:t.error??l}),n.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function Fp(e){if(e.avatar)return/^[A-Za-z0-9_-]+\.(png|jpe?g|gif|webp)$/i.test(e.avatar)?{kind:"image",url:`/api/agents/${encodeURIComponent(e.id)}/avatar`}:{kind:"emoji",value:e.avatar.slice(0,8)}}function JB({agent:e,avatar:t,onEmoji:s,onChanged:r,disabled:i}){const[a,l]=f.useState(null),[o,c]=f.useState(!1),[u,d]=f.useState(null),h=t.trim()!==""&&(t.trim()!==(e.avatar??"")||!e.picture),m=a??(h?{kind:"emoji",value:t.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async g=>{if(d(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await T.uploadAgentPicture(e.id,await gE(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(So))}catch(y){d(y instanceof Error?y.message:String(y))}finally{l(null),c(!1)}};return n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Face"}),n.jsx(BB,{face:m,label:"Face",kept:e.picture,disabled:i||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:n.jsx(XB,{agent:e,onChanged:r})}),u?n.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function XB({agent:e,onChanged:t}){const[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(null),[d,h]=f.useState(null),[m,p]=f.useState(0);f.useEffect(()=>{if(!s)return a(null);const N=URL.createObjectURL(s);return a(N),()=>URL.revokeObjectURL(N)},[s]);const g=N=>{r(null),p(C=>C+1),h(N),t(),window.dispatchEvent(new Event(So))},y=async N=>{o(!0),u(null),h(null);try{g(await N())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},b=()=>y(async()=>(await T.uploadAgentPicture(e.id,s)).note??null),x=()=>y(async()=>(await T.removeAgentPicture(e.id),null)),v={avatar:Fp(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...i??e.picture?{picture:i??e.picture}:{}},[j,w]=f.useState(!1),S=f.useRef(null),k=N=>{u(null),h(null),r(N??null)};return n.jsxs("div",{className:"setup-upload","data-dragging":j?"true":void 0,onDragOver:N=>{N.preventDefault(),l||w(!0)},onDragLeave:()=>w(!1),onDrop:N=>{var C;N.preventDefault(),w(!1),l||k((C=N.dataTransfer.files)==null?void 0:C[0])},children:[n.jsxs(J,{children:[n.jsx(Es,{id:e.id,name:e.name,size:"xl",face:v}),n.jsx("input",{ref:S,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:N=>{var C;return k((C=N.target.files)==null?void 0:C[0])}},m),n.jsx(R,{disabled:l,onClick:()=>{var N;return(N=S.current)==null?void 0:N.click()},children:"Upload a picture"}),n.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),n.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?n.jsx(R,{variant:"ghost",disabled:l,onClick:()=>void x(),children:"Remove picture"}):null,n.jsx(R,{variant:"accent",disabled:!s||l,onClick:()=>void b(),children:"Save picture"})]}),c?n.jsx("span",{className:"critical save-error",role:"alert",children:c}):n.jsx("span",{className:"ui-field-hint",children:d??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function ZB({agentId:e,accounts:t,onRun:s}){const r=t.bindings.find(p=>p.agentId===e),[i,a]=f.useState((r==null?void 0:r.accountId)??""),[l,o]=f.useState((r==null?void 0:r.model)??""),[c,u]=f.useState(!1),d=t.accounts.find(p=>p.id===i),h=i!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=t.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return n.jsxs("div",{className:"ui-stack",children:[n.jsxs(J,{valign:"end",children:[n.jsx(Z,{label:"Account",children:n.jsxs("select",{value:i,disabled:c,onChange:p=>{var g;a(p.target.value),o(((g=t.accounts.find(y=>y.id===p.target.value))==null?void 0:g.defaultModel)??"")},children:[n.jsx("option",{value:"",children:"Choose an account"}),t.accounts.map(p=>n.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),n.jsx(pv,{accountId:d!=null&&d.configured?i:void 0,label:"Model",value:l,onChange:o,disabled:c},`${i}:${d==null?void 0:d.revision}`)]}),n.jsxs(J,{children:[h&&i&&l.trim()?n.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):n.jsx("span",{className:"muted",children:m?`Running on ${m.label} with ${(r==null?void 0:r.model)??"no model"}.`:"No account chosen yet: this agent cannot run until you save one."}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsx(R,{variant:"accent",disabled:c||!i||!l.trim()||!h,onClick:()=>{u(!0),s(T.assignProviderAccount(e,i,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const e5=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],Af=e=>e.tools.some(t=>e5.includes(t)),t5=["front-desk","maker"],n5={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function s5({agent:e,all:t,onSaved:s}){const[r,i]=f.useState(e.delegates),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,d]=f.useState(!1),[h,m]=f.useState(e.delegates),[p,g]=f.useState(e.asksEveryone),[y,b]=f.useState(!1),x=t.filter(A=>A.id!==e.id),v=t5.find(A=>{var _;return(_=e.roles)==null?void 0:_.includes(A)}),j=p===void 0||y,w=y||[...r].sort().join(",")!==[...h].sort().join(","),S=t.filter(A=>A.id!==e.id&&(A.delegates.includes(e.id)||A.asksEveryone!==void 0&&!Af(e))),k=A=>i(_=>_.includes(A)?_.filter(z=>z!==A):[..._,A]),N=async A=>{l(!0),c(null),d(!1);try{const _=await T.setDelegates(e.id,A);m(_.delegates),i(_.delegates),g(_.asksEveryone),b(!1),d(!0),s()}catch(_){c(_ instanceof Error?_.message:String(_))}finally{l(!1)}},C=()=>{i(x.filter(A=>!Af(A)).map(A=>A.id)),b(!0),d(!1)},I=w?"Not saved yet.":u?"Saved. Applies to the next run.":j?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return n.jsx(te,{title:"Delegation",aside:e.tools.includes("agent.delegate")?"holds agent.delegate":"no agent.delegate tool: it cannot ask anyone until granted",panel:!0,foot:e.isExample?void 0:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:w?"warning":"muted",children:I}),n.jsx("span",{className:"ui-toolbar-spacer"}),j&&v!==void 0?n.jsx(R,{disabled:a,onClick:()=>void N(["*"]),children:"Let it ask everyone"}):null,j?n.jsx(R,{variant:"accent",disabled:!w||a,onClick:()=>void N(r),children:"Save who it can ask"}):n.jsx(R,{variant:"accent",disabled:a,onClick:C,children:"Limit to…"})]}),children:n.jsxs(Q,{divided:!0,children:[n.jsxs(te,{title:"Can ask",children:[e.isExample?n.jsx(W,{tone:"warning",children:"This agent ships with buddi, so its allowlist is read-only here. Ask Agent Father to make it yours, then it can change."}):null,n.jsx(re,{message:o}),j?x.length===0?n.jsx(ce,{children:"Nobody else is installed."}):n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),n.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:x.map(A=>{const _=Af(A);return n.jsxs("li",{className:"ui-list-row",children:[n.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${A.id}`,checked:r.includes(A.id),disabled:_||e.isExample||a,onChange:()=>k(A.id)}),n.jsxs("label",{htmlFor:`can-ask-${e.id}-${A.id}`,className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[A.name," ",n.jsxs("span",{className:"mono muted",children:["@",A.handle]})]}),n.jsx("span",{className:"ui-list-sub",children:_?"Makes and changes agents. Never reachable by delegation.":A.description})]})]},A.id)})})]}):n.jsxs("p",{className:"ui-card-meta",children:[n5[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),n.jsx(te,{title:"Asked by",children:S.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):n.jsx(eL,{children:S.map(A=>n.jsx(ve,{children:A.name},A.id))})})]})})}const r5=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"}],i5=[{id:"conversations",label:"Conversations"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"memory",label:"Memory"},{id:"skills",label:"Skills"},{id:"setup",label:"Setup"}];function a5({hash:e,timezone:t,navigate:s,agents:r,attention:i,defaultAgentId:a}){var x,v,j,w,S;const l=ZO(e),o=((x=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:x[1])??"team",c=k=>N=>{N.preventDefault(),s(k)},u=le(()=>T.agents(),[]),d=qx(),h=le(()=>T.offers(),[],2e4),m=uC(),p=(((v=h.data)==null?void 0:v.offers.length)??0)+m.offers.length,g=((w=(j=u.data)==null?void 0:j.default)==null?void 0:w.defaultAgentId)??a??null,y=r.find(k=>k.roles.includes(Zd)),b=XC(r,g);return n.jsxs("div",{className:"ui-page",children:[n.jsx(th,{title:"Agents",lede:`Your team. Each one is a file on ${d} — what it can reach is listed on its page.`,actions:y?n.jsx(Ut,{variant:"accent",href:Je(y.id),onClick:c(Je(y.id)),children:"Add an agent"}):null}),n.jsx(Yo,{children:r5.map(k=>n.jsx(Ha,{href:k.id==="team"?gt:`${gt}?tab=${k.id}`,active:o===k.id,count:k.id==="offers"?p:void 0,onClick:c(k.id==="team"?gt:`${gt}?tab=${k.id}`),children:k.label},k.id))}),o==="missions"?n.jsx(qC,{timezone:t,embedded:!0}):null,o==="offers"?n.jsx(dC,{offers:m.offers,reload:m.reload}):null,o==="offers"?n.jsx(JC,{embedded:!0}):null,o==="reminders"?n.jsx(nE,{timezone:t,embedded:!0}):null,o==="team"&&b?n.jsx(_p,{navigate:s,standing:!0}):null,o==="team"?n.jsx(l5,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?n.jsx(Zt,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):n.jsx("div",{className:"agents-grid",children:n1(r,g).map(k=>{const N=Xd(i.get(k.id));return n.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Vo(Ko(k)),"data-unavailable":k.available?void 0:"true",children:[n.jsx("div",{className:"agent-card-top"}),n.jsx("div",{className:"agent-card-face",children:n.jsx(Es,{id:k.id,name:k.name,size:"xl",unavailable:!k.available,face:k})}),n.jsxs("div",{children:[n.jsxs("div",{className:"ui-card-title",children:[n.jsx("a",{className:"agent-card-link",href:xt(k.id,"conversations"),onClick:c(xt(k.id,"conversations")),children:k.name}),n.jsxs("span",{className:"agent-card-handle mono faint",children:["@",k.handle]})]}),n.jsx("p",{className:"ui-card-meta agent-card-desc",children:k.description})]}),n.jsxs("div",{className:"ui-row",children:[k.id===g?n.jsx(Ia,{children:"front desk"}):null,N?n.jsx(ve,{tone:"critical",dot:!0,children:"waiting for you"}):k.available?n.jsx(ve,{tone:"good",dot:!0,children:"ready"}):n.jsx(ve,{tone:"warning",children:Vs(k.unavailableReason??"cannot run",60)}),n.jsx(ve,{mono:!0,children:k.model}),n.jsx(Ut,{className:"agent-card-talk",size:"sm",href:Je(k.id),onClick:c(Je(k.id)),"aria-label":`Talk to ${k.name}`,children:"Talk"})]})]},k.id)})}):null,o==="team"&&!b?n.jsx(_p,{navigate:s,standing:!0}):null,l?n.jsx(kt,{title:((S=r.find(k=>k.id===l.agentId))==null?void 0:S.name)??l.agentId,size:"wide",onClose:()=>s(gt),children:n.jsx(o5,{agentId:l.agentId,agent:r.find(k=>k.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:t,navigate:s,attention:i})}):null]})}function l5({data:e,error:t,reload:s}){const r=e==null?void 0:e.default,[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(null),[d,h]=f.useState(null);if(t)return n.jsx(re,{message:t});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=i??m??"",g=p!==""&&p!==m,y=r.problem,b=v=>v.map(j=>{var w;return((w=r.choices.find(S=>S.id===j))==null?void 0:w.name)??j}).join(" and "),x=async()=>{o(!0),u(null),h(null);try{const v=await T.setDefaultAgent(p);h(v.note),a(null),s()}catch(v){u(v instanceof Error?v.message:String(v))}finally{o(!1)}};return n.jsx(Ze,{children:n.jsxs("div",{className:"ui-stack",children:[n.jsx(re,{message:c}),(y==null?void 0:y.code)==="multiple-defaults"?n.jsx(W,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${b(y.agents)}. The one chosen here wins.`}):(y==null?void 0:y.code)==="no-default-agent"?n.jsx(W,{tone:"warning",role:"status",children:"No agent file claims the default and this installation has not recorded one. Choose who answers when you name nobody."}):null,d?n.jsx(W,{tone:"good",role:"status",children:d}):null,n.jsxs(J,{children:[n.jsxs("div",{className:"default-agent-text",children:[n.jsx("h3",{className:"default-agent-title",children:"Default agent"}),n.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),n.jsx("span",{className:"ui-toolbar-spacer"}),n.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:v=>a(v.target.value),children:[p===""?n.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(v=>n.jsxs("option",{value:v.id,disabled:!v.available,children:[v.name," @",v.handle,v.available?"":" (cannot run)"]},v.id))]}),n.jsx(R,{variant:"accent",disabled:l||!g,onClick:()=>void x(),children:"Save"})]})]})})}function o5({agentId:e,agent:t,agents:s,tab:r,section:i,timezone:a,navigate:l,attention:o}){const c=h=>m=>{m.preventDefault(),l(h)},u=Xd(o.get(e)),d=(t==null?void 0:t.name)??e;return n.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[n.jsxs("header",{className:"agent-head",children:[n.jsx(Es,{id:e,name:d,size:"xl",unavailable:t?!t.available:!1,face:t}),n.jsxs("div",{className:"agent-head-text",children:[n.jsx("p",{className:"ui-page-lede",children:(t==null?void 0:t.description)??"This agent is not in the roster right now."}),n.jsxs("div",{className:"ui-row",children:[t?n.jsxs("span",{className:"muted mono",children:["@",t.handle]}):null,t?n.jsx("span",{className:"muted",children:t.model}):null,u?n.jsx(ve,{tone:"critical",children:u}):t&&!t.available?n.jsx(ve,{tone:"warning",children:t.unavailableReason??"cannot run"}):null]})]}),n.jsx("div",{className:"ui-page-actions",children:n.jsxs(Ut,{variant:"accent",href:Je(e),onClick:c(Je(e)),children:["Talk to ",d]})})]}),t&&!t.available?n.jsxs(W,{tone:"warning",role:"status",children:[i1(t)," ",n.jsx("a",{href:Be(tp(t).section),children:tp(t).label})]}):null,n.jsx(Yo,{children:i5.map(h=>n.jsx(Ha,{href:xt(e,h.id),active:r===h.id,onClick:c(xt(e,h.id)),children:h.label},h.id))}),r==="conversations"?n.jsx(c5,{agentId:e,navigate:l}):null,r==="missions"?n.jsx(qC,{timezone:a,embedded:!0,agentId:e}):null,r==="offers"?n.jsx(JC,{embedded:!0,agentId:e,agentName:d}):null,r==="reminders"?n.jsx(nE,{timezone:a,embedded:!0,agentId:e}):null,r==="memory"?n.jsx(ZC,{embedded:!0,agents:s,timezone:a,agentId:e}):null,r==="skills"?n.jsx(Z6,{agentId:e,agentName:d}):null,r==="setup"?n.jsx(HB,{agentId:e,section:i,navigate:l}):null]})}function c5({agentId:e,navigate:t}){const{data:s,error:r}=le(()=>Fe.conversations(e,50),[e]);if(r)return n.jsx(ce,{children:r});const i=(s==null?void 0:s.conversations)??[];return n.jsx(Ze,{flush:!0,children:s?i.length===0?n.jsx(Zt,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):n.jsx(yt,{children:i.map(a=>n.jsx(ft,{href:Je(e,a.id),onClick:()=>t(Je(e,a.id)),title:Vs(a.preview||a.opening||"Untitled conversation",90),sub:`${a.messageCount} message${a.messageCount===1?"":"s"}`,side:ze(a.lastMessageAt??a.startedAt??a.createdAt??null)},a.id))}):n.jsx(ce,{children:"Loading…"})})}const ab=3,u5=40;function d5({agent:e,navigate:t}){var g;const s=f.useRef(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(null),u=le(()=>Fe.conversations(e.id,ab),[e.id],3e4),d=Li(rv),h=Li("(pointer: coarse)");f.useEffect(()=>{var y;!d&&!h&&((y=s.current)==null||y.focus())},[]);const m=(y,b)=>{i(!0),l(null),(async()=>{try{const{conversationId:x}=await Fe.startConversation(e.id),v=await Fe.send(e.id,{conversationId:x,text:y,...b.length>0?{attachmentIds:b.map(j=>j.artifactId)}:{}});t(Je(e.id,v.conversationId))}catch(x){l(x instanceof ge?x.message:String(x)),c({text:y,at:Date.now()}),i(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,ab);return n.jsxs("div",{className:"home-ask",children:[a?n.jsx(re,{message:a}):null,n.jsx(Qx,{ref:s,disabled:r||!e.available,running:!1,onSend:m,onStop:()=>{},agentName:e.name,placeholder:`Message ${e.name}…`,draft:o,threadKey:`home.${e.id}`,slim:!0}),p.length>0?n.jsxs("div",{className:"home-continue",children:[n.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),n.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(y=>{const b=Je(e.id,y.id),x=y.opening??y.preview??"Untitled conversation",v=YN(y.lastMessageAt??y.createdAt??y.startedAt??null);return n.jsx("li",{children:n.jsxs("a",{className:"home-continue-chip",href:b,title:x,onClick:j=>{j.preventDefault(),t(b)},children:[n.jsx("span",{className:"home-continue-title",children:Vs(x,u5)}),v?n.jsx("span",{className:"home-continue-when",children:v}):null]})},y.id)})})]}):null]})}function h5(e){const t=e.indexOf("?");if(t===-1)return;const s=new URLSearchParams(e.slice(t+1)).get("tip");return s&&/^[a-z0-9-]{1,40}$/.test(s)?s:void 0}function f5({navigate:e,preview:t,hidden:s}){var c;const r=le(()=>T.currentTip(t),[t]),[i,a]=f.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||i===l.id||s)return null;const o=u=>{a(l.id),!t&&(u==="dismiss"?T.dismissTip(l.id):T.laterTip(l.id)).catch(()=>{})};return n.jsx("div",{className:"home-tip","data-tip":l.id,children:n.jsxs(W,{children:[n.jsxs("div",{className:"ui-notice-row",children:[n.jsx("p",{className:"ui-notice-body",children:l.text}),n.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Not now",title:"Not now",onClick:()=>o("later"),children:n.jsx(ye,{name:"close"})})]}),n.jsxs(J,{children:[n.jsx(Xt,{}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),n.jsx(R,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const zp="buddi.tipsOpen";function m5(e){const t=new Date(`${e}T12:00:00Z`);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",timeZone:"UTC"}).format(t)}function p5(e){switch(e.status){case"today":return"Due today";case"holding":return"Waiting";case"quiet":return"Not needed now";case"dismissed":return"Dismissed";case"shown":return e.shownAt?`Shown on ${m5(e.shownAt)}`:"Shown"}}function g5(){try{return window.localStorage.getItem(zp)==="1"}catch{return!1}}function x5(){const e=le(()=>T.tips(),[]),[t,s]=f.useState(g5),r=f.useCallback(i=>{s(i);try{i?window.localStorage.setItem(zp,"1"):window.localStorage.removeItem(zp)}catch{}},[]);return{open:t,setOpen:r,list:e}}function v5({tips:e}){const{open:t,setOpen:s,list:r}=e,i=!!r.data&&!r.data.enabled&&r.data.tips.some(a=>a.status==="today");return n.jsxs("button",{type:"button",className:"ui-icon-btn home-tips-btn","aria-label":i?"Tips, one due today":"Tips","aria-pressed":t,title:"Tips","data-open":t,onClick:()=>{t||r.reload(),s(!t)},children:[n.jsx(ye,{name:"bulb"}),i?n.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function j5({tips:e,navigate:t}){var b,x;const{open:s,setOpen:r,list:i}=e,[a,l]=f.useState(null),[o,c]=f.useState(null),[u,d]=f.useState(null);if(!s)return null;const h=((b=i.data)==null?void 0:b.tips)??null,m=u??((x=i.data)==null?void 0:x.enabled)??!0,p=v=>l(v instanceof ge?v.message:String(v)),g=v=>{c(v),l(null),T.restoreTip(v).then(()=>i.reload(),p).finally(()=>c(null))},y=v=>{c("switch"),l(null),d(v),T.saveTipsSettings(v).then(j=>{d(j.enabled),i.reload()}).catch(j=>{d(!v),p(j)}).finally(()=>c(null))};return n.jsx("div",{className:"home-tips","data-testid":"tips-section",children:n.jsxs(te,{title:"Tips",children:[n.jsx(re,{message:i.error??a}),n.jsx("div",{className:"tips-grid",children:(h??[]).map(v=>n.jsx("div",{className:"tips-card","data-tip":v.id,"data-status":v.status,children:n.jsxs(ks,{tone:v.status==="today"?"accent":void 0,children:[n.jsx("div",{children:n.jsx(ve,{tone:v.status==="today"?"accent":"muted",children:p5(v)})}),n.jsx("p",{className:"tips-card-text",children:v.text}),n.jsxs(J,{children:[n.jsx(Xt,{}),v.status==="dismissed"?n.jsx(R,{size:"sm",disabled:o===v.id,onClick:()=>g(v.id),children:"Bring back"}):n.jsx(R,{size:"sm",variant:v.status==="today"?"accent":void 0,onClick:()=>t(v.action.route),children:v.action.label})]})]})},v.id))}),n.jsxs(J,{children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||h===null,onChange:v=>y(v.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx(Xt,{}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const y5=3;function yE(e,t=new Set){return(e??[]).filter(s=>!s.hidden&&!t.has(s.id)).slice(0,y5)}function w5(e){return yE(e).find(t=>t.card!==void 0)??null}function wE(e){const[t,s]=f.useState(new Set);return{hiddenHere:t,hide:i=>{s(a=>new Set(a).add(i.id)),T.setGlanceHidden(i.id,!0).then(()=>e==null?void 0:e(),()=>{s(a=>{const l=new Set(a);return l.delete(i.id),l})})}}}function bE(e){return e.link?F1(e.link.plugin,e.link.page,e.link.place):null}function b5({glances:e,navigate:t,onChanged:s,except:r}){const{hiddenHere:i,hide:a}=wE(s),l=yE(e,i).filter(o=>o.id!==r);return l.length===0?null:n.jsx("span",{className:"home-glances",children:l.map(o=>{const c=bE(o),u=n.jsxs(n.Fragment,{children:[n.jsx(ye,{name:qo(o.icon),size:14}),n.jsx("span",{children:o.text})]});return n.jsxs("span",{className:"home-glance",children:[n.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c?n.jsx("a",{className:"home-glance-text",href:c,onClick:d=>{d.preventDefault(),t(c)},children:u}):n.jsx("span",{className:"home-glance-text",children:u}),n.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${o.title} from Home`,title:"Hide from Home",onClick:()=>a(o),children:n.jsx(ye,{name:"close",size:10})})]},o.id)})})}function k5(e){const i=Math.min(...e),l=Math.max(...e)-i||1,o=Math.max(e.length-1,1);return e.map((c,u)=>[u/o*100,2+(1-(c-i)/l)*(24-2*2)])}function S5({points:e}){const t=k5(e).map(([s,r])=>`${s.toFixed(1)},${r.toFixed(1)}`);return n.jsxs("svg",{className:"home-spark",viewBox:"0 0 100 24",preserveAspectRatio:"none","aria-hidden":"true","data-testid":"spark",children:[n.jsx("path",{d:`M0,24 L${t.join(" L")} L100,24 Z`,fill:"currentColor",opacity:"0.12",stroke:"none"}),n.jsx("polyline",{points:t.join(" "),fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})}function N5({glance:e,navigate:t,onChanged:s,blob:r}){const{hiddenHere:i,hide:a}=wE(s),l=e.card;if(!l||i.has(e.id))return n.jsx(n.Fragment,{children:r});const o=bE(e),c=n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"home-weather-now",children:[n.jsx("span",{className:"home-weather-icon",children:n.jsx(ye,{name:qo(e.icon),size:30})}),n.jsx("span",{className:"home-weather-value",children:l.value})]}),l.caption?n.jsx("span",{className:"home-weather-caption",children:l.caption}):null,l.trend?n.jsxs("span",{className:"home-weather-trend",children:[n.jsx(S5,{points:l.trend.points}),l.trend.label?n.jsx("span",{children:l.trend.label}):null]}):null,l.foot?n.jsx("span",{className:"home-weather-foot",children:l.foot}):null]});return n.jsxs("div",{className:"home-weather",role:"group","aria-label":e.title,children:[o?n.jsx("a",{className:"home-weather-main",href:o,onClick:u=>{u.preventDefault(),t(o)},children:c}):n.jsx("div",{className:"home-weather-main",children:c}),r,n.jsx("button",{type:"button",className:"home-weather-hide","aria-label":`Hide ${e.title} from Home`,title:"Hide from Home",onClick:()=>a(e),children:n.jsx(ye,{name:"close",size:10})})]})}const kE="buddi.needsYouView";function C5(){try{return window.localStorage.getItem(kE)==="list"?"list":"deck"}catch{return"deck"}}function E5(e){try{window.localStorage.setItem(kE,e)}catch{}}function A5(e,t,s){const r=(t.alsoFrom??[]).filter(i=>i!==t.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function T5({rows:e,agents:t,label:s,onOpen:r,onDone:i}){const[a,l]=f.useState(0);if(e.length===0)return n.jsx(ce,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(a,e.length-1),c=e[o],u=e.length>1,d=y=>l((o+y+e.length)%e.length),h=()=>r(c),m=()=>i(c),p=y=>{const b=y.target;b.closest('input, textarea, select, [contenteditable="true"]')||(y.key==="ArrowRight"&&u?(y.preventDefault(),d(1)):y.key==="ArrowLeft"&&u?(y.preventDefault(),d(-1)):y.key==="Enter"&&!b.closest("button, a")?(y.preventDefault(),c.link&&h()):(y.key==="d"||y.key==="Delete")&&!y.metaKey&&!y.ctrlKey&&!y.altKey&&(y.preventDefault(),m()))},g=n.jsxs("span",{className:"home-deck-from",children:[c.agentId?n.jsx(Nn,{agents:t,id:c.agentId,size:"sm"}):null,n.jsx("span",{children:s(c)})]});return n.jsx("div",{className:"home-deck","data-depth":Math.min(e.length-1,2),role:"region","aria-label":"Needs you, one at a time","aria-roledescription":"deck",tabIndex:0,onKeyDown:p,children:n.jsx(ks,{as:"article",title:g,meta:n.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":ze(c.createdAt)}),actions:n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>d(-1),children:n.jsx(ye,{name:"chevron-left"})}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>d(1),children:n.jsx(ye,{name:"chevron-right"})})]}),foot:n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:m,children:"Done"}),c.link?n.jsx(R,{variant:"accent",onClick:h,children:"Open"}):null]}),children:n.jsxs("div",{className:"home-deck-body",children:[n.jsx("p",{className:"home-deck-title",children:Eo(c)}),c.text?n.jsx("p",{className:"home-deck-text",children:c.text}):null]})})})}function R5({timezone:e,navigate:t,agents:s,defaultAgentId:r,attention:i,update:a,connectionSignals:l=[],hash:o=""}){var he,Me,Pe,Ye,Y,me,oe,Oe,Le,Ue,at,Rt,bn;const c=le(()=>T.overview(),[],15e3),u=le(()=>T.approvals(),[],1e4),d=le(()=>T.missions(),[],6e4),h=le(()=>T.reminders(),[],6e4),m=le(()=>T.conversations(),[],3e4),p=le(()=>T.offers(),[],3e4),g=le(()=>T.proposals(),[],6e4),y=le(()=>T.agentOffers(),[],6e4),b=le(()=>T.owner(),[]),x=le(()=>T.notifications(20),[],3e4),v=f.useMemo(()=>n1(s,r??null),[s,r]),{busy:j,note:w,failure:S,decide:k}=Jx(()=>{u.reload(),c.reload()}),N=c.data,C=s.find(V=>V.id===r)??null,I=V=>{var xe;return((xe=s.find(De=>De.id===V))==null?void 0:xe.name)??V},A=V=>xe=>{xe.preventDefault(),t(V)},_=((he=u.data)==null?void 0:he.pending)??[],z=((Me=N==null?void 0:N.jobs)==null?void 0:Me.failed)??0,L=((Pe=N==null?void 0:N.sentinels)==null?void 0:Pe.openUrgent)??0,E=((Ye=g.data)==null?void 0:Ye.open.length)??0,M=(((Y=y.data)==null?void 0:Y.offers)??[]).filter(V=>!_.some(xe=>cC(xe,V.plugin,V.agent))),D=$5(((me=x.data)==null?void 0:me.notifications)??[],_),[U,$]=f.useState(new Set),[B,O]=f.useState(C5),K=D.filter(V=>!U.has(V.id)),G=V=>{$(xe=>new Set(xe).add(V.id)),T.notificationSeen(V.id).catch(()=>{})},se=V=>{G(V),V.link&&t(V.link)},ue=V=>A5(V.agentId?I(V.agentId):V.pluginId??P5[V.kind],V,I),ie=_.length+(z>0?1:0)+(L>0?1:0)+(N!=null&&N.paused?1:0)+(E>0?1:0)+M.length+D.length,ee=f.useMemo(()=>{var V,xe;return _5(((V=d.data)==null?void 0:V.missions)??[],((xe=h.data)==null?void 0:xe.reminders)??[])},[d.data,h.data]),X=(((oe=m.data)==null?void 0:oe.conversations)??[]).slice(0,5),de=((Oe=p.data)==null?void 0:Oe.offers)??[],Ie=de.slice(0,M5),Se=x5(),we=de.length-Ie.length,Ce=w5(N==null?void 0:N.glances),mt=B5({approvals:_.length,failed:z,urgent:L,paused:(N==null?void 0:N.paused)??!1,proposals:E,agentsToSetUp:M.length,messages:D.length});return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"home-band",children:n.jsxs("header",{className:"home-top","data-card":Ce?"true":void 0,children:[n.jsxs("div",{className:"home-top-text",children:[n.jsxs("p",{className:"home-date",children:[n.jsx("span",{children:z5(N==null?void 0:N.now,e)}),n.jsx(b5,{glances:N==null?void 0:N.glances,navigate:t,onChanged:()=>c.reload(),except:Ce==null?void 0:Ce.id}),n.jsx(v5,{tips:Se})]}),n.jsx("h1",{className:"home-greeting",children:F5(N==null?void 0:N.now,e,((Le=b.data)==null?void 0:Le.preferredName)||((Ue=b.data)==null?void 0:Ue.displayName))}),n.jsx(W5,{items:mt,navigate:t})]}),n.jsx("div",{className:"home-side",children:Ce?n.jsx(N5,{glance:Ce,navigate:t,onChanged:()=>c.reload(),blob:n.jsx(sp,{size:"lg",anim:"idle"})}):n.jsx(sp,{size:"lg",anim:"idle"})})]})}),n.jsxs("div",{className:"home",children:[C?n.jsx(d5,{agent:C,navigate:t},C.id):null,n.jsx(j5,{tips:Se,navigate:t}),n.jsx(f5,{navigate:t,preview:h5(o),hidden:Se.open}),a&&a.updateAvailable&&!a.checkout&&a.latest?n.jsx(W,{tone:"accent",children:n.jsxs("p",{children:["A newer buddi is ready: ",n.jsx("span",{className:"mono",children:a.latest}),"."," ",n.jsx("a",{href:Be("system"),onClick:A(Be("system")),children:"Upgrade from Settings → Version."})]})}):null,l.map(V=>n.jsx(W,{tone:"accent",children:n.jsxs("p",{children:[V.sentence," ",n.jsx("a",{href:Be("connections"),onClick:A(Be("connections")),children:"Settings → Connections."})]})},V.id)),n.jsx(re,{message:c.error??u.error??S}),w?n.jsx(W,{tone:"good",role:"status",children:w}):null,ie>0?n.jsx("div",{id:SE,className:"home-needs",children:n.jsx(te,{title:"Needs you",actions:D.length>0?n.jsx(ls,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:B,onChange:V=>{O(V),E5(V)}}):void 0,children:n.jsxs(Q,{children:[N!=null&&N.paused?n.jsxs(W,{tone:"warning",title:"The installation is paused.",children:["Nothing is being claimed until you resume it."," ",n.jsx(R,{size:"sm",onClick:()=>{T.setPaused(!1).then(()=>c.reload())},children:"Resume"})]}):null,_.map(V=>n.jsx(Xx,{action:V,timezone:e,busy:j===V.id,onDecide:k,agentName:I(V.agentId)},V.id)),D.length>0&&B==="deck"?n.jsx(T5,{rows:K,agents:s,label:ue,onOpen:se,onDone:G}):null,D.length>0&&B==="list"?n.jsx(Ze,{flush:!0,children:n.jsx(yt,{children:K.map(V=>n.jsx(ft,{href:V.link??void 0,onClick:()=>se(V),lead:V.agentId?n.jsx(Nn,{agents:s,id:V.agentId,size:"sm"}):void 0,title:Eo(V),sub:ue(V),side:V.state==="held"?"today":ze(V.createdAt)},V.id))})}):null,z>0?n.jsx(W,{tone:"critical",children:n.jsxs("a",{href:`${dt}/jobs?state=failed`,onClick:A(`${dt}/jobs?state=failed`),children:[z," failed job",z===1?"":"s",". See why, then retry or cancel them, one by one or all at once."]})}):null,L>0?n.jsx(W,{tone:"critical",children:n.jsxs("a",{href:`${dt}/alerts`,onClick:A(`${dt}/alerts`),children:[L," urgent alert",L===1?"":"s"," from your watchers."]})}):null,M.map(V=>n.jsx(Ze,{children:n.jsx(ev,{plugin:V.plugin,agent:V.agent,text:V.text,label:`Create @${V.handle}`,handle:V.handle,onDismiss:()=>{T.dismissAgentOffer(V.plugin,V.agent).then(()=>y.reload())}})},`${V.plugin}/${V.agent}`)),E>0?n.jsx(W,{tone:"accent",children:n.jsxs("a",{href:Be("proposals"),onClick:A(Be("proposals")),children:[E," proposal",E===1?"":"s"," from your agents to keep or discard."]})}):null,(((at=N==null?void 0:N.sentinels)==null?void 0:at.errors)??[]).map(V=>n.jsxs(W,{tone:"warning",children:["Watcher ",V.sentinelId," failed: ",V.error]},V.sentinelId)),((N==null?void 0:N.mail)??[]).filter(V=>V.lastError).map(V=>n.jsxs(W,{tone:"warning",children:["Source ",V.sourceId,": ",V.lastError]},V.sourceId))]})})}):null,n.jsx(te,{title:"Your team",aside:n.jsx("a",{href:gt,onClick:A(gt),children:"All agents"}),children:s.length===0?n.jsx(ce,{mascot:!0,children:"No agents yet. Add one under Agents."}):n.jsx("div",{className:"home-team",children:v.map(V=>{const xe=Xd(i.get(V.id));return n.jsxs("a",{className:"home-face",...Vo(Ko(V)),href:Je(V.id),onClick:A(Je(V.id)),"data-waiting":xe?"true":void 0,"data-unavailable":V.available?void 0:"true",children:[n.jsx(Es,{id:V.id,name:V.name,size:"lg",unavailable:!V.available,face:V}),n.jsxs("span",{className:"home-face-text",children:[n.jsx("span",{className:"home-face-name",children:V.name}),n.jsx("span",{className:"home-face-status",children:xe?H5(xe):V.available?Vs(V.description,60):V.unavailableReason??"Cannot run right now."})]})]},V.id)})})}),XC(s,r)?n.jsx(_p,{navigate:t}):null,Ie.length>0?n.jsx(te,{title:"On offer",aside:n.jsxs("span",{className:"ui-row",children:[we>0?n.jsxs("a",{href:`${gt}?tab=offers`,onClick:A(`${gt}?tab=offers`),children:[we," more"]}):null,n.jsx(QC,{ids:de.map(V=>V.id),onDone:()=>p.reload()})]}),children:n.jsx("div",{className:"home-offers",children:Ie.map(V=>n.jsx(D5,{offer:V,agents:s,open:A(xt(V.agentId,"offers")),onDismissed:()=>p.reload()},V.id))})}):null,n.jsx(i6,{}),(bn=(Rt=g.data)==null?void 0:Rt.digest)!=null&&bn.latest?n.jsx(U5,{digest:g.data.digest.latest,go:A}):null,n.jsxs("div",{className:"home-columns",children:[n.jsx(te,{title:"Coming up",aside:n.jsx("a",{href:`${gt}?tab=missions`,onClick:A(`${gt}?tab=missions`),children:"All missions"}),children:n.jsx(Ze,{flush:!0,children:ee.length===0?n.jsx(ce,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):n.jsx(yt,{children:ee.map(V=>n.jsx(ft,{href:V.route,onClick:()=>t(V.route),lead:n.jsx(Nn,{agents:s,id:V.agentId,size:"sm"}),title:V.title,sub:`${V.kind} for ${I(V.agentId)}`,side:ze(V.at)},V.key))})})}),n.jsx(te,{title:"Lately",aside:n.jsx("a",{href:dt,onClick:A(dt),children:"All activity"}),children:n.jsx(Ze,{flush:!0,children:X.length===0?n.jsx(ce,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):n.jsx(yt,{children:X.map(V=>n.jsx(ft,{href:Je(V.agentId,V.id),onClick:()=>t(Je(V.agentId,V.id)),lead:n.jsx(Nn,{agents:s,id:V.agentId,size:"sm"}),title:V.opening?Vs(V.opening,80):"Untitled conversation",sub:`${I(V.agentId)}, ${V.messageCount} message${V.messageCount===1?"":"s"}`,side:ze(V.lastMessageAt??V.createdAt)},V.id))})})})]}),((N==null?void 0:N.home)??[]).map(V=>n.jsx(K5,{block:V},V.id)),N!=null&&N.jobs&&N.missions?n.jsxs("p",{className:"home-foot muted",children:[_t(N.jobs.pending??0)," queued, ",_t(N.jobs.leased??0)," running, ",_t(N.missions.enabled)," of ",_t(N.missions.total)," missions on."," ",N.paused?n.jsx(ve,{tone:"warning",children:"paused"}):n.jsx(ve,{tone:"good",children:"running"})," ",n.jsx("a",{href:Wa("").replace(/\/conversations\/$/,""),onClick:A(dt),children:"Activity"})," · ",n.jsx("a",{href:Be("system"),onClick:A(Be("system")),children:"System"})]}):null]})]})}const I5=new Set(["watcher","reminder","failure","recap","plugin","agent"]),P5={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function $5(e,t){const s=new Set(t.map(r=>r.id));return e.filter(r=>I5.has(r.kind)&&r.actedAt===null&&r.state!=="stored"&&(r.seenAt===null||r.state==="held")&&!(r.actionId&&s.has(r.actionId)))}const M5=6,O5=500;function D5({offer:e,agents:t,open:s,onDismissed:r}){const[i,a]=f.useState(!1),l=f.useRef(null),o=f.useRef(!1),c=()=>{i||(a(!0),T.dismissOffer(e.id).then(r).finally(()=>a(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return n.jsxs("span",{className:"home-offer-chip",children:[n.jsxs("a",{className:"home-offer",href:xt(e.agentId,"offers"),onClick:d=>{if(o.current){o.current=!1,d.preventDefault();return}s(d)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},O5)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[n.jsx(Nn,{agents:t,id:e.agentId,size:"sm"}),n.jsx("span",{children:e.label})]}),n.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:i,onClick:c,children:"×"})]})}function _5(e,t){const s=[];for(const r of e)r.enabled&&r.nextRun&&s.push({key:`m-${r.id}`,at:r.nextRun,title:r.name,kind:"Mission",agentId:r.agentId,route:xt(r.agentId,"missions")});for(const r of t)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:xt(r.agentId,"reminders")});return s.sort((r,i)=>r.at.localeCompare(i.at)).slice(0,5)}function L5(e,t){try{const s=new Intl.DateTimeFormat("en-GB",{hour:"numeric",hourCycle:"h23",timeZone:t}).format(e?new Date(e):new Date);return Number(s)}catch{return new Date().getHours()}}function F5(e,t,s){const r=L5(e,t),i=s!=null&&s.trim()?`, ${s.trim()}`:"";return r<5?`Still up${i}?`:r<12?`Good morning${i}.`:r<18?`Good afternoon${i}.`:`Good evening${i}.`}function z5(e,t){try{const s=e?new Date(e):new Date,r=new Intl.DateTimeFormat("en-GB",{weekday:"long",timeZone:t}).format(s),i=new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"long",timeZone:t}).format(s);return`${r}, ${i}`}catch{return Ve(e??null,t)}}function Kc(e,t,s){return e.count===0?null:`${e.count} ${e.count===1?t:s}${e.names.length>0?`: ${e.names.join("; ")}${e.count>e.names.length?"; …":""}`:""}`}function U5({digest:e,go:t}){const s=[Kc(e.memory,"memory note","memory notes"),Kc(e.skills,"skill kept","skills kept"),Kc(e.rules,"rule kept","rules kept"),Kc(e.changes,"change to an agent kept","changes to agents kept")].filter(i=>i!==null),r=e.stopped===null?"Not measured yet.":e.stopped.total>0?`Rules you kept acted ${e.stopped.total} time${e.stopped.total===1?"":"s"} (${Object.entries(e.stopped.byPlugin).filter(([,i])=>i>0).map(([i,a])=>`${i} ${a}`).join(", ")}).`:"No rule you kept acted this week.";return n.jsx(te,{title:"What buddi learned this week",aside:n.jsx("span",{className:"muted",children:ze(e.at)}),children:n.jsx(Ze,{children:n.jsxs(Q,{divided:!0,children:[n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Learned"}),s.length===0?n.jsx("p",{children:"Nothing new."}):n.jsx("ul",{className:"home-digest-list",children:s.map(i=>n.jsx("li",{children:i},i))})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Proposes"}),n.jsx("p",{children:e.open>0?n.jsxs("a",{href:Be("proposals"),onClick:t(Be("proposals")),children:[e.open," proposal",e.open===1?"":"s"," waiting for you to keep or discard."]}):"Nothing was waiting for you."})]}),n.jsxs("div",{children:[n.jsx("p",{className:"ui-card-meta",children:"Stopped doing"}),n.jsx("p",{children:r})]})]})})})}const SE="home-needs";function B5(e){const t=(r,i,a=`${i}s`)=>r===1?i:a,s=[];return e.approvals>0&&s.push({key:"approvals",count:e.approvals,label:t(e.approvals,"approval")}),e.failed>0&&s.push({key:"failed",count:e.failed,label:t(e.failed,"failed job"),tone:"critical",route:`${dt}/jobs?state=failed`}),e.urgent>0&&s.push({key:"urgent",count:e.urgent,label:t(e.urgent,"urgent alert"),tone:"critical",route:`${dt}/alerts`}),e.paused&&s.push({key:"paused",count:null,label:"Paused"}),e.proposals>0&&s.push({key:"proposals",count:e.proposals,label:t(e.proposals,"proposal"),route:Be("proposals")}),e.agentsToSetUp>0&&s.push({key:"agents",count:e.agentsToSetUp,label:t(e.agentsToSetUp,"agent to set up","agents to set up")}),e.messages>0&&s.push({key:"messages",count:e.messages,label:t(e.messages,"message")}),s}function W5({items:e,navigate:t}){if(e.length===0)return n.jsx("p",{className:"home-calm",children:"Nothing needs you. Your agents are on it."});const s=()=>{var r,i;(i=(r=document.getElementById(SE))==null?void 0:r.scrollIntoView)==null||i.call(r,{behavior:"smooth",block:"start"})};return n.jsx("p",{className:"home-counts",children:e.map((r,i)=>{const a=n.jsxs(n.Fragment,{children:[r.count!==null?n.jsxs(n.Fragment,{children:[n.jsx("strong",{children:r.count})," "]}):null,r.label]});return n.jsxs(f.Fragment,{children:[i>0?n.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?n.jsx("a",{className:"home-count","data-tone":r.tone,href:r.route,onClick:l=>{l.preventDefault(),t(r.route)},children:a}):n.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:a})]},r.key)})})}function H5(e){return e.charAt(0).toUpperCase()+e.slice(1)}function K5({block:e}){const[t,s]=f.useState(!1),r=e.sensitive===!0&&!t;f.useEffect(()=>{if(!e.sensitive||!t)return;const a=()=>{document.visibilityState==="hidden"&&s(!1)};return document.addEventListener("visibilitychange",a),window.addEventListener("blur",a),()=>{document.removeEventListener("visibilitychange",a),window.removeEventListener("blur",a)}},[e.sensitive,t]);const i=n.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!r?n.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?n.jsx(R,{size:"sm",variant:"ghost","aria-pressed":!r,onClick:()=>s(a=>!a),children:r?"Show":"Hide"}):null]});return n.jsxs(te,{title:e.title,aside:i,children:[e.note?n.jsx(W,{tone:"warning",children:e.note}):null,e.stats.length>0?n.jsx(nh,{children:e.stats.map(a=>n.jsx(zs,{label:a.label,value:r?"••••":a.value,note:r?void 0:a.note,tone:r?void 0:a.tone},a.label))}):null,e.rows.length>0?r?n.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):n.jsx(Ze,{flush:!0,children:n.jsx(yt,{children:e.rows.map((a,l)=>n.jsx(ft,{title:a.title,sub:a.sub,side:a.side?n.jsx("span",{className:a.tone==="critical"?"critical":a.tone==="good"?"good":void 0,children:a.side}):void 0},`${a.title}-${l}`))})}):null]})}const V5=3e4;function NE(){const{data:e,reload:t}=le(()=>T.recovery(),[],V5),s=f.useRef(t);return s.current=t,f.useEffect(()=>{const r=()=>s.current(),i=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",i),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",i)}},[]),{data:e,reload:t}}function G5(e){return e.kind==="account"?e.accountId?sD(e.accountId):Be("accounts"):e.kind==="telegram"?Be("telegram"):Be("secrets")}function Y5(e){return e.install?iD(e.install):aD}const q5="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function Q5({active:e,onNavigate:t}){return e?n.jsxs("div",{className:"recovery-banner",role:"status",children:[n.jsx("span",{children:q5}),n.jsx("a",{href:Yy,onClick:s=>{s.preventDefault(),t(Yy)},children:"Finish the checklist"})]}):null}function J5({view:e,onLeft:t}){const{secrets:s,plugins:r,pending:i,grants:a}=e.checklist,l=e.checklist.keptTables??[],[o,c]=f.useState(!0),[u,d]=f.useState([]),[h,m]=f.useState(!1),[p,g]=f.useState(null),[y,b]=f.useState(!1),x=r.filter(S=>!S.installed||S.waiting!==void 0),v=i.jobs+i.missions+i.approvals+i.telegramChats,j=S=>{d(k=>k.includes(S)?k.filter(N=>N!==S):[...k,S])},w=()=>{m(!0),g(null),T.leaveRecovery({dropPending:o,keepGrants:u}).then(()=>{b(!0),t==null||t()}).catch(S=>g(S instanceof ge?S.message:String(S))).finally(()=>m(!1))};return n.jsx(Ze,{title:"Back from a backup",children:n.jsxs(Q,{divided:!0,children:[n.jsxs(te,{children:[n.jsx(Gt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:n.jsx("span",{className:"mono",children:e.archive??"—"})}]}),n.jsx("p",{className:"ui-card-meta",children:"Nothing runs on its own yet: no schedules, no watchers, no phone. Chat works. Go through what is below, then turn this buddi back on."})]}),n.jsx(te,{title:"Keys to paste again",children:s.length===0?n.jsx(ce,{children:"Nothing is missing."}):n.jsx(yt,{children:s.map(S=>n.jsx(ft,{title:S.label??S.name,sub:S.name?n.jsx("span",{className:"mono",children:S.name}):void 0,side:n.jsx(Ut,{size:"sm",href:G5(S),"aria-label":`Fix ${S.label??S.name}`,children:"Fix"})},`${S.kind}:${S.accountId??S.name}`))})}),n.jsx(te,{title:"Add-ons to install again",children:x.length===0&&l.length===0?n.jsx(ce,{children:"Everything the backup named is installed."}):n.jsxs(yt,{children:[x.map(S=>n.jsx(ft,{title:n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"mono",children:S.name})," ",S.version]}),sub:S.waiting?`${S.name} — ${S.waiting.note}`:S.source,side:S.installed?void 0:n.jsx(Ut,{size:"sm",href:Y5(S),"aria-label":`Install ${S.name} again`,children:S.install?"Install":"Find it"})},S.name)),l.map(S=>n.jsx(ft,{title:n.jsx("span",{className:"mono",children:S.table}),sub:S.sentence},`kept:${S.table}`))]})}),n.jsx(te,{title:"Work that was waiting",children:v===0?n.jsx(ce,{children:"Nothing was in flight when the backup was taken."}):n.jsxs(Q,{gap:"sm",children:[n.jsx(Gt,{items:[{label:"Jobs",value:String(i.jobs)},{label:"Missions",value:String(i.missions)},{label:"Waiting for an answer",value:String(i.approvals)},{label:"Phones",value:String(i.telegramChats)}]}),n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:S=>c(S.target.checked)}),n.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),n.jsx(te,{title:"Standing permissions",children:a.length===0?n.jsx(ce,{children:"No agent had a standing permission."}):n.jsxs(Q,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),n.jsx("ul",{className:"recovery-list",children:a.map(S=>n.jsx("li",{children:n.jsxs("label",{className:"recovery-check",children:[n.jsx("input",{type:"checkbox",checked:u.includes(S.id),onChange:()=>j(S.id),"aria-label":`Keep ${S.tool} for ${S.agent}`}),n.jsxs("span",{children:[n.jsx("span",{className:"mono",children:S.tool})," for ",S.agent," ",n.jsx("span",{className:"ui-card-meta",children:S.scope}),S.description?n.jsxs("span",{className:"ui-card-meta",children:[" — ",S.description]}):null]})]})},S.id))})]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:p}),y?n.jsx(W,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):n.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",disabled:h||y,onClick:w,children:"Leave recovery mode"})})]})})]})})}const X5=2e3,Z5={queued:"Getting started.",stopping:"Stopping the gateway. The database stays up.",snapshot:"Taking a copy of what is here now, first.",database:"Putting the database back.",recovery:"Marking this installation as restored.",files:"Putting the files back.",starting:"Starting back up.",encrypt:"Locking it with your passphrase.",done:"Done.",failed:"That did not work.","rolled-back":"That did not work, so everything was put back as it was."};function lb(e){return Z5[e.phase]??e.detail??e.phase}const e8=new Set(["done","failed","rolled-back"]);function CE(e){return e!==void 0&&(e8.has(e.phase)||!!e.finishedAt)}function t8(e){const[t,s]=f.useState(void 0),[r,i]=f.useState(!1),[a,l]=f.useState(null),o=f.useRef(!1);return f.useEffect(()=>{if(!e){s(void 0),i(!1),o.current=!1;return}let c=!1;const u=()=>{T.backupJob(e).then(h=>{if(!c){if(o.current){window.location.reload();return}s(h),l(null),CE(h)&&(c=!0)}}).catch(h=>{if(!c){if(h instanceof ge&&h.status!==0&&h.status<500){l(h.message);return}o.current=!0,i(!0)}})};u();const d=window.setInterval(u,X5);return()=>{c=!0,window.clearInterval(d)}},[e]),{job:t,away:r,error:a}}function n8({job:e,away:t,error:s}){return s?n.jsx(re,{message:s}):t?n.jsx(W,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="rolled-back"||e.phase==="failed"?n.jsxs(W,{tone:"critical",role:"alert",children:[lb(e)," ",e.error??""]}):n.jsxs(W,{tone:e.phase==="done"?"good":void 0,role:"status",children:[lb(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function s8(){var b,x,v,j,w,S,k;const e=le(()=>T.backups(),[],3e4),t=NE(),s=le(()=>T.service(),[]),[r,i]=f.useState(null),a=t8(r),[l,o]=f.useState(null),[c,u]=f.useState(!1),[d,h]=f.useState(null),m=((b=e.data)==null?void 0:b.supervised)??((x=s.data)==null?void 0:x.supervised),p=d!==null||m===!1,g=((v=e.data)==null?void 0:v.archives)??[],y=N=>{u(!0),o(null),N.then(C=>{var I;return i(((I=C.job)==null?void 0:I.id)??null)}).catch(C=>{C instanceof ge&&C.status===409?h(C.message):o(C instanceof ge?C.message:String(C))}).finally(()=>{u(!1),e.reload()})};return f.useEffect(()=>{CE(a.job)&&e.reload()},[(j=a.job)==null?void 0:j.phase]),n.jsxs(Q,{gap:"lg",children:[(w=t.data)!=null&&w.active?n.jsx(J5,{view:t.data,onLeft:t.reload}):null,n.jsx(re,{message:e.error??l}),n.jsx(n8,{...a}),n.jsx(i8,{onSaved:()=>e.reload()}),n.jsx(te,{title:"Backups",panel:!0,actions:n.jsx(R,{variant:"accent",size:"sm",disabled:c,onClick:()=>y(T.startBackup(!0)),children:"Back up now"}),children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs("p",{className:"ui-card-meta",children:["Kept in ",n.jsx("span",{className:"mono",children:((S=e.data)==null?void 0:S.dir)??"…"}),". A backup holds your agents, conversations, memory and files. It never holds a key."]})}),n.jsx(te,{children:e.data&&g.length===0?n.jsx(Zt,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?n.jsxs(Pn,{children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Name"}),n.jsx("th",{children:"Taken"}),n.jsx("th",{children:"Size"}),n.jsx("th",{children:"State"}),n.jsx("th",{})]})}),n.jsx("tbody",{children:g.map(N=>{var C;return n.jsx(a8,{archive:N,busy:c,database:(C=e.data)==null?void 0:C.database,checkout:p,onVerify:()=>y(T.verifyArchive(N.name)),onRestore:(I,A)=>y(T.restoreArchive({name:N.name,...I?{passphrase:I}:{},...A?{confirm:A}:{}}))},N.name)})})]}):n.jsx(ce,{children:"Loading…"})})]})}),n.jsx(l8,{}),n.jsx(o8,{busy:c,checkout:p,checkoutSaid:d,database:(k=e.data)==null?void 0:k.database,onRestore:(N,C,I)=>y(T.restoreUpload(N,{passphrase:C,confirm:I}))})]})}const r8={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function i8({onSaved:e}){var p;const t=le(()=>T.backupSchedule(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1);f.useEffect(()=>{t.data&&r(t.data)},[t.data]);const d={...r8,...s??t.data??{}};if(((p=t.data)==null?void 0:p.supervised)===!1)return n.jsx(te,{title:"Every night",panel:!0,children:n.jsx(te,{children:n.jsx(W,{tone:"warning",children:t.data.error??"This installation schedules its own backups."})})});const h=g=>{u(!1),r({...d,...g})},m=()=>{a(!0),o(null),T.setBackupSchedule(d).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof ge?g.message:String(g))).finally(()=>a(!1))};return n.jsx(te,{title:"Every night",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:i,onClick:m,children:"Save"}),children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:l}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:d.enabled,onChange:g=>h({enabled:g.target.checked})}),n.jsx("span",{children:"Back this buddi up on its own"})]}),n.jsxs(bs,{children:[n.jsx(Z,{label:"At",children:n.jsx("input",{type:"time",value:d.time,onChange:g=>h({time:g.target.value})})}),n.jsx(Z,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:n.jsx("input",{type:"number",min:1,max:365,value:d.keep,onChange:g=>h({keep:Number(g.target.value)||1})})})]}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:d.encryptLocal,onChange:g=>h({encryptLocal:g.target.checked})}),n.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(Z,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:n.jsx("input",{type:"text",value:d.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>h({copyTo:g.target.value===""?null:g.target.value})})}),c?n.jsxs(W,{tone:"good",role:"status",children:["Saved.",d.lastRunAt?` Last run ${ze(d.lastRunAt)}.`:""]}):null]})})]})})}function a8({archive:e,busy:t,database:s,checkout:r,onVerify:i,onRestore:a}){const[l,o]=f.useState(!1),[c,u]=f.useState(""),[d,h]=f.useState("");return n.jsxs(n.Fragment,{children:[n.jsxs("tr",{children:[n.jsx("td",{className:"mono",children:e.name}),n.jsx("td",{children:ze(e.createdAt)}),n.jsx("td",{children:$n(e.bytes)}),n.jsxs("td",{children:[e.encrypted?n.jsx(ve,{tone:"good",children:"locked"}):n.jsx(ve,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?n.jsx(ve,{tone:"critical",children:"damaged"}):null]}),n.jsx("td",{children:n.jsxs(J,{align:"end",children:[n.jsx(R,{size:"sm",disabled:t,onClick:i,children:"Verify"}),n.jsx(R,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?n.jsx("tr",{children:n.jsx("td",{colSpan:5,children:r?n.jsx(W,{tone:"warning",children:EE}):n.jsx(AE,{what:`${e.name}, taken ${ze(e.createdAt)}, ${$n(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:d,onConfirm:h,busy:t,onCancel:()=>o(!1),onGo:()=>a(c,d)})})}):null]})}const EE="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function AE({what:e,database:t,needsPassphrase:s,passphrase:r,onPassphrase:i,confirm:a,onConfirm:l,busy:o,onCancel:c,onGo:u}){const d=t??"",h=d===""?a.trim()!=="":a.trim()===d;return n.jsxs(Q,{gap:"sm",children:[n.jsxs(W,{tone:"warning",children:["This replaces everything in this buddi with ",e,". What is here now is copied first, so a restore that fails puts it back."]}),s?n.jsx(Z,{label:"The passphrase this one was locked with",children:n.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>i(m.target.value)})}):null,n.jsx(Z,{label:d?`Type ${d} to confirm`:"Type the name of this database to confirm",hint:d?void 0:"The same name buddi shows on the System tab.",children:n.jsx("input",{value:a,onChange:m=>l(m.target.value)})}),n.jsxs(J,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:c,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:o||!h||s&&r==="",onClick:u,children:"Restore"})]})]})}function l8(){const[e,t]=f.useState(null),[s,r]=f.useState(""),[i,a]=f.useState(!1),[l,o]=f.useState(null),[c,u]=f.useState(!1),d=()=>{a(!0),o(null),T.backupPassphrase().then(m=>t(m.passphrase)).catch(m=>o(m instanceof ge?m.message:String(m))).finally(()=>a(!1))},h=()=>{a(!0),o(null),T.setBackupPassphrase(s.trim()).then(m=>{t(m.passphrase),r(""),u(!0)}).catch(m=>o(m instanceof ge?m.message:String(m))).finally(()=>a(!1))};return n.jsx(te,{title:"The passphrase",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:l}),n.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?n.jsx("p",{className:"backup-phrase mono",children:e}):n.jsx(J,{align:"end",children:n.jsx(R,{disabled:i,onClick:d,children:"Show it"})}),c?n.jsx(W,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(Z,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:n.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:m=>{u(!1),r(m.target.value)}})}),n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",disabled:i||s.trim()==="",onClick:h,children:"Use this one"})})]})})]})})}function o8({busy:e,checkout:t,checkoutSaid:s,database:r,onRestore:i}){const[a,l]=f.useState(null),[o,c]=f.useState(""),[u,d]=f.useState(""),[h,m]=f.useState(!1);return t?n.jsx(te,{title:"Restore from a file",panel:!0,children:n.jsx(te,{children:n.jsx(W,{tone:"warning",children:s??EE})})}):n.jsx(te,{title:"Restore from a file",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),n.jsxs(bs,{children:[n.jsx(Z,{label:"The backup file",children:n.jsx("input",{type:"file",onChange:p=>{var g;m(!1),l(((g=p.target.files)==null?void 0:g[0])??null)}})}),n.jsx(Z,{label:"Its passphrase",hint:"Only if it was locked with one.",children:n.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),h?null:n.jsx(J,{align:"end",children:n.jsx(R,{variant:"accent",disabled:e||!a,onClick:()=>m(!0),children:"Restore"})})]})}),h&&a?n.jsx(te,{children:n.jsx(AE,{what:`${a.name}, ${$n(a.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:d,busy:e,onCancel:()=>m(!1),onGo:()=>i(a,o,u)})}):null]})})}const TE="gemini-2.5-pro";function ih(e){return e.replace(/^models\//,"")}const yv=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function RE(e){const t=e.map(ih);let s;for(const r of t){const i=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!i||yv.test(i[2]??""))continue;const a=i[1].split(".").map(Number),l=(i[2]??"")!=="";(!s||dd(a,s.version)>0||dd(a,s.version)===0&&s.preview&&!l)&&(s={id:r,version:a,preview:l})}return(s==null?void 0:s.id)??t.find(r=>r.startsWith("gemini-"))}function IE(e){let t;for(const s of e.map(ih)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||yv.test(r[2]??""))continue;const i=r[1].split(".").map(Number),a=(r[2]??"")!=="";(!t||dd(i,t.version)>0||dd(i,t.version)===0&&t.preview&&!a)&&(t={id:s,version:i,preview:a})}return t==null?void 0:t.id}function PE(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(ih(e))}function c8(e){return[...new Set(e.map(ih).filter(t=>t.startsWith("gemini-")&&!yv.test(t)))]}function $E(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function dd(e,t){for(let s=0;s<Math.max(e.length,t.length);s+=1){const r=(e[s]??0)-(t[s]??0);if(r!==0)return r}return 0}function u8(e,t){if(!t||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(t)}function d8({embedded:e,account:t}={}){const{data:s,error:r,reload:i,loading:a}=le(()=>T.providerAccounts(),[]),[l,o]=f.useState(!1),[c,u]=f.useState(null),[d,h]=f.useState(""),[m,p]=f.useState(!1),[g,y]=f.useState(!1),[b,x]=f.useState(t??null);f.useEffect(()=>{t&&x(t)},[t]);const v=s==null?void 0:s.accounts.some(k=>{var N;return((N=k.login)==null?void 0:N.state)==="pending"&&k.login.expiresAt&&Date.parse(k.login.expiresAt)>Date.now()});f.useEffect(()=>{if(!v)return;const k=setInterval(i,2e3);return()=>clearInterval(k)},[v,i]);const j=async(k,N)=>{o(!0),u(null),h(""),y(!1);try{const C=await k();return h((C==null?void 0:C.warning)??N),i(),!0}catch(C){return u(C instanceof Error?C.message:"Could not apply change."),i(),!1}finally{o(!1)}},w=(s==null?void 0:s.accounts)??[],S=w.find(k=>k.id===b)??w[0];return n.jsxs(yn,{embedded:e,title:"Model accounts",lede:"Give each API key or subscription a name, then pick one per agent. An account never falls back to another credential on its own.",children:[n.jsx(re,{message:r??c}),d&&n.jsx(W,{tone:"good",role:"status",children:d}),g&&n.jsx(W,{role:"status",children:a?"Refreshing account status…":r?"Could not refresh account status. Try again.":"Account status refreshed. This checks saved credentials; it does not renew subscription tokens or test connections."}),!s&&!r&&n.jsx(ce,{children:"Loading accounts…"}),r&&n.jsx(J,{children:n.jsx(R,{onClick:i,children:"Retry"})}),s&&n.jsxs(n.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&n.jsx(W,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&n.jsx(kt,{title:"Add an account",onClose:()=>p(!1),children:n.jsx("div",{id:"new-provider-account",children:n.jsx(v8,{accounts:w,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:j,onDone:k=>{p(!1),k&&x(k)}})})}),n.jsx(te,{title:"Accounts",aside:`Secrets live in the ${h8(s.vault.kind)}; Postgres holds names and assignments only.`,actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",size:"sm",disabled:l||a,onClick:()=>{u(null),h(""),y(!0),i()},children:a?"Refreshing…":"Refresh status"}),n.jsx(R,{variant:"accent",size:"sm",disabled:l,"aria-expanded":m,"aria-controls":"new-provider-account",onClick:()=>p(!m),children:"Add account"})]}),panel:!0,flush:!0,children:w.length===0?n.jsx(Zt,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):n.jsxs("div",{className:"accounts",children:[n.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:w.map(k=>n.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(S==null?void 0:S.id)===k.id,onClick:()=>x(k.id),children:[n.jsx(f8,{kind:k.kind,auth:k.auth}),n.jsxs("span",{className:"accounts-row-text",children:[n.jsx("span",{className:"accounts-row-name",children:k.label}),n.jsxs("span",{className:"accounts-row-sub",children:[wv(k)," · ",k.assignedAgents.length===0?"no agents":`${k.assignedAgents.length} agent${k.assignedAgents.length===1?"":"s"}`]})]}),n.jsx(OE,{account:k})]},k.id))}),S?n.jsx(p8,{account:S,anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:j},`${S.id}:${S.revision}`):null]})})]})]})}function h8(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function wv(e){return e.kind==="codex"?"ChatGPT subscription":e.kind==="anthropic"?e.auth==="anthropic-oauth"?"Claude subscription":"Anthropic API":e.kind==="openai"?"OpenAI API":e.auth==="device-key"?"Ollama Cloud":mv(e)?"mlxh":"OpenAI-compatible"}function ME(e){return e.detectedContextWindowSource==="mlxh"?rB(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function f8({kind:e,auth:t}){const s=e==="anthropic"?"A":e==="codex"?"G":e==="openai"?"O":"∞",r=e==="anthropic"?"3":e==="codex"?"2":e==="openai"?"5":"4";return n.jsx("span",{className:"ui-avatar","data-tint":r,"aria-hidden":"true",title:`${e} · ${t}`,children:s})}function m8(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function OE({account:e}){const t=e.enabled?e.configured?"good":"warning":void 0,s=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return n.jsx(ve,{tone:t,children:s})}function bv(e){return{id:e.id,revision:e.revision,label:e.label,kind:e.kind,auth:e.auth,baseUrl:e.baseUrl,defaultModel:e.defaultModel,enabled:e.enabled,contextWindowTokens:e.contextWindowTokens??null}}function p8({account:e,busy:t,run:s,anthropicOAuthEnabled:r}){const[i,a]=f.useState(!1),[l,o]=f.useState(!1);return n.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:e.label}),n.jsx(OE,{account:e})]}),n.jsx(Gt,{items:[{label:"Provider",value:wv(e)},{label:"Default model",value:n.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:n.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${ME(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:n.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?n.jsx("span",{className:"ui-row",children:e.assignedAgents.map(c=>n.jsx("a",{href:xt(c,"setup","brain"),children:c},c))}):n.jsxs("span",{className:"ui-row",children:[n.jsx("span",{className:"muted",children:"No agents"}),n.jsx("a",{href:gt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${new Date(e.tokenExpiresAt).toLocaleString()} (not your subscription renewal date)`}]:[]]}),e.removalPending&&n.jsx(W,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&n.jsxs(W,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&n.jsx(LE,{account:e,enabled:!!r,busy:t,run:s}),e.kind==="codex"&&n.jsx(DE,{account:e,busy:t,run:s}),e.auth==="device-key"&&n.jsx(_E,{account:e,busy:t,run:s}),n.jsxs(J,{children:[n.jsx(R,{disabled:t||e.removalPending,onClick:()=>a(!0),children:"Edit account"}),n.jsx(R,{disabled:t||e.removalPending,onClick:()=>void s(()=>T.saveProviderAccount({...bv(e),enabled:!e.enabled}),e.enabled?"Account disabled. Subsequent model calls will stop; already-sent requests cannot be recalled.":"Account enabled."),children:e.enabled?"Disable":"Enable"}),e.kind!=="codex"&&n.jsx(R,{disabled:t||!e.enabled||!e.configured,onClick:()=>void s(()=>T.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),n.jsx(R,{variant:"danger",disabled:t||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>o(!0),children:"Remove account"})]}),e.test&&n.jsxs(n.Fragment,{children:[n.jsxs(W,{role:"status",tone:m8(e.test.state),children:[n.jsx("p",{children:e.test.message}),e.test.retryAt?n.jsxs("p",{children:["Provider suggested retry time: ",new Date(e.test.retryAt).toLocaleString(),". This is retry advice, not a guaranteed quota reset."]}):["rate-limited","quota-exhausted"].includes(e.test.state)&&n.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),n.jsxs("p",{className:"muted",children:["Tested at ",new Date(e.test.checkedAt).toLocaleString(),e.test.httpStatus?` · HTTP ${e.test.httpStatus}`:"",". This is not a quota reset or subscription renewal date."]})]}),i&&n.jsx(kt,{title:`Edit ${e.label}`,onClose:()=>a(!1),children:n.jsx(g8,{account:e,busy:t,run:s,onDone:()=>a(!1)})}),l&&n.jsxs(W,{tone:"critical",children:[n.jsxs("p",{children:["Remove “",e.label,"” and its stored credential from Buddi? This does not revoke it at the provider or remove it from backups."]}),n.jsxs(J,{children:[n.jsx(R,{variant:"danger",disabled:t,onClick:()=>void s(()=>T.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),n.jsx(R,{disabled:t,onClick:()=>o(!1),children:"Cancel"})]})]}),n.jsx(Ct,{summary:"Details",children:n.jsxs("div",{className:"ui-prose muted",children:[e.kind==="codex"?n.jsxs(n.Fragment,{children:[n.jsx("p",{children:"Talks to OpenAI’s Codex backend directly with your ChatGPT sign-in. The credential stays in buddi’s vault; buddi refreshes it and never reads your own Codex login."}),n.jsx("p",{children:"Native tool-step usage reporting is incomplete. Do not use Buddi’s token or API-cost estimates as subscription billing or remaining quota."}),n.jsx("p",{children:"After connecting, assign this account to an agent and send a test message. Model turns use your subscription allowance."})]}):n.jsx("p",{children:"Testing sends a small fixed prompt and may incur a charge. No conversation or files are sent. Configured does not mean verified."}),e.auth==="device-key"&&n.jsx("p",{children:"Ollama Cloud with a device key: buddi made a key pair and keeps it in the vault; ollama.com only ever saw the public half and this computer’s name. Each request to ollama.com is signed with the key, and nothing else is sent with it. Disconnect asks ollama.com to forget the device and removes the key from buddi either way."}),e.auth==="anthropic-oauth"&&n.jsx("p",{children:"Claude subscription sign-in. Tokens remain in Buddi’s vault and refresh before use. Uses your plan’s monthly Agent SDK credits; after them, an API key. Remaining credits are unknown here."}),n.jsx("p",{children:"Subscription login is separate from API-key access."})]})})]})}function DE({account:e,busy:t,run:s}){var r,i,a;return n.jsxs(n.Fragment,{children:[n.jsxs(J,{children:[n.jsx(R,{disabled:t||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>T.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((i=e.login)==null?void 0:i.state)==="pending"&&n.jsx(R,{disabled:t,onClick:()=>void s(()=>T.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),n.jsx(R,{disabled:t||!e.configured,onClick:()=>void s(()=>T.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((a=e.login)==null?void 0:a.state)==="pending"&&n.jsxs(W,{tone:"accent",role:"status",children:[n.jsxs("p",{children:["Here is your code: ",n.jsx("strong",{children:e.login.userCode}),". Open the link, enter it, and approve buddi on openai.com."]}),e.login.userCode&&n.jsx(gv,{code:e.login.userCode}),e.login.verificationUrl&&n.jsx(J,{children:n.jsx(Ut,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&n.jsxs("p",{className:"muted",children:["The code works until ",new Date(e.login.expiresAt).toLocaleTimeString(),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&n.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function g8({account:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a}){const[l,o]=f.useState((e==null?void 0:e.label)??""),[c,u]=f.useState((e==null?void 0:e.kind)??"anthropic"),[d,h]=f.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=f.useState((e==null?void 0:e.baseUrl)??""),[g,y]=f.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[b,x]=f.useState(""),[v,j]=f.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),w=k=>{u(k),h(k==="codex"?"chatgpt":"api-key"),x(""),p(k==="openai-compatible"?"http://localhost:11434/v1":""),y(k==="anthropic"?"claude-sonnet-5":k==="openai"?"gpt-5":"")},S=!l.trim()||!g.trim();return n.jsxs("form",{className:"ui-stack",onSubmit:k=>{k.preventDefault();const N=b;x(""),s(()=>T.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:d,baseUrl:m,defaultModel:g,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:v.trim()?Number(v):null,...N.trim()?{secret:N}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(Z,{label:"Account name",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:k=>o(k.target.value),placeholder:"Anthropic — Personal"})}),n.jsx(Z,{label:"Provider",children:n.jsxs("select",{disabled:!!e,value:d==="anthropic-oauth"?"anthropic-oauth":d==="device-key"?"ollama-cloud":c,onChange:k=>{k.target.value==="anthropic-oauth"?(w("anthropic"),h("anthropic-oauth")):w(k.target.value)},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(a||(e==null?void 0:e.auth)==="anthropic-oauth")&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(i||(e==null?void 0:e.kind)==="codex")&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&d!=="device-key"&&n.jsxs(n.Fragment,{children:[n.jsx(Z,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:m,onChange:k=>p(k.target.value)})}),n.jsx(Z,{label:"Authentication",children:n.jsxs("select",{disabled:!!e,value:d,onChange:k=>{h(k.target.value),x("")},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),n.jsx(J,{valign:"end",children:n.jsx(pv,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:y,disabled:t},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),n.jsx(Z,{label:"Context window",hint:mv(e)?"mlxh refuses a prompt over its max_prompt_tokens, and its model manager does not report the number, so buddi assumes 8,192. After `mlxh config max_prompt_tokens 40960`, enter the same number here.":"Tokens this endpoint actually serves. Leave blank unless you run the model yourself and set a window of your own — a conversation is ended once its history would fill half of this.",children:n.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:v,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${ME(e)})`:"assumed from the model",onChange:k=>j(k.target.value)})}),c==="codex"&&n.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),d==="anthropic-oauth"&&n.jsx("p",{className:"muted",children:"Save this account, then choose Connect Claude. You will approve in your browser and paste the authorization code here, not in chat. No existing agent assignment changes."}),d==="api-key"&&n.jsx(Z,{label:e?"Replacement API key (leave blank to keep)":"API key",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:b,onChange:k=>x(k.target.value)})}),e&&n.jsx("p",{className:"muted",children:"Saving changes stops an active run at its next model call. Start a new turn afterward. Changing the default model does not change existing agent assignments."}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:r,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:S,children:"Save account"})]})]}),S&&n.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function _E({account:e,busy:t,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,i=f.useRef(s);i.current=s,f.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const d=setInterval(()=>{c||u||(u=!0,T.ollamaPoll(e.id,r.attemptId).then(h=>{c||h.state==="waiting"||(c=!0,h.state==="connected"?i.current(async()=>{},`Connected as ${h.username}, device ${h.deviceName}.`):i.current(async()=>{throw new Error(h.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(d)}},[e.id,r==null?void 0:r.attemptId]);const a=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await T.ollamaConnect(e.id,e.revision);return c&&(c.location.href=u.verificationUrl),u}catch(u){throw c==null||c.close(),u}},"Press Connect on the ollama.com page. This card notices on its own.")},l=e.device;return n.jsxs(n.Fragment,{children:[l&&n.jsx("p",{className:"muted",role:"status",children:l.connectedAt?`Connected as ${l.username||"an ollama.com account"}, device ${l.deviceName}.`:`Not connected yet. Device ${l.deviceName}.`}),n.jsxs(J,{children:[n.jsx(R,{disabled:t||!e.enabled||e.removalPending||!!r,onClick:a,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),n.jsx(R,{disabled:t||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await T.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&n.jsxs(W,{tone:"accent",role:"status",children:[n.jsxs("p",{children:[n.jsx("a",{href:r.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open the ollama.com page"})," and press Connect. Sign in there first if it asks."]}),n.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&new Date(r.expiresAt).toLocaleTimeString(),"."]})]})]})}function LE({account:e,enabled:t,busy:s,run:r}){var l,o,c,u,d;const[i,a]=f.useState("");return f.useEffect(()=>{a("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),n.jsxs(n.Fragment,{children:[!t&&n.jsx(W,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),n.jsxs(J,{children:[n.jsx(R,{disabled:s||!t||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>T.anthropicAccountAction(e.id,"login",e.revision),"Open the Claude consent link below. Existing credentials remain until sign-in succeeds."),children:e.configured?"Reconnect Claude":"Connect Claude"}),((u=e.login)==null?void 0:u.state)==="pending"&&n.jsx(R,{disabled:s,onClick:()=>{a(""),r(()=>T.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),n.jsx(R,{disabled:s||!e.configured||e.removalPending,onClick:()=>{a(""),r(()=>T.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((d=e.login)==null?void 0:d.state)==="pending"&&n.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:h=>{h.preventDefault();const m=i;a(""),r(()=>T.anthropicAccountAction(e.id,"complete-login",e.revision,{attemptId:e.login.attemptId,code:m}),"Claude connected. Edit account to load its model list, then assign it to an agent.")},children:[n.jsx("p",{children:n.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),n.jsxs("p",{className:"muted",children:["Use the Claude account you want to connect. Paste the entire code including #state. This attempt expires at ",e.login.expiresAt&&new Date(e.login.expiresAt).toLocaleTimeString(),"; restarting Buddi also ends it."]}),n.jsx(Z,{label:"Claude authorization code",children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:i,onChange:h=>a(h.target.value),disabled:s})}),n.jsx(J,{align:"end",children:n.jsx(R,{type:"submit",variant:"accent",disabled:s||!i.trim(),children:"Complete Claude sign-in"})})]})]})}const Tf={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function Rf(e,t,s){return Up(e==="codex"?"ChatGPT subscription":e==="anthropic"?t==="anthropic-oauth"?"Claude subscription":"Anthropic API":e==="openai"?"OpenAI API":t==="device-key"?"Ollama Cloud":"Local endpoint",s)}function Up(e,t){const s=new Set(t.map(r=>r.trim().toLowerCase()));if(!s.has(e.toLowerCase()))return e;for(let r=2;r<100;r+=1)if(!s.has(`${e} ${r}`.toLowerCase()))return`${e} ${r}`;return e}const x8="That key was refused. Check it and paste it again.";function v8({accounts:e,busy:t,run:s,onDone:r,codexEnabled:i,anthropicOAuthEnabled:a,gemini:l}){const o=e.map(he=>he.label),[c,u]=f.useState(null),[d,h]=f.useState("anthropic"),[m,p]=f.useState("api-key"),[g,y]=f.useState(()=>Rf("anthropic","api-key",o)),[b,x]=f.useState(!1),[v,j]=f.useState(""),[w,S]=f.useState(""),[k,N]=f.useState(null),[C,I]=f.useState(!1),[A,_]=f.useState(""),[z,L]=f.useState(""),[E,M]=f.useState(!1),[D,U]=f.useState(!1),[$,B]=f.useState(!1),[O,K]=f.useState(void 0),G=(he,Me,Pe=!1)=>{h(he),p(Me),S(""),N(null),_(""),L(""),M(!1),U(Pe),B(!1),K(void 0),j(Pe?"":he==="openai-compatible"?"http://localhost:11434/v1":""),b||y(Pe?Rf(he,"device-key",o):Rf(he,Me,o))},se=he=>{G("openai-compatible",he?"api-key":"device-key",!0),he&&T.ollama().then(Me=>j(Me.cloudBaseUrl)).catch(()=>{})},ue=()=>{l&&(G("openai-compatible","api-key"),B(!0),j(l.baseUrl),b||y(Up("Gemini",o)))},ie=()=>{G("openai-compatible","none"),K(null),b||y(Up("mlxh",o)),T.mlxh().then(he=>{K(he),j(he.baseUrl)}).catch(()=>K(void 0))},ee=O!==void 0,X=c?e.find(he=>he.id===c):void 0;if(c)return X?n.jsx(j8,{account:X,busy:t,run:s,anthropicOAuthEnabled:a,onDone:()=>r(X.id)}):n.jsx(ce,{children:"Saving…"});const de=d==="openai-compatible"&&m!=="device-key",Ie=d==="codex"||m==="anthropic-oauth"||m==="device-key",Se=!Ie&&(m==="none"||w.trim()!=="")&&(!de||v.trim()!==""),we=async()=>{var he,Me;I(!0),_("");try{const Pe=await T.probeModels({kind:d,auth:m,...de?{baseUrl:v}:{},...w.trim()?{secret:w}:{}});N(Pe),z||L(((he=Pe.models.find(Ye=>Ye.isDefault))==null?void 0:he.id)??((Me=Pe.models[0])==null?void 0:Me.id)??"")}catch(Pe){_(Pe instanceof Error?Pe.message:"Could not load models. You can still enter a custom model.")}finally{I(!1)}},Ce=z.trim(),mt=!g.trim()||de&&!v.trim()||de&&!$&&!ee&&!Ce||$&&!w.trim()||ee&&!(O!=null&&O.running);return n.jsxs("form",{className:"ui-stack",onSubmit:he=>{var Y;he.preventDefault();const Me=w;S("");let Pe=Ce||(ee?Lp(O)??((Y=O==null?void 0:O.models[0])==null?void 0:Y.id):void 0)||(m==="device-key"?uu:Tf[d])||"claude-sonnet-5",Ye;(async()=>{if($){Pe=TE;try{const Ue=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:v,secret:Me})).models.map(at=>at.id);Pe=RE(Ue)??Pe,Ye=PE(Pe)?IE(Ue):void 0}catch{}}let me,oe=!1;!await s(async()=>{if(me=await T.saveProviderAccount({label:g,kind:d,auth:m,baseUrl:v,defaultModel:Pe,enabled:!0,...Me.trim()?{secret:Me}:{}}),m!=="api-key")return me;const Le=await T.testProviderAccount(me.id);if(Le.state==="connected")return me;if(ux(Le)){const Ue=me.id;me=void 0;try{const at=(await T.providerAccounts()).accounts.find(Rt=>Rt.id===Ue);at&&await T.removeProviderAccount(Ue,at.revision)}catch{}throw new Error(x8)}if($&&Ye&&$E(Le)){const Ue=(await T.providerAccounts()).accounts.find(at=>at.id===me.id);if(Ue&&(await T.saveProviderAccount({...bv(Ue),defaultModel:Ye}),(await T.testProviderAccount(me.id)).state==="connected"))return{...me,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${Ye}; turn on billing at Google to use Pro.`}}return oe=!0,{...me,warning:`Account saved. ${Le.message}`}},"Account saved.")||!me||($||ee||oe?u(me.id):Ce||!Ie?r(me.id):u(me.id))})()},children:[n.jsxs("fieldset",{disabled:t,className:"ui-fields","data-stack":"true",children:[n.jsx(Z,{label:"Provider",children:n.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":D?"ollama-cloud":$?"gemini":ee?"mlxh":d,onChange:he=>{if(he.target.value==="anthropic-oauth")G("anthropic","anthropic-oauth");else if(he.target.value==="gemini")ue();else if(he.target.value==="mlxh")ie();else if(he.target.value==="ollama-cloud")G("openai-compatible","device-key",!0);else{const Me=he.target.value;G(Me,Me==="codex"?"chatgpt":"api-key")}},children:[n.jsx("option",{value:"anthropic",children:"Anthropic API"}),n.jsx("option",{value:"openai",children:"OpenAI API"}),l&&n.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),n.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),n.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),n.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),a&&n.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),i&&n.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),n.jsx(Z,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:n.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:g,onChange:he=>{y(he.target.value),x(!0)},placeholder:"Anthropic — Personal"})}),D&&n.jsxs("label",{className:"ui-row",children:[n.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:he=>se(he.target.checked)}),n.jsx("span",{children:"Use a key instead"})]}),de&&n.jsxs(n.Fragment,{children:[n.jsx(Z,{label:"API base URL",hint:"Include the API path, such as /v1 or /api/v1. Conversation data will be sent to this endpoint. The model must support tool calling to use agent tools.",children:n.jsx("input",{required:!0,type:"url",value:v,onChange:he=>{j(he.target.value),N(null)}})}),!$&&!ee&&n.jsx(Z,{label:"Authentication",children:n.jsxs("select",{value:m,onChange:he=>{p(he.target.value),S(""),N(null)},children:[n.jsx("option",{value:"api-key",children:"API key"}),n.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&n.jsx(Z,{label:"API key",hint:"Stored in the vault, never shown again.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:w,onChange:he=>{S(he.target.value),N(null)}})}),ee?O===null?n.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):O!=null&&O.running?n.jsxs(Q,{gap:"sm",children:[n.jsxs("p",{className:"muted",children:["mlxh answers with ",O.models.length===1?"one model":`${O.models.length} models`,". No key: mlxh takes any. buddi starts on ",Lp(O)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),O.models.some(he=>he.kind==="image")?n.jsxs("p",{className:"muted",children:[O.models.filter(he=>he.kind==="image").map(he=>he.id).join(", "),": ",iE,"."]}):null]}):n.jsx(W,{tone:"warning",children:rE((O==null?void 0:O.baseUrl)??v)}):$&&l?n.jsxs("p",{className:"muted",children:[n.jsx("a",{href:l.keyUrl,target:"_blank",rel:"noreferrer",children:"Get a key at aistudio.google.com"}),". buddi picks the newest Gemini Pro your key can reach; the next step lists the rest."]}):Ie?n.jsx("p",{className:"muted",children:d==="codex"?"You will connect your ChatGPT subscription on the next step, with a code you enter on openai.com, and pick a model then.":m==="device-key"?"You will connect on the next step: ollama.com opens, you press Connect, and no key is typed. Free to start.":"You will connect your Claude subscription on the next step, in your browser, and pick a model then."}):n.jsxs("div",{className:"ui-field",children:[n.jsx("span",{className:"ui-field-label",children:"Model"}),k?n.jsxs("div",{className:"ui-row",children:[n.jsxs("select",{"aria-label":"Model",value:E?"__custom__":z,onChange:he=>{he.target.value==="__custom__"?(M(!0),L("")):(M(!1),L(he.target.value))},children:[k.models.map(he=>n.jsxs("option",{value:he.id,children:[he.name===he.id?he.id:`${he.name} — ${he.id}`,he.isDefault?" (provider default)":"",he.thinks?" · thinks":""]},he.id)),n.jsx("option",{value:"__custom__",children:"Custom model…"})]}),n.jsx(R,{size:"sm",disabled:C||!Se,onClick:()=>void we(),children:C?"Loading…":"Reload"})]}):n.jsxs("div",{className:"ui-row",children:[n.jsx(R,{disabled:C||!Se,onClick:()=>void we(),children:C?"Loading models…":"Load models"}),de?n.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):n.jsxs("span",{className:"muted",children:["Optional now: ",Tf[d]," is used until you pick one."]})]}),E||de&&!k?n.jsx("input",{"aria-label":"Custom model",required:de,maxLength:150,value:z,onChange:he=>L(he.target.value),placeholder:de?"qwen3:8b":Tf[d]}):null,A?n.jsx("span",{className:"ui-field-hint critical",role:"alert",children:A}):null,k!=null&&k.truncated?n.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:()=>r(),children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:mt,children:"Save account"})]})]}),mt&&!ee&&n.jsxs("p",{className:"muted",children:["Enter an account name",$?" and a key":de?", an endpoint and a model":""," to enable Save account."]})]})}function j8({account:e,busy:t,run:s,anthropicOAuthEnabled:r,onDone:i}){const[a,l]=f.useState(e.defaultModel),o=e.configured;return n.jsxs(Q,{gap:"lg",children:[n.jsxs(W,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?n.jsx(LE,{account:e,enabled:!!r,busy:t,run:s}):null,e.kind==="codex"&&!o?n.jsx(DE,{account:e,busy:t,run:s}):null,e.auth==="device-key"&&!o?n.jsx(_E,{account:e,busy:t,run:s}):null,o?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-page-lede",children:"Pick the model this account offers by default. An agent can still choose another when you assign it."}),n.jsx(J,{valign:"end",children:n.jsx(pv,{accountId:e.enabled?e.id:void 0,label:"Default model",value:a,onChange:l,disabled:t},`${e.id}:${e.revision}`)}),n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:i,children:"Skip for now"}),n.jsx(R,{variant:"accent",disabled:t||!a.trim(),onClick:()=>{if(a===e.defaultModel){i();return}s(()=>T.saveProviderAccount({...bv(e),defaultModel:a}),"Default model saved.").then(c=>{c&&i()})},children:"Done"})]})]}):n.jsx(J,{children:n.jsx(R,{onClick:i,children:"Finish later"})})]})}const ob=new Set(["co.uk","org.uk","me.uk","ltd.uk","plc.uk","net.uk","sch.uk","ac.uk","gov.uk","nhs.uk","police.uk","mod.uk","gov.ie","co.at","or.at","ac.at","gv.at","com.pl","net.pl","org.pl","info.pl","biz.pl","edu.pl","gov.pl","waw.pl","com.es","org.es","nom.es","gob.es","edu.es","com.pt","org.pt","gov.pt","edu.pt","com.gr","org.gr","net.gr","edu.gr","gov.gr","com.cy","org.cy","net.cy","gov.cy","ac.cy","com.mt","org.mt","net.mt","edu.mt","gov.mt","co.hu","org.hu","info.hu","com.ro","org.ro","info.ro","nom.ro","co.rs","org.rs","edu.rs","gov.rs","in.rs","com.ua","org.ua","net.ua","gov.ua","edu.ua","in.ua","kiev.ua","com.ru","org.ru","net.ru","msk.ru","spb.ru","co.no","priv.no","com.hr","from.hr","iz.hr","name.hr","co.it","gov.it","edu.it","asso.fr","com.fr","gouv.fr","nom.fr","prd.fr","tm.fr","co.je","net.je","org.je","co.gg","net.gg","org.gg","co.im","net.im","org.im","gc.ca","on.ca","qc.ca","bc.ca","ab.ca","com.mx","org.mx","net.mx","edu.mx","gob.mx","ny.us","ca.us","tx.us","fl.us","wa.us","k12.ca.us","lib.ca.us","com.br","net.br","org.br","gov.br","edu.br","art.br","blog.br","eco.br","emp.br","ind.br","inf.br","tv.br","app.br","dev.br","com.ar","org.ar","net.ar","gob.ar","edu.ar","int.ar","tur.ar","com.co","org.co","net.co","edu.co","gov.co","nom.co","com.pe","org.pe","net.pe","gob.pe","edu.pe","nom.pe","com.ve","org.ve","net.ve","gob.ve","co.ve","com.uy","org.uy","net.uy","gub.uy","edu.uy","com.ec","org.ec","net.ec","gob.ec","edu.ec","fin.ec","com.bo","org.bo","net.bo","gob.bo","edu.bo","com.py","org.py","net.py","gov.py","edu.py","gob.cl","gov.cl","co.cl","com.do","org.do","net.do","gob.do","edu.do","com.gt","org.gt","net.gt","gob.gt","edu.gt","co.cr","or.cr","fi.cr","go.cr","ac.cr","com.pa","org.pa","net.pa","gob.pa","com.sv","org.sv","gob.sv","edu.sv","com.ni","org.ni","gob.ni","com.hn","org.hn","net.hn","gob.hn","com.cu","org.cu","net.cu","gob.cu","com.jm","org.jm","net.jm","gov.jm","com.tt","org.tt","net.tt","gov.tt","co.tt","com.pr","org.pr","net.pr","gov.pr","com.au","net.au","org.au","edu.au","gov.au","asn.au","id.au","co.nz","net.nz","org.nz","ac.nz","govt.nz","school.nz","geek.nz","gen.nz","kiwi.nz","maori.nz","co.jp","ne.jp","or.jp","ac.jp","ad.jp","ed.jp","go.jp","gr.jp","lg.jp","com.cn","net.cn","org.cn","gov.cn","edu.cn","ac.cn","com.hk","net.hk","org.hk","edu.hk","gov.hk","idv.hk","com.tw","net.tw","org.tw","edu.tw","gov.tw","idv.tw","co.kr","or.kr","ne.kr","go.kr","ac.kr","re.kr","pe.kr","co.in","net.in","org.in","firm.in","gen.in","ind.in","ac.in","edu.in","gov.in","res.in","nic.in","com.sg","net.sg","org.sg","edu.sg","gov.sg","per.sg","com.my","net.my","org.my","edu.my","gov.my","name.my","co.id","or.id","ac.id","go.id","web.id","my.id","biz.id","net.id","sch.id","co.th","in.th","ac.th","go.th","or.th","net.th","com.vn","net.vn","org.vn","edu.vn","gov.vn","com.ph","net.ph","org.ph","edu.ph","gov.ph","com.pk","net.pk","org.pk","edu.pk","gov.pk","com.bd","org.bd","net.bd","gov.bd","edu.bd","com.lk","org.lk","gov.lk","edu.lk","com.np","org.np","gov.np","edu.np","com.kh","org.kh","gov.kh","com.mm","org.mm","gov.mm","com.fj","org.fj","gov.fj","ac.fj","com.pg","org.pg","gov.pg","ac.pg","com.kz","org.kz","gov.kz","edu.kz","com.tr","net.tr","org.tr","gov.tr","edu.tr","gen.tr","biz.tr","info.tr","av.tr","bel.tr","k12.tr","co.il","org.il","net.il","ac.il","gov.il","muni.il","com.sa","net.sa","org.sa","gov.sa","edu.sa","med.sa","co.ae","net.ae","org.ae","gov.ae","ac.ae","com.qa","org.qa","net.qa","gov.qa","edu.qa","com.kw","org.kw","net.kw","gov.kw","edu.kw","com.bh","org.bh","net.bh","gov.bh","edu.bh","com.om","org.om","net.om","gov.om","co.om","com.jo","org.jo","net.jo","gov.jo","edu.jo","com.lb","org.lb","net.lb","gov.lb","edu.lb","com.eg","org.eg","net.eg","gov.eg","edu.eg","eun.eg","co.ir","ac.ir","gov.ir","org.ir","net.ir","co.za","org.za","net.za","gov.za","ac.za","web.za","edu.za","nom.za","com.ng","org.ng","net.ng","gov.ng","edu.ng","name.ng","co.ke","or.ke","ne.ke","go.ke","ac.ke","sc.ke","co.tz","or.tz","ne.tz","go.tz","ac.tz","co.ug","or.ug","ne.ug","go.ug","ac.ug","com.gh","org.gh","gov.gh","edu.gh","co.ma","net.ma","org.ma","gov.ma","ac.ma","press.ma","com.tn","org.tn","gov.tn","ens.tn","fin.tn","com.dz","org.dz","net.dz","gov.dz","edu.dz","com.et","org.et","gov.et","edu.et","co.zw","org.zw","gov.zw","ac.zw","co.zm","org.zm","gov.zm","ac.zm","co.bw","org.bw","ac.bw","com.na","org.na","co.na","co.mz","org.mz","gov.mz","com.cm","co.cm","net.cm","gov.cm","com.sn","org.sn","edu.sn","gouv.sn","com.ci","co.ci","or.ci","go.ci","ac.ci","com.tg","gouv.tg","co.rw","gov.rw","ac.rw","*.ck","*.er","*.fk","*.jm","*.kh","*.mm","*.np","*.pg","*.bd","github.io","githubusercontent.com","gitlab.io","bitbucket.io","pages.dev","workers.dev","trycloudflare.com","vercel.app","vercel.dev","now.sh","netlify.app","netlify.com","herokuapp.com","herokussl.com","cloudfront.net","amazonaws.com","s3.amazonaws.com","elasticbeanstalk.com","awsapprunner.com","amplifyapp.com","azurewebsites.net","azurestaticapps.net","cloudapp.net","azureedge.net","azurefd.net","blob.core.windows.net","trafficmanager.net","appspot.com","firebaseapp.com","web.app","run.app","cloudfunctions.net","blogspot.com","fly.dev","onrender.com","up.railway.app","deno.dev","deno.net","glitch.me","repl.co","replit.dev","replit.app","ngrok.io","ngrok.app","ngrok-free.app","ngrok.dev","ngrok-free.dev","surge.sh","readthedocs.io","myshopify.com","wixsite.com","webflow.io","framer.app","framer.website","ondigitalocean.app","digitaloceanspaces.com","supabase.co","fastly.net","global.ssl.fastly.net","edgecompute.app","duckdns.org","dyndns.org","ddns.net","no-ip.org","hopto.org","zapto.org","eu.org","us.org","neocities.org","codeberg.page","sourceforge.io","pythonanywhere.com","streamlit.app","hf.space"]);function y8(e){const t=e.toLowerCase().replace(/\.$/,"");if(!t.includes(".")||ob.has(t))return!0;const s=t.slice(t.indexOf(".")+1);return ob.has(`*.${s}`)}function w8(e){return typeof e=="string"&&e.includes("*")}function b8(e){const t=/^(https?):\/\/([^/?#@\s]+)(?:[/?#]\S*)?$/i.exec(e.trim());if(t===null)return{ok:!1,reason:"invalid"};const[,s,r]=t;if(!r.startsWith("*.")||r.slice(2).includes("*"))return{ok:!1,reason:"placement"};let i;try{i=new URL(`${s.toLowerCase()}://${r.slice(2)}`)}catch{return{ok:!1,reason:"invalid"}}const a=i.hostname;return a===""||a.startsWith("[")||/^[\d.]+$/.test(a)||a.startsWith(".")||a.includes("..")?{ok:!1,reason:"invalid"}:y8(a)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${i.protocol}//*.${i.host}`,protocol:i.protocol,suffix:a,port:i.port}}}const cb=["every-time","first-time","pre-approved"],FE={"every-time":"every time","first-time":"first time only","pre-approved":"pre-approved"};function k8(e){const t=cb.indexOf(e);return cb.slice(0,t<0?1:t+1)}function zE(e){return e.endsWith(".account")}const S8="This account’s process holds the value for as long as its connection lives.",kv="Stored, not usable until it has a binding.";function N8(e){return e==="browser.field"?"the origin of the site that holds the field, e.g. https://en.wikipedia.org or *.wikimedia.org":e==="browser.form.data"?"the origin, then the field name — e.g. https://localhost:8443 card-number":e==="browser.native.type"?"the app’s bundle id, e.g. com.bank.app":e==="http.header"?"the host, then the header name — e.g. localhost:9200 Authorization":e==="http.url"?"the plugin, then the host — e.g. calendar calendar.google.com":e==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":zE(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const UE={"browser.form.data":{hint:"an origin, then the field name",build:(e,t)=>({origin:e,field:t})},"http.header":{hint:"a host, then the header name",build:(e,t)=>({host:e,header:t})},"http.url":{hint:"a plugin, then the host",build:(e,t)=>({plugin:e,host:t})},"developer.env":{hint:"a workspace, then the variable name",build:(e,t)=>({workspace:e,variable:t})}},C8="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",E8=e=>`That is a public suffix; ${e} would match every site.`,ub="Give the site as an origin, like https://en.wikipedia.org.";function db(e){const t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(w8(e)){const s=b8(t);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:C8};if(s.reason==="public-suffix"){const r=t.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:E8(r)}}return{ok:!1,error:ub}}try{const s=new URL(t);if(s.origin==="null"||s.protocol!=="https:"&&s.protocol!=="http:")throw new Error("not an origin");return{ok:!0,target:s.origin}}catch{return{ok:!1,error:ub}}}function A8(e){const t=e.search(/\s\S+\s*$/);if(t<=0)return null;const s=e.slice(t).trim(),r=e.slice(0,t).trim();return r&&s?[r,s]:null}function BE(e,t){const s=t.trim();if(s==="")return{ok:!1,error:"Give the exact place this value may go."};if(s.startsWith("{"))try{const a=JSON.parse(s);return a!==null&&typeof a=="object"&&!Array.isArray(a)?{ok:!0,target:a}:{ok:!1,error:'A target in JSON is an object, like {"host":"localhost","header":"Authorization"}.'}}catch{return{ok:!1,error:"That opens like JSON but does not parse."}}if(e==="browser.field")return db(s);if(e==="browser.native.type"||zE(e))return{ok:!0,target:s};const r=UE[e];if(r===void 0)return{ok:!0,target:s};const i=A8(s);if(i===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const a=db(i[0]);return a.ok?{ok:!0,target:r.build(a.target,i[1])}:a}return{ok:!0,target:r.build(i[0],i[1])}}function T8(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function R8(e,t){if(typeof t=="string")return t;if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const s=t,r=UE[e];if(r!==void 0){const i=Object.keys(r.build("a","b")),a=i.map(l=>s[l]);if(i.every(l=>typeof s[l]=="string"))return a.join(" · ")}}try{return JSON.stringify(t)??String(t)}catch{return String(t)}}const WE="accounts.provider";function I8(e,t){for(const s of e)if(s.kind===WE&&typeof s.target=="string"){const r=t.get(s.target);if(r)return r}}function Bp(e,t,s){if(e===WE&&typeof t=="string"){const r=s.get(t);if(r)return r.label}return R8(e,t)}function HE(e){if(e==="delivered")return"good";if(e==="held"||e==="pending")return"warning";if(e==="refused"||e==="failed")return"critical"}function KE(e,t){if(typeof e!="object"||e===null)return[];const s=e[t];return Array.isArray(s)?s.flatMap(r=>{if(typeof r!="object"||r===null)return[];const i=r.place,a=r.count;return typeof i!="string"||typeof a!="number"||!(a>0)?[]:[{place:i,count:a}]}):[]}function VE(e){const t=e.map(({place:s,count:r})=>`${r.toLocaleString("en-GB")} ${r===1?s.replace(/s$/,""):s}`);return t.length<=1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}function P8(e){const t=KE(e,"found");return t.length?`The value already sits in ${VE(t)}.`:""}function $8(e){const t=KE(e,"scrubbed");return t.length?`Replaced with ‹secret:…› in ${VE(t)}.`:""}async function zi(e,t,s,r){s(!0),r(null);try{return(await T.secretsAct(e,t)).result}catch(i){return r(i instanceof Error?i.message:String(i)),null}finally{s(!1)}}function M8({embedded:e,timezone:t}={}){const s=le(()=>T.secrets(),[]),r=le(()=>T.providerAccounts(),[]),i=f.useMemo(()=>{var c;return new Map((((c=r.data)==null?void 0:c.accounts)??[]).map(u=>[u.id,{label:u.label,provider:wv(u)}]))},[r.data]),[a,l]=f.useState(!1),o=s.data;return n.jsxs(yn,{embedded:e,title:"Keys and secrets",lede:"What the agents may use and never see: a name, a value buddi keeps, and the exact places the value may go.",children:[n.jsxs(Q,{gap:"lg",children:[!o&&!s.error?n.jsx(ce,{children:"Opening the vault…"}):null,s.error?n.jsx(J,{children:n.jsx(R,{onClick:s.reload,children:"Retry"})}):null,o?n.jsx(te,{title:"Secrets",aside:"A value the agents use and never see: bound to where it may go, never shown again.",actions:n.jsx(R,{variant:"accent",size:"sm",onClick:()=>l(!0),children:"Add a secret"}),panel:!0,children:n.jsx(Q,{divided:!0,children:o.secrets.length===0?n.jsx(Zt,{icon:"key",title:"Nothing stored yet",children:"Add one — a site password, an API token — and bind it to the places an agent may use it."}):o.secrets.map(c=>n.jsx(O8,{secret:c,accounts:i,destinations:o.destinations,timezone:t,onChanged:s.reload},c.name))})}):null,o?n.jsx(te,{title:"buddi’s own keys",aside:"Read-only.",children:n.jsxs(Q,{gap:"sm",children:[o.ownKeys.length===0?n.jsx(ce,{children:"No keys of buddi’s own right now."}):n.jsx("div",{className:"ui-list",children:o.ownKeys.map(c=>n.jsx("div",{className:"ui-list-row",children:n.jsx("span",{className:"ui-list-main",children:n.jsx("span",{className:"mono",children:c})})},c))}),n.jsx("p",{className:"ui-card-meta",children:"These are the keys buddi itself runs on. They cannot be bound or replaced here, and the scrubber replaces them in what buddi sends out, exactly like your own secrets."})]})}):null]}),a&&o?n.jsx(_8,{destinations:o.destinations,onClose:()=>l(!1),onChanged:s.reload}):null]})}function O8({secret:e,accounts:t,destinations:s,timezone:r,onChanged:i}){const[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,d]=f.useState(null),[h,m]=f.useState(!1),[p,g]=f.useState(!1),y=async()=>{await zi("secrets.delete",{name:e.name},l,c)!==null&&(m(!1),i())},b=e.lastUse,x=I8(e.bindings,t);return n.jsxs(Q,{gap:"sm",children:[n.jsxs("div",{className:"ui-card-head",children:[n.jsx("h3",{className:"ui-card-title",children:x?x.label:e.name}),x?n.jsx(Ia,{children:x.provider}):null,e.totp?n.jsx(Ia,{children:"TOTP"}):null,b?n.jsx(ve,{tone:HE(b.outcome),children:b.outcome}):null]}),x?n.jsx("p",{className:"ui-card-meta mono",children:e.name}):null,e.bindings.length===0?n.jsx("p",{className:"ui-card-meta",children:kv}):n.jsx("div",{className:"ui-stack","data-gap":"sm",children:e.bindings.map((v,j)=>n.jsxs("div",{className:"ui-row",children:[n.jsx(Ia,{children:v.kind}),n.jsx("span",{className:"mono",children:Bp(v.kind,v.target,t)}),n.jsx(ve,{tone:"muted",children:FE[v.rule]??v.rule})]},j))}),e.bindings.some(v=>v.heldByPlugin)?n.jsx("p",{className:"ui-card-meta",children:S8}):null,n.jsx("p",{className:"ui-card-meta",children:b?`Last used ${ze(b.at)}${b.agentId?` by ${b.agentId}`:""} — ${b.kind}, ${Bp(b.kind,b.target,t)}.`:"Never used."}),n.jsx(re,{message:o}),h?n.jsxs(W,{tone:"critical",role:"alert",children:[n.jsxs("p",{children:["Delete “",e.name,"”? The value and its bindings go; the use log stays, under the name."]}),n.jsxs(J,{children:[n.jsx(R,{variant:"danger",disabled:a,onClick:()=>void y(),children:"Delete it"}),n.jsx(R,{disabled:a,onClick:()=>m(!1),children:"Cancel"})]})]}):null,n.jsxs(J,{children:[n.jsx(R,{size:"sm",disabled:a,onClick:()=>d("replace"),children:"Replace value"}),n.jsx(R,{size:"sm",disabled:a,onClick:()=>d("rename"),children:"Rename"}),n.jsx(R,{size:"sm",disabled:a,onClick:()=>d("rebind"),children:e.bindings.length===0?"Add a binding":"Rebind"}),n.jsx(R,{size:"sm",variant:"danger",disabled:a,onClick:()=>m(!0),children:"Delete"}),n.jsx(R,{size:"sm",variant:"ghost","aria-expanded":p,onClick:()=>g(!p),children:"Use log"})]}),p?n.jsx(D8,{name:e.name,accounts:t,timezone:r}):null,u==="replace"?n.jsx(L8,{secret:e,onClose:()=>d(null),onChanged:i}):null,u==="rename"?n.jsx(F8,{secret:e,onClose:()=>d(null),onChanged:i}):null,u==="rebind"?n.jsx(z8,{secret:e,destinations:s,onClose:()=>d(null),onChanged:i}):null]})}function D8({name:e,accounts:t,timezone:s}){const r=le(()=>T.secretUses(e,50),[e]);if(r.error)return n.jsx(re,{message:r.error});if(!r.data)return n.jsx(ce,{children:"Reading the log…"});const i=r.data.uses;return i.length===0?n.jsx(ce,{children:"No uses yet."}):n.jsx("div",{className:"ui-list",children:i.map((a,l)=>n.jsxs("div",{className:"ui-list-row",children:[n.jsxs("span",{className:"ui-list-main",children:[n.jsxs("span",{className:"ui-list-title",children:[Ve(a.at,s??"UTC")," — ",a.kind,", ",Bp(a.kind,a.target,t)]}),n.jsxs("span",{className:"ui-list-sub",children:[a.agent?a.agent:"the owner",a.plugin?` · ${a.plugin}`:"",a.detail?` · ${a.detail}`:""]})]}),n.jsx("span",{className:"ui-list-side",children:n.jsx(ve,{tone:HE(a.outcome),children:a.outcome})})]},l))})}function GE({name:e,result:t,scrubbed:s,busy:r,failure:i,onScrub:a,onDone:l}){const o=P8(t);return n.jsxs(Q,{gap:"sm",children:[n.jsxs(W,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),n.jsx("p",{className:"ui-card-meta",children:o||"Nothing of the value sits where buddi already holds text."}),n.jsx(re,{message:i}),o?n.jsx(J,{children:n.jsx(R,{variant:"accent",disabled:r||s!==null,onClick:a,children:s===null?"Scrub the history":$8(s)||"Nothing of it was left to replace."})}):null,n.jsx(J,{align:"end",children:n.jsx(R,{onClick:l,children:"Done"})})]})}function YE({destinations:e,bindings:t,disabled:s,onChange:r}){const i=(a,l)=>{r(t.map((o,c)=>c===a?{...o,...l}:o))};return n.jsx(Q,{gap:"sm",children:t.map((a,l)=>{const o=e.find(u=>u.kind===a.kind),c=(o==null?void 0:o.maxRule)??a.rule;return n.jsxs(J,{valign:"end",children:[n.jsx(Z,{label:"Kind",inline:!0,children:n.jsx("select",{value:a.kind,disabled:s,onChange:u=>{var h;const d=u.target.value;i(l,{kind:d,rule:((h=e.find(m=>m.kind===d))==null?void 0:h.maxRule)??a.rule})},children:(o?e:[...e,{kind:a.kind,plugin:"",maxRule:a.rule}]).map(u=>n.jsx("option",{value:u.kind,children:u.kind},u.kind))})}),n.jsx(Z,{label:"Target",inline:!0,grow:!0,children:n.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:a.target,placeholder:N8(a.kind),onChange:u=>i(l,{target:u.target.value})})}),n.jsx(Z,{label:"Rule",inline:!0,children:n.jsx("select",{value:a.rule,disabled:s,onChange:u=>i(l,{rule:u.target.value}),children:k8(c).map(u=>n.jsx("option",{value:u,children:FE[u]},u))})}),n.jsx(R,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(t.filter((u,d)=>d!==l)),children:"Remove"})]},l)})})}function _8({destinations:e,onClose:t,onChanged:s}){const[r,i]=f.useState(""),[a,l]=f.useState(""),[o,c]=f.useState(!1),[u,d]=f.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:e[0].maxRule}]:[]),[h,m]=f.useState(!1),[p,g]=f.useState(null),[y,b]=f.useState(null),[x,v]=f.useState(null),j=async()=>{const S=u.map(I=>BE(I.kind,I.target)),k=S.findIndex(I=>!I.ok);if(k!==-1){g(`Binding ${k+1}: ${S[k].error}`);return}const N=a;l("");const C=await zi("secrets.put",{name:r.trim(),value:N,totp:o,bindings:u.map((I,A)=>({kind:I.kind,target:S[A].target,rule:I.rule}))},m,g);C!==null&&(b({name:r.trim(),result:C}),s())},w=async()=>{const S=await zi("secrets.scrub_history",{name:(y==null?void 0:y.name)??""},m,g);S!==null&&(v(S),s())};return n.jsx(kt,{title:"Add a secret",onClose:t,children:y?n.jsx(GE,{name:y.name,result:y.result,scrubbed:x,busy:h,failure:p,onScrub:()=>void w(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:S=>{S.preventDefault(),j()},children:n.jsxs("fieldset",{disabled:h,className:"ui-stack","data-gap":"sm",children:[n.jsx(Z,{label:"Name",hint:"What an agent calls it. Saving a name that exists replaces that secret’s value.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:S=>i(S.target.value),placeholder:"PNC password"})}),n.jsx(Z,{label:"Value",hint:"Kept in the vault, never shown again — not even here.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:a,onChange:S=>l(S.target.value)})}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:S=>c(S.target.checked)}),n.jsx("span",{children:"The code comes from this secret"})]}),n.jsx("p",{className:"ui-field-hint",children:"The seed and the code are one thing buddi holds — the owner’s explicit choice per secret."}),n.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[n.jsx("span",{className:"ui-field-label",children:"Bindings — the places this value may go"}),n.jsx(YE,{destinations:e,bindings:u,disabled:h,onChange:d}),u.length===0?n.jsx("p",{className:"ui-field-hint",children:kv}):null,e.length?n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>d([...u,{kind:e[0].kind,target:"",rule:e[0].maxRule}]),children:"Add a binding"})}):n.jsx("p",{className:"ui-field-hint",children:"No destination is registered on this installation yet, so there is nothing to bind to."})]}),p?n.jsx(W,{tone:"critical",role:"alert",children:p}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save secret"})]})]})})})}function L8({secret:e,onClose:t,onChanged:s}){const[r,i]=f.useState(""),[a,l]=f.useState(!1),[o,c]=f.useState(null),[u,d]=f.useState(null),[h,m]=f.useState(null),p=async()=>{const y=r;i("");const b=await zi("secrets.put",{name:e.name,value:y,totp:e.totp,bindings:e.bindings.map(({kind:x,target:v,rule:j})=>({kind:x,target:v,rule:j}))},l,c);b!==null&&(d(b),s())},g=async()=>{const y=await zi("secrets.scrub_history",{name:e.name},l,c);y!==null&&(m(y),s())};return n.jsx(kt,{title:`Replace the value of “${e.name}”`,onClose:t,children:u?n.jsx(GE,{name:e.name,result:u,scrubbed:h,busy:a,failure:o,onScrub:()=>void g(),onDone:t}):n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:y=>{y.preventDefault(),p()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(Z,{label:"New value",hint:"Replaces what is stored. The bindings stay as they are.",children:n.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,value:r,onChange:y=>i(y.target.value)})}),o?n.jsx(W,{tone:"critical",role:"alert",children:o}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save value"})]})]})})})}function F8({secret:e,onClose:t,onChanged:s}){const[r,i]=f.useState(e.name),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=async()=>{await zi("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),t())};return n.jsx(kt,{title:`Rename “${e.name}”`,onClose:t,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:d=>{d.preventDefault(),u()},children:n.jsxs("fieldset",{disabled:a,className:"ui-stack","data-gap":"sm",children:[n.jsx(Z,{label:"New name",hint:"The vault entry never moves; only the name the agents ask for does.",children:n.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:d=>i(d.target.value)})}),o?n.jsx(W,{tone:"critical",role:"alert",children:o}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:t,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",disabled:!r.trim()||r.trim()===e.name,children:"Save name"})]})]})})})}function z8({secret:e,destinations:t,onClose:s,onChanged:r}){const[i,a]=f.useState(()=>e.bindings.map(h=>({kind:h.kind,target:T8(h.target),rule:h.rule}))),[l,o]=f.useState(!1),[c,u]=f.useState(null),d=async()=>{const h=i.map(g=>BE(g.kind,g.target)),m=h.findIndex(g=>!g.ok);if(m!==-1){u(`Binding ${m+1}: ${h[m].error}`);return}await zi("secrets.rebind",{name:e.name,bindings:i.map((g,y)=>({kind:g.kind,target:h[y].target,rule:g.rule}))},o,u)!==null&&(r(),s())};return n.jsx(kt,{title:`Rebind “${e.name}”`,onClose:s,children:n.jsx("form",{className:"ui-stack","data-gap":"sm",onSubmit:h=>{h.preventDefault(),d()},children:n.jsxs("fieldset",{disabled:l,className:"ui-stack","data-gap":"sm",children:[n.jsx(YE,{destinations:t,bindings:i,disabled:l,onChange:a}),i.length===0?n.jsx("p",{className:"ui-field-hint",children:kv}):null,t.length?n.jsx(J,{children:n.jsx(R,{size:"sm",onClick:()=>a([...i,{kind:t[0].kind,target:"",rule:t[0].maxRule}]),children:"Add a binding"})}):null,c?n.jsx(W,{tone:"critical",role:"alert",children:c}):null,n.jsxs(J,{align:"end",children:[n.jsx(R,{onClick:s,children:"Cancel"}),n.jsx(R,{type:"submit",variant:"accent",children:"Save bindings"})]})]})})})}function U8({timezone:e,embedded:t}){const{data:s,error:r,reload:i}=le(()=>T.sentinels(),[],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),u=(s==null?void 0:s.installed)??[],d=((s==null?void 0:s.runs)??[]).filter(p=>p.lastError),h=u.filter(p=>!p.enabled),m=(p,g)=>{l(p),c(null),T.setSentinelEnabled(p,g).catch(y=>c(y instanceof ge?y.message:String(y))).finally(()=>{l(null),i()})};return n.jsxs(yn,{embedded:t,title:"Watchers",children:[n.jsx(re,{message:r??o}),n.jsx(W,{children:"Watchers are small checks that run on their own, with no model involved. An urgent finding wakes an agent, which verifies it before it tells you. The rest waits for the weekly recap."}),d.length>0?n.jsx(W,{tone:"warning",children:d.length===1?"One watcher failed on its last run.":`${d.length} watchers failed on their last run.`}):null,h.length>0?n.jsxs(W,{tone:"warning",children:[h.length===1?"One watcher is off.":`${h.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,n.jsx(te,{title:"Installed",aside:n.jsx("a",{href:`${dt}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?n.jsx(Zt,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):n.jsx(yt,{children:u.map(p=>{const g=s.runs.find(y=>y.sentinelId===p.id);return n.jsx(ft,{lead:n.jsx(ve,{tone:p.enabled?g!=null&&g.lastError?"critical":g?"good":void 0:"muted",children:p.enabled?g!=null&&g.lastError?"failed":g?"ok":"never ran":"off"}),title:p.description,sub:`${p.id}, every ${B8(p.every)}${g!=null&&g.lastError?`. ${g.lastError}`:""}`,side:n.jsxs(n.Fragment,{children:[n.jsx("span",{title:g?Ve(g.lastRunAt,e):void 0,children:g?ze(g.lastRunAt):"never ran"}),n.jsx(R,{size:"sm",disabled:a===p.id,onClick:()=>m(p.id,!p.enabled),children:p.enabled?"Turn off":"Turn on"})]})},p.id)})}):n.jsx(ce,{children:"Loading…"})})]})}function B8(e){if(e%86400===0){const s=e/86400;return s===1?"day":`${s} days`}if(e%3600===0){const s=e/3600;return s===1?"hour":`${s} hours`}const t=Math.max(1,Math.round(e/60));return t===1?"minute":`${t} minutes`}function W8({embedded:e}){const{data:t,error:s,reload:r}=le(()=>T.owner(),[]);return n.jsxs(yn,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[n.jsx(re,{message:s}),t?n.jsx(H8,{initial:t,onSaved:r}):null]})}function H8({initial:e,onSaved:t}){const[s,r]=f.useState(e.preferredName??""),[i,a]=f.useState(e.timezone??""),[l,o]=f.useState(e.language??""),[c,u]=f.useState(e.about??""),[d,h]=f.useState(!1),[m,p]=f.useState(!1),[g,y]=f.useState(null);f.useEffect(()=>{r(e.preferredName??""),a(e.timezone??""),o(e.language??""),u(e.about??"")},[e]);const b=s.trim()!==(e.preferredName??"")||i!==(e.timezone??"")||l.trim()!==(e.language??"")||c.trim()!==(e.about??""),x=async()=>{h(!0),y(null);try{await T.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:i===""?null:i,language:l.trim()===""?null:l.trim(),about:c.trim()===""?null:c.trim()}),p(!0),t()}catch(j){y(j instanceof ge?j.message:String(j))}finally{h(!1)}},v=e.zones.length>0?e.zones:[e.detectedTimezone];return n.jsx(te,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:n.jsxs(n.Fragment,{children:[m&&!b?n.jsx("span",{className:"muted",children:"Saved"}):null,n.jsx(R,{variant:"accent",disabled:!b||d,onClick:()=>void x(),children:d?"Saving…":"Save"})]}),children:n.jsxs(Q,{divided:!0,gap:"lg",children:[n.jsx(te,{title:"Name and place",children:n.jsxs(bs,{children:[n.jsx(Z,{label:"What the agents call you",children:n.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:j=>{p(!1),r(j.target.value)}})}),n.jsx(Z,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:n.jsxs("select",{value:i,onChange:j=>{p(!1),a(j.target.value)},children:[n.jsx("option",{value:"",children:"Not set (use the host's)"}),v.map(j=>n.jsx("option",{value:j,children:j},j))]})}),n.jsx(Z,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:n.jsx("input",{value:l,maxLength:40,placeholder:"English, français…",onChange:j=>{p(!1),o(j.target.value)}})})]})}),n.jsxs(te,{title:"About you",children:[n.jsx(Z,{label:"In your own words",hint:"Who you are, how you like answers, anything every agent should keep in mind. A few lines is plenty.",children:n.jsx("textarea",{rows:4,maxLength:1e3,value:c,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:j=>{p(!1),u(j.target.value)}})}),g?n.jsx(W,{tone:"critical",children:g}):null]})]})})}const K8=2e6;function hb(e,t){const s=e.replace(/\r\n/g,`
|
|
117
|
+
`).replace(/\n+$/,"").split(`
|
|
118
|
+
`),r=t.replace(/\r\n/g,`
|
|
119
|
+
`).replace(/\n+$/,"").split(`
|
|
120
|
+
`);if(e.trim()===t.trim())return"(no change)";if(s.length*r.length>K8)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
|
|
121
|
+
`);const i=Array.from({length:s.length+1},()=>new Uint32Array(r.length+1));for(let c=s.length-1;c>=0;c--)for(let u=r.length-1;u>=0;u--)i[c][u]=s[c]===r[u]?i[c+1][u+1]+1:Math.max(i[c+1][u],i[c][u+1]);const a=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(a.push(` ${s[l]}`),l++,o++):i[l+1][o]>=i[l][o+1]?a.push(`-${s[l++]}`):a.push(`+${r[o++]}`);for(;l<s.length;)a.push(`-${s[l++]}`);for(;o<r.length;)a.push(`+${r[o++]}`);return a.join(`
|
|
122
|
+
`)}const V8={skill:"skill",policy:"rule",change:"change to itself"};function G8(e){return e===null||typeof e!="object"||Array.isArray(e)?String(e??""):Object.entries(e).filter(([t,s])=>!/Id$/.test(t)&&s!==null&&s!==void 0&&s!=="").map(([t,s])=>`${t} ${typeof s=="object"?JSON.stringify(s):String(s)}`).join(" · ")}function Wp(e){return[...new Set(e.split(/[,\n]/).map(t=>t.trim().replace(/^[-*]\s+/,"")).filter(t=>t!==""))]}function Y8(e,t){const s=e.change;if(!s||s.part!=="tools")return[];if(t===e.editable)return s.added;const r=new Set(Wp(s.current??""));return Wp(t).filter(i=>!r.has(i))}function fb(e,t){return!t||e.kind==="policy"&&e.payload.plugin===t}function q8({embedded:e,plugin:t}){const{data:s,error:r,reload:i}=le(()=>T.proposals(),[],3e4),[a,l]=f.useState(null),[o,c]=f.useState(null),[u,d]=f.useState(null),[h,m]=f.useState({}),p=async(x,v,j=!1)=>{l(null),c(null),d(x),m(({[x]:w,...S})=>S);try{c(await v()),i()}catch(w){const S=w instanceof Error?w.message:String(w);j?m(k=>({...k,[x]:S})):l(S)}finally{d(null)}},g=uC(),y=((s==null?void 0:s.open)??[]).filter(x=>fb(x,t)),b=((s==null?void 0:s.closed)??[]).filter(x=>fb(x,t));return n.jsxs(yn,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Nothing here applies itself. Keep what is right, correct what is nearly right, discard the rest.",children:[n.jsx(re,{message:r??a}),t?n.jsxs(W,{role:"status",children:["Showing the rules ",t," proposes. ",n.jsx("a",{href:Be("proposals"),children:"Show every proposal"})]}):null,o?n.jsx(W,{tone:"good",role:"status",children:o}):null,t?null:n.jsx(dC,{offers:g.offers,reload:g.reload}),!s||y.length===0?n.jsx(te,{title:"Waiting",panel:!0,children:s?t?n.jsx(Zt,{icon:"bulb",title:`No rule from ${t} is waiting`,children:"It proposes one when you decide the same way several times running."}):n.jsx(Zt,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):n.jsx(ce,{children:"Loading…"})}):n.jsx(te,{title:"Waiting",aside:`${y.length} to decide`,children:y.map(x=>n.jsx(Z8,{proposal:x,busy:u===x.id,refusal:h[x.id]??null,onKeep:v=>void p(x.id,async()=>{const j=await T.keepProposal(x.id,v);return`${x.title}: ${j.note}`},!0),onDiscard:v=>void p(x.id,async()=>(await T.discardProposal(x.id,v),`Discarded: ${x.title}. ${x.agent} will be told once and will not propose it again for 90 days.`))},x.id))}),b.length>0?n.jsx(te,{title:`Kept, discarded and expired (${b.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:n.jsx(yt,{children:b.map(x=>{var v;return n.jsx(ft,{title:x.title,sub:`${x.agent}: ${Q8(x)}`,side:x.kind==="skill"&&x.state==="kept"&&((v=x.skill)!=null&&v.live)?n.jsxs(J,{align:"end",children:[n.jsx("span",{className:"muted",children:ze(x.decidedAt??x.createdAt)}),n.jsx(R,{size:"sm",variant:"ghost",disabled:u===x.id,onClick:()=>void p(x.id,async()=>{const j=x.skill;return await T.removeSkill(x.agent,j.name),`Removed ${j.name} from ${x.agent}. Its versions are kept, and ${x.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):ze(x.decidedAt??x.createdAt)},x.id)})})}):null,!t&&(s!=null&&s.digest)?n.jsx(X8,{schedule:s.digest.schedule,onSaved:i}):null]})}function Q8(e){switch(e.state){case"kept":return e.kind==="skill"&&e.skill?e.skill.live?`Kept as ${e.skill.name}, version ${e.skill.version}; it loads on the agent's next run.`:`Kept; ${e.skill.name} has a newer version now (${e.skill.version}).`:e.note??"Kept.";case"discarded":return e.reason?`Discarded: ${e.reason}`:"Discarded.";case"expired":return`Expired: ${e.reason??"not decided in 30 days"}.`;default:return"Waiting."}}const J8=Array.from({length:24},(e,t)=>t),mb=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function X8({schedule:e,onSaved:t}){const[s,r]=f.useState(e.day),[i,a]=f.useState(e.hour),[l,o]=f.useState(!1),[c,u]=f.useState(null),d=s!==e.day||i!==e.hour,h=async()=>{o(!0),u(null);try{await T.setDigestSchedule(s,i),u({tone:"good",text:`The digest now runs on ${mb[s]} at ${String(i).padStart(2,"0")}:00.`}),t()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return n.jsx(te,{title:"Weekly digest",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:l||!d,onClick:()=>void h(),children:"Save"}),children:n.jsxs(Q,{children:[n.jsxs("p",{className:"muted",children:["Once a week, one message on Telegram and a card on Home: what your agents learned, what waits here, and what the rules you kept stopped them doing. No message when nothing was learned and nothing waits.",e.next?` Next: ${ze(e.next)}.`:""]}),n.jsxs(J,{children:[n.jsx(Z,{label:"Day",children:n.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:mb.map((m,p)=>n.jsx("option",{value:p,children:m},m))})}),n.jsx(Z,{label:`Hour (${e.timezone})`,children:n.jsx("select",{value:i,disabled:l,onChange:m=>a(Number(m.target.value)),children:J8.map(m=>n.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?n.jsx(W,{tone:c.tone,role:"status",children:c.text}):null]})})}function pb(e,t){return e==="tools"?Wp(t).join(`
|
|
123
|
+
`):t}function Z8({proposal:e,busy:t,refusal:s,onKeep:r,onDiscard:i}){const[a,l]=f.useState(e.editable??""),[o,c]=f.useState(""),u=e.editable!==null&&a!==e.editable,d=e.payload,h=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=Y8(e,a);return n.jsx(ks,{tone:e.untrusted?"warning":"accent",title:e.title,meta:n.jsxs(n.Fragment,{children:[n.jsx(ve,{children:V8[e.kind]}),n.jsx(ve,{mono:!0,children:e.agent}),e.untrusted?n.jsx(ve,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?n.jsx(ve,{tone:"warning",children:"widens its tools"}):null]}),foot:n.jsxs(J,{align:"end",children:[s?n.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,n.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:t,onChange:g=>c(g.target.value)}),n.jsx(R,{variant:"ghost",size:"sm",disabled:t,onClick:()=>i(o.trim()||void 0),children:"Discard"}),n.jsx(R,{variant:"accent",size:"sm",disabled:t||e.editable!==null&&a.trim()==="",onClick:()=>r(u?a:void 0),children:u?"Keep my version":"Keep"})]}),children:n.jsxs(Q,{gap:"sm",children:[e.why?n.jsx("p",{children:e.why}):null,n.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",ze(e.createdAt),e.conversationId?n.jsxs(n.Fragment,{children:[" in ",n.jsx("a",{href:Wa(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?n.jsxs(W,{tone:"warning",title:e.kind==="policy"?"Learned from mail you received.":"Made with untrusted text in view.",children:[e.kind==="policy"?"The plugin counted this rule from your own triage decisions; no instruction in that mail can change what it does.":"Something written by someone other than you was in the agent's context when it proposed this. Read it for instructions that came from there rather than from you.",n.jsx("ul",{className:"proposal-sources",children:e.sources.map(g=>n.jsx("li",{className:"mono",children:g},g))}),h.length>0?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),n.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:h.map(g=>n.jsx("li",{children:n.jsx("mark",{className:"wb-diff-mark",children:g})},g))})]}):null]}):null,e.kind==="skill"?n.jsxs(n.Fragment,{children:[typeof d.when=="string"?n.jsxs("p",{className:"ui-card-meta",children:["When: ",d.when]}):null,e.skill?n.jsxs(Q,{gap:"sm",children:[n.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",n.jsxs("a",{href:xt(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),n.jsx(Ju,{text:hb(e.skill.steps,a),marks:h,label:`Version ${e.skill.version} against this proposal`})]}):null,n.jsx(Z,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="change"?n.jsxs(n.Fragment,{children:[p.length>0?n.jsxs(W,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!u?n.jsx(W,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?n.jsx(Ju,{text:hb(pb(m.part,m.current),pb(m.part,a)),marks:h,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof d.before=="string"?n.jsx(Ct,{summary:`What its ${d.part==="tools"?"tool list":"instructions"} said when proposed`,children:n.jsx(jt,{children:d.before})}):null,n.jsx(Z,{label:d.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:n.jsx("textarea",{rows:8,value:a,disabled:t,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?n.jsx(Gt,{items:[{label:"Plugin",value:n.jsx("span",{className:"mono",children:String(d.plugin??"")})},{label:"Matches",value:n.jsx("span",{className:"mono",children:G8(d.matcher??{})})},{label:"Does",value:String(d.action??"")},{label:"Learned from",value:(()=>{const g=Array.isArray(d.verdicts)?d.verdicts.length:0;return`${g} ${g===1?"decision":"decisions"}`})()}]}):null]})})}function eW(e){const t=[{label:"Home",path:e.home}];if(e.path===e.home||!e.path.startsWith(`${e.home}/`))return t;let s=e.home;for(const r of e.path.slice(e.home.length+1).split("/"))s=`${s}/${r}`,t.push({label:r,path:s});return t}function tW({start:e,onPick:t,onClose:s}){const[r,i]=f.useState(null),[a,l]=f.useState(null),[o,c]=f.useState(""),u=(p,g=!1)=>{l(null),T.pluginFolders(p).then(y=>{i(y),c("")}).catch(y=>{g&&p!==void 0?u(void 0):l(y instanceof ge?y.message:String(y))})};f.useEffect(()=>{u(e,!0)},[]);const d=o.trim().toLowerCase(),h=((r==null?void 0:r.folders)??[]).filter(p=>d===""||p.name.toLowerCase().includes(d)),m=r?eW(r):[];return n.jsxs(kt,{title:"Choose the folder",onClose:s,foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),n.jsx(Xt,{}),n.jsx(R,{variant:"ghost",onClick:s,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:!r,onClick:()=>r&&t(r.path),children:"Use this folder"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Folders on the computer buddi runs on, inside your home directory. The one you want holds the plugin's package.json and is already built."}),r?n.jsx(E1,{label:"Folder",items:m.map((p,g)=>g===m.length-1?{key:p.path,label:p.label,current:!0}:{key:p.path,label:p.label,onClick:()=>u(p.path)})}):null,n.jsx(C1,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),n.jsx(re,{message:a}),r?h.length===0?n.jsx(ce,{children:d===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):n.jsx(Ze,{flush:!0,children:n.jsx(yt,{children:h.map(p=>n.jsx(ft,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:n.jsx(Ka,{icon:"folder"}),title:p.name,side:p.plugin?n.jsx(ve,{tone:"accent",children:"package.json"}):void 0},p.path))})}):a?null:n.jsx(ce,{children:"Reading the folders…"}),r!=null&&r.truncated?n.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const nW="New tools and pages for your team, written by someone else. Each one is read with you, fact by fact, before any of it runs.";function gb(){return n.jsxs("p",{className:"plugins-quiet connections-quiet",children:[n.jsx(ye,{name:"globe",size:14}),n.jsxs("span",{children:["A plugin is code buddi installs and runs; a connection is a service or program buddi talks to."," ",n.jsx("a",{href:Be("connections"),children:"Connections"})]})]})}const sW=1500,rW={fetching:"Fetching the package.","installing-dependencies":"Installing its dependencies. Nothing of the plugin has run.",reading:"Reading what it says it is.",done:"Read. Nothing has been imported yet.",failed:"That did not work."},iW="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",qE=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],QE="buddi.plugins.install-mode";function aW(){try{const e=window.localStorage.getItem(QE);if(qE.some(t=>t.value===e))return e}catch{}return"npm"}function lW(e){try{window.localStorage.setItem(QE,e)}catch{}}const Vc=".tgz",Jr=(e,t,s)=>`${e} ${e===1?t:s}`;function JE(e){const t=[];return e.tools>0&&t.push(Jr(e.tools,"tool","tools")),e.sentinels>0&&t.push(`${e.sentinels} on a timer`),e.views>0&&t.push(Jr(e.views,"view","views")),e.agents>0&&t.push(`${Jr(e.agents,"agent","agents")} proposed`),t.length===0?"nothing on its own":t.join(", ")}function Hp(e){return e.kind==="registry"?`npm · ${e.name}@${e.version}`:e.kind==="tarball"?`a file on this machine · ${e.path}`:`a directory on this machine · ${e.path}`}function oW(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function XE(e,t){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":t??"nobody npm will name"}function ZE(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Sv({author:e}){return e.url?n.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.name}):n.jsx(n.Fragment,{children:e.name})}function Kp({value:e}){return e===void 0||e===""?n.jsx("span",{className:"muted",children:"none — this came off a disk"}):n.jsx("span",{className:"plugins-hash",children:e})}function eA(e){return e.length===0?"none; nothing leaves this computer":n.jsx("span",{className:"mono",children:e.join(", ")})}function Nv(e){return e.length===0?"Nothing beyond its own tables, its own folder and its own tools' approvals.":e.map(t=>`It ${t.words}.`).join(" ")}const ai=e=>e instanceof ge?e.message:String(e);function cW(e){const[t,s]=f.useState(void 0),[r,i]=f.useState(null);return f.useEffect(()=>{if(!e){s(void 0),i(null);return}let a=!1;const l=()=>{T.pluginJob(e).then(c=>{a||(s(c),(c.phase==="done"||c.phase==="failed")&&(a=!0))}).catch(c=>{a||(i(ai(c)),a=!0)})};l();const o=window.setInterval(l,sW);return()=>{a=!0,window.clearInterval(o)}},[e]),{job:t,error:r}}function uW({plugin:e,pages:t,navigate:s,variant:r}){const i=t.filter(a=>a.plugin===e);return i.length===0?null:n.jsx(n.Fragment,{children:i.map(a=>{const l=si(a.plugin,a.id);return n.jsx(Ut,{size:"sm",variant:r,href:l,"aria-label":`Open ${a.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:i.length===1?"Open":`Open ${a.title}`},a.id)})})}function tA({plugin:e}){return e.enabled===!1?n.jsx(ve,{children:"disabled"}):e.loaded?n.jsx(ve,{tone:"good",dot:!0,children:"loaded"}):n.jsx(ve,{tone:"critical",children:"did not load"})}function Cv({entry:e}){var t;return e.trust==="by-buddi"?n.jsx(ve,{tone:"accent",children:"by buddi"}):n.jsxs(ve,{tone:"good",children:["reviewed ",((t=e.reviewed)==null?void 0:t.version)??e.version]})}const Vp=Be("plugins"),If={installed:Vp,browse:`${Vp}?tab=browse`};function dW({railPages:e=[],settingsPages:t=[],navigate:s,hash:r=""}={}){const i=le(()=>T.plugins(),[],2e4),[a,l]=f.useState(null),{job:o,error:c}=cW(a),[u,d]=f.useState(null),[h,m]=f.useState(null),[p,g]=f.useState(()=>Gy(r));f.useEffect(()=>g(Gy(r)),[r]);const[y,b]=f.useState(null),[x,v]=f.useState(null),[j,w]=f.useState(null),[S,k]=f.useState(null),[N,C]=f.useState(!1),I=Y=>{C(!0),T.market(Y).then(k).catch(me=>k({plugins:[],unavailable:ai(me)})).finally(()=>C(!1))};f.useEffect(()=>{p==="browse"&&S===null&&!N&&I(!1)},[p]);const A=Y=>{d(null),m(null),l(Y)},_=Y=>d(ai(Y)),[z,L]=f.useState(!1),E=Y=>{L(!0),b(null),Y.then(me=>{A(me.job.id),g("installed")}).catch(_).finally(()=>L(!1))},M=f.useRef(null);f.useEffect(()=>{const Y=cD(r);if(!(Y===null||M.current===Y)){M.current=Y,g("installed"),E(T.stagePlugin(Y));try{window.history.replaceState(window.history.state,"",Vp)}catch{}}},[r]);const D=Y=>me=>{me.preventDefault(),g(Y),b(null),s==null||s(If[Y])};f.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&i.reload()},[o==null?void 0:o.phase]);const U=i.data,$=(U==null?void 0:U.checkout)??!0,B=(U==null?void 0:U.installed)??[],O=Y=>S==null?void 0:S.plugins.find(me=>me.installed!==void 0&&(me.installed.name??me.name)===Y.name),K=Y=>e.some(me=>me.plugin===Y),G=(Y,me)=>K(Y)?n.jsx(uW,{plugin:Y,pages:e,navigate:s,variant:me}):void 0,se=Y=>{const me=e.find(oe=>oe.plugin===Y);me&&s&&s(si(me.plugin,me.id))},ue=Y=>{const me=t.find(oe=>oe.plugin===Y);if(!(!me||!s))return()=>s(ll(me.plugin,me.id))},ie=((S==null?void 0:S.plugins)??[]).filter(Y=>Y.update).length,ee=(Y,me)=>T.setPluginEnabled(Y,me).then(oe=>{QL(),w({name:Y,notes:oe.notes??[]}),i.reload()}),X=(Y,me,oe)=>T.uninstallPlugin(Y,me?{purge:!0,confirm:oe}:{}).then(Oe=>{b(null),w({name:Y,notes:Oe.notes??[]}),i.reload()}),de=Y=>{d(null),ee(Y,!0).catch(_)},Ie=(Y,me)=>{const oe=S==null?void 0:S.plugins.find(Le=>{var Ue;return(((Ue=Le.installed)==null?void 0:Ue.name)??Le.name)===Y&&Le.installed!==void 0}),Oe=oe&&me?`${oe.npm}@${me}`:void 0;E(Oe?T.updatePlugin(Y,me,Oe):T.updatePlugin(Y,me))},Se=n.jsxs(Yo,{label:"Plugins",children:[n.jsx(Ha,{href:If.installed,active:p==="installed",count:ie,onClick:D("installed"),children:"Installed"}),n.jsx(Ha,{href:If.browse,active:p==="browse",onClick:D("browse"),children:"Browse"})]}),we=(y==null?void 0:y.kind)==="installed"?B.find(Y=>Y.name===y.name):void 0,Ce=(y==null?void 0:y.kind)==="market"?S==null?void 0:S.plugins.find(Y=>Y.name===y.name):void 0,mt=j&&!(we&&we.name===j.name)&&j.notes.length>0?j.notes:null,he=we?n.jsx(yW,{plugin:we,listing:O(we),notes:(j==null?void 0:j.name)===we.name?j.notes:null,canOpen:K(we.name)&&we.enabled!==!1,onOpen:()=>se(we.name),onClose:()=>b(null),onDisable:()=>v({kind:"disable",name:we.name}),onEnable:()=>de(we.name),onRemove:()=>v({kind:"remove",name:we.name}),onUpdate:Y=>Ie(we.name,Y),onSettings:we.enabled===!1?void 0:ue(we.name),busy:z}):Ce?n.jsx(AW,{entry:Ce,canOpen:Ce.installed!==void 0&&K(Ce.installed.name??Ce.name),onOpen:()=>{var Y;return se(((Y=Ce.installed)==null?void 0:Y.name)??Ce.name)},onClose:()=>b(null),onInstall:()=>E(T.stagePlugin(`${Ce.npm}@${Ce.version}`)),onUpdate:Y=>{var me;return Ie(((me=Ce.installed)==null?void 0:me.name)??Ce.name,Y)},busy:z}):null,Me=x?B.find(Y=>Y.name===x.name):void 0,Pe=x?n.jsx(wW,{kind:x.kind,name:x.name,canDisable:(Me==null?void 0:Me.enabled)!==!1,onCancel:()=>v(null),onDisableInstead:()=>v({kind:"disable",name:x.name}),onDisable:()=>ee(x.name,!1).then(()=>v(null)),onRemove:(Y,me)=>X(x.name,Y,me).then(()=>v(null))},`${x.kind}:${x.name}`):null;if(p==="browse")return n.jsxs(Q,{gap:"lg",children:[n.jsx(gb,{}),Se,n.jsx(re,{message:u}),n.jsx(TW,{market:S,loading:N,busy:z,onRetry:()=>I(!0),onOpen:Y=>b({kind:"market",name:Y.name}),onInstall:Y=>E(T.stagePlugin(`${Y.npm}@${Y.version}`)),onUpdate:(Y,me)=>{var oe;return Ie(((oe=Y.installed)==null?void 0:oe.name)??Y.name,me)}}),he]});const Ye=(U==null?void 0:U.builtIn)??[];return n.jsxs(Q,{gap:"lg",children:[n.jsx(gb,{}),Se,n.jsx(re,{message:i.error??u??c}),U!=null&&U.unavailable?n.jsx(W,{tone:"warning",children:U.unavailable}):null,mt?n.jsx(W,{role:"status",children:mt.join(" ")}):null,n.jsx(hW,{trust:(U==null?void 0:U.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:A,onFailed:d}),((U==null?void 0:U.staged)??[]).map(Y=>n.jsx(mW,{staged:Y,onInstalled:me=>{m(me),l(null),i.reload()},onGone:()=>i.reload()},Y.id)),h||U!=null&&U.restartNeeded?n.jsx(pW,{checkout:$,name:h}):null,n.jsx(Ze,{flush:!0,title:"Installed",tool:U?Jr(B.length,"plugin","plugins"):void 0,children:U?B.length===0?n.jsx(ce,{children:"Nothing installed yet. Only what buddi ships with is here."}):n.jsx("div",{className:"plugins-rows",children:n.jsx(yt,{children:B.map(Y=>n.jsx(xW,{plugin:Y,listing:O(Y),open:Y.enabled===!1?void 0:G(Y.name,"ghost"),canOpen:K(Y.name)&&Y.enabled!==!1,busy:z,onDetails:()=>b({kind:"installed",name:Y.name}),onOpen:()=>se(Y.name),onSettings:Y.enabled===!1?void 0:ue(Y.name),onDisable:()=>v({kind:"disable",name:Y.name}),onEnable:()=>de(Y.name),onRemove:()=>v({kind:"remove",name:Y.name}),onUpdate:me=>Ie(Y.name,me)},Y.name))})}):n.jsx(ce,{children:"Loading…"})}),Ye.length>0?n.jsx(bW,{plugins:Ye,openFor:G}):null,he,Pe]})}function hW({trust:e,job:t,busy:s,onStaged:r,onFailed:i}){const[a,l]=f.useState(aW),[o,c]=f.useState(""),[u,d]=f.useState(!1),[h,m]=f.useState(null),[p,g]=f.useState(null),[y,b]=f.useState(!1),[x,v]=f.useState(!1),j=f.useRef(null),w=C=>i(ai(C)),S=C=>{l(C),lW(C),g(null)},k=()=>{d(!0),T.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(w).finally(()=>d(!1))},N=C=>{if(C){if(!C.name.toLowerCase().endsWith(Vc)){m(null),g(`${C.name} is not a ${Vc}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),d(!0),T.uploadPlugin(C).then(I=>r(I.job.id)).catch(w).finally(()=>d(!1))}};return n.jsxs(Ze,{title:"Add a plugin",actions:n.jsx(ls,{label:"Where it comes from",options:qE,value:a,onChange:S}),children:[n.jsxs("div",{className:"plugins-add",children:[a==="file"?n.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":y?"over":p?"refused":h?"chosen":void 0,onDragOver:C=>{C.preventDefault(),b(!0)},onDragLeave:()=>b(!1),onDrop:C=>{var I,A;C.preventDefault(),b(!1),N((A=(I=C.dataTransfer)==null?void 0:I.files)==null?void 0:A[0])},children:[n.jsx(ye,{name:"drop",size:20}),n.jsx("span",{className:"plugins-drop-text",children:p??(h?`${h} — reading it.`:n.jsxs(n.Fragment,{children:["Drop a ",n.jsx("span",{className:"mono",children:Vc})," here: the file ",n.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),n.jsx(R,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=j.current)==null?void 0:C.click()},children:"Choose a file"}),n.jsx("input",{ref:j,type:"file",accept:Vc,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var I;N((I=C.target.files)==null?void 0:I[0]),C.target.value=""}})]}):n.jsxs("div",{className:"plugins-add-row",children:[n.jsxs(J,{valign:"end",children:[n.jsx(Z,{grow:!0,label:a==="npm"?"Package":"The directory it is in",children:n.jsx("input",{type:"text",value:o,placeholder:a==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),a==="directory"?n.jsx(R,{onClick:()=>v(!0),children:"Browse…"}):null,n.jsx(R,{variant:"accent",disabled:s||u||o.trim()==="",onClick:k,children:"Read it first"})]}),n.jsx("span",{className:"ui-field-hint",children:a==="npm"?"A package name, or a name@version. Reading fetches it and hashes it; nothing of it runs.":"The folder with its package.json, already built. Nothing of it runs until you say yes."})]}),t?n.jsxs("p",{className:"plugins-status",role:"status","data-tone":t.phase==="failed"?"critical":void 0,children:[rW[t.phase]," ",t.error??""]}):null,n.jsx("div",{className:"plugins-trust",children:n.jsx(W,{tone:"warning",children:e})})]}),x?n.jsx(tW,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>v(!1),onPick:C=>{c(C),v(!1)}}):null]})}function fW({staged:e}){var r,i;const t=((r=e.uses)==null?void 0:r.areas)??[],s=((i=e.uses)==null?void 0:i.dropped)??[];return n.jsxs("span",{className:"plugins-uses",children:[t.length===0?Nv([]):t.map(a=>n.jsxs("span",{children:["It ",a.words,". ",a.added?n.jsxs(ve,{tone:"warning",children:["new in ",e.version]}):null]},a.use)),s.length>0?n.jsxs("span",{className:"muted",children:["No longer: ",s.map(a=>a.words).join("; "),"."]}):null]})}function mW({staged:e,onInstalled:t,onGone:s}){const[r,i]=f.useState(e.plan??null),[a,l]=f.useState(!1),[o,c]=f.useState(null),u=p=>{l(!0),c(null),T.approveStaged(e.id,{integrity:e.integrity??"",...p?{acknowledgeDrift:!0}:{}}).then(g=>{g.installed?t(e.name):g.plan&&i(g.plan)}).catch(g=>c(ai(g))).finally(()=>l(!1))},d=()=>{l(!0),c(null),T.rejectStaged(e.id).then(()=>s()).catch(p=>c(ai(p))).finally(()=>l(!1))},h=(r==null?void 0:r.drift)??[],m=e.dependencies;return n.jsxs(Q,{gap:"sm",children:[n.jsxs(ks,{tone:"accent",title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:n.jsx(ve,{children:"read, not installed"}),foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),n.jsx(Xt,{}),n.jsx(R,{variant:"ghost",disabled:a,onClick:d,children:"Not this one"}),n.jsx(R,{variant:"accent",disabled:a||h.length>0,onClick:()=>u(!1),children:"Install"})]}),children:[n.jsx(re,{message:o}),n.jsxs("div",{className:"plugins-staged",children:[n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[...e.author?[{label:"By",value:n.jsx(Sv,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Hp(e.source)},{label:"Published by",value:XE(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Hp(e.previousSource)}`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?n.jsx("span",{className:"mono",children:e.installsAs}):"the name its manifest gives, read when you approve — it declares no buddi.name"}],...e.coreAsDependency?[{label:"Core",value:"It asks npm for buddi's core; buddi provides its own."}]:[],{label:"Dependencies",value:m.count===0?"none":`${m.count}${m.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${m.withScripts.join(", ")}`}`},{label:"What it reaches",value:n.jsx(fW,{staged:e})},{label:"Integrity",value:n.jsx(Kp,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:n.jsx(Kp,{value:e.stagedHash})}]:[]]})}),n.jsxs("div",{className:"plugins-claim",children:[n.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),n.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?n.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):n.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"Schema it owns",value:e.claims.schema?n.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":n.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})]}),h.length>0?n.jsxs(ks,{tone:"warning",title:"What it said, and what it does",meta:n.jsx(ve,{tone:"warning",children:"read this first"}),foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),n.jsx(Xt,{}),n.jsx(R,{variant:"ghost",disabled:a,onClick:d,children:"Not this one"}),n.jsx(R,{variant:"danger",disabled:a,onClick:()=>u(!0),children:"Install anyway"})]}),children:[n.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),n.jsx("ul",{className:"plugins-drift",children:h.map(p=>n.jsx("li",{children:p},p))}),n.jsx(nA,{unlocks:(r==null?void 0:r.agents)??[]})]}):null]})}function pW({checkout:e,name:t}){const[s,r]=f.useState(!1),[i,a]=f.useState(null),l=t?`${t} is installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:i}),n.jsxs(W,{tone:e?"warning":"accent",role:"status",action:e?void 0:n.jsx(R,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),a(null),T.serviceAction("restart").catch(o=>a(ai(o))).finally(()=>r(!1))},children:"Restart to load it"}),children:[l," ",e?iW:`${t?"Its tools appear":"It takes effect"} once buddi restarts. That closes this dashboard for a few seconds.`]})]})}const Gp=e=>t=>{t.stopPropagation(),e()},gW=e=>e.unlocks.filter(t=>t.drift.state==="not-accepted").length;function xW({plugin:e,listing:t,open:s,canOpen:r,busy:i,onDetails:a,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:d,onUpdate:h}){const m=e.enabled===!1,p=gW(e);return n.jsx(ft,{onClick:a,label:`${e.name}: details`,dimmed:m,lead:n.jsx(Ka,{svg:t==null?void 0:t.iconSvg}),title:n.jsxs(n.Fragment,{children:[e.name," ",n.jsx("span",{className:"plugins-ver",children:e.version}),p>0?n.jsxs("span",{className:"plugins-ask",children:[Jr(p,"agent","agents")," to accept"]}):null]}),sub:`by ${ZE(e)} · from ${oW(e.source)} · ${JE(e.contribution)}`,side:n.jsxs("span",{className:"plugins-side",children:[t!=null&&t.update?n.jsxs(R,{size:"sm",disabled:i,onClick:Gp(()=>h(t.update)),children:["Update to ",t.update]}):null,s,!r&&o?n.jsx(R,{size:"sm",variant:"ghost",onClick:g=>{g.stopPropagation(),o()},children:"Settings"}):null,n.jsx(tA,{plugin:e}),n.jsx(tL,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:a},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,m?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:d}]})]})})}const vW={"not-accepted":["warning","not accepted"],"up-to-date":["good","up to date"],"owner-edited":["accent","yours, edited"],"proposal-changed":["warning","proposal changed"],"owner-edited-and-proposal-changed":["warning","edited, and changed"],gone:[void 0,"gone"]};function nA({plugin:e,unlocks:t}){return t.length===0?null:n.jsxs(te,{title:"Agents it would unlock",children:[n.jsx("div",{className:"plugins-unlocks",children:n.jsx(yt,{children:t.map(s=>n.jsx(jW,{plugin:e,unlock:s},s.id))})}),n.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",n.jsx("a",{href:gt,children:"on the Agents page"}),"."]})]})}function jW({plugin:e,unlock:t}){const s=Zx(e,t.id),r=s.created?"up-to-date":t.drift.state,[i,a]=vW[r];return n.jsxs("div",{className:"plugins-unlock",children:[n.jsx(ft,{title:n.jsxs("span",{className:"plugins-handle",children:["@",t.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":t.drift.message,side:n.jsxs("span",{className:"plugins-side",children:[n.jsx(ve,{tone:i,children:a}),e&&r==="not-accepted"?n.jsx(R,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),n.jsx(re,{message:s.failure}),s.created?n.jsx(oC,{agent:s.created}):null]})}function sA({svg:e,name:t,version:s,by:r,pills:i}){return n.jsxs("span",{className:"plugins-sheet-title",children:[n.jsx(Ka,{svg:e,size:"lg"}),n.jsxs("span",{className:"plugins-sheet-name",children:[n.jsxs("span",{children:[t," ",n.jsx("span",{className:"plugins-ver",children:s})]}),n.jsxs("span",{className:"plugins-sheet-by",children:["by ",r,i]})]})]})}function yW({plugin:e,listing:t,notes:s,canOpen:r,busy:i,onOpen:a,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:d,onUpdate:h}){var x,v;const m=e.enabled===!1,p=e.author!==void 0&&e.source.kind==="directory",g=(t==null?void 0:t.summary)??e.description,y=(e.network??((v=(x=t==null?void 0:t.claims)==null?void 0:x.manifest)==null?void 0:v.network)??[]).map(j=>j.host),b=e.uses??(t==null?void 0:t.usesWords);return n.jsxs(kt,{title:n.jsx(sA,{svg:t==null?void 0:t.iconSvg,name:e.name,version:e.version,by:e.author?n.jsx(Sv,{author:e.author}):ZE(e),pills:n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[" · ",n.jsx(Cv,{entry:t})]}):null," · ",n.jsx(tA,{plugin:e})]})}),onClose:o,foot:n.jsxs(J,{children:[n.jsx(R,{variant:"danger-ghost",onClick:d,children:"Remove…"}),n.jsx(Xt,{}),l?n.jsx(R,{variant:"ghost",onClick:l,children:"Settings"}):null,r?n.jsx(R,{onClick:a,children:"Open"}):null,m?n.jsx(R,{onClick:u,children:"Enable"}):n.jsx(R,{variant:"ghost",onClick:c,children:"Disable…"}),t!=null&&t.update?n.jsxs(R,{variant:"accent",disabled:i,onClick:()=>h(t.update),children:["Update to ",t.update]}):n.jsx(R,{disabled:i,onClick:()=>h(),children:"Check for an update"})]}),children:[e.error?n.jsx(W,{tone:"critical",children:e.error}):null,s&&s.length>0?n.jsx(W,{role:"status",children:s.join(" ")}):null,m?n.jsx(W,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,g?n.jsx("p",{className:"plugins-summary-full",children:g}):null,n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"From",value:Hp(e.source)},...p?[]:[{label:"Published by",value:XE(e.source,e.publisher)}],{label:"Integrity",value:n.jsx(Kp,{value:e.integrity})},{label:"Installed",value:ze(e.installedAt)},{label:"Contributes",value:JE(e.contribution)},...e.network||t?[{label:"Talks to hosts",value:eA(y)}]:[],...b?[{label:"Reaches in buddi",value:Nv(b)}]:[]]})}),n.jsx(nA,{plugin:e.name,unlocks:e.unlocks})]})}function wW({kind:e,name:t,canDisable:s,onCancel:r,onDisableInstead:i,onDisable:a,onRemove:l}){const[o,c]=f.useState(!1),[u,d]=f.useState(""),[h,m]=f.useState(!1),[p,g]=f.useState(null),y=x=>{m(!0),g(null),x().catch(v=>g(ai(v))).finally(()=>m(!1))};if(e==="disable")return n.jsxs(Xu,{title:`Disable ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:h,onClick:r,children:"Cancel"}),n.jsx(R,{variant:"accent",disabled:h,onClick:()=>y(a),children:"Disable"})]}),children:[n.jsx("p",{className:"plugins-dialog-text",children:"Its tools, pages and watchers stop now and its missions pause. Its data and the agents you accepted from it are kept; enable it to have it all back."}),n.jsx(re,{message:p})]});const b=!o||u.trim()===t;return n.jsxs(Xu,{title:`Remove ${t}?`,onClose:r,foot:n.jsxs(n.Fragment,{children:[s?n.jsx(R,{variant:"ghost",size:"sm",disabled:h,onClick:i,children:"Disable instead"}):null,n.jsx(Xt,{}),n.jsx(R,{variant:"ghost",disabled:h,onClick:r,children:"Cancel"}),n.jsx(R,{variant:"danger",disabled:h||!b,onClick:()=>y(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[n.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",t," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),n.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[n.jsxs("label",{className:"plugins-check",children:[n.jsx("input",{type:"checkbox",checked:o,onChange:x=>{c(x.target.checked),d("")}}),n.jsxs("span",{children:[n.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),n.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?n.jsx(Z,{label:n.jsxs(n.Fragment,{children:["Type ",n.jsx("span",{className:"mono",children:t})," to confirm"]}),children:n.jsx("input",{autoFocus:!0,value:u,onChange:x=>d(x.target.value)})}):null]}),n.jsx(re,{message:p})]})}function bW({plugins:e,openFor:t}){return n.jsxs(Ct,{boxed:!0,summary:`Ships with buddi · ${Jr(e.length,"plugin","plugins")}`,children:[n.jsx("p",{className:"plugins-note",children:"Compiled into this buddi: nothing to approve, nothing to remove. An agent still reaches one only if its own tools line names it."}),n.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(a=>a.host),i=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return n.jsxs("div",{className:"plugins-builtin",title:i||void 0,children:[n.jsx("span",{className:"mono",children:s.name}),n.jsxs("span",{className:"plugins-builtin-n",children:[t(s.name,"ghost"),Jr(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const kW=[{value:"days",label:"Your days"},{value:"money",label:"Money"},{value:"voice",label:"Voice"},{value:"work",label:"Work"},{value:"home",label:"Home"},{value:"other",label:"Other"}];function SW(e,t){const s=t.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm].some(r=>r.toLowerCase().includes(s))}function NW({pricing:e}){return e.kind==="free"?n.jsx(n.Fragment,{children:"free"}):n.jsxs(n.Fragment,{children:[e.kind==="paid"?"paid":"a subscription",e.trialDays?` · ${e.trialDays} days to try`:"",e.note?` · ${e.note}`:"",e.vendor?n.jsxs(n.Fragment,{children:[" · ",n.jsx("a",{href:e.vendor,target:"_blank",rel:"noopener noreferrer",children:"its maker's page"})]}):null]})}function CW({entry:e,busy:t,onOpen:s,onInstall:r,onUpdate:i}){var a;return n.jsxs(ks,{onClick:s,label:`${e.title}: details`,children:[n.jsxs("div",{className:"plugins-card-head",children:[n.jsx(Ka,{svg:e.iconSvg,size:"lg"}),n.jsxs("div",{className:"plugins-card-name",children:[n.jsx("h3",{className:"ui-card-title",children:e.title}),n.jsxs("div",{className:"plugins-card-by",children:["by ",((a=e.author)==null?void 0:a.name)??"someone who gave no name"]})]})]}),n.jsx("p",{className:"plugins-summary",children:e.summary}),n.jsxs("div",{className:"plugins-card-foot",children:[n.jsx(Cv,{entry:e}),e.installed?n.jsxs(ve,{children:["installed ",e.installed.version]}):null,n.jsx(Xt,{}),e.update?n.jsxs(R,{size:"sm",disabled:t,onClick:Gp(()=>i(e.update)),children:["Update to ",e.update]}):e.installed?null:n.jsx(R,{size:"sm",variant:"accent",disabled:t,onClick:Gp(r),children:"Install"})]})]})}function EW(e){var o,c;const t=(o=e.claims)==null?void 0:o.manifest,s=t==null?void 0:t.tools;if(!s)return;const r=s.filter(u=>u.tier==="auto").length,i=s.length-r,a=((c=t==null?void 0:t.sentinels)==null?void 0:c.length)??0,l=[r>0?`${r} run without asking`:null,i>0?`${i} ask${i===1?"s":""} you first`:null,a>0?`${a} on a timer`:null].filter(Boolean);return l.length===0?"none":l.join(", ")}function AW({entry:e,canOpen:t,busy:s,onOpen:r,onClose:i,onInstall:a,onUpdate:l}){var m,p,g,y,b,x,v,j;const o=(m=e.screenshots)==null?void 0:m[0],c=(((g=(p=e.claims)==null?void 0:p.manifest)==null?void 0:g.network)??[]).map(w=>w.host),u=EW(e),d=((x=(b=(y=e.claims)==null?void 0:y.manifest)==null?void 0:b.agents)==null?void 0:x.length)??0,h=(j=(v=e.claims)==null?void 0:v.package)==null?void 0:j.dependencies;return n.jsxs(kt,{title:n.jsx(sA,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?n.jsx(Sv,{author:e.author}):"someone who gave no name",pills:n.jsxs(n.Fragment,{children:[" · ",n.jsx(Cv,{entry:e}),e.installed?n.jsxs(n.Fragment,{children:[" · ",n.jsxs(ve,{children:["installed ",e.installed.version]})]}):null]})}),onClose:i,foot:n.jsxs(J,{children:[n.jsx("span",{className:"plugins-foot-note",children:e.installed&&!e.update?"This is the version you have.":"Install reads it first. Nothing of it runs until you say yes."}),n.jsx(Xt,{}),t?n.jsx(R,{onClick:r,children:"Open"}):null,e.update?n.jsxs(R,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:n.jsx(R,{variant:"accent",disabled:s,onClick:a,children:"Install"})]}),children:[o?n.jsx("img",{className:"plugins-shot",src:T.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,n.jsx("p",{className:"plugins-summary-full",children:e.summary}),n.jsx("div",{className:"plugins-facts",children:n.jsx(Gt,{items:[{label:"Package",value:n.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...d>0?[{label:"Proposes",value:`${Jr(d,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:eA(c)},{label:"Reaches in buddi",value:Nv(e.usesWords??[])},...h?[{label:"Dependencies",value:h.count===0?"none":`${h.count}${h.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${h.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:n.jsxs(n.Fragment,{children:[e.license??"not stated"," · ",n.jsx(NW,{pricing:e.pricing})]})}]})})]})}function TW({market:e,loading:t,busy:s,onRetry:r,onOpen:i,onInstall:a,onUpdate:l}){const[o,c]=f.useState(""),[u,d]=f.useState("all"),h=(e==null?void 0:e.plugins)??[],m=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...kW.filter(y=>h.some(b=>b.category===y.value))],p=h.filter(y=>u==="recommended"&&(y.trust!=="by-buddi"||y.installed)||u!=="all"&&u!=="recommended"&&y.category!==u?!1:SW(y,o)),g=o.trim();return n.jsxs(Q,{gap:"lg",children:[n.jsxs(J,{children:[n.jsx(C1,{grow:!0,label:"Search plugins",value:o,placeholder:"Search plugins: weather, money, calendar…",onChange:c}),n.jsx(iL,{label:"Show",options:m,value:u,onChange:d})]}),n.jsxs("p",{className:"plugins-quiet",children:[n.jsx(ye,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",n.jsx("button",{type:"button",className:"plugins-link",disabled:t,onClick:r,children:"Refresh"})]}),e===null||t&&e.unavailable?n.jsx(ce,{children:"Asking withbuddi.com…"}):e.unavailable?n.jsx(W,{tone:"warning",action:n.jsx(R,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:e.unavailable}):n.jsxs(n.Fragment,{children:[e.stale?n.jsxs(W,{tone:"warning",action:n.jsx(R,{size:"sm",disabled:t,onClick:r,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",e.fetchedAt?` ${ze(e.fetchedAt)}`:" last time","."]}):null,p.length>0?n.jsx("div",{className:"plugins-grid",children:p.map(y=>n.jsx(CW,{entry:y,busy:s,onOpen:()=>i(y),onInstall:()=>a(y),onUpdate:b=>l(y,b)},y.npm))}):n.jsx(ce,{warm:!0,title:"Nothing listed matches",children:g!==""?`No plugin on withbuddi.com mentions “${g}”.`:h.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]})]})}var Jo={},RW=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},rA={},Qn={};let Ev;const IW=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];Qn.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17};Qn.getSymbolTotalCodewords=function(t){return IW[t]};Qn.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t};Qn.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');Ev=t};Qn.isKanjiModeEnabled=function(){return typeof Ev<"u"};Qn.toSJIS=function(t){return Ev(t)};var ah={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return e.L;case"m":case"medium":return e.M;case"q":case"quartile":return e.Q;case"h":case"high":return e.H;default:throw new Error("Unknown EC Level: "+s)}}e.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},e.from=function(r,i){if(e.isValid(r))return r;try{return t(r)}catch{return i}}})(ah);function iA(){this.buffer=[],this.length=0}iA.prototype={get:function(e){const t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)===1},put:function(e,t){for(let s=0;s<t;s++)this.putBit((e>>>t-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}};var PW=iA;function Xo(e){if(!e||e<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}Xo.prototype.set=function(e,t,s,r){const i=e*this.size+t;this.data[i]=s,r&&(this.reservedBit[i]=!0)};Xo.prototype.get=function(e,t){return this.data[e*this.size+t]};Xo.prototype.xor=function(e,t,s){this.data[e*this.size+t]^=s};Xo.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]};var $W=Xo,aA={};(function(e){const t=Qn.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const i=Math.floor(r/7)+2,a=t(r),l=a===145?26:Math.ceil((a-13)/(2*i-2))*2,o=[a-7];for(let c=1;c<i-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const i=[],a=e.getRowColCoords(r),l=a.length;for(let o=0;o<l;o++)for(let c=0;c<l;c++)o===0&&c===0||o===0&&c===l-1||o===l-1&&c===0||i.push([a[o],a[c]]);return i}})(aA);var lA={};const MW=Qn.getSymbolSize,xb=7;lA.getPositions=function(t){const s=MW(t);return[[0,0],[s-xb,0],[0,s-xb]]};var oA={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(i){return i!=null&&i!==""&&!isNaN(i)&&i>=0&&i<=7},e.from=function(i){return e.isValid(i)?parseInt(i,10):void 0},e.getPenaltyN1=function(i){const a=i.size;let l=0,o=0,c=0,u=null,d=null;for(let h=0;h<a;h++){o=c=0,u=d=null;for(let m=0;m<a;m++){let p=i.get(h,m);p===u?o++:(o>=5&&(l+=t.N1+(o-5)),u=p,o=1),p=i.get(m,h),p===d?c++:(c>=5&&(l+=t.N1+(c-5)),d=p,c=1)}o>=5&&(l+=t.N1+(o-5)),c>=5&&(l+=t.N1+(c-5))}return l},e.getPenaltyN2=function(i){const a=i.size;let l=0;for(let o=0;o<a-1;o++)for(let c=0;c<a-1;c++){const u=i.get(o,c)+i.get(o,c+1)+i.get(o+1,c)+i.get(o+1,c+1);(u===4||u===0)&&l++}return l*t.N2},e.getPenaltyN3=function(i){const a=i.size;let l=0,o=0,c=0;for(let u=0;u<a;u++){o=c=0;for(let d=0;d<a;d++)o=o<<1&2047|i.get(u,d),d>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|i.get(d,u),d>=10&&(c===1488||c===93)&&l++}return l*t.N3},e.getPenaltyN4=function(i){let a=0;const l=i.data.length;for(let c=0;c<l;c++)a+=i.data[c];return Math.abs(Math.ceil(a*100/l/5)-10)*t.N4};function s(r,i,a){switch(r){case e.Patterns.PATTERN000:return(i+a)%2===0;case e.Patterns.PATTERN001:return i%2===0;case e.Patterns.PATTERN010:return a%3===0;case e.Patterns.PATTERN011:return(i+a)%3===0;case e.Patterns.PATTERN100:return(Math.floor(i/2)+Math.floor(a/3))%2===0;case e.Patterns.PATTERN101:return i*a%2+i*a%3===0;case e.Patterns.PATTERN110:return(i*a%2+i*a%3)%2===0;case e.Patterns.PATTERN111:return(i*a%3+(i+a)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(i,a){const l=a.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)a.isReserved(c,o)||a.xor(c,o,s(i,c,o))},e.getBestMask=function(i,a){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){a(u),e.applyMask(u,i);const d=e.getPenaltyN1(i)+e.getPenaltyN2(i)+e.getPenaltyN3(i)+e.getPenaltyN4(i);e.applyMask(u,i),d<c&&(c=d,o=u)}return o}})(oA);var lh={};const Lr=ah,Gc=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],Yc=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];lh.getBlocksCount=function(t,s){switch(s){case Lr.L:return Gc[(t-1)*4+0];case Lr.M:return Gc[(t-1)*4+1];case Lr.Q:return Gc[(t-1)*4+2];case Lr.H:return Gc[(t-1)*4+3];default:return}};lh.getTotalCodewordsCount=function(t,s){switch(s){case Lr.L:return Yc[(t-1)*4+0];case Lr.M:return Yc[(t-1)*4+1];case Lr.Q:return Yc[(t-1)*4+2];case Lr.H:return Yc[(t-1)*4+3];default:return}};var cA={},oh={};const Xl=new Uint8Array(512),hd=new Uint8Array(256);(function(){let t=1;for(let s=0;s<255;s++)Xl[s]=t,hd[t]=s,t<<=1,t&256&&(t^=285);for(let s=255;s<512;s++)Xl[s]=Xl[s-255]})();oh.log=function(t){if(t<1)throw new Error("log("+t+")");return hd[t]};oh.exp=function(t){return Xl[t]};oh.mul=function(t,s){return t===0||s===0?0:Xl[hd[t]+hd[s]]};(function(e){const t=oh;e.mul=function(r,i){const a=new Uint8Array(r.length+i.length-1);for(let l=0;l<r.length;l++)for(let o=0;o<i.length;o++)a[l+o]^=t.mul(r[l],i[o]);return a},e.mod=function(r,i){let a=new Uint8Array(r);for(;a.length-i.length>=0;){const l=a[0];for(let c=0;c<i.length;c++)a[c]^=t.mul(i[c],l);let o=0;for(;o<a.length&&a[o]===0;)o++;a=a.slice(o)}return a},e.generateECPolynomial=function(r){let i=new Uint8Array([1]);for(let a=0;a<r;a++)i=e.mul(i,new Uint8Array([1,t.exp(a)]));return i}})(cA);const uA=cA;function Av(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}Av.prototype.initialize=function(t){this.degree=t,this.genPoly=uA.generateECPolynomial(this.degree)};Av.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(t.length+this.degree);s.set(t);const r=uA.mod(s,this.genPoly),i=this.degree-r.length;if(i>0){const a=new Uint8Array(this.degree);return a.set(r,i),a}return r};var OW=Av,dA={},fi={},Tv={};Tv.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40};var qs={};const hA="[0-9]+",DW="[A-Z $%*+\\-./:]+";let Mo="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";Mo=Mo.replace(/u/g,"\\u");const _W="(?:(?![A-Z0-9 $%*+\\-./:]|"+Mo+`)(?:.|[\r
|
|
124
|
+
]))+`;qs.KANJI=new RegExp(Mo,"g");qs.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");qs.BYTE=new RegExp(_W,"g");qs.NUMERIC=new RegExp(hA,"g");qs.ALPHANUMERIC=new RegExp(DW,"g");const LW=new RegExp("^"+Mo+"$"),FW=new RegExp("^"+hA+"$"),zW=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");qs.testKanji=function(t){return LW.test(t)};qs.testNumeric=function(t){return FW.test(t)};qs.testAlphanumeric=function(t){return zW.test(t)};(function(e){const t=Tv,s=qs;e.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},e.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},e.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(a,l){if(!a.ccBits)throw new Error("Invalid mode: "+a);if(!t.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?a.ccBits[0]:l<27?a.ccBits[1]:a.ccBits[2]},e.getBestModeForData=function(a){return s.testNumeric(a)?e.NUMERIC:s.testAlphanumeric(a)?e.ALPHANUMERIC:s.testKanji(a)?e.KANJI:e.BYTE},e.toString=function(a){if(a&&a.id)return a.id;throw new Error("Invalid mode")},e.isValid=function(a){return a&&a.bit&&a.ccBits};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"numeric":return e.NUMERIC;case"alphanumeric":return e.ALPHANUMERIC;case"kanji":return e.KANJI;case"byte":return e.BYTE;default:throw new Error("Unknown mode: "+i)}}e.from=function(a,l){if(e.isValid(a))return a;try{return r(a)}catch{return l}}})(fi);(function(e){const t=Qn,s=lh,r=ah,i=fi,a=Tv,l=7973,o=t.getBCHDigit(l);function c(m,p,g){for(let y=1;y<=40;y++)if(p<=e.getCapacity(y,g,m))return y}function u(m,p){return i.getCharCountIndicator(m,p)+4}function d(m,p){let g=0;return m.forEach(function(y){const b=u(y.mode,p);g+=b+y.getBitsLength()}),g}function h(m,p){for(let g=1;g<=40;g++)if(d(m,g)<=e.getCapacity(g,p,i.MIXED))return g}e.from=function(p,g){return a.isValid(p)?parseInt(p,10):g},e.getCapacity=function(p,g,y){if(!a.isValid(p))throw new Error("Invalid QR Code version");typeof y>"u"&&(y=i.BYTE);const b=t.getSymbolTotalCodewords(p),x=s.getTotalCodewordsCount(p,g),v=(b-x)*8;if(y===i.MIXED)return v;const j=v-u(y,p);switch(y){case i.NUMERIC:return Math.floor(j/10*3);case i.ALPHANUMERIC:return Math.floor(j/11*2);case i.KANJI:return Math.floor(j/13);case i.BYTE:default:return Math.floor(j/8)}},e.getBestVersionForData=function(p,g){let y;const b=r.from(g,r.M);if(Array.isArray(p)){if(p.length>1)return h(p,b);if(p.length===0)return 1;y=p[0]}else y=p;return c(y.mode,y.getLength(),b)},e.getEncodedBits=function(p){if(!a.isValid(p)||p<7)throw new Error("Invalid QR Code version");let g=p<<12;for(;t.getBCHDigit(g)-o>=0;)g^=l<<t.getBCHDigit(g)-o;return p<<12|g}})(dA);var fA={};const Yp=Qn,mA=1335,UW=21522,vb=Yp.getBCHDigit(mA);fA.getEncodedBits=function(t,s){const r=t.bit<<3|s;let i=r<<10;for(;Yp.getBCHDigit(i)-vb>=0;)i^=mA<<Yp.getBCHDigit(i)-vb;return(r<<10|i)^UW};var pA={};const BW=fi;function Ya(e){this.mode=BW.NUMERIC,this.data=e.toString()}Ya.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)};Ya.prototype.getLength=function(){return this.data.length};Ya.prototype.getBitsLength=function(){return Ya.getBitsLength(this.data.length)};Ya.prototype.write=function(t){let s,r,i;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),i=parseInt(r,10),t.put(i,10);const a=this.data.length-s;a>0&&(r=this.data.substr(s),i=parseInt(r,10),t.put(i,a*3+1))};var WW=Ya;const HW=fi,Pf=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function qa(e){this.mode=HW.ALPHANUMERIC,this.data=e}qa.getBitsLength=function(t){return 11*Math.floor(t/2)+6*(t%2)};qa.prototype.getLength=function(){return this.data.length};qa.prototype.getBitsLength=function(){return qa.getBitsLength(this.data.length)};qa.prototype.write=function(t){let s;for(s=0;s+2<=this.data.length;s+=2){let r=Pf.indexOf(this.data[s])*45;r+=Pf.indexOf(this.data[s+1]),t.put(r,11)}this.data.length%2&&t.put(Pf.indexOf(this.data[s]),6)};var KW=qa;const VW=fi;function Qa(e){this.mode=VW.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}Qa.getBitsLength=function(t){return t*8};Qa.prototype.getLength=function(){return this.data.length};Qa.prototype.getBitsLength=function(){return Qa.getBitsLength(this.data.length)};Qa.prototype.write=function(e){for(let t=0,s=this.data.length;t<s;t++)e.put(this.data[t],8)};var GW=Qa;const YW=fi,qW=Qn;function Ja(e){this.mode=YW.KANJI,this.data=e}Ja.getBitsLength=function(t){return t*13};Ja.prototype.getLength=function(){return this.data.length};Ja.prototype.getBitsLength=function(){return Ja.getBitsLength(this.data.length)};Ja.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let s=qW.toSJIS(this.data[t]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[t]+`
|
|
125
|
+
Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var QW=Ja,gA={exports:{}};(function(e){var t={single_source_shortest_paths:function(s,r,i){var a={},l={};l[r]=0;var o=t.PriorityQueue.make();o.push(r,0);for(var c,u,d,h,m,p,g,y,b;!o.empty();){c=o.pop(),u=c.value,h=c.cost,m=s[u]||{};for(d in m)m.hasOwnProperty(d)&&(p=m[d],g=h+p,y=l[d],b=typeof l[d]>"u",(b||y>g)&&(l[d]=g,o.push(d,g),a[d]=u))}if(typeof i<"u"&&typeof l[i]>"u"){var x=["Could not find a path from ",r," to ",i,"."].join("");throw new Error(x)}return a},extract_shortest_path_from_predecessor_list:function(s,r){for(var i=[],a=r;a;)i.push(a),s[a],a=s[a];return i.reverse(),i},find_path:function(s,r,i){var a=t.single_source_shortest_paths(s,r,i);return t.extract_shortest_path_from_predecessor_list(a,i)},PriorityQueue:{make:function(s){var r=t.PriorityQueue,i={},a;s=s||{};for(a in r)r.hasOwnProperty(a)&&(i[a]=r[a]);return i.queue=[],i.sorter=s.sorter||r.default_sorter,i},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var i={value:s,cost:r};this.queue.push(i),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=t})(gA);var JW=gA.exports;(function(e){const t=fi,s=WW,r=KW,i=GW,a=QW,l=qs,o=Qn,c=JW;function u(x){return unescape(encodeURIComponent(x)).length}function d(x,v,j){const w=[];let S;for(;(S=x.exec(j))!==null;)w.push({data:S[0],index:S.index,mode:v,length:S[0].length});return w}function h(x){const v=d(l.NUMERIC,t.NUMERIC,x),j=d(l.ALPHANUMERIC,t.ALPHANUMERIC,x);let w,S;return o.isKanjiModeEnabled()?(w=d(l.BYTE,t.BYTE,x),S=d(l.KANJI,t.KANJI,x)):(w=d(l.BYTE_KANJI,t.BYTE,x),S=[]),v.concat(j,w,S).sort(function(N,C){return N.index-C.index}).map(function(N){return{data:N.data,mode:N.mode,length:N.length}})}function m(x,v){switch(v){case t.NUMERIC:return s.getBitsLength(x);case t.ALPHANUMERIC:return r.getBitsLength(x);case t.KANJI:return a.getBitsLength(x);case t.BYTE:return i.getBitsLength(x)}}function p(x){return x.reduce(function(v,j){const w=v.length-1>=0?v[v.length-1]:null;return w&&w.mode===j.mode?(v[v.length-1].data+=j.data,v):(v.push(j),v)},[])}function g(x){const v=[];for(let j=0;j<x.length;j++){const w=x[j];switch(w.mode){case t.NUMERIC:v.push([w,{data:w.data,mode:t.ALPHANUMERIC,length:w.length},{data:w.data,mode:t.BYTE,length:w.length}]);break;case t.ALPHANUMERIC:v.push([w,{data:w.data,mode:t.BYTE,length:w.length}]);break;case t.KANJI:v.push([w,{data:w.data,mode:t.BYTE,length:u(w.data)}]);break;case t.BYTE:v.push([{data:w.data,mode:t.BYTE,length:u(w.data)}])}}return v}function y(x,v){const j={},w={start:{}};let S=["start"];for(let k=0;k<x.length;k++){const N=x[k],C=[];for(let I=0;I<N.length;I++){const A=N[I],_=""+k+I;C.push(_),j[_]={node:A,lastCount:0},w[_]={};for(let z=0;z<S.length;z++){const L=S[z];j[L]&&j[L].node.mode===A.mode?(w[L][_]=m(j[L].lastCount+A.length,A.mode)-m(j[L].lastCount,A.mode),j[L].lastCount+=A.length):(j[L]&&(j[L].lastCount=A.length),w[L][_]=m(A.length,A.mode)+4+t.getCharCountIndicator(A.mode,v))}}S=C}for(let k=0;k<S.length;k++)w[S[k]].end=0;return{map:w,table:j}}function b(x,v){let j;const w=t.getBestModeForData(x);if(j=t.from(v,w),j!==t.BYTE&&j.bit<w.bit)throw new Error('"'+x+'" cannot be encoded with mode '+t.toString(j)+`.
|
|
126
|
+
Suggested mode is: `+t.toString(w));switch(j===t.KANJI&&!o.isKanjiModeEnabled()&&(j=t.BYTE),j){case t.NUMERIC:return new s(x);case t.ALPHANUMERIC:return new r(x);case t.KANJI:return new a(x);case t.BYTE:return new i(x)}}e.fromArray=function(v){return v.reduce(function(j,w){return typeof w=="string"?j.push(b(w,null)):w.data&&j.push(b(w.data,w.mode)),j},[])},e.fromString=function(v,j){const w=h(v,o.isKanjiModeEnabled()),S=g(w),k=y(S,j),N=c.find_path(k.map,"start","end"),C=[];for(let I=1;I<N.length-1;I++)C.push(k.table[N[I]].node);return e.fromArray(p(C))},e.rawSplit=function(v){return e.fromArray(h(v,o.isKanjiModeEnabled()))}})(pA);const ch=Qn,$f=ah,XW=PW,ZW=$W,eH=aA,tH=lA,qp=oA,Qp=lh,nH=OW,fd=dA,sH=fA,rH=fi,Mf=pA;function iH(e,t){const s=e.size,r=tH.getPositions(t);for(let i=0;i<r.length;i++){const a=r[i][0],l=r[i][1];for(let o=-1;o<=7;o++)if(!(a+o<=-1||s<=a+o))for(let c=-1;c<=7;c++)l+c<=-1||s<=l+c||(o>=0&&o<=6&&(c===0||c===6)||c>=0&&c<=6&&(o===0||o===6)||o>=2&&o<=4&&c>=2&&c<=4?e.set(a+o,l+c,!0,!0):e.set(a+o,l+c,!1,!0))}}function aH(e){const t=e.size;for(let s=8;s<t-8;s++){const r=s%2===0;e.set(s,6,r,!0),e.set(6,s,r,!0)}}function lH(e,t){const s=eH.getPositions(t);for(let r=0;r<s.length;r++){const i=s[r][0],a=s[r][1];for(let l=-2;l<=2;l++)for(let o=-2;o<=2;o++)l===-2||l===2||o===-2||o===2||l===0&&o===0?e.set(i+l,a+o,!0,!0):e.set(i+l,a+o,!1,!0)}}function oH(e,t){const s=e.size,r=fd.getEncodedBits(t);let i,a,l;for(let o=0;o<18;o++)i=Math.floor(o/3),a=o%3+s-8-3,l=(r>>o&1)===1,e.set(i,a,l,!0),e.set(a,i,l,!0)}function Of(e,t,s){const r=e.size,i=sH.getEncodedBits(t,s);let a,l;for(a=0;a<15;a++)l=(i>>a&1)===1,a<6?e.set(a,8,l,!0):a<8?e.set(a+1,8,l,!0):e.set(r-15+a,8,l,!0),a<8?e.set(8,r-a-1,l,!0):a<9?e.set(8,15-a-1+1,l,!0):e.set(8,15-a-1,l,!0);e.set(r-8,8,1,!0)}function cH(e,t){const s=e.size;let r=-1,i=s-1,a=7,l=0;for(let o=s-1;o>0;o-=2)for(o===6&&o--;;){for(let c=0;c<2;c++)if(!e.isReserved(i,o-c)){let u=!1;l<t.length&&(u=(t[l]>>>a&1)===1),e.set(i,o-c,u),a--,a===-1&&(l++,a=7)}if(i+=r,i<0||s<=i){i-=r,r=-r;break}}}function uH(e,t,s){const r=new XW;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),rH.getCharCountIndicator(c.mode,e)),c.write(r)});const i=ch.getSymbolTotalCodewords(e),a=Qp.getTotalCodewordsCount(e,t),l=(i-a)*8;for(r.getLengthInBits()+4<=l&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const o=(l-r.getLengthInBits())/8;for(let c=0;c<o;c++)r.put(c%2?17:236,8);return dH(r,e,t)}function dH(e,t,s){const r=ch.getSymbolTotalCodewords(t),i=Qp.getTotalCodewordsCount(t,s),a=r-i,l=Qp.getBlocksCount(t,s),o=r%l,c=l-o,u=Math.floor(r/l),d=Math.floor(a/l),h=d+1,m=u-d,p=new nH(m);let g=0;const y=new Array(l),b=new Array(l);let x=0;const v=new Uint8Array(e.buffer);for(let N=0;N<l;N++){const C=N<c?d:h;y[N]=v.slice(g,g+C),b[N]=p.encode(y[N]),g+=C,x=Math.max(x,C)}const j=new Uint8Array(r);let w=0,S,k;for(S=0;S<x;S++)for(k=0;k<l;k++)S<y[k].length&&(j[w++]=y[k][S]);for(S=0;S<m;S++)for(k=0;k<l;k++)j[w++]=b[k][S];return j}function hH(e,t,s,r){let i;if(Array.isArray(e))i=Mf.fromArray(e);else if(typeof e=="string"){let u=t;if(!u){const d=Mf.rawSplit(e);u=fd.getBestVersionForData(d,s)}i=Mf.fromString(e,u||40)}else throw new Error("Invalid data");const a=fd.getBestVersionForData(i,s);if(!a)throw new Error("The amount of data is too big to be stored in a QR Code");if(!t)t=a;else if(t<a)throw new Error(`
|
|
127
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
128
|
+
Minimum version required to store current data is: `+a+`.
|
|
129
|
+
`);const l=uH(t,s,i),o=ch.getSymbolSize(t),c=new ZW(o);return iH(c,t),aH(c),lH(c,t),Of(c,s,0),t>=7&&oH(c,t),cH(c,l),isNaN(r)&&(r=qp.getBestMask(c,Of.bind(null,c,s))),qp.applyMask(r,c),Of(c,s,r),{modules:c,version:t,errorCorrectionLevel:s,maskPattern:r,segments:i}}rA.create=function(t,s){if(typeof t>"u"||t==="")throw new Error("No input text");let r=$f.M,i,a;return typeof s<"u"&&(r=$f.from(s.errorCorrectionLevel,$f.M),i=fd.from(s.version),a=qp.from(s.maskPattern),s.toSJISFunc&&ch.setToSJISFunction(s.toSJISFunc)),hH(t,i,r,a)};var xA={},Rv={};(function(e){function t(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let r=s.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+s);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(a){return[a,a]}))),r.length===6&&r.push("F","F");const i=parseInt(r.join(""),16);return{r:i>>24&255,g:i>>16&255,b:i>>8&255,a:i&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const i=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,a=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:a,scale:a?4:l,margin:i,color:{dark:t(r.color.dark||"#000000ff"),light:t(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,i){return i.width&&i.width>=r+i.margin*2?i.width/(r+i.margin*2):i.scale},e.getImageWidth=function(r,i){const a=e.getScale(r,i);return Math.floor((r+i.margin*2)*a)},e.qrToImageData=function(r,i,a){const l=i.modules.size,o=i.modules.data,c=e.getScale(l,a),u=Math.floor((l+a.margin*2)*c),d=a.margin*c,h=[a.color.light,a.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,y=a.color.light;if(m>=d&&p>=d&&m<u-d&&p<u-d){const b=Math.floor((m-d)/c),x=Math.floor((p-d)/c);y=h[o[b*l+x]?1:0]}r[g++]=y.r,r[g++]=y.g,r[g++]=y.b,r[g]=y.a}}})(Rv);(function(e){const t=Rv;function s(i,a,l){i.clearRect(0,0,a.width,a.height),a.style||(a.style={}),a.height=l,a.width=l,a.style.height=l+"px",a.style.width=l+"px"}function r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}e.render=function(a,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=t.getOptions(c);const d=t.getImageWidth(a.modules.size,c),h=u.getContext("2d"),m=h.createImageData(d,d);return t.qrToImageData(m.data,a,c),s(h,u,d),h.putImageData(m,0,0),u},e.renderToDataURL=function(a,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(a,l,c),d=c.type||"image/png",h=c.rendererOpts||{};return u.toDataURL(d,h.quality)}})(xA);var vA={};const fH=Rv;function jb(e,t){const s=e.a/255,r=t+'="'+e.hex+'"';return s<1?r+" "+t+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function Df(e,t,s){let r=e+t;return typeof s<"u"&&(r+=" "+s),r}function mH(e,t,s){let r="",i=0,a=!1,l=0;for(let o=0;o<e.length;o++){const c=Math.floor(o%t),u=Math.floor(o/t);!c&&!a&&(a=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=a?Df("M",c+s,.5+u+s):Df("m",i,0),i=0,a=!1),c+1<t&&e[o+1]||(r+=Df("h",l),l=0)):i++}return r}vA.render=function(t,s,r){const i=fH.getOptions(s),a=t.modules.size,l=t.modules.data,o=a+i.margin*2,c=i.color.light.a?"<path "+jb(i.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+jb(i.color.dark,"stroke")+' d="'+mH(l,a,i.margin)+'"/>',d='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(i.width?'width="'+i.width+'" height="'+i.width+'" ':"")+d+' shape-rendering="crispEdges">'+c+u+`</svg>
|
|
130
|
+
`;return typeof r=="function"&&r(null,m),m};const pH=RW,Jp=rA,jA=xA,gH=vA;function Iv(e,t,s,r,i){const a=[].slice.call(arguments,1),l=a.length,o=typeof a[l-1]=="function";if(!o&&!pH())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(i=s,s=t,t=r=void 0):l===3&&(t.getContext&&typeof i>"u"?(i=r,r=void 0):(i=r,r=s,s=t,t=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=t,t=r=void 0):l===2&&!t.getContext&&(r=s,s=t,t=void 0),new Promise(function(c,u){try{const d=Jp.create(s,r);c(e(d,t,r))}catch(d){u(d)}})}try{const c=Jp.create(s,r);i(null,e(c,t,r))}catch(c){i(c)}}Jo.create=Jp.create;Jo.toCanvas=Iv.bind(null,jA.render);Jo.toDataURL=Iv.bind(null,jA.renderToDataURL);Jo.toString=Iv.bind(null,function(e,t,s){return gH.render(e,s)});async function xH(e){const t=await Jo.toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}const yb=10*6e4,vH=2e3;function Pv(e,t){const[s,r]=f.useState(null),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),d=f.useRef(e);d.current=e;const h=f.useRef(t);h.current=t;const m=f.useCallback(async()=>{const p=await T.telegramPairing();r(p),u(!1),o(!1),a(await xH(p.link).catch(()=>""))},[]);return f.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+yb,Date.now()+yb),y=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}d.current().then(b=>{var x;p||!b||(o(!0),(x=h.current)==null||x.call(h))}).catch(()=>{})},vH);return()=>{p=!0,window.clearInterval(y)}},[s,l,c]),{offer:s,square:i,paired:l,stale:c,ask:m}}function $v({offer:e,square:t,children:s}){return n.jsxs("div",{className:"meet-pair",children:[t?n.jsx("img",{className:"meet-qr",src:t,alt:e.link}):null,n.jsx("a",{className:"meet-link",href:e.link,target:"_blank",rel:"noreferrer",children:e.link}),s]})}const yA=new Set(["approval","question"]),ju={approval:{label:"Approvals",hint:"A run nobody is watching wants to do something gated."},question:{label:"Questions",hint:"A run asked you something and waits."},watcher:{label:"Watchers",hint:"A watcher or a source found something."},reminder:{label:"Reminders",hint:"A reminder an agent promised you came due."},failure:{label:"Failures",hint:"Background jobs died and will not be retried."},recap:{label:"Reports",hint:"Mission reports, the weekly recap, answers to actions you tapped."},plugin:{label:"Plugins",hint:"A plugin that may send you messages has something to say."},agent:{label:"Messages from your agents",hint:"An agent told you something itself."}},jH=new Set(["agent"]),yH={maxUrgency:"now",muted:[]};function wH(e,t){var i;const s=ju[e.kind].label.toLowerCase();return e.kind!=="agent"||!e.agentId?s:`from ${((i=t.find(a=>a.id===e.agentId))==null?void 0:i.name)??e.agentId}`}function bH({timezone:e}){var b,x,v;const t=le(()=>T.notificationSettings(),[]),s=le(()=>T.agents(),[]),r=le(()=>T.notifications(20),[],3e4),[i,a]=f.useState(null),[l,o]=f.useState(!1),[c,u]=f.useState(!1),[d,h]=f.useState(null),m=((b=t.data)==null?void 0:b.channels)??[],p=i??((x=t.data)==null?void 0:x.settings),g=j=>{p&&(u(!1),a({...p,...j}))},y=()=>{p&&(o(!0),u(!1),h(null),T.saveNotificationSettings(p).then(()=>{u(!0),a(null),t.reload()}).catch(j=>h(j instanceof ge?j.message:String(j))).finally(()=>o(!1)))};return n.jsxs(Q,{gap:"lg",children:[n.jsx(te,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:l||!p,onClick:y,children:"Save"}),children:n.jsxs(Q,{divided:!0,children:[n.jsx(re,{message:t.error??d}),n.jsx(te,{title:"Where buddi reaches you",children:p?m.length===0?n.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",n.jsx("a",{href:Be("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):n.jsxs(Q,{gap:"sm",children:[m.map(j=>{var w;return n.jsx(TH,{channel:j,checked:(p.defaultChannel??((w=m[0])==null?void 0:w.kind))===j.kind,onPick:()=>g({defaultChannel:j.kind})},j.kind)}),m.some(j=>j.kind==="telegram")?null:n.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",n.jsx("a",{href:Be("telegram"),children:"Set up Telegram"})]})]}):n.jsx(ce,{children:"Loading…"})}),n.jsx(te,{title:"By kind",children:p?n.jsxs(Q,{gap:"sm",children:[i$.filter(j=>!jH.has(j)).map(j=>n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:ju[j].label}),n.jsx("span",{className:"ui-field-hint",children:ju[j].hint})]}),n.jsxs("select",{"aria-label":ju[j].label,value:RH(p,j,m),onChange:w=>{const S={...p.perKind};w.target.value==="default"?delete S[j]:S[j]=w.target.value,g({perKind:S})},children:[n.jsx("option",{value:"default",children:"Default"}),m.map(w=>n.jsx("option",{value:w.kind,children:w.label},w.kind)),yA.has(j)?null:n.jsx("option",{value:"off",children:"Off"})]})]},j)),n.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),n.jsx(te,{title:"Messages from your agents",children:p?n.jsx(kH,{settings:p,agents:((v=s.data)==null?void 0:v.agents)??[],onChange:g}):null}),n.jsx(te,{title:"Focus schedules",children:p?n.jsxs(Q,{gap:"sm",children:[n.jsx($H,{schedules:p.schedules,onChange:j=>g({schedules:j})}),n.jsxs("p",{className:"ui-field-hint",children:["Do not disturb holds everything but approvals and questions; Urgent only also lets watchers and failures through. What waited comes in one message when the focus ends. Switch a focus by hand from your initial at the foot of the rail, or /focus on Telegram. Times are on your clock (",e,")."]}),n.jsx("div",{className:"nt-times",children:n.jsx(Z,{label:"End of the day",children:n.jsx("input",{type:"time",value:p.endOfDay,onChange:j=>g({endOfDay:j.target.value})})})}),n.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),c?n.jsx(W,{tone:"good",role:"status",children:"Saved."}):null]})}),n.jsx(SH,{}),n.jsxs(te,{title:"The last twenty",panel:!0,flush:!0,children:[n.jsx(re,{message:r.error}),r.data?r.data.notifications.length===0?n.jsx(ce,{children:"Nothing yet. What buddi tells you will be listed here."}):n.jsx(yt,{children:r.data.notifications.map(j=>{var w;return n.jsx(ft,{title:Eo(j),sub:`${Ve(j.createdAt,e)} · ${wH(j,((w=s.data)==null?void 0:w.agents)??[])} · ${IH(j,m)}`,side:n.jsx(PH,{row:j})},j.id)})}):n.jsx(ce,{children:"Loading…"})]})]})}function kH({settings:e,agents:t,onChange:s}){const r=e.perKind.agent!=="off",i=e.agents??yH,a=o=>{const c={...e.perKind};o?delete c.agent:c.agent="off",s({perKind:c})},l=(o,c)=>s({agents:{...i,muted:c?[...new Set([...i.muted,o])]:i.muted.filter(u=>u!==o)}});return n.jsxs(Q,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:r,onChange:o=>a(o.target.checked)}),n.jsx("span",{children:"Agents may message you"})]}),n.jsxs("div",{className:"pref-row nt-kind",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Highest urgency"}),n.jsx("span",{className:"ui-field-hint",children:"End of the day holds every message for the end-of-day message."})]}),n.jsxs("select",{"aria-label":"Highest urgency for agents",value:i.maxUrgency,disabled:!r,onChange:o=>s({agents:{...i,maxUrgency:o.target.value==="today"?"today":"now"}}),children:[n.jsx("option",{value:"now",children:"Now"}),n.jsx("option",{value:"today",children:"End of the day"})]})]}),t.length>0?n.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Muted agents",children:t.map(o=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:i.muted.includes(o.id),disabled:!r,onChange:c=>l(o.id,c.target.checked),"aria-label":`Mute @${o.handle}`}),n.jsxs("span",{children:["Mute ",o.name," (@",o.handle,")"]})]},o.id))}):null,n.jsx("p",{className:"ui-field-hint",children:'An agent given the owner.notify tool can message you itself, signed "@agent: title" on Telegram; here the agent is named beside it. Each agent may send 6 urgent messages an hour and 20 a day. Off keeps them in the list below and never sends them.'})]})}function SH(){var u;const e=le(()=>T.tipsSettings(),[]),[t,s]=f.useState(!1),[r,i]=f.useState(null),[a,l]=f.useState(null),o=a??((u=e.data)==null?void 0:u.enabled)??!0,c=d=>{s(!0),i(null),l(d),T.saveTipsSettings(d).then(h=>l(h.enabled)).catch(h=>{l(!d),i(h instanceof ge?h.message:String(h))}).finally(()=>s(!1))};return n.jsx(te,{title:"Tips",panel:!0,children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:e.error??r}),n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:o,disabled:t||!e.data,onChange:d=>c(d.target.checked)}),n.jsx("span",{children:"Tips on Home"})]}),n.jsx("p",{className:"ui-field-hint",children:"When something in buddi has gone unused, Home may say so in one sentence, at most once a day."})]})})}function NH({timezone:e}){return n.jsx(CH,{timezone:e,onChange:()=>{}})}function CH({timezone:e,onChange:t}){var C,I;const s=le(()=>T.telegramBot(),[]),r=le(()=>T.telegramDevices(),[]),[i,a]=f.useState(!1),[l,o]=f.useState(""),[c,u]=f.useState(!1),[d,h]=f.useState(null),[m,p]=f.useState(null),g=f.useRef(new Set),y=Pv(()=>T.telegramDevices().then(A=>A.devices.some(_=>!g.current.has(_.id))),()=>{r.reload(),t()}),b=((C=s.data)==null?void 0:C.configured)??!1,x=!b||i,v=()=>{var _;if(l.trim()===""||c)return;u(!0),h(null);const A=i&&(((_=s.data)==null?void 0:_.running)??!1);T.saveTelegramToken(l.trim()).then(z=>{o(""),a(!1),h(z.restartNeeded?{ok:!1,text:z.note??"Saved. It will be ready the next time buddi starts."}:A?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),t()}).catch(z=>h({ok:!1,text:z instanceof ge?z.message:String(z)})).finally(()=>u(!1))},j=()=>{var A;p(null),g.current=new Set((((A=r.data)==null?void 0:A.devices)??[]).map(_=>_.id)),y.ask().catch(_=>p(_ instanceof ge?_.message:String(_)))},{offer:w,square:S,paired:k,stale:N}=y;return n.jsx(te,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{title:"The bot",foot:x?n.jsxs(n.Fragment,{children:[i?n.jsx(R,{variant:"ghost",onClick:()=>{a(!1),o("")},children:"Cancel"}):null,n.jsx(R,{variant:"accent",disabled:c||l.trim()==="",onClick:v,children:"Save token"})]}):void 0,children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:s.error}),!s.data&&!s.error?n.jsx(ce,{children:"Loading…"}):b&&!i?n.jsxs("div",{className:"nt-channel",children:[n.jsx("span",{className:"pref-label",children:(I=s.data)!=null&&I.username?`Bot: @${s.data.username}`:"A bot token is saved."}),n.jsx(R,{variant:"ghost",size:"sm",onClick:()=>{a(!0),h(null)},children:"Replace token"})]}):null,x?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),n.jsx(Z,{label:"Bot token",grow:!0,children:n.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:A=>o(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),v())}})})]}):null,d?n.jsx(W,{tone:d.ok?"good":"warning",role:"status",children:d.text}):null]})}),n.jsxs(te,{title:"Your devices",children:[n.jsx(re,{message:r.error}),r.data?r.data.devices.length===0?n.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):n.jsx(yt,{children:r.data.devices.map(A=>n.jsx(ft,{title:A.name??`Telegram user ${A.userId}`,sub:`Paired ${Ve(A.pairedAt,e)} · ${A.lastSeenAt?`last spoke ${ze(A.lastSeenAt)}`:"has not spoken yet"}`,side:n.jsx(EH,{id:A.id,onGone:()=>{r.reload(),t()}})},A.id))}):r.error?null:n.jsx(ce,{children:"Loading…"})]}),n.jsx(te,{title:"Pair a device",foot:b&&(!w||k)?n.jsx(R,{variant:w?void 0:"accent",onClick:j,children:"Pair a phone"}):b&&N?n.jsx(R,{variant:"accent",onClick:j,children:"New code"}):void 0,children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:m}),b?k?n.jsx(W,{tone:"good",role:"status",children:"Paired."}):w&&N?n.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):w?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"ui-card-meta",children:"Open this on your phone, then send /start to the bot."}),n.jsx($v,{offer:w,square:S,children:n.jsx(AH,{text:w.link})}),n.jsxs("p",{className:"ui-field-hint",children:["The code works until ",Ve(w.expiresAt,e),"."]})]}):n.jsx("p",{className:"ui-card-meta",children:"Pair another phone, or the first one if you skipped it."}):n.jsx("p",{className:"ui-card-meta",children:"Save a bot token first."})]})})]})})}function EH({id:e,onGone:t}){const[s,r]=f.useState(!1),[i,a]=f.useState(!1),[l,o]=f.useState(null);if(!s)return n.jsx(R,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{a(!0),o(null),T.unpairTelegramDevice(e).then(t).catch(u=>o(u instanceof ge?u.message:String(u))).finally(()=>a(!1))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),n.jsx(R,{size:"sm",variant:"ghost",disabled:i,onClick:()=>r(!1),children:"Keep"}),n.jsx(R,{size:"sm",variant:"danger",disabled:i,onClick:c,children:"Unpair"})]})}function AH({text:e}){const[t,s]=f.useState(null),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return n.jsxs("span",{className:"nt-channel",children:[n.jsx(R,{size:"sm",onClick:r,children:"Copy"}),t?n.jsx("span",{className:"ui-field-hint",role:"status",children:t}):null]})}function TH({channel:e,checked:t,onPick:s}){const[r,i]=f.useState(!1),[a,l]=f.useState(null),o=()=>{i(!0),l(null),T.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof ge?c.message:String(c)})).finally(()=>i(!1))};return n.jsxs("div",{className:"nt-channel",children:[n.jsxs("label",{children:[n.jsx("input",{type:"radio",name:"nt-default-channel",checked:t,onChange:s}),n.jsxs("span",{className:"nt-channel-text",children:[n.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),n.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),a?n.jsx("span",{className:"nt-channel-sent","data-tone":a.ok?void 0:"critical",role:"status",children:a.text}):null]})]}),n.jsx(R,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function RH(e,t,s){const r=e.perKind[t];return r==="off"?yA.has(t)?"default":"off":r&&s.some(i=>i.kind===r)?r:"default"}function IH(e,t){var s;return e.channel&&e.channel!=="dashboard"?((s=t.find(r=>r.kind===e.channel))==null?void 0:s.label)??e.channel:"dashboard"}function PH({row:e}){return e.state==="failed"?n.jsxs("span",{className:"nt-state","data-tone":"critical",children:["Failed: ",e.error??"no reason given"]}):e.actedAt?n.jsx("span",{className:"nt-state",children:"Acted on"}):e.seenAt?n.jsx("span",{className:"nt-state",children:"Seen"}):e.state==="held"?n.jsx("span",{className:"nt-state",children:"Waiting"}):e.state==="stored"?n.jsx("span",{className:"nt-state",children:"Kept"}):e.state==="sent"?n.jsx("span",{className:"nt-state",children:"Sent"}):n.jsx("span",{className:"nt-state",children:"Not seen"})}const wb={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},bb={mode:"do-not-disturb",days:[...Wm],from:"22:00",to:"07:00"};function $H({schedules:e,onChange:t}){const s=(r,i)=>t(e.map((a,l)=>l===r?{...a,...i}:a));return n.jsxs(Q,{gap:"sm",children:[e.length===0?n.jsx("p",{className:"ui-card-meta",children:"No schedule: a focus is on only when you switch one on."}):null,e.map((r,i)=>{const a=i+1;return n.jsxs("div",{className:"nt-schedule",role:"group","aria-label":`Schedule ${a}`,children:[n.jsxs("select",{"aria-label":`Schedule ${a} mode`,value:r.mode,onChange:l=>s(i,{mode:l.target.value}),children:[n.jsx("option",{value:"do-not-disturb",children:"Do not disturb"}),n.jsx("option",{value:"urgent-only",children:"Urgent only"})]}),n.jsx("span",{className:"nt-days",children:Wm.map(l=>{const o=r.days.includes(l);return n.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${a} ${wb[l]}`,onClick:()=>s(i,{days:o?r.days.filter(c=>c!==l):Wm.filter(c=>c===l||r.days.includes(c))}),children:wb[l]},l)})}),n.jsx(Z,{label:"From",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} from`,value:r.from,onChange:l=>s(i,{from:l.target.value})})}),n.jsx(Z,{label:"To",children:n.jsx("input",{type:"time","aria-label":`Schedule ${a} to`,value:r.to,onChange:l=>s(i,{to:l.target.value})})}),n.jsx(R,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${a}`,onClick:()=>t(e.filter((l,o)=>o!==i)),children:"Remove"})]},i)}),n.jsx("div",{className:"nt-schedule-add",children:n.jsx(R,{size:"sm",onClick:()=>t([...e,{...bb,days:[...bb.days]}]),children:"Add a schedule"})})]})}const MH={you:"person",appearance:"sun",notifications:"bell",telegram:"send",memory:"notebook",proposals:"bulb",accounts:"key",computer:"monitor",secrets:"key",connections:"globe",watchers:"eye",backup:"archive",system:"chip",plugins:"plug"};function OH(e){const t=hD.map(r=>({id:r.id,route:Be(r.id),label:r.label,icon:MH[r.id],group:r.group})),s=[...e].sort((r,i)=>r.title.localeCompare(i.title,void 0,{sensitivity:"base"})||r.plugin.localeCompare(i.plugin)||r.id.localeCompare(i.id)).map(r=>({id:QN(r.plugin,r.id),route:ll(r.plugin,r.id),label:r.title,icon:$C(r.icon),group:"plugins"}));return[...t,...s]}function wA(e){return dD.map(t=>({id:t.id,label:t.label,entries:e.filter(s=>s.group===t.id)})).filter(t=>t.entries.length>0)}function bA(e,t,s){return t?`${e}, ${t} open`:s?`${e}, ${s}`:void 0}function DH({entries:e,active:t,counts:s={},dots:r={},navigate:i}){var u;const a=f.useRef(null),l=wA(e),o=e.some(d=>d.id===t)?t:(u=e[0])==null?void 0:u.id,c=d=>{var g;const h=[...((g=a.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=h.indexOf(document.activeElement);if(m===-1)return;const p=y=>{var b;d.preventDefault(),(b=h[Math.max(0,Math.min(h.length-1,y))])==null||b.focus()};if(d.key==="ArrowDown")p(m+1);else if(d.key==="ArrowUp")p(m-1);else if(d.key==="Home")p(0);else if(d.key==="End")p(h.length-1);else if(d.key==="Enter"||d.key===" "){d.preventDefault();const y=h[m].getAttribute("href");y&&i(y)}};return n.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:a,onKeyDown:c,children:l.map(d=>n.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${d.id}`,children:[n.jsx("div",{className:"settings-nav-label",id:`settings-nav-${d.id}`,children:d.label}),d.entries.map(h=>{const m=h.id===t,p=s[h.id],g=r[h.id];return n.jsxs("a",{className:"settings-nav-link",href:h.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":bA(h.label,p,g),tabIndex:h.id===o?0:-1,onClick:y=>{y.preventDefault(),i(h.route)},children:[n.jsx(ye,{name:h.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:h.label}),p?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},h.id)})]},d.id))})}function _H({entries:e,active:t,counts:s={},dots:r={},navigate:i}){const a=wA(e),l=e.find(o=>o.id===t)??e[0];return n.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:n.jsxs(Gd,{modal:!1,children:[n.jsx(Yd,{asChild:!0,children:n.jsxs("button",{type:"button",className:"settings-menu-trigger","aria-label":`Settings section: ${(l==null?void 0:l.label)??""}`,children:[l?n.jsx(ye,{name:l.icon,className:"settings-nav-icon"}):null,n.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),n.jsx(ye,{name:"chevron-down",className:"settings-menu-chevron"})]})}),n.jsx(Ho,{children:n.jsx(qd,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:n.jsx(jO,{value:t,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&i(c.route)},children:a.map((o,c)=>n.jsxs(VN,{children:[c>0?n.jsx(Dr,{className:"ui-menu-sep"}):null,n.jsx(Qd,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const d=s[u.id],h=r[u.id];return n.jsxs(yO,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===t?"true":void 0,"aria-label":bA(u.label,d,h),children:[n.jsxs("span",{className:"settings-menu-entry",children:[n.jsx(ye,{name:u.icon,className:"settings-nav-icon"}),n.jsx("span",{className:"settings-nav-text",children:u.label})]}),d?n.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:d>99?"99+":d}):h?n.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function LH({hash:e,timezone:t,navigate:s,agents:r,pluginPages:i}){var v,j,w;const a=fD(e),l=L1(i!==void 0),o=i??l,c=nD(e),u=c?o.find(c.plugin,c.page):void 0,d=Li(rv),h=OH(o.settings),p={proposals:((j=(v=le(()=>Promise.resolve().then(()=>T.proposals()),[],3e4).data)==null?void 0:v.open)==null?void 0:j.length)??0},g=le(()=>T.version(),[]),y=le(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4),b={};g.data&&!g.data.checkout&&g.data.updateAvailable&&(b.system="a newer buddi is ready"),(((w=y.data)==null?void 0:w.signals)??[]).length>0&&(b.connections=_C);const x={entries:h,active:a,counts:p,dots:b,navigate:S=>s(S)};return n.jsxs("div",{className:"settings",children:[d?null:n.jsx(DH,{...x}),n.jsx("div",{className:"settings-body",children:n.jsxs("div",{className:"ui-page",children:[a==="plugins"||a==="connections"?n.jsx(th,{before:n.jsx(E1,{inline:!0,items:[{label:"Settings",href:cn,onClick:()=>s(cn)}]}),title:a==="plugins"?"Plugins":"Connections",lede:a==="plugins"?nW:fE}):n.jsxs("header",{className:"ui-page-head",children:[n.jsx("h2",{className:"ui-page-title",children:"Settings"}),n.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),d?n.jsx(_H,{...x}):null,u?n.jsx(QU,{page:u,navigate:s,timezone:t,siblings:o.all.filter(S=>S.plugin===u.plugin)}):null,a==="you"?n.jsx(W8,{embedded:!0}):null,a==="appearance"?n.jsx(FH,{railPages:o.rail}):null,a==="notifications"?n.jsx(bH,{timezone:t}):null,a==="telegram"?n.jsx(NH,{timezone:t}):null,a==="memory"?n.jsx(ZC,{embedded:!0,agents:r,timezone:t}):null,a==="proposals"?n.jsx(q8,{embedded:!0,plugin:oD(e)}):null,a==="accounts"?n.jsx(d8,{embedded:!0,account:rD(e)}):null,a==="computer"?n.jsx(j3,{embedded:!0,timezone:t}):null,a==="secrets"?n.jsx(M8,{embedded:!0,timezone:t}):null,a==="connections"?n.jsx(vB,{embedded:!0,timezone:t}):null,a==="watchers"?n.jsx(U8,{timezone:t,embedded:!0}):null,a==="backup"?n.jsx(s8,{}):null,a==="plugins"?n.jsx(dW,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,a==="system"?n.jsx(BH,{timezone:t}):null]})})]})}function FH({railPages:e}){const[t,s]=KC();return n.jsx(te,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:n.jsxs(Q,{divided:!0,gap:"lg",children:[n.jsx(_f,{label:"Theme",hint:"System follows your Mac.",children:n.jsx(ls,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:t.theme,onChange:r=>s({theme:r})})}),n.jsx(_f,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:n.jsx(ls,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:t.ground,onChange:r=>s({ground:r})})}),n.jsx(_f,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:n.jsx(ls,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:t.width,onChange:r=>s({width:r})})}),n.jsx(UH,{pages:e}),n.jsx(zH,{})]})})}function zH(){var a;const e=le(()=>T.overview(),[]),[t,s]=f.useState(null),r=((a=e.data)==null?void 0:a.glances)??[];if(r.length===0)return null;const i=(l,o)=>{s(l),T.setGlanceHidden(l,!o).then(()=>e.reload()).finally(()=>s(null))};return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"Home glances"}),n.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),n.jsx(Q,{gap:"sm",children:r.map(l=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!l.hidden,disabled:t===l.id,onChange:o=>i(l.id,o.target.checked)}),n.jsx("span",{children:l.title})]},l.id))})]})}function UH({pages:e}){const t=FC(),[s,r]=f.useState(null);if(e.length===0)return null;const i=(a,l)=>{r(null),g6(a,!l).catch(o=>r(o instanceof Error?o.message:String(o)))};return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:"In the rail"}),n.jsx("span",{className:"ui-field-hint",children:"The plugin pages beside Home and Chat. One you turn off still opens from Settings → Plugins. Kept for every browser."})]}),n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:s}),e.map(a=>n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:!t.has($o(a)),onChange:l=>i(a,l.target.checked)}),n.jsx("span",{children:a.title})]},$o(a)))]})]})}function _f({label:e,hint:t,children:s}){return n.jsxs("div",{className:"pref-row ui-section",children:[n.jsxs("div",{className:"pref-text",children:[n.jsx("span",{className:"pref-label",children:e}),n.jsx("span",{className:"ui-field-hint",children:t})]}),s]})}function BH({timezone:e}){const t=le(()=>T.overview(),[],15e3),s=le(()=>T.session(),[]),r=le(()=>T.providerAccounts(),[]),i=t.data;return n.jsxs(Q,{gap:"lg",children:[n.jsx(re,{message:t.error}),n.jsx(nK,{}),i?n.jsx(te,{title:"The queue",panel:!0,actions:n.jsx(R,{size:"sm",variant:i.paused?"accent":void 0,onClick:()=>{T.setPaused(!i.paused).then(()=>t.reload())},children:i.paused?"Resume the queue":"Pause the queue"}),children:n.jsxs("p",{className:"ui-card-meta",children:[i.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",i.paused?n.jsx(ve,{tone:"warning",children:"paused"}):n.jsx(ve,{tone:"good",children:"running"})]})}):null,n.jsxs(te,{title:"This host",panel:!0,children:[n.jsx(Gt,{items:[{label:"Time zone",value:e},{label:"Server time",value:i?Ve(i.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?VH(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?n.jsx(W,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),n.jsx(KH,{}),n.jsx(a6,{}),n.jsx(WH,{}),n.jsx(te,{title:"Mail and sources",panel:!0,children:i?i.mail.length===0?n.jsx(ce,{children:"No sources are installed."}):n.jsx(Gt,{items:i.mail.map(a=>({key:a.sourceId,label:n.jsx("span",{className:"mono",children:a.sourceId}),value:a.lastError?n.jsx("span",{className:"critical",children:a.lastError}):n.jsxs("span",{children:["polled ",ze(a.lastRunAt)]})}))}):n.jsx(ce,{children:"Loading…"})})]})}function WH(){var p;const e=le(()=>T.tailscale(),[]),[t,s]=f.useState(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),[o,c]=f.useState(!1),u=e.data,d=t??((u==null?void 0:u.login)||((p=u==null?void 0:u.self)==null?void 0:p.login)||""),h=(u==null?void 0:u.proxied)===!0,m=g=>{i(!0),l(null),c(!1),T.setTailscale({enabled:g,login:d.trim()}).then(()=>{c(!0)}).catch(y=>l(y instanceof ge?y.message:String(y))).finally(()=>{i(!1),e.reload()})};return n.jsx(te,{title:"Sign in through Tailscale",panel:!0,foot:n.jsx(R,{variant:"accent",disabled:r||!u||h,onClick:()=>m((u==null?void 0:u.enabled)??!1),children:"Save"}),children:n.jsx(Q,{divided:!0,children:n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:e.error??a}),n.jsx("p",{className:"ui-card-meta",children:u?u.available&&u.self?`Tailscale is running on this machine as ${u.self.login}.`:u.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),h?n.jsxs(n.Fragment,{children:[n.jsx(W,{tone:"warning",children:"Change this from the computer buddi runs on."}),n.jsx("p",{className:"ui-card-meta",children:u!=null&&u.enabled?`On, for ${d}`:"Off"})]}):null,n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(u==null?void 0:u.enabled)??!1,disabled:r||!u||h,onChange:g=>m(g.target.checked)}),n.jsx("span",{children:"Let this Tailscale login sign in"})]}),n.jsx(Z,{label:"Tailscale login",children:n.jsx("input",{type:"text",value:d,placeholder:"you@example.com",disabled:r||!u||h,onChange:g=>s(g.target.value)})}),n.jsx("p",{className:"ui-card-meta",children:"Anyone signed in to Tailscale as this login, on any device in your tailnet, is signed in to buddi. The proxy must run on this machine:"}),n.jsxs("div",{className:"tailscale-command",children:[n.jsx("code",{className:"mono",children:(u==null?void 0:u.serveCommand)??"tailscale serve"}),n.jsx(R,{size:"sm",disabled:r||!u,onClick:()=>{HH((u==null?void 0:u.serveCommand)??"")},children:"Copy"})]}),n.jsx("p",{className:"ui-card-meta",children:"This gives your tailnet the trust this machine already has: buddi cannot tell the Tailscale proxy from another program running here, and any program that can reach the dashboard on this machine can already read buddi’s files."}),o?n.jsx(W,{tone:"good",role:"status",children:"Saved."}):null]})})})})}async function HH(e){var t;try{await((t=navigator.clipboard)==null?void 0:t.writeText(e))}catch{}}function KH(){var u;const e=le(()=>T.service(),[],1e4),[t,s]=f.useState(null),[r,i]=f.useState(!1),[a,l]=f.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=d=>{i(!0),l(null),T.serviceAction(d).then(()=>{s(null)}).catch(h=>{l(h.message)}).finally(()=>{i(!1),e.reload()})};return n.jsx(te,{title:"Service",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsx(Gt,{items:[{label:"Database",value:n.jsx(kb,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:n.jsx(kb,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:n.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:a}),t?n.jsx(W,{tone:"warning",role:"alert",children:t==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway closes this dashboard for a few seconds. If it does not come back on its own, run buddi in a terminal."}):n.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),n.jsx(J,{align:"end",children:t?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),n.jsx(R,{variant:t==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(t)},children:t==="stop"?"Stop it":"Restart it"})]}):n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),n.jsx(R,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function kb({state:e,pid:t}){return n.jsxs("span",{children:[n.jsx(ve,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",t===null?n.jsx("span",{className:"ui-card-meta",children:"no process"}):n.jsxs("span",{className:"mono",children:["pid ",t]})]})}function VH(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const GH=2e3,Sb={starting:"Getting started.",backup:"Taking a backup first, so there is a way back.",stopping:"Stopping the gateway. The database stays up.",installing:"Installing the new version.",verifying:"Checking that the new version can start its database.","rolling-back":"The new version could not start its database. Putting the previous one back.",restarting:"Restarting buddi on the new version.",migrating:"Bringing the database up to date.",done:"Done.",failed:"That did not work."},YH=new Set(["done","failed","rolled-back"]),qH="The check asks the npm registry for the newest version and sends nothing else.",QH="This takes a backup, installs the new version and restarts buddi. This page closes and comes back on its own.",JH="A checkout upgrades with git pull, then buddi upgrade in a terminal.",XH=10*6e4,ZH="buddi did not come back. Run buddi doctor in a terminal.";function eK(e){const t=e.step==="starting"?"while starting":`at ${e.step??"an unknown step"}`;return`The upgrade to ${e.to} failed ${t}: ${e.error??"no reason given"}. The backup taken first is ${e.backup??"not available"}. Run buddi doctor in a terminal; it prints the way back.`}function tK(e,t,s,r){const[i,a]=f.useState(void 0),[l,o]=f.useState(!1),[c,u]=f.useState(null),d=f.useRef(!1),h=f.useRef(s),m=f.useRef(r);return h.current=s,m.current=r,f.useEffect(()=>{if(!e){a(void 0),o(!1),d.current=!1;return}let p=!1,g=0;const y=()=>{d.current=!0,g=Date.now()+XH,o(!0)},b=()=>{if(Date.now()<g){T.session().then(j=>{p||j.version!==void 0&&j.version===t||(p=!0,h.current())}).catch(()=>{}),T.version().then(j=>{const w=j.history[j.history.length-1];p||(w==null?void 0:w.outcome)!=="failed"||(p=!0,o(!1),u(eK(w)))}).catch(()=>{});return}p=!0,o(!1),u(ZH)},x=()=>{if(!p){if(d.current)return b();T.upgradeJob(e).then(j=>{var w;p||(a(j),u(null),(YH.has(j.phase)||j.finishedAt)&&(p=!0,j.phase==="failed"&&((w=m.current)==null||w.call(m,j))))}).catch(j=>{p||(j instanceof ge&&j.status!==0&&j.status<500?u(j.message):y())})}};x();const v=window.setInterval(x,GH);return()=>{p=!0,window.clearInterval(v)}},[e,t]),{job:i,away:l,error:c}}function nK({reload:e}){var w;const t=le(()=>T.version(),[]),[s,r]=f.useState(null),[i,a]=f.useState(!1),[l,o]=f.useState(!1),[c,u]=f.useState(null),[d,h]=f.useState(null),m=(w=t.data)==null?void 0:w.current,p=e??(()=>window.location.reload()),g=f.useCallback(S=>{r(null),h(S)},[]),y=tK(s,m,p,g),b=t.data,x=()=>{o(!0),u(null),T.checkVersion().catch(S=>u(S instanceof ge?S.message:String(S))).finally(()=>{o(!1),t.reload()})},v=S=>{o(!0),u(null),T.setVersionCheck(S).catch(k=>u(k instanceof ge?k.message:String(k))).finally(()=>{o(!1),t.reload()})},j=()=>{o(!0),u(null),h(null),T.startUpgrade(b==null?void 0:b.latest).then(S=>{var k;a(!1),r(((k=S.job)==null?void 0:k.id)??null)}).catch(S=>u(S instanceof ge?S.message:String(S))).finally(()=>o(!1))};return b!=null&&b.checkout?n.jsx(te,{title:"Version",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsx(Gt,{items:[{label:"Running",value:n.jsx("span",{className:"mono",children:b.current})}]})}),n.jsx(te,{children:n.jsx("p",{className:"ui-card-meta",children:JH})})]})}):n.jsx(te,{title:"Version",panel:!0,children:n.jsxs(Q,{divided:!0,children:[n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(re,{message:t.error??c}),n.jsx(Gt,{items:[{label:"Running",value:b?n.jsx("span",{className:"mono",children:b.current}):"…"},{label:"Newest",value:b?b.updateAvailable&&b.latest?n.jsxs("span",{children:["A newer buddi is available: ",n.jsx("span",{className:"mono",children:b.latest})]}):b.checkedAt?n.jsxs("span",{children:["This is the latest, as of ",ze(b.checkedAt),"."]}):n.jsx("span",{children:"Not checked yet."}):"…"}]}),b!=null&&b.error?n.jsxs(W,{tone:"warning",children:["The last check did not get an answer: ",b.error]}):null,n.jsx(J,{align:"end",children:n.jsx(R,{disabled:l,onClick:x,children:"Check now"})})]})}),n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsxs("label",{className:"backup-check",children:[n.jsx("input",{type:"checkbox",checked:(b==null?void 0:b.checkEnabled)??!1,disabled:l||!b,onChange:S=>v(S.target.checked)}),n.jsx("span",{children:"Check once a day"})]}),n.jsx("p",{className:"ui-card-meta",children:qH})]})}),b!=null&&b.updateAvailable&&b.latest&&b.latestNotes?n.jsx(te,{title:`What changes in ${b.latest}`,children:n.jsx(gr,{text:b.latestNotes})}):null,n.jsx(te,{children:n.jsxs(Q,{gap:"sm",children:[n.jsx(sK,{...y,job:y.job??d??void 0}),i?n.jsx(W,{tone:"warning",role:"alert",children:QH}):null,n.jsx(J,{align:"end",children:i?n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",disabled:l,onClick:()=>a(!1),children:"Cancel"}),n.jsxs(R,{variant:"accent",disabled:l,onClick:j,children:["Upgrade to ",b==null?void 0:b.latest]})]}):n.jsx(R,{variant:"accent",disabled:l||s!==null||!(b!=null&&b.updateAvailable),onClick:()=>a(!0),children:b!=null&&b.updateAvailable&&b.latest?`Upgrade to ${b.latest}`:"Upgrade"})})]})}),b&&b.history.length>0?n.jsx(te,{title:"Upgrades so far",children:n.jsx(Gt,{items:b.history.slice().reverse().map(S=>({key:S.startedAt,label:n.jsxs("span",{className:"mono",children:[S.from," → ",S.to]}),value:n.jsx(rK,{attempt:S})}))})}):null]})})}function sK({job:e,away:t,error:s}){return s?n.jsx(re,{message:s}):t?n.jsx(W,{tone:"warning",role:"status",children:"buddi is restarting. This page comes back on its own when it answers again."}):e?e.phase==="failed"?n.jsxs(W,{tone:"critical",role:"alert",children:[Sb.failed," ",e.error??""," buddi is still running on the version it had."]}):n.jsx(W,{tone:e.phase==="done"?"good":void 0,role:"status",children:Sb[e.phase]??e.detail??e.phase}):null}function rK({attempt:e}){return n.jsxs("span",{children:[n.jsx(ve,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",ze(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?n.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",n.jsx("span",{className:"mono",children:e.backup})]}):null]})}const md=["hello","brain","takeOn","reach","assistant","handover"],kA={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function SA(e){return((e==null?void 0:e.accounts)??[]).filter(t=>t.enabled&&t.configured&&t.removalPending!==!0)}function iK(e){var a,l,o;const t=SA(e.accounts),s=e.assistant?(((a=e.accounts)==null?void 0:a.bindings)??[]).find(c=>c.agentId===e.assistant.id):void 0,r=(s==null?void 0:s.accountId)??((o=(l=e.onboarding)==null?void 0:l.details)==null?void 0:o.accountId);if(!r)return;const i=t.find(c=>c.id===r);if(i)return{accountId:i.id,label:i.label,model:(s==null?void 0:s.model)??i.defaultModel}}function NA(e){var a,l,o,c,u;const t=iK(e),s=e.onboarding&&!e.onboarding.needs.agent?e.assistant:void 0,r=((a=e.onboarding)==null?void 0:a.details)??{},i=((l=e.onboarding)==null?void 0:l.stepsDone)??[];return{...(o=e.owner)!=null&&o.preferredName?{name:e.owner.preferredName}:{},...(c=e.owner)!=null&&c.timezone?{clock:e.owner.timezone}:{},...t?{brain:t}:{},...Array.isArray(r.takeOn)?{takeOn:r.takeOn}:s?{takeOn:[]}:{},...r.reach?{reach:r.reach}:i.includes("reach")||s?{reach:{}}:{},...i.includes("browser")||((u=r.reach)==null?void 0:u.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function CA(e,t){return t==="hello"?typeof e.name=="string"&&e.name!==""&&typeof e.clock=="string"&&e.clock!=="":t==="brain"?e.brain!==void 0:t==="takeOn"?e.takeOn!==void 0:t==="reach"?e.reach!==void 0:t==="assistant"?e.assistant!==void 0:!1}function yu(e){return md.find(t=>!CA(e,t))??"handover"}function aK(e){const t=md.indexOf(e);return t>0?md[t-1]:null}function Nb(e,t,s){return s===t?"now":CA(e,s)?"done":"todo"}function lK(e,t){return{...e}}const Xp="buddi.firstRun.restore";function Zp(e){try{e===null?window.sessionStorage.removeItem(Xp):window.sessionStorage.setItem(Xp,e)}catch{}}function EA(){try{return window.sessionStorage.getItem(Xp)}catch{return null}}function oK(e){const t=NA(e),s=yu(t);return{answers:t,open:s,stay:s!=="handover"}}function cK(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function uK(e){const t=e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^[^a-z]+/,"").replace(/-+$/,"").slice(0,20).replace(/-+$/,"");return t===""?"assistant":t}const dK=6e4,hK=5*6e4,AA=1500,fK=2e3,mK="(max-width: 720px)";function hl(){const e=f.useRef(null);return f.useEffect(()=>{let t=0,s=0;const r=l=>{const o=l.ownerDocument.activeElement;if(o===null||o===l.ownerDocument.body||o===l.ownerDocument.documentElement)return!0;const c=l.closest('[role="dialog"]');return c!==null&&o.tagName==="BUTTON"&&o.closest('[role="dialog"]')===c},i=()=>{const l=e.current;l&&r(l)&&l.focus()},a=()=>{i(),s=window.setTimeout(i,0)};return typeof window.requestAnimationFrame=="function"?t=window.requestAnimationFrame(a):a(),window.addEventListener("focus",i),()=>{t&&window.cancelAnimationFrame(t),window.clearTimeout(s),window.removeEventListener("focus",i)}},[]),e}const Mv=f.createContext({busy:0,report:()=>{}});function pK({children:e}){const[t,s]=f.useState(0),r=f.useCallback(a=>s(l=>Math.max(0,l+(a?1:-1))),[]),i=f.useMemo(()=>({busy:t,report:r}),[t,r]);return n.jsx(Mv.Provider,{value:i,children:e})}function et({children:e}){const{busy:t}=f.useContext(Mv);return n.jsxs("div",{className:"wiz-say",children:[n.jsx(eh,{state:t>0?"working":"idle",size:"sm",className:"wiz-say-face"}),n.jsx("div",{className:"wiz-bubble",children:e})]})}function Ge({children:e}){return n.jsx(n.Fragment,{children:e})}function Ts({line:e}){const{report:t}=f.useContext(Mv);return f.useEffect(()=>(t(!0),()=>t(!1)),[t]),n.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[n.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),e]})}const Ov=f.createContext(null);function Ft({children:e,actions:t}){const s=f.useContext(Ov),r=t==null?null:s?zo.createPortal(t,s):n.jsx("div",{className:"wiz-dock-inline",children:t});return n.jsxs(n.Fragment,{children:[e?n.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function Hn({onClick:e,disabled:t}){return n.jsxs(R,{variant:"ghost",size:"lg",onClick:e,disabled:t,children:[n.jsx(ye,{name:"chevron-left"}),P.back]})}function fl({children:e,onClick:t,disabled:s}){return n.jsxs(R,{variant:"accent",size:"lg",onClick:t,disabled:s,children:[e,n.jsx(ye,{name:"arrow"})]})}function gK({navigate:e,timezone:t}){var en,Rs,H,Ee,nt,St,hn;const s=Li(mK),[r,i]=f.useState(void 0);f.useEffect(()=>{T.session().then(pe=>i(pe.platform)).catch(()=>{})},[]);const[a,l]=f.useState({}),[o,c]=f.useState(null),[u,d]=f.useState(void 0),[h,m]=f.useState(void 0),[p,g]=f.useState([]),[y,b]=f.useState(null),[x,v]=f.useState(null),[j,w]=f.useState(!1),[S,k]=f.useState(null),[N,C]=f.useState(null),[I,A]=f.useState(null),[_,z]=f.useState(null),[L,E]=f.useState(()=>EA()?"running":"idle"),[M,D]=f.useState({}),[U,$]=f.useState([]),[B,O]=f.useState(0),K=f.useRef(void 0),[G,se]=f.useState(null),ue=f.useCallback(()=>{Promise.resolve().then(()=>T.takeOnProgress()).then(pe=>{pe&&Array.isArray(pe.plugins)&&se(pe)}).catch(()=>{})},[]);f.useEffect(()=>{if(!(G!=null&&G.running))return;const pe=window.setInterval(ue,fK);return()=>window.clearInterval(pe)},[G==null?void 0:G.running,ue]);const ie=f.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||t}catch{return t}},[t]),ee=f.useRef(e);ee.current=e;const X=f.useCallback(async(pe=!0,He=!1)=>{var Zo,Qs,mi,pl,pi,Mn,gi,Js,Cr;const[Te,tn,br,Jn,kr,Sr]=await Promise.all([T.onboarding().catch(()=>{}),T.owner().catch(()=>{}),T.providerAccounts().catch(()=>{}),Fe.agents().catch(()=>{}),T.browser().catch(()=>{}),T.providers().catch(()=>{})]);d(br);const Nr=(Qs=(Zo=Sr==null?void 0:Sr.providers.find(Pt=>Pt.kind==="anthropic"))==null?void 0:Zo.defaultModel)==null?void 0:Qs.trim();m(Nr||void 0),g((tn==null?void 0:tn.zones)??[]),k(((mi=Te==null?void 0:Te.details)==null?void 0:mi.conversationId)??null);const Xe=(Jn==null?void 0:Jn.agents.find(Pt=>Pt.id===Jn.defaultAgentId))??(Jn==null?void 0:Jn.agents[0]);Xe&&b(Xe),C(Te&&!Te.needs.agent&&Xe?{id:Xe.id,name:Xe.name,avatar:((pl=Xe.avatar)==null?void 0:pl.kind)==="emoji"?Xe.avatar.value:"",description:Xe.description,...Xe.picture?{picture:Xe.picture}:{}}:null),Array.isArray((pi=Te==null?void 0:Te.details)==null?void 0:pi.takeOn)&&ue();const fn={onboarding:Te,owner:tn,accounts:br,browser:(Mn=kr==null?void 0:kr.browser)==null?void 0:Mn.engine,...Xe?{assistant:{id:Xe.id,name:Xe.name,avatar:((gi=Xe.avatar)==null?void 0:gi.kind)==="emoji"?Xe.avatar.value:""}}:{}};if(He){const Pt=oK(fn);if(l(Pt.answers),c(Pt.open),!Pt.stay){const Is=(Js=Te==null?void 0:Te.details)==null?void 0:Js.conversationId;ee.current(Is&&Xe?Je(Xe.id,Is):Vt,!0)}return}if(pe&&(Te==null?void 0:Te.state)==="done"){const Pt=(Cr=Te.details)==null?void 0:Cr.conversationId;ee.current(Pt&&Xe?Je(Xe.id,Pt):Vt,!0);return}if(!pe)return;const Ne=NA(fn);l(Ne),c(Pt=>Pt??yu(Ne))},[]);f.useEffect(()=>{X()},[X]);const de=(pe,He={})=>{Promise.resolve().then(()=>T.onboardingStep(kA[pe],He)).catch(()=>{})},Ie=pe=>yu(pe)==="brain"&&M.brain?{...pe,brain:M.brain}:pe,Se=(pe,He)=>{const Te=Ie(He);Te.brain&&(K.current=Te.brain),v(null),$([]),l(Te),pe==="brain"&&Te.brain?de(pe,{accountId:Te.brain.accountId}):pe==="reach"?de(pe,Te.reach?{reach:Te.reach}:{}):pe!=="takeOn"&&de(pe),c(yu(Te))},we=(pe,He)=>{v(null),l(He),He.brain&&(K.current=He.brain),pe==="brain"&&He.brain&&de(pe,{accountId:He.brain.accountId})},Ce=pe=>{v(null),l(He=>lK(He)),c(pe)},mt=()=>{if(!o)return;const pe=aK(o==="handover"?"handover":o);pe&&Ce(pe)},he=()=>{const pe=a.brain??K.current,He=((G==null?void 0:G.plugins)??[]).filter(Te=>Te.state==="ready").map(Te=>Te.title);v(null),D({}),$([]),l({}),c("hello"),O(Te=>Te+1),(async()=>{var Nr;const[Te,tn,br]=await Promise.all([Promise.resolve().then(()=>T.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>T.telegram()).catch(()=>{}),Promise.resolve().then(()=>T.browser()).catch(()=>{})]),Jn=SA(Te),kr=pe&&Jn.some(Xe=>Xe.id===pe.accountId)?pe:void 0;Te&&d(Te),D(kr?{brain:kr}:{});const Sr=[...new Set(Jn.map(Xe=>Xe.label)),...tn!=null&&tn.paired?[P.startOver.telegram]:[],...((Nr=br==null?void 0:br.browser)==null?void 0:Nr.engine)==="chromium"?[P.startOver.browser]:[],...He];$(Sr.length>0?[P.startOver.said(Sr.join(", "))]:[])})()},Me=()=>{w(!0),T.skipOnboarding().then(()=>e(Vt)).catch(pe=>v(pe instanceof ge?pe.message:String(pe))).finally(()=>w(!1))},Pe=le(()=>T.version().catch(()=>({current:""})),[]),Ye=f.useRef(null);f.useEffect(()=>{Ye.current&&(Ye.current.scrollTop=0)},[o]);const Y=L==="running",me=Object.keys(a).length===0,oe={answers:a,accounts:u,claudeModel:h,zones:p,browserZone:ie,assistantAgent:y,met:S,onMet:k,existing:N,progress:G,onProgress:ue,navigate:e,onSettled:pe=>o&&Se(o,pe),onKept:pe=>o&&we(o,pe),onBack:mt,onTrouble:v,onReload:()=>void X(!1),onPickAnotherBrain:()=>Ce("brain"),onSpoken:z},Oe=(a.takeOn??[]).map(pe=>{var He;return((He=Ra.find(Te=>Te.id===pe))==null?void 0:He.title)??pe}),Le=(G==null?void 0:G.plugins)??[],Ue=Le.filter(pe=>pe.state==="ready").length,at=Le.length===0?null:G!=null&&G.running?P.takeOn.installing(Ue,Le.length):Ue===Le.length?P.takeOn.installed:null,Rt=[(en=a.reach)!=null&&en.phone?P.reach.done.phone:null,(Rs=a.reach)!=null&&Rs.mailbox?P.reach.done.mailbox:null,(H=a.reach)!=null&&H.app||(Ee=a.reach)!=null&&Ee.browser?P.reach.done.app:null].filter(pe=>pe!==null),bn={hello:{answer:P.hello.answer(a.name??""),sub:a.clock??null},brain:{answer:P.brain.answer(((nt=a.brain)==null?void 0:nt.label)??"")},takeOn:{answer:P.takeOn.answer(Oe),sub:at},reach:{answer:P.reach.answer(Rt)},assistant:{answer:((St=a.assistant)==null?void 0:St.name)??""}},V=md.filter(pe=>pe!=="handover"),xe=o===null||o==="handover"?V.length:V.indexOf(o),De=Math.min(xe,V.length-1),rt=_?null:n.jsxs("div",{className:"wiz-map-out",children:[n.jsx("button",{type:"button",className:"wiz-link",disabled:j,onClick:Me,children:P.later}),o==="hello"&&me&&L==="idle"?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>E("form"),children:P.restore.offer}):!Y&&o!==null&&!(o==="hello"&&me)?n.jsx("button",{type:"button",className:"wiz-link",disabled:j,onClick:he,children:P.startOver.link}):null]}),It=r===void 0||r==="darwin"?P.tagline:P.taglineElsewhere,it=o&&o!=="handover"?n.jsx("span",{className:"wiz-count",children:P.count(xe+1)}):n.jsx("span",{className:"wiz-count"});return n.jsx(Ov.Provider,{value:I,children:n.jsx(pK,{children:n.jsxs(T1,{className:"wiz-ground",children:[n.jsx("div",{className:"wiz",ref:Ye,"data-phone":s?"true":void 0,"data-testid":"meet",children:n.jsxs("div",{className:"wiz-frame",children:[s?n.jsxs("div",{className:"wiz-strip",children:[n.jsx(ed,{size:"sm"}),n.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?P.count(xe+1):void 0,children:V.map(pe=>n.jsx("i",{"data-state":Nb(a,o,pe)},pe))}),n.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?P.strip(xe+1,P.chapters[xe]??""):P.handover.starterLabel})]}):n.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[n.jsxs("div",{className:"wiz-head",children:[n.jsx(ed,{size:"lg"}),n.jsxs("div",{children:[n.jsx("div",{className:"wiz-head-name",children:"buddi"}),n.jsx("div",{className:"wiz-head-line",children:It}),(hn=Pe.data)!=null&&hn.current?n.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",Pe.data.current]}):null]})]}),V.map((pe,He)=>{const Te=Y?pe==="hello"?"now":"todo":Nb(a,o,pe),tn=bn[pe];return n.jsxs("div",{className:"wiz-ch","data-state":Te,"aria-current":Te==="now"?"step":void 0,children:[n.jsx("span",{className:"wiz-num","data-state":Te,children:Te==="done"?n.jsx(ye,{name:"check",size:12}):He+1}),n.jsxs("span",{className:"wiz-ch-label",children:[Te==="done"?tn.answer:P.chapters[He],Te==="done"&&tn.sub?n.jsx("span",{className:"wiz-ch-sub",children:tn.sub}):null]}),Te==="done"&&!Y?n.jsx("button",{type:"button",className:"wiz-link",onClick:()=>Ce(pe),children:P.change}):null]},pe)}),n.jsx("div",{className:"wiz-map-spacer"}),n.jsx("div",{className:"wiz-map-note",children:P.mapNotes[De]}),rt]}),n.jsx("div",{className:"wiz-stage",role:"main",children:n.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[n.jsxs(aL,{dock:n.jsxs(n.Fragment,{children:[it,n.jsx("div",{className:"wiz-dock-actions",ref:A})]}),children:[Y?n.jsx(KK,{onDone:pe=>{E("idle"),$([...pe?[P.restore.welcome(pe)]:[],P.restore.keys]),X(!0,!0)},onFailed:pe=>{E("idle"),v(pe)}}):o==="hello"?n.jsx(xK,{...oe}):o==="brain"?n.jsx(jK,{...oe}):o==="takeOn"?n.jsx(OK,{...oe}):o==="reach"?n.jsx(DK,{...oe}):o==="assistant"?n.jsx(UK,{...oe}):o==="handover"?n.jsx(BK,{...oe}):n.jsx(Ts,{}),U.length>0||x?n.jsxs(Ge,{children:[U.map(pe=>n.jsx(et,{children:pe},pe)),x?n.jsx(et,{children:x}):null]}):null]},`${B}-${o??""}-${Y?"r":""}`),s?n.jsx("div",{className:"wiz-phone-out",children:rt}):null]})})]})}),L==="form"?n.jsx(HK,{onCancel:()=>E("idle"),onStarted:()=>E("running"),onTrouble:v}):null]})})})}function ml({children:e}){return n.jsx("h1",{className:"wiz-title",children:e})}function Cb(e){try{return new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",timeZone:e}).format(new Date)}catch{return""}}function xK({answers:e,zones:t,browserZone:s,onSettled:r,onTrouble:i}){const a=hl(),[l,o]=f.useState(e.name??""),[c,u]=f.useState(e.clock??s),[d,h]=f.useState(!1),[m,p]=f.useState(!1),g=()=>{const y=l.trim();y===""||m||(p(!0),T.setOwner({preferredName:y,timezone:c}).then(()=>r({...e,name:y,clock:c})).catch(b=>i(b instanceof ge?b.message:String(b))).finally(()=>p(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.hello.title}),n.jsx(Ge,{children:P.hello.opening.map(y=>n.jsx(et,{children:y},y))}),n.jsxs(Ft,{actions:n.jsx(fl,{onClick:g,disabled:m||l.trim()==="",children:P.hello.submit}),children:[n.jsxs("div",{className:"wiz-pair",children:[n.jsx(Z,{label:P.name.label,children:n.jsx("input",{ref:a,placeholder:P.name.placeholder,maxLength:80,value:l,onChange:y=>o(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),g())}})}),d?n.jsx(Z,{label:P.clock.label,hint:P.clock.hint(Cb(c)),children:n.jsx("select",{value:c,onChange:y=>u(y.target.value),children:(t.includes(c)?t:[c,...t]).map(y=>n.jsx("option",{value:y,children:y},y))})}):n.jsx(Z,{label:P.clock.label,hint:P.clock.hint(Cb(c)),action:n.jsx(R,{size:"lg",onClick:()=>h(!0),children:P.clock.change}),children:n.jsx("input",{value:c,readOnly:!0})})]}),n.jsx("div",{className:"wiz-foot",children:P.hello.foot})]})]})}const vK={free:{icon:"cloud",tone:"good"},claude:{icon:"bulb",tone:"mail"},chatgpt:{icon:"chat",tone:"coding"},key:{icon:"key",tone:"accent"},local:{icon:"monitor",tone:"plain",wide:!0}};function jK(e){const{accounts:t,answers:s,onSettled:r,onKept:i,onReload:a,onBack:l}=e,[o,c]=f.useState(null),[u,d]=f.useState("key"),[h,m]=f.useState(null),[p,g]=f.useState(!1),[y,b]=f.useState(null),[x,v]=f.useState(null),[j,w]=f.useState(null),S=(t==null?void 0:t.anthropicOAuthEnabled)===!0,k=(t==null?void 0:t.codexEnabled)===!0,N=t==null?void 0:t.gemini,[C,I]=f.useState(null);f.useEffect(()=>{let B=!1;const O=()=>{Promise.resolve().then(()=>T.ollama()).then(G=>{!B&&G&&b(G)}).catch(()=>{}),Promise.resolve().then(()=>T.mlxh()).then(G=>{!B&&G&&v(G)}).catch(()=>{B||v({running:!1,baseUrl:"",manager:!1,models:[]})})};O();const K=window.setInterval(O,4e3);return()=>{B=!0,window.clearInterval(K)}},[]);const A=async B=>{if(s.assistant??e.existing)try{await T.bindBrain({accountId:B.accountId,model:B.model})}catch(O){return O instanceof ge?O.message:String(O)}return a(),i({...s,brain:B}),C==null||C.close(),I(null),c(null),w(null),null},_=async(B,O,K)=>{g(!0),m(null);try{const G=await T.saveProviderAccount(B);let se=await T.testProviderAccount(G.id),ue=B.defaultModel,ie=!1;if(se.state!=="connected"&&K&&K!==ue&&$E(se)){const X=(await T.providerAccounts()).accounts.find(de=>de.id===G.id);X&&(await T.saveProviderAccount({id:X.id,revision:X.revision,label:X.label,kind:X.kind,auth:X.auth,baseUrl:X.baseUrl,defaultModel:K,enabled:X.enabled}),se=await T.testProviderAccount(G.id),se.state==="connected"&&(ue=K,ie=!0))}if(se.state!=="connected"){try{const X=(await T.providerAccounts()).accounts.find(de=>de.id===G.id);X&&await T.removeProviderAccount(G.id,X.revision)}catch{}return m(se.message),se}const ee=await A({accountId:G.id,label:O,model:ue,...ie?{freeTier:ie}:{}});return ee&&m(ee),se}catch(G){return m(G instanceof ge?G.message:String(G)),null}finally{g(!1)}},z=async B=>{g(!0),m(null);try{const O=await T.saveProviderAccount(B);let K;try{K=await T.testProviderAccount(O.id)}finally{try{const G=(await T.providerAccounts()).accounts.find(se=>se.id===O.id);G&&await T.removeProviderAccount(O.id,G.revision)}catch{}}return K.state!=="connected"&&m(K.message),K}catch(O){return m(O instanceof ge?O.message:String(O)),null}finally{g(!1)}},L=(B,O,K)=>{if(B.length<=1){_(O(B[0]??""),K);return}w({models:B,make:O,label:K})},E=B=>{if(B===o)return;C==null||C.close(),I((B==="free"||B==="chatgpt")&&typeof window.open=="function"?window.open("","_blank"):null),m(null),w(null),d("key"),c(B)},M=()=>{C==null||C.close(),I(null),w(null),m(null),c(null)},D=RA(y,x),U=["free",...S?["claude"]:[],...k?["chatgpt"]:[],"key","local"];let $=null;return j?$=n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:n.jsx(et,{children:P.brain.model.ask})}),p?n.jsx(Ts,{line:P.brain.checking.service}):h?n.jsx(Ge,{children:n.jsx(et,{children:h})}):null,n.jsx(yK,{busy:p,models:j.models,onBack:M,onUse:B=>void _(j.make(B),j.label)})]}):o==="key"?$=n.jsxs(n.Fragment,{children:[n.jsx(ls,{label:P.brain.keyKinds.label,value:u,onChange:B=>{m(null),d(B)},options:[{value:"key",label:P.brain.keyKinds.key},...N?[{value:"gemini",label:P.brain.keyKinds.gemini}]:[],{value:"service",label:P.brain.keyKinds.service}]}),u==="gemini"&&N?n.jsx(bK,{busy:p,problem:h,preset:N,onBack:M,onUse:_},"gemini"):u==="service"?n.jsx(SK,{busy:p,problem:h,address:(y==null?void 0:y.cloudBaseUrl)??"",onBack:M,onOffer:L,onTrial:z,onUse:_},"service"):n.jsx(wK,{busy:p,problem:h,onBack:M,onUse:_},"key")]}):o==="local"?$=n.jsx(kK,{busy:p,problem:h,probe:y,mlxh:x,onBack:M,onOffer:L,onUse:_}):o==="free"?$=n.jsx(CK,{...e,busy:p,consent:C,onBack:M,onConnected:A}):o==="chatgpt"?$=n.jsx(TK,{...e,busy:p,consent:C,onBack:M,onConnected:A}):o==="claude"&&($=n.jsx(IK,{...e,busy:p,problem:h,onBack:M,onConnected:A})),n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.brain.title}),n.jsx(Ge,{children:n.jsx(et,{children:P.brain.ask})}),n.jsx("div",{className:"wiz-grid",role:"group","aria-label":P.brain.ask,children:U.map(B=>{const O=vK[B],K=P.brain.cards[B];return n.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===B,"data-wide":O.wide?"true":void 0,onClick:()=>E(B),children:[n.jsx("span",{className:"wiz-glyph","data-tone":O.tone,"aria-hidden":"true",children:n.jsx(ye,{name:O.icon})}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:K.title}),n.jsx("span",{className:"wiz-opt-line",children:B==="local"?D:K.line}),"pill"in K?n.jsx(ve,{tone:"good",children:K.pill}):null]})]},B)})}),$,$===null&&s.brain?n.jsxs(Ge,{children:[n.jsx(et,{children:s.brain.freeTier?P.brain.worksOnFlash(s.brain.model):P.brain.works(s.brain.model)}),n.jsx(EK,{...e})]}):null,$===null?n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:l}),n.jsx(fl,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:P.brain.submit})]})}):null]})}function yK({busy:e,models:t,onBack:s,onUse:r}){const[i,a]=f.useState(t[0]??"");return n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:e}),n.jsx(R,{variant:"accent",size:"lg",disabled:e||i==="",onClick:()=>r(i),children:P.brain.model.submit})]}),children:n.jsx(Z,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:i,onChange:l=>a(l.target.value),children:t.map(l=>n.jsx("option",{value:l,children:l},l))})})})}function TA({models:e,picked:t,disabled:s,onPick:r}){return n.jsx(Z,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:t,disabled:s,onChange:i=>r(i.target.value),children:e.map(i=>n.jsx("option",{value:i,children:i},i))})})}function wK({busy:e,problem:t,onBack:s,onUse:r}){const i=hl(),[a,l]=f.useState(""),[o,c]=f.useState(null),[u,d]=f.useState(!1),[h,m]=f.useState([]),[p,g]=f.useState(""),[y,b]=f.useState(!1),x=e||u,v=!y&&t!==null&&h.length>0,j=o??cK(a),w=()=>{const S=a.trim();S===""||x||(d(!0),b(!1),(async()=>{var I;let k=j==="anthropic"?"claude-sonnet-5":"gpt-5",N=h;if(v&&p!=="")k=p;else try{const A=await T.probeModels({kind:j,auth:"api-key",secret:S});k=((I=A.models.find(_=>_.isDefault))==null?void 0:I.id)??k,N=A.models.map(_=>_.id)}catch{N=[]}d(!1);const C=await r({label:j==="anthropic"?P.brain.key.anthropic:P.brain.key.openai,kind:j,auth:"api-key",baseUrl:"",defaultModel:k,enabled:!0,secret:S},j==="anthropic"?P.brain.key.anthropic:P.brain.key.openai);if(!(!C||C.state==="connected")){if(ux(C)){b(!0),m([]);return}m(N.includes(k)||N.length===0?N:[k,...N]),g(k)}})())};return n.jsxs(n.Fragment,{children:[x?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.key})}):y?n.jsx(Ge,{children:n.jsx(et,{children:P.brain.key.refused})}):t?n.jsx(Ge,{children:n.jsx(et,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:x}),n.jsx(R,{variant:"accent",size:"lg",disabled:x||a.trim()==="",onClick:w,children:v?P.brain.model.retry:P.brain.key.submit})]}),children:[n.jsx(Z,{label:P.brain.key.field,grow:!0,children:n.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:P.brain.key.placeholder,value:a,onChange:S=>{l(S.target.value),m([])},onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),w())}})}),v?n.jsx(TA,{models:h,picked:p,disabled:x,onPick:g}):null,n.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(j==="anthropic"?"openai":"anthropic"),children:[j==="anthropic"?P.brain.key.anthropic:P.brain.key.openai," · ",P.brain.key.which]})]})]})}function bK({busy:e,problem:t,preset:s,onBack:r,onUse:i}){const a=hl(),[l,o]=f.useState(""),[c,u]=f.useState(!1),[d,h]=f.useState([]),[m,p]=f.useState(""),g=e||c,y=t!==null&&d.length>0,b=()=>{const x=l.trim();x===""||g||(u(!0),(async()=>{let v=TE,j;if(y&&m!=="")v=m;else try{const S=(await T.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:x})).models.map(k=>k.id);v=RE(S)??v,j=PE(v)?IE(S):void 0,h(c8(S)),p(j??v)}catch{}u(!1),await i({label:P.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:v,enabled:!0,secret:x},P.brain.gemini.label,j)})())};return n.jsxs(n.Fragment,{children:[g?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.gemini})}):t?n.jsx(Ge,{children:n.jsx(et,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r,disabled:g}),n.jsx(R,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:b,children:P.brain.gemini.submit})]}),children:[n.jsx(Z,{label:P.brain.gemini.field,grow:!0,children:n.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:P.brain.gemini.placeholder,value:l,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),b())}})}),y?n.jsx(Z,{label:P.brain.model.label,grow:!0,children:n.jsx("select",{value:m,disabled:g,onChange:x=>p(x.target.value),children:d.map(x=>n.jsx("option",{value:x,children:x},x))})}):null,n.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:P.brain.gemini.get})]})]})}function RA(e,t){return e===null||t===null?P.brain.local.looking:!e.running&&!t.running?P.brain.local.missing:P.brain.local.found({...e.running?{ollama:e.models.length}:{},...t.running?{mlxh:t.models.length}:{}})}function kK({busy:e,problem:t,probe:s,mlxh:r,onBack:i,onOffer:a,onUse:l}){const o=(s==null?void 0:s.models)??[],c=Lp(r),u=()=>{!(r!=null&&r.running)||!c||l({label:P.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:c,enabled:!0},P.brain.mlxh.label)},d=s!==null&&r!==null&&!s.running&&!r.running,h=()=>{s&&a(o,m=>({label:P.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:s.baseUrl,defaultModel:m,enabled:!0}),P.brain.ollama.label)};return n.jsxs(n.Fragment,{children:[e?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.ollama})}):t?n.jsx(Ge,{children:n.jsx(et,{children:t})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:i,disabled:e}),s!=null&&s.running?n.jsx(R,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e||o.length===0,onClick:h,children:P.brain.ollama.connect}):null,r!=null&&r.running?n.jsx(R,{variant:"accent",size:"lg",disabled:e||!c,onClick:u,children:P.brain.mlxh.connect}):null,d&&s?n.jsx(Ut,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:P.brain.ollama.download}):null]}),children:n.jsxs("span",{className:"wiz-foot",children:[RA(s,r),r!=null&&r.running&&!c?` ${P.brain.mlxh.noBrain}`:"",d&&(r!=null&&r.baseUrl)?` ${rE(r.baseUrl)}`:""]})})]})}function SK({busy:e,problem:t,address:s,onBack:r,onOffer:i,onTrial:a,onUse:l}){const o=hl(),[c,u]=f.useState(s),[d,h]=f.useState(""),[m,p]=f.useState(!1),[g,y]=f.useState([]),[b,x]=f.useState(""),[v,j]=f.useState(!1),w=e||m,S=!v&&t!==null&&g.length>0,k=()=>{c.trim()===""||w||(p(!0),j(!1),(async()=>{var M;const N=d.trim()?"api-key":"none",C=D=>({label:P.brain.service.label,kind:"openai-compatible",auth:N,baseUrl:c.trim(),defaultModel:D,enabled:!0,...d.trim()?{secret:d.trim()}:{}}),I=(D,U,$)=>{if(!(!D||D.state==="connected")){if(ux(D)){j(!0),y([]);return}y(U),x($)}};if(N==="api-key"&&S&&b!==""){p(!1),I(await l(C(b),P.brain.service.label),g,b);return}let A=[],_;try{const D=await T.probeModels({kind:"openai-compatible",auth:N,baseUrl:c.trim(),...d.trim()?{secret:d.trim()}:{}});A=D.models.map(U=>U.id),_=(M=D.models.find(U=>U.isDefault))==null?void 0:M.id}catch{}p(!1);const z=_?[_]:A;if(N==="none"){i(z,C,P.brain.service.label);return}const L=z[0]??"";if(z.length<=1){I(await l(C(L),P.brain.service.label),A,L);return}const E=await a(C(L));(E==null?void 0:E.state)==="connected"?i(z,C,P.brain.service.label):I(E,A,L)})())};return n.jsxs(n.Fragment,{children:[w?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.service})}):v?n.jsx(Ge,{children:n.jsx(et,{children:P.brain.key.refused})}):t?n.jsx(Ge,{children:n.jsx(et,{children:t})}):null,n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r,disabled:w}),n.jsx(R,{variant:"accent",size:"lg",disabled:w||c.trim()==="",onClick:k,children:S?P.brain.model.retry:P.brain.service.submit})]}),children:[n.jsx(Z,{label:P.brain.service.address,grow:!0,children:n.jsx("input",{ref:o,value:c,placeholder:P.brain.service.addressPlaceholder,onChange:N=>{u(N.target.value),y([])}})}),n.jsx(Z,{label:P.brain.service.key,children:n.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:d,onChange:N=>{h(N.target.value),y([])}})}),S?n.jsx(TA,{models:g,picked:b,disabled:w,onPick:x}):null]})]})}const NK=2e3;function CK({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=f.useState(!0),[o,c]=f.useState(null),[u,d]=f.useState(null),[h,m]=f.useState(0),p=f.useRef(-1),g=f.useRef(null),y=P.brain.cloud.label;f.useEffect(()=>{if(p.current===h)return;p.current=h,l(!0),c(null);const x=h===0?t:g.current;(async()=>{try{const v=((i==null?void 0:i.accounts)??[]).find(k=>k.auth==="device-key"),j=v?{id:v.id}:await T.saveProviderAccount({label:y,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:uu,enabled:!0}),w=(await T.providerAccounts()).accounts.find(k=>k.id===j.id),S=await T.ollamaConnect(w.id,w.revision);d({id:w.id,attemptId:S.attemptId,url:S.verificationUrl}),x&&(x.location.href=S.verificationUrl)}catch(v){x==null||x.close(),c(v instanceof ge?v.message:String(v))}finally{l(!1)}})()},[h]),f.useEffect(()=>{if(!u)return;let x=!1,v=!1;const j=async()=>{if(!(x||v)){v=!0;try{const S=await T.ollamaPoll(u.id,u.attemptId);if(x||S.state==="waiting")return;if(x=!0,d(null),S.state==="failed"){c(S.message);return}l(!0),c(await b(u.id)),l(!1)}catch{}finally{v=!1}}},w=window.setInterval(()=>void j(),NK);return()=>{x=!0,window.clearInterval(w)}},[u]);const b=async x=>{try{const v=(await T.accountModels(x).catch(()=>({models:[]}))).models.map(k=>k.id),j=v.length===0||v.includes(uu)?uu:v[0],w=(await T.providerAccounts()).accounts.find(k=>k.id===x);w&&w.defaultModel!==j&&await T.saveProviderAccount({id:w.id,revision:w.revision,label:w.label,kind:w.kind,auth:w.auth,baseUrl:w.baseUrl,defaultModel:j,enabled:w.enabled});const S=await T.testProviderAccount(x);return S.state!=="connected"?S.message:await r({accountId:x,label:y,model:j})}catch(v){return v instanceof ge?v.message:String(v)}};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.cloud})}):o?n.jsx(Ge,{children:n.jsx(et,{children:o})}):u?n.jsx(Ge,{children:n.jsx(et,{children:P.brain.cloud.waiting})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:s,disabled:a||e}),u?n.jsx(Ut,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:P.brain.cloud.open}):o?n.jsx(R,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(x=>x+1)},children:P.brain.cloud.again}):null]})})]})}function EK({answers:e,accounts:t,onKept:s,onTrouble:r}){var p;const i=e.brain,a=i?((t==null?void 0:t.accounts)??[]).find(g=>g.id===i.accountId):void 0,[l,o]=f.useState([]),[c,u]=f.useState(!1),d=mv(a),h=(a==null?void 0:a.auth)==="device-key"||(a==null?void 0:a.kind)==="codex"||d||!!a&&u8(a,(p=t==null?void 0:t.gemini)==null?void 0:p.baseUrl);if(f.useEffect(()=>{if(!h||!a)return;let g=!1;return T.accountModels(a.id).then(y=>{const b=d?y.models.filter(x=>!sE({id:x.id,...x.image?{kind:"image"}:{}})):y.models;g||o(b.map(x=>x.id))}).catch(()=>{}),()=>{g=!0}},[h,a==null?void 0:a.id]),!h||!a||!i||l.length<2)return null;const m=g=>{g===i.model||c||(u(!0),r(null),(async()=>{try{await T.saveProviderAccount({id:a.id,revision:a.revision,label:a.label,kind:a.kind,auth:a.auth,baseUrl:a.baseUrl,defaultModel:g,enabled:a.enabled}),e.assistant&&await T.bindBrain({accountId:a.id,model:g}),s({...e,brain:{accountId:i.accountId,label:i.label,model:g}})}catch(y){r(y instanceof ge?y.message:String(y))}finally{u(!1)}})())};return n.jsx(et,{children:n.jsx(Z,{label:P.brain.model.change,children:n.jsx("select",{value:i.model,disabled:c,onChange:g=>m(g.target.value),children:(l.includes(i.model)?l:[i.model,...l]).map(g=>n.jsx("option",{value:g,children:g},g))})})})}const Eb="gpt-5.5",AK=2e3;function TK({busy:e,consent:t,onBack:s,onConnected:r,accounts:i}){const[a,l]=f.useState(!0),[o,c]=f.useState(null),[u,d]=f.useState(null),[h,m]=f.useState(0),p=f.useRef(-1),g=f.useRef(null),y=f.useRef(null),b=P.brain.chatgpt.label;f.useEffect(()=>()=>{const j=y.current;y.current=null,j&&T.codexAccountAction(j.id,"cancel-login",j.revision).catch(()=>{})},[]),f.useEffect(()=>{if(p.current===h)return;p.current=h,l(!0),c(null);const j=h===0?t:g.current;(async()=>{try{const w=((i==null?void 0:i.accounts)??[]).find(C=>C.kind==="codex"),S=w?{id:w.id}:await T.saveProviderAccount({label:b,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:Eb,enabled:!0}),k=(await T.providerAccounts()).accounts.find(C=>C.id===S.id),N=await T.codexAccountAction(k.id,"login",k.revision);if(!(N!=null&&N.verificationUrl)||!N.userCode)throw new Error((N==null?void 0:N.message)??P.brain.chatgpt.failed);y.current={id:k.id,revision:k.revision},d({id:k.id,revision:k.revision,url:N.verificationUrl,code:N.userCode}),j&&(j.location.href=N.verificationUrl)}catch(w){j==null||j.close(),c(w instanceof ge||w instanceof Error?w.message:String(w))}finally{l(!1)}})()},[h]),f.useEffect(()=>{if(!u)return;let j=!1,w=!1;const S=async()=>{if(!(j||w)){w=!0;try{const N=(await T.providerAccounts()).accounts.find(I=>I.id===u.id);if(j)return;const C=N==null?void 0:N.login;if(!C||C.state==="pending")return;if(j=!0,y.current=null,d(null),C.state!=="connected"){c(C.message??P.brain.chatgpt.failed);return}l(!0),c(await x(u.id)),l(!1)}catch{}finally{w=!1}}},k=window.setInterval(()=>void S(),AK);return()=>{j=!0,window.clearInterval(k)}},[u]);const x=async j=>{var w,S;try{const k=(await T.accountModels(j).catch(()=>({models:[]}))).models,N=((w=k.find(I=>I.isDefault))==null?void 0:w.id)??((S=k[0])==null?void 0:S.id)??Eb,C=(await T.providerAccounts()).accounts.find(I=>I.id===j);return C&&C.defaultModel!==N&&await T.saveProviderAccount({id:C.id,revision:C.revision,label:C.label,kind:C.kind,auth:C.auth,baseUrl:C.baseUrl,defaultModel:N,enabled:C.enabled}),await r({accountId:j,label:b,model:N})}catch(k){return k instanceof ge?k.message:String(k)}},v=()=>{const j=y.current;y.current=null,j&&T.codexAccountAction(j.id,"cancel-login",j.revision).catch(()=>{}),s()};return n.jsxs(n.Fragment,{children:[a||e?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.chatgpt})}):o?n.jsx(Ge,{children:n.jsx(et,{children:o})}):u?n.jsx(Ge,{children:n.jsxs(et,{children:[P.brain.chatgpt.codeBefore,n.jsx("strong",{children:u.code}),P.brain.chatgpt.codeAfter]})}):null,n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:v,disabled:a||e}),u?n.jsx(Ut,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:P.brain.chatgpt.open}):o?n.jsx(R,{variant:"accent",size:"lg",disabled:a||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:P.brain.chatgpt.again}):null]}),children:u?n.jsx(gv,{code:u.code,label:P.brain.chatgpt.code}):null})]})}const RK="claude-sonnet-5";function IK({busy:e,problem:t,onBack:s,onConnected:r,accounts:i,claudeModel:a}){const[l,o]=f.useState(!1),[c,u]=f.useState(null),[d,h]=f.useState(null),[m,p]=f.useState(""),g=f.useRef(null);f.useEffect(()=>()=>{const j=g.current;g.current=null,j&&T.anthropicAccountAction(j.id,"cancel-login",j.revision).catch(()=>{})},[]);const y=()=>{const j=g.current;g.current=null,j&&T.anthropicAccountAction(j.id,"cancel-login",j.revision).catch(()=>{}),s()},b=a??RK,x=()=>{o(!0),u(null);const j=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const w=((i==null?void 0:i.accounts)??[]).find(I=>I.auth==="anthropic-oauth"),S=w?{id:w.id}:await T.saveProviderAccount({label:P.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:b,enabled:!0}),N=(await T.providerAccounts()).accounts.find(I=>I.id===S.id),C=await T.anthropicAccountAction(N.id,"login",N.revision);g.current={id:N.id,revision:N.revision+1},h({id:N.id,revision:N.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),j&&C.verificationUrl?j.location.href=C.verificationUrl:j==null||j.close()}catch(w){j==null||j.close(),u(w instanceof ge?w.message:String(w))}finally{o(!1)}})()},v=()=>{!d||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await T.anthropicAccountAction(d.id,"complete-login",d.revision,{attemptId:d.attemptId,code:m.trim()});const j=await T.testProviderAccount(d.id);if(j.state!=="connected"){u(j.message);return}u(await r({accountId:d.id,label:P.brain.claude.label,model:b}))}catch(j){u(j instanceof ge?j.message:String(j))}finally{o(!1)}})())};return n.jsxs(n.Fragment,{children:[l||e?n.jsx(Ge,{children:n.jsx(Ts,{line:P.brain.checking.claude})}):t??c?n.jsx(Ge,{children:n.jsx(et,{children:t??c})}):null,d?n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:n.jsx(et,{children:P.brain.claude.waiting})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:y,disabled:l}),n.jsx(Ut,{size:"lg",href:d.url,target:"_blank",rel:"noreferrer",children:P.brain.claude.open}),n.jsx(R,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:v,children:P.brain.claude.finish})]}),children:n.jsx(Z,{label:P.brain.claude.paste,grow:!0,children:n.jsx(PK,{value:m,onChange:p})})})]}):n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:y,disabled:e||l}),n.jsx(R,{variant:"accent",size:"lg",disabled:e||l,onClick:x,children:P.brain.claude.start})]})})]})}function PK({value:e,onChange:t}){const s=hl();return n.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>t(r.target.value)})}const $K={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function MK(e){const t=(e==null?void 0:e.plugins)??[];if(t.length===0)return null;const s=t.map(i=>i.title),r=t.filter(i=>i.state==="failed");if(e!=null&&e.running){const i=t.filter(a=>a.state==="ready"||a.state==="failed").length;return{line:P.takeOn.fetching(s,Math.min(i+1,t.length),t.length),done:!1}}return r.length>0?{line:r.map(i=>P.takeOn.failed(i.title,i.reason??"")).join(" "),done:!0}:{line:P.takeOn.ready(s),done:!0}}function OK({answers:e,progress:t,onProgress:s,onSettled:r,onBack:i,onTrouble:a}){const[l,o]=f.useState(()=>e.takeOn??[...m_]),[c,u]=f.useState(!1),d=Ra.filter(g=>l.includes(g.id)),h=g=>o(y=>y.includes(g)?y.filter(b=>b!==g):[...y,g]),m=g=>{c||(u(!0),Promise.resolve().then(()=>T.takeOn(g)).then(()=>{s(),r({...e,takeOn:g})}).catch(y=>a(y instanceof ge?y.message:String(y))).finally(()=>u(!1)))},p=MK(t);return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.takeOn.title}),n.jsx(Ge,{children:n.jsx(et,{children:P.takeOn.ask})}),n.jsxs(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:i,disabled:c}),n.jsx(R,{variant:"ghost",size:"lg",disabled:c,onClick:()=>m([]),children:P.takeOn.none}),n.jsx(fl,{onClick:()=>m(Ra.filter(g=>l.includes(g.id)).map(g=>g.id)),disabled:c||l.length===0,children:P.takeOn.submit})]}),children:[n.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":P.takeOn.title,children:Ra.map(g=>{const y=l.includes(g.id);return n.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":y,onClick:()=>h(g.id),children:[n.jsxs("span",{className:"wiz-tile-top",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ye,{name:$K[g.id]})}),n.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:y?n.jsx(ye,{name:"check",size:12}):null})]}),n.jsxs("span",{children:[n.jsx("span",{className:"wiz-opt-title",children:g.title}),n.jsx("span",{className:"wiz-opt-plugins",children:g.plugins})]}),n.jsx("span",{className:"wiz-opt-line",children:g.line})]},g.id)})}),d.length>0?n.jsxs("div",{className:"wiz-stack",children:[p?n.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[n.jsxs("span",{className:"wiz-pulse","data-done":p.done?"true":void 0,"aria-hidden":"true",children:[n.jsx("i",{}),n.jsx("i",{}),n.jsx("i",{})]}),n.jsx("span",{children:p.line}),l.includes("mail")?n.jsx("span",{className:"wiz-busy-side",children:P.takeOn.builtIn}):null]}):null,n.jsx("div",{className:"wiz-foot",children:d.map(g=>g.note).join(" ")})]}):n.jsx("div",{className:"wiz-foot",children:P.takeOn.nothing})]})]})}function DK({answers:e,navigate:t,onSettled:s,onBack:r}){var g,y,b;const[i,a]=f.useState(((g=e.reach)==null?void 0:g.phone)===!0),[l,o]=f.useState(((y=e.reach)==null?void 0:y.mailbox)===!0),[c,u]=f.useState(((b=e.reach)==null?void 0:b.app)===!0),[d,h]=f.useState(e.browser),m=(e.takeOn??[]).includes("mail"),p=()=>{const x={phone:i,mailbox:l,app:c,browser:d==="chrome"||d==="chromium"||d==="installed"};d!==void 0&&Promise.resolve().then(()=>T.onboardingStep("browser")).catch(()=>{}),s({...e,reach:x,...d!==void 0?{browser:d}:{}})};return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.reach.title}),n.jsx(Ge,{children:n.jsx(et,{children:P.reach.ask})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:r}),n.jsx(fl,{onClick:p,children:P.reach.submit})]}),children:n.jsxs("div",{className:"wiz-rows",children:[n.jsx(_K,{paired:i,onPaired:()=>a(!0)}),n.jsx(FK,{wanted:m,added:l,onAdded:o,navigate:t,timezone:e.clock??"UTC"}),n.jsx(zK,{app:c,onApp:()=>u(!0),browser:d,onBrowser:h}),i?n.jsx(W,{tone:"good",role:"status",children:P.reach.phone.hello}):null]})})]})}function _K({paired:e,onPaired:t}){const[s,r]=f.useState(null),[i,a]=f.useState(!1),l=f.useRef(t);l.current=t,f.useEffect(()=>{let c=!1;return Promise.resolve().then(()=>T.telegram()).then(u=>{c||!u||(r(u),u.paired&&l.current())}).catch(()=>{c||r({configured:!1,running:!1,paired:!1})}),()=>{c=!0}},[]);const o=(s==null?void 0:s.configured)===!0&&s.running===!0&&!e;return n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:n.jsx(ye,{name:"chat"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:P.reach.phone.title}),n.jsx("span",{className:"wiz-opt-line",children:P.reach.phone.line})]}),e?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ve,{tone:"good",dot:!0,children:P.reach.phone.paired})}):o?n.jsx(LK,{onPaired:t}):n.jsx("span",{className:"wiz-row-side",children:n.jsx(R,{size:"lg",disabled:s===null,onClick:()=>a(!0),children:P.reach.phone.setUp})}),i?n.jsx(kt,{title:P.telegram.sheet,onClose:()=>a(!1),children:n.jsx(VK,{onPaired:t,onDismiss:()=>a(!1)})}):null]})}function LK({onPaired:e}){const{offer:t,square:s,paired:r,stale:i,ask:a}=Pv(()=>T.telegram().then(o=>o.paired),e),l=f.useRef(!1);return f.useEffect(()=>{l.current||(l.current=!0,a().catch(()=>{}))},[a]),r?n.jsx("span",{className:"wiz-row-side",children:n.jsx(ve,{tone:"good",dot:!0,children:P.reach.phone.paired})}):i||!t?n.jsx("span",{className:"wiz-row-side",children:n.jsx(R,{size:"lg",onClick:()=>void a().catch(()=>{}),children:P.telegram.newCode})}):n.jsx("span",{className:"wiz-qr-slot",children:n.jsx($v,{offer:t,square:s})})}function FK({wanted:e,added:t,onAdded:s,navigate:r,timezone:i}){const[a,l]=f.useState(void 0),[o,c]=f.useState(!1),[u,d]=f.useState(null),h=f.useCallback(()=>{Promise.resolve().then(()=>T.pageQuery("email","accounts")).then(m=>{var g,y,b;const p=((b=(y=(g=m==null?void 0:m.data)==null?void 0:g.accounts)==null?void 0:y[0])==null?void 0:b.address)??null;d(p),s(p!==null)}).catch(()=>{})},[]);return f.useEffect(()=>{let m=!1;return Promise.resolve().then(()=>T.pages()).then(p=>{if(m)return;const g=((p==null?void 0:p.pages)??[]).filter(b=>b.plugin==="email"),y=g.find(b=>b.id==="settings")??null;l(y?{page:y,siblings:g}:null)}).catch(()=>{m||l(null)}),h(),()=>{m=!0}},[h]),n.jsxs("div",{className:"wiz-row",children:[n.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:n.jsx(ye,{name:"mail"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:e?P.reach.mailbox.forTriage:P.reach.mailbox.title}),n.jsx("span",{className:"wiz-opt-line",children:a===null?P.reach.mailbox.unavailable:P.reach.mailbox.line})]}),n.jsx("span",{className:"wiz-row-side",children:t||u?n.jsx(ve,{tone:"good",dot:!0,mono:u!==null,children:u??P.reach.mailbox.added}):a?n.jsx(R,{size:"lg",onClick:()=>c(!0),children:P.reach.mailbox.add}):null}),o&&a?n.jsx(kt,{title:P.reach.mailbox.sheet,size:"wide",onClose:()=>{c(!1),h()},children:n.jsx(uv,{page:a.page,siblings:a.siblings,navigate:r,timezone:i,embedded:!0})}):null]})}function zK({app:e,onApp:t,browser:s,onBrowser:r}){const i=rh(),a=typeof navigator>"u"?null:DC(navigator.userAgent),[l,o]=f.useState(null),[c,u]=f.useState("idle"),[d,h]=f.useState(null),[m,p]=f.useState(null),[g,y]=f.useState(void 0),b=f.useRef(!1),x=f.useRef(!0);f.useEffect(()=>(x.current=!0,Promise.resolve().then(()=>T.browser()).then(C=>{var A;if(!x.current)return;const I=C==null?void 0:C.browser;I?((A=I.install)==null?void 0:A.state)==="running"?(o("none"),b.current=!0,u("installing"),w()):o(I.engine):o("other")}).catch(()=>{x.current&&o("other")}),()=>{x.current=!1}),[]);const v=(C,I)=>{x.current&&(b.current=!1,u("failed"),h(C),p(I??null))},j=async C=>{u("launching");let I;try{I=await T.browserCheck()}catch(A){return v(A instanceof ge?A.message:String(A))}if(x.current){if(I.ok){u("idle"),o(C),r(b.current?"installed":C);return}v(I.message,I.command)}},w=async()=>{var A,_;let C;try{C=await T.browser()}catch(z){return v(z instanceof ge?z.message:String(z))}if(!x.current)return;const I=C.browser;if(!I)return v(P.browser.failed(""));if(((A=I.install)==null?void 0:A.state)==="running"){u("installing"),y(I.install.progress),window.setTimeout(()=>void w(),1e3);return}return I.engine!=="none"?j(I.engine):v(((_=I.install)==null?void 0:_.line)??"")},S=()=>{if(p(null),l==="chrome"||l==="chromium"){j(l);return}b.current=!0,u("installing"),y(void 0),Promise.resolve().then(()=>T.browserInstall()).then(()=>{x.current&&window.setTimeout(()=>void w(),1e3)}).catch(C=>v(C instanceof ge?C.message:String(C)))},k=s==="chrome"||s==="chromium"||s==="installed",N=c==="installing"||c==="launching";return n.jsxs("div",{className:"wiz-row","data-wrap":c!=="idle"?"true":void 0,children:[n.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:n.jsx(ye,{name:"globe"})}),n.jsxs("span",{className:"wiz-row-text",children:[n.jsx("span",{className:"wiz-opt-title",children:P.reach.app.title}),n.jsx("span",{className:"wiz-opt-line",children:P.reach.app.line})]}),n.jsxs("span",{className:"wiz-row-side",children:[e?n.jsx(ve,{tone:"good",dot:!0,children:P.reach.app.installed}):i?n.jsx(R,{size:"lg",onClick:()=>{i.prompt().then(()=>i.userChoice).then(C=>{(!C||C.outcome==="accepted")&&t()}).catch(()=>{})},children:P.reach.app.install}):null,k?n.jsx(ve,{tone:"good",dot:!0,children:P.reach.app.ready(s==="chrome"?"chrome":"chromium")}):l===null||l==="other"?null:n.jsx(R,{size:"lg",disabled:N,onClick:S,children:N?P.browser.installing:c==="failed"?P.browser.retry:l==="chrome"?P.reach.app.chrome:l==="chromium"?P.reach.app.chromium:P.reach.app.fetch})]}),!e&&!i&&a?n.jsx("span",{className:"wiz-row-note",children:a}):null,c==="installing"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:P.browser.needs}),n.jsx(sC,{progress:g})]}):c==="launching"?n.jsx("div",{className:"wiz-row-more",children:n.jsx(Ts,{line:P.browser.launching})}):c==="failed"?n.jsxs("div",{className:"wiz-row-more",children:[n.jsx("span",{className:"wiz-opt-line",children:P.browser.failed(d??"")}),m?n.jsx(WK,{command:m}):null]}):null]})}function UK({answers:e,existing:t,onSettled:s,onTrouble:r,onReload:i,onBack:a}){const[l,o]=f.useState(()=>(t==null?void 0:t.name)??l_),[c,u]=f.useState(()=>t!=null&&t.picture||t!=null&&t.avatar?null:"buddi"),[d,h]=f.useState(t?null:P.assistant.purposeValue),[m,p]=f.useState(t?"":P.assistant.purposeValue);f.useEffect(()=>{if(!t)return;let j=!1;return T.firstAgentPersona().then(w=>{j||(h(w.persona),p(w.persona))},w=>{j||r(w instanceof ge?w.message:String(w))}),()=>{j=!0}},[t==null?void 0:t.id]);const[g,y]=f.useState(!1),b=Ra.filter(j=>(e.takeOn??[]).includes(j.id)&&"mate"in j).map(j=>j.mate),x=tw.find(j=>j.id===c),v=()=>{if(l.trim()===""||g)return;y(!0);const j=!t||d!==null&&m.trim()!==""&&m.trim()!==d.trim()?{instructions:m.trim()}:{},w=t?T.updateFirstAgent({name:l.trim(),...j}):T.createFirstAgent({name:l.trim(),handle:uK(l),description:"",...j,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{let S;try{S=await w}catch(N){r(N instanceof ge?N.message:String(N)),y(!1);return}let k=null;try{x&&await T.uploadAgentPicture(S.id,await gE(x.role))}catch(N){k=N instanceof ge?N.message:String(N)}y(!1),i(),s({...e,assistant:{id:S.id,name:l.trim(),avatar:x?"":(t==null?void 0:t.avatar)??""}}),k&&r(k)})()};return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.assistant.title}),n.jsx(Ge,{children:n.jsxs(et,{children:[P.assistant.ask,b.length>0?P.assistant.team(b):""]})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(Hn,{onClick:a,disabled:g}),n.jsx(fl,{onClick:v,disabled:g||l.trim()===""||d===null,children:P.assistant.submit})]}),children:n.jsxs("div",{className:"wiz-meet",children:[n.jsxs("div",{className:"wiz-face",children:[n.jsx("span",{className:"wiz-face-tile","data-agent":(x==null?void 0:x.id)??"buddi","aria-hidden":"true",children:x?n.jsx("img",{src:Yi(x.role),alt:""}):t!=null&&t.picture?n.jsx("img",{src:t.picture,alt:""}):n.jsx("span",{className:"wiz-face-emoji",children:(t==null?void 0:t.avatar)??""})}),n.jsx("div",{className:"wiz-swatches",role:"group","aria-label":P.assistant.colour,children:tw.map(j=>n.jsx("button",{type:"button",className:"wiz-swatch","data-agent":j.id,"aria-label":P.assistant.swatch(j.label),"aria-pressed":c===j.id,onClick:()=>u(j.id)},j.id))}),n.jsx("span",{className:"wiz-face-cap",children:P.assistant.colour})]}),n.jsxs("div",{className:"wiz-stack",children:[n.jsx(Z,{label:P.assistant.name,children:n.jsx("input",{value:l,maxLength:60,onChange:j=>o(j.target.value)})}),n.jsx(Z,{label:P.assistant.purpose,hint:P.assistant.purposeHint,children:n.jsx("textarea",{className:"wiz-persona",value:m,maxLength:8e3,rows:7,onChange:j=>p(j.target.value)})})]})]})})]})}function BK({answers:e,assistantAgent:t,met:s,onMet:r,navigate:i,onPickAnotherBrain:a,onSpoken:l,progress:o,onProgress:c}){var M;const u=e.assistant,[d,h]=f.useState(s),[m,p]=f.useState([]),[g,y]=f.useState(!1),[b,x]=f.useState(!1),[v,j]=f.useState(!0),[w,S]=f.useState(!1),k=f.useRef(!1),N=f.useMemo(()=>t?[t]:[],[t]);f.useEffect(()=>{c()},[]),f.useEffect(()=>{if(!u||k.current)return;if(k.current=!0,s){h(s);return}let D=!1;return(async()=>{try{const U=await Fe.startConversation(u.id);if(D)return;h(U.conversationId),r(U.conversationId),await T.onboardingStep(kA.handover,{conversationId:U.conversationId}).catch(()=>{}),await Fe.send(u.id,{conversationId:U.conversationId,text:d_,opening:!0})}catch{D||(j(!1),y(!0))}})(),()=>{D=!0}},[u==null?void 0:u.id,s]),f.useEffect(()=>{if(!d)return;let D=!1;const U=Date.now(),$=()=>{Fe.conversation(d).then(O=>{if(D)return;p(O.messages);const K=Date.now()-U;if(O.messages.some(Ab)){j(!1),y(!1),x(!1);return}const G=O.runs??[],se=G.some(ie=>ie.finishedAt===null),ue=G.length>0&&!se;x(se&&K>=dK),(ue||K>=hK)&&(j(!1),y(!0))}).catch(()=>{})};$();const B=window.setInterval($,AA);return()=>{D=!0,window.clearInterval(B)}},[d]);const C=u&&d?Je(u.id,d):null,I=m.some(Ab);f.useEffect(()=>{I&&C&&l(C)},[I,C,l]);const A=e.takeOn??[],_=Ra.filter(D=>A.includes(D.id)&&"mate"in D).map(D=>D.mate),z=P.handover.starters({days:A.includes("days"),mail:A.includes("mail"),mailbox:((M=e.reach)==null?void 0:M.mailbox)===!0},_),L=(o==null?void 0:o.waiting)??[],E=D=>{!u||!d||w||(S(!0),Promise.resolve().then(()=>Fe.send(u.id,{conversationId:d,text:D})).then(()=>i(Je(u.id,d),!0)).catch(()=>S(!1)))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"wiz-hello",children:n.jsx(Gx,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:v,agents:N,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:P.handover.waiting,plain:!0,workingLine:P.handover.looking((u==null?void 0:u.name)??"")})}),b&&!g?n.jsx(Ge,{children:n.jsx(et,{children:P.handover.slow})}):null,g?n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:n.jsx(et,{children:P.handover.silent})}),n.jsx(Ft,{actions:n.jsx(fl,{onClick:a,children:P.handover.again})})]}):null,I?n.jsx("div",{className:"wiz-starters",role:"group","aria-label":P.handover.starterLabel,children:z.map(D=>n.jsx("button",{type:"button",className:"wiz-starter",disabled:w,onClick:()=>E(D),children:D},D))}):null,I&&L.length>0?n.jsx(W,{tone:"warm",title:P.handover.waitingTitle(L.length),action:n.jsx(R,{variant:"accent",onClick:()=>i(Vt,!0),children:P.handover.home}),children:P.handover.waitingBody(L)}):null,I&&C?n.jsx(Ft,{actions:n.jsx(Ut,{variant:"accent",size:"lg",href:C,onClick:D=>{D.preventDefault(),i(C,!0)},children:P.done.open})}):null]})}function WK({command:e}){const[t,s]=f.useState("idle"),r=()=>{var i;if(!((i=navigator.clipboard)!=null&&i.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return n.jsxs(Q,{gap:"sm",children:[n.jsx(jt,{label:"The command to run",children:e}),n.jsxs(J,{align:"end",children:[t==="failed"?n.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,n.jsx(R,{size:"sm",onClick:r,children:t==="done"?"Copied":"Copy"})]})]})}function Ab(e){return e.role==="assistant"&&(e.blocks??[]).some(t=>t.type==="text"&&t.text.trim()!=="")}function HK({onCancel:e,onStarted:t,onTrouble:s}){const[r,i]=f.useState(null),[a,l]=f.useState(""),[o,c]=f.useState(!1),u=()=>{!r||o||(c(!0),s(null),T.firstRunRestore(r,a.trim()).then(d=>{Zp(d.job.id),t()}).catch(d=>s(d instanceof ge?d.message:String(d))).finally(()=>c(!1)))};return n.jsx(kt,{title:P.restore.sheet,onClose:e,children:n.jsxs("div",{className:"wiz-restore",children:[n.jsx("p",{className:"wiz-foot",children:P.restore.lede}),n.jsx(Z,{label:P.restore.file,children:n.jsx("input",{type:"file",onChange:d=>{var h;return i(((h=d.target.files)==null?void 0:h[0])??null)}})}),n.jsx(Z,{label:P.restore.passphrase,hint:P.restore.passphraseHint,children:n.jsx("input",{type:"password",autoComplete:"off",value:a,onChange:d=>l(d.target.value)})}),n.jsxs(J,{align:"end",children:[n.jsx(R,{variant:"ghost",onClick:e,children:P.restore.cancel}),n.jsx(R,{variant:"accent",disabled:o||!r,onClick:u,children:P.restore.submit})]})]})})}function KK({onDone:e,onFailed:t}){const[s,r]=f.useState([]),i=f.useRef({onDone:e,onFailed:t});i.current={onDone:e,onFailed:t},f.useEffect(()=>{const l=EA();if(!l)return;let o=!1;const c=()=>{T.backupJob(l).then(d=>{o||(r(h=>h.includes(d.phase)?h:[...h,d.phase]),d.phase==="done"?(o=!0,Zp(null),T.owner().then(h=>i.current.onDone(h.preferredName??void 0),()=>i.current.onDone(void 0))):(d.phase==="rolled-back"||d.phase==="failed")&&(o=!0,Zp(null),i.current.onFailed(d.error??P.restore.phases[d.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,AA);return()=>{o=!0,window.clearInterval(u)}},[]);const a=s.filter(l=>l in P.restore.phases);return n.jsxs(n.Fragment,{children:[n.jsx(ml,{children:P.restore.title}),n.jsxs(Ge,{children:[n.jsx(et,{children:P.restore.started}),a.map(l=>n.jsx(et,{children:P.restore.phases[l]},l))]}),n.jsx(Ts,{})]})}function VK(e){return n.jsx(Ov.Provider,{value:null,children:n.jsx("div",{className:"wiz-sheet-body",children:n.jsx(GK,{...e})})})}function GK({onPaired:e,onDismiss:t}){const s=hl(),[r,i]=f.useState(""),[a,l]=f.useState(!1),[o,c]=f.useState(null),{offer:u,square:d,paired:h,stale:m,ask:p}=Pv(()=>T.telegram().then(b=>b.paired),e),g=()=>{r.trim()===""||a||(l(!0),c(null),(async()=>{try{const b=await T.saveTelegramToken(r.trim());if(i(""),b.restartNeeded){c(b.note??P.telegram.restart);return}await p()}catch(b){c(b instanceof ge?b.message:String(b))}finally{l(!1)}})())},y=()=>{c(null),p().catch(b=>c(b instanceof ge?b.message:String(b)))};return h?n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:n.jsx(et,{children:P.telegram.paired})}),n.jsx(Ft,{actions:n.jsx(R,{variant:"accent",onClick:t,children:P.telegram.close})})]}):u?n.jsxs(n.Fragment,{children:[n.jsx(Ge,{children:n.jsx(et,{children:m?P.telegram.expired:P.telegram.scan})}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:t,children:P.telegram.notNow}),m?n.jsx(R,{variant:"accent",onClick:y,children:P.telegram.newCode}):null]}),children:m?null:n.jsx($v,{offer:u,square:d})})]}):n.jsxs(n.Fragment,{children:[n.jsxs(Ge,{children:[n.jsx(et,{children:P.telegram.how}),o?n.jsx(et,{children:o}):null]}),n.jsx(Ft,{actions:n.jsxs(n.Fragment,{children:[n.jsx(R,{variant:"ghost",onClick:t,children:P.telegram.notNow}),n.jsx(R,{variant:"accent",disabled:a||r.trim()==="",onClick:g,children:P.telegram.submit})]}),children:n.jsx(Z,{label:P.telegram.field,grow:!0,children:n.jsx("input",{ref:s,type:"password",value:r,autoComplete:"off",spellCheck:!1,onChange:b=>i(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),g())}})})})]})}const YK="(max-width: 1080px)";function qK(){const[e,t]=f.useState(()=>window.location.hash||Vt);f.useEffect(()=>{const r=()=>t(window.location.hash||Vt);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=f.useCallback((r,i=!1)=>{i?window.history.replaceState(null,"",r):window.location.hash=r,t(r)},[]);return[e,s]}function QK(){const[e,t]=KC();f.useEffect(()=>{HC(e)},[e]);const s=f.useCallback(r=>t({theme:r}),[t]);return[e.theme,s]}const Tb=new Map;function JK(){var Rt,bn,V;const[e,t]=qK(),[s,r]=f.useState("UTC"),[i,a]=f.useState({approvals:0,failed:0}),[l,o]=QK(),c=Li(rv),[u,d]=f.useState(!1),[h,m]=f.useState([]),[p,g]=f.useState(null),[y,b]=f.useState(null),[x,v]=f.useState([]),[j,w]=f.useState(!1),[S,k]=f.useState(null),N=WD(),C=h.find(xe=>xe.id===p)??null,I=C!==null&&bz(e),[A,_]=f.useState(!1),z=f.useCallback(()=>_(!0),[]);f.useEffect(()=>{I||_(!1)},[I]),j6(t,fu(e)===null,I?z:void 0);const L=Li(YK),E=NE(),M=L1(),D=FC(),U=le(()=>Promise.resolve().then(()=>T.version()),[],ED),$=U.data;_D(U.reload);const B=$&&!$.checkout&&$.updateAvailable?$:null,O=Ax($==null?void 0:$.web);LD($==null?void 0:$.web);const K=((Rt=le(()=>Promise.resolve().then(()=>T.connectionSignals()),[],6e4).data)==null?void 0:Rt.signals)??[],[G,se]=f.useState(null),ue=f.useMemo(()=>new Set(G?[G]:[]),[G]),[ie,ee]=f.useState(new Map);f.useEffect(()=>{const xe=()=>{T.conversations().then(rt=>{const It=new Map;for(const it of rt.conversations){const en=it.lastMessageAt??it.createdAt,Rs=It.get(it.agentId);(!Rs||en>Rs)&&It.set(it.agentId,en)}ee(It)}).catch(()=>{})};xe();const De=window.setInterval(xe,3e4);return()=>window.clearInterval(De)},[e]);const[X,de]=f.useState(!1);f.useEffect(()=>{if(X)return;let xe=!1;return T.onboarding().then(De=>{xe||(de(!0),De.state==="pending"&&De.needs.model&&!fu(window.location.hash)&&t(QO,!0))}).catch(()=>{xe||de(!0)}),()=>{xe=!0}},[X,t]),f.useEffect(()=>{const xe=mD(e);xe&&t(xe,!0)},[e,t]),f.useEffect(()=>{let xe=!1;const De=()=>{Fe.agents().then(It=>{xe||(m(It.agents),wD(It.defaultAgentId??null),g(It.defaultAgentId??null),b(it=>{var en;return it??It.defaultAgentId??((en=It.agents[0])==null?void 0:en.id)??null}))}).catch(()=>{})};De();const rt=window.setInterval(De,15e3);return window.addEventListener("focus",De),window.addEventListener(So,De),()=>{xe=!0,window.clearInterval(rt),window.removeEventListener("focus",De),window.removeEventListener(So,De)}},[e]),f.useEffect(()=>{let xe=!1;const De=()=>{Fe.groups().then(It=>{xe||v(It.groups)}).catch(()=>{})};De();const rt=window.setInterval(De,3e4);return()=>{xe=!0,window.clearInterval(rt)}},[e]);const Ie=t1(h,p),Se=XO(e),we=qN(e),Ce=we?x.find(xe=>xe.id===we.groupId)??null:null,mt=we?null:(Se==null?void 0:Se.agentId)??y;f.useEffect(()=>{Se&&b(Se.agentId)},[Se==null?void 0:Se.agentId]);const he=xe=>{b(xe),t(Je(xe))},Me=xe=>t(Yl(xe)),Pe=f.useCallback((xe,De,rt=!0)=>t(we?Yl(we.groupId,De):Je(xe,De),rt),[t,we==null?void 0:we.groupId]),[Ye,Y]=f.useState(!1);f.useEffect(()=>{T.session().then(xe=>{r(xe.timezone),Y(!0)}).catch(()=>{})},[]);const me=Iz(Ye);Dz(Ye,me.refresh,()=>Y(!1)),f.useEffect(()=>{const xe=()=>{T.overview().then(rt=>a({approvals:rt.approvals.pending,failed:rt.jobs.failed??0})).catch(()=>{})};xe();const De=window.setInterval(xe,2e4);return()=>window.clearInterval(De)},[]),f.useEffect(()=>{if(!Ye)return;if(e===pD){w(!0),t(Yr,!0);return}const xe=gD(e),De=new Date().toDateString();!xe||Tb.get(xe)===De||(Tb.set(xe,De),T.tipsSeenPage(xe).catch(()=>{}))},[e,Ye,t]);const oe=fu(e),Oe=XN(e),Le=Oe===Yr,Ue=S?x.find(xe=>xe.id===S)??null:null,at=j?n.jsx(Bw,{agents:h,onClose:()=>w(!1),onCreated:xe=>{v(De=>[...De,xe]),w(!1),t(Yl(xe.id))}}):Ue?n.jsx(Bw,{agents:h,group:Ue,onClose:()=>k(null),onSaved:xe=>{v(De=>De.map(rt=>rt.id===xe.id?xe:rt)),k(null)},onArchived:xe=>{v(De=>De.filter(rt=>rt.id!==xe)),k(null),t(Yr)}}):null;return oe?n.jsx(Oy,{delayDuration:400,children:n.jsxs(by,{swipeDirection:"right",children:[n.jsx(gK,{navigate:t,timezone:s}),n.jsx(ky,{className:"ui-toasts"})]})}):n.jsx(v_,{picture:(bn=h.find(xe=>xe.id===p))==null?void 0:bn.picture,children:n.jsx(Oy,{delayDuration:400,children:n.jsxs(by,{swipeDirection:"right",children:[at,n.jsxs("div",{className:"wb-shell",children:[n.jsx(Q5,{active:((V=E.data)==null?void 0:V.active)===!0,onNavigate:t}),n.jsxs("div",{className:"wb",children:[n.jsx(l6,{attention:i.approvals+i.failed,place:Oe,onNavigate:t,theme:l,onTheme:o,plugins:x6(M.rail,D),updateAvailable:B!==null,settingsDot:K.length>0?_C:void 0,stale:O,timezone:s,version:$&&!$.checkout?{current:$.current,latest:$.latest,updateAvailable:$.updateAvailable}:$?{current:$.current,updateAvailable:!1}:void 0}),Le&&!L?n.jsx(l1,{agents:Ie,currentId:mt,attention:N,onSelect:he,lastActivity:ie,working:ue,groups:x,currentGroupId:(Ce==null?void 0:Ce.id)??null,onSelectGroup:Me,onNewGroup:()=>w(!0)}):null,Le?n.jsx(dz,{timezone:s,agents:Ie,agentId:Ce?Ce.coordinator:mt,defaultAgentId:p,group:Ce,onEditGroup:Ce?()=>k(Ce.id):void 0,requestedConversationId:(we==null?void 0:we.conversationId)??(Se==null?void 0:Se.conversationId),requestedTab:Se==null?void 0:Se.tab,onConversationOpened:Pe,onSelectAgent:he,onWorking:se,attention:N,agentsInHeader:L,narrow:c,canvasOpen:u,onOpenCanvas:()=>d(!0),onCloseCanvas:()=>d(!1)}):n.jsx("main",{"data-ground":XK(Oe,e)?"plain":void 0,"data-layout":Oe===cn?"split":void 0,children:n.jsx(ZK,{hash:e,place:Oe,timezone:s,navigate:t,agents:h,defaultAgentId:p,attention:N,pluginPages:M,update:B,connectionSignals:K})})]})]}),I&&C?n.jsx(kz,{agent:C,agents:h,open:A,onOpenChange:_,navigate:t}):null,n.jsxs(Tz,{placement:Az(I,A),children:[n.jsx(Pz,{queue:me.queue,agents:h,navigate:t,onDismiss:me.dismiss}),n.jsx(ky,{className:"ui-toasts"})]})]})})})}function XK(e,t){return Sx(t)!==null}function ZK({place:e,pluginPages:t,...s}){const r={...s,pluginPages:t},i=Sx(s.hash);if(i){const a=t.find(i.plugin,i.page);if(a)return n.jsx(uv,{page:a,item:i.item??null,navigate:s.navigate,timezone:s.timezone,siblings:t.all.filter(l=>l.plugin===i.plugin)});if(t.all.length===0)return n.jsx(n.Fragment,{})}switch(e){case gt:return n.jsx(a5,{...s});case dt:return n.jsx($6,{...s});case cn:return n.jsx(LH,{...r});case _i:return n.jsx(XU,{...s});default:return n.jsx(R5,{...s})}}function eV(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(Ex)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}const IA=1e4,tV=3e4,PA=6e3,nV=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function sV(e){return nV.test(e)?n.jsxs(n.Fragment,{children:["Is buddi running on this Mac? ",n.jsx("code",{children:"buddi status"})," says."]}):n.jsx(n.Fragment,{children:"Is Tailscale on, and the Mac it runs on awake?"})}async function $A(e){let t;const s=new Promise((r,i)=>{t=setTimeout(()=>i(new ge(0,qu)),e)});try{return{up:!0,version:await Promise.race([T.version(),s])}}catch(r){return t$(r)?{up:!1}:{up:!0}}finally{clearTimeout(t)}}function MA(e){var t;return e.up&&Ax((t=e.version)==null?void 0:t.web)?(window.location.reload(),!1):e.up}function rV({host:e,onRetry:t,retrying:s}){return n.jsxs("main",{className:"unreachable",role:"alert",children:[n.jsx("span",{className:"ui-blob","data-size":"lg","aria-hidden":"true",children:n.jsx("img",{src:Yi("core"),alt:""})}),n.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),n.jsx("p",{children:sV(e.replace(/:\d+$/,""))}),n.jsx("div",{className:"unreachable-actions",children:n.jsx(R,{variant:"accent",onClick:t,disabled:s,children:s?"Retrying…":"Retry"})})]})}function iV({children:e}){const[t,s]=f.useState("checking"),[r,i]=f.useState(!1),a=f.useRef(!1),l=f.useCallback(async()=>{if(a.current)return;a.current=!0,i(!0);const o=await $A(PA);a.current=!1,i(!1),s(c=>c==="checking"?o.up?"up":"down":MA(o)?"up":"down")},[]);return f.useEffect(()=>{l()},[l]),f.useEffect(()=>{if(t!=="down")return;const o=window.setInterval(()=>void l(),IA);return()=>window.clearInterval(o)},[t,l]),t==="checking"?null:t==="down"?n.jsx(rV,{host:window.location.host,onRetry:()=>void l(),retrying:r}):n.jsxs(n.Fragment,{children:[n.jsx(lV,{}),e]})}function aV(e=tV){const[t,s]=f.useState(!1);return f.useEffect(()=>{let r;const i=()=>{clearTimeout(r);const l=Z2();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(i,o)};i();const a=e$(i);return()=>{a(),clearTimeout(r)}},[e]),t}function lV(){const e=aV();return f.useEffect(()=>{if(!e)return;const t=window.setInterval(()=>{$A(PA).then(MA)},IA);return()=>window.clearInterval(t)},[e]),e?n.jsx("div",{className:"lost-bar",role:"status",children:"Lost buddi. Retrying…"}):null}function oV({search:e=location.search}){const[t,s]=f.useState(null),r=f.useRef(!1);return f.useEffect(()=>{if(r.current)return;r.current=!0;const i=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const a=i.get("state")??"",l=i.get("code")??void 0,o=i.get("error")??void 0;T.connectionCallback({state:a,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(hE);u.postMessage({id:c.id}),u.close()}catch{}window.setTimeout(()=>{try{window.close()}catch{}},1500)}).catch(c=>s({ok:!1,message:c instanceof Error?c.message:String(c)}))},[e]),n.jsx("main",{className:"ui-page connections-callback",children:n.jsxs(Q,{gap:"lg",children:[n.jsx("h2",{className:"ui-page-title",children:"Connections"}),t===null?n.jsx(W,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,t!=null&&t.ok?n.jsxs(W,{tone:"good",role:"status",title:`Signed in to ${t.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",t.cli?"the terminal carries on.":"the other one carries on."]}):null,t&&!t.ok?n.jsx(W,{tone:"critical",role:"alert",title:"Nothing was connected",children:t.message}):null,t?n.jsx(Ut,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const Rb=document.getElementById("root");Rb&&Wk(Rb).render(n.jsx(f.StrictMode,{children:location.pathname==="/connections/callback"?n.jsx(oV,{}):n.jsx(iV,{children:n.jsx(JK,{})})}));eV();export{uV as c,JA as g};
|