@withbuddi/buddi 0.1.0-pre.42 → 0.1.0-pre.43
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 +10 -1
- package/node_modules/@buddi/cli/dist/doctor-probes.js.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor.d.ts +9 -0
- package/node_modules/@buddi/cli/dist/doctor.d.ts.map +1 -1
- package/node_modules/@buddi/cli/dist/doctor.js +21 -3
- 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/agents/catalog.js +1 -1
- package/node_modules/@buddi/core/dist/agents/catalog.js.map +1 -1
- package/node_modules/@buddi/core/dist/testing/database-url.d.ts +13 -0
- package/node_modules/@buddi/core/dist/testing/database-url.d.ts.map +1 -1
- package/node_modules/@buddi/core/dist/testing/database-url.js +34 -0
- package/node_modules/@buddi/core/dist/testing/database-url.js.map +1 -1
- package/node_modules/@buddi/core/dist/testing/isolated-global-setup.d.ts +2 -0
- package/node_modules/@buddi/core/dist/testing/isolated-global-setup.d.ts.map +1 -0
- package/node_modules/@buddi/core/dist/testing/isolated-global-setup.js +20 -0
- package/node_modules/@buddi/core/dist/testing/isolated-global-setup.js.map +1 -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/agents/platform.d.ts +8 -0
- package/node_modules/@buddi/gateway/dist/agents/platform.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/agents/platform.js +48 -22
- package/node_modules/@buddi/gateway/dist/agents/platform.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/index.d.ts +1 -0
- package/node_modules/@buddi/gateway/dist/plugins/index.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/index.js +1 -0
- package/node_modules/@buddi/gateway/dist/plugins/index.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/plugins/pages-state.d.ts +37 -0
- package/node_modules/@buddi/gateway/dist/plugins/pages-state.d.ts.map +1 -0
- package/node_modules/@buddi/gateway/dist/plugins/pages-state.js +98 -0
- package/node_modules/@buddi/gateway/dist/plugins/pages-state.js.map +1 -0
- package/node_modules/@buddi/gateway/dist/provider-accounts.d.ts +33 -4
- package/node_modules/@buddi/gateway/dist/provider-accounts.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/provider-accounts.js +81 -18
- package/node_modules/@buddi/gateway/dist/provider-accounts.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/provider-diagnostics.d.ts +5 -0
- package/node_modules/@buddi/gateway/dist/provider-diagnostics.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/provider-diagnostics.js +6 -1
- package/node_modules/@buddi/gateway/dist/provider-diagnostics.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/serve.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/serve.js +5 -2
- package/node_modules/@buddi/gateway/dist/serve.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/agent-offers.d.ts +6 -0
- package/node_modules/@buddi/gateway/dist/web/agent-offers.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/agent-offers.js +6 -0
- package/node_modules/@buddi/gateway/dist/web/agent-offers.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/api-routes.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/api-routes.js +6 -1
- package/node_modules/@buddi/gateway/dist/web/api-routes.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/attention.d.ts +11 -1
- package/node_modules/@buddi/gateway/dist/web/attention.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/attention.js +22 -2
- package/node_modules/@buddi/gateway/dist/web/attention.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/chat.d.ts +0 -2
- package/node_modules/@buddi/gateway/dist/web/chat.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/chat.js +15 -4
- package/node_modules/@buddi/gateway/dist/web/chat.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/lock.d.ts +9 -0
- package/node_modules/@buddi/gateway/dist/web/lock.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/lock.js +3 -1
- package/node_modules/@buddi/gateway/dist/web/lock.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/plugins.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/plugins.js +4 -0
- package/node_modules/@buddi/gateway/dist/web/plugins.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/server.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/server.js +15 -4
- package/node_modules/@buddi/gateway/dist/web/server.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/take-on.d.ts +3 -1
- package/node_modules/@buddi/gateway/dist/web/take-on.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/take-on.js +14 -3
- package/node_modules/@buddi/gateway/dist/web/take-on.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/telegram.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/telegram.js +4 -2
- package/node_modules/@buddi/gateway/dist/web/telegram.js.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/version.d.ts +10 -0
- package/node_modules/@buddi/gateway/dist/web/version.d.ts.map +1 -1
- package/node_modules/@buddi/gateway/dist/web/version.js +12 -0
- package/node_modules/@buddi/gateway/dist/web/version.js.map +1 -1
- package/node_modules/@buddi/install/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/install/dist/backup.d.ts +12 -0
- package/node_modules/@buddi/install/dist/backup.d.ts.map +1 -1
- package/node_modules/@buddi/install/dist/backup.js +26 -8
- package/node_modules/@buddi/install/dist/backup.js.map +1 -1
- package/node_modules/@buddi/install/dist/upgrade.d.ts +2 -0
- package/node_modules/@buddi/install/dist/upgrade.d.ts.map +1 -1
- package/node_modules/@buddi/install/dist/upgrade.js +3 -2
- package/node_modules/@buddi/install/dist/upgrade.js.map +1 -1
- package/node_modules/@buddi/runtime/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/runtime/dist/codex-direct.d.ts +12 -1
- package/node_modules/@buddi/runtime/dist/codex-direct.d.ts.map +1 -1
- package/node_modules/@buddi/runtime/dist/codex-direct.js +15 -6
- package/node_modules/@buddi/runtime/dist/codex-direct.js.map +1 -1
- package/node_modules/@buddi/runtime/dist/groups.d.ts +5 -4
- package/node_modules/@buddi/runtime/dist/groups.d.ts.map +1 -1
- package/node_modules/@buddi/runtime/dist/groups.js +7 -6
- package/node_modules/@buddi/runtime/dist/groups.js.map +1 -1
- package/node_modules/@buddi/runtime/dist/provider-models.d.ts +4 -0
- package/node_modules/@buddi/runtime/dist/provider-models.d.ts.map +1 -1
- package/node_modules/@buddi/runtime/dist/provider-models.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/.tsbuildinfo +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/descriptors.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/descriptors.js +42 -0
- package/node_modules/@buddi/tool-email/dist/pages/descriptors.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts +14 -0
- package/node_modules/@buddi/tool-email/dist/pages/queries.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/pages/queries.js +95 -8
- package/node_modules/@buddi/tool-email/dist/pages/queries.js.map +1 -1
- package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.d.ts.map +1 -1
- package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.js +5 -0
- package/node_modules/@buddi/tool-email/dist/sources/inbox-poll.js.map +1 -1
- package/node_modules/@buddi/tool-email/migrations/027_first_contact.sql +13 -0
- 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 +10 -1
- package/packages/cli/dist/doctor-probes.js.map +1 -1
- package/packages/cli/dist/doctor.d.ts +9 -0
- package/packages/cli/dist/doctor.d.ts.map +1 -1
- package/packages/cli/dist/doctor.js +21 -3
- package/packages/cli/dist/doctor.js.map +1 -1
- package/packages/core/dist/.tsbuildinfo +1 -1
- package/packages/core/dist/agents/catalog.js +1 -1
- package/packages/core/dist/agents/catalog.js.map +1 -1
- package/packages/core/dist/testing/database-url.d.ts +13 -0
- package/packages/core/dist/testing/database-url.d.ts.map +1 -1
- package/packages/core/dist/testing/database-url.js +34 -0
- package/packages/core/dist/testing/database-url.js.map +1 -1
- package/packages/core/dist/testing/isolated-global-setup.d.ts +2 -0
- package/packages/core/dist/testing/isolated-global-setup.d.ts.map +1 -0
- package/packages/core/dist/testing/isolated-global-setup.js +20 -0
- package/packages/core/dist/testing/isolated-global-setup.js.map +1 -0
- package/packages/core/package.json +4 -0
- package/packages/gateway/dist/.tsbuildinfo +1 -1
- package/packages/gateway/dist/agents/platform.d.ts +8 -0
- package/packages/gateway/dist/agents/platform.d.ts.map +1 -1
- package/packages/gateway/dist/agents/platform.js +48 -22
- package/packages/gateway/dist/agents/platform.js.map +1 -1
- package/packages/gateway/dist/plugins/index.d.ts +1 -0
- package/packages/gateway/dist/plugins/index.d.ts.map +1 -1
- package/packages/gateway/dist/plugins/index.js +1 -0
- package/packages/gateway/dist/plugins/index.js.map +1 -1
- package/packages/gateway/dist/plugins/pages-state.d.ts +37 -0
- package/packages/gateway/dist/plugins/pages-state.d.ts.map +1 -0
- package/packages/gateway/dist/plugins/pages-state.js +98 -0
- package/packages/gateway/dist/plugins/pages-state.js.map +1 -0
- package/packages/gateway/dist/provider-accounts.d.ts +33 -4
- package/packages/gateway/dist/provider-accounts.d.ts.map +1 -1
- package/packages/gateway/dist/provider-accounts.js +81 -18
- package/packages/gateway/dist/provider-accounts.js.map +1 -1
- package/packages/gateway/dist/provider-diagnostics.d.ts +5 -0
- package/packages/gateway/dist/provider-diagnostics.d.ts.map +1 -1
- package/packages/gateway/dist/provider-diagnostics.js +6 -1
- package/packages/gateway/dist/provider-diagnostics.js.map +1 -1
- package/packages/gateway/dist/serve.d.ts.map +1 -1
- package/packages/gateway/dist/serve.js +5 -2
- package/packages/gateway/dist/serve.js.map +1 -1
- package/packages/gateway/dist/web/agent-offers.d.ts +6 -0
- package/packages/gateway/dist/web/agent-offers.d.ts.map +1 -1
- package/packages/gateway/dist/web/agent-offers.js +6 -0
- package/packages/gateway/dist/web/agent-offers.js.map +1 -1
- package/packages/gateway/dist/web/api-routes.d.ts.map +1 -1
- package/packages/gateway/dist/web/api-routes.js +6 -1
- package/packages/gateway/dist/web/api-routes.js.map +1 -1
- package/packages/gateway/dist/web/attention.d.ts +11 -1
- package/packages/gateway/dist/web/attention.d.ts.map +1 -1
- package/packages/gateway/dist/web/attention.js +22 -2
- package/packages/gateway/dist/web/attention.js.map +1 -1
- package/packages/gateway/dist/web/chat.d.ts +0 -2
- package/packages/gateway/dist/web/chat.d.ts.map +1 -1
- package/packages/gateway/dist/web/chat.js +15 -4
- package/packages/gateway/dist/web/chat.js.map +1 -1
- package/packages/gateway/dist/web/lock.d.ts +9 -0
- package/packages/gateway/dist/web/lock.d.ts.map +1 -1
- package/packages/gateway/dist/web/lock.js +3 -1
- package/packages/gateway/dist/web/lock.js.map +1 -1
- package/packages/gateway/dist/web/plugins.d.ts.map +1 -1
- package/packages/gateway/dist/web/plugins.js +4 -0
- package/packages/gateway/dist/web/plugins.js.map +1 -1
- package/packages/gateway/dist/web/server.d.ts.map +1 -1
- package/packages/gateway/dist/web/server.js +15 -4
- package/packages/gateway/dist/web/server.js.map +1 -1
- package/packages/gateway/dist/web/take-on.d.ts +3 -1
- package/packages/gateway/dist/web/take-on.d.ts.map +1 -1
- package/packages/gateway/dist/web/take-on.js +14 -3
- package/packages/gateway/dist/web/take-on.js.map +1 -1
- package/packages/gateway/dist/web/telegram.d.ts.map +1 -1
- package/packages/gateway/dist/web/telegram.js +4 -2
- package/packages/gateway/dist/web/telegram.js.map +1 -1
- package/packages/gateway/dist/web/version.d.ts +10 -0
- package/packages/gateway/dist/web/version.d.ts.map +1 -1
- package/packages/gateway/dist/web/version.js +12 -0
- package/packages/gateway/dist/web/version.js.map +1 -1
- package/packages/install/dist/.tsbuildinfo +1 -1
- package/packages/install/dist/backup.d.ts +12 -0
- package/packages/install/dist/backup.d.ts.map +1 -1
- package/packages/install/dist/backup.js +26 -8
- package/packages/install/dist/backup.js.map +1 -1
- package/packages/install/dist/upgrade.d.ts +2 -0
- package/packages/install/dist/upgrade.d.ts.map +1 -1
- package/packages/install/dist/upgrade.js +3 -2
- package/packages/install/dist/upgrade.js.map +1 -1
- package/packages/runtime/dist/.tsbuildinfo +1 -1
- package/packages/runtime/dist/codex-direct.d.ts +12 -1
- package/packages/runtime/dist/codex-direct.d.ts.map +1 -1
- package/packages/runtime/dist/codex-direct.js +15 -6
- package/packages/runtime/dist/codex-direct.js.map +1 -1
- package/packages/runtime/dist/groups.d.ts +5 -4
- package/packages/runtime/dist/groups.d.ts.map +1 -1
- package/packages/runtime/dist/groups.js +7 -6
- package/packages/runtime/dist/groups.js.map +1 -1
- package/packages/runtime/dist/provider-models.d.ts +4 -0
- package/packages/runtime/dist/provider-models.d.ts.map +1 -1
- package/packages/runtime/dist/provider-models.js.map +1 -1
- package/packages/tools/email/dist/.tsbuildinfo +1 -1
- package/packages/tools/email/dist/pages/descriptors.d.ts.map +1 -1
- package/packages/tools/email/dist/pages/descriptors.js +42 -0
- package/packages/tools/email/dist/pages/descriptors.js.map +1 -1
- package/packages/tools/email/dist/pages/queries.d.ts +14 -0
- package/packages/tools/email/dist/pages/queries.d.ts.map +1 -1
- package/packages/tools/email/dist/pages/queries.js +95 -8
- package/packages/tools/email/dist/pages/queries.js.map +1 -1
- package/packages/tools/email/dist/sources/inbox-poll.d.ts.map +1 -1
- package/packages/tools/email/dist/sources/inbox-poll.js +5 -0
- package/packages/tools/email/dist/sources/inbox-poll.js.map +1 -1
- package/packages/tools/email/migrations/027_first_contact.sql +13 -0
- package/packages/web/dist/assets/index-BB52n8Fa.js +146 -0
- package/packages/web/dist/assets/index-CY4cPN4I.css +1 -0
- package/packages/web/dist/assets/{lottie_light-CQmEj1as.js → lottie_light-CHWAvOde.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-BrA8nWN-.css +0 -1
- package/packages/web/dist/assets/index-lmUTDd2T.js +0 -146
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
var a2=Object.defineProperty;var Db=e=>{throw TypeError(e)};var i2=(e,n,s)=>n in e?a2(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var Lb=(e,n,s)=>i2(e,typeof n!="symbol"?n+"":n,s),Fb=(e,n,s)=>n.has(e)||Db("Cannot "+s);var Ln=(e,n,s)=>(Fb(e,n,"read from private field"),s?s.call(e):n.get(e)),_b=(e,n,s)=>n.has(e)?Db("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(e):n.set(e,s),Mm=(e,n,s,r)=>(Fb(e,n,"write to private field"),r?r.call(e,s):n.set(e,s),s);function l2(e,n){for(var s=0;s<n.length;s++){const r=n[s];if(typeof r!="string"&&!Array.isArray(r)){for(const a in r)if(a!=="default"&&!(a in e)){const i=Object.getOwnPropertyDescriptor(r,a);i&&Object.defineProperty(e,a,i.get?i:{enumerable:!0,get:()=>r[a]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const l of i.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function s(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=s(a);fetch(a.href,i)}})();var Dse=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function o2(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pC={exports:{}},xf={},gC={exports:{}},ht={};/**
|
|
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 fu=Symbol.for("react.element"),c2=Symbol.for("react.portal"),u2=Symbol.for("react.fragment"),d2=Symbol.for("react.strict_mode"),h2=Symbol.for("react.profiler"),f2=Symbol.for("react.provider"),m2=Symbol.for("react.context"),p2=Symbol.for("react.forward_ref"),g2=Symbol.for("react.suspense"),x2=Symbol.for("react.memo"),v2=Symbol.for("react.lazy"),zb=Symbol.iterator;function j2(e){return e===null||typeof e!="object"?null:(e=zb&&e[zb]||e["@@iterator"],typeof e=="function"?e:null)}var xC={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},vC=Object.assign,jC={};function fo(e,n,s){this.props=e,this.context=n,this.refs=jC,this.updater=s||xC}fo.prototype.isReactComponent={};fo.prototype.setState=function(e,n){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,n,"setState")};fo.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function wC(){}wC.prototype=fo.prototype;function sj(e,n,s){this.props=e,this.context=n,this.refs=jC,this.updater=s||xC}var rj=sj.prototype=new wC;rj.constructor=sj;vC(rj,fo.prototype);rj.isPureReactComponent=!0;var Ub=Array.isArray,yC=Object.prototype.hasOwnProperty,aj={current:null},bC={key:!0,ref:!0,__self:!0,__source:!0};function kC(e,n,s){var r,a={},i=null,l=null;if(n!=null)for(r in n.ref!==void 0&&(l=n.ref),n.key!==void 0&&(i=""+n.key),n)yC.call(n,r)&&!bC.hasOwnProperty(r)&&(a[r]=n[r]);var o=arguments.length-2;if(o===1)a.children=s;else if(1<o){for(var c=Array(o),u=0;u<o;u++)c[u]=arguments[u+2];a.children=c}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)a[r]===void 0&&(a[r]=o[r]);return{$$typeof:fu,type:e,key:i,ref:l,props:a,_owner:aj.current}}function w2(e,n){return{$$typeof:fu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function ij(e){return typeof e=="object"&&e!==null&&e.$$typeof===fu}function y2(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(s){return n[s]})}var Bb=/\/+/g;function Om(e,n){return typeof e=="object"&&e!==null&&e.key!=null?y2(""+e.key):n.toString(36)}function Rd(e,n,s,r,a){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var l=!1;if(e===null)l=!0;else switch(i){case"string":case"number":l=!0;break;case"object":switch(e.$$typeof){case fu:case c2:l=!0}}if(l)return l=e,a=a(l),e=r===""?"."+Om(l,0):r,Ub(a)?(s="",e!=null&&(s=e.replace(Bb,"$&/")+"/"),Rd(a,n,s,"",function(u){return u})):a!=null&&(ij(a)&&(a=w2(a,s+(!a.key||l&&l.key===a.key?"":(""+a.key).replace(Bb,"$&/")+"/")+e)),n.push(a)),1;if(l=0,r=r===""?".":r+":",Ub(e))for(var o=0;o<e.length;o++){i=e[o];var c=r+Om(i,o);l+=Rd(i,n,s,c,a)}else if(c=j2(e),typeof c=="function")for(e=c.call(e),o=0;!(i=e.next()).done;)i=i.value,c=r+Om(i,o++),l+=Rd(i,n,s,c,a);else if(i==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return l}function zu(e,n,s){if(e==null)return e;var r=[],a=0;return Rd(e,r,"","",function(i){return n.call(s,i,a++)}),r}function b2(e){if(e._status===-1){var n=e._result;n=n(),n.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=n)}if(e._status===1)return e._result.default;throw e._result}var ts={current:null},Id={transition:null},k2={ReactCurrentDispatcher:ts,ReactCurrentBatchConfig:Id,ReactCurrentOwner:aj};function NC(){throw Error("act(...) is not supported in production builds of React.")}ht.Children={map:zu,forEach:function(e,n,s){zu(e,function(){n.apply(this,arguments)},s)},count:function(e){var n=0;return zu(e,function(){n++}),n},toArray:function(e){return zu(e,function(n){return n})||[]},only:function(e){if(!ij(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};ht.Component=fo;ht.Fragment=u2;ht.Profiler=h2;ht.PureComponent=sj;ht.StrictMode=d2;ht.Suspense=g2;ht.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=k2;ht.act=NC;ht.cloneElement=function(e,n,s){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=vC({},e.props),a=e.key,i=e.ref,l=e._owner;if(n!=null){if(n.ref!==void 0&&(i=n.ref,l=aj.current),n.key!==void 0&&(a=""+n.key),e.type&&e.type.defaultProps)var o=e.type.defaultProps;for(c in n)yC.call(n,c)&&!bC.hasOwnProperty(c)&&(r[c]=n[c]===void 0&&o!==void 0?o[c]:n[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:fu,type:e.type,key:a,ref:i,props:r,_owner:l}};ht.createContext=function(e){return e={$$typeof:m2,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:f2,_context:e},e.Consumer=e};ht.createElement=kC;ht.createFactory=function(e){var n=kC.bind(null,e);return n.type=e,n};ht.createRef=function(){return{current:null}};ht.forwardRef=function(e){return{$$typeof:p2,render:e}};ht.isValidElement=ij;ht.lazy=function(e){return{$$typeof:v2,_payload:{_status:-1,_result:e},_init:b2}};ht.memo=function(e,n){return{$$typeof:x2,type:e,compare:n===void 0?null:n}};ht.startTransition=function(e){var n=Id.transition;Id.transition={};try{e()}finally{Id.transition=n}};ht.unstable_act=NC;ht.useCallback=function(e,n){return ts.current.useCallback(e,n)};ht.useContext=function(e){return ts.current.useContext(e)};ht.useDebugValue=function(){};ht.useDeferredValue=function(e){return ts.current.useDeferredValue(e)};ht.useEffect=function(e,n){return ts.current.useEffect(e,n)};ht.useId=function(){return ts.current.useId()};ht.useImperativeHandle=function(e,n,s){return ts.current.useImperativeHandle(e,n,s)};ht.useInsertionEffect=function(e,n){return ts.current.useInsertionEffect(e,n)};ht.useLayoutEffect=function(e,n){return ts.current.useLayoutEffect(e,n)};ht.useMemo=function(e,n){return ts.current.useMemo(e,n)};ht.useReducer=function(e,n,s){return ts.current.useReducer(e,n,s)};ht.useRef=function(e){return ts.current.useRef(e)};ht.useState=function(e){return ts.current.useState(e)};ht.useSyncExternalStore=function(e,n,s){return ts.current.useSyncExternalStore(e,n,s)};ht.useTransition=function(){return ts.current.useTransition()};ht.version="18.3.1";gC.exports=ht;var d=gC.exports;const N2=o2(d),mo=l2({__proto__:null,default:N2},[d]);/**
|
|
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 S2=d,C2=Symbol.for("react.element"),E2=Symbol.for("react.fragment"),$2=Object.prototype.hasOwnProperty,A2=S2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,T2={key:!0,ref:!0,__self:!0,__source:!0};function SC(e,n,s){var r,a={},i=null,l=null;s!==void 0&&(i=""+s),n.key!==void 0&&(i=""+n.key),n.ref!==void 0&&(l=n.ref);for(r in n)$2.call(n,r)&&!T2.hasOwnProperty(r)&&(a[r]=n[r]);if(e&&e.defaultProps)for(r in n=e.defaultProps,n)a[r]===void 0&&(a[r]=n[r]);return{$$typeof:C2,type:e,key:i,ref:l,props:a,_owner:A2.current}}xf.Fragment=E2;xf.jsx=SC;xf.jsxs=SC;pC.exports=xf;var t=pC.exports,CC={exports:{}},As={},EC={exports:{}},$C={};/**
|
|
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 n(P,K){var F=P.length;P.push(K);e:for(;0<F;){var Q=F-1>>>1,_=P[Q];if(0<a(_,K))P[Q]=K,P[F]=_,F=Q;else break e}}function s(P){return P.length===0?null:P[0]}function r(P){if(P.length===0)return null;var K=P[0],F=P.pop();if(F!==K){P[0]=F;e:for(var Q=0,_=P.length,re=_>>>1;Q<re;){var Y=2*(Q+1)-1,B=P[Y],q=Y+1,J=P[q];if(0>a(B,F))q<_&&0>a(J,B)?(P[Q]=J,P[q]=F,Q=q):(P[Q]=B,P[Y]=F,Q=Y);else if(q<_&&0>a(J,F))P[Q]=J,P[q]=F,Q=q;else break e}}return K}function a(P,K){var F=P.sortIndex-K.sortIndex;return F!==0?F:P.id-K.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var l=Date,o=l.now();e.unstable_now=function(){return l.now()-o}}var c=[],u=[],h=1,f=null,m=3,p=!1,g=!1,x=!1,k=typeof setTimeout=="function"?setTimeout:null,j=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 w(P){for(var K=s(u);K!==null;){if(K.callback===null)r(u);else if(K.startTime<=P)r(u),K.sortIndex=K.expirationTime,n(c,K);else break;K=s(u)}}function y(P){if(x=!1,w(P),!g)if(s(c)!==null)g=!0,U(N);else{var K=s(u);K!==null&&D(y,K.startTime-P)}}function N(P,K){g=!1,x&&(x=!1,j(C),C=-1),p=!0;var F=m;try{for(w(K),f=s(c);f!==null&&(!(f.expirationTime>K)||P&&!R());){var Q=f.callback;if(typeof Q=="function"){f.callback=null,m=f.priorityLevel;var _=Q(f.expirationTime<=K);K=e.unstable_now(),typeof _=="function"?f.callback=_:f===s(c)&&r(c),w(K)}else r(c);f=s(c)}if(f!==null)var re=!0;else{var Y=s(u);Y!==null&&D(y,Y.startTime-K),re=!1}return re}finally{f=null,m=F,p=!1}}var b=!1,S=null,C=-1,T=5,E=-1;function R(){return!(e.unstable_now()-E<T)}function M(){if(S!==null){var P=e.unstable_now();E=P;var K=!0;try{K=S(!0,P)}finally{K?O():(b=!1,S=null)}}else b=!1}var O;if(typeof v=="function")O=function(){v(M)};else if(typeof MessageChannel<"u"){var I=new MessageChannel,z=I.port2;I.port1.onmessage=M,O=function(){z.postMessage(null)}}else O=function(){k(M,0)};function U(P){S=P,b||(b=!0,O())}function D(P,K){C=k(function(){P(e.unstable_now())},K)}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(P){P.callback=null},e.unstable_continueExecution=function(){g||p||(g=!0,U(N))},e.unstable_forceFrameRate=function(P){0>P||125<P?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):T=0<P?Math.floor(1e3/P):5},e.unstable_getCurrentPriorityLevel=function(){return m},e.unstable_getFirstCallbackNode=function(){return s(c)},e.unstable_next=function(P){switch(m){case 1:case 2:case 3:var K=3;break;default:K=m}var F=m;m=K;try{return P()}finally{m=F}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(P,K){switch(P){case 1:case 2:case 3:case 4:case 5:break;default:P=3}var F=m;m=P;try{return K()}finally{m=F}},e.unstable_scheduleCallback=function(P,K,F){var Q=e.unstable_now();switch(typeof F=="object"&&F!==null?(F=F.delay,F=typeof F=="number"&&0<F?Q+F:Q):F=Q,P){case 1:var _=-1;break;case 2:_=250;break;case 5:_=1073741823;break;case 4:_=1e4;break;default:_=5e3}return _=F+_,P={id:h++,callback:K,priorityLevel:P,startTime:F,expirationTime:_,sortIndex:-1},F>Q?(P.sortIndex=F,n(u,P),s(c)===null&&P===s(u)&&(x?(j(C),C=-1):x=!0,D(y,F-Q))):(P.sortIndex=_,n(c,P),g||p||(g=!0,U(N))),P},e.unstable_shouldYield=R,e.unstable_wrapCallback=function(P){var K=m;return function(){var F=m;m=K;try{return P.apply(this,arguments)}finally{m=F}}}})($C);EC.exports=$C;var R2=EC.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 I2=d,Ss=R2;function Ee(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,s=1;s<arguments.length;s++)n+="&args[]="+encodeURIComponent(arguments[s]);return"Minified React error #"+e+"; visit "+n+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var AC=new Set,Sc={};function Yi(e,n){Gl(e,n),Gl(e+"Capture",n)}function Gl(e,n){for(Sc[e]=n,e=0;e<n.length;e++)AC.add(n[e])}var ha=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),xg=Object.prototype.hasOwnProperty,P2=/^[: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]*$/,Wb={},Hb={};function M2(e){return xg.call(Hb,e)?!0:xg.call(Wb,e)?!1:P2.test(e)?Hb[e]=!0:(Wb[e]=!0,!1)}function O2(e,n,s,r){if(s!==null&&s.type===0)return!1;switch(typeof n){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 D2(e,n,s,r){if(n===null||typeof n>"u"||O2(e,n,s,r))return!0;if(r)return!1;if(s!==null)switch(s.type){case 3:return!n;case 4:return n===!1;case 5:return isNaN(n);case 6:return isNaN(n)||1>n}return!1}function ns(e,n,s,r,a,i,l){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=a,this.mustUseProperty=s,this.propertyName=e,this.type=n,this.sanitizeURL=i,this.removeEmptyString=l}var Mn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Mn[e]=new ns(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Mn[n]=new ns(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Mn[e]=new ns(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Mn[e]=new ns(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){Mn[e]=new ns(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Mn[e]=new ns(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Mn[e]=new ns(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Mn[e]=new ns(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Mn[e]=new ns(e,5,!1,e.toLowerCase(),null,!1,!1)});var lj=/[\-:]([a-z])/g;function oj(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 n=e.replace(lj,oj);Mn[n]=new ns(n,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var n=e.replace(lj,oj);Mn[n]=new ns(n,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var n=e.replace(lj,oj);Mn[n]=new ns(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Mn[e]=new ns(e,1,!1,e.toLowerCase(),null,!1,!1)});Mn.xlinkHref=new ns("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Mn[e]=new ns(e,1,!1,e.toLowerCase(),null,!0,!0)});function cj(e,n,s,r){var a=Mn.hasOwnProperty(n)?Mn[n]:null;(a!==null?a.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(D2(n,s,a,r)&&(s=null),r||a===null?M2(n)&&(s===null?e.removeAttribute(n):e.setAttribute(n,""+s)):a.mustUseProperty?e[a.propertyName]=s===null?a.type===3?!1:"":s:(n=a.attributeName,r=a.attributeNamespace,s===null?e.removeAttribute(n):(a=a.type,s=a===3||a===4&&s===!0?"":""+s,r?e.setAttributeNS(r,n,s):e.setAttribute(n,s))))}var ja=I2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Uu=Symbol.for("react.element"),jl=Symbol.for("react.portal"),wl=Symbol.for("react.fragment"),uj=Symbol.for("react.strict_mode"),vg=Symbol.for("react.profiler"),TC=Symbol.for("react.provider"),RC=Symbol.for("react.context"),dj=Symbol.for("react.forward_ref"),jg=Symbol.for("react.suspense"),wg=Symbol.for("react.suspense_list"),hj=Symbol.for("react.memo"),Ra=Symbol.for("react.lazy"),IC=Symbol.for("react.offscreen"),Kb=Symbol.iterator;function Lo(e){return e===null||typeof e!="object"?null:(e=Kb&&e[Kb]||e["@@iterator"],typeof e=="function"?e:null)}var Yt=Object.assign,Dm;function Xo(e){if(Dm===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);Dm=n&&n[1]||""}return`
|
|
34
|
-
`+Dm+e}var Lm=!1;function Fm(e,n){if(!e||Lm)return"";Lm=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(u){var r=u}Reflect.construct(e,[],n)}else{try{n.call()}catch(u){r=u}e.call(n.prototype)}else{try{throw Error()}catch(u){r=u}e()}}catch(u){if(u&&r&&typeof u.stack=="string"){for(var a=u.stack.split(`
|
|
35
|
-
`),i=r.stack.split(`
|
|
36
|
-
`),l=a.length-1,o=i.length-1;1<=l&&0<=o&&a[l]!==i[o];)o--;for(;1<=l&&0<=o;l--,o--)if(a[l]!==i[o]){if(l!==1||o!==1)do if(l--,o--,0>o||a[l]!==i[o]){var c=`
|
|
37
|
-
`+a[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{Lm=!1,Error.prepareStackTrace=s}return(e=e?e.displayName||e.name:"")?Xo(e):""}function L2(e){switch(e.tag){case 5:return Xo(e.type);case 16:return Xo("Lazy");case 13:return Xo("Suspense");case 19:return Xo("SuspenseList");case 0:case 2:case 15:return e=Fm(e.type,!1),e;case 11:return e=Fm(e.type.render,!1),e;case 1:return e=Fm(e.type,!0),e;default:return""}}function yg(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 wl:return"Fragment";case jl:return"Portal";case vg:return"Profiler";case uj:return"StrictMode";case jg:return"Suspense";case wg:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case RC:return(e.displayName||"Context")+".Consumer";case TC:return(e._context.displayName||"Context")+".Provider";case dj:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case hj:return n=e.displayName||null,n!==null?n:yg(e.type)||"Memo";case Ra:n=e._payload,e=e._init;try{return yg(e(n))}catch{}}return null}function F2(e){var n=e.type;switch(e.tag){case 24:return"Cache";case 9:return(n.displayName||"Context")+".Consumer";case 10:return(n._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=n.render,e=e.displayName||e.name||"",n.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return n;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return yg(n);case 8:return n===uj?"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 n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function Qa(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function PC(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function _2(e){var n=PC(e)?"checked":"value",s=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),r=""+e[n];if(!e.hasOwnProperty(n)&&typeof s<"u"&&typeof s.get=="function"&&typeof s.set=="function"){var a=s.get,i=s.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return a.call(this)},set:function(l){r=""+l,i.call(this,l)}}),Object.defineProperty(e,n,{enumerable:s.enumerable}),{getValue:function(){return r},setValue:function(l){r=""+l},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function Bu(e){e._valueTracker||(e._valueTracker=_2(e))}function MC(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var s=n.getValue(),r="";return e&&(r=PC(e)?e.checked?"true":"false":e.value),e=r,e!==s?(n.setValue(e),!0):!1}function ah(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 bg(e,n){var s=n.checked;return Yt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:s??e._wrapperState.initialChecked})}function Vb(e,n){var s=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;s=Qa(n.value!=null?n.value:s),e._wrapperState={initialChecked:r,initialValue:s,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function OC(e,n){n=n.checked,n!=null&&cj(e,"checked",n,!1)}function kg(e,n){OC(e,n);var s=Qa(n.value),r=n.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}n.hasOwnProperty("value")?Ng(e,n.type,s):n.hasOwnProperty("defaultValue")&&Ng(e,n.type,Qa(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function Gb(e,n,s){if(n.hasOwnProperty("value")||n.hasOwnProperty("defaultValue")){var r=n.type;if(!(r!=="submit"&&r!=="reset"||n.value!==void 0&&n.value!==null))return;n=""+e._wrapperState.initialValue,s||n===e.value||(e.value=n),e.defaultValue=n}s=e.name,s!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,s!==""&&(e.name=s)}function Ng(e,n,s){(n!=="number"||ah(e.ownerDocument)!==e)&&(s==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+s&&(e.defaultValue=""+s))}var Zo=Array.isArray;function Ol(e,n,s,r){if(e=e.options,n){n={};for(var a=0;a<s.length;a++)n["$"+s[a]]=!0;for(s=0;s<e.length;s++)a=n.hasOwnProperty("$"+e[s].value),e[s].selected!==a&&(e[s].selected=a),a&&r&&(e[s].defaultSelected=!0)}else{for(s=""+Qa(s),n=null,a=0;a<e.length;a++){if(e[a].value===s){e[a].selected=!0,r&&(e[a].defaultSelected=!0);return}n!==null||e[a].disabled||(n=e[a])}n!==null&&(n.selected=!0)}}function Sg(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(Ee(91));return Yt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Yb(e,n){var s=n.value;if(s==null){if(s=n.children,n=n.defaultValue,s!=null){if(n!=null)throw Error(Ee(92));if(Zo(s)){if(1<s.length)throw Error(Ee(93));s=s[0]}n=s}n==null&&(n=""),s=n}e._wrapperState={initialValue:Qa(s)}}function DC(e,n){var s=Qa(n.value),r=Qa(n.defaultValue);s!=null&&(s=""+s,s!==e.value&&(e.value=s),n.defaultValue==null&&e.defaultValue!==s&&(e.defaultValue=s)),r!=null&&(e.defaultValue=""+r)}function qb(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function LC(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 Cg(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?LC(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Wu,FC=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(n,s,r,a){MSApp.execUnsafeLocalFunction(function(){return e(n,s,r,a)})}:e}(function(e,n){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=n;else{for(Wu=Wu||document.createElement("div"),Wu.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=Wu.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Cc(e,n){if(n){var s=e.firstChild;if(s&&s===e.lastChild&&s.nodeType===3){s.nodeValue=n;return}}e.textContent=n}var lc={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},z2=["Webkit","ms","Moz","O"];Object.keys(lc).forEach(function(e){z2.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),lc[n]=lc[e]})});function _C(e,n,s){return n==null||typeof n=="boolean"||n===""?"":s||typeof n!="number"||n===0||lc.hasOwnProperty(e)&&lc[e]?(""+n).trim():n+"px"}function zC(e,n){e=e.style;for(var s in n)if(n.hasOwnProperty(s)){var r=s.indexOf("--")===0,a=_C(s,n[s],r);s==="float"&&(s="cssFloat"),r?e.setProperty(s,a):e[s]=a}}var U2=Yt({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 Eg(e,n){if(n){if(U2[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(Ee(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(Ee(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(Ee(61))}if(n.style!=null&&typeof n.style!="object")throw Error(Ee(62))}}function $g(e,n){if(e.indexOf("-")===-1)return typeof n.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 Ag=null;function fj(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var Tg=null,Dl=null,Ll=null;function Qb(e){if(e=gu(e)){if(typeof Tg!="function")throw Error(Ee(280));var n=e.stateNode;n&&(n=bf(n),Tg(e.stateNode,e.type,n))}}function UC(e){Dl?Ll?Ll.push(e):Ll=[e]:Dl=e}function BC(){if(Dl){var e=Dl,n=Ll;if(Ll=Dl=null,Qb(e),n)for(e=0;e<n.length;e++)Qb(n[e])}}function WC(e,n){return e(n)}function HC(){}var _m=!1;function KC(e,n,s){if(_m)return e(n,s);_m=!0;try{return WC(e,n,s)}finally{_m=!1,(Dl!==null||Ll!==null)&&(HC(),BC())}}function Ec(e,n){var s=e.stateNode;if(s===null)return null;var r=bf(s);if(r===null)return null;s=r[n];e:switch(n){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(Ee(231,n,typeof s));return s}var Rg=!1;if(ha)try{var Fo={};Object.defineProperty(Fo,"passive",{get:function(){Rg=!0}}),window.addEventListener("test",Fo,Fo),window.removeEventListener("test",Fo,Fo)}catch{Rg=!1}function B2(e,n,s,r,a,i,l,o,c){var u=Array.prototype.slice.call(arguments,3);try{n.apply(s,u)}catch(h){this.onError(h)}}var oc=!1,ih=null,lh=!1,Ig=null,W2={onError:function(e){oc=!0,ih=e}};function H2(e,n,s,r,a,i,l,o,c){oc=!1,ih=null,B2.apply(W2,arguments)}function K2(e,n,s,r,a,i,l,o,c){if(H2.apply(this,arguments),oc){if(oc){var u=ih;oc=!1,ih=null}else throw Error(Ee(198));lh||(lh=!0,Ig=u)}}function qi(e){var n=e,s=e;if(e.alternate)for(;n.return;)n=n.return;else{e=n;do n=e,n.flags&4098&&(s=n.return),e=n.return;while(e)}return n.tag===3?s:null}function VC(e){if(e.tag===13){var n=e.memoizedState;if(n===null&&(e=e.alternate,e!==null&&(n=e.memoizedState)),n!==null)return n.dehydrated}return null}function Jb(e){if(qi(e)!==e)throw Error(Ee(188))}function V2(e){var n=e.alternate;if(!n){if(n=qi(e),n===null)throw Error(Ee(188));return n!==e?null:e}for(var s=e,r=n;;){var a=s.return;if(a===null)break;var i=a.alternate;if(i===null){if(r=a.return,r!==null){s=r;continue}break}if(a.child===i.child){for(i=a.child;i;){if(i===s)return Jb(a),e;if(i===r)return Jb(a),n;i=i.sibling}throw Error(Ee(188))}if(s.return!==r.return)s=a,r=i;else{for(var l=!1,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){for(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)throw Error(Ee(189))}}if(s.alternate!==r)throw Error(Ee(190))}if(s.tag!==3)throw Error(Ee(188));return s.stateNode.current===s?e:n}function GC(e){return e=V2(e),e!==null?YC(e):null}function YC(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=YC(e);if(n!==null)return n;e=e.sibling}return null}var qC=Ss.unstable_scheduleCallback,Xb=Ss.unstable_cancelCallback,G2=Ss.unstable_shouldYield,Y2=Ss.unstable_requestPaint,sn=Ss.unstable_now,q2=Ss.unstable_getCurrentPriorityLevel,mj=Ss.unstable_ImmediatePriority,QC=Ss.unstable_UserBlockingPriority,oh=Ss.unstable_NormalPriority,Q2=Ss.unstable_LowPriority,JC=Ss.unstable_IdlePriority,vf=null,Rr=null;function J2(e){if(Rr&&typeof Rr.onCommitFiberRoot=="function")try{Rr.onCommitFiberRoot(vf,e,void 0,(e.current.flags&128)===128)}catch{}}var or=Math.clz32?Math.clz32:eO,X2=Math.log,Z2=Math.LN2;function eO(e){return e>>>=0,e===0?32:31-(X2(e)/Z2|0)|0}var Hu=64,Ku=4194304;function ec(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 ch(e,n){var s=e.pendingLanes;if(s===0)return 0;var r=0,a=e.suspendedLanes,i=e.pingedLanes,l=s&268435455;if(l!==0){var o=l&~a;o!==0?r=ec(o):(i&=l,i!==0&&(r=ec(i)))}else l=s&~a,l!==0?r=ec(l):i!==0&&(r=ec(i));if(r===0)return 0;if(n!==0&&n!==r&&!(n&a)&&(a=r&-r,i=n&-n,a>=i||a===16&&(i&4194240)!==0))return n;if(r&4&&(r|=s&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=r;0<n;)s=31-or(n),a=1<<s,r|=e[s],n&=~a;return r}function tO(e,n){switch(e){case 1:case 2:case 4:return n+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 n+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 nO(e,n){for(var s=e.suspendedLanes,r=e.pingedLanes,a=e.expirationTimes,i=e.pendingLanes;0<i;){var l=31-or(i),o=1<<l,c=a[l];c===-1?(!(o&s)||o&r)&&(a[l]=tO(o,n)):c<=n&&(e.expiredLanes|=o),i&=~o}}function Pg(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function XC(){var e=Hu;return Hu<<=1,!(Hu&4194240)&&(Hu=64),e}function zm(e){for(var n=[],s=0;31>s;s++)n.push(e);return n}function mu(e,n,s){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-or(n),e[n]=s}function sO(e,n){var s=e.pendingLanes&~n;e.pendingLanes=n,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=n,e.mutableReadLanes&=n,e.entangledLanes&=n,n=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<s;){var a=31-or(s),i=1<<a;n[a]=0,r[a]=-1,e[a]=-1,s&=~i}}function pj(e,n){var s=e.entangledLanes|=n;for(e=e.entanglements;s;){var r=31-or(s),a=1<<r;a&n|e[r]&n&&(e[r]|=n),s&=~a}}var Nt=0;function ZC(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var e1,gj,t1,n1,s1,Mg=!1,Vu=[],_a=null,za=null,Ua=null,$c=new Map,Ac=new Map,Pa=[],rO="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 Zb(e,n){switch(e){case"focusin":case"focusout":_a=null;break;case"dragenter":case"dragleave":za=null;break;case"mouseover":case"mouseout":Ua=null;break;case"pointerover":case"pointerout":$c.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Ac.delete(n.pointerId)}}function _o(e,n,s,r,a,i){return e===null||e.nativeEvent!==i?(e={blockedOn:n,domEventName:s,eventSystemFlags:r,nativeEvent:i,targetContainers:[a]},n!==null&&(n=gu(n),n!==null&&gj(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,a!==null&&n.indexOf(a)===-1&&n.push(a),e)}function aO(e,n,s,r,a){switch(n){case"focusin":return _a=_o(_a,e,n,s,r,a),!0;case"dragenter":return za=_o(za,e,n,s,r,a),!0;case"mouseover":return Ua=_o(Ua,e,n,s,r,a),!0;case"pointerover":var i=a.pointerId;return $c.set(i,_o($c.get(i)||null,e,n,s,r,a)),!0;case"gotpointercapture":return i=a.pointerId,Ac.set(i,_o(Ac.get(i)||null,e,n,s,r,a)),!0}return!1}function r1(e){var n=Si(e.target);if(n!==null){var s=qi(n);if(s!==null){if(n=s.tag,n===13){if(n=VC(s),n!==null){e.blockedOn=n,s1(e.priority,function(){t1(s)});return}}else if(n===3&&s.stateNode.current.memoizedState.isDehydrated){e.blockedOn=s.tag===3?s.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Pd(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var s=Og(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(s===null){s=e.nativeEvent;var r=new s.constructor(s.type,s);Ag=r,s.target.dispatchEvent(r),Ag=null}else return n=gu(s),n!==null&&gj(n),e.blockedOn=s,!1;n.shift()}return!0}function ek(e,n,s){Pd(e)&&s.delete(n)}function iO(){Mg=!1,_a!==null&&Pd(_a)&&(_a=null),za!==null&&Pd(za)&&(za=null),Ua!==null&&Pd(Ua)&&(Ua=null),$c.forEach(ek),Ac.forEach(ek)}function zo(e,n){e.blockedOn===n&&(e.blockedOn=null,Mg||(Mg=!0,Ss.unstable_scheduleCallback(Ss.unstable_NormalPriority,iO)))}function Tc(e){function n(a){return zo(a,e)}if(0<Vu.length){zo(Vu[0],e);for(var s=1;s<Vu.length;s++){var r=Vu[s];r.blockedOn===e&&(r.blockedOn=null)}}for(_a!==null&&zo(_a,e),za!==null&&zo(za,e),Ua!==null&&zo(Ua,e),$c.forEach(n),Ac.forEach(n),s=0;s<Pa.length;s++)r=Pa[s],r.blockedOn===e&&(r.blockedOn=null);for(;0<Pa.length&&(s=Pa[0],s.blockedOn===null);)r1(s),s.blockedOn===null&&Pa.shift()}var Fl=ja.ReactCurrentBatchConfig,uh=!0;function lO(e,n,s,r){var a=Nt,i=Fl.transition;Fl.transition=null;try{Nt=1,xj(e,n,s,r)}finally{Nt=a,Fl.transition=i}}function oO(e,n,s,r){var a=Nt,i=Fl.transition;Fl.transition=null;try{Nt=4,xj(e,n,s,r)}finally{Nt=a,Fl.transition=i}}function xj(e,n,s,r){if(uh){var a=Og(e,n,s,r);if(a===null)Qm(e,n,r,dh,s),Zb(e,r);else if(aO(a,e,n,s,r))r.stopPropagation();else if(Zb(e,r),n&4&&-1<rO.indexOf(e)){for(;a!==null;){var i=gu(a);if(i!==null&&e1(i),i=Og(e,n,s,r),i===null&&Qm(e,n,r,dh,s),i===a)break;a=i}a!==null&&r.stopPropagation()}else Qm(e,n,r,null,s)}}var dh=null;function Og(e,n,s,r){if(dh=null,e=fj(r),e=Si(e),e!==null)if(n=qi(e),n===null)e=null;else if(s=n.tag,s===13){if(e=VC(n),e!==null)return e;e=null}else if(s===3){if(n.stateNode.current.memoizedState.isDehydrated)return n.tag===3?n.stateNode.containerInfo:null;e=null}else n!==e&&(e=null);return dh=e,null}function a1(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(q2()){case mj:return 1;case QC:return 4;case oh:case Q2:return 16;case JC:return 536870912;default:return 16}default:return 16}}var Oa=null,vj=null,Md=null;function i1(){if(Md)return Md;var e,n=vj,s=n.length,r,a="value"in Oa?Oa.value:Oa.textContent,i=a.length;for(e=0;e<s&&n[e]===a[e];e++);var l=s-e;for(r=1;r<=l&&n[s-r]===a[i-r];r++);return Md=a.slice(e,1<r?1-r:void 0)}function Od(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function Gu(){return!0}function tk(){return!1}function Ts(e){function n(s,r,a,i,l){this._reactName=s,this._targetInst=a,this.type=r,this.nativeEvent=i,this.target=l,this.currentTarget=null;for(var o in e)e.hasOwnProperty(o)&&(s=e[o],this[o]=s?s(i):i[o]);return this.isDefaultPrevented=(i.defaultPrevented!=null?i.defaultPrevented:i.returnValue===!1)?Gu:tk,this.isPropagationStopped=tk,this}return Yt(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var s=this.nativeEvent;s&&(s.preventDefault?s.preventDefault():typeof s.returnValue!="unknown"&&(s.returnValue=!1),this.isDefaultPrevented=Gu)},stopPropagation:function(){var s=this.nativeEvent;s&&(s.stopPropagation?s.stopPropagation():typeof s.cancelBubble!="unknown"&&(s.cancelBubble=!0),this.isPropagationStopped=Gu)},persist:function(){},isPersistent:Gu}),n}var po={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},jj=Ts(po),pu=Yt({},po,{view:0,detail:0}),cO=Ts(pu),Um,Bm,Uo,jf=Yt({},pu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:wj,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!==Uo&&(Uo&&e.type==="mousemove"?(Um=e.screenX-Uo.screenX,Bm=e.screenY-Uo.screenY):Bm=Um=0,Uo=e),Um)},movementY:function(e){return"movementY"in e?e.movementY:Bm}}),nk=Ts(jf),uO=Yt({},jf,{dataTransfer:0}),dO=Ts(uO),hO=Yt({},pu,{relatedTarget:0}),Wm=Ts(hO),fO=Yt({},po,{animationName:0,elapsedTime:0,pseudoElement:0}),mO=Ts(fO),pO=Yt({},po,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),gO=Ts(pO),xO=Yt({},po,{data:0}),sk=Ts(xO),vO={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},jO={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"},wO={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function yO(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=wO[e])?!!n[e]:!1}function wj(){return yO}var bO=Yt({},pu,{key:function(e){if(e.key){var n=vO[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Od(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?jO[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:wj,charCode:function(e){return e.type==="keypress"?Od(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Od(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),kO=Ts(bO),NO=Yt({},jf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),rk=Ts(NO),SO=Yt({},pu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:wj}),CO=Ts(SO),EO=Yt({},po,{propertyName:0,elapsedTime:0,pseudoElement:0}),$O=Ts(EO),AO=Yt({},jf,{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}),TO=Ts(AO),RO=[9,13,27,32],yj=ha&&"CompositionEvent"in window,cc=null;ha&&"documentMode"in document&&(cc=document.documentMode);var IO=ha&&"TextEvent"in window&&!cc,l1=ha&&(!yj||cc&&8<cc&&11>=cc),ak=" ",ik=!1;function o1(e,n){switch(e){case"keyup":return RO.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function c1(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var yl=!1;function PO(e,n){switch(e){case"compositionend":return c1(n);case"keypress":return n.which!==32?null:(ik=!0,ak);case"textInput":return e=n.data,e===ak&&ik?null:e;default:return null}}function MO(e,n){if(yl)return e==="compositionend"||!yj&&o1(e,n)?(e=i1(),Md=vj=Oa=null,yl=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(n.ctrlKey||n.altKey||n.metaKey)||n.ctrlKey&&n.altKey){if(n.char&&1<n.char.length)return n.char;if(n.which)return String.fromCharCode(n.which)}return null;case"compositionend":return l1&&n.locale!=="ko"?null:n.data;default:return null}}var OO={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 lk(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!OO[e.type]:n==="textarea"}function u1(e,n,s,r){UC(r),n=hh(n,"onChange"),0<n.length&&(s=new jj("onChange","change",null,s,r),e.push({event:s,listeners:n}))}var uc=null,Rc=null;function DO(e){y1(e,0)}function wf(e){var n=Nl(e);if(MC(n))return e}function LO(e,n){if(e==="change")return n}var d1=!1;if(ha){var Hm;if(ha){var Km="oninput"in document;if(!Km){var ok=document.createElement("div");ok.setAttribute("oninput","return;"),Km=typeof ok.oninput=="function"}Hm=Km}else Hm=!1;d1=Hm&&(!document.documentMode||9<document.documentMode)}function ck(){uc&&(uc.detachEvent("onpropertychange",h1),Rc=uc=null)}function h1(e){if(e.propertyName==="value"&&wf(Rc)){var n=[];u1(n,Rc,e,fj(e)),KC(DO,n)}}function FO(e,n,s){e==="focusin"?(ck(),uc=n,Rc=s,uc.attachEvent("onpropertychange",h1)):e==="focusout"&&ck()}function _O(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return wf(Rc)}function zO(e,n){if(e==="click")return wf(n)}function UO(e,n){if(e==="input"||e==="change")return wf(n)}function BO(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var hr=typeof Object.is=="function"?Object.is:BO;function Ic(e,n){if(hr(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(r=0;r<s.length;r++){var a=s[r];if(!xg.call(n,a)||!hr(e[a],n[a]))return!1}return!0}function uk(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function dk(e,n){var s=uk(e);e=0;for(var r;s;){if(s.nodeType===3){if(r=e+s.textContent.length,e<=n&&r>=n)return{node:s,offset:n-e};e=r}e:{for(;s;){if(s.nextSibling){s=s.nextSibling;break e}s=s.parentNode}s=void 0}s=uk(s)}}function f1(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?f1(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function m1(){for(var e=window,n=ah();n instanceof e.HTMLIFrameElement;){try{var s=typeof n.contentWindow.location.href=="string"}catch{s=!1}if(s)e=n.contentWindow;else break;n=ah(e.document)}return n}function bj(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function WO(e){var n=m1(),s=e.focusedElem,r=e.selectionRange;if(n!==s&&s&&s.ownerDocument&&f1(s.ownerDocument.documentElement,s)){if(r!==null&&bj(s)){if(n=r.start,e=r.end,e===void 0&&(e=n),"selectionStart"in s)s.selectionStart=n,s.selectionEnd=Math.min(e,s.value.length);else if(e=(n=s.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var a=s.textContent.length,i=Math.min(r.start,a);r=r.end===void 0?i:Math.min(r.end,a),!e.extend&&i>r&&(a=r,r=i,i=a),a=dk(s,i);var l=dk(s,r);a&&l&&(e.rangeCount!==1||e.anchorNode!==a.node||e.anchorOffset!==a.offset||e.focusNode!==l.node||e.focusOffset!==l.offset)&&(n=n.createRange(),n.setStart(a.node,a.offset),e.removeAllRanges(),i>r?(e.addRange(n),e.extend(l.node,l.offset)):(n.setEnd(l.node,l.offset),e.addRange(n)))}}for(n=[],e=s;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof s.focus=="function"&&s.focus(),s=0;s<n.length;s++)e=n[s],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var HO=ha&&"documentMode"in document&&11>=document.documentMode,bl=null,Dg=null,dc=null,Lg=!1;function hk(e,n,s){var r=s.window===s?s.document:s.nodeType===9?s:s.ownerDocument;Lg||bl==null||bl!==ah(r)||(r=bl,"selectionStart"in r&&bj(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}),dc&&Ic(dc,r)||(dc=r,r=hh(Dg,"onSelect"),0<r.length&&(n=new jj("onSelect","select",null,n,s),e.push({event:n,listeners:r}),n.target=bl)))}function Yu(e,n){var s={};return s[e.toLowerCase()]=n.toLowerCase(),s["Webkit"+e]="webkit"+n,s["Moz"+e]="moz"+n,s}var kl={animationend:Yu("Animation","AnimationEnd"),animationiteration:Yu("Animation","AnimationIteration"),animationstart:Yu("Animation","AnimationStart"),transitionend:Yu("Transition","TransitionEnd")},Vm={},p1={};ha&&(p1=document.createElement("div").style,"AnimationEvent"in window||(delete kl.animationend.animation,delete kl.animationiteration.animation,delete kl.animationstart.animation),"TransitionEvent"in window||delete kl.transitionend.transition);function yf(e){if(Vm[e])return Vm[e];if(!kl[e])return e;var n=kl[e],s;for(s in n)if(n.hasOwnProperty(s)&&s in p1)return Vm[e]=n[s];return e}var g1=yf("animationend"),x1=yf("animationiteration"),v1=yf("animationstart"),j1=yf("transitionend"),w1=new Map,fk="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 ii(e,n){w1.set(e,n),Yi(n,[e])}for(var Gm=0;Gm<fk.length;Gm++){var Ym=fk[Gm],KO=Ym.toLowerCase(),VO=Ym[0].toUpperCase()+Ym.slice(1);ii(KO,"on"+VO)}ii(g1,"onAnimationEnd");ii(x1,"onAnimationIteration");ii(v1,"onAnimationStart");ii("dblclick","onDoubleClick");ii("focusin","onFocus");ii("focusout","onBlur");ii(j1,"onTransitionEnd");Gl("onMouseEnter",["mouseout","mouseover"]);Gl("onMouseLeave",["mouseout","mouseover"]);Gl("onPointerEnter",["pointerout","pointerover"]);Gl("onPointerLeave",["pointerout","pointerover"]);Yi("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Yi("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Yi("onBeforeInput",["compositionend","keypress","textInput","paste"]);Yi("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Yi("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Yi("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var tc="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(" "),GO=new Set("cancel close invalid load scroll toggle".split(" ").concat(tc));function mk(e,n,s){var r=e.type||"unknown-event";e.currentTarget=s,K2(r,n,void 0,e),e.currentTarget=null}function y1(e,n){n=(n&4)!==0;for(var s=0;s<e.length;s++){var r=e[s],a=r.event;r=r.listeners;e:{var i=void 0;if(n)for(var l=r.length-1;0<=l;l--){var o=r[l],c=o.instance,u=o.currentTarget;if(o=o.listener,c!==i&&a.isPropagationStopped())break e;mk(a,o,u),i=c}else for(l=0;l<r.length;l++){if(o=r[l],c=o.instance,u=o.currentTarget,o=o.listener,c!==i&&a.isPropagationStopped())break e;mk(a,o,u),i=c}}}if(lh)throw e=Ig,lh=!1,Ig=null,e}function Lt(e,n){var s=n[Bg];s===void 0&&(s=n[Bg]=new Set);var r=e+"__bubble";s.has(r)||(b1(n,e,2,!1),s.add(r))}function qm(e,n,s){var r=0;n&&(r|=4),b1(s,e,r,n)}var qu="_reactListening"+Math.random().toString(36).slice(2);function Pc(e){if(!e[qu]){e[qu]=!0,AC.forEach(function(s){s!=="selectionchange"&&(GO.has(s)||qm(s,!1,e),qm(s,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[qu]||(n[qu]=!0,qm("selectionchange",!1,n))}}function b1(e,n,s,r){switch(a1(n)){case 1:var a=lO;break;case 4:a=oO;break;default:a=xj}s=a.bind(null,n,s,e),a=void 0,!Rg||n!=="touchstart"&&n!=="touchmove"&&n!=="wheel"||(a=!0),r?a!==void 0?e.addEventListener(n,s,{capture:!0,passive:a}):e.addEventListener(n,s,!0):a!==void 0?e.addEventListener(n,s,{passive:a}):e.addEventListener(n,s,!1)}function Qm(e,n,s,r,a){var i=r;if(!(n&1)&&!(n&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===a||o.nodeType===8&&o.parentNode===a)break;if(l===4)for(l=r.return;l!==null;){var c=l.tag;if((c===3||c===4)&&(c=l.stateNode.containerInfo,c===a||c.nodeType===8&&c.parentNode===a))return;l=l.return}for(;o!==null;){if(l=Si(o),l===null)return;if(c=l.tag,c===5||c===6){r=i=l;continue e}o=o.parentNode}}r=r.return}KC(function(){var u=i,h=fj(s),f=[];e:{var m=w1.get(e);if(m!==void 0){var p=jj,g=e;switch(e){case"keypress":if(Od(s)===0)break e;case"keydown":case"keyup":p=kO;break;case"focusin":g="focus",p=Wm;break;case"focusout":g="blur",p=Wm;break;case"beforeblur":case"afterblur":p=Wm;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=nk;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=dO;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=CO;break;case g1:case x1:case v1:p=mO;break;case j1:p=$O;break;case"scroll":p=cO;break;case"wheel":p=TO;break;case"copy":case"cut":case"paste":p=gO;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=rk}var x=(n&4)!==0,k=!x&&e==="scroll",j=x?m!==null?m+"Capture":null:m;x=[];for(var v=u,w;v!==null;){w=v;var y=w.stateNode;if(w.tag===5&&y!==null&&(w=y,j!==null&&(y=Ec(v,j),y!=null&&x.push(Mc(v,y,w)))),k)break;v=v.return}0<x.length&&(m=new p(m,g,null,s,h),f.push({event:m,listeners:x}))}}if(!(n&7)){e:{if(m=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",m&&s!==Ag&&(g=s.relatedTarget||s.fromElement)&&(Si(g)||g[fa]))break e;if((p||m)&&(m=h.window===h?h:(m=h.ownerDocument)?m.defaultView||m.parentWindow:window,p?(g=s.relatedTarget||s.toElement,p=u,g=g?Si(g):null,g!==null&&(k=qi(g),g!==k||g.tag!==5&&g.tag!==6)&&(g=null)):(p=null,g=u),p!==g)){if(x=nk,y="onMouseLeave",j="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(x=rk,y="onPointerLeave",j="onPointerEnter",v="pointer"),k=p==null?m:Nl(p),w=g==null?m:Nl(g),m=new x(y,v+"leave",p,s,h),m.target=k,m.relatedTarget=w,y=null,Si(h)===u&&(x=new x(j,v+"enter",g,s,h),x.target=w,x.relatedTarget=k,y=x),k=y,p&&g)t:{for(x=p,j=g,v=0,w=x;w;w=cl(w))v++;for(w=0,y=j;y;y=cl(y))w++;for(;0<v-w;)x=cl(x),v--;for(;0<w-v;)j=cl(j),w--;for(;v--;){if(x===j||j!==null&&x===j.alternate)break t;x=cl(x),j=cl(j)}x=null}else x=null;p!==null&&pk(f,m,p,x,!1),g!==null&&k!==null&&pk(f,k,g,x,!0)}}e:{if(m=u?Nl(u):window,p=m.nodeName&&m.nodeName.toLowerCase(),p==="select"||p==="input"&&m.type==="file")var N=LO;else if(lk(m))if(d1)N=UO;else{N=_O;var b=FO}else(p=m.nodeName)&&p.toLowerCase()==="input"&&(m.type==="checkbox"||m.type==="radio")&&(N=zO);if(N&&(N=N(e,u))){u1(f,N,s,h);break e}b&&b(e,m,u),e==="focusout"&&(b=m._wrapperState)&&b.controlled&&m.type==="number"&&Ng(m,"number",m.value)}switch(b=u?Nl(u):window,e){case"focusin":(lk(b)||b.contentEditable==="true")&&(bl=b,Dg=u,dc=null);break;case"focusout":dc=Dg=bl=null;break;case"mousedown":Lg=!0;break;case"contextmenu":case"mouseup":case"dragend":Lg=!1,hk(f,s,h);break;case"selectionchange":if(HO)break;case"keydown":case"keyup":hk(f,s,h)}var S;if(yj)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 yl?o1(e,s)&&(C="onCompositionEnd"):e==="keydown"&&s.keyCode===229&&(C="onCompositionStart");C&&(l1&&s.locale!=="ko"&&(yl||C!=="onCompositionStart"?C==="onCompositionEnd"&&yl&&(S=i1()):(Oa=h,vj="value"in Oa?Oa.value:Oa.textContent,yl=!0)),b=hh(u,C),0<b.length&&(C=new sk(C,e,null,s,h),f.push({event:C,listeners:b}),S?C.data=S:(S=c1(s),S!==null&&(C.data=S)))),(S=IO?PO(e,s):MO(e,s))&&(u=hh(u,"onBeforeInput"),0<u.length&&(h=new sk("onBeforeInput","beforeinput",null,s,h),f.push({event:h,listeners:u}),h.data=S))}y1(f,n)})}function Mc(e,n,s){return{instance:e,listener:n,currentTarget:s}}function hh(e,n){for(var s=n+"Capture",r=[];e!==null;){var a=e,i=a.stateNode;a.tag===5&&i!==null&&(a=i,i=Ec(e,s),i!=null&&r.unshift(Mc(e,i,a)),i=Ec(e,n),i!=null&&r.push(Mc(e,i,a))),e=e.return}return r}function cl(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function pk(e,n,s,r,a){for(var i=n._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,a?(c=Ec(s,i),c!=null&&l.unshift(Mc(s,c,o))):a||(c=Ec(s,i),c!=null&&l.push(Mc(s,c,o)))),s=s.return}l.length!==0&&e.push({event:n,listeners:l})}var YO=/\r\n?/g,qO=/\u0000|\uFFFD/g;function gk(e){return(typeof e=="string"?e:""+e).replace(YO,`
|
|
38
|
-
`).replace(qO,"")}function Qu(e,n,s){if(n=gk(n),gk(e)!==n&&s)throw Error(Ee(425))}function fh(){}var Fg=null,_g=null;function zg(e,n){return e==="textarea"||e==="noscript"||typeof n.children=="string"||typeof n.children=="number"||typeof n.dangerouslySetInnerHTML=="object"&&n.dangerouslySetInnerHTML!==null&&n.dangerouslySetInnerHTML.__html!=null}var Ug=typeof setTimeout=="function"?setTimeout:void 0,QO=typeof clearTimeout=="function"?clearTimeout:void 0,xk=typeof Promise=="function"?Promise:void 0,JO=typeof queueMicrotask=="function"?queueMicrotask:typeof xk<"u"?function(e){return xk.resolve(null).then(e).catch(XO)}:Ug;function XO(e){setTimeout(function(){throw e})}function Jm(e,n){var s=n,r=0;do{var a=s.nextSibling;if(e.removeChild(s),a&&a.nodeType===8)if(s=a.data,s==="/$"){if(r===0){e.removeChild(a),Tc(n);return}r--}else s!=="$"&&s!=="$?"&&s!=="$!"||r++;s=a}while(s);Tc(n)}function Ba(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function vk(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="$"||s==="$!"||s==="$?"){if(n===0)return e;n--}else s==="/$"&&n++}e=e.previousSibling}return null}var go=Math.random().toString(36).slice(2),Er="__reactFiber$"+go,Oc="__reactProps$"+go,fa="__reactContainer$"+go,Bg="__reactEvents$"+go,ZO="__reactListeners$"+go,eD="__reactHandles$"+go;function Si(e){var n=e[Er];if(n)return n;for(var s=e.parentNode;s;){if(n=s[fa]||s[Er]){if(s=n.alternate,n.child!==null||s!==null&&s.child!==null)for(e=vk(e);e!==null;){if(s=e[Er])return s;e=vk(e)}return n}e=s,s=e.parentNode}return null}function gu(e){return e=e[Er]||e[fa],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Nl(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(Ee(33))}function bf(e){return e[Oc]||null}var Wg=[],Sl=-1;function li(e){return{current:e}}function _t(e){0>Sl||(e.current=Wg[Sl],Wg[Sl]=null,Sl--)}function Mt(e,n){Sl++,Wg[Sl]=e.current,e.current=n}var Ja={},Wn=li(Ja),os=li(!1),Di=Ja;function Yl(e,n){var s=e.type.contextTypes;if(!s)return Ja;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var a={},i;for(i in s)a[i]=n[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=a),a}function cs(e){return e=e.childContextTypes,e!=null}function mh(){_t(os),_t(Wn)}function jk(e,n,s){if(Wn.current!==Ja)throw Error(Ee(168));Mt(Wn,n),Mt(os,s)}function k1(e,n,s){var r=e.stateNode;if(n=n.childContextTypes,typeof r.getChildContext!="function")return s;r=r.getChildContext();for(var a in r)if(!(a in n))throw Error(Ee(108,F2(e)||"Unknown",a));return Yt({},s,r)}function ph(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ja,Di=Wn.current,Mt(Wn,e),Mt(os,os.current),!0}function wk(e,n,s){var r=e.stateNode;if(!r)throw Error(Ee(169));s?(e=k1(e,n,Di),r.__reactInternalMemoizedMergedChildContext=e,_t(os),_t(Wn),Mt(Wn,e)):_t(os),Mt(os,s)}var ta=null,kf=!1,Xm=!1;function N1(e){ta===null?ta=[e]:ta.push(e)}function tD(e){kf=!0,N1(e)}function oi(){if(!Xm&&ta!==null){Xm=!0;var e=0,n=Nt;try{var s=ta;for(Nt=1;e<s.length;e++){var r=s[e];do r=r(!0);while(r!==null)}ta=null,kf=!1}catch(a){throw ta!==null&&(ta=ta.slice(e+1)),qC(mj,oi),a}finally{Nt=n,Xm=!1}}return null}var Cl=[],El=0,gh=null,xh=0,zs=[],Us=0,Li=null,aa=1,ia="";function yi(e,n){Cl[El++]=xh,Cl[El++]=gh,gh=e,xh=n}function S1(e,n,s){zs[Us++]=aa,zs[Us++]=ia,zs[Us++]=Li,Li=e;var r=aa;e=ia;var a=32-or(r)-1;r&=~(1<<a),s+=1;var i=32-or(n)+a;if(30<i){var l=a-a%5;i=(r&(1<<l)-1).toString(32),r>>=l,a-=l,aa=1<<32-or(n)+a|s<<a|r,ia=i+e}else aa=1<<i|s<<a|r,ia=e}function kj(e){e.return!==null&&(yi(e,1),S1(e,1,0))}function Nj(e){for(;e===gh;)gh=Cl[--El],Cl[El]=null,xh=Cl[--El],Cl[El]=null;for(;e===Li;)Li=zs[--Us],zs[Us]=null,ia=zs[--Us],zs[Us]=null,aa=zs[--Us],zs[Us]=null}var ks=null,ys=null,Wt=!1,sr=null;function C1(e,n){var s=Ks(5,null,null,0);s.elementType="DELETED",s.stateNode=n,s.return=e,n=e.deletions,n===null?(e.deletions=[s],e.flags|=16):n.push(s)}function yk(e,n){switch(e.tag){case 5:var s=e.type;return n=n.nodeType!==1||s.toLowerCase()!==n.nodeName.toLowerCase()?null:n,n!==null?(e.stateNode=n,ks=e,ys=Ba(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,ks=e,ys=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(s=Li!==null?{id:aa,overflow:ia}:null,e.memoizedState={dehydrated:n,treeContext:s,retryLane:1073741824},s=Ks(18,null,null,0),s.stateNode=n,s.return=e,e.child=s,ks=e,ys=null,!0):!1;default:return!1}}function Hg(e){return(e.mode&1)!==0&&(e.flags&128)===0}function Kg(e){if(Wt){var n=ys;if(n){var s=n;if(!yk(e,n)){if(Hg(e))throw Error(Ee(418));n=Ba(s.nextSibling);var r=ks;n&&yk(e,n)?C1(r,s):(e.flags=e.flags&-4097|2,Wt=!1,ks=e)}}else{if(Hg(e))throw Error(Ee(418));e.flags=e.flags&-4097|2,Wt=!1,ks=e}}}function bk(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;ks=e}function Ju(e){if(e!==ks)return!1;if(!Wt)return bk(e),Wt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!zg(e.type,e.memoizedProps)),n&&(n=ys)){if(Hg(e))throw E1(),Error(Ee(418));for(;n;)C1(e,n),n=Ba(n.nextSibling)}if(bk(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(Ee(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var s=e.data;if(s==="/$"){if(n===0){ys=Ba(e.nextSibling);break e}n--}else s!=="$"&&s!=="$!"&&s!=="$?"||n++}e=e.nextSibling}ys=null}}else ys=ks?Ba(e.stateNode.nextSibling):null;return!0}function E1(){for(var e=ys;e;)e=Ba(e.nextSibling)}function ql(){ys=ks=null,Wt=!1}function Sj(e){sr===null?sr=[e]:sr.push(e)}var nD=ja.ReactCurrentBatchConfig;function Bo(e,n,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(Ee(309));var r=s.stateNode}if(!r)throw Error(Ee(147,e));var a=r,i=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===i?n.ref:(n=function(l){var o=a.refs;l===null?delete o[i]:o[i]=l},n._stringRef=i,n)}if(typeof e!="string")throw Error(Ee(284));if(!s._owner)throw Error(Ee(290,e))}return e}function Xu(e,n){throw e=Object.prototype.toString.call(n),Error(Ee(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function kk(e){var n=e._init;return n(e._payload)}function $1(e){function n(j,v){if(e){var w=j.deletions;w===null?(j.deletions=[v],j.flags|=16):w.push(v)}}function s(j,v){if(!e)return null;for(;v!==null;)n(j,v),v=v.sibling;return null}function r(j,v){for(j=new Map;v!==null;)v.key!==null?j.set(v.key,v):j.set(v.index,v),v=v.sibling;return j}function a(j,v){return j=Va(j,v),j.index=0,j.sibling=null,j}function i(j,v,w){return j.index=w,e?(w=j.alternate,w!==null?(w=w.index,w<v?(j.flags|=2,v):w):(j.flags|=2,v)):(j.flags|=1048576,v)}function l(j){return e&&j.alternate===null&&(j.flags|=2),j}function o(j,v,w,y){return v===null||v.tag!==6?(v=ap(w,j.mode,y),v.return=j,v):(v=a(v,w),v.return=j,v)}function c(j,v,w,y){var N=w.type;return N===wl?h(j,v,w.props.children,y,w.key):v!==null&&(v.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===Ra&&kk(N)===v.type)?(y=a(v,w.props),y.ref=Bo(j,v,w),y.return=j,y):(y=Bd(w.type,w.key,w.props,null,j.mode,y),y.ref=Bo(j,v,w),y.return=j,y)}function u(j,v,w,y){return v===null||v.tag!==4||v.stateNode.containerInfo!==w.containerInfo||v.stateNode.implementation!==w.implementation?(v=ip(w,j.mode,y),v.return=j,v):(v=a(v,w.children||[]),v.return=j,v)}function h(j,v,w,y,N){return v===null||v.tag!==7?(v=Ii(w,j.mode,y,N),v.return=j,v):(v=a(v,w),v.return=j,v)}function f(j,v,w){if(typeof v=="string"&&v!==""||typeof v=="number")return v=ap(""+v,j.mode,w),v.return=j,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case Uu:return w=Bd(v.type,v.key,v.props,null,j.mode,w),w.ref=Bo(j,null,v),w.return=j,w;case jl:return v=ip(v,j.mode,w),v.return=j,v;case Ra:var y=v._init;return f(j,y(v._payload),w)}if(Zo(v)||Lo(v))return v=Ii(v,j.mode,w,null),v.return=j,v;Xu(j,v)}return null}function m(j,v,w,y){var N=v!==null?v.key:null;if(typeof w=="string"&&w!==""||typeof w=="number")return N!==null?null:o(j,v,""+w,y);if(typeof w=="object"&&w!==null){switch(w.$$typeof){case Uu:return w.key===N?c(j,v,w,y):null;case jl:return w.key===N?u(j,v,w,y):null;case Ra:return N=w._init,m(j,v,N(w._payload),y)}if(Zo(w)||Lo(w))return N!==null?null:h(j,v,w,y,null);Xu(j,w)}return null}function p(j,v,w,y,N){if(typeof y=="string"&&y!==""||typeof y=="number")return j=j.get(w)||null,o(v,j,""+y,N);if(typeof y=="object"&&y!==null){switch(y.$$typeof){case Uu:return j=j.get(y.key===null?w:y.key)||null,c(v,j,y,N);case jl:return j=j.get(y.key===null?w:y.key)||null,u(v,j,y,N);case Ra:var b=y._init;return p(j,v,w,b(y._payload),N)}if(Zo(y)||Lo(y))return j=j.get(w)||null,h(v,j,y,N,null);Xu(v,y)}return null}function g(j,v,w,y){for(var N=null,b=null,S=v,C=v=0,T=null;S!==null&&C<w.length;C++){S.index>C?(T=S,S=null):T=S.sibling;var E=m(j,S,w[C],y);if(E===null){S===null&&(S=T);break}e&&S&&E.alternate===null&&n(j,S),v=i(E,v,C),b===null?N=E:b.sibling=E,b=E,S=T}if(C===w.length)return s(j,S),Wt&&yi(j,C),N;if(S===null){for(;C<w.length;C++)S=f(j,w[C],y),S!==null&&(v=i(S,v,C),b===null?N=S:b.sibling=S,b=S);return Wt&&yi(j,C),N}for(S=r(j,S);C<w.length;C++)T=p(S,j,C,w[C],y),T!==null&&(e&&T.alternate!==null&&S.delete(T.key===null?C:T.key),v=i(T,v,C),b===null?N=T:b.sibling=T,b=T);return e&&S.forEach(function(R){return n(j,R)}),Wt&&yi(j,C),N}function x(j,v,w,y){var N=Lo(w);if(typeof N!="function")throw Error(Ee(150));if(w=N.call(w),w==null)throw Error(Ee(151));for(var b=N=null,S=v,C=v=0,T=null,E=w.next();S!==null&&!E.done;C++,E=w.next()){S.index>C?(T=S,S=null):T=S.sibling;var R=m(j,S,E.value,y);if(R===null){S===null&&(S=T);break}e&&S&&R.alternate===null&&n(j,S),v=i(R,v,C),b===null?N=R:b.sibling=R,b=R,S=T}if(E.done)return s(j,S),Wt&&yi(j,C),N;if(S===null){for(;!E.done;C++,E=w.next())E=f(j,E.value,y),E!==null&&(v=i(E,v,C),b===null?N=E:b.sibling=E,b=E);return Wt&&yi(j,C),N}for(S=r(j,S);!E.done;C++,E=w.next())E=p(S,j,C,E.value,y),E!==null&&(e&&E.alternate!==null&&S.delete(E.key===null?C:E.key),v=i(E,v,C),b===null?N=E:b.sibling=E,b=E);return e&&S.forEach(function(M){return n(j,M)}),Wt&&yi(j,C),N}function k(j,v,w,y){if(typeof w=="object"&&w!==null&&w.type===wl&&w.key===null&&(w=w.props.children),typeof w=="object"&&w!==null){switch(w.$$typeof){case Uu:e:{for(var N=w.key,b=v;b!==null;){if(b.key===N){if(N=w.type,N===wl){if(b.tag===7){s(j,b.sibling),v=a(b,w.props.children),v.return=j,j=v;break e}}else if(b.elementType===N||typeof N=="object"&&N!==null&&N.$$typeof===Ra&&kk(N)===b.type){s(j,b.sibling),v=a(b,w.props),v.ref=Bo(j,b,w),v.return=j,j=v;break e}s(j,b);break}else n(j,b);b=b.sibling}w.type===wl?(v=Ii(w.props.children,j.mode,y,w.key),v.return=j,j=v):(y=Bd(w.type,w.key,w.props,null,j.mode,y),y.ref=Bo(j,v,w),y.return=j,j=y)}return l(j);case jl:e:{for(b=w.key;v!==null;){if(v.key===b)if(v.tag===4&&v.stateNode.containerInfo===w.containerInfo&&v.stateNode.implementation===w.implementation){s(j,v.sibling),v=a(v,w.children||[]),v.return=j,j=v;break e}else{s(j,v);break}else n(j,v);v=v.sibling}v=ip(w,j.mode,y),v.return=j,j=v}return l(j);case Ra:return b=w._init,k(j,v,b(w._payload),y)}if(Zo(w))return g(j,v,w,y);if(Lo(w))return x(j,v,w,y);Xu(j,w)}return typeof w=="string"&&w!==""||typeof w=="number"?(w=""+w,v!==null&&v.tag===6?(s(j,v.sibling),v=a(v,w),v.return=j,j=v):(s(j,v),v=ap(w,j.mode,y),v.return=j,j=v),l(j)):s(j,v)}return k}var Ql=$1(!0),A1=$1(!1),vh=li(null),jh=null,$l=null,Cj=null;function Ej(){Cj=$l=jh=null}function $j(e){var n=vh.current;_t(vh),e._currentValue=n}function Vg(e,n,s){for(;e!==null;){var r=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,r!==null&&(r.childLanes|=n)):r!==null&&(r.childLanes&n)!==n&&(r.childLanes|=n),e===s)break;e=e.return}}function _l(e,n){jh=e,Cj=$l=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(is=!0),e.firstContext=null)}function Ys(e){var n=e._currentValue;if(Cj!==e)if(e={context:e,memoizedValue:n,next:null},$l===null){if(jh===null)throw Error(Ee(308));$l=e,jh.dependencies={lanes:0,firstContext:e}}else $l=$l.next=e;return n}var Ci=null;function Aj(e){Ci===null?Ci=[e]:Ci.push(e)}function T1(e,n,s,r){var a=n.interleaved;return a===null?(s.next=s,Aj(n)):(s.next=a.next,a.next=s),n.interleaved=s,ma(e,r)}function ma(e,n){e.lanes|=n;var s=e.alternate;for(s!==null&&(s.lanes|=n),s=e,e=e.return;e!==null;)e.childLanes|=n,s=e.alternate,s!==null&&(s.childLanes|=n),s=e,e=e.return;return s.tag===3?s.stateNode:null}var Ia=!1;function Tj(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function R1(e,n){e=e.updateQueue,n.updateQueue===e&&(n.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function oa(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Wa(e,n,s){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,jt&2){var a=r.pending;return a===null?n.next=n:(n.next=a.next,a.next=n),r.pending=n,ma(e,s)}return a=r.interleaved,a===null?(n.next=n,Aj(r)):(n.next=a.next,a.next=n),r.interleaved=n,ma(e,s)}function Dd(e,n,s){if(n=n.updateQueue,n!==null&&(n=n.shared,(s&4194240)!==0)){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,pj(e,s)}}function Nk(e,n){var s=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,s===r)){var a=null,i=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};i===null?a=i=l:i=i.next=l,s=s.next}while(s!==null);i===null?a=i=n:i=i.next=n}else a=i=n;s={baseState:r.baseState,firstBaseUpdate:a,lastBaseUpdate:i,shared:r.shared,effects:r.effects},e.updateQueue=s;return}e=s.lastBaseUpdate,e===null?s.firstBaseUpdate=n:e.next=n,s.lastBaseUpdate=n}function wh(e,n,s,r){var a=e.updateQueue;Ia=!1;var i=a.firstBaseUpdate,l=a.lastBaseUpdate,o=a.shared.pending;if(o!==null){a.shared.pending=null;var c=o,u=c.next;c.next=null,l===null?i=u:l.next=u,l=c;var h=e.alternate;h!==null&&(h=h.updateQueue,o=h.lastBaseUpdate,o!==l&&(o===null?h.firstBaseUpdate=u:o.next=u,h.lastBaseUpdate=c))}if(i!==null){var f=a.baseState;l=0,h=u=c=null,o=i;do{var m=o.lane,p=o.eventTime;if((r&m)===m){h!==null&&(h=h.next={eventTime:p,lane:0,tag:o.tag,payload:o.payload,callback:o.callback,next:null});e:{var g=e,x=o;switch(m=n,p=s,x.tag){case 1:if(g=x.payload,typeof g=="function"){f=g.call(p,f,m);break e}f=g;break e;case 3:g.flags=g.flags&-65537|128;case 0:if(g=x.payload,m=typeof g=="function"?g.call(p,f,m):g,m==null)break e;f=Yt({},f,m);break e;case 2:Ia=!0}}o.callback!==null&&o.lane!==0&&(e.flags|=64,m=a.effects,m===null?a.effects=[o]:m.push(o))}else p={eventTime:p,lane:m,tag:o.tag,payload:o.payload,callback:o.callback,next:null},h===null?(u=h=p,c=f):h=h.next=p,l|=m;if(o=o.next,o===null){if(o=a.shared.pending,o===null)break;m=o,o=m.next,m.next=null,a.lastBaseUpdate=m,a.shared.pending=null}}while(!0);if(h===null&&(c=f),a.baseState=c,a.firstBaseUpdate=u,a.lastBaseUpdate=h,n=a.shared.interleaved,n!==null){a=n;do l|=a.lane,a=a.next;while(a!==n)}else i===null&&(a.shared.lanes=0);_i|=l,e.lanes=l,e.memoizedState=f}}function Sk(e,n,s){if(e=n.effects,n.effects=null,e!==null)for(n=0;n<e.length;n++){var r=e[n],a=r.callback;if(a!==null){if(r.callback=null,r=s,typeof a!="function")throw Error(Ee(191,a));a.call(r)}}}var xu={},Ir=li(xu),Dc=li(xu),Lc=li(xu);function Ei(e){if(e===xu)throw Error(Ee(174));return e}function Rj(e,n){switch(Mt(Lc,n),Mt(Dc,e),Mt(Ir,xu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:Cg(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=Cg(n,e)}_t(Ir),Mt(Ir,n)}function Jl(){_t(Ir),_t(Dc),_t(Lc)}function I1(e){Ei(Lc.current);var n=Ei(Ir.current),s=Cg(n,e.type);n!==s&&(Mt(Dc,e),Mt(Ir,s))}function Ij(e){Dc.current===e&&(_t(Ir),_t(Dc))}var Kt=li(0);function yh(e){for(var n=e;n!==null;){if(n.tag===13){var s=n.memoizedState;if(s!==null&&(s=s.dehydrated,s===null||s.data==="$?"||s.data==="$!"))return n}else if(n.tag===19&&n.memoizedProps.revealOrder!==void 0){if(n.flags&128)return n}else if(n.child!==null){n.child.return=n,n=n.child;continue}if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return null;n=n.return}n.sibling.return=n.return,n=n.sibling}return null}var Zm=[];function Pj(){for(var e=0;e<Zm.length;e++)Zm[e]._workInProgressVersionPrimary=null;Zm.length=0}var Ld=ja.ReactCurrentDispatcher,ep=ja.ReactCurrentBatchConfig,Fi=0,Vt=null,pn=null,Nn=null,bh=!1,hc=!1,Fc=0,sD=0;function Fn(){throw Error(Ee(321))}function Mj(e,n){if(n===null)return!1;for(var s=0;s<n.length&&s<e.length;s++)if(!hr(e[s],n[s]))return!1;return!0}function Oj(e,n,s,r,a,i){if(Fi=i,Vt=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Ld.current=e===null||e.memoizedState===null?lD:oD,e=s(r,a),hc){i=0;do{if(hc=!1,Fc=0,25<=i)throw Error(Ee(301));i+=1,Nn=pn=null,n.updateQueue=null,Ld.current=cD,e=s(r,a)}while(hc)}if(Ld.current=kh,n=pn!==null&&pn.next!==null,Fi=0,Nn=pn=Vt=null,bh=!1,n)throw Error(Ee(300));return e}function Dj(){var e=Fc!==0;return Fc=0,e}function Sr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Nn===null?Vt.memoizedState=Nn=e:Nn=Nn.next=e,Nn}function qs(){if(pn===null){var e=Vt.alternate;e=e!==null?e.memoizedState:null}else e=pn.next;var n=Nn===null?Vt.memoizedState:Nn.next;if(n!==null)Nn=n,pn=e;else{if(e===null)throw Error(Ee(310));pn=e,e={memoizedState:pn.memoizedState,baseState:pn.baseState,baseQueue:pn.baseQueue,queue:pn.queue,next:null},Nn===null?Vt.memoizedState=Nn=e:Nn=Nn.next=e}return Nn}function _c(e,n){return typeof n=="function"?n(e):n}function tp(e){var n=qs(),s=n.queue;if(s===null)throw Error(Ee(311));s.lastRenderedReducer=e;var r=pn,a=r.baseQueue,i=s.pending;if(i!==null){if(a!==null){var l=a.next;a.next=i.next,i.next=l}r.baseQueue=a=i,s.pending=null}if(a!==null){i=a.next,r=r.baseState;var o=l=null,c=null,u=i;do{var h=u.lane;if((Fi&h)===h)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 f={lane:h,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};c===null?(o=c=f,l=r):c=c.next=f,Vt.lanes|=h,_i|=h}u=u.next}while(u!==null&&u!==i);c===null?l=r:c.next=o,hr(r,n.memoizedState)||(is=!0),n.memoizedState=r,n.baseState=l,n.baseQueue=c,s.lastRenderedState=r}if(e=s.interleaved,e!==null){a=e;do i=a.lane,Vt.lanes|=i,_i|=i,a=a.next;while(a!==e)}else a===null&&(s.lanes=0);return[n.memoizedState,s.dispatch]}function np(e){var n=qs(),s=n.queue;if(s===null)throw Error(Ee(311));s.lastRenderedReducer=e;var r=s.dispatch,a=s.pending,i=n.memoizedState;if(a!==null){s.pending=null;var l=a=a.next;do i=e(i,l.action),l=l.next;while(l!==a);hr(i,n.memoizedState)||(is=!0),n.memoizedState=i,n.baseQueue===null&&(n.baseState=i),s.lastRenderedState=i}return[i,r]}function P1(){}function M1(e,n){var s=Vt,r=qs(),a=n(),i=!hr(r.memoizedState,a);if(i&&(r.memoizedState=a,is=!0),r=r.queue,Lj(L1.bind(null,s,r,e),[e]),r.getSnapshot!==n||i||Nn!==null&&Nn.memoizedState.tag&1){if(s.flags|=2048,zc(9,D1.bind(null,s,r,a,n),void 0,null),En===null)throw Error(Ee(349));Fi&30||O1(s,n,a)}return a}function O1(e,n,s){e.flags|=16384,e={getSnapshot:n,value:s},n=Vt.updateQueue,n===null?(n={lastEffect:null,stores:null},Vt.updateQueue=n,n.stores=[e]):(s=n.stores,s===null?n.stores=[e]:s.push(e))}function D1(e,n,s,r){n.value=s,n.getSnapshot=r,F1(n)&&_1(e)}function L1(e,n,s){return s(function(){F1(n)&&_1(e)})}function F1(e){var n=e.getSnapshot;e=e.value;try{var s=n();return!hr(e,s)}catch{return!0}}function _1(e){var n=ma(e,1);n!==null&&cr(n,e,1,-1)}function Ck(e){var n=Sr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:_c,lastRenderedState:e},n.queue=e,e=e.dispatch=iD.bind(null,Vt,e),[n.memoizedState,e]}function zc(e,n,s,r){return e={tag:e,create:n,destroy:s,deps:r,next:null},n=Vt.updateQueue,n===null?(n={lastEffect:null,stores:null},Vt.updateQueue=n,n.lastEffect=e.next=e):(s=n.lastEffect,s===null?n.lastEffect=e.next=e:(r=s.next,s.next=e,e.next=r,n.lastEffect=e)),e}function z1(){return qs().memoizedState}function Fd(e,n,s,r){var a=Sr();Vt.flags|=e,a.memoizedState=zc(1|n,s,void 0,r===void 0?null:r)}function Nf(e,n,s,r){var a=qs();r=r===void 0?null:r;var i=void 0;if(pn!==null){var l=pn.memoizedState;if(i=l.destroy,r!==null&&Mj(r,l.deps)){a.memoizedState=zc(n,s,i,r);return}}Vt.flags|=e,a.memoizedState=zc(1|n,s,i,r)}function Ek(e,n){return Fd(8390656,8,e,n)}function Lj(e,n){return Nf(2048,8,e,n)}function U1(e,n){return Nf(4,2,e,n)}function B1(e,n){return Nf(4,4,e,n)}function W1(e,n){if(typeof n=="function")return e=e(),n(e),function(){n(null)};if(n!=null)return e=e(),n.current=e,function(){n.current=null}}function H1(e,n,s){return s=s!=null?s.concat([e]):null,Nf(4,4,W1.bind(null,n,e),s)}function Fj(){}function K1(e,n){var s=qs();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&Mj(n,r[1])?r[0]:(s.memoizedState=[e,n],e)}function V1(e,n){var s=qs();n=n===void 0?null:n;var r=s.memoizedState;return r!==null&&n!==null&&Mj(n,r[1])?r[0]:(e=e(),s.memoizedState=[e,n],e)}function G1(e,n,s){return Fi&21?(hr(s,n)||(s=XC(),Vt.lanes|=s,_i|=s,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,is=!0),e.memoizedState=s)}function rD(e,n){var s=Nt;Nt=s!==0&&4>s?s:4,e(!0);var r=ep.transition;ep.transition={};try{e(!1),n()}finally{Nt=s,ep.transition=r}}function Y1(){return qs().memoizedState}function aD(e,n,s){var r=Ka(e);if(s={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null},q1(e))Q1(n,s);else if(s=T1(e,n,s,r),s!==null){var a=Xn();cr(s,e,r,a),J1(s,n,r)}}function iD(e,n,s){var r=Ka(e),a={lane:r,action:s,hasEagerState:!1,eagerState:null,next:null};if(q1(e))Q1(n,a);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=n.lastRenderedReducer,i!==null))try{var l=n.lastRenderedState,o=i(l,s);if(a.hasEagerState=!0,a.eagerState=o,hr(o,l)){var c=n.interleaved;c===null?(a.next=a,Aj(n)):(a.next=c.next,c.next=a),n.interleaved=a;return}}catch{}finally{}s=T1(e,n,a,r),s!==null&&(a=Xn(),cr(s,e,r,a),J1(s,n,r))}}function q1(e){var n=e.alternate;return e===Vt||n!==null&&n===Vt}function Q1(e,n){hc=bh=!0;var s=e.pending;s===null?n.next=n:(n.next=s.next,s.next=n),e.pending=n}function J1(e,n,s){if(s&4194240){var r=n.lanes;r&=e.pendingLanes,s|=r,n.lanes=s,pj(e,s)}}var kh={readContext:Ys,useCallback:Fn,useContext:Fn,useEffect:Fn,useImperativeHandle:Fn,useInsertionEffect:Fn,useLayoutEffect:Fn,useMemo:Fn,useReducer:Fn,useRef:Fn,useState:Fn,useDebugValue:Fn,useDeferredValue:Fn,useTransition:Fn,useMutableSource:Fn,useSyncExternalStore:Fn,useId:Fn,unstable_isNewReconciler:!1},lD={readContext:Ys,useCallback:function(e,n){return Sr().memoizedState=[e,n===void 0?null:n],e},useContext:Ys,useEffect:Ek,useImperativeHandle:function(e,n,s){return s=s!=null?s.concat([e]):null,Fd(4194308,4,W1.bind(null,n,e),s)},useLayoutEffect:function(e,n){return Fd(4194308,4,e,n)},useInsertionEffect:function(e,n){return Fd(4,2,e,n)},useMemo:function(e,n){var s=Sr();return n=n===void 0?null:n,e=e(),s.memoizedState=[e,n],e},useReducer:function(e,n,s){var r=Sr();return n=s!==void 0?s(n):n,r.memoizedState=r.baseState=n,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:n},r.queue=e,e=e.dispatch=aD.bind(null,Vt,e),[r.memoizedState,e]},useRef:function(e){var n=Sr();return e={current:e},n.memoizedState=e},useState:Ck,useDebugValue:Fj,useDeferredValue:function(e){return Sr().memoizedState=e},useTransition:function(){var e=Ck(!1),n=e[0];return e=rD.bind(null,e[1]),Sr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,s){var r=Vt,a=Sr();if(Wt){if(s===void 0)throw Error(Ee(407));s=s()}else{if(s=n(),En===null)throw Error(Ee(349));Fi&30||O1(r,n,s)}a.memoizedState=s;var i={value:s,getSnapshot:n};return a.queue=i,Ek(L1.bind(null,r,i,e),[e]),r.flags|=2048,zc(9,D1.bind(null,r,i,s,n),void 0,null),s},useId:function(){var e=Sr(),n=En.identifierPrefix;if(Wt){var s=ia,r=aa;s=(r&~(1<<32-or(r)-1)).toString(32)+s,n=":"+n+"R"+s,s=Fc++,0<s&&(n+="H"+s.toString(32)),n+=":"}else s=sD++,n=":"+n+"r"+s.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},oD={readContext:Ys,useCallback:K1,useContext:Ys,useEffect:Lj,useImperativeHandle:H1,useInsertionEffect:U1,useLayoutEffect:B1,useMemo:V1,useReducer:tp,useRef:z1,useState:function(){return tp(_c)},useDebugValue:Fj,useDeferredValue:function(e){var n=qs();return G1(n,pn.memoizedState,e)},useTransition:function(){var e=tp(_c)[0],n=qs().memoizedState;return[e,n]},useMutableSource:P1,useSyncExternalStore:M1,useId:Y1,unstable_isNewReconciler:!1},cD={readContext:Ys,useCallback:K1,useContext:Ys,useEffect:Lj,useImperativeHandle:H1,useInsertionEffect:U1,useLayoutEffect:B1,useMemo:V1,useReducer:np,useRef:z1,useState:function(){return np(_c)},useDebugValue:Fj,useDeferredValue:function(e){var n=qs();return pn===null?n.memoizedState=e:G1(n,pn.memoizedState,e)},useTransition:function(){var e=np(_c)[0],n=qs().memoizedState;return[e,n]},useMutableSource:P1,useSyncExternalStore:M1,useId:Y1,unstable_isNewReconciler:!1};function tr(e,n){if(e&&e.defaultProps){n=Yt({},n),e=e.defaultProps;for(var s in e)n[s]===void 0&&(n[s]=e[s]);return n}return n}function Gg(e,n,s,r){n=e.memoizedState,s=s(r,n),s=s==null?n:Yt({},n,s),e.memoizedState=s,e.lanes===0&&(e.updateQueue.baseState=s)}var Sf={isMounted:function(e){return(e=e._reactInternals)?qi(e)===e:!1},enqueueSetState:function(e,n,s){e=e._reactInternals;var r=Xn(),a=Ka(e),i=oa(r,a);i.payload=n,s!=null&&(i.callback=s),n=Wa(e,i,a),n!==null&&(cr(n,e,a,r),Dd(n,e,a))},enqueueReplaceState:function(e,n,s){e=e._reactInternals;var r=Xn(),a=Ka(e),i=oa(r,a);i.tag=1,i.payload=n,s!=null&&(i.callback=s),n=Wa(e,i,a),n!==null&&(cr(n,e,a,r),Dd(n,e,a))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var s=Xn(),r=Ka(e),a=oa(s,r);a.tag=2,n!=null&&(a.callback=n),n=Wa(e,a,r),n!==null&&(cr(n,e,r,s),Dd(n,e,r))}};function $k(e,n,s,r,a,i,l){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,i,l):n.prototype&&n.prototype.isPureReactComponent?!Ic(s,r)||!Ic(a,i):!0}function X1(e,n,s){var r=!1,a=Ja,i=n.contextType;return typeof i=="object"&&i!==null?i=Ys(i):(a=cs(n)?Di:Wn.current,r=n.contextTypes,i=(r=r!=null)?Yl(e,a):Ja),n=new n(s,i),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Sf,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=a,e.__reactInternalMemoizedMaskedChildContext=i),n}function Ak(e,n,s,r){e=n.state,typeof n.componentWillReceiveProps=="function"&&n.componentWillReceiveProps(s,r),typeof n.UNSAFE_componentWillReceiveProps=="function"&&n.UNSAFE_componentWillReceiveProps(s,r),n.state!==e&&Sf.enqueueReplaceState(n,n.state,null)}function Yg(e,n,s,r){var a=e.stateNode;a.props=s,a.state=e.memoizedState,a.refs={},Tj(e);var i=n.contextType;typeof i=="object"&&i!==null?a.context=Ys(i):(i=cs(n)?Di:Wn.current,a.context=Yl(e,i)),a.state=e.memoizedState,i=n.getDerivedStateFromProps,typeof i=="function"&&(Gg(e,n,i,s),a.state=e.memoizedState),typeof n.getDerivedStateFromProps=="function"||typeof a.getSnapshotBeforeUpdate=="function"||typeof a.UNSAFE_componentWillMount!="function"&&typeof a.componentWillMount!="function"||(n=a.state,typeof a.componentWillMount=="function"&&a.componentWillMount(),typeof a.UNSAFE_componentWillMount=="function"&&a.UNSAFE_componentWillMount(),n!==a.state&&Sf.enqueueReplaceState(a,a.state,null),wh(e,s,a,r),a.state=e.memoizedState),typeof a.componentDidMount=="function"&&(e.flags|=4194308)}function Xl(e,n){try{var s="",r=n;do s+=L2(r),r=r.return;while(r);var a=s}catch(i){a=`
|
|
39
|
-
Error generating stack: `+i.message+`
|
|
40
|
-
`+i.stack}return{value:e,source:n,stack:a,digest:null}}function sp(e,n,s){return{value:e,source:null,stack:s??null,digest:n??null}}function qg(e,n){try{console.error(n.value)}catch(s){setTimeout(function(){throw s})}}var uD=typeof WeakMap=="function"?WeakMap:Map;function Z1(e,n,s){s=oa(-1,s),s.tag=3,s.payload={element:null};var r=n.value;return s.callback=function(){Sh||(Sh=!0,ax=r),qg(e,n)},s}function eE(e,n,s){s=oa(-1,s),s.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var a=n.value;s.payload=function(){return r(a)},s.callback=function(){qg(e,n)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(s.callback=function(){qg(e,n),typeof r!="function"&&(Ha===null?Ha=new Set([this]):Ha.add(this));var l=n.stack;this.componentDidCatch(n.value,{componentStack:l!==null?l:""})}),s}function Tk(e,n,s){var r=e.pingCache;if(r===null){r=e.pingCache=new uD;var a=new Set;r.set(n,a)}else a=r.get(n),a===void 0&&(a=new Set,r.set(n,a));a.has(s)||(a.add(s),e=ND.bind(null,e,n,s),n.then(e,e))}function Rk(e){do{var n;if((n=e.tag===13)&&(n=e.memoizedState,n=n!==null?n.dehydrated!==null:!0),n)return e;e=e.return}while(e!==null);return null}function Ik(e,n,s,r,a){return e.mode&1?(e.flags|=65536,e.lanes=a,e):(e===n?e.flags|=65536:(e.flags|=128,s.flags|=131072,s.flags&=-52805,s.tag===1&&(s.alternate===null?s.tag=17:(n=oa(-1,1),n.tag=2,Wa(s,n,1))),s.lanes|=1),e)}var dD=ja.ReactCurrentOwner,is=!1;function qn(e,n,s,r){n.child=e===null?A1(n,null,s,r):Ql(n,e.child,s,r)}function Pk(e,n,s,r,a){s=s.render;var i=n.ref;return _l(n,a),r=Oj(e,n,s,r,i,a),s=Dj(),e!==null&&!is?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,pa(e,n,a)):(Wt&&s&&kj(n),n.flags|=1,qn(e,n,r,a),n.child)}function Mk(e,n,s,r,a){if(e===null){var i=s.type;return typeof i=="function"&&!Vj(i)&&i.defaultProps===void 0&&s.compare===null&&s.defaultProps===void 0?(n.tag=15,n.type=i,tE(e,n,i,r,a)):(e=Bd(s.type,null,r,n,n.mode,a),e.ref=n.ref,e.return=n,n.child=e)}if(i=e.child,!(e.lanes&a)){var l=i.memoizedProps;if(s=s.compare,s=s!==null?s:Ic,s(l,r)&&e.ref===n.ref)return pa(e,n,a)}return n.flags|=1,e=Va(i,r),e.ref=n.ref,e.return=n,n.child=e}function tE(e,n,s,r,a){if(e!==null){var i=e.memoizedProps;if(Ic(i,r)&&e.ref===n.ref)if(is=!1,n.pendingProps=r=i,(e.lanes&a)!==0)e.flags&131072&&(is=!0);else return n.lanes=e.lanes,pa(e,n,a)}return Qg(e,n,s,r,a)}function nE(e,n,s){var r=n.pendingProps,a=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Mt(Tl,js),js|=s;else{if(!(s&1073741824))return e=i!==null?i.baseLanes|s:s,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Mt(Tl,js),js|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:s,Mt(Tl,js),js|=r}else i!==null?(r=i.baseLanes|s,n.memoizedState=null):r=s,Mt(Tl,js),js|=r;return qn(e,n,a,s),n.child}function sE(e,n){var s=n.ref;(e===null&&s!==null||e!==null&&e.ref!==s)&&(n.flags|=512,n.flags|=2097152)}function Qg(e,n,s,r,a){var i=cs(s)?Di:Wn.current;return i=Yl(n,i),_l(n,a),s=Oj(e,n,s,r,i,a),r=Dj(),e!==null&&!is?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~a,pa(e,n,a)):(Wt&&r&&kj(n),n.flags|=1,qn(e,n,s,a),n.child)}function Ok(e,n,s,r,a){if(cs(s)){var i=!0;ph(n)}else i=!1;if(_l(n,a),n.stateNode===null)_d(e,n),X1(n,s,r),Yg(n,s,r,a),r=!0;else if(e===null){var l=n.stateNode,o=n.memoizedProps;l.props=o;var c=l.context,u=s.contextType;typeof u=="object"&&u!==null?u=Ys(u):(u=cs(s)?Di:Wn.current,u=Yl(n,u));var h=s.getDerivedStateFromProps,f=typeof h=="function"||typeof l.getSnapshotBeforeUpdate=="function";f||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==r||c!==u)&&Ak(n,l,r,u),Ia=!1;var m=n.memoizedState;l.state=m,wh(n,r,l,a),c=n.memoizedState,o!==r||m!==c||os.current||Ia?(typeof h=="function"&&(Gg(n,s,h,r),c=n.memoizedState),(o=Ia||$k(n,s,o,r,m,c,u))?(f||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"&&(n.flags|=4194308)):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),l.props=r,l.state=c,l.context=u,r=o):(typeof l.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{l=n.stateNode,R1(e,n),o=n.memoizedProps,u=n.type===n.elementType?o:tr(n.type,o),l.props=u,f=n.pendingProps,m=l.context,c=s.contextType,typeof c=="object"&&c!==null?c=Ys(c):(c=cs(s)?Di:Wn.current,c=Yl(n,c));var p=s.getDerivedStateFromProps;(h=typeof p=="function"||typeof l.getSnapshotBeforeUpdate=="function")||typeof l.UNSAFE_componentWillReceiveProps!="function"&&typeof l.componentWillReceiveProps!="function"||(o!==f||m!==c)&&Ak(n,l,r,c),Ia=!1,m=n.memoizedState,l.state=m,wh(n,r,l,a);var g=n.memoizedState;o!==f||m!==g||os.current||Ia?(typeof p=="function"&&(Gg(n,s,p,r),g=n.memoizedState),(u=Ia||$k(n,s,u,r,m,g,c)||!1)?(h||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"&&(n.flags|=4),typeof l.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=g),l.props=r,l.state=g,l.context=c,r=u):(typeof l.componentDidUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=4),typeof l.getSnapshotBeforeUpdate!="function"||o===e.memoizedProps&&m===e.memoizedState||(n.flags|=1024),r=!1)}return Jg(e,n,s,r,i,a)}function Jg(e,n,s,r,a,i){sE(e,n);var l=(n.flags&128)!==0;if(!r&&!l)return a&&wk(n,s,!1),pa(e,n,i);r=n.stateNode,dD.current=n;var o=l&&typeof s.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&l?(n.child=Ql(n,e.child,null,i),n.child=Ql(n,null,o,i)):qn(e,n,o,i),n.memoizedState=r.state,a&&wk(n,s,!0),n.child}function rE(e){var n=e.stateNode;n.pendingContext?jk(e,n.pendingContext,n.pendingContext!==n.context):n.context&&jk(e,n.context,!1),Rj(e,n.containerInfo)}function Dk(e,n,s,r,a){return ql(),Sj(a),n.flags|=256,qn(e,n,s,r),n.child}var Xg={dehydrated:null,treeContext:null,retryLane:0};function Zg(e){return{baseLanes:e,cachePool:null,transitions:null}}function aE(e,n,s){var r=n.pendingProps,a=Kt.current,i=!1,l=(n.flags&128)!==0,o;if((o=l)||(o=e!==null&&e.memoizedState===null?!1:(a&2)!==0),o?(i=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(a|=1),Mt(Kt,a&1),e===null)return Kg(n),e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(n.mode&1?e.data==="$!"?n.lanes=8:n.lanes=1073741824:n.lanes=1,null):(l=r.children,e=r.fallback,i?(r=n.mode,i=n.child,l={mode:"hidden",children:l},!(r&1)&&i!==null?(i.childLanes=0,i.pendingProps=l):i=$f(l,r,0,null),e=Ii(e,r,s,null),i.return=n,e.return=n,i.sibling=e,n.child=i,n.child.memoizedState=Zg(s),n.memoizedState=Xg,e):_j(n,l));if(a=e.memoizedState,a!==null&&(o=a.dehydrated,o!==null))return hD(e,n,l,r,o,a,s);if(i){i=r.fallback,l=n.mode,a=e.child,o=a.sibling;var c={mode:"hidden",children:r.children};return!(l&1)&&n.child!==a?(r=n.child,r.childLanes=0,r.pendingProps=c,n.deletions=null):(r=Va(a,c),r.subtreeFlags=a.subtreeFlags&14680064),o!==null?i=Va(o,i):(i=Ii(i,l,s,null),i.flags|=2),i.return=n,r.return=n,r.sibling=i,n.child=r,r=i,i=n.child,l=e.child.memoizedState,l=l===null?Zg(s):{baseLanes:l.baseLanes|s,cachePool:null,transitions:l.transitions},i.memoizedState=l,i.childLanes=e.childLanes&~s,n.memoizedState=Xg,r}return i=e.child,e=i.sibling,r=Va(i,{mode:"visible",children:r.children}),!(n.mode&1)&&(r.lanes=s),r.return=n,r.sibling=null,e!==null&&(s=n.deletions,s===null?(n.deletions=[e],n.flags|=16):s.push(e)),n.child=r,n.memoizedState=null,r}function _j(e,n){return n=$f({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Zu(e,n,s,r){return r!==null&&Sj(r),Ql(n,e.child,null,s),e=_j(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function hD(e,n,s,r,a,i,l){if(s)return n.flags&256?(n.flags&=-257,r=sp(Error(Ee(422))),Zu(e,n,l,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(i=r.fallback,a=n.mode,r=$f({mode:"visible",children:r.children},a,0,null),i=Ii(i,a,l,null),i.flags|=2,r.return=n,i.return=n,r.sibling=i,n.child=r,n.mode&1&&Ql(n,e.child,null,l),n.child.memoizedState=Zg(l),n.memoizedState=Xg,i);if(!(n.mode&1))return Zu(e,n,l,null);if(a.data==="$!"){if(r=a.nextSibling&&a.nextSibling.dataset,r)var o=r.dgst;return r=o,i=Error(Ee(419)),r=sp(i,r,void 0),Zu(e,n,l,r)}if(o=(l&e.childLanes)!==0,is||o){if(r=En,r!==null){switch(l&-l){case 4:a=2;break;case 16:a=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:a=32;break;case 536870912:a=268435456;break;default:a=0}a=a&(r.suspendedLanes|l)?0:a,a!==0&&a!==i.retryLane&&(i.retryLane=a,ma(e,a),cr(r,e,a,-1))}return Kj(),r=sp(Error(Ee(421))),Zu(e,n,l,r)}return a.data==="$?"?(n.flags|=128,n.child=e.child,n=SD.bind(null,e),a._reactRetry=n,null):(e=i.treeContext,ys=Ba(a.nextSibling),ks=n,Wt=!0,sr=null,e!==null&&(zs[Us++]=aa,zs[Us++]=ia,zs[Us++]=Li,aa=e.id,ia=e.overflow,Li=n),n=_j(n,r.children),n.flags|=4096,n)}function Lk(e,n,s){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),Vg(e.return,n,s)}function rp(e,n,s,r,a){var i=e.memoizedState;i===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:s,tailMode:a}:(i.isBackwards=n,i.rendering=null,i.renderingStartTime=0,i.last=r,i.tail=s,i.tailMode=a)}function iE(e,n,s){var r=n.pendingProps,a=r.revealOrder,i=r.tail;if(qn(e,n,r.children,s),r=Kt.current,r&2)r=r&1|2,n.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&Lk(e,s,n);else if(e.tag===19)Lk(e,s,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Mt(Kt,r),!(n.mode&1))n.memoizedState=null;else switch(a){case"forwards":for(s=n.child,a=null;s!==null;)e=s.alternate,e!==null&&yh(e)===null&&(a=s),s=s.sibling;s=a,s===null?(a=n.child,n.child=null):(a=s.sibling,s.sibling=null),rp(n,!1,a,s,i);break;case"backwards":for(s=null,a=n.child,n.child=null;a!==null;){if(e=a.alternate,e!==null&&yh(e)===null){n.child=a;break}e=a.sibling,a.sibling=s,s=a,a=e}rp(n,!0,s,null,i);break;case"together":rp(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function _d(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function pa(e,n,s){if(e!==null&&(n.dependencies=e.dependencies),_i|=n.lanes,!(s&n.childLanes))return null;if(e!==null&&n.child!==e.child)throw Error(Ee(153));if(n.child!==null){for(e=n.child,s=Va(e,e.pendingProps),n.child=s,s.return=n;e.sibling!==null;)e=e.sibling,s=s.sibling=Va(e,e.pendingProps),s.return=n;s.sibling=null}return n.child}function fD(e,n,s){switch(n.tag){case 3:rE(n),ql();break;case 5:I1(n);break;case 1:cs(n.type)&&ph(n);break;case 4:Rj(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,a=n.memoizedProps.value;Mt(vh,r._currentValue),r._currentValue=a;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Mt(Kt,Kt.current&1),n.flags|=128,null):s&n.child.childLanes?aE(e,n,s):(Mt(Kt,Kt.current&1),e=pa(e,n,s),e!==null?e.sibling:null);Mt(Kt,Kt.current&1);break;case 19:if(r=(s&n.childLanes)!==0,e.flags&128){if(r)return iE(e,n,s);n.flags|=128}if(a=n.memoizedState,a!==null&&(a.rendering=null,a.tail=null,a.lastEffect=null),Mt(Kt,Kt.current),r)break;return null;case 22:case 23:return n.lanes=0,nE(e,n,s)}return pa(e,n,s)}var lE,ex,oE,cE;lE=function(e,n){for(var s=n.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===n)break;for(;s.sibling===null;){if(s.return===null||s.return===n)return;s=s.return}s.sibling.return=s.return,s=s.sibling}};ex=function(){};oE=function(e,n,s,r){var a=e.memoizedProps;if(a!==r){e=n.stateNode,Ei(Ir.current);var i=null;switch(s){case"input":a=bg(e,a),r=bg(e,r),i=[];break;case"select":a=Yt({},a,{value:void 0}),r=Yt({},r,{value:void 0}),i=[];break;case"textarea":a=Sg(e,a),r=Sg(e,r),i=[];break;default:typeof a.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=fh)}Eg(s,r);var l;s=null;for(u in a)if(!r.hasOwnProperty(u)&&a.hasOwnProperty(u)&&a[u]!=null)if(u==="style"){var o=a[u];for(l in o)o.hasOwnProperty(l)&&(s||(s={}),s[l]="")}else u!=="dangerouslySetInnerHTML"&&u!=="children"&&u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&u!=="autoFocus"&&(Sc.hasOwnProperty(u)?i||(i=[]):(i=i||[]).push(u,null));for(u in r){var c=r[u];if(o=a!=null?a[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||(i||(i=[]),i.push(u,s)),s=c;else u==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,o=o?o.__html:void 0,c!=null&&o!==c&&(i=i||[]).push(u,c)):u==="children"?typeof c!="string"&&typeof c!="number"||(i=i||[]).push(u,""+c):u!=="suppressContentEditableWarning"&&u!=="suppressHydrationWarning"&&(Sc.hasOwnProperty(u)?(c!=null&&u==="onScroll"&&Lt("scroll",e),i||o===c||(i=[])):(i=i||[]).push(u,c))}s&&(i=i||[]).push("style",s);var u=i;(n.updateQueue=u)&&(n.flags|=4)}};cE=function(e,n,s,r){s!==r&&(n.flags|=4)};function Wo(e,n){if(!Wt)switch(e.tailMode){case"hidden":n=e.tail;for(var s=null;n!==null;)n.alternate!==null&&(s=n),n=n.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?n||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function _n(e){var n=e.alternate!==null&&e.alternate.child===e.child,s=0,r=0;if(n)for(var a=e.child;a!==null;)s|=a.lanes|a.childLanes,r|=a.subtreeFlags&14680064,r|=a.flags&14680064,a.return=e,a=a.sibling;else for(a=e.child;a!==null;)s|=a.lanes|a.childLanes,r|=a.subtreeFlags,r|=a.flags,a.return=e,a=a.sibling;return e.subtreeFlags|=r,e.childLanes=s,n}function mD(e,n,s){var r=n.pendingProps;switch(Nj(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return _n(n),null;case 1:return cs(n.type)&&mh(),_n(n),null;case 3:return r=n.stateNode,Jl(),_t(os),_t(Wn),Pj(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Ju(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,sr!==null&&(ox(sr),sr=null))),ex(e,n),_n(n),null;case 5:Ij(n);var a=Ei(Lc.current);if(s=n.type,e!==null&&n.stateNode!=null)oE(e,n,s,r,a),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!r){if(n.stateNode===null)throw Error(Ee(166));return _n(n),null}if(e=Ei(Ir.current),Ju(n)){r=n.stateNode,s=n.type;var i=n.memoizedProps;switch(r[Er]=n,r[Oc]=i,e=(n.mode&1)!==0,s){case"dialog":Lt("cancel",r),Lt("close",r);break;case"iframe":case"object":case"embed":Lt("load",r);break;case"video":case"audio":for(a=0;a<tc.length;a++)Lt(tc[a],r);break;case"source":Lt("error",r);break;case"img":case"image":case"link":Lt("error",r),Lt("load",r);break;case"details":Lt("toggle",r);break;case"input":Vb(r,i),Lt("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!i.multiple},Lt("invalid",r);break;case"textarea":Yb(r,i),Lt("invalid",r)}Eg(s,i),a=null;for(var l in i)if(i.hasOwnProperty(l)){var o=i[l];l==="children"?typeof o=="string"?r.textContent!==o&&(i.suppressHydrationWarning!==!0&&Qu(r.textContent,o,e),a=["children",o]):typeof o=="number"&&r.textContent!==""+o&&(i.suppressHydrationWarning!==!0&&Qu(r.textContent,o,e),a=["children",""+o]):Sc.hasOwnProperty(l)&&o!=null&&l==="onScroll"&&Lt("scroll",r)}switch(s){case"input":Bu(r),Gb(r,i,!0);break;case"textarea":Bu(r),qb(r);break;case"select":case"option":break;default:typeof i.onClick=="function"&&(r.onclick=fh)}r=a,n.updateQueue=r,r!==null&&(n.flags|=4)}else{l=a.nodeType===9?a:a.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=LC(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[Er]=n,e[Oc]=r,lE(e,n,!1,!1),n.stateNode=e;e:{switch(l=$g(s,r),s){case"dialog":Lt("cancel",e),Lt("close",e),a=r;break;case"iframe":case"object":case"embed":Lt("load",e),a=r;break;case"video":case"audio":for(a=0;a<tc.length;a++)Lt(tc[a],e);a=r;break;case"source":Lt("error",e),a=r;break;case"img":case"image":case"link":Lt("error",e),Lt("load",e),a=r;break;case"details":Lt("toggle",e),a=r;break;case"input":Vb(e,r),a=bg(e,r),Lt("invalid",e);break;case"option":a=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},a=Yt({},r,{value:void 0}),Lt("invalid",e);break;case"textarea":Yb(e,r),a=Sg(e,r),Lt("invalid",e);break;default:a=r}Eg(s,a),o=a;for(i in o)if(o.hasOwnProperty(i)){var c=o[i];i==="style"?zC(e,c):i==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&FC(e,c)):i==="children"?typeof c=="string"?(s!=="textarea"||c!=="")&&Cc(e,c):typeof c=="number"&&Cc(e,""+c):i!=="suppressContentEditableWarning"&&i!=="suppressHydrationWarning"&&i!=="autoFocus"&&(Sc.hasOwnProperty(i)?c!=null&&i==="onScroll"&&Lt("scroll",e):c!=null&&cj(e,i,c,l))}switch(s){case"input":Bu(e),Gb(e,r,!1);break;case"textarea":Bu(e),qb(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Qa(r.value));break;case"select":e.multiple=!!r.multiple,i=r.value,i!=null?Ol(e,!!r.multiple,i,!1):r.defaultValue!=null&&Ol(e,!!r.multiple,r.defaultValue,!0);break;default:typeof a.onClick=="function"&&(e.onclick=fh)}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&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return _n(n),null;case 6:if(e&&n.stateNode!=null)cE(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(Ee(166));if(s=Ei(Lc.current),Ei(Ir.current),Ju(n)){if(r=n.stateNode,s=n.memoizedProps,r[Er]=n,(i=r.nodeValue!==s)&&(e=ks,e!==null))switch(e.tag){case 3:Qu(r.nodeValue,s,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Qu(r.nodeValue,s,(e.mode&1)!==0)}i&&(n.flags|=4)}else r=(s.nodeType===9?s:s.ownerDocument).createTextNode(r),r[Er]=n,n.stateNode=r}return _n(n),null;case 13:if(_t(Kt),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Wt&&ys!==null&&n.mode&1&&!(n.flags&128))E1(),ql(),n.flags|=98560,i=!1;else if(i=Ju(n),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(Ee(318));if(i=n.memoizedState,i=i!==null?i.dehydrated:null,!i)throw Error(Ee(317));i[Er]=n}else ql(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;_n(n),i=!1}else sr!==null&&(ox(sr),sr=null),i=!0;if(!i)return n.flags&65536?n:null}return n.flags&128?(n.lanes=s,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||Kt.current&1?vn===0&&(vn=3):Kj())),n.updateQueue!==null&&(n.flags|=4),_n(n),null);case 4:return Jl(),ex(e,n),e===null&&Pc(n.stateNode.containerInfo),_n(n),null;case 10:return $j(n.type._context),_n(n),null;case 17:return cs(n.type)&&mh(),_n(n),null;case 19:if(_t(Kt),i=n.memoizedState,i===null)return _n(n),null;if(r=(n.flags&128)!==0,l=i.rendering,l===null)if(r)Wo(i,!1);else{if(vn!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(l=yh(e),l!==null){for(n.flags|=128,Wo(i,!1),r=l.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=s,s=n.child;s!==null;)i=s,e=r,i.flags&=14680066,l=i.alternate,l===null?(i.childLanes=0,i.lanes=e,i.child=null,i.subtreeFlags=0,i.memoizedProps=null,i.memoizedState=null,i.updateQueue=null,i.dependencies=null,i.stateNode=null):(i.childLanes=l.childLanes,i.lanes=l.lanes,i.child=l.child,i.subtreeFlags=0,i.deletions=null,i.memoizedProps=l.memoizedProps,i.memoizedState=l.memoizedState,i.updateQueue=l.updateQueue,i.type=l.type,e=l.dependencies,i.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),s=s.sibling;return Mt(Kt,Kt.current&1|2),n.child}e=e.sibling}i.tail!==null&&sn()>Zl&&(n.flags|=128,r=!0,Wo(i,!1),n.lanes=4194304)}else{if(!r)if(e=yh(l),e!==null){if(n.flags|=128,r=!0,s=e.updateQueue,s!==null&&(n.updateQueue=s,n.flags|=4),Wo(i,!0),i.tail===null&&i.tailMode==="hidden"&&!l.alternate&&!Wt)return _n(n),null}else 2*sn()-i.renderingStartTime>Zl&&s!==1073741824&&(n.flags|=128,r=!0,Wo(i,!1),n.lanes=4194304);i.isBackwards?(l.sibling=n.child,n.child=l):(s=i.last,s!==null?s.sibling=l:n.child=l,i.last=l)}return i.tail!==null?(n=i.tail,i.rendering=n,i.tail=n.sibling,i.renderingStartTime=sn(),n.sibling=null,s=Kt.current,Mt(Kt,r?s&1|2:s&1),n):(_n(n),null);case 22:case 23:return Hj(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?js&1073741824&&(_n(n),n.subtreeFlags&6&&(n.flags|=8192)):_n(n),null;case 24:return null;case 25:return null}throw Error(Ee(156,n.tag))}function pD(e,n){switch(Nj(n),n.tag){case 1:return cs(n.type)&&mh(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Jl(),_t(os),_t(Wn),Pj(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return Ij(n),null;case 13:if(_t(Kt),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(Ee(340));ql()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return _t(Kt),null;case 4:return Jl(),null;case 10:return $j(n.type._context),null;case 22:case 23:return Hj(),null;case 24:return null;default:return null}}var ed=!1,Un=!1,gD=typeof WeakSet=="function"?WeakSet:Set,De=null;function Al(e,n){var s=e.ref;if(s!==null)if(typeof s=="function")try{s(null)}catch(r){Qt(e,n,r)}else s.current=null}function tx(e,n,s){try{s()}catch(r){Qt(e,n,r)}}var Fk=!1;function xD(e,n){if(Fg=uh,e=m1(),bj(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 a=r.anchorOffset,i=r.focusNode;r=r.focusOffset;try{s.nodeType,i.nodeType}catch{s=null;break e}var l=0,o=-1,c=-1,u=0,h=0,f=e,m=null;t:for(;;){for(var p;f!==s||a!==0&&f.nodeType!==3||(o=l+a),f!==i||r!==0&&f.nodeType!==3||(c=l+r),f.nodeType===3&&(l+=f.nodeValue.length),(p=f.firstChild)!==null;)m=f,f=p;for(;;){if(f===e)break t;if(m===s&&++u===a&&(o=l),m===i&&++h===r&&(c=l),(p=f.nextSibling)!==null)break;f=m,m=f.parentNode}f=p}s=o===-1||c===-1?null:{start:o,end:c}}else s=null}s=s||{start:0,end:0}}else s=null;for(_g={focusedElem:e,selectionRange:s},uh=!1,De=n;De!==null;)if(n=De,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,De=e;else for(;De!==null;){n=De;try{var g=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(g!==null){var x=g.memoizedProps,k=g.memoizedState,j=n.stateNode,v=j.getSnapshotBeforeUpdate(n.elementType===n.type?x:tr(n.type,x),k);j.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var w=n.stateNode.containerInfo;w.nodeType===1?w.textContent="":w.nodeType===9&&w.documentElement&&w.removeChild(w.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Ee(163))}}catch(y){Qt(n,n.return,y)}if(e=n.sibling,e!==null){e.return=n.return,De=e;break}De=n.return}return g=Fk,Fk=!1,g}function fc(e,n,s){var r=n.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var a=r=r.next;do{if((a.tag&e)===e){var i=a.destroy;a.destroy=void 0,i!==void 0&&tx(n,s,i)}a=a.next}while(a!==r)}}function Cf(e,n){if(n=n.updateQueue,n=n!==null?n.lastEffect:null,n!==null){var s=n=n.next;do{if((s.tag&e)===e){var r=s.create;s.destroy=r()}s=s.next}while(s!==n)}}function nx(e){var n=e.ref;if(n!==null){var s=e.stateNode;switch(e.tag){case 5:e=s;break;default:e=s}typeof n=="function"?n(e):n.current=e}}function uE(e){var n=e.alternate;n!==null&&(e.alternate=null,uE(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Er],delete n[Oc],delete n[Bg],delete n[ZO],delete n[eD])),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 dE(e){return e.tag===5||e.tag===3||e.tag===4}function _k(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||dE(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 sx(e,n,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?s.nodeType===8?s.parentNode.insertBefore(e,n):s.insertBefore(e,n):(s.nodeType===8?(n=s.parentNode,n.insertBefore(e,s)):(n=s,n.appendChild(e)),s=s._reactRootContainer,s!=null||n.onclick!==null||(n.onclick=fh));else if(r!==4&&(e=e.child,e!==null))for(sx(e,n,s),e=e.sibling;e!==null;)sx(e,n,s),e=e.sibling}function rx(e,n,s){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?s.insertBefore(e,n):s.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(rx(e,n,s),e=e.sibling;e!==null;)rx(e,n,s),e=e.sibling}var In=null,nr=!1;function $a(e,n,s){for(s=s.child;s!==null;)hE(e,n,s),s=s.sibling}function hE(e,n,s){if(Rr&&typeof Rr.onCommitFiberUnmount=="function")try{Rr.onCommitFiberUnmount(vf,s)}catch{}switch(s.tag){case 5:Un||Al(s,n);case 6:var r=In,a=nr;In=null,$a(e,n,s),In=r,nr=a,In!==null&&(nr?(e=In,s=s.stateNode,e.nodeType===8?e.parentNode.removeChild(s):e.removeChild(s)):In.removeChild(s.stateNode));break;case 18:In!==null&&(nr?(e=In,s=s.stateNode,e.nodeType===8?Jm(e.parentNode,s):e.nodeType===1&&Jm(e,s),Tc(e)):Jm(In,s.stateNode));break;case 4:r=In,a=nr,In=s.stateNode.containerInfo,nr=!0,$a(e,n,s),In=r,nr=a;break;case 0:case 11:case 14:case 15:if(!Un&&(r=s.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){a=r=r.next;do{var i=a,l=i.destroy;i=i.tag,l!==void 0&&(i&2||i&4)&&tx(s,n,l),a=a.next}while(a!==r)}$a(e,n,s);break;case 1:if(!Un&&(Al(s,n),r=s.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=s.memoizedProps,r.state=s.memoizedState,r.componentWillUnmount()}catch(o){Qt(s,n,o)}$a(e,n,s);break;case 21:$a(e,n,s);break;case 22:s.mode&1?(Un=(r=Un)||s.memoizedState!==null,$a(e,n,s),Un=r):$a(e,n,s);break;default:$a(e,n,s)}}function zk(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var s=e.stateNode;s===null&&(s=e.stateNode=new gD),n.forEach(function(r){var a=CD.bind(null,e,r);s.has(r)||(s.add(r),r.then(a,a))})}}function Zs(e,n){var s=n.deletions;if(s!==null)for(var r=0;r<s.length;r++){var a=s[r];try{var i=e,l=n,o=l;e:for(;o!==null;){switch(o.tag){case 5:In=o.stateNode,nr=!1;break e;case 3:In=o.stateNode.containerInfo,nr=!0;break e;case 4:In=o.stateNode.containerInfo,nr=!0;break e}o=o.return}if(In===null)throw Error(Ee(160));hE(i,l,a),In=null,nr=!1;var c=a.alternate;c!==null&&(c.return=null),a.return=null}catch(u){Qt(a,n,u)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)fE(n,e),n=n.sibling}function fE(e,n){var s=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Zs(n,e),br(e),r&4){try{fc(3,e,e.return),Cf(3,e)}catch(x){Qt(e,e.return,x)}try{fc(5,e,e.return)}catch(x){Qt(e,e.return,x)}}break;case 1:Zs(n,e),br(e),r&512&&s!==null&&Al(s,s.return);break;case 5:if(Zs(n,e),br(e),r&512&&s!==null&&Al(s,s.return),e.flags&32){var a=e.stateNode;try{Cc(a,"")}catch(x){Qt(e,e.return,x)}}if(r&4&&(a=e.stateNode,a!=null)){var i=e.memoizedProps,l=s!==null?s.memoizedProps:i,o=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{o==="input"&&i.type==="radio"&&i.name!=null&&OC(a,i),$g(o,l);var u=$g(o,i);for(l=0;l<c.length;l+=2){var h=c[l],f=c[l+1];h==="style"?zC(a,f):h==="dangerouslySetInnerHTML"?FC(a,f):h==="children"?Cc(a,f):cj(a,h,f,u)}switch(o){case"input":kg(a,i);break;case"textarea":DC(a,i);break;case"select":var m=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!i.multiple;var p=i.value;p!=null?Ol(a,!!i.multiple,p,!1):m!==!!i.multiple&&(i.defaultValue!=null?Ol(a,!!i.multiple,i.defaultValue,!0):Ol(a,!!i.multiple,i.multiple?[]:"",!1))}a[Oc]=i}catch(x){Qt(e,e.return,x)}}break;case 6:if(Zs(n,e),br(e),r&4){if(e.stateNode===null)throw Error(Ee(162));a=e.stateNode,i=e.memoizedProps;try{a.nodeValue=i}catch(x){Qt(e,e.return,x)}}break;case 3:if(Zs(n,e),br(e),r&4&&s!==null&&s.memoizedState.isDehydrated)try{Tc(n.containerInfo)}catch(x){Qt(e,e.return,x)}break;case 4:Zs(n,e),br(e);break;case 13:Zs(n,e),br(e),a=e.child,a.flags&8192&&(i=a.memoizedState!==null,a.stateNode.isHidden=i,!i||a.alternate!==null&&a.alternate.memoizedState!==null||(Bj=sn())),r&4&&zk(e);break;case 22:if(h=s!==null&&s.memoizedState!==null,e.mode&1?(Un=(u=Un)||h,Zs(n,e),Un=u):Zs(n,e),br(e),r&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!h&&e.mode&1)for(De=e,h=e.child;h!==null;){for(f=De=h;De!==null;){switch(m=De,p=m.child,m.tag){case 0:case 11:case 14:case 15:fc(4,m,m.return);break;case 1:Al(m,m.return);var g=m.stateNode;if(typeof g.componentWillUnmount=="function"){r=m,s=m.return;try{n=r,g.props=n.memoizedProps,g.state=n.memoizedState,g.componentWillUnmount()}catch(x){Qt(r,s,x)}}break;case 5:Al(m,m.return);break;case 22:if(m.memoizedState!==null){Bk(f);continue}}p!==null?(p.return=m,De=p):Bk(f)}h=h.sibling}e:for(h=null,f=e;;){if(f.tag===5){if(h===null){h=f;try{a=f.stateNode,u?(i=a.style,typeof i.setProperty=="function"?i.setProperty("display","none","important"):i.display="none"):(o=f.stateNode,c=f.memoizedProps.style,l=c!=null&&c.hasOwnProperty("display")?c.display:null,o.style.display=_C("display",l))}catch(x){Qt(e,e.return,x)}}}else if(f.tag===6){if(h===null)try{f.stateNode.nodeValue=u?"":f.memoizedProps}catch(x){Qt(e,e.return,x)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break e;for(;f.sibling===null;){if(f.return===null||f.return===e)break e;h===f&&(h=null),f=f.return}h===f&&(h=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:Zs(n,e),br(e),r&4&&zk(e);break;case 21:break;default:Zs(n,e),br(e)}}function br(e){var n=e.flags;if(n&2){try{e:{for(var s=e.return;s!==null;){if(dE(s)){var r=s;break e}s=s.return}throw Error(Ee(160))}switch(r.tag){case 5:var a=r.stateNode;r.flags&32&&(Cc(a,""),r.flags&=-33);var i=_k(e);rx(e,i,a);break;case 3:case 4:var l=r.stateNode.containerInfo,o=_k(e);sx(e,o,l);break;default:throw Error(Ee(161))}}catch(c){Qt(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function vD(e,n,s){De=e,mE(e)}function mE(e,n,s){for(var r=(e.mode&1)!==0;De!==null;){var a=De,i=a.child;if(a.tag===22&&r){var l=a.memoizedState!==null||ed;if(!l){var o=a.alternate,c=o!==null&&o.memoizedState!==null||Un;o=ed;var u=Un;if(ed=l,(Un=c)&&!u)for(De=a;De!==null;)l=De,c=l.child,l.tag===22&&l.memoizedState!==null?Wk(a):c!==null?(c.return=l,De=c):Wk(a);for(;i!==null;)De=i,mE(i),i=i.sibling;De=a,ed=o,Un=u}Uk(e)}else a.subtreeFlags&8772&&i!==null?(i.return=a,De=i):Uk(e)}}function Uk(e){for(;De!==null;){var n=De;if(n.flags&8772){var s=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:Un||Cf(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Un)if(s===null)r.componentDidMount();else{var a=n.elementType===n.type?s.memoizedProps:tr(n.type,s.memoizedProps);r.componentDidUpdate(a,s.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var i=n.updateQueue;i!==null&&Sk(n,i,r);break;case 3:var l=n.updateQueue;if(l!==null){if(s=null,n.child!==null)switch(n.child.tag){case 5:s=n.child.stateNode;break;case 1:s=n.child.stateNode}Sk(n,l,s)}break;case 5:var o=n.stateNode;if(s===null&&n.flags&4){s=o;var c=n.memoizedProps;switch(n.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(n.memoizedState===null){var u=n.alternate;if(u!==null){var h=u.memoizedState;if(h!==null){var f=h.dehydrated;f!==null&&Tc(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Ee(163))}Un||n.flags&512&&nx(n)}catch(m){Qt(n,n.return,m)}}if(n===e){De=null;break}if(s=n.sibling,s!==null){s.return=n.return,De=s;break}De=n.return}}function Bk(e){for(;De!==null;){var n=De;if(n===e){De=null;break}var s=n.sibling;if(s!==null){s.return=n.return,De=s;break}De=n.return}}function Wk(e){for(;De!==null;){var n=De;try{switch(n.tag){case 0:case 11:case 15:var s=n.return;try{Cf(4,n)}catch(c){Qt(n,s,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var a=n.return;try{r.componentDidMount()}catch(c){Qt(n,a,c)}}var i=n.return;try{nx(n)}catch(c){Qt(n,i,c)}break;case 5:var l=n.return;try{nx(n)}catch(c){Qt(n,l,c)}}}catch(c){Qt(n,n.return,c)}if(n===e){De=null;break}var o=n.sibling;if(o!==null){o.return=n.return,De=o;break}De=n.return}}var jD=Math.ceil,Nh=ja.ReactCurrentDispatcher,zj=ja.ReactCurrentOwner,Vs=ja.ReactCurrentBatchConfig,jt=0,En=null,cn=null,Pn=0,js=0,Tl=li(0),vn=0,Uc=null,_i=0,Ef=0,Uj=0,mc=null,as=null,Bj=0,Zl=1/0,Zr=null,Sh=!1,ax=null,Ha=null,td=!1,Da=null,Ch=0,pc=0,ix=null,zd=-1,Ud=0;function Xn(){return jt&6?sn():zd!==-1?zd:zd=sn()}function Ka(e){return e.mode&1?jt&2&&Pn!==0?Pn&-Pn:nD.transition!==null?(Ud===0&&(Ud=XC()),Ud):(e=Nt,e!==0||(e=window.event,e=e===void 0?16:a1(e.type)),e):1}function cr(e,n,s,r){if(50<pc)throw pc=0,ix=null,Error(Ee(185));mu(e,s,r),(!(jt&2)||e!==En)&&(e===En&&(!(jt&2)&&(Ef|=s),vn===4&&Ma(e,Pn)),us(e,r),s===1&&jt===0&&!(n.mode&1)&&(Zl=sn()+500,kf&&oi()))}function us(e,n){var s=e.callbackNode;nO(e,n);var r=ch(e,e===En?Pn:0);if(r===0)s!==null&&Xb(s),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(s!=null&&Xb(s),n===1)e.tag===0?tD(Hk.bind(null,e)):N1(Hk.bind(null,e)),JO(function(){!(jt&6)&&oi()}),s=null;else{switch(ZC(r)){case 1:s=mj;break;case 4:s=QC;break;case 16:s=oh;break;case 536870912:s=JC;break;default:s=oh}s=bE(s,pE.bind(null,e))}e.callbackPriority=n,e.callbackNode=s}}function pE(e,n){if(zd=-1,Ud=0,jt&6)throw Error(Ee(327));var s=e.callbackNode;if(zl()&&e.callbackNode!==s)return null;var r=ch(e,e===En?Pn:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=Eh(e,r);else{n=r;var a=jt;jt|=2;var i=xE();(En!==e||Pn!==n)&&(Zr=null,Zl=sn()+500,Ri(e,n));do try{bD();break}catch(o){gE(e,o)}while(!0);Ej(),Nh.current=i,jt=a,cn!==null?n=0:(En=null,Pn=0,n=vn)}if(n!==0){if(n===2&&(a=Pg(e),a!==0&&(r=a,n=lx(e,a))),n===1)throw s=Uc,Ri(e,0),Ma(e,r),us(e,sn()),s;if(n===6)Ma(e,r);else{if(a=e.current.alternate,!(r&30)&&!wD(a)&&(n=Eh(e,r),n===2&&(i=Pg(e),i!==0&&(r=i,n=lx(e,i))),n===1))throw s=Uc,Ri(e,0),Ma(e,r),us(e,sn()),s;switch(e.finishedWork=a,e.finishedLanes=r,n){case 0:case 1:throw Error(Ee(345));case 2:bi(e,as,Zr);break;case 3:if(Ma(e,r),(r&130023424)===r&&(n=Bj+500-sn(),10<n)){if(ch(e,0)!==0)break;if(a=e.suspendedLanes,(a&r)!==r){Xn(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=Ug(bi.bind(null,e,as,Zr),n);break}bi(e,as,Zr);break;case 4:if(Ma(e,r),(r&4194240)===r)break;for(n=e.eventTimes,a=-1;0<r;){var l=31-or(r);i=1<<l,l=n[l],l>a&&(a=l),r&=~i}if(r=a,r=sn()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*jD(r/1960))-r,10<r){e.timeoutHandle=Ug(bi.bind(null,e,as,Zr),r);break}bi(e,as,Zr);break;case 5:bi(e,as,Zr);break;default:throw Error(Ee(329))}}}return us(e,sn()),e.callbackNode===s?pE.bind(null,e):null}function lx(e,n){var s=mc;return e.current.memoizedState.isDehydrated&&(Ri(e,n).flags|=256),e=Eh(e,n),e!==2&&(n=as,as=s,n!==null&&ox(n)),e}function ox(e){as===null?as=e:as.push.apply(as,e)}function wD(e){for(var n=e;;){if(n.flags&16384){var s=n.updateQueue;if(s!==null&&(s=s.stores,s!==null))for(var r=0;r<s.length;r++){var a=s[r],i=a.getSnapshot;a=a.value;try{if(!hr(i(),a))return!1}catch{return!1}}}if(s=n.child,n.subtreeFlags&16384&&s!==null)s.return=n,n=s;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Ma(e,n){for(n&=~Uj,n&=~Ef,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var s=31-or(n),r=1<<s;e[s]=-1,n&=~r}}function Hk(e){if(jt&6)throw Error(Ee(327));zl();var n=ch(e,0);if(!(n&1))return us(e,sn()),null;var s=Eh(e,n);if(e.tag!==0&&s===2){var r=Pg(e);r!==0&&(n=r,s=lx(e,r))}if(s===1)throw s=Uc,Ri(e,0),Ma(e,n),us(e,sn()),s;if(s===6)throw Error(Ee(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,bi(e,as,Zr),us(e,sn()),null}function Wj(e,n){var s=jt;jt|=1;try{return e(n)}finally{jt=s,jt===0&&(Zl=sn()+500,kf&&oi())}}function zi(e){Da!==null&&Da.tag===0&&!(jt&6)&&zl();var n=jt;jt|=1;var s=Vs.transition,r=Nt;try{if(Vs.transition=null,Nt=1,e)return e()}finally{Nt=r,Vs.transition=s,jt=n,!(jt&6)&&oi()}}function Hj(){js=Tl.current,_t(Tl)}function Ri(e,n){e.finishedWork=null,e.finishedLanes=0;var s=e.timeoutHandle;if(s!==-1&&(e.timeoutHandle=-1,QO(s)),cn!==null)for(s=cn.return;s!==null;){var r=s;switch(Nj(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&mh();break;case 3:Jl(),_t(os),_t(Wn),Pj();break;case 5:Ij(r);break;case 4:Jl();break;case 13:_t(Kt);break;case 19:_t(Kt);break;case 10:$j(r.type._context);break;case 22:case 23:Hj()}s=s.return}if(En=e,cn=e=Va(e.current,null),Pn=js=n,vn=0,Uc=null,Uj=Ef=_i=0,as=mc=null,Ci!==null){for(n=0;n<Ci.length;n++)if(s=Ci[n],r=s.interleaved,r!==null){s.interleaved=null;var a=r.next,i=s.pending;if(i!==null){var l=i.next;i.next=a,r.next=l}s.pending=r}Ci=null}return e}function gE(e,n){do{var s=cn;try{if(Ej(),Ld.current=kh,bh){for(var r=Vt.memoizedState;r!==null;){var a=r.queue;a!==null&&(a.pending=null),r=r.next}bh=!1}if(Fi=0,Nn=pn=Vt=null,hc=!1,Fc=0,zj.current=null,s===null||s.return===null){vn=1,Uc=n,cn=null;break}e:{var i=e,l=s.return,o=s,c=n;if(n=Pn,o.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var u=c,h=o,f=h.tag;if(!(h.mode&1)&&(f===0||f===11||f===15)){var m=h.alternate;m?(h.updateQueue=m.updateQueue,h.memoizedState=m.memoizedState,h.lanes=m.lanes):(h.updateQueue=null,h.memoizedState=null)}var p=Rk(l);if(p!==null){p.flags&=-257,Ik(p,l,o,i,n),p.mode&1&&Tk(i,u,n),n=p,c=u;var g=n.updateQueue;if(g===null){var x=new Set;x.add(c),n.updateQueue=x}else g.add(c);break e}else{if(!(n&1)){Tk(i,u,n),Kj();break e}c=Error(Ee(426))}}else if(Wt&&o.mode&1){var k=Rk(l);if(k!==null){!(k.flags&65536)&&(k.flags|=256),Ik(k,l,o,i,n),Sj(Xl(c,o));break e}}i=c=Xl(c,o),vn!==4&&(vn=2),mc===null?mc=[i]:mc.push(i),i=l;do{switch(i.tag){case 3:i.flags|=65536,n&=-n,i.lanes|=n;var j=Z1(i,c,n);Nk(i,j);break e;case 1:o=c;var v=i.type,w=i.stateNode;if(!(i.flags&128)&&(typeof v.getDerivedStateFromError=="function"||w!==null&&typeof w.componentDidCatch=="function"&&(Ha===null||!Ha.has(w)))){i.flags|=65536,n&=-n,i.lanes|=n;var y=eE(i,o,n);Nk(i,y);break e}}i=i.return}while(i!==null)}jE(s)}catch(N){n=N,cn===s&&s!==null&&(cn=s=s.return);continue}break}while(!0)}function xE(){var e=Nh.current;return Nh.current=kh,e===null?kh:e}function Kj(){(vn===0||vn===3||vn===2)&&(vn=4),En===null||!(_i&268435455)&&!(Ef&268435455)||Ma(En,Pn)}function Eh(e,n){var s=jt;jt|=2;var r=xE();(En!==e||Pn!==n)&&(Zr=null,Ri(e,n));do try{yD();break}catch(a){gE(e,a)}while(!0);if(Ej(),jt=s,Nh.current=r,cn!==null)throw Error(Ee(261));return En=null,Pn=0,vn}function yD(){for(;cn!==null;)vE(cn)}function bD(){for(;cn!==null&&!G2();)vE(cn)}function vE(e){var n=yE(e.alternate,e,js);e.memoizedProps=e.pendingProps,n===null?jE(e):cn=n,zj.current=null}function jE(e){var n=e;do{var s=n.alternate;if(e=n.return,n.flags&32768){if(s=pD(s,n),s!==null){s.flags&=32767,cn=s;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{vn=6,cn=null;return}}else if(s=mD(s,n,js),s!==null){cn=s;return}if(n=n.sibling,n!==null){cn=n;return}cn=n=e}while(n!==null);vn===0&&(vn=5)}function bi(e,n,s){var r=Nt,a=Vs.transition;try{Vs.transition=null,Nt=1,kD(e,n,s,r)}finally{Vs.transition=a,Nt=r}return null}function kD(e,n,s,r){do zl();while(Da!==null);if(jt&6)throw Error(Ee(327));s=e.finishedWork;var a=e.finishedLanes;if(s===null)return null;if(e.finishedWork=null,e.finishedLanes=0,s===e.current)throw Error(Ee(177));e.callbackNode=null,e.callbackPriority=0;var i=s.lanes|s.childLanes;if(sO(e,i),e===En&&(cn=En=null,Pn=0),!(s.subtreeFlags&2064)&&!(s.flags&2064)||td||(td=!0,bE(oh,function(){return zl(),null})),i=(s.flags&15990)!==0,s.subtreeFlags&15990||i){i=Vs.transition,Vs.transition=null;var l=Nt;Nt=1;var o=jt;jt|=4,zj.current=null,xD(e,s),fE(s,e),WO(_g),uh=!!Fg,_g=Fg=null,e.current=s,vD(s),Y2(),jt=o,Nt=l,Vs.transition=i}else e.current=s;if(td&&(td=!1,Da=e,Ch=a),i=e.pendingLanes,i===0&&(Ha=null),J2(s.stateNode),us(e,sn()),n!==null)for(r=e.onRecoverableError,s=0;s<n.length;s++)a=n[s],r(a.value,{componentStack:a.stack,digest:a.digest});if(Sh)throw Sh=!1,e=ax,ax=null,e;return Ch&1&&e.tag!==0&&zl(),i=e.pendingLanes,i&1?e===ix?pc++:(pc=0,ix=e):pc=0,oi(),null}function zl(){if(Da!==null){var e=ZC(Ch),n=Vs.transition,s=Nt;try{if(Vs.transition=null,Nt=16>e?16:e,Da===null)var r=!1;else{if(e=Da,Da=null,Ch=0,jt&6)throw Error(Ee(331));var a=jt;for(jt|=4,De=e.current;De!==null;){var i=De,l=i.child;if(De.flags&16){var o=i.deletions;if(o!==null){for(var c=0;c<o.length;c++){var u=o[c];for(De=u;De!==null;){var h=De;switch(h.tag){case 0:case 11:case 15:fc(8,h,i)}var f=h.child;if(f!==null)f.return=h,De=f;else for(;De!==null;){h=De;var m=h.sibling,p=h.return;if(uE(h),h===u){De=null;break}if(m!==null){m.return=p,De=m;break}De=p}}}var g=i.alternate;if(g!==null){var x=g.child;if(x!==null){g.child=null;do{var k=x.sibling;x.sibling=null,x=k}while(x!==null)}}De=i}}if(i.subtreeFlags&2064&&l!==null)l.return=i,De=l;else e:for(;De!==null;){if(i=De,i.flags&2048)switch(i.tag){case 0:case 11:case 15:fc(9,i,i.return)}var j=i.sibling;if(j!==null){j.return=i.return,De=j;break e}De=i.return}}var v=e.current;for(De=v;De!==null;){l=De;var w=l.child;if(l.subtreeFlags&2064&&w!==null)w.return=l,De=w;else e:for(l=v;De!==null;){if(o=De,o.flags&2048)try{switch(o.tag){case 0:case 11:case 15:Cf(9,o)}}catch(N){Qt(o,o.return,N)}if(o===l){De=null;break e}var y=o.sibling;if(y!==null){y.return=o.return,De=y;break e}De=o.return}}if(jt=a,oi(),Rr&&typeof Rr.onPostCommitFiberRoot=="function")try{Rr.onPostCommitFiberRoot(vf,e)}catch{}r=!0}return r}finally{Nt=s,Vs.transition=n}}return!1}function Kk(e,n,s){n=Xl(s,n),n=Z1(e,n,1),e=Wa(e,n,1),n=Xn(),e!==null&&(mu(e,1,n),us(e,n))}function Qt(e,n,s){if(e.tag===3)Kk(e,e,s);else for(;n!==null;){if(n.tag===3){Kk(n,e,s);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Ha===null||!Ha.has(r))){e=Xl(s,e),e=eE(n,e,1),n=Wa(n,e,1),e=Xn(),n!==null&&(mu(n,1,e),us(n,e));break}}n=n.return}}function ND(e,n,s){var r=e.pingCache;r!==null&&r.delete(n),n=Xn(),e.pingedLanes|=e.suspendedLanes&s,En===e&&(Pn&s)===s&&(vn===4||vn===3&&(Pn&130023424)===Pn&&500>sn()-Bj?Ri(e,0):Uj|=s),us(e,n)}function wE(e,n){n===0&&(e.mode&1?(n=Ku,Ku<<=1,!(Ku&130023424)&&(Ku=4194304)):n=1);var s=Xn();e=ma(e,n),e!==null&&(mu(e,n,s),us(e,s))}function SD(e){var n=e.memoizedState,s=0;n!==null&&(s=n.retryLane),wE(e,s)}function CD(e,n){var s=0;switch(e.tag){case 13:var r=e.stateNode,a=e.memoizedState;a!==null&&(s=a.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(Ee(314))}r!==null&&r.delete(n),wE(e,s)}var yE;yE=function(e,n,s){if(e!==null)if(e.memoizedProps!==n.pendingProps||os.current)is=!0;else{if(!(e.lanes&s)&&!(n.flags&128))return is=!1,fD(e,n,s);is=!!(e.flags&131072)}else is=!1,Wt&&n.flags&1048576&&S1(n,xh,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;_d(e,n),e=n.pendingProps;var a=Yl(n,Wn.current);_l(n,s),a=Oj(null,n,r,e,a,s);var i=Dj();return n.flags|=1,typeof a=="object"&&a!==null&&typeof a.render=="function"&&a.$$typeof===void 0?(n.tag=1,n.memoizedState=null,n.updateQueue=null,cs(r)?(i=!0,ph(n)):i=!1,n.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,Tj(n),a.updater=Sf,n.stateNode=a,a._reactInternals=n,Yg(n,r,e,s),n=Jg(null,n,r,!0,i,s)):(n.tag=0,Wt&&i&&kj(n),qn(null,n,a,s),n=n.child),n;case 16:r=n.elementType;e:{switch(_d(e,n),e=n.pendingProps,a=r._init,r=a(r._payload),n.type=r,a=n.tag=$D(r),e=tr(r,e),a){case 0:n=Qg(null,n,r,e,s);break e;case 1:n=Ok(null,n,r,e,s);break e;case 11:n=Pk(null,n,r,e,s);break e;case 14:n=Mk(null,n,r,tr(r.type,e),s);break e}throw Error(Ee(306,r,""))}return n;case 0:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:tr(r,a),Qg(e,n,r,a,s);case 1:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:tr(r,a),Ok(e,n,r,a,s);case 3:e:{if(rE(n),e===null)throw Error(Ee(387));r=n.pendingProps,i=n.memoizedState,a=i.element,R1(e,n),wh(n,r,null,s);var l=n.memoizedState;if(r=l.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:l.cache,pendingSuspenseBoundaries:l.pendingSuspenseBoundaries,transitions:l.transitions},n.updateQueue.baseState=i,n.memoizedState=i,n.flags&256){a=Xl(Error(Ee(423)),n),n=Dk(e,n,r,s,a);break e}else if(r!==a){a=Xl(Error(Ee(424)),n),n=Dk(e,n,r,s,a);break e}else for(ys=Ba(n.stateNode.containerInfo.firstChild),ks=n,Wt=!0,sr=null,s=A1(n,null,r,s),n.child=s;s;)s.flags=s.flags&-3|4096,s=s.sibling;else{if(ql(),r===a){n=pa(e,n,s);break e}qn(e,n,r,s)}n=n.child}return n;case 5:return I1(n),e===null&&Kg(n),r=n.type,a=n.pendingProps,i=e!==null?e.memoizedProps:null,l=a.children,zg(r,a)?l=null:i!==null&&zg(r,i)&&(n.flags|=32),sE(e,n),qn(e,n,l,s),n.child;case 6:return e===null&&Kg(n),null;case 13:return aE(e,n,s);case 4:return Rj(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=Ql(n,null,r,s):qn(e,n,r,s),n.child;case 11:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:tr(r,a),Pk(e,n,r,a,s);case 7:return qn(e,n,n.pendingProps,s),n.child;case 8:return qn(e,n,n.pendingProps.children,s),n.child;case 12:return qn(e,n,n.pendingProps.children,s),n.child;case 10:e:{if(r=n.type._context,a=n.pendingProps,i=n.memoizedProps,l=a.value,Mt(vh,r._currentValue),r._currentValue=l,i!==null)if(hr(i.value,l)){if(i.children===a.children&&!os.current){n=pa(e,n,s);break e}}else for(i=n.child,i!==null&&(i.return=n);i!==null;){var o=i.dependencies;if(o!==null){l=i.child;for(var c=o.firstContext;c!==null;){if(c.context===r){if(i.tag===1){c=oa(-1,s&-s),c.tag=2;var u=i.updateQueue;if(u!==null){u=u.shared;var h=u.pending;h===null?c.next=c:(c.next=h.next,h.next=c),u.pending=c}}i.lanes|=s,c=i.alternate,c!==null&&(c.lanes|=s),Vg(i.return,s,n),o.lanes|=s;break}c=c.next}}else if(i.tag===10)l=i.type===n.type?null:i.child;else if(i.tag===18){if(l=i.return,l===null)throw Error(Ee(341));l.lanes|=s,o=l.alternate,o!==null&&(o.lanes|=s),Vg(l,s,n),l=i.sibling}else l=i.child;if(l!==null)l.return=i;else for(l=i;l!==null;){if(l===n){l=null;break}if(i=l.sibling,i!==null){i.return=l.return,l=i;break}l=l.return}i=l}qn(e,n,a.children,s),n=n.child}return n;case 9:return a=n.type,r=n.pendingProps.children,_l(n,s),a=Ys(a),r=r(a),n.flags|=1,qn(e,n,r,s),n.child;case 14:return r=n.type,a=tr(r,n.pendingProps),a=tr(r.type,a),Mk(e,n,r,a,s);case 15:return tE(e,n,n.type,n.pendingProps,s);case 17:return r=n.type,a=n.pendingProps,a=n.elementType===r?a:tr(r,a),_d(e,n),n.tag=1,cs(r)?(e=!0,ph(n)):e=!1,_l(n,s),X1(n,r,a),Yg(n,r,a,s),Jg(null,n,r,!0,e,s);case 19:return iE(e,n,s);case 22:return nE(e,n,s)}throw Error(Ee(156,n.tag))};function bE(e,n){return qC(e,n)}function ED(e,n,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=n,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 Ks(e,n,s,r){return new ED(e,n,s,r)}function Vj(e){return e=e.prototype,!(!e||!e.isReactComponent)}function $D(e){if(typeof e=="function")return Vj(e)?1:0;if(e!=null){if(e=e.$$typeof,e===dj)return 11;if(e===hj)return 14}return 2}function Va(e,n){var s=e.alternate;return s===null?(s=Ks(e.tag,n,e.key,e.mode),s.elementType=e.elementType,s.type=e.type,s.stateNode=e.stateNode,s.alternate=e,e.alternate=s):(s.pendingProps=n,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,n=e.dependencies,s.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},s.sibling=e.sibling,s.index=e.index,s.ref=e.ref,s}function Bd(e,n,s,r,a,i){var l=2;if(r=e,typeof e=="function")Vj(e)&&(l=1);else if(typeof e=="string")l=5;else e:switch(e){case wl:return Ii(s.children,a,i,n);case uj:l=8,a|=8;break;case vg:return e=Ks(12,s,n,a|2),e.elementType=vg,e.lanes=i,e;case jg:return e=Ks(13,s,n,a),e.elementType=jg,e.lanes=i,e;case wg:return e=Ks(19,s,n,a),e.elementType=wg,e.lanes=i,e;case IC:return $f(s,a,i,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case TC:l=10;break e;case RC:l=9;break e;case dj:l=11;break e;case hj:l=14;break e;case Ra:l=16,r=null;break e}throw Error(Ee(130,e==null?e:typeof e,""))}return n=Ks(l,s,n,a),n.elementType=e,n.type=r,n.lanes=i,n}function Ii(e,n,s,r){return e=Ks(7,e,r,n),e.lanes=s,e}function $f(e,n,s,r){return e=Ks(22,e,r,n),e.elementType=IC,e.lanes=s,e.stateNode={isHidden:!1},e}function ap(e,n,s){return e=Ks(6,e,null,n),e.lanes=s,e}function ip(e,n,s){return n=Ks(4,e.children!==null?e.children:[],e.key,n),n.lanes=s,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function AD(e,n,s,r,a){this.tag=n,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=zm(0),this.expirationTimes=zm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=zm(0),this.identifierPrefix=r,this.onRecoverableError=a,this.mutableSourceEagerHydrationData=null}function Gj(e,n,s,r,a,i,l,o,c){return e=new AD(e,n,s,o,c),n===1?(n=1,i===!0&&(n|=8)):n=0,i=Ks(3,null,null,n),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:s,cache:null,transitions:null,pendingSuspenseBoundaries:null},Tj(i),e}function TD(e,n,s){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:jl,key:r==null?null:""+r,children:e,containerInfo:n,implementation:s}}function kE(e){if(!e)return Ja;e=e._reactInternals;e:{if(qi(e)!==e||e.tag!==1)throw Error(Ee(170));var n=e;do{switch(n.tag){case 3:n=n.stateNode.context;break e;case 1:if(cs(n.type)){n=n.stateNode.__reactInternalMemoizedMergedChildContext;break e}}n=n.return}while(n!==null);throw Error(Ee(171))}if(e.tag===1){var s=e.type;if(cs(s))return k1(e,s,n)}return n}function NE(e,n,s,r,a,i,l,o,c){return e=Gj(s,r,!0,e,a,i,l,o,c),e.context=kE(null),s=e.current,r=Xn(),a=Ka(s),i=oa(r,a),i.callback=n??null,Wa(s,i,a),e.current.lanes=a,mu(e,a,r),us(e,r),e}function Af(e,n,s,r){var a=n.current,i=Xn(),l=Ka(a);return s=kE(s),n.context===null?n.context=s:n.pendingContext=s,n=oa(i,l),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Wa(a,n,l),e!==null&&(cr(e,a,l,i),Dd(e,a,l)),l}function $h(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 Vk(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var s=e.retryLane;e.retryLane=s!==0&&s<n?s:n}}function Yj(e,n){Vk(e,n),(e=e.alternate)&&Vk(e,n)}function RD(){return null}var SE=typeof reportError=="function"?reportError:function(e){console.error(e)};function qj(e){this._internalRoot=e}Tf.prototype.render=qj.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(Ee(409));Af(e,n,null,null)};Tf.prototype.unmount=qj.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;zi(function(){Af(null,e,null,null)}),n[fa]=null}};function Tf(e){this._internalRoot=e}Tf.prototype.unstable_scheduleHydration=function(e){if(e){var n=n1();e={blockedOn:null,target:e,priority:n};for(var s=0;s<Pa.length&&n!==0&&n<Pa[s].priority;s++);Pa.splice(s,0,e),s===0&&r1(e)}};function Qj(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Rf(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function Gk(){}function ID(e,n,s,r,a){if(a){if(typeof r=="function"){var i=r;r=function(){var u=$h(l);i.call(u)}}var l=NE(n,r,e,0,null,!1,!1,"",Gk);return e._reactRootContainer=l,e[fa]=l.current,Pc(e.nodeType===8?e.parentNode:e),zi(),l}for(;a=e.lastChild;)e.removeChild(a);if(typeof r=="function"){var o=r;r=function(){var u=$h(c);o.call(u)}}var c=Gj(e,0,!1,null,null,!1,!1,"",Gk);return e._reactRootContainer=c,e[fa]=c.current,Pc(e.nodeType===8?e.parentNode:e),zi(function(){Af(n,c,s,r)}),c}function If(e,n,s,r,a){var i=s._reactRootContainer;if(i){var l=i;if(typeof a=="function"){var o=a;a=function(){var c=$h(l);o.call(c)}}Af(n,l,e,a)}else l=ID(s,n,e,a,r);return $h(l)}e1=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var s=ec(n.pendingLanes);s!==0&&(pj(n,s|1),us(n,sn()),!(jt&6)&&(Zl=sn()+500,oi()))}break;case 13:zi(function(){var r=ma(e,1);if(r!==null){var a=Xn();cr(r,e,1,a)}}),Yj(e,1)}};gj=function(e){if(e.tag===13){var n=ma(e,134217728);if(n!==null){var s=Xn();cr(n,e,134217728,s)}Yj(e,134217728)}};t1=function(e){if(e.tag===13){var n=Ka(e),s=ma(e,n);if(s!==null){var r=Xn();cr(s,e,n,r)}Yj(e,n)}};n1=function(){return Nt};s1=function(e,n){var s=Nt;try{return Nt=e,n()}finally{Nt=s}};Tg=function(e,n,s){switch(n){case"input":if(kg(e,s),n=s.name,s.type==="radio"&&n!=null){for(s=e;s.parentNode;)s=s.parentNode;for(s=s.querySelectorAll("input[name="+JSON.stringify(""+n)+'][type="radio"]'),n=0;n<s.length;n++){var r=s[n];if(r!==e&&r.form===e.form){var a=bf(r);if(!a)throw Error(Ee(90));MC(r),kg(r,a)}}}break;case"textarea":DC(e,s);break;case"select":n=s.value,n!=null&&Ol(e,!!s.multiple,n,!1)}};WC=Wj;HC=zi;var PD={usingClientEntryPoint:!1,Events:[gu,Nl,bf,UC,BC,Wj]},Ho={findFiberByHostInstance:Si,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},MD={bundleType:Ho.bundleType,version:Ho.version,rendererPackageName:Ho.rendererPackageName,rendererConfig:Ho.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ja.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=GC(e),e===null?null:e.stateNode},findFiberByHostInstance:Ho.findFiberByHostInstance||RD,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 nd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!nd.isDisabled&&nd.supportsFiber)try{vf=nd.inject(MD),Rr=nd}catch{}}As.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=PD;As.createPortal=function(e,n){var s=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Qj(n))throw Error(Ee(200));return TD(e,n,null,s)};As.createRoot=function(e,n){if(!Qj(e))throw Error(Ee(299));var s=!1,r="",a=SE;return n!=null&&(n.unstable_strictMode===!0&&(s=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(a=n.onRecoverableError)),n=Gj(e,1,!1,null,null,s,!1,r,a),e[fa]=n.current,Pc(e.nodeType===8?e.parentNode:e),new qj(n)};As.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(Ee(188)):(e=Object.keys(e).join(","),Error(Ee(268,e)));return e=GC(n),e=e===null?null:e.stateNode,e};As.flushSync=function(e){return zi(e)};As.hydrate=function(e,n,s){if(!Rf(n))throw Error(Ee(200));return If(null,e,n,!0,s)};As.hydrateRoot=function(e,n,s){if(!Qj(e))throw Error(Ee(405));var r=s!=null&&s.hydratedSources||null,a=!1,i="",l=SE;if(s!=null&&(s.unstable_strictMode===!0&&(a=!0),s.identifierPrefix!==void 0&&(i=s.identifierPrefix),s.onRecoverableError!==void 0&&(l=s.onRecoverableError)),n=NE(n,null,e,1,s??null,a,!1,i,l),e[fa]=n.current,Pc(e),r)for(e=0;e<r.length;e++)s=r[e],a=s._getVersion,a=a(s._source),n.mutableSourceEagerHydrationData==null?n.mutableSourceEagerHydrationData=[s,a]:n.mutableSourceEagerHydrationData.push(s,a);return new Tf(n)};As.render=function(e,n,s){if(!Rf(n))throw Error(Ee(200));return If(null,e,n,!1,s)};As.unmountComponentAtNode=function(e){if(!Rf(e))throw Error(Ee(40));return e._reactRootContainer?(zi(function(){If(null,null,e,!1,function(){e._reactRootContainer=null,e[fa]=null})}),!0):!1};As.unstable_batchedUpdates=Wj;As.unstable_renderSubtreeIntoContainer=function(e,n,s,r){if(!Rf(s))throw Error(Ee(200));if(e==null||e._reactInternals===void 0)throw Error(Ee(38));return If(e,n,s,!1,r)};As.version="18.3.1-next-f1338f8080-20240426";function CE(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(CE)}catch(e){console.error(e)}}CE(),CC.exports=As;var xo=CC.exports,EE,Yk=xo;EE=Yk.createRoot,Yk.hydrateRoot;const OD=["use","new","stop","quiet"];function qk(e){return OD.includes(e)}function DD(e,n){return[{group:"This chat",name:"use",args:"<agent>",desc:"Talk to another agent from here on",source:"chat"},{group:"This chat",name:"new",args:"[what it is for]",desc:"Make a new agent with Agent Father",source:"chat"},{group:"This chat",name:"stop",desc:n?`Stop what ${e} is doing`:"Nothing is running",key:"Esc",off:!n,source:"chat"},{group:"This chat",name:"quiet",args:"[1d|1w|off]",desc:"No messages from agents for a while",source:"chat"}]}const LD=e=>e.replace(/^plugin-/,"").replace(/[-_]+/g," ").replace(/^./,n=>n.toUpperCase());function FD(e){return e.map(n=>({group:`From ${LD(n.plugin)}`,name:n.name,...n.args?{args:n.args}:{},desc:n.description,source:"plugin"}))}const _D=e=>!!(e.args&&e.args.startsWith("<"));let Ah=[];const cx=new Set;function zD(e){const n=e??[];JSON.stringify(n)!==JSON.stringify(Ah)&&(Ah=n,cx.forEach(s=>s()))}function UD(){return d.useSyncExternalStore(e=>(cx.add(e),()=>cx.delete(e)),()=>Ah,()=>Ah)}var BD=Object.defineProperty,vo=(e,n)=>BD(e,"name",{value:n,configurable:!0}),$E=!!(typeof window<"u"&&window.document&&window.document.createElement);function Be(e,n,{checkForDefaultPrevented:s=!0}={}){return vo(function(a){if(e==null||e(a),s===!1||!a||!a.defaultPrevented)return n==null?void 0:n(a)},"handleEvent")}vo(Be,"composeEventHandlers");function WD(e){var n;if(!$E)throw new Error("Cannot access window outside of the DOM");return((n=e==null?void 0:e.ownerDocument)==null?void 0:n.defaultView)??window}vo(WD,"getOwnerWindow");function ux(e){if(!$E)throw new Error("Cannot access document outside of the DOM");return(e==null?void 0:e.ownerDocument)??document}vo(ux,"getOwnerDocument");function AE(e,n=!1){const{activeElement:s}=ux(e);if(!(s!=null&&s.nodeName))return null;if(TE(s)&&s.contentDocument)return AE(s.contentDocument.body,n);if(n){const r=s.getAttribute("aria-activedescendant");if(r){const a=ux(s).getElementById(r);if(a)return a}}return s}vo(AE,"getActiveElement");function TE(e){return e.tagName==="IFRAME"}vo(TE,"isFrame");var HD=Object.defineProperty,Jj=(e,n)=>HD(e,"name",{value:n,configurable:!0});function dx(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}Jj(dx,"setRef");function RE(...e){return n=>{let s=!1;const r=e.map(a=>{const i=dx(a,n);return!s&&typeof i=="function"&&(s=!0),i});if(s)return()=>{for(let a=0;a<r.length;a++){const i=r[a];typeof i=="function"?i():dx(e[a],null)}}}}Jj(RE,"composeRefs");function Rt(...e){return d.useCallback(RE(...e),e)}Jj(Rt,"useComposedRefs");var KD=Object.defineProperty,Hs=(e,n)=>KD(e,"name",{value:n,configurable:!0});function VD(e,n){const s=d.createContext(n);s.displayName=e+"Context";const r=Hs(i=>{const{children:l,...o}=i,c=d.useMemo(()=>o,Object.values(o));return t.jsx(s.Provider,{value:c,children:l})},"Provider");r.displayName=e+"Provider";function a(i,l={}){const{optional:o=!1}=l,c=d.useContext(s);if(c)return c;if(n!==void 0)return n;if(!o)throw new Error(`\`${i}\` must be used within \`${e}\``)}return Hs(a,"useContext"),[r,a]}Hs(VD,"createContext");function vr(e,n=[]){let s=[];function r(i,l){const o=d.createContext(l);o.displayName=i+"Context";const c=s.length;s=[...s,l];const u=Hs(f=>{var j;const{scope:m,children:p,...g}=f,x=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,k=d.useMemo(()=>g,Object.values(g));return t.jsx(x.Provider,{value:k,children:p})},"Provider");u.displayName=i+"Provider";function h(f,m,p={}){var j;const{optional:g=!1}=p,x=((j=m==null?void 0:m[e])==null?void 0:j[c])||o,k=d.useContext(x);if(k)return k;if(l!==void 0)return l;if(!g)throw new Error(`\`${f}\` must be used within \`${i}\``)}return Hs(h,"useContext"),[u,h]}Hs(r,"createContext");const a=Hs(()=>{const i=s.map(l=>d.createContext(l));return Hs(function(o){const c=(o==null?void 0:o[e])||i;return d.useMemo(()=>({[`__scope${e}`]:{...o,[e]:c}}),[o,c])},"useScope")},"createScope");return a.scopeName=e,[r,IE(a,...n)]}Hs(vr,"createContextScope");function IE(...e){const n=e[0];if(e.length===1)return n;const s=Hs(()=>{const r=e.map(a=>({useScope:a(),scopeName:a.scopeName}));return Hs(function(i){const l=r.reduce((o,{useScope:c,scopeName:u})=>{const f=c(i)[`__scope${u}`];return{...o,...f}},{});return d.useMemo(()=>({[`__scope${n.scopeName}`]:l}),[l])},"useComposedScopes")},"createScope");return s.scopeName=n.scopeName,s}Hs(IE,"composeContextScopes");var GD=Object.defineProperty,jr=(e,n)=>GD(e,"name",{value:n,configurable:!0});function Xa(e){const n=d.forwardRef((s,r)=>{let{children:a,...i}=s,l=null,o=!1;const c=[];hx(a)&&typeof sd=="function"&&(a=sd(a._payload)),d.Children.forEach(a,m=>{var p;if(LE(m)){o=!0;const g=m;let x="child"in g.props?g.props.child:g.props.children;hx(x)&&typeof sd=="function"&&(x=sd(x._payload)),l=YD(g,x),c.push((p=l==null?void 0:l.props)==null?void 0:p.children)}else c.push(m)}),l?l=d.cloneElement(l,void 0,c):!o&&d.Children.count(a)===1&&d.isValidElement(a)&&(l=a);const u=l?DE(l):void 0,h=Rt(r,u);if(!l){if(a||a===0)throw new Error(o?JD(e):QD(e));return a}const f=OE(i,l.props??{});return l.type!==d.Fragment&&(f.ref=r?h:u),d.cloneElement(l,f)});return n.displayName=`${e}.Slot`,n}jr(Xa,"createSlot");var PE=Symbol.for("radix.slottable");function ME(e){const n=jr(s=>"child"in s?s.children(s.child):s.children,"Slottable");return n.displayName=`${e}.Slottable`,n.__radixId=PE,n}jr(ME,"createSlottable");var YD=jr((e,n)=>{if("child"in e.props){const s=e.props.child;return d.isValidElement(s)?d.cloneElement(s,void 0,e.props.children(s.props.children)):null}return d.isValidElement(n)?n:null},"getSlottableElementFromSlottable");function OE(e,n){const s={...n};for(const r in n){const a=e[r],i=n[r];/^on[A-Z]/.test(r)?a&&i?s[r]=(...o)=>{const c=i(...o);return a(...o),c}:a&&(s[r]=a):r==="style"?s[r]={...a,...i}:r==="className"&&(s[r]=[a,i].filter(Boolean).join(" "))}return{...e,...s}}jr(OE,"mergeProps");function DE(e){var r,a;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?e.ref:(n=(a=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}jr(DE,"getElementRef");function LE(e){return d.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===PE}jr(LE,"isSlottable");var qD=Symbol.for("react.lazy");function hx(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===qD&&"_payload"in e&&FE(e._payload)}jr(hx,"isLazyComponent");function FE(e){return typeof e=="object"&&e!==null&&"then"in e}jr(FE,"isPromiseLike");var QD=jr(e=>`${e} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),JD=jr(e=>`${e} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),sd=mo[" use ".trim().toString()],XD=Object.defineProperty,Sn=(e,n)=>XD(e,"name",{value:n,configurable:!0});function Pf(e){const n=e+"CollectionProvider",[s,r]=vr(n),[a,i]=s(n,{collectionRef:{current:null},itemMap:new Map}),l=Sn(x=>{const{scope:k,children:j}=x,v=d.useRef(null),w=d.useRef(new Map).current;return t.jsx(a,{scope:k,itemMap:w,collectionRef:v,children:j})},"CollectionProvider");l.displayName=n;const o=e+"CollectionSlot",c=Xa(o),u=d.forwardRef((x,k)=>{const{scope:j,children:v}=x,w=i(o,j),y=Rt(k,w.collectionRef);return t.jsx(c,{ref:y,children:v})});u.displayName=o;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=Xa(h),p=d.forwardRef((x,k)=>{const{scope:j,children:v,...w}=x,y=d.useRef(null),N=Rt(k,y),b=i(h,j);return d.useEffect(()=>(b.itemMap.set(y,{ref:y,...w}),()=>void b.itemMap.delete(y))),t.jsx(m,{[f]:"",ref:N,children:v})});p.displayName=h;function g(x){const k=i(e+"CollectionConsumer",x);return d.useCallback(()=>{const v=k.collectionRef.current;if(!v)return[];const w=Array.from(v.querySelectorAll(`[${f}]`));return Array.from(k.itemMap.values()).sort((b,S)=>w.indexOf(b.ref.current)-w.indexOf(S.ref.current))},[k.collectionRef,k.itemMap])}return Sn(g,"useCollection"),[{Provider:l,Slot:u,ItemSlot:p},g,r]}Sn(Pf,"createCollection");var Qk=new WeakMap,ln,ws,lp=(ws=class extends Map{constructor(s){super(s);_b(this,ln);Mm(this,ln,[...super.keys()]),Qk.set(this,!0)}set(s,r){return Qk.get(this)&&(this.has(s)?Ln(this,ln)[Ln(this,ln).indexOf(s)]=s:Ln(this,ln).push(s)),super.set(s,r),this}insert(s,r,a){const i=this.has(r),l=Ln(this,ln).length,o=Xj(s);let c=o>=0?o:l+o;const u=c<0||c>=l?-1:c;if(u===this.size||i&&u===this.size-1||u===-1)return this.set(r,a),this;const h=this.size+(i?0:1);o<0&&c++;const f=[...Ln(this,ln)];let m,p=!1;for(let g=c;g<h;g++)if(c===g){let x=f[g];f[g]===r&&(x=f[g+1]),i&&this.delete(r),m=this.get(x),this.set(r,a)}else{!p&&f[g-1]===r&&(p=!0);const x=f[p?g:g-1],k=m;m=this.get(x),this.delete(x),this.set(x,k)}return this}with(s,r,a){const i=new ws(this);return i.insert(s,r,a),i}before(s){const r=Ln(this,ln).indexOf(s)-1;if(!(r<0))return this.entryAt(r)}setBefore(s,r,a){const i=Ln(this,ln).indexOf(s);return i===-1?this:this.insert(i,r,a)}after(s){let r=Ln(this,ln).indexOf(s);if(r=r===-1||r===this.size-1?-1:r+1,r!==-1)return this.entryAt(r)}setAfter(s,r,a){const i=Ln(this,ln).indexOf(s);return i===-1?this:this.insert(i+1,r,a)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return Mm(this,ln,[]),super.clear()}delete(s){const r=super.delete(s);return r&&Ln(this,ln).splice(Ln(this,ln).indexOf(s),1),r}deleteAt(s){const r=this.keyAt(s);return r!==void 0?this.delete(r):!1}at(s){const r=Wd(Ln(this,ln),s);if(r!==void 0)return this.get(r)}entryAt(s){const r=Wd(Ln(this,ln),s);if(r!==void 0)return[r,this.get(r)]}indexOf(s){return Ln(this,ln).indexOf(s)}keyAt(s){return Wd(Ln(this,ln),s)}from(s,r){const a=this.indexOf(s);if(a===-1)return;let i=a+r;return i<0&&(i=0),i>=this.size&&(i=this.size-1),this.at(i)}keyFrom(s,r){const a=this.indexOf(s);if(a===-1)return;let i=a+r;return i<0&&(i=0),i>=this.size&&(i=this.size-1),this.keyAt(i)}find(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return i;a++}}findIndex(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return a;a++}return-1}filter(s,r){const a=[];let i=0;for(const l of this)Reflect.apply(s,r,[l,i,this])&&a.push(l),i++;return new ws(a)}map(s,r){const a=[];let i=0;for(const l of this)a.push([l[0],Reflect.apply(s,r,[l,i,this])]),i++;return new ws(a)}reduce(...s){const[r,a]=s;let i=0,l=a??this.at(0);for(const o of this)i===0&&s.length===1?l=o:l=Reflect.apply(r,this,[l,o,i,this]),i++;return l}reduceRight(...s){const[r,a]=s;let i=a??this.at(-1);for(let l=this.size-1;l>=0;l--){const o=this.at(l);l===this.size-1&&s.length===1?i=o:i=Reflect.apply(r,this,[i,o,l,this])}return i}toSorted(s){const r=[...this.entries()].sort(s);return new ws(r)}toReversed(){const s=new ws;for(let r=this.size-1;r>=0;r--){const a=this.keyAt(r),i=this.get(a);s.set(a,i)}return s}toSpliced(...s){const r=[...this.entries()];return r.splice(...s),new ws(r)}slice(s,r){const a=new ws;let i=this.size-1;if(s===void 0)return a;s<0&&(s=s+this.size),r!==void 0&&r>0&&(i=r-1);for(let l=s;l<=i;l++){const o=this.keyAt(l),c=this.get(o);a.set(o,c)}return a}every(s,r){let a=0;for(const i of this){if(!Reflect.apply(s,r,[i,a,this]))return!1;a++}return!0}some(s,r){let a=0;for(const i of this){if(Reflect.apply(s,r,[i,a,this]))return!0;a++}return!1}},ln=new WeakMap,Sn(ws,"OrderedDict"),ws);function Wd(e,n){if("at"in Array.prototype)return Array.prototype.at.call(e,n);const s=_E(e,n);return s===-1?void 0:e[s]}Sn(Wd,"at");function _E(e,n){const s=e.length,r=Xj(n),a=r>=0?r:s+r;return a<0||a>=s?-1:a}Sn(_E,"toSafeIndex");function Xj(e){return e!==e||e===0?0:Math.trunc(e)}Sn(Xj,"toSafeInteger");function ZD(e){const n=e+"CollectionProvider",[s,r]=vr(n),[a,i]=s(n,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new lp,setItemMap:Sn(()=>{},"setItemMap")}),l=Sn(({state:w,...y})=>w?t.jsx(c,{...y,state:w}):t.jsx(o,{...y}),"CollectionProvider");l.displayName=n;const o=Sn(w=>{const y=k();return t.jsx(c,{...w,state:y})},"CollectionInit");o.displayName=n+"Init";const c=Sn(w=>{const{scope:y,children:N,state:b}=w,S=d.useRef(null),[C,T]=d.useState(null),E=Rt(S,T),[R,M]=b;return d.useEffect(()=>{if(!C)return;const O=BE(()=>{});return O.observe(C,{childList:!0,subtree:!0}),()=>{O.disconnect()}},[C]),t.jsx(a,{scope:y,itemMap:R,setItemMap:M,collectionRef:E,collectionRefObject:S,collectionElement:C,children:N})},"CollectionProviderImpl");c.displayName=n+"Impl";const u=e+"CollectionSlot",h=Xa(u),f=d.forwardRef((w,y)=>{const{scope:N,children:b}=w,S=i(u,N),C=Rt(y,S.collectionRef);return t.jsx(h,{ref:C,children:b})});f.displayName=u;const m=e+"CollectionItemSlot",p="data-radix-collection-item",g=Xa(m),x=d.forwardRef((w,y)=>{const{scope:N,children:b,...S}=w,C=d.useRef(null),[T,E]=d.useState(null),R=Rt(y,C,E),M=i(m,N),{setItemMap:O}=M,I=d.useRef(S);zE(I.current,S)||(I.current=S);const z=I.current;return d.useEffect(()=>{const U=z;return O(D=>T?D.has(T)?D.set(T,{...U,element:T}).toSorted(fx):(D.set(T,{...U,element:T}),D.toSorted(fx)):D),()=>{O(D=>!T||!D.has(T)?D:(D.delete(T),new lp(D)))}},[T,z,O]),t.jsx(g,{[p]:"",ref:R,children:b})});x.displayName=m;function k(){return d.useState(new lp)}Sn(k,"useInitCollection");function j(w){const{itemMap:y}=i(e+"CollectionConsumer",w);return y}return Sn(j,"useCollection"),[{Provider:l,Slot:f,ItemSlot:x},{createCollectionScope:r,useCollection:j,useInitCollection:k}]}Sn(ZD,"createCollection");function zE(e,n){if(e===n)return!0;if(typeof e!="object"||typeof n!="object"||e==null||n==null)return!1;const s=Object.keys(e),r=Object.keys(n);if(s.length!==r.length)return!1;for(const a of s)if(!Object.prototype.hasOwnProperty.call(n,a)||e[a]!==n[a])return!1;return!0}Sn(zE,"shallowEqual");function UE(e,n){return!!(n.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}Sn(UE,"isElementPreceding");function fx(e,n){return!e[1].element||!n[1].element?0:UE(e[1].element,n[1].element)?-1:1}Sn(fx,"sortByDocumentPosition");function BE(e){return new MutationObserver(s=>{for(const r of s)if(r.type==="childList"){e();return}})}Sn(BE,"getChildListObserver");var eL=Object.defineProperty,tL=(e,n)=>eL(e,"name",{value:n,configurable:!0}),nL=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],St=nL.reduce((e,n)=>{const s=Xa(`Primitive.${n}`),r=d.forwardRef((a,i)=>{const{asChild:l,...o}=a,c=l?s:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),t.jsx(c,{...o,ref:i})});return r.displayName=`Primitive.${n}`,{...e,[n]:r}},{});function Mf(e,n){e&&xo.flushSync(()=>e.dispatchEvent(n))}tL(Mf,"dispatchDiscreteCustomEvent");var sL=Object.defineProperty,rL=(e,n)=>sL(e,"name",{value:n,configurable:!0});function Zn(e){const n=d.useRef(e);return d.useEffect(()=>{n.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}rL(Zn,"useCallbackRef");var aL=Object.defineProperty,gn=(e,n)=>aL(e,"name",{value:n,configurable:!0}),mx="dismissableLayer.update",iL="dismissableLayer.pointerDownOutside",lL="dismissableLayer.focusOutside",Jk,Zj=d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),Of=d.forwardRef(gn(function(n,s){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:a=!1,onEscapeKeyDown:i,onPointerDownOutside:l,onFocusOutside:o,onInteractOutside:c,onDismiss:u,...h}=n,f=d.useContext(Zj),[m,p]=d.useState(null),g=(m==null?void 0:m.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,x]=d.useState({}),k=Rt(s,p),j=Array.from(f.layers),[v]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),w=v?j.indexOf(v):-1,y=m?j.indexOf(m):-1,N=f.layersWithOutsidePointerEventsDisabled.size>0,b=y>=w,S=d.useRef(!1),C=HE(M=>{l==null||l(M),c==null||c(M),M.defaultPrevented||u==null||u()},{ownerDocument:g,deferPointerDownOutside:a,isDeferredPointerDownOutsideRef:S,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:d.useCallback(M=>{if(!(M instanceof Node))return!1;const O=[...f.branches].some(I=>I.contains(M));return b&&!O},[f.branches,b])}),T=KE(M=>{if(a&&S.current)return;const O=M.target;[...f.branches].some(z=>z.contains(O))||(o==null||o(M),c==null||c(M),M.defaultPrevented||u==null||u())},g),E=m?y===j.length-1:!1,R=Zn(M=>{M.key==="Escape"&&(i==null||i(M),!M.defaultPrevented&&u&&(M.preventDefault(),u()))});return d.useEffect(()=>{if(E)return g.addEventListener("keydown",R,{capture:!0}),()=>g.removeEventListener("keydown",R,{capture:!0})},[g,E,R]),d.useEffect(()=>{if(m)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Jk=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(m)),f.layers.add(m),px(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(m),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=Jk))}},[m,g,r,f]),d.useEffect(()=>()=>{m&&(f.layers.delete(m),f.layersWithOutsidePointerEventsDisabled.delete(m),px())},[m,f]),d.useEffect(()=>{const M=gn(()=>x({}),"handleUpdate");return document.addEventListener(mx,M),()=>document.removeEventListener(mx,M)},[]),t.jsx(St.div,{...h,ref:k,style:{pointerEvents:N?b?"auto":"none":void 0,...n.style},onFocusCapture:Be(n.onFocusCapture,T.onFocusCapture),onBlurCapture:Be(n.onBlurCapture,T.onBlurCapture),onPointerDownCapture:Be(n.onPointerDownCapture,C.onPointerDownCapture)})},"DismissableLayer")),oL=d.forwardRef(gn(function(n,s){const r=d.useContext(Zj),a=d.useRef(null),i=Rt(s,a);return d.useEffect(()=>{const l=a.current;if(l)return r.branches.add(l),()=>{r.branches.delete(l)}},[r.branches]),t.jsx(St.div,{...n,ref:i})},"DismissableLayerBranch"));function WE(){const e=d.useContext(Zj),[n,s]=d.useState(null);return d.useEffect(()=>{if(n)return e.dismissableSurfaces.add(n),()=>{e.dismissableSurfaces.delete(n)}},[n,e.dismissableSurfaces]),s}gn(WE,"useDismissableLayerSurface");var cL=gn(()=>!0,"IS_TRUE");function HE(e,n){const{ownerDocument:s=globalThis==null?void 0:globalThis.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:a,dismissableSurfaces:i,shouldHandlePointerDownOutside:l=cL}=n,o=Zn(e),c=d.useRef(!1),u=d.useRef(!1),h=d.useRef(new Map),f=d.useRef(()=>{});return d.useEffect(()=>{function m(){u.current=!1,a.current=!1,h.current.clear()}gn(m,"resetOutsideInteraction");function p(){return Array.from(h.current.values()).some(Boolean)}gn(p,"isOutsideInteractionIntercepted");function g(w){if(!u.current)return;const y=w.target;y instanceof Node&&[...i].some(b=>b.contains(y))||h.current.set(w.type,!0),w.type==="click"&&window.setTimeout(()=>{u.current&&f.current()},0)}gn(g,"handleInteractionCapture");function x(w){u.current&&h.current.set(w.type,!1)}gn(x,"handleInteractionBubble");const k=gn(w=>{if(w.target&&!c.current){let y=function(){s.removeEventListener("click",f.current);const b=p();m(),b||ew(iL,o,N,{discrete:!0})};if(gn(y,"handleAndDispatchPointerDownOutsideEvent"),!l(w.target)){s.removeEventListener("click",f.current),m(),c.current=!1;return}const N={originalEvent:w};u.current=!0,a.current=r&&w.button===0,h.current.clear(),!r||w.button!==0?y():(s.removeEventListener("click",f.current),f.current=y,s.addEventListener("click",f.current,{once:!0}))}else s.removeEventListener("click",f.current),m();c.current=!1},"handlePointerDown"),j=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const w of j)s.addEventListener(w,g,!0),s.addEventListener(w,x);const v=window.setTimeout(()=>{s.addEventListener("pointerdown",k)},0);return()=>{window.clearTimeout(v),s.removeEventListener("pointerdown",k),s.removeEventListener("click",f.current);for(const w of j)s.removeEventListener(w,g,!0),s.removeEventListener(w,x)}},[s,o,r,a,i,l]),{onPointerDownCapture:gn(()=>c.current=!0,"onPointerDownCapture")}}gn(HE,"usePointerDownOutside");function KE(e,n=globalThis==null?void 0:globalThis.document){const s=Zn(e),r=d.useRef(!1);return d.useEffect(()=>{const a=gn(i=>{i.target&&!r.current&&ew(lL,s,{originalEvent:i},{discrete:!1})},"handleFocus");return n.addEventListener("focusin",a),()=>n.removeEventListener("focusin",a)},[n,s]),{onFocusCapture:gn(()=>r.current=!0,"onFocusCapture"),onBlurCapture:gn(()=>r.current=!1,"onBlurCapture")}}gn(KE,"useFocusOutside");function px(){const e=new CustomEvent(mx);document.dispatchEvent(e)}gn(px,"dispatchUpdate");function ew(e,n,s,{discrete:r}){const a=s.originalEvent.target,i=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:s});n&&a.addEventListener(e,n,{once:!0}),r?Mf(a,i):a.dispatchEvent(i)}gn(ew,"handleAndDispatchCustomEvent");var uL=Of,dL=oL,ds=globalThis!=null&&globalThis.document?d.useLayoutEffect:()=>{},hL=Object.defineProperty,fL=(e,n)=>hL(e,"name",{value:n,configurable:!0}),Df=d.forwardRef(fL(function(n,s){var c;const{container:r,...a}=n,[i,l]=d.useState(!1);ds(()=>l(!0),[]);const o=r||i&&((c=globalThis==null?void 0:globalThis.document)==null?void 0:c.body);return o?xo.createPortal(t.jsx(St.div,{...a,ref:s}),o):null},"Portal")),mL=Object.defineProperty,ga=(e,n)=>mL(e,"name",{value:n,configurable:!0});function VE(e,n){return d.useReducer((s,r)=>n[s][r]??s,e)}ga(VE,"useStateMachine");var Kr=ga(e=>{const{present:n,children:s}=e,r=GE(n),a=typeof s=="function"?s({present:r.isPresent}):d.Children.only(s),i=YE(r.ref,qE(a));return typeof s=="function"||r.isPresent?d.cloneElement(a,{ref:i}):null},"Presence");function GE(e){const[n,s]=d.useState(),r=d.useRef(null),a=d.useRef(e),i=d.useRef("none"),l=d.useRef(void 0),o=e?"mounted":"unmounted",[c,u]=VE(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return d.useEffect(()=>{c==="mounted"?(i.current=l.current??vl(r.current),l.current=void 0):i.current="none"},[c]),ds(()=>{const h=r.current,f=a.current;if(f!==e){const p=i.current,g=vl(h);e?(l.current=g,u("MOUNT")):g==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&p!==g?"ANIMATION_OUT":"UNMOUNT"),a.current=e}},[e,u]),ds(()=>{if(n){let h;const f=n.ownerDocument.defaultView??window,m=ga(g=>{const k=vl(r.current).includes(CSS.escape(g.animationName));if(g.target===n&&k&&(u("ANIMATION_END"),!a.current)){const j=n.style.animationFillMode;n.style.animationFillMode="forwards",h=f.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=j)})}},"handleAnimationEnd"),p=ga(g=>{g.target===n&&(i.current=vl(r.current))},"handleAnimationStart");return n.addEventListener("animationstart",p),n.addEventListener("animationcancel",m),n.addEventListener("animationend",m),()=>{f.clearTimeout(h),n.removeEventListener("animationstart",p),n.removeEventListener("animationcancel",m),n.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[n,u]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:d.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,l.current=vl(f)}else r.current=null;s(h)},[])}}ga(GE,"usePresence");function gx(e,n){if(typeof e=="function")return e(n);e!=null&&(e.current=n)}ga(gx,"setRef");function YE(...e){const n=d.useRef(e);return n.current=e,d.useCallback(s=>{const r=n.current;let a=!1;const i=r.map(l=>{const o=gx(l,s);return!a&&typeof o=="function"&&(a=!0),o});if(a)return()=>{for(let l=0;l<i.length;l++){const o=i[l];typeof o=="function"?o():gx(r[l],null)}}},[])}ga(YE,"useStableComposedRefs");function vl(e){return(e==null?void 0:e.animationName)||"none"}ga(vl,"getAnimationName");function qE(e){var r,a;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,s=n&&"isReactWarning"in n&&n.isReactWarning;return s?e.ref:(n=(a=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:a.get,s=n&&"isReactWarning"in n&&n.isReactWarning,s?e.props.ref:e.props.ref||e.ref)}ga(qE,"getElementRef");var pL=Object.defineProperty,gL=(e,n)=>pL(e,"name",{value:n,configurable:!0}),Xk=mo[" useEffectEvent ".trim().toString()],Zk=mo[" useInsertionEffect ".trim().toString()];function QE(e){if(typeof Xk=="function")return Xk(e);const n=d.useRef(()=>{throw new Error("Cannot call an event handler while rendering.")});return typeof Zk=="function"?Zk(()=>{n.current=e}):ds(()=>{n.current=e}),d.useMemo(()=>(...s)=>{var r;return(r=n.current)==null?void 0:r.call(n,...s)},[])}gL(QE,"useEffectEvent");var xL=Object.defineProperty,vu=(e,n)=>xL(e,"name",{value:n,configurable:!0}),vL=mo[" useInsertionEffect ".trim().toString()]||ds;function ci({prop:e,defaultProp:n,onChange:s=vu(()=>{},"onChange"),caller:r}){const[a,i,l]=JE({defaultProp:n,onChange:s}),o=e!==void 0,c=o?e:a,u=d.useCallback(h=>{var f;if(o){const m=XE(h)?h(e):h;m!==e&&((f=l.current)==null||f.call(l,m))}else i(h)},[o,e,i,l]);return[c,u]}vu(ci,"useControllableState");function JE({defaultProp:e,onChange:n}){const[s,r]=d.useState(e),a=d.useRef(s),i=d.useRef(n);return vL(()=>{i.current=n},[n]),d.useEffect(()=>{var l;a.current!==s&&((l=i.current)==null||l.call(i,s),a.current=s)},[s,a]),[s,r,i]}vu(JE,"useUncontrolledState");function XE(e){return typeof e=="function"}vu(XE,"isFunction");var e0=Symbol("RADIX:SYNC_STATE");function jL(e,n,s,r){const{prop:a,defaultProp:i,onChange:l,caller:o}=n,c=a!==void 0,u=QE(l),h=[{...s,state:i}];r&&h.push(r);const[f,m]=d.useReducer((k,j)=>{if(j.type===e0)return{...k,state:j.state};const v=e(k,j);return c&&!Object.is(v.state,k.state)&&u(v.state),v},...h),p=f.state,g=d.useRef(p);d.useEffect(()=>{g.current!==p&&(g.current=p,c||u(p))},[p,g,c]);const x=d.useMemo(()=>a!==void 0?{...f,state:a}:f,[f,a]);return d.useEffect(()=>{c&&!Object.is(a,f.state)&&m({type:e0,state:a})},[a,f.state,c]),[x,m]}vu(jL,"useControllableStateReducer");var wL=Object.defineProperty,yL=(e,n)=>wL(e,"name",{value:n,configurable:!0}),bL=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"}),tw=d.forwardRef(yL(function(n,s){return t.jsx(St.span,{...n,ref:s,style:{...bL,...n.style}})},"VisuallyHidden")),kL=tw,NL=Object.defineProperty,$t=(e,n)=>NL(e,"name",{value:n,configurable:!0}),ZE="ToastProvider",[nw,e$,SL]=Pf("Toast"),[t$,Lse]=vr("Toast",[SL]),[CL,Lf]=t$(ZE),EL=$t(e=>{const{__scopeToast:n,label:s="Notification",duration:r=5e3,swipeDirection:a="right",swipeThreshold:i=50,announcerContainer:l,children:o}=e,[c,u]=d.useState(null),[h,f]=d.useState(0),m=d.useRef(!1);return s.trim()||console.error(`Invalid prop \`label\` supplied to \`${ZE}\`. Expected non-empty \`string\`.`),t.jsx(nw.Provider,{scope:n,children:t.jsx(CL,{scope:n,label:s,duration:r,swipeDirection:a,swipeThreshold:i,toastCount:h,viewport:c,onViewportChange:u,onToastAdd:d.useCallback(()=>f(p=>p+1),[]),onToastRemove:d.useCallback(()=>f(p=>p-1),[]),isClosePausedRef:m,announcerContainer:l,children:o})})},"ToastProvider"),$L="ToastViewport",AL=["F8"],xx="toast.viewportPause",vx="toast.viewportResume",TL=d.forwardRef($t(function(n,s){const{__scopeToast:r,hotkey:a=AL,label:i="Notifications ({hotkey})",...l}=n,o=Lf($L,r),c=e$(r),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef(null),p=Rt(s,m,o.onViewportChange),g=a.join("+").replace(/Key/g,"").replace(/Digit/g,""),x=o.toastCount>0;d.useEffect(()=>{const j=$t(v=>{var y;a.length!==0&&a.every(N=>v[N]||v.code===N)&&((y=m.current)==null||y.focus())},"handleKeyDown");return document.addEventListener("keydown",j),()=>document.removeEventListener("keydown",j)},[a]),d.useEffect(()=>{const j=u.current,v=m.current;if(x&&j&&v){const w=$t(()=>{if(!o.isClosePausedRef.current){const S=new CustomEvent(xx);v.dispatchEvent(S),o.isClosePausedRef.current=!0}},"handlePause"),y=$t(()=>{if(o.isClosePausedRef.current){const S=new CustomEvent(vx);v.dispatchEvent(S),o.isClosePausedRef.current=!1}},"handleResume"),N=$t(S=>{!j.contains(S.relatedTarget)&&y()},"handleFocusOutResume"),b=$t(()=>{j.contains(document.activeElement)||y()},"handlePointerLeaveResume");return j.addEventListener("focusin",w),j.addEventListener("focusout",N),j.addEventListener("pointermove",w),j.addEventListener("pointerleave",b),window.addEventListener("blur",w),window.addEventListener("focus",y),()=>{j.removeEventListener("focusin",w),j.removeEventListener("focusout",N),j.removeEventListener("pointermove",w),j.removeEventListener("pointerleave",b),window.removeEventListener("blur",w),window.removeEventListener("focus",y)}}},[x,o.isClosePausedRef]);const k=d.useCallback(({tabbingDirection:j})=>{const w=c().map(y=>{const N=y.ref.current,b=[N,...a$(N)];return j==="forwards"?b:b.reverse()});return(j==="forwards"?w.reverse():w).flat()},[c]);return d.useEffect(()=>{const j=m.current;if(j){const v=$t(w=>{var b,S,C;const y=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!y){const T=document.activeElement,E=w.shiftKey;if(w.target===j&&E){(b=h.current)==null||b.focus();return}const O=k({tabbingDirection:E?"backwards":"forwards"}),I=O.findIndex(z=>z===T);Hd(O.slice(I+1))?w.preventDefault():E?(S=h.current)==null||S.focus():(C=f.current)==null||C.focus()}},"handleKeyDown");return j.addEventListener("keydown",v),()=>j.removeEventListener("keydown",v)}},[c,k]),t.jsxs(dL,{ref:u,role:"region","aria-label":i.replace("{hotkey}",g),tabIndex:-1,style:{pointerEvents:x?void 0:"none"},children:[x&&t.jsx(t0,{ref:h,onFocusFromOutsideViewport:()=>{const j=k({tabbingDirection:"forwards"});Hd(j)}}),t.jsx(nw.Slot,{scope:r,children:t.jsx(St.ol,{tabIndex:-1,...l,ref:p})}),x&&t.jsx(t0,{ref:f,onFocusFromOutsideViewport:()=>{const j=k({tabbingDirection:"backwards"});Hd(j)}})]})},"ToastViewport")),RL="ToastFocusProxy",t0=d.forwardRef($t(function(n,s){const{__scopeToast:r,onFocusFromOutsideViewport:a,...i}=n,l=Lf(RL,r);return t.jsx(tw,{tabIndex:0,...i,ref:s,style:{position:"fixed"},onFocus:o=>{var h;const c=o.relatedTarget;!((h=l.viewport)!=null&&h.contains(c))&&a()}})},"ToastFocusProxy")),Ff="Toast",IL="toast.swipeStart",PL="toast.swipeMove",ML="toast.swipeCancel",OL="toast.swipeEnd",DL=d.forwardRef($t(function(n,s){const{forceMount:r,open:a,defaultOpen:i,onOpenChange:l,...o}=n,[c,u]=ci({prop:a,defaultProp:i??!0,onChange:l,caller:Ff});return t.jsx(Kr,{present:r||c,children:t.jsx(_L,{open:c,...o,ref:s,onClose:()=>u(!1),onPause:Zn(n.onPause),onResume:Zn(n.onResume),onSwipeStart:Be(n.onSwipeStart,h=>{h.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:Be(n.onSwipeMove,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","move"),h.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${m}px`)}),onSwipeCancel:Be(n.onSwipeCancel,h=>{h.currentTarget.setAttribute("data-swipe","cancel"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:Be(n.onSwipeEnd,h=>{const{x:f,y:m}=h.detail.delta;h.currentTarget.setAttribute("data-swipe","end"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),h.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),h.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${f}px`),h.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${m}px`),u(!1)})})})},"Toast")),[LL,FL]=t$(Ff,{onClose(){}}),_L=d.forwardRef($t(function(n,s){const{__scopeToast:r,type:a="foreground",duration:i,open:l,onClose:o,onEscapeKeyDown:c,onPause:u,onResume:h,onSwipeStart:f,onSwipeMove:m,onSwipeCancel:p,onSwipeEnd:g,...x}=n,k=Lf(Ff,r),j=e$(r),[v,w]=d.useState(null),y=Rt(s,w),N=d.useRef(null),b=d.useRef(null),S=i||k.duration,C=d.useRef(0),T=d.useRef(S),E=d.useRef(0),{onToastAdd:R,onToastRemove:M}=k,O=Zn(()=>{var D;(v==null?void 0:v.contains(document.activeElement))&&((D=k.viewport)==null||D.focus()),o()}),I=d.useCallback(U=>{!U||U===1/0||(window.clearTimeout(E.current),C.current=new Date().getTime(),E.current=window.setTimeout(O,U))},[O]);d.useEffect(()=>{const U=k.viewport;if(U){const D=$t(()=>{I(T.current),h==null||h()},"handleResume"),P=$t(()=>{const K=new Date().getTime()-C.current;T.current=T.current-K,window.clearTimeout(E.current),u==null||u()},"handlePause");return U.addEventListener(xx,P),U.addEventListener(vx,D),()=>{U.removeEventListener(xx,P),U.removeEventListener(vx,D)}}},[k.viewport,S,u,h,I]),d.useEffect(()=>{l&&!k.isClosePausedRef.current&&I(S)},[l,S,k.isClosePausedRef,I]),d.useEffect(()=>()=>{window.clearTimeout(E.current)},[]),d.useEffect(()=>(R(),()=>M()),[R,M]);const z=d.useMemo(()=>v?sw(v):null,[v]);return k.viewport?t.jsxs(t.Fragment,{children:[z&&t.jsx(zL,{__scopeToast:r,role:"status","aria-live":a==="foreground"?"assertive":"polite",children:z}),t.jsx(LL,{scope:r,onClose:O,children:xo.createPortal(t.jsx(nw.ItemSlot,{scope:r,children:t.jsx(uL,{asChild:!0,onEscapeKeyDown:Be(c,U=>{j().some(P=>{var K;return(K=P.ref.current)==null?void 0:K.contains(U.target)})||O()}),children:t.jsx(St.li,{tabIndex:0,"data-state":l?"open":"closed","data-swipe-direction":k.swipeDirection,...x,ref:y,style:{userSelect:"none",touchAction:"none",...n.style},onKeyDown:Be(n.onKeyDown,U=>{U.key==="Escape"&&(c==null||c(U.nativeEvent),U.nativeEvent.defaultPrevented||O())}),onPointerDown:Be(n.onPointerDown,U=>{U.button===0&&(N.current={x:U.clientX,y:U.clientY})}),onPointerMove:Be(n.onPointerMove,U=>{if(!N.current)return;const D=U.clientX-N.current.x,P=U.clientY-N.current.y,K=!!b.current,F=["left","right"].includes(k.swipeDirection),Q=["left","up"].includes(k.swipeDirection)?Math.min:Math.max,_=F?Q(0,D):0,re=F?0:Q(0,P),Y=U.pointerType==="touch"?10:2,B={x:_,y:re},q={originalEvent:U,delta:B};K?(b.current=B,nc(PL,m,q,{discrete:!1})):n0(B,k.swipeDirection,Y)?(b.current=B,nc(IL,f,q,{discrete:!1}),U.target.setPointerCapture(U.pointerId)):(Math.abs(D)>Y||Math.abs(P)>Y)&&(N.current=null)}),onPointerUp:Be(n.onPointerUp,U=>{const D=b.current,P=U.target;if(P.hasPointerCapture(U.pointerId)&&P.releasePointerCapture(U.pointerId),b.current=null,N.current=null,D){const K=U.currentTarget,F={originalEvent:U,delta:D};n0(D,k.swipeDirection,k.swipeThreshold)?nc(OL,g,F,{discrete:!0}):nc(ML,p,F,{discrete:!0}),K.addEventListener("click",Q=>Q.preventDefault(),{once:!0})}})})})}),k.viewport)})]}):null},"ToastImpl")),zL=$t(e=>{const{__scopeToast:n,children:s,...r}=e,a=Lf(Ff,n),[i,l]=d.useState(!1),[o,c]=d.useState(!1);return s$(()=>l(!0)),d.useEffect(()=>{const u=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(u)},[]),o?null:t.jsx(Df,{asChild:!0,container:a.announcerContainer||void 0,children:t.jsx(tw,{...r,children:i&&t.jsxs(t.Fragment,{children:[a.label," ",s]})})})},"ToastAnnounce"),UL=d.forwardRef($t(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"ToastTitle")),BL=d.forwardRef($t(function(n,s){const{__scopeToast:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"ToastDescription")),WL="ToastAction",HL=d.forwardRef($t(function(n,s){const{altText:r,...a}=n;return r.trim()?t.jsx(n$,{altText:r,asChild:!0,children:t.jsx(VL,{...a,ref:s})}):(console.error(`Invalid prop \`altText\` supplied to \`${WL}\`. Expected non-empty \`string\`.`),null)},"ToastAction")),KL="ToastClose",VL=d.forwardRef($t(function(n,s){const{__scopeToast:r,...a}=n,i=FL(KL,r);return t.jsx(n$,{asChild:!0,children:t.jsx(St.button,{type:"button",...a,ref:s,onClick:Be(n.onClick,i.onClose)})})},"ToastClose")),n$=d.forwardRef($t(function(n,s){const{__scopeToast:r,altText:a,...i}=n;return t.jsx(St.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":a||void 0,...i,ref:s})},"ToastAnnounceExclude"));function sw(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),r$(r)){const a=r.ariaHidden||r.hidden||r.style.display==="none",i=r.dataset.radixToastAnnounceExclude==="";if(!a)if(i){const l=r.dataset.radixToastAnnounceAlt;l&&n.push(l)}else n.push(...sw(r))}}),n}$t(sw,"getAnnounceTextContent");function nc(e,n,s,{discrete:r}){const a=s.originalEvent.currentTarget,i=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:s});n&&a.addEventListener(e,n,{once:!0}),r?Mf(a,i):a.dispatchEvent(i)}$t(nc,"handleAndDispatchCustomEvent");var n0=$t((e,n,s=0)=>{const r=Math.abs(e.x),a=Math.abs(e.y),i=r>a;return n==="left"||n==="right"?i&&r>s:!i&&a>s},"isDeltaInDirection");function s$(e=()=>{}){const n=Zn(e);ds(()=>{let s=0,r=0;return s=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(s),window.cancelAnimationFrame(r)}},[n])}$t(s$,"useNextFrame");function r$(e){return e.nodeType===e.ELEMENT_NODE}$t(r$,"isHTMLElement");function a$(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:$t(r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)n.push(s.currentNode);return n}$t(a$,"getTabbableCandidates");function Hd(e){const n=document.activeElement;return e.some(s=>s===n?!0:(s.focus(),document.activeElement!==n))}$t(Hd,"focusFirst");var s0=EL,r0=TL,GL=DL,YL=UL,qL=BL,QL=HL,JL=Object.defineProperty,XL=(e,n)=>JL(e,"name",{value:n,configurable:!0}),ZL=mo[" useId ".trim().toString()]||(()=>{}),eF=0;function ur(e){const[n,s]=d.useState(ZL());return ds(()=>{e||s(r=>r??String(eF++))},[e]),e||(n?`radix-${n}`:"")}XL(ur,"useId");const tF=["top","right","bottom","left"],Za=Math.min,ca=Math.max,Th=Math.round,rd=Math.floor,ua=e=>({x:e,y:e}),nF={left:"right",right:"left",bottom:"top",top:"bottom"};function i$(e,n,s){return ca(e,Za(n,s))}function xa(e,n){return typeof e=="function"?e(n):e}function ei(e){return e.split("-")[0]}function jo(e){return e.split("-")[1]}function rw(e){return e==="x"?"y":"x"}function aw(e){return e==="y"?"height":"width"}function Ar(e){const n=e[0];return n==="t"||n==="b"?"y":"x"}function iw(e){return rw(Ar(e))}function sF(e,n,s){s===void 0&&(s=!1);const r=jo(e),a=iw(e),i=aw(a);let l=a==="x"?r===(s?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[i]>n.floating[i]&&(l=Rh(l)),[l,Rh(l)]}function rF(e){const n=Rh(e);return[jx(e),n,jx(n)]}function jx(e){return e.includes("start")?e.replace("start","end"):e.replace("end","start")}const a0=["left","right"],i0=["right","left"],aF=["top","bottom"],iF=["bottom","top"];function lF(e,n,s){switch(e){case"top":case"bottom":return s?n?i0:a0:n?a0:i0;case"left":case"right":return n?aF:iF;default:return[]}}function oF(e,n,s,r){const a=jo(e);let i=lF(ei(e),s==="start",r);return a&&(i=i.map(l=>l+"-"+a),n&&(i=i.concat(i.map(jx)))),i}function Rh(e){const n=ei(e);return nF[n]+e.slice(n.length)}function cF(e){var n,s,r,a;return{top:(n=e.top)!=null?n:0,right:(s=e.right)!=null?s:0,bottom:(r=e.bottom)!=null?r:0,left:(a=e.left)!=null?a:0}}function l$(e){return typeof e!="number"?cF(e):{top:e,right:e,bottom:e,left:e}}function Ih(e){const{x:n,y:s,width:r,height:a}=e;return{width:r,height:a,top:s,left:n,right:n+r,bottom:s+a,x:n,y:s}}function l0(e,n,s){let{reference:r,floating:a}=e;const i=Ar(n),l=iw(n),o=aw(l),c=ei(n),u=i==="y",h=r.x+r.width/2-a.width/2,f=r.y+r.height/2-a.height/2,m=r[o]/2-a[o]/2;let p;switch(c){case"top":p={x:h,y:r.y-a.height};break;case"bottom":p={x:h,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-a.width,y:f};break;default:p={x:r.x,y:r.y}}const g=jo(n);return g&&(p[l]+=m*(g==="end"?1:-1)*(s&&u?-1:1)),p}async function uF(e,n){var s;n===void 0&&(n={});const{x:r,y:a,platform:i,rects:l,elements:o,strategy:c}=e,{boundary:u="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:m=!1,padding:p=0}=xa(n,e),g=l$(p),k=o[m?f==="floating"?"reference":"floating":f],j=Ih(await i.getClippingRect({element:(s=await(i.isElement==null?void 0:i.isElement(k)))==null||s?k:k.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:u,rootBoundary:h,strategy:c})),v=f==="floating"?{x:r,y:a,width:l.floating.width,height:l.floating.height}:l.reference,w=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),y=await(i.isElement==null?void 0:i.isElement(w))&&await(i.getScale==null?void 0:i.getScale(w))||{x:1,y:1},N=Ih(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:v,offsetParent:w,strategy:c}):v);return{top:(j.top-N.top+g.top)/y.y,bottom:(N.bottom-j.bottom+g.bottom)/y.y,left:(j.left-N.left+g.left)/y.x,right:(N.right-j.right+g.right)/y.x}}const dF=50,hF=async(e,n,s)=>{const{placement:r="bottom",strategy:a="absolute",middleware:i=[],platform:l}=s,o=l.detectOverflow?l:{...l,detectOverflow:uF},c=await(l.isRTL==null?void 0:l.isRTL(n));let u=await l.getElementRects({reference:e,floating:n,strategy:a}),{x:h,y:f}=l0(u,r,c),m=r,p=0;const g={};for(let x=0;x<i.length;x++){const k=i[x];if(!k)continue;const{name:j,fn:v}=k,{x:w,y,data:N,reset:b}=await v({x:h,y:f,initialPlacement:r,placement:m,strategy:a,middlewareData:g,rects:u,platform:o,elements:{reference:e,floating:n}});h=w??h,f=y??f,g[j]={...g[j],...N},b&&p<dF&&(p++,typeof b=="object"&&(b.placement&&(m=b.placement),b.rects&&(u=b.rects===!0?await l.getElementRects({reference:e,floating:n,strategy:a}):b.rects),{x:h,y:f}=l0(u,m,c)),x=-1)}return{x:h,y:f,placement:m,strategy:a,middlewareData:g}},fF=e=>({name:"arrow",options:e,async fn(n){const{x:s,y:r,placement:a,rects:i,platform:l,elements:o,middlewareData:c}=n,{element:u,padding:h=0}=xa(e,n)||{};if(u==null)return{};const f=l$(h),m={x:s,y:r},p=iw(a),g=aw(p),x=await l.getDimensions(u),k=p==="y",j=k?"top":"left",v=k?"bottom":"right",w=k?"clientHeight":"clientWidth",y=i.reference[g]+i.reference[p]-m[p]-i.floating[g],N=m[p]-i.reference[p],b=await(l.getOffsetParent==null?void 0:l.getOffsetParent(u));let S=b?b[w]:0;(!S||!await(l.isElement==null?void 0:l.isElement(b)))&&(S=o.floating[w]||i.floating[g]);const C=y/2-N/2,T=S/2-x[g]/2-1,E=Za(f[j],T),R=Za(f[v],T),M=S-x[g]-R,O=S/2-x[g]/2+C,I=i$(E,O,M),z=!c.arrow&&jo(a)!=null&&O!==I&&i.reference[g]/2-(O<E?E:R)-x[g]/2<0,U=z?O<E?O-E:O-M:0;return{[p]:m[p]+U,data:{[p]:I,centerOffset:O-I-U,...z&&{alignmentOffset:U}},reset:z}}}),mF=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var s,r;const{placement:a,middlewareData:i,rects:l,initialPlacement:o,platform:c,elements:u}=n,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:m,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:x=!0,...k}=xa(e,n);if((s=i.arrow)!=null&&s.alignmentOffset)return{};const j=ei(a),v=Ar(o),w=ei(o)===o,y=await(c.isRTL==null?void 0:c.isRTL(u.floating)),N=m||(w||!x?[Rh(o)]:rF(o)),b=g!=="none";!m&&b&&N.push(...oF(o,x,g,y));const S=[o,...N],C=await c.detectOverflow(n,k),T=[];let E=((r=i.flip)==null?void 0:r.overflows)||[];if(h&&T.push(C[j]),f){const I=sF(a,l,y);T.push(C[I[0]],C[I[1]])}if(E=[...E,{placement:a,overflows:T}],!T.every(I=>I<=0)){var R,M;const I=(((R=i.flip)==null?void 0:R.index)||0)+1,z=S[I];if(z&&(!(f==="alignment"?v!==Ar(z):!1)||E.every(P=>Ar(P.placement)===v?P.overflows[0]>0:!0)))return{data:{index:I,overflows:E},reset:{placement:z}};let U=(M=E.filter(D=>D.overflows[0]<=0).sort((D,P)=>D.overflows[1]-P.overflows[1])[0])==null?void 0:M.placement;if(!U)switch(p){case"bestFit":{var O;const D=(O=E.filter(P=>{if(b){const K=Ar(P.placement);return K===v||K==="y"}return!0}).map(P=>[P.placement,P.overflows.filter(K=>K>0).reduce((K,F)=>K+F,0)]).sort((P,K)=>P[1]-K[1])[0])==null?void 0:O[0];D&&(U=D);break}case"initialPlacement":U=o;break}if(a!==U)return{reset:{placement:U}}}return{}}}};function o0(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function c0(e){return tF.some(n=>e[n]>=0)}const pF=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:s,platform:r}=n,{strategy:a="referenceHidden",...i}=xa(e,n);switch(a){case"referenceHidden":{const l=await r.detectOverflow(n,{...i,elementContext:"reference"}),o=o0(l,s.reference);return{data:{referenceHiddenOffsets:o,referenceHidden:c0(o)}}}case"escaped":{const l=await r.detectOverflow(n,{...i,altBoundary:!0}),o=o0(l,s.floating);return{data:{escapedOffsets:o,escaped:c0(o)}}}default:return{}}}}},o$=new Set(["left","top"]);async function gF(e,n){const{placement:s,platform:r,elements:a}=e,i=await(r.isRTL==null?void 0:r.isRTL(a.floating)),l=ei(s),o=jo(s),c=Ar(s)==="y",u=o$.has(l)?-1:1,h=i&&c?-1:1,f=xa(n,e);let{mainAxis:m,crossAxis:p,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return o&&typeof g=="number"&&(p=o==="end"?g*-1:g),c?{x:p*h,y:m*u}:{x:m*u,y:p*h}}const xF=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var s,r;const{x:a,y:i,placement:l,middlewareData:o}=n,c=await gF(n,e);return l===((s=o.offset)==null?void 0:s.placement)&&(r=o.arrow)!=null&&r.alignmentOffset?{}:{x:a+c.x,y:i+c.y,data:{...c,placement:l}}}}},vF=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:s,y:r,placement:a,platform:i}=n,{mainAxis:l=!0,crossAxis:o=!1,limiter:c={fn:v=>{let{x:w,y}=v;return{x:w,y}}},...u}=xa(e,n),h={x:s,y:r},f=await i.detectOverflow(n,u),m=Ar(a),p=rw(m);let g=h[p],x=h[m];const k=(v,w)=>i$(w+f[v==="y"?"top":"left"],w,w-f[v==="y"?"bottom":"right"]);l&&(g=k(p,g)),o&&(x=k(m,x));const j=c.fn({...n,[p]:g,[m]:x});return{...j,data:{x:j.x-s,y:j.y-r,enabled:{[p]:l,[m]:o}}}}}},jF=function(e){return e===void 0&&(e={}),{options:e,fn(n){var s,r;const{x:a,y:i,placement:l,rects:o,middlewareData:c}=n,{offset:u=0,mainAxis:h=!0,crossAxis:f=!0}=xa(e,n),m={x:a,y:i},p=Ar(l),g=rw(p);let x=m[g],k=m[p];const j=xa(u,n),v=typeof j=="number"?{mainAxis:j,crossAxis:0}:{mainAxis:(s=j.mainAxis)!=null?s:0,crossAxis:(r=j.crossAxis)!=null?r:0};if(h){const N=g==="y"?"height":"width",b=o.reference[g]-o.floating[N]+v.mainAxis,S=o.reference[g]+o.reference[N]-v.mainAxis;x<b?x=b:x>S&&(x=S)}if(f){var w,y;const N=g==="y"?"width":"height",b=o$.has(ei(l)),S=o.reference[p]-o.floating[N]+(b&&((w=c.offset)==null?void 0:w[p])||0)+(b?0:v.crossAxis),C=o.reference[p]+o.reference[N]+(b?0:((y=c.offset)==null?void 0:y[p])||0)-(b?v.crossAxis:0);k<S?k=S:k>C&&(k=C)}return{[g]:x,[p]:k}}}},wF=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:s,rects:r,platform:a,elements:i}=n,{apply:l=()=>{},...o}=xa(e,n),c=await a.detectOverflow(n,o),u=ei(s),h=jo(s),f=Ar(s)==="y",{width:m,height:p}=r.floating;let g,x;u==="top"||u==="bottom"?(g=u,x=h===(await(a.isRTL==null?void 0:a.isRTL(i.floating))?"start":"end")?"left":"right"):(x=u,g=h==="end"?"top":"bottom");const k=p-c.top-c.bottom,j=m-c.left-c.right,v=Za(p-c[g],k),w=Za(m-c[x],j),y=n.middlewareData.shift,N=!y;let b=v,S=w;y!=null&&y.enabled.x&&(S=j),y!=null&&y.enabled.y&&(b=k),N&&!h&&(f?S=m-2*ca(c.left,c.right):b=p-2*ca(c.top,c.bottom)),await l({...n,availableWidth:S,availableHeight:b});const C=await a.getDimensions(i.floating);return m!==C.width||p!==C.height?{reset:{rects:!0}}:{}}}};function _f(){return typeof window<"u"}function wo(e){return c$(e)?(e.nodeName||"").toLowerCase():"#document"}function hs(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function wa(e){var n;return(n=(c$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function c$(e){return _f()?e instanceof Node||e instanceof hs(e).Node:!1}function Dr(e){return _f()?e instanceof Element||e instanceof hs(e).Element:!1}function ui(e){return _f()?e instanceof HTMLElement||e instanceof hs(e).HTMLElement:!1}function u0(e){return!_f()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof hs(e).ShadowRoot}function zf(e){const{overflow:n,overflowX:s,overflowY:r,display:a}=Lr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+s)&&a!=="inline"&&a!=="contents"}function yF(e){return/^(table|td|th)$/.test(wo(e))}function Uf(e){try{if(e.matches(":popover-open"))return!0}catch{}try{return e.matches(":modal")}catch{return!1}}const bF=/transform|translate|scale|rotate|perspective|filter/,kF=/paint|layout|strict|content/,vi=e=>!!e&&e!=="none";let op;function lw(e){const n=Dr(e)?Lr(e):e;return vi(n.transform)||vi(n.translate)||vi(n.scale)||vi(n.rotate)||vi(n.perspective)||!ow()&&(vi(n.backdropFilter)||vi(n.filter))||bF.test(n.willChange||"")||kF.test(n.contain||"")}function NF(e){let n=Ui(e);for(;ui(n)&&!Bc(n);){if(lw(n))return n;if(Uf(n))return null;n=Ui(n)}return null}function ow(){return op==null&&(op=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),op}function Bc(e){return/^(html|body|#document)$/.test(wo(e))}function Lr(e){return hs(e).getComputedStyle(e)}function Bf(e){return Dr(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Ui(e){if(wo(e)==="html")return e;const n=e.assignedSlot||e.parentNode||u0(e)&&e.host||wa(e);return u0(n)?n.host:n}function u$(e){const n=Ui(e);return Bc(n)?(e.ownerDocument||e).body:ui(n)&&zf(n)?n:u$(n)}function Wc(e,n,s){var r;n===void 0&&(n=[]),s===void 0&&(s=!0);const a=u$(e),i=a===((r=e.ownerDocument)==null?void 0:r.body),l=hs(a);if(i){const o=wx(l);return n.concat(l,l.visualViewport||[],zf(a)?a:[],o&&s?Wc(o):[])}else return n.concat(a,Wc(a,[],s))}function wx(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function d$(e){const n=Lr(e);let s=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const a=ui(e),i=a?e.offsetWidth:s,l=a?e.offsetHeight:r,o=Th(s)!==i||Th(r)!==l;return o&&(s=i,r=l),{width:s,height:r,$:o}}function cw(e){return Dr(e)?e:e.contextElement}function Ul(e){const n=cw(e);if(!ui(n))return ua(1);const s=n.getBoundingClientRect(),{width:r,height:a,$:i}=d$(n);let l=(i?Th(s.width):s.width)/r,o=(i?Th(s.height):s.height)/a;return(!l||!Number.isFinite(l))&&(l=1),(!o||!Number.isFinite(o))&&(o=1),{x:l,y:o}}const SF=ua(0);function h$(e){const n=hs(e);return!ow()||!n.visualViewport?SF:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function CF(e,n,s){return n===void 0&&(n=!1),!!s&&n&&s===hs(e)}function Bi(e,n,s,r){n===void 0&&(n=!1),s===void 0&&(s=!1);const a=e.getBoundingClientRect(),i=cw(e);let l=ua(1);n&&(r?Dr(r)&&(l=Ul(r)):l=Ul(e));const o=CF(i,s,r)?h$(i):ua(0);let c=(a.left+o.x)/l.x,u=(a.top+o.y)/l.y,h=a.width/l.x,f=a.height/l.y;if(i&&r){const m=hs(i),p=Dr(r)?hs(r):r;let g=m,x=wx(g);for(;x&&p!==g;){const k=Ul(x),j=x.getBoundingClientRect(),v=Lr(x),w=j.left+(x.clientLeft+parseFloat(v.paddingLeft))*k.x,y=j.top+(x.clientTop+parseFloat(v.paddingTop))*k.y;c*=k.x,u*=k.y,h*=k.x,f*=k.y,c+=w,u+=y,g=hs(x),x=wx(g)}}return Ih({width:h,height:f,x:c,y:u})}function Wf(e,n){const s=Bf(e).scrollLeft;return n?n.left+s:Bi(wa(e)).left+s}function f$(e,n){const s=e.getBoundingClientRect(),r=s.left+n.scrollLeft-Wf(e,s),a=s.top+n.scrollTop;return{x:r,y:a}}function EF(e){let{elements:n,rect:s,offsetParent:r,strategy:a}=e;const i=a==="fixed",l=wa(r),o=n?Uf(n.floating):!1;if(r===l||o&&i)return s;let c={scrollLeft:0,scrollTop:0},u=ua(1);const h=ua(0),f=ui(r);if((f||!i)&&((wo(r)!=="body"||zf(l))&&(c=Bf(r)),f)){const p=Bi(r);u=Ul(r),h.x=p.x+r.clientLeft,h.y=p.y+r.clientTop}const m=l&&!f&&!i?f$(l,c):ua(0);return{width:s.width*u.x,height:s.height*u.y,x:s.x*u.x-c.scrollLeft*u.x+h.x+m.x,y:s.y*u.y-c.scrollTop*u.y+h.y+m.y}}function $F(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function AF(e){const n=Bf(e),s=e.ownerDocument.body,r=ca(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),a=ca(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let i=-n.scrollLeft+Wf(e);const l=-n.scrollTop;return Lr(s).direction==="rtl"&&(i+=ca(e.clientWidth,s.clientWidth)-r),{width:r,height:a,x:i,y:l}}const TF=25;function RF(e,n,s){s===void 0&&(s="viewport");const r=s==="layoutViewport",a=hs(e),i=wa(e),l=a.visualViewport;let o=i.clientWidth,c=i.clientHeight,u=0,h=0;if(l){const m=!ow()||n==="fixed";r?m||(u=-l.offsetLeft,h=-l.offsetTop):(o=l.width,c=l.height,m&&(u=l.offsetLeft,h=l.offsetTop))}if(Wf(i)<=0){const m=i.ownerDocument,p=m.body,g=getComputedStyle(p),x=m.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,k=Math.abs(i.clientWidth-p.clientWidth-x),j=getComputedStyle(i).scrollbarGutter==="stable both-edges"?k/2:k;j<=TF&&(o-=j)}return{width:o,height:c,x:u,y:h}}function IF(e,n){const s=Bi(e,!0,n==="fixed"),r=s.top+e.clientTop,a=s.left+e.clientLeft,i=Ul(e),l=e.clientWidth*i.x,o=e.clientHeight*i.y,c=a*i.x,u=r*i.y;return{width:l,height:o,x:c,y:u}}function d0(e,n,s){let r;if(n==="viewport"||n==="layoutViewport")r=RF(e,s,n);else if(n==="document")r=AF(wa(e));else if(Dr(n))r=IF(n,s);else{const a=h$(e);r={x:n.x-a.x,y:n.y-a.y,width:n.width,height:n.height}}return Ih(r)}function PF(e,n){const s=n.get(e);if(s)return s;let r=Wc(e,[],!1).filter(o=>Dr(o)&&wo(o)!=="body"),a=null;const i=Lr(e).position==="fixed";let l=i?Ui(e):e;for(;Dr(l)&&!Bc(l);){const o=Lr(l),c=lw(l),u=a?a.position:i?"fixed":"";!c&&(u==="fixed"||u==="absolute"&&o.position==="static")?r=r.filter(f=>f!==l):a=o,l=Ui(l)}return n.set(e,r),r}function MF(e){let{element:n,boundary:s,rootBoundary:r,strategy:a}=e;const l=[...s==="clippingAncestors"?Uf(n)?[]:PF(n,this._c):[].concat(s),r],o=d0(n,l[0],a);let c=o.top,u=o.right,h=o.bottom,f=o.left;for(let m=1;m<l.length;m++){const p=d0(n,l[m],a);c=ca(p.top,c),u=Za(p.right,u),h=Za(p.bottom,h),f=ca(p.left,f)}return{width:u-f,height:h-c,x:f,y:c}}function OF(e){const{width:n,height:s}=d$(e);return{width:n,height:s}}function DF(e,n,s){const r=ui(n),a=wa(n),i=s==="fixed",l=Bi(e,!0,i,n);let o={scrollLeft:0,scrollTop:0};const c=ua(0);if((r||!i)&&((wo(n)!=="body"||zf(a))&&(o=Bf(n)),r)){const m=Bi(n,!0,i,n);c.x=m.x+n.clientLeft,c.y=m.y+n.clientTop}!r&&a&&(c.x=Wf(a));const u=a&&!r&&!i?f$(a,o):ua(0),h=l.left+o.scrollLeft-c.x-u.x,f=l.top+o.scrollTop-c.y-u.y;return{x:h,y:f,width:l.width,height:l.height}}function cp(e){return Lr(e).position==="static"}function h0(e,n){if(!ui(e)||Lr(e).position==="fixed")return null;if(n)return n(e);let s=e.offsetParent;return wa(e)===s&&(s=s.ownerDocument.body),s}function m$(e,n){const s=hs(e);if(Uf(e))return s;if(!ui(e)){let a=Ui(e);for(;a&&!Bc(a);){if(Dr(a)&&!cp(a))return a;a=Ui(a)}return s}let r=h0(e,n);for(;r&&yF(r)&&cp(r);)r=h0(r,n);return r&&Bc(r)&&cp(r)&&!lw(r)?s:r||NF(e)||s}const LF=async function(e){const n=this.getOffsetParent||m$,s=this.getDimensions,r=await s(e.floating);return{reference:DF(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function FF(e){return Lr(e).direction==="rtl"}const _F={convertOffsetParentRelativeRectToViewportRelativeRect:EF,getDocumentElement:wa,getClippingRect:MF,getOffsetParent:m$,getElementRects:LF,getClientRects:$F,getDimensions:OF,getScale:Ul,isElement:Dr,isRTL:FF};function p$(e,n){return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height}function zF(e,n,s){let r=null,a;const i=wa(e);function l(){var h;clearTimeout(a),(h=r)==null||h.disconnect(),r=null}function o(h,f){h===void 0&&(h=!1),f===void 0&&(f=1),l();const m=e.getBoundingClientRect(),{left:p,top:g,width:x,height:k}=m;if(h||n(),!x||!k)return;const j=rd(g),v=rd(i.clientWidth-(p+x)),w=rd(i.clientHeight-(g+k)),y=rd(p),b={rootMargin:-j+"px "+-v+"px "+-w+"px "+-y+"px",threshold:ca(0,Za(1,f))||1};let S=!0;function C(T){const E=T[0].intersectionRatio;if(!p$(m,e.getBoundingClientRect()))return o();if(E!==f){if(!S)return o();E?o(!1,E):a=setTimeout(()=>{o(!1,1e-7)},1e3)}S=!1}try{r=new IntersectionObserver(C,{...b,root:i.ownerDocument})}catch{r=new IntersectionObserver(C,b)}r.observe(e)}const c=hs(e),u=()=>o(s);return c.addEventListener("resize",u),o(!0),()=>{c.removeEventListener("resize",u),l()}}function UF(e,n,s,r){r===void 0&&(r={});const{ancestorScroll:a=!0,ancestorResize:i=!0,elementResize:l=typeof ResizeObserver=="function",layoutShift:o=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,u=cw(e),h=a||i?[...u?Wc(u):[],...n?Wc(n):[]]:[];h.forEach(j=>{a&&j.addEventListener("scroll",s),i&&j.addEventListener("resize",s)});const f=u&&o?zF(u,s,i):null;let m=-1,p=null;l&&(p=new ResizeObserver(j=>{let[v]=j;v&&v.target===u&&p&&n&&(p.unobserve(n),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var w;(w=p)==null||w.observe(n)})),s()}),u&&!c&&p.observe(u),n&&p.observe(n));let g,x=c?Bi(e):null;c&&k();function k(){const j=Bi(e);x&&!p$(x,j)&&s(),x=j,g=requestAnimationFrame(k)}return s(),()=>{var j;h.forEach(v=>{a&&v.removeEventListener("scroll",s),i&&v.removeEventListener("resize",s)}),f==null||f(),(j=p)==null||j.disconnect(),p=null,c&&cancelAnimationFrame(g)}}const BF=xF,WF=vF,HF=mF,KF=wF,VF=pF,f0=fF,GF=jF,YF=(e,n,s)=>{const r=new Map,a=s??{},i={..._F,...a.platform,_c:r};return hF(e,n,{...a,platform:i})};var qF=typeof document<"u",QF=function(){},Kd=qF?d.useLayoutEffect:QF;function Ph(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let s,r,a;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(s=e.length,s!==n.length)return!1;for(r=s;r--!==0;)if(!Ph(e[r],n[r]))return!1;return!0}if(a=Object.keys(e),s=a.length,s!==Object.keys(n).length)return!1;for(r=s;r--!==0;)if(!{}.hasOwnProperty.call(n,a[r]))return!1;for(r=s;r--!==0;){const i=a[r];if(!(i==="_owner"&&e.$$typeof)&&!Ph(e[i],n[i]))return!1}return!0}return e!==e&&n!==n}function g$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function m0(e,n){const s=g$(e);return Math.round(n*s)/s}function up(e){const n=d.useRef(e);return Kd(()=>{n.current=e}),n}function JF(e){e===void 0&&(e={});const{placement:n="bottom",strategy:s="absolute",middleware:r=[],platform:a,elements:{reference:i,floating:l}={},transform:o=!0,whileElementsMounted:c,open:u}=e,[h,f]=d.useState({x:0,y:0,strategy:s,placement:n,middlewareData:{},isPositioned:!1}),[m,p]=d.useState(r);Ph(m,r)||p(r);const[g,x]=d.useState(null),[k,j]=d.useState(null),v=d.useCallback(P=>{P!==b.current&&(b.current=P,x(P))},[]),w=d.useCallback(P=>{P!==S.current&&(S.current=P,j(P))},[]),y=i||g,N=l||k,b=d.useRef(null),S=d.useRef(null),C=d.useRef(h),T=c!=null,E=up(c),R=up(a),M=up(u),O=d.useCallback(()=>{if(!b.current||!S.current)return;const P={placement:n,strategy:s,middleware:m};R.current&&(P.platform=R.current),YF(b.current,S.current,P).then(K=>{const F={...K,isPositioned:M.current!==!1};I.current&&!Ph(C.current,F)&&(C.current=F,xo.flushSync(()=>{f(F)}))})},[m,n,s,R,M]);Kd(()=>{u===!1&&C.current.isPositioned&&(C.current.isPositioned=!1,f(P=>({...P,isPositioned:!1})))},[u]);const I=d.useRef(!1);Kd(()=>(I.current=!0,()=>{I.current=!1}),[]),Kd(()=>{if(y&&(b.current=y),N&&(S.current=N),y&&N){if(E.current)return E.current(y,N,O);O()}},[y,N,O,E,T]);const z=d.useMemo(()=>({reference:b,floating:S,setReference:v,setFloating:w}),[v,w]),U=d.useMemo(()=>({reference:y,floating:N}),[y,N]),D=d.useMemo(()=>{const P={position:s,left:0,top:0};if(!U.floating)return P;const K=m0(U.floating,h.x),F=m0(U.floating,h.y);return o?{...P,transform:"translate("+K+"px, "+F+"px)",...g$(U.floating)>=1.5&&{willChange:"transform"}}:{position:s,left:K,top:F}},[s,o,U.floating,h.x,h.y]);return d.useMemo(()=>({...h,update:O,refs:z,elements:U,floatingStyles:D}),[h,O,z,U,D])}const XF=e=>{function n(s){return{}.hasOwnProperty.call(s,"current")}return{name:"arrow",options:e,fn(s){const{element:r,padding:a}=typeof e=="function"?e(s):e;return r&&n(r)?r.current!=null?f0({element:r.current,padding:a}).fn(s):{}:r?f0({element:r,padding:a}).fn(s):{}}}},ZF=(e,n)=>{const s=BF(e);return{name:s.name,fn:s.fn,options:[e,n]}},e_=(e,n)=>{const s=WF(e);return{name:s.name,fn:s.fn,options:[e,n]}},t_=(e,n)=>({fn:GF(e).fn,options:[e,n]}),n_=(e,n)=>{const s=HF(e);return{name:s.name,fn:s.fn,options:[e,n]}},s_=(e,n)=>{const s=KF(e);return{name:s.name,fn:s.fn,options:[e,n]}},r_=(e,n)=>{const s=VF(e);return{name:s.name,fn:s.fn,options:[e,n]}},a_=(e,n)=>{const s=XF(e);return{name:s.name,fn:s.fn,options:[e,n]}};var i_=Object.defineProperty,l_=(e,n)=>i_(e,"name",{value:n,configurable:!0});function x$(e){const[n,s]=d.useState(void 0);return ds(()=>{if(e){s({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(a=>{if(!Array.isArray(a)||!a.length)return;const i=a[0];let l,o;if("borderBoxSize"in i){const c=i.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]),n}l_(x$,"useSize");var o_=Object.defineProperty,Ga=(e,n)=>o_(e,"name",{value:n,configurable:!0}),v$="Popper",[j$,Hf]=vr(v$),[c_,w$]=j$(v$),u_=Ga(e=>{const{__scopePopper:n,children:s}=e,[r,a]=d.useState(null),[i,l]=d.useState(void 0);return t.jsx(c_,{scope:n,anchor:r,onAnchorChange:a,placementState:i,setPlacementState:l,children:s})},"Popper"),d_="PopperAnchor",h_=d.forwardRef(Ga(function(n,s){const{__scopePopper:r,virtualRef:a,...i}=n,l=w$(d_,r),o=d.useRef(null),c=l.onAnchorChange,u=d.useCallback(x=>{o.current=x,x&&c(x)},[c]),h=Rt(s,u),f=d.useRef(null);d.useEffect(()=>{if(!a)return;const x=f.current;f.current=a.current,x!==f.current&&c(f.current)});const m=l.placementState&&Kf(l.placementState),p=m==null?void 0:m[0],g=m==null?void 0:m[1];return a?null:t.jsx(St.div,{"data-radix-popper-side":p,"data-radix-popper-align":g,...i,ref:h})},"PopperAnchor")),y$="PopperContent",[f_,Fse]=j$(y$),m_=d.forwardRef(Ga(function(n,s){var fe,ve,Oe,W,se,X,je;const{__scopePopper:r,side:a="bottom",sideOffset:i=0,align:l="center",alignOffset:o=0,arrowPadding:c=0,avoidCollisions:u=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:m="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:x,...k}=n,j=w$(y$,r),[v,w]=d.useState(null),y=Rt(s,w),[N,b]=d.useState(null),S=x$(N),C=(S==null?void 0:S.width)??0,T=(S==null?void 0:S.height)??0,E=a+(l!=="center"?"-"+l:""),R=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},M=Array.isArray(h)?h:[h],O=M.length>0,I={padding:R,boundary:M.filter(b$),altBoundary:O},{refs:z,floatingStyles:U,placement:D,isPositioned:P,middlewareData:K}=JF({strategy:"fixed",placement:E,whileElementsMounted:Ga((...be)=>UF(...be,{animationFrame:g==="always"}),"whileElementsMounted"),elements:{reference:j.anchor},middleware:[ZF({mainAxis:i+T,alignmentAxis:o}),u&&e_({mainAxis:!0,crossAxis:!1,limiter:m==="partial"?t_():void 0,...I}),u&&n_({...I}),s_({...I,apply:Ga(({elements:be,rects:xe,availableWidth:we,availableHeight:Ie})=>{const{width:ke,height:me}=xe.reference,$e=be.floating.style;$e.setProperty("--radix-popper-available-width",`${we}px`),$e.setProperty("--radix-popper-available-height",`${Ie}px`),$e.setProperty("--radix-popper-anchor-width",`${ke}px`),$e.setProperty("--radix-popper-anchor-height",`${me}px`)},"apply")}),N&&a_({element:N,padding:c}),p_({arrowWidth:C,arrowHeight:T}),p&&r_({strategy:"referenceHidden",...I,boundary:O?I.boundary:void 0})]}),F=j.setPlacementState;ds(()=>(F(D),()=>{F(void 0)}),[D,F]);const[Q,_]=Kf(D),re=Zn(x);ds(()=>{P&&(re==null||re())},[P,re]);const Y=(fe=K.arrow)==null?void 0:fe.x,B=(ve=K.arrow)==null?void 0:ve.y,q=((Oe=K.arrow)==null?void 0:Oe.centerOffset)!==0,[J,Z]=d.useState();return ds(()=>{v&&Z(window.getComputedStyle(v).zIndex)},[v]),t.jsx("div",{ref:z.setFloating,"data-radix-popper-content-wrapper":"",style:{...U,transform:P?U.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:J,"--radix-popper-transform-origin":[(W=K.transformOrigin)==null?void 0:W.x,(se=K.transformOrigin)==null?void 0:se.y].join(" "),...((X=K.hide)==null?void 0:X.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:n.dir,children:t.jsx(f_,{scope:r,placedSide:Q,placedAlign:_,onArrowChange:b,arrowX:Y,arrowY:B,shouldHideArrow:q,children:t.jsx(St.div,{"data-side":Q,"data-align":_,...k,ref:y,style:{...k.style,animation:P?(je=k.style)==null?void 0:je.animation:"none"}})})})},"PopperContent"));function b$(e){return e!==null}Ga(b$,"isNotNull");var p_=Ga(e=>({name:"transformOrigin",options:e,fn(n){var k,j,v;const{placement:s,rects:r,middlewareData:a}=n,l=((k=a.arrow)==null?void 0:k.centerOffset)!==0,o=l?0:e.arrowWidth,c=l?0:e.arrowHeight,[u,h]=Kf(s),f={start:"0%",center:"50%",end:"100%"}[h],m=(((j=a.arrow)==null?void 0:j.x)??0)+o/2,p=(((v=a.arrow)==null?void 0:v.y)??0)+c/2;let g="",x="";return u==="bottom"?(g=l?f:`${m}px`,x=`${-c}px`):u==="top"?(g=l?f:`${m}px`,x=`${r.floating.height+c}px`):u==="right"?(g=`${-c}px`,x=l?f:`${p}px`):u==="left"&&(g=`${r.floating.width+c}px`,x=l?f:`${p}px`),{data:{x:g,y:x}}}}),"transformOrigin");function Kf(e){const[n,s="center"]=e.split("-");return[n,s]}Ga(Kf,"getSideAndAlignFromPlacement");var uw=u_,k$=h_,N$=m_,g_=Object.defineProperty,Cn=(e,n)=>g_(e,"name",{value:n,configurable:!0}),[dw,_se]=vr("Tooltip",[Hf]),hw=Hf(),x_="TooltipProvider",v_=700,yx="tooltip.open",[j_,fw]=dw(x_),w_=Cn(e=>{const{__scopeTooltip:n,delayDuration:s=v_,skipDelayDuration:r=300,disableHoverableContent:a=!1,children:i}=e,l=d.useRef(!0),o=d.useRef(!1),c=d.useRef(0);return d.useEffect(()=>{const u=c.current;return()=>window.clearTimeout(u)},[]),t.jsx(j_,{scope:n,isOpenDelayedRef:l,delayDuration:s,onOpen:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),l.current=!1)},[r]),onClose:d.useCallback(()=>{r<=0||(window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.current=!0,r))},[r]),isPointerInTransitRef:o,onPointerInTransitChange:d.useCallback(u=>{o.current=u},[]),disableHoverableContent:a,children:i})},"TooltipProvider"),bx="Tooltip",[y_,ju]=dw(bx),b_=Cn(e=>{const{__scopeTooltip:n,children:s,open:r,defaultOpen:a,onOpenChange:i,disableHoverableContent:l,delayDuration:o}=e,c=fw(bx,e.__scopeTooltip),u=hw(n),[h,f]=d.useState(null),[m,p]=d.useState(void 0),g=ur(),x=d.useRef(0),k=l??c.disableHoverableContent,j=o??c.delayDuration,v=d.useRef(!1),[w,y]=ci({prop:r,defaultProp:a??!1,onChange:Cn(E=>{E?(c.onOpen(),document.dispatchEvent(new CustomEvent(yx))):c.onClose(),i==null||i(E)},"onChange"),caller:bx}),N=d.useMemo(()=>w?v.current?"delayed-open":"instant-open":"closed",[w]),b=d.useCallback(()=>{window.clearTimeout(x.current),x.current=0,v.current=!1,y(!0)},[y]),S=d.useCallback(()=>{window.clearTimeout(x.current),x.current=0,y(!1)},[y]),C=d.useCallback(()=>{window.clearTimeout(x.current),x.current=window.setTimeout(()=>{v.current=!0,y(!0),x.current=0},j)},[j,y]);d.useEffect(()=>()=>{x.current&&(window.clearTimeout(x.current),x.current=0)},[]);const T=m??g;return t.jsx(uw,{...u,children:t.jsx(y_,{scope:n,contentId:T,setContentId:p,open:w,stateAttribute:N,trigger:h,onTriggerChange:f,onTriggerEnter:d.useCallback(()=>{c.isOpenDelayedRef.current?C():b()},[c.isOpenDelayedRef,C,b]),onTriggerLeave:d.useCallback(()=>{k?S():(window.clearTimeout(x.current),x.current=0)},[S,k]),onOpen:b,onClose:S,disableHoverableContent:k,children:s})})},"Tooltip"),p0="TooltipTrigger",k_=d.forwardRef(Cn(function(n,s){const{__scopeTooltip:r,...a}=n,i=ju(p0,r),l=fw(p0,r),o=hw(r),c=d.useRef(null),u=Rt(s,c,i.onTriggerChange),h=d.useRef(!1),f=d.useRef(!1),m=d.useCallback(()=>h.current=!1,[]);return d.useEffect(()=>()=>document.removeEventListener("pointerup",m),[m]),t.jsx(k$,{asChild:!0,...o,children:t.jsx(St.button,{"aria-describedby":i.open?i.contentId:void 0,"data-state":i.stateAttribute,...a,ref:u,onPointerMove:Be(n.onPointerMove,p=>{p.pointerType!=="touch"&&!f.current&&!l.isPointerInTransitRef.current&&(i.onTriggerEnter(),f.current=!0)}),onPointerLeave:Be(n.onPointerLeave,()=>{i.onTriggerLeave(),f.current=!1}),onPointerDown:Be(n.onPointerDown,()=>{i.open&&i.onClose(),h.current=!0,document.addEventListener("pointerup",m,{once:!0})}),onFocus:Be(n.onFocus,()=>{h.current||i.onOpen()}),onBlur:Be(n.onBlur,i.onClose),onClick:Be(n.onClick,i.onClose)})})},"TooltipTrigger")),S$="TooltipPortal",[N_,S_]=dw(S$,{forceMount:void 0}),C_=Cn(e=>{const{__scopeTooltip:n,forceMount:s,children:r,container:a}=e,i=ju(S$,n);return t.jsx(N_,{scope:n,forceMount:s,children:t.jsx(Kr,{present:s||i.open,children:t.jsx(Df,{asChild:!0,container:a,children:r})})})},"TooltipPortal"),Hc="TooltipContent",E_=d.forwardRef(Cn(function(n,s){const r=S_(Hc,n.__scopeTooltip),{forceMount:a=r.forceMount,side:i="top",...l}=n,o=ju(Hc,n.__scopeTooltip);return t.jsx(Kr,{present:a||o.open,children:o.disableHoverableContent?t.jsx(C$,{side:i,...l,ref:s}):t.jsx($_,{side:i,...l,ref:s})})},"TooltipContent")),$_=d.forwardRef(Cn(function(n,s){const r=ju(Hc,n.__scopeTooltip),a=fw(Hc,n.__scopeTooltip),i=d.useRef(null),l=Rt(s,i),[o,c]=d.useState(null),{trigger:u,onClose:h}=r,f=i.current,{onPointerInTransitChange:m}=a,p=d.useCallback(()=>{c(null),m(!1)},[m]),g=d.useCallback((x,k)=>{const j=x.currentTarget,v={x:x.clientX,y:x.clientY},w=E$(v,j.getBoundingClientRect()),y=$$(v,w),N=A$(k.getBoundingClientRect()),b=R$([...y,...N]);c(b),m(!0)},[m]);return d.useEffect(()=>()=>p(),[p]),d.useEffect(()=>{if(u&&f){const x=Cn(j=>g(j,f),"handleTriggerLeave"),k=Cn(j=>g(j,u),"handleContentLeave");return u.addEventListener("pointerleave",x),f.addEventListener("pointerleave",k),()=>{u.removeEventListener("pointerleave",x),f.removeEventListener("pointerleave",k)}}},[u,f,g,p]),d.useEffect(()=>{if(o){const x=Cn(k=>{const j=k.target,v={x:k.clientX,y:k.clientY},w=(u==null?void 0:u.contains(j))||(f==null?void 0:f.contains(j)),y=!T$(v,o);w?p():y&&(p(),h())},"handleTrackPointerGrace");return document.addEventListener("pointermove",x),()=>document.removeEventListener("pointermove",x)}},[u,f,o,h,p]),t.jsx(C$,{...n,ref:l})},"TooltipContentHoverable")),A_=ME("TooltipContent"),C$=d.forwardRef(Cn(function(n,s){const{__scopeTooltip:r,children:a,"aria-label":i,id:l,onEscapeKeyDown:o,onPointerDownOutside:c,...u}=n,h=ju(Hc,r),f=hw(r),{onClose:m}=h;d.useEffect(()=>(document.addEventListener(yx,m),()=>document.removeEventListener(yx,m)),[m]),d.useEffect(()=>{if(h.trigger){const g=Cn(x=>{x.target instanceof Node&&x.target.contains(h.trigger)&&m()},"handleScroll");return window.addEventListener("scroll",g,{capture:!0}),()=>window.removeEventListener("scroll",g,{capture:!0})}},[h.trigger,m]);const{setContentId:p}=h;return ds(()=>(p(l),()=>{p(void 0)}),[l,p]),t.jsx(Of,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:o,onPointerDownOutside:c,onFocusOutside:g=>g.preventDefault(),onDismiss:m,children:t.jsxs(N$,{"data-state":h.stateAttribute,role:i?void 0:"tooltip",id:i?void 0:h.contentId,...f,...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:[t.jsx(A_,{children:a}),i?t.jsx(kL,{id:h.contentId,role:"tooltip",children:i}):null]})})},"TooltipContentImpl"));function E$(e,n){const s=Math.abs(n.top-e.y),r=Math.abs(n.bottom-e.y),a=Math.abs(n.right-e.x),i=Math.abs(n.left-e.x);switch(Math.min(s,r,a,i)){case i:return"left";case a:return"right";case s:return"top";case r:return"bottom";default:throw new Error("unreachable")}}Cn(E$,"getExitSideFromRect");function $$(e,n,s=5){const r=[];switch(n){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}Cn($$,"getPaddedExitPoints");function A$(e){const{top:n,right:s,bottom:r,left:a}=e;return[{x:a,y:n},{x:s,y:n},{x:s,y:r},{x:a,y:r}]}Cn(A$,"getPointsFromRect");function T$(e,n){const{x:s,y:r}=e;let a=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const o=n[i],c=n[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(a=!a)}return a}Cn(T$,"isPointInPolygon");function R$(e){const n=e.slice();return n.sort((s,r)=>s.x<r.x?-1:s.x>r.x?1:s.y<r.y?-1:s.y>r.y?1:0),I$(n)}Cn(R$,"getHull");function I$(e){if(e.length<=1)return e.slice();const n=[];for(let r=0;r<e.length;r++){const a=e[r];for(;n.length>=2;){const i=n[n.length-1],l=n[n.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))n.pop();else break}n.push(a)}n.pop();const s=[];for(let r=e.length-1;r>=0;r--){const a=e[r];for(;s.length>=2;){const i=s[s.length-1],l=s[s.length-2];if((i.x-l.x)*(a.y-l.y)>=(i.y-l.y)*(a.x-l.x))s.pop();else break}s.push(a)}return s.pop(),n.length===1&&s.length===1&&n[0].x===s[0].x&&n[0].y===s[0].y?n:n.concat(s)}Cn(I$,"getHullPresorted");var g0=w_,Kc=b_,Vc=k_,Gc=C_,Yc=E_;let hn={time:"auto",date:"auto",locale:void 0};function mw(e){const n=e.timeFormat===void 0?hn.time:e.timeFormat==="12h"||e.timeFormat==="24h"?e.timeFormat:"auto",s=e.dateFormat===void 0?hn.date:e.dateFormat==="short"||e.dateFormat==="long"||e.dateFormat==="iso"?e.dateFormat:"auto";hn={time:n,date:s,locale:e.locale??hn.locale}}function P$(){return{time:hn.time,date:hn.date}}function wu(e,n){const s=hn;mw(e);try{return n()}finally{hn=s}}const kx="buddi:formats";function yu(){if(hn.locale)return hn.locale;try{return typeof navigator<"u"&&navigator.language?navigator.language:"en-US"}catch{return"en-US"}}const x0=new Map;function yo(e,n){const s=`${e}|${JSON.stringify(n)}`;let r=x0.get(s);if(!r){try{r=new Intl.DateTimeFormat(e,n)}catch{r=new Intl.DateTimeFormat(e,{...n,timeZone:"UTC"})}x0.set(s,r)}return r}function dp(e,n,s,r){return Object.fromEntries(yo(s,{timeZone:n,...r}).formatToParts(e).map(a=>[a.type,a.value]))}function T_(){return hn.time==="12h"?{hour:"numeric",minute:"2-digit",hourCycle:"h12"}:hn.time==="24h"?{hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:{hour:Vf()?"numeric":"2-digit",minute:"2-digit"}}function R_(){return hn.time==="auto"?yu():"en-US"}function Tt(e,n){return Number.isNaN(e.getTime())?"—":yo(R_(),{timeZone:n,...T_()}).format(e)}function I_(e){return e>=1440&&!Vf()?"24:00":Tt(new Date(Date.UTC(2026,0,1,Math.floor(e/60)%24,e%60)),"UTC")}function Vf(){var e;return hn.time!=="auto"?hn.time==="12h":((e=yo(yu(),{hour:"numeric"}).resolvedOptions().hourCycle)==null?void 0:e.startsWith("h1"))===!0}function M$(){return`Profile (${Vf()?"12-hour":"24-hour"})`}function P_(){if(hn.date!=="auto")return hn.date==="short";const e=yo(yu(),{month:"short",day:"numeric"}).formatToParts(new Date(Date.UTC(2026,9,1))).map(n=>n.type);return e.indexOf("month")<e.indexOf("day")}function wr(e,n,s={}){return M_(e,n,s).replace(/\bSept\b/g,"Sep")}function M_(e,n,s){if(Number.isNaN(e.getTime()))return"—";const{weekday:r=!1,year:a=!1,compact:i=!1}=s;switch(hn.date){case"iso":{const l=dp(e,n,"en-CA",{year:"numeric",month:"2-digit",day:"2-digit",...r?{weekday:i?"short":"long"}:{}}),o=`${l.year}-${l.month}-${l.day}`;return r?`${l.weekday} ${o}`:o}case"short":{const l=dp(e,n,"en-US",{month:"short",day:"numeric",year:"numeric",weekday:"short"});return`${r?`${l.weekday}, `:""}${l.month} ${l.day}${a?`, ${l.year}`:""}`}case"long":{const l=dp(e,n,"en-GB",{month:i?"short":"long",day:"numeric",year:"numeric",weekday:i?"short":"long"});return`${r?`${l.weekday}, `:""}${l.day} ${l.month}${a?` ${l.year}`:""}`}default:return yo(yu(),{timeZone:n,month:i?"short":"long",day:"numeric",...a?{year:"numeric"}:{},...r?{weekday:i?"short":"long"}:{}}).format(e)}}function O$(e,n){if(hn.date==="iso")return`${e}-${String(n).padStart(2,"0")}`;const s=new Date(Date.UTC(e,n-1,15)),r=hn.date==="auto"?yu():"en-GB";return yo(r,{timeZone:"UTC",month:"long",year:"numeric"}).format(s)}function bu(e,n={}){const s=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(!s)return e;const r=new Date(`${s[0]}T12:00:00Z`);return Number.isNaN(r.getTime())?e:wr(r,"UTC",n)}function mt(e,n){if(!e)return"—";const s=new Date(e);return Number.isNaN(s.getTime())?String(e):`${wr(s,n,{year:!0,compact:!0})}, ${Tt(s,n)}`}function pw(e,n){return`${wr(e,n,{weekday:!0,compact:!0})}, ${Tt(e,n)}`}function Ge(e,n=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.round((s-n)/1e3),a=Math.abs(r),[i,l]=a<60?[r,"second"]:a<3600?[Math.round(r/60),"minute"]:a<86400?[Math.round(r/3600),"hour"]:[Math.round(r/86400),"day"];return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(i,l)}function gw(e,n=Date.now()){if(!e)return"";const s=new Date(e).getTime();if(Number.isNaN(s))return"";const r=Math.abs(Math.round((n-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 O_(e,n=Date.now()){const s=gw(e,n);return s===""?"":s==="now"||new Date(e).getTime()>n?"just now":s==="1 d"?"yesterday":`${s} ago`}function D_(e,n){if(e==null||!Number.isFinite(e))return"—";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:0}).format(e)}catch{return e.toFixed(2)}}function xn(e){return new Intl.NumberFormat("en-US").format(e)}function Nx(e){return[...e.cacheRead?[`cached ${xn(e.cacheRead)}`]:[],...e.cacheWrite?[`cache write ${xn(e.cacheWrite)}`]:[]].join(", ")}function L_(e){const n=Nx(e);return`${xn(e.input)} in${n?` (${n})`:""} / ${xn(e.output)} out`}function Cs(e){try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function qc(e,n=8){return e.length<=n?e:e.slice(0,n)}function fr(e,n){return e.length<=n?e:`${e.slice(0,n-1)}…`}function Qc(e){if(e.kind!=="agent")return e.title;const n=e.title.replace(/^@[^\s:]+:\s+/,"");return n.trim()===""?e.title:n}const v0="buddi_csrf",bo="x-buddi-csrf",Fr="buddi:agents-changed",$i="buddi:status-changed",Ko=e=>(window.dispatchEvent(new Event($i)),e),Sx="buddi:locked",F_="This page's sign-in no longer matches its cookies. Reload the page and try again.";class he extends Error{constructor(n,s,r){super(s),this.status=n,this.detail=r,this.name="ApiError"}}function Qi(){var r;const e=Number(location.port)||(location.protocol==="https:"?443:80),n=document.cookie.match(new RegExp(`(?:^|; )${v0}_${e}=([^;]*)`));if(n!=null&&n[1])return decodeURIComponent(n[1]);const s=[...document.cookie.matchAll(new RegExp(`(?:^|; )${v0}(?:_\\d+)?=([^;]*)`,"g"))];return s.length===1&&((r=s[0])!=null&&r[1])?decodeURIComponent(s[0][1]):""}const Mh="buddi isn't answering.";let Cx=null;const Ex=new Set;function Vo(e){if(e!==(Cx===null)){Cx=e?null:Date.now();for(const n of Ex)n()}}function Jc(){return Cx}function xw(e){return Ex.add(e),()=>Ex.delete(e)}function Oh(e){return e instanceof he&&(e.status===0||e.status===502||e.status===503)&&e.message===Mh}async function Ji(e,n={}){var l;let s;try{s=await fetch(e,{...n,credentials:"same-origin",redirect:"error",headers:{Accept:"application/json",...n.headers??{}}})}catch(o){throw(o==null?void 0:o.name)==="AbortError"||(l=n.signal)!=null&&l.aborted?o:(Vo(!1),new he(0,Mh,o))}if(s.status===401)throw Vo(!0),new he(401,"This session has expired. Run `buddi dashboard` for a fresh link.");if(s.status===423)throw Vo(!0),window.dispatchEvent(new Event(Sx)),new he(423,"This dashboard is locked.");const r=await s.text(),a=r===""?null:__(r),i=a&&typeof a=="object"&&"error"in a?String(a.error):void 0;if((s.status===502||s.status===503)&&i===void 0)throw Vo(!1),new he(s.status,Mh,a);if(Vo(!0),!s.ok){const o=(n.method??"GET").toUpperCase(),c=i??(s.status===403&&o!=="GET"&&o!=="HEAD"?F_:`request failed (${s.status})`);throw new he(s.status,c,a)}return a}function __(e){try{return JSON.parse(e)}catch{return null}}function hp(){return P$().time==="auto"?{hour:Vf()?"12":"24"}:{}}function ye(e,n={}){const s=new URLSearchParams;for(const[a,i]of Object.entries(n))i!==void 0&&i!==""&&s.set(a,String(i));const r=s.toString();return Ji(`/api${e}${r?`?${r}`:""}`)}function $x(e,n){return Ji(`/api${e}`,{method:"POST",headers:{[bo]:Qi()},body:n})}function rr(e){return Ji(`/api${e}`,{method:"DELETE",headers:{[bo]:Qi()}})}function te(e,n={}){return Ji(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/json",[bo]:Qi()},body:JSON.stringify(n??{})})}function vw(e,n,s,r={}){const a=n.name.replace(/[^\w.-]+/g,"_").slice(-120)||s;return Ji(`/api${e}`,{method:"POST",headers:{"Content-Type":"application/octet-stream",[bo]:Qi(),"X-Filename":a,...r},body:n})}function j0(e,n,s){return vw(e,n,"backup.tar.gz",{...s.passphrase?{"X-Backup-Passphrase":s.passphrase}:{},...s.confirm?{"X-Backup-Confirm":s.confirm}:{}})}function z_(e,n={}){return Ji(`/api${e}`,{method:"PATCH",headers:{"Content-Type":"application/json",[bo]:Qi()},body:JSON.stringify(n??{})})}function er(e,n={}){return Ji(`/api${e}`,{method:"PUT",headers:{"Content-Type":"application/json",[bo]:Qi()},body:JSON.stringify(n??{})})}function U_(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 Vd="gpt-oss:120b",B_=["approval","question","watcher","reminder","failure","recap","plugin","agent"],Ax=["mon","tue","wed","thu","fri","sat","sun"],Je={agents:()=>ye("/chat/agents"),views:()=>ye("/chat/views"),conversations:(e,n)=>ye(`/chat/${encodeURIComponent(e)}/conversations`,{limit:n}),startConversation:e=>te(`/chat/${encodeURIComponent(e)}/conversations`),conversation:e=>ye(`/chat/conversations/${encodeURIComponent(e)}`),deleteCarryOver:e=>rr(`/chat/conversations/${encodeURIComponent(e)}/carry-over`),send:(e,n)=>te(`/chat/${encodeURIComponent(e)}/messages`,n),answerQuestion:(e,n)=>te(`/chat/questions/${encodeURIComponent(e)}/answer`,n),cancel:e=>te(`/chat/conversations/${encodeURIComponent(e)}/cancel`),attach:e=>{const n=new FormData;return n.append("file",e,e.name),$x("/chat/attachments",n)},transcribe:e=>te("/speech/transcribe",e),say:e=>te("/speech/say",e),discardAttachment:e=>rr(`/artifacts/${encodeURIComponent(e)}`),groups:()=>ye("/groups"),group:e=>ye(`/groups/${encodeURIComponent(e)}`),createGroup:e=>te("/groups",e),updateGroup:(e,n)=>z_(`/groups/${encodeURIComponent(e)}`,n),deleteGroup:e=>rr(`/groups/${encodeURIComponent(e)}`),restoreGroup:e=>te(`/groups/${encodeURIComponent(e)}/restore`),clearGroup:e=>te(`/groups/${encodeURIComponent(e)}/clear`),groupConversations:e=>ye(`/groups/${encodeURIComponent(e)}/conversations`),startGroupConversation:e=>te(`/groups/${encodeURIComponent(e)}/conversations`),sendToGroup:(e,n)=>te(`/groups/${encodeURIComponent(e)}/messages`,n),streamUrl:e=>`/api/chat/conversations/${encodeURIComponent(e)}/stream`};function jw(e){return e.httpStatus===401||e.httpStatus===403||e.state==="authentication-error"||e.state==="access-denied"}const A={providers:()=>ye("/providers"),providerAccounts:()=>ye("/provider-accounts"),probeModels:e=>te("/provider-accounts/probe-models",e),accountModels:(e,n=!1)=>te(`/provider-accounts/${encodeURIComponent(e)}/models`,{refresh:n}),saveProviderAccount:e=>te("/provider-accounts/save",e),testProviderAccount:e=>te(`/provider-accounts/${encodeURIComponent(e)}/test`),removeProviderAccount:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/remove`,{revision:n}),codexAccountAction:(e,n,s)=>te(`/provider-accounts/${encodeURIComponent(e)}/${n}`,{revision:s}),ollamaConnect:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/connect`,{revision:n}),ollamaPoll:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/poll`,{attemptId:n}),ollamaDisconnect:(e,n)=>te(`/provider-accounts/${encodeURIComponent(e)}/ollama/disconnect`,{revision:n}),anthropicAccountAction:(e,n,s,r)=>te(`/provider-accounts/${encodeURIComponent(e)}/anthropic/${n}`,{revision:s,...r}),assignProviderAccount:(e,n,s)=>te(`/agents/${encodeURIComponent(e)}/account`,{accountId:n,model:s}),configureProvider:(e,n)=>te(`/providers/${encodeURIComponent(e)}/settings`,n),saveCredential:(e,n)=>te(`/providers/credentials/${encodeURIComponent(e)}/save`,{value:n}),removeCredential:e=>te(`/providers/credentials/${encodeURIComponent(e)}/remove`),testProvider:e=>te(`/providers/${encodeURIComponent(e)}/test`),browser:e=>ye(`/browser${e?`?agentId=${encodeURIComponent(e.agentId)}&conversationId=${encodeURIComponent(e.conversationId)}`:""}`),browserControl:(e,n,s)=>te(`/browser/${e}`,{...n===void 0?{}:{sessionId:n},...s!=null&&s.forever?{forever:!0}:{}}),browserSettings:e=>te("/browser/settings",e),browserPin:(e,n)=>te("/browser/pin",{conversationId:e,route:n}),browserLogin:(e,n)=>te("/browser/login",{id:e,decision:n}),browserCard:(e,n)=>te("/browser/card",{conversationId:e,answer:n}),browserInstall:()=>te("/browser/install",{}),browserCheck:()=>te("/browser/check",{}),previewLink:(e,n)=>ye(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/link`),previewCheck:(e,n)=>ye(`/preview/${encodeURIComponent(e)}/${encodeURIComponent(n)}/check`),extension:()=>ye("/extension"),pairExtension:e=>te("/extension/pair",{code:e}),forgetExtension:()=>rr("/extension/pair"),session:()=>ye("/session"),overview:()=>ye("/overview"),events:e=>ye("/events",e),eventKinds:()=>ye("/events/kinds"),conversations:()=>ye("/conversations"),conversation:e=>ye(`/conversations/${encodeURIComponent(e)}`),missions:()=>ye("/missions"),jobs:(e={})=>ye("/jobs",e),approvals:()=>ye("/approvals"),approval:e=>ye(`/approvals/${encodeURIComponent(e)}`).then(n=>n.action),offers:()=>ye("/offers"),dismissOffer:e=>te(`/offers/${encodeURIComponent(e)}/dismiss`,{}),dismissOffers:e=>te("/offers/dismiss-all",{ids:e}),agentOffers:()=>ye("/agent-offers"),catalogue:(e=!1)=>ye(`/catalogue${e?"?refresh=1":""}`),cataloguePlan:(e,n={})=>te(`/catalogue/${encodeURIComponent(e)}/plan`,n),catalogueInstall:(e,n)=>te(`/catalogue/${encodeURIComponent(e)}/install`,n),catalogueJob:e=>ye(`/catalogue/jobs/${encodeURIComponent(e)}`),catalogueConfirm:(e,n)=>te(`/catalogue/jobs/${encodeURIComponent(e)}/confirm`,{approve:n}),catalogueUpdatePlan:(e,n)=>te(`/catalogue/${encodeURIComponent(e)}/update/plan`,{agentId:n}),catalogueUpdate:(e,n,s,r=!1)=>te(`/catalogue/${encodeURIComponent(e)}/update`,{agentId:n,plan:s,...r?{replace:!0}:{}}),agentRemovePreview:e=>ye(`/agents/${encodeURIComponent(e)}/remove`),removeAgent:e=>te(`/agents/${encodeURIComponent(e)}/remove`),dismissAgentOffer:(e,n)=>te(`/agent-offers/${encodeURIComponent(e)}/${encodeURIComponent(n)}/dismiss`,{}),proposals:()=>ye("/proposals"),setDigestSchedule:(e,n)=>te("/proposals/digest-schedule",{day:e,hour:n}),keepProposal:(e,n)=>te(`/proposals/${encodeURIComponent(e)}/keep`,n===void 0?{}:{text:n}),keepAllProposals:e=>te("/proposals/keep-all",{ids:e}),discardProposal:(e,n)=>te(`/proposals/${encodeURIComponent(e)}/discard`,n?{reason:n}:{}),reminders:()=>ye("/reminders"),sentinels:()=>ye("/sentinels"),setSentinelEnabled:(e,n)=>te(`/sentinels/${encodeURIComponent(e)}/enabled`,{enabled:n}),widgets:(e="home")=>ye("/widgets",{...e==="lock"?{surface:e}:{},...hp()}),saveWidgets:(e,n)=>er(`/widgets/${e}`,{placements:n.map(({key:s,widget:r,size:a,settings:i})=>({...s?{key:s}:{},widget:r,size:a,settings:i}))}),widgetSettings:e=>ye(`/widgets/settings/${encodeURIComponent(e)}`),previewWidget:e=>te("/widgets/preview",{...e,...hp()}),refreshWidget:(e,n="home")=>te(`/widgets/${encodeURIComponent(e)}/refresh${n==="lock"?"?surface=lock":""}`),homeDismiss:(e,n)=>te("/home/dismiss",{slot:e,token:n}),setGlanceHidden:(e,n)=>te(`/home/glances/${encodeURIComponent(e)}/hidden`,{hidden:n}),rail:()=>ye("/rail"),setRailHidden:(e,n,s)=>te(`/rail/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}/hidden`,{hidden:s}),snoozeAlerts:(e,n,s)=>te("/alerts/snooze",{keys:e,snoozed:n,...s!==void 0?{days:s}:{}}),muteAlert:(e,n)=>te("/alerts/mute",{key:e,scope:n}),unmuteAlert:e=>te(`/alerts/mutes/${encodeURIComponent(e)}/remove`,{}),actOnAlerts:e=>te("/alerts/act",{entries:e}),askAboutAlerts:e=>te("/alerts/ask",{keys:e}),agents:()=>ye("/agents"),library:e=>ye("/artifacts",e),libraryEntry:(e,n=0)=>ye(`/artifacts/${encodeURIComponent(e)}`,n?{contexts:n}:{}),onboarding:()=>ye("/onboarding"),onboardingStep:(e,n={})=>te("/onboarding/step",{step:e,...n}),takeOn:e=>te("/onboarding/take-on",{tiles:e}),takeOnProgress:()=>ye("/onboarding/take-on"),completeOnboarding:()=>te("/onboarding/complete"),skipOnboarding:()=>te("/onboarding/skip"),createFirstAgent:e=>te("/onboarding/agent",e),ollama:()=>ye("/onboarding/ollama"),ollamaPull:e=>te("/onboarding/ollama/pull",{model:e}),ollamaPullState:()=>ye("/onboarding/ollama/pull"),mlxh:()=>ye("/onboarding/mlxh"),firstAgentPersona:()=>ye("/onboarding/agent"),updateFirstAgent:e=>te("/onboarding/agent/update",e),bindBrain:e=>te("/onboarding/brain",e),pages:()=>ye("/pages"),pageQuery:(e,n,s={})=>ye(`/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}`,s),pageFileUrl:(e,n,s={})=>{const r=new URLSearchParams(Object.entries(s).filter(([,a])=>a!=="")).toString();return`/api/pages/${encodeURIComponent(e)}/${encodeURIComponent(n)}${r?`?${r}`:""}`},pageAct:(e,n)=>te(`/pages/${encodeURIComponent(e)}/act`,n),telegram:()=>ye("/telegram"),saveTelegramToken:e=>te("/telegram/token",{token:e}),telegramPairing:()=>te("/telegram/pairing"),telegramBot:()=>ye("/telegram/bot"),telegramDevices:()=>ye("/telegram/devices"),unpairTelegramDevice:e=>rr(`/telegram/devices/${encodeURIComponent(e)}`),notifications:(e=20)=>ye("/notifications",{limit:e}),notificationsNeedingYou:()=>ye("/notifications",{needs:1}),notificationSeen:e=>te(`/notifications/${encodeURIComponent(e)}/seen`),notificationSettings:()=>ye("/notifications/settings"),saveNotificationSettings:e=>er("/notifications/settings",e),focus:()=>ye("/notifications/focus"),lockState:()=>ye("/lock"),lockScreen:()=>ye("/lock/screen",hp()),lockNow:(e="owner",n)=>te("/lock",{reason:e,...e==="idle"&&n!==void 0?{idleForMs:Math.max(0,Math.round(n))}:{}}),unlock:e=>te("/lock/unlock",{pin:e}),lockActivity:()=>te("/lock/activity"),setPin:(e,n)=>er("/lock/pin",n===void 0?{pin:e}:{pin:e,current:n}),removePin:e=>te("/lock/pin/remove",{current:e}),setLockSettings:e=>er("/lock/settings",e),uploadLockBackground:e=>{const n=new FormData;return n.append("file",e),$x("/lock/background",n)},removeLockBackground:()=>rr("/lock/background"),setFocus:(e,n)=>er("/notifications/focus",n?{mode:e,duration:n}:{mode:e}).then(Ko),testChannel:e=>te("/notifications/test",{channel:e}),setAgentMuted:(e,n)=>te("/notifications/agent-mute",{agentId:e,muted:n}),currentTip:e=>ye(e?`/tips/current?preview=${encodeURIComponent(e)}`:"/tips/current"),tips:()=>ye("/tips"),restoreTip:e=>te(`/tips/${encodeURIComponent(e)}/restore`),dismissTip:e=>te(`/tips/${encodeURIComponent(e)}/dismiss`),laterTip:e=>te(`/tips/${encodeURIComponent(e)}/later`),tipsSeenPage:e=>te("/tips/seen-page",{page:e}),tipsSettings:()=>ye("/tips/settings"),saveTipsSettings:e=>er("/tips/settings",{enabled:e}),presence:e=>te("/presence",{state:e}),owner:()=>ye("/owner"),setOwner:e=>te("/owner",e),findPlace:e=>te("/owner/places/find",{address:e}),savePlace:e=>te("/owner/places",e),removePlace:e=>te("/owner/places/remove",{id:e}),memory:e=>ye(e?`/memory?agent=${encodeURIComponent(e)}`:"/memory"),setPreference:e=>te("/memory/preferences",e),forgetPreference:e=>te("/memory/preferences/forget",e),updateNote:(e,n)=>te(`/memory/notes/${encodeURIComponent(e)}`,n),forgetNote:e=>te(`/memory/notes/${encodeURIComponent(e)}/forget`),people:()=>ye("/memory/people"),savePerson:e=>te("/memory/people",e),forgetPerson:e=>te(`/memory/people/${encodeURIComponent(e)}/forget`),restorePerson:e=>te(`/memory/people/${encodeURIComponent(e)}/restore`),birthday:()=>ye("/owner/birthday"),setDelegates:(e,n)=>te(`/agents/${encodeURIComponent(e)}/delegates`,{delegates:n}),agentProfile:e=>ye(`/agents/${encodeURIComponent(e)}/profile`),agentSkills:e=>ye(`/agents/${encodeURIComponent(e)}/skills`),removeSkill:(e,n)=>te(`/agents/${encodeURIComponent(e)}/skills/${encodeURIComponent(n)}/remove`,{}),host:(e,n)=>ye("/host",{agentId:e,conversationId:n}),connections:()=>ye("/connections"),connection:e=>ye(`/connections/${e}`),addConnection:(e,n)=>te("/connections",{url:e,...n?{name:n}:{}}),addProgram:e=>te("/connections",{transport:"stdio",...e}),updateProgram:(e,n)=>te(`/connections/${e}/program`,n),connectionConsent:(e,n)=>te(`/connections/${e}/consent`,n?{clientId:n}:{}),connectionToken:(e,n)=>te(`/connections/${e}/token`,n),connectionDevice:e=>te(`/connections/${e}/device`,{}),connectionCallback:e=>te("/connections/callback",e),connectionReview:e=>ye(`/connections/${e}/review`),saveConnectionReview:(e,n)=>te(`/connections/${e}/review`,n),grantConnection:(e,n,s=!1)=>te(`/connections/${e}/grant`,s?{agents:n,exact:!0}:{agents:n}),setConnectionHolder:(e,n,s)=>te(`/connections/${e}/holders/${encodeURIComponent(n)}`,{held:s}),disconnect:e=>rr(`/connections/${e}`),connectionSignals:()=>ye("/connections/signals"),connectionTools:e=>ye(`/connections/${e}/tools`),rememberedApprovals:e=>ye(`/connections/remembered/${encodeURIComponent(e)}`),setRememberedApproval:(e,n,s)=>te("/connections/remembered",{agent:e,tool:n,remember:s}),secrets:()=>ye("/secrets"),secretUses:(e,n)=>ye("/secrets/uses",{name:e,limit:n}),secretsAct:(e,n)=>te("/secrets/act",{tool:e,args:n}),stopHost:(e,n)=>te("/host/stop",{agentId:e,conversationId:n}),revokeHost:e=>te("/host/revoke",{id:e}),decide:(e,n,s,r)=>te(`/approvals/${encodeURIComponent(e)}/${n}`,s||r?{...s?{permissionScope:s}:{},...r?{ownerChoices:r}:{}}:void 0),setPaused:e=>te("/pause",{paused:e}).then(Ko),service:()=>ye("/service"),serviceAction:e=>te(`/service/${e}`),version:()=>ye("/version"),checkVersion:()=>te("/version/check"),setVersionCheck:e=>er("/version/check",{enabled:e}),tailscale:()=>ye("/access/tailscale"),setTailscale:e=>er("/access/tailscale",e),access:()=>ye("/access"),cloudflareAccess:()=>ye("/access/cloudflare-access"),setCloudflareAccess:e=>er("/access/cloudflare-access",e),testCloudflareAccess:e=>te("/access/cloudflare-access/test",e),cloudflareSetup:()=>ye("/access/cloudflare-access/setup"),cloudflareZones:(e={})=>te("/access/cloudflare-access/zones",e),startCloudflareSetup:e=>te("/access/cloudflare-access/setup",e),stopCloudflareSetup:()=>te("/access/cloudflare-access/setup/stop"),removeCloudflareSetup:(e={})=>te("/access/cloudflare-access/setup/remove",e),forgetCloudflareToken:()=>te("/access/cloudflare-access/setup/forget-token"),apiTokens:()=>ye("/api-tokens"),createApiToken:e=>te("/api-tokens",{name:e}),revokeApiToken:e=>rr(`/api-tokens/${encodeURIComponent(e)}`),startUpgrade:e=>te("/upgrade",e===void 0?{}:{version:e}),upgradeJob:e=>ye(`/upgrade/jobs/${encodeURIComponent(e)}`),backups:()=>ye("/backups"),startBackup:e=>te("/backups",{encrypt:e}),verifyArchive:e=>te("/backups/verify",{name:e}),restoreArchive:e=>te("/backups/restore",e),restoreUpload:(e,n)=>j0("/backups/restore",e,n),backupJob:e=>ye(`/backups/jobs/${encodeURIComponent(e)}`),backupSchedule:()=>ye("/backups/schedule"),setBackupSchedule:e=>er("/backups/schedule",e),backupPassphrase:()=>ye("/backups/passphrase"),revealBackupPassphrase:e=>te("/backups/passphrase/reveal",e===void 0?{}:{pin:e}),cliTool:()=>ye("/system/cli"),installCliTool:()=>te("/system/cli",{}),uninstallPlan:()=>ye("/system/uninstall"),uninstallBackup:e=>te("/system/uninstall/backup",{token:e}),uninstallJob:e=>ye(`/system/uninstall/jobs/${encodeURIComponent(e)}`),uninstall:e=>te("/system/uninstall",e),passphraseNotice:()=>ye("/backups/passphrase/notice"),acknowledgePassphrase:()=>te("/backups/passphrase/notice",{}),setBackupPassphrase:e=>er("/backups/passphrase",{passphrase:e}),plugins:()=>ye("/plugins"),market:(e=!1)=>ye(`/market${e?"?refresh=1":""}`),marketAssetUrl:e=>`/api/market/asset?url=${encodeURIComponent(e)}`,pluginFolders:e=>ye("/plugins/folders",e?{path:e}:{}),stagePlugin:e=>te("/plugins/stage",{spec:e}),uploadPlugin:e=>vw("/plugins/upload",e,"plugin.tgz"),pluginJob:e=>ye(`/plugins/jobs/${encodeURIComponent(e)}`),approveStaged:(e,n)=>te(`/plugins/staged/${encodeURIComponent(e)}/approve`,n),rejectStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/reject`),openedStaged:e=>te(`/plugins/staged/${encodeURIComponent(e)}/opened`),updatePlugin:(e,n,s)=>te(`/plugins/${encodeURIComponent(e)}/update`,{...n?{version:n}:{},...s?{from:s}:{}}),setPluginEnabled:(e,n)=>te(`/plugins/${encodeURIComponent(e)}/${n?"enable":"disable"}`,{}),uninstallPlugin:(e,n)=>te(`/plugins/${encodeURIComponent(e)}/uninstall`,n),acceptPluginAgent:(e,n)=>te(`/plugins/${encodeURIComponent(e)}/agents/${encodeURIComponent(n)}/accept`),recovery:()=>ye("/recovery"),leaveRecovery:e=>te("/recovery/leave",e),firstRunRestore:(e,n)=>j0("/onboarding/restore",e,{passphrase:n}),setMissionEnabled:(e,n)=>te(`/missions/${encodeURIComponent(e)}/enabled`,{enabled:n}),keepMission:e=>te(`/missions/${encodeURIComponent(e)}/keep`,{}),answerStillUseful:(e,n)=>te(`/missions/${encodeURIComponent(e)}/still-useful`,{answer:n}),setMisfirePolicy:(e,n,s)=>te(`/missions/${encodeURIComponent(e)}/schedule`,{misfirePolicy:n,...s===void 0?{}:{deadlineMinutes:s}}),retryJob:e=>te(`/jobs/${encodeURIComponent(e)}/retry`),cancelJob:e=>te(`/jobs/${encodeURIComponent(e)}/cancel`),jobFailures:()=>ye("/jobs/failures"),dismissJobs:e=>te("/jobs/dismiss",e).then(Ko),undismissJobs:e=>te("/jobs/undismiss",{ids:e}).then(Ko),retryJobs:e=>te("/jobs/retry",e).then(Ko),setDefaultAgent:e=>te("/agents/default",{agentId:e}),agentTools:e=>ye(`/agents/${encodeURIComponent(e)}/tools`),agentFile:e=>ye(`/agents/${encodeURIComponent(e)}/file`),uploadAgentPicture:(e,n)=>{const s=new FormData;return s.append("file",n,n.name),$x(`/agents/${encodeURIComponent(e)}/avatar`,s)},removeAgentPicture:e=>rr(`/agents/${encodeURIComponent(e)}/avatar`),updateAgentFile:(e,n)=>te(`/agents/${encodeURIComponent(e)}/file`,n),setAgentEngine:(e,n)=>te(`/agents/${encodeURIComponent(e)}/engine`,n),quiet:e=>te("/quiet",{arg:e}),takeOffer:(e,n)=>te(`/offers/${encodeURIComponent(e)}/take`,n?{conversationId:n}:{}),cancelReminder:e=>te(`/reminders/${encodeURIComponent(e)}/cancel`,{reason:"cancelled from the dashboard"})},Tx="buddi.chatDraft";function ku(e,n){try{window.sessionStorage.setItem(Tx,JSON.stringify({agentId:e,text:n}))}catch{}}function W_(e){try{const n=window.sessionStorage.getItem(Tx);if(!n)return null;const s=JSON.parse(n);return s.agentId!==e||typeof s.text!="string"?null:(window.sessionStorage.removeItem(Tx),s.text)}catch{return null}}const H_=4e3,K_={ts:"TypeScript",tsx:"TypeScript",js:"JavaScript",jsx:"JavaScript",py:"Python",sh:"Shell",bash:"Shell",json:"JSON",sql:"SQL",md:"Markdown",html:"HTML",css:"CSS",go:"Go",rs:"Rust",yaml:"YAML",yml:"YAML"},D$=e=>K_[e.toLowerCase()]??e;function Gf(e,n){const s=e.lastIndexOf(`
|
|
41
|
-
`,n-1)+1,r=e.indexOf(`
|
|
42
|
-
`,n),a=r<0?e.length:r;return{start:s,end:a,text:e.slice(s,a)}}function gc(e,n){return(e.slice(0,Gf(e,n).start).match(/^```/gm)??[]).length%2===1}function V_(e,n){const s=e.slice(0,n),r=/(^|[\s(])@([a-z0-9-]*)$/i.exec(s);return!r||gc(e,n)?null:{start:n-r[2].length-1,query:r[2]}}function G_(e,n){const s=/^\/([a-z0-9-]*)$/i.exec(e.slice(0,n));return s?{query:s[1]}:null}function Y_(e,n){return/^\/use @?[a-z0-9-]*$/i.test(e.slice(0,n))}function q_(e){const n=/^\/([a-z][a-z0-9-]*)(?:[ \t]+([\s\S]*))?$/i.exec(e.trim());return n?{name:n[1].toLowerCase(),arg:(n[2]??"").trim()}:null}function Q_(e,n,s,r){const a=e.slice(n),i=a.startsWith(" ")?"":" ";return{value:`${e.slice(0,s)}@${r}${i}${a}`,caret:s+r.length+2}}const J_=/^(\s*)([-*]|\d+\.)( )(.*)$/;function ww(e,n){if(gc(e,n))return null;const s=J_.exec(Gf(e,n).text);return s?{indent:s[1],mark:s[2],body:s[4]}:null}function X_(e,n){const s=ww(e,n);if(!s)return null;const r=Gf(e,n);if(s.body.trim()==="")return{value:e.slice(0,r.start)+e.slice(r.end),caret:r.start};const a=/\d/.test(s.mark)?`${parseInt(s.mark,10)+1}.`:s.mark,i=`
|
|
43
|
-
${s.indent}${a} `;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function Z_(e,n,s){if(!ww(e,n))return null;const r=Gf(e,n);if(!s)return{value:e.slice(0,r.start)+" "+e.slice(r.start),caret:n+2};const a=r.text.replace(/^ {1,2}/,""),i=r.text.length-a.length;return{value:e.slice(0,r.start)+a+e.slice(r.end),caret:Math.max(r.start,n-i)}}function e4(e){const n=e.replace(/\n$/,"").split(`
|
|
44
|
-
`);return n.length<3||/^```/m.test(e)?!1:n.filter(r=>/[;{}()=<>]\s*$|^\s{2,}\S|^\t+\S|^\s*(const|let|var|function|def|import|from|export|return|if|for|while|class|SELECT|INSERT|UPDATE|<\w)/.test(r)).length/n.length>.5}function t4(e){return/\bdef \w+\(|^\s*import \w+$|^\s*from \w+ import /m.test(e)?"py":/^\s*(SELECT|INSERT|UPDATE|WITH)\b/im.test(e)?"sql":/^\s*[{[]/.test(e)&&/"\w+"\s*:/.test(e)&&!/;\s*$/m.test(e)?"json":/:\s*\w+[\]>]?\s*[=;),]|\binterface \w+|\bas const\b|\btype \w+ =/.test(e)?"ts":"js"}function n4(e,n,s,r){const i=`${n>0&&e[n-1]!==`
|
|
45
|
-
`?`
|
|
46
|
-
`:""}\`\`\`${r}
|
|
47
|
-
${s.replace(/\n$/,"")}
|
|
48
|
-
\`\`\`
|
|
49
|
-
`;return{value:e.slice(0,n)+i+e.slice(n),caret:n+i.length}}function s4(e){const n=e.replace(/```[\s\S]*?(```|$)/g," ").replace(/`[^`\n]*`/g," "),s=[];for(const r of n.matchAll(/(^|[\s(])@([a-z][a-z0-9-]*)/gi)){const a=r[2].toLowerCase();s.includes(a)||s.push(a)}return s}function L$(e){const n=/^@([a-z][a-z0-9-]*)\s*[:,]?[ \t]*([\s\S]*)$/i.exec(e.trim());return n?{handle:n[1].toLowerCase(),rest:n[2].trim()}:null}function F$(e){return e==="anthropic"||e==="openai"}function _$(e,n){var a,i;if(!e)return null;const s=e.credentialEnv&&(n!=null&&n.accounts.some(l=>l.id===e.credentialEnv))?e.credentialEnv:(i=(a=n==null?void 0:n.bindings)==null?void 0:a.find(l=>l.agentId===e.id))==null?void 0:i.accountId,r=s?n==null?void 0:n.accounts.find(l=>l.id===s):void 0;return(r==null?void 0:r.kind)??e.provider}const r4="Thinking is up to this model. What it writes while thinking is shown apart and kept out of the answer.";var a4=Object.defineProperty,i4=(e,n)=>a4(e,"name",{value:n,configurable:!0}),l4=d.createContext(void 0);function Yf(e){const n=d.useContext(l4);return e||n||"ltr"}i4(Yf,"useDirection");var o4=Object.defineProperty,yw=(e,n)=>o4(e,"name",{value:n,configurable:!0}),ad=0,kr=null;function c4(e){return qf(),e.children}yw(c4,"FocusGuards");function qf(){d.useEffect(()=>{kr||(kr={start:Rx(),end:Rx()});const{start:e,end:n}=kr;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement("afterbegin",e),document.body.lastElementChild!==n&&document.body.insertAdjacentElement("beforeend",n),ad++,()=>{ad===1&&(kr==null||kr.start.remove(),kr==null||kr.end.remove(),kr=null),ad=Math.max(0,ad-1)}},[])}yw(qf,"useFocusGuards");function Rx(){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}yw(Rx,"createFocusGuard");var u4=Object.defineProperty,Jn=(e,n)=>u4(e,"name",{value:n,configurable:!0}),fp="focusScope.autoFocusOnMount",mp="focusScope.autoFocusOnUnmount",w0={bubbles:!1,cancelable:!0},z$=d.forwardRef(Jn(function(n,s){const{loop:r=!1,trapped:a=!1,onMountAutoFocus:i,onUnmountAutoFocus:l,...o}=n,[c,u]=d.useState(null),h=Zn(i),f=Zn(l),m=d.useRef(null),p=Rt(s,u),g=d.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;d.useEffect(()=>{if(a){let k=function(y){if(g.paused||!c)return;const N=y.target;c.contains(N)?m.current=N:ea(m.current,{select:!0})},j=function(y){if(g.paused||!c)return;const N=y.relatedTarget;N!==null&&(c.contains(N)||ea(m.current,{select:!0}))},v=function(y){if(document.activeElement===document.body)for(const b of y)b.removedNodes.length>0&&ea(c)};Jn(k,"handleFocusIn"),Jn(j,"handleFocusOut"),Jn(v,"handleMutations"),document.addEventListener("focusin",k),document.addEventListener("focusout",j);const w=new MutationObserver(v);return c&&w.observe(c,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",k),document.removeEventListener("focusout",j),w.disconnect()}}},[a,c,g.paused]),d.useEffect(()=>{if(c){y0.add(g);const k=document.activeElement;if(!c.contains(k)){const v=new CustomEvent(fp,w0);c.addEventListener(fp,h),c.dispatchEvent(v),v.defaultPrevented||(U$(V$(bw(c)),{select:!0}),document.activeElement===k&&ea(c))}return()=>{c.removeEventListener(fp,h),setTimeout(()=>{const v=new CustomEvent(mp,w0);c.addEventListener(mp,f),c.dispatchEvent(v),v.defaultPrevented||ea(k??document.body,{select:!0}),c.removeEventListener(mp,f),y0.remove(g)},0)}}},[c,h,f,g]);const x=d.useCallback(k=>{if(!r&&!a||g.paused)return;const j=k.key==="Tab"&&!k.altKey&&!k.ctrlKey&&!k.metaKey,v=document.activeElement;if(j&&v){const w=k.currentTarget,[y,N]=B$(w);y&&N?!k.shiftKey&&v===N?(k.preventDefault(),r&&ea(y,{select:!0})):k.shiftKey&&v===y&&(k.preventDefault(),r&&ea(N,{select:!0})):v===w&&k.preventDefault()}},[r,a,g.paused]);return t.jsx(St.div,{tabIndex:-1,...o,ref:p,onKeyDown:x})},"FocusScope"));function U$(e,{select:n=!1}={}){const s=document.activeElement;for(const r of e)if(ea(r,{select:n}),document.activeElement!==s)return}Jn(U$,"focusFirst");function B$(e){const n=bw(e),s=Ix(n,e),r=Ix(n.reverse(),e);return[s,r]}Jn(B$,"getTabbableEdges");function bw(e){const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:Jn(r=>{const a=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||a?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;s.nextNode();)n.push(s.currentNode);return n}Jn(bw,"getTabbableCandidates");function Ix(e,n){const s=typeof n.checkVisibility=="function"&&n.checkVisibility({checkVisibilityCSS:!0});for(const r of e)if(!(s?!r.checkVisibility({checkVisibilityCSS:!0}):W$(r,{upTo:n})))return r}Jn(Ix,"findVisible");function W$(e,{upTo:n}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(n!==void 0&&e===n)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}Jn(W$,"isHidden");function H$(e){return e instanceof HTMLInputElement&&"select"in e}Jn(H$,"isSelectableInput");function ea(e,{select:n=!1}={}){if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),e!==s&&H$(e)&&n&&e.select()}}Jn(ea,"focus");var y0=K$();function K$(){let e=[];return{add(n){const s=e[0];n!==s&&(s==null||s.pause()),e=Px(e,n),e.unshift(n)},remove(n){var s;e=Px(e,n),(s=e[0])==null||s.resume()}}}Jn(K$,"createFocusScopesStack");function Px(e,n){const s=[...e],r=s.indexOf(n);return r!==-1&&s.splice(r,1),s}Jn(Px,"arrayRemove");function V$(e){return e.filter(n=>n.tagName!=="A")}Jn(V$,"removeLinks");var d4=Object.defineProperty,kw=(e,n)=>d4(e,"name",{value:n,configurable:!0}),pp=!1;function G$(){const[e,n]=d.useState(pp);return d.useEffect(()=>{pp||(pp=!0,n(!0))},[]),e}kw(G$,"useIsHydrated");var Y$=mo[" useSyncExternalStore ".trim().toString()];function q$(){return()=>{}}kw(q$,"subscribe");function Q$(){return Y$(q$,()=>!0,()=>!1)}kw(Q$,"useIsHydratedModern");var h4=typeof Y$=="function"?Q$:G$,f4=Object.defineProperty,Xi=(e,n)=>f4(e,"name",{value:n,configurable:!0}),gp="rovingFocusGroup.onEntryFocus",m4={bubbles:!1,cancelable:!0},Qf="RovingFocusGroup",[Mx,J$,p4]=Pf(Qf),[g4,Jf]=vr(Qf,[p4]),[x4,v4]=g4(Qf),j4=d.forwardRef(Xi(function(n,s){return t.jsx(Mx.Provider,{scope:n.__scopeRovingFocusGroup,children:t.jsx(Mx.Slot,{scope:n.__scopeRovingFocusGroup,children:t.jsx(w4,{...n,ref:s})})})},"RovingFocusGroup")),w4=d.forwardRef(Xi(function(n,s){const{__scopeRovingFocusGroup:r,orientation:a,loop:i=!1,dir:l,currentTabStopId:o,defaultCurrentTabStopId:c,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=n,p=d.useRef(null),g=Rt(s,p),x=Yf(l),[k,j]=ci({prop:o,defaultProp:c??null,onChange:u,caller:Qf}),[v,w]=d.useState(!1),y=Zn(h),N=J$(r),b=d.useRef(!1),[S,C]=d.useState(0);return d.useEffect(()=>{const T=p.current;if(T)return T.addEventListener(gp,y),()=>T.removeEventListener(gp,y)},[y]),t.jsx(x4,{scope:r,orientation:a,dir:x,loop:i,currentTabStopId:k,onItemFocus:d.useCallback(T=>j(T),[j]),onItemShiftTab:d.useCallback(()=>w(!0),[]),onFocusableItemAdd:d.useCallback(()=>C(T=>T+1),[]),onFocusableItemRemove:d.useCallback(()=>C(T=>T-1),[]),children:t.jsx(St.div,{tabIndex:v||S===0?-1:0,"data-orientation":a,...m,ref:g,style:{outline:"none",...n.style},onMouseDown:Be(n.onMouseDown,()=>{b.current=!0}),onFocus:Be(n.onFocus,T=>{const E=!b.current;if(T.target===T.currentTarget&&E&&!v){const R=new CustomEvent(gp,m4);if(T.currentTarget.dispatchEvent(R),!R.defaultPrevented){const M=N().filter(D=>D.focusable),O=M.find(D=>D.active),I=M.find(D=>D.id===k),U=[O,I,...M].filter(Boolean).map(D=>D.ref.current);Nw(U,f)}}b.current=!1}),onBlur:Be(n.onBlur,()=>w(!1))})})},"RovingFocusGroupImpl")),y4="RovingFocusGroupItem",b4=d.forwardRef(Xi(function(n,s){const{__scopeRovingFocusGroup:r,focusable:a=!0,active:i=!1,tabStopId:l,children:o,...c}=n,u=ur(),h=l||u,f=v4(y4,r),m=f.currentTabStopId===h,p=J$(r),{onFocusableItemAdd:g,onFocusableItemRemove:x,currentTabStopId:k}=f,j=h4();return ds(()=>{if(!(!j||!a))return g(),()=>x()},[j,a,g,x]),d.useEffect(()=>{if(!(j||!a))return g(),()=>x()},[j,a,g,x]),t.jsx(Mx.ItemSlot,{scope:r,id:h,focusable:a,active:i,children:t.jsx(St.span,{tabIndex:m?0:-1,"data-orientation":f.orientation,...c,ref:s,onMouseDown:Be(n.onMouseDown,v=>{a?f.onItemFocus(h):v.preventDefault()}),onFocus:Be(n.onFocus,()=>f.onItemFocus(h)),onKeyDown:Be(n.onKeyDown,v=>{if(v.key==="Tab"&&v.shiftKey){f.onItemShiftTab();return}if(v.target!==v.currentTarget)return;const w=Z$(v,f.orientation,f.dir);if(w!==void 0){if(v.metaKey||v.ctrlKey||v.altKey||v.shiftKey)return;v.preventDefault();let N=p().filter(b=>b.focusable).map(b=>b.ref.current);if(w==="last")N.reverse();else if(w==="prev"||w==="next"){w==="prev"&&N.reverse();const b=N.indexOf(v.currentTarget);N=f.loop?eA(N,b+1):N.slice(b+1)}setTimeout(()=>Nw(N))}}),children:typeof o=="function"?o({isCurrentTabStop:m,hasTabStop:k!=null}):o})})},"RovingFocusGroupItem")),k4={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function X$(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}Xi(X$,"getDirectionAwareKey");function Z$(e,n,s){const r=X$(e.key,s);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return k4[r]}Xi(Z$,"getFocusIntent");function Nw(e,n=!1){const s=document.activeElement;for(const r of e)if(r===s||(r.focus({preventScroll:n}),document.activeElement!==s))return}Xi(Nw,"focusFirst");function eA(e,n){return e.map((s,r)=>e[(n+r)%e.length])}Xi(eA,"wrapArray");var tA=j4,nA=b4,N4=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},ul=new WeakMap,id=new WeakMap,ld={},xp=0,sA=function(e){return e&&(e.host||sA(e.parentNode))},S4=function(e,n){return n.map(function(s){if(e.contains(s))return s;var r=sA(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})},C4=function(e,n,s,r){var a=S4(n,Array.isArray(e)?e:[e]);ld[s]||(ld[s]=new WeakMap);var i=ld[s],l=[],o=new Set,c=new Set(a),u=function(f){!f||o.has(f)||(o.add(f),u(f.parentNode))};a.forEach(u);var h=function(f){!f||c.has(f)||Array.prototype.forEach.call(f.children,function(m){if(o.has(m))h(m);else try{var p=m.getAttribute(r),g=p!==null&&p!=="false",x=(ul.get(m)||0)+1,k=(i.get(m)||0)+1;ul.set(m,x),i.set(m,k),l.push(m),x===1&&g&&id.set(m,!0),k===1&&m.setAttribute(s,"true"),g||m.setAttribute(r,"true")}catch(j){console.error("aria-hidden: cannot operate on ",m,j)}})};return h(n),o.clear(),xp++,function(){l.forEach(function(f){var m=ul.get(f)-1,p=i.get(f)-1;ul.set(f,m),i.set(f,p),m||(id.has(f)||f.removeAttribute(r),id.delete(f)),p||f.removeAttribute(s)}),xp--,xp||(ul=new WeakMap,ul=new WeakMap,id=new WeakMap,ld={})}},rA=function(e,n,s){s===void 0&&(s="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),a=N4(e);return a?(r.push.apply(r,Array.from(a.querySelectorAll("[aria-live], script"))),C4(r,a,s,"aria-hidden")):function(){return null}},$r=function(){return $r=Object.assign||function(n){for(var s,r=1,a=arguments.length;r<a;r++){s=arguments[r];for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(n[i]=s[i])}return n},$r.apply(this,arguments)};function aA(e,n){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(e);a<r.length;a++)n.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(s[r[a]]=e[r[a]]);return s}function E4(e,n,s){if(s||arguments.length===2)for(var r=0,a=n.length,i;r<a;r++)(i||!(r in n))&&(i||(i=Array.prototype.slice.call(n,0,r)),i[r]=n[r]);return e.concat(i||Array.prototype.slice.call(n))}var Gd="right-scroll-bar-position",Yd="width-before-scroll-bar",$4="with-scroll-bars-hidden",A4="--removed-body-scroll-bar-size";function vp(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function T4(e,n){var s=d.useState(function(){return{value:e,callback:n,facade:{get current(){return s.value},set current(r){var a=s.value;a!==r&&(s.value=r,s.callback(r,a))}}}})[0];return s.callback=n,s.facade}var R4=typeof window<"u"?d.useLayoutEffect:d.useEffect,b0=new WeakMap;function I4(e,n){var s=T4(null,function(r){return e.forEach(function(a){return vp(a,r)})});return R4(function(){var r=b0.get(s);if(r){var a=new Set(r),i=new Set(e),l=s.current;a.forEach(function(o){i.has(o)||vp(o,null)}),i.forEach(function(o){a.has(o)||vp(o,l)})}b0.set(s,e)},[e]),s}function P4(e){return e}function M4(e,n){n===void 0&&(n=P4);var s=[],r=!1,a={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(i){var l=n(i,r);return s.push(l),function(){s=s.filter(function(o){return o!==l})}},assignSyncMedium:function(i){for(r=!0;s.length;){var l=s;s=[],l.forEach(i)}s={push:function(o){return i(o)},filter:function(){return s}}},assignMedium:function(i){r=!0;var l=[];if(s.length){var o=s;s=[],o.forEach(i),l=s}var c=function(){var h=l;l=[],h.forEach(i)},u=function(){return Promise.resolve().then(c)};u(),s={push:function(h){l.push(h),u()},filter:function(h){return l=l.filter(h),s}}}};return a}function O4(e){e===void 0&&(e={});var n=M4(null);return n.options=$r({async:!0,ssr:!1},e),n}var iA=function(e){var n=e.sideCar,s=aA(e,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return d.createElement(r,$r({},s))};iA.isSideCarExport=!0;function D4(e,n){return e.useMedium(n),iA}var lA=O4(),jp=function(){},Xf=d.forwardRef(function(e,n){var s=d.useRef(null),r=d.useState({onScrollCapture:jp,onWheelCapture:jp,onTouchMoveCapture:jp}),a=r[0],i=r[1],l=e.forwardProps,o=e.children,c=e.className,u=e.removeScrollBar,h=e.enabled,f=e.shards,m=e.sideCar,p=e.noRelative,g=e.noIsolation,x=e.inert,k=e.allowPinchZoom,j=e.as,v=j===void 0?"div":j,w=e.gapMode,y=aA(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),N=m,b=I4([s,n]),S=$r($r({},y),a);return d.createElement(d.Fragment,null,h&&d.createElement(N,{sideCar:lA,removeScrollBar:u,shards:f,noRelative:p,noIsolation:g,inert:x,setCallbacks:i,allowPinchZoom:!!k,lockRef:s,gapMode:w}),l?d.cloneElement(d.Children.only(o),$r($r({},S),{ref:b})):d.createElement(v,$r({},S,{className:c,ref:b}),o))});Xf.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Xf.classNames={fullWidth:Yd,zeroRight:Gd};var L4=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function F4(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=L4();return n&&e.setAttribute("nonce",n),e}function _4(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function z4(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var U4=function(){var e=0,n=null;return{add:function(s){e==0&&(n=F4())&&(_4(n,s),z4(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},B4=function(){var e=U4();return function(n,s){d.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&s])}},oA=function(){var e=B4(),n=function(s){var r=s.styles,a=s.dynamic;return e(r,a),null};return n},W4={left:0,top:0,right:0,gap:0},wp=function(e){return parseInt(e||"",10)||0},H4=function(e){var n=window.getComputedStyle(document.body),s=n[e==="padding"?"paddingLeft":"marginLeft"],r=n[e==="padding"?"paddingTop":"marginTop"],a=n[e==="padding"?"paddingRight":"marginRight"];return[wp(s),wp(r),wp(a)]},K4=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return W4;var n=H4(e),s=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-s+n[2]-n[0])}},V4=oA(),Bl="data-scroll-locked",G4=function(e,n,s,r){var a=e.left,i=e.top,l=e.right,o=e.gap;return s===void 0&&(s="margin"),`
|
|
50
|
-
.`.concat($4,` {
|
|
51
|
-
overflow: hidden `).concat(r,`;
|
|
52
|
-
padding-right: `).concat(o,"px ").concat(r,`;
|
|
53
|
-
}
|
|
54
|
-
body[`).concat(Bl,`] {
|
|
55
|
-
overflow: hidden `).concat(r,`;
|
|
56
|
-
overscroll-behavior: contain;
|
|
57
|
-
`).concat([n&&"position: relative ".concat(r,";"),s==="margin"&&`
|
|
58
|
-
padding-left: `.concat(a,`px;
|
|
59
|
-
padding-top: `).concat(i,`px;
|
|
60
|
-
padding-right: `).concat(l,`px;
|
|
61
|
-
margin-left:0;
|
|
62
|
-
margin-top:0;
|
|
63
|
-
margin-right: `).concat(o,"px ").concat(r,`;
|
|
64
|
-
`),s==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.`).concat(Gd,` {
|
|
68
|
-
right: `).concat(o,"px ").concat(r,`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.`).concat(Yd,` {
|
|
72
|
-
margin-right: `).concat(o,"px ").concat(r,`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
.`).concat(Gd," .").concat(Gd,` {
|
|
76
|
-
right: 0 `).concat(r,`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.`).concat(Yd," .").concat(Yd,` {
|
|
80
|
-
margin-right: 0 `).concat(r,`;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
body[`).concat(Bl,`] {
|
|
84
|
-
`).concat(A4,": ").concat(o,`px;
|
|
85
|
-
}
|
|
86
|
-
`)},k0=function(){var e=parseInt(document.body.getAttribute(Bl)||"0",10);return isFinite(e)?e:0},Y4=function(){d.useEffect(function(){return document.body.setAttribute(Bl,(k0()+1).toString()),function(){var e=k0()-1;e<=0?document.body.removeAttribute(Bl):document.body.setAttribute(Bl,e.toString())}},[])},q4=function(e){var n=e.noRelative,s=e.noImportant,r=e.gapMode,a=r===void 0?"margin":r;Y4();var i=d.useMemo(function(){return K4(a)},[a]);return d.createElement(V4,{styles:G4(i,!n,a,s?"":"!important")})},Ox=!1;if(typeof window<"u")try{var od=Object.defineProperty({},"passive",{get:function(){return Ox=!0,!0}});window.addEventListener("test",od,od),window.removeEventListener("test",od,od)}catch{Ox=!1}var dl=Ox?{passive:!1}:!1,Q4=function(e){return e.tagName==="TEXTAREA"},cA=function(e,n){if(!(e instanceof Element))return!1;var s=window.getComputedStyle(e);return s[n]!=="hidden"&&!(s.overflowY===s.overflowX&&!Q4(e)&&s[n]==="visible")},J4=function(e){return cA(e,"overflowY")},X4=function(e){return cA(e,"overflowX")},N0=function(e,n){var s=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var a=uA(e,r);if(a){var i=dA(e,r),l=i[1],o=i[2];if(l>o)return!0}r=r.parentNode}while(r&&r!==s.body);return!1},Z4=function(e){var n=e.scrollTop,s=e.scrollHeight,r=e.clientHeight;return[n,s,r]},ez=function(e){var n=e.scrollLeft,s=e.scrollWidth,r=e.clientWidth;return[n,s,r]},uA=function(e,n){return e==="v"?J4(n):X4(n)},dA=function(e,n){return e==="v"?Z4(n):ez(n)},tz=function(e,n){return e==="h"&&n==="rtl"?-1:1},nz=function(e,n,s,r,a){var i=tz(e,window.getComputedStyle(n).direction),l=i*r,o=s.target,c=n.contains(o),u=!1,h=l>0,f=0,m=0;do{if(!o)break;var p=dA(e,o),g=p[0],x=p[1],k=p[2],j=x-k-i*g;(g||j)&&uA(e,o)&&(f+=j,m+=g);var v=o.parentNode;o=v&&v.nodeType===Node.DOCUMENT_FRAGMENT_NODE?v.host:v}while(!c&&o!==document.body||c&&(n.contains(o)||n===o));return(h&&Math.abs(f)<1||!h&&Math.abs(m)<1)&&(u=!0),u},cd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},S0=function(e){return[e.deltaX,e.deltaY]},C0=function(e){return e&&"current"in e?e.current:e},sz=function(e,n){return e[0]===n[0]&&e[1]===n[1]},rz=function(e){return`
|
|
87
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
88
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
89
|
-
`)},az=0,hl=[];function iz(e){var n=d.useRef([]),s=d.useRef([0,0]),r=d.useRef(),a=d.useState(az++)[0],i=d.useState(oA)[0],l=d.useRef(e);d.useEffect(function(){l.current=e},[e]),d.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(a));var x=E4([e.lockRef.current],(e.shards||[]).map(C0),!0).filter(Boolean);return x.forEach(function(k){return k.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),x.forEach(function(k){return k.classList.remove("allow-interactivity-".concat(a))})}}},[e.inert,e.lockRef.current,e.shards]);var o=d.useCallback(function(x,k){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!l.current.allowPinchZoom;var j=cd(x),v=s.current,w="deltaX"in x?x.deltaX:v[0]-j[0],y="deltaY"in x?x.deltaY:v[1]-j[1],N,b=x.target,S=Math.abs(w)>Math.abs(y)?"h":"v";if("touches"in x&&S==="h"&&b.type==="range")return!1;var C=window.getSelection(),T=C&&C.anchorNode,E=T?T===b||T.contains(b):!1;if(E)return!1;var R=N0(S,b);if(!R)return!0;if(R?N=S:(N=S==="v"?"h":"v",R=N0(S,b)),!R)return!1;if(!r.current&&"changedTouches"in x&&(w||y)&&(r.current=N),!N)return!0;var M=r.current||N;return nz(M,k,x,M==="h"?w:y)},[]),c=d.useCallback(function(x){var k=x;if(!(!hl.length||hl[hl.length-1]!==i)){var j="deltaY"in k?S0(k):cd(k),v=n.current.filter(function(N){return N.name===k.type&&(N.target===k.target||k.target===N.shadowParent)&&sz(N.delta,j)})[0];if(v&&v.should){k.cancelable&&k.preventDefault();return}if(!v){var w=(l.current.shards||[]).map(C0).filter(Boolean).filter(function(N){return N.contains(k.target)}),y=w.length>0?o(k,w[0]):!l.current.noIsolation;y&&k.cancelable&&k.preventDefault()}}},[]),u=d.useCallback(function(x,k,j,v){var w={name:x,delta:k,target:j,should:v,shadowParent:lz(j)};n.current.push(w),setTimeout(function(){n.current=n.current.filter(function(y){return y!==w})},1)},[]),h=d.useCallback(function(x){s.current=cd(x),r.current=void 0},[]),f=d.useCallback(function(x){u(x.type,S0(x),x.target,o(x,e.lockRef.current))},[]),m=d.useCallback(function(x){u(x.type,cd(x),x.target,o(x,e.lockRef.current))},[]);d.useEffect(function(){return hl.push(i),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:m}),document.addEventListener("wheel",c,dl),document.addEventListener("touchmove",c,dl),document.addEventListener("touchstart",h,dl),function(){hl=hl.filter(function(x){return x!==i}),document.removeEventListener("wheel",c,dl),document.removeEventListener("touchmove",c,dl),document.removeEventListener("touchstart",h,dl)}},[]);var p=e.removeScrollBar,g=e.inert;return d.createElement(d.Fragment,null,g?d.createElement(i,{styles:rz(a)}):null,p?d.createElement(q4,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function lz(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const oz=D4(lA,iz);var Sw=d.forwardRef(function(e,n){return d.createElement(Xf,$r({},e,{ref:n,sideCar:oz}))});Sw.classNames=Xf.classNames;var cz=Object.defineProperty,wt=(e,n)=>cz(e,"name",{value:n,configurable:!0}),Dx=["Enter"," "],uz=["ArrowDown","PageUp","Home"],hA=["ArrowUp","PageDown","End"],dz=[...uz,...hA],hz={ltr:[...Dx,"ArrowRight"],rtl:[...Dx,"ArrowLeft"]},fz={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Zf="Menu",[Xc,mz,pz]=Pf(Zf),[Zi,fA]=vr(Zf,[pz,Hf,Jf]),em=Hf(),mA=Jf(),[pA,di]=Zi(Zf),[gz,Nu]=Zi(Zf),xz=wt(e=>{const{__scopeMenu:n,open:s=!1,children:r,dir:a,onOpenChange:i,modal:l=!0}=e,o=em(n),[c,u]=d.useState(null),h=d.useRef(!1),f=Zn(i),m=Yf(a);return d.useEffect(()=>{const p=wt(()=>{h.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=wt(()=>h.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})}},[]),d.useEffect(()=>{if(!s)return;const p=wt(()=>f(!1),"handleBlur");return window.addEventListener("blur",p),()=>window.removeEventListener("blur",p)},[s,f]),t.jsx(uw,{...o,children:t.jsx(pA,{scope:n,open:s,onOpenChange:f,content:c,onContentChange:u,children:t.jsx(gz,{scope:n,onClose:d.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:m,modal:l,children:r})})})},"Menu"),gA=d.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n,i=em(r);return t.jsx(k$,{...i,...a,ref:s})},"MenuAnchor")),xA="MenuPortal",[vz,vA]=Zi(xA,{forceMount:void 0}),jz=wt(e=>{const{__scopeMenu:n,forceMount:s,children:r,container:a}=e,i=di(xA,n);return t.jsx(vz,{scope:n,forceMount:s,children:t.jsx(Kr,{present:s||i.open,children:t.jsx(Df,{asChild:!0,container:a,children:r})})})},"MenuPortal"),dr="MenuContent",[wz,Cw]=Zi(dr),yz=d.forwardRef(wt(function(n,s){const r=vA(dr,n.__scopeMenu),{forceMount:a=r.forceMount,...i}=n,l=di(dr,n.__scopeMenu),o=Nu(dr,n.__scopeMenu);return t.jsx(Xc.Provider,{scope:n.__scopeMenu,children:t.jsx(Kr,{present:a||l.open,children:t.jsx(Xc.Slot,{scope:n.__scopeMenu,children:o.modal?t.jsx(bz,{...i,ref:s}):t.jsx(kz,{...i,ref:s})})})})},"MenuContent")),bz=d.forwardRef(wt(function(n,s){const r=di(dr,n.__scopeMenu),a=d.useRef(null),i=Rt(s,a);return d.useEffect(()=>{const l=a.current;if(l)return rA(l)},[]),t.jsx(Ew,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Be(n.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),kz=d.forwardRef(wt(function(n,s){const r=di(dr,n.__scopeMenu);return t.jsx(Ew,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),Nz=Xa("MenuContent.ScrollLock"),Ew=d.forwardRef(wt(function(n,s){const{__scopeMenu:r,loop:a=!1,trapFocus:i,onOpenAutoFocus:l,onCloseAutoFocus:o,disableOutsidePointerEvents:c,onEntryFocus:u,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,disableOutsideScroll:x,...k}=n,j=di(dr,r),v=Nu(dr,r),w=em(r),y=mA(r),N=mz(r),[b,S]=d.useState(null),C=d.useRef(null),T=Rt(s,C,j.onContentChange),E=d.useRef(0),R=d.useRef(""),M=d.useRef(0),O=d.useRef(null),I=d.useRef("right"),z=d.useRef(0),U=x?Sw:d.Fragment,D=x?{as:Nz,allowPinchZoom:!0}:void 0,P=wt(F=>{var Z,fe;const Q=R.current+F,_=N().filter(ve=>!ve.disabled),re=document.activeElement,Y=(Z=_.find(ve=>ve.ref.current===re))==null?void 0:Z.textValue,B=_.map(ve=>ve.textValue),q=$A(B,Q,Y),J=(fe=_.find(ve=>ve.textValue===q))==null?void 0:fe.ref.current;wt(function ve(Oe){R.current=Oe,window.clearTimeout(E.current),Oe!==""&&(E.current=window.setTimeout(()=>ve(""),1e3))},"updateSearch")(Q),J&&setTimeout(()=>J.focus())},"handleTypeaheadSearch");d.useEffect(()=>()=>window.clearTimeout(E.current),[]),qf();const K=d.useCallback(F=>{var _,re;return I.current===((_=O.current)==null?void 0:_.side)&&TA(F,(re=O.current)==null?void 0:re.area)},[]);return t.jsx(wz,{scope:r,searchRef:R,onItemEnter:d.useCallback(F=>{K(F)&&F.preventDefault()},[K]),onItemLeave:d.useCallback(F=>{var Q;K(F)||((Q=C.current)==null||Q.focus(),S(null))},[K]),onTriggerLeave:d.useCallback(F=>{K(F)&&F.preventDefault()},[K]),pointerGraceTimerRef:M,onPointerGraceIntentChange:d.useCallback(F=>{O.current=F},[]),children:t.jsx(U,{...D,children:t.jsx(z$,{asChild:!0,trapped:i,onMountAutoFocus:Be(l,F=>{var Q;F.preventDefault(),(Q=C.current)==null||Q.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:t.jsx(Of,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:m,onInteractOutside:p,onDismiss:g,children:t.jsx(tA,{asChild:!0,...y,dir:v.dir,orientation:"vertical",loop:a,currentTabStopId:b,onCurrentTabStopIdChange:S,onEntryFocus:Be(u,F=>{v.isUsingKeyboardRef.current||F.preventDefault()}),preventScrollOnEntryFocus:!0,children:t.jsx(N$,{role:"menu","aria-orientation":"vertical","data-state":$w(j.open),"data-radix-menu-content":"",dir:v.dir,...w,...k,ref:T,style:{outline:"none",...k.style},onKeyDown:Be(k.onKeyDown,F=>{const _=F.target.closest("[data-radix-menu-content]")===F.currentTarget,re=F.ctrlKey||F.altKey||F.metaKey,Y=F.key.length===1;_&&(F.key==="Tab"&&F.preventDefault(),!re&&Y&&P(F.key));const B=C.current;if(F.target!==B||!dz.includes(F.key))return;F.preventDefault();const J=N().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);hA.includes(F.key)&&J.reverse(),CA(J)}),onBlur:Be(n.onBlur,F=>{F.currentTarget.contains(F.target)||(window.clearTimeout(E.current),R.current="")}),onPointerMove:Be(n.onPointerMove,eo(F=>{const Q=F.target,_=z.current!==F.clientX;if(F.currentTarget.contains(Q)&&_){const re=F.clientX>z.current?"right":"left";I.current=re,z.current=F.clientX}}))})})})})})})},"MenuContentImpl")),jA=d.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{role:"group",...a,ref:s})},"MenuGroup")),Sz=d.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{...a,ref:s})},"MenuLabel")),Lx="MenuItem",E0="menu.itemSelect",wA=d.forwardRef(wt(function(n,s){const{disabled:r=!1,onSelect:a,...i}=n,l=d.useRef(null),o=Nu(Lx,n.__scopeMenu),c=Cw(Lx,n.__scopeMenu),u=Rt(s,l),h=d.useRef(!1),f=wt(()=>{const m=l.current;if(!r&&m){const p=new CustomEvent(E0,{bubbles:!0,cancelable:!0});m.addEventListener(E0,g=>a==null?void 0:a(g),{once:!0}),Mf(m,p),p.defaultPrevented?h.current=!1:o.onClose()}},"handleSelect");return t.jsx(yA,{...i,ref:u,disabled:r,onClick:Be(n.onClick,f),onPointerDown:m=>{var p;(p=n.onPointerDown)==null||p.call(n,m),h.current=!0},onPointerUp:Be(n.onPointerUp,m=>{var p;h.current||(p=m.currentTarget)==null||p.click()}),onKeyDown:Be(n.onKeyDown,m=>{r||m.target!==m.currentTarget||c.searchRef.current!==""&&m.key===" "||Dx.includes(m.key)&&(m.currentTarget.click(),m.preventDefault())})})},"MenuItem")),yA=d.forwardRef(wt(function(n,s){const{__scopeMenu:r,disabled:a=!1,textValue:i,...l}=n,o=Cw(Lx,r),c=mA(r),u=d.useRef(null),h=Rt(s,u),[f,m]=d.useState(!1),[p,g]=d.useState("");return d.useEffect(()=>{const x=u.current;x&&g((x.textContent??"").trim())},[l.children]),t.jsx(Xc.ItemSlot,{scope:r,disabled:a,textValue:i??p,children:t.jsx(nA,{asChild:!0,...c,focusable:!a,children:t.jsx(St.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":a||void 0,"data-disabled":a?"":void 0,...l,ref:h,onPointerMove:Be(n.onPointerMove,eo(x=>{a?o.onItemLeave(x):(o.onItemEnter(x),x.defaultPrevented||x.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Be(n.onPointerLeave,eo(x=>o.onItemLeave(x))),onFocus:Be(n.onFocus,()=>m(!0)),onBlur:Be(n.onBlur,()=>m(!1))})})})},"MenuItemImpl")),Cz="MenuRadioGroup",[Ez,$z]=Zi(Cz,{value:void 0,onValueChange:wt(()=>{},"onValueChange")}),Az=d.forwardRef(wt(function(n,s){const{value:r,onValueChange:a,...i}=n,l=Zn(a);return t.jsx(Ez,{scope:n.__scopeMenu,value:r,onValueChange:l,children:t.jsx(jA,{...i,ref:s})})},"MenuRadioGroup")),Tz="MenuRadioItem",Rz=d.forwardRef(wt(function(n,s){const{value:r,...a}=n,i=$z(Tz,n.__scopeMenu),l=r===i.value;return t.jsx(Pz,{scope:n.__scopeMenu,checked:l,children:t.jsx(wA,{role:"menuitemradio","aria-checked":l,...a,ref:s,"data-state":SA(l),onSelect:Be(a.onSelect,()=>{var o;return(o=i.onValueChange)==null?void 0:o.call(i,r)},{checkForDefaultPrevented:!1})})})},"MenuRadioItem")),Iz="MenuItemIndicator",[Pz,zse]=Zi(Iz,{checked:!1}),Mz=d.forwardRef(wt(function(n,s){const{__scopeMenu:r,...a}=n;return t.jsx(St.div,{role:"separator","aria-orientation":"horizontal",...a,ref:s})},"MenuSeparator")),bA="MenuSub",[Oz,kA]=Zi(bA),Dz=wt(e=>{const{__scopeMenu:n,children:s,open:r=!1,onOpenChange:a}=e,i=di(bA,n),l=em(n),[o,c]=d.useState(null),[u,h]=d.useState(null),f=Zn(a);return d.useEffect(()=>(i.open===!1&&f(!1),()=>f(!1)),[i.open,f]),t.jsx(uw,{...l,children:t.jsx(pA,{scope:n,open:r,onOpenChange:f,content:u,onContentChange:h,children:t.jsx(Oz,{scope:n,contentId:ur(),triggerId:ur(),trigger:o,onTriggerChange:c,children:s})})})},"MenuSub"),ud="MenuSubTrigger",Lz=d.forwardRef(wt(function(n,s){const r=di(ud,n.__scopeMenu),a=Nu(ud,n.__scopeMenu),i=kA(ud,n.__scopeMenu),l=Cw(ud,n.__scopeMenu),o=d.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:u}=l,h={__scopeMenu:n.__scopeMenu},f=d.useCallback(()=>{o.current&&window.clearTimeout(o.current),o.current=null},[]);d.useEffect(()=>f,[f]),d.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),u(null)}},[c,u]);const m=Rt(s,i.onTriggerChange);return t.jsx(gA,{asChild:!0,...h,children:t.jsx(yA,{id:i.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":r.open?i.contentId:void 0,"data-state":$w(r.open),...n,ref:m,onClick:p=>{var g;(g=n.onClick)==null||g.call(n,p),!(n.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:Be(n.onPointerMove,eo(p=>{l.onItemEnter(p),!p.defaultPrevented&&!n.disabled&&!r.open&&!o.current&&(l.onPointerGraceIntentChange(null),o.current=window.setTimeout(()=>{r.onOpenChange(!0),f()},100))})),onPointerLeave:Be(n.onPointerLeave,eo(p=>{var x,k;f();const g=(x=r.content)==null?void 0:x.getBoundingClientRect();if(g){const j=(k=r.content)==null?void 0:k.dataset.side,v=j==="right",w=v?-5:5,y=g[v?"left":"right"],N=g[v?"right":"left"];l.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:g.top},{x:N,y:g.top},{x:N,y:g.bottom},{x:y,y:g.bottom}],side:j}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>l.onPointerGraceIntentChange(null),300)}else{if(l.onTriggerLeave(p),p.defaultPrevented)return;l.onPointerGraceIntentChange(null)}})),onKeyDown:Be(n.onKeyDown,p=>{var x;n.disabled||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||hz[a.dir].includes(p.key)&&(r.onOpenChange(!0),(x=r.content)==null||x.focus(),p.preventDefault())})})})},"MenuSubTrigger")),Fz="MenuSubContent",_z=d.forwardRef(wt(function(n,s){const r=vA(dr,n.__scopeMenu),{forceMount:a=r.forceMount,align:i="start",...l}=n,o=di(dr,n.__scopeMenu),c=Nu(dr,n.__scopeMenu),u=kA(Fz,n.__scopeMenu),h=d.useRef(null),f=Rt(s,h);return t.jsx(Xc.Provider,{scope:n.__scopeMenu,children:t.jsx(Kr,{present:a||o.open,children:t.jsx(Xc.Slot,{scope:n.__scopeMenu,children:t.jsx(Ew,{id:u.contentId,"aria-labelledby":u.triggerId,...l,ref:f,align:i,side:c.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:m=>{var p;c.isUsingKeyboardRef.current&&((p=h.current)==null||p.focus()),m.preventDefault()},onCloseAutoFocus:m=>m.preventDefault(),onFocusOutside:Be(n.onFocusOutside,m=>{m.target!==u.trigger&&o.onOpenChange(!1)}),onEscapeKeyDown:Be(n.onEscapeKeyDown,m=>{c.onClose(),m.preventDefault()}),onKeyDown:Be(n.onKeyDown,m=>{var x;const p=m.currentTarget.contains(m.target),g=fz[c.dir].includes(m.key);p&&g&&(o.onOpenChange(!1),(x=u.trigger)==null||x.focus(),m.preventDefault())})})})})})},"MenuSubContent"));function $w(e){return e?"open":"closed"}wt($w,"getOpenState");function NA(e){return e==="indeterminate"}wt(NA,"isIndeterminate");function SA(e){return NA(e)?"indeterminate":e?"checked":"unchecked"}wt(SA,"getCheckedState");function CA(e){const n=document.activeElement;for(const s of e)if(s===n||(s.focus(),document.activeElement!==n))return}wt(CA,"focusFirst");function EA(e,n){return e.map((s,r)=>e[(n+r)%e.length])}wt(EA,"wrapArray");function $A(e,n,s){const a=n.length>1&&Array.from(n).every(u=>u===n[0])?n[0]:n,i=s?e.indexOf(s):-1;let l=EA(e,Math.max(i,0));a.length===1&&(l=l.filter(u=>u!==s));const c=l.find(u=>u.toLowerCase().startsWith(a.toLowerCase()));return c!==s?c:void 0}wt($A,"getNextMatch");function AA(e,n){const{x:s,y:r}=e;let a=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const o=n[i],c=n[l],u=o.x,h=o.y,f=c.x,m=c.y;h>r!=m>r&&s<(f-u)*(r-h)/(m-h)+u&&(a=!a)}return a}wt(AA,"isPointInPolygon");function TA(e,n){if(!n)return!1;const s={x:e.clientX,y:e.clientY};return AA(s,n)}wt(TA,"isPointerInGraceArea");function eo(e){return n=>n.pointerType==="mouse"?e(n):void 0}wt(eo,"whenMouse");var zz=xz,Uz=gA,Bz=jz,Wz=yz,Hz=jA,Kz=Sz,Vz=wA,Gz=Az,Yz=Rz,qz=Mz,Qz=Dz,Jz=Lz,Xz=_z,Zz=Object.defineProperty,Rs=(e,n)=>Zz(e,"name",{value:n,configurable:!0}),Aw="DropdownMenu",[e3,Use]=vr(Aw,[fA]),Is=fA(),[t3,RA]=e3(Aw),n3=Rs(e=>{const{__scopeDropdownMenu:n,children:s,dir:r,open:a,defaultOpen:i,onOpenChange:l,modal:o=!0}=e,c=Is(n),u=d.useRef(null),[h,f]=ci({prop:a,defaultProp:i??!1,onChange:l,caller:Aw});return t.jsx(t3,{scope:n,triggerId:ur(),triggerRef:u,contentId:ur(),open:h,onOpenChange:f,onOpenToggle:d.useCallback(()=>f(m=>!m),[f]),modal:o,children:t.jsx(zz,{...c,open:h,onOpenChange:f,dir:r,modal:o,children:s})})},"DropdownMenu"),s3="DropdownMenuTrigger",r3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,disabled:a=!1,...i}=n,l=RA(s3,r),o=Is(r),c=Rt(s,l.triggerRef);return t.jsx(Uz,{asChild:!0,...o,children:t.jsx(St.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":a?"":void 0,disabled:a,...i,ref:c,onPointerDown:Be(n.onPointerDown,u=>{!a&&u.button===0&&u.ctrlKey===!1&&(l.onOpenToggle(),l.open||u.preventDefault())}),onKeyDown:Be(n.onKeyDown,u=>{a||(["Enter"," "].includes(u.key)&&l.onOpenToggle(),u.key==="ArrowDown"&&l.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(u.key)&&u.preventDefault())})})})},"DropdownMenuTrigger")),a3=Rs(e=>{const{__scopeDropdownMenu:n,...s}=e,r=Is(n);return t.jsx(Bz,{...r,...s})},"DropdownMenuPortal"),i3="DropdownMenuContent",l3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=RA(i3,r),l=Is(r),o=d.useRef(!1);return t.jsx(Wz,{id:i.contentId,"aria-labelledby":i.triggerId,...l,...a,ref:s,onCloseAutoFocus:Be(n.onCloseAutoFocus,c=>{var u;o.current||(u=i.triggerRef.current)==null||u.focus(),o.current=!1,c.preventDefault()}),onInteractOutside:Be(n.onInteractOutside,c=>{const u=c.detail.originalEvent,h=u.button===0&&u.ctrlKey===!0,f=u.button===2||h;(!i.modal||f)&&(o.current=!0)}),style:{...n.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")),o3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Hz,{...i,...a,ref:s})},"DropdownMenuGroup")),c3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Kz,{...i,...a,ref:s})},"DropdownMenuLabel")),u3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Vz,{...i,...a,ref:s})},"DropdownMenuItem")),d3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Gz,{...i,...a,ref:s})},"DropdownMenuRadioGroup")),h3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Yz,{...i,...a,ref:s})},"DropdownMenuRadioItem")),f3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(qz,{...i,...a,ref:s})},"DropdownMenuSeparator")),m3=Rs(e=>{const{__scopeDropdownMenu:n,children:s,open:r,onOpenChange:a,defaultOpen:i}=e,l=Is(n),[o,c]=ci({prop:r,defaultProp:i??!1,onChange:a,caller:"DropdownMenuSub"});return t.jsx(Qz,{...l,open:o,onOpenChange:c,children:s})},"DropdownMenuSub"),p3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Jz,{...i,...a,ref:s})},"DropdownMenuSubTrigger")),g3=d.forwardRef(Rs(function(n,s){const{__scopeDropdownMenu:r,...a}=n,i=Is(r);return t.jsx(Xz,{...i,...a,ref:s,style:{...n.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")),Su=n3,Cu=r3,ko=a3,Eu=l3,IA=o3,Wi=c3,Bs=u3,x3=d3,v3=h3,la=f3,j3=m3,w3=p3,y3=g3,b3=Object.defineProperty,No=(e,n)=>b3(e,"name",{value:n,configurable:!0}),Tw="Tabs",[k3,Bse]=vr(Tw,[Jf]),PA=Jf(),[N3,Rw]=k3(Tw),S3=d.forwardRef(No(function(n,s){const{__scopeTabs:r,value:a,onValueChange:i,defaultValue:l,orientation:o="horizontal",dir:c,activationMode:u="automatic",...h}=n,f=Yf(c),[m,p]=ci({prop:a,onChange:i,defaultProp:l??"",caller:Tw});return t.jsx(N3,{scope:r,baseId:ur(),value:m,onValueChange:p,orientation:o,dir:f,activationMode:u,children:t.jsx(St.div,{dir:f,"data-orientation":o,...h,ref:s})})},"Tabs")),C3="TabsList",E3=d.forwardRef(No(function(n,s){const{__scopeTabs:r,loop:a=!0,...i}=n,l=Rw(C3,r),o=PA(r);return t.jsx(tA,{asChild:!0,...o,orientation:l.orientation,dir:l.dir,loop:a,children:t.jsx(St.div,{role:"tablist","aria-orientation":l.orientation,...i,ref:s})})},"TabsList")),$3="TabsTrigger",A3=d.forwardRef(No(function(n,s){const{__scopeTabs:r,value:a,disabled:i=!1,...l}=n,o=Rw($3,r),c=PA(r),u=Iw(o.baseId,a),h=Pw(o.baseId,a),f=a===o.value;return t.jsx(nA,{asChild:!0,...c,focusable:!i,active:f,children:t.jsx(St.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:u,...l,ref:s,onMouseDown:Be(n.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?o.onValueChange(a):m.preventDefault()}),onKeyDown:Be(n.onKeyDown,m=>{i||m.target!==m.currentTarget||[" ","Enter"].includes(m.key)&&o.onValueChange(a)}),onFocus:Be(n.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!i&&m&&o.onValueChange(a)})})})},"TabsTrigger")),T3="TabsContent",R3=d.forwardRef(No(function(n,s){const{__scopeTabs:r,value:a,forceMount:i,children:l,...o}=n,c=Rw(T3,r),u=Iw(c.baseId,a),h=Pw(c.baseId,a),f=a===c.value,m=d.useRef(f);return d.useEffect(()=>{const p=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(p)},[]),t.jsx(Kr,{present:i||f,children:({present:p})=>t.jsx(St.div,{"data-state":f?"active":"inactive","data-orientation":c.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:h,tabIndex:0,...o,ref:s,style:{...n.style,animationDuration:m.current?"0s":void 0},children:p&&l})})},"TabsContent"));function Iw(e,n){return`${e}-trigger-${n}`}No(Iw,"makeTriggerId");function Pw(e,n){return`${e}-content-${n}`}No(Pw,"makeContentId");var I3=S3,P3=E3,M3=A3,O3=R3;function yn(e,n,s){if(e==null)return"—";switch(n){case"currency":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?D3(r,s):String(e)}case"percent":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?`${$0(r)}%`:String(e)}case"number":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Number.isInteger(r)?xn(r):$0(r):String(e)}case"date":return L3(String(e));default:return typeof e=="string"?e:typeof e=="number"?xn(e):typeof e=="boolean"?e?"yes":"no":JSON.stringify(e)??String(e)}}function D3(e,n){if(!(Math.abs(e)<1e3&&!Number.isInteger(e)))return D_(e,n);try{return new Intl.NumberFormat("en-US",{style:"currency",currency:n??"USD",maximumFractionDigits:2}).format(e)}catch{return e.toFixed(2)}}function L3(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?bu(n[0],{year:!0,compact:!0}):e}function Fx(e){const n=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);return n?bu(n[0],{compact:!0}):e}function $0(e){return String(Math.round(e*100)/100)}function Dh(e,n,s=4){if(!Number.isFinite(e)||!Number.isFinite(n))return[];if(e===n)return[e];const r=(n-e)/Math.max(1,s),a=10**Math.floor(Math.log10(r)),i=[1,2,2.5,5,10].map(o=>o*a).find(o=>o>=r)??a*10,l=[];for(let o=Math.ceil(e/i)*i;o<=n+i/1e3;o+=i)l.push(Math.round(o*1e6)/1e6);return l.filter(o=>o>=e&&o<=n)}function F3({props:e}){if(e.bars.length===0)return t.jsx("p",{className:"wb-empty",children:"No categories came back."});const n=e.bars.map(i=>i.value),s=Math.max(0,...n),r=Math.min(0,...n),a=s-r||1;return t.jsx("div",{className:"wb-bars",children:e.bars.map(i=>{const l=Math.abs(i.value)/a;return t.jsxs("div",{className:"wb-bar-row",children:[t.jsx("div",{className:"wb-bar-cat",title:i.category,children:i.category}),t.jsx("div",{className:"wb-bar-track",children:t.jsx("div",{className:"wb-bar-fill",style:{width:`${Math.max(1,l*100)}%`,background:i.value<0?"var(--chart-bar-negative)":"var(--chart-bar)"}})}),t.jsx("div",{className:"wb-bar-val",children:yn(i.value,e.unit,e.currency)})]},i.category)})})}const _3=/^(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 )/,z3=/^(… |\.\.\. |\(no change\)$|\)/;function U3(e){return e.replace(/\n$/,"").split(`
|
|
90
|
-
`).map(s=>({kind:B3(s),text:s}))}function B3(e){return e.startsWith("@@")?"hunk":_3.test(e)||z3.test(e)?"meta":e.startsWith("+")?"add":e.startsWith("-")?"del":"context"}function W3({text:e,marks:n}){const s=e.toLowerCase(),r=[];for(const l of n){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 t.jsx(t.Fragment,{children:e===""?" ":e});r.sort((l,o)=>l[0]-o[0]);const a=[];let i=0;for(const[l,o]of r)l<i||(l>i&&a.push(t.jsx("span",{children:e.slice(i,l)},`t${i}`)),a.push(t.jsx("mark",{className:"wb-diff-mark",children:e.slice(l,o)},`m${l}`)),i=o);return i<e.length&&a.push(t.jsx("span",{children:e.slice(i)},`t${i}`)),t.jsx(t.Fragment,{children:a})}function Lh({text:e,limit:n,more:s,label:r="Diff",marks:a}){const i=U3(e),l=n===void 0?i:i.slice(0,n),o=i.length-l.length;return t.jsxs("div",{className:"wb-diff-wrap",children:[t.jsx("pre",{className:"wb-diff","aria-label":r,"data-testid":"diff",children:l.map((c,u)=>t.jsx("span",{className:"wb-diff-line","data-kind":c.kind,children:a&&a.length>0?t.jsx(W3,{text:c.text,marks:a}):c.text===""?" ":c.text},u))}),o>0?t.jsxs("p",{className:"wb-diff-more",children:[o," more line",o===1?"":"s",s?t.jsxs(t.Fragment,{children:[" · ",t.jsx("button",{type:"button",className:"wb-diff-open",onClick:s.onClick,children:s.label})]}):null]}):null]})}function H3({props:e}){return t.jsxs("div",{children:[e.title?t.jsx("h4",{className:"wb-doc-title mono",children:e.title}):null,e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:yn(n.value,n.unit,null)})]},n.label))}):null,e.diff?t.jsx(Lh,{text:e.diff,label:e.title?`Diff of ${e.title}`:"Diff"}):t.jsx("p",{className:"wb-empty",children:"This change came back with no diff."})]})}const $n="#/",to="#/needs",da="#/chat",bt="#/agents",At="#/activity",on="#/settings",va="#/files",K3="#/welcome";function qd(e){const n=/^#\/welcome(?:\?(.*))?$/.exec(e);if(!n)return null;try{return{step:new URLSearchParams(n[1]??"").get("step")}}catch{return{step:null}}}function dd(e,n={}){const s=new URLSearchParams;n.q&&s.set("q",n.q),n.origin&&s.set("origin",n.origin),n.family&&s.set("family",n.family);const r=s.toString();return`${va}${e?`/${encodeURIComponent(e)}`:""}${r?`?${r}`:""}`}function V3(e){const n=/^#\/files(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!n)return null;try{const s=new URLSearchParams(n[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")),{...n[1]?{artifactId:decodeURIComponent(n[1])}:{},filters:r}}catch{return null}}function at(e,n,s){return`#/chat/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}${s?`?tab=${s}`:""}`}function G3(e){if(MA(e))return null;const n=/^#\/chat\/([^/?]+)(?:\/([^/?]+))?(?:\?(.*))?$/.exec(e);if(!n)return null;try{const s=new URLSearchParams(n[3]??"").get("tab");return{agentId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{},...s?{tab:s}:{}}}catch{return null}}function ki(e,n){return`#/chat/g/${encodeURIComponent(e)}${n?`/${encodeURIComponent(n)}`:""}`}function MA(e){const n=/^#\/chat\/g\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{groupId:decodeURIComponent(n[1]),...n[2]?{conversationId:decodeURIComponent(n[2])}:{}}}catch{return null}}function Ft(e,n,s){return`${bt}/${encodeURIComponent(e)}${n?`/${n}${s?`/${s}`:""}`:""}`}function Y3(e){const n=/^#\/agents\/([^/]+)(?:\/([a-z-]+)(?:\/([a-z-]+))?)?$/.exec(e);if(!n||n[1]===OA)return null;try{return{agentId:decodeURIComponent(n[1]),...n[2]?{tab:n[2]}:{},...n[3]?{section:n[3]}:{}}}catch{return null}}const OA="catalogue",A0=`${bt}/${OA}`;function un(e){return e?`${A0}/${encodeURIComponent(e)}`:A0}function q3(e){return`${un(e)}?add=1`}function Q3(e,n){const s=/^#\/agents\/catalogue\/([a-z0-9-]+)\?(?:.*&)?add=1(?:&|$)/.exec(e);return(s==null?void 0:s[1])===n}function J3(e){const n=/^#\/agents\/catalogue(?:\/([a-z0-9-]+))?(?:\?.*)?$/.exec(e);return n?n[1]?{name:n[1]}:{}:null}function Zc(e){return`${At}/conversations/${encodeURIComponent(e)}`}const X3="#/p";function _r(e,n,s){const r=`${X3}/${encodeURIComponent(e)}/${encodeURIComponent(n)}`;return s?`${r}/${encodeURIComponent(s)}`:r}function Mw(e){const n=/^#\/p\/([^/?]+)\/([^/?]+)(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(!n)return null;try{return{plugin:decodeURIComponent(n[1]),page:decodeURIComponent(n[2]),...n[3]?{item:decodeURIComponent(n[3])}:{}}}catch{return null}}const Z3="p.";function mr(e,n=e,s){const r=s?new URLSearchParams(s).toString():"";return`${on}/${encodeURIComponent(LA(e,n))}${r?`?${r}`:""}`}function eU(e,n){const s=DA(e);if(!s)return null;const r=n.filter(i=>i.plugin===s.plugin);if(r.length===0||r.some(i=>i.id===s.page))return null;const a=Ow(e);return mr(s.plugin,r[0].id,Object.keys(a).length>0?a:void 0)}function Ow(e){const n=e.indexOf("?");if(n===-1)return{};try{const s={};for(const[r,a]of new URLSearchParams(e.slice(n+1)))a!==""&&(s[r]=a);return s}catch{return{}}}function DA(e){const n=/^#\/settings\/p\.([^/?.]+)(?:\.([^/?.]+))?(?:\?.*)?$/.exec(e);if(!n)return null;const s=decodeURIComponent(n[1]);return{plugin:s,page:n[2]?decodeURIComponent(n[2]):s}}function LA(e,n){return`${Z3}${e}${n===e?"":`.${n}`}`}function Fe(e){return e?`${on}/${e}`:on}function FA(e){return`${Fe("accounts")}?account=${encodeURIComponent(e)}`}function tU(e){const n=/^#\/settings\/accounts\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("account")||null}catch{return null}}function eu(e,n,s){const r=new RegExp(`^#/settings/${n}\\?(.*)$`).exec(e);if(!r)return null;try{return new URLSearchParams(r[1]).get(s)||null}catch{return null}}function _A(e){return`${Fe("connections")}?connection=${encodeURIComponent(e)}`}function T0(e){const n=(eu(e,"computer","code")??eu(e,"browser","code")??"").replace(/[\s-]/g,"");return/^\d{6}$/.test(n)?n:null}function nU(e){const n=/^(#\/settings\/(?:computer|browser))\?(.*)$/.exec(e);if(!n)return e;let s;try{s=new URLSearchParams(n[2])}catch{return e}if(!s.has("code"))return e;s.delete("code");const r=s.toString();return r?`${n[1]}?${r}`:n[1]}function sU(e){return eu(e,"connections","connection")}const rU=Fe("computer");function aU(e){return eu(e,"secrets","secret")}const _x=`${Fe("secrets")}?add=1`;function iU(e){return eu(e,"secrets","add")==="1"}function lU(e){return`${Fe("plugins")}?install=${encodeURIComponent(e)}`}const zx=`${Fe("plugins")}?tab=browse`;function Ux(e="all"){return e==="all"?zx:`${zx}&kind=${e}`}function oU(e){return`${Fe("proposals")}${e?`?plugin=${encodeURIComponent(e)}`:""}`}function cU(e){const n=/^#\/settings\/proposals\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1]).get("plugin")||null}catch{return null}}function Dw(e){const n=/^#\/settings\/plugins\?(.*)$/.exec(e);if(!n)return null;try{return new URLSearchParams(n[1])}catch{return null}}function uU(e){var s,r;const n=(r=(s=Dw(e))==null?void 0:s.get("install"))==null?void 0:r.trim();return n||null}function R0(e){var s;const n=(s=Dw(e))==null?void 0:s.get("kind");return n==="plugins"||n==="widgets"||n==="agents"?n:"all"}function I0(e){const n=Dw(e);return n!=null&&n.get("install")?"installed":(n==null?void 0:n.get("tab"))==="browse"?"browse":"installed"}const dU=[{route:$n,label:"Home"},{route:da,label:"Chat"},{route:bt,label:"Agents"},{route:At,label:"Activity"},{route:va,label:"Files"},{route:on,label:"Settings"}],hU=[{id:"you",label:"You"},{id:"access",label:"Models and access"},{id:"running",label:"Running"},{id:"plugins",label:"Plugins"}],fU=[{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:"Browser & apps",group:"access"},{id:"secrets",label:"Keys and secrets",group:"access"},{id:"connections",label:"Connections",group:"access"},{id:"lock",label:"Lock screen",group:"access"},{id:"api",label:"API tokens",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 mU(e){var n;return((n=/^#\/settings\/([a-z0-9.-]+)/.exec(e))==null?void 0:n[1])??"you"}const Bx="#/settings/notifications/recent",Wx=Fe("backup");function pU(e){const n=/^#\/conversations\/(.+)$/.exec(e);if(n)return Zc(decodeURIComponent(n[1]));const s=/^#\/email(?:\/([^/?]+))?(?:\?.*)?$/.exec(e);if(s)try{return _r("email","mail",s[1]?decodeURIComponent(s[1]):null)}catch{return _r("email","mail")}if(e==="#/settings/email")return mr("email","settings");const r=/^#\/settings\/browser(\?.*)?$/.exec(e);return r?`${Fe("computer")}${r[1]??""}`:{"#/overview":$n,"#/approvals":$n,"#/events":`${At}/events`,"#/jobs":`${At}/jobs`,"#/conversations":At,"#/missions":`${bt}?tab=missions`,"#/offers":`${bt}?tab=offers`,"#/reminders":`${bt}?tab=reminders`,"#/providers":Fe("accounts"),"#/browser":Fe("computer"),"#/sentinels":Fe("watchers"),"#/settings/sentinels":Fe("watchers")}[e]??null}function zA(e){if(e===""||e==="#"||e===$n)return $n;if(e.startsWith(da))return da;if(e.startsWith(bt))return bt;if(e.startsWith(At))return At;if(e.startsWith(va))return va;if(e.startsWith(on))return on;const n=Mw(e);return n?_r(n.plugin,n.page):$n}const gU="#/chat?group=new";function xU(e){const n=e.replace(/^#\/?/,"").split("?")[0].toLowerCase();if(n==="")return"home";const[s,r]=n.split("/");return!s||!/^[a-z0-9-]+$/.test(s)?null:(s==="settings"||s==="p")&&r&&/^[a-z0-9.-]+$/.test(r)?`${s}/${r}`:s}const $u="front-desk",Lw=[{id:$u,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."}],UA=new Set(Lw.map(e=>e.id)),P0=e=>UA.has(e);function M0(e,n){const s=n.filter(r=>!UA.has(r));return[...Lw.filter(r=>e.has(r.id)).map(r=>r.id),...s.filter((r,a)=>s.indexOf(r)===a)]}function vU(e,n){return e.find(s=>(s.roles??[]).includes(n))}const O0=["coding","finance","mail","research","calendar","files","memory"],jU={developer:"coding",coding:"coding",finance:"finance",credit:"finance",mail:"mail",email:"mail",research:"research",calendar:"calendar",files:"files",memory:"memory",[$u]:"buddi"},wU=[["mail",["email"]],["finance",["finance"]],["coding",["developer"]],["research",["web","browser"]],["art",["image"]]];function yU(e){const n=new Set(e.map(s=>s.split(".")[0]??s));for(const[s,r]of wU)if(r.some(a=>n.has(a)))return s;return n.size>0&&[...n].every(s=>s==="memory")?"memory":null}let Hx=null;function bU(e){Hx=e}function So(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=jU[s];if(r)return{key:r}}const n=yU(e.tools??[]);return n?{key:n}:Hx!==null&&e.id===Hx?{key:"buddi"}:{key:O0[kU(e.id)%O0.length]??"coding"}}function Hi(e){return e.key==="own"?{"data-agent":"own",style:{"--agent-fill":e.hex}}:{"data-agent":e.key}}function kU(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n}const NU=["run.started","tool.called","tool.result","message.appended","awaiting-approval","run.finished","reaction","live","live.settle","live.snapshot","attention","closing","ping"];function SU(e){const s=e.replace(/\r\n/g,`
|
|
91
|
-
`).split(`
|
|
92
|
-
|
|
93
|
-
`),r=s.pop()??"",a=[];for(const i of s){let l=null,o="message";const c=[];for(const u of i.split(`
|
|
94
|
-
`)){if(u===""||u.startsWith(":"))continue;const h=u.indexOf(":"),f=h===-1?u:u.slice(0,h),m=h===-1?"":u.slice(h+1).replace(/^ /,"");f==="id"?l=m:f==="event"?o=m:f==="data"&&c.push(m)}c.length===0&&o==="message"||a.push({id:l,name:NU.includes(o)?o:"ping",data:CU(c.join(`
|
|
95
|
-
`))})}return{events:a,rest:r}}function CU(e){if(e==="")return{};try{const n=JSON.parse(e);return n!==null&&typeof n=="object"?n:{value:n}}catch{return{value:e}}}function tm(e){const n=e.fetchImpl??globalThis.fetch.bind(globalThis),s=e.wait??(u=>new Promise(h=>setTimeout(h,u))),r=e.retryMs??1500;let a=e.lastEventId??null,i=!1,l=!1,o=null;return(async()=>{var u,h,f,m,p;for(;!i;){(u=e.onStatus)==null||u.call(e,"connecting"),o=new AbortController;try{const g=await n(e.url,{credentials:"same-origin",signal:o.signal,headers:{Accept:"text/event-stream",...a===null?{}:{"Last-Event-ID":a}}});if(!g.ok||!g.body)throw new Error(`stream ${g.status}`);(h=e.onStatus)==null||h.call(e,"open"),l&&((f=e.onReconnect)==null||f.call(e));const x=g.body.getReader(),k=new TextDecoder;let j="";for(;;){const{done:v,value:w}=await x.read();if(v)break;j+=k.decode(w,{stream:!0});const{events:y,rest:N}=SU(j);j=N;for(const b of y)e.onEvent(b),b.id!==null&&(a=b.id);if(i)break}}catch{}if(i)break;l=!0,(m=e.onStatus)==null||m.call(e,"closed"),await s(r)}(p=e.onStatus)==null||p.call(e,"closed")})(),{close:()=>{i=!0,o==null||o.abort()},lastEventId:()=>a}}const Fw="0.1.0+85200a2";function _w(e,n=Fw){return typeof e=="string"&&e!==""&&typeof n=="string"&&n!==""&&e!==n}function EU(){var e;try{if((e=window.matchMedia)!=null&&e.call(window,"(display-mode: standalone)").matches)return!0}catch{}return window.navigator.standalone===!0}const $U=5*6e4,AU=6e4,TU=5e3,tu="buddi:stream-reconnected",BA="buddi.autoReloadedFor";function RU(){window.dispatchEvent(new Event(tu))}const D0=["keydown","pointerdown","pointermove","wheel","touchstart","input"];let zw=Date.now(),hd=0;const L0=()=>{zw=Date.now()};function IU(){if(hd===0){zw=Date.now();for(const e of D0)window.addEventListener(e,L0,{capture:!0,passive:!0})}return hd+=1,()=>{if(hd-=1,hd===0)for(const e of D0)window.removeEventListener(e,L0,{capture:!0})}}function PU(e=Date.now()){return e-zw}function WA(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 MU(e){return e.hidden?!0:e.idleMs>=AU&&!e.busy}function OU(e){try{return window.sessionStorage.getItem(BA)===e}catch{return!1}}function DU(e){try{window.sessionStorage.setItem(BA,e)}catch{}}function LU(e){const n=d.useRef(e);n.current=e,d.useEffect(()=>{const s=()=>n.current();return window.addEventListener(tu,s),()=>window.removeEventListener(tu,s)},[])}function FU(e,n=()=>window.location.reload(),s=Fw){const r=_w(e,s),a=d.useRef(n);a.current=n,d.useEffect(()=>IU(),[]),d.useEffect(()=>{if(!r||e===void 0||OU(e))return;let i=!1;const l=()=>{if(i)return;const c=document.visibilityState==="hidden";MU({hidden:c,idleMs:PU(),busy:WA()})&&(i=!0,DU(e),a.current())};l();const o=window.setInterval(l,TU);return document.addEventListener("visibilitychange",l),()=>{window.clearInterval(o),document.removeEventListener("visibilitychange",l)}},[r,e])}const _U=9e4,HA=5*6e4,zU=500,UU=2e3,BU=3e3,WU="/_buddi/ready",Wl={reload:()=>window.location.reload(),now:()=>Date.now()};let ti=null,Rl=null,sc=null;const Kx=new Set;function Fh(e){ti=e;for(const n of Kx)n()}function F0(){return ti}function HU(e){return Kx.add(e),()=>Kx.delete(e)}function KU(){const e=new Uint8Array(32);return crypto.getRandomValues(e),[...e].map(n=>n.toString(16).padStart(2,"0")).join("")}async function Uw(e=BU){const n=new AbortController,s=setTimeout(()=>n.abort(),e);try{const r=await fetch(`${WU}?challenge=${KU()}`,{cache:"no-store",credentials:"omit",redirect:"error",signal:n.signal,headers:{Accept:"application/json"}});if(r.status!==200)return null;const a=await r.json().catch(()=>null);return typeof(a==null?void 0:a.boot)=="string"?a.boot:""}catch{return null}finally{clearTimeout(s)}}async function VU(){const e=await Uw();e&&(Rl=e)}function GU(){let e=Rl,n=!1,s=!1,r=zU,a;const i=async()=>{if(n)return;const l=await Uw();if(!n){if(l===null)s=!0;else if(e!==null?l!==e:s){n=!0,Wl.reload();return}else e===null&&l!==""&&(e=l);r=Math.min(Math.round(r*1.5),UU),a=setTimeout(()=>void i(),r)}};return a=setTimeout(()=>void i(),r),()=>{n=!0,clearTimeout(a)}}function nm(e){if(ti){if(e.kind==="detected")return;Fh({...ti,...e});return}Fh({...e,startedAt:Wl.now()}),sc=GU()}function KA(e){ti&&Fh({...ti,...e})}function no(){sc==null||sc(),sc=null,Fh(null)}async function sm(e,n){nm(e);try{return await n()}catch(s){if(Oh(s))return;throw no(),s}}function YU(e){nm({kind:e.for==="stop"?"stop":"detected"})}async function _0(){if(ti)return;const e=await Uw();if(Rl===null){e&&(Rl=e);return}if(!(!e||e===Rl||ti)){if(WA()){Rl=e;return}nm({kind:"detected"})}}function qU(e){const[n,s]=e;if(!n)return null;const r=`${n.name} ${n.version}`;return s?e.length===2?`${r} and ${s.name} ${s.version}`:`${r} and ${e.length-1} more`:r}const QU="/api/chat/attention/stream";function VA(e,n){const s=(i,l)=>i.name.localeCompare(l.name),r=i=>e.filter(l=>l.anchor===i).sort(s),a=e.filter(i=>i.anchor!=="top"&&i.anchor!=="bottom").sort((i,l)=>i.id===n?l.id===n?0:-1:l.id===n?1:s(i,l));return{top:r("top"),middle:a,bottom:r("bottom")}}function GA(e,n){const s=VA(e,n);return[...s.top,...s.middle,...s.bottom]}function rm(e){if(!e)return null;const n=[];return e.approvals>0&&n.push(e.approvals===1?"one approval is waiting for you":`${e.approvals} approvals are waiting for you`),e.question&&n.push("asked you a question and is holding for the answer"),n.length===0?null:n.join(", and ")}function JU(e){if(!e)return null;const n=e.approvals,s=n===1?"1 approval":`${n} approvals`;return n>0&&e.question?`${s} and a question`:n>0?`${s} waiting`:e.question?"Has a question":null}function XU(e,n){return e&&(e.approvals>0||e.question)?"needs":n?"working":null}function ZU(e){return new Map(((e==null?void 0:e.agents)??[]).map(n=>[n.agentId,n]))}function e6(){const[e,n]=d.useState(null);return d.useEffect(()=>{let s=!1;const r=()=>{ye("/chat/attention").then(i=>{s||n(i)}).catch(()=>{})};r();const a=tm({url:QU,onEvent:i=>i.name==="closing"?YU(i.data):r(),onReconnect:RU});return()=>{s=!0,a.close()}},[]),ZU(e)}const zr="maker";function Bw(e){return e.filter(n=>n.available&&!n.roles.includes(zr))}function YA(e){return Bw(e).length>=2}function t6(e){var n;return((n=e.find(s=>s.roles.includes(zr)))==null?void 0:n.name)??"the agent maker"}const n6="{{default}}";function s6(e,n){return e.split(n6).join(n??"your assistant")}function r6(e,n){return((e==null?void 0:e.starters)??[]).slice(0,3).map(s=>s6(s,n))}function a6(e){var s,r;const n=(s=e==null?void 0:e.intro)==null?void 0:s.trim();return n&&n!==""?n:((r=e==null?void 0:e.description)==null?void 0:r.trim())??""}function i6(e){const n=(e??"·").trim().split(/\s+/).filter(Boolean);return n.length===0?"·":n.length===1?n[0].slice(0,2).toUpperCase():(n[0][0]+n[1][0]).toUpperCase()}function qA(e){var r,a;const n=(r=e.heldBack)==null?void 0:r.message.trim();if(n!==void 0&&n!=="")return`${e.name??"This agent"} is held back. ${n}`;const s=(a=e.unavailableReason)==null?void 0:a.trim();return s&&s!==""?`${e.name??"This agent"} cannot run: ${s}`:`${e.name??"This agent"} cannot run: it has no model account yet.`}const l6="Settings → Model accounts",o6="Install it in Settings → Plugins";function Vx(e){return e!=null&&e.heldBack?{section:"plugins",label:o6}:{section:"accounts",label:l6}}const c6={home:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M3.5 9.2 10 3.6l6.5 5.6"}),t.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,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M7 8.3h6M7 11.3h3.6"})]})],agents:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7.5",cy:"7",r:"2.8"}),t.jsx("path",{d:"M2.8 16.2a4.7 4.7 0 0 1 9.4 0"}),t.jsx("circle",{cx:"14",cy:"7.8",r:"2.2"}),t.jsx("path",{d:"M13.2 12.5a3.9 3.9 0 0 1 4.3 3.7"})]})],activity:[20,1.6,t.jsx("path",{d:"M2.8 10.5h3.4l2-5.2 3.4 9.8 2.2-4.6h3.4"})],settings:[24,1.9,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),20],files:[20,1.6,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M12.7 2.8v3.8h3.8"}),t.jsx("path",{d:"M4.4 6.2v9.4a1.6 1.6 0 0 0 1.6 1.6h6.6"})]})],mail:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"3",y:"5",width:"14",height:"10.5",rx:"1.4"}),t.jsx("path",{d:"M3.4 6 10 11l6.6-5"})]})],money:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.6",y:"5.2",width:"14.8",height:"9.6",rx:"1.6"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.2"}),t.jsx("path",{d:"M5.4 10h.5M14.1 10h.5"})]})],calendar:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"3",y:"4.4",width:"14",height:"12.2",rx:"1.6"}),t.jsx("path",{d:"M3 8.2h14M6.8 2.9v2.6M13.2 2.9v2.6"})]})],chart:[20,1.6,t.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,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.4 13.6V9a4.6 4.6 0 0 1 9.2 0v4.6l1.2 1.7H4.2Z"}),t.jsx("path",{d:"M8.4 17.1a1.8 1.8 0 0 0 3.2 0"})]})],plug:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.4 2.8v3.4M12.6 2.8v3.4"}),t.jsx("path",{d:"M5 6.2h10v3.1a5 5 0 0 1-10 0Z"}),t.jsx("path",{d:"M10 14.3v3"})]})],key:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"6.6",cy:"10",r:"3.2"}),t.jsx("path",{d:"M9.8 10h7.2M14.4 10v2.6M16.6 10v1.8"})]})],globe:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.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"})]})],news:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4 3.6h9.2a.8.8 0 0 1 .8.8v11.2a.8.8 0 0 0 .8.8H5.2A1.6 1.6 0 0 1 3.6 14.8V4a.4.4 0 0 1 .4-.4Z"}),t.jsx("path",{d:"M14 7h1.6a.8.8 0 0 1 .8.8v7.2a1.4 1.4 0 0 1-1.4 1.4"}),t.jsx("path",{d:"M6.4 6.8h4.4M6.4 9.8h4.4M6.4 12.8h2.8"})]})],terminal:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.6"}),t.jsx("path",{d:"M6.2 8l2.6 2.4-2.6 2.4M10.6 12.8h3.4"})]})],person:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"7",r:"3.2"}),t.jsx("path",{d:"M4 16.6a6 6 0 0 1 12 0"})]})],briefcase:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"6",width:"14.4",height:"10.2",rx:"1.6"}),t.jsx("path",{d:"M7.4 6V4.6a1 1 0 0 1 1-1h3.2a1 1 0 0 1 1 1V6M2.8 10.4h14.4"})]})],pin:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M10 17.2s5.2-4.9 5.2-9a5.2 5.2 0 0 0-10.4 0c0 4.1 5.2 9 5.2 9Z"}),t.jsx("circle",{cx:"10",cy:"8.2",r:"1.9"})]})],sun:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),t.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,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M7.6 3.2v13.6M10 7h2.6M10 9.8h2.6"})]})],bulb:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M7.2 13.2a5 5 0 1 1 5.6 0v1.6H7.2Z"}),t.jsx("path",{d:"M8 17.2h4"})]})],monitor:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"10",rx:"1.4"}),t.jsx("path",{d:"M7.4 16.8h5.2M10 13.6v3.2"})]})],lock:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"4",y:"8.6",width:"12",height:"8.6",rx:"2.2"}),t.jsx("path",{d:"M6.8 8.6V6.2a3.2 3.2 0 0 1 6.4 0v2.4"})]})],eye:[20,1.6,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.4"})]})],archive:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"3.6",rx:"1"}),t.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,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5.4",y:"5.4",width:"9.2",height:"9.2",rx:"1.4"}),t.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,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7.4",cy:"7.4",r:"2.4"}),t.jsx("path",{d:"M7.4 2.8v1M2.8 7.4h1M4.2 4.2l.7.7M10.6 4.2l-.7.7"}),t.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,t.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,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M7.2 14.6l-.8 2M10.4 14.6l-.8 2M13.6 14.6l-.8 2"})]})],drizzle:[20,1.6,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M7 15.2v.3M10 16.4v.3M13 15.2v.3"})]})],snow:[20,1.6,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M7.4 14.4v2.4M6.2 15.6h2.4M12.6 14.4v2.4M11.4 15.6h2.4"})]})],storm:[20,1.6,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("path",{d:"M10.8 13.2 9 15.6h2.4l-1.8 2.6"})]})],fog:[20,1.6,t.jsx("path",{d:"M3.6 7.2h12.8M5.2 10.2h9.6M3.6 13.2h12.8M6.4 16.2h7.2"})],wind:[20,1.6,t.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,t.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"})],"moon-cloud":[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M9.4 6.8A3.6 3.6 0 0 1 4.6 2a3.6 3.6 0 1 0 4.8 4.8Z"}),t.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"})]})],clock:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("path",{d:"M10 5.8V10l2.8 1.8"})]})],dot:[20,1.6,t.jsx("circle",{cx:"10",cy:"10",r:"2.2"})],camera:[17,1.5,t.jsxs(t.Fragment,{children:[t.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"}),t.jsx("circle",{cx:"8.5",cy:"9.2",r:"2.4"})]})],clip:[17,1.5,t.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,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"6.3",y:"2.4",width:"4.4",height:"7.6",rx:"2.2"}),t.jsx("path",{d:"M3.9 8.4a4.6 4.6 0 0 0 9.2 0M8.5 13v2"})]})],speaker:[17,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M2.8 6.6h2.4l3.4-2.8v9.4l-3.4-2.8H2.8z"}),t.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,t.jsx("path",{d:"M8 13V3.5M3.8 7.7 8 3.5l4.2 4.2"})],check:[16,1.8,t.jsx("path",{d:"M3.5 8.4 6.6 11.4 12.5 4.8"})],close:[16,1.8,t.jsx("path",{d:"M4.5 4.5l7 7M11.5 4.5l-7 7"})],search:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"7",cy:"7",r:"4.5"}),t.jsx("path",{d:"M10.5 10.5L14 14"})]})],alert:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"8",cy:"8",r:"6.2"}),t.jsx("path",{d:"M8 4.8v3.8M8 11.2v.01"})]})],thought:[13,1.4,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4.2 9.6a3.6 3.6 0 1 1 4.6 0v1.2H4.2z"}),t.jsx("path",{d:"M5.2 12.2h2.6"})]})],chevron:[11,1.5,t.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})],arrow:[13,1.5,t.jsx("path",{d:"M4.8 2.6 9 6.5l-4.2 3.9"})],back:[16,1.6,t.jsx("path",{d:"M13 8H3.4M7.4 4 3.4 8l4 4"})],forward:[16,1.6,t.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})],reload:[16,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M13 8a5 5 0 1 1-1.6-3.7"}),t.jsx("path",{d:"M11.8 1.9v2.8H9"})]})],expand:[16,1.6,t.jsx("path",{d:"M9.6 2.8h3.6v3.6M13.2 2.8 9 7M6.4 13.2H2.8V9.6M2.8 13.2 7 9"})],collapse:[16,1.6,t.jsx("path",{d:"M12.8 7H9V3.2M9 7l4.2-4.2M3.2 9H7v3.8M7 9l-4.2 4.2"})],copy:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"5.6",y:"5.6",width:"7.6",height:"7.6",rx:"1.4"}),t.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,t.jsx("path",{d:"M5.2 3.4v9.2L12.6 8z"})],pause:[16,1.5,t.jsx("path",{d:"M5.6 3.6v8.8M10.4 3.6v8.8"})],stop:[16,1.5,t.jsx("rect",{x:"4.2",y:"4.2",width:"7.6",height:"7.6",rx:"1.2"})],download:[16,1.5,t.jsx("path",{d:"M8 2.8v7.2M4.9 7 8 10.1 11.1 7M3 12.8h10"})],out:[12,1.6,t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"6",cy:"6",r:"4.4"}),t.jsx("path",{d:"M3.4 8.6 8.6 3.4"})]}),11],external:[12,1.6,t.jsx("path",{d:"M4.5 3H9v4.5M9 3 3 9"}),11],"chevron-left":[14,1.6,t.jsx("path",{d:"M9 2.5 4.5 7 9 11.5"})],"chevron-right":[14,1.6,t.jsx("path",{d:"M5 2.5 9.5 7 5 11.5"})],plus:[14,1.6,t.jsx("path",{d:"M7 2.5v9M2.5 7h9"})],grip:[16,0,t.jsxs("g",{fill:"currentColor",stroke:"none",children:[t.jsx("circle",{cx:"6",cy:"4",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"4",r:"1.2"}),t.jsx("circle",{cx:"6",cy:"8",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"8",r:"1.2"}),t.jsx("circle",{cx:"6",cy:"12",r:"1.2"}),t.jsx("circle",{cx:"10",cy:"12",r:"1.2"})]})],more:[16,0,t.jsxs("g",{fill:"currentColor",stroke:"none",children:[t.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})],drop:[28,1.8,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),t.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,t.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,t.jsx("path",{d:"M4 5.5 7 8.5l3-3"}),12],frame:[22,1.3,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2.6",y:"3.6",width:"16.8",height:"14.8",rx:"2"}),t.jsx("path",{d:"M2.6 14.2 7.4 9.6l3.4 3 3-2.6 3.6 3.2"}),t.jsx("circle",{cx:"7.4",cy:"7.6",r:"1.2"})]})],"shape-timeseries":[16,1.4,t.jsx("path",{d:"M2 11.5 5.4 7.2l2.6 2.2L14 3.5"})],"shape-table":[16,1.4,t.jsx("path",{d:"M2.2 3.5h11.6v9H2.2zM2.2 6.6h11.6M6.6 6.6v5.9"})],"shape-bars":[16,1.4,t.jsx("path",{d:"M3 13V8.2M7 13V3.6M11 13V6.4M2 13.6h12"})],"shape-keyvalue":[16,1.4,t.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,t.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,t.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3M6 9h4M6 11.2h3"})],"shape-diff":[16,1.4,t.jsx("path",{d:"M8 2.6v5M5.5 5.1h5M5.5 11.6h5M3 14h10"})],"shape-terminal":[16,1.4,t.jsx("path",{d:"M2.2 3.4h11.6v9.2H2.2zM4.6 6.4l2 1.6-2 1.6M8 10h3"})],"shape-image":[16,1.4,t.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,t.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,t.jsx("path",{d:"M2.2 4h11.6v8H2.2zM2.2 4.4 8 8.8l5.8-4.4"})],moon:[16,1.5,t.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"})],code:[16,1.6,t.jsx("path",{d:"M5.8 4.6L2.4 8l3.4 3.4M10.2 4.6L13.6 8l-3.4 3.4"})],"pasted-doc":[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4 2.5h5.2L12 5.3v8.2H4z"}),t.jsx("path",{d:"M9 2.5v3h3M6 8.5h4M6 10.8h4"})]})],"shape-structured":[16,1.4,t.jsx("path",{d:"M4 2.6h8v10.8H4zM6.2 5.6h3.6M6.2 8h3.6M6.2 10.4h2.2"})]};function oe({name:e,size:n,className:s,...r}){const[a,i,l,o]=c6[e],c=n??o??a;return t.jsx("svg",{className:s,width:c,height:c,viewBox:`0 0 ${a} ${a}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round","data-icon":e,...r,children:l})}const QA="buddi.rosterCollapsed";function u6(){try{return window.localStorage.getItem(QA)==="1"}catch{return!1}}function d6(e){try{window.localStorage.setItem(QA,e?"1":"0")}catch{}}function JA({agents:e,currentId:n,attention:s,onSelect:r,orientation:a="vertical",lastActivity:i,working:l,groups:o=[],currentGroupId:c=null,onSelectGroup:u,onNewGroup:h}){const f=[...e.top,...e.middle,...e.bottom],m=a==="vertical"?"right":"bottom",[p,g]=d.useState(u6),x=k=>t.jsx(h6,{agent:k,active:k.id===n,attention:s.get(k.id),side:m,onSelect:r,lastAt:(i==null?void 0:i.get(k.id))??null,working:(l==null?void 0:l.has(k.id))??!1},k.id);return t.jsxs("nav",{className:a==="vertical"?"wb-agent-rail":"wb-agent-strip","aria-label":"Agents","data-testid":"agent-rail","data-collapsed":a==="vertical"&&p?"true":void 0,children:[e.top.map(x),e.top.length>0&&e.middle.length>0?t.jsx("span",{className:"wb-agent-sep","data-testid":"agent-rail-sep","aria-hidden":"true"}):null,a==="vertical"&&!p&&e.middle.length>0?t.jsx("span",{className:"wb-roster-label",children:"Your team"}):null,t.jsxs("div",{className:"wb-agent-scroll",children:[e.middle.map(x),u&&YA(f)?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsxs("div",{className:"wb-groups-head",children:[t.jsx("span",{className:"wb-groups-label",children:"Groups"}),h?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"New group",title:"A team of agents in one conversation",onClick:h,children:t.jsx(oe,{name:"plus"})}):null]}),o.map(k=>t.jsxs("button",{type:"button",className:"wb-face wb-group-face","data-active":k.id===c?"true":void 0,"aria-current":k.id===c?"true":void 0,"aria-label":`${k.name}, ${k.members.length} agents`,onClick:()=>u(k.id),children:[t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:k.members.slice(0,2).map(j=>{const v=f.find(w=>w.id===j);return t.jsx(am,{className:"wb-group-chip",id:j,name:(v==null?void 0:v.name)??"?",face:v,initials:1},j)})}),t.jsxs("span",{className:"wb-face-text",children:[t.jsx("span",{className:"wb-face-name",children:k.name}),t.jsx("span",{className:"wb-face-status",children:k.members.map(j=>{var v;return((v=f.find(w=>w.id===j))==null?void 0:v.name)??j}).join(", ")})]})]},k.id))]}):u?t.jsxs("div",{className:"wb-groups","data-testid":"group-rail-hint",children:[t.jsx("span",{className:"wb-agent-sep","aria-hidden":"true"}),t.jsx("div",{className:"wb-groups-head",children:t.jsx("span",{className:"wb-groups-label",children:"Groups"})}),t.jsxs("p",{className:"wb-groups-hint",children:["A group needs two agents; ",t.jsx("a",{href:bt,children:"add a teammate"}),"."]})]}):null]}),e.bottom.map(x),a==="vertical"?t.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(k=>(d6(!k),!k)),children:t.jsx(oe,{name:p?"chevron-right":"chevron-left"})}):null]})}function h6({agent:e,active:n,attention:s,side:r,onSelect:a,lastAt:i=null,working:l=!1}){const o=rm(s),c=JU(s)??(e.available?i?O_(i):e.description:e.unavailableReason??"Cannot run right now"),u=XU(s,l&&e.available),h=e.unavailableReason??"This agent cannot run on this machine right now.",f=[`${e.name} @${e.handle}`,e.available?null:"unavailable",o,u==="working"?"working now":null,n?"current":null].filter(m=>m!==null&&m!=="").join(" — ");return t.jsxs(Kc,{children:[t.jsx(Vc,{asChild:!0,children:t.jsxs("button",{className:"wb-face",...Hi(So(e)),"data-active":n?"true":void 0,"data-unavailable":e.available?void 0:"true","data-testid":`agent-face-${e.id}`,"aria-label":f,"aria-current":n?"true":void 0,disabled:!e.available,onClick:()=>e.available&&a(e.id),children:[t.jsxs("span",{className:"wb-face-frame",children:[t.jsx(am,{className:"wb-face-mark",id:e.id,name:e.name,face:e}),u?t.jsx("span",{className:"wb-face-dot","data-state":u,"data-testid":`agent-dot-${e.id}`,"aria-hidden":"true"}):null]}),t.jsxs("span",{className:"wb-face-text","aria-hidden":"true",children:[t.jsx("span",{className:"wb-face-name",children:e.name}),t.jsx("span",{className:"wb-face-status","data-tone":o?"critical":void 0,children:c})]}),e.available?null:t.jsx("span",{className:"wb-face-out","aria-hidden":"true",children:t.jsx(oe,{name:"out"})})]})}),t.jsx(Gc,{children:t.jsxs(Yc,{className:"ui-tip",side:r,sideOffset:8,children:[t.jsx("span",{className:"ui-tip-title",children:e.name}),t.jsx("span",{className:"ui-tip-hint",children:e.available?`@${e.handle} · ${e.model}`:h}),o?t.jsx("span",{className:"ui-tip-alert",children:f6(o)}):null]})})]})}function f6(e){return`${e.slice(0,1).toUpperCase()}${e.slice(1)}.`}function m6(e){let n=0;for(const s of e)n=(n*31+s.charCodeAt(0))%997;return n%6+1}const p6="modulepreload",g6=function(e,n){return new URL(e,n).href},z0={},x6=function(n,s,r){let a=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"));a=Promise.allSettled(s.map(u=>{if(u=g6(u,r),u in z0)return;z0[u]=!0;const h=u.endsWith(".css"),f=h?'[rel="stylesheet"]':"";if(!!r)for(let g=l.length-1;g>=0;g--){const x=l[g];if(x.href===u&&(!h||x.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${f}`))return;const p=document.createElement("link");if(p.rel=h?"stylesheet":p6,h||(p.as="script"),p.crossOrigin="",p.href=u,c&&p.setAttribute("nonce",c),document.head.appendChild(p),h)return new Promise((g,x)=>{p.addEventListener("load",g),p.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${u}`)))})}))}function i(l){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=l,window.dispatchEvent(o),!o.defaultPrevented)throw l}return a.then(l=>{for(const o of l||[])o.status==="rejected"&&i(o.reason);return n().catch(i)})},v6="buddi",j6=["core","coding","finance","garage","mail","maker","playground","research"],el=e=>`./mascot/${e}.png`,w6=["core"],Gx=(e,n)=>w6.includes(e)?`./mascot/anim/${e}-${n}.json`:null,y6=["🙂","📚","🧭","🦊","🛟","🌿","🛠️","🎧"],b6="Introduce yourself by name and say one thing you can do today.",k6=["Hello","A brain","What I take on","Reach me","Your assistant"],fd=(e,n=!1)=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")}${n&&e.length>2?", and ":" and "}${e[e.length-1]}`,yp=e=>e.charAt(0).toUpperCase()+e.slice(1),N6=["No","One","Two","Three","Four","Five","Six","Seven","Eight"],_h=[{id:"days",title:"My days",plugins:"Weather · Calendar",line:"Weather and your calendars, for a brief every morning.",note:"Weather needs nothing. Calendar asks for your calendar’s private link in chapter 4."},{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, kept on this computer.",note:"Finance reads the statements you hand it; no bank sign-in."},{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:"One picture from a prompt, with an account you pick.",note:"Image asks which account to draw with."}],S6=["days","mail"],U0=[{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"}],L={tagline:"Setting up, on this Mac.",taglineElsewhere:"Setting up, on this computer.",chapters:k6,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. At the end I suggest teammates for what you picked; nothing runs until you have read its card, and you can say no to any of them.","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,n)=>`${e} · ${n}`,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",instruct:"Open openai.com, type this code there and approve buddi. I’ll notice.",waiting:"Waiting for your approval…",signedIn:e=>e?`Signed in as ${e}.`:"Signed in.",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 n=r=>r===1?"one model":`${r} models`;return`Free and private. I found ${[e.ollama!==void 0?`Ollama with ${n(e.ollama)}`:null,e.mlxh!==void 0?`mlxh with ${n(e.mlxh)}`:null].filter(Boolean).join(" and ")}; the first answer takes a minute.`},missing:"Free, private, no key. Not here yet: I show you how to install Ollama and fetch a model."},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",copy:"Copy",copied:"Copied",missing:e=>`Ollama isn’t on ${e} yet. Install it, open it, and I’ll notice; I never run an installer for you.`,missingHow:(e,n)=>e==="linux"?`The official script from ollama.com. Paste it into a terminal on ${n}.`:e==="darwin"?"In Terminal, with Homebrew. Or download the app.":"Download it from ollama.com and open it.",stopped:e=>`Ollama is installed but not running. Open the Ollama app${e==="linux"?", or start it with the command below":""}, and I’ll notice.`,empty:(e,n,s,r)=>`Ollama is running, with no model yet. For ${e}’s ${Math.round(n)} GB I’d fetch ${s}: about ${r} GB, once.`,emptyFoot:e=>`Free and private: it runs here, and nothing you say leaves ${e}.`,fetch:e=>`Fetch ${e}`,fetching:(e,n,s)=>s?`Fetching ${e}: ${n} of ${s} GB.`:`Fetching ${e}…`,fetchingFoot:"Keep this page open or not: Ollama keeps fetching, and I pick up where it is.",failed:e=>`The download stopped: ${e} Try again; it picks up where it was.`,again:"Try again",cloud:(e,n)=>e==="memory"?`${Math.round(n)} GB is little for a model of its own: it would be slow. Ollama Cloud runs bigger models for you, free to start.`:e==="gpu"?"No graphics chip Ollama can use here: it would be slow. Ollama Cloud runs bigger models for you, free to start.":"Rather not run a model here? Ollama Cloud runs bigger models for you, free to start.",useCloud:"Use Ollama Cloud instead",honestTitle:"A small model, honestly",honest:"Private and free, but slower and less able than Claude or ChatGPT: fine for chat, notes and reminders; weaker at long plans, careful tool use and code. Home shows how to add a stronger brain whenever you like."},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,n,s)=>`Fetching ${fd(e)} from withbuddi.com and reading them. ${n} of ${s}.`,ready:e=>`${fd(e)} ${e.length>1?"are":"is"} in, read and ready.`,failed:(e,n)=>`${e} did not come: ${n}.`,installing:(e,n)=>`Installing, ${e} of ${n} ready`,installed:"Installed",answer:e=>e.length===0?"Just an assistant":yp(e.join(", ").toLowerCase())},reach:{title:"How do we reach each other?",ask:"A few 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",pair:"Pair your phone",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."},calendar:{title:"Your calendar",line:"Its private link, or a Google sign-in. Reading only until you say otherwise.",waiting:"Calendar is still being fetched. The button wakes up when it is in.",add:"Link a calendar",linked:"Calendar linked"},bank:{title:"Your bank",line:"No bank sign-in: Finance reads the statements you hand it.",add:"How it works",later:"After setup"},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. Chrome pairs later, in Settings → Browser & apps.",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",inApp:{title:"buddi is in your Dock, and a browser of its own",line:"You’re in buddi.app already. To open it when your Mac starts, choose Start at Login in the buddi menu at the top of your screen. Give your assistant Chrome or its own Chromium (150 MB) so it can look at websites. Chrome pairs later, in Settings → Browser & apps.",extension:"Get the Chrome extension"}},answer:e=>e.length===0?"Later, in Settings":yp(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.",making:"Making a code…",waiting:"Waiting for your Start…",pairedWith:e=>e!=null&&e.trim()?`Paired with ${e.trim()}’s phone`:"Paired with your phone",expired:"That code has run out. I can make you another one.",newCode:"Show a new code",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: ${fd(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(`
|
|
96
|
-
`),submit:"Introduce us",refusedTitle:"You already have an assistant.",toAgents:"Open Agents"},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=>[e.days?"What’s my day like?":"What can you do?","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=>`${N6[e]??String(e)} ${e===1?"thing":"things"} still waiting.`,waitingBody:e=>`${yp(fd(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 md=null;const B0=new Map;function C6(){return md??(md=x6(()=>import("./lottie_light-CQmEj1as.js").then(e=>e.l),[],import.meta.url).then(e=>e.default)),md.catch(()=>{md=null}),md}function E6(e){let n=B0.get(e);return n||(n=fetch(e).then(s=>s.ok?s.text():null).catch(()=>null),B0.set(e,n)),n}const W0="(prefers-reduced-motion: reduce)";function XA(){const[e,n]=d.useState(()=>typeof window.matchMedia=="function"&&!window.matchMedia(W0).matches);return d.useEffect(()=>{var a;if(typeof window.matchMedia!="function")return;const s=window.matchMedia(W0),r=()=>n(!s.matches);return(a=s.addEventListener)==null||a.call(s,"change",r),()=>{var i;return(i=s.removeEventListener)==null?void 0:i.call(s,"change",r)}},[]),e}function Au({role:e="core",state:n,size:s,still:r,className:a,onStillError:i}){const l=d.useRef(null),o=XA(),[c,u]=d.useState(!1),h=s==="xs"?null:Gx(e,n);return d.useEffect(()=>{if(u(!1),!o||!h)return;let f=!1,m=null;return Promise.all([C6(),E6(h)]).then(([p,g])=>{if(f||!g||!l.current)return;const x=p.loadAnimation({container:l.current,renderer:"svg",loop:!0,autoplay:!document.hidden,animationData:JSON.parse(g),rendererSettings:{preserveAspectRatio:"xMidYMid meet"}}),k=()=>{document.hidden?x.pause():x.play()};document.addEventListener("visibilitychange",k),m=()=>{document.removeEventListener("visibilitychange",k),x.destroy()},u(!0)}).catch(()=>{}),()=>{f=!0,m==null||m()}},[o,h]),t.jsx("span",{ref:l,className:a?`ui-blob ${a}`:"ui-blob","data-size":s,"data-playing":c?"true":void 0,"data-testid":"blob","data-state":n,"aria-hidden":"true",children:c?null:t.jsx("img",{src:r??el(e),alt:"",onError:i})})}async function H0(e){const n=new Image;n.src=e,await n.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(n,0,0,8,8),Array.from(r.getImageData(0,0,8,8).data)):null}function ZA(e,n="core"){const s=XA(),r=e!==null&&$6(e,n),[a,i]=d.useState(!1);return d.useEffect(()=>{if(i(!1),!e||r||!s||!Gx(n,"idle"))return;let l=!1;return Promise.all([H0(e),H0(el(n))]).then(([o,c])=>{if(l||!o||!c||o.length!==c.length)return;const u=o.reduce((h,f,m)=>h+Math.abs(f-c[m]),0)/o.length;i(u<12)}).catch(()=>{}),()=>{l=!0}},[e,r,s,n]),s&&Gx(n,"idle")!==null&&(r||a)}function $6(e,n){const s=el(n);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 am({className:e,id:n,name:s,face:r,tint:a,size:i,unavailable:l,initials:o=2}){const[c,u]=d.useState(null),h=r!=null&&r.picture&&r.picture!==c?r.picture:void 0,f=r==null?void 0:r.avatar,m=h?"image":f==null?void 0:f.kind,p=n?Hi(So({id:n,accent:r==null?void 0:r.accent,roles:r==null?void 0:r.roles,tools:r==null?void 0:r.tools})):void 0;return t.jsx("span",{className:e,"data-tint":p?void 0:a,"data-size":i,"data-kind":m,"data-unavailable":l?"true":void 0,...p,"aria-hidden":"true",children:h?t.jsx("img",{src:h,alt:"",onError:()=>u(h)}):(f==null?void 0:f.kind)==="image"?t.jsx("img",{src:f.url,alt:""}):(f==null?void 0:f.kind)==="emoji"?f.value:i6(s).slice(0,o)})}function On({id:e,name:n,size:s,unavailable:r,face:a}){return t.jsx(am,{className:"ui-avatar",id:e,tint:m6(e),name:n,size:s,unavailable:r,face:a})}function jn({agents:e,id:n,size:s}){const r=e.find(a=>a.id===n);return t.jsx(On,{id:n,name:(r==null?void 0:r.name)??n,size:s,unavailable:r?!r.available:!1,face:r})}const eT=d.createContext(null);function A6({picture:e,children:n}){return t.jsx(eT.Provider,{value:e??null,children:n})}function tT({size:e,anim:n}){const s=d.useContext(eT),[r,a]=d.useState(null),i=ZA(n?s:null);return!s||s===r?null:t.jsx("span",{className:"ui-mascot","data-size":e,"data-testid":"mascot","aria-hidden":"true",children:n&&i?t.jsx(Au,{state:n,still:s,className:"ui-mascot-blob",onStillError:()=>a(s)}):t.jsx("img",{src:s,alt:"",onError:()=>a(s)})})}const nT=d.createContext([]);function pr({text:e,className:n}){const s=Yx(e.replace(/\r\n/g,`
|
|
97
|
-
`).split(`
|
|
98
|
-
`));return t.jsx("div",{className:n??"wb-md",children:s.map((r,a)=>t.jsx(qx,{block:r},a))})}const K0=/^(\s*)(```|~~~)\s*([\w+-]*)\s*$/,V0=/^(#{1,6})\s+(.*?)\s*#*\s*$/,G0=/^\s*([-*_])(\s*\1){2,}\s*$/,pd=/^(\s*)([-*+])\s+(.*)$/,Go=/^(\s*)(\d{1,9})[.)]\s+(.*)$/,gd=/^\s*>\s?(.*)$/,bp=/^\s*\|.*\|\s*$/,Y0=/^\s*\|?\s*:?-{2,}:?\s*(\|\s*:?-{2,}:?\s*)*\|?\s*$/;function Yx(e){const n=[];let s=0;for(;s<e.length;){const r=e[s];if(r.trim()===""){s+=1;continue}const a=K0.exec(r);if(a){const o=a[2],c=[];for(s+=1;s<e.length&&!new RegExp(`^\\s*${o}\\s*$`).test(e[s]);)c.push(e[s]),s+=1;s+=1,n.push({type:"code",lang:a[3]||null,text:c.join(`
|
|
99
|
-
`)});continue}const i=V0.exec(r);if(i){n.push({type:"h",level:i[1].length,text:i[2]}),s+=1;continue}if(G0.test(r)){n.push({type:"hr"}),s+=1;continue}if(gd.test(r)){const o=[];for(;s<e.length&&gd.test(e[s]);)o.push(gd.exec(e[s])[1]),s+=1;n.push({type:"quote",blocks:Yx(o),raw:o.join(`
|
|
100
|
-
`)});continue}if(bp.test(r)&&s+1<e.length&&Y0.test(e[s+1])){const o=Np(r),c=Np(e[s+1]).map(h=>{const f=h.startsWith(":"),m=h.endsWith(":");return f&&m?"center":m?"right":f?"left":null});s+=2;const u=[];for(;s<e.length&&bp.test(e[s]);)u.push(Np(e[s])),s+=1;n.push({type:"table",head:o,rows:u,align:c});continue}if(pd.test(r)||Go.test(r)){const o=Go.exec(r)??pd.exec(r),c=Go.test(r),u=o[1].length,h=c?Number(o[2]):1,f=[];for(;s<e.length;){const m=c?Go.exec(e[s]):pd.exec(e[s]);if(!m||m[1].length!==u)break;const p=[m[3]];for(s+=1;s<e.length;){const g=e[s],x=g.trim()!==""&&kp(g)>u,k=g.trim()===""&&s+1<e.length&&e[s+1].trim()!==""&&kp(e[s+1])>u;if(!x&&!k)break;p.push(g.trim()===""?"":g.slice(Math.min(kp(g),u+2))),s+=1}f.push(Yx(p))}n.push({type:"list",ordered:c,start:h,items:f});continue}const l=[];for(;s<e.length;){const o=e[s];if(o.trim()===""||K0.test(o)||V0.test(o)||G0.test(o)||gd.test(o)||pd.test(o)||Go.test(o)||bp.test(o)&&s+1<e.length&&Y0.test(e[s+1]))break;l.push(o.trim()),s+=1}l.length>0&&n.push({type:"p",text:l.join(`
|
|
101
|
-
`)})}return n}function kp(e){return e.length-e.trimStart().length}function Np(e){const n=e.trim().replace(/^\|/,"").replace(/\|$/,""),s=[];let r="";for(let a=0;a<n.length;a+=1){const i=n[a];if(i==="\\"&&n[a+1]==="|"){r+="|",a+=1;continue}if(i==="|"){s.push(r.trim()),r="";continue}r+=i}return s.push(r.trim()),s}function qx({block:e}){switch(e.type){case"p":return t.jsx("p",{children:ar(e.text)});case"h":{const n=Math.min(6,Math.max(1,e.level)),s=`h${Math.min(n+2,6)}`;return t.jsx(s,{className:"wb-md-h","data-level":n,children:ar(e.text)})}case"code":return t.jsxs("div",{className:"wb-md-code-frame",children:[t.jsxs("div",{className:"wb-md-code-head",children:[t.jsx("span",{className:"wb-md-code-lang",children:e.lang??"text"}),t.jsx(q0,{text:e.text,what:"code",always:!0})]}),t.jsx("pre",{className:"wb-md-code","data-lang":e.lang??void 0,children:t.jsx("code",{children:e.text})})]});case"quote":return t.jsxs("div",{className:"wb-md-copyable",children:[t.jsx("blockquote",{children:e.blocks.map((n,s)=>t.jsx(qx,{block:n},s))}),t.jsx(q0,{text:e.raw,what:"quote"})]});case"hr":return t.jsx("hr",{});case"list":{const n=e.items.map((s,r)=>t.jsx("li",{children:s.map((a,i)=>a.type==="p"?t.jsx(d.Fragment,{children:ar(a.text)},i):t.jsx(qx,{block:a},i))},r));return e.ordered?t.jsx("ol",{start:e.start,children:n}):t.jsx("ul",{children:n})}case"table":return t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table wb-md-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:e.head.map((n,s)=>t.jsx("th",{style:e.align[s]?{textAlign:e.align[s]}:void 0,children:ar(n)},s))})}),t.jsx("tbody",{children:e.rows.map((n,s)=>t.jsx("tr",{children:n.map((r,a)=>t.jsx("td",{style:e.align[a]?{textAlign:e.align[a]}:void 0,children:ar(r)},a))},s))})]})})}}function q0({text:e,what:n,always:s=!1}){const[r,a]=d.useState("idle"),i=()=>{var l;if(!((l=navigator.clipboard)!=null&&l.writeText)){a("failed");return}navigator.clipboard.writeText(e).then(()=>a("done"),()=>a("failed")),window.setTimeout(()=>a("idle"),1500)};return t.jsx("button",{type:"button",className:"wb-md-copy","data-state":r,"data-always":s||void 0,"aria-label":`Copy ${n}`,title:`Copy ${n}`,onClick:i,children:r==="done"?"Copied":r==="failed"?"Select to copy":t.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:[t.jsx("rect",{x:"4.5",y:"4.5",width:"6.5",height:"6.5",rx:"1.2"}),t.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 T6({handle:e}){const s=d.useContext(nT).find(r=>r.handle.toLowerCase()===e.toLowerCase());return s?t.jsxs(Kc,{children:[t.jsx(Vc,{asChild:!0,children:t.jsxs("a",{className:"wb-mention-link",href:at(s.id),children:["@",s.handle]})}),t.jsx(Gc,{children:t.jsxs(Yc,{className:"wb-agent-card",sideOffset:6,children:[t.jsx(On,{id:s.id,name:s.name,face:s,unavailable:!s.available}),t.jsxs("span",{className:"wb-agent-card-text",children:[t.jsx("span",{className:"wb-agent-card-name",children:s.name}),t.jsx("span",{className:"wb-agent-card-desc",children:s.description}),t.jsxs("span",{className:"wb-agent-card-meta",children:[s.model,s.available?"":" · unavailable"]})]})]})})]}):t.jsxs(t.Fragment,{children:["@",e]})}const R6=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 ar(e){const n=[];let s=e,r=0;for(;s!=="";){const a=R6.exec(s);if(!a){n.push(...Q0(s,r));break}a.index>0&&n.push(...Q0(s.slice(0,a.index),r)),r+=100,a[2]!==void 0?n.push(t.jsx("code",{children:a[2]},r)):a[3]!==void 0?n.push(t.jsx("strong",{children:ar(a[3])},r)):a[4]!==void 0?n.push(t.jsx("strong",{children:ar(a[4])},r)):a[5]!==void 0?n.push(t.jsx("s",{children:ar(a[5])},r)):a[6]!==void 0?n.push(t.jsx("em",{children:ar(a[6])},r)):a[7]!==void 0?n.push(t.jsx("em",{children:ar(a[7])},r)):a[8]!==void 0&&a[9]!==void 0?n.push(t.jsx("a",{href:a[9],target:"_blank",rel:"noopener noreferrer",children:ar(a[8])},r)):a[10]!==void 0?n.push(t.jsx("a",{href:a[10],target:"_blank",rel:"noopener noreferrer",children:a[10]},r)):a[11]!==void 0&&n.push(t.jsx(T6,{handle:a[11]},r)),s=s.slice(a.index+a[0].length)}return n}function Q0(e,n){return e.split(`
|
|
102
|
-
`).flatMap((r,a)=>a===0?[r]:[t.jsx("br",{},`${n}-br-${a}`),r])}function I6({props:e}){return t.jsxs("div",{children:[e.title?t.jsx("h4",{className:"wb-doc-title",children:e.title}):null,e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-block",children:e.metadata.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:yn(n.value,n.unit,null)})]},n.label))}):null,e.kind==="image"&&e.src?t.jsx("img",{src:e.src,alt:e.title??"Attached image",className:"wb-doc-image"}):e.kind==="pdf"&&e.src?t.jsx("object",{data:e.src,type:"application/pdf",className:"wb-doc-pdf",children:t.jsx("a",{href:e.src,children:"Open the PDF"})}):e.text?t.jsx("div",{className:"wb-doc",children:t.jsx(pr,{text:e.text})}):t.jsx("p",{className:"wb-empty",children:"This document came back with no body."})]})}const P6=["mail","money","calendar","people","file","chart","bell","plug","key","globe","sun","partly-cloudy","cloud","rain","drizzle","snow","storm","fog","wind","moon-clear","check","clock","moon-cloud"];function Re(e,n){if(n===""||n==="$")return e;let s=e;for(const r of n.split(".")){const a=/^([^[\]]*)((?:\[\d+\])*)$/.exec(r);if(!a)return;const[,i="",l=""]=a;if(i!==""){if(s===null||typeof s!="object")return;s=s[i]}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 Ke(e,n){if(n)return"const"in n?n.const:Re(e,n.path)}function Ns(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const n=Number(e);return Number.isFinite(n)?n:null}return null}function kt(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):null}function Ya(e){return Array.isArray(e)?e:[]}function M6(e,n){const s=Ya(Re(e,n.points)).map(a=>{const i=Ns(Re(a,n.y)),l=kt(Re(a,n.x));return i===null||l===null?null:{x:l,y:i}}).filter(a=>a!==null),r=(n.referenceLines??[]).map(a=>{const i=Ns(Ke(e,a.value));return i===null?null:{value:i,label:a.label,tone:a.tone??"neutral"}}).filter(a=>a!==null);return{points:s,unit:n.unit??"number",currency:kt(Ke(e,n.currency)),label:kt(Ke(e,n.label)),referenceLines:r,mark:n.mark??null,shadeBelow:Ns(Ke(e,n.shadeBelow)),events:O6(e,n)}}function O6(e,n){const s=n.events;if(!s)return[];const r=[],a=(i,l)=>{const o=kt(Re(i,s.label));if(o===null)return;const c=kt(Re(i,s.at))??l;c!==null&&r.push({at:c,label:o,amount:s.amount?Ns(Re(i,s.amount)):null})};if(s.parent){for(const i of Ya(Re(e,n.points))){const l=kt(Re(i,n.x));for(const o of Ya(Re(i,s.parent)))a(o,l)}return r}for(const i of Ya(Re(e,s.path??n.points)))a(i,null);return r}function D6(e,n){const s=(n.columns??[]).map(o=>({key:o.key,label:o.label,type:o.type??"text"})),r=o=>(n.columns??[]).map(c=>{const u=Re(o,c.key);let h=null;if(c.bar){const f=Ns(Ke(o,c.bar.max))??Ns(Ke(e,c.bar.max)),m=Ns(u);if(f!==null&&f>0&&m!==null){const p=Math.max(0,Math.min(1,m/f));h={fraction:p,tone:F6(p*100,c.bar.thresholds)}}}return{value:u,type:c.type??"text",currency:kt(Ke(o,c.currency))??kt(Ke(e,c.currency)),bar:h}}),a=Ya(Re(e,n.rows)),i=n.groupBy?L6(a,n.groupBy,r):[{label:null,rows:a.map(r)}],l=(n.summary??[]).map(o=>({label:o.label,value:Ke(e,o.value),unit:o.unit??"text",currency:kt(Ke(e,o.currency)),tone:o.tone??"neutral"}));return{columns:s,groups:i,summary:l,empty:n.empty??"Nothing to show."}}function L6(e,n,s){const r=new Map;for(const a of e){const i=String(Re(a,n.key)??""),l=r.get(i);l?l.push(a):r.set(i,[a])}return[...r.entries()].map(([a,i])=>{var l;return{label:((l=n.labels)==null?void 0:l[a])??a,rows:i.map(s)}})}function F6(e,n){var r;return!n||n.length===0?"neutral":((r=[...n].sort((a,i)=>i.atLeast-a.atLeast).find(a=>e>=a.atLeast))==null?void 0:r.tone)??"neutral"}function _6(e,n){return{bars:Ya(Re(e,n.bars)).map(r=>{const a=Ns(Re(r,n.value)),i=kt(Re(r,n.category));return a===null||i===null?null:{category:i,value:a}}).filter(r=>r!==null),unit:n.unit??"number",currency:kt(Ke(e,n.currency))}}function z6(e,n){if(n.pairs)return{pairs:n.pairs.map(r=>({label:r.label,value:Ke(e,r.value),unit:r.unit??"text",currency:kt(Ke(e,r.currency)),tone:r.tone??"neutral"}))};const s=Re(e,n.from??"$");return s===null||typeof s!="object"||Array.isArray(s)?{pairs:[]}:{pairs:Object.entries(s).map(([r,a])=>({label:Bn(r),value:a,unit:"text",currency:null,tone:"neutral"}))}}const U6=new Set(["good","warning","critical","neutral","accent"]),B6=new Set(P6);function Qx(e){return typeof e=="string"&&B6.has(e)?e:null}function Ww(e,n,s=""){const r=n.empty??"Nothing to show.",a=s.split(".")[0]??"";if(n.notice){const l=kt(Re(e,n.notice.text));if(l!==null&&l.trim()!==""){const o=n.notice.link&&a!==""?{plugin:a,page:n.notice.link.page}:null;return{tiles:[{icon:Qx(n.notice.icon??"bell"),value:"",label:l.trim(),lines:[],tone:"neutral",link:o}],notice:!0,empty:r}}}return{tiles:Ya(Re(e,n.items)).map(l=>{const o=kt(Re(l,n.value))??"",c=kt(Re(l,n.label))??"";if(o===""&&c==="")return null;const u=n.tone?kt(Re(l,n.tone)):null;return{icon:Qx(Ke(l,n.icon)),value:o,label:c,lines:(n.lines??[]).slice(0,2).map(h=>kt(Re(l,h))).filter(h=>h!==null&&h.trim()!==""),tone:u!==null&&U6.has(u)?u:"neutral",link:null}}).filter(l=>l!==null),notice:!1,empty:r}}function W6(e,n){const s=kt(Ke(e,n.kind)),r=s==="image"||s==="pdf"?s:"text",a=n.src?kt(Re(e,n.src)):null;return{kind:r,text:n.text?kt(Re(e,n.text)):null,src:a&&rT(a)?a:null,title:kt(Ke(e,n.title)),metadata:(n.metadata??[]).map(i=>({label:i.label,value:Ke(e,i.value),unit:i.unit??"text"}))}}function H6(e,n){const s=n.diff?Re(e,n.diff):void 0;return{diff:typeof s=="string"&&s.trim()!==""?s:null,title:kt(Ke(e,n.title)),metadata:(n.metadata??[]).map(r=>({label:r.label,value:Ke(e,r.value),unit:r.unit??"text"}))}}function K6(e,n){const s=n.output?Re(e,n.output):void 0,r=l=>{const o=l?Re(e,l):void 0;return typeof o=="number"&&Number.isInteger(o)?o:null},a=r(n.omittedBytes),i=n.elapsedMs?Re(e,n.elapsedMs):void 0;return{command:kt(Ke(e,n.command)),output:typeof s=="string"?s:null,exitCode:r(n.exitCode),elapsedMs:typeof i=="number"&&Number.isFinite(i)&&i>=0?i:null,omittedBytes:a!==null&&a>0?a:null,metadata:(n.metadata??[]).map(l=>({label:l.label,value:Ke(e,l.value),unit:l.unit??"text"}))}}const V6=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function sT(e){const n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e.artifactId??e.id:e;return typeof n=="string"&&V6.test(n)?n.toLowerCase():null}function G6(e,n){return{artifactId:n.src?sT(Re(e,n.src)):null,title:kt(Ke(e,n.title)),caption:kt(Ke(e,n.caption)),...n.captionLabel?{captionLabel:kt(Ke(e,n.captionLabel))}:{}}}function J0(e){if(!rT(e))return null;let n;try{n=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(n);return s?{plugin:s[1],name:s[2]}:null}function Y6(e,n){const s=n.src?kt(Re(e,n.src)):null,r=n.port?Re(e,n.port):null,a=n.awaiting?kt(Re(e,n.awaiting)):null;return{target:s?J0(s):null,title:kt(Ke(e,n.title)),output:n.output?kt(Re(e,n.output)):null,port:typeof r=="number"&&Number.isInteger(r)&&r>0&&r<=65535?r:null,awaiting:a?J0(a):null,reloadsItself:n.reloadsItself?Re(e,n.reloadsItself)===!0:!1,ports:n.ports?q6(Re(e,n.ports)):[]}}function q6(e){const n=Ya(e).filter(s=>typeof s=="number"&&Number.isInteger(s)&&s>0&&s<=65535);return[...new Set(n)].sort((s,r)=>s-r)}function rT(e){return e.startsWith("/")&&!e.startsWith("//")}function Bn(e){const n=e.replace(/[_-]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return n.charAt(0).toUpperCase()+n.slice(1)}function aT(e,n){const s=e.map??{};switch(e.renderer){case"timeseries":return{renderer:"timeseries",props:M6(n,s)};case"table":return{renderer:"table",props:D6(n,s)};case"bars":return{renderer:"bars",props:_6(n,s)};case"keyvalue":return{renderer:"keyvalue",props:z6(n,s)};case"tiles":return{renderer:"tiles",props:Ww(n,s,e.tool)};case"document":return{renderer:"document",props:W6(n,s)};case"diff":return{renderer:"diff",props:H6(n,s)};case"terminal":return{renderer:"terminal",props:K6(n,s)};case"image":return{renderer:"image",props:G6(n,s)};case"preview":return{renderer:"preview",props:Y6(n,s)};default:return{renderer:"structured",props:{value:n}}}}var Q6=Object.defineProperty,Qs=(e,n)=>Q6(e,"name",{value:n,configurable:!0}),Hw="Dialog",[iT,Wse]=vr(Hw),[J6,Vr]=iT(Hw),im=Qs(e=>{const{__scopeDialog:n,children:s,open:r,defaultOpen:a,onOpenChange:i,modal:l=!0}=e,o=d.useRef(null),c=d.useRef(null),[u,h]=ci({prop:r,defaultProp:a??!1,onChange:i,caller:Hw}),[f,m]=d.useState(0),[p,g]=d.useState(0);return t.jsx(J6,{scope:n,triggerRef:o,contentRef:c,contentId:ur(),titleId:ur(),descriptionId:ur(),titlePresent:f>0,descriptionPresent:p>0,setTitleCount:m,setDescriptionCount:g,open:u,onOpenChange:h,onOpenToggle:d.useCallback(()=>h(x=>!x),[h]),modal:l,children:s})},"Dialog"),X6="DialogTrigger",Z6=d.forwardRef(Qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Vr(X6,r),l=Rt(s,i.triggerRef);return t.jsx(St.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":um(i.open),...a,ref:l,onClick:Be(n.onClick,i.onOpenToggle)})},"DialogTrigger")),lT="DialogPortal",[eB,oT]=iT(lT,{forceMount:void 0}),lm=Qs(e=>{const{__scopeDialog:n,forceMount:s,children:r,container:a}=e,i=Vr(lT,n);return t.jsx(eB,{scope:n,forceMount:s,children:d.Children.map(r,l=>t.jsx(Kr,{present:s||i.open,children:t.jsx(Df,{asChild:!0,container:a,children:l})}))})},"DialogPortal"),Jx="DialogOverlay",Kw=d.forwardRef(Qs(function(n,s){const r=oT(Jx,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=Vr(Jx,n.__scopeDialog);return l.modal?t.jsx(Kr,{present:a||l.open,children:t.jsx(nB,{...i,ref:s})}):null},"DialogOverlay")),tB=Xa("DialogOverlay.RemoveScroll"),nB=d.forwardRef(Qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Vr(Jx,r),l=WE(),o=Rt(s,l);return t.jsx(Sw,{as:tB,allowPinchZoom:!0,shards:[i.contentRef],children:t.jsx(St.div,{"data-state":um(i.open),...a,ref:o,style:{pointerEvents:"auto",...a.style}})})},"DialogOverlayImpl")),nu="DialogContent",om=d.forwardRef(Qs(function(n,s){const r=oT(nu,n.__scopeDialog),{forceMount:a=r.forceMount,...i}=n,l=Vr(nu,n.__scopeDialog);return t.jsx(Kr,{present:a||l.open,children:l.modal?t.jsx(sB,{...i,ref:s}):t.jsx(rB,{...i,ref:s})})},"DialogContent")),sB=d.forwardRef(Qs(function(n,s){const r=Vr(nu,n.__scopeDialog),a=d.useRef(null),i=Rt(s,r.contentRef,a);return d.useEffect(()=>{const l=a.current;if(l)return rA(l)},[]),t.jsx(cT,{...n,ref:i,trapFocus:r.open,disableOutsidePointerEvents:r.open,onCloseAutoFocus:Be(n.onCloseAutoFocus,l=>{var o;l.preventDefault(),(o=r.triggerRef.current)==null||o.focus()}),onPointerDownOutside:Be(n.onPointerDownOutside,l=>{const o=l.detail.originalEvent,c=o.button===0&&o.ctrlKey===!0;(o.button===2||c)&&l.preventDefault()}),onFocusOutside:Be(n.onFocusOutside,l=>l.preventDefault())})},"DialogContentModal")),rB=d.forwardRef(Qs(function(n,s){const r=Vr(nu,n.__scopeDialog),a=d.useRef(!1),i=d.useRef(!1);return t.jsx(cT,{...n,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{var o,c;(o=n.onCloseAutoFocus)==null||o.call(n,l),l.defaultPrevented||(a.current||(c=r.triggerRef.current)==null||c.focus(),l.preventDefault()),a.current=!1,i.current=!1},onInteractOutside:l=>{var u,h;(u=n.onInteractOutside)==null||u.call(n,l),l.defaultPrevented||(a.current=!0,l.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const o=l.target;((h=r.triggerRef.current)==null?void 0:h.contains(o))&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&i.current&&l.preventDefault()}})},"DialogContentNonModal")),cT=d.forwardRef(Qs(function(n,s){const{__scopeDialog:r,trapFocus:a,onOpenAutoFocus:i,onCloseAutoFocus:l,...o}=n,c=Vr(nu,r);return qf(),t.jsx(t.Fragment,{children:t.jsx(z$,{asChild:!0,loop:!0,trapped:a,onMountAutoFocus:i,onUnmountAutoFocus:l,children:t.jsx(Of,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionPresent?c.descriptionId:void 0,"aria-labelledby":c.titlePresent?c.titleId:void 0,"data-state":um(c.open),...o,ref:s,deferPointerDownOutside:!0,onDismiss:()=>c.onOpenChange(!1)})})})},"DialogContentImpl")),aB="DialogTitle",cm=d.forwardRef(Qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Vr(aB,r),{setTitleCount:l}=i;return ds(()=>(l(o=>o+1),()=>l(o=>o-1)),[l]),t.jsx(St.h2,{id:i.titleId,...a,ref:s})},"DialogTitle")),iB="DialogClose",Vw=d.forwardRef(Qs(function(n,s){const{__scopeDialog:r,...a}=n,i=Vr(iB,r);return t.jsx(St.button,{type:"button",...a,ref:s,onClick:Be(n.onClick,()=>i.onOpenChange(!1))})},"DialogClose"));function um(e){return e?"open":"closed"}Qs(um,"getState");const lB=5;function ge(e,n,s){const[r,a]=d.useState(void 0),[i,l]=d.useState(null),[o,c]=d.useState(!0),[u,h]=d.useState(0),[f,m]=d.useState(0),p=d.useRef(e);return p.current=e,d.useEffect(()=>{let g=!1;return c(!0),p.current().then(x=>{g||(a(x),l(null),m(0))}).catch(x=>{g||(l(x instanceof he?x.message:String(x)),m(k=>k+1))}).finally(()=>{g||c(!1)}),()=>{g=!0}},[...n,u]),d.useEffect(()=>{if(!s||f>=lB)return;const g=window.setTimeout(()=>h(x=>x+1),s*2**f);return()=>window.clearTimeout(g)},[s,f,u]),{data:r,error:i,loading:o,reload:()=>{m(0),h(g=>g+1)}}}const uT={width:480,height:160,top:10,right:10,bottom:22,left:40},dT={width:1200,height:180,top:10,right:40,bottom:22,left:40};function oB({xs:e,series:n}){const s=dT,r=s.width-s.left-s.right,a=s.height-s.top-s.bottom,i=O=>O.filter(I=>I!==null&&Number.isFinite(I)),l=n.filter(O=>O.type!=="bar"),o=n.filter(O=>O.type==="bar"),c=l.flatMap(O=>i(O.values)),u=c.length>0?Math.min(...c):0,h=c.length>0?Math.max(...c):1;let f=u,m=h;if(f===m)f-=1,m+=1;else{const O=(m-f)*.08;f-=O,m+=O}const p=O=>Ws(s.top+a-(O-f)/(m-f)*a),g=o.length>0&&o.every(O=>O.unit==="percent"),x=g?100:Math.max(1,...o.flatMap(O=>i(O.values))),k=O=>Ws(s.top+a-Math.max(0,O)/x*a),j=e.length,v=j>0?r/j:r,w=O=>Ws(s.left+v*(O+.5)),y=n.map(O=>{if(O.type==="bar")return"";let I="M";const z=[];return O.values.forEach((U,D)=>{if(U===null||!Number.isFinite(U)){I="M";return}z.push(`${I}${w(D)},${p(U)}`),I="L"}),z.join(" ")}),N=[],b=v*.6/Math.max(1,o.length),S=s.height-s.bottom;let C=0;n.forEach((O,I)=>{if(O.type!=="bar")return;const z=C++;O.values.forEach((U,D)=>{if(U===null||!Number.isFinite(U)||U<=0)return;const P=k(U);N.push({series:I,index:D,x:Ws(w(D)-v*.3+b*z),y:P,width:Ws(b),height:Ws(S-P)})})});const T=c.length>0?Dh(u,h,2).map(O=>({value:O,y:p(O)})):[],E=o.length===0?[]:(g?[0,50,100]:Dh(0,x,2)).map(O=>({value:O,y:k(O),percent:g})),R=Math.max(1,Math.ceil(j/8)),M=e.flatMap((O,I)=>I%R===0?[{index:I,x:w(I)}]:[]);return{lines:y,bars:N,targetY:null,ticks:T,xLabels:M,rightTicks:E}}function cB({xs:e,series:n,type:s="line",target:r=null}){const a=uT,i=a.width-a.left-a.right,l=a.height-a.top-a.bottom,o=n.flatMap(w=>w.values.filter(y=>y!==null&&Number.isFinite(y)));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 w=(u-c)*.08;c-=w,u+=w}const h=w=>Ws(a.top+l-(w-c)/(u-c)*l),f=e.length,m=f>0?i/f:i,p=w=>Ws(s==="bar"?a.left+m*(w+.5):a.left+(f<=1?i/2:w/(f-1)*i)),g=s==="line"?n.map(w=>{let y="M";const N=[];return w.values.forEach((b,S)=>{if(b===null||!Number.isFinite(b)){y="M";return}N.push(`${y}${p(S)},${h(b)}`),y="L"}),N.join(" ")}):[],x=[];if(s==="bar"&&f>0){const w=m*.7,y=w/Math.max(1,n.length),N=h(0);n.forEach((b,S)=>{b.values.forEach((C,T)=>{if(C===null||!Number.isFinite(C))return;const E=h(C);x.push({series:S,index:T,x:Ws(a.left+m*T+(m-w)/2+y*S),y:Math.min(E,N),width:Ws(y),height:Ws(Math.abs(N-E))})})})}const j=(o.length>0?Dh(Math.min(...o),Math.max(...o),2):[]).map(w=>({value:w,y:h(w)})),v=f===0?[]:f===1?[0]:f<5?[0,f-1]:[0,Math.floor((f-1)/2),f-1];return{lines:g,bars:x,targetY:r!==null&&Number.isFinite(r)?h(r):null,ticks:j,xLabels:v.map(w=>({index:w,x:p(w)}))}}function uB(e){const n=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 a=r===1?`on ${n(e.xs[0])}`:`from ${n(e.xs[0])} to ${n(e.xs[r-1])}`,i=e.series.map(o=>{const c=o.values.filter(h=>h!==null&&Number.isFinite(h));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"} ${a}. ${i.join("; ")}.${l}`}function dB({xs:e,series:n,type:s="line",target:r=null,label:a,formatX:i=o=>o,formatY:l=o=>String(o)}){const o=s==="mixed",c=o?dT:uT,u=o?oB({xs:e,series:n}):cB({xs:e,series:n,type:s,target:r}),h=uB({xs:e,series:n,target:r,...a?{label:a}:{},formatX:i,formatY:l});return t.jsxs("figure",{className:"ui-chart","data-type":s,children:[t.jsxs("svg",{viewBox:`0 0 ${c.width} ${c.height}`,"aria-hidden":"true",focusable:"false","data-testid":"chart-svg",children:[u.ticks.map(f=>t.jsxs("g",{children:[t.jsx("line",{className:"ui-chart-grid",x1:c.left,x2:c.width-c.right,y1:f.y,y2:f.y}),t.jsx("text",{x:c.left-6,y:f.y,textAnchor:"end",dominantBaseline:"middle",children:l(f.value)})]},f.value)),(u.rightTicks??[]).map(f=>t.jsx("text",{x:c.width-c.right+6,y:f.y,textAnchor:"start",dominantBaseline:"middle",children:f.percent?`${f.value}%`:l(f.value)},`r-${f.value}`)),t.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(f=>t.jsx("rect",{className:"ui-chart-bar","data-series":f.series,x:f.x,y:f.y,width:f.width,height:f.height},`${f.series}-${f.index}`)),u.lines.map((f,m)=>f?t.jsx("path",{className:"ui-chart-line","data-series":m,d:f},m):null),u.targetY!==null?t.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(f=>t.jsx("text",{x:f.x,y:c.height-6,textAnchor:o?"middle":u.xLabels.length>1&&f.index===0?"start":f.index===e.length-1&&e.length>1?"end":"middle",children:i(e[f.index])},f.index))]}),t.jsx("figcaption",{className:"sr-only",children:h}),n.length>1?t.jsx("ul",{className:"ui-chart-legend","aria-hidden":"true",children:n.map((f,m)=>t.jsx("li",{"data-series":m,"data-type":o?f.type??"line":void 0,children:f.label},f.label))}):null]})}function Ws(e){return Math.round(e*10)/10}const Gw="(max-width: 900px)";function fs(e){const[n,s]=d.useState(()=>{try{return window.matchMedia(e).matches}catch{return!1}});return d.useEffect(()=>{var i;let r;try{r=window.matchMedia(e)}catch{return}const a=l=>s(l.matches);return(i=r.addEventListener)==null||i.call(r,"change",a),()=>{var l;return(l=r.removeEventListener)==null?void 0:l.call(r,"change",a)}},[e]),n}function hi(...e){return e.filter(Boolean).join(" ")}function $({variant:e,size:n,className:s,type:r="button",...a}){return t.jsx("button",{type:r,className:hi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...a})}function lt({variant:e,size:n,className:s,...r}){return t.jsx("a",{className:hi("ui-btn",s),"data-variant":e&&e!=="default"?e:void 0,"data-size":n,...r})}function Tu({checked:e,onChange:n,label:s,disabled:r}){return t.jsxs("label",{className:"ui-switch","data-disabled":r?"true":void 0,children:[t.jsx("input",{type:"checkbox",role:"switch",checked:e,disabled:r,"aria-label":s,onChange:a=>n(a.target.checked)}),t.jsx("i",{"aria-hidden":"true"})]})}function ne({children:e,align:n,valign:s,className:r}){return t.jsx("div",{className:hi("ui-toolbar",r),"data-align":n,"data-valign":s,children:e})}function ot(){return t.jsx("span",{className:"ui-toolbar-spacer"})}function ie({label:e,hint:n,inline:s,grow:r,wide:a,group:i,action:l,after:o,children:c}){const u=d.useId();return t.jsxs("div",{className:"ui-field","data-inline":s?"true":void 0,"data-grow":r?"true":void 0,"data-wide":a?"true":void 0,children:[l?t.jsxs("div",{className:"ui-field-row",children:[t.jsxs("label",{className:"ui-field-control",children:[t.jsx("span",{className:"ui-field-label",children:e}),c]}),l]}):i?t.jsxs("div",{className:"ui-field-control",role:"group","aria-labelledby":u,children:[t.jsx("span",{className:"ui-field-label",id:u,children:e}),c]}):t.jsxs("label",{className:"ui-field-control",children:[t.jsx("span",{className:"ui-field-label",children:e}),c]}),n?t.jsx("span",{className:"ui-field-hint",children:n}):null,o]})}function Es({children:e,dense:n,columns:s}){return t.jsx("div",{className:"ui-formgrid","data-dense":n?"true":void 0,"data-columns":s===3?"3":void 0,children:e})}function Ae({tone:e,mono:n,dot:s,children:r,className:a,title:i}){return t.jsxs("span",{className:hi("ui-pill",n&&"mono",a),"data-tone":e,title:i,children:[s?t.jsx("span",{className:"ui-pill-dot","aria-hidden":"true"}):null,r]})}function so({children:e}){return t.jsx("span",{className:"ui-tag",children:e})}function Ru({state:e}){const n=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 t.jsx(Ae,{tone:n,children:e})}function G({tone:e,title:n,children:s,role:r,action:a}){return a?t.jsx("div",{className:"ui-notice","data-tone":e,role:r,children:t.jsxs("div",{className:"ui-notice-row",children:[t.jsxs("div",{className:"ui-notice-body",children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]}),a]})}):t.jsxs("div",{className:"ui-notice","data-tone":e,role:r,children:[n?t.jsx("div",{className:"ui-notice-title",children:n}):null,s]})}function ae({message:e}){return e?t.jsx(G,{tone:"critical",role:"alert",children:e}):null}function Ne({mascot:e,warm:n,title:s,action:r,children:a}){return n||s?t.jsxs("div",{className:"ui-empty","data-warm":n?"true":void 0,children:[s?t.jsx("div",{className:"ui-empty-title",children:s}):null,t.jsx("div",{children:a}),r]}):e?t.jsxs("div",{className:"ui-empty","data-mascot":"true",children:[t.jsx(tT,{size:"sm"}),t.jsx("p",{children:a})]}):t.jsx("p",{className:"ui-empty",children:a})}function es({icon:e,title:n,action:s,children:r}){return t.jsxs("div",{className:"ui-empty-state",children:[e?t.jsx("span",{className:"ui-empty-state-icon",children:typeof e=="string"?t.jsx(oe,{name:e}):e}):null,t.jsx("div",{className:"ui-empty-state-title",children:n}),r?t.jsx("p",{className:"ui-empty-state-line",children:r}):null,s?t.jsx("div",{className:"ui-empty-state-action",children:s}):null]})}function Yw({children:e}){return t.jsx("div",{className:"ui-page",children:e})}function Pi({title:e,lede:n,actions:s,before:r}){return t.jsxs("header",{className:"ui-page-head",children:[t.jsxs("div",{className:"ui-page-head-row",children:[t.jsxs("h2",{className:"ui-page-title",children:[r,t.jsx("span",{children:e})]}),s?t.jsx("div",{className:"ui-page-actions",children:s}):null]}),n?t.jsx("p",{className:"ui-page-lede",children:n}):null]})}function gs({embedded:e,title:n,lede:s,actions:r,children:a}){return e?t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[r?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:r}):null,a]}):t.jsxs(Yw,{children:[t.jsx(Pi,{title:n,lede:s,actions:r}),a]})}function pe({title:e,aside:n,actions:s,panel:r,flush:a,foot:i,children:l}){const o=e||n||s?t.jsxs("div",{className:"ui-section-head",children:[e?t.jsx("h3",{className:"ui-section-title",children:e}):t.jsx("span",{}),n||s?t.jsxs("div",{className:"ui-section-side",children:[n?t.jsx("span",{className:"ui-section-aside",children:n}):null,s?t.jsx("div",{className:"ui-section-actions",children:s}):null]}):null]}):null;return t.jsxs("section",{className:"ui-section","data-panel":r?"true":void 0,children:[o,r?t.jsxs("div",{className:"ui-panel","data-flush":a?"true":void 0,children:[l,i?t.jsx("div",{className:"ui-panel-foot",children:i}):null]}):t.jsxs(t.Fragment,{children:[l,i?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:i}):null]})]})}function Xe({title:e,tool:n,actions:s,flush:r,children:a}){return t.jsxs("section",{className:"ui-panel","data-flush":r?"true":void 0,children:[e||n||s?t.jsxs("header",{className:"ui-panel-head",children:[e?t.jsx("h3",{className:"ui-panel-title",children:e}):t.jsx("span",{}),n?t.jsx("span",{className:"ui-panel-tool",children:n}):null,s?t.jsx("div",{className:"ui-panel-actions",children:s}):null]}):null,a]})}function Ps({tone:e,title:n,meta:s,actions:r,children:a,foot:i,onClick:l,label:o,as:c="div"}){const u=l?{"data-interactive":"true",tabIndex:0,"aria-label":o,onClick:l,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),l())}}:{};return t.jsxs(c,{className:"ui-card","data-tone":e,...u,children:[n||s||r?t.jsxs("div",{className:"ui-card-head",children:[n?t.jsx("h3",{className:"ui-card-title",children:n}):null,s,r?t.jsx("div",{className:"ui-card-actions",children:r}):null]}):null,a,i?t.jsx("div",{className:"ui-card-foot",children:i}):null]})}function ue({gap:e,divided:n,children:s}){return t.jsx("div",{className:"ui-stack","data-gap":e,"data-divided":n?"true":void 0,children:s})}function hB({children:e}){return t.jsx("div",{className:"ui-row",children:e})}function dm({inline:e,children:n}){return t.jsx("div",{className:"ui-stats","data-inline":e?"true":void 0,children:n})}function Tr({label:e,value:n,note:s,tone:r,size:a}){return t.jsxs("div",{className:"ui-stat",children:[t.jsx("div",{className:"ui-stat-k",children:e}),t.jsx("div",{className:"ui-stat-v","data-tone":r,"data-size":a,children:n}),s?t.jsx("div",{className:"ui-stat-n",children:s}):null]})}function Xt({items:e}){return t.jsx("dl",{className:"ui-kv",children:e.map((n,s)=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{children:n.value})]},n.key??s))})}function Gr({children:e}){return t.jsx("div",{className:"ui-table-wrap",children:t.jsx("table",{className:"ui-table",children:e})})}function qw({value:e,label:n}){const s=Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));return t.jsx("div",{className:"ui-progress",role:"progressbar","aria-label":n,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-valuetext":`${s}%`,children:t.jsx("div",{className:"ui-progress-fill",style:{inlineSize:`${s}%`}})})}function zt({children:e,label:n}){return t.jsx("pre",{className:"ui-code","aria-label":n,children:e})}function Zt({summary:e,boxed:n,open:s,className:r,onToggle:a,children:i}){return t.jsxs("details",{className:hi("ui-details",r),"data-boxed":n?"true":void 0,open:s,onToggle:a?l=>a(l.currentTarget.open):void 0,children:[t.jsx("summary",{children:e}),i]})}function Ye({title:e,onClose:n,size:s,foot:r,children:a}){return t.jsx(im,{open:!0,onOpenChange:i=>{i||n()},children:t.jsxs(lm,{children:[t.jsx(Kw,{className:"ui-sheet-overlay"}),t.jsxs(om,{className:"ui-sheet","data-size":s,"aria-describedby":void 0,children:[t.jsxs("div",{className:"ui-sheet-head",children:[t.jsx(cm,{className:"ui-sheet-title",children:e}),t.jsx(Vw,{asChild:!0,children:t.jsx($,{size:"sm",children:"Close"})})]}),a,r?t.jsx("div",{className:"ui-sheet-foot",children:r}):null]})]})})}function Ut({title:e,onClose:n,foot:s,children:r}){return t.jsx(im,{open:!0,onOpenChange:a=>{a||n()},children:t.jsxs(lm,{children:[t.jsx(Kw,{className:"ui-sheet-overlay","data-layer":"modal"}),t.jsxs(om,{className:"ui-modal",role:"alertdialog","aria-describedby":void 0,children:[t.jsx(cm,{className:"ui-modal-title",children:e}),r,s?t.jsx("div",{className:"ui-modal-foot",children:s}):null]})]})})}function ss({label:e,items:n,note:s,trigger:r,sheet:a,stacked:i}){const l=fs(fB);return a&&l&&!r?t.jsx(mB,{label:e,items:n,title:a.title,sub:a.sub}):t.jsx(pB,{label:e,items:n,note:s,trigger:r,stacked:i})}const fB="(max-width: 720px)";function mB({label:e,items:n,title:s,sub:r}){const[a,i]=d.useState(!1);return t.jsxs(im,{open:a,onOpenChange:i,children:[t.jsx(Z6,{asChild:!0,children:t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:l=>l.stopPropagation(),children:t.jsx(oe,{name:"more"})})}),t.jsxs(lm,{children:[t.jsx(Kw,{className:"ui-sheet-overlay",onClick:l=>l.stopPropagation()}),t.jsxs(om,{className:"ui-action-sheet","aria-describedby":void 0,onClick:l=>l.stopPropagation(),children:[t.jsxs("div",{className:"ui-action-sheet-head",children:[t.jsx(cm,{className:"ui-action-sheet-title",children:s}),r?t.jsx("span",{className:"ui-action-sheet-sub",children:r}):null]}),t.jsx("div",{className:"ui-menu ui-action-sheet-list",role:"menu",children:n.map((l,o)=>l?l==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${o}`):"heading"in l?t.jsx("div",{className:"ui-menu-label",children:l.heading},`head-${o}`):t.jsxs("button",{type:"button",role:"menuitem",className:"ui-menu-item","data-tone":l.tone,onClick:()=>{i(!1),l.onSelect()},children:[t.jsx("span",{children:l.label}),l.hint?t.jsx("span",{className:"ui-menu-item-hint",children:l.hint}):null]},o):null)}),t.jsx(Vw,{asChild:!0,children:t.jsx($,{className:"ui-action-sheet-cancel",children:"Cancel"})})]})]})]})}function pB({label:e,items:n,note:s,trigger:r,stacked:a}){const i=o=>o.stopPropagation(),l=d.useRef(!1);return t.jsxs(Su,{modal:!1,onOpenChange:o=>{o&&(l.current=!1)},children:[t.jsx(Cu,{asChild:!0,children:r??t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:i,children:t.jsx(oe,{name:"more"})})}),t.jsx(ko,{children:t.jsxs(Eu,{className:"ui-menu","data-stacked":a?"true":void 0,align:"end",sideOffset:4,onClick:i,onKeyDown:i,onCloseAutoFocus:o=>{l.current&&o.preventDefault()},children:[s?t.jsx(Wi,{className:"ui-menu-label",children:s}):null,n.map((o,c)=>o?o==="separator"?t.jsx(la,{className:"ui-menu-sep"},`sep-${c}`):"heading"in o?t.jsx(Wi,{className:"ui-menu-label",children:o.heading},`head-${c}`):t.jsxs(Bs,{className:"ui-menu-item","data-tone":o.tone,onSelect:()=>{l.current=!0,o.onSelect()},children:[t.jsx("span",{children:o.label}),o.hint?t.jsx("span",{className:"ui-menu-item-hint",children:o.hint}):null]},c):null)]})})]})}function gB({title:e,actions:n,onClose:s,onCloseAutoFocus:r,onOpenAutoFocus:a,label:i,children:l}){return t.jsx(im,{open:!0,modal:!1,onOpenChange:o=>{o||s()},children:t.jsx(lm,{children:t.jsxs(om,{className:"ui-dock","aria-describedby":void 0,...i?{"aria-label":i}:{},onInteractOutside:o=>o.preventDefault(),...r?{onCloseAutoFocus:r}:{},...a?{onOpenAutoFocus:a}:{},children:[t.jsxs("div",{className:"ui-dock-head",children:[t.jsx(cm,{className:"ui-dock-title",children:e}),t.jsxs("div",{className:"ui-dock-actions",children:[n,t.jsx(Vw,{asChild:!0,children:t.jsx($,{size:"sm",variant:"ghost",children:"Close"})})]})]}),t.jsx("div",{className:"ui-dock-body",children:l})]})})})}function Co({level:e,label:n,children:s}){return t.jsx("nav",{className:"ui-tabs","data-level":e,"aria-label":n,children:s})}function Ki({href:e,active:n,count:s,onClick:r,children:a}){return t.jsxs("a",{className:"ui-tab",href:e,"aria-current":n?"page":void 0,onClick:r,children:[a,s?t.jsx("span",{className:"ui-count",children:s}):null]})}function Gt({label:e,options:n,value:s,onChange:r}){return t.jsx("div",{className:"ui-segment",role:"radiogroup","aria-label":e,children:n.map(a=>t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":a.value===s,onClick:()=>r(a.value),children:a.label},a.value))})}function ct({children:e}){return t.jsx("div",{className:"ui-list",children:e})}function rt({href:e,onClick:n,lead:s,title:r,sub:a,side:i,dimmed:l,label:o}){const c=t.jsxs(t.Fragment,{children:[s,t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:r}),a?t.jsx("span",{className:"ui-list-sub",children:a}):null]}),i?t.jsx("span",{className:"ui-list-side",children:i}):null]}),u=l?"true":void 0;return e?t.jsx("a",{className:"ui-list-row","data-dimmed":u,href:e,onClick:n?h=>{h.preventDefault(),n()}:void 0,children:c}):n?t.jsx("div",{className:"ui-list-row","data-interactive":"true","data-dimmed":u,tabIndex:0,"aria-label":o,onClick:n,onKeyDown:h=>{h.target!==h.currentTarget||h.key!=="Enter"&&h.key!==" "||(h.preventDefault(),n())},children:c}):t.jsx("div",{className:"ui-list-row","data-dimmed":u,children:c})}function hT({href:e,onClick:n,current:s,lead:r,title:a,meta:i,sub:l,snippet:o,side:c}){return t.jsxs("a",{className:"ui-pick",href:e,"aria-current":s?"true":void 0,onClick:n?u=>{u.preventDefault(),n()}:void 0,children:[r?t.jsx("span",{className:"ui-pick-lead",children:r}):null,t.jsxs("span",{className:"ui-pick-main",children:[t.jsxs("span",{className:"ui-pick-top",children:[t.jsx("span",{className:"ui-pick-title",children:a}),i?t.jsx("span",{className:"ui-pick-meta",children:i}):null]}),l||c?t.jsxs("span",{className:"ui-pick-line",children:[l?t.jsx("span",{className:"ui-pick-sub",children:l}):null,c?t.jsx("span",{className:"ui-pick-side",children:c}):null]}):null,o?t.jsx("span",{className:"ui-pick-snippet",children:o}):null]})]})}function fT({list:e,detail:n,empty:s,label:r,className:a}){return t.jsxs("div",{className:hi("ui-split",a),"data-open":n?"true":void 0,children:[t.jsx("section",{className:"ui-split-list","aria-label":r,children:e}),t.jsx("section",{className:"ui-split-detail","data-empty":n?void 0:"true",children:n??t.jsx("p",{className:"ui-empty ui-split-empty",children:s})})]})}function zh({children:e,onRemove:n,label:s,disabled:r}){return t.jsxs("span",{className:"ui-chip",children:[e,t.jsx("button",{type:"button",className:"ui-chip-x","aria-label":`Remove ${s}`,onClick:n,disabled:r,children:"×"})]})}const xB=8;function vB({label:e,options:n,value:s,onChange:r,max:a,disabled:i,id:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(0),p=d.useRef(null),g=d.useRef(null),x=d.useRef(null),k=d.useRef(null),j=d.useId(),v=I=>{var z;return((z=n.find(U=>U.value===I))==null?void 0:z.label)??I},w=a!==void 0&&s.length>=a,y=n.filter(I=>!s.includes(I.value)),N=n.length>xB,b=u.trim().toLowerCase(),S=b===""?y:y.filter(I=>I.label.toLowerCase().includes(b)),C=Math.min(f,Math.max(0,S.length-1)),T=I=>{var z;c(!1),h(""),m(0),I&&((z=g.current)==null||z.focus())};d.useEffect(()=>{var z;if(!o)return;(z=N?x.current:k.current)==null||z.focus();const I=U=>{p.current&&!p.current.contains(U.target)&&T(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[o,N]);const E=I=>{const z=[...s,I];r(z),h(""),m(0);const U=a!==void 0&&z.length>=a;(U||z.length>=n.length)&&T(!U)},R=I=>{if(I.key==="Escape")I.preventDefault(),T(!0);else if(I.key==="ArrowDown")I.preventDefault(),m(S.length===0?0:(C+1)%S.length);else if(I.key==="ArrowUp")I.preventDefault(),m(S.length===0?0:(C-1+S.length)%S.length);else if(I.key==="Enter"){I.preventDefault();const z=S[C];z&&E(z.value)}else I.key==="Backspace"&&u===""&&s.length>0&&(I.preventDefault(),r(s.slice(0,-1)))},M=I=>`${j}-${I}`,O=o&&S.length>0?M(C):void 0;return t.jsxs("div",{className:"ui-chippicker",ref:p,id:l,children:[s.map(I=>t.jsx(zh,{label:v(I),disabled:i,onRemove:()=>r(s.filter(z=>z!==I)),children:v(I)},I)),t.jsxs("div",{className:"ui-chippicker-add",children:[t.jsx("button",{ref:g,type:"button",className:"ui-btn","data-size":"sm","data-variant":"ghost","aria-haspopup":"listbox","aria-expanded":o,"aria-controls":o?j:void 0,disabled:i||w||y.length===0,onClick:()=>o?T(!1):c(!0),children:"Add…"}),o?t.jsxs("div",{className:"ui-menu ui-chippicker-menu",onKeyDown:R,children:[N?t.jsx("input",{ref:x,type:"search",className:"ui-chippicker-filter","aria-label":`Filter ${e}`,"aria-controls":j,"aria-activedescendant":O,value:u,onChange:I=>{h(I.target.value),m(0)}}):null,t.jsxs("div",{ref:k,id:j,role:"listbox","aria-multiselectable":"true","aria-label":e,"aria-activedescendant":N?void 0:O,tabIndex:N?-1:0,className:"ui-chippicker-list",children:[S.map((I,z)=>t.jsx("div",{id:M(z),role:"option","aria-selected":"false",className:"ui-menu-item","data-highlighted":z===C?"":void 0,onMouseEnter:()=>m(z),onMouseDown:U=>U.preventDefault(),onClick:()=>E(I.value),children:I.label},I.value)),S.length===0?t.jsx("p",{className:"ui-menu-empty",children:"Nothing matches"}):null]})]}):null]})]})}function mT({label:e,options:n,value:s,onChange:r}){return t.jsx("div",{className:"ui-filter-chips",role:"group","aria-label":e,children:n.map(a=>t.jsx("button",{type:"button",className:"ui-btn ui-filter-chip","data-size":"sm","aria-pressed":a.value===s,onClick:()=>r(a.value),children:a.label},a.value))})}function hm({label:e,value:n,onChange:s,placeholder:r,grow:a}){return t.jsx("span",{className:"ui-search","data-grow":a?"true":void 0,children:t.jsx("input",{type:"search","aria-label":e,value:n,placeholder:r,onChange:i=>s(i.target.value)})})}function Hn({svg:e,icon:n="plug",letter:s,size:r}){return t.jsx("span",{className:"ui-app-icon","data-size":r,"data-tone":e||s?"accent":void 0,"aria-hidden":"true",children:e?t.jsx("span",{className:"ui-app-icon-svg",dangerouslySetInnerHTML:{__html:e}}):s?t.jsx("span",{className:"ui-app-icon-letter",children:s}):t.jsx(oe,{name:n})})}function xc({items:e,label:n="Where this is",inline:s}){const r=e.map((a,i)=>{const l=a.key??String(i);if(a.current)return t.jsx("span",{className:"ui-crumb","aria-current":"page",children:a.label},l);const o=a.href?t.jsx("a",{className:"ui-crumb",href:a.href,onClick:a.onClick?c=>{var u;c.preventDefault(),(u=a.onClick)==null||u.call(a)}:void 0,children:a.label}):t.jsx("button",{type:"button",className:"ui-crumb",onClick:a.onClick,children:a.label});return t.jsxs("span",{className:"ui-crumb-step",children:[o,t.jsx(oe,{name:"chevron-right",size:12})]},l)});return s?t.jsx("span",{className:"ui-crumbs","aria-label":n,children:r}):t.jsx("nav",{className:"ui-crumbs","aria-label":n,children:r})}function pT({main:e,filters:n,filtersOpen:s,onToggleFilters:r,active:a,chips:i,actions:l,onSubmit:o,label:c}){return t.jsxs("form",{className:"ui-panel ui-searchbar",role:"search","aria-label":c,onSubmit:u=>{u.preventDefault(),o()},children:[t.jsxs("div",{className:"ui-searchbar-row",children:[e?t.jsx("div",{className:"ui-searchbar-main",children:e}):null,n&&r?t.jsxs($,{"aria-expanded":s===!0,"aria-pressed":s===!0,onClick:r,children:["Filters",a?t.jsx("span",{className:"ui-count",children:a}):null]}):null,!r&&n?t.jsx("div",{className:"ui-searchbar-inline",children:n}):null,l?t.jsx("div",{className:"ui-searchbar-actions",children:l}):null]}),n&&r&&s?t.jsx("div",{className:"ui-searchbar-filters",children:n}):null,i?t.jsx("div",{className:"ui-searchbar-chips",children:i}):null]})}function su({size:e}){return t.jsx("span",{className:"ui-mark","data-size":e,"aria-hidden":"true",children:"b"})}function gT({quiet:e,still:n,className:s,children:r}){return t.jsx("div",{className:hi("ui-fieldbg",s),"data-quiet":e?"true":void 0,"data-still":n?"true":void 0,children:r})}function jB({dock:e,className:n,children:s}){return t.jsxs("div",{className:hi("ui-float",n),children:[t.jsx("div",{className:"ui-float-body",children:s}),e?t.jsx("div",{className:"ui-float-dock",children:e}):null]})}function wB(e){const n={};for(const s of e??[])n[s.key]=s.default;return n}function Qw(e){const[n,s]=d.useState({}),r=e??[],a={...wB(r),...n};return r.length===0?{values:void 0,controls:null}:{values:a,controls:t.jsx("div",{className:"ui-choices",children:r.map(i=>t.jsx(ie,{label:i.label,inline:!0,children:t.jsx("select",{value:a[i.key],onChange:l=>s(o=>({...o,[i.key]:l.target.value})),children:i.options.map(l=>t.jsx("option",{value:l,children:l},l))})},i.key))})}}function yB({props:e,timezone:n="UTC",onDecided:s}){var w;const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let y=!1;return a(null),l(null),A.approval(e.approvalId).then(N=>{y||a(N)}).catch(N=>{y||l(N instanceof he?N.message:String(N))}),()=>{y=!0}},[e.approvalId]);const{values:f,controls:m}=Qw(r==null?void 0:r.choices),p=(y,N)=>{h(y),l(null),(f&&y==="approve"?A.decide(e.approvalId,y,N,f):A.decide(e.approvalId,y,N)).then(b=>{a(b.action),s==null||s(b.action)}).catch(b=>l(b instanceof he?b.message:String(b))).finally(()=>h(null))};if(i&&!r)return t.jsx("p",{className:"wb-empty",children:i});if(!r)return t.jsx("p",{className:"wb-empty",children:"Loading the envelope…"});const g=r.state==="pending",x=(w=r.permissionScopes)==null?void 0:w.includes("always"),k=bB(r),j=(r.preview??"").split(`
|
|
103
|
-
`).length>12||(r.preview??"").length>900,v=[r.decidedBy?`by ${r.decidedBy}`:"",r.decidedVia?`via ${r.decidedVia}`:""].filter(Boolean).join(" ");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"Action"}),t.jsx("dd",{className:"wb-envelope-action",children:r.tool.split(".").map(y=>Bn(y)).join(" · ")}),t.jsx("dt",{children:"Status"}),t.jsxs("dd",{children:[g?t.jsx(Ae,{tone:"warning",dot:!0,children:"waiting for you"}):t.jsx(Ru,{state:r.state}),!g&&v?t.jsxs("span",{className:"wb-envelope-note",children:[" ",v]}):null]}),t.jsx("dt",{children:g?"Expires":"Decided"}),t.jsx("dd",{children:mt(g?r.expiresAt:r.decidedAt,n)})]}),t.jsxs("div",{className:"envelope-body","data-clamp":j&&!o?"true":void 0,children:[r.preview||"(this tool wrote no preview)",j&&!o?t.jsx("button",{type:"button",className:"wb-doc-more",onClick:()=>c(!0),children:"Show the whole preview"}):null]})]}),t.jsx(ae,{message:i}),g?m:null,g?t.jsxs("div",{className:"wb-envelope-decide",children:[t.jsx("p",{className:"wb-envelope-note",children:x?"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."}),t.jsxs("div",{className:"wb-envelope-buttons",children:[t.jsx("button",{className:"ui-btn","data-variant":"danger",disabled:u!==null,onClick:()=>p("reject"),children:u==="reject"?"Rejecting…":"Reject"}),x?t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","conversation"),children:"Auto: this conversation"}),t.jsx("button",{className:"ui-btn",disabled:u!==null,onClick:()=>p("approve","always"),children:"Always: this agent"})]}):null,t.jsx("button",{className:"ui-btn","data-variant":"good",disabled:u!==null,onClick:()=>p("approve"),children:u==="approve"?"Approving…":x?"Allow once":"Approve"})]})]}):null,t.jsxs("details",{className:"ui-details",children:[t.jsx("summary",{children:"The envelope, field by field"}),t.jsx("dl",{className:"ui-kv wb-envelope-fields",children:k.map(y=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:y.label}),y.block?t.jsx("dd",{className:"wb-envelope-block",children:t.jsx("pre",{className:"mono",children:y.value})}):t.jsx("dd",{className:y.mono?"mono":void 0,children:y.value})]},y.label))})]})]})}function bB(e){const n=[],s=e.envelope;if(s!==null&&typeof s=="object"&&!Array.isArray(s))for(const[a,i]of Object.entries(s))n.push(X0(Bn(a),i));else s!=null&&n.push({label:"Envelope",value:Jw(s)});const r=e.canonicalArgs;if(r!==null&&typeof r=="object"&&!Array.isArray(r))for(const[a,i]of Object.entries(r)){const l=`Argument · ${Bn(a)}`;n.some(o=>o.label===l)||n.push(X0(l,i))}return n.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&&n.push({label:"Conversation",value:e.conversationId,mono:!0}),e.jobId&&n.push({label:"Job",value:e.jobId,mono:!0}),n}function X0(e,n){return n!==null&&typeof n=="object"&&(!Array.isArray(n)||n.some(r=>r!==null&&typeof r=="object"))?{label:e,value:JSON.stringify(n,null,2),block:!0}:{label:e,value:Jw(n)}}function Jw(e){return e==null?"—":Array.isArray(e)?e.map(n=>Jw(n)).join(", ")||"—":typeof e=="object"?JSON.stringify(e):yn(e,"text",null)}const kB=new Set(["image/png","image/jpeg","image/gif","image/webp"]),NB=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Uh(e){const n=e!==null&&typeof e=="object"?e.artifacts:null;return Array.isArray(n)?n.flatMap(s=>{if(s===null||typeof s!="object")return[];const r=s;return typeof r.id!="string"||!NB.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 Xw(e){return kB.has(e.toLowerCase())}function Ur(e){return`/api/artifacts/${encodeURIComponent(e)}/preview`}function ni(e){return`/api/artifacts/${encodeURIComponent(e)}/download`}function ps(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 Zw(e,n){const s=e.toLowerCase(),r=(n??"").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 Mi={image:"Image",pdf:"PDF",table:"Spreadsheet",text:"Document",code:"Code",audio:"Audio",video:"Video",archive:"Archive",file:"File"};function Qd(e){return`artifact:${e}`}function SB(e){const n=Zw(e.mime,e.filename);return{id:Qd(e.artifactId),tool:Mi[n],title:e.filename??"Untitled file",renderer:"artifact",props:{attachment:e},at:null,source:"artifact",substantial:!1}}function CB({props:e}){const n=sT(e.artifactId),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(!1);if(d.useEffect(()=>{if(n===null)return;let h=!0;return r(null),i(null),o(!1),A.libraryEntry(n).then(f=>{h&&r({filename:f.entry.filename,sizeBytes:f.entry.sizeBytes})}).catch(()=>{}),()=>{h=!1}},[n]),n===null)return t.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=[a?`${a.width} × ${a.height}`:null,s!=null&&s.sizeBytes?ps(s.sizeBytes):null].filter(h=>h!==null);return t.jsxs("figure",{className:"wb-image",children:[t.jsx("div",{className:"wb-image-frame",children:l?t.jsx("p",{className:"wb-empty",children:"This file cannot be shown here. Download it to open it."}):t.jsx("a",{href:Ur(n),className:"wb-image-link",title:"Open at full size",children:t.jsx("img",{src:Ur(n),alt:e.caption??c,onLoad:h=>{const f=h.currentTarget;f.naturalWidth>0&&i({width:f.naturalWidth,height:f.naturalHeight})},onError:()=>o(!0)})})}),t.jsxs("figcaption",{className:"wb-image-caption",children:[t.jsxs(ne,{children:[t.jsx("span",{className:"wb-image-name",children:c}),u.length>0?t.jsx("span",{className:"wb-image-facts",children:u.join(" · ")}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(lt,{size:"sm",href:ni(n),download:(s==null?void 0:s.filename)??c,children:"Download"})]}),e.caption&&e.captionLabel?t.jsx(Zt,{summary:e.captionLabel,className:"wb-image-note",children:t.jsx("p",{className:"wb-image-note-body",children:e.caption})}):e.caption?t.jsx("p",{className:"wb-image-note",children:e.caption}):null]})]})}function EB({props:e}){return e.pairs.length===0?t.jsx("p",{className:"wb-empty",children:"Nothing to show."}):t.jsx("dl",{className:"ui-kv",children:e.pairs.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{className:"tnum",style:n.tone==="neutral"?void 0:{color:`var(--${n.tone})`},children:yn(n.value,n.unit,n.currency)})]},n.label))})}const $B=8;function xT({text:e,label:n="Output",className:s}){const r=d.useRef(null),a=d.useRef(!0);return d.useLayoutEffect(()=>{const i=r.current;i&&a.current&&(i.scrollTop=i.scrollHeight)},[e]),t.jsx("pre",{ref:r,className:s?`wb-terminal-body ${s}`:"wb-terminal-body","aria-label":n,tabIndex:0,onScroll:i=>{const l=i.currentTarget;a.current=l.scrollHeight-l.scrollTop-l.clientHeight<=$B},children:e})}function AB(e){if(e<1e3)return`${Math.round(e)} ms`;const n=e/1e3;if(n<60)return`${n.toFixed(n<10?1:0)} s`;const s=Math.floor(n/60);return`${s} min ${Math.round(n-s*60)} s`}function TB({text:e}){const[n,s]=d.useState("");return t.jsxs(t.Fragment,{children:[n?t.jsx("span",{role:"status",className:"wb-hint",children:n}):null,t.jsx($,{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 RB({props:e}){const n=e.output??"";return t.jsxs("div",{className:"wb-terminal",children:[t.jsxs(ne,{className:"wb-terminal-head",children:[e.command!==null?t.jsx("code",{className:"wb-terminal-command",title:e.command,children:e.command}):null,e.exitCode!==null?t.jsxs(Ae,{tone:e.exitCode===0?"good":"critical",mono:!0,children:["exit ",e.exitCode]}):null,e.elapsedMs!==null?t.jsx("span",{className:"wb-terminal-fact",children:AB(e.elapsedMs)}):null,t.jsx("span",{className:"ui-toolbar-spacer"}),n!==""?t.jsx(TB,{text:n}):null]}),e.omittedBytes!==null?t.jsxs("p",{className:"wb-terminal-note",children:["First ",ps(e.omittedBytes)," not shown."]}):null,n!==""?t.jsx(xT,{text:n}):t.jsx("p",{className:"wb-empty",children:"No output."}),e.metadata.length>0?t.jsx("dl",{className:"ui-kv wb-terminal-facts",children:e.metadata.map(s=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:s.label}),t.jsx("dd",{children:yn(s.value,s.unit,null)})]},s.label))}):null]})}function IB(){const e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase();return e==="127.0.0.1"||e==="::1"||e==="localhost"}function Z0(e){try{const n=new URL(e);return n.searchParams.delete("ticket"),n.toString()}catch{return e}}function PB(e){const n=new Set(e.ports??[]);return e.port!==null&&n.add(e.port),[...n].sort((s,r)=>s-r)}function MB({props:e}){var N;const[n,s]=d.useState(null),[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=((N=e.target)==null?void 0:N.plugin)??null,h=PB(e),[f,m]=d.useState(null),p=f!==null&&h.includes(f)?f:e.port,g=e.target?p!==null&&p!==e.port?`${e.target.name}.${p}`:e.target.name:null,x=e.changes??0,k=d.useRef(x),[j,v]=d.useState(0);d.useEffect(()=>{x<=k.current||(k.current=x,e.reloadsItself||v(b=>b+1))},[x,e.reloadsItself]),d.useEffect(()=>{if(u===null||g===null)return;let b=!0;return s(null),a(null),l(null),v(0),A.previewLink(u,g).then(S=>{b&&(s(S.url),a(Z0(S.url)))}).catch(S=>{b&&l(S instanceof Error?S.message:"That preview could not be opened.")}),()=>{b=!1}},[u,g]);const w=()=>{u===null||g===null||A.previewLink(u,g).then(b=>a(b.url)).catch(()=>{})};if(e.target===null)return t.jsxs("p",{className:"wb-empty",children:["This panel names no preview. A preview is ",t.jsx("code",{children:"/preview/<plugin>/<name>/"}),", and nothing else is framed here."]});const y=!(e.output===null||e.output==="");return t.jsxs("div",{className:"wb-preview","data-output":o||void 0,children:[t.jsxs("div",{className:"wb-row wb-preview-head",children:[e.title?t.jsx("h4",{className:"wb-doc-title",children:e.title}):null,h.length>1?t.jsx("select",{className:"wb-preview-port","aria-label":"Port",title:"The ports this process is listening on.",value:p??"",onChange:b=>m(Number(b.target.value)),children:h.map(b=>t.jsxs("option",{value:b,children:[":",b]},b))}):null,y?t.jsx("button",{type:"button",className:"ui-btn wb-preview-toggle","data-variant":"ghost","data-size":"sm","aria-pressed":o,onClick:()=>c(b=>!b),children:o?"Hide output":"Output"}):null,r?t.jsx("a",{className:"wb-preview-open",href:r,target:"_blank",rel:"noreferrer noopener",onPointerEnter:w,onFocus:w,title:"Through buddi: works from anywhere the dashboard does, including the tailnet.",children:"Open in a tab"}):null,p!==null&&IB()?t.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]}),t.jsxs("div",{className:"wb-preview-body",children:[n?t.jsx("iframe",{className:"wb-preview-frame",src:j===0?n:Z0(n),title:e.title??"Preview",sandbox:"allow-scripts allow-forms allow-same-origin allow-modals allow-downloads"},j):t.jsx("p",{className:"wb-empty wb-preview-frame",children:i??"Opening the preview…"}),y&&o?t.jsx(xT,{text:e.output??"",className:"wb-preview-output"}):null]})]})}const OB=50,DB=9,LB=24,FB=.6,_B=48,zB=/(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,UB=/^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}|$)/,BB=/^id$|(^|[a-z0-9])Id$|_id$/;function Il(e){return e===null||typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function bs(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function vT(...e){for(const n of e)if(bs(n))for(const s of["currency","currencyCode"]){const r=n[s];if(typeof r=="string"&&/^[A-Za-z]{3}$/.test(r))return r.toUpperCase()}return null}function jT(e,n,s){const r=n.filter(a=>a!=null&&a!=="");return r.length===0?"text":r.every(a=>typeof a=="boolean")?"boolean":r.every(a=>typeof a=="number"&&Number.isFinite(a))?s!==null&&zB.test(e)?"currency":"number":r.every(a=>typeof a=="string"&&UB.test(a))?"date":"text"}function WB(e,n){if(!BB.test(e))return!1;const s=n.filter(r=>!Eo(r));return s.length<2?!1:new Set(s.map(r=>String(r))).size===s.length}function Eo(e){return e==null||e===""?!0:Array.isArray(e)?e.length===0:bs(e)?Object.keys(e).length===0:!1}function eN(e,n){const s=e.filter(bs);if(s.length===0||s.length/e.length<.8)return null;const r=s.slice(0,OB),a=new Map,i=[];for(const h of r)for(const f of Object.keys(h))a.has(f)||i.push(f),a.set(f,(a.get(f)??0)+1);if(a.size===0||a.size>LB||[...a.values()].reduce((h,f)=>h+f,0)/(a.size*r.length)<FB)return null;const o=[...a.keys()].sort((h,f)=>{const m=(a.get(f)??0)-(a.get(h)??0);return m!==0?m:i.indexOf(h)-i.indexOf(f)}),c=[],u=[];for(const h of o){const f=r.map(x=>x[h]),m=f.filter(x=>!Eo(x));if(m.length===0||WB(h,f))continue;const p=vT(r[0],n),g=jT(h,f,p);if(r.length>=4&&m.length===f.length&&f.every(x=>Il(x)&&x===f[0])){u.push({label:Bn(h),value:f[0],type:g,currency:p});continue}if(c.push({key:h,label:Bn(h),type:g,currency:g==="currency"?p:null}),c.length===DB)break}return c.length===0?null:{columns:c,rows:s,constants:u}}function HB(e,n,s){const r=vT(s);return{label:Bn(e),value:n,type:jT(e,[n],r),currency:r}}function wT(e){return typeof e=="string"&&e.length>_B}function KB(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.":bs(e)&&Object.keys(e).length===0?"This tool returned an empty result.":null}function Xx(e){if(typeof e=="string"&&e.trim()!=="")return e;if(bs(e))for(const n of["message","error","reason","detail","description"]){const s=e[n];if(typeof s=="string"&&s.trim()!=="")return s;if(bs(s)){const r=Xx(s);if(r!=="The call failed with no reason given.")return r}}return"The call failed with no reason given."}function ey(e,n={}){if(n.failed){let f=e;if(typeof e=="string")try{const m=JSON.parse(e.replace(/^tool-error:\s*/,""));bs(m)&&(f=m)}catch{}return{kind:"error",summary:Xx(f),detail:tN(f)}}if(bs(e)){const f=e.error,m=e.ok;if(typeof f=="string"&&f.trim()!==""||m===!1)return{kind:"error",summary:Xx(e),detail:tN(e)}}const s=KB(e);if(s)return{kind:"empty",note:s,stats:[]};if(Array.isArray(e)){const f=eN(e,e);return f?{kind:"table",label:null,columns:f.columns,rows:f.rows,total:f.rows.length,stats:f.constants,notes:[],asides:[]}:e.every(Il)?{kind:"list",label:null,items:e,total:e.length,stats:[],notes:[],asides:[]}:{kind:"tree",value:e}}if(!bs(e))return{kind:"tree",value:e};const r=Object.entries(e);let a=null,i=null;for(const[f,m]of r){if(!Array.isArray(m))continue;const p=eN(m,e);if(p){(!a||p.rows.length>a.candidate.rows.length)&&(a={key:f,candidate:p});continue}m.length>0&&m.every(Il)&&(!i||m.length>i.items.length)&&(i={key:f,items:m})}const l=(a==null?void 0:a.key)??(i==null?void 0:i.key)??null,o=[],c=[],u=[];for(const[f,m]of r)if(f!==l){if(wT(m)){c.push(m);continue}if(Il(m)){if(m==="")continue;o.push(HB(f,m,e));continue}m!==void 0&&u.push({label:Bn(f),value:m})}if(a)return{kind:"table",label:Bn(a.key),columns:a.candidate.columns,rows:a.candidate.rows,total:a.candidate.rows.length,stats:[...o,...a.candidate.constants],notes:c,asides:u};if(i)return{kind:"list",label:Bn(i.key),items:i.items,total:i.items.length,stats:o,notes:c,asides:u};const h=r.filter(([,f])=>Array.isArray(f)&&f.length===0);return h.length>0&&h.length===r.filter(([,f])=>Array.isArray(f)).length?{kind:"empty",note:`No ${h.map(([m])=>Bn(m).toLowerCase()).join(", ")} to show.`,stats:o}:r.every(([,f])=>Il(f)||bs(f)||Array.isArray(f))?{kind:"record",pairs:o,notes:c,asides:u}:{kind:"tree",value:e}}function tN(e){if(!bs(e))return null;const n=Object.entries(e).filter(([s])=>s!=="message"&&s!=="error");return n.length===0?null:Object.fromEntries(n)}const Bh=25,VB=3,Zx=8,yT=6;function ev(e,n=0){if(n>yT||Eo(e)||wT(e))return 0;if(Il(e))return 1;if(Array.isArray(e)){let s=0;for(const r of e)if(s+=ev(r,n+1),s>=Zx)return s;return s}if(bs(e)){let s=0;for(const r of Object.values(e))if(s+=ev(r,n+1),s>=Zx)return s;return s}return 0}function tv(e,n=0){if(n>yT)return!1;if(Array.isArray(e))return e.some(i=>tv(i,n+1));if(!bs(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,a=e.url??e.src??e.downloadUrl??e.path;return typeof r=="string"&&r.includes("/")&&typeof a=="string"&&a.trim()!==""?!0:Object.values(e).some(i=>tv(i,n+1))}function GB(e){if(tv(e))return!0;const n=ey(e);switch(n.kind){case"table":return n.rows.length>0;case"list":return n.items.length>=VB;case"record":case"tree":return ev(e)>=Zx;default:return!1}}function Sp(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function ty(e){const n=Sp(e);if(!n)return null;const s=Sp(n.output)??n;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===n?null:Sp(n.input),a=(r==null?void 0:r.command)??s.command;return{command:typeof a=="string"?a:null,input:r,result:s}}function YB({text:e,label:n}){const[s,r]=d.useState("");return t.jsxs("span",{className:"wb-command-copy",children:[t.jsx("button",{className:"ui-btn",onClick:()=>{var a;if(r(""),!((a=navigator.clipboard)!=null&&a.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:n}),s&&t.jsx("span",{role:"status",className:"wb-hint",children:s})]})}function Cp({title:e,text:n,error:s=!1}){return t.jsxs("section",{className:"wb-command-stream","data-error":s||void 0,children:[t.jsxs("div",{className:"wb-command-bar",children:[t.jsx("h4",{children:e}),t.jsx(YB,{text:n,label:`Copy ${e.toLowerCase()}`})]}),t.jsx("pre",{className:"wb-command-text","aria-label":e,tabIndex:0,children:n})]})}function qB({value:e,children:n}){const{result:s,command:r,input:a}=e,i=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(([h,f])=>!["stdout","stderr","state","exitCode","artifacts","outputErrors","command"].includes(h)&&f!==null&&f!==void 0&&f!=="")),u=Array.isArray(s.outputErrors)?s.outputErrors.filter(h=>typeof h=="string"):[];return t.jsxs("div",{className:"wb-command-result",children:[t.jsxs("div",{className:"wb-command-bar",children:[t.jsx("span",{className:"ui-pill","data-tone":o?"good":"critical",children:i?"Failed":s.state==="completed"&&l?"Terminated":s.state}),s.exitCode!==null&&t.jsxs("span",{className:"mono",children:["Exit code ",s.exitCode]}),l&&t.jsxs("span",{className:"mono",children:["Signal ",l]}),t.jsx("span",{className:"wb-hint",children:"Recorded command result"})]}),r!==null&&t.jsx(Cp,{title:"Command",text:r}),s.state==="output-limit"&&t.jsx("p",{className:"wb-fail",children:"Output limit reached. The command was stopped and the captured output may be incomplete."}),s.state==="timed-out"&&t.jsx("p",{className:"wb-fail",children:"The command exceeded its time limit. Output below may be partial."}),s.state==="cancelled"&&t.jsx("p",{className:"wb-note",children:"The command was cancelled. Completed changes were not undone."}),s.stdout?t.jsx(Cp,{title:"Output",text:s.stdout}):t.jsx("p",{className:"wb-note",children:"No standard output."}),s.stderr?t.jsx(Cp,{title:"Standard error",text:s.stderr,error:!0}):null,u.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"File export errors"}),u.map((h,f)=>t.jsx("p",{className:"wb-fail",children:h},f))]}),n,(Object.keys(c).length>0||a!==null)&&t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Execution details"}),t.jsx("pre",{children:Cs({...c,...a?{input:a}:{}})})]})]})}const xd=2,nN=64;function QB({props:e}){const[n,s]=d.useState(!1),r=ty(e.value),a=JB((r==null?void 0:r.result)??e.value),i=d.useMemo(()=>ey(e.value,{failed:e.failed??!1}),[e.value,e.failed]);return t.jsxs("div",{children:[!r&&t.jsx(sN,{files:a}),n?t.jsx("pre",{className:"ui-code",children:Cs(e.value)}):r?t.jsx(qB,{value:r,children:a.length>0&&t.jsxs("section",{children:[t.jsx("h4",{children:"Generated files"}),t.jsx(sN,{files:a})]})}):a.length?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"Tool details"}),t.jsx(rN,{shape:i})]}):t.jsx(rN,{shape:i}),t.jsx("div",{className:"wb-row-end wb-section",children:t.jsx("button",{className:"ui-btn","data-variant":"ghost","data-size":"sm",onClick:()=>s(l=>!l),"aria-pressed":n,children:n?"Readable":"Raw JSON"})})]})}function JB(e){const n=e&&typeof e=="object"&&"artifacts"in e?e.artifacts:null;return Array.isArray(n)?n.filter(s=>s&&typeof s.id=="string"&&/^[0-9a-f-]{36}$/i.test(s.id)&&typeof s.filename=="string"):[]}function sN({files:e}){return e.length?t.jsx("div",{className:"wb-artifacts",children:e.map(n=>{var s;return t.jsxs("div",{children:[["image/png","image/jpeg","image/gif","image/webp"].includes(n.mime??"")?t.jsx(XB,{file:n}):null,t.jsx("a",{className:"ui-btn",href:`/api/artifacts/${encodeURIComponent(n.id)}/download`,download:!0,children:(s=n.mime)!=null&&s.startsWith("image/")?`Download ${n.filename}`:n.filename})]},n.id)})}):null}function XB({file:e}){const[n,s]=d.useState(!1);return n?t.jsx("p",{className:"wb-note",children:"Preview unavailable. You can still download the file."}):t.jsx("img",{className:"wb-artifact-image",src:`/api/artifacts/${e.id}/preview`,alt:e.filename,onError:()=>s(!0)})}function rN({shape:e}){switch(e.kind){case"error":return t.jsxs("div",{children:[t.jsx("p",{className:"wb-fail",role:"status",children:e.summary}),e.detail===null?null:t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:"What came back with it"}),t.jsx("div",{className:"wb-tree",children:ru(e.detail,1)})]})]});case"empty":return t.jsxs("div",{children:[t.jsx(Ep,{stats:e.stats}),t.jsx("p",{className:"wb-note",children:e.note})]});case"table":{const n=r5(e.columns,e.rows);return t.jsxs("div",{children:[t.jsx(Ep,{stats:e.stats}),t.jsx($p,{notes:e.notes}),n?t.jsx(a5,{label:e.label,plan:n,rows:e.rows,total:e.total}):t.jsx(e5,{label:e.label,columns:e.columns,rows:e.rows,total:e.total}),t.jsx(Ap,{asides:e.asides})]})}case"list":return t.jsxs("div",{children:[t.jsx(Ep,{stats:e.stats}),t.jsx($p,{notes:e.notes}),e.label?t.jsx("h4",{className:"wb-sub",children:e.label}):null,t.jsx("ul",{className:"wb-list",children:e.items.slice(0,100).map((n,s)=>t.jsx("li",{children:yn(n,"text",null)},s))}),e.total>100?t.jsxs("p",{className:"wb-note",children:["Showing 100 of ",e.total,"."]}):null,t.jsx(Ap,{asides:e.asides})]});case"record":return t.jsxs("div",{children:[t.jsx($p,{notes:e.notes}),t.jsx(ZB,{pairs:e.pairs}),t.jsx(Ap,{asides:e.asides})]});default:return t.jsx("div",{className:"wb-tree",children:ru(e.value,0)})}}function Ep({stats:e}){return e.length===0?null:t.jsx("div",{className:"ui-stats","data-inline":"true",children:e.map(n=>t.jsxs("div",{children:[t.jsx("div",{className:"ui-stat-k",children:n.label}),t.jsx("div",{className:"ui-stat-v",children:ny(n.value,n.type,n.currency)})]},n.label))})}const aN=200;function $p({notes:e}){if(e.length===0)return null;const n=e.filter(r=>r.length<=aN),s=e.filter(r=>r.length>aN);return t.jsxs(t.Fragment,{children:[n.map(r=>t.jsx("p",{className:"wb-note",children:r},r)),s.length>0?t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:s.length===1?"A note that came with this result":`${s.length} notes that came with this result`}),s.map(r=>t.jsx("p",{className:"wb-note",children:r},r))]}):null]})}function ZB({pairs:e}){return e.length===0?t.jsx("p",{className:"wb-note",children:"Nothing to show."}):t.jsx("dl",{className:"ui-kv",children:e.map(n=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{children:n.label}),t.jsx("dd",{className:n.type==="text"?void 0:"tnum",children:ny(n.value,n.type,n.currency)})]},n.label))})}function Ap({asides:e}){return e.length===0?null:t.jsx("div",{className:"wb-section",children:e.map(n=>t.jsxs("details",{className:"wb-aside",children:[t.jsx("summary",{children:n.label}),t.jsx("div",{className:"wb-tree",children:ru(n.value,1)})]},n.label))})}function e5({label:e,columns:n,rows:s,total:r}){const[a,i]=d.useState(!1),l=r<=Bh+5?r:Bh,o=a?s:s.slice(0,l);return t.jsxs("div",{children:[e?t.jsx("h4",{className:"wb-sub",children:e}):null,t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:n.map(c=>t.jsx("th",{className:kT(c.type)?"num":void 0,children:c.label},c.key))})}),t.jsx("tbody",{children:o.map((c,u)=>t.jsx("tr",{children:n.map(h=>t.jsx(i5,{value:c[h.key],column:h},h.key))},u))})]})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}const t5=/^(title|name|headline|subject|label|heading)$/i,n5=/^(url|link|href|uri|permalink)$/i;function Wh(e){return typeof e=="string"&&/^https?:\/\/[^\s]+$/i.test(e.trim())}function s5(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function bT(e,n=48){try{const s=new URL(e),r=s.pathname==="/"?"":s.pathname,a=`${s.hostname.replace(/^www\./,"")}${r}${s.search}`;return a.length>n?`${a.slice(0,n-1)}…`:a}catch{return e.length>n?`${e.slice(0,n-1)}…`:e}}function vd(e,n){const s=e.map(r=>r[n]).filter(r=>typeof r=="string"&&r.trim()!=="");return s.length===0?0:s.reduce((r,a)=>r+a.length,0)/s.length}function r5(e,n){if(n.length===0)return null;const s=e.filter(h=>h.type==="text"),r=s.find(h=>n5.test(h.key)&&n.some(f=>Wh(f[h.key])))??s.find(h=>{const f=n.map(m=>m[h.key]).filter(m=>!Eo(m));return f.length>0&&f.filter(Wh).length/f.length>=.6});if(!r)return null;const a=s.filter(h=>h.key!==r.key),i=a.find(h=>t5.test(h.key))??a.find(h=>vd(n,h.key)>0);if(!i)return null;const o=[...a.filter(h=>h.key!==i.key)].sort((h,f)=>vd(n,f.key)-vd(n,h.key)),c=o[0]&&vd(n,o[0].key)>40?o[0]:null,u=e.filter(h=>h.key!==r.key&&h.key!==i.key&&h.key!==(c==null?void 0:c.key)).map(h=>h.key);return{url:r.key,title:i.key,description:(c==null?void 0:c.key)??null,meta:u}}function a5({label:e,plan:n,rows:s,total:r}){const[a,i]=d.useState(!1),l=r<=Bh+5?r:Bh,o=a?s:s.slice(0,l);return t.jsxs("div",{children:[e?t.jsx("h4",{className:"wb-sub",children:e}):null,t.jsx("ol",{className:"wb-records",children:o.map((c,u)=>{const h=c[n.url],f=Wh(h)?h.trim():null,m=typeof c[n.title]=="string"&&c[n.title].trim()!==""?c[n.title]:f?bT(f):"Untitled",p=n.description&&typeof c[n.description]=="string"?c[n.description]:null,g=f?s5(f):null,x=n.meta.map(k=>c[k]).filter(k=>!Eo(k)&&typeof k!="object").map(k=>String(k)).filter(k=>g===null||k.replace(/^www\./,"")!==g);return t.jsxs("li",{className:"wb-record",children:[f?t.jsx("a",{className:"wb-record-title",href:f,target:"_blank",rel:"noopener noreferrer",children:m}):t.jsx("span",{className:"wb-record-title",children:m}),t.jsxs("div",{className:"wb-record-meta",children:[g?t.jsx("span",{className:"wb-record-host",title:f??void 0,children:g}):null,x.map((k,j)=>t.jsx("span",{children:k.length>60?`${k.slice(0,59)}…`:k},j))]}),p?t.jsx("p",{className:"wb-record-desc",children:p.length>280?`${p.slice(0,279)}…`:p}):null]},u)})}),r>o.length?t.jsxs("p",{className:"wb-note wb-note-row",children:[t.jsxs("span",{children:["Showing ",o.length," of ",r]}),t.jsxs("button",{className:"ui-btn",onClick:()=>i(!0),children:["Show all ",r]})]}):null]})}function i5({value:e,column:n}){if(Eo(e))return t.jsx("td",{className:"wb-cell-soft",children:"—"});if(Wh(e)){const a=e.trim();return t.jsx("td",{className:"wb-cell-link",children:t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",title:a,children:bT(a)})})}if(e!==null&&typeof e=="object"){const a=Array.isArray(e)?`${e.length} item${e.length===1?"":"s"}`:`${Object.keys(e).length} fields`;return t.jsx("td",{className:"wb-cell-soft",title:Cs(e),children:a})}const s=ny(e,n.type,n.currency),r=s.length>nN?`${s.slice(0,nN-1)}…`:s;return t.jsx("td",{className:kT(n.type)?"num":"wb-cell-text",...r===s?{}:{title:s},children:r})}function kT(e){return e==="number"||e==="currency"}function ny(e,n,s){return e==null?"—":n==="boolean"?e?"yes":"no":yn(e,n==="text"?"text":n,s)}function ru(e,n){if(e===null)return t.jsx("span",{className:"wb-tree-null",children:"null"});if(e===void 0)return t.jsx("span",{className:"wb-tree-null",children:"—"});if(typeof e=="number")return t.jsx("span",{className:"wb-tree-num",children:e});if(typeof e=="boolean")return t.jsx("span",{className:"wb-tree-bool",children:e?"true":"false"});if(typeof e=="string")return t.jsx("span",{children:e===""?t.jsx("em",{className:"wb-tree-null",children:"empty"}):e});if(Array.isArray(e)){if(e.length===0)return t.jsx("span",{className:"wb-tree-null",children:"none"});const a=t.jsxs("div",{className:"wb-tree-branch",children:[e.slice(0,50).map((i,l)=>t.jsxs("div",{children:[t.jsxs("span",{className:"wb-tree-key",children:[l,". "]}),ru(i,n+1)]},l)),e.length>50?t.jsxs("div",{className:"wb-tree-key",children:["…and ",e.length-50," more"]}):null]});return n>=xd?t.jsx(iN,{summary:`${e.length} items`,open:n===xd,children:a}):a}const s=Object.entries(e);if(s.length===0)return t.jsx("span",{className:"wb-tree-null",children:"empty"});const r=t.jsx("div",{className:n===0?void 0:"wb-tree-branch",children:s.map(([a,i])=>t.jsxs("div",{children:[t.jsxs("span",{className:"wb-tree-key",children:[Bn(a),": "]}),ru(i,n+1)]},a))});return n>=xd?t.jsx(iN,{summary:`${s.length} fields`,open:n===xd,children:r}):r}function iN({summary:e,open:n,children:s}){return t.jsxs("details",{open:n,children:[t.jsx("summary",{className:"wb-tree-key",children:e}),s]})}function l5({props:e}){const n=e.groups.every(s=>s.rows.length===0);return t.jsxs("div",{children:[e.summary.length>0?t.jsx("div",{className:"ui-stats","data-inline":"true",children:e.summary.map(s=>t.jsxs("div",{children:[t.jsx("div",{className:"ui-stat-k",children:s.label}),t.jsx("div",{className:"ui-stat-v","data-tone":s.tone,children:yn(s.value,s.unit,s.currency)})]},s.label))}):null,n?t.jsx("p",{className:"wb-empty",children:e.empty}):e.groups.map((s,r)=>t.jsxs("div",{className:r>0?"wb-section":void 0,children:[s.label?t.jsx("h4",{className:"ui-stat-k wb-label",children:s.label}):null,t.jsx("div",{className:"ui-table-wrap",children:t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:e.columns.map(a=>t.jsx("th",{className:NT(a.type)?"num":void 0,"data-type":a.type,children:a.label},a.key))})}),t.jsx("tbody",{children:s.rows.map((a,i)=>t.jsx("tr",{children:a.map((l,o)=>{var c;return t.jsx(o5,{cell:l},((c=e.columns[o])==null?void 0:c.key)??o)})},i))})]})})]},s.label??r))]})}function o5({cell:e}){const n=yn(e.value,e.type,e.currency);return e.bar?t.jsx("td",{className:"num",children:t.jsxs("div",{className:"wb-row wb-row-end",children:[t.jsx("div",{className:"ui-meter",role:"meter","aria-valuenow":Math.round(e.bar.fraction*100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":n,children:t.jsx("div",{className:"ui-meter-fill","data-tone":e.bar.tone,style:{width:`${Math.round(e.bar.fraction*100)}%`}})}),t.jsx("span",{className:"tnum",children:n})]})}):t.jsx("td",{className:NT(e.type)?"num":void 0,"data-type":e.type,title:n.length>40?n:void 0,children:n})}function NT(e){return e==="number"||e==="currency"||e==="percent"}const lN={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","moon-cloud":"moon-cloud",check:"check",clock:"clock"};function $o(e){return(e&&Object.prototype.hasOwnProperty.call(lN,e)?lN[e]:void 0)??"dot"}function Hh(e,n){return(e??[]).filter(s=>s.place===n).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 Kh="buddi:plugin-pages-changed";function c5(){window.dispatchEvent(new Event(Kh))}function ST(e=!1){const[n,s]=d.useState([]);return d.useEffect(()=>{if(e)return;let r=!1;const a=()=>{Promise.resolve().then(()=>A.pages()).then(l=>{r||s(Array.isArray(l==null?void 0:l.pages)?l.pages:[])}).catch(()=>{})};a();const i=()=>{document.visibilityState==="visible"&&a()};return window.addEventListener(Kh,a),document.addEventListener("visibilitychange",i),()=>{r=!0,window.removeEventListener(Kh,a),document.removeEventListener("visibilitychange",i)}},[e]),{all:n,rail:Hh(n,"rail"),settings:Hh(n,"settings"),find:(r,a)=>n.find(i=>i.plugin===r&&i.id===a)}}function CT(e,n){const s=(n??[]).filter(i=>i.plugin===e),r=Hh(s,"rail")[0]??Hh(s,"settings")[0];if(r!=null&&r.title.trim())return r.title.trim();const a=e.replace(/[-_]+/g," ").trim();return a?a.charAt(0).toUpperCase()+a.slice(1):e}let Jd=null;typeof window<"u"&&window.addEventListener(Kh,()=>{Jd=null});function u5(){return Jd??(Jd=Promise.resolve().then(()=>A.pages()).then(e=>Array.isArray(e==null?void 0:e.pages)?e.pages:[]).catch(()=>(Jd=null,[]))),Jd}function sy(e,n,s){return s==="settings"?mr(e,n):_r(e,n)}function d5(e){const[n,s]=d.useState(null),r=e==null?void 0:e.plugin,a=e==null?void 0:e.page;return d.useEffect(()=>{if(!r||!a)return;let i=!1;return u5().then(l=>{const o=l.find(c=>c.plugin===r&&c.id===a);i||s(o?{href:sy(r,a,o.place),label:o.place==="settings"?`Settings → ${o.title}`:o.title}:null)}),()=>{i=!0}},[r,a]),n}function ET({props:e,layout:n,selected:s,onPick:r}){return e.tiles.length===0?t.jsx("p",{className:"wb-empty",children:e.empty}):t.jsx("ul",{className:"wb-tiles","data-notice":e.notice?"true":void 0,"data-layout":n&&n!=="grid"?n:void 0,style:n==="row"?{"--tiles-n":e.tiles.length}:void 0,children:e.tiles.map((a,i)=>t.jsx(h5,{tile:a,...r?{picked:i===s,onPick:()=>r(i)}:{}},`${i}-${a.label}`))})}function h5({tile:e,picked:n,onPick:s}){const r=d5(e.link),a=[e.label,e.value,...e.lines].filter(l=>l!=="").join(", "),i=t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":e.icon??"dot",children:t.jsx(oe,{name:$o(e.icon),size:22})}),e.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:e.value}):null,t.jsx("span",{className:"wb-tile-label",children:e.label}),e.lines.map((l,o)=>t.jsx("span",{className:"wb-tile-line",children:l},o))]});return s?t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-tone":n?"accent":e.tone==="neutral"?void 0:e.tone,"data-selected":n?"true":void 0,"aria-pressed":n===!0,"aria-label":a,onClick:s,children:i})}):t.jsxs("li",{className:"wb-tile",children:[t.jsx("span",{className:"sr-only",children:a}),t.jsxs(Ps,{tone:e.tone==="neutral"?void 0:e.tone,children:[i,r?t.jsx("a",{className:"wb-tile-link",href:r.href,children:r.label}):null]})]})}const fl=760,Tp=400,nn={top:18,right:18,bottom:36,left:66},f5=5;function m5({props:e}){const{points:n,referenceLines:s,unit:r,currency:a}=e;if(n.length===0)return t.jsx("p",{className:"wb-empty",children:"This result carried no points to plot."});const i=[...n.map(y=>y.y),...s.map(y=>y.value)],l=Math.min(...i),o=Math.max(...i),c=o-l||Math.abs(o)||1,u=l-c*.08,h=o+c*.08,f=fl-nn.left-nn.right,m=Tp-nn.top-nn.bottom,p=y=>nn.left+(n.length===1?f/2:y/(n.length-1)*f),g=y=>nn.top+m-(y-u)/(h-u)*m,x=Dh(l,o,4),k=g5(n.map(y=>y.y),e.mark),j=e.shadeBelow===null?[]:x5(n.map(y=>y.y),e.shadeBelow),v=n.map((y,N)=>`${N===0?"M":"L"}${p(N)},${g(y.y)}`).join(" "),w=y=>yn(y,r,a);return t.jsxs("div",{children:[e.label?t.jsx("p",{className:"ui-panel-sub",children:e.label}):null,t.jsxs("div",{className:"wb-chart-layout",children:[t.jsx("div",{className:"wb-chart-plot",children:t.jsxs("svg",{className:"wb-chart",viewBox:`0 0 ${fl} ${Tp}`,role:"img","aria-label":p5(e,w),preserveAspectRatio:"xMidYMid meet",children:[j.map(y=>t.jsx("rect",{className:"wb-chart-breach",x:p(y.from),width:Math.max(2,p(y.to)-p(y.from)),y:nn.top,height:m},`band-${y.from}`)),x.map(y=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-grid",x1:nn.left,x2:fl-nn.right,y1:g(y),y2:g(y)}),t.jsx("text",{x:nn.left-8,y:g(y)+4,textAnchor:"end",children:w(y)})]},`tick-${y}`)),s.map(y=>t.jsxs("g",{children:[t.jsx("line",{className:"wb-chart-floor",x1:nn.left,x2:fl-nn.right,y1:g(y.value),y2:g(y.value)}),t.jsxs("text",{x:fl-nn.right,y:g(y.value)-6,textAnchor:"end",children:[y.label," ",w(y.value)]})]},`rule-${y.label}`)),t.jsx("line",{className:"wb-chart-axis",x1:nn.left,x2:nn.left,y1:nn.top,y2:nn.top+m}),t.jsx("line",{className:"wb-chart-axis",x1:nn.left,x2:fl-nn.right,y1:nn.top+m,y2:nn.top+m}),t.jsx("path",{className:"wb-chart-series",d:v}),k!==null?t.jsxs("g",{children:[t.jsx("circle",{className:"wb-chart-min",cx:p(k),cy:g(n[k].y),r:4.5}),t.jsx("text",{x:p(k),y:g(n[k].y)+20,textAnchor:"middle",children:w(n[k].y)})]}):null,v5(n.length).map(y=>t.jsx("text",{x:p(y),y:Tp-10,textAnchor:"middle",children:Fx(n[y].x)},`x-${y}`))]})}),e.events.length>0?t.jsxs("aside",{className:"wb-chart-events",children:[t.jsx("h4",{className:"ui-stat-k wb-label",children:"What happens"}),t.jsx("ul",{className:"wb-chart-event-list",children:e.events.map((y,N)=>t.jsxs("li",{className:"wb-chart-event",children:[t.jsxs("span",{children:[t.jsx("span",{className:"wb-chart-event-day",children:Fx(y.at)}),y.label]}),y.amount===null?null:t.jsx("span",{className:y.amount<0?"tnum critical":"tnum good",children:yn(y.amount,r,a)})]},`${y.at}-${y.label}-${N}`))})]}):null]})]})}function p5(e,n){const s=e.points.map(l=>l.y),r=e.points[0],a=e.points[e.points.length-1],i=e.referenceLines.map(l=>`${l.label} at ${n(l.value)}`).join(", ");return[`${e.points.length} points from ${r==null?void 0:r.x} to ${a==null?void 0:a.x}`,`low ${n(Math.min(...s))}, high ${n(Math.max(...s))}`,i].filter(Boolean).join("; ")}function g5(e,n){if(!n||e.length===0)return null;let s=0;for(let r=1;r<e.length;r+=1)(n==="min"?e[r]<e[s]:e[r]>e[s])&&(s=r);return s}function x5(e,n){const s=[];let r=null;return e.forEach((a,i)=>{a<n?r===null&&(r=i):r!==null&&(s.push({from:r,to:i}),r=null)}),r!==null&&s.push({from:r,to:e.length-1}),s}function v5(e,n=f5){if(e<=0)return[];if(e<=n)return[...Array(e).keys()];const s=e-1,r=new Set;for(let a=0;a<n;a+=1)r.add(Math.round(a/(n-1)*s));return[...r].sort((a,i)=>a-i)}const Ls=e=>e,nv={timeseries:Ls(m5),table:Ls(l5),bars:Ls(F3),keyvalue:Ls(EB),tiles:Ls(ET),document:Ls(I6),diff:Ls(H3),terminal:Ls(RB),image:Ls(CB),preview:Ls(MB),envelope:Ls(yB),structured:Ls(QB)},j5="structured";function w5(e){return(Vh(e)?nv[e]:void 0)??nv[j5]}function Vh(e){return Object.prototype.hasOwnProperty.call(nv,e)}function y5({renderer:e,props:n,timezone:s,onDecided:r}){const a=w5(e),l=Vh(e)?n:{value:n};return t.jsx(a,{props:l,timezone:s,onDecided:r})}function b5({profile:e,onChange:n}){return t.jsxs("div",{className:"wb-prof","data-testid":"agent-profile",children:[t.jsx("p",{className:"wb-prof-lead",children:e.description}),t.jsxs("div",{className:"wb-prof-tags",children:[e.isDefault?t.jsx(Rp,{children:"Opens by default"}):null,t.jsx(Rp,{children:e.source==="example"?"Shipped with buddi":"Yours"}),e.roles.map(s=>t.jsx(Rp,{title:`A surface command that asks for "${s}" lands on this agent.`,children:Bn(s)},s))]}),e.available?null:t.jsxs("p",{className:"wb-prof-blocked","data-testid":"agent-profile-unavailable",children:[t.jsx("strong",{children:"This agent cannot run here."})," ",e.unavailableReason]}),(e.disabled??[]).map(s=>t.jsx("p",{className:"wb-prof-blocked","data-testid":"agent-profile-disabled",children:s},s)),t.jsx(Yo,{title:"How it works with you",note:"Live decisions stay in the conversation; this page explains the standing rules.",children:t.jsxs("ul",{className:"wb-prof-list",children:[t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name",children:"Quick questions"}),t.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."})]}),t.jsx("span",{className:"wb-prof-auto",children:"Answers only"})]}),t.jsxs("li",{className:"wb-prof-row","data-gated":"true",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name",children:"Action approvals"}),t.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."})]}),t.jsxs("span",{className:"wb-prof-gate",children:[t.jsx($T,{}),"Exact action"]})]})]})}),t.jsx(Yo,{title:"What it can do",note:k5(e),tone:e.gatedCount>0?"warning":void 0,children:e.tools.length===0?t.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=>t.jsx(N5,{family:s},s.family))}),t.jsx(Yo,{title:"What it runs on",children:t.jsxs("dl",{className:"wb-prof-kv",children:[t.jsx(qo,{label:"Provider",children:e.engine.provider}),t.jsx(qo,{label:"Model",children:t.jsx("span",{className:"mono",children:e.engine.model})}),t.jsxs(qo,{label:"Credential",children:[e.engine.credentialKind," from"," ",t.jsx("span",{className:"mono",children:e.engine.credentialEnv})]}),t.jsxs(qo,{label:"Turn budget",children:[e.engine.maxTurns," ",e.engine.maxTurns===1?"turn":"turns"," per message"]}),t.jsx(qo,{label:"Language",children:A5(e.engine.language)})]})}),e.skills.length>0?t.jsx(Yo,{title:"What it has read",note:`${e.skills.length} ${e.skills.length===1?"skill":"skills"}, composed into every run`,children:t.jsx("ul",{className:"wb-prof-list",children:e.skills.map(s=>t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name mono",children:s.name}),s.description?t.jsx("span",{className:"wb-prof-row-desc",children:s.description}):null]}),t.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?t.jsx(Yo,{title:"Who it can hand work to",note:"A colleague's tools are reached through the colleague, never held here",children:t.jsx("ul",{className:"wb-prof-list",children:e.delegates.map(s=>t.jsxs("li",{className:"wb-prof-row",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsxs("span",{className:"wb-prof-row-name mono",children:["@",s.handle]}),t.jsx("span",{className:"wb-prof-row-desc",children:s.description})]}),t.jsx("span",{className:"wb-prof-row-side",children:s.available?s.name:`${s.name} · cannot run`})]},s.id))})}):null,t.jsxs("footer",{className:"wb-prof-foot",children:[t.jsx("p",{className:"wb-prof-note",children:e.note}),t.jsx("p",{className:"wb-prof-file mono",title:e.file,children:e.file}),e.changeVia&&n?t.jsxs("button",{className:"ui-btn","data-testid":"agent-profile-change",title:e.changeVia.prompt,onClick:()=>n({agentId:e.changeVia.agentId,prompt:e.changeVia.prompt}),children:["Ask @",e.changeVia.handle," to change this"]}):null]})]})}function k5(e){if(e.toolCount===0)return"Nothing. This agent holds no tools.";const n=`${e.toolCount} ${e.toolCount===1?"tool":"tools"}`;if(e.gatedCount===0)return`${n}, 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`${n}, and ${s}.`}function N5({family:e}){const n=[...e.tools].sort((s,r)=>Number(r.gated)-Number(s.gated));return t.jsxs("section",{className:"wb-prof-family",children:[t.jsxs("h4",{className:"wb-prof-family-head",children:[t.jsx("span",{className:"wb-prof-family-name",children:Bn(e.family)}),t.jsxs("span",{className:"wb-prof-family-note",children:[e.tools.length," ",e.tools.length===1?"tool":"tools",e.gated>0?` · ${e.gated} needs you`:""]})]}),t.jsx("ul",{className:"wb-prof-list",children:n.map(s=>t.jsx(S5,{tool:s},s.name))})]})}function S5({tool:e}){return t.jsxs("li",{className:"wb-prof-row","data-gated":e.gated?"true":void 0,"data-testid":"agent-profile-tool",children:[t.jsxs("span",{className:"wb-prof-row-main",children:[t.jsx("span",{className:"wb-prof-row-name mono",children:$5(e.name)}),t.jsx("span",{className:"wb-prof-row-desc","data-clamp":"true",title:e.description,children:e.description})]}),e.gated?t.jsxs("span",{className:"wb-prof-gate",title:"The call is recorded and waits; nothing happens until you approve it.",children:[t.jsx($T,{}),"Needs your approval"]}):t.jsx("span",{className:"wb-prof-auto",title:E5(e.tier),children:C5(e.tier)})]})}function C5(e){return e==="auto"?"Runs on its own":e==="gated"?"Needs your approval":"Not runnable here"}function E5(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 $5(e){const n=e.split(".");return(n[n.length-1]??e).replace(/_/g," ")}function A5(e){return e==="mirror"?"Mirrors whichever language you write in":e==="en"?"Always English":e==="fr"?"Always French":e}function Yo({title:e,note:n,tone:s,children:r}){return t.jsxs("section",{className:"wb-prof-section",children:[t.jsx("h3",{className:"wb-prof-title",children:e}),n?t.jsx("p",{className:"wb-prof-note-lead","data-tone":s,children:n}):null,r]})}function qo({label:e,children:n}){return t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"wb-prof-k",children:e}),t.jsx("dd",{className:"wb-prof-v",children:n})]})}function Rp({children:e,title:n}){return t.jsx("span",{className:"wb-prof-tag",title:n,children:e})}function $T(){return t.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:[t.jsx("rect",{x:"2.8",y:"6",width:"8.4",height:"6.2",rx:"1.4"}),t.jsx("path",{d:"M4.8 6V4.4a2.2 2.2 0 0 1 4.4 0V6"})]})}const oN=16e3,T5=10*6e4,R5="The microphone is blocked for this page: allow it in the browser’s site settings to talk.",AT="This browser cannot record here: talking needs a microphone and a secure page (https or localhost).";function I5(){const e=window;return e.AudioContext??e.webkitAudioContext}function P5(e){const n=e&&typeof e=="object"&&"name"in e?String(e.name):"";return n==="NotAllowedError"||n==="SecurityError"||n==="PermissionDeniedError"?R5:n==="NotFoundError"||n==="DevicesNotFoundError"?"No microphone was found on this computer.":n==="NotReadableError"?"The microphone is in use by another app.":AT}async function M5(e){var c;const n=I5();if(!((c=navigator.mediaDevices)!=null&&c.getUserMedia)||!n)throw Object.assign(new Error(AT),{name:"Unsupported"});const s=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),r=new n,a=r.createMediaStreamSource(s),i=r.createScriptProcessor(4096,1,1),l=[];i.onaudioprocess=u=>{const h=u.inputBuffer.getChannelData(0);l.push(new Float32Array(h));let f=0;for(let m=0;m<h.length;m++)f+=h[m]*h[m];e(Math.min(1,Math.sqrt(f/h.length)*6))},a.connect(i),i.connect(r.destination),r.state==="suspended"&&await r.resume().catch(()=>{});const o=()=>{i.onaudioprocess=null;try{a.disconnect(),i.disconnect()}catch{}s.getTracks().forEach(u=>u.stop()),r.close().catch(()=>{})};return{async stop(){const u=r.sampleRate;return o(),L5(D5(O5(l),u,oN),oN)},cancel:o}}function O5(e){const n=new Float32Array(e.reduce((r,a)=>r+a.length,0));let s=0;for(const r of e)n.set(r,s),s+=r.length;return n}function D5(e,n,s){if(n<=s)return e;const r=n/s,a=new Float32Array(Math.floor(e.length/r));for(let i=0;i<a.length;i++){const l=Math.floor(i*r),o=Math.min(e.length,Math.floor((i+1)*r));let c=0;for(let u=l;u<o;u++)c+=e[u];a[i]=o>l?c/(o-l):0}return a}function L5(e,n){const s=new ArrayBuffer(44+e.length*2),r=new DataView(s),a=(i,l)=>{for(let o=0;o<l.length;o++)r.setUint8(i+o,l.charCodeAt(o))};a(0,"RIFF"),r.setUint32(4,36+e.length*2,!0),a(8,"WAVEfmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,n,!0),r.setUint32(28,n*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),a(36,"data"),r.setUint32(40,e.length*2,!0);for(let i=0;i<e.length;i++){const l=Math.max(-1,Math.min(1,e[i]));r.setInt16(44+i*2,Math.round(l<0?l*32768:l*32767),!0)}return new Blob([s],{type:"audio/wav"})}const sv="buddi.readAloud";function TT(){try{return window.localStorage.getItem(sv)==="on"}catch{return!1}}function RT(e){try{e?window.localStorage.setItem(sv,"on"):window.localStorage.removeItem(sv)}catch{}}let Cr=null,vc=null,au=0,rv=null;const av=new Set;function Gh(e){rv!==e&&(rv=e,av.forEach(n=>n()))}function F5(){return rv}function _5(e){return av.add(e),()=>av.delete(e)}function IT(e){return Ao(),Gh(e),au}function cN(e){return e===au}function Ao(){au++,Cr&&(Cr.pause(),Cr.removeAttribute("src")),vc&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(vc),vc=null,Gh(null)}async function z5(e,n,s=null){var a;const r=IT(s);try{const i=await fetch(e,{credentials:"same-origin"});if(!i.ok)throw new Error(`The spoken reply could not be fetched (${i.status}).`);const l=new Blob([await i.arrayBuffer()],{type:n});if(r!==au)return;Cr||(Cr=new Audio,(a=Cr.addEventListener)==null||a.call(Cr,"ended",()=>Gh(null))),vc=URL.createObjectURL(l),Cr.src=vc,await Cr.play()}catch(i){throw r===au&&Gh(null),i}}const U5=new Set(["audio/ogg","audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/webm"]);function ry(e){return U5.has(e.toLowerCase().split(";")[0].trim())}function jc(e){if(e===null||!Number.isFinite(e)||e<0)return"–:––";const n=Math.floor(e);return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function PT(e,n){const s=d.useRef(null),r=d.useRef(null),[a,i]=d.useState(!1),[l,o]=d.useState(!1),[c,u]=d.useState(!1),[h,f]=d.useState(0),[m,p]=d.useState(null);return d.useEffect(()=>()=>{var k;(k=s.current)==null||k.pause(),r.current&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(r.current)},[]),{playing:a,loading:l,failed:c,position:h,duration:m,toggle:async()=>{const k=s.current;if(k){if(a){k.pause();return}Ao(),u(!1);try{if(!r.current){o(!0);const j=await fetch(ni(e),{credentials:"same-origin"});if(!j.ok)throw new Error(String(j.status));r.current=URL.createObjectURL(new Blob([await j.arrayBuffer()],{type:n})),k.src=r.current}await k.play()}catch{u(!0)}finally{o(!1)}}},bind:{ref:s,preload:"none",onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>{i(!1),f(0)},onTimeUpdate:k=>f(k.currentTarget.currentTime),onLoadedMetadata:k=>p(Number.isFinite(k.currentTarget.duration)?k.currentTarget.duration:null),onDurationChange:k=>p(Number.isFinite(k.currentTarget.duration)?k.currentTarget.duration:null)}}}function fm({artifactId:e,name:n,mime:s,sizeBytes:r}){const{playing:a,loading:i,failed:l,position:o,duration:c,toggle:u,bind:h}=PT(e,s),f=l?"Could not play. Download it instead.":`${jc(o)} / ${jc(c)}`;return t.jsxs("span",{className:"wb-audio","data-testid":"audio-card","data-playing":a?"true":void 0,children:[t.jsx("button",{type:"button",className:"ui-icon-btn wb-audio-play","data-size":"sm","aria-label":a?`Pause ${n}`:`Play ${n}`,disabled:i,onClick:()=>void u(),children:t.jsx(oe,{name:a?"pause":"play",size:14})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:n,children:n}),t.jsxs("span",{className:"wb-file-meta","data-testid":"audio-time",children:[i?"Loading…":f,!l&&ps(r)?` · ${ps(r)}`:""]})]}),t.jsx("a",{className:"ui-icon-btn wb-audio-download","data-size":"sm",href:ni(e),download:n,"aria-label":`Download ${n}`,title:"Download",children:t.jsx(oe,{name:"download",size:14})}),t.jsx("audio",{...h})]})}const Ip=1e5,Pp=200,Mp=30;function MT({artifactId:e,filename:n,mime:s,family:r,available:a=!0}){const[i,l]=d.useState(!1);return a?r==="image"&&!i?t.jsx("figure",{className:"file-preview file-preview-image",children:t.jsx("img",{src:Ur(e),alt:n??"Image",onError:()=>l(!0)})}):r==="audio"&&ry(s)?t.jsx("div",{className:"file-preview file-preview-audio",children:t.jsx(fm,{artifactId:e,name:n??"Audio",mime:s})}):r==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:Ur(e),type:"application/pdf","aria-label":n??"PDF",children:t.jsx(G,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):r==="text"||r==="code"||r==="table"?t.jsx(B5,{artifactId:e,filename:n,mime:s,family:r}):t.jsx(G,{children:"Preview not supported for this kind of file. Download it to open it."}):t.jsx(G,{children:"The file is no longer available; its record is kept."})}function B5({artifactId:e,filename:n,mime:s,family:r}){const[a,i]=d.useState("loading");if(d.useEffect(()=>{let o=!1;return i("loading"),fetch(Ur(e),{credentials:"same-origin"}).then(async c=>{if(!c.ok)throw new Error(String(c.status));const u=await c.text();o||i({text:u.slice(0,Ip),truncated:c.headers.get("X-Preview-Truncated")==="1"||u.length>Ip})}).catch(()=>{o||i("failed")}),()=>{o=!0}},[e]),a==="loading")return t.jsx("div",{className:"file-preview",children:t.jsx(Ne,{children:"Loading preview…"})});if(a==="failed")return t.jsx(G,{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(n??""));return t.jsxs("div",{className:"file-preview",children:[l?t.jsx(H5,{text:a.text,delimiter:/tab|\.tsv$/i.test(s+(n??""))?" ":","}):t.jsx("pre",{className:"file-preview-text",children:a.text}),a.truncated?t.jsxs("p",{className:"muted",children:["Showing the first ",Ip.toLocaleString()," characters. The download has the whole file."]}):null]})}function W5(e,n,s,r){const a=[];let i=[],l="",o=!1,c=!1,u=!1;const h=()=>{i.length<r?i.push(l):c=!0,l=""},f=()=>{h(),a.push(i),i=[]};let m=0;for(;m<e.length;m+=1){if(a.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===n){h();continue}if(p!=="\r"){if(p===`
|
|
104
|
-
`){f();continue}l+=p}}return a.length<s&&(l!==""||i.length>0)&&f(),{rows:a,truncatedRows:u,truncatedCols:c}}function H5({text:e,delimiter:n}){const s=d.useMemo(()=>W5(e,n,Pp+1,Mp),[e,n]),[r,...a]=s.rows;if(!r)return t.jsx("p",{className:"muted",children:"The file is empty."});const i=Math.min(Mp,s.rows.reduce((o,c)=>Math.max(o,c.length),0)),l=Array.from({length:i},(o,c)=>c);return t.jsxs("div",{className:"ui-table-wrap file-preview-table",children:[t.jsxs("table",{className:"ui-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:l.map(o=>t.jsx("th",{children:r[o]??""},o))})}),t.jsx("tbody",{children:a.slice(0,Pp).map((o,c)=>t.jsx("tr",{children:l.map(u=>t.jsx("td",{children:o[u]??""},u))},c))})]}),s.truncatedRows||s.truncatedCols?t.jsxs("p",{className:"muted",children:["Showing the first ",Pp," rows",s.truncatedCols?` and ${Mp} columns`:"",". The download has the whole file."]}):null]})}function K5(e,n){const s=e.toLowerCase().split(";")[0].trim(),r=(n??"").toLowerCase().split(".").pop()??"";return s==="text/markdown"||s==="text/x-markdown"||s==="text/plain"&&(r==="md"||r==="markdown")?[{format:"pdf",label:"PDF",hint:".pdf"},{format:"docx",label:"Word",hint:".docx"},{format:"md",label:"Markdown",hint:".md, as written",asWritten:!0}]:s==="text/csv"||s==="text/plain"&&r==="csv"?[{format:"xlsx",label:"Excel",hint:".xlsx"},{format:"csv",label:"CSV",hint:".csv, as written",asWritten:!0}]:[]}function V5(e,n){return`/api/artifacts/${encodeURIComponent(e)}/export/${n}`}function G5(e,n){return`${(e??"document").replace(/\.[a-z0-9]{1,8}$/i,"")||"document"}.${n}`}function uN(e,n){const s=document.createElement("a");s.href=e,s.download=n,s.rel="noopener",document.body.appendChild(s),s.click(),s.remove()}function OT({artifactId:e,filename:n,mime:s,accent:r=!0}){const a=n??"download",i=K5(s,n),l=r?"accent":void 0;if(i.length===0)return t.jsx("a",{className:"ui-btn","data-variant":l,href:ni(e),download:a,children:"Download"});const o=i.filter(h=>!h.asWritten),c=i.filter(h=>h.asWritten),u=h=>({label:h.label,hint:h.hint,onSelect:()=>h.asWritten?uN(ni(e),a):uN(V5(e,h.format),G5(n,h.format))});return t.jsx(ss,{label:`Download ${a}`,note:"Download as",items:[...o.map(u),"separator",...c.map(u)],trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-variant":l,"aria-label":`Download ${a}`,children:["Download ",t.jsx(oe,{name:"chevron-down"})]})})}function Y5({attachment:e}){const n=Zw(e.mime,e.filename);return t.jsxs("div",{className:"wb-artifact","data-family":n,"data-testid":"artifact-view",children:[t.jsx(MT,{artifactId:e.artifactId,filename:e.filename??null,mime:e.mime,family:n}),t.jsxs("dl",{className:"ui-kv",children:[t.jsx("dt",{children:"Type"}),t.jsxs("dd",{children:[Mi[n],t.jsx("span",{className:"wb-artifact-mime mono",children:e.mime})]}),e.sizeBytes?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Size"}),t.jsx("dd",{children:ps(e.sizeBytes)})]}):null,t.jsx("dt",{children:"Id"}),t.jsx("dd",{className:"mono",children:e.artifactId})]}),t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx(OT,{artifactId:e.artifactId,filename:e.filename,mime:e.mime})})]})}const dN=80,q5=["query","path","url","dir"],Q5=["message","task"];function ay(e,n){const s=J5(n);if(!s)return null;const r=ml(s.command);if(r!==null){const l=ml(s.name);return jd(l===null?r:`${l}: ${r}`)}for(const l of q5){const o=ml(s[l]);if(o!==null)return jd(o)}const a=ml(s.action);if(a!==null){const l=Q5.map(o=>ml(s[o])).find(o=>o!==null)??null;return jd(l===null?a:`${a} · ${l}`)}const i=Object.values(s).filter(l=>typeof l=="string");return i.length===1?jd(ml(i[0])):null}function ml(e){if(typeof e!="string")return null;const n=e.replace(/\s+/g," ").trim();return n===""?null:n}function jd(e){return e===null?null:e.length>dN?`${e.slice(0,dN-1)}…`:e}function J5(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const DT="owner.notify",na=e=>typeof e=="string"&&e.trim()!==""?e:null;function X5(e){const n=e!==null&&typeof e=="object"?e:{};return{title:na(n.title)??"(no title)",text:na(n.text),urgency:na(n.urgency)??"now",key:na(n.key),link:na(n.link)}}function LT(e){if(e===null||typeof e!="object")return na(e);const n=e;return na(n.delivered)??na(n.message)??na(n.error)}function Z5(e,n){if(!n||!e)return"critical";const s=e.toLowerCase();return/^(refused|not sent)/.test(s)?"critical":/^sent\b/.test(s)?"good":"warning"}const e8=/^[a-z0-9](?:[a-z0-9._-]{0,94}[a-z0-9])?$/,t8=/^[a-z][a-z0-9_-]{0,63}$/;function Iu(e,n,s=64){return!t8.test(e)||typeof n!="string"||!e8.test(n)||n.includes("..")?null:`/api/plugin-assets/${e}/${n}?size=${s}`}function FT(e){return typeof e=="string"&&/^\/api\/plugin-assets\/[a-z][a-z0-9_-]{0,63}\/[a-z0-9._-]+(\?size=(64|128))?$/.test(e)}function n8(e){var n,s;return((s=(n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])==null?void 0:s.toUpperCase())??"?"}function To({src:e,label:n,className:s}){const[r,a]=d.useState(!1),i=e!==null&&FT(e)&&!r;return t.jsx("span",{className:["pl-logo",s].filter(Boolean).join(" "),"data-letter":i?void 0:"true","aria-hidden":"true",children:i?t.jsx("img",{src:e,alt:"",loading:"lazy",decoding:"async",onError:()=>a(!0)}):n8(n)})}const Xd="news",s8="edition";function _T(e){if(!e)return null;const n=/^#\/p\/news\/stories\?(.*)$/.exec(e);if(!n)return null;const s=new URLSearchParams(n[1]).get("edition");return s&&/^[A-Za-z0-9_-]{1,40}$/.test(s)?s:null}const Bt=e=>typeof e=="string"?e:"",r8=e=>/^https?:\/\/[^\s]+$/i.test(e),hN=/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/,Yh=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null;function fN(e){const n=Yh(e);if(!n)return null;const s={};for(const[r,a]of Object.entries(n)){const i=Yh(a);if(!i||!("const"in i))return null;s[r]=i.const}return s}function a8(e){return(Array.isArray(e)?e:[]).flatMap(n=>{const s=Yh(n);if(!s)return[];const r=Bt(s.label).trim(),a=Bt(s.tool),i=fN(s.args??{});if(r===""||!hN.test(a)||!i)return[];const l=Yh(s.undo),o=l?fN(l.args??{}):null,c=l&&hN.test(Bt(l.tool))&&o?{tool:Bt(l.tool),label:Bt(l.label).trim()||"Undo",args:o}:null,u=Bt(s.hint).trim(),h=Bt(s.group).trim(),f=Bt(s.confirm).trim();return[{label:r,tool:a,args:i,...u?{hint:u}:{},...h?{group:h}:{},...f?{confirm:f}:{},done:Bt(s.done).trim()||"Done.",...c?{undo:c}:{}}]}).slice(0,12)}function i8(e){const n=e!==null&&typeof e=="object"?e.edition:null;if(n===null||typeof n!="object")return null;const s=n,r=(Array.isArray(s.groups)?s.groups:[]).flatMap(i=>{if(i===null||typeof i!="object")return[];const l=(Array.isArray(i.stories)?i.stories:[]).flatMap(o=>{if(o===null||typeof o!="object")return[];const c=o,u=Bt(c.title).trim();if(u==="")return[];const h=c.link!==null&&typeof c.link=="object"?c.link:null,f=h?Bt(h.url):"",m=c.mark==="update"||c.mark==="opinion"?c.mark:void 0,p=Bt(c.topicName).trim(),g=a8(c.actions);return[{...m?{mark:m,markLabel:Bt(c.markLabel)||void 0}:{},title:u,lead:Bt(c.lead),outlet:Bt(c.outlet),more:typeof c.more=="number"&&Number.isFinite(c.more)&&c.more>0?Math.floor(c.more):0,...r8(f)?{link:{url:f,label:Bt(h.label)||f}}:{},logos:(Array.isArray(c.logos)?c.logos:[]).flatMap(x=>{if(x===null||typeof x!="object")return[];const k=Bt(x.name),j=Bt(x.logo);return k?[{name:k,...j?{logo:j}:{}}]:[]}),...p?{topicName:p}:{},...g.length>0?{actions:g}:{}}]});return l.length>0?[{topic:Bt(i.topic),stories:l}]:[]});if(r.length===0)return null;const a=Bt(s.next);return{id:Bt(s.id),name:Bt(s.name)||"Edition",when:Bt(s.when),lede:Bt(s.lede),groups:r,notes:(Array.isArray(s.notes)?s.notes:[]).filter(i=>typeof i=="string"&&i.trim()!==""),.../^\d{1,2}:\d{2}$/.test(a)?{next:a}:{}}}function l8(e,n){const s=[];let r=null;return e.forEach((a,i)=>{const l=a.group??a.tool;i>0&&l!==r&&s.push("separator"),a.group&&l!==r&&s.push({heading:a.group}),r=l,s.push({label:a.label,...a.hint?{hint:a.hint}:{},onSelect:()=>n(a)})}),s}function o8({s:e}){const[n,s]=d.useState(null),r=e.logos[0]??{name:e.outlet||e.title},a=e.outlet||r.name,[i,l]=d.useState(null),o=e.actions??[],c=async f=>{try{const m=await A.pageAct(Xd,{tool:f.tool,args:f.args});s(m.approvalId?{text:"Waiting for your approval."}:{text:f.done,...f.undo?{undo:f.undo}:{}})}catch(m){s({text:m instanceof Error&&m.message?`That did not work: ${m.message}`:"That did not work."})}},u=async f=>{try{await A.pageAct(Xd,{tool:f.tool,args:f.args}),s(null)}catch{s({text:"Could not take it back. Undo it in News → Sources."})}};if(n)return t.jsxs("li",{className:"ed-story ed-story-gone",role:"status",children:[t.jsx("span",{children:n.text}),n.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>void u(n.undo),children:n.undo.label})]}):null]});const h=[e.topicName,a?e.more>0?`${a} and ${e.more} more`:a:""].filter(Boolean).join(" · ");return t.jsxs("li",{className:"ed-story",children:[o.length>0?t.jsx("span",{className:"ed-more-btn",children:t.jsx(ss,{label:`Ways out for ${e.title}`,items:l8(o,f=>f.confirm?l(f):void c(f)),sheet:{title:e.title,sub:h},stacked:!0})}):null,i?t.jsx(Ut,{title:i.confirm??i.label,onClose:()=>l(null),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>l(null),children:"Cancel"}),t.jsx($,{variant:"accent",onClick:()=>{const f=i;l(null),c(f)},children:i.label})]})}):null,t.jsx(To,{src:r.logo?Iu(Xd,r.logo):null,label:r.name,className:"pl-logo-md"}),t.jsxs("span",{className:"ed-story-text",children:[t.jsxs("span",{className:"ed-story-title",children:[e.mark?t.jsx("span",{className:"ed-mark","data-kind":e.mark==="update"?"update":void 0,children:e.mark==="update"?"Update":"Opinion"}):null,e.title]}),e.lead?t.jsx("span",{className:"ed-story-line",children:e.lead}):null,a?t.jsxs("span",{className:"ed-story-src",children:[e.link?t.jsxs("a",{className:"wb-src-link",href:e.link.url,target:"_blank",rel:"noopener noreferrer",title:e.link.label,children:[a,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:a}),e.more>0?t.jsxs("span",{className:"ed-more",children:["and ",e.more," more"]}):null]}):null]})]})}const mN=Array.from({length:64},(e,n)=>30+Math.round(Math.abs(Math.sin(n*1.7)*Math.cos(n*.4))*70));function c8({audio:e}){const{playing:n,loading:s,failed:r,position:a,duration:i,toggle:l,bind:o}=PT(e.fileId,e.mime),c=i?Math.min(1,a/i):0,u=r?"Could not play":s?"Loading…":i===null?"Listen":n||a>0?`${jc(a)} / ${jc(i)}`:jc(i);return t.jsxs("button",{type:"button",className:"ed-audio","aria-label":n?"Pause the edition":"Listen to the edition","aria-pressed":n,disabled:s,onClick:()=>void l(),"data-testid":"edition-audio",children:[t.jsx("span",{className:"ed-play","aria-hidden":"true",children:n?t.jsxs("svg",{viewBox:"0 0 16 16",width:"12",height:"12",fill:"currentColor",children:[t.jsx("rect",{x:"4",y:"3",width:"3",height:"10",rx:"1"}),t.jsx("rect",{x:"9",y:"3",width:"3",height:"10",rx:"1"})]}):t.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",fill:"currentColor",children:t.jsx("path",{d:"M5 3.2v9.6c0 .5.5.8.9.5l7.2-4.8a.6.6 0 0 0 0-1L5.9 2.7c-.4-.3-.9 0-.9.5Z"})})}),t.jsx("span",{className:"ed-wave","aria-hidden":"true",children:mN.map((h,f)=>t.jsx("i",{style:{"--h":`${h}%`},"data-on":(n||a>0)&&f<Math.round(c*mN.length)?"true":void 0},f))}),t.jsx("span",{className:"ed-dur",children:u}),t.jsx("audio",{...o})]})}function u8({edition:e,audio:n}){const s=[...e.notes,`${e.next?`Next edition at ${e.next}. `:""}Tell me what to leave out, or mute anything from News.`];return t.jsxs("div",{className:"ed","data-testid":"edition-card",children:[t.jsxs("div",{className:"ed-head",children:[t.jsx("span",{className:"ed-kicker",children:e.name}),e.when?t.jsx("span",{className:"ed-when",children:e.when}):null]}),n,e.lede?t.jsx("p",{className:"ed-lede",children:e.lede}):null,e.groups.map((r,a)=>t.jsxs("section",{className:"ed-group",children:[r.topic?t.jsx("h4",{className:"ed-topic",children:r.topic}):null,t.jsx("ul",{className:"ed-list",children:r.stories.map((i,l)=>t.jsx(o8,{s:i},l))})]},a)),t.jsx("p",{className:"ed-foot",children:s.join(" ")})]})}function d8({editionId:e,text:n,audio:s,link:r}){const[a,i]=d.useState(void 0),[l,o]=d.useState(!1);d.useEffect(()=>{let u=!0;return i(void 0),A.pageQuery(Xd,s8,{id:e}).then(h=>{u&&i(i8(h.data))}).catch(()=>{u&&i(null)}),()=>{u=!1}},[e]);const c=a&&!l;return t.jsxs("div",{className:"wb-report ed-report","data-testid":"mission-report",children:[c?t.jsx("div",{className:"ed-bubble",children:t.jsx(u8,{edition:a,audio:s?t.jsx(c8,{audio:s}):null})}):a===void 0?t.jsx("div",{className:"ed-bubble","aria-busy":"true",children:t.jsx("div",{className:"ed ed-loading"})}):t.jsxs(t.Fragment,{children:[s?t.jsx(fm,{artifactId:s.fileId,name:s.filename??"Voice note",mime:s.mime,sizeBytes:s.sizeBytes}):null,n]}),t.jsxs("div",{className:"ed-actions",children:[a?t.jsx($,{size:"sm",variant:"ghost","aria-pressed":l,onClick:()=>o(!l),children:l?"Show as card":"Show as text"}):null,t.jsx(lt,{className:"wb-report-link",size:"sm",href:r.route,children:r.label})]})]})}const h8="mission.report",pl=e=>typeof e=="string"&&e.trim()!==""?e.trim():null,f8=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function m8(e,n){const s=e!==null&&typeof e=="object"?e:{},r=n!==null&&typeof n=="object"?n:{},a=pl(r.link),i=r.audio!==null&&typeof r.audio=="object"?r.audio:null,l=i?pl(i.fileId):null,o=i?pl(i.mime):null;return{text:pl(s.text),link:a&&a.startsWith("#/")?{route:a,label:pl(r.linkLabel)??"Open"}:null,audio:l&&f8.test(l)&&o&&ry(o)?{fileId:l,mime:o,filename:i?pl(i.filename):null,sizeBytes:i&&typeof i.sizeBytes=="number"?i.sizeBytes:null}:null}}function p8(e){return!!(e.text&&e.link&&_T(e.link.route))}function pN({view:e}){var a;if(!e.text&&!e.audio)return null;const n=e.audio?t.jsx(fm,{artifactId:e.audio.fileId,name:e.audio.filename??"Voice note",mime:e.audio.mime,sizeBytes:e.audio.sizeBytes}):null,s=e.text?t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(pr,{text:e.text})}):null,r=_T((a=e.link)==null?void 0:a.route);return r&&e.link&&e.text?t.jsx(d8,{editionId:r,text:s,audio:e.audio,link:e.link}):t.jsxs("div",{className:"wb-report","data-testid":"mission-report",children:[n,s,e.link?t.jsx("a",{className:"ui-btn wb-report-link","data-size":"sm",href:e.link.route,children:e.link.label}):null]})}const si="agent.delegate";function g8(e){if(e===null||typeof e!="object")return null;const n=e,s=n.conversationId;if(typeof s!="string"||s==="")return null;const r=n.agentId??n.agent;return{conversationId:s,agentId:typeof r=="string"?r:"",runId:typeof n.runId=="string"?n.runId:null}}function x8(e){if(typeof e=="string")return e;if(e===null||typeof e!="object")return null;const n=e.text;return typeof n=="string"?n:null}const iv="canvas.show",gN="canvas.clear",xN=12;function v8(e){return`sources:${e}`}function j8(e){return e.role==="user"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function Hl(e){return`${e.plugin}/${e.name}`}function w8(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const n=e.diff;return typeof n=="string"&&n.trim()!==""}function y8({messages:e,descriptors:n}){const s=new Map(n.filter(i=>i.renderer==="preview").map(i=>[i.tool,i]));if(s.size===0)return[];const r=new Map,a=[];for(const i of e)for(const l of i.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=aT(o,lv(l.output)).props;c.target===null&&c.awaiting!==null&&a.push({...c.awaiting,at:i.at??null})}return a}function zT({messages:e,descriptors:n,awaiting:s,folded:r,served:a,gathered:i}){var m;const l=new Map(n.map(p=>[p.tool,p])),o=new Map;let c=[],u=0,h=null;const f=p=>{h||(h={id:v8(p.id),tool:p.tool,title:"Sources",renderer:"sources",source:"sources",props:{entries:[]},at:p.at,substantial:!1,count:0},c.push(h));const g=h.props,x=g.entries.some(j=>j.id===p.id)?g.entries.map(j=>j.id===p.id?{...p,input:p.input??j.input}:j):[...g.entries,p],k=[...new Set(x.map(j=>j.tool))];h.props={entries:x},h.tool=k.join(" · "),h.count=x.length,h.substantial=x.some(j=>j.ok===!0),h.tone=x.every(j=>j.ok===!1)?"critical":void 0};for(const p of e){j8(p)&&(h=null);for(const g of p.blocks??[]){if(g.type==="tool_use"){if(o.set(g.id,{name:g.name,input:g.input,at:p.at??null}),i!=null&&i.has(g.name)){f({id:g.id,tool:g.name,input:g.input,output:null,ok:null,at:p.at??null});continue}if(g.name===iv){const S=k8(g.id,g.input,p.at??null);S&&c.push(S)}if(g.name===gN&&(c=[],h=null),g.name===si){const S=g8(g.input);S&&c.push({id:g.id,tool:si,title:"Delegation",renderer:"delegate",props:{...S,result:null},at:p.at??null,source:"delegate",substantial:!0})}continue}if(g.type!=="tool_result"||g.name===iv||g.name===gN)continue;const x=o.get(g.toolUseId),k=p.at??(x==null?void 0:x.at)??null,j=g.name||(x==null?void 0:x.name)||"tool",v=c.find(S=>S.source==="delegate"&&S.id===g.toolUseId);if(v&&((m=g.delegation)==null?void 0:m.state)==="waiting"){v.props={...v.props,result:null,waiting:{approvalId:g.delegation.approvalId}},g.delegation.approvalId&&(v.tone="warning");continue}if(v){v.props={...v.props,result:{ok:g.ok,text:x8(g.ok?g.output:g.error??g.output),...g.ok&&Uh(g.output).length>0?{files:Uh(g.output)}:{}}},g.ok||(v.tone="critical");continue}const w=g.approval?cv(g):(s==null?void 0:s.get(g.toolUseId))??cv(g);if(w){c.push({id:g.toolUseId,tool:j,title:"Approval",renderer:"envelope",props:{approvalId:w},at:k,tone:"warning",source:"approval",substantial:!0});continue}if(r!=null&&r.has(j))continue;if(i!=null&&i.has(j)){f({id:g.toolUseId,tool:j,input:(x==null?void 0:x.input)??null,output:lv(g.output)??null,ok:g.ok!==!1,...g.error===void 0?{}:{error:g.error},at:k});continue}if(j===DT){c.push({id:g.toolUseId,tool:j,title:"Message to you",renderer:"notify",props:{input:(x==null?void 0:x.input)??null,output:g.output??null,ok:g.ok!==!1},at:k,tone:g.ok===!1?"critical":void 0,source:"notify",substantial:!1});continue}const y=lv(g.output);if(g.ok===!1){c.push({id:g.toolUseId,tool:j,title:Pr(j),renderer:"structured",props:{value:g.error??y??null,failed:!0},at:k,tone:"critical",source:"fallback",substantial:!1});continue}w8(y)&&(u+=1);const N=l.get(j);if(N){const S=aT(N,y),{renderer:C}=S;let{props:T}=S;if(C==="preview"){const E=T,R=E.target??(E.awaiting&&(a!=null&&a.has(Hl(E.awaiting)))?E.awaiting:null);if(R===null)continue;T={...E,target:R,awaiting:null};const M=Hl(R);c=c.filter(O=>!(O.source==="descriptor"&&O.renderer==="preview"&&O.props.target!==null&&Hl(O.props.target)===M))}c.push({id:g.toolUseId,tool:j,title:N.title??Pr(j),renderer:C,props:T,at:k,source:"descriptor",substantial:ov(C,T)});continue}const b={value:ty(y)?{input:x==null?void 0:x.input,output:y}:y};N8("structured",b)&&c.push({id:g.toolUseId,tool:j,title:Pr(j),renderer:"structured",props:b,at:k,source:"fallback",substantial:ov("structured",b)})}}for(const p of c)p.source==="descriptor"&&p.renderer==="preview"&&(p.props={...p.props,changes:u});return b8(c)}const vN="forAgent";function lv(e){if(e===null||typeof e!="object"||Array.isArray(e)||!(vN in e))return e;const{[vN]:n,...s}=e;return s}function b8(e){if(e.length<=xN)return e;const n=e.length-xN;return[...e.slice(0,n).filter(r=>r.source==="approval"),...e.slice(n)]}function k8(e,n,s){if(n===null||typeof n!="object")return null;const{renderer:r,title:a,data:i}=n,l=typeof r=="string"&&Vh(r)?r:"structured";return{id:e,tool:iv,title:typeof a=="string"&&a.trim()!==""?a:"Shown",renderer:l,props:l==="structured"&&!Vh(String(r))?{value:i}:i,at:s,substantial:!0,source:"canvas"}}function N8(e,n){const s=n??{};return!!(s.failed===!0||ov(e,n)||ey(s.value).kind==="error")}function ov(e,n){const s=n??{};switch(e){case"timeseries":return Qo(s.points)>0;case"bars":return Qo(s.bars)>0;case"keyvalue":return Qo(s.pairs)>0;case"tiles":return s.notice!==!0&&Qo(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(a=>Qo(a.rows)>0);default:return ty(s.value)?!0:s.failed===!0?!1:GB(s.value)}}function Qo(e){return Array.isArray(e)?e.length:0}function cv(e){if(e.approval)return e.approval.state==="pending"?e.approval.id:null;for(const n of[e.error,e.output]){const s=BT(n,0);if(s)return s}return null}function S8(e,n,s={}){var o,c;const r=e.flatMap(u=>u.blocks),a=r.find(u=>u.type==="tool_use"&&u.id===n);if((a==null?void 0:a.type)!=="tool_use")return null;const i=r.find(u=>u.type==="tool_result"&&u.toolUseId===n),l=(o=s.redactInputOf)!=null&&o.has(a.name)?UT(a.input):a.input;return{id:n,tool:a.name,title:Pr(a.name),renderer:"structured",props:{value:{input:l,...(i==null?void 0:i.type)==="tool_result"?{status:((c=i.approval)==null?void 0:c.state)??(i.ok?"completed":"failed"),output:i.output,...i.error?{error:i.error}:{}}:{status:"Awaiting result"}}},at:null,source:"fallback",substantial:!1}}const C8=new Set(["value","text","password","secret","code"]);function UT(e){if(e===null||typeof e!="object"||Array.isArray(e))return e;const n={};for(const[s,r]of Object.entries(e))n[s]=C8.has(s)&&typeof r=="string"?"— withheld —":UT(r);return n}function BT(e,n){if(n>3||e===null||typeof e!="object")return null;const s=e,r=s.reason,a=s.actionId??s.approvalId;if(typeof a=="string"&&a!==""&&(r===void 0||r==="approval-required"))return a;for(const i of Object.values(s)){const l=BT(i,n+1);if(l)return l}return null}function Pr(e){const n=e.split(".");return n.length===1?Bn(e):n.map(s=>Bn(s)).join(" · ")}function jN(e,n){return e.find(s=>s.source==="sources"&&s.props.entries.some(r=>r.id===n))??null}function mm({name:e,mime:n,sizeBytes:s,thumbnail:r,state:a,error:i,onOpen:l,onRemove:o,size:c="md",detail:u}){const h=Zw(n,e),f=u??[Mi[h],ps(s)].filter(Boolean).join(" · "),m=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-file-visual","data-family":h,children:r?t.jsx("img",{src:r,alt:""}):t.jsx(iy,{family:h})}),t.jsxs("span",{className:"wb-file-text",children:[t.jsx("span",{className:"wb-file-name",title:e,children:e}),t.jsx("span",{className:"wb-file-meta",children:a==="uploading"?"Uploading…":a==="failed"?"Upload failed":f})]})]});return t.jsxs("span",{className:"wb-file","data-size":c,"data-state":a,"data-thumb":r?"true":void 0,title:a==="failed"?i:void 0,children:[l?t.jsx("button",{type:"button",className:"wb-file-open",onClick:l,"aria-label":`Open ${e}`,children:m}):t.jsx("span",{className:"wb-file-open",children:m}),o?t.jsx("button",{type:"button",className:"wb-file-x","aria-label":`Remove ${e}`,onClick:o,children:t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",children:t.jsx("path",{d:"M2.5 2.5l5 5M7.5 2.5l-5 5"})})}):null]})}function iy({family:e}){const n={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 t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"2"}),t.jsx("circle",{cx:"7.5",cy:"8.5",r:"1.4"}),t.jsx("path",{d:"M17 13l-3.6-3.6a1 1 0 0 0-1.4 0L6 15.5"})]});case"pdf":return t.jsxs("svg",{...n,children:[t.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"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 13.5h5M7.5 11h5"})]});case"table":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"4",width:"14",height:"12",rx:"1.5"}),t.jsx("path",{d:"M3 8.5h14M3 12.5h14M8 4v12M13 4v12"})]});case"text":return t.jsxs("svg",{...n,children:[t.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"}),t.jsx("path",{d:"M11.5 2.5V7H16"}),t.jsx("path",{d:"M7.5 10.5h5M7.5 13.5h3.5"})]});case"code":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M7 6l-4 4 4 4M13 6l4 4-4 4M11.5 4l-3 12"})});case"audio":return t.jsx("svg",{...n,children:t.jsx("path",{d:"M4 8v4M7.5 5.5v9M11 3.5v13M14.5 6.5v7M18 8.5v3"})});case"video":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"3",y:"5",width:"10",height:"10",rx:"1.5"}),t.jsx("path",{d:"M13 9l4-2.5v7L13 11"})]});case"archive":return t.jsxs("svg",{...n,children:[t.jsx("rect",{x:"4",y:"3",width:"12",height:"14",rx:"1.5"}),t.jsx("path",{d:"M10 3v3M10 8v2M10 12v2M8.5 14h3"})]});default:return t.jsxs("svg",{...n,children:[t.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"}),t.jsx("path",{d:"M11.5 2.5V7H16"})]})}}function E8(e,n,s){const r=yN(e),a=yN(n==null?void 0:n.input),i=ji(r==null?void 0:r.name)??I8(ji(r==null?void 0:r.handle))??ji(r==null?void 0:r.agent)??ji(a==null?void 0:a.agent),l=typeof e=="string"?e.trim()||null:ji(r==null?void 0:r.text)??ji(r==null?void 0:r.note),o=wN(r==null?void 0:r.durationMs)??wN(r==null?void 0:r.elapsedMs),c=n!=null&&n.at?Date.parse(n.at):NaN,u=s?Date.parse(s):NaN,h=Number.isFinite(c)&&Number.isFinite(u)&&u>=c?u-c:null;return{who:i,question:ji(a==null?void 0:a.task),answer:l,files:Uh(e),durationMs:o??h}}function $8(e,n){var r;let s=null;for(const a of e)for(const i of a.blocks??[])i.type==="tool_result"&&i.name===si&&((r=i.delegation)==null?void 0:r.approvalId)===n&&(s=i.toolUseId);if(s===null)return null;for(const a of e)for(const i of a.blocks??[])if(i.type==="tool_use"&&i.id===s)return{input:i.input,at:a.at||null};return null}function A8({block:e,messages:n,answeredAt:s}){const r=E8(e.output,$8(n,e.actionId),s),a=[r.who?`Asked ${r.who}`:null,r.durationMs===null?null:`took ${T8(r.durationMs)}`].filter(i=>i!==null);return t.jsxs("div",{className:"wb-delegation-result","data-testid":"delegation-result",children:[a.length>0?t.jsx("p",{className:"wb-delegation-facts",children:a.join(" · ")}):null,r.question?t.jsx("blockquote",{className:"wb-delegation-question",children:r.question}):null,r.answer?t.jsx("div",{className:"wb-delegation-answer","data-testid":"delegation-answer",children:t.jsx(pr,{text:r.answer})}):t.jsx("p",{className:"wb-delegation-facts",children:"No answer came back."}),r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${r.who??"the colleague"} made`,children:r.files.map(i=>t.jsx("a",{role:"listitem",href:ni(i.artifactId),download:!0,children:t.jsx(mm,{name:i.filename??"Untitled file",mime:i.mime,sizeBytes:i.sizeBytes,thumbnail:Xw(i.mime)?Ur(i.artifactId):null,size:"sm"})},i.artifactId))}):null,t.jsx(Zt,{summary:"Raw JSON",children:t.jsx("pre",{className:"wb-approval-output mono",children:R8(e.output)})})]})}function T8(e){if(e<1e3)return`${Math.round(e)}ms`;const n=Math.round(e/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60);return s<60?`${s}m ${String(n%60).padStart(2,"0")}s`:`${Math.floor(s/60)}h ${String(s%60).padStart(2,"0")}m`}function R8(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}function I8(e){return e===null?null:`@${e.replace(/^@/,"")}`}function ji(e){return typeof e=="string"&&e.trim()!==""?e:null}function wN(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function yN(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const P8=1e3;function M8({messageId:e,text:n,onReadAloud:s}){const[r,a]=d.useState(!1),i=d.useRef(null),l=d.useSyncExternalStore(_5,F5)===e;d.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const o=()=>{var c;(c=navigator.clipboard)==null||c.writeText(n).then(()=>{a(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),P8)},()=>{})};return t.jsxs("div",{className:"wb-reply-actions","data-testid":"reply-actions",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":r?"Copied":"Copy",title:r?"Copied":"Copy",onClick:o,children:t.jsx(oe,{name:r?"check":"copy",size:14})}),r?t.jsx("span",{className:"wb-reply-copied",role:"status",children:"Copied"}):null,s?t.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?Ao():s(e,n),children:t.jsx(oe,{name:l?"stop":"play",size:14})}):null]})}function O8(e){const n=D8(e);if(!n)return null;const s=Op(n.diff);if(s!==null)return{kind:"diff",diff:s};const r=Op(n.command),a=Op(n.plain),i=Dp(n.exitCode);return r!==null&&(a!==null||i!==null||Dp(n.pid)!==null)?{kind:"command",command:r,output:a,exitCode:i,elapsedMs:Dp(n.elapsedMs)}:null}function Op(e){return typeof e=="string"&&e.trim()!==""?e:null}function Dp(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function D8(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}const bN="offer:",WT="owner:interjection";function L8(e){return e===WT}function F8(e){if(typeof e!="string"||!e.startsWith(bN))return null;const n=e.slice(bN.length).trim();return n===""?null:n}const kN="brief:";function _8(e){if(typeof e!="string"||!e.startsWith(kN))return null;const n=e.slice(kN.length).trim();return n===""?null:n}function ly({messages:e,live:n,now:s,onOpen:r,working:a=!1,partial:i=null,agents:l,agentId:o,speakers:c,coordinatorId:u,workingAs:h,onOpenFile:f,onReadAloud:m,children:p,agentName:g,emptyHint:x,empty:k,plain:j=!1,workingLine:v,runs:w,onContinue:y}){var Y;const N=d.useRef(null);d.useEffect(()=>{var B;(B=N.current)==null||B.scrollIntoView({block:"end"})},[e.length,n.length,a,i==null?void 0:i.text.length,i==null?void 0:i.thinking.length,!!p]);const b=i&&!i.settled&&(i.text!==""||i.thinking!==""),S=e.filter(B=>(B.blocks??[]).some(J8)).map(HT),C=q8(S,w??[]),T=c??l??[],E=B=>(o&&!c?T.find(q=>q.id===o):void 0)??T.find(q=>q.name===B)??null,R=o?T.find(B=>B.id===o)??null:null,M=a||n.length>0,O=M||!!b,I=!!b&&i.text!=="",z=M&&!I,U=S.at(-1),D=(U==null?void 0:U.role)!=="assistant"||!!h,P=h??g??"Assistant",K=S.filter((B,q)=>{var J;return q===0||(c?(((J=S[q-1])==null?void 0:J.speaker)??null)!==(B.speaker??null):S[q-1].role!==B.role)}),F=O&&!D?((Y=K.at(-1))==null?void 0:Y.id)??null:null,Q=(w??[]).reduce((B,q)=>B===null||(q.startedAt??"")>(B.startedAt??"")?q:B,null),_=(w??[]).some(B=>B.finishedAt===null),re=y&&!O&&!_&&U&&(Q==null?void 0:Q.stopped)==="max_turns"&&C.get(U.id)===Q?U.id:null;return t.jsx(nT.Provider,{value:l??c??[],children:t.jsxs("div",{className:"wb-messages","data-testid":"messages",children:[S.length===0&&n.length===0?k??t.jsx("p",{className:"wb-chat-empty",children:x}):null,S.map((B,q)=>{const J=B.speaker??null,Z=c?J==="owner"||J===null&&B.role==="user":B.role==="user",fe=c&&J==="room",ve=c&&J&&J!=="owner"&&J!=="room"?c.find(me=>me.id===J)??null:null,Oe=S[q-1],W=q===0||(c?((Oe==null?void 0:Oe.speaker)??null)!==J:Oe.role!==B.role);if(fe)return t.jsx("div",{className:"wb-msg wb-msg-room","data-role":"room",children:(B.blocks??[]).filter(me=>me.type==="text").map((me,$e)=>t.jsx("span",{children:me.text},$e))},B.id);const se=(B.blocks??[]).filter(me=>me.type==="approval_result");if(se.length>0)return t.jsx("div",{className:"wb-msg","data-role":"assistant","data-testid":"approval-result",children:se.map((me,$e)=>t.jsx(X8,{block:me,messages:e,at:B.at||null},$e))},B.id);const X=B.role==="user"&&L8(J),je=B.role==="user"?_8(J):null;if(je)return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",children:je})},B.id);const be=B.role==="user"?F8(J):null;if(be){const me=(B.blocks??[]).filter($e=>$e.type==="text").map($e=>$e.text).join(`
|
|
105
|
-
`);return t.jsx("div",{className:"wb-msg","data-role":"user","data-testid":"offer-turn",children:t.jsx("div",{className:"wb-bubble wb-bubble-offer",title:me,children:be})},B.id)}const xe=c&&ve&&B.role==="user"?K8(B):null;if(xe){const me=S.slice(q+1).find(_e=>_e.role==="assistant"&&_e.speaker&&_e.speaker!==ve.id),$e=me!=null&&me.speaker?c.find(_e=>_e.id===me.speaker):void 0;return t.jsxs("details",{className:"wb-msg wb-msg-room wb-msg-ask","data-role":"room",children:[t.jsxs("summary",{children:[ve.name," asked ",($e==null?void 0:$e.name)??"a member",xe.request?`: ${xe.request.length>120?`${xe.request.slice(0,119)}…`:xe.request}`:""]}),xe.request?t.jsx("p",{children:xe.request}):null]},B.id)}const we=C.get(B.id)??null,Ie=Y8(B,e),ke=!Z&&!X&&!j?G8(B):"";return t.jsxs("div",{className:"wb-msg","data-role":Z||X?"user":"assistant",children:[X?t.jsx("div",{className:"wb-msg-added","data-testid":"added-while-working",children:"added while working"}):null,W&&!Z&&!X?t.jsx(NN,{name:ve?ve.name:c&&J&&J!=="owner"&&J!=="room"?J:g??"Assistant",face:ve??R??E(g),moving:z&&F===B.id,children:ve&&u===ve.id?t.jsx("span",{className:"wb-msg-role",children:"coordinator"}):null}):null,Ie.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":"Files sent with this message",children:Ie.map(me=>t.jsx("span",{role:"listitem",children:ry(me.mime)?t.jsx(fm,{artifactId:me.artifactId,name:me.filename??"Untitled file",mime:me.mime,sizeBytes:me.sizeBytes}):t.jsx(mm,{name:me.filename??"Untitled file",mime:me.mime,sizeBytes:me.sizeBytes,thumbnail:Xw(me.mime)?Ur(me.artifactId):null,...f?{onOpen:()=>f(me)}:{}})},me.artifactId))}):null,(B.blocks??[]).map((me,$e)=>{const _e=B8(B.blocks??[],$e,e);if(_e==="inside")return null;if(_e)return t.jsx(W8,{refusals:_e.refusals},$e);if(me.type==="thinking")return j||me.text.trim()===""?null:t.jsx(uv,{text:me.text},$e);if(me.type==="text")return me.text.trim()===""?null:Z?t.jsx("div",{className:"wb-bubble",children:me.text},$e):t.jsx("div",{className:"wb-bubble","data-rich":"true",children:t.jsx(pr,{text:me.text})},$e);if(me.type==="attachment")return null;if(me.type==="tool_use"){if(j)return null;const Le=oy(e,me.id),qe=Le?tW(Le):null,yt=!qe&&me.name===DT&&Le?LT(Le.output):null,le=!qe&&me.name===h8&&(Le!=null&&Le.ok)?m8(me.input,Le.output):null;return le&&p8(le)?t.jsx(pN,{view:le},$e):t.jsxs(d.Fragment,{children:[t.jsx(dv,{label:qe&&!(Le!=null&&Le.delegation)?`Approval · ${me.name}`:Pr(me.name),tool:me.name,ok:(Le==null?void 0:Le.ok)??null,running:Le===null,...qe?{status:qe.status,waiting:qe.waiting,approval:!0}:yt?{status:yt}:{},gist:ay(me.name,me.input),body:Le?O8(Le.output):null,opens:!0,onOpen:()=>r(me.id)},$e),le?t.jsx(pN,{view:le}):null]},$e)}return null}),we?t.jsxs("div",{className:"wb-msg-budget","data-testid":"budget-stop",children:[t.jsx("span",{children:Q8(we)}),re===B.id?t.jsx($,{size:"sm",className:"wb-msg-budget-continue","data-testid":"budget-continue",onClick:y,children:"Continue"}):null]}):null,B.feedback&&!Z&&!X?t.jsx(rW,{feedback:B.feedback}):null,ke!==""?t.jsx(M8,{messageId:B.id,text:ke,onReadAloud:m}):null]},B.id)}),O?t.jsxs("div",{className:"wb-msg","data-role":"assistant","data-testid":"live-turn",children:[D?t.jsx(NN,{name:P,face:E(P)??R,moving:z}):null,b&&i.thinking!==""&&!j?t.jsx(uv,{text:i.thinking,live:i.text==="",seconds:H8(i.thinkingStartedAt,i.textStartedAt??s)}):null,I?t.jsxs("div",{className:"wb-bubble","data-live":"true","data-rich":"true",children:[t.jsx(pr,{text:i.text}),t.jsx("span",{className:"wb-caret","aria-hidden":"true"})]}):null,a&&n.length===0&&!b?t.jsxs("span",{className:"wb-working",role:"status","aria-live":"polite","data-testid":"working",children:[v??`${h??g??"The agent"} is working`,t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):null,n.map(B=>t.jsx(dv,{label:Pr(B.name),tool:B.name,ok:null,running:!0,elapsed:Math.max(0,Math.round((s-B.startedAt)/1e3)),opens:!1,onOpen:()=>r(B.toolUseId)},B.toolUseId))]}):null,p,t.jsx("div",{ref:N})]})})}function NN({name:e,face:n,moving:s=!1,children:r}){const a=(n==null?void 0:n.picture)??null,i=ZA(s?a:null);return t.jsxs("div",{className:"wb-msg-who","data-testid":"turn-head",children:[t.jsx("span",{className:"wb-msg-mark","data-moving":s?i&&a?"blob":"ring":void 0,children:s&&i&&a?t.jsx(Au,{state:"working",size:"sm",still:a,className:"wb-msg-blob"}):t.jsx(On,{id:(n==null?void 0:n.id)??e,name:(n==null?void 0:n.name)??e,unavailable:n?!n.available:!1,...n?{face:n}:{}})}),t.jsx("span",{children:e}),r]})}function z8(e){var n,s;return((s=(n=/ may delegate to ([^;]*);/.exec(e)??/\(allowed: ([^)]*)\)/.exec(e))==null?void 0:n[1])==null?void 0:s.trim())||null}const U8="delegation refused:";function B8(e,n,s){const r=i=>{const l=e[i];if(!l||l.type!=="tool_use"||l.name!==si)return null;const o=oy(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(U8))return null;const u=l.input??{};return{target:typeof u.agent=="string"&&u.agent!==""?u.agent:"a colleague",message:c}};if(!r(n))return null;if(r(n-1))return"inside";const a=[];for(let i=n;;i+=1){const l=r(i);if(!l)break;a.push(l)}return a.length<2?null:{refusals:a}}function W8({refusals:e}){const[n,s]=d.useState(!1),r=e.map(o=>z8(o.message)).find(o=>o!==null)??null,a=e.map(o=>o.target),i=a.slice(0,3),l=`Delegation refused ${e.length} times: ${i.join(", ")}${a.length>i.length?", …":""}`+(r?` (allowed: ${r})`:"");return t.jsxs("div",{className:"wb-refusals","data-testid":"delegation-refusals","data-open":n||void 0,children:[t.jsxs("button",{type:"button",className:"wb-tool","data-ok":!1,"aria-expanded":n,onClick:()=>s(o=>!o),children:[t.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:l}),t.jsx(oe,{name:"arrow",className:"wb-tool-arrow"})]}),n?t.jsx("div",{className:"wb-refusals-list",children:e.map((o,c)=>t.jsxs("div",{className:"wb-refusal",children:[t.jsxs("span",{className:"wb-tool","data-static":"true","data-ok":!1,children:[t.jsx("span",{className:"wb-tool-mark","data-ok":"false","aria-hidden":"true"}),t.jsxs("span",{className:"wb-tool-label",children:[Pr(si)," · ",o.target]}),t.jsx("span",{className:"wb-tool-elapsed",children:"refused"})]}),t.jsx("p",{className:"wb-refusal-why",children:o.message})]},c))}):null]})}function H8(e,n){return e===null?null:Math.max(0,Math.round((n-e)/1e3))}function uv({text:e,live:n=!1,seconds:s=null}){const[r,a]=d.useState(!1),i=n?`Thinking${s!==null&&s>0?` · ${s}s`:""}`:s!==null&&s>0?`Thought for ${s}s`:"Thoughts";return t.jsxs("div",{className:"wb-thought","data-live":n||void 0,"data-open":r||void 0,children:[t.jsxs("button",{type:"button",className:"wb-thought-toggle","aria-expanded":r,onClick:()=>a(l=>!l),children:[n?t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}):t.jsx(oe,{name:"thought"}),t.jsx("span",{children:i}),t.jsx(oe,{name:"arrow",className:"wb-tool-arrow"})]}),r?t.jsx("div",{className:"wb-thought-text",children:t.jsx(pr,{text:e})}):null]})}function K8(e){var r;const n=((r=(e.blocks??[]).find(a=>a.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(n);return s?{handle:s[1],request:s[2].trim()}:null}function HT(e){const n=e.blocks??[];if(e.role!=="assistant"||n.length<2)return e;const s=[];let r=!1;for(const a of n){const i=s[s.length-1];a.type==="text"&&(i==null?void 0:i.type)==="text"?(s[s.length-1]={...i,text:i.text+V8(i.text,a.text)+a.text},r=!0):s.push(a)}return r?{...e,blocks:s}:e}function V8(e,n){return e===""||n===""||/\s$/.test(e)||/^\s/.test(n)||/^[.,;:!?)\]}»”’'"]/.test(n)?"":/[.!?:…)"”»]$/.test(e)?`
|
|
106
|
-
|
|
107
|
-
`:""}function G8(e){return(HT(e).blocks??[]).filter(n=>n.type==="text").map(n=>n.text.trim()).filter(n=>n!=="").join(`
|
|
108
|
-
|
|
109
|
-
`)}function Y8(e,n){const s=[],r=new Set,a=i=>{r.has(i.artifactId)||(r.add(i.artifactId),s.push(i))};for(const i of e.blocks??[])if(i.type==="attachment"&&a(i),i.type==="tool_use"&&i.name===si){const l=oy(n,i.id);l!=null&&l.ok&&Uh(l.output).forEach(a)}return s}function q8(e,n){const s=n.filter(l=>l.startedAt!==null&&l.finishedAt!==null),r=(l,o)=>o.at!==""&&o.at>=l.startedAt&&o.at<=l.finishedAt,a=(l,o)=>l!==o&&l.startedAt>=o.startedAt&&l.finishedAt<=o.finishedAt&&(l.startedAt>o.startedAt||l.finishedAt<o.finishedAt),i=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=>a(c,l)&&r(c,o))||i.has(o.id)||i.set(o.id,l)}return i}function Q8(e){if(e.stopped==="max_tokens")return"Length limit reached · answer cut off";const n=e.turns;return n===null?"Turn budget reached":`Turn budget reached · ${n} ${n===1?"step":"steps"}`}function J8(e){return e.type==="text"||e.type==="thinking"?e.text.trim()!=="":e.type==="tool_use"||e.type==="attachment"||e.type==="approval_result"}function X8({block:e,messages:n,at:s}){const[r,a]=d.useState(!1),i=e.state==="succeeded";return t.jsxs("div",{className:"wb-approval","data-open":r||void 0,children:[t.jsxs("button",{type:"button",className:"wb-tool","data-ok":i,"aria-expanded":r,onClick:()=>a(l=>!l),children:[t.jsx("span",{className:"wb-tool-mark","data-ok":i?"true":"false","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e.name===""?"Approved action":Pr(e.name)}),t.jsx("span",{className:"wb-tool-elapsed",children:e.state}),t.jsx(oe,{name:"arrow",className:"wb-tool-arrow"})]}),r&&e.name===si?t.jsx(A8,{block:e,messages:n,answeredAt:s}):null,r&&e.name!==si?t.jsx("pre",{className:"wb-approval-output mono",children:Z8(e.output)}):null]})}function Z8(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)??"null"}catch{return String(e)}}const eW=40;function tW(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(cv(e))return{status:"waiting",waiting:!0};const n=(r=e.approval)==null?void 0:r.state;return n?n==="approved"||n==="executing"?{status:"approved",waiting:!0}:n==="succeeded"?{status:"approved",waiting:!1}:{status:n,waiting:!1}:null}function dv({label:e,tool:n,ok:s,running:r,elapsed:a,opens:i,onOpen:l,status:o,waiting:c=!1,approval:u=!1,gist:h=null,body:f=null}){const[m,p]=d.useState(!1),g=t.jsxs(t.Fragment,{children:[r?t.jsx("span",{className:"wb-pulse","aria-hidden":"true"}):t.jsx("span",{className:"wb-tool-mark","data-ok":c?"pending":s===!1?"false":"true","aria-hidden":"true"}),t.jsx("span",{className:"wb-tool-label",children:e}),h?t.jsx("span",{className:"wb-tool-gist mono","data-testid":"tool-gist",children:h}):null,a===void 0?null:t.jsxs("span",{className:"wb-tool-elapsed",children:[a,"s"]}),o||s===!1?t.jsx("span",{className:"wb-tool-elapsed",children:o??"failed"}):null]}),x={"data-ok":s===null?void 0:s,"data-running":r,"data-gist":h?!0:void 0,"data-approval":u||void 0};return f?t.jsxs("div",{className:"wb-toolcall","data-open":m||void 0,children:[t.jsxs("div",{className:"wb-tool","data-split":"true",...x,children:[t.jsxs("button",{type:"button",className:"wb-tool-toggle","aria-expanded":m,onClick:()=>p(k=>!k),children:[t.jsx(oe,{name:"chevron",className:"wb-tool-chevron"}),g]}),i?t.jsxs(Kc,{children:[t.jsx(Vc,{asChild:!0,children:t.jsx("button",{type:"button",className:"wb-tool-open","aria-label":"Open on the canvas",onClick:l,children:t.jsx(oe,{name:"arrow",className:"wb-tool-arrow"})})}),t.jsx(Gc,{children:t.jsxs(Yc,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):null]}),m?t.jsx(nW,{body:f,onOpen:i?l:null}):null]}):i?t.jsxs(Kc,{children:[t.jsx(Vc,{asChild:!0,children:t.jsxs("button",{className:"wb-tool",...x,onClick:l,children:[g,t.jsx(oe,{name:"arrow",className:"wb-tool-arrow"})]})}),t.jsx(Gc,{children:t.jsxs(Yc,{className:"ui-tip",sideOffset:6,children:[t.jsx("span",{className:"ui-tip-title",children:"Open on the canvas"}),t.jsx("span",{className:"ui-tip-hint mono",children:n})]})})]}):t.jsx("span",{className:"wb-tool","data-static":"true",...x,children:g})}function nW({body:e,onOpen:n}){const s=n?{label:"Open on the canvas",onClick:n}:void 0;if(e.kind==="diff")return t.jsx("div",{className:"wb-tool-body","data-kind":"diff","data-testid":"tool-body",children:t.jsx(Lh,{text:e.diff,limit:eW,...s?{more:s}:{}})});const r=[e.exitCode===null?null:`exit ${e.exitCode}`,e.elapsedMs===null?null:sW(e.elapsedMs)].filter(a=>a!==null);return t.jsxs("div",{className:"wb-tool-body","data-kind":"command","data-testid":"tool-body",children:[t.jsxs("div",{className:"wb-tool-command",children:[t.jsx("code",{className:"mono",children:e.command}),r.length>0?t.jsx("span",{className:"wb-tool-facts","data-failed":e.exitCode!==null&&e.exitCode!==0?!0:void 0,children:r.join(" · ")}):null]}),e.output?t.jsx("pre",{className:"wb-tool-output",children:e.output}):null]})}function sW(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function oy(e,n){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===n)return r;return null}function rW({feedback:e}){const n=e.source==="telegram"?"on Telegram":`on ${e.source}`;return t.jsxs("div",{className:"wb-msg-feedback","data-value":e.value,"data-testid":"message-feedback",title:`You reacted ${e.emoji} ${n}`,children:[t.jsx("span",{className:"wb-msg-feedback-emoji","aria-label":`You reacted ${e.emoji} ${n}`,children:e.emoji}),t.jsx("span",{children:n}),e.note?t.jsxs("span",{className:"wb-msg-feedback-note",children:["“",e.note,"”"]}):null]})}const aW=20*1024*1024,iW=500,Aa=e=>`/skills/${encodeURIComponent(e)}`,wd=e=>`/skills/bundles/${encodeURIComponent(e)}`;async function lW(e){var n;try{const{staged:s}=await vw("/skills/bundles",e,"bundle.zip");return s}catch(s){const r=s instanceof he?(n=s.detail)==null?void 0:n.refusal:void 0;throw r?new KT({...r,filename:e.name,error:s instanceof Error?s.message:void 0}):s}}class KT extends Error{constructor(s){super(s.error??`“${s.filename}” was refused.`);Lb(this,"name","BundleRefused");this.refusal=s}}const Jt={list:()=>ye("/skills"),detail:e=>ye(Aa(e)),downloadUrl:e=>`/api${Aa(e)}/download`,create:e=>te("/skills",e),saveText:(e,n)=>te(`${Aa(e)}/text`,{text:n}),grant:(e,n)=>te(`${Aa(e)}/grants`,n),trust:e=>te(`${Aa(e)}/trust`),remove:e=>rr(Aa(e)),file:(e,n)=>ye(`${Aa(e)}/file`,{path:n}),imageUrl:(e,n)=>`/api${Aa(e)}/image?path=${encodeURIComponent(n)}`,uploadBundle:lW,stagedFile:(e,n)=>ye(`${wd(e)}/file`,{path:n}),stagedImageUrl:(e,n)=>`/api${wd(e)}/image?path=${encodeURIComponent(n)}`,acceptBundle:(e,n)=>te(wd(e),n),discardBundle:e=>rr(wd(e))};function VT(e,n){return`${bt}?tab=skills${e?`&skill=${encodeURIComponent(e)}`:""}${e&&n?`&skfile=${encodeURIComponent(n)}`:""}`}function oW(e){var s;const n=(s=/[?&]skfile=([^&]+)/.exec(e))==null?void 0:s[1];if(!n)return null;try{return decodeURIComponent(n)}catch{return null}}function cW(e){var s;const n=(s=/[?&]skill=([^&]+)/.exec(e))==null?void 0:s[1];if(!n)return null;try{return decodeURIComponent(n)}catch{return null}}function GT(e){const n=document.createElement("a");n.href=Jt.downloadUrl(e),n.download="",document.body.appendChild(n),n.click(),n.remove()}const cy=[{id:"mine",title:"Yours",aside:"Written or uploaded by you."},{id:"learned",title:"Learned",aside:"An agent proposed it and you kept it."},{id:"plugin",title:"From plugins",aside:"Comes with a plugin and goes with it."},{id:"catalogue",title:"From the catalogue",aside:"Came with a teammate. Yours to change."}];function ri(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Gs(e,n){var s;return((s=e.find(r=>r.id===n))==null?void 0:s.name)??n}function uy(e){return e.charAt(0).toUpperCase()+e.slice(1)}function dy(e,n){const s=e.shadowedBy??[];if(!s.length)return"Every agent";const r=s.map(a=>{var i;return`@${((i=n.find(l=>l.id===a))==null?void 0:i.handle)??a}`});return`Every agent except ${ri(r)} (${s.length===1?"has its own":"each has its own"})`}function YT(e,n){return e.holders.some(s=>s.agent===n)}function uW(e,n){if(e.every)return dy(e,n);const s=e.holders.map(r=>Gs(n,r.agent));return s.length?ri(s):"No agent uses it yet"}function dW(e){return!e.every&&e.holders.length===0}function hW(){const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}function SN(e){return e.slice(0,10)===hW()?"today":`on ${bu(e,{compact:!0})}`}function wc(e,n,s=!1){var l,o;if(e.learned){const c=e.learned.by,u=s&&e.holders.some(f=>f.agent===c),h=e.learned.keptAt?` · kept ${Ge(e.learned.keptAt)}`:"";return`${u?"":`learned by ${Gs(n,c)} · `}v${e.learned.version}${e.learned.edited?" with your correction":""}${h}`}const r=e.from;if((r==null?void 0:r.kind)==="plugin")return`from ${uy(r.plugin)} ${r.version}`;if((r==null?void 0:r.kind)==="catalogue")return`came with ${Gs(n,r.agent)} ${r.version}`;if((r==null?void 0:r.kind)==="upload")return`uploaded${e.created?` ${SN(e.created)}`:""} · ${r.filename}`;const a=((l=e.created)==null?void 0:l.slice(0,10))??null,i=((o=e.updatedAt)==null?void 0:o.slice(0,10))??null;return a&&(!i||i<=a)?`written by you ${SN(a)}`:e.updatedAt?`edited by you ${Ge(e.updatedAt)}`:"written by you"}function qT(e){return e.charAt(0).toUpperCase()+e.slice(1)}function hy(e,n){var s;return e.untrusted==="page"?`Untrusted: a web page was in view when ${Gs(n,((s=e.learned)==null?void 0:s.by)??e.home??"")} proposed it.`:e.bundle?"Untrusted: it came in a .zip, so agents read its text as outside text and its scripts can’t run.":"Untrusted: it came from a file, so agents read it as outside text."}function Mr(e){return e<1024*1024?`${Math.max(1,Math.round(e/1024))} KB`:`${(e/(1024*1024)).toFixed(e<10*1024*1024?1:0).replace(/\.0$/,"")} MB`}function QT(e,n){return e.every?n.filter(s=>!(e.shadowedBy??[]).includes(s.id)).map(s=>s.id):e.holders.map(s=>s.agent)}function fW(e,n){const s=e.bundle;if(!s)return null;const r=s.scripts.length;if(!r)return`No scripts · ${s.files} file${s.files===1?"":"s"} beside the text`;const a=QT(e,n),i=u=>{var h;return((h=n.find(f=>f.id===u))==null?void 0:h.canRunScripts)===!0},l=a.filter(i).map(u=>Gs(n,u)),o=a.filter(u=>!i(u)).map(u=>Gs(n,u)),c=`${r} script${r>1?"s":""}`;return e.untrusted?`${c} · they can’t run until you mark it as yours`:a.length?l.length?`${c} · ${ri(l)} can run them, asking first${o.length?`; ${ri(o)} ${o.length>1?"read":"reads"} the text only`:""}`:`${c} · nobody holding it can run them, so it’s text only`:`${c} · they run only through an agent you allow, and ask first`}function mW(e){var n;switch(e.kind){case"big":return{title:`“${e.filename}” is too big`,body:`${e.size?`It’s ${Mr(e.size)}; a`:"A"} bundle can be up to 20 MB unpacked. Leave large files out — SKILL.md can say where to find them.`};case"count":return{title:`“${e.filename}” holds too many files`,body:`It holds ${e.files??"over 500"} files; a bundle can hold up to ${iW}.`};case"noskill":{const s=(e.looked??[]).filter(r=>r!=="");return{title:`No SKILL.md in “${e.filename}”`,body:`buddi looked at the top${s.length?` and inside ${s.join(", ")}`:""}. A bundle needs SKILL.md in one of them, with scripts/ and assets/ beside it.`}}case"paths":{const s=((n=e.entries)==null?void 0:n.length)??0;return{title:`“${e.filename}” was refused`,body:`${s===1?"One entry reaches":`${s===2?"Two":s} entries reach`} outside the bundle, so nothing was unpacked. A bundle holds plain files inside its own folder.`,items:(e.entries??[]).map(r=>({path:r.path,rest:r.why==="is a link"&&r.target?`is a link to ${r.target}`:r.why}))}}case"executable":return{title:`“${e.filename}” was refused`,body:"Something that runs is outside scripts/, so nothing was kept. A bundle keeps anything that runs in scripts/.",items:(e.entries??[]).map(s=>({path:s.path,rest:s.why}))};case"frontmatter":return{title:`“${e.filename}” has no usable SKILL.md`,body:"Its SKILL.md needs front matter with a description (when it’s used) between --- lines, then the steps."};case"notzip":return{title:`“${e.filename}” isn’t a .zip or a .md`,body:"A skill is one Markdown file, or a .zip bundle with SKILL.md inside."};default:return{title:`“${e.filename}” was refused`,body:e.error??"It could not be read as a bundle."}}}function CN(e){const n=e.file.split(/[\\/]/).pop()??e.file;return e.bundle?`skills/${e.name}/${n}`:e.home?`agents/${e.home}/skills/${n}`:`skills/${n}`}function fy(e){return e.every?[]:e.holders.map(n=>n.agent)}function pW(e,n){var s;if(e.learned){const r=Gs(n,e.learned.by);return`Saved as v${e.learned.version+1}, your correction. v${e.learned.version} stays in ${r}’s folder.`}return((s=e.from)==null?void 0:s.kind)==="catalogue"?`${Gs(n,e.from.agent)}’s next update will ask before it replaces your change.`:null}function gW(e,n,s){var o;const r=n.stops.map(c=>Gs(s,c)),a=e.learned?Gs(s,e.learned.by):"";if(e.learned&&!n.every&&n.stops.length===1&&n.stops[0]===e.learned.by)return`${a} stops using it and won’t propose it again for 90 days. Earlier versions stay in its folder.`;const i=n.every?"Every agent stops using it.":r.length===0?"No agent uses it, so nothing changes.":`${ri(r)} ${r.length>1?"stop":"stops"} using it.`,l=n.then==="versions-kept"?`${a} won’t propose it again for 90 days. Earlier versions stay in its folder.`:n.then==="catalogue-asks"?`${((o=e.from)==null?void 0:o.kind)==="catalogue"?Gs(s,e.from.agent):"Its teammate"}’s next update asks before bringing it back.`:"The file goes to the trash folder.";return`${i} ${l}`}function xW(e,n){var c,u;const s=n.replace(/\r\n/g,`
|
|
110
|
-
`),r=/^---\n([\s\S]*?)\n---\n*/.exec(s),a=h=>{var m;return(r?((m=new RegExp(`^${h}:\\s*(.*)$`,"m").exec(r[1]))==null?void 0:m[1])??"":"").trim().replace(/^(['"])(.*)\1$/,"$2")},i=r?s.slice(r[0].length):s,l=(u=(c=/^#\s+(.+)$/m.exec(i))==null?void 0:c[1])==null?void 0:u.trim(),o=a("name");return{title:l||(o?qT(o.replace(/-/g," ")):e.replace(/\.md$/i,"")),description:a("description"),body:i}}function vW(e){const n=e==null?void 0:e.envelope;if(!n||typeof n!="object"||Array.isArray(n))return null;const s=n.skillRun;if(!s||typeof s!="object")return null;const r=s;return typeof r.bundle!="string"||typeof r.script!="string"?null:{bundle:r.bundle,title:typeof r.title=="string"?r.title:r.bundle,script:r.script,interpreter:typeof r.interpreter=="string"?r.interpreter:"",args:Array.isArray(r.args)?r.args.filter(a=>typeof a=="string"):[],reads:typeof r.reads=="string"?r.reads:"",writes:typeof r.writes=="string"?r.writes:"",files:typeof r.files=="number"?r.files:0}}function Lp(e){return/[\s"'\\]/.test(e)||e===""?JSON.stringify(e):e}function jW(e){const n=[];for(let s=0;s<e.length;s+=1){const r=e[s],a=e[s+1];r.startsWith("-")&&!r.includes("=")&&a!==void 0&&!a.startsWith("-")?(n.push(`${Lp(r)} ${Lp(a)}`),s+=1):n.push(Lp(r))}return n}function wW({action:e,run:n,agentName:s,count:r,busy:a,error:i,onDecide:l}){const o=a!==null||e.state!=="pending",c=jW(n.args);return t.jsxs("section",{id:"approval-dock",tabIndex:-1,className:"wb-question skb-dock","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),r>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",r]}):null,t.jsxs("strong",{children:[s," wants to run a script from ",n.title]})]}),t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[t.jsx("code",{className:"wb-dock-gist",children:[n.interpreter,n.script].filter(Boolean).join(" ")}),t.jsx("span",{className:"wb-dock-where",children:"From a bundle you marked as yours."})]}),t.jsx("div",{className:"wb-dock-section",children:t.jsx(Xt,{items:[{label:"Arguments",value:c.length?t.jsx("span",{className:"mono skb-args",children:c.map((u,h)=>t.jsx("span",{children:u},`${h}:${u}`))}):"None"},{label:"Working folder",value:t.jsx("span",{className:"mono skb-path",children:n.writes})},{label:"What it may touch",value:`Reads ${n.title}’s ${n.files} file${n.files===1?"":"s"} without changing them, and the working folder. Writes only in the working folder.`}]})}),t.jsx(ae,{message:i}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(ne,{children:[t.jsx("span",{className:"skb-dock-note",children:"Scripts ask every time."}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",size:"sm",disabled:o,onClick:()=>l("reject"),children:a==="reject"?"Rejecting…":"Reject"}),t.jsx($,{size:"sm",onClick:()=>{window.location.hash=VT(n.bundle,n.script)},children:"Show the script"}),t.jsx($,{variant:"good",size:"sm",disabled:o,onClick:()=>l("approve"),children:a==="approve"?"Allowing…":"Allow once"})]})})]})}const JT="approval-dock";function yW(){var n;const e=document.getElementById(JT);e&&((n=e.scrollIntoView)==null||n.call(e,{block:"nearest"}),e.focus())}const bW=["workspace","cwd","workdir","root"];function XT({approvals:e,timezone:n,now:s,version:r,onDecided:a,onSay:i,onOpenFull:l}){const[o,c]=d.useState([]),u=e.filter(m=>!o.includes(m.approvalId)),h=u[0];if(!h)return null;const f=m=>c(p=>p.includes(m)?p:[...p,m]);return t.jsx(kW,{item:h,count:u.length,timezone:n,now:s,version:r,onSettled:m=>{f(h.approvalId),m&&a(m)},onSay:i,onOpenFull:()=>l(h.toolUseId)},h.approvalId)}function kW({item:e,count:n,timezone:s,now:r,version:a,onSettled:i,onSay:l,onOpenFull:o}){var T;const[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,x]=d.useState("");d.useEffect(()=>{let E=!1;return A.approval(e.approvalId).then(R=>{E||(u(R),R.state!=="pending"&&i(R))}).catch(R=>{E||f(R instanceof he?R.message:String(R))}),()=>{E=!0}},[e.approvalId,a]);const k=c!==null&&c.state==="pending"&&Date.parse(c.expiresAt)<=r;d.useEffect(()=>{k&&c&&i({...c,state:"expired"})},[k]);const{values:j,controls:v}=Qw(c==null?void 0:c.choices),w=(E,R)=>{const M=g.trim();p(E),f(null),(j&&E==="approve"?A.decide(e.approvalId,E,R,j):A.decide(e.approvalId,E,R)).then(O=>{i(O.action),M&&l(M)}).catch(O=>{f(O instanceof he?O.message:String(O)),p(null)})},y=vW(c);if(c&&y){const E=c.agentId?c.agentId.charAt(0).toUpperCase()+c.agentId.slice(1):"An agent";return t.jsx(wW,{action:c,run:y,agentName:E,count:n,busy:m,error:h,onDecide:R=>w(R)})}const N=m!==null||c===null||c.state!=="pending",b=((T=c==null?void 0:c.permissionScopes)==null?void 0:T.includes("always"))??!1,S=c?ay(c.tool,c.canonicalArgs)??SW(c.preview):null,C=c?NW(c):null;return t.jsxs("section",{id:JT,tabIndex:-1,className:"wb-question","data-kind":"approval","aria-label":"Approval needed","data-testid":"approval-dock",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your OK"}),n>1?t.jsxs("span",{className:"wb-dock-count","data-testid":"approval-dock-count",children:["1 of ",n]}):null,t.jsx("strong",{children:c?Pr(c.tool):"Loading the request…"}),e.askedBy?t.jsx("span",{className:"wb-dock-asker","data-testid":"approval-dock-asker",children:e.askedBy}):null]}),S||C?t.jsxs("div",{className:"wb-dock-section wb-dock-subject",children:[S?t.jsx("code",{className:"wb-dock-gist",children:S}):null,C?t.jsxs("span",{className:"wb-dock-where",children:["in ",t.jsx("span",{className:"mono",children:C})]}):null]}):null,v?t.jsx("div",{className:"wb-dock-section",children:v}):null,t.jsx(ae,{message:h}),t.jsx("div",{className:"wb-dock-section",children:t.jsx("input",{className:"wb-dock-instead",value:g,onChange:E=>x(E.target.value),onKeyDown:E=>{E.key==="Enter"&&E.preventDefault()},placeholder:"Tell the agent what to do instead (optional)","aria-label":"Tell the agent what to do instead (optional)",disabled:m!==null})}),t.jsxs("div",{className:"wb-dock-section wb-dock-actions",children:[t.jsxs("span",{className:"wb-dock-meta",children:[c?t.jsxs(t.Fragment,{children:["Expires ",mt(c.expiresAt,s)," · "]}):null,t.jsx("button",{type:"button",className:"wb-link",onClick:o,children:"See the full request on the Canvas"})]}),t.jsx($,{variant:"ghost",size:"sm",disabled:N,onClick:()=>w("reject"),children:m==="reject"?"Rejecting…":"Reject"}),b?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",size:"sm",disabled:N,onClick:()=>w("approve","conversation"),children:"Auto: this conversation"}),t.jsx($,{size:"sm",disabled:N,onClick:()=>w("approve","always"),children:"Always: this agent"})]}):null,t.jsx($,{variant:"good",size:"sm",disabled:N,onClick:()=>w("approve"),children:m==="approve"?"Approving…":b?"Allow once":"Approve"})]})]})}function NW(e){for(const n of[e.canonicalArgs,e.envelope])if(!(n===null||typeof n!="object"||Array.isArray(n)))for(const s of bW){const r=n[s];if(typeof r=="string"&&r.trim()!=="")return r.trim()}return null}function SW(e){const n=(e??"").split(`
|
|
111
|
-
`).map(s=>s.trim()).find(Boolean);return n?n.length>160?`${n.slice(0,157)}…`:n:null}const CW=2e3;function EW({conversationId:e,agentId:n,runId:s=null,result:r=null,waiting:a=null,agents:i=[]}){const l=r!==null,[o,c]=d.useState(l),u=!o||a!==null,{data:h,error:f}=ge(()=>Je.conversation(e),[e,o,(a==null?void 0:a.approvalId)??null],u?CW:void 0),m=(h==null?void 0:h.runs)??[],p=s===null?null:m.find(y=>y.runId===s)??null,g=l||a===null&&(s!==null?p!==null&&p.finishedAt!==null:m.length>0&&m.every(y=>y.finishedAt!==null));d.useEffect(()=>{g&&c(!0)},[g]);const x=r?r.ok?"done":"failed":a!=null&&a.approvalId?"waiting":g?"done":"working",k=i.find(y=>y.id===n)??null,j=(k==null?void 0:k.name)??(h==null?void 0:h.agentId)??n,v=(h==null?void 0:h.messages)??[],w=(r==null?void 0:r.text)??$W(v);return t.jsxs("div",{className:"wb-delegate","data-testid":"delegate-view","data-status":x,children:[t.jsxs("header",{className:"wb-delegate-head",children:[t.jsx(jn,{agents:i,id:n}),t.jsxs("div",{className:"wb-delegate-who",children:[t.jsx("strong",{children:j}),t.jsx("span",{className:"wb-delegate-status","data-status":x,role:"status",children:x==="working"?t.jsxs(t.Fragment,{children:["Working",t.jsxs("span",{className:"wb-dots","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]})]}):x==="waiting"?"Waiting for your approval":x==="failed"?"Failed":"Done"})]})]}),f?t.jsx("p",{className:"muted",children:f}):null,t.jsx("div",{className:"wb-delegate-work",children:v.map((y,N)=>t.jsx("div",{className:"wb-delegate-turn",children:(y.blocks??[]).map((b,S)=>{if(b.type==="thinking")return b.text.trim()===""?null:t.jsx(uv,{text:b.text},S);if(b.type==="tool_use"){const C=TW(AW(v,b.id));return t.jsx(dv,{label:Pr(b.name),tool:b.name,ok:C.ok,running:C.running,waiting:C.waiting,status:C.status,gist:ay(b.name,b.input),opens:!1,onOpen:()=>{}},S)}return null})},y.id??N))}),w?t.jsx("div",{className:"wb-delegate-answer","data-testid":"delegate-answer",children:t.jsx(pr,{text:w})}):x==="working"||x==="waiting"?t.jsxs("p",{className:"muted",children:[j," has not answered yet."]}):null,r!=null&&r.files&&r.files.length>0?t.jsx("div",{className:"wb-msg-files",role:"list","aria-label":`Files ${j} made`,"data-testid":"delegate-files",children:r.files.map(y=>t.jsx("a",{role:"listitem",href:ni(y.artifactId),download:!0,children:t.jsx(mm,{name:y.filename??"Untitled file",mime:y.mime,sizeBytes:y.sizeBytes,thumbnail:Xw(y.mime)?Ur(y.artifactId):null})},y.artifactId))}):null,t.jsxs("div",{className:"wb-delegate-actions",children:[x==="waiting"?t.jsx($,{variant:"accent",onClick:()=>yW(),"data-testid":"delegate-to-approval",children:"Go to the approval"}):null,t.jsx("a",{className:"ui-btn",href:at(n||(h==null?void 0:h.agentId)||"",e),children:"Open this conversation"})]})]})}function $W(e){for(let n=e.length-1;n>=0;n-=1){const s=e[n];if(s.role!=="assistant")continue;const r=(s.blocks??[]).filter(a=>a.type==="text").map(a=>a.text.trim()).filter(a=>a!=="").join(`
|
|
112
|
-
|
|
113
|
-
`);if(r!=="")return r}return null}function AW(e,n){for(const s of e)for(const r of s.blocks??[])if(r.type==="tool_result"&&r.toolUseId===n)return r;return null}function TW(e){var s;if(e===null)return{running:!0,ok:null,waiting:!1,status:void 0};const n=(s=e.approval)==null?void 0:s.state;return n==="pending"?{running:!1,ok:null,waiting:!0,status:"waiting approval"}:n==="approved"||n==="executing"?{running:!0,ok:null,waiting:!1,status:"running"}:n==="succeeded"?{running:!1,ok:!0,waiting:!1,status:void 0}:n?{running:!1,ok:!1,waiting:!1,status:n}:{running:!1,ok:e.ok,waiting:!1,status:void 0}}const EN=1024*1024;function RW({files:e,agentId:n,root:s,revision:r}){const[a,i]=d.useState({kind:"dir",path:""});return d.useEffect(()=>i({kind:"dir",path:""}),[e.plugin,n]),t.jsx("div",{className:"wb-files","data-testid":"files-view",children:a.kind==="dir"?t.jsx(IW,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i}):t.jsx(PW,{files:e,agentId:n,root:s,path:a.path,revision:r,go:i})})}function ZT({root:e,path:n,go:s}){const r=n===""?[]:n.split("/"),a=[{label:e,path:""},...r.map((i,l)=>({label:i,path:r.slice(0,l+1).join("/")}))];return t.jsx("nav",{className:"wb-files-crumbs","aria-label":"Where you are in the workspace",children:a.map((i,l)=>{const o=l===a.length-1;return t.jsxs("span",{className:"wb-files-crumb",children:[l>0?t.jsx("span",{className:"wb-files-sep","aria-hidden":"true",children:"/"}):null,o?t.jsx("span",{className:"wb-files-here mono","aria-current":"location",children:i.label}):t.jsx("button",{type:"button",className:"wb-files-step mono",onClick:()=>s({kind:"dir",path:i.path}),children:i.label})]},i.path)})})}function IW({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null);d.useEffect(()=>{let k=!1;return u(null),A.pageQuery(e.plugin,e.list,{agent:n,...r?{path:r}:{}}).then(j=>{k||o(j.data)}).catch(j=>{k||u(j instanceof Error?j.message:String(j))}),()=>{k=!0}},[e.plugin,e.list,n,r,a]),d.useEffect(()=>p(null),[r]);const g=async()=>{f(!0),p(null);try{const k=await fetch(A.pageFileUrl(e.plugin,e.archive,{agent:n,...r?{path:r}:{}}),{credentials:"same-origin"});if(!k.ok){const y=await k.json().catch(()=>null);p((y==null?void 0:y.error)??"The archive could not be made.");return}const j=await k.blob(),v=URL.createObjectURL(j),w=document.createElement("a");w.href=v,w.download=`${r===""?s:r.split("/").at(-1)}.zip`,w.click(),window.setTimeout(()=>URL.revokeObjectURL(v),1e4)}catch{p("The archive could not be made.")}finally{f(!1)}},x=l&&l.path===r?l.entries:null;return t.jsxs(t.Fragment,{children:[t.jsxs(ne,{children:[t.jsx(ZT,{root:s,path:r,go:i}),t.jsx(ot,{}),t.jsx($,{size:"sm",onClick:()=>void g(),disabled:h||x===null||x.length===0,children:h?"Packing…":"Download as archive"})]}),m?t.jsx(G,{tone:"warning",role:"alert",children:m}):null,c?t.jsx(G,{tone:"critical",role:"alert",children:c}):null,x===null?c?null:t.jsx(Ne,{children:"Reading the folder…"}):x.length===0?t.jsx(Ne,{children:r===""?t.jsxs(t.Fragment,{children:["Nothing in this workspace yet. To hand the agent a file, add it to the ",t.jsx("a",{href:va,children:"Files library"})," and mention it here."]}):"This folder is empty."}):t.jsx(ct,{children:x.map(k=>t.jsx(rt,{href:"#",onClick:()=>i({kind:k.kind,path:k.path}),lead:t.jsx(OW,{kind:k.kind}),title:t.jsxs("span",{className:"mono",children:[k.name,k.kind==="dir"?"/":""]}),side:k.kind==="file"?ps(k.bytes):void 0},k.path))}),l&&l.path===r&&(l.skipped>0||l.truncated)?t.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 PW({files:e,agentId:n,root:s,path:r,revision:a,go:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1);d.useEffect(()=>{let j=!1;return u(null),A.pageQuery(e.plugin,e.stat,{agent:n,path:r}).then(v=>{j||o(v.data)}).catch(v=>{j||u(v instanceof Error?v.message:String(v))}),()=>{j=!0}},[e.plugin,e.stat,n,r,a]);const m=l&&l.path===r?l:null,p=m?`${m.bytes}-${Math.round(m.mtimeMs)}`:"",g=m?A.pageFileUrl(e.plugin,e.read,{agent:n,path:r,v:p}):"",x=A.pageFileUrl(e.plugin,e.read,{agent:n,path:r,download:"1"}),k=(m==null?void 0:m.type)==="text"&&m.bytes<=EN;return t.jsxs(t.Fragment,{children:[t.jsxs(ne,{children:[t.jsx(ZT,{root:s,path:r,go:i}),t.jsx(ot,{}),k?t.jsx($,{size:"sm","aria-pressed":h,onClick:()=>f(j=>!j),children:"Wrap"}):null,t.jsx(lt,{size:"sm",href:x,download:(m==null?void 0:m.name)??r.split("/").at(-1),children:"Download"})]}),c?t.jsx(G,{tone:"critical",role:"alert",children:c}):null,m===null?c?null:t.jsx(Ne,{children:"Reading the file…"}):m.type==="image"?t.jsx("figure",{className:"wb-files-picture",children:t.jsx("img",{src:g,alt:m.name})}):m.type==="pdf"?t.jsx("div",{className:"file-preview file-preview-pdf",children:t.jsx("object",{data:g,type:"application/pdf","aria-label":m.name,children:t.jsx(G,{children:"Your browser cannot show this PDF here. Download it to open it."})})}):k?t.jsx(MW,{src:g,wrap:h}):t.jsxs(t.Fragment,{children:[t.jsx(G,{children:m.type==="text"?`This file is over ${ps(EN)}, too long to read here. Download it to open it.`:"This kind of file is not shown here. Download it to open it."}),t.jsx(Xt,{items:[{label:"Size",value:ps(m.bytes)},{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})}]})]})]})}function MW({src:e,wrap:n}){const[s,r]=d.useState(null),[a,i]=d.useState(!1);return d.useEffect(()=>{let l=!1;return i(!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||i(!0)}),()=>{l=!0}},[e]),a?t.jsx(G,{tone:"critical",children:"The file could not be read."}):s===null?t.jsx(Ne,{children:"Reading the file…"}):s===""?t.jsx(Ne,{children:"This file is empty."}):t.jsx("pre",{className:"wb-files-text","data-wrap":n?"true":void 0,"data-testid":"files-text",children:s})}function OW({kind:e}){return t.jsx("span",{className:"wb-files-icon","data-kind":e,"aria-hidden":"true",children:t.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"?t.jsx("path",{d:"M2 4.2h4.2l1.4 1.6H14v7H2z"}):t.jsx("path",{d:"M4 2.4h5l3 3v8.2H4zM9 2.4v3h3"})})})}function DW({input:e,output:n,ok:s}){const r=X5(e),a=LT(n)??(s?"sent":"not sent");return t.jsxs("div",{className:"wb-envelope",children:[t.jsxs("div",{className:"envelope",children:[t.jsxs("dl",{className:"envelope-head",children:[t.jsx("dt",{children:"To"}),t.jsx("dd",{className:"wb-envelope-action",children:"You"}),t.jsx("dt",{children:"Status"}),t.jsx("dd",{children:t.jsx(Ae,{tone:Z5(a,s),dot:!0,children:a})})]}),t.jsxs("div",{className:"envelope-body",children:[t.jsx("strong",{children:r.title}),r.text?`
|
|
114
|
-
|
|
115
|
-
${r.text}`:null]})]}),t.jsx(Zt,{summary:"The call",children:t.jsxs("dl",{className:"ui-kv wb-envelope-fields",children:[t.jsx("dt",{children:"Urgency"}),t.jsx("dd",{children:r.urgency}),r.link?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Link"}),t.jsx("dd",{className:"mono",children:r.link})]}):null,r.key?t.jsxs(t.Fragment,{children:[t.jsx("dt",{children:"Key"}),t.jsx("dd",{className:"mono",children:r.key})]}):null]})})]})}const rc=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:{},qt=e=>typeof e=="string"&&e.trim()!==""?e:null,LW={blocked:"Blocked — that address is on this computer or a private network, which the reader never opens.",forbidden:"The site turned the reader away. It may need a sign-in or refuse automated readers.",unauthorised:"The page needs a sign-in, which the reader doesn’t have.","not-found":"Page not found — the link may be old or mistyped.",timeout:"Timed out — the site didn’t answer in time.","too-large":"Too large to read — the page is bigger than the reader takes.","unsupported-content":"Not a web page — a PDF, an image or a file the reader doesn’t open.","rate-limited":"The site is limiting how often it can be read. Try again later.","server-error":"The site had a problem of its own.","too-many-redirects":"The link kept redirecting, so the reader gave up.",network:"Couldn’t reach the site.",unreadable:"The page came back unreadable.","turned-away":"The site turned the reader away with a robot check."};function FW(e){const n=e.slice(0,4e3);if(n.length<20)return!1;let s=0;for(const r of n){const a=r.codePointAt(0);(a===65533||a<32&&a!==9&&a!==10&&a!==13||a>=127&&a<160)&&(s+=1)}return s/n.length>.1}function Fp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function _W(e){if(!e)return null;try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"?n.href:null}catch{return null}}function hv(e){try{const n=new URL(e);return`${n.hostname.replace(/^www\./,"")}${n.pathname.replace(/\/+$/,"")}${n.search}`}catch{return e}}function $N(e){var n;return((n=e.match(/[\p{L}\p{N}]/u))==null?void 0:n[0])??"?"}function eR(e){const n=rc(e.input),s=rc(e.output),r={input:e.input,...e.ok===null?{status:"Awaiting result"}:{output:e.output},...e.error===void 0?{}:{error:e.error}},a=e.ok===!1,i=qt(e.error)??qt(rc(e.error).message);if(Array.isArray(s.results)||qt(n.query)&&!qt(n.url)){const f=(Array.isArray(s.results)?s.results:[]).map(p=>rc(p)).flatMap(p=>{const g=qt(p.url);return g?[{title:qt(p.title)??Fp(g),url:g,host:qt(p.source)??Fp(g),snippet:qt(p.snippet)}]:[]}),m=s.available===!1;return{kind:"search",id:e.id,raw:r,query:qt(s.query)??qt(n.query)??"",state:e.ok===null?"pending":a||m?"failed":"ok",provider:qt(s.provider),results:f,why:a?`The search failed${i?`: ${i}`:"."}`:m?qt(s.provider)?"The search couldn’t be run this time.":"Web search isn’t set up on this buddi yet — `buddi doctor` says how.":null}}const l=qt(s.url)??qt(n.url)??"",o=!a&&s.ok!==!1&&FW(qt(s.text)??""),c=a||s.ok===!1||o,u=o?"unreadable":qt(s.problem),h=qt(s.message);return{kind:"page",id:e.id,url:l,raw:r,host:qt(s.source)??Fp(l),state:e.ok===null?"pending":c?"failed":"ok",title:qt(s.title),text:o?null:qt(s.text),truncated:s.truncated===!0,retrievedAt:qt(s.retrievedAt)??e.at,why:c?(u&&LW[u])??(h?h.charAt(0).toUpperCase()+h.slice(1)+(/[.!?]$/.test(h)?"":"."):null)??`The read failed${i?`: ${i}`:"."}`:null}}function zW(e){const n=e.entries.map(eR),s=n.filter(a=>a.kind==="search").length,r=n.length-s;return[s?`${s} ${s===1?"search":"searches"}`:null,r?`${r} ${r===1?"page":"pages"}`:null].filter(Boolean).join(" · ")}function UW(e){return e.split(/\s+/).filter(Boolean).length}function BW(e){return e>=1e3?`${(e/1e3).toFixed(1).replace(/\.0$/,"")}k words`:`${e} ${e===1?"word":"words"}`}function WW(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Tt(s,n??Intl.DateTimeFormat().resolvedOptions().timeZone)}function tR({url:e,className:n,children:s}){const r=_W(e);return r?t.jsxs("a",{className:`wb-src-link ${n}`,href:r,target:"_blank",rel:"noopener noreferrer",children:[s,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx("span",{className:n,children:s})}function nR({value:e}){const[n,s]=d.useState(!1);return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-src-quiet","data-raw":"","aria-expanded":n,onClick:()=>s(!n),children:n?"Hide JSON":"Raw JSON"}),n?t.jsx("pre",{className:"wb-src-raw",children:JSON.stringify(e,null,2)}):null]})}function HW({page:e,focused:n,timezone:s}){const[r,a]=d.useState(n),[i,l]=d.useState(!1),o=d.useRef(null);if(d.useEffect(()=>{var m,p;n&&(a(!0),(p=(m=o.current)==null?void 0:m.scrollIntoView)==null||p.call(m,{block:"nearest"}))},[n]),e.state==="pending")return t.jsx("li",{className:"wb-src-page","data-state":"pending",ref:o,children:t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-state":"pending","aria-hidden":"true",children:$N(e.host)}),t.jsxs("span",{className:"wb-src-head",children:[t.jsxs("span",{className:"wb-src-title",children:["Reading ",e.host,"…"]}),t.jsx("span",{className:"wb-src-meta",children:e.url})]}),t.jsx("span",{})]})});const c=e.state==="failed",u=e.text?UW(e.text):0,h=WW(e.retrievedAt,s),f=[e.host,h?`read ${h}`:null,u?BW(u):null,u?`${Math.max(1,Math.round(u/230))} min read`:null].filter(Boolean).join(" · ");return t.jsxs("li",{className:"wb-src-page","data-open":r?"true":void 0,"data-state":e.state,ref:o,children:[t.jsxs("div",{className:"wb-src-row",children:[t.jsx("span",{className:"wb-src-tile","data-tone":c?"critical":void 0,"aria-hidden":"true",children:c?"!":$N(e.host)}),t.jsxs("span",{className:"wb-src-head",children:[c?t.jsxs("span",{className:"wb-src-title",children:["Couldn’t read ",e.host]}):t.jsx(tR,{url:e.url,className:"wb-src-title",children:e.title??e.host}),c?t.jsx("span",{className:"wb-src-why",children:e.why}):t.jsx("span",{className:"wb-src-meta",children:f})]}),t.jsx("button",{type:"button",className:"wb-src-toggle","aria-expanded":r,"aria-label":r?`Hide what was read from ${e.host}`:`Show what was read from ${e.host}`,onClick:()=>a(!r),children:t.jsx(oe,{name:"chevron"})})]}),r?t.jsxs("div",{className:"wb-src-body",children:[c?t.jsx("p",{className:"wb-src-note",children:e.url}):t.jsxs(t.Fragment,{children:[e.text?t.jsx("p",{className:"wb-src-text","data-clamped":i?void 0:"true",children:e.text}):t.jsx("p",{className:"wb-src-note",children:"The page had no text to read."}),e.truncated?t.jsx("p",{className:"wb-src-note",children:"Only the beginning of the page was read; it was longer than the limit."}):null]}),t.jsxs("div",{className:"wb-src-foot",children:[!c&&e.text?t.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>l(!i),children:i?"Show less":"Show more"}):null,t.jsx(nR,{value:e.raw})]})]}):null]})}const AN=3;function KW({search:e,read:n,focused:s}){const[r,a]=d.useState(!1),i=d.useRef(null);d.useEffect(()=>{var c,u;s&&((u=(c=i.current)==null?void 0:c.scrollIntoView)==null||u.call(c,{block:"nearest"}))},[s]);const l=r?e.results:e.results.slice(0,AN),o=e.state==="pending"?"Searching…":[e.provider,e.state==="ok"?`${e.results.length} ${e.results.length===1?"result":"results"}`:null].filter(Boolean).join(" · ");return t.jsxs("div",{className:"wb-src-list","data-state":e.state,ref:i,children:[t.jsxs("div",{className:"wb-src-query",children:[t.jsxs("span",{className:"wb-src-query-text",children:["“",e.query,"”"]}),o?t.jsx("span",{className:"wb-src-query-meta",children:o}):null,t.jsx("span",{className:"wb-src-query-raw",children:t.jsx(nR,{value:e.raw})})]}),e.state==="failed"?t.jsx("p",{className:"wb-src-empty wb-src-why",children:e.why}):null,e.state==="ok"&&e.results.length===0?t.jsx("p",{className:"wb-src-empty",children:"No results."}):null,l.length>0?t.jsx("ol",{className:"wb-src-results",children:l.map(c=>t.jsxs("li",{className:"wb-src-result",children:[t.jsx(tR,{url:c.url,className:"wb-src-result-title",children:c.title}),t.jsx("span",{className:"wb-src-result-site",children:c.host}),c.snippet?t.jsx("p",{className:"wb-src-result-snippet",children:c.snippet}):null,n.has(hv(c.url))?t.jsx("span",{className:"wb-src-result-side",children:t.jsx(Ae,{tone:"good",children:"Read"})}):null]},c.url))}):null,e.results.length>AN?t.jsx("div",{className:"wb-src-more",children:t.jsx("button",{type:"button",className:"wb-src-quiet",onClick:()=>a(!r),children:r?"Show fewer":`Show all ${e.results.length}`})}):null]})}function VW({entries:e,focus:n,timezone:s}){const r=e.map(eR),a=r.filter(o=>o.kind==="page"),i=r.filter(o=>o.kind==="search"),l=new Set(a.filter(o=>o.state==="ok").flatMap(o=>{const c=e.find(h=>h.id===o.id),u=qt(rc(c==null?void 0:c.input).url);return[hv(o.url),...u?[hv(u)]:[]]}));return t.jsxs("div",{className:"wb-src",children:[a.length>0?t.jsxs("div",{className:"wb-src-group",children:[t.jsx("p",{className:"wb-src-kicker",children:"Read"}),t.jsx("ul",{className:"wb-src-list",children:a.map(o=>t.jsx(HW,{page:o,focused:n===o.id,timezone:s},o.id))})]}):null,i.length>0?t.jsxs("div",{className:"wb-src-group",children:[t.jsx("p",{className:"wb-src-kicker",children:"Searched"}),i.map(o=>t.jsx(KW,{search:o,read:l,focused:n===o.id},o.id))]}):null]})}const GW=3,YW=152,qW=104,QW=100,JW=2,TN=5;function XW({renderables:e,activeId:n,onActivate:s,timezone:r,onDecided:a,onChangeAgent:i,face:l,descriptors:o,grantedTools:c,agentName:u,maxTabs:h,browserPanel:f,browserMenu:m,agents:p,onClose:g,loading:x=!1}){var N;const[k,j]=ZW(h);if(e.length===0)return t.jsxs("div",{className:"wb-canvas","data-testid":"canvas",children:[t.jsx("div",{className:"wb-canvas-tabs",ref:k,"aria-hidden":"true",children:t.jsx("span",{className:"wb-canvas-label",children:"Canvas"})}),t.jsx("div",{className:"wb-canvas-body wb-canvas-body-empty",children:x?null:t.jsxs("div",{className:"wb-empty",children:[l?t.jsx("span",{className:"wb-empty-face",children:l}):null,t.jsx("p",{className:"ui-empty wb-empty-line",children:rH(u,aH(o??[],c??[]))})]})})]});const v=e.some(b=>b.id===n)?n:e[e.length-1].id,{shown:w,hidden:y}=eH(e,v,j);return t.jsx("div",{className:"wb-canvas","data-testid":"canvas",children:t.jsxs(I3,{value:v,onValueChange:s,className:"contents",children:[t.jsxs("div",{className:"wb-canvas-tabs",ref:k,children:[t.jsx("span",{className:"wb-canvas-label","aria-hidden":"true",children:"Canvas"}),t.jsx(P3,{className:"wb-tabstrip","aria-label":"Canvas",children:w.map(b=>t.jsxs("div",{className:"wb-tab-item",children:[t.jsxs(M3,{value:b.id,className:"wb-tab","data-tone":b.tone,onKeyDown:S=>{S.key==="Delete"&&g&&RN(b)&&(S.preventDefault(),g(b.id))},children:[b.tone==="warning"||b.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":b.tone,"aria-hidden":"true"}):null,t.jsx("span",{className:"wb-tab-text",children:b.title}),b.count?t.jsx("span",{className:"wb-tab-count",children:b.count}):null]}),g&&RN(b)?t.jsx("button",{className:"wb-tab-close","aria-label":`Close ${b.title} tab`,title:"Dismiss panel; keep conversation history",onClick:()=>g(b.id),children:"×"}):null]},b.id))}),t.jsx(tH,{items:y,onActivate:s,timezone:r}),m&&((N=e.find(b=>b.id===v))==null?void 0:N.source)==="browser"?t.jsx("span",{className:"wb-canvas-menu",children:m}):null]}),e.map(b=>t.jsx(O3,{value:b.id,className:"wb-canvas-body","data-renderer":b.source==="descriptor"&&b.renderer==="preview"?"preview":void 0,"data-dense":lH.has(b.renderer)?"true":void 0,"data-page":b.source==="browser"?"true":void 0,children:b.source==="browser"?f:t.jsxs("section",{className:"ui-panel","data-flush":b.source==="descriptor"&&b.renderer==="preview"?"true":void 0,children:[b.source!=="files"&&!(b.source==="descriptor"&&b.renderer==="preview")?t.jsxs("header",{className:"ui-panel-head",children:[t.jsx("h2",{className:"ui-panel-title",children:b.title}),t.jsx("span",{className:"ui-panel-tool mono",children:b.source==="sources"?zW(b.props):b.tool})]}):null,b.tone==="critical"?t.jsxs("p",{className:"muted",children:["Recorded tool failure",b.at?` · ${mt(b.at,Intl.DateTimeFormat().resolvedOptions().timeZone)}`:"",". This is history, not live session status."]}):null,b.source==="profile"?t.jsx(b5,{...b.props,...i?{onChange:i}:{}}):b.source==="artifact"?t.jsx(Y5,{...b.props}):b.source==="files"?t.jsx(RW,{...b.props}):b.source==="sources"?t.jsx(VW,{...b.props,timezone:r}):b.source==="notify"?t.jsx(DW,{...b.props}):b.source==="delegate"?t.jsx(EW,{...b.props,agents:p??[]}):t.jsx(y5,{renderer:b.renderer,props:b.props,timezone:r,onDecided:a})]})},b.id))]})})}function RN(e){return e.source==="approval"?!1:e.source==="browser"?e.pinned!==!0:e.source!=="files"}function ZW(e){const[n,s]=d.useState(TN),r=d.useRef(null);return[d.useCallback(i=>{var o;if((o=r.current)==null||o.disconnect(),r.current=null,!i||e!==void 0||typeof ResizeObserver>"u")return;const l=()=>{const c=i.clientWidth;if(c===0)return;const u=Math.floor((c-QW-qW)/YW);s(Math.max(JW,Math.min(TN,u)))};l(),r.current=new ResizeObserver(l),r.current.observe(i)},[e]),e??n]}function eH(e,n,s){const r=new Set(e.filter(i=>i.id===n||i.source==="approval"||i.pinned===!0).map(i=>i.id)),a=new Set(r);for(let i=e.length-1;i>=0&&a.size<s;i-=1)a.add(e[i].id);return{shown:e.filter(i=>a.has(i.id)),hidden:e.filter(i=>!a.has(i.id))}}function tH({items:e,onActivate:n,timezone:s}){if(e.length===0)return null;const r=e.some(a=>a.tone==="critical")?"critical":e.some(a=>a.tone==="warning")?"warning":null;return t.jsxs(Su,{modal:!1,children:[t.jsx(Cu,{asChild:!0,children:t.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?t.jsx("span",{className:"wb-tab-dot","data-tone":r,"aria-hidden":"true"}):null,t.jsxs("span",{className:"wb-tab-text",children:[e.length," more"]}),t.jsx(oe,{name:"chevron-down"})]})}),t.jsx(ko,{children:t.jsxs(Eu,{className:"ui-menu","data-wide":"true",align:"end",sideOffset:6,children:[t.jsx(Wi,{className:"ui-menu-label",children:"Earlier in this conversation"}),[...e].reverse().map(a=>t.jsxs(Bs,{className:"ui-menu-item",onSelect:()=>n(a.id),children:[t.jsxs("span",{className:"ui-menu-item-text",children:[a.tone==="warning"||a.tone==="critical"?t.jsx("span",{className:"wb-tab-dot","data-tone":a.tone,"aria-hidden":"true"}):null,a.title]}),t.jsx("span",{className:"ui-menu-note mono",children:nH(a.at,s)??a.tool})]},a.id))]})})]})}function nH(e,n){if(!e)return null;const s=new Date(e);return Number.isNaN(s.getTime())?null:Tt(s,n)}const sH={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 rH(e,n){const s=e?`What ${e} shows you`:"What your agent shows you",r=[...new Set(n.map(a=>sH[a.renderer]??"results"))].slice(0,3);return r.length>0?`${s} lands here: ${r.join(", ")}.`:`${s} lands here.`}function aH(e,n){const s=new Set(n),r=new Set,a=e.filter(c=>{if(!s.has(c.tool))return!1;const u=iH(c);return r.has(u)?!1:(r.add(u),!0)}),i=new Set,l=a.filter(c=>i.has(c.renderer)?!1:(i.add(c.renderer),!0)),o=a.filter(c=>!l.includes(c));return[...l,...o].slice(0,GW)}function iH(e){return e.title&&e.title.trim()!==""?e.title:e.tool.split(".").map(n=>n.replace(/[_-]+/g," ")).join(" · ").replace(/\b\w/,n=>n.toUpperCase())}const lH=new Set(["table","diff","files"]),oH=3.5*6e4,cH=2e3;function uH(e,n,s={}){const[r,a]=d.useState({served:new Set,live:new Set,scope:n}),i=d.useRef(r.served);if(r.scope!==n){const u={served:new Set,live:new Set,scope:n};i.current=u.served,a(u)}const l=s.check??A.previewCheck,o=s.everyMs??cH,c=e.map(u=>`${Hl(u)}@${u.at??""}`).join("|");return d.useEffect(()=>{const u=new Map;for(const p of e){const g=Hl(p);if(i.current.has(g))continue;const x=p.at===null?Number.NaN:Date.parse(p.at),k=Number.isNaN(x)?0:x+oH,j=u.get(g);(!j||k>j.until)&&u.set(g,{plugin:p.plugin,name:p.name,until:k})}if(u.size===0)return;let h=!1,f;const m=async()=>{const p=Date.now();for(const[g,x]of[...u]){const k=await l(x.plugin,x.name).catch(()=>null);if(h)return;const j=p<=x.until;k!=null&&k.ok?(u.delete(g),a(v=>{const w={served:new Set(v.served).add(g),live:j?new Set(v.live).add(g):v.live,scope:v.scope};return i.current=w.served,w})):j||u.delete(g)}!h&&u.size>0&&(f=setTimeout(()=>void m(),o))};return m(),()=>{h=!0,f!==void 0&&clearTimeout(f)}},[c,n,l,o]),r}const fv="workspace-files";function dH(e){let n=0;for(const s of e)for(const r of s.blocks??[]){if(r.type!=="tool_result"||r.ok===!1)continue;const a=r.output;if(a===null||typeof a!="object"||Array.isArray(a))continue;const{diff:i,path:l}=a;typeof i=="string"&&i.trim()!==""&&typeof l=="string"&&l!==""&&(n+=1)}return n}function hH(e){const[n,s]=d.useState(null);return d.useEffect(()=>{if(s(null),!e)return;let r=!1;return(async()=>{var i;const a=await A.pages();for(const l of Array.isArray(a==null?void 0:a.files)?a.files:[]){const o=await A.pageQuery(l.plugin,l.workspace,{agent:e}).catch(()=>null),c=(i=o==null?void 0:o.data)==null?void 0:i.workspace;if(c&&typeof c.name=="string")return{files:l,agentId:e,root:c.name}}return null})().then(a=>{r||s(a)}).catch(()=>{}),()=>{r=!0}},[e]),n&&n.agentId===e?n:null}function fH(e,n){return{id:fv,tool:"",title:"Files",renderer:"files",props:{files:e.files,agentId:e.agentId,root:e.root,revision:n},at:null,source:"files",pinned:!0,substantial:!1}}function mv(e){return`agent-properties:${e}`}function mH(e){return{id:mv(e.id),tool:`@${e.handle}`,title:"Properties",renderer:"profile",props:{profile:e},at:null,source:"profile",substantial:!1}}function pH(e,n,s,r){const a=e.width||1,i=e.height||1,l=n.pageScaleFactor||1,o=(s-e.left)*(n.deviceWidth/a)/l,c=((r-e.top)*(n.deviceHeight/i)-n.offsetTop)/l,u=(h,f)=>Math.max(0,Math.min(Math.round(h),Math.round(f)));return{x:u(o,n.deviceWidth),y:u(c,n.deviceHeight)}}function _p(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function IN(e){return[...e].length===1&&e.codePointAt(0)>=32&&e.codePointAt(0)!==127}const gH=4e3;function xH(e){return e.replace(/\r\n?/g,`
|
|
116
|
-
`).replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g,"").slice(0,gH)}const vH=["left","middle","right"],jH=33;function wH(e,n){return e.deviceWidth===n.deviceWidth&&e.deviceHeight===n.deviceHeight&&e.pageScaleFactor===n.pageScaleFactor&&e.offsetTop===n.offsetTop&&e.url===n.url}function yH(e){if(e.byteLength<3)return null;const n=new DataView(e);if(n.getUint8(0)!==1)return null;const s=n.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 bH(e=window.location){return`${e.protocol==="https:"?"wss":"ws"}://${e.host}/api/browser/hand`}const kH=d.forwardRef(function({sessionId:n,csrf:s,onGiveBack:r,connect:a,bare:i=!1,typing:l,onTyping:o,onLocation:c,onLoginSeen:u},h){const[f,m]=d.useState("connecting"),[p,g]=d.useState(null),[x,k]=d.useState(!1),[j,v]=d.useState(null),[w,y]=d.useState(!1),N=l??w,b=B=>{o?o(B):y(B)},[S,C]=d.useState(0),T=d.useRef(null),E=d.useRef(u);E.current=u;const R=d.useRef(null),M=d.useRef(null),O=d.useRef({at:0});d.useEffect(()=>{var B,q,J,Z;l!==void 0&&(l?(q=(B=M.current)==null?void 0:B.focus)==null||q.call(B):(Z=(J=M.current)==null?void 0:J.blur)==null||Z.call(J))},[l]),d.useEffect(()=>{const B=a??(Z=>new WebSocket(Z));let q=!0,J;try{J=B(bH())}catch{m("lost");return}return J.binaryType="arraybuffer",T.current=J,J.onopen=()=>J.send(JSON.stringify({type:"hello",csrf:s,sessionId:n})),J.onmessage=Z=>{var ve;if(!q)return;if(typeof Z.data!="string"){const Oe=yH(Z.data);if(!Oe||(v(W=>W&&wH(W,Oe.metadata)?W:Oe.metadata),k(!0),typeof createImageBitmap!="function"))return;createImageBitmap(Oe.jpeg).then(W=>{var X,je,be;const se=R.current;if(!q||!se){(X=W.close)==null||X.call(W);return}(se.width!==W.width||se.height!==W.height)&&(se.width=W.width,se.height=W.height),(je=se.getContext("2d"))==null||je.drawImage(W,0,0),(be=W.close)==null||be.call(W)}).catch(()=>{});return}const fe=JSON.parse(Z.data);if(fe.type==="driving"){m("driving"),g(null);return}if(fe.type==="loginSeen"){typeof fe.id=="string"&&typeof fe.site=="string"&&typeof fe.username=="string"&&((ve=E.current)==null||ve.call(E,{id:fe.id,site:fe.site,username:fe.username,...fe.update===!0?{update:!0}:{}}));return}(fe.type==="refused"||fe.type==="ended")&&(g(fe.error??"The screen cannot be driven from here."),m("refused"))},J.onclose=()=>{q&&m(Z=>Z==="refused"?Z:"lost")},J.onerror=()=>{q&&m(Z=>Z==="refused"?Z:"lost")},()=>{q=!1,T.current=null;try{J.close()}catch{}}},[n,s,S,a]),d.useEffect(()=>()=>{clearTimeout(O.current.timer)},[]);const I=j==null?void 0:j.url;d.useEffect(()=>{I&&(c==null||c(I))},[I]);const z=d.useCallback(B=>{const q=T.current;if(q)try{q.send(JSON.stringify({type:"input",input:B}))}catch{}},[]);d.useImperativeHandle(h,()=>({nav:(B,q)=>T.current?(z({kind:"nav",action:B,...B==="navigate"&&q?{url:q}:{}}),!0):!1}),[z]);const U=B=>{var Z;const q=R.current;if(!q||!j)return null;const J=(Z=q.getBoundingClientRect)==null?void 0:Z.call(q);return J?pH(J,j,B.clientX,B.clientY):null},D=B=>{const q=O.current,J=Date.now();clearTimeout(q.timer),q.timer=void 0;const Z=q.at+jH-J;if(Z<=0){q.at=J,q.pending=void 0,z(B);return}q.pending=B,q.timer=setTimeout(()=>{const fe=O.current.pending;O.current.timer=void 0,O.current.pending=void 0,O.current.at=Date.now(),fe&&z(fe)},Z)},P=()=>{const B=O.current;clearTimeout(B.timer),B.timer=void 0;const q=B.pending;B.pending=void 0,q&&(B.at=Date.now(),z(q))},K=B=>q=>{var fe,ve;const J=U(q);if(!J)return;B==="mousePressed"&&(q.preventDefault(),(ve=(fe=R.current)==null?void 0:fe.focus)==null||ve.call(fe));const Z={kind:"mouse",type:B,x:J.x,y:J.y,button:vH[q.button]??"left",clickCount:B==="mouseMoved"?0:Math.min(3,Math.max(1,q.detail||1)),modifiers:_p(q)};if(B==="mouseMoved"){D(Z);return}P(),z(Z)},F=B=>{const q=U(B);q&&(P(),z({kind:"wheel",x:q.x,y:q.y,deltaX:Math.round(B.deltaX),deltaY:Math.round(B.deltaY)}))},Q=B=>B.ctrlKey||B.metaKey||B.altKey,_=B=>{var J,Z;if(B.key==="Escape"&&Q(B)){b(!1),(Z=(J=B.target).blur)==null||Z.call(J);return}if(B.preventDefault(),(B.metaKey||B.ctrlKey)&&(B.key==="v"||B.key==="V"))return;const q=_p(B);if(IN(B.key)&&!Q(B)){z({kind:"key",type:"char",key:B.key,code:B.code,text:B.key,modifiers:q});return}z({kind:"key",type:"keyDown",key:B.key,code:B.code,modifiers:q})},re=B=>{B.key==="Escape"&&Q(B)||(B.preventDefault(),!((B.metaKey||B.ctrlKey)&&(B.key==="v"||B.key==="V"))&&(IN(B.key)&&!Q(B)||z({kind:"key",type:"keyUp",key:B.key,code:B.code,modifiers:_p(B)})))},Y=B=>{var J;B.preventDefault();const q=xH(((J=B.clipboardData)==null?void 0:J.getData("text/plain"))??"");q!==""&&z({kind:"text",text:q})};return t.jsxs("section",{className:"hand","data-testid":"remote-hand","data-phase":f,"data-bare":i?"true":void 0,"aria-label":"Driving the page",children:[i?null:t.jsxs("div",{className:"hand-bar",children:[t.jsx("span",{className:"hand-said",role:"status",children:"You have the page. Nothing you type here is kept."}),t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",variant:N?"accent":"ghost","aria-pressed":N,onClick:()=>{var q,J,Z,fe;const B=!N;b(B),B?(J=(q=M.current)==null?void 0:q.focus)==null||J.call(q):(fe=(Z=M.current)==null?void 0:Z.blur)==null||fe.call(Z)},children:"Keyboard"}),t.jsx($,{size:"sm",variant:"accent",onClick:r,children:"Give it back"})]})]}),f==="lost"?t.jsxs(G,{tone:"warning",role:"status",children:["Connection lost. The picture below is the last frame that arrived.",t.jsx(ne,{align:"end",children:t.jsx($,{size:"sm",variant:"accent",onClick:()=>{m("connecting"),C(B=>B+1)},children:"Reconnect"})})]}):null,f==="refused"&&p?t.jsx(G,{tone:"warning",role:"status",children:p}):null,t.jsx("div",{className:"hand-screen",children:x?t.jsx("canvas",{ref:R,className:"hand-picture",role:"img","aria-label":"The host browser, live","data-testid":"hand-picture",tabIndex:0,onMouseDown:K("mousePressed"),onMouseUp:K("mouseReleased"),onMouseMove:K("mouseMoved"),onWheel:F,onKeyDown:_,onKeyUp:re,onPaste:Y,onContextMenu:B=>B.preventDefault()}):t.jsx("p",{className:"muted hand-waiting",children:f==="lost"?"No picture arrived before the connection dropped.":"Waiting for the first frame…"})}),t.jsx("input",{ref:M,className:"hand-typing","aria-label":"Type into the host browser",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,value:"",onChange:()=>{},onKeyDown:_,onKeyUp:re,onPaste:Y,onBlur:()=>b(!1)})]})});function NH(e){return e==="darwin"?"this Mac":"this computer"}let zp=null;function pm(){const[e,n]=d.useState(void 0);return d.useEffect(()=>{let s=!0;return zp??(zp=A.session().then(r=>r.platform,()=>{zp=null})),zp.then(r=>{s&&n(r)}),()=>{s=!1}},[]),NH(e)}const SH="sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0";function CH({timezone:e,navigate:n}={}){var u;const{data:s,error:r,reload:a}=ge(()=>A.browser(),[],3e3),i=ge(()=>A.session(),[]),l=(u=i.data)!=null&&u.platform?i.data.platform==="darwin":!0,o=!!i.data||!!i.error,c=h=>{n?n(h):window.location.hash=h};return t.jsxs("div",{className:"ui-stack br-looking","data-gap":"lg",children:[t.jsx(ae,{message:r}),!s||!o?t.jsx(Ne,{children:"Checking where agents may look…"}):t.jsx(IH,{data:s,macOS:l,reload:a,timezone:e,go:c})]})}function my({kind:e}){const n={own:t.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"2.8",y:"3.6",width:"14.4",height:"12.8",rx:"1.8"}),t.jsx("path",{d:"M2.8 7.2h14.4M5.4 5.4h.1M7.4 5.4h.1"})]}),chrome:t.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.1"}),t.jsx("circle",{cx:"10",cy:"10",r:"2.6"}),t.jsx("path",{d:"M10 7.4h6.6M7.8 11.4 4.4 5.6M12.2 11.4 9 16.9"})]}),apps:t.jsxs("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"6",height:"6",rx:"1.4"}),t.jsx("rect",{x:"11",y:"3",width:"6",height:"6",rx:"1.4"}),t.jsx("rect",{x:"3",y:"11",width:"6",height:"6",rx:"1.4"}),t.jsx("rect",{x:"11",y:"11",width:"6",height:"6",rx:"1.4"})]})}[e];return t.jsx("span",{className:"br-glyph","aria-hidden":"true",children:n})}function ir({line:e,status:n,tone:s,children:r}){return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-row-line",children:e}),n?t.jsx("span",{className:"pl-row-status","data-tone":s,children:n}):null,r]})}function EH({text:e}){const[n,s]=d.useState(!1);return t.jsxs("span",{className:"br-copy",children:[t.jsx("code",{className:"mono",children:e}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function yd({label:e,hint:n,children:s}){return t.jsxs("div",{className:"br-adv-row",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsx("span",{className:"br-adv-title",children:e}),n?t.jsx("span",{className:"br-adv-hint",children:n}):null]}),s]})}function gm(e){const n=e.split(".").filter(Boolean).at(-1)??e;return n.charAt(0).toUpperCase()+n.slice(1)}function $H(e){return e.length<=2?e.join(" and "):`${e.slice(0,2).join(", ")} and ${e.length-2} more`}const AH=[{value:"auto",label:"Let it choose"},{value:"own",label:"Its own browser only"},{value:"chrome",label:"Your Chrome first"},{value:"apps",label:"Your apps first"}];function pv({value:e,label:n,apps:s,disabled:r,onChange:a}){return t.jsx("select",{className:"br-select",value:e,"aria-label":n,disabled:r,onChange:i=>a(i.target.value),children:AH.filter(i=>s||i.value!=="apps"||e==="apps").map(i=>t.jsx("option",{value:i.value,children:i.label},i.value))})}function TH(e){return(e==null?void 0:e.installed)===!0}function RH(e,n){return e?e.pending?"pair":e.pairedAt?e.connected?"connected":n&&n.state!=="paired"&&iR(n.gateway)?"broken":"notrunning":n&&n.state!=="paired"?"pair":"none":"none"}function IH({data:e,macOS:n,reload:s,timezone:r,go:a}){var j,v;const[i,l]=d.useState(!1),[o,c]=d.useState(null),u=async w=>{l(!0),c(null);try{await w()}catch(y){c(y instanceof Error?y.message:String(y))}finally{l(!1),s()}},h=e.settings,f=w=>void u(()=>A.browserSettings(w)),m=r??Intl.DateTimeFormat().resolvedOptions().timeZone,p=e.learnedSignInSites??[],g=(j=e.routes)==null?void 0:j.find(w=>w.kind==="apps"),x=TH(g),k=(v=e.sessions)!=null&&v.length?e.sessions:e.session?[e]:[];return t.jsxs(t.Fragment,{children:[t.jsx(G,{children:"Agents pick where to look for each task: their own browser first, your Chrome for a site that needs your sign-in, an app when you name one. You don’t choose each time; here you say what they may use."}),t.jsx(ae,{message:o}),e.enabled?null:t.jsx(G,{tone:"warning",children:"Agents can’t look at pages from here. Start buddi serve on the machine buddi runs on."}),e.stop?t.jsx(G,{tone:"warning",role:"status",action:t.jsx($,{size:"sm",variant:"accent",disabled:i,onClick:()=>void u(()=>A.browserControl("resume")),children:"Resume"}),children:`Agents’ browsing is paused since ${Tt(new Date(e.stop.at),m)}, by you from the Canvas, ${e.stop.until?`until ${Tt(new Date(e.stop.until),m)}`:"until you resume it"}. An agent that needs a page asks you in its chat.`}):null,t.jsx(Xe,{title:"Browsers and apps",flush:!0,children:t.jsxs("div",{className:"ui-list",children:[t.jsx(PH,{data:e,busy:i,run:u}),h?t.jsx(MH,{settings:h,learned:p,busy:i||!e.enabled,save:f,zone:m}):null,x&&h?t.jsx(OH,{route:g,settings:h,busy:i||!e.enabled,save:f,run:u,onSettings:()=>a(mr(g.provider||"computer"))}):null]})}),!x&&n?t.jsxs("p",{className:"pl-note br-foot","data-testid":"computer-plugin-offer",children:["Agents can also work in apps on this Mac with the Computer plugin. ",t.jsx("a",{href:"#/settings/plugins?tab=browse&kind=plugins",children:"See plugins"})]}):null,k.length>0?t.jsx(Xe,{title:"Looking now",flush:!0,actions:t.jsx($,{size:"sm",disabled:i,onClick:()=>void u(()=>A.browserControl("stop")),children:"Stop agents’ browsing"}),children:t.jsx("div",{className:"ui-list",children:k.map(w=>{var y;return t.jsxs("a",{className:"ui-list-row",href:at(w.session.agentId,w.session.conversationId,"browser"),children:[t.jsx(On,{id:w.session.agentId,name:w.session.agentId,size:"sm"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:((y=w.page)==null?void 0:y.title)||w.session.task}),t.jsx("span",{className:"ui-list-sub",children:sR(w)})]}),t.jsx("span",{className:"ui-list-side",children:"Open the Canvas"})]},w.session.id)})})}):null,h?t.jsx(DH,{settings:h,learned:p,busy:i,save:f,run:u,showApps:x}):null]})}function sR(e){var s,r;return e.needsOwner?`Waiting for you · ${e.needsOwner.kind==="human"?"it asks for a human":e.needsOwner.kind==="uncertain"?"did that click land?":e.needsOwner.kind==="budget"?"keep going?":"it asks for your sign-in"}`:e.route==="apps"?`Working in ${(s=e.page)!=null&&s.appId?gm(e.page.appId):"an app"} · its own window`:`Looking at ${py((r=e.page)==null?void 0:r.url)??"a page"} · ${e.route==="chrome"?"in your Chrome · background tab":"in buddi’s browser"}`}function py(e){if(e)try{return new URL(e).hostname.replace(/^www\./,"")||void 0}catch{return}}function PH({data:e,busy:n,run:s}){var c,u,h;const r=e.browser,a=r==null?void 0:r.install,i=(c=e.settings)!=null&&c.showWindow?"For every page, in a window on this machine":"For every page, out of sight";let l,o;if((a==null?void 0:a.state)==="running"){const f=(u=a.progress)==null?void 0:u.percent;l=t.jsx(ir,{line:i,status:t.jsxs("span",{className:"br-installing",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),`Installing Chromium…${f!==void 0?` ${Math.round(f)}%`:""}`]})}),o=null}else(r==null?void 0:r.engine)==="none"?(l=t.jsx(ir,{line:i,tone:"critical",status:(a==null?void 0:a.state)==="failed"?`The install didn’t finish: ${a.line??"no reason given"}`:"Chromium isn’t installed, so agents can’t look at pages yet."}),o=t.jsx($,{size:"sm",variant:"accent",disabled:n,onClick:()=>void s(()=>A.browserInstall()),children:"Install · 150 MB"})):(r==null?void 0:r.problem)==="no-sandbox"?(l=t.jsx(ir,{line:i,tone:"critical",status:"Linux blocks its sandbox (AppArmor). Run this once, then Check again:",children:t.jsx(EH,{text:SH})}),o=t.jsx($,{size:"sm",disabled:n,onClick:()=>void s(()=>A.browserCheck()),children:"Check again"})):r!=null&&r.problem?(l=t.jsx(ir,{line:i,tone:"critical",status:r.message??"It doesn’t start on this machine."}),o=t.jsx($,{size:"sm",disabled:n,onClick:()=>void s(()=>A.browserCheck()),children:"Check again"})):(l=(h=e.settings)!=null&&h.showWindow?"For every page, in a window on this machine. You also watch it on the Canvas.":"For every page, out of sight. You watch it on the Canvas.",o=e.enabled?t.jsx(Ae,{tone:"good",dot:!0,children:"ready"}):null);return t.jsxs("div",{className:"ui-list-row",children:[t.jsx(my,{kind:"own"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"buddi’s own browser"}),t.jsx("span",{className:"ui-list-sub",children:l})]}),o?t.jsx("span",{className:"ui-list-side",children:t.jsx("span",{className:"br-side",children:o})}):null]})}const PN=1e4;async function MN(e,n={pair:s=>A.pairExtension(s),extension:()=>A.extension()}){try{await n.pair(e)}catch(s){if((s==null?void 0:s.status)!==409)throw s;const r=(n.now??Date.now)(),a=await n.extension().catch(()=>{}),i=a!=null&&a.pairedAt?Date.parse(a.pairedAt):NaN;if(!(Number.isFinite(i)&&r-i>=-PN&&r-i<=PN))throw s}rR()}function rR(){if(typeof window>"u")return;const e=window.location.hash,n=nU(e);if(n!==e)try{window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.search}${n}`)}catch{}}function MH({settings:e,learned:n,busy:s,save:r,zone:a}){var F,Q,_,re,Y,B,q,J,Z,fe;const i=ge(()=>A.extension(),[],3e3),l=ge(()=>UH(),[],3e3).data??null,o=pm(),[c,u]=d.useState(()=>T0(typeof window>"u"?"":window.location.hash)??"");d.useEffect(()=>{const ve=()=>{const Oe=T0(window.location.hash);Oe&&u(Oe)};return window.addEventListener("hashchange",ve),()=>window.removeEventListener("hashchange",ve)},[]);const[h,f]=d.useState(!1),[m,p]=d.useState(null),[g,x]=d.useState(!1),[k,j]=d.useState(!1),v=RH(i.data,l),w=BH(),y=async ve=>{f(!0),p(null);try{await ve()}catch(Oe){p(Oe instanceof Error?Oe.message:String(Oe))}finally{f(!1),i.reload()}},N=(F=i.data)!=null&&F.pending&&(l==null?void 0:l.state)==="pairing"?l.code??"":"",b=d.useRef("");d.useEffect(()=>{!N||b.current===N||h||(b.current=N,y(async()=>{await A.pairExtension(N),rR()}))},[N]);const S=s||h,C=(Q=i.data)!=null&&Q.pairedAt?`paired ${mt(i.data.pairedAt,a)}`:null,T=(l==null?void 0:l.version)??((_=i.data)==null?void 0:_.extension),E=t.jsx(ss,{label:"More for your Chrome",items:[C||v==="broken"||v==="notrunning"||v==="connected"?{label:"Pair again",hint:[T?`Extension ${T}`:null,C].filter(Boolean).join(" · ")||void 0,onSelect:()=>void y(()=>A.forgetExtension())}:null,(re=i.data)!=null&&re.checkout?{label:"Install unpacked…",hint:"For a developer build of the extension",onSelect:()=>j(!0)}:null,(Y=i.data)!=null&&Y.pairedAt?"separator":null,(B=i.data)!=null&&B.pairedAt?{label:"Forget this Chrome…",tone:"critical",onSelect:()=>x(!0)}:null]}),R=t.jsxs("span",{className:"br-pair",children:[t.jsx("input",{"aria-label":"Pairing code",inputMode:"numeric",autoComplete:"one-time-code",maxLength:7,placeholder:"482 913",value:c,onChange:ve=>u(ve.target.value),onKeyDown:ve=>{ve.key==="Enter"&&c.replace(/[^0-9]/g,"").length===6&&!S&&y(async()=>{await MN(c),u("")})}}),t.jsx($,{size:"sm",variant:"accent",disabled:S||c.replace(/[^0-9]/g,"").length!==6,onClick:()=>void y(async()=>{await MN(c),u("")}),children:"Pair"})]}),M=t.jsxs("span",{className:"br-enter-code",children:[t.jsx("span",{className:"pl-row-line",children:"Enter the code · Open the buddi icon in Chrome; type its code here"}),R]}),O=[...e.signInSites,...n],I=O.length>0?`Always for ${$H(O)}`:null;let z,U;if(v==="none")z=t.jsx(ir,{line:"For sites that need your sign-in",status:w==="chromium"?"Add the buddi extension to Chrome, then pair it here. Until then agents use their own browser and your saved logins.":"The buddi extension runs in Chrome, Edge, Brave or Arc on a computer: add it there, then pair it on this page. Until then agents use their own browser and your saved logins.",children:M}),U=t.jsxs(t.Fragment,{children:[w==="chromium"?t.jsxs(lt,{size:"sm",variant:"accent",href:aR,target:"_blank",rel:"noopener noreferrer",children:["Add to Chrome ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):null,E]});else if(v==="pair"){const ve=l?`Extension ${l.version} found in Chrome`:"The buddi extension asks to pair";z=N?t.jsx(ir,{line:ve,status:"Pairing with the code the extension shows. This finishes by itself.",children:t.jsx("span",{className:"br-code mono","aria-label":"Pairing code",children:N.replace(/^(\d{3})(\d{3})$/,"$1 · $2")})}):(q=i.data)!=null&&q.pending?t.jsx(ir,{line:ve,status:"Type the six digits the extension shows.",children:R}):t.jsx(ir,{line:ve,status:"Open the extension and press Connect: it shows a code, and this page pairs with it.",children:M}),U=E}else if(v==="broken")z=t.jsx(ir,{line:"Used only for sites that need your sign-in",tone:"critical",status:"Chrome forgot the pairing, so agents use their own browser instead."}),U=t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"accent",disabled:S,onClick:()=>void y(()=>A.forgetExtension()),children:"Pair again"}),E]});else{const ve=e.yourChrome?v==="notrunning"?`Used only for sites that need your sign-in · Chrome isn’t open on ${o}; agents wait or use their own browser`:"Used only for sites that need your sign-in · background tabs in a buddi group":"Off. Sites that need a sign-in use your saved logins, or ask you.";z=I&&e.yourChrome?t.jsx(ir,{line:ve,status:I}):ve,U=t.jsxs(t.Fragment,{children:[e.yourChrome?v==="notrunning"?t.jsx(Ae,{children:"Chrome closed"}):t.jsx(Ae,{tone:"good",dot:!0,children:"connected"}):null,t.jsx(Tu,{checked:e.yourChrome,label:"Let agents use your Chrome",disabled:S,onChange:Oe=>r({yourChrome:Oe})}),E]})}const D=l&&((J=i.data)!=null&&J.extensionMinimum)&&zH(l.version,i.data.extensionMinimum)?`This extension is ${l.version}; this buddi needs ${i.data.extensionMinimum} or later. Update it from chrome://extensions or the store.`:null,P=l&&!iR(l.gateway)?`The extension is pointed at ${l.gateway}; set it to ${window.location.origin} in its popup.`:null,K=(Z=i.data)!=null&&Z.portMoved&&v!=="pair"?`Port ${i.data.portMoved.from} was taken by another program, so buddi now listens on ${i.data.portMoved.to}. Pair the extension again: in its popup set the address to http://127.0.0.1:${i.data.portMoved.to} and press Connect.`:null;return K&&v!=="broken"&&v!=="none"&&(U=t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"accent",disabled:S,onClick:()=>void y(()=>A.forgetExtension()),children:"Pair again"}),E]})),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"ui-list-row",children:[t.jsx(my,{kind:"chrome"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"Your Chrome"}),t.jsxs("span",{className:"ui-list-sub",children:[z,D?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:D}):null,P?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:P}):null,K?t.jsx("span",{className:"pl-row-status","data-tone":"warning",children:K}):null,m??i.error?t.jsx("span",{className:"pl-row-status","data-tone":"critical",children:m??i.error}):null]})]}),t.jsx("span",{className:"ui-list-side",children:t.jsx("span",{className:"br-side",children:U})})]}),g?t.jsx("div",{className:"br-confirm",children:t.jsx(G,{tone:"warning",action:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>x(!1),children:"Cancel"}),t.jsx($,{size:"sm",variant:"danger",disabled:S,onClick:()=>{x(!1),y(()=>A.forgetExtension())},children:"Forget"})]}),children:"Forget this Chrome? Agents stop using it until you pair it again."})}):null,k?t.jsxs(Ye,{title:"Install the extension unpacked",onClose:()=>j(!1),children:[t.jsx("div",{className:"ui-prose muted",children:t.jsx("p",{children:"For a developer build. Open chrome://extensions, turn on Developer mode, choose Load unpacked, and pick this folder. Then pair it on this page."})}),t.jsx(zt,{label:"The unpacked extension",children:((fe=i.data)==null?void 0:fe.path)??"…"})]}):null]})}function OH({route:e,settings:n,busy:s,save:r,run:a,onSettings:i}){const l=n.yourApps!=="off",o=`From the ${e.label??gm(e.provider.replace(/^@withbuddi\/plugin-/,""))} plugin`,c=l&&!e.available&&!!e.message,u=c?t.jsx(ir,{line:o,tone:"critical",status:e.message}):l?`${o} · ${n.yourApps==="ask"?"asks for each app":"when you name an app"}`:"Off. Agents tell you when a task needs an app.";return t.jsxs("div",{className:"ui-list-row",children:[t.jsx(my,{kind:"apps"}),t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title",children:"Your apps"}),t.jsx("span",{className:"ui-list-sub",children:u})]}),t.jsx("span",{className:"ui-list-side",children:t.jsxs("span",{className:"br-side",children:[c&&e.repair==="permissions"?t.jsx($,{size:"sm",variant:"accent",onClick:i,children:"Allow in macOS"}):null,!c&&l?t.jsx(Ae,{tone:"good",dot:!0,children:"ready"}):null,c&&e.repair==="permissions"?null:t.jsx(Tu,{checked:l,label:"Let agents use your apps",disabled:s,onChange:h=>r({yourApps:h?"on":"off"})}),t.jsxs($,{size:"sm",variant:"ghost","aria-label":"Manage apps",onClick:i,children:["Settings",t.jsx(oe,{name:"chevron-right",size:12})]})]})})]})}function DH({settings:e,learned:n,busy:s,save:r,run:a,showApps:i}){var b;const l=ge(()=>A.agents(),[]),o=((b=l.data)==null?void 0:b.engines)??[],c=o.filter(S=>S.browser&&S.browser!=="auto"),u=o.filter(S=>!S.browser||S.browser==="auto"),[h,f]=d.useState(!1),[m,p]=d.useState(""),[g,x]=d.useState("own"),[k,j]=d.useState(""),v=(S,C)=>void a(async()=>{await A.setAgentEngine(S,{browser:C}),l.reload()}),w=e.defaultRoute==="apps"?"auto":e.defaultRoute,y=[1,3,5].includes(e.maxOwnPages)?[1,3,5]:[1,3,5,e.maxOwnPages].sort((S,C)=>S-C),N=()=>{const S=k.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/\/.*$/,"").replace(/^www\./,"");if(!S||e.signInSites.includes(S)||n.includes(S)){j("");return}r({signInSites:[...e.signInSites,S]}),j("")};return t.jsx(Zt,{boxed:!0,summary:"Advanced",children:t.jsxs("div",{className:"br-adv",children:[t.jsx(yd,{label:"First choice for every agent",hint:"Let them choose is right for almost everyone: a wrong guess costs one extra page load, never a stop.",children:t.jsx(Gt,{label:"First choice for every agent",value:w,onChange:S=>r({defaultRoute:S}),options:[{value:"auto",label:"Let them choose"},{value:"own",label:"Own browser only"},{value:"chrome",label:"Your Chrome first"}]})}),t.jsxs("div",{className:"br-adv-block",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsx("span",{className:"br-adv-title",children:"Agents with their own rule"}),t.jsx("span",{className:"br-adv-hint",children:"Also on each agent’s page, under Where it may look. A rule never allows what is off above."})]}),c.length?t.jsx("div",{className:"ui-list",children:c.map(S=>t.jsxs("div",{className:"ui-list-row",children:[t.jsx(On,{id:S.id,name:S.name,size:"sm"}),t.jsx("span",{className:"ui-list-main",children:t.jsx("span",{className:"ui-list-title",children:S.name})}),t.jsxs("span",{className:"ui-list-side",children:[t.jsx(pv,{value:S.browser??"auto",label:`Where ${S.name} may look`,apps:i,disabled:s,onChange:C=>v(S.id,C)}),t.jsx($,{size:"sm",variant:"ghost",disabled:s,onClick:()=>v(S.id,"auto"),children:"Remove"})]})]},S.id))}):t.jsx("p",{className:"br-adv-empty",children:"No agent has its own rule. Every agent follows the first choice."}),h?t.jsxs(ne,{children:[t.jsxs("select",{className:"br-select","aria-label":"Agent",value:m,onChange:S=>p(S.target.value),children:[t.jsx("option",{value:"",children:"Choose an agent"}),u.map(S=>t.jsx("option",{value:S.id,children:S.name},S.id))]}),t.jsx(pv,{value:g,label:"Its rule",apps:i,onChange:x}),t.jsx(ot,{}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>f(!1),children:"Cancel"}),t.jsx($,{size:"sm",variant:"accent","aria-label":"Add this rule",disabled:s||!m||g==="auto",onClick:()=>{v(m,g),f(!1),p("")},children:"Add"})]}):t.jsx(ne,{children:t.jsxs($,{size:"sm",disabled:u.length===0,onClick:()=>f(!0),children:[t.jsx("span",{"aria-hidden":"true",children:"+"})," Give an agent its own rule"]})})]}),t.jsxs("div",{className:"br-adv-block",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsx("span",{className:"br-adv-title",children:"Sites that need your sign-in"}),t.jsx("span",{className:"br-adv-hint",children:"Always looked at in your Chrome while it is on and connected. buddi adds a site, outlined dashed, when it meets its sign-in page."})]}),e.signInSites.length||n.length?t.jsxs("span",{className:"br-sites",children:[e.signInSites.map(S=>t.jsxs("span",{className:"br-site-chip mono",children:[S,t.jsx("button",{type:"button","aria-label":`Remove ${S}`,disabled:s,onClick:()=>r({forgetSignInSite:S}),children:"×"})]},S)),n.map(S=>t.jsxs("span",{className:"br-site-chip mono","data-learned":"true",title:"buddi added this when it met its sign-in page",children:[S,t.jsx("button",{type:"button","aria-label":`Remove ${S}`,disabled:s,onClick:()=>r({forgetSignInSite:S}),children:"×"})]},S))]}):t.jsx("p",{className:"br-adv-empty",children:"None yet."}),t.jsxs("form",{className:"br-site-add",onSubmit:S=>{S.preventDefault(),N()},children:[t.jsx("input",{"aria-label":"A site that needs your sign-in",placeholder:"amazon.com",value:k,onChange:S=>j(S.target.value)}),t.jsx($,{size:"sm",type:"submit",disabled:s||!k.trim(),children:"Add"})]})]}),t.jsx(yd,{label:"Stop agents’ browsing lasts",hint:"What Stop in the Canvas does. Resume from the chat card, here, or /browser resume on Telegram.",children:t.jsx(Gt,{label:"Stop agents’ browsing lasts",value:e.stopExpiryMinutes===0?"until":"hour",onChange:S=>r({stopExpiryMinutes:S==="until"?0:60}),options:[{value:"hour",label:"An hour"},{value:"until",label:"Until I say"}]})}),t.jsx(yd,{label:"Pages open at once",hint:"In buddi’s own browser. One more waits its turn; nothing is refused.",children:t.jsx(Gt,{label:"Pages open at once",value:String(e.maxOwnPages),onChange:S=>r({maxOwnPages:Number(S)}),options:y.map(S=>({value:String(S),label:String(S)}))})}),t.jsx(yd,{label:"Show buddi’s browser as a window",hint:"Off: it works out of sight and you watch on the Canvas. On for the few sites that refuse a hidden browser.",children:t.jsx(Tu,{checked:e.showWindow,label:"Show buddi’s browser as a window",disabled:s,onChange:S=>r({showWindow:S})})}),t.jsx("p",{className:"br-adv-empty",children:"Missions run without you, so they look only in buddi’s own browser, never in your Chrome."})]})})}const LH="kmbckpnnjfggeffkkbmkggojnolkdokb",FH="pbfpjefkiijjgefblpnlnlpmeaddfbah",aR="https://chromewebstore.google.com/detail/pbfpjefkiijjgefblpnlnlpmeaddfbah",_H=[LH,FH].filter(Boolean);function zH(e,n){const s=i=>/^\d+(\.\d+){0,3}$/.test(i.trim())?i.trim().split(".").map(Number):null,r=s(e),a=s(n);if(!r||!a)return!1;for(let i=0;i<4;i++){const l=(r[i]??0)-(a[i]??0);if(l!==0)return l<0}return!1}async function UH(){var e;try{if(typeof chrome>"u"||!((e=chrome==null?void 0:chrome.runtime)!=null&&e.sendMessage))return null;for(const n of _H)try{const s=await chrome.runtime.sendMessage(n,{type:"buddi.status"});if(s!=null&&s.installed)return s}catch{}return null}catch{return null}}function BH(e=navigator){var s,r,a;const n=e.userAgent??"";return(s=e.userAgentData)!=null&&s.mobile||/Android|iPhone|iPad|iPod|Mobile/i.test(n)?"phone":(a=(r=e.userAgentData)==null?void 0:r.brands)!=null&&a.some(i=>/Chromium/i.test(i.brand))||/Chrome\/|Chromium\/|Edg\//.test(n)&&!/Firefox\/|OPR\//.test(n)?"chromium":"other"}function iR(e){try{return new URL(e).origin===window.location.origin}catch{return!1}}const ON=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 WH(e){const n=e.toLowerCase().replace(/\.$/,"");if(!n.includes(".")||ON.has(n))return!0;const s=n.slice(n.indexOf(".")+1);return ON.has(`*.${s}`)}function HH(e){return typeof e=="string"&&e.includes("*")}function KH(e){const n=/^(https?):\/\/([^/?#@\s]+)(?:[/?#]\S*)?$/i.exec(e.trim());if(n===null)return{ok:!1,reason:"invalid"};const[,s,r]=n;if(!r.startsWith("*.")||r.slice(2).includes("*"))return{ok:!1,reason:"placement"};let a;try{a=new URL(`${s.toLowerCase()}://${r.slice(2)}`)}catch{return{ok:!1,reason:"invalid"}}const i=a.hostname;return i===""||i.startsWith("[")||/^[\d.]+$/.test(i)||i.startsWith(".")||i.includes("..")?{ok:!1,reason:"invalid"}:WH(i)?{ok:!1,reason:"public-suffix"}:{ok:!0,value:{pattern:`${a.protocol}//*.${a.host}`,protocol:a.protocol,suffix:i,port:a.port}}}const DN=["every-time","first-time","pre-approved"];function lR(e){const n=DN.indexOf(e);return DN.slice(0,n<0?1:n+1)}function tl(e){return e.endsWith(".account")}const VH="Stored, not usable until it has a binding.";function GH(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==="http.basic"?"the plugin, then the host — e.g. calendar *.icloud.com":e==="http.bearer"?"the plugin, then the host — e.g. calendar www.googleapis.com":e==="developer.env"?"the workspace, then the variable name — e.g. cour des comptes ADMIN_PASSWORD":tl(e)?"the account id, e.g. acct-1":'the place, as JSON — e.g. {"host":"localhost","header":"Authorization"}'}const oR={"browser.form.data":{hint:"an origin, then the field name",build:(e,n)=>({origin:e,field:n})},"http.header":{hint:"a host, then the header name",build:(e,n)=>({host:e,header:n})},"http.url":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"http.basic":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"http.bearer":{hint:"a plugin, then the host",build:(e,n)=>({plugin:e,host:n})},"developer.env":{hint:"a workspace, then the variable name",build:(e,n)=>({workspace:e,variable:n})}},YH="A wildcard may only stand for the leftmost part of a site, like *.wikimedia.org.",qH=e=>`That is a public suffix; ${e} would match every site.`,LN="Give the site as an origin, like https://en.wikipedia.org.";function FN(e){const n=/^[a-z][a-z0-9+.-]*:\/\//i.test(e)?e:["https:","//",e].join("");if(HH(e)){const s=KH(n);if(s.ok)return{ok:!0,target:s.value.pattern};if(s.reason==="placement")return{ok:!1,error:YH};if(s.reason==="public-suffix"){const r=n.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/[/?#:].*$/,"").toLowerCase();return{ok:!1,error:qH(r)}}return{ok:!1,error:LN}}try{const s=new URL(n);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:LN}}}function QH(e){const n=e.search(/\s\S+\s*$/);if(n<=0)return null;const s=e.slice(n).trim(),r=e.slice(0,n).trim();return r&&s?[r,s]:null}function JH(e,n){const s=n.trim();if(s==="")return{ok:!1,error:"Give the exact place this value may go."};if(s.startsWith("{"))try{const i=JSON.parse(s);return i!==null&&typeof i=="object"&&!Array.isArray(i)?{ok:!0,target:i}:{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 FN(s);if(e==="browser.native.type"||tl(e))return{ok:!0,target:s};const r=oR[e];if(r===void 0)return{ok:!0,target:s};const a=QH(s);if(a===null)return{ok:!1,error:`${e} needs both: ${r.hint}.`};if(e==="browser.form.data"){const i=FN(a[0]);return i.ok?{ok:!0,target:r.build(i.target,a[1])}:i}return{ok:!0,target:r.build(a[0],a[1])}}function XH(e){if(typeof e=="string")return e;try{return JSON.stringify(e)??""}catch{return""}}function cR(e,n){if(typeof n=="string")return n;if(n!==null&&typeof n=="object"&&!Array.isArray(n)){const s=n,r=oR[e];if(r!==void 0){const a=Object.keys(r.build("a","b")),i=a.map(l=>s[l]);if(a.every(l=>typeof s[l]=="string"))return i.join(" · ")}}try{return JSON.stringify(n)??String(n)}catch{return String(n)}}const Ro="accounts.provider";function uR(e,n){if(typeof e!="object"||e===null)return[];const s=e[n];return Array.isArray(s)?s.flatMap(r=>{if(typeof r!="object"||r===null)return[];const a=r.place,i=r.count;return typeof a!="string"||typeof i!="number"||!(i>0)?[]:[{place:a,count:i}]}):[]}function dR(e){const n=e.map(({place:s,count:r})=>`${r.toLocaleString("en-GB")} ${r===1?s.replace(/s$/,""):s}`);return n.length<=1?n[0]??"":`${n.slice(0,-1).join(", ")} and ${n[n.length-1]}`}function ZH(e){const n=uR(e,"found");return n.length?`The value already sits in ${dR(n)}.`:""}function eK(e){const n=uR(e,"scrubbed");return n.length?`Replaced with ‹secret:…› in ${dR(n)}.`:""}const tK=/^(PROVIDER_ACCOUNT_|CODEX_ACCOUNT_|ANTHROPIC_ACCOUNT_|OLLAMA_DEVICE_)/,nK=/^MCP_(TOKEN|ENV|CONNECTION)_/,hR="GMAIL_APP_PASSWORD";function ya(e){const n=e.usedBy??[],s=e.bindings.map(r=>r.kind);if(n.some(r=>r.kind==="mailbox")||s.includes("email.account")||e.name===hR)return"mail";if(n.some(r=>r.kind==="model-account")||s.includes(Ro)||tK.test(e.name))return"models";if(n.some(r=>r.kind==="connection")||s.includes("mcp.env")||nK.test(e.name))return"connections";for(const r of e.bindings){if((r.kind==="http.url"||r.kind==="http.basic"||r.kind==="http.bearer")&&gy(r.target)&&typeof r.target.plugin=="string")return`plugin:${r.target.plugin}`;if(tl(r.kind))return`plugin:${r.kind.slice(0,-8)}`}return"mine"}function sK(e){if(e==="mine")return{title:"Your secrets",aside:"Agents fill these where you allow, without seeing them."};if(e==="mail")return{title:"Mail",aside:"Mailbox passwords. A new one is set on the Email page, which tests it first."};if(e==="models")return{title:"Model accounts",aside:"Managed in Model accounts."};if(e==="connections")return{title:"Connections",aside:"Managed in Connections."};const n=e.slice(7);return n==="calendar"?{title:"Calendar links and sign-ins",aside:"Private links and app passwords, used only by the calendar plugin."}:{title:n.charAt(0).toUpperCase()+n.slice(1),aside:`Kept for the ${n} plugin.`}}function rK(e,n){const s=r=>r==="mine"?0:r==="mail"?1:r==="models"?3:r==="connections"?4:2;return s(e)-s(n)||e.localeCompare(n)}function fR(e){return e==="models"||e==="connections"}function gy(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function _N(e){const n=e.replace(/^[a-z][a-z0-9+.-]*:\/\//i,"").replace(/\/.*$/,"").replace(/^www\./,"");return n.startsWith("*.")?`any ${n.slice(2)} site`:n}const xy=e=>(e.usedBy??[]).flatMap(n=>n.kind==="mailbox"?[n]:[]),xm=e=>(e.usedBy??[]).find(n=>n.kind==="model-account"),vy=e=>(e.usedBy??[]).find(n=>n.kind==="connection");function yc(e,n=new Map){var r,a;const s=ya(e);if(s==="mail"){const i=xy(e)[0];return i?`${i.provider==="Email"?"Mailbox":i.provider} ${i.auth==="xoauth2"?"sign-in":"app password"}`:"Old mailbox password"}if(s==="models"){const i=xm(e),l=(i==null?void 0:i.id)??((r=e.bindings.find(c=>c.kind===Ro&&typeof c.target=="string"))==null?void 0:r.target),o=typeof l=="string"?n.get(l):void 0;return(o==null?void 0:o.label)??(i==null?void 0:i.label)??"Old model account key"}if(s==="connections")return((a=vy(e))==null?void 0:a.name)??"Old connection sign-in";if(s.startsWith("plugin:")){const i=/^[^:]{1,40}:\s+(.+)$/.exec(e.name);return i?i[1]:e.name}return e.login?`Login · ${e.login.site}`:e.name}function mR(e){const n=e.indexOf("@");return n>0?`${e.slice(0,Math.min(n,24))}@…`:e.length>24?`${e.slice(0,23)}…`:e}function aK(e,n){const s=new Date(e);if(Number.isNaN(s.getTime()))return"";try{return new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",...n?{timeZone:n}:{}}).format(s)}catch{return new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short"}).format(s)}}function iK(e,n){const s=e.login;if(!s)return null;const r=aK(s.savedAt,n);return[s.username?`for ${mR(s.username)}`:null,r?`saved ${r}`:null].filter(Boolean).join(" · ")}function lK(e,n){var r,a,i;if(ya(e)!=="models")return null;const s=((r=xm(e))==null?void 0:r.id)??((a=e.bindings.find(l=>l.kind===Ro&&typeof l.target=="string"))==null?void 0:a.target);return typeof s=="string"?((i=n.get(s))==null?void 0:i.provider)??null:null}function pR(e,n){const s=gy(n)?n:{},r=a=>typeof s[a]=="string"?s[a]:"";return e==="browser.field"&&typeof n=="string"?`Filled on ${_N(n)}`:e==="browser.form.data"&&r("origin")?`Filled into “${r("field")}” on ${_N(r("origin"))}`:e==="browser.native.type"&&typeof n=="string"?`Typed into the app ${n}`:(e==="http.header"||e==="http.url"||e==="http.basic"||e==="http.bearer")&&r("host")?`Sent only to ${r("host")}`:e==="developer.env"&&r("variable")?`Given to ${r("workspace")} as ${r("variable")}`:e==="mcp.env"&&r("variable")?`Given to a program as ${r("variable")}`:e==="email.account"?"Used by a mailbox":e===Ro?"Used by a model account":tl(e)?`Used by a ${e.slice(0,-8)} account`:`Goes to ${cR(e,n)}`}function oK(e,n){return tl(e)||e===Ro?"Signed in":pR(e,n).replace(/^Sent only to/,"Sent to")}const cK={"api-key":"API key for this model account",chatgpt:"ChatGPT sign-in for this model account","anthropic-oauth":"Claude sign-in for this model account","device-key":"Ollama device key for this model account"};function uK(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function jy(e){const n=ya(e);if(n==="mail"){const i=xy(e).map(l=>l.address);return i.length?`Used by the ${i.length===1?"mailbox":"mailboxes"} ${uK(i)}`:e.name===hR?"From the old .env setup":"No mailbox uses it"}if(n==="models"){const i=xm(e);return i?cK[i.auth]??"Key for this model account":"No model account uses it"}if(n==="connections"){const i=vy(e);if(i!=null&&i.variable)return`Given to the program as ${i.variable}`;const l=e.bindings.find(c=>c.kind==="http.header"),o=l&&gy(l.target)&&typeof l.target.host=="string"?l.target.host:null;return o?`Sign-in token · sent only to ${o}`:i?"Sign-in for this connection":"No connection uses it"}if(e.bindings.length===0)return"";const s=e.bindings.map(i=>pR(i.kind,i.target));let r=s.length<=2?s.join(" · "):`${s[0]} and ${s.length-1} more places`;const a=new Set(e.bindings.map(i=>i.rule==="first-time"&&i.firstApprovedAt!==null?"pre-approved":i.rule));return a.size===1&&a.has("every-time")&&(r+=" · asks you every time"),a.size===1&&a.has("first-time")&&(r+=" · asks you the first time"),e.totp&&(r+=" · a fresh code each time"),r}function dK(e,n=Date.now()){return e.lastUse?`Last used ${Ge(e.lastUse.at,n)}`:"Never used"}function gv(e){return mr("email","settings",{account:e,set:"password"})}function gR(e){var s,r;const n=ya(e);if(n==="models"){const a=(s=xm(e))==null?void 0:s.id;return{label:"Managed in Model accounts",href:a?FA(a):Fe("accounts")}}if(n==="connections"){const a=(r=vy(e))==null?void 0:r.id;return{label:"Managed in Connections",href:a?_A(a):Fe("connections")}}return null}function xR(e){const n=/is not bound to (.+?)\.?$/.exec(e);if(!n)return null;const s=n[1];return/[0-9a-f]{8}-[0-9a-f]{4}-/i.test(s)?null:s}function vR(e,n=Date.now()){if(e.unused)return null;const s=ya(e),r=xy(e)[0],a=gR(e),i=()=>r?{label:"Set password",href:gv(r.id)}:a?{label:s==="models"?"Fix in Model accounts":"Fix in Connections",href:a.href}:{label:"Set a value",action:"replace"},l=e.lastUse,o=l?Ge(l.at,n):"",c=(l==null?void 0:l.detail)??"";if(e.hasValue===!1||(l==null?void 0:l.outcome)==="refused"&&/has no value stored/.test(c))return{text:"No value stored.",fix:i()};if(r!=null&&r.loginFailedAt)return{text:`${r.provider==="Email"?"The mail server":r.provider} turned it down at sign-in ${Ge(r.loginFailedAt,n)}.`,fix:{label:"Set password",href:gv(r.id)}};if((l==null?void 0:l.outcome)==="refused"){if(/vault is locked/.test(c))return{text:`Held back ${o}: the vault was locked.`,fix:null};if(/TOTP secret/.test(c))return{text:`Held back ${o}: a one-time code goes only into a field on a website.`,fix:null};if(/is not bound to/.test(c)){const u=s==="mine"?xR(c):null;return{text:u?`Held back ${o}: it was asked for at ${u}, where it may not go.`:`Held back ${o}: it was asked for somewhere it may not go.`,fix:s==="mine"?{label:"Change where it may go",action:"places"}:null}}return{text:`Held back ${o}: ${wR(c||null)}.`,fix:null}}if((l==null?void 0:l.outcome)==="failed"){const u=r?i():a?null:{label:"Replace value",action:"replace"};return{text:`Didn’t go through ${o}${c?`: ${c.replace(/\.$/,"")}`:""}.`,fix:u}}return(l==null?void 0:l.outcome)==="pending"?{text:`Waiting for your approval since ${o}.`,fix:{label:"Review",href:to}}:s==="mine"&&e.bindings.length===0?{text:"Can’t be used anywhere until you choose where it may go.",fix:{label:"Choose where it may go",action:"places"}}:null}function jR(e){if(!e.unused)return"";const n=ya(e);return n==="mail"?"Not used by anything — no mailbox uses it any more.":n==="models"?"Not used by anything — no model account uses it any more.":n==="connections"?"Not used by anything — no connection uses it any more.":"Not used by anything — what it was for is gone."}function xv(e){return e.usageUnknown&&!e.unused?"Couldn’t check what uses it just now.":""}function Pl(e){return!!e.unused&&!fR(ya(e))}function hK(e){if(e.unused||e.bindings.length===0)return"Nothing uses it, so nothing stops working.";const n=jy(e).split(" · ")[0]??"";return n.startsWith("Filled on ")?`Agents can no longer fill it on ${n.slice(10)}.`:n.startsWith("Sent only to ")?`Agents can no longer send it to ${n.slice(13)}.`:`Whatever uses it stops working: ${n.charAt(0).toLowerCase()}${n.slice(1)}.`}const fK={"every-time":"Every time","first-time":"The first time, then not again","pre-approved":"Never — allowed ahead of time"};function mK(e){const n={"browser.field":"A field on a website","browser.form.data":"A form field, by its name","browser.native.type":"An app on this computer","http.header":"A request to a host","http.url":"A plugin’s web address","http.basic":"A plugin’s sign-in","http.bearer":"A plugin’s account sign-in","developer.env":"A workspace variable","mcp.env":"A program’s variable",[Ro]:"A model account"};return n[e]?n[e]:tl(e)?`A ${e.slice(0,-8)} account`:e}const pK={"every-time":"Every time","first-time":"The first time","pre-approved":"Never"};function wR(e){if(!e)return"buddi didn’t hand it over";if(/has no value stored/.test(e))return"no value was stored";if(/vault is locked/.test(e))return"the vault was locked";if(/TOTP secret/.test(e))return"a one-time code goes only into a field on a website";const n=/is not bound to/.test(e)?xR(e):void 0;return n!==void 0?n?`asked for at ${n}, where it may not go`:"asked for somewhere it may not go":e.replace(/\.$/,"")}function gK(e){return e==="browser.field"?"www.pnc.com":e==="browser.form.data"?"www.pnc.com card-number":e==="browser.native.type"?"com.bank.app":e==="http.header"?"api.github.com Authorization":e==="http.url"?"calendar calendar.google.com":e==="http.basic"?"calendar caldav.fastmail.com":e==="http.bearer"?"calendar www.googleapis.com":e==="developer.env"?"my-app ADMIN_PASSWORD":tl(e)?"acct-1":'{"host":"localhost","header":"Authorization"}'}function qh(e){return lR(e).includes("first-time")?"first-time":e}function xK(e){const n=oK(e.kind,e.target);return e.outcome==="refused"?{text:`Held back — ${wR(e.detail)}`,tone:"warning"}:e.outcome==="failed"?{text:`Didn’t go through — ${(e.detail??n).replace(/\.$/,"")}`,tone:"warning"}:e.outcome==="pending"?{text:`Asked for your approval · ${n}`}:{text:n}}const vK=2*6e4,jK=2e3;function wK({login:e,onDone:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(null),[l,o]=d.useState(!1);d.useEffect(()=>{o(!1),i(null);const f=window.setTimeout(n,vK);return()=>window.clearTimeout(f)},[e.id]),d.useEffect(()=>{if(!l)return;const f=window.setTimeout(n,jK);return()=>window.clearTimeout(f)},[l]);const c=async f=>{r(!0),i(null);try{const m=await A.browserLogin(e.id,f);if(f==="save"&&m.outcome==="saved"){o(!0);return}if(f==="save"&&m.outcome==="gone"){i({reason:"That sign-in is no longer held. Add it in Keys and secrets.",retry:!1});return}n()}catch(m){i({reason:m instanceof Error?m.message:String(m),retry:f==="save"})}finally{r(!1)}},u=e.update===!0;if(l)return t.jsxs(G,{tone:"good",role:"status",title:u?`Updated the login for ${e.site}`:`Saved the login for ${e.site}`,children:["Agents can sign in there now without seeing it. It’s under ",t.jsx("a",{className:"wb-link",href:Fe("secrets"),children:"Keys and secrets"}),"."]});const h=e.username?`For ${mR(e.username)}. `:"";return t.jsxs("section",{className:"br-login","data-testid":"save-login","aria-label":u?"Update this login":"Save this login",children:[t.jsx(G,{tone:"accent",role:"status",title:u?`Update the login for ${e.site}?`:`Save this login for ${e.site}?`,action:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",disabled:s,onClick:()=>void c("never"),children:"Never for this site"}),t.jsx($,{size:"sm",disabled:s,onClick:()=>void c("later"),children:"Not now"}),t.jsx($,{size:"sm",variant:"accent",disabled:s,onClick:()=>void c("save"),children:u?"Update":"Save"})]}),children:u?`${h}buddi replaces the password it keeps under Keys and secrets with the one you just used.`:`${h}buddi keeps it under Keys and secrets, and agents use it without ever seeing it.`}),a?t.jsx(G,{tone:"critical",role:"alert",action:a.retry?t.jsx($,{size:"sm",disabled:s,onClick:()=>void c("save"),children:"Try again"}):void 0,children:a.reason}):null]})}const yK=2e3,bK=5,kK="(hover: none) and (pointer: coarse)",vv="buddi:browser-enlarge",NK=8e3,SK="https:";function CK(e){const n=e.trim();if(n===""||/\s/.test(n))return null;const s=/^[a-z][a-z0-9+.-]*:/i.test(n)&&!/^[^:]+:\d+(\/|$)/.test(n)?n:`${SK}//${n}`;try{const r=new URL(s);return r.protocol==="https:"||r.protocol==="http:"?r.toString():null}catch{return null}}function EK(e){if(!e)return null;try{const n=new URL(e);if(n.protocol!=="http:"&&n.protocol!=="https:")return{host:e,rest:"",secure:!1};const s=`${n.pathname==="/"?"":n.pathname}${n.search}${n.hash}`;return{host:n.host.replace(/^www\./,""),rest:s,secure:n.protocol==="https:"}}catch{return{host:e,rest:"",secure:!1}}}function zN(e,n){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}${n?`&tick=${n}`:""}`}function $K(e){var s,r,a;return(e==null?void 0:e.route)==="apps"&&((s=e.page)!=null&&s.appId)?gm(e.page.appId).charAt(0).toUpperCase():(py((r=e==null?void 0:e.page)==null?void 0:r.url)??((a=e==null?void 0:e.page)==null?void 0:a.title)??"·").charAt(0).toUpperCase()}function AK({status:e,error:n,reload:s,live:r,agentName:a="The agent",timezone:i,paused:l=null}){var bn,fn,Kn,en,kn,Pt,mn,tn,Te,st,H,de;const o=i??Intl.DateTimeFormat().resolvedOptions().timeZone,[c,u]=d.useState(0),[h,f]=d.useState(0),m=h>=bK;d.useEffect(()=>{if(!r||m)return;const et=window.setInterval(()=>{typeof document<"u"&&document.hidden||u(Qe=>Qe+1)},yK);return()=>window.clearInterval(et)},[r,m]);const p=d.useRef(null);r&&(e!=null&&e.session)&&(p.current=e);const[g,x]=d.useState(null);d.useEffect(()=>{!r&&p.current&&g===null&&x(Date.now()),r&&x(null)},[r]);const[k,j]=d.useState(null),v=d.useRef(null),w=((bn=e==null?void 0:e.page)==null?void 0:bn.id)??null;d.useEffect(()=>{const et=r&&e?zN(e):null;if(!et||typeof fetch!="function"||typeof(URL==null?void 0:URL.createObjectURL)!="function")return;let Qe=!1;return(async()=>{try{const Se=await fetch(et);if(!Se.ok||Qe)return;const Ve=await Se.blob();if(Qe)return;const nt=URL.createObjectURL(Ve);v.current&&URL.revokeObjectURL(v.current),v.current=nt,j(nt)}catch{}})(),()=>{Qe=!0}},[r,w]),d.useEffect(()=>()=>{v.current&&typeof(URL==null?void 0:URL.revokeObjectURL)=="function"&&URL.revokeObjectURL(v.current)},[]);const y=p.current,N=r?e:y??e,[b,S]=d.useState(!1),[C,T]=d.useState(null),[E,R]=d.useState(null),[M,O]=d.useState(!1),[I,z]=d.useState(null),[U,D]=d.useState(!1),P=pm(),K=fs(kK),F=d.useRef(null),[Q,_]=d.useState(null),re=d.useRef(null),Y=N==null?void 0:N.session,B=async et=>{S(!0),T(null);try{await et()}catch(Qe){T(Qe instanceof Error?Qe.message:String(Qe))}finally{S(!1),s()}},q=()=>void B(async()=>{var Se;z(null),D(!1);const et=Y==null?void 0:Y.id;et&&(re.current=et);const Qe=await A.browserControl("takeover",et);((Se=Qe.held)==null?void 0:Se.where)!=="chrome"&&(Qe.hand&&Qe.session&&(!et||Qe.session.id===et)?R(Qe.session.id):Qe.handReason==="browser-offline"?D(!0):z(Qe.handMessage??null))}),J=()=>void B(async()=>{R(null),O(!1),await A.browserControl("resume",Y==null?void 0:Y.id)}),Z=()=>void B(async()=>{R(null),await A.browserControl("stop",Y==null?void 0:Y.id)}),fe=()=>void B(async()=>{Y&&(await A.browserPin(Y.conversationId,"own"),await A.browserControl("release",Y.id),D(!1),z("This conversation uses buddi’s browser now. Send the agent a message and it opens the page there."))}),ve=r&&!!(e!=null&&e.session)&&e.state==="paused",Oe=ve&&((fn=e==null?void 0:e.held)==null?void 0:fn.where)==="chrome",W=ve&&!Oe&&E&&((Kn=e==null?void 0:e.session)==null?void 0:Kn.id)===E?E:null,se=ve?((en=e==null?void 0:e.session)==null?void 0:en.id)??null:null;d.useEffect(()=>{!se||E===se||K||b||(e==null?void 0:e.route)==="apps"||Oe||re.current!==se&&q()},[se,E,K]),d.useEffect(()=>{ve||(re.current=null)},[ve]);const[X,je]=d.useState(!1);d.useEffect(()=>{const et=()=>je(!0);return window.addEventListener(vv,et),()=>window.removeEventListener(vv,et)},[]),d.useEffect(()=>{if(!X)return;const et=Qe=>{Qe.key==="Escape"&&!Qe.defaultPrevented&&je(!1)};return window.addEventListener("keydown",et),()=>window.removeEventListener("keydown",et)},[X]);const[be,xe]=d.useState(null),[we,Ie]=d.useState(!1);d.useEffect(()=>{xe(null),Ie(!1)},[W]),d.useEffect(()=>{if(!we)return;const et=window.setTimeout(()=>Ie(!1),NK);return()=>window.clearTimeout(et)},[we]);const ke=et=>{xe(et),Ie(!1)},me=(et,Qe)=>{var Se;T(null),(Se=F.current)!=null&&Se.nav(et,Qe)&&Ie(!0)},$e=ve,_e=r&&!!(N!=null&&N.needsOwner),Le=!r&&!l,qe=py((kn=N==null?void 0:N.page)==null?void 0:kn.url)??((Pt=N==null?void 0:N.page)!=null&&Pt.appId?gm(N.page.appId):"the page"),yt=(N==null?void 0:N.route)==="chrome"?"in your Chrome · background tab":(N==null?void 0:N.route)==="apps"?`in ${qe}`:"in buddi’s browser",le=l?"Browsing is paused":((mn=N==null?void 0:N.page)==null?void 0:mn.title)||qe,Ce=l?`By you at ${Tt(new Date(l.at),o)} · ${l.until?`until ${Tt(new Date(l.until),o)}`:"until you resume it"}`:Oe?"You have the page · in your Chrome · it’s in front":$e?`You have the page · ${yt}`:Le?`${a} looked at ${qe} · done${g?` at ${Tt(new Date(g),o)}`:""}`:N?sR(N):"Opening the page…",Ze=r?N?zN(N,c):null:k,xt=(N==null?void 0:N.route)==="apps",Ct=W?be??((tn=N==null?void 0:N.page)==null?void 0:tn.url):(Te=N==null?void 0:N.page)==null?void 0:Te.url,It=r&&(we||!$e&&!!(e!=null&&e.busy)),Ot=N||r?t.jsx("button",{type:"button",className:"ui-icon-btn br-enlarge","data-size":"sm","aria-label":X?"Back to the side":"Enlarge the page",title:X?"Back to the side (Esc)":"Enlarge the page",onClick:()=>je(!X),children:t.jsx(oe,{name:X?"collapse":"expand"})}):null;return t.jsxs("div",{className:"br-canvas","data-testid":"browser-view","data-live":r?"true":"false","data-enlarged":X?"true":void 0,...X?{role:"dialog","aria-modal":!0,"aria-label":"The page, full size"}:{},children:[t.jsxs("header",{className:"br-head",children:[t.jsx("span",{className:"br-tile","aria-hidden":"true",children:l?t.jsx(RK,{}):$K(N)}),t.jsxs("span",{className:"br-head-text",children:[t.jsx("span",{className:"br-head-title",children:le}),t.jsxs("span",{className:"br-head-line",role:"status",children:[r&&!_e&&!$e&&!l?t.jsx("span",{className:"br-live","aria-hidden":"true"}):null,Ce]})]}),$e?t.jsxs(ne,{align:"end",children:[Oe?null:W?K?t.jsx($,{size:"sm",variant:M?"accent":"ghost","aria-pressed":M,onClick:()=>O(!M),children:"Type into the page"}):null:t.jsx($,{size:"sm",variant:"ghost",disabled:b,onClick:q,children:"Drive it here"}),t.jsx($,{size:"sm",variant:"accent",disabled:b,onClick:J,children:"Give it back"}),Ot]}):l?t.jsx($,{size:"sm",variant:"accent",disabled:b,onClick:()=>void B(async()=>{await A.browserControl("resume")}),children:"Resume"}):Le||!Y?Ot?t.jsx(ne,{align:"end",children:Ot}):null:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",disabled:b||!(N!=null&&N.enabled),onClick:Z,children:"Stop"}),t.jsx($,{size:"sm",variant:_e?"accent":void 0,disabled:b||!(N!=null&&N.enabled)||(N==null?void 0:N.state)==="paused",onClick:q,children:"Take over"}),Ot]})]}),$e?t.jsx("p",{className:"br-hand-said",role:"status",children:Oe?"Finish in Chrome, then give it back.":W?`Nothing you type here is kept. ${a} carries on when you give it back.${K?" Tap Type into the page to bring up your keyboard.":""}`:`${a} waits. It carries on when you give the page back.`}):null,C||n?t.jsx(G,{tone:"critical",role:"alert",children:C??n}):null,I?t.jsx(G,{tone:"warning",role:"status",children:I}):null,U?t.jsx(G,{tone:"warning",role:"status",title:"Your Chrome isn’t connected.",action:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",disabled:b,onClick:fe,children:"Use buddi’s browser"}),t.jsx($,{size:"sm",variant:"accent",disabled:b,onClick:q,children:"Try again"})]}),children:`Open Chrome on ${P} and try again, or let this conversation use buddi’s own browser.`}):null,Q?t.jsx(wK,{login:Q,onDone:()=>_(null)}):null,l?t.jsx("div",{className:"br-frame br-frame-empty",children:t.jsx("p",{className:"ui-empty",children:`No page is open. Agents look again when you resume${l.until?`, or by themselves at ${Tt(new Date(l.until),o)}`:""}.`})}):t.jsxs("div",{className:"br-window","data-state":W?"yours":_e?"waiting":Le?"done":"live",children:[t.jsx(TK,{app:xt?qe:null,title:((st=N==null?void 0:N.page)==null?void 0:st.title)||void 0,address:Ct,held:!!W,loading:It,onNav:me,onRefused:et=>T(et)}),W?t.jsx("div",{className:"br-frame","data-state":"yours",children:t.jsx(kH,{ref:F,sessionId:W,csrf:Qi(),onGiveBack:J,bare:!0,typing:M,onTyping:O,onLocation:ke,onLoginSeen:_})}):t.jsx("div",{className:"br-frame","data-state":_e?"waiting":Le?"done":"live",children:Ze?t.jsx("img",{className:"br-shot",src:Ze,alt:`What ${a} sees: ${((H=N==null?void 0:N.page)==null?void 0:H.title)||qe}`,onError:()=>f(et=>et+1),onLoad:()=>f(0)},r?((de=N==null?void 0:N.page)==null?void 0:de.id)??"live":"kept"):t.jsx("p",{className:"ui-empty br-frame-wait",children:r?"The page appears here as soon as it opens.":"No picture of this page was kept."})})]}),Le?t.jsx("p",{className:"br-ended",role:"status",children:"The page is closed. This is the last thing it showed."}):r&&m?t.jsx("p",{className:"br-ended",role:"status",children:"The newest picture didn’t load. Showing the one before it."}):null]})}function TK({app:e,title:n,address:s,held:r,loading:a,onNav:i,onRefused:l}){const[o,c]=d.useState(null),[u,h]=d.useState(!1);d.useEffect(()=>{c(null)},[s,r]),d.useEffect(()=>{if(!u)return;const x=window.setTimeout(()=>h(!1),1500);return()=>window.clearTimeout(x)},[u]);const f=EK(s),m=()=>{var x;s&&((x=navigator.clipboard)==null||x.writeText(s).then(()=>h(!0),()=>{}))},p=x=>{var j,v;if(x.preventDefault(),o===null)return;const k=CK(o);if(!k){l("That isn’t a web address. Type one like amazon.com/orders.");return}c(null),i("navigate",k),(v=(j=document.activeElement)==null?void 0:j.blur)==null||v.call(j)},g=x=>{x.key==="Escape"&&(x.preventDefault(),c(null),x.currentTarget.blur())};return t.jsxs("div",{className:"br-window-bar",role:"toolbar","aria-label":"Page controls",children:[e?t.jsx("span",{className:"br-window-app",children:e}):t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"br-window-nav",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Back",title:"Back",disabled:!r,onClick:()=>i("back"),children:t.jsx(oe,{name:"back"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Forward",title:"Forward",disabled:!r,onClick:()=>i("forward"),children:t.jsx(oe,{name:"forward"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Reload",title:"Reload",disabled:!r,onClick:()=>i("reload"),children:t.jsx(oe,{name:"reload"})})]}),r?t.jsxs("form",{className:"br-address","data-editable":"true",onSubmit:p,children:[t.jsx(UN,{secure:(f==null?void 0:f.secure)??!1}),t.jsx("input",{className:"br-address-input","aria-label":"Address",value:o??s??"",spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",onFocus:x=>x.currentTarget.select(),onChange:x=>c(x.target.value),onKeyDown:g}),t.jsx("button",{type:"button",className:"br-address-copy","aria-label":u?"Copied":"Copy the address",title:u?"Copied":"Copy the address",disabled:!s,onClick:m,children:t.jsx(oe,{name:u?"check":"copy",size:14})})]}):t.jsxs("button",{type:"button",className:"br-address","aria-label":u?"Address copied":"Copy the address",title:u?"Copied":"Copy the address",disabled:!s,onClick:m,children:[t.jsx(UN,{secure:(f==null?void 0:f.secure)??!1}),t.jsx("span",{className:"br-address-text",children:f?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"br-address-host",children:f.host}),t.jsx("span",{className:"br-address-rest",children:f.rest})]}):t.jsx("span",{className:"br-address-rest",children:"No address yet"})}),u?t.jsx("span",{className:"br-address-said","aria-hidden":"true",children:"Copied"}):null]})]}),n?t.jsx("span",{className:"br-window-title",title:n,children:n}):null,a?t.jsx("span",{className:"br-window-progress",role:"progressbar","aria-label":"Loading"}):null]})}function UN({secure:e}){return t.jsx("span",{className:"br-address-mark","aria-hidden":"true",children:t.jsx(oe,{name:e?"lock":"globe",size:12})})}function RK(){return t.jsxs("svg",{viewBox:"0 0 20 20",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("circle",{cx:"10",cy:"10",r:"7.2"}),t.jsx("path",{d:"M2.8 10h14.4M10 2.8c2.2 2.3 2.2 12.1 0 14.4M10 2.8c-2.2 2.3-2.2 12.1 0 14.4"})]})}function IK({status:e,timezone:n,reload:s}){var o;const r=n??Intl.DateTimeFormat().resolvedOptions().timeZone,a=((o=e==null?void 0:e.settings)==null?void 0:o.stopExpiryMinutes)??60,i=Tt(new Date(Date.now()+(a||60)*6e4),r),l=c=>void c().catch(()=>{}).finally(s);return t.jsx(ss,{label:"More for this page",items:[{heading:"Stop agents’ browsing"},{label:"For an hour",hint:`Every agent, every conversation; back on at ${i}`,onSelect:()=>l(()=>A.browserControl("stop"))},{label:"Until I say",hint:"Until you press Resume",onSelect:()=>l(()=>A.browserControl("stop",void 0,{forever:!0}))},"separator",e!=null&&e.settings&&!e.settings.showWindow?{label:"Show the window",hint:"A window on this machine, for sites that refuse a hidden browser",onSelect:()=>l(()=>A.browserSettings({showWindow:!0}))}:null,{label:"Open the full page view",hint:"This page over the whole window; Esc comes back",onSelect:()=>{window.dispatchEvent(new Event(vv))}}]})}function PK({agentId:e,conversationId:n}){const{data:s,error:r,reload:a}=ge(()=>A.host(e,n),[e,n],2e3),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=async p=>{c(!0),l(null);try{await p(),a()}catch(g){l(g instanceof Error?g.message:String(g))}finally{c(!1)}},h=(s==null?void 0:s.permissions)??[],f=(s==null?void 0:s.runs)??[],m=h.some(p=>!p.conversationId)?"Always allowed":h.length?"Conversation auto-mode":"Ask each time";return t.jsx(Zt,{className:"host-controls",summary:`Host execution · ${r?"Status unavailable":m}${f.length?` · ${f.length} running`:""}`,children:t.jsxs(ue,{gap:"sm",children:[t.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."}),t.jsx(ae,{message:i??r}),h.map(p=>t.jsxs(ne,{children:[t.jsxs("span",{children:[p.agentId,": ",p.conversationId?"conversation auto-mode":"always allowed"]}),t.jsx($,{size:"sm",disabled:o,onClick:()=>void u(()=>A.revokeHost(p.id)),children:"Revoke permission"})]},p.id)),h.length?null:t.jsx("p",{className:"muted",children:"The next command will ask for approval. Choose its permission scope there."}),f.map(p=>t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{children:[p.agentId," · ",t.jsx("span",{className:"mono",children:p.cwd})]}),t.jsx(zt,{children:p.command}),t.jsx(zt,{label:"Command output",children:p.stdout||p.stderr?`${p.stdout}
|
|
117
|
-
${p.stderr}`:"Waiting for output…"}),t.jsx(ne,{children:t.jsx($,{size:"sm",variant:"danger",disabled:o,onClick:()=>void u(()=>A.stopHost(p.agentId,p.conversationId)),children:"Stop command"})})]},p.actionId))]})})}const MK="browser.act",OK="browser.status",Zd=new Set([MK,OK]);function DK(e,n,s){const r=e==null?void 0:e.session;return!r||!n||!s||r.agentId!==n||r.conversationId!==s?null:{id:`host-browser:${r.id}`,title:"Page",tool:"Page",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function LK(e,n){return{...e,title:"Page",pinned:!1}}function FK(e,n,s){return!(e!=null&&e.stop)||!n||!s?null:{id:`host-browser:paused:${n}`,title:"Page",tool:"Page",renderer:"browser",source:"browser",pinned:!0,props:{},at:null,substantial:!1}}function BN(e,n){var r;let s=!1;for(const a of e)for(const i of a.blocks??[])if(i.type==="tool_use"&&i.id===n&&(s=Zd.has(i.name)),i.type==="tool_result"&&i.toolUseId===n&&((r=i.approval)==null?void 0:r.state)==="pending")return null;return s?n:null}const Up="Save a login for next time",_K=new Set(["Skip this site","Skip it","Keep paused","Leave it stopped"]),zK=["Use my Chrome","Use Chrome when it’s open","Open Chrome and I'll use it there"];function jv(e){if(!e||e.allowOther)return null;const n=new Set(e.options.map(h=>h.label)),s=(...h)=>h.some(f=>n.has(f)),r=s("Look")&&s("Carry on")?"look":s("Keep going")&&s("Stop here")?"budget":s("Resume")&&s("Keep paused","Leave it stopped")?"paused":s("Take over")&&s("Skip this site","Skip it")?"human":s("Take over")&&(s(Up,...zK)||/sign-in|asks for a code/i.test(e.question))?"signin":null;if(!r)return null;const[a,...i]=e.question.split(`
|
|
118
|
-
`),l=(a??"").trim().replace(/\.$/,""),o=e.options.find(h=>h.label===Up)??null,c=e.options.filter(h=>h.label!==Up),u=[...c.filter(h=>!h.recommended),...c.filter(h=>h.recommended)];return{kind:r,title:l,line:i.join(" ").trim(),saveLogin:o,actions:u}}function yR({card:e,disabled:n,onAnswer:s,site:r}){const a=`${_x}${r?`&site=${encodeURIComponent(r)}`:""}`;return t.jsxs("section",{className:"wb-question br-ask","data-kind":e.kind,"aria-label":e.kind==="paused"?"Browsing is paused":"The agent needs you","data-testid":"browser-ask",children:[t.jsxs("div",{className:"br-ask-head",children:[t.jsx("span",{className:"wb-question-kicker",children:e.kind==="paused"?"Paused":"Needs you"}),t.jsx("strong",{children:e.title}),e.line?t.jsx("span",{className:"br-ask-line",children:e.line}):null]}),t.jsx("div",{className:"wb-dock-section",children:t.jsxs(ne,{align:"end",children:[e.saveLogin?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-link",href:a,children:e.saveLogin.label}),t.jsx(ot,{})]}):null,e.actions.map(i=>t.jsx($,{size:"sm",variant:i.recommended?"accent":_K.has(i.label)?"ghost":void 0,disabled:n,title:i.hint??void 0,onClick:()=>s(i.label,i.id),children:i.label},i.id))]})})]})}const UK="web.read",BK="web.search",WK=new Set([UK,BK]);function HK({agentId:e,groupId:n,currentId:s,timezone:r,onSelect:a,onNew:i}){const[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(0);return d.useEffect(()=>{let m=!1;return o(null),u(null),(n?Je.groupConversations(n):Je.conversations(e,100)).then(p=>{m||o(p.conversations)}).catch(p=>{m||u(p instanceof Error?p.message:String(p))}),()=>{m=!0}},[e,n,h]),t.jsxs("section",{className:"wb-history","aria-label":"Past conversations",children:[t.jsxs("div",{className:"ui-toolbar",children:[t.jsx("strong",{children:"Past conversations"}),t.jsx("button",{className:"ui-btn",onClick:i,children:"New conversation"})]}),c?t.jsxs("p",{role:"alert",children:[c," ",t.jsx("button",{className:"ui-btn",onClick:()=>f(m=>m+1),children:"Retry"})]}):l===null?t.jsx("p",{className:"muted",children:"Loading conversations…"}):l.length===0?t.jsx("p",{className:"muted",children:"No conversations yet."}):t.jsx("ul",{children:l.map(m=>t.jsx("li",{children:t.jsxs("a",{href:n?ki(n,m.id):at(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(),a(m.id))},children:[t.jsx("span",{children:m.preview||m.opening||"Untitled conversation"}),t.jsxs("small",{children:[mt(m.lastMessageAt??m.startedAt??m.createdAt??null,r)," · ",m.messageCount," messages",m.id===s?" · Current":""]})]})},m.id))}),t.jsx("a",{href:"#/conversations",children:"View all agents’ conversation records ↗"}),(l==null?void 0:l.length)===100?t.jsx("p",{className:"muted",children:"Showing the 100 most recent conversations."}):null]})}const bR="buddi.dismissedTabs";function KK(){try{const e=JSON.parse(sessionStorage.getItem(bR)??"{}");return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).filter(([,n])=>Array.isArray(n)&&n.every(s=>typeof s=="string")))}catch{return{}}}function WN(e){try{sessionStorage.setItem(bR,JSON.stringify(Object.fromEntries(Object.entries(e).slice(-100))))}catch{}}const wv="",Bp=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|(\[[^\]\n]+\]\([^)\s]+\))|(https?:\/\/[^\s)]+)|(@[a-z][a-z0-9-]*)/gi;function Wp(e,n,s){const r=[];let a=0,i=0;Bp.lastIndex=0;for(let l=Bp.exec(e);l;l=Bp.exec(e)){l.index>a&&r.push(e.slice(a,l.index));const o=l[0],c=`${s}-${i++}`;if(l[1])r.push(t.jsxs("span",{className:"cv-code",children:[t.jsx("span",{className:"cv-mark",children:"`"}),o.slice(1,-1),t.jsx("span",{className:"cv-mark",children:"`"})]},c));else if(l[2])r.push(t.jsxs("span",{className:"cv-b",children:[t.jsx("span",{className:"cv-mark",children:"**"}),o.slice(2,-2),t.jsx("span",{className:"cv-mark",children:"**"})]},c));else if(l[3])r.push(t.jsxs("span",{className:"cv-i",children:[t.jsx("span",{className:"cv-mark",children:o[0]}),o.slice(1,-1),t.jsx("span",{className:"cv-mark",children:o[0]})]},c));else if(l[4]){const u=o.indexOf("](");r.push(t.jsxs("span",{className:"cv-link-md",children:[t.jsx("span",{className:"cv-mark",children:"["}),t.jsx("span",{className:"cv-link",children:o.slice(1,u)}),t.jsx("span",{className:"cv-mark",children:o.slice(u)})]},c))}else if(l[5])r.push(t.jsx("span",{className:"cv-link",children:o},c));else{const u=l.index>0?e[l.index-1]:" ",h=/[\s(]/.test(u)?n.find(f=>f.handle.toLowerCase()===o.slice(1).toLowerCase()):void 0;r.push(h?t.jsx("span",{className:"cv-chip",...h.accent,children:o},c):o)}a=l.index+o.length}return a<e.length&&r.push(e.slice(a)),r}function VK(e,n){const s=e.split(`
|
|
119
|
-
`);let r=null;return s.map((a,i)=>{const l=/^```(\w*)\s*$/.exec(a);if(r===null&&l){r=l[1]??"";const u=s.slice(i+1).some(h=>/^```\s*$/.test(h));return t.jsxs("div",{className:"cv-line","data-code":"open","data-unclosed":u?void 0:"true",children:[t.jsx("span",{className:"cv-mark",children:a}),r?t.jsx("span",{className:"cv-lang","aria-hidden":"true","data-paint-extra":"",children:D$(r)}):null]},i)}if(r!==null)return/^```\s*$/.test(a)?(r=null,t.jsx("div",{className:"cv-line","data-code":"close",children:t.jsx("span",{className:"cv-mark",children:a})},i)):t.jsx("div",{className:"cv-line","data-code":"body",children:t.jsx("span",{className:"cv-code-ink",children:a||wv})},i);const o=/^(#{1,3} )(.*)$/.exec(a);if(o)return t.jsxs("div",{className:"cv-line","data-h":o[1].length-1,children:[t.jsx("span",{className:"cv-mark",children:o[1]}),t.jsx("span",{className:"cv-h",children:Wp(o[2],n,String(i))})]},i);const c=/^(\s*)([-*]|\d+\.)( )(.*)$/.exec(a);return c?t.jsxs("div",{className:"cv-line",children:[c[1],t.jsx("span",{className:"cv-bullet",children:c[2]}),c[3],Wp(c[4],n,String(i))]},i):t.jsx("div",{className:"cv-line",children:a?Wp(a,n,String(i)):wv},i)})}const wy=(e,n)=>`${e}-opt-${n}`;function GK({id:e,items:n,active:s,onPick:r,phone:a,maxHeight:i}){let l=null;return t.jsxs("div",{className:"cv-pop","data-testid":"mention-popup",children:[t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Mention someone",style:i?{maxHeight:i}:void 0,children:n.map((o,c)=>{const u=o.group!==l?l=o.group:null;return t.jsxs(d.Fragment,{children:[u?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:u}):null,t.jsxs("div",{id:wy(e,c),role:"option","aria-selected":c===s,"aria-label":`${o.name}, @${o.handle}. ${o.effect}`,className:"cv-pop-row","data-mention":"true","data-active":c===s||void 0,onMouseDown:h=>{h.preventDefault(),r(o)},children:[t.jsx(On,{id:o.id,name:o.name,size:"sm",...o.face?{face:o.face}:{}}),t.jsxs("span",{className:"cv-pop-title",children:[o.name," ",t.jsxs("span",{className:"cv-pop-handle",children:["@",o.handle]})]}),c===s?t.jsx("span",{className:"cv-pop-effect",children:o.effect}):null,c===s&&!a?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},o.id)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," or ",t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," mention"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}function YK({id:e,items:n,active:s,onPick:r,phone:a,query:i,maxHeight:l}){if(n.length===0)return t.jsx("div",{className:"cv-pop","data-testid":"command-menu",children:t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Commands",children:t.jsxs("div",{className:"cv-pop-empty",role:"status",children:["No command called ",t.jsxs("span",{className:"mono",children:["/",i]}),". ",a?"Send sends it as text.":"Enter sends it as text."]})})});let o=null;return t.jsxs("div",{className:"cv-pop","data-testid":"command-menu",children:[t.jsx("div",{className:"cv-pop-list",id:e,role:"listbox","aria-label":"Commands",style:l?{maxHeight:l}:void 0,children:n.map((c,u)=>{const h=c.group!==o?o=c.group:null;return t.jsxs(d.Fragment,{children:[h?t.jsx("div",{className:"cv-pop-group",role:"presentation",children:h}):null,t.jsxs("div",{id:wy(e,u),role:"option","aria-selected":u===s,"aria-disabled":c.off||void 0,"aria-label":`/${c.name}${c.args?` ${c.args}`:""}: ${c.desc}`,className:"cv-pop-row","data-cmd":"true","data-active":u===s||void 0,"data-off":c.off||void 0,onMouseDown:f=>{f.preventDefault(),c.off||r(c)},children:[t.jsxs("span",{className:"cv-pop-cmd",children:["/",c.name,c.args?t.jsxs("span",{className:"cv-pop-args",children:[" ",c.args]}):null]}),t.jsx("span",{className:"cv-pop-desc",children:c.desc}),a?null:c.key?t.jsx("kbd",{className:"cv-kbd",children:c.key}):u===s?t.jsx("kbd",{className:"cv-kbd",children:"↵"}):null]})]},`${c.group}/${c.name}`)})}),a?null:t.jsxs("div",{className:"cv-pop-foot","aria-hidden":"true",children:[t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↑"}),t.jsx("kbd",{className:"cv-kbd",children:"↓"})," choose"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"↵"})," run"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Tab"})," add words"]}),t.jsxs("span",{children:[t.jsx("kbd",{className:"cv-kbd",children:"Esc"})," close"]})]})]})}const qK=350,QK=60;function JK({conversationId:e,onText:n,onNotice:s}){const[r,a]=d.useState("idle"),i=d.useRef("idle"),l=v=>{i.current=v,a(v)},o=d.useRef(null),c=d.useRef(null),u=d.useRef(null),h=d.useRef(null),f=d.useRef(null),m=d.useRef({onText:n,onNotice:s,conversationId:e});m.current={onText:n,onNotice:s,conversationId:e};const p=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},g=async()=>{if(i.current!=="idle")return;m.current.onNotice(null),l("starting"),c.current=null;let v;try{v=await M5(N=>{var b;return(b=f.current)==null?void 0:b.call(f,N)})}catch(N){h.current=null,l("idle"),m.current.onNotice(P5(N));return}const w=c.current;c.current=null;const y=i.current;if(w==="discard"||y!=="starting"){v.cancel(),y==="starting"&&l("idle");return}o.current=v,l("recording"),u.current=window.setTimeout(()=>void x(!1),T5),w&&x(w.sendNow)},x=async v=>{h.current=null;const w=o.current;if(!w){i.current==="starting"&&(c.current={sendNow:v});return}o.current=null,p(),l("transcribing");try{const y=await w.stop();if(y.size<=44){m.current.onNotice("Nothing was recorded.");return}const N=new File([y],`recording-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.wav`,{type:"audio/wav"}),b=await Je.attach(N),S=m.current.conversationId,C=await Je.transcribe({artifactId:b.artifactId,...S?{conversationId:S}:{}});m.current.onText(C.text,v)}catch(y){m.current.onNotice(y instanceof he||y instanceof Error?y.message:String(y))}finally{l("idle")}},k=()=>{h.current=null;const v=o.current;if(!v){i.current==="starting"&&(c.current="discard");return}o.current=null,p(),v.cancel(),l("idle")};d.useEffect(()=>{const v=w=>{if(h.current===null)return;const y=Date.now()-h.current;h.current=null,y>=qK&&x(w.shiftKey)};return window.addEventListener("pointerup",v),()=>window.removeEventListener("pointerup",v)},[]);const j=r==="starting"||r==="recording";return d.useEffect(()=>{if(!j)return;const v=w=>{w.isComposing||w.repeat||(w.key==="Escape"?(w.preventDefault(),w.stopPropagation(),k()):w.key==="Enter"&&(w.preventDefault(),w.stopPropagation(),x(w.shiftKey)))};return window.addEventListener("keydown",v,!0),()=>window.removeEventListener("keydown",v,!0)},[j]),d.useEffect(()=>()=>{var v;(v=o.current)==null||v.cancel(),p()},[]),{state:r,hold:()=>{h.current=Date.now(),g()},start:()=>{h.current=null,g()},finish:v=>void x(v),discard:k,levels:f}}function XK({disabled:e,voice:n}){const s=a=>{e||a.button>0||n.state!=="idle"||(a.preventDefault(),n.hold())},r=a=>{a.detail!==0||e||n.state!=="idle"||n.start()};return t.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:a=>a.preventDefault(),children:t.jsx(oe,{name:"mic"})})}function ZK({voice:e}){const n=d.useRef(null),s=e.state==="transcribing";return d.useEffect(()=>{var r;(r=n.current)==null||r.focus()},[]),t.jsxs("div",{className:"wb-listening",role:"group","aria-label":"Recording","data-phase":s?"transcribing":"listening",children:[t.jsx("p",{className:"wb-listening-label","aria-live":"polite",children:s?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wb-listening-spinner","aria-hidden":"true"}),"Transcribing…"]}):"Listening…"}),t.jsxs("div",{className:"wb-listening-row",children:[t.jsx(e9,{sink:e.levels,frozen:s}),t.jsx("button",{type:"button",className:"wb-send","data-variant":"quiet","aria-label":"Discard recording",title:"Discard (Escape)",disabled:s,onClick:()=>e.discard(),children:t.jsx(oe,{name:"close"})}),t.jsx("button",{ref:n,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:t.jsx(oe,{name:"check"})})]})]})}function e9({sink:e,frozen:n}){const[s,r]=d.useState(()=>Array(QK).fill(0));return d.useEffect(()=>{if(!n)return e.current=a=>r(i=>[...i.slice(1),a]),()=>{e.current=null}},[n]),t.jsx("div",{className:"wb-wave","aria-hidden":"true","data-testid":"waveform",children:s.map((a,i)=>t.jsx("span",{className:"wb-wave-bar",style:{"--level":a.toFixed(3)}},i))})}const t9="This browser cannot capture a tab. Chrome, Safari and Firefox can, on a secure address.",bd="The tab could not be captured. Try again, and pick the tab itself rather than the whole screen.",n9=e=>e instanceof Error&&(e.name==="NotAllowedError"||e.name==="AbortError");async function s9(e={}){var r;const n=e.media??(typeof navigator>"u"?void 0:navigator.mediaDevices);if(!n||typeof n.getDisplayMedia!="function")throw new Error(t9);let s;try{s=await n.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,selfBrowserSurface:"exclude",surfaceSwitching:"exclude",preferCurrentTab:!1})}catch(a){if(n9(a))return null;throw new Error(bd)}try{const a=e.document??document,i=a.createElement("video");i.muted=!0,i.playsInline=!0,i.srcObject=s,await new Promise((h,f)=>{i.onloadedmetadata=()=>h(),i.onerror=()=>f(new Error(bd))}),await i.play(),await new Promise(h=>{const f=i.requestVideoFrameCallback;typeof f=="function"?f.call(i,()=>h()):setTimeout(h,120)});const l=a.createElement("canvas");l.width=i.videoWidth,l.height=i.videoHeight;const o=l.getContext("2d");if(!o||l.width===0)throw new Error(bd);o.drawImage(i,0,0);const c=await new Promise(h=>l.toBlob(h,"image/png"));if(!c)throw new Error(bd);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(a=>a.stop())}}const HN="Send files once the agent has answered.",yv="wb-composer-input",r9="(max-width: 720px)",KN={desk:288,phone:240};function a9(e,n,s){const[r,a]=d.useState(void 0);return d.useEffect(()=>{if(!n)return;const i=window.visualViewport??null,l=()=>{const o=e.current;if(!o||typeof o.getBoundingClientRect!="function")return;const c=o.getBoundingClientRect().top-(i?i.offsetTop:0),u=Math.floor(c-(s?16:64)),h=s?KN.phone:KN.desk;a(u>0&&u<h?Math.max(u,96):void 0)};return l(),i==null||i.addEventListener("resize",l),i==null||i.addEventListener("scroll",l),window.addEventListener("resize",l),()=>{i==null||i.removeEventListener("resize",l),i==null||i.removeEventListener("scroll",l),window.removeEventListener("resize",l)}},[n,s,e]),r}const yy=d.forwardRef(function({disabled:n,running:s,onSend:r,onStop:a,agentName:i,draft:l,model:o,chrome:c,setupHref:u,thinking:h,onThinking:f,onOpenFile:m,mentions:p,team:g,onCommand:x,history:k,threadKey:j,conversationId:v,readAloud:w,onReadAloud:y,placeholder:N,slim:b},S){var Tn,Du,al;const C=j?`buddi.draft.${j}`:null,T=V=>{if(!V)return"";try{return window.localStorage.getItem(V)??""}catch{return""}},[E,R]=d.useState(()=>T(C)),[M,O]=d.useState(()=>E.length),[I,z]=d.useState([]),[U,D]=d.useState(!1),[P,K]=d.useState(null),[F,Q]=d.useState(!1),[_,re]=d.useState(null),Y=d.useRef(null),B=d.useRef(null),q=d.useRef(null),J=fs(r9),Z=`cv-pop-${d.useId().replace(/[^a-zA-Z0-9_-]/g,"")}`,fe=UD(),ve=d.useMemo(()=>{const V=He=>g==null?void 0:g.agents.find(an=>an.id===He),ze=(He,an)=>Hi(So(He??{id:an}));if(p)return p.map(He=>{const an=He.id??He.handle,Yn=V(an);return{id:an,handle:He.handle,name:He.name,effect:`Asks @${He.handle} in this room`,group:"In this room",accent:ze(Yn,an),...Yn?{face:Yn}:{}}});if(!g)return[];const We=g.agents.find(He=>He.roles.includes(zr)&&He.id!==g.selfId),Dt=g.agents.filter(He=>He.id!==g.selfId&&He!==We);return[...We?[{id:We.id,handle:We.handle,name:We.name,effect:`Borrows ${We.name} for this message`,group:"Borrow",accent:Hi({key:"buddi"}),face:We}]:[],...Dt.map(He=>({id:He.id,handle:He.handle,name:He.name,effect:`${i} asks @${He.handle}`,group:"Ask a teammate",accent:ze(He,He.id),face:He}))]},[p,g,i]),Oe=!p&&g?((Tn=g.agents.find(V=>V.roles.includes(zr)&&V.id!==g.selfId))==null?void 0:Tn.handle)??null:null,[W,se]=d.useState(!1),[X,je]=d.useState(0),be=!!x,xe=be&&Y_(E,M),we=!W&&ve.length>0?V_(E,M):null,Ie=!W&&be&&!we?G_(E,M):null,ke=we?ve.filter(V=>!xe||V.group!=="Borrow").filter(V=>V.handle.toLowerCase().startsWith(we.query.toLowerCase())||V.name.toLowerCase().startsWith(we.query.toLowerCase())).map(V=>xe?{...V,group:"Talk to",effect:`Talk to ${V.name} from here on`}:V).slice(0,8):[],me=d.useMemo(()=>[...DD(i,s),...FD(fe)],[i,s,fe]),$e=Ie?me.filter(V=>V.name.startsWith(Ie.query.toLowerCase())):[],_e=we&&ke.length>0?"mention":Ie?"slash":null,Le=_e==="mention"?ke:_e==="slash"?$e:[],qe=Le.length>0?Math.min(X,Le.length-1):-1,yt=a9(q,_e!==null,J),le=k??[],[Ce,Ze]=d.useState(-1),xt=d.useRef(E),Ct=d.useRef(C);if(Ct.current!==C){Ct.current=C;const V=T(C);xt.current=V,V!==E&&(R(V),O(V.length),Ze(-1),re(null))}const It=V=>{if(xt.current=V,!!C)try{V===""?window.localStorage.removeItem(C):window.localStorage.setItem(C,V)}catch{}},Ot=V=>{R(V.value),O(V.caret),se(!1),je(0),Ce<0&&It(V.value);const ze=B.current;ze&&(ze.value=V.value,ze.setSelectionRange(V.caret,V.caret),window.requestAnimationFrame(()=>{ze.focus(),ze.setSelectionRange(V.caret,V.caret)}))},bn=V=>{R(V),O(V.length),se(!1);const ze=B.current;ze&&(ze.value=V,ze.setSelectionRange(V.length,V.length))},fn=V=>!V.value.slice(0,V.selectionStart??V.value.length).includes(`
|
|
120
|
-
`),Kn=()=>E===""||Ce>=0&&E===le[Ce],en=()=>{Ce<0||(Ze(-1),bn(xt.current))},kn=I.some(V=>V.state==="uploading"),Pt=I.length>0,mn=s&&Pt,tn=!n&&!kn&&!mn&&E.trim()!=="",Te=V=>{const ze=[];for(const We of Array.from(V??[])){const Dt=`${We.name}:${We.size}:${Math.random().toString(36).slice(2,8)}`;ze.push(Dt);const He=We.type.startsWith("image/")&&typeof URL.createObjectURL=="function"?URL.createObjectURL(We):null;z(an=>[...an,{key:Dt,filename:We.name||"Pasted image",mime:We.type||"application/octet-stream",sizeBytes:We.size,thumbnail:He,state:"uploading"}]),Je.attach(We).then(an=>z(Yn=>Yn.map(vs=>vs.key===Dt?{...vs,state:"ready",uploaded:an}:vs))).catch(an=>z(Yn=>Yn.map(vs=>vs.key===Dt?{...vs,state:"failed",error:an instanceof he?an.message:String(an)}:vs)))}return ze},st=V=>{V.thumbnail&&typeof URL.revokeObjectURL=="function"&&URL.revokeObjectURL(V.thumbnail)},H=V=>{const ze=I.find(We=>We.key===V);ze&&(st(ze),ze.state==="ready"&&ze.uploaded&&Je.discardAttachment(ze.uploaded.artifactId).catch(()=>{})),z(We=>We.filter(Dt=>Dt.key!==V)),(_==null?void 0:_.kind)==="long"&&_.key===V&&re(null)};d.useImperativeHandle(S,()=>({addFiles:V=>{var ze;Te(V),(ze=B.current)==null||ze.focus()},focus:()=>{var V;return(V=B.current)==null?void 0:V.focus()}}));const de=d.useRef(I);de.current=I,d.useEffect(()=>()=>de.current.forEach(st),[]);const et=d.useRef(0);d.useEffect(()=>{if(!l||l.at===et.current)return;et.current=l.at;const V=E.trim()==="";R(We=>We.trim()===""?l.text:We),Ce<0&&V&&It(l.text);const ze=B.current;ze&&(ze.focus(),window.requestAnimationFrame(()=>{ze.setSelectionRange(ze.value.length,ze.value.length),O(ze.value.length)}))},[l]);const Qe=()=>{Ze(-1),It(""),R(""),O(0),re(null),se(!1)},Se=(V,ze)=>{if(x){if(V==="stop"&&!s){Qe();return}Qe(),x(V,ze)}},Ve=V=>{const ze=(V??E).trim();if(V===void 0?!tn:n||kn||mn||ze==="")return;const We=V===void 0&&x?q_(ze):null;if(We&&qk(We.name)&&I.length===0){if(We.name==="use"&&We.arg===""){Ot({value:"/use @",caret:6});return}Se(We.name,We.arg.replace(/^@/,""));return}const Dt=I.filter(He=>He.state==="ready"&&He.uploaded).map(He=>He.uploaded);r(ze,Dt),I.forEach(st),Qe(),z([])},nt=V=>{if(we){if(xe&&x){Se("use",V.handle);return}Ot(Q_(E,M,we.start,V.handle))}},Ue=(V,ze)=>{if(V.off)return;const We=E.slice(M);if(ze||_D(V)){const He=`/${V.name} ${V.name==="use"?"@":""}`;Ot({value:He+We.replace(/^\S*/,"").replace(/^ /,""),caret:He.length});return}if(V.source==="chat"&&qk(V.name)){Se(V.name,"");return}const Dt=`/${V.name}`;if(n||kn||mn){Ot({value:`${Dt} `,caret:Dt.length+1});return}Ve(Dt)},rn=V=>{if(V.nativeEvent.isComposing)return;if(_e&&Le.length>0){if(V.key==="ArrowDown"){V.preventDefault(),je((qe+1)%Le.length);return}if(V.key==="ArrowUp"){V.preventDefault(),je((qe-1+Le.length)%Le.length);return}if(V.key==="Enter"&&!V.shiftKey||V.key==="Tab"){V.preventDefault();const He=Le[qe];_e==="mention"?nt(He):Ue(He,V.key==="Tab");return}}if(_e&&V.key==="Escape"){V.preventDefault(),se(!0);return}if(V.key==="ArrowUp"&&!V.shiftKey&&!V.altKey&&!V.metaKey&&!V.ctrlKey){const He=V.currentTarget;if(le.length>0&&Ce+1<le.length&&fn(He)&&Kn()){V.preventDefault(),Ce<0&&(xt.current=E),Ze(Ce+1),bn(le[Ce+1]);return}}if(V.key==="ArrowDown"&&!V.shiftKey&&!V.altKey&&!V.metaKey&&!V.ctrlKey&&Ce>=0&&E===le[Ce]){if(V.preventDefault(),Ce===0){en();return}Ze(Ce-1),bn(le[Ce-1]);return}if(V.key==="Escape"&&Ce>=0){V.preventDefault(),en();return}if(V.key==="Escape"&&s&&x){V.preventDefault(),a();return}const ze=V.currentTarget,We=ze.selectionStart??M,Dt=ze.selectionStart===ze.selectionEnd;if(V.key==="Tab"&&Dt&&!V.altKey&&!V.metaKey&&!V.ctrlKey){const He=Z_(E,We,V.shiftKey);if(He){V.preventDefault(),Ot(He);return}}if(V.key==="Enter"&&!V.shiftKey&&!V.metaKey&&!V.ctrlKey&&!V.altKey){const He=Dt?X_(E,We):null;if(He){V.preventDefault(),Ot(He);return}if(gc(E,We))return;V.preventDefault(),Ve();return}V.key==="Enter"&&(V.metaKey||V.ctrlKey)&&(V.preventDefault(),Ve())},pt=V=>{var vs,Ca;const ze=Array.from(((vs=V.clipboardData)==null?void 0:vs.files)??[]);if(ze.length>0){V.preventDefault(),Te(ze);return}const We=typeof((Ca=V.clipboardData)==null?void 0:Ca.getData)=="function"?V.clipboardData.getData("text/plain"):"";if(We==="")return;const Dt=V.currentTarget,He=Dt.selectionStart??M,an=Dt.selectionEnd??He,Yn=E.slice(0,He)+E.slice(an);if(We.length>H_){V.preventDefault();const Ea=new File([We],"pasted-text.txt",{type:"text/plain"}),[Qr]=Te([Ea]),xi=We.replace(/\n$/,"").split(`
|
|
121
|
-
`).length,Lu=`${xi} ${xi===1?"line":"lines"} · ${Math.ceil(We.length/1024)} KB`;z(Jr=>Jr.map(il=>il.key===Qr?{...il,detail:Lu}:il)),Yn!==E&&Ot({value:Yn,caret:He}),re({kind:"long",key:Qr,text:We,caret:He});return}if(e4(We)&&!gc(Yn,He)){V.preventDefault();const Ea=t4(We),Qr=n4(Yn,He,We,Ea);re({kind:"fenced",lang:Ea,block:Qr.value.slice(He,Qr.caret),text:We}),Ot(Qr)}},xs=()=>{if(_){if(_.kind==="fenced"){const V=E.indexOf(_.block);V>=0&&Ot({value:E.slice(0,V)+_.text+E.slice(V+_.block.length),caret:V+_.text.length})}else{H(_.key);const V=Math.min(_.caret,E.length);Ot({value:E.slice(0,V)+_.text+E.slice(V),caret:V+_.text.length})}re(null)}},Vn=I.filter(V=>V.state==="failed"),Gn=Vn.length,Ds=JK({conversationId:v??null,onNotice:K,onText:(V,ze)=>{const We=E.trim()===""?V:`${E.replace(/\s+$/,"")} ${V}`;if(ze){Ve(We);return}bn(We),Ce<0&&It(We)}}),An=Ds.state!=="idle",pi=d.useRef(!1);d.useEffect(()=>{var V;pi.current&&!An&&((V=B.current)==null||V.focus()),pi.current=An},[An]);const Xs=_e!==null&&!An&&!n,yr=ww(E,M),gi=gc(E,M),ut=s4(E).map(V=>ve.find(ze=>ze.handle.toLowerCase()===V)).filter(V=>!!V),qr=Oe!==null&&((Du=L$(E))==null?void 0:Du.handle)===Oe.toLowerCase(),Rm=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform||navigator.userAgent),hb=V=>V.group==="Borrow"?qr?`borrows ${V.name} for this message`:`${i} asks them`:V.group==="In this room"?"is asked in this room":`${i} asks them`,Na=Gn>0?Gn===1&&((al=Vn[0])!=null&&al.error)?Vn[0].error:`${Gn} files failed to upload and will not be sent`:P??(mn?HN:null),Ou=Na??(s||Xs?null:yr?"Enter continues the list · Enter on an empty item ends it · Tab indents":gi?`In a code block Enter adds a line · ${Rm?"⌘":"Ctrl+"}Enter sends`:ut.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"cv-chip",...ut[0].accent,children:["@",ut[0].handle]})," ",hb(ut[0]),ut.length>1?` · and ${ut.length-1} more`:""]}):E!==""?"Enter sends, Shift+Enter for a new line":null),Sa=N??(s?`${i} is working…`:p?"Message the room · @ to ask someone":g&&be?`Message ${i} · @ to mention, / for commands`:`Message ${i}`),Oo=d.useMemo(()=>ve.map(V=>({handle:V.handle,accent:V.accent})),[ve]),Do=V=>O(V.selectionStart??V.value.length);return t.jsx("div",{className:"wb-composer cv","data-testid":"composer","data-slim":b||void 0,"data-phone":J?"true":void 0,"data-busy":E.trim()!==""||Pt||An?"true":void 0,children:t.jsxs("div",{className:"cv-anchor",children:[Xs&&_e==="mention"?t.jsx(GK,{id:Z,items:ke,active:qe,onPick:nt,phone:J,maxHeight:yt}):null,Xs&&_e==="slash"?t.jsx(YK,{id:Z,items:$e,active:qe,onPick:V=>Ue(V,!1),phone:J,query:(Ie==null?void 0:Ie.query)??"",maxHeight:yt}):null,t.jsxs("div",{ref:q,className:"wb-composer-box cv-box","data-focused":F||An,"data-disabled":n,"data-listening":An||void 0,children:[I.length>0?t.jsx("div",{className:"wb-composer-files",role:"list","aria-label":"Files to send",children:I.map(V=>t.jsx("span",{role:"listitem",children:t.jsx(mm,{name:V.filename,mime:V.mime,sizeBytes:V.sizeBytes,thumbnail:V.thumbnail,state:V.state,error:V.error,onRemove:()=>H(V.key),...m&&V.state==="ready"&&V.uploaded?{onOpen:()=>m(i9(V.uploaded))}:{},size:"sm",detail:V.detail})},V.key))}):null,t.jsxs("label",{className:"sr-only",htmlFor:yv,children:["Message ",i]}),t.jsxs("div",{className:"cv-field",hidden:An,children:[t.jsxs("div",{className:"cv-paint","aria-hidden":"true","data-testid":"composer-paint",children:[VK(E,Oo),t.jsx("span",{className:"cv-tail",children:wv})]}),t.jsx("textarea",{id:yv,ref:B,value:E,rows:1,spellCheck:!1,placeholder:Sa,"aria-controls":Xs?Z:void 0,"aria-expanded":Xs?!0:void 0,"aria-autocomplete":ve.length>0||be?"list":void 0,"aria-activedescendant":Xs&&qe>=0?wy(Z,qe):void 0,onChange:V=>{R(V.target.value),Do(V.target),se(!1),je(0),Ce<0&&It(V.target.value)},onSelect:V=>Do(V.currentTarget),onFocus:()=>Q(!0),onBlur:()=>Q(!1),onKeyDown:rn,onPaste:pt,disabled:n,hidden:An})]}),An?t.jsx(ZK,{voice:Ds}):null,_&&!An?t.jsxs("div",{className:"cv-note",role:"status",children:[t.jsx("span",{className:"cv-note-icon",children:t.jsx(oe,{name:_.kind==="long"?"pasted-doc":"code"})}),t.jsx("span",{className:"cv-note-text",children:_.kind==="fenced"?t.jsxs(t.Fragment,{children:["Pasted as code · ",D$(_.lang)]}):t.jsx(t.Fragment,{children:"Long paste, attached as a file"})}),t.jsx($,{size:"sm",variant:"ghost",onClick:xs,children:_.kind==="fenced"?"Undo":"Put it in the message"})]}):null,t.jsxs("div",{className:"wb-composer-row",hidden:An,children:[t.jsx("input",{ref:Y,type:"file",multiple:!0,hidden:!0,"data-testid":"file-input",onChange:V=>{Te(V.target.files),V.target.value=""}}),t.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 V;return(V=Y.current)==null?void 0:V.click()},disabled:n,children:t.jsx(oe,{name:"clip"})}),t.jsx(XK,{disabled:n,voice:Ds}),J?null:t.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:()=>{K(null),D(!0),s9().then(V=>{var ze;V&&(Te([V]),(ze=B.current)==null||ze.focus())}).catch(V=>K(V instanceof Error?V.message:String(V))).finally(()=>D(!1))},disabled:n||U,children:t.jsx(oe,{name:"camera"})}),o&&!J?u?t.jsxs("a",{className:"wb-composer-model",href:u,title:"The model this agent runs on. Click to change it.",children:[t.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),t.jsx("span",{className:"wb-composer-chip-label",children:o})]}):t.jsxs("span",{className:"wb-composer-model",title:"The model this agent runs on",children:[t.jsx("span",{className:"wb-composer-model-dot","aria-hidden":"true"}),t.jsx("span",{className:"wb-composer-chip-label",children:o})]}):null,f?t.jsxs("button",{type:"button",className:"wb-composer-think","aria-pressed":kd(h),disabled:n||s,title:s?`Wait for ${i} to finish — this run started with thinking ${kd(h)?"on":"off"}`:kd(h)?"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:()=>f(kd(h)?"off":"on"),children:[t.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),t.jsx("span",{className:"wb-composer-chip-label",children:"Thinking"})]}):null,c?t.jsxs("button",{type:"button",className:"wb-composer-think wb-composer-chrome","aria-pressed":c.on,disabled:n,title:c.on?"This conversation looks in your Chrome first, where you are signed in. Click to let the agent choose again.":"Use my Chrome for this conversation: pages open in background tabs of your Chrome, where you are signed in.",onClick:()=>c.onChange(!c.on),children:[t.jsx("span",{className:"wb-composer-think-dot","aria-hidden":"true"}),t.jsxs("span",{className:"wb-composer-chip-label",children:[J?null:t.jsx("span",{className:"wb-composer-chip-lead",children:"Use my "}),"Chrome"]})]}):null,y?t.jsx("button",{type:"button",className:"ui-icon-btn wb-read-aloud","data-size":"sm","aria-label":"Read replies aloud","aria-pressed":!!w,title:w?"Replies are read aloud. Click to stop.":"Read replies aloud, through the voice chosen in Settings → Speech",onClick:()=>y(!w),children:t.jsx(oe,{name:"speaker"})}):null,t.jsx("span",{className:"wb-hint cv-hint","data-shown":!!Ou&&(!J||Na!==null),"data-tone":Gn>0||P!==null?"critical":void 0,children:J&&Na===null?null:Ou}),s?t.jsx("button",{className:"ui-btn","data-variant":"stop",onClick:a,children:"Stop"}):null,t.jsx("button",{className:"wb-send","aria-label":"Send",title:mn?HN:kn?"Waiting for the upload to finish":s?`Send — ${i} picks it up between steps`:"Send",onClick:()=>Ve(),disabled:!tn,children:t.jsx(oe,{name:"send"})})]})]})]})})});function kd(e){return(e??"on")==="on"}function i9(e){return{type:"attachment",artifactId:e.artifactId,filename:e.filename,mime:e.mime,kind:e.kind,sizeBytes:e.sizeBytes}}function kR({question:e,disabled:n,onAnswer:s,onSkip:r}){const[a,i]=d.useState("");return d.useEffect(()=>{if(n)return;const l=o=>{o.key!=="Escape"||o.defaultPrevented||(o.preventDefault(),r())};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[n,r]),t.jsxs("section",{className:"wb-question","aria-label":"Question from agent","data-testid":"question-picker",children:[t.jsxs("div",{className:"wb-question-head",children:[t.jsx("span",{className:"wb-question-kicker",children:"Needs your input"}),t.jsx($,{className:"wb-question-skip",variant:"ghost",size:"sm",disabled:n,onClick:r,title:"Skip this question (Esc). The agent carries on without an answer.",children:"Skip"}),t.jsx("strong",{children:l9(e.question)})]}),e.options.length>0?t.jsx("div",{className:"wb-question-options",children:e.options.map((l,o)=>t.jsxs("button",{className:"wb-question-option","data-recommended":l.recommended||void 0,disabled:n,onClick:()=>s(l.label,l.id),children:[t.jsx("span",{className:"wb-question-number",children:o+1}),t.jsxs("span",{children:[t.jsxs("span",{className:"wb-question-label",children:[l.label,l.recommended?t.jsx("em",{children:"Recommended"}):null]}),l.hint?t.jsx("small",{children:l.hint}):null]})]},l.id))}):null,e.allowOther?t.jsxs("form",{className:"wb-question-other",onSubmit:l=>{l.preventDefault(),a.trim()&&s(a.trim())},children:[t.jsx("input",{value:a,onChange:l=>i(l.target.value),placeholder:e.options.length?"Something else…":"Type your answer…",disabled:n}),t.jsx("button",{className:"ui-btn","data-variant":"accent",disabled:n||!a.trim(),children:"Answer"})]}):null,t.jsx("p",{className:"wb-question-note",children:"This answers a question. It does not approve an action. Esc skips it."})]})}function l9(e){const n=[];let s=0;for(const r of e.matchAll(/https:\/\/[^\s<>"']+/g)){const a=r[0].replace(/[.,;:!?)\]]+$/,""),i=r.index??0;i>s&&n.push(e.slice(s,i)),n.push(t.jsx("a",{href:a,target:"_blank",rel:"noopener noreferrer",children:a},i)),s=i+a.length}return s<e.length&&n.push(e.slice(s)),n}function o9(e,n){const s=i=>{var l;return`@${((l=n.find(o=>o.id===i))==null?void 0:l.handle)??i}`},[r,...a]=e;return r===void 0?"":[s(r),...a.map(i=>`asked by ${s(i)}`)].join(", ")}function c9(e,n,s){return e?[...zT({messages:e.messages,descriptors:[],...s?{awaiting:new Map(s)}:{}}).filter(a=>a.source==="approval").map(a=>({approvalId:a.props.approvalId,toolUseId:a.id})),...NR(e,n)]:[]}function NR(e,n){return((e==null?void 0:e.delegatedApprovals)??[]).map(s=>({approvalId:s.approvalId,toolUseId:s.toolUseId??"",askedBy:o9(s.chain,n)}))}function VN(e){return e instanceof he||e instanceof Error?e.message:String(e)}function SR({conversation:e,conversationId:n,agentId:s,now:r,refresh:a,onRunStarted:i,onError:l,navigate:o}){const[c,u]=d.useState(null),[h,f]=d.useState([]),[m,p]=d.useState(!1),g=((e==null?void 0:e.offers)??[]).filter(j=>!h.includes(j.id)&&Date.parse(j.expiresAt)>r),x=j=>{var w;const v=g.find(y=>y.id===j);if(((w=v==null?void 0:v.handoff)==null?void 0:w.kind)==="install"){o(q3(v.handoff.package));return}l(null),u(j),f(y=>[...y,j]),A.takeOffer(j,n??void 0).then(y=>{if(y.agentId&&y.agentId!==s){o(at(y.agentId,y.conversationId??null));return}y.runId&&i(),n&&a(n)}).catch(y=>{f(N=>N.filter(b=>b!==j)),l(VN(y)),n&&a(n)}).finally(()=>u(null))},k=j=>{const v=e==null?void 0:e.question;v&&(l(null),p(!0),i(),Je.answerQuestion(v.id,j).then(()=>{if(n)return a(n)}).catch(w=>l(VN(w),!0)).finally(()=>p(!1)))};return{openOffers:g,takingOffer:c,takeOffer:x,answeringQuestion:m,answerQuestion:(j,v)=>k({answer:j,...v?{optionId:v}:{}}),skipQuestion:()=>k({answer:"",skipped:!0})}}function CR({offers:e,disabled:n,onTake:s}){return e.length===0?null:t.jsx("div",{className:"wb-offers","data-testid":"chat-offers",children:e.map(r=>{var a,i;return t.jsx("button",{type:"button",className:"ui-btn",disabled:n,title:((a=r.handoff)==null?void 0:a.kind)==="install"?`Opens ${r.handoff.title}'s install sheet`:r.prompt,"data-handoff":(i=r.handoff)==null?void 0:i.kind,onClick:()=>s(r.id),children:r.label},r.id)})})}function u9(e,n){return e.messages<=0?!1:e.chars>e.maxChars?!0:e.lastActivityAt===null||e.idleTimeoutMs===null?!1:n-Date.parse(e.lastActivityAt)>e.idleTimeoutMs}function d9(e){const n=e/864e5;if(n>=1&&Number.isInteger(n))return n===7?"1 week":`${n} day${n===1?"":"s"}`;const s=e/36e5;if(s>=1&&Number.isInteger(s))return`${s} hour${s===1?"":"s"}`;const r=Math.round(e/6e4);return`${r} minute${r===1?"":"s"}`}function h9(e){const{lifetime:n,startedAt:s,now:r,timezone:a}=e;if(!n||n.messages<=0)return{text:"New conversation",title:"Nothing has been said in this one yet.",tone:"quiet"};const i=`${Math.round(n.maxChars/1e3)}k characters`,l=(n.idleTimeoutMs===null?`A conversation ends once its transcript grows past ${i}. `:`A conversation ends after ${d9(n.idleTimeoutMs)} idle, or once its transcript grows past ${i}. `)+"What the agent remembers about you carries over.",o=`${n.messages} message${n.messages===1?"":"s"}`;if(u9(n,r))return{text:`${o} · your next message starts a fresh one`,title:l,tone:"note"};const c=s?Ge(s,r):"";return{text:c===""?o:`${o} · started ${c}`,title:s?`Started ${mt(s,a)}. ${l}`:l,tone:"quiet"}}function f9({text:e,onDelete:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(null);return t.jsx("div",{className:"wb-carryover","data-testid":"chat-carryover",children:t.jsxs(Zt,{summary:"Carried over from the previous conversation",children:[t.jsx("p",{className:"wb-carryover-text",children:e}),t.jsxs(ne,{align:"end",children:[a?t.jsx("span",{className:"critical",role:"alert",children:a}):null,t.jsx($,{size:"sm",variant:"danger-ghost",disabled:s,onClick:()=>{r(!0),i(null),n().catch(l=>{i(l instanceof Error?l.message:String(l)),r(!1)})},children:"Delete note"})]})]})})}function ER(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function $R(e,n){return e.members.map(s=>n.find(r=>r.id===s)).filter(s=>s!==void 0)}function m9(e,n){var a;const s=$R(e,n),r=e.members.filter(i=>!n.some(l=>l.id===i));if(!n.some(i=>i.id===e.coordinator))return{kind:"coordinator",text:`${e.coordinator} coordinated this group and is no longer in buddi, so the group can't take requests.`,action:"Choose a coordinator"};if(s.length<2){const i=r.length>0?`: ${r.join(", ")} ${r.length===1?"was":"were"} removed from buddi`:"";return{kind:"alone",text:`Only ${((a=s[0])==null?void 0:a.name)??e.coordinator} is left here${i}.`,action:"Add a member"}}return null}function p9(){return t.jsx("span",{className:"ui-avatar group-gone-face","aria-hidden":"true",children:"?"})}function g9({group:e,agents:n,onClose:s,onSaved:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=[e.coordinator,...e.members.filter(g=>g!==e.coordinator)],u=e.members.length>2,h=Bw(n).filter(g=>!e.members.includes(g.id)),f=!n.some(g=>g.id===e.coordinator),m=async g=>{i(!0),o(null);try{r(await Je.updateGroup(e.id,g))}catch(x){o(x instanceof he?x.message:String(x))}finally{i(!1)}},p=g=>void m({members:e.members.filter(x=>x!==g)});return t.jsxs(Ye,{title:"Members",onClose:s,children:[t.jsxs("p",{className:"group-lede",children:[e.name," · ",e.members.length," agents. Each keeps its own account, tools and approvals; being here grants nothing."]}),f?t.jsxs(G,{tone:"warning",children:[e.coordinator," coordinated this group and is no longer in buddi. Pick who coordinates now."]}):null,l?t.jsx(G,{tone:"critical",children:l}):null,t.jsx(ct,{children:c.map(g=>{const x=n.find(j=>j.id===g),k=g===e.coordinator;return x?t.jsx(rt,{lead:t.jsx(jn,{agents:n,id:g}),title:x.name,sub:x.description,side:t.jsxs(t.Fragment,{children:[k?t.jsx(Ae,{tone:"accent",children:"Coordinator"}):null,f&&x.available?t.jsx($,{size:"sm",disabled:a,onClick:()=>void m({coordinator:g}),children:"Make coordinator"}):null,t.jsx(ss,{label:`More for ${x.name}`,...k?{note:"Coordinates the group"}:{},items:[!k&&x.available&&{label:"Make coordinator",hint:"Reads your requests, answers for the room",onSelect:()=>void m({coordinator:g})},{label:`Open ${x.name}'s page`,onSelect:()=>{window.location.hash=Ft(g)}},!k&&"separator",!k&&{label:"Remove from group",hint:u?"What it said stays":"A group needs two",tone:"critical",onSelect:()=>{u?p(g):o("A group needs two agents. Add someone before taking this one out.")}}]})]})},g):t.jsx(rt,{lead:t.jsx(p9,{}),title:t.jsx("span",{className:"group-gone-id",children:g}),sub:t.jsxs("span",{className:"group-gone-line",children:["No longer in buddi",k?" · was the coordinator":u?"":" · add a member to take it out"]}),side:u&&!k?t.jsx($,{size:"sm",disabled:a,onClick:()=>p(g),children:"Remove"}):void 0},g)})}),t.jsxs("div",{className:"group-add",children:[t.jsx("h3",{className:"group-add-title",children:"Add a member"}),h.length>0?t.jsx(ct,{children:h.map(g=>t.jsx(rt,{lead:t.jsx(jn,{agents:n,id:g.id,size:"sm"}),title:g.name,sub:g.description,side:t.jsx($,{size:"sm",disabled:a,onClick:()=>void m({members:[...e.members,g.id]}),children:"Add"})},g.id))}):t.jsx("p",{className:"group-quiet",children:"Everyone who can join a group is here."})]}),t.jsx("p",{className:"group-quiet",children:"Members read what is said here and what they recall from shared and group memory; nothing an agent knows privately comes in on its own. Taking a member out leaves what it said in the history."})]})}function x9({group:e,onClose:n,onSaved:s}){const[r,a]=d.useState(e.name),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name&&!i,h=async()=>{if(u){l(!0),c(null);try{s(await Je.updateGroup(e.id,{name:r.trim()}))}catch(f){c(f instanceof he?f.message:String(f)),l(!1)}}};return t.jsx(Ut,{title:"Rename group",onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!u,onClick:()=>void h(),children:i?"Renaming…":"Rename"})]}),children:t.jsx("form",{onSubmit:f=>{f.preventDefault(),h()},children:t.jsxs(ue,{children:[t.jsx(ie,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onFocus:f=>f.currentTarget.select(),onChange:f=>a(f.target.value)})}),o?t.jsx(G,{tone:"critical",children:o}):null]})})})}function AR(e){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return Je.group(e).then(a=>{var i;r&&s(((i=a.history)==null?void 0:i.conversations)??null)}).catch(()=>{}),()=>{r=!1}},[e]),n}function v9(e){return e===null?"Its conversations":e===0?"Nothing has been said yet, and its next conversation":`Its ${e} ${e===1?"conversation":"conversations"}`}function j9({group:e,onClose:n,onCleared:s}){const r=AR(e.id),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=async()=>{i(!0),o(null);try{await Je.clearGroup(e.id),s()}catch(h){o(h instanceof he?h.message:String(h)),i(!1)}},u=r===0;return t.jsxs(Ut,{title:`Clear the history of ${e.name}?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:a||u,"data-testid":"group-clear-confirm",onClick:()=>void c(),children:a?"Clearing…":"Clear history"})]}),children:[t.jsx("p",{className:"group-dialog-text",children:u?"Nothing has been said in this group yet, so there is nothing to clear.":`${v9(r)} ${r===1?"is":"are"} deleted for good, and anything it is doing now stops. The group, its members and what it remembers stay; files it made stay in Files.`}),l?t.jsx(G,{tone:"critical",children:l}):null]})}function w9({group:e,agents:n,onClose:s,onDeleted:r}){const a=AR(e.id),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=$R(e,n).map(m=>m.name),h=async()=>{l(!0),c(null);try{const{undoUntil:m}=await Je.deleteGroup(e.id);r(m)}catch(m){c(m instanceof he?m.message:String(m)),l(!1)}},f=a===null?"its conversations":a===0?"nothing said yet":`its ${a} ${a===1?"conversation":"conversations"}`;return t.jsxs(Ut,{title:`Delete ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:i,"data-testid":"group-delete-confirm",onClick:()=>void h(),children:i?"Deleting…":"Delete group"})]}),children:[t.jsxs("p",{className:"group-dialog-text",children:["The group goes with ",f," and what it remembers."," ",u.length>0?`${ER(u)} ${u.length===1?"is":"are"} not touched, and files it made stay in Files.`:"Files it made stay in Files."]}),o?t.jsx(G,{tone:"critical",children:o}):null]})}const eh=320,TR="buddi.chatWidth";function GN(){var e;return typeof document>"u"||document.querySelector('[role="dialog"], [role="alertdialog"]')?!0:((e=window.matchMedia)==null?void 0:e.call(window,"(pointer: coarse)").matches)===!0}function y9({timezone:e,agents:n,agentId:s,defaultAgentId:r=null,group:a=null,onGroupAction:i,onSelectAgent:l,onWorking:o,attention:c,agentsInHeader:u,narrow:h,canvasOpen:f,onOpenCanvas:m,onCloseCanvas:p,newConversationSignal:g,requestedConversationId:x,requestedTab:k,onConversationOpened:j}){var Sb,Cb,Eb,$b,Ab,Tb,Rb,Ib,Pb,Mb,Ob;const v=pm(),[w,y]=d.useState([]),[N,b]=d.useState(null),[S,C]=d.useState(null),[T,E]=d.useState(null),[R,M]=d.useState([]),[O,I]=d.useState([]),[z,U]=d.useState(null),[D,P]=d.useState(!1),[K,F]=d.useState(new Map),[Q,_]=d.useState(null),[re,Y]=d.useState(KK),[B,q]=d.useState([]),[J,Z]=d.useState(!1),fe=d.useRef(0),ve=d.useRef(null),[Oe,W]=d.useState(!1),se=d.useRef(g??0),X=d.useRef(s),je=d.useRef({agentId:s,conversationId:N});je.current={agentId:s,conversationId:N};const be=re[N??""]??[],[xe,we]=d.useState(null),[Ie,ke]=d.useState(null),[me,$e]=d.useState(()=>Date.now()),[_e,Le]=d.useState(b9),qe=d.useRef(null),[yt,le]=d.useState(null),[Ce,Ze]=d.useState(!1),[xt,Ct]=d.useState(null),[It,Ot]=d.useState(TT),bn=d.useRef(It);bn.current=It;const fn=d.useRef(null),[Kn,en]=d.useState(null),kn=d.useCallback(ee=>{Ot(ee),RT(ee),ee||Ao()},[]),[Pt,mn]=d.useState(null),[tn,Te]=d.useState(null);d.useEffect(()=>{if(!s)return;const ee=W_(s);ee&&Ct({text:ee,at:Date.now()})},[s]);const st=a?`group:${a.id}`:s??null,H=[...n.top,...n.middle,...n.bottom],de=H.find(ee=>ee.id===s)??null,et=ge(()=>A.providerAccounts(),[]),Qe=a?a.members.map(ee=>H.find(ce=>ce.id===ee)).filter(ee=>!!ee):[],[Se,Ve]=d.useState(null),nt=D?Se??s??null:null;d.useEffect(()=>{o==null||o(nt)},[nt,o]),d.useEffect(()=>()=>o==null?void 0:o(null),[o]),d.useEffect(()=>{let ee=!1;return Je.views().then(ce=>{ee||y(ce.views??[])}).catch(()=>{}),()=>{ee=!0}},[]),d.useEffect(()=>{if(!s)return;const ee=X.current===s;if(X.current=s,ee&&x&&x===je.current.conversationId)return;let ce=!1;return b(null),C(null),E(null),M([]),we(null),P(!1),_(null),q([]),Na(null),W(!1),le(null),x?(x!=="new"?b(x):E(st),()=>{ce=!0}):((a?Je.groupConversations(a.id):Je.conversations(s)).then(Pe=>{if(ce)return;const Me=[...Pe.conversations??[]].sort(k9)[0];Me?(b(Me.id),j==null||j(s,Me.id)):E(st)}).catch(()=>{ce||E(st)}),()=>{ce=!0})},[s,a==null?void 0:a.id,st,x,j]);const Ue=d.useCallback(ee=>Je.conversation(ee).then(ce=>{if(je.current.conversationId===ee){if(ce.agentId!==je.current.agentId)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ce),M(Pe=>Pe.filter(Me=>!Hp(ce,Me)))}}).catch(ce=>{je.current.conversationId===ee&&we(Ta(ce))}),[]);d.useEffect(()=>{if(!N)return;let ee=!1;return F(new Map),I([]),Je.conversation(N).then(ce=>{if(!ee){if(ce.agentId!==s)throw new Error("This conversation belongs to another agent. Open it from that agent’s history.");C(ce),M(Pe=>Pe.filter(Me=>!Hp(ce,Me)))}}).catch(ce=>{ee||we(Ta(ce))}),()=>{ee=!0}},[N,s]),d.useEffect(()=>{if(!N)return;let ee=!1;const ce=window.setInterval(()=>{Je.conversation(N).then(Pe=>{ee||Pe.agentId!==je.current.agentId||(C(Pe),M(Me=>Me.filter(dt=>!Hp(Pe,dt))))}).catch(()=>{})},3e3);return()=>{ee=!0,window.clearInterval(ce)}},[N,s]),d.useEffect(()=>{if(!N)return;const ee=tm({url:Je.streamUrl(N),onEvent:ce=>{var Pe;switch(ce.name){case"run.started":fn.current=null,P(!0),U(null),Ve(Rn(ce.data.agentId));break;case"live":{const Me=Rn(ce.data.runId)??"",dt=Number(ce.data.turn??0),Et=ce.data.kind==="thinking"?"thinking":"text",ft=Rn(ce.data.text)??"",Xr=Date.now();if(Et==="text"){const rs=fn.current;fn.current=rs&&rs.runId===Me&&rs.turn===dt?{...rs,text:rs.text+ft}:{runId:Me,turn:dt,text:ft}}U(rs=>{const ol=rs&&rs.runId===Me&&rs.turn===dt?rs:{runId:Me,turn:dt,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return Et==="thinking"?{...ol,thinking:ol.thinking+ft,thinkingStartedAt:ol.thinkingStartedAt??Xr}:{...ol,text:ol.text+ft,textStartedAt:ol.textStartedAt??Xr}});break}case"live.snapshot":{const Me=Rn(ce.data.runId)??"",dt=Number(ce.data.turn??0),Et=Rn(ce.data.text)??"",ft=Rn(ce.data.thinking)??"",Xr=Number(ce.data.startedAt??Date.now());fn.current={runId:Me,turn:dt,text:Et},U({runId:Me,turn:dt,text:Et,thinking:ft,thinkingStartedAt:ft?Xr:null,textStartedAt:Et?Xr:null,settled:!1});break}case"live.settle":{const Me=Rn(ce.data.runId)??"",dt=Number(ce.data.turn??0);U(Et=>Et&&Et.runId===Me&&Et.turn===dt?{...Et,settled:!0}:Et);break}case"tool.called":{const Me=Rn(ce.data.toolUseId)??Rn(ce.data.id),dt=Rn(ce.data.name)??Rn(ce.data.tool)??"tool";Me&&I(Et=>[...Et.filter(ft=>ft.toolUseId!==Me),{toolUseId:Me,name:dt,startedAt:Date.now()}]);break}case"tool.result":{const Me=Rn(ce.data.toolUseId)??Rn(ce.data.id);Me&&I(dt=>dt.filter(Et=>Et.toolUseId!==Me)),Ue(N);break}case"reaction":Ue(N);break;case"message.appended":Ue(N).then(()=>{U(Me=>Me!=null&&Me.settled?null:Me)});break;case"awaiting-approval":{const Me=Rn(ce.data.approvalId)??Rn(ce.data.actionId),dt=Rn(ce.data.toolUseId);Me&&dt&&F(Et=>new Map(Et).set(dt,Me)),I(Et=>Et.filter(ft=>ft.toolUseId!==dt)),Ue(N);break}case"run.finished":{P(!1),I([]),U(null),Ve(null);const Me=Rn(ce.data.message);we(Me??null);const dt=((Pe=fn.current)==null?void 0:Pe.text.trim())??"";fn.current=null,!Me&&dt!==""&&bn.current&&Qh(dt,N).then(Et=>{Et&&en(Et)}),Ue(N);break}}}});return()=>ee.close()},[N,Ue]),d.useEffect(()=>{const ee=window.setInterval(()=>$e(Date.now()),O.length===0?6e4:1e3);return()=>window.clearInterval(ee)},[O.length]);const rn=ge(()=>s&&N?A.browser({agentId:s,conversationId:N}):Promise.resolve(void 0),[s,N],1500),pt=rn.error?void 0:rn.data,xs=pt!=null&&pt.session&&pt.session.agentId===s&&pt.session.conversationId===N?pt:void 0,Vn=DK(xs,s,N),Gn=(Vn==null?void 0:Vn.id)??null,[Ds,An]=d.useState(null),pi=xs==null?void 0:xs.mode;d.useEffect(()=>{Vn&&s&&N&&An({agentId:s,conversationId:N,tab:LK(Vn)})},[Gn,pi,s,N]);const Xs=Ds&&Ds.agentId===s&&Ds.conversationId===N&&!be.includes(Ds.tab.id)?Ds.tab:null,yr=jv(S==null?void 0:S.question),gi=Vn?null:FK(pt,N??null,(yr==null?void 0:yr.kind)==="paused"),ut=Vn??gi??Xs,qr=(Sb=pt==null?void 0:pt.routes)==null?void 0:Sb.find(ee=>ee.kind==="chrome"),Rm=!a&&N&&(qr!=null&&qr.allowed)&&qr.paired?{on:(pt==null?void 0:pt.pin)==="chrome",onChange:ee=>{A.browserPin(N,ee?"chrome":"auto").catch(()=>{}).finally(rn.reload)}}:void 0,[hb,Na]=d.useState(null),Ou=d.useMemo(()=>y8({messages:(S==null?void 0:S.messages)??[],descriptors:w}),[S,w]),Sa=uH(Ou,N??null),Oo=hH(a?null:s),Do=d.useMemo(()=>dH((S==null?void 0:S.messages)??[]),[S]),Tn=d.useMemo(()=>{const ce=zT({messages:(S==null?void 0:S.messages)??[],descriptors:w,awaiting:K,served:Sa.served,...ut?{folded:Zd}:{},gathered:WK}).filter(Me=>Me.source==="approval"||!be.includes(Me.id)),Pe=Q?jN(ce,Q):null;if(Pe&&(Pe.props={...Pe.props,focus:Q}),Q&&!Pe&&!be.includes(Q)&&!ce.some(Me=>Me.id===Q)){const Me=S8((S==null?void 0:S.messages)??[],Q,{redactInputOf:Zd});Me&&!Zd.has(Me.tool)&&ce.push(Me)}ut&&ce.push(ut);for(const Me of B)ce.push(SB(Me));return Oo&&ce.unshift(fH(Oo,Do)),yt?[...ce,mH(yt)]:ce},[S,w,K,yt,Gn,ut==null?void 0:ut.title,Q,re,N,B,Sa.served,Oo,Do]),Du=d.useMemo(()=>{var ce;const ee=[];for(const Pe of(S==null?void 0:S.messages)??[]){if(Pe.role!=="user"||Pe.speaker&&Pe.speaker!=="owner")continue;const Me=(ce=Pe.blocks.find(dt=>dt.type==="text"))==null?void 0:ce.text.trim();Me&&ee.unshift(Me)}return ee},[S]),al=d.useMemo(()=>Tn.filter(ee=>ee.source==="approval"),[Tn]),V=al.at(-1)??null,ze=d.useMemo(()=>[...al.map(ee=>({approvalId:ee.props.approvalId,toolUseId:ee.id})),...NR(S,H)],[al,S==null?void 0:S.delegatedApprovals]),We=d.useMemo(()=>{for(let ee=Tn.length-1;ee>=0;ee-=1){const ce=Tn[ee];if(ce!=null&&ce.substantial)return ce.id}return null},[Tn]),Dt=d.useRef(null),He=((Cb=Tn.filter(ee=>(ee.source!=="browser"||ee.pinned===!0)&&ee.id!==fv).at(-1))==null?void 0:Cb.id)??((Eb=Tn.filter(ee=>ee.id!==fv).at(-1))==null?void 0:Eb.id)??null;d.useEffect(()=>{if(We&&We!==Dt.current){Dt.current=We,_(We);return}Q===null&&He&&_(He)},[We,Q,He]);const an=d.useRef(Sa.live);d.useEffect(()=>{const ee=an.current;an.current=Sa.live;const ce=[...Sa.live].filter(dt=>!ee.has(dt));if(ce.length===0||V||Q!==null&&Q!==Dt.current)return;const Me=[...Tn].reverse().find(dt=>dt.source==="descriptor"&&dt.renderer==="preview"&&dt.props.target!==null&&ce.includes(Hl(dt.props.target)));Me&&_(Me.id)},[Sa.live,Tn,V,Q]);const Yn=d.useRef(null);d.useEffect(()=>{Gn!==Yn.current&&(Yn.current=Gn,Gn&&!V&&_(Gn))},[Gn,V]);const vs=d.useRef(null),Ca=k==="browser"?(ut==null?void 0:ut.id)??null:null;d.useEffect(()=>{!Ca||vs.current===Ca||(vs.current=Ca,_(Ca))},[Ca]);const Ea=(ut==null?void 0:ut.id)??null;d.useEffect(()=>{!Ea||!Q||BN((S==null?void 0:S.messages)??[],Q)!==null&&(Na(Q),_(Ea))},[Ea,Q,S]);const Qr=ee=>{q(ce=>ce.some(Pe=>Pe.artifactId===ee.artifactId)?ce:[...ce,ee]),_(Qd(ee.artifactId)),h&&(m==null||m())},xi=!a&&de&&!de.available?qA(de):null,Lu=a?t.jsx("span",{className:"wb-group-stack","aria-hidden":"true",children:a.members.slice(0,2).map(ee=>{const ce=H.find(Pe=>Pe.id===ee);return t.jsx(am,{className:"wb-group-chip",id:ee,name:(ce==null?void 0:ce.name)??"?",face:ce,initials:1},ee)})}):null,Jr=a&&H.length>0?m9(a,H):null,il=(Jr==null?void 0:Jr.kind)==="coordinator",fb=Vx(a?null:de),mb=ze.length>0||!!(S!=null&&S.question),Im=d.useRef(mb);Im.current=mb,d.useEffect(()=>{if(Im.current||GN())return;const ee=window.requestAnimationFrame(()=>{var ce;Im.current||GN()||(ce=ve.current)==null||ce.focus()});return()=>window.cancelAnimationFrame(ee)},[s,a==null?void 0:a.id,N,g]);const qM=de&&tn===de.id?Pt:(de==null?void 0:de.thinking)??null,QM=ee=>{if(!de)return;const ce=de.id;Te(ce),mn(ee),A.setAgentEngine(ce,{thinking:ee}).catch(Pe=>{Te(null),we(Pe instanceof he?Pe.message:String(Pe))})},Pm=(ee,ce)=>{if(!s)return;const Pe=a?null:$9(ee,H,s);if(Pe){we(null),Je.send(Pe.agent.id,{text:Pe.rest,attachmentIds:ce.map(ft=>ft.artifactId)}).then(ft=>{window.location.hash=at(Pe.agent.id,ft.conversationId)}).catch(ft=>we(Ta(ft)));return}const Me=ce.map(ft=>ft.artifactId),dt=D,Et={id:`optimistic:${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:ee},...ce.map(ft=>({type:"attachment",artifactId:ft.artifactId,filename:ft.filename,mime:ft.mime,kind:ft.kind,sizeBytes:ft.sizeBytes}))],...dt?{speaker:WT}:{}};M(ft=>dt?[...ft,Et]:[Et]),we(null),ke(null),P(!0),(a?Je.sendToGroup(a.id,{...N?{conversationId:N}:{},text:ee,attachmentIds:Me}):Je.send(s,{...N?{conversationId:N}:{},text:ee,attachmentIds:Me})).then(async ft=>{je.current.agentId!==s||je.current.conversationId!==N||(ke(ft.rolledOver===!0?"(New thread — the room had grown long. Where it stopped carries over as a summary.)":null),ft.conversationId!==N?(C(null),b(ft.conversationId)):await Ue(ft.conversationId),ft.queued===!0&&M(Xr=>Xr.filter(rs=>rs.id!==Et.id)),j==null||j(s,ft.conversationId))}).catch(ft=>{M(Xr=>Xr.filter(rs=>rs.id!==Et.id)),we(Ta(ft)),P(!1)})},{openOffers:JM,takingOffer:XM,takeOffer:ZM,answeringQuestion:pb,answerQuestion:gb,skipQuestion:e2}=SR({conversation:S,conversationId:N??null,agentId:(de==null?void 0:de.id)??null,now:me,refresh:Ue,onRunStarted:()=>{ke(null),P(!0)},onError:(ee,ce)=>{we(ee),ce&&P(!1)},navigate:ee=>{window.location.hash=ee}}),t2=()=>{if(s){if(yt){le(null);return}Ze(!0),A.agentProfile(s).then(ee=>{le(ee),_(mv(ee.id)),h&&(m==null||m())}).catch(ee=>we(Ta(ee))).finally(()=>Ze(!1))}},n2=ee=>{Ct({text:ee.prompt,at:Date.now()}),l(ee.agentId),h&&(p==null||p())},xb=()=>{N&&Je.cancel(N).catch(ee=>we(Ta(ee))).finally(()=>{P(!1),I([])})},s2=(ee,ce)=>{if(we(null),ee==="stop"){xb();return}if(ee==="use"){const Pe=ce.replace(/^@/,"").toLowerCase(),Me=H.find(dt=>dt.handle.toLowerCase()===Pe||dt.id===Pe);if(!Me){ke(Pe?`No agent called @${Pe}.`:"Say who: /use @handle.");return}ke(null),l(Me.id);return}if(ee==="new"){const Pe=H.find(Me=>Me.roles.includes(zr));if(!Pe){ke("There is no agent here that makes agents.");return}ce.trim()&&ku(Pe.id,`I'd like a teammate for this: ${ce.trim()}`),l(Pe.id);return}A.quiet(ce).then(Pe=>ke(Pe.text)).catch(Pe=>we(Ta(Pe)))},Fu=d.useCallback(()=>{if(b(null),C(null),M([]),P(!1),we(null),ke(null),I([]),F(new Map),_(null),q([]),Na(null),Dt.current=null,a){Je.startGroupConversation(a.id).then(({conversationId:ee})=>{b(ee),s&&(j==null||j(s,ee))}).catch(ee=>we(Ta(ee)));return}E(st),s&&(j==null||j(s,"new"))},[s,a,st,j]);d.useEffect(()=>{g&&g!==se.current&&(se.current=g,Fu())},[g,Fu]);const vb=ee=>{N&&Ue(N),A.overview().catch(()=>{}),ee.state!=="pending"&&F(ce=>new Map([...ce].filter(([,Pe])=>Pe!==ee.id)))},_u=d.useRef(!1);d.useEffect(()=>{const ee=Pe=>{if(!_u.current)return;const Me=Math.max(eh,Math.min(720,Pe.clientX-52));Le(Me)},ce=()=>{if(_u.current){_u.current=!1;try{_e!==null&&window.localStorage.setItem(TR,String(_e))}catch{}}};return window.addEventListener("pointermove",ee),window.addEventListener("pointerup",ce),()=>{window.removeEventListener("pointermove",ee),window.removeEventListener("pointerup",ce)}},[_e]);const r2=(($b=H.find(ee=>ee.id===r))==null?void 0:$b.name)??null,jb=a?[]:r6(de,r2),wb=!(S&&S.conversationId===N)&&!(!N&&T!==null&&T===st),yb=wb?t.jsx("div",{className:"wb-chat-loading","data-testid":"chat-loading","aria-busy":"true"}):!a&&de?t.jsx(gT,{quiet:!0,still:!0,className:"wb-chat-field",children:t.jsxs("div",{className:"wb-chat-opening","data-testid":"chat-opening",children:[t.jsx(jn,{agents:H,id:de.id,size:"xl"}),t.jsx("h2",{className:"wb-chat-hello",children:`Hi, I'm ${de.name}.`}),t.jsx("p",{className:"wb-chat-intro",children:a6(de)}),jb.length>0?t.jsx("div",{className:"wb-starters",role:"group","aria-label":`Things to ask ${de.name}`,children:jb.map(ee=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>{var ce;Ct({text:ee,at:Date.now()}),(ce=ve.current)==null||ce.focus()},children:ee},ee))}):null]})}):null,bb=t.jsx(XW,{renderables:Tn,activeId:(Q?(Ab=jN(Tn,Q))==null?void 0:Ab.id:null)??Q,onActivate:_,onClose:ee=>{yt&&ee===mv(yt.id)?le(null):B.some(ce=>Qd(ce.artifactId)===ee)?q(ce=>ce.filter(Pe=>Qd(Pe.artifactId)!==ee)):N&&Y(ce=>{const Pe={...ce,[N]:[...new Set([...ce[N]??[],ee])]};return WN(Pe),Pe}),Q===ee&&_(null)},timezone:e,onDecided:vb,onChangeAgent:n2,agents:H,browserPanel:ut?t.jsx(AK,{status:xs,error:rn.error,reload:rn.reload,live:Vn!==null,agentName:(de==null?void 0:de.name)??"The agent",timezone:e,paused:gi&&(pt!=null&&pt.stop)?pt.stop:null},ut.id):null,browserMenu:ut?t.jsx(IK,{status:pt,timezone:e,reload:rn.reload}):null,descriptors:w,grantedTools:a?Qe.flatMap(ee=>ee.tools??[]):(de==null?void 0:de.tools)??[],...de?{agentName:de.name}:{},loading:wb,...!a&&de?{face:t.jsx(jn,{agents:H,id:de.id,size:"xl"})}:{}}),kb=(Rb=(Tb=[...(S==null?void 0:S.messages)??[],...R].find(ee=>ee.role==="user"))==null?void 0:Tb.blocks.find(ee=>ee.type==="text"))==null?void 0:Rb.text.trim(),Nb=kb?kb.split(`
|
|
122
|
-
`)[0]:"New conversation",ll=h9({lifetime:(S==null?void 0:S.lifetime)??null,startedAt:(S==null?void 0:S.startedAt)??null,now:me,timezone:e});return t.jsxs(t.Fragment,{children:[t.jsxs("section",{className:"wb-chat",ref:qe,style:h||_e===null?void 0:{width:_e},"data-sized":!h&&_e!==null?"true":void 0,"data-testid":"chat-column","data-dropping":J||void 0,onDragEnter:ee=>{Nd(ee)&&(ee.preventDefault(),fe.current+=1,Z(!0))},onDragOver:ee=>{Nd(ee)&&(ee.preventDefault(),ee.dataTransfer.dropEffect="copy")},onDragLeave:ee=>{Nd(ee)&&(fe.current=Math.max(0,fe.current-1),fe.current===0&&Z(!1))},onDrop:ee=>{var ce;Nd(ee)&&(ee.preventDefault(),fe.current=0,Z(!1),s&&((ce=ve.current)==null||ce.addFiles(ee.dataTransfer.files)))},children:[J?t.jsx("div",{className:"wb-drop","aria-hidden":"true",children:t.jsxs("div",{className:"wb-drop-card",children:[t.jsx(N9,{}),t.jsx("strong",{children:"Drop to attach"}),t.jsx("span",{children:de?`It goes with your next message to ${de.name}`:"Pick an agent first"})]})}):null,t.jsxs("header",{className:"wb-chat-head","data-testid":"chat-head",...!a&&de?Hi(So(de)):{},children:[t.jsxs("div",{className:"wb-head-row",children:[a?t.jsx("span",{className:"wb-head-face","aria-hidden":"true",children:Lu}):de?t.jsx("a",{className:"wb-head-face",href:Ft(de.id),"aria-label":`${de.name}'s page`,children:t.jsx(jn,{agents:H,id:de.id})}):null,t.jsxs("div",{className:"wb-head-text",children:[a?t.jsx("span",{className:"wb-head-title",children:a.name}):t.jsx("span",{className:"wb-head-title",title:Nb,children:Nb}),t.jsx("span",{className:"wb-head-meta","data-tone":ll.tone,title:a?`${Qe.map(ee=>ee.name).join(", ")}. Coordinator: ${(de==null?void 0:de.name)??a.coordinator}.`:ll.title,children:a?`${Qe.map(ee=>ee.name).join(", ")} · ${ll.text}`:de?t.jsxs(t.Fragment,{children:[t.jsx("a",{className:"wb-head-name",href:Ft(de.id),title:`${de.name}'s page`,children:de.name})," ",t.jsxs("span",{className:"wb-head-handle",children:["@",de.handle]}),` · ${ll.tone==="quiet"&&ll.text==="New conversation"?`on ${v}`:ll.text}`]}):"No agent"})]}),t.jsx("button",{className:"ui-icon-btn wb-head-more","data-size":"sm","aria-label":"New chat",title:"New chat",disabled:!s,onClick:()=>{W(!1),Fu()},children:t.jsx(oe,{name:"plus",size:16})}),t.jsx("button",{className:"ui-icon-btn wb-head-more","aria-label":"History",title:"Earlier conversations","aria-expanded":Oe,"data-open":Oe?"true":void 0,disabled:!s,onClick:()=>W(ee=>!ee),children:t.jsx(S9,{})}),h?t.jsxs("button",{className:"ui-btn",onClick:m,disabled:Tn.length===0,children:["Canvas",Tn.length>0?` (${Tn.length})`:""]}):null,a?t.jsx(YN,{disabled:!1,label:"More about this group",title:a.name,sub:ER(Qe.map(ee=>ee.name)),face:Lu,items:[{label:"Members",hint:`${a.members.length} agents · ${de?`${de.name} coordinates`:"no coordinator"}`,testId:"group-members",onSelect:()=>i==null?void 0:i("members")},{label:"Rename…",hint:"What this team is for",testId:"group-rename",onSelect:()=>i==null?void 0:i("rename")},"separator",{label:"Clear history…",hint:"Keeps the group and its members",testId:"group-clear",onSelect:()=>i==null?void 0:i("clear")},{label:"Delete group…",hint:"With its history; the agents stay",tone:"critical",testId:"group-delete",onSelect:()=>i==null?void 0:i("delete")}]}):t.jsx(YN,{disabled:!s,label:"More about this agent",title:(de==null?void 0:de.name)??"Agent",...de?{sub:`@${de.handle}`,face:t.jsx(jn,{agents:H,id:de.id,size:"sm"})}:{},items:[{label:yt?"Close properties":"Properties",hint:"What this agent can do, on the Canvas",testId:"agent-properties",disabled:Ce,onSelect:t2},...de?[{label:"Set up",hint:"Identity, model and access",href:Ft(de.id,"setup")},{label:"Open agent page",hint:"Profile, activity and setup",href:Ft(de.id)}]:[]]})]}),u?t.jsx(JA,{agents:n,currentId:s,attention:c,onSelect:l,orientation:"horizontal",...nt?{working:new Set([nt])}:{}}):null]}),Oe&&s?t.jsx(HK,{agentId:s,...a?{groupId:a.id}:{},currentId:N,timezone:e,onNew:()=>{W(!1),Fu()},onSelect:ee=>{if(ee===N){W(!1);return}W(!1),C(null),M([]),P(!1),_(null),we(null),ke(null),q([]),b(ee),j==null||j(s,ee,!1)}}):null,s&&N?t.jsx(PK,{agentId:s,conversationId:N},`${s}:${N}`):null,xe?t.jsx("div",{className:"wb-chat-notice",children:t.jsx(ae,{message:xe})}):null,Ie?t.jsx("div",{className:"wb-chat-notice","data-testid":"chat-notice",children:Ie}):null,S!=null&&S.carriedOver?t.jsx(f9,{text:S.carriedOver,onDelete:async()=>{const ee=S.conversationId;await Je.deleteCarryOver(ee),C(ce=>{if(!ce||ce.conversationId!==ee)return ce;const{carriedOver:Pe,...Me}=ce;return Me})}},S.conversationId):null,t.jsx(ly,{messages:[...(S==null?void 0:S.messages)??[],...R],live:O,now:me,working:D,partial:z,agents:H,...S!=null&&S.runs?{runs:S.runs}:{},...s&&N?{onContinue:()=>Pm("continue",[])}:{},...a?{speakers:H,coordinatorId:a.coordinator}:{},...Se?{workingAs:((Ib=H.find(ee=>ee.id===Se))==null?void 0:Ib.name)??Se}:{},onOpenFile:Qr,onReadAloud:(ee,ce)=>{en(null),Qh(ce,N??void 0,ee).then(Pe=>{Pe&&en(Pe)})},onOpen:ee=>{if(ut){const ce=BN([...(S==null?void 0:S.messages)??[],...R],ee);if(ce){Na(ce),_(ut.id),h&&(m==null||m());return}}N&&Y(ce=>{const Pe={...ce,[N]:(ce[N]??[]).filter(Me=>Me!==ee)};return WN(Pe),Pe}),_(ee),h&&(m==null||m())},...de?{agentName:de.name,agentId:de.id}:{},...yb?{empty:yb}:{},emptyHint:a?`Give the team a task once; ${de?de.name:"the coordinator"} brings members in. @ addresses one of them.`:de?`Nothing here yet. Ask ${de.name} for something.`:"Loading agents…"}),t.jsx(CR,{offers:JM,disabled:XM!==null,onTake:ZM}),Jr?t.jsx("div",{className:"wb-composer-blocked","data-testid":"group-problem","data-kind":Jr.kind,children:t.jsx(G,{tone:il?"warning":void 0,role:"status",children:t.jsxs("span",{children:[Jr.text," ",t.jsx("button",{type:"button",className:"wb-link-btn",onClick:()=>i==null?void 0:i("members"),children:Jr.action})]})})}):null,xi?t.jsx("div",{className:"wb-composer-blocked","data-testid":"composer-blocked",children:t.jsxs(G,{tone:"warning",role:"status",children:[xi," ",t.jsx("a",{href:Fe(fb.section),children:fb.label})]})}):ze.length>0?t.jsx(XT,{approvals:ze,timezone:e,now:me,version:S,onDecided:vb,onSay:ee=>Pm(ee,[]),onOpenFull:ee=>{_(ee),h&&(m==null||m())}}):null,xi||ze.length>0?null:S!=null&&S.question&&yr?t.jsx(yR,{card:yr,disabled:pb||D,onAnswer:gb,site:((Pb=pt==null?void 0:pt.needsOwner)==null?void 0:Pb.site)??((Ob=(Mb=pt==null?void 0:pt.page)==null?void 0:Mb.url)==null?void 0:Ob.replace(/^https?:\/\/(www\.)?([^/]+).*$/,"$2"))},S.question.id):S!=null&&S.question?t.jsx(kR,{question:S.question,disabled:pb||D,onAnswer:gb,onSkip:e2},S.question.id):null,xi||il?null:t.jsxs("div",{hidden:ze.length>0||!!(S!=null&&S.question),"data-testid":"composer-slot",children:[t.jsx(yy,{ref:ve,disabled:!s,running:D,onSend:Pm,onStop:xb,agentName:a?a.name:(de==null?void 0:de.name)??"the agent",draft:xt,history:Du,threadKey:N??(a?`group:${a.id}`:s),model:a?null:(de==null?void 0:de.model)??null,chrome:Rm,setupHref:a?null:de?Ft(de.id,"setup","brain"):null,thinking:qM,...!a&&de&&F$(_$(de,et.data))?{onThinking:QM}:{},...a?{mentions:Qe.map(ee=>({id:ee.id,handle:ee.handle,name:ee.name})),team:{agents:H,selfId:""}}:s?{team:{agents:H,selfId:s}}:{},onCommand:s2,onOpenFile:Qr,conversationId:N??null,readAloud:It,onReadAloud:kn}),Kn?t.jsx("p",{className:"wb-voice-note",role:"status",children:Kn}):null]})]}),h?f?t.jsxs("div",{className:"wb-sheet",role:"dialog","aria-label":"Canvas",children:[t.jsxs("div",{className:"wb-sheet-head",children:[t.jsx("strong",{children:"Canvas"}),t.jsx("button",{className:"ui-btn",onClick:p,children:"Close"})]}),bb]}):null:t.jsxs(t.Fragment,{children:[t.jsx("button",{className:"wb-grip","aria-label":"Resize the conversation column",onPointerDown:ee=>{var ce,Pe;_u.current=!0,(Pe=(ce=ee.currentTarget).setPointerCapture)==null||Pe.call(ce,ee.pointerId)},onKeyDown:ee=>{const ce=Pe=>{var Me;return Pe??((Me=qe.current)==null?void 0:Me.offsetWidth)??eh};ee.key==="ArrowLeft"&&Le(Pe=>Math.max(eh,ce(Pe)-16)),ee.key==="ArrowRight"&&Le(Pe=>Math.min(720,ce(Pe)+16))}}),bb]})]})}function b9(){try{const e=window.localStorage.getItem(TR),n=Number(e);return e!==null&&Number.isFinite(n)&&n>=eh?n:null}catch{return null}}function k9(e,n){return Date.parse(n.lastMessageAt??n.startedAt??n.createdAt??"")-Date.parse(e.lastMessageAt??e.startedAt??e.createdAt??"")}function Rn(e){return typeof e=="string"&&e!==""?e:null}function Ta(e){return e instanceof he||e instanceof Error?e.message:String(e)}function Hp(e,n){var r;const s=(r=n.blocks.find(a=>a.type==="text"))==null?void 0:r.text.trim();if(!s)return!0;for(let a=e.messages.length-1;a>=0;a-=1){const i=e.messages[a];if(i.role!=="user")continue;const l=i.blocks.find(o=>o.type==="text");if(l)return l.text.trim()===s}return!1}function Nd(e){var s;const n=(s=e.dataTransfer)==null?void 0:s.types;return!!(n&&Array.from(n).includes("Files"))}function N9(){return t.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:[t.jsx("path",{d:"M14 4v13M8.5 11.5 14 17l5.5-5.5"}),t.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"})]})}function S9(){return t.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:[t.jsx("path",{d:"M2.6 8a5.4 5.4 0 1 0 1.6-3.8"}),t.jsx("path",{d:"M2.4 2.6v2.6h2.6M8 5.2V8l2 1.3"})]})}function C9(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16","aria-hidden":"true",fill:"currentColor",children:[t.jsx("circle",{cx:"8",cy:"3.4",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"8",r:"1.35"}),t.jsx("circle",{cx:"8",cy:"12.6",r:"1.35"})]})}function YN({items:e,disabled:n,label:s,title:r,sub:a,face:i}){const[l,o]=d.useState(!1),c=d.useRef(null);d.useEffect(()=>{if(!l)return;const h=m=>{c.current&&!c.current.contains(m.target)&&o(!1)},f=m=>{m.key==="Escape"&&o(!1)};return window.addEventListener("mousedown",h),window.addEventListener("keydown",f),()=>{window.removeEventListener("mousedown",h),window.removeEventListener("keydown",f)}},[l]);const u=h=>{const f=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-menu-item-text",children:h.label}),h.hint?t.jsx("span",{className:"ui-menu-item-hint",children:h.hint}):null]});return h.href?t.jsx("a",{className:"ui-menu-item",role:"menuitem",href:h.href,"data-tone":h.tone,onClick:()=>o(!1),children:f},h.label):t.jsx("button",{className:"ui-menu-item",role:"menuitem","data-testid":h.testId,"data-tone":h.tone,disabled:h.disabled,onClick:()=>{var m;o(!1),(m=h.onSelect)==null||m.call(h)},children:f},h.label)};return t.jsxs("div",{className:"wb-head-menu",ref:c,children:[t.jsx("button",{className:"ui-icon-btn wb-head-more","data-testid":"chat-menu","aria-label":s,"aria-haspopup":"menu","aria-expanded":l,"data-open":l?"true":void 0,disabled:n,onClick:()=>o(h=>!h),children:t.jsx(C9,{})}),l?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wb-head-menu-scrim","aria-hidden":"true",onClick:()=>o(!1)}),t.jsxs("div",{className:"ui-menu wb-head-menu-list",role:"menu","aria-label":r,children:[t.jsxs("div",{className:"wb-head-menu-head","aria-hidden":"true",children:[i,t.jsxs("span",{className:"wb-head-menu-heading",children:[t.jsx("span",{className:"wb-head-menu-title",children:r}),a?t.jsx("span",{className:"wb-head-menu-sub",children:a}):null]})]}),e.map((h,f)=>h==="separator"?t.jsx("div",{className:"ui-menu-sep",role:"separator"},`sep-${f}`):u(h)),t.jsx("button",{type:"button",className:"ui-btn wb-head-menu-cancel",onClick:()=>o(!1),children:"Cancel"})]})]}):null]})}let qN=!1;const E9=new Set(["missing","unconfigured","not-english"]);async function Qh(e,n,s=null){const r=IT(s);try{const a=await Je.say({text:e,...n?{conversationId:n}:{}});return cN(r)&&await z5(a.audioUrl,a.mime,s),null}catch(a){cN(r)&&Ao();const i=a instanceof he&&a.detail&&typeof a.detail=="object"?a.detail.reason:void 0;return typeof i=="string"&&E9.has(i)&&(s!==null||!qN)?(qN=!0,a.message):null}}function $9(e,n,s){const r=L$(e);if(!r||r.rest==="")return null;const a=n.find(i=>i.roles.includes(zr));return!a||a.id===s||a.handle.toLowerCase()!==r.handle?null:{agent:a,rest:r.rest}}const bv="buddi:ask";function A9(e){const n={text:e,handled:!1};return window.dispatchEvent(new CustomEvent(bv,{detail:n})),n.handled}let Fs=null;function T9(e){if(qd(e)!==null)return!1;const n=zA(e);return n!==$n&&n!==da}function R9({agent:e,agents:n,open:s,onOpenChange:r,navigate:a,timezone:i}){const l=d.useRef(null),o=d.useRef(s),c=`Ask ${e.name}`,[u,h]=d.useState(!1),[f,m]=d.useState(null);return d.useEffect(()=>{const p=g=>{const x=g.detail;!x||typeof x.text!="string"||(x.handled=!0,m({text:x.text,at:Date.now()}),r(!0))};return window.addEventListener(bv,p),()=>window.removeEventListener(bv,p)},[r]),d.useEffect(()=>{if(s||!u||!Fs)return;const p=tm({url:Je.streamUrl(Fs.conversationId),lastEventId:Fs.lastEventId??null,onEvent:g=>{g.name==="run.finished"&&h(!1)}});return()=>p.close()},[s,u]),d.useEffect(()=>{const p=g=>{!g.altKey||g.ctrlKey||g.metaKey||g.code!=="Slash"||(g.preventDefault(),r(!s))};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,r]),d.useEffect(()=>{var p;o.current&&!s&&((p=l.current)==null||p.focus()),o.current=s},[s]),s?t.jsx(P9,{agent:e,agents:n,timezone:i,navigate:a,onClose:()=>r(!1),onBusy:h,prefill:f}):t.jsxs(Kc,{children:[t.jsx(Vc,{asChild:!0,children:t.jsx("button",{ref:l,type:"button",className:"wb-ask-fab","data-busy":u?"true":void 0,"aria-label":c,onClick:()=>r(!0),children:t.jsx(I9,{busy:u})})}),t.jsx(Gc,{children:t.jsx(Yc,{className:"ui-tip",side:"left",sideOffset:8,children:c})})]})}function I9({busy:e}){const[n,s]=d.useState(!1);return n?t.jsx(su,{size:"lg"}):t.jsx(Au,{state:e?"working":"idle",className:"wb-ask-fab-face",onStillError:()=>s(!0)})}function P9({agent:e,agents:n,timezone:s,navigate:r,onClose:a,onBusy:i,prefill:l}){const o=d.useRef(null),[c,u]=d.useState(Fs&&Fs.agentId===e.id?Fs.conversationId:null),[h,f]=d.useState(null),[m,p]=d.useState([]),[g,x]=d.useState([]),[k,j]=d.useState(null),[v,w]=d.useState(!1),[y,N]=d.useState(!1),[b,S]=d.useState(null),[C,T]=d.useState(l??null);d.useEffect(()=>{l&&T(l)},[l]);const[E,R]=d.useState(Date.now()),[M,O]=d.useState(TT),I=d.useRef(M);I.current=M;const[z,U]=d.useState(null),[D,P]=d.useState(new Map),K=d.useRef(null),F=d.useCallback(async xe=>{try{const we=await Je.conversation(xe);f(we),p(Ie=>Ie.filter(ke=>!M9(we,ke)))}catch{}},[]);d.useEffect(()=>{c&&F(c)},[c,F]),d.useEffect(()=>{if(!c)return;const xe=tm({url:Je.streamUrl(c),onEvent:we=>{var Ie;switch(we.name){case"run.started":K.current=null,w(!0),j(null);break;case"live":{const ke=zn(we.data.runId)??"",me=Number(we.data.turn??0),$e=we.data.kind==="thinking"?"thinking":"text",_e=zn(we.data.text)??"",Le=Date.now();if($e==="text"){const qe=K.current;K.current=qe&&qe.runId===ke&&qe.turn===me?{...qe,text:qe.text+_e}:{runId:ke,turn:me,text:_e}}j(qe=>{const yt=qe&&qe.runId===ke&&qe.turn===me?qe:{runId:ke,turn:me,text:"",thinking:"",thinkingStartedAt:null,textStartedAt:null,settled:!1};return $e==="thinking"?{...yt,thinking:yt.thinking+_e,thinkingStartedAt:yt.thinkingStartedAt??Le}:{...yt,text:yt.text+_e,textStartedAt:yt.textStartedAt??Le}});break}case"live.snapshot":{const ke=zn(we.data.runId)??"",me=Number(we.data.turn??0),$e=zn(we.data.text)??"",_e=zn(we.data.thinking)??"",Le=Number(we.data.startedAt??Date.now());K.current={runId:ke,turn:me,text:$e},w(!0),j({runId:ke,turn:me,text:$e,thinking:_e,thinkingStartedAt:_e?Le:null,textStartedAt:$e?Le:null,settled:!1});break}case"live.settle":{const ke=zn(we.data.runId)??"",me=Number(we.data.turn??0);j($e=>$e&&$e.runId===ke&&$e.turn===me?{...$e,settled:!0}:$e);break}case"tool.called":{const ke=zn(we.data.toolUseId)??zn(we.data.id),me=zn(we.data.name)??zn(we.data.tool)??"tool";ke&&x($e=>[...$e.filter(_e=>_e.toolUseId!==ke),{toolUseId:ke,name:me,startedAt:Date.now()}]);break}case"tool.result":{const ke=zn(we.data.toolUseId)??zn(we.data.id);ke&&x(me=>me.filter($e=>$e.toolUseId!==ke)),F(c);break}case"awaiting-approval":{const ke=zn(we.data.approvalId)??zn(we.data.actionId),me=zn(we.data.toolUseId);ke&&me&&P($e=>new Map($e).set(me,ke)),me&&x($e=>$e.filter(_e=>_e.toolUseId!==me)),F(c).then(()=>j($e=>$e!=null&&$e.settled?null:$e));break}case"message.appended":F(c).then(()=>j(ke=>ke!=null&&ke.settled?null:ke));break;case"run.finished":{w(!1),x([]),j(null);const ke=zn(we.data.message);S(ke??null);const me=((Ie=K.current)==null?void 0:Ie.text.trim())??"";K.current=null,!ke&&me!==""&&I.current&&Qh(me,c).then($e=>{$e&&U($e)}),F(c);break}}}});return()=>{Fs&&Fs.conversationId===c&&(Fs.lastEventId=xe.lastEventId()),xe.close()}},[c,F]),d.useEffect(()=>{i(v||y)},[v,y,i]),d.useEffect(()=>{if(g.length===0)return;const xe=window.setInterval(()=>R(Date.now()),1e3);return()=>window.clearInterval(xe)},[g.length]);const Q=(xe,we)=>{N(!0),S(null);const Ie={id:`local-${Date.now()}`,role:"user",at:new Date().toISOString(),blocks:[{type:"text",text:xe}]};p(ke=>[...ke,Ie]),(async()=>{try{const ke=c??(await Je.startConversation(e.id)).conversationId;ke!==c&&(Fs={agentId:e.id,conversationId:ke},u(ke));const me=await Je.send(e.id,{conversationId:ke,text:xe,...we.length>0?{attachmentIds:we.map($e=>$e.artifactId)}:{}});me.conversationId!==ke&&(Fs={agentId:e.id,conversationId:me.conversationId},u(me.conversationId)),w(!0),F(me.conversationId)}catch(ke){p(me=>me.filter($e=>$e.id!==Ie.id)),S(ke instanceof he?ke.message:String(ke)),T({text:xe,at:Date.now()})}finally{N(!1)}})()},_=(xe,we)=>{if(S(null),xe==="stop"){re();return}if(xe==="use"){const Ie=we.replace(/^@/,"").toLowerCase(),ke=n.find(me=>me.handle.toLowerCase()===Ie||me.id===Ie);if(!ke){U(Ie?`No agent called @${Ie}.`:"Say who: /use @handle.");return}r(at(ke.id));return}if(xe==="new"){const Ie=n.find(ke=>ke.roles.includes(zr));if(!Ie){U("There is no agent here that makes agents.");return}we.trim()&&ku(Ie.id,`I'd like a teammate for this: ${we.trim()}`),r(at(Ie.id));return}A.quiet(we).then(Ie=>U(Ie.text)).catch(Ie=>S(Ie instanceof Error?Ie.message:String(Ie)))},re=()=>{c&&Je.cancel(c).catch(xe=>S(String(xe))).finally(()=>w(!1))},Y=()=>{var xe;Fs=null,u(null),f(null),p([]),x([]),j(null),w(!1),S(null),P(new Map),(xe=o.current)==null||xe.focus()},B=xe=>{O(xe),RT(xe),xe||Ao()},q=c?at(e.id,c):at(e.id),J=[...(h==null?void 0:h.messages)??[],...m],{openOffers:Z,takingOffer:fe,takeOffer:ve,answeringQuestion:Oe,answerQuestion:W,skipQuestion:se}=SR({conversation:h,conversationId:c,agentId:e.id,now:E,refresh:F,onRunStarted:()=>w(!0),onError:(xe,we)=>{S(xe),we&&w(!1)},navigate:r}),X=d.useMemo(()=>c9(h,n,D),[h,n,D]),je=X.length===0?(h==null?void 0:h.question)??null:null,be=xe=>{c&&F(c),A.overview().catch(()=>{}),xe.state!=="pending"&&P(we=>new Map([...we].filter(([,Ie])=>Ie!==xe.id)))};return t.jsxs(gB,{title:e.name,label:`${e.name}, a quick chat`,onClose:a,onOpenAutoFocus:xe=>{var we;xe.preventDefault(),(we=o.current)==null||we.focus()},onCloseAutoFocus:xe=>xe.preventDefault(),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"ghost",onClick:Y,disabled:c===null&&m.length===0,children:"New"}),t.jsx(lt,{size:"sm",variant:"ghost",href:q,onClick:xe=>{xe.preventDefault(),r(q)},children:"Open in Chat"})]}),children:[t.jsx("div",{className:"wb-ask-thread",children:t.jsx(ly,{messages:J,live:g,now:E,working:v||y,partial:k,agents:n,agentName:e.name,agentId:e.id,onOpen:()=>r(q),onReadAloud:(xe,we)=>{U(null),Qh(we,c??void 0,xe).then(Ie=>{Ie&&U(Ie)})},emptyHint:`Ask ${e.name} anything, without leaving this page.`})}),t.jsxs("div",{className:"wb-ask-compose",children:[b?t.jsx(ae,{message:b}):null,t.jsx(CR,{offers:Z,disabled:fe!==null,onTake:ve}),X.length>0?t.jsx(XT,{approvals:X,timezone:s,now:E,version:h,onDecided:be,onSay:xe=>Q(xe,[]),onOpenFull:()=>r(q)}):je&&jv(je)?t.jsx(yR,{card:jv(je),disabled:Oe||v,onAnswer:W},je.id):je?t.jsx(kR,{question:je,disabled:Oe||v,onAnswer:W,onSkip:se},je.id):null,t.jsxs("div",{hidden:X.length>0||je!==null,"data-testid":"composer-slot",children:[t.jsx(yy,{ref:o,disabled:y||!e.available,running:v,onSend:Q,onStop:re,agentName:e.name,placeholder:`Message ${e.name}…`,draft:C,threadKey:`dock.${c??e.id}`,conversationId:c,readAloud:M,onReadAloud:B,team:{agents:n,selfId:e.id},onCommand:_}),z?t.jsx("p",{className:"wb-voice-note",role:"status",children:z}):null]})]})]})}function zn(e){return typeof e=="string"?e:null}function M9(e,n){var r;const s=(r=n.blocks)==null?void 0:r.find(a=>a.type==="text");return!s||s.type!=="text"?!1:e.messages.some(a=>a.role==="user"&&(a.blocks??[]).some(i=>i.type==="text"&&i.text.includes(s.text)))}const RR=3;function O9(e){if(e==="approval"||e==="question")return"accent";if(e==="watcher"||e==="reminder")return"warm";if(e==="failure")return"critical"}function D9(e,n){return e?n?"above-dock":"above-button":"corner"}function L9({placement:e,children:n}){return t.jsx("div",{className:"wb-toast-stack","data-placement":e,children:n})}function F9(e){return e.state==="shown"&&e.seenAt===null}function _9(e){const[n,s]=d.useState([]),r=d.useRef(new Set),a=d.useRef(new Set),i=d.useCallback(()=>{e&&A.notifications(20).then(({notifications:o})=>{const c=o.filter(u=>F9(u)&&!r.current.has(u.id));s(u=>{const h=new Set(u.map(m=>m.id)),f=c.filter(m=>!h.has(m.id));return f.length===0?u:[...u,...f].sort((m,p)=>p.createdAt.localeCompare(m.createdAt))})}).catch(()=>{})},[e]);d.useEffect(()=>{for(const o of n.slice(0,RR))a.current.has(o.id)||(a.current.add(o.id),A.notificationSeen(o.id).catch(()=>{}))},[n]);const l=d.useCallback(o=>{r.current.add(o),s(c=>c.filter(u=>u.id!==o))},[]);return{queue:n,refresh:i,dismiss:l}}function z9({queue:e,agents:n,navigate:s,onDismiss:r}){if(e.length===0)return null;const a=e.slice(0,RR),i=e.length-a.length;return t.jsxs("section",{className:"nt-toasts","aria-label":"Notifications",children:[a.map(l=>t.jsxs("div",{className:"ui-toast nt-toast","data-tone":O9(l.kind),role:"status",children:[l.agentId?t.jsx(jn,{agents:n,id:l.agentId,size:"sm"}):null,t.jsxs("div",{className:"nt-toast-main",children:[t.jsx("div",{className:"ui-toast-title",children:Qc(l)}),l.text?t.jsx("div",{className:"ui-toast-body nt-toast-line",children:U9(l.text)}):null,l.link?t.jsx("a",{className:"nt-toast-link",href:l.link,onClick:o=>{o.preventDefault(),r(l.id),s(l.link)},children:"See"}):null]}),t.jsx("button",{type:"button",className:"nt-toast-x","aria-label":`Dismiss ${Qc(l)}`,onClick:()=>r(l.id),children:"×"})]},l.id)),i>0?t.jsxs("p",{className:"nt-toasts-more",children:["and ",i," more"]}):null]})}function U9(e){var n;return((n=e.split(`
|
|
123
|
-
`).find(s=>s.trim()!==""))==null?void 0:n.trim())??""}const B9=3e4,W9=1e3;function H9(e,n,s){const r=d.useRef(n);r.current=n;const a=d.useRef(s);a.current=s,d.useEffect(()=>{if(!e)return;let i=!1,l=-1/0,o=null,c=null,u=!0;const h=()=>document.visibilityState!=="hidden",f=j=>{var v;l=Date.now(),A.presence(j).catch(w=>{var y;w instanceof he&&w.status===401&&(i=!0,(y=a.current)==null||y.call(a))}),j==="active"&&((v=r.current)==null||v.call(r))},m=j=>{if(i||(o=j,c!==null))return;const v=l+W9-Date.now();if(v<=0){o=null,f(j);return}c=window.setTimeout(()=>{if(c=null,i||o===null)return;const w=o;o=null,f(w)},v)},p=()=>{u=!0,h()&&m("active")},g=()=>{u=!1,m("away")},x=()=>m(h()?"active":"away");h()&&m("active");const k=window.setInterval(()=>{h()&&u&&m("active")},B9);return window.addEventListener("focus",p),window.addEventListener("blur",g),document.addEventListener("visibilitychange",x),()=>{i=!0,window.clearInterval(k),c!==null&&window.clearTimeout(c),window.removeEventListener("focus",p),window.removeEventListener("blur",g),document.removeEventListener("visibilitychange",x)}},[e])}function K9({agents:e,onClose:n,onCreated:s}){return YA(e)?t.jsx(V9,{agents:Bw(e),onClose:n,...s?{onCreated:s}:{}}):t.jsx(Ye,{title:"A new group",onClose:n,children:t.jsxs(G,{children:["A group needs two agents. Make another one with ",t6(e)," first."]})})}function V9({agents:e,onClose:n,onCreated:s}){var j,v;const[r,a]=d.useState(""),[i,l]=d.useState([]),[o,c]=d.useState(((j=e.find(w=>w.roles.includes($u)))==null?void 0:j.id)??((v=e[0])==null?void 0:v.id)??""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=[...new Set([o,...i])].filter(Boolean),g=r.trim()!==""&&o!==""&&p.length>=2,x=w=>l(y=>y.includes(w)?y.filter(N=>N!==w):[...y,w]),k=async()=>{h(!0),m(null);try{s==null||s(await Je.createGroup({name:r.trim(),coordinator:o,members:p.filter(w=>w!==o)}))}catch(w){m(w instanceof he?w.message:String(w))}finally{h(!1)}};return t.jsx(Ye,{title:"A new group",onClose:n,children:t.jsxs(ue,{children:[t.jsx(ie,{label:"Name",hint:"What this team is for: Household finances, The move, Tax season.",children:t.jsx("input",{value:r,autoFocus:!0,maxLength:80,onChange:w=>a(w.target.value),placeholder:"Household finances"})}),t.jsx(ie,{label:"Coordinator",hint:"Reads your request, brings members in, and answers for the group. Concierge by default.",children:t.jsx("select",{value:o,onChange:w=>c(w.target.value),children:e.map(w=>t.jsx("option",{value:w.id,children:w.name},w.id))})}),t.jsx(ie,{label:"Members",hint:"Each keeps its own account, tools and approvals. Membership grants nothing.",children:t.jsx("div",{className:"group-pick",role:"group","aria-label":"Members",children:e.filter(w=>w.id!==o).map(w=>t.jsxs("label",{className:"group-pick-row","data-on":i.includes(w.id)||void 0,children:[t.jsx("input",{type:"checkbox",checked:i.includes(w.id),onChange:()=>x(w.id)}),t.jsx(jn,{agents:e,id:w.id,size:"sm"}),t.jsxs("span",{className:"group-pick-text",children:[t.jsx("span",{className:"group-pick-name",children:w.name}),t.jsx("span",{className:"group-pick-desc",children:w.description})]})]},w.id))})}),t.jsx(G,{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."}),f?t.jsx(G,{tone:"critical",children:f}):null,t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!g||u,onClick:()=>void k(),children:u?"Creating…":"Create group"})]})]})})}const G9=1e4;function iu({title:e,body:n,duration:s,onUndo:r,onGone:a}){return t.jsxs(GL,{className:"ui-toast wb-undo-toast",duration:s,onOpenChange:i=>{i||a()},"data-testid":"undo-toast",children:[t.jsx("span",{className:"ui-toast-mark","aria-hidden":"true"}),t.jsxs("div",{className:"ui-toast-main",children:[t.jsx(YL,{className:"ui-toast-title",children:e}),n?t.jsx(qL,{className:"ui-toast-body",children:n}):null]}),r?t.jsx(QL,{altText:"Undo",asChild:!0,children:t.jsx("button",{type:"button",className:"ui-btn wb-undo-toast-action","data-variant":"ghost","data-size":"sm",onClick:r,children:"Undo"})}):null]})}function by(e){const[n,s]=d.useState(null),[r,a]=d.useState(null),[i,l]=d.useState(null);return{busy:n,note:r,failure:i,decide:async(c,u,h,f)=>{var p,g,x,k;s(c),l(null),a(null);let m;try{const j=f?await A.decide(c,u,h,f):await A.decide(c,u,h);m={decision:u,...(p=j.execution)!=null&&p.state?{state:j.execution.state}:{},...j.execution&&"result"in j.execution?{result:j.execution.result}:{}},a(u==="reject"?`Rejected ${j.action.tool}.`:((g=j.execution)==null?void 0:g.state)==="succeeded"?`Approved and done: ${j.action.tool}.`:`Approved ${j.action.tool}: ${((x=j.execution)==null?void 0:x.state)??"no execution"}${(k=j.execution)!=null&&k.message?` (${j.execution.message})`:""}`)}catch(j){l(j instanceof Error?j.message:String(j))}finally{s(null),e(m)}}}}function ky({action:e,timezone:n,busy:s,onDecide:r,agentName:a}){var h,f;const[i,l]=d.useState(!1),{values:o,controls:c}=Qw(e.choices),u=m=>o?r(e.id,"approve",m,o):r(e.id,"approve",m);return t.jsxs(Ps,{tone:"accent",title:e.tool,meta:t.jsxs(t.Fragment,{children:[t.jsxs(Ae,{children:["v",e.toolVersion]}),t.jsxs("span",{className:"muted",children:["asked by ",a??e.agentId]})]}),children:[t.jsx(zt,{children:e.preview}),t.jsxs("p",{className:"ui-card-meta",children:["Expires ",mt(e.expiresAt,n)," (",Ge(e.expiresAt),"). Policy v",e.policyVersion,", args ",qc(e.argsHash,12),e.jobId?`, job ${qc(e.jobId)}`:"","."]}),c,t.jsxs(ne,{children:[t.jsx($,{variant:"good",disabled:s,onClick:()=>u(),children:(h=e.permissionScopes)!=null&&h.length?"Allow once":"Approve"}),(f=e.permissionScopes)!=null&&f.length?t.jsxs(t.Fragment,{children:[t.jsx($,{disabled:s,onClick:()=>u("conversation"),children:"Auto: this conversation"}),t.jsx($,{disabled:s,onClick:()=>u("always"),children:"Always: this agent"})]}):null,t.jsx($,{variant:"danger",disabled:s,onClick:()=>r(e.id,"reject"),children:"Reject"}),t.jsx($,{variant:"ghost",onClick:()=>l(m=>!m),"aria-expanded":i,children:i?"Hide envelope":"Show envelope"})]}),i?t.jsxs("div",{className:"ui-card-foot",children:[t.jsx(pe,{title:"Envelope: everything that decides what the world will see",children:t.jsx(zt,{children:Cs(e.envelope)})}),t.jsx(pe,{title:"Canonical arguments",children:t.jsx(zt,{children:Cs(e.canonicalArgs)})})]}):null]})}function Ny(e,n,s){const[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null);return{accept:()=>{e&&(a(!0),c(null),A.acceptPluginAgent(e,n).then(h=>{l(h.agent),s==null||s(h.agent)}).catch(h=>c(h instanceof he?h.message:String(h))).finally(()=>a(!1)))},busy:r,created:i,failure:o}}function IR({agent:e}){return t.jsxs(G,{tone:"good",role:"status",children:["@",e.handle," is ready. ",t.jsxs("a",{href:at(e.id),children:["Talk to @",e.handle]})]})}function PR(e,n,s){const r=e.canonicalArgs;return e.tool==="platform.accept_plugin_agent"&&(r==null?void 0:r.plugin)===n&&typeof r.agent=="string"&&r.agent.toLowerCase()===s.toLowerCase()}function Y9(e,n){var a;const s=ge(()=>A.approvals(),[e,n],15e3);return{action:((a=s.data)==null?void 0:a.pending.find(i=>PR(i,e,n)))??null,reload:s.reload}}function q9({action:e,onDecided:n}){const{busy:s,failure:r,decide:a}=by(i=>n(i));return t.jsxs(ue,{gap:"sm",children:[t.jsx(ky,{action:e,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,busy:s===e.id,onDecide:(i,l,o,c)=>{a(i,l,o,c)}}),t.jsx(ae,{message:r})]})}function Sy({plugin:e,agent:n,text:s,label:r,handle:a,onDismiss:i}){var f;const l=Ny(e,n),o=Y9(e,n),[c,u]=d.useState(null),h=l.created??c;if(h)return t.jsx(IR,{agent:h});if(o.action){const m=a??((f=/@(\S+)/.exec(r))==null?void 0:f[1])??n;return t.jsxs(ue,{gap:"sm",children:[t.jsx("span",{children:s}),t.jsx(q9,{action:o.action,onDecided:p=>{(p==null?void 0:p.decision)==="approve"&&p.state==="succeeded"?u({id:n,handle:m,name:m}):o.reload()}})]})}return t.jsxs(ue,{gap:"sm",children:[t.jsxs(ne,{children:[t.jsx("span",{children:s}),t.jsx(ot,{}),i?t.jsx($,{variant:"ghost",disabled:l.busy,onClick:i,children:"Not now"}):null,t.jsx($,{variant:"accent",disabled:l.busy,onClick:l.accept,children:r})]}),t.jsx(ae,{message:l.failure})]})}function MR(){var n;const e=ge(()=>A.agentOffers(),[],6e4);return{offers:((n=e.data)==null?void 0:n.offers)??[],reload:e.reload}}function OR({offers:e,reload:n}){return e.length===0?null:t.jsx(pe,{title:"From your plugins",aside:`${e.length} to decide`,panel:!0,children:t.jsx(ue,{gap:"sm",divided:!0,children:e.map(s=>t.jsx(Sy,{plugin:s.plugin,agent:s.agent,text:s.text,label:`Create @${s.handle}`,handle:s.handle,onDismiss:()=>{A.dismissAgentOffer(s.plugin,s.agent).then(n,n)}},`${s.plugin}/${s.agent}`))})})}const Q9=512*1024,J9=/^[A-Za-z0-9+/]*={0,2}$/;function DR(e){const n=e==null?void 0:e.play;if(typeof n!="object"||n===null)return null;const{mime:s,data:r}=n;return typeof s!="string"||!/^audio\/[a-z0-9.+-]+$/i.test(s.split(";")[0].trim())||typeof r!="string"||r===""||!J9.test(r)||Math.floor(r.length*3/4)>Q9+2?null:{mime:s,data:r}}function LR(e){const n=e==null?void 0:e.message;return typeof n=="string"&&n.trim()!==""?n:null}let sa=null,bc=null,lu=null;const kv=new Set;function FR(){for(const e of kv)e()}function ac(){sa&&(sa.onended=null,sa.onerror=null,sa.pause()),bc&&URL.revokeObjectURL(bc),bc=null,lu!==null&&(lu=null,FR())}async function _R(e,n){ac();const s=atob(e.data),r=new Uint8Array(s.length);for(let a=0;a<s.length;a+=1)r[a]=s.charCodeAt(a);sa??(sa=new Audio),bc=URL.createObjectURL(new Blob([r],{type:e.mime})),lu=n,sa.onended=ac,sa.onerror=ac,sa.src=bc,FR();try{await sa.play()}catch{throw ac(),new Error("The browser would not play the sound.")}}function QN(e){e!==void 0&&lu!==e||ac()}function X9(){return d.useSyncExternalStore(e=>(kv.add(e),()=>kv.delete(e)),()=>lu,()=>null)}const Z9=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Nr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],JN=/^\d{4}-\d{2}-\d{2}$/;function Oi(e){return e.split("-").map(Number)}function fi(e,n){const[s,r,a]=Oi(e);return new Date(Date.UTC(s,r-1,a+n)).toISOString().slice(0,10)}function zR(e){const[n,s,r]=Oi(e);return new Date(Date.UTC(n,s-1,r)).getUTCDay()}function UR(e){return Z9[zR(e)]}function BR(e){return Oi(e)[2]}function XN(e){return fi(e,-((zR(e)+6)%7))}function Qn(e){return bu(e,{weekday:!0,compact:!0})}function eV(e,n){return e===n?`Today · ${Qn(e)}`:e===fi(n,1)?`Tomorrow · ${Qn(e)}`:Qn(e)}function lr(e){return I_(e)}const ZN=new Map;function Nv(e,n){let s=ZN.get(n);s||(s=new Intl.DateTimeFormat("en-GB",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}),ZN.set(n,s));const r=Object.fromEntries(s.formatToParts(e).map(a=>[a.type,a.value]));return{date:`${r.year}-${r.month}-${r.day}`,minutes:Number(r.hour)*60+Number(r.minute)}}function tV(e,n=new Date){return Nv(n,e).date}function nV(e,n){return e==="week"?{from:XN(n),days:7}:e==="month"?{from:XN(`${n.slice(0,8)}01`),days:42}:{from:n,days:7}}function sV(e,n,s){if(e!=="month")return fi(n,s*7);const[r,a]=Oi(n);return new Date(Date.UTC(r,a-1+s,1)).toISOString().slice(0,10)}function rV(e,n,s,r){const[a,i]=Oi(n);if(e==="month")return O$(a,i);const l=fi(s,r-1),[o,c,u]=Oi(s),[h,f,m]=Oi(l);return P$().date==="iso"?`${s} – ${l}`:P_()?c===f&&o===h?`${Nr[c-1]} ${u} – ${m}, ${h}`:o===h?`${Nr[c-1]} ${u} – ${Nr[f-1]} ${m}, ${h}`:`${Nr[c-1]} ${u}, ${o} – ${Nr[f-1]} ${m}, ${h}`:c===f&&o===h?`${u} – ${m} ${Nr[f-1]} ${h}`:o===h?`${u} ${Nr[c-1]} – ${m} ${Nr[f-1]} ${h}`:`${u} ${Nr[c-1]} ${o} – ${m} ${Nr[f-1]} ${h}`}function gl(e){return e==null?"":String(e)}function aV(e,n,s,r){const a=[],i=new Set;return e.forEach((l,o)=>{const c=gl(Re(l,n.id)),u=gl(Re(l,n.title)),h=gl(Re(l,n.start)),f=gl(Re(l,n.end));if(c===""||i.has(c)||h===""){console.warn(`buddi: ${r}: event ${o} has no id, a repeated one, or no start — not drawn`);return}i.add(c);const m=n.allDay===void 0?void 0:Re(l,n.allDay),p=m===void 0?JN.test(h):m===!0||m==="true",g=n.tone===void 0?0:Number(Re(l,n.tone)),x=Number.isFinite(g)?(Math.trunc(g)%4+4)%4:0,k={id:c,title:u,calendar:n.calendar===void 0?"":gl(Re(l,n.calendar)),tone:x,location:n.location===void 0?"":gl(Re(l,n.location)),row:l};if(p){const N=h.slice(0,10),b=JN.test(f.slice(0,10))&&f.slice(0,10)>N?f.slice(0,10):fi(N,1);a.push({...k,allDay:!0,startDate:N,startMin:0,endDate:b,endMin:0});return}const j=new Date(h);if(Number.isNaN(j.getTime())){console.warn(`buddi: ${r}: event ${o} starts at "${h}", which is not a time — not drawn`);return}const v=new Date(f),w=Nv(j,s),y=Number.isNaN(v.getTime())||v<j?w:Nv(v,s);a.push({...k,allDay:!1,startDate:w.date,startMin:w.minutes,endDate:y.date,endMin:y.minutes})}),a}function iV(e,n){if(e.allDay)return n>=e.startDate&&n<e.endDate?{from:0,to:1440,allDay:!0}:null;if(n<e.startDate||n>e.endDate)return null;const s=n===e.startDate?e.startMin:0,r=n===e.endDate?e.endMin:1440,a=e.startDate===e.endDate&&e.startMin===e.endMin;return r<=s&&!(a&&n===e.startDate)?null:{from:s,to:r,allDay:s===0&&r===1440}}function Cy(e,n){return e.map(s=>({event:s,part:iV(s,n)})).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 Ey(e,n){if(n.allDay)return"All day";const s=e.startDate!==e.endDate;return s&&n.from===0?`until ${lr(n.to)}`:s&&n.to===1440?`from ${lr(n.from)}`:n.from===n.to?lr(n.from):`${lr(n.from)}–${lr(n.to)}`}function Sv(e,n,s){return[Ey(e,n),e.title,e.location,e.calendar,Qn(s)].filter(Boolean).join(", ")}const WR=30;function lV(e){const n=[];let s=[],r=-1;const a=[],i=()=>{const l=Math.max(1,...s.map(o=>o.lane+1));for(const o of s)n.push({...o,lanes:l});s=[],a.length=0};for(const l of e){const o=Math.max(l.part.to,l.part.from+WR);s.length>0&&l.part.from>=r&&i();let c=a.findIndex(u=>u<=l.part.from);c===-1?(c=a.length,a.push(o)):a[c]=o,s.push({...l,lane:c,lanes:1}),r=Math.max(r,o)}return s.length>0&&i(),n}function oV(e){if(e<60)return`${e} min`;const n=Math.floor(e/60),s=e%60;return s===0?`${n} h`:`${n} h ${String(s).padStart(2,"0")}`}function cV(e){if(e.allDay){const a=fi(e.endDate,-1);return a>e.startDate?`${Qn(e.startDate)} – ${Qn(a)} · all day`:`${Qn(e.startDate)} · all day`}const n=Math.round((Date.parse(`${e.endDate}T00:00:00Z`)-Date.parse(`${e.startDate}T00:00:00Z`))/864e5),s=n*1440+e.endMin-e.startMin,r=n===0?`${Qn(e.startDate)} · ${lr(e.startMin)}–${lr(e.endMin)}`:`${Qn(e.startDate)} ${lr(e.startMin)} – ${Qn(e.endDate)} ${lr(e.endMin)}`;return s>0?`${r} · ${oV(s)}`:r}const uV={week:"Week",month:"Month",list:"List"},dV=["week","month","list"],hV="(max-width: 720px)";function fV(e){try{return window.localStorage.getItem(e)}catch{return null}}function mV(e,n){try{window.localStorage.setItem(e,n)}catch{}}function pV(e){const n=e.views&&e.views.length>0?e.views:dV,s=fs(hV),[r,a]=d.useState(()=>{const p=fV(e.storageKey);return p!==null&&n.includes(p)?p:null}),i=s&&n.includes("list")?"list":e.default&&n.includes(e.default)?e.default:n[0],l=r??i,[o,c]=d.useState(e.today),[u,h]=d.useState(null),{from:f,days:m}=nV(l,o);return{views:n,view:l,setView:p=>{a(p),mV(e.storageKey,p),h(null)},anchor:o,today:e.today,go:p=>{c(p===0?e.today:sV(l,o,p)),h(null)},from:f,days:m,to:fi(f,m),selected:u,select:h}}function gV({state:e,events:n,hours:s,empty:r,label:a,onEvent:i,count:l}){const{view:o,anchor:c,today:u,from:h,days:f}=e,m=d.useMemo(()=>Array.from({length:f},(j,v)=>fi(h,v)),[h,f]),p=o==="month"?"month":"week",g=e.selected??(c.slice(0,7)===u.slice(0,7)?u:`${c.slice(0,8)}01`),x=o==="month"?g:o==="week"&&!i?e.selected:null,k=j=>{if(!j.target.closest('input, textarea, select, [contenteditable="true"]')&&!(j.altKey||j.ctrlKey||j.metaKey)){if(j.key==="ArrowLeft")e.go(-1);else if(j.key==="ArrowRight")e.go(1);else if(j.key==="t"||j.key==="T")e.go(0);else return;j.preventDefault()}};return t.jsxs("div",{className:"cal",role:"region","aria-label":a,tabIndex:0,onKeyDown:k,children:[t.jsxs("div",{className:"cal-bar",children:[t.jsx($,{size:"sm","aria-label":`Previous ${p}`,onClick:()=>e.go(-1),children:t.jsx(oe,{name:"chevron-left",size:14})}),t.jsx($,{size:"sm",onClick:()=>e.go(0),children:"Today"}),t.jsx($,{size:"sm","aria-label":`Next ${p}`,onClick:()=>e.go(1),children:t.jsx(oe,{name:"chevron-right",size:14})}),t.jsxs("h3",{className:"cal-title","aria-live":"polite",children:[rV(o,c,h,f),l!==void 0?t.jsx("span",{className:"cal-count",children:l===0?"No events":l===1?"1 event":`${l} events`}):null]}),e.views.length>1?t.jsx(Gt,{label:"View",options:e.views.map(j=>({value:j,label:uV[j]})),value:o,onChange:e.setView}):null]}),o==="week"?t.jsx(xV,{dates:m,today:u,events:n,hours:s??[7,21],onPick:e.select,onEvent:i}):null,o==="month"?t.jsx(jV,{dates:m,month:c.slice(0,7),today:u,events:n,selected:g,onPick:e.select,onEvent:i}):null,o==="list"?t.jsx("div",{className:"cal-list",children:m.map(j=>t.jsx(eS,{date:j,today:u,events:n,empty:r,onEvent:i},j))}):null,x?t.jsx(eS,{date:x,today:u,events:n,empty:r,onEvent:i}):null]})}function eS({date:e,today:n,events:s,empty:r,onEvent:a}){const i=Cy(s,e);return t.jsx(Xe,{flush:!0,title:eV(e,n),children:t.jsx(ct,{children:i.length===0?t.jsx(rt,{title:t.jsx("span",{className:"muted",children:r})}):i.map(({event:l,part:o})=>t.jsx(rt,{lead:t.jsx("span",{className:"cal-dot","data-tone":l.tone,"aria-hidden":"true"}),title:l.title,sub:l.location||void 0,side:Ey(l,o),...a?{onClick:()=>a(l)}:{}},l.id))})})}function xV({dates:e,today:n,events:s,hours:r,onPick:a,onEvent:i}){const l=d.useRef(null);d.useLayoutEffect(()=>{const h=l.current;h&&(h.scrollTop=h.scrollHeight/24*r[0])},[r[0]]);const o=wV(l),c=e.map(h=>({date:h,items:Cy(s,h)})),u=h=>h===n?"true":void 0;return t.jsx(Xe,{flush:!0,children:t.jsxs("div",{className:"cal-week",role:"grid","aria-label":`Week of ${Qn(e[0])}`,style:{"--cal-span":r[1]-r[0],"--cal-scrollbar":`${o}px`},children:[t.jsxs("div",{className:"cal-row",role:"row",children:[t.jsx("span",{className:"cal-gutter","aria-hidden":"true"}),e.map(h=>t.jsxs("div",{className:"cal-day-head",role:"columnheader","data-today":u(h),"aria-label":Qn(h),children:[t.jsx("span",{className:"cal-wd",children:UR(h)}),t.jsx("span",{className:"cal-num",children:BR(h)})]},h))]}),t.jsxs("div",{className:"cal-row cal-allday",role:"row",children:[t.jsx("span",{className:"cal-gutter cal-gutter-label",children:"All day"}),c.map(({date:h,items:f})=>t.jsx("div",{className:"cal-allday-cell",role:"gridcell","data-today":u(h),children:f.filter(m=>m.part.allDay).map(({event:m,part:p})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":m.tone,"aria-label":Sv(m,p,h),onClick:()=>i?i(m):a(h),children:m.title},m.id))},h))]}),t.jsx("div",{className:"cal-scroll",ref:l,children:t.jsxs("div",{className:"cal-row cal-times",role:"row",children:[t.jsx("div",{className:"cal-gutter cal-hours","aria-hidden":"true",children:Array.from({length:23},(h,f)=>f+1).map(h=>t.jsx("span",{className:"cal-hour-label",style:{top:`calc(var(--cal-hour) * ${h})`},children:lr(h*60)},h))}),c.map(({date:h,items:f})=>t.jsx("div",{className:"cal-col",role:"gridcell","aria-label":Qn(h),"data-today":u(h),children:lV(f.filter(m=>!m.part.allDay)).map(({event:m,part:p,lane:g,lanes:x})=>t.jsxs("button",{type:"button",className:"cal-event","data-tone":m.tone,"data-short":p.to-p.from<60?"true":void 0,"data-lane":g,"aria-label":Sv(m,p,h),onClick:()=>i?i(m):a(h),style:{top:`calc(var(--cal-hour) * ${p.from/60})`,height:`calc(var(--cal-hour) * ${Math.max(p.to-p.from,WR)/60})`,left:`calc((100% - var(--space-1)) * ${g/x} + var(--space-0))`,width:`calc((100% - var(--space-1)) / ${x} - var(--space-0))`},children:[t.jsx("span",{className:"cal-event-time",children:Ey(m,p)}),t.jsx("span",{className:"cal-event-title",children:m.title})]},m.id))},h))]})})]})})}const vV=3;function jV({dates:e,month:n,today:s,events:r,selected:a,onPick:i,onEvent:l}){const o=Array.from({length:6},(f,m)=>e.slice(m*7,m*7+7)),[c,u]=n.split("-").map(Number),h=O$(c,u);return t.jsx(Xe,{flush:!0,children:t.jsxs("div",{className:"cal-month",role:"grid","aria-label":h,children:[t.jsx("div",{className:"cal-row",role:"row",children:e.slice(0,7).map(f=>t.jsx("div",{className:"cal-wd-head",role:"columnheader",children:UR(f)},f))}),o.map(f=>t.jsx("div",{className:"cal-row",role:"row",children:f.map(m=>{const p=Cy(r,m),g=p.slice(0,vV),x=p.length-g.length,k=p.length===0?"nothing":p.length===1?"1 event":`${p.length} events`;return t.jsxs("div",{className:"cal-cell",role:"gridcell","aria-selected":m===a,"data-date":m,"data-today":m===s?"true":void 0,"data-outside":m.slice(0,7)!==n?"true":void 0,"data-selected":m===a?"true":void 0,onClick:()=>i(m),children:[t.jsx("button",{type:"button",className:"cal-num","aria-label":`${Qn(m)}, ${k}`,"aria-pressed":m===a,children:BR(m)}),g.map(({event:j,part:v})=>t.jsx("button",{type:"button",className:"cal-chip","data-tone":j.tone,"data-timed":v.allDay?void 0:"true","aria-label":Sv(j,v,m),...l?{onClick:w=>{w.stopPropagation(),i(m),l(j)}}:{},children:v.allDay?j.title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"cal-dot","data-tone":j.tone,"aria-hidden":"true"}),t.jsx("span",{className:"cal-chip-time",children:lr(v.from)})," ",j.title]})},j.id)),x>0?t.jsxs("button",{type:"button",className:"cal-more","aria-label":`${x} more on ${Qn(m)}`,children:["+",x]}):null]},m)})},f[0]))]})})}function wV(e){const[n,s]=d.useState(0);return d.useLayoutEffect(()=>{const r=e.current;if(!r)return;const a=()=>s(Math.max(0,r.offsetWidth-r.clientWidth));if(a(),typeof ResizeObserver>"u")return;const i=new ResizeObserver(a);return i.observe(r),()=>i.disconnect()},[e]),n}const HR={width:1200,height:200,top:28,right:12,bottom:24,left:36};function yV(e,n){if(n==="percent")return[0,50,100];let s=e.length>0?Math.min(...e):0,r=e.length>0?Math.max(...e):1;n!=="temp"&&(s=Math.min(0,s)),s===r&&(s-=1,r+=1);const a=10**Math.floor(Math.log10(Math.max(1,(r-s)/3))),i=c=>Math.ceil(r/c)-Math.floor(s/c);let l=[1,2,5,10].map(c=>c*a).find(c=>i(c)<=3)??a*10;i(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 Sd(e,n){return n==="temp"?`${e}°`:n==="percent"?`${e}%`:String(e)}function bV(e){const n=HR,s=e.values.length,r=n.width-n.left-n.right,a=n.height-n.top-n.bottom,i=n.height-n.bottom,l=s>0?r/s:r,o=j=>Ni(n.left+l*(j+.5)),c=e.values.filter(j=>j!==null&&Number.isFinite(j)),u=yV(c,e.unit),h=u[0],f=u[u.length-1],m=j=>Ni(n.top+a-(j-h)/(f-h)*a),p=e.values.map((j,v)=>{const w=j!==null&&Number.isFinite(j);return{index:v,x:o(v),y:w?m(j):null,value:w?j:null}}),g=[],x=[];if(e.kind==="area"){let j=[];const v=()=>{if(j.length===0)return;const w=j.map((y,N)=>`${N===0?"M":"L"}${y.x},${y.y}`).join(" ");g.push(w),x.push(`${w} L${j[j.length-1].x},${i} L${j[0].x},${i} Z`),j=[]};for(const w of p)w.y===null?v():j.push(w);v()}const k=e.kind==="bars"?p.flatMap(j=>j.y===null?[]:[{index:j.index,x:Ni(j.x-l*.28),y:j.y,width:Ni(l*.56),height:Ni(i-j.y)}]):[];return{ticks:u.map(j=>({value:j,y:m(j)})),lines:g,areas:x,bars:k,points:p,slot:l,floor:i}}function kV({title:e,note:n,xs:s,series:r,tiles:a,labelEvery:i=3}){var N;const[l,o]=d.useState(((N=r[0])==null?void 0:N.id)??""),[c,u]=d.useState(null),[h,f]=d.useState(null),m=d.useRef(null),p=s.length,g=c??h,x=r.find(b=>b.id===l)??r[0],k=bV(x),j=HR,v=b=>b%i===0||b===g,w=x.values.filter(b=>b!==null&&Number.isFinite(b));d.useEffect(()=>{const b=m.current,S=g===null?null:b==null?void 0:b.children[g];!b||!S||typeof b.scrollTo!="function"||(S.offsetLeft<b.scrollLeft?b.scrollTo({left:S.offsetLeft,behavior:"smooth"}):S.offsetLeft+S.offsetWidth>b.scrollLeft+b.clientWidth&&b.scrollTo({left:S.offsetLeft+S.offsetWidth-b.clientWidth,behavior:"smooth"}))},[g]);const y=b=>{var T,E,R;const S=b.key==="ArrowRight"?1:b.key==="ArrowLeft"?-1:0,C=b.key==="Home"?0:b.key==="End"?p-1:S===0?null:Math.max(0,Math.min(p-1,(h??-S)+S));C!==null&&(b.preventDefault(),f(C),(R=(E=(T=m.current)==null?void 0:T.children[C])==null?void 0:E.querySelector("button"))==null||R.focus())};return t.jsxs(Xe,{...e?{title:e}:{},children:[n?t.jsx("p",{className:"ui-panel-sub",children:n}):null,t.jsxs("div",{className:"pg-series",onMouseLeave:()=>u(null),children:[r.length>1?t.jsx("div",{className:"pg-series-tabs",role:"tablist","aria-label":"Series",children:r.map(b=>t.jsx("button",{type:"button",role:"tab",className:"ui-tab","aria-selected":b.id===x.id,onClick:()=>o(b.id),children:b.label},b.id))}):null,t.jsxs("figure",{className:"pg-series-chart","data-kind":x.kind,children:[t.jsxs("svg",{viewBox:`0 0 ${j.width} ${j.height}`,"aria-hidden":"true",focusable:"false","data-testid":"series-svg",children:[k.ticks.map(b=>t.jsxs("g",{children:[t.jsx("line",{className:"pg-series-grid",x1:j.left,x2:j.width-j.right,y1:b.y,y2:b.y}),t.jsx("text",{className:"pg-series-tick",x:j.left-8,y:b.y,textAnchor:"end",dominantBaseline:"middle",children:Sd(b.value,x.unit)})]},b.value)),k.areas.map((b,S)=>t.jsx("path",{className:"pg-series-area",d:b},`a${S}`)),k.lines.map((b,S)=>t.jsx("path",{className:"pg-series-line",d:b},`l${S}`)),k.bars.map(b=>t.jsx("rect",{className:"pg-series-bar","data-index":b.index,"data-hover":b.index===g?"true":void 0,x:b.x,y:b.y,width:b.width,height:b.height},b.index)),g!==null&&k.points[g]?t.jsx("line",{className:"pg-series-guide","data-index":g,x1:k.points[g].x,x2:k.points[g].x,y1:j.top-4,y2:k.floor}):null,x.kind==="area"?k.points.map(b=>b.y!==null&&v(b.index)?t.jsx("circle",{className:"pg-series-dot","data-index":b.index,"data-hover":b.index===g?"true":void 0,cx:b.x,cy:b.y,r:b.index===g?5:3},b.index):null):null,k.points.map(b=>b.y!==null&&b.value!==null&&v(b.index)?t.jsx("text",{className:"pg-series-value","data-index":b.index,"data-hover":b.index===g?"true":void 0,x:b.x,y:b.y-(x.kind==="area"?10:6),textAnchor:"middle",children:Sd(b.value,x.unit)},b.index):null),k.points.map(b=>b.index%i===0?t.jsx("text",{className:"pg-series-x",x:b.x,y:j.height-6,textAnchor:"middle",children:s[b.index]},b.index):null),k.points.map(b=>t.jsx("rect",{className:"pg-series-hit","data-index":b.index,x:Ni(j.left+k.slot*b.index),y:0,width:Ni(k.slot),height:j.height,onMouseEnter:()=>u(b.index),onClick:()=>f(b.index)},b.index))]}),t.jsx("figcaption",{className:"sr-only",children:w.length===0?`${x.label}: no values.`:`${x.label}, ${p} ${p===1?"point":"points"} from ${s[0]} to ${s[p-1]}: lowest ${Sd(Math.min(...w),x.unit)}, highest ${Sd(Math.max(...w),x.unit)}.`})]}),t.jsx("ul",{className:"wb-tiles","data-layout":"strip",ref:m,onKeyDown:y,children:a.map((b,S)=>t.jsx("li",{className:"wb-tile",children:t.jsx("button",{type:"button",className:"ui-card","data-index":S,"data-hover":S===g?"true":void 0,"aria-pressed":S===h,"aria-label":[b.label,b.value,...b.lines].filter(C=>C!=="").join(", "),onMouseEnter:()=>u(S),onClick:()=>f(S),children:t.jsxs("div",{className:"wb-tile-body","aria-hidden":"true",children:[t.jsx("span",{className:"wb-tile-icon","data-icon":b.icon??"dot",children:t.jsx(oe,{name:$o(b.icon),size:22})}),b.value!==""?t.jsx("span",{className:"wb-tile-value tnum",children:b.value}):null,t.jsx("span",{className:"wb-tile-label",children:b.label}),b.lines.map((C,T)=>t.jsx("span",{className:"wb-tile-line",children:C},T))]})})},S))})]})]})}function Ni(e){return Math.round(e*10)/10}const $y=d.createContext(null),Jh=d.createContext(!1);function vt(){const e=d.useContext($y);if(!e)throw new Error("a plugin page component outside a plugin page");return e}function Cv(e,n=new Set){if(Array.isArray(e))for(const s of e)Cv(s,n);else if(e&&typeof e=="object"){const s=e.query;typeof s=="string"&&n.add(s);for(const r of Object.values(e))Cv(r,n)}return n}function KR(e,n){if(n.size===0)return!1;for(const s of Cv(e))if(n.has(s))return!0;return!1}function VR(){const[e,n]=d.useState(!1);return d.useEffect(()=>{if(!e)return;const s=()=>{document.visibilityState==="hidden"&&n(!1)};return document.addEventListener("visibilitychange",s),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",s),window.removeEventListener("blur",s)}},[e]),[e,()=>n(s=>!s)]}function GR({revealed:e,onToggle:n}){return t.jsx($,{size:"sm",variant:"ghost","aria-pressed":e,onClick:n,children:e?"Hide":"Show"})}function YR(){return t.jsx("p",{className:"muted",children:"Hidden until you show it."})}function qR({children:e}){const[n,s]=VR();return t.jsxs(ue,{gap:"sm",children:[t.jsx(ne,{align:"end",children:t.jsx(GR,{revealed:n,onToggle:s})}),n?t.jsx(Jh.Provider,{value:!0,children:e}):t.jsx(YR,{})]})}function Ay(e){return e===void 0||e==="neutral"?void 0:e}function Ev(e){return Ay(e)}function NV(e){const n=Ay(e);return n==="accent"?void 0:n}function Ht(e,n){if(!n)return!0;const s=Re(e,n.path),r=n.in!==void 0?n.in.includes(s):s===n.equals;return n.not===!0?!r:r}function Xh(e){if(typeof e!="string"||e.length>2048)return null;try{const n=new URL(e);return n.protocol==="https:"&&n.hostname!==""&&n.username===""&&n.password===""?n.href:null}catch{return null}}function SV({plugin:e,images:n,row:s}){const a=(Array.isArray(n)?n.map(l=>({asset:Ke(s,l.asset),label:String(Ke(s,l.label)??"").trim()})):(()=>{const l=Re(s,n.from);return(Array.isArray(l)?l:[]).map(o=>({asset:Re(o,n.asset),label:String(Re(o,n.label)??"").trim()}))})()).filter(l=>l.label!=="");if(a.length===0)return null;const i=a.length===1?a[0].label:`${a[0].label} and ${a.length-1} more`;return t.jsxs("span",{className:"pl-stack","data-testid":"row-images",children:[t.jsx("span",{className:"pl-stack-logos",children:a.slice(0,3).map((l,o)=>t.jsx(To,{src:Iu(e,l.asset),label:l.label},o))}),t.jsx("span",{className:"pl-stack-words",children:i})]})}function ro({href:e,children:n,className:s}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:s,onClick:r=>r.stopPropagation(),children:[n,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),t.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}function ba(e,n,s){if("href"in n)return Xh(Ke(s,n.href))??"";if("chat"in n){const i=Ke(s,n.chat);return i==null?"":at(String(i))}if("proposals"in n)return oU(e.plugin);const r=e.pages.find(i=>i.id===n.page);if((r==null?void 0:r.place)==="settings")return mr(e.plugin,n.page);const a=n.item===void 0?null:Ke(s,n.item);return _r(e.plugin,n.page,a==null?null:String(a))}function ls(e,n){return e.replace(/\{count\}/g,String(n.count??0)).replace(/\{([^{}|]+)\|([^{}|]+)\}/g,(s,r,a)=>(n.count??0)===1?r:a).replace(/\{([A-Za-z_][A-Za-z0-9_.]*)\}/g,(s,r)=>{const a=Re(n.row,r);return a==null?"":String(a)})}function Zh(e,n){if(e===void 0)return;if(typeof e=="string")return e;const s=Ke(n,e);return s==="good"||s==="warning"||s==="critical"||s==="neutral"?s:void 0}function QR(e,n,s){const r={};for(const[a,i]of Object.entries(e??{})){let l;"param"in i?l=s.params[i.param]:"route"in i?l=i.route==="plugin"?s.plugin:i.route==="page"?s.page:s.item:l=Ke(n,i),!(l==null||l==="")&&(r[a]=String(l))}return r}function Js(e,n){var r,a,i;const s={};for(const[l,o]of Object.entries(e??{}))if("row"in o)s[l]=Re(n.row,o.row);else if("choice"in o)s[l]=n.choice;else if("field"in o){if((r=n.omit)!=null&&r.has(o.field))continue;const c=(a=n.fields)==null?void 0:a[o.field],u=(i=n.shape)==null?void 0:i.find(h=>h.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]=n.selected??[]:"param"in o?s[l]=n.scope.params[o.param]:s[l]=Ke(n.data,o);return s}function Dn(e,n,s,r){const a=vt(),i=e?{...QR(e.params,n,a),...r}:{},l=JSON.stringify([(e==null?void 0:e.query)??null,i,a.version]),o=ge(()=>e?A.pageQuery(a.plugin,e.query,i).then(c=>c.data):Promise.resolve(void 0),[l],s);return{data:o.data,error:o.error,loading:o.loading}}function ka(){const e=vt(),n=d.useId(),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=(j,v)=>{if(j.done===void 0)return null;if(typeof j.done=="string")return j.done;const w=Ke(v,j.done);return w==null?null:String(w)},p=(j,v,w)=>{const y=j??"refresh";if(typeof y=="object"){const N="href"in y.route?"":ba(e,y.route,v);N===""?e.refresh():e.navigate(N);return}y==="close"&&(w==null||w()),e.refresh()},g=async(j,v,w)=>{r(j.tool),i(null),o(null);try{const y=await A.pageAct(e.plugin,{tool:j.tool,args:v});if(y.approvalId)return u(y.approvalId),f({then:j.then,ref:j,...w?{onDone:w}:{}}),!1;u(null),f(null);const N=DR(y.result);return o(m(j,y.result)??(N?LR(y.result):null)),N&&await _R(N,n),p(j.then,y.result,w),!0}catch(y){return i(y instanceof Error?y.message:String(y)),e.refresh(),!1}finally{r(null)}},x=j=>{if(!j){e.refresh();return}const v=h;if(u(null),f(null),v&&j.decision==="approve"&&j.state==="succeeded"){o(m(v.ref,j.result)),p(v.then,void 0,v.onDone);return}e.refresh()},k=()=>{i(null),o(null)};return{running:s,busy:s!==null,error:a,done:l,approvalId:c,waiting:(h==null?void 0:h.ref.pending)??null,settle:x,run:g,reset:k}}function nl({action:e,args:n,disabled:s,running:r,count:a,row:i,onRun:l}){const[o,c]=d.useState(!1),u=f=>ls(f,{...a===void 0?{}:{count:a},row:i}),h=u(e.label);return o&&e.confirm?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"ui-toolbar-note",children:u(e.confirm)}),t.jsx($,{variant:"ghost",onClick:()=>c(!1),children:"Cancel"}),t.jsxs($,{variant:e.tone==="danger"?"danger":"accent",disabled:s,onClick:()=>{c(!1),l(e,n)},children:["Yes, ",h.toLowerCase()]})]}):t.jsx($,{variant:e.tone==="danger"?"danger":e.tone==="accent"?"accent":void 0,disabled:s,onClick:()=>e.confirm?c(!0):l(e,n),children:r&&e.busy?e.busy:h})}function ef({id:e,onDecided:n}){const s=vt(),r=ge(()=>A.approval(e),[e,s.version]),{busy:a,note:i,failure:l,decide:o}=by(c=>{n?n(c):s.refresh()});return r.error?t.jsx(ae,{message:r.error}):r.data?t.jsxs(ue,{children:[t.jsx(ky,{action:r.data,timezone:s.timezone,busy:a===e,onDecide:(c,u,h,f)=>{o(c,u,h,f)}}),i?t.jsx(G,{tone:"good",role:"status",children:i}):null,t.jsx(ae,{message:l})]}):t.jsx(Ne,{children:"Loading the approval…"})}function Br({act:e}){return e.error?t.jsx(ae,{message:e.error}):e.approvalId?e.waiting?t.jsxs(ue,{children:[t.jsx(G,{role:"status",children:e.waiting}),t.jsx(ef,{id:e.approvalId,onDecided:e.settle})]}):t.jsx(ef,{id:e.approvalId,onDecided:e.settle}):e.done?t.jsx(G,{tone:"good",role:"status",children:e.done}):null}function ou(e,n){const s={};for(const r of e){const a=r.from===void 0?void 0:Re(n,r.from);s[r.name]=r.multiple?Array.isArray(a)?a.map(String):[]:a!==void 0?a:r.type==="checkbox"?!1:""}return s}function JR(e,n,s){const r=vt(),a=e.optionsFrom,i=a?{...QR(a.query.params,s,r),...Object.fromEntries((a.dependsOn??[]).map(c=>[c,String(n[c]??"")]).filter(([,c])=>c!==""))}:{},l=JSON.stringify([(a==null?void 0:a.query.query)??null,i,r.version]),o=ge(()=>a?A.pageQuery(r.plugin,a.query.query,i).then(c=>c.data):Promise.resolve(void 0),[l]);return a?{options:gr(o.data,a.rows).map(c=>({value:String(Re(c,a.value)??""),label:String(Re(c,a.label)??"")})),loading:o.loading}:{options:e.options??[],loading:!1}}function CV({field:e,fields:n,value:s,values:r,data:a,disabled:i,compact:l,onChange:o}){const c=JR(e,r,a),u={id:`f-${e.name}`,required:e.required,name:e.name,disabled:i,...l&&e.hint?{title:e.hint}:{}},h=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 t.jsx(ie,{label:e.label,hint:l?void 0:[h,g].filter(Boolean).join(" ")||void 0,group:!0,children:t.jsx(vB,{id:u.id,label:e.label,options:c.options,value:m,max:e.max,disabled:i,onChange:o})})}if(e.type==="select"){const m=t.jsxs("select",{...u,value:String(s??""),onChange:p=>o(p.target.value),children:[t.jsx("option",{value:"",children:c.loading?"Loading…":"—"}),c.options.map(p=>t.jsx("option",{value:p.value,children:p.label},p.value))]});return e.action&&!l?t.jsx(EV,{field:e,action:e.action,fields:n??[e],values:r,data:a,disabled:i,hint:h,children:m}):t.jsx(ie,{label:e.label,hint:h,children:m})}if(e.type==="textarea")return t.jsx(ie,{label:e.label,hint:h,wide:!0,children:t.jsx("textarea",{...u,value:String(s??""),onChange:m=>o(m.target.value),rows:6})});if(e.type==="checkbox")return t.jsx(ie,{label:e.label,hint:h,inline:!0,wide:!l,children:t.jsx("input",{...u,type:"checkbox",checked:s===!0,onChange:m=>o(m.target.checked)})});const f=e.type==="secret"?"password":e.type==="number"?"number":e.type;return t.jsx(ie,{label:e.label,hint:h,children:t.jsx("input",{...u,type:f,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"?$V(m.target.value):m.target.value)})})}function EV({field:e,action:n,fields:s,values:r,data:a,disabled:i,hint:l,children:o}){const c=vt(),u=d.useId(),h=X9()===u,[f,m]=d.useState(!1),[p,g]=d.useState(null),[x,k]=d.useState(null),[j,v]=d.useState(null);d.useEffect(()=>()=>QN(u),[u]);const w=Ty(s,r,a),y=n.args!==void 0?Js(n.args,{data:a,fields:r,shape:s,omit:w,scope:c}):Object.fromEntries(Object.entries(r).filter(([S,C])=>!w.has(S)&&C!=="")),N=async()=>{if(h){QN(u);return}m(!0),g(null),k(null),v(null);try{const S=await A.pageAct(c.plugin,{tool:n.tool,args:y});if(S.approvalId){v(S.approvalId);return}g(LR(S.result));const C=DR(S.result);C&&await _R(C,u)}catch(S){k(S instanceof Error?S.message:String(S))}finally{m(!1)}},b=h?"Stop":n.label;return t.jsx(ie,{label:e.label,hint:l,action:t.jsx($,{"data-shape":"icon","aria-label":f?`${n.label}: working`:b,title:b,"aria-busy":f||void 0,"aria-pressed":n.icon==="play"?h:void 0,disabled:i===!0||f,onClick:()=>void N(),children:f?t.jsx("span",{className:"ui-spinner","aria-hidden":"true"}):t.jsx(oe,{name:h?"stop":n.icon??"arrow"})}),after:x?t.jsx(ae,{message:x}):j?t.jsx(ef,{id:j,onDecided:()=>v(null)}):p?t.jsx("span",{className:"ui-field-hint",role:"status",children:p}):null,children:o})}function $V(e){if(e.trim()==="")return"";const n=Number(e);return Number.isFinite(n)?n:e}function XR(e,n){return{...typeof n=="object"&&n!==null?n:{},...e}}function Ty(e,n,s){const r=XR(n,s);return new Set(e.filter(a=>a.when!==void 0&&!Ht(r,a.when)||a.disabledWhen!==void 0&&Ht(r,a.disabledWhen)).map(a=>a.name))}function vm({fields:e,values:n,data:s,disabled:r,compact:a,columns:i,onChange:l}){const o=XR(n,s);return t.jsx(Es,{dense:a,columns:i,children:e.filter(c=>c.when===void 0||Ht(o,c.when)).map(c=>t.jsx(CV,{field:c,fields:e,compact:a,value:n[c.name],values:n,data:s,disabled:r===!0||c.disabledWhen!==void 0&&Ht(o,c.disabledWhen),onChange:u=>l(c.name,u)},c.name))})}const cu=d.createContext(!1),ZR=d.createContext(!1),eI=d.createContext(!1);function Ms({title:e,note:n,actions:s,children:r}){const a=d.useContext(cu);return t.jsx(pe,{title:e,aside:n,actions:s,panel:a,children:t.jsx(cu.Provider,{value:!1,children:t.jsx(ZR.Provider,{value:a,children:r})})})}function Wr({component:e,data:n,choose:s,chosen:r}){const a=vt(),i=d.useContext(Jh);if(!Ht(n,e.when)||e.where!==void 0&&e.where!==(TV()?"local":"remote"))return null;if(e.kind!=="section"&&!i&&KR(e,a.sensitive))return t.jsx(qR,{children:t.jsx(Wr,{component:e,data:n,...s?{choose:s}:{},...r===void 0?{}:{chosen:r}})});switch(e.kind){case"section":return t.jsx(AV,{component:e,data:n});case"notice":return t.jsx(RV,{component:e,data:n});case"link":return t.jsx(IV,{component:e,data:n});case"progress":return t.jsx(MV,{component:e,data:n});case"chart":return t.jsx(OV,{component:e,data:n});case"stats":return t.jsx(DV,{component:e,data:n});case"list":return t.jsx(FV,{component:e,data:n,...s?{onChoose:s}:{},...r===void 0?{}:{chosen:r}});case"table":return t.jsx(BV,{component:e,data:n});case"detail":return t.jsx(VV,{component:e,data:n});case"form":return t.jsx(GV,{component:e,data:n});case"search":return t.jsx(QV,{component:e,data:n});case"list-detail":return t.jsx(JV,{component:e,data:n});case"repeat":return t.jsx(XV,{component:e,data:n});case"calendar":return t.jsx(ZV,{component:e,data:n});case"tiles":return t.jsx(t7,{component:e,data:n});case"series-panel":return t.jsx(n7,{component:e,data:n});case"hero":return t.jsx(s7,{component:e,data:n});case"tabs":return t.jsx(r7,{component:e,data:n});case"expand":return t.jsx(a7,{component:e,data:n});case"button":return t.jsx(lI,{component:e,data:n});case"menu":return t.jsx(tI,{component:e,data:n});case"approval":return t.jsx(g7,{component:e,data:n});case"artifact":return t.jsx(x7,{component:e,data:n});case"editor":return t.jsx(v7,{component:e,data:n});case"agent-offer":return t.jsx(i7,{component:e});case"stories":return t.jsx(c7,{component:e,data:n});default:return t.jsx(G,{children:"This page uses a part this dashboard does not know yet. Reload buddi to see it."})}}function AV({component:e,data:n}){const s=vt(),r=d.useContext(Jh),[a,i]=VR(),l=!r&&KR(e.body,s.sensitive),o=l&&!a,c=d.useContext(cu);let u=e.body.length;const h=x=>{var k;return x.kind==="button"||x.kind==="link"||x.kind==="menu"||x.kind==="form"&&((k=x.drawer)==null?void 0:k.button)!==void 0&&!x.title};for(;c&&u>0&&h(e.body[u-1]);)u-=1;const f=e.body.slice(0,u),m=[...e.actions??[],...e.body.slice(u)],[p,g]=d.useState(null);return t.jsx($v.Provider,{value:g,children:t.jsx(Ms,{title:e.title,note:e.note,actions:m.length>0||l?t.jsxs(t.Fragment,{children:[m.map((x,k)=>t.jsx(Wr,{component:x,data:n},k)),l?t.jsx(GR,{revealed:a,onToggle:i}):null]}):void 0,children:t.jsxs(ue,{gap:"lg",divided:c,children:[p,o?t.jsx(YR,{}):t.jsx(Jh.Provider,{value:r||l,children:t.jsx($v.Provider,{value:null,children:f.map((x,k)=>t.jsx(Wr,{component:x,data:n},k))})})]})})})}const $v=d.createContext(null);function TV(){const e=typeof location>"u"?"":location.hostname;return e==="127.0.0.1"||e==="localhost"||e==="::1"||e==="[::1]"}function tI({component:e,data:n}){var c;const s=vt(),r=ka(),a=d.useContext($v),i=e.items.filter(u=>Ht(n,u.when)).map(u=>({label:u.label,...u.hint?{hint:u.hint}:{},onSelect:()=>{u.open!==void 0?s.setParams({open:u.open}):u.action&&r.run(u.action,Js(u.action.args,{data:n,row:n,scope:s}))}})),l=(c=e.items.find(u=>{var h;return((h=u.action)==null?void 0:h.tool)===r.running}))==null?void 0:c.action,o=r.error||r.done||r.approvalId?t.jsx(Br,{act:r}):null;return d.useEffect(()=>{a&&a(o)},[r.error,r.done,r.approvalId,r.waiting]),d.useEffect(()=>()=>a==null?void 0:a(null),[a]),t.jsxs(t.Fragment,{children:[t.jsx(ss,{label:e.label,items:i,stacked:e.items.some(u=>u.hint!==void 0),trigger:t.jsxs("button",{type:"button",className:"ui-btn pl-menu-btn","data-variant":e.tone==="accent"?"accent":void 0,disabled:r.busy,children:[(l==null?void 0:l.busy)??e.label,t.jsx(oe,{name:"chevron-down",size:12})]})}),a?null:o]})}function RV({component:e,data:n}){const s=vt(),r=ka(),a=typeof e.text=="string"?e.text:String(Ke(n,e.text)??""),i=e.link&&Ht(n,e.link.when)?e.link:void 0,l=i?ba(s,i.to,n):"",o=i?typeof i.label=="string"?i.label:String(Ke(n,i.label)??""):"",c=i&&l!==""&&o!==""?"href"in i.to?t.jsx(ro,{href:l,children:o}):t.jsx("a",{href:l,onClick:h=>{h.preventDefault(),s.navigate(l)},children:o}):null;if(e.look==="quiet")return a===""&&!c?null:t.jsxs("p",{className:"pl-quiet","data-tone":e.tone,children:[e.icon?t.jsx(oe,{name:e.icon,size:14}):null,t.jsxs("span",{children:[a,c?t.jsxs(t.Fragment,{children:[a?" · ":null,c]}):null]})]});const u=e.action;return t.jsxs(t.Fragment,{children:[t.jsxs(G,{tone:Ay(e.tone),title:e.title,action:u?t.jsx(nl,{action:u,args:Js(u.args,{data:n,scope:s}),disabled:r.busy,running:r.running===u.tool,onRun:(h,f)=>void r.run(h,f)}):void 0,children:[a,c?t.jsxs(t.Fragment,{children:[" ",c]}):null]}),t.jsx(oI,{act:r})]})}function IV({component:e,data:n}){const s=vt(),r=ba(s,e.to,n);return r===""?null:"href"in e.to?t.jsx(ne,{children:t.jsxs(lt,{href:r,target:"_blank",rel:"noopener noreferrer",variant:e.tone==="accent"?"accent":void 0,children:[e.label,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"}),t.jsx("span",{className:"sr-only",children:" (opens in a new tab)"})]})}):t.jsx(ne,{children:t.jsx(lt,{href:r,variant:e.tone==="accent"?"accent":void 0,onClick:a=>{a.preventDefault(),s.navigate(r)},children:e.label})})}function tS(e){return Math.round(e/1e6)}function PV(e,n){const s=Ns(Ke(n,e.value))??0,r=e.total?Ns(Ke(n,e.total)):null,a=e.total?r&&r>0?s/r:0:s,i=Math.max(0,Math.min(1,a)),l=Math.floor(i*100),o=a>=1,c=e.total&&r&&r>0?`${tS(s)} of ${Math.max(1,tS(r))} MB · ${l}%`:`${l}%`;return{percent:l,full:o,line:c}}function MV({component:e,data:n}){const s=c=>c===void 0?"":typeof c=="string"?c:String(Ke(n,c)??""),r=s(e.label),a=s(e.done),{percent:i,full:l,line:o}=PV(e,n);return t.jsxs(ue,{gap:"sm",children:[r?t.jsx("span",{children:r}):null,l&&a?t.jsx("span",{role:"status",children:a}):t.jsxs(t.Fragment,{children:[t.jsx(qw,{value:i,label:r||"Progress"}),t.jsx("span",{role:"status",children:o})]})]})}function OV({component:e,data:n}){const s=Dn(e.query,n),r=e.rows===void 0?Array.isArray(s.data)?s.data:[]:gr(s.data,e.rows),a=r.map(h=>String(Re(h,e.x)??"")),i=h=>r.map(f=>Ns(Re(f,h))??null),l=e.series!==void 0,o=e.y===void 0?[]:Array.isArray(e.y)?e.y:[e.y],c=l?e.series.map(h=>({label:h.label,values:i(h.y),type:h.type,...h.unit?{unit:h.unit}:{}})):o.map(h=>({label:o.length===1?e.label??h:h,values:i(h)})),u=e.target?Ns(Ke(s.data,e.target))??null:null;return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),r.length===0?s.loading||s.data===void 0?t.jsx(Ne,{children:"Loading…"}):t.jsx(sl,{text:e.empty??"Nothing recorded yet."}):t.jsx(dB,{xs:a,series:c,type:l?"mixed":e.type??"line",target:u,...e.label?{label:e.label}:{},formatX:h=>/^\d{4}-\d{2}-\d{2}/.test(h)?Fx(h):h,formatY:h=>yn(h,"number",null)})]})}function DV({component:e,data:n}){const s=Dn(e.query,n);return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),s.data===void 0?t.jsx(Ne,{children:e.empty??"Loading…"}):t.jsx(dm,{children:e.items.map((r,a)=>t.jsx(Tr,{label:r.label,value:yn(Ke(s.data,r.value),r.unit??"text",null),tone:NV(r.tone)},a))})]})}function nI(e,n,s,r){const a=(n.meta??[]).map(N=>String(Ke(s,N)??"")).filter(N=>N!==""),i=String(Ke(s,n.title)??""),l=n.to&&!r?ba(e,n.to,s):null,o=l===""?null:l,c=o!==null&&n.to!==void 0&&"href"in n.to,u=n.images?t.jsx(SV,{plugin:e.plugin,images:n.images,row:s}):null,f=[...n.pill?[n.pill]:[],...n.pills??[]].map((N,b)=>{const S=Ke(s,N.value);if(S==null||S==="")return null;const C=LV(N,S,s);return t.jsx(Ae,{tone:Ev(C.tone),children:C.text},b)}),m=o&&c?t.jsx(ro,{href:o,children:i}):o?t.jsx("a",{href:o,onClick:N=>{N.preventDefault(),e.navigate(o)},children:i}):i,p=n.tag?Ke(s,n.tag):void 0,g=p==null||p===""?null:t.jsx("span",{className:"pl-row-tag",children:String(p)}),x=n.status?Ke(s,n.status.text):void 0,k=n.status?Zh(n.status.tone,s):void 0,j=x==null||x===""?null:t.jsx("span",{className:"pl-row-status","data-tone":k,children:String(x)}),v=n.sub?String(Ke(s,n.sub)??""):"",w=n.swatch?Re(s,n.swatch):void 0,y=n.logo?t.jsx(To,{className:"pl-logo-lg",src:Iu(e.plugin,Ke(s,n.logo.asset)),label:String(Ke(s,n.logo.label)??"")}):n.swatch?typeof w=="string"&&Iy.test(w)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":w}}):t.jsx("span",{className:"pl-swatch","data-none":"true","aria-hidden":"true"}):null;return{text:i,href:o,outside:c,lead:y,pills:t.jsx(t.Fragment,{children:f}),meta:a.join(" · "),title:u?t.jsxs(t.Fragment,{children:[u,t.jsx("span",{className:"pl-row-title",children:m}),g]}):g?t.jsxs(t.Fragment,{children:[m,g]}):m,sub:j?t.jsxs(t.Fragment,{children:[v?t.jsx("span",{className:"pl-row-line",children:v}):null,j]}):n.sub?v:null,side:t.jsxs(t.Fragment,{children:[f,a.length>0?t.jsxs("span",{className:"muted",children:[" ",a.join(" · ")]}):null]})}}function LV(e,n,s){const r=String(n),a=e.labels??{},i=e.tones??{};return{text:Object.prototype.hasOwnProperty.call(a,r)?a[r]:r,tone:Object.prototype.hasOwnProperty.call(i,r)?i[r]:Zh(e.tone,s)}}function gr(e,n){const s=Re(e,n);return Array.isArray(s)?s:[]}function sI(e,n,s){const r=[],a=new Set;return e.forEach((i,l)=>{const o=n===void 0?void 0:Re(i,n),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 "${n??"(no key)"}" — not drawn`);return}if(a.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}a.add(c),r.push({key:c,row:i})}),r}function FV({component:e,data:n,onChoose:s,chosen:r}){var b;const a=vt(),i=d.useContext(eI),l=Dn(e.query,n),o=ka(),[c,u]=d.useState([]),h=i&&!e.select&&(e.actions??[]).length===0&&(e.bulk??[]).length===0,f=gr(l.data,e.rows),m=e.collapsed?gr(l.data,e.collapsed.rows):[],p=rI(e.actions,f,o),g={plugin:a.plugin,page:a.page,component:`list "${e.title??e.rows}"`},x=sI([...f,...m],e.key??((b=e.select)==null?void 0:b.key),g),k=new Map(x.map(S=>[S.row,S.key])),j=new Set(x.map(S=>S.row)),v=new Set(x.filter(({row:S})=>{var C;return((C=e.select)==null?void 0:C.disabledWhen)===void 0||!Ht(S,e.select.disabledWhen)}).map(({key:S})=>S)),w=c.filter(S=>v.has(S)),y=d.useMemo(()=>{const S=f.filter(E=>j.has(E));if(!e.groupBy)return[{label:null,aside:null,asideTone:void 0,rows:S}];const C=new Map;for(const E of S){const R=String(Re(E,e.groupBy.key)??"");C.set(R,[...C.get(R)??[],E])}const T=(E,R)=>{var I,z,U;const M=(z=(I=e.groupBy)==null?void 0:I.labels)==null?void 0:z[E];if(M!==void 0)return M;const O=(U=e.groupBy)!=null&&U.label?Re(R,e.groupBy.label):void 0;return O==null||O===""?E:String(O)};return[...C].map(([E,R])=>{var I,z;const M=(I=e.groupBy)!=null&&I.aside?Re(R[0],e.groupBy.aside):void 0,O=(z=e.groupBy)!=null&&z.asideTone?Re(R[0],e.groupBy.asideTone):void 0;return{label:T(E,R[0]),aside:M==null||M===""?null:String(M),asideTone:O==="warning"||O==="critical"?O:void 0,rows:R}})},[f,e.groupBy,x.length]),N=S=>S.map(C=>{var z;const T=nI(a,e.item,C,s),E=k.get(C);if(h&&(s||T.href&&!T.outside))return t.jsx(hT,{href:T.href??"#",current:r===E,onClick:()=>s?s(E):a.navigate(T.href),title:T.text,meta:T.meta,sub:T.sub,side:T.pills},E);const R=((z=e.select)==null?void 0:z.disabledWhen)!==void 0&&Ht(C,e.select.disabledWhen),M=(e.actions??[]).filter(U=>Ht(C,U.when)),O=M.filter(U=>U.menu!==!0),I=M.filter(U=>U.menu===!0);return t.jsx(rt,{lead:T.lead?T.lead:e.select?t.jsx("input",{type:"checkbox","aria-label":`Select ${T.text}`,disabled:R,checked:c.includes(E),onClick:U=>U.stopPropagation(),onChange:U=>u(D=>U.target.checked?[...D,E]:D.filter(P=>P!==E))}):void 0,title:s?t.jsx("a",{href:"#","aria-current":r===E?"true":void 0,onClick:U=>{U.preventDefault(),s(E)},children:T.text}):T.title,sub:T.sub,side:t.jsxs(t.Fragment,{children:[T.side,e.item.choice?t.jsx(zV,{choice:e.item.choice,row:C,data:l.data,act:o}):null,O.map((U,D)=>t.jsx(Ry,{action:U,row:C,data:l.data,act:o,onForm:p.show},D)),I.length>0?t.jsx(aI,{actions:I,row:C,title:T.text,data:l.data,act:o,onForm:p.show}):null]})},E)});return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:l.error}),p.open?null:t.jsx(Br,{act:o}),p.open?t.jsx(iI,{open:p.open,data:l.data,act:o,onClose:p.close,onDone:p.finish}):null,y.every(S=>S.rows.length===0)?l.loading?t.jsx(Ne,{children:"Loading…"}):t.jsx(sl,{text:e.empty??"Nothing here yet."}):t.jsxs(ct,{children:[e.select?t.jsx(rt,{lead:t.jsx("input",{type:"checkbox","aria-label":"Select every row",checked:v.size>0&&w.length===v.size,disabled:v.size===0,onChange:S=>u(S.target.checked?[...v]:[])}),title:t.jsxs("span",{className:"muted",children:[v.size," to choose from"]})}):null,y.map((S,C)=>{var T,E;return(T=e.groupBy)!=null&&T.actions||(E=e.groupBy)!=null&&E.asideTone?t.jsxs("section",{className:"pl-group","aria-label":S.label??void 0,children:[t.jsxs("header",{className:"pl-group-head",children:[t.jsx("span",{className:"pl-group-title",children:S.label}),S.aside?t.jsx("span",{className:"pl-group-aside","data-tone":S.asideTone,children:S.aside}):null,t.jsx(_V,{actions:e.groupBy.actions??[],row:S.rows[0],title:S.label??"",data:l.data,act:o,onForm:p.show})]}),N(S.rows)]},C):t.jsxs("div",{children:[S.label?t.jsxs("div",{className:"ui-list-group","data-aside":S.aside?"true":void 0,children:[S.label,S.aside?t.jsx("span",{className:"pl-group-aside",children:S.aside}):null]}):null,N(S.rows)]},C)})]}),e.collapsed&&m.some(S=>j.has(S))?t.jsx(Zt,{summary:`${e.collapsed.label} (${m.filter(S=>j.has(S)).length})`,children:t.jsx(ct,{children:N(m.filter(S=>j.has(S)))})}):null,e.bulk&&e.bulk.length>0?t.jsxs(ne,{align:"end",children:[t.jsxs("span",{className:"ui-toolbar-note",children:[w.length," selected"]}),e.bulk.map((S,C)=>{const T=w.length>0||S.all!==!0?w:[...v];return t.jsx(nl,{action:S,args:Js(S.args,{data:l.data,selected:T,scope:a}),count:T.length,disabled:o.busy||T.length===0,running:o.running===S.tool,onRun:(E,R)=>{u([]),o.run(E,R)}},C)})]}):null]})}function _V({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=e.filter(u=>Ht(n,u.when));if(l.length===0)return null;const o=l.filter(u=>u.menu!==!0),c=l.filter(u=>u.menu===!0);return t.jsxs("span",{className:"pl-group-act",children:[o.map((u,h)=>t.jsx(Ry,{action:u,row:n,data:r,act:a,onForm:i},h)),c.length>0?t.jsx(aI,{actions:c,row:n,title:s,data:r,act:a,onForm:i}):null]})}function zV({choice:e,row:n,data:s,act:r}){const a=vt(),i=String(Re(n,e.value)??""),[l,o]=d.useState(null);d.useEffect(()=>o(null),[i]);const c=l??i,u=e.options.filter(h=>Ht(n,h.when));return t.jsx("span",{className:"ui-segment pl-choice",role:"radiogroup","aria-label":ls(e.label,{row:n}),"aria-busy":l!==null&&r.running===e.tool?"true":void 0,children:u.map(h=>{const f=h.disabledWhen!==void 0&&Ht(n,h.disabledWhen),m=f&&h.hint?ls(h.hint,{row:n}):void 0;return t.jsx("button",{type:"button",role:"radio",className:"ui-tab","aria-checked":c===h.value,disabled:f||r.busy,title:m,"aria-description":m,onClick:()=>{if(h.value===c)return;o(h.value);const p=Js(e.args,{data:s,row:n,choice:h.value,scope:a});r.run(e,p).then(g=>{g||o(null)})},children:h.label},h.value)})})}function UV(e,n,s){return Object.entries(e).every(([r,a])=>{const i=typeof a=="string"?a:Re(s,a.row);return i!=null&&n[r]===String(i)})}function rI(e,n,s){const r=vt(),[a,i]=d.useState(null);return d.useEffect(()=>{var l;if(!(a!==null||n.length===0))for(const o of e??[]){const c=(l=o.form)==null?void 0:l.openWhen;if(!c)continue;const u=n.find(h=>Ht(h,o.when)&&UV(c,r.params,h));if(u!==void 0){i({action:o,row:u}),r.setParams(Object.fromEntries(Object.keys(c).map(h=>[h,null])));return}}},[n.length,JSON.stringify(r.params)]),{open:a,show:(l,o)=>{s.reset(),i({action:l,row:o})},close:()=>{s.reset(),i(null)},finish:()=>i(null)}}function Ry({action:e,row:n,data:s,act:r,onForm:a}){const i=vt();return e.form?t.jsx($,{disabled:r.busy,onClick:()=>a(e,n),children:ls(e.label,{row:n})}):t.jsx(nl,{action:e,args:Js(e.args,{data:s,row:n,scope:i}),disabled:r.busy,running:r.running===e.tool,row:n,onRun:(l,o)=>void r.run(l,o)})}function aI({actions:e,row:n,title:s,data:r,act:a,onForm:i}){const l=vt(),[o,c]=d.useState(null),u=m=>void a.run(m,Js(m.args,{data:r,row:n,scope:l})),h=[];let f;return e.forEach((m,p)=>{m.group!==f?(p>0&&h.push("separator"),m.group&&h.push({heading:m.group}),f=m.group):m.tone==="danger"&&p>0&&h.push("separator"),h.push({label:ls(m.label,{row:n}),...m.hint?{hint:ls(m.hint,{row:n})}:{},...m.tone==="danger"?{tone:"critical"}:{},onSelect:()=>m.form?i(m,n):m.confirm?c(m):u(m)})}),t.jsxs(t.Fragment,{children:[t.jsx(ss,{label:`More for ${s}`,items:h,sheet:{title:s}}),o?t.jsx(Ut,{title:ls(o.confirm??o.label,{row:n}),onClose:()=>c(null),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>c(null),children:"Cancel"}),t.jsx($,{variant:o.tone==="danger"?"danger":"accent",onClick:()=>{const m=o;c(null),u(m)},children:ls(o.label,{row:n})})]})}):null]})}function iI({open:e,data:n,act:s,onClose:r,onDone:a}){const i=vt(),{action:l,row:o}=e,c=l.form,[u,h]=d.useState(()=>ou(c.fields,o)),f=c.fields.some(x=>x.required&&(u[x.name]===""||u[x.name]===void 0)),{confirm:m,...p}=l,g={...p,label:c.submit};return t.jsx(Ye,{title:ls(c.title,{row:o}),onClose:r,foot:t.jsxs(ne,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx(nl,{action:g,args:Js(l.args,{data:n,row:o,fields:u,shape:c.fields,scope:i}),disabled:s.busy||f,running:s.running===l.tool,row:o,onRun:(x,k)=>void s.run(x,k,a)})]}),children:t.jsxs(ue,{children:[t.jsx(vm,{fields:c.fields,values:u,data:o,onChange:(x,k)=>h(j=>({...j,[x]:k}))}),t.jsx(ae,{message:s.error})]})})}function BV({component:e,data:n}){const s=Dn(e.query,n),r=ka(),a=gr(s.data,e.rows),i=rI(e.actions,a,r);return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),i.open?null:t.jsx(Br,{act:r}),i.open?t.jsx(iI,{open:i.open,data:s.data,act:r,onClose:i.close,onDone:i.finish}):null,a.length===0?s.loading?t.jsx(Ne,{children:"Loading…"}):t.jsx(sl,{text:e.empty??"Nothing here yet."}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[e.columns.map(l=>t.jsx("th",{children:l.label},l.key)),e.actions&&e.actions.length>0?t.jsx("th",{"aria-label":"Actions"}):null]})}),t.jsx("tbody",{children:a.map((l,o)=>t.jsxs("tr",{children:[e.columns.map(c=>{const u=c.pill?null:yn(Re(l,c.key),c.type??"text",null);return t.jsxs("td",{"data-fit":c.fit,title:HV(c,l,u),children:[c.pill?null:t.jsx(WV,{column:c,row:l}),c.pill?t.jsx(KV,{column:c,row:l}):c.fit==="truncate"?t.jsx("span",{className:"ui-table-cut",children:u}):u]},c.key)}),e.actions&&e.actions.length>0?t.jsx("td",{children:t.jsx(ne,{align:"end",children:e.actions.filter(c=>Ht(l,c.when)).map((c,u)=>t.jsx(Ry,{action:c,row:l,data:s.data,act:r,onForm:i.show},u))})}):null]},o))})]})]})}const Iy=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function WV({column:e,row:n}){if(!e.swatch)return null;const s=Re(n,e.swatch);return typeof s!="string"||!Iy.test(s)?null:t.jsx("span",{className:"ui-table-swatch","aria-hidden":"true",style:{"--swatch":s}})}function HV(e,n,s){if(e.hint){const r=Re(n,e.hint);if(r!=null&&r!=="")return String(r)}return e.fit==="truncate"&&s?s:void 0}function KV({column:e,row:n}){var l,o;const s=Re(n,e.key);if(Array.isArray(s))return t.jsx(t.Fragment,{children:s.map((c,u)=>{var x;const h=c,f=typeof h=="object"&&h!==null?h.value:c;if(f==null||f==="")return null;const m=typeof h=="object"&&h!==null?h.tone:void 0,p=(x=e.pill)==null?void 0:x.labels,g=p&&Object.prototype.hasOwnProperty.call(p,String(f))?p[String(f)]:yn(f,e.type??"text",null);return t.jsx(Ae,{tone:Ev(Zh(typeof m=="string"?m:void 0,n)),children:g},u)})});const r=(l=e.pill)==null?void 0:l.labels,a=String(s),i=r&&Object.prototype.hasOwnProperty.call(r,a)?r[a]:yn(s,e.type??"text",null);return t.jsx(Ae,{tone:Ev(Zh((o=e.pill)==null?void 0:o.tone,n)),children:i})}function VV({component:e,data:n}){const s=Dn(e.query,n);return s.error?t.jsx(ae,{message:s.error}):s.data===void 0?t.jsx(Ne,{children:e.empty??"Loading…"}):t.jsx(Ms,{title:e.title,note:e.note,children:t.jsxs(ue,{gap:"lg",children:[e.fields.length>0?t.jsx(Xt,{items:e.fields.map(r=>({key:r.label,label:r.label,value:yn(Ke(s.data,r.value),r.unit??"text",null)}))}):null,e.body.map((r,a)=>t.jsx(Wr,{component:r,data:s.data},a))]})})}function GV({component:e,data:n}){var m;const s=vt(),r=Dn(e.initial,n),a=ka(),[i,l]=d.useState(!1),o=((m=e.drawer)==null?void 0:m.id)!==void 0&&s.params.open===e.drawer.id,c=i||o,u=p=>{l(p),!p&&o&&s.setParams({open:null})},h=JSON.stringify([r.data??null,s.version]),f=t.jsx(YV,{component:e,data:n,initialData:r.data,act:a,onDone:()=>u(!1)},h);return e.drawer?e.drawer.button===void 0&&!e.title?t.jsxs(t.Fragment,{children:[t.jsx(Br,{act:a}),c?t.jsx(Ye,{title:e.drawer.title,onClose:()=>u(!1),children:f}):null]}):t.jsxs(pe,{title:e.title,aside:e.note,actions:e.drawer.button!==void 0?t.jsx($,{variant:"accent",onClick:()=>u(!0),children:e.drawer.button}):void 0,children:[t.jsx(Br,{act:a}),c?t.jsx(Ye,{title:e.drawer.title,onClose:()=>u(!1),children:f}):null]}):t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:r.error}),f]})}function YV({component:e,data:n,initialData:s,act:r,onDone:a}){const i=d.useContext(ZR),l=vt(),[o,c]=d.useState(()=>ou(e.fields,s)),u=Ty(e.fields,o,s),h=e.fields.some(f=>f.required&&!u.has(f.name)&&(o[f.name]===""||o[f.name]===void 0||Array.isArray(o[f.name])&&o[f.name].length===0));return t.jsxs(ue,{children:[t.jsx(vm,{fields:e.fields,columns:e.columns,values:o,data:s,onChange:(f,m)=>c(p=>({...p,[f]:m}))}),e.drawer?null:t.jsx(Br,{act:r}),t.jsx(ne,{align:"end",className:i?"ui-panel-foot":void 0,children:t.jsx(nl,{action:e.submit,args:Js(e.submit.args,{data:n,fields:o,shape:e.fields,omit:u,scope:l}),disabled:r.busy||h,running:r.running===e.submit.tool,onRun:(f,m)=>void r.run(f,m,a)})})]})}function qV(e,n){var r;if(e.type==="checkbox")return e.label;const s=(r=e.options)==null?void 0:r.find(a=>a.value===n);return`${e.label}: ${s?s.label:n}`}function nS(e){return e!=null&&e!==""&&e!==!1&&e!=="false"}function QV({component:e,data:n}){const s=vt(),[r,a]=d.useState(()=>ou(e.fields,n)),[i,l]=d.useState(e.auto===!0),[o,c]=d.useState(!1),u=e.fields.every(C=>!C.required||String(r[C.name]??"")!==""),h=Dn(i&&u?e.query:void 0,n),f=gr(h.data,e.rows),m=e.count===void 0?void 0:Re(h.data,e.count),p=e.note===void 0?void 0:Re(h.data,e.note),g=e.fields.find(C=>C.type==="text"||C.type==="email")??null,x=e.fields.filter(C=>C!==g),k=C=>{s.setParams(Object.fromEntries(e.fields.map(T=>[T.name,String(C[T.name]??"")||null]))),l(!0)},j=(C,T)=>{const E={...r,[C]:T};a(E),e.auto&&k(E)},v=()=>{const C=ou(e.fields,null);a(C),e.auto?k(C):(s.setParams(Object.fromEntries(e.fields.map(T=>[T.name,null]))),l(!1))},w=i?x.filter(C=>nS(s.params[C.name])):[],y=g?w.map(C=>t.jsx(zh,{label:C.label,onRemove:()=>{const T={...r,[C.name]:C.type==="checkbox"?!1:""};a(T),k(T)},children:qV(C,String(s.params[C.name]))},C.name)):[],N=x.filter(C=>nS(r[C.name])).length,b=e.auto&&!e.reset?null:t.jsxs(t.Fragment,{children:[e.reset?t.jsx($,{variant:"ghost",onClick:v,children:"Clear"}):null,e.auto?null:t.jsx($,{type:"submit",variant:"accent",disabled:!u,children:"Search"})]}),S=e.results.to?e.results:e.to?{...e.results,to:e.to}:e.results;return t.jsx(Ms,{title:e.title,children:t.jsxs(ue,{children:[t.jsx(pT,{label:e.title??"Search",onSubmit:()=>{!e.auto&&u&&k(r)},main:g?t.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=>j(g.name,C.target.value)}):void 0,filters:x.length>0?t.jsx(vm,{fields:x,values:r,data:n,compact:!0,onChange:j}):void 0,...g&&x.length>0?{filtersOpen:o,onToggleFilters:()=>c(C=>!C),active:N}:{},chips:y.length>0?y:void 0,actions:b}),t.jsx(ae,{message:h.error}),i&&(m!==void 0||p!==void 0)?t.jsxs("p",{className:"ui-card-meta",children:[m===void 0?"":`${yn(m,"number",null)} in all. `,p===void 0?"":String(p)]}):null,i?f.length===0?t.jsx(Ne,{children:h.loading?"Searching…":e.empty??"Nothing matches."}):t.jsx("div",{className:"ui-panel","data-flush":"true",children:t.jsx(ct,{children:f.map((C,T)=>{const E=nI(s,S,C);return t.jsx(rt,{title:E.title,sub:E.sub,side:E.side},T)})})}):null]})})}function JV({component:e,data:n}){const s=vt(),r=e.selection==="local",[a,i]=d.useState(null),l=r?a:s.params[e.param]??s.item,o=r&&a!==null?{...s,params:{...s.params,[e.param]:a}}:null,c=t.jsx(ue,{gap:"lg",divided:!0,children:e.detail.map((u,h)=>t.jsx(Wr,{component:u,data:n},h))});return t.jsx(cu.Provider,{value:!1,children:t.jsx(fT,{list:t.jsx(eI.Provider,{value:!0,children:t.jsx(Wr,{component:e.list,data:n,chosen:l??null,...r?{choose:i}:{}})}),detail:l?o?t.jsx($y.Provider,{value:o,children:c}):c:void 0,empty:e.empty??"Choose one to see it here."})})}function XV({component:e,data:n}){var x;const s=vt(),[r,a]=d.useState(!1),i=Dn(e.query,n,r&&e.poll?e.poll.seconds*1e3:void 0),l=e.poll!==void 0&&i.data!==void 0&&Ht(i.data,e.poll.while);d.useEffect(()=>a(l),[l]);const o=gr(i.data,e.rows),c=(x=e.poll)==null?void 0:x.finish,u=ka(),[h,f]=d.useState(()=>new Set),m=c?o.find(k=>{if(!Ht(k,c.when))return!1;const j=String(Re(k,e.key)??"");return j!==""&&!h.has(j)}):void 0,p=m===void 0?null:String(Re(m,e.key)??"");d.useEffect(()=>{!c||m===void 0||p===null||p===""||h.has(p)||u.busy||(f(k=>new Set([...k,p])),u.run(c.action,Js(c.action.args,{data:m,row:m,scope:s})))},[p,u.busy]);const g=c!==void 0&&u.running===c.action.tool;return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:i.error}),g?t.jsxs("p",{className:"pl-wait",role:"status",children:[t.jsx("span",{className:"pl-spin","aria-hidden":"true"}),c.action.busy??c.action.label]}):t.jsx(Br,{act:u}),g?null:o.length===0?i.loading?t.jsx(Ne,{children:"Loading…"}):t.jsx(sl,{text:e.empty??"Nothing here yet."}):t.jsx(ue,{gap:"lg",divided:!0,children:sI(o,e.key,{plugin:s.plugin,page:s.page,component:`repeat "${e.title??e.rows}"`}).map(({key:k,row:j})=>t.jsx(pe,{children:t.jsx(ue,{children:e.body.map((v,w)=>t.jsx(Wr,{component:v,data:j},w))})},k))})]})}function ZV({component:e,data:n}){const s=vt(),r=pV({...e.views?{views:e.views}:{},...e.default?{default:e.default}:{},today:tV(s.timezone),storageKey:`buddi.calendar-view:${s.plugin}/${s.page}`}),a=Dn(e.query,n,void 0,{from:r.from,to:r.to}),i=d.useMemo(()=>aV(gr(a.data,e.events),e.map,s.timezone,`plugin ${s.plugin}, page ${s.page}, calendar`),[a.data,e.events,e.map,s.timezone,s.plugin,s.page]),[l,o]=d.useState(null),c=e.sheet&&l!==null?i.find(u=>u.id===l)??null:null;return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:a.error}),t.jsx(gV,{state:r,events:i,hours:e.hours,empty:e.empty??"Nothing.",label:e.title??"Calendar",onEvent:e.sheet?u=>o(u.id):void 0,count:e.count&&a.data!==void 0?i.length:void 0}),c&&e.sheet?t.jsx(e7,{event:c,sheet:e.sheet,onClose:()=>o(null)}):null]})}function e7({event:e,sheet:n,onClose:s}){const r=vt(),a=e.row,i=p=>{if(p===void 0)return"";const g=Re(a,p);return g==null?"":String(g)},l=cV(e),o=i(n.color),c=i(n.notes),u=Xh(i(n.mapHref)),h=n.open?Xh(i(n.open.href)):null,f=n.open?i(n.open.label):"",m=p=>{const g=ls(p.replace(/\{when\}/g,l),{row:{...a,title:e.title,calendar:e.calendar,location:e.location}});s(),A9(g)||r.navigate(da)};return t.jsx(Ye,{title:e.title,onClose:s,foot:n.asks&&n.asks.length>0?t.jsx(ne,{align:"end",children:n.asks.map((p,g)=>t.jsx($,{onClick:()=>m(p.text),children:p.label},g))}):void 0,children:t.jsxs("div",{className:"pl-event-sheet",children:[t.jsx("p",{className:"pl-event-when",children:l}),e.calendar?t.jsxs("p",{className:"pl-event-cal",children:[o&&Iy.test(o)?t.jsx("span",{className:"pl-swatch","aria-hidden":"true",style:{"--swatch":o}}):t.jsx("span",{className:"cal-dot","data-tone":e.tone,"aria-hidden":"true"}),e.calendar]}):null,e.location?t.jsxs("p",{className:"pl-event-where",children:[t.jsx(oe,{name:"pin",size:14}),u?t.jsx(ro,{href:u,children:e.location}):t.jsx("span",{children:e.location})]}):null,c?t.jsx("p",{className:"pl-event-notes",children:c}):null,h&&f?t.jsx("p",{className:"pl-event-open",children:t.jsx(ro,{href:h,className:"wb-src-link",children:f})}):null]})})}function t7({component:e,data:n}){var f;const s=vt(),r=Dn(e.query,n),a={items:"$",icon:e.icon,value:e.value,label:e.label,...e.lines?{lines:e.lines}:{},...e.tone?{tone:e.tone}:{}},i=gr(r.data,e.items).flatMap(m=>{const p=Ww([m],a).tiles[0];return p?[{tile:p,key:e.select?String(Re(m,e.select.key)??""):""}]:[]}),l=e.select,o=l?Math.max(0,i.findIndex(m=>m.key===s.params[l.param])):null,c=((f=i[0])==null?void 0:f.key)??"",u=l?s.params[l.param]:void 0,h=i.some(m=>m.key===u);return d.useEffect(()=>{l&&c!==""&&!h&&s.setParams({[l.param]:c})},[l==null?void 0:l.param,c,h]),t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:r.error}),r.data===void 0?t.jsx(Ne,{children:"Loading…"}):i.length===0?t.jsx(sl,{text:e.empty??"Nothing to show."}):t.jsx(ET,{props:{tiles:i.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=i[m])==null?void 0:p.key)||null})}}:{}})]})}function n7({component:e,data:n}){const s=Dn(e.query,n),r=gr(s.data,e.points);if(s.data===void 0||r.length===0)return t.jsxs(Ms,{title:e.title,note:e.note,children:[t.jsx(ae,{message:s.error}),s.data===void 0?t.jsx(Ne,{children:"Loading…"}):t.jsx(sl,{text:e.empty??"Nothing to show."})]});const a=r.map(c=>String(Re(c,e.x)??"")),i={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)=>Ww([c],i).tiles[0]??{icon:null,value:"",label:a[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=>Ns(Re(u,c.y))??null)}));return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:s.error}),t.jsx(kV,{...e.title?{title:e.title}:{},...e.note?{note:e.note}:{},...e.labelEvery?{labelEvery:e.labelEvery}:{},xs:a,series:o,tiles:l})]})}function s7({component:e,data:n}){const s=Dn(e.query,n),r=o=>{const c=Re(s.data,o);return c==null?"":String(c)};if(s.data===void 0||s.data===null)return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:s.error}),t.jsx(Ne,{children:s.loading?"Loading…":e.empty??"Nothing to show."})]});const a=r(e.value),i=r(e.title),l=e.facts.map(o=>({label:o.label,value:r(o.path)})).filter(o=>o.value!=="");return t.jsxs("section",{className:"pg-hero","aria-label":[a,i,...l.map(o=>`${o.label} ${o.value}`)].filter(Boolean).join(", "),children:[t.jsxs("div",{className:"pg-hero-main","aria-hidden":"true",children:[t.jsx("span",{className:"pg-hero-icon",children:t.jsx(oe,{name:$o(Qx(Ke(s.data,e.icon))),size:44})}),t.jsx("span",{className:"pg-hero-value",children:a}),i?t.jsx("span",{className:"pg-hero-title",children:i}):null]}),l.length>0?t.jsx("dl",{className:"pg-hero-facts","aria-hidden":"true",children:l.map(o=>t.jsxs("div",{className:"pg-hero-fact",children:[t.jsx("dt",{children:o.label}),t.jsx("dd",{children:o.value})]},o.label))}):null]})}function r7({component:e,data:n}){var g;const s=vt(),[r,a]=d.useState(e.default??e.tabs[0].id),i=e.param,l=i?s.params[i]??e.default??e.tabs[0].id:r,o=x=>i?s.setParams({[i]:x}):a(x),c=e.pick,{options:u}=JR({name:(c==null?void 0:c.param)??"",label:(c==null?void 0:c.label)??"",...c!=null&&c.options?{options:c.options}:{},...c!=null&&c.optionsFrom?{optionsFrom:c.optionsFrom}:{}},{},n),h=c?u.some(x=>x.value===s.params[c.param])?s.params[c.param]:((g=u[0])==null?void 0:g.value)??"":"",f=e.tabs.find(x=>x.id===l)??e.tabs[0],m=(c==null?void 0:c.look)==="chips",p=c!=null&&c.add?ba(s,c.add.to,n):"";return t.jsxs("div",{className:"pg-tabs",children:[t.jsxs("div",{className:"pg-tabs-bar","data-only":e.tabs.length===1?"pick":void 0,"data-chips":m?"true":void 0,children:[c&&m&&u.length>0?t.jsxs("div",{className:"pl-chips",role:"group","aria-label":c.label,children:[u.map(x=>t.jsx($,{size:"sm","aria-pressed":x.value===h,onClick:()=>s.setParams({[c.param]:x.value}),children:x.label},x.value)),c.add&&p!==""?t.jsxs(lt,{size:"sm",variant:"ghost",href:p,onClick:x=>{x.preventDefault(),s.navigate(p)},children:[t.jsx(oe,{name:"plus",size:12}),c.add.label]}):null]}):c&&u.length>1?t.jsx(Gt,{label:c.label,options:u,value:h,onChange:x=>s.setParams({[c.param]:x})}):null,e.tabs.length>1?t.jsx("span",{className:"pg-tabs-switch",children:t.jsx(Gt,{label:e.title??"View",options:e.tabs.map(x=>({value:x.id,label:x.label})),value:f.id,onChange:o})}):null]}),f.body.map((x,k)=>t.jsx(Wr,{component:x,data:n},`${f.id}-${k}`))]})}function a7({component:e,data:n}){const[s,r]=d.useState(!1),a=Dn(s?e.query:void 0,n),i=typeof e.label=="string"?e.label:String(Ke(n,e.label)??"");return t.jsxs(Zt,{summary:i,boxed:!0,onToggle:l=>r(l),children:[t.jsx(ae,{message:a.error}),a.data===void 0?t.jsx(Ne,{children:"Loading…"}):t.jsx(ue,{children:e.body.map((l,o)=>t.jsx(Wr,{component:l,data:a.data},o))})]})}function lI({component:e,data:n}){const s=vt(),r=ka();return t.jsxs(t.Fragment,{children:[t.jsx(ne,{align:"end",children:t.jsx(nl,{action:e.action,args:Js(e.action.args,{data:n,row:n,scope:s}),disabled:r.busy,running:r.running===e.action.tool,row:n,onRun:(a,i)=>void r.run(a,i)})}),t.jsx(Br,{act:r})]})}function i7({component:e}){const n=vt();return t.jsx(Sy,{plugin:n.plugin,agent:e.agent,text:e.text,label:e.label})}function l7(e){if(!e||typeof e!="object")return null;const n=e;return typeof n.id!="string"||n.id===""||typeof n.title!="string"?null:{...n,outlets:Array.isArray(n.outlets)?n.outlets.filter(s=>s&&typeof s.name=="string"):[]}}function Av(e){return e.length===0?"":e.length===1?e[0].name:`${e[0].name} and ${e.length-1} more`}function sS(e,n,s){const r={};for(const[a,i]of Object.entries(e))"row"in i?r[a]=Re(n,i.row):"item"in i?r[a]=Re(s,i.item):r[a]=Ke(n,i);return r}const o7=8e3;function rS(e,n,s){const r=[];let a=null;return e.forEach((i,l)=>{if(!Ht(n,i.when))return;const o=i.each?Array.isArray(Re(n,i.each))?Re(n,i.each).slice(0,4):[]:[void 0];if(o.length!==0){l>0&&r.length>0&&i.group!==a&&r.push("separator"),i.group&&i.group!==a&&r.push({heading:i.group}),a=i.group;for(const c of o)r.push({label:ls(i.label,{row:c===void 0?n:c}),...i.hint?{hint:ls(i.hint,{row:n})}:{},onSelect:()=>s(i,c)})}}),r}function c7({component:e,data:n}){var S,C;const s=vt(),r=Dn(e.query,n),a=ka(),i=e.param??"story",[l,o]=d.useState(null);d.useEffect(()=>{if(!l)return;const T=setTimeout(()=>o(null),o7);return()=>clearTimeout(T)},[l]);const c=gr(r.data,e.rows).map(l7).filter(T=>T!==null),u=e.ways??[],h=s.params[i],f=h?c.find(T=>T.id===h)??null:null,m=async(T,E,R,M)=>{var U;const O=sS(T.args,E,R);if(!await a.run({tool:T.tool,label:T.label,...T.done!==void 0?{done:T.done}:{},...T.then?{then:T.then}:{}},O)||!T.hides)return;h===E.id&&s.setParams({[i]:null});const z=typeof T.done=="string"?ls(T.done,{row:R===void 0?E:R}):"Hidden.";o({id:E.id,group:((U=E.group)==null?void 0:U.id)??null,index:M,text:z,...T.undo?{undo:{tool:T.undo.tool,label:T.undo.label,args:sS(T.undo.args,E,R)}}:{}})},p=()=>{const T=l;o(null),T!=null&&T.undo&&a.run({tool:T.undo.tool,label:T.undo.label},T.undo.args)},g=[];for(const T of c){if(l&&T.id===l.id)continue;const E=e.groups&&T.group?T.group.id:null;let R=g.find(M=>M.id===E);R||(R={id:E,name:e.groups&&T.group?T.group.name:null,rows:[]},g.push(R)),R.rows.push(T)}l&&!g.some(T=>T.id===l.group)&&g.push({id:l.group,name:null,rows:[]});const x=(S=e.groups)==null?void 0:S.param,k=!(g.length===1&&x!==void 0&&s.params[x]===g[0].id),j=(T,E)=>t.jsx(f7,{row:T,plugin:s.plugin,menu:rS(u,T,(R,M)=>void m(R,T,M,E)),onOpen:()=>s.setParams({[i]:T.id})},T.id),v=T=>t.jsxs("div",{className:"pl-story-gone",role:"status",children:[t.jsx("span",{children:T.text}),T.undo?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"pl-story-gone-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:p,children:T.undo.label})]}):null]},`gone-${T.id}`),w=T=>{const E=T.rows.map(j);return l&&l.group===T.id&&E.splice(Math.min(l.index,E.length),0,v(l)),E};let y;if(r.data===void 0&&r.loading)y=t.jsx("div",{className:"pl-story-grid","aria-busy":"true","aria-label":"Fetching stories",children:Array.from({length:6},(T,E)=>t.jsxs("div",{className:"ui-card pl-story cat-skel pl-story-skel",children:[t.jsxs("span",{className:"pl-story-head",children:[t.jsx("i",{className:"cat-skel-face pl-story-skel-logo"}),t.jsx("i",{className:"cat-skel-line","data-w":"30"})]}),t.jsx("i",{className:"cat-skel-line","data-w":"90"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"}),t.jsx("i",{className:"cat-skel-line","data-w":"40"})]},E))});else if(c.length===0&&!l){const T=(e.emptyStates??[]).find(E=>Ht(r.data,E.when));if(T){const E=M=>M===void 0?"":typeof M=="string"?M:String(Ke(r.data,M)??""),R=(T.actions??[]).map((M,O,I)=>{const z=O===I.length-1&&(I.length>1||T.warm===!0);if(M.set)return t.jsx($,{size:"sm",variant:z?"accent":"ghost",onClick:()=>s.setParams(M.set),children:M.label},O);const U=M.to?ba(s,M.to,r.data):"";return U===""?null:t.jsx(lt,{size:"sm",variant:z?"accent":"ghost",href:U,onClick:D=>{D.preventDefault(),s.navigate(U)},children:M.label},O)});y=t.jsx(Ne,{warm:T.warm===!0,title:E(T.title),action:R.length>0?t.jsx(ne,{children:R}):void 0,children:E(T.text)})}else y=t.jsx(sl,{text:e.empty??"Nothing here yet."})}else y=g.map(T=>{var E;return t.jsxs("section",{className:"pl-story-group","aria-label":T.name??e.title??"Stories",children:[k&&T.name?t.jsxs("header",{className:"pl-story-group-head",children:[t.jsx("h2",{className:"pl-story-group-title",children:T.name}),x&&T.id?t.jsxs("a",{href:"#",className:"pl-story-group-aside",onClick:R=>{R.preventDefault(),s.setParams({[x]:T.id})},children:[((E=e.groups)==null?void 0:E.label)??"See all",t.jsx(oe,{name:"arrow",size:12})]}):null]}):null,t.jsx("div",{className:"pl-story-grid",children:w(T)})]},T.id??"all")});const N=u.find(T=>T.hides&&!T.each&&Ht(f,T.when)),b=u.filter(T=>T!==N);return t.jsxs("div",{className:"pl-stories",children:[t.jsx(ae,{message:r.error}),t.jsx(oI,{act:a}),y,f?t.jsx(Ye,{title:f.kicker??((C=f.group)==null?void 0:C.name)??e.title??"Story",onClose:()=>s.setParams({[i]:null}),foot:t.jsxs(ne,{children:[N?t.jsx($,{variant:"ghost",disabled:a.busy,onClick:()=>void m(N,f,void 0,0),children:ls(N.label,{row:f})}):null,b.length>0?t.jsx(ss,{label:`Less of this: ${f.title}`,trigger:t.jsx("button",{type:"button",className:"ui-btn","data-variant":"ghost",disabled:a.busy,children:"Less of this…"}),items:rS(b,f,(T,E)=>void m(T,f,E,0)),stacked:!0}):null,t.jsx(ot,{}),e.ask&&Ht(f,e.ask.when)?t.jsx(u7,{to:e.ask.to,row:f,label:e.ask.label,accent:!0}):null]}),children:t.jsx(m7,{row:f,plugin:s.plugin,edition:e.edition})}):null]})}function oI({act:e}){return e.error?t.jsx(ae,{message:e.error}):e.approvalId?t.jsx(Br,{act:e}):null}function u7({to:e,row:n,label:s,accent:r}){const a=vt(),i=ba(a,e,n);return i===""?null:"href"in e?t.jsx(lt,{variant:r?"accent":"ghost",href:i,target:"_blank",rel:"noopener noreferrer",children:s}):t.jsx(lt,{variant:r?"accent":"ghost",href:i,onClick:l=>{l.preventDefault(),a.navigate(i)},children:s})}function d7({row:e}){var s;const n=((s=e.mark)==null?void 0:s.kind)==="told";return!e.opinion&&!e.languages&&!e.mark?null:t.jsxs("span",{className:"pl-story-marks",children:[e.opinion?t.jsx(so,{children:"Opinion"}):null,e.languages?t.jsx("span",{className:"pl-story-lang",children:e.languages}):null,e.mark?n?t.jsxs("span",{className:"pl-story-told",children:[t.jsx(oe,{name:"check",size:12}),e.mark.text]}):t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null]})}function h7({plugin:e,outlets:n}){return n.length===0?null:t.jsxs("span",{className:"pl-stack","aria-label":Av(n),children:[t.jsx("span",{className:"pl-stack-logos",children:n.slice(0,3).map((s,r)=>t.jsx(To,{src:Iu(e,s.logo),label:s.name},r))}),t.jsx("span",{className:"pl-stack-words",children:Av(n)})]})}function f7({row:e,plugin:n,menu:s,onOpen:r}){var i;const a=Av(e.outlets);return t.jsxs("article",{className:"ui-card pl-story","data-told":e.quiet?"true":void 0,"data-opinion":e.opinion?"true":void 0,tabIndex:0,onClick:r,onKeyDown:l=>{l.target!==l.currentTarget||l.key!=="Enter"||(l.preventDefault(),r())},"aria-label":`${e.opinion?"Opinion: ":""}${e.title}.${a?` ${a}`:""}${e.ago?`, ${e.ago}`:""}.`,children:[t.jsxs("header",{className:"pl-story-head",children:[t.jsx(h7,{plugin:n,outlets:e.outlets}),e.ago?t.jsx("span",{className:"pl-story-time",children:e.ago}):null,s.length>0?t.jsx("span",{className:"pl-story-more",onClick:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),children:t.jsx(ss,{label:`Ways out for ${e.title}`,items:s.map(l=>typeof l=="string"||"heading"in l?l:{label:l.label,...l.hint?{hint:l.hint}:{},onSelect:l.onSelect}),sheet:{title:e.title,sub:[e.kicker??((i=e.group)==null?void 0:i.name),a].filter(Boolean).join(" · ")},stacked:!0})}):null]}),t.jsx("h3",{className:"pl-story-title",children:e.title}),e.lead?t.jsx("p",{className:"pl-story-lead",children:e.lead}):null,t.jsx(d7,{row:e})]})}function m7({row:e,plugin:n,edition:s}){const r=Array.isArray(e.sources)?e.sources.filter(l=>l&&typeof l.title=="string"):[],a=Array.isArray(e.timeline)?e.timeline.filter(l=>l&&typeof l.text=="string"):[],i=s&&Ht(e,s.when)?s:void 0;return t.jsxs("div",{className:"pl-story-sheet",children:[t.jsxs("div",{className:"pl-story-sheet-lead",children:[e.opinion?t.jsx(so,{children:"Opinion"}):null,t.jsx("h3",{className:"pl-story-sheet-title",children:e.title}),e.summary??e.lead?t.jsx("p",{className:"pl-story-sheet-summary",children:e.summary??e.lead}):null,e.update?t.jsxs("p",{className:"pl-story-sheet-update",children:[e.mark&&e.mark.kind==="new"?t.jsx("span",{className:"pl-story-new",children:e.mark.text}):null,e.update]}):null,e.meta||i?t.jsxs("p",{className:"pl-story-sheet-meta",children:[e.meta,i?t.jsxs(t.Fragment,{children:[e.meta?" · ":null,t.jsx(p7,{to:i.to,row:e,label:i.label})]}):null]}):null]}),r.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"Sources"}),t.jsx("ul",{className:"pl-story-sources",children:r.map((l,o)=>{const c=Xh(l.url);return t.jsxs("li",{className:"pl-story-source",children:[t.jsx(To,{className:"pl-logo-md",src:Iu(n,l.logo),label:l.outlet}),t.jsxs("span",{className:"pl-story-source-text",children:[c?t.jsx(ro,{href:c,className:"wb-src-link pl-story-source-title",children:l.title}):t.jsx("span",{className:"pl-story-source-title",children:l.title}),l.meta?t.jsx("span",{className:"pl-story-source-meta",children:l.meta}):null]})]},o)})})]}):null,a.length>0?t.jsxs("section",{className:"pl-story-sheet-block",children:[t.jsx("h4",{className:"pl-story-sheet-head",children:"How it moved"}),t.jsx("ol",{className:"pl-story-timeline",children:a.map((l,o)=>t.jsxs("li",{className:"pl-story-tl","data-told":l.told?"true":void 0,"data-last":o===a.length-1?"true":void 0,children:[t.jsx("span",{className:"pl-story-tl-at",children:l.at}),t.jsx("span",{className:"pl-story-tl-dot","aria-hidden":"true"}),t.jsx("span",{className:"pl-story-tl-what",children:l.text})]},o))})]}):null]})}function p7({to:e,row:n,label:s}){const r=vt(),a=ba(r,e,n);return a===""?null:"href"in e?t.jsx(ro,{href:a,children:s}):t.jsx("a",{href:a,onClick:i=>{i.preventDefault(),r.navigate(a)},children:s})}function g7({component:e,data:n}){const s=Re(n,e.path);return typeof s!="string"||s===""?null:t.jsx(ef,{id:s})}function x7({component:e,data:n}){const s=Re(n,e.path);return typeof s!="string"||s===""?null:t.jsx(ne,{children:t.jsx("a",{href:ni(s),children:e.label})})}function v7({component:e,data:n}){const s=Dn(e.query,n),r=ka();return s.error?t.jsx(ae,{message:s.error}):s.data===void 0?t.jsx(Ne,{children:e.empty??"Loading…"}):t.jsxs(t.Fragment,{children:[t.jsx(Br,{act:r}),t.jsx(j7,{component:e,data:n,loaded:s.data,act:r},JSON.stringify(s.data))]})}function j7({component:e,data:n,loaded:s,act:r}){const a=vt(),[i,l]=d.useState(()=>ou(e.fields,s)),o={...i,version:Re(s,e.version)},c=Ty(e.fields,i,s),u=e.readOnlyWhen!==void 0&&Ht(s,e.readOnlyWhen),h=(e.actions??[]).filter(p=>p.placement==="leading"),f=(e.actions??[]).filter(p=>p.placement!=="leading"),m=(p,g)=>t.jsx(nl,{action:p,args:Js(p.args,{data:n,fields:o,shape:e.fields,omit:c,scope:a}),disabled:r.busy,running:r.running===p.tool,onRun:(x,k)=>void r.run(x,k)},`${p.tool}-${g}`);return t.jsx(Ms,{title:e.title,note:e.note,children:t.jsxs(ue,{children:[t.jsx(vm,{fields:e.fields,values:i,data:s,disabled:u,onChange:(p,g)=>l(x=>({...x,[p]:g}))}),u?null:t.jsxs(ne,{align:"end",children:[h.map(m),h.length>0?t.jsx(ot,{}):null,m(e.save,-1),f.map(m)]}),e.footnote?t.jsx("p",{className:"ui-toolbar-note",children:e.footnote}):null]})})}function cI({page:e,item:n,navigate:s,timezone:r,embedded:a,siblings:i,params:l}){const[o,c]=d.useState(()=>({...l})),u=JSON.stringify(l??{});d.useEffect(()=>{l&&Object.keys(l).length>0&&c(k=>({...k,...l}))},[u]);const[h,f]=d.useState(0),m={plugin:e.plugin,page:e.id,pages:i??[e],item:n??null,params:{...o,...n?{item:n}:{},...k7(e,n)},setParams:k=>c(j=>{const v={...j};for(const[w,y]of Object.entries(k))y===null?delete v[w]:v[w]=y;return v}),navigate:s,timezone:r,version:h,refresh:()=>f(k=>k+1),sensitive:new Set(e.sensitive??[])},p=e.body[0],g=!a&&(p==null?void 0:p.kind)==="notice"&&p.look!=="quiet"&&p.link===void 0&&p.action===void 0&&p.when===void 0&&p.title===void 0&&(p.tone===void 0||p.tone==="neutral")?p.text:void 0,x=g===void 0?e:{...e,body:e.body.slice(1)};return t.jsx($y.Provider,{value:m,children:t.jsx(w7,{page:x,embedded:a===!0,lede:g})})}function w7({page:e,embedded:n,lede:s}){const r=vt(),a=e.data!==void 0&&r.sensitive.has(e.data.query),i=Dn(a?void 0:e.data,null),l=i.data??null,o=s===void 0||typeof s=="string"?s:Ke(l,s),c=o==null||o===""?void 0:String(o),u=!n&&e.actions&&e.actions.length>0?t.jsx(t.Fragment,{children:e.actions.map((h,f)=>t.jsx(y7,{component:h,data:l},f))}):void 0;return t.jsx(gs,{embedded:n,title:e.title,lede:c,actions:u,children:t.jsx(b7,{page:e,boxed:n,root:a?void 0:i})})}function y7({component:e,data:n}){const s=vt();if(!Ht(n,e.when))return null;if(e.kind==="button")return t.jsx(lI,{component:e,data:n});if(e.kind==="menu")return t.jsx(tI,{component:e,data:n});const r=ba(s,e.to,n);if(r==="")return null;const a=e.tone==="accent"?"accent":"ghost";return"href"in e.to?t.jsxs(lt,{variant:a,href:r,target:"_blank",rel:"noopener noreferrer",children:[e.label,t.jsx("span",{className:"wb-src-out","aria-hidden":"true",children:"↗"})]}):t.jsx(lt,{variant:a,href:r,onClick:i=>{i.preventDefault(),s.navigate(r)},children:e.label})}function b7({page:e,boxed:n,root:s}){const r=vt();return e.data&&r.sensitive.has(e.data.query)?t.jsx(qR,{children:t.jsx(aS,{page:e,boxed:n})}):t.jsx(aS,{page:e,boxed:n,root:s})}function aS({page:e,boxed:n,root:s}){const r=Dn(s?void 0:e.data,null),a=s??r;return t.jsxs(ue,{gap:"lg",divided:!n,children:[t.jsx(ae,{message:a.error}),t.jsx(cu.Provider,{value:n,children:e.body.map((i,l)=>t.jsx(Wr,{component:i,data:a.data??null},l))})]})}function k7(e,n){if(!n)return{};const s=[],r=a=>{for(const i of a)if(i.kind==="list-detail")s.push(i.param),r(i.detail);else if(i.kind==="section"||i.kind==="detail"||i.kind==="expand")r(i.body);else if(i.kind==="tabs")for(const l of i.tabs)r(l.body)};return r(e.body),Object.fromEntries(s.map(a=>[a,n]))}function N7(e){return t.jsx(cI,{...e,embedded:!0})}function sl({text:e}){const n=e.search(/[.!?]\s/),s=n===-1?e.replace(/[.]$/,""):e.slice(0,n+(e[n]==="."?0:1)),r=n===-1?"":e.slice(n+1).trim();return t.jsx(es,{title:s,children:r||null})}const iS=[{id:"",label:"All files"},{id:"produced",label:"Created by agents"},{id:"uploaded",label:"Uploaded by you"}],S7=["","image","pdf","table","text","code","audio","video","archive","file"];function C7({hash:e,timezone:n,navigate:s,agents:r}){var O;const a=V3(e),i=(a==null?void 0:a.artifactId)??null,l=(a==null?void 0:a.filters.origin)??"",o=(a==null?void 0:a.filters.family)??"",c=(a==null?void 0:a.filters.q)??"",[u,h]=d.useState(c);d.useEffect(()=>{h(c)},[c]);const f=(I,z=!1)=>s(dd(i,{q:c,origin:l,family:o,...I}),z);d.useEffect(()=>{if(u===c)return;const I=window.setTimeout(()=>f({q:u},!0),250);return()=>window.clearTimeout(I)},[u]);const[m,p]=d.useState(null),[g,x]=d.useState(null),[k,j]=d.useState(null),[v,w]=d.useState(!1),[y,N]=d.useState(!1),b=I=>{var z;return I?((z=r.find(U=>U.id===I))==null?void 0:z.name)??I:""},S=d.useRef(0);d.useEffect(()=>{const I=++S.current;p(null),x(null),w(!1),j(null),A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{}}).then(z=>{S.current===I&&(p(z.entries),x(z.next))}).catch(z=>{S.current===I&&j(z instanceof he?z.message:String(z))})},[c,l,o]);const C=()=>{if(!g||v)return;w(!0);const I=S.current;A.library({...c?{q:c}:{},...l?{origin:l}:{},...o?{family:o}:{},cursor:g}).then(z=>{S.current===I&&(p(U=>{const D=new Set((U??[]).map(P=>P.id));return[...U??[],...z.entries.filter(P=>!D.has(P.id))]}),x(z.next))}).catch(z=>{S.current===I&&j(z instanceof he?z.message:String(z))}).finally(()=>{S.current===I&&w(!1)})},T=(l?1:0)+(o?1:0),E=((O=iS.find(I=>I.id===l))==null?void 0:O.label)??l,R=t.jsxs(t.Fragment,{children:[m===null?t.jsx(Ne,{children:"Loading…"}):m.length===0?t.jsx(Ne,{children:"No file matches that."}):t.jsx(ct,{children:m.map(I=>t.jsx(hT,{href:dd(I.id,{q:c,origin:l,family:o}),current:I.id===i,onClick:()=>s(dd(I.id,{q:c,origin:l,family:o})),lead:t.jsx("span",{className:"files-row-visual","data-family":I.family,children:I.family==="image"&&!I.deleted?t.jsx("img",{src:Ur(I.id),alt:"",loading:"lazy"}):t.jsx(iy,{family:I.family})}),title:I.filename??"Untitled file",meta:t.jsx("span",{title:mt(I.createdAt,n),children:Ge(I.createdAt)}),sub:`${I.caption&&I.origin==="produced"?`${I.caption} · `:""}${Mi[I.family]} · ${ps(I.sizeBytes)} · ${uI(I,b)}${E7(I,b)}`},I.id))}),g?t.jsx("div",{className:"files-more",children:t.jsx($,{size:"sm",onClick:C,disabled:v,children:v?"Loading…":"Show more"})}):null]}),M=m!==null&&m.length===0&&!c&&!l&&!o&&!u;return t.jsxs("div",{className:"ui-page files","data-selected":i?"true":void 0,children:[t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Files"}),t.jsx("p",{className:"ui-page-lede",children:"What your agents made or were given."})]}),M?t.jsx(es,{icon:"files",title:"Nothing here yet",children:"Drop a file into any conversation and it shows up here too."}):t.jsxs(t.Fragment,{children:[t.jsx(pT,{label:"Files",onSubmit:()=>f({q:u},!0),main:t.jsx("input",{type:"search",value:u,placeholder:"Search by name or label","aria-label":"Search files by name or label",onChange:I=>h(I.target.value)}),filters:t.jsxs(Es,{dense:!0,children:[t.jsx(ie,{label:"Origin",children:t.jsx("select",{value:l,"aria-label":"Origin",onChange:I=>f({origin:I.target.value}),children:iS.map(I=>t.jsx("option",{value:I.id,children:I.label},I.id))})}),t.jsx(ie,{label:"Kind",children:t.jsx("select",{value:o,"aria-label":"Kind",onChange:I=>f({family:I.target.value}),children:S7.map(I=>t.jsx("option",{value:I,children:I===""?"Any kind":Mi[I]},I))})})]}),filtersOpen:y,onToggleFilters:()=>N(I=>!I),active:T,chips:T>0?t.jsxs(t.Fragment,{children:[l?t.jsx(zh,{label:"Origin",onRemove:()=>f({origin:""}),children:E}):null,o?t.jsx(zh,{label:"Kind",onRemove:()=>f({family:""}),children:Mi[o]}):null]}):void 0}),t.jsx(ae,{message:k}),t.jsx(fT,{className:"files-split",label:"Files",list:R,detail:i?t.jsx($7,{id:i,timezone:n,agents:r,navigate:s,onBack:()=>s(dd(null,{q:c,origin:l,family:o}))},i):void 0,empty:"Choose a file to see it here."})]})]})}function E7(e,n){var a,i;const s=(a=e.context)!=null&&a.groupName?`in ${e.context.groupName}`:(i=e.context)!=null&&i.agentId&&e.context.agentId!==e.agentId?`with ${n(e.context.agentId)}`:"",r=e.contexts>1?`${e.contexts} conversations`:"";return[s,r].filter(Boolean).map(l=>` · ${l}`).join("")}function uI(e,n){return e.origin==="uploaded"?"You sent it":e.origin==="produced"?`Made by ${n(e.agentId)||"an agent"}`:e.agentId?`Saved by ${n(e.agentId)}`:"Origin unknown"}function $7({id:e,timezone:n,agents:s,navigate:r,onBack:a}){const[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null);d.useEffect(()=>{let v=!1;return l(null),h(null),A.libraryEntry(e).then(w=>{v||l(w)}).catch(w=>{v||h(w instanceof he&&w.status===404?"This file is no longer in the library.":w instanceof he?w.message:String(w))}),()=>{v=!0}},[e]);const f=v=>{var w;return v?((w=s.find(y=>y.id===v))==null?void 0:w.name)??v:""};if(u)return t.jsxs("div",{className:"files-detail-body",children:[t.jsx($,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsx(G,{tone:"critical",children:u})]});if(!i)return t.jsx("div",{className:"files-detail-body",children:t.jsx(Ne,{children:"Loading…"})});const{entry:m,contexts:p,contextsTotal:g,available:x}=i,k=m.filename??"Untitled file",j=()=>{c(!0),A.libraryEntry(e,p.length).then(v=>l(w=>w&&{...w,contexts:[...w.contexts,...v.contexts],contextsTotal:v.contextsTotal})).catch(()=>{}).finally(()=>c(!1))};return t.jsxs("div",{className:"files-detail-body",children:[t.jsx($,{size:"sm",onClick:a,className:"files-back",children:"Back to Files"}),t.jsxs("header",{className:"files-detail-head",children:[t.jsx("span",{className:"files-detail-mark","data-family":m.family,"aria-hidden":"true",children:t.jsx(iy,{family:m.family})}),t.jsxs("div",{className:"files-detail-text",children:[t.jsx("h3",{className:"files-detail-name",children:k}),t.jsxs("p",{className:"files-detail-meta",children:[Mi[m.family]," · ",ps(m.sizeBytes)," · ",mt(m.createdAt,n)]})]}),x?t.jsx(OT,{artifactId:m.id,filename:m.filename,mime:m.mime}):null]}),x?null:t.jsx(G,{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."}),t.jsx(MT,{artifactId:m.id,filename:m.filename,mime:m.mime,family:m.family,available:x}),t.jsx(Xt,{items:[{label:"Origin",value:uI(m,f)},...m.caption&&m.origin==="produced"?[{label:"Filed under",value:m.caption}]:[],...m.agentId&&m.origin==="produced"?[{label:"Made by",value:t.jsxs("span",{className:"files-agent",children:[t.jsx(jn,{agents:s,id:m.agentId,size:"sm"}),f(m.agentId)]})}]:[],{label:"Type",value:t.jsx("span",{className:"mono",children:m.mime})},{label:"Id",value:t.jsx("span",{className:"mono",children:m.id})}]}),t.jsxs("section",{className:"files-conversations",children:[t.jsx("h4",{className:"ui-section-title",children:"Conversations"}),p.length===0?t.jsx("p",{className:"muted",children:"No conversation is recorded for this file. It may date from before the library kept track."}):t.jsx("ul",{className:"files-ctx",role:"list",children:p.map(v=>{const w=v.groupId?ki(v.groupId,v.conversationId):at(v.conversationAgentId,v.conversationId),y=v.groupId?v.groupName??"a group":f(v.conversationAgentId);return t.jsxs("li",{className:"files-ctx-row",children:[t.jsxs("span",{className:"files-ctx-text",children:[t.jsx("span",{children:v.groupId?`Group: ${y}`:y}),t.jsxs("span",{className:"muted",children:[" · ",v.kind==="produced"?`made by ${f(v.agentId)||"an agent"}`:v.kind==="reused"?"sent again":"sent by you"," · ",Ge(v.at)]})]}),t.jsx("a",{className:"ui-btn","data-size":"sm",href:w,onClick:N=>{N.preventDefault(),r(w)},children:"Open conversation"})]},`${v.conversationId}:${v.kind}`)})}),p.length<g?t.jsx(ne,{align:"end",children:t.jsx($,{size:"sm",onClick:j,disabled:o,children:o?"Loading…":`Show ${g-p.length} more`})}):null]})]})}const A7={mail:"mail",money:"money",calendar:"calendar",people:"agents",file:"files",chart:"chart",bell:"bell",plug:"plug",key:"key",globe:"globe",sun:"sun",cloud:"cloud",news:"news"};function dI(e){return e&&A7[e]||"plug"}const hI="buddi.keepClose";let ao=null;const Tv=new Set;function Rv(){for(const e of Tv)e()}typeof window<"u"&&(window.addEventListener("beforeinstallprompt",e=>{e.preventDefault(),ao=e,Rv()}),window.addEventListener("appinstalled",()=>{ao=null,My(),Rv()}));function jm(){const[e,n]=d.useState(ao);return d.useEffect(()=>{const s=()=>n(ao);return Tv.add(s),s(),()=>{Tv.delete(s)}},[]),fI()?null:e}async function Py(e){try{await e.prompt();const n=await e.userChoice;ao===e&&(ao=null);const s=(n==null?void 0:n.outcome)==="accepted";return s&&My(),Rv(),s}catch{return!1}}function T7(){try{return window.localStorage.getItem(hI)!==null}catch{return!1}}function My(){try{window.localStorage.setItem(hI,"dismissed")}catch{}}function fI(){var e;try{return((e=window.matchMedia)==null?void 0:e.call(window,"(display-mode: standalone)").matches)??!1}catch{return!1}}function R7(e=window.location.hostname){const n=e.replace(/^\[|\]$/g,"").toLowerCase();return n==="127.0.0.1"||n==="::1"||n==="localhost"}function mI(e=typeof navigator>"u"?"":navigator.userAgent){return/\bbuddi-mac\/\S+/.test(e)}function pI(e){return mI(e)?null:/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 I7(e){return/Mac|iPhone|iPad/.test(e)}function P7(){const e=jm(),[n,s]=d.useState(T7);if(n||!e)return null;const r=()=>{My(),s(!0)};return t.jsxs("div",{className:"home-install",role:"region","aria-label":"Install buddi",children:[t.jsx("p",{className:"home-install-text",children:"Install buddi as an app, one click from your dock."}),t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:r,children:"Not now"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>{Py(e).then(a=>{a&&s(!0)})},children:"Install"})]})]})}function M7(){const e=jm(),[n,s]=d.useState(void 0),[r]=d.useState(fI);if(d.useEffect(()=>{if(r)return;let o=!0;return A.session().then(c=>{o&&s(c.platform)},()=>{}),()=>{o=!1}},[r]),r)return null;const a=typeof navigator>"u"?"":navigator.userAgent,i=R7(),l=e?null:pI(a);return t.jsx(pe,{title:"The dashboard as an app",panel:!0,foot:e?t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>{Py(e)},children:"Install the app"})}):void 0,children:t.jsxs(ue,{children:[t.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 ",I7(a)?"⌘D":"Ctrl+D",".",i?null:" This tailnet address installs as its own app, separate from the one on the machine buddi runs on."]}),i&&n==="darwin"?t.jsxs("p",{children:["On this Mac, ",t.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 O7=""+new URL("earth-2560-Ce3xs8Cb.webp",import.meta.url).href,D7=""+new URL("earth-phone-BqC7cDhk.webp",import.meta.url).href,L7="data:image/webp;base64,UklGRloGAABXRUJQVlA4IE4GAADQKgCdASrAAJAAPpVInUolpKmtqTe6EbASiUdvknkVpMHex+cfn6FpYp/9uZP+p3tPRfzQ/Vd/Sej/8/++pP8bkmkrujVcbfosAWVvo98GPJDgcpdpkar6crJ+OUcccXvyduwiVqZIt11sMX//3JP2wugWcHYMSjhNfw/YXfPBz7/+f4KsYSTyT6uayU6+fROo0TO6X4IyHrF+l6toP//txS0FMPUdRtJ6p+KCT2dP3gpLomT/wObriNY+VMOA0Zv+Tv48yM6/mEHjtXwfON8gBTL8RqQm7vROt+4EPvqHCsf6f1vUb+PxZm8Y0/H4GI68rdhftV4yy/CoatiRgTrzW8ekWPCSt9eJvusnrXMcJruQHwSz5/vX9vG8C1y5aeF5l34kChCD3TSgQUw9kBS9sQ1NbMi1pMKuJqUEgiZd/2y+wAjF/DOKI3FZHBa5Q2qCooTfUj9A0XCixL3kuiAA/vqtztWnhuK0AAUKVrOx4/8K6IntNvzYOatrdU3xfr4QYYAHyIAAE90qDuxwvNSaslOgj1XzeQ7o4CiG+WFb4zwdPY6lyVxnN49hB6ipRsqQgAGt1TM/WHRmZXsFqcgHgXvLRO/p+gY76bpHJq4QeDFM3Q6tVUsq12eA8xdt9XMl/j2W0PHmipASSSIaS5KLMTjz4jtZfUwqTOj0emDBJw60TFqwI7jSvw3mbEwxxbojRIHLx6DfSdsFdhjJvJMS7fn0N+lA61ZOdS0OwUdd69Dt/YuIccchkuSR0QX9woaHISeHgXHlRAF2XLwciGQqbLIy9BogJ/4g+AKroStuCVhcYugjGC2gxUtl2UrwpIDcHI1ccHnGLv68wJ5AAfOSAKcV1RtS2UUbfSRLCnU6xoa6KmV/rAxptF6OJf8GfEOtKNwm6VddtwyPoa9muhJGhR/j6ruJ/kFnMRNLH7WcXtQIhNlVo8xRvRaoH9RGwIfvhwAigF4zejYm1wAynQhgR7ecE/15lbKTsTBb8Y9fEc9zNmZZgMzlto8cNZj+0+k1TTQ0wmrRktZ299Sqko1Ov4yDQRP0iKSe/g8XpiHowGqR5N0lsvJeEojijafpSRp0k3G59maRyl+1LsIb5YW8WfgFHbtRtYszt39yl7EPwLfsYwXOWqPwg0IVemW8v5CMln54J4c9m95OIxJHYL7cQTzWyrY8qgaxhR5vtr+NJyiQTlKN31r1xeJhCmJZKtY9OIGzesGUOdmetfh1jmfh5YtwdxOG900hLMD4vv1jYXAng8YZpjDTRUcuUrlYiO+BtcbnuIUA9SVRzFAdwReo1Rry/Sm7lNWjORAVT0B4dXzkfjv/+SykUdSAYx2evoGEJeUFqXPQt16XiwAduftyvFBUlNVwP8bZv+Hg3wueDwbUZYgaHM2qC7CJdIdf4uB9elmZViV9gssG5C8+Vk1BCJoqMasH9cFJcYjqlpDSWtZ5XcTreCV+dBwxHKh/IfqUOmZWnvYIE6xQ0YlVMc2CZuriPdRDQEoKjgMZ67X1f7XsanRDwL3attVpj5zWBRiXYdoGzt/O4w9zk/qCWUbZyy7ik+prantqxCiKAbRE7jZhTXFGprni/fldU5v5vRozeswfGCVXQzQpmjEMJA5uV4eB1w0ooNYM+ZV9yo/rqYIfhQHnzn3N7N44UBzZl6EI7806lpMMDZMk2Vd7aTc7dapectSczJ1D9mZ0MKvd0Skg1Euq1uGwQNEu1ANTFFUYIOmREj8d3vYHkWlhmuiTLKbQxl4CgDYk4vH6kA9iGe43Mo5BF4WoiQ6OqRJTxel29R6Yc/FWmw/enfMaPdyWgKnVSn6TSLoPcgJ6lu1pd39McpTo92Aw0czVjUXTcdSL3c38q4YyOdJkv6sw+FeXr/DOXP3S3xXjo7SMXD2UED68pQEVkjf4SaSqWUarBkeacGOlssJDsoVFm46XleiI+Ug9j+hAVyLDPKsLDo+8qrFgcEexTGjmonZnow0nKD80SpF+KbZD78vfc4MJN2F5ZhWC+mDVgv6Bj8kTD6MGV+6YllFA/AdnvTw+idzBKLNTYe7PEcq2AWNOAog/43qtjJQbAdxGkS8KewzmlpTP4KIuDoynjBuqv9Y6PR+nv2IZpWyNvqTUkqiFJnCQI/XKogTppN/pcEAOJ+XFqAA=",Iv={desk:O7,phone:D7,thumb:L7},Kp={author:"ActionVance",authorUrl:"https://unsplash.com/@actionvance",photoUrl:"https://unsplash.com/photos/outer-space-photography-of-earth-t7EL2iG3jMc"};function F7(e){return e?Iv.phone:Iv.desk}function gI(){const[e,n]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4+50)};return r(),()=>clearTimeout(s)},[]),e}const _7=3,xI=8e3,z7={hiddenHere:new Set,restoredHere:new Set};function U7(e,n){return n.hiddenHere.has(e.id)?!0:e.hidden&&!n.restoredHere.has(e.id)}function B7(e,n=z7){return(e??[]).filter(s=>!U7(s,n)).slice(0,_7)}function vI(e){const[n,s]=d.useState(new Set),[r,a]=d.useState(new Set),[i,l]=d.useState(null),o=d.useRef(e);o.current=e;const c=(m,p)=>new Set(m).add(p),u=(m,p)=>{const g=new Set(m);return g.delete(p),g};return d.useEffect(()=>{if(!i)return;const m=window.setTimeout(()=>l(null),xI);return()=>window.clearTimeout(m)},[i]),{hiddenHere:n,restoredHere:r,justHidden:i,hide:(m,p)=>{s(g=>c(g,m.id)),a(g=>u(g,m.id)),l({glance:m,spot:p}),A.setGlanceHidden(m.id,!0).then(()=>{var g;return(g=o.current)==null?void 0:g.call(o)},()=>{s(g=>u(g,m.id)),l(g=>(g==null?void 0:g.glance.id)===m.id?null:g)})},undo:()=>{if(!i)return;const{glance:m}=i;l(null),s(p=>u(p,m.id)),a(p=>c(p,m.id)),A.setGlanceHidden(m.id,!1).then(()=>{var p;return(p=o.current)==null?void 0:p.call(o)},()=>{a(p=>u(p,m.id)),s(p=>c(p,m.id))})}}}function W7({hiding:e,spot:n}){const s=e.justHidden;return!s||s.spot!==n?null:t.jsxs("span",{className:"home-glance-undo",role:"status","aria-live":"polite","data-spot":n,children:[t.jsxs("span",{children:[s.glance.title," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:e.undo,children:"Undo"})]})}function H7(e){return e.link?sy(e.link.plugin,e.link.page,e.link.place):null}function K7({glances:e,navigate:n,onChanged:s,except:r,hiding:a}){var u,h;const i=vI(s),l=a??i,o=B7(e,l).filter(f=>!(r!=null&&r.has(f.id))),c=t.jsx(W7,{hiding:l,spot:"line"});return o.length===0&&((u=l.justHidden)==null?void 0:u.spot)!=="line"?null:t.jsxs("span",{className:"home-glances",children:[((h=l.justHidden)==null?void 0:h.spot)==="line"?t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),c]}):null,o.map(f=>{const m=H7(f),p=t.jsxs(t.Fragment,{children:[t.jsx(oe,{name:$o(f.icon),size:14}),t.jsx("span",{children:f.text})]});return t.jsxs("span",{className:"home-glance",children:[t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),m?t.jsx("a",{className:"home-glance-text",href:m,onClick:g=>{g.preventDefault(),n(m)},children:p}):t.jsx("span",{className:"home-glance-text",children:p}),t.jsx("button",{type:"button",className:"home-glance-hide","aria-label":`Hide ${f.title} from Home`,title:"Hide from Home",onClick:()=>l.hide(f,"line"),children:t.jsx(oe,{name:"close",size:10})})]},f.id)})]})}function V7(e){const a=Math.min(...e),l=Math.max(...e)-a||1,o=Math.max(e.length-1,1);return e.map((c,u)=>[u/o*100,2+(1-(c-a)/l)*(24-2*2)])}function G7({points:e,className:n="wg-spark"}){const s=V7(e).map(([r,a])=>`${r.toFixed(1)},${a.toFixed(1)}`);return t.jsxs("svg",{className:n,viewBox:"0 0 100 24",preserveAspectRatio:"none","aria-hidden":"true","data-testid":"spark",children:[t.jsx("path",{d:`M0,24 L${s.join(" L")} L100,24 Z`,fill:"currentColor",opacity:"0.12",stroke:"none"}),t.jsx("polyline",{points:s.join(" "),fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",vectorEffect:"non-scaling-stroke"})]})}const xl=Math.PI/180;function Y7(e,n,s){const r=e.getTime()/864e5+24405875e-1-2451545,a=(357.529+.98560028*r)*xl,l=(280.459+.98564736*r+1.915*Math.sin(a)+.02*Math.sin(2*a))*xl,o=(23.439-36e-8*r)*xl,c=Math.atan2(Math.cos(o)*Math.sin(l),Math.cos(l)),u=Math.asin(Math.sin(o)*Math.sin(l)),f=((18.697374558+24.06570982441908*r)*15+s)*xl-c,m=n*xl,p=Math.sin(m)*Math.sin(u)+Math.cos(m)*Math.cos(u)*Math.cos(f);return Math.asin(Math.max(-1,Math.min(1,p)))/xl}function q7(e,n,s){return Y7(e,n,s)>-.833}const Q7={small:2,medium:4},lS=new Map;function J7(e){let n=lS.get(e);return n||(n=new Intl.DateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}),lS.set(e,n)),n}function oS(e,n){const s=Object.fromEntries(J7(n).formatToParts(e).map(l=>[l.type,l.value])),r=Number(s.hour)%24,a=Number(s.minute),i=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),r,a);return{date:`${s.year}-${s.month}-${s.day}`,h:r,m:a,s:Number(s.second),offset:Math.round((i-Math.floor(e.getTime()/6e4)*6e4)/6e4)}}function X7(e){if(e===0)return"Same time";const n=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${e>0?"+":"−"}${n===0?`${s} min`:s===0?`${n} h`:`${n} h ${s}`}`}function Z7(e){if(e===0)return"same time";const n=Math.floor(Math.abs(e)/60),s=Math.abs(e)%60;return`${[n?`${n} hour${n===1?"":"s"}`:"",s?`${s} minute${s===1?"":"s"}`:""].filter(Boolean).join(" ")} ${e>0?"ahead":"behind"}`}function eG(e,n,s,r,a){const i=oS(e,n.zone),l=oS(e,s),o=i.date===l.date?"Today":i.date>l.date?"Tomorrow":"Yesterday",c=i.offset-l.offset,u=wu(a?{timeFormat:a}:{},()=>Tt(e,n.zone)),h=r?"your time":Z7(c);return{...i,day:o,daytime:typeof n.latitude=="number"&&typeof n.longitude=="number"?q7(e,n.latitude,n.longitude):i.h>=6&&i.h<18,offsetText:r?"Here":X7(c),time:u,label:`${n.label}, ${u}${o==="Today"?"":` ${o.toLowerCase()}`}, ${h}`}}function tG(e,n){const s=n?e.s:0;return{hour:(e.h%12+e.m/60+s/3600)*30,minute:(e.m+s/60)*6,second:n?e.s*6:null}}function nG(e){const[n,s]=d.useState(()=>new Date);return d.useEffect(()=>{const r=e?1e3:6e4;let a;const i=()=>{a=setTimeout(()=>{s(new Date),i()},r-Date.now()%r+5)};return s(new Date),i(),()=>clearTimeout(a)},[e]),n}function cS({angle:e,length:n,width:s}){return t.jsxs("g",{className:"wg-clock-hand",transform:`rotate(${e} 50 50)`,children:[t.jsx("line",{x1:"50",y1:"50",x2:"50",y2:"42",strokeWidth:Math.min(s,1.8)}),t.jsx("line",{x1:"50",y1:"42",x2:"50",y2:50-n,strokeWidth:s})]})}const sG=Array.from({length:12},(e,n)=>n);function rG({time:e,seconds:n}){const s=tG(e,n);return t.jsxs("svg",{className:"wg-clock-face",viewBox:"0 0 100 100","aria-hidden":"true",focusable:"false",children:[t.jsx("circle",{className:"wg-clock-dial",cx:"50",cy:"50",r:"49.25"}),sG.map(r=>t.jsx("line",{className:"wg-clock-tick","data-major":r%3===0?"true":void 0,x1:"50",y1:r%3===0?6.5:7.5,x2:"50",y2:r%3===0?14:12,transform:`rotate(${r*30} 50 50)`},r)),t.jsx(cS,{angle:s.hour,length:24,width:4.6}),t.jsx(cS,{angle:s.minute,length:37,width:3.4}),s.second===null?null:t.jsx("g",{className:"wg-clock-second","data-testid":"second-hand",transform:`rotate(${s.second} 50 50)`,children:t.jsx("line",{x1:"50",y1:"59",x2:"50",y2:"9"})}),t.jsx("circle",{className:"wg-clock-pin",cx:"50",cy:"50",r:"2.8"}),s.second===null?null:t.jsx("circle",{className:"wg-clock-pin-second",cx:"50",cy:"50",r:"1.5"})]})}function aG({body:e,size:n}){const s=fs("(prefers-reduced-motion: reduce)"),r=nG(!s),a=e.clocks.slice(0,Q7[n]);return t.jsx("div",{className:"wg-clocks","data-count":a.length,children:a.map((i,l)=>{let o;try{o=eG(r,i,e.home,l===0&&i.zone===e.home,e.time)}catch{return null}return t.jsxs("div",{className:"wg-clock","data-night":o.daytime?void 0:"true",role:"img","aria-label":o.label,title:`${i.label} · ${o.time}`,children:[t.jsx(rG,{time:o,seconds:!s}),t.jsxs("span",{className:"wg-clock-words","aria-hidden":"true",children:[t.jsx("span",{className:"wg-clock-city",children:i.label}),t.jsx("span",{className:"wg-clock-day","data-today":o.day==="Today"?"true":void 0,children:o.day}),t.jsx("span",{className:"wg-clock-off",children:o.offsetText})]})]},`${i.label}-${i.zone}`)})})}const Vp=3,iG={small:4,medium:6};function Gp({icon:e,size:n}){return e?t.jsx("span",{className:"wg-icon",children:t.jsx(oe,{name:$o(e),size:n})}):null}function wm({body:e,size:n}){switch(e.kind){case"stat":return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"wg-stat-now",children:[t.jsx(Gp,{icon:e.icon,size:24}),t.jsx("span",{className:"wg-value",children:e.value})]}),e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null,t.jsx("span",{className:"wg-push"}),e.trend?t.jsxs("span",{className:"wg-trend",children:[t.jsx(G7,{points:e.trend.points,className:"wg-spark"}),e.trend.label?t.jsx("span",{children:e.trend.label}):null]}):null,e.foot?t.jsx("span",{className:"wg-foot",children:e.foot}):null]});case"list":{const s=e.rows.slice(0,Math.min(e.max??Vp,n==="medium"?5:Vp));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"wg-list","data-dense":s.length>Vp?"true":void 0,"data-wrap":e.wrap?"true":void 0,children:s.map((r,a)=>t.jsxs("li",{className:"wg-row","data-marked":r.image?"true":void 0,children:[r.image?t.jsx(To,{className:"wg-mark",src:FT(r.image.src)?r.image.src:null,label:r.image.label??r.title}):null,t.jsxs("span",{className:"wg-row-text",children:[t.jsx("span",{className:"wg-row-title",children:r.title}),r.sub&&n==="medium"?t.jsx("span",{className:"wg-row-sub",children:r.sub}):null]}),r.side?t.jsx("span",{className:"wg-row-side","data-tone":r.tone,children:r.side}):null]},`${r.title}-${a}`))}),t.jsx("span",{className:"wg-push"}),e.more?t.jsx("span",{className:"wg-foot",children:e.more}):null]})}case"strip":return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"wg-strip-head",children:[t.jsx(Gp,{icon:e.icon,size:20}),e.value?t.jsx("span",{className:"wg-strip-value",children:e.value}):null,e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null]}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-strip",children:e.items.slice(0,iG[n]).map((s,r)=>t.jsxs("span",{className:"wg-tile",children:[t.jsx("span",{className:"wg-tile-label",children:s.label}),t.jsx(Gp,{icon:s.icon,size:18}),t.jsx("span",{className:"wg-tile-value",children:s.value})]},`${s.label}-${r}`))})]});case"progress":{const s=Math.round(Math.max(0,Math.min(1,e.ratio))*100);return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"wg-value",children:e.value}),e.caption?t.jsx("span",{className:"wg-caption",children:e.caption}):null,t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"ui-meter",role:"meter","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":s,"aria-label":e.caption??e.value,children:t.jsx("span",{className:"ui-meter-fill","data-tone":e.tone,style:{inlineSize:`${s}%`}})}),e.foot?t.jsx("span",{className:"wg-foot",children:e.foot}):null]})}case"clocks":return t.jsx(aG,{body:e,size:n});case"text":return t.jsxs("span",{className:"wg-text",children:[e.icon?t.jsx("span",{className:"wg-text-icon",children:t.jsx(oe,{name:$o(e.icon),size:18})}):null,t.jsxs("span",{className:"wg-text-words",children:[t.jsx("span",{className:"wg-text-main",children:e.text}),e.sub?t.jsx("span",{className:"wg-row-sub",children:e.sub}):null]})]})}}function Pv({label:e,options:n,multiple:s,value:r,onChange:a}){const i=Array.isArray(r)?r:[r],l=c=>i.includes(c),o=c=>{if(!s)return a(c);a(l(c)?i.filter(u=>u!==c):[...i,c])};return t.jsx("div",{className:"wg-options",role:s?"group":"radiogroup","aria-label":e,children:n.map(c=>t.jsxs("button",{type:"button",role:s?"checkbox":"radio","aria-checked":l(c.value),className:"wg-option","data-on":l(c.value)?"true":void 0,onClick:()=>o(c.value),children:[t.jsx("span",{className:"wg-option-mark","data-multiple":s?"true":void 0,"aria-hidden":"true",children:s&&l(c.value)?t.jsx(oe,{name:"check",size:12}):null}),t.jsxs("span",{className:"wg-option-text",children:[t.jsx("span",{className:"wg-option-name",children:c.label}),c.sub?t.jsx("span",{className:"wg-option-sub",children:c.sub}):null]})]},c.value))})}function uS(e){return"place"in e?e.place:`town:${e.latitude.toFixed(3)},${e.longitude.toFixed(3)}`}function lG(e){var n;return{label:((n=e.name.split(",")[0])==null?void 0:n.trim())||e.name,name:e.name,latitude:e.latitude,longitude:e.longitude,timezone:e.timezone??null}}function oG({field:e,value:n,places:s,onChange:r}){const a=Array.isArray(n)?n:n?[n]:[],[i,l]=d.useState(""),[o,c]=d.useState([]),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=new Map;for(const y of s)p.set(y.id,{value:{place:y.id},label:y.label,sub:y.name});for(const y of[...a,...o])"place"in y||p.set(uS(y),{value:y,label:y.label,sub:y.name});const g=[...p.entries()].map(([y,N])=>({value:y,label:N.label,sub:N.sub})),x=a.map(uS),k=s.find(y=>y.id==="home"||y.label.toLowerCase()==="home")??s[0],j=e.multiple?x:x[0]??(k==null?void 0:k.id)??"",v=y=>{const N=(Array.isArray(y)?y:[y]).map(b=>{var S;return(S=p.get(b))==null?void 0:S.value}).filter(b=>!!b);r(e.multiple?N.slice(-3):N[0]??null)},w=()=>{const y=i.trim();y.length<2||(h(!0),m(null),A.findPlace(y).then(({found:N})=>{const b=N.slice(0,3).map(lG);c(b),b.length===0?m(`Nothing found for “${y}”.`):e.multiple?r([...a,b[0]].slice(-3)):r(b[0])}).catch(()=>m("The place finder didn’t answer. Try again in a moment.")).finally(()=>h(!1)))};return t.jsxs("div",{className:"wg-field-stack",children:[g.length>0?t.jsx(Pv,{label:e.label,options:g,multiple:e.multiple,value:j,onChange:v}):null,t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{value:i,placeholder:"Find a town: Tokyo","aria-label":`Find a town for ${e.label}`,onChange:y=>l(y.target.value),onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),w())}}),t.jsx($,{size:"sm",disabled:u||i.trim().length<2,onClick:w,children:u?"Finding…":"Find"})]}),f?t.jsx("span",{className:"ui-field-hint",children:f}):null]})}function cG({field:e,value:n,sheet:s,onChange:r}){var i;let a;switch(e.kind){case"select":{const l=e.options??[],o=typeof n=="string"?n:e.default??((i=l[0])==null?void 0:i.value)??"",c=l.length>0&&l.length<=3&&l.every(u=>u.label.length<=14);a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):c?t.jsx(Gt,{label:e.label,options:l,value:o,onChange:r}):t.jsx(Pv,{label:e.label,options:l,value:o,onChange:r});break}case"multiselect":{const l=e.options??[];a=l.length===0?t.jsx("span",{className:"ui-field-hint",children:"Nothing to choose from yet."}):t.jsx(Pv,{label:e.label,options:l,multiple:!0,value:Array.isArray(n)?n:e.default??[],onChange:r});break}case"toggle":return t.jsxs("div",{className:"wg-field",children:[t.jsxs("label",{className:"wg-toggle",children:[t.jsx("input",{type:"checkbox",checked:typeof n=="boolean"?n:e.default??!1,onChange:l=>r(l.target.checked)}),t.jsx("span",{children:e.label})]}),e.hint?t.jsx("span",{className:"ui-field-hint",children:e.hint}):null]});case"text":a=t.jsx("input",{"aria-label":e.label,value:typeof n=="string"?n:e.default??"",maxLength:e.max??60,placeholder:e.placeholder,onChange:l=>r(l.target.value)});break;case"place":a=t.jsx(oG,{field:e,value:n,places:s.places,onChange:r});break;case"timeFormat":a=t.jsx(Gt,{label:e.label,options:[{value:"profile",label:M$()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:n==="12h"||n==="24h"?n:"profile",onChange:r});break}return t.jsxs("div",{className:"wg-field",role:"group","aria-label":e.label,children:[t.jsx("span",{className:"wg-field-label",children:e.label}),a,e.hint?t.jsx("span",{className:"ui-field-hint",children:e.hint}):null]})}function uG({info:e,placement:n,surface:s,view:r,label:a}){var u;const i=s==="lock",l=((u=r==null?void 0:r.body)==null?void 0:u.kind)==="text",o=i&&(l||n.size==="small")?"small":n.size,c=r?r.body?e.sensitive?t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."})]}):t.jsx(wm,{body:r.body,size:o}):t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:r.state==="error"?`Couldn't load this${r.error?`: ${r.error}`:""}.`:"Nothing to show right now."})}):t.jsxs("span",{className:"wg-skel-body","aria-hidden":"true",children:[t.jsx("span",{className:"wg-skel","data-w":"half"}),t.jsx("span",{className:"wg-skel","data-w":"third"}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-skel"})]});return t.jsx("div",{className:"wg-preview","data-surface":s,"aria-label":`Preview of ${a}`,role:"img",children:t.jsxs("div",{className:"wg-frame","data-size":o,"data-variant":i?"compact":void 0,"data-kind":r!=null&&r.body&&!e.sensitive?r.body.kind:void 0,"aria-hidden":"true",children:[i?null:t.jsx("div",{className:"wg-head",children:t.jsx("span",{className:"wg-title",children:a})}),t.jsx("div",{className:"wg-body",children:c}),i?t.jsx("span",{className:"wg-compact-title",children:a}):null]})})}function jI({info:e,placement:n,surface:s,onSave:r,onRemove:a,onClose:i}){const l=ge(()=>A.widgetSettings(e.id),[e.id]),[o,c]=d.useState(n.settings??{}),[u,h]=d.useState(null),[f,m]=d.useState(n.label??e.title),[p,g]=d.useState(!1),[x,k]=d.useState(null),j=d.useRef(0),v=d.useMemo(()=>JSON.stringify(o),[o]);d.useEffect(()=>{const N=++j.current,b=window.setTimeout(()=>{A.previewWidget({widget:e.id,size:n.size,settings:o}).then(S=>{N===j.current&&(h(S.view),m(S.label))}).catch(()=>{N===j.current&&h({state:"error",error:"the preview could not be made"})})},u?250:0);return()=>window.clearTimeout(b)},[v,e.id,n.size]);const w=()=>{g(!0),k(null),r(o).then(N=>{g(!1),N||k("Couldn’t keep these settings. Try again.")})},y=s==="lock"?"the lock screen":"Home";return t.jsx(Ye,{title:f,onClose:i,foot:t.jsxs(ne,{children:[t.jsxs($,{variant:"danger-ghost",onClick:a,children:["Remove from ",s==="lock"?"lock screen":"Home"]}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:i,children:"Cancel"}),t.jsx($,{variant:"accent",onClick:w,disabled:p||!l.data,children:p?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"wg-sheet",children:[t.jsx(uG,{info:e,placement:n,surface:s,view:u,label:f}),t.jsxs("p",{className:"wg-sheet-note",children:[e.builtIn?"Built in":`From the ${e.plugin} plugin`," · on ",y,". These settings are this one’s own",s==="lock"?"; Home keeps its own":"","."]}),t.jsx(ae,{message:x??(l.error?"Couldn’t read this widget’s settings.":null)}),l.data?l.data.fields.map(N=>t.jsx(cG,{field:N,value:o[N.key],sheet:l.data,onChange:b=>c({...o,[N.key]:b})},N.key)):l.error?null:t.jsx("p",{className:"wg-sheet-note","aria-busy":"true",children:"Reading its choices…"})]})})}const dG=6e4,wI="buddi.clock",yI="buddi.home.widgets";function hG(){try{const e=Number(window.localStorage.getItem(yI));return Number.isInteger(e)&&e>0?Math.min(e,6):0}catch{return 0}}function fG(e){try{window.localStorage.setItem(yI,String(e))}catch{}}function bI(){const e=new Uint8Array(4);return crypto.getRandomValues(e),`w-${Array.from(e,n=>n.toString(16).padStart(2,"0")).join("")}`}function kI(e,n){const s=d.useRef(n);s.current=n,d.useEffect(()=>{if(!e)return;let r;const a=()=>{r=setTimeout(()=>{s.current(),a()},6e4-Date.now()%6e4+1e3)};return a(),()=>clearTimeout(r)},[e])}function mG(){const e=ge(()=>A.widgets("home"),[],dG),[n,s]=d.useState(void 0);return d.useEffect(()=>{e.data&&s(e.data)},[e.data]),d.useEffect(()=>{n&&fG(n.home.length)},[n]),kI((n==null?void 0:n.home.some(r=>{var a,i;return r.widget===wI&&((i=(a=n.views[r.key])==null?void 0:a.body)==null?void 0:i.kind)!=="clocks"}))??!1,e.reload),{answer:n,error:e.error,apply:s,reload:e.reload}}function pG(e){return new Set(((e==null?void 0:e.home)??[]).map(n=>n.widget))}function gG(e){const[n,s]=d.useState(!1);return d.useEffect(()=>{if(!e||!n)return;const r=()=>{(document.visibilityState==="hidden"||!document.hasFocus())&&s(!1)};return document.addEventListener("visibilitychange",r),window.addEventListener("blur",r),()=>{document.removeEventListener("visibilitychange",r),window.removeEventListener("blur",r)}},[e,n]),[n,s]}const NI=(e,n)=>e.label??(n==null?void 0:n.title)??e.widget;function xG({info:e,placement:n,view:s,index:r,count:a,editing:i,navigate:l,act:o,onRetry:c,retrying:u,drag:h}){var S;const[f,m]=gG(e.sensitive===!0),p=(s==null?void 0:s.state)??"error",g=e.sensitive===!0&&!f,x=e.link?sy(e.link.plugin,e.link.page,e.link.place):null,k=x!==null&&!i&&p!=="error"&&!g,j=n.size==="small"?"medium":"small",v=NI(n,e),w=n.key,y=(((S=e.settings)==null?void 0:S.length)??0)>0;let N;!s&&i?N=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Fills in when you press Done."})}):p==="error"||!s?N=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-state-title",children:"Couldn't load this."}),s!=null&&s.error?t.jsxs("span",{className:"wg-state-sub",children:[vG(s.error),"."]}):null,i?null:t.jsx($,{size:"sm",onClick:c,disabled:u,children:u?"Trying…":"Try again"})]}):p==="empty"||!s.body?N=t.jsx("span",{className:"wg-state",children:t.jsx("span",{className:"wg-state-sub",children:"Nothing to show right now."})}):g?N=t.jsxs("span",{className:"wg-state",children:[t.jsx("span",{className:"wg-mask","aria-hidden":"true",children:"••••"}),t.jsx("span",{className:"wg-state-sub",children:"Hidden on this screen."}),i?null:t.jsx($,{size:"sm",onClick:()=>m(!0),children:"Show"})]}):N=t.jsx(wm,{body:s.body,size:n.size});const b=C=>{C.dataTransfer.effectAllowed="move",C.dataTransfer.setData("text/plain",w),h.start(w)};return t.jsxs("div",{className:"wg-frame",role:"group","aria-label":v,"data-id":e.id,"data-key":w,"data-size":n.size,"data-kind":s!=null&&s.body&&!g&&p!=="error"?s.body.kind:void 0,"data-state":p==="ok"?void 0:p,"data-linked":k?"true":void 0,"data-dragging":h.dragging===w?"true":void 0,"data-over":h.over===w&&h.dragging!==w?"true":void 0,draggable:i?!0:void 0,onDragStart:i?b:void 0,onDragOver:i?C=>{h.dragging&&(C.preventDefault(),h.enter(w))}:void 0,onDrop:i?C=>{C.preventDefault(),h.drop(w)}:void 0,onDragEnd:i?()=>h.end():void 0,children:[t.jsxs("div",{className:"wg-head",children:[i?t.jsx("button",{type:"button",className:"ui-icon-btn wg-grip","data-size":"sm","data-grip":w,"aria-label":`Move ${v}, position ${r+1} of ${a}: arrow keys`,title:"Drag, or use the arrow keys",onKeyDown:C=>{(C.key==="ArrowLeft"||C.key==="ArrowUp")&&(C.preventDefault(),o("earlier")),(C.key==="ArrowRight"||C.key==="ArrowDown")&&(C.preventDefault(),o("later"))},children:t.jsx(oe,{name:"grip",size:14})}):null,t.jsx("span",{className:"wg-title",children:v}),p==="stale"?t.jsx("span",{className:"wg-stale",title:s!=null&&s.error?`Couldn't refresh: ${s.error}.`:void 0,children:s!=null&&s.updatedAt?`${gw(s.updatedAt)} old`:"Not current"}):null,i&&y?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${v}`,title:"Settings",onClick:()=>o("settings"),children:t.jsx(oe,{name:"settings",size:14})}):null,i?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${v} off Home`,title:"Take off Home",onClick:()=>o("hide"),children:t.jsx(oe,{name:"close",size:12})}):t.jsx("span",{className:"wg-more",children:t.jsx(ss,{label:`More for ${v}`,note:s!=null&&s.updatedAt?`${e.builtIn?"Built in":e.plugin} · ${Ge(s.updatedAt)}`:e.builtIn?"Built in":e.plugin,items:[y?{label:"Settings…",onSelect:()=>o("settings")}:null,r>0?{label:"Move earlier",onSelect:()=>o("earlier")}:null,r<a-1?{label:"Move later",onSelect:()=>o("later")}:null,e.sizes.includes(j)?{label:`Make it ${j}`,onSelect:()=>o("size",j)}:null,{label:"Edit widgets",onSelect:()=>o("edit")},"separator",{label:"Hide from Home",onSelect:()=>o("hide")}]})})]}),k?t.jsx("a",{className:"wg-body",href:x,onClick:C=>{C.preventDefault(),l(x)},children:N}):t.jsx("div",{className:"wg-body",children:N}),i?t.jsxs("div",{className:"wg-edit-bar",children:[e.sizes.length>1?t.jsx("span",{className:"ui-segment",role:"radiogroup","aria-label":`Size of ${v}`,children:["small","medium"].filter(C=>e.sizes.includes(C)).map(C=>t.jsx("button",{type:"button",className:"ui-tab",role:"radio","aria-checked":n.size===C,onClick:()=>o("size",C),children:C==="small"?"Small":"Medium"},C))}):t.jsx("span",{className:"wg-edit-note",children:e.sizes[0]==="small"?"Small only":"Medium only"}),t.jsxs("span",{className:"wg-edit-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:earlier`,"aria-label":`Move ${v} earlier`,title:"Move earlier",disabled:r===0,onClick:()=>o("earlier"),children:t.jsx(oe,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","data-move":`${w}:later`,"aria-label":`Move ${v} later`,title:"Move later",disabled:r===a-1,onClick:()=>o("later"),children:t.jsx(oe,{name:"chevron-right"})})]})]}):null]})}function vG(e){const n=e.replace(/\.$/,"");return n.charAt(0).toUpperCase()+n.slice(1)}function jG({widgets:e,navigate:n}){const{answer:s,apply:r}=e,[a,i]=d.useState(!1),[l,o]=d.useState([]),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(null),[g,x]=d.useState(!1),[k,j]=d.useState(null),[v,w]=d.useState(null),[y,N]=d.useState(null),[b,S]=d.useState(null),[C,T]=d.useState(new Set),[E]=d.useState(hG),R=d.useRef(null);if(d.useEffect(()=>{if(!c)return;const W=window.setTimeout(()=>u(null),xI);return()=>window.clearTimeout(W)},[c]),d.useEffect(()=>{var se;const W=R.current;W&&(R.current=null,(se=document.querySelector(`[data-grip="${CSS.escape(W)}"], [data-move="${CSS.escape(W)}"]`))==null||se.focus())}),!s)return E===0?null:t.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets","aria-busy":"true",children:[t.jsx("div",{className:"ui-section-head",children:t.jsx("h3",{className:"ui-section-title",children:"Widgets"})}),t.jsx("div",{className:"wg-grid",children:Array.from({length:E},(W,se)=>t.jsxs("div",{className:"wg-frame","data-state":"loading","aria-hidden":"true",children:[t.jsx("div",{className:"wg-head"}),t.jsxs("span",{className:"wg-skel-body",children:[t.jsx("span",{className:"wg-skel","data-w":"half"}),t.jsx("span",{className:"wg-skel","data-w":"third"}),t.jsx("span",{className:"wg-push"}),t.jsx("span",{className:"wg-skel"})]})]},se))})]});if(s.available.every(W=>W.builtIn)&&s.home.length===0)return null;const M=new Map(s.available.map(W=>[W.id,W])),O=a?l:s.home,I=W=>NI(W,M.get(W.widget)),z=(W,se)=>(p(null),r({...se,home:W,arranged:{...se.arranged,home:!0}}),A.saveWidgets("home",W).then(X=>(r(X),!0),X=>(r(se),p(`Couldn't save your widgets: ${X instanceof Error?X.message:String(X)}`),!1))),U=(W,se,X)=>{if(X<0||X>=W.length||se===X)return null;const je=W.slice(),[be]=je.splice(se,1);return je.splice(X,0,be),f(`${I(be)}, position ${X+1} of ${je.length}.`),je},D=()=>{o(s.home),T(new Set),u(null),p(null),i(!0)},P=W=>(se,X)=>{const je=O[W];if(se==="edit"){D();return}if(se==="settings"){S(je.key);return}if(a){if(se==="earlier"||se==="later"){const be=U(l,W,se==="earlier"?W-1:W+1);if(be){const xe=document.activeElement;R.current=(xe==null?void 0:xe.dataset.grip)??(xe==null?void 0:xe.dataset.move)??null,o(be)}}se==="size"&&X&&(o(l.map((be,xe)=>xe===W?{...be,size:X}:be)),T(new Set([...C,je.key]))),se==="hide"&&(o(l.filter((be,xe)=>xe!==W)),f(`${I(je)} taken off.`));return}if(se==="earlier"||se==="later"){const be=U(s.home,W,se==="earlier"?W-1:W+1);be&&z(be,s)}se==="size"&&X&&z(s.home.map((be,xe)=>xe===W?{...be,size:X}:be),s),se==="hide"&&z(s.home.filter((be,xe)=>xe!==W),s).then(be=>{be&&u({item:je,at:W})})},K=()=>{if(!c)return;const W=s.home.filter(se=>se.key!==c.item.key);W.splice(Math.min(c.at,W.length),0,c.item),u(null),z(W,s)},F=()=>{x(!0),z(l,s).then(W=>{x(!1),W&&(i(!1),f("Widgets saved."))})},Q=W=>{j(W),A.refreshWidget(W).then(r,()=>{}).finally(()=>j(null))},_=W=>{var je;const se={key:bI(),widget:W.id,size:W.sizes[0],settings:{}},X=l.some(be=>be.widget===W.id);o([...l,se]),f(`${W.title} added.`),X&&(((je=W.settings)==null?void 0:je.length)??0)>0&&S(se.key)},re=(W,se)=>a?(o(l.map(X=>{if(X.key!==W)return X;const{label:je,...be}=X;return{...be,settings:se}})),T(new Set([...C,W])),S(null),Promise.resolve(!0)):z(s.home.map(X=>X.key===W?{...X,settings:se}:X),s).then(X=>(X&&(S(null),f("Settings saved.")),X)),Y=W=>{S(null);const se=O.findIndex(X=>X.key===W);se>=0&&P(se)("hide")},B={dragging:v,over:y,start:W=>w(W),enter:W=>{y!==W&&N(W)},end:()=>{w(null),N(null)},drop:W=>{const se=l.findIndex(be=>be.key===v),X=l.findIndex(be=>be.key===W),je=se>=0&&X>=0?U(l,se,X):null;je&&o(je),w(null),N(null)}},q=c?t.jsxs("div",{className:"wg-undo","data-size":c.item.size,role:"status","aria-live":"polite",children:[t.jsxs("span",{children:[I(c.item)," hidden"]}),t.jsx("span",{className:"home-glance-sep","aria-hidden":"true",children:"·"}),t.jsx($,{size:"sm",variant:"ghost",onClick:K,children:"Undo"})]},"undo"):null,J=[];O.forEach((W,se)=>{const X=M.get(W.widget);if(!X)return;c&&!a&&c.at===se&&J.push(q);const je=a&&(C.has(W.key)||!s.home.some(be=>be.key===W.key));J.push(t.jsx(xG,{info:X,placement:W,view:je?void 0:s.views[W.key],index:se,count:O.length,editing:a,navigate:n,act:P(se),onRetry:()=>Q(W.key),retrying:k===W.key,drag:B},W.key))}),c&&!a&&c.at>=O.length&&J.push(q);const Z=s.available.filter(W=>!W.builtIn),fe=Z.length-2,ve=b?O.find(W=>W.key===b):void 0,Oe=ve?M.get(ve.widget):void 0;return t.jsxs("section",{className:"ui-section wg-section","aria-label":"Widgets",children:[t.jsxs("div",{className:"ui-section-head",children:[t.jsx("h3",{className:"ui-section-title",children:"Widgets"}),a?t.jsxs("div",{className:"ui-toolbar","data-align":"end",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{i(!1),o([])},disabled:g,children:"Cancel"}),t.jsx($,{size:"sm",variant:"accent",onClick:F,disabled:g,children:g?"Saving…":"Done"})]}):O.length>0?t.jsx("div",{className:"ui-toolbar","data-align":"end",children:t.jsx($,{size:"sm",variant:"ghost",onClick:D,children:"Edit"})}):null]}),t.jsx("p",{className:"sr-only","aria-live":"polite",children:h}),m?t.jsx(G,{tone:"critical",role:"alert",children:m}):null,O.length===0&&!a&&!c?t.jsxs("div",{className:"wg-empty",children:[t.jsxs("div",{className:"wg-empty-text",children:[t.jsx("p",{className:"wg-empty-title",children:"Add widgets to Home"}),t.jsxs("p",{className:"wg-empty-sub",children:["Small live panels from your plugins:"," ",(Z.length>0?Z:s.available).slice(0,2).map(W=>W.title).join(", "),fe>0?` and ${fe} more`:"","."]})]}),t.jsx($,{size:"sm",variant:"accent",onClick:D,children:"Add widgets"})]}):J.length>0?t.jsx("div",{className:"wg-grid","data-editing":a?"true":void 0,children:J}):null,a?t.jsxs("div",{className:"wg-gallery",role:"region","aria-label":"Add widgets",children:[t.jsxs("div",{className:"wg-gallery-head",children:[t.jsx("p",{className:"wg-gallery-title",children:"Add widgets"}),t.jsx("a",{className:"wg-gallery-aside",href:Fe("lock"),onClick:W=>{W.preventDefault(),n(Fe("lock"))},children:"The lock screen has its own pick"})]}),t.jsx("ul",{className:"wg-gallery-list",children:s.available.map(W=>{var we;const se=l.filter(Ie=>Ie.widget===W.id).length,X=(((we=W.settings)==null?void 0:we.length)??0)>0,je=W.builtIn?"Built in":`${W.plugin} plugin`,be=W.sizes.length>1?"small or medium":`${W.sizes[0]} only`,xe=se>1?` · ${se} on Home`:se===1&&X?" · on Home":"";return t.jsxs("li",{className:"wg-add",children:[t.jsxs("span",{className:"wg-add-text",children:[t.jsx("span",{className:"wg-add-title",children:W.title}),t.jsxs("span",{className:"wg-add-sub",children:[je," · ",be,W.sensitive?" · hidden until you show it":"",xe]})]}),se>0&&!X?t.jsx("span",{className:"wg-add-note",children:"On Home"}):t.jsxs($,{size:"sm","aria-label":`${se>0?"Add another":"Add"} ${W.title}`,onClick:()=>_(W),children:[t.jsx(oe,{name:"plus",size:12})," ",se>0?"Add another":"Add"]})]},W.id)})}),t.jsxs("a",{className:"wg-gallery-more",href:Ux("widgets"),onClick:W=>{W.preventDefault(),n(Ux("widgets"))},children:[t.jsx(oe,{name:"plug",size:14}),t.jsx("span",{children:"Get more widgets"}),t.jsx("span",{className:"wg-gallery-more-sub",children:"from plugins on withbuddi.com"})]})]}):null,ve&&Oe?t.jsx(jI,{info:Oe,placement:ve,surface:"home",onClose:()=>S(null),onSave:W=>re(ve.key,W),onRemove:()=>Y(ve.key)}):null]})}function Oy(e,n){return!e||e==="image"&&!n?"earth":e}const wG="(max-width: 720px)",yG=3e4,bG=5e3,kG={1:"a minute",5:"5 minutes",15:"15 minutes",60:"an hour"};function Yp(e,n){return{time:Tt(e,n),day:wr(e,n,{weekday:!0})}}function ym(e,n){return e?wu({timeFormat:e.time,...e.date==="off"?{}:{dateFormat:e.date}},n):n()}function NG(e,n,s=new Date,r){return ym(r,()=>SG(e,n,s))}function SG(e,n,s){if(!e.lockedAt)return"Locked";const r=new Date(e.lockedAt),i=Yp(r,n).day===Yp(s,n).day?Yp(r,n).time:pw(r,n);return e.reason==="idle"?`Locked after ${e.delayMinutes?kG[e.delayMinutes]??`${e.delayMinutes} minutes`:"a while"} away, at ${i}`:e.reason==="start"?`Locked since this session began, at ${i}`:`Locked by you at ${i}`}function CG(e){const n=()=>e?Math.max(0,Math.ceil((Date.parse(e)-Date.now())/1e3)):0,[s,r]=d.useState(n);return d.useEffect(()=>{if(r(n()),!e)return;const a=window.setInterval(()=>r(n()),500);return()=>window.clearInterval(a)},[e]),s}const EG=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;function dS({size:e=16}){return t.jsx(oe,{name:"lock",size:e})}function SI({size:e=16}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M3 8h9.6M8.6 4l4 4-4 4"})})}function $G(){return t.jsxs("svg",{width:18,height:18,viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M7.6 5h8a1.4 1.4 0 0 1 1.4 1.4v7.2A1.4 1.4 0 0 1 15.6 15h-8L3 10z"}),t.jsx("path",{d:"M9.6 8l4 4M13.6 8l-4 4"})]})}function hS({text:e}){const[n,s]=d.useState(!1),r=()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return t.jsxs("div",{className:"so-cmd",children:[t.jsx("code",{className:"so-cmd-text",children:e}),t.jsx($,{size:"sm",onClick:r,children:n?"Copied":"Copy"})]})}function AG({onClose:e}){return t.jsx(Ut,{title:"Forgot your PIN?",onClose:e,foot:t.jsx($,{variant:"accent",onClick:e,children:"Done"}),children:t.jsxs("div",{className:"lk-forgot",children:[t.jsx("p",{className:"lk-forgot-text",children:"The PIN covers this dashboard; it doesn’t sign you in. On the computer buddi runs on, run one of these:"}),t.jsxs("div",{className:"lk-forgot-way",children:[t.jsx(hS,{text:"buddi dashboard --unlock"}),t.jsx("p",{className:"lk-forgot-hint",children:"Opens buddi without the PIN, once. It prints a link for your other devices too, good for five minutes."})]}),t.jsxs("div",{className:"lk-forgot-way",children:[t.jsx(hS,{text:"buddi dashboard --remove-pin"}),t.jsx("p",{className:"lk-forgot-hint",children:"Removes the PIN on every device. Set a new one in Settings → Lock screen."})]})]})})}function TG({approvals:e,needs:n,after:s,onPick:r}){const a=[];return e>0&&a.push({key:"approvals",n:e,text:e===1?"approval waiting":"approvals waiting"}),n>0&&a.push({key:"needs",n,text:e>0?n===1?"more needs you":"more need you":n===1?"thing needs you":"things need you"}),a.length===0?null:t.jsx("ul",{className:"lk-badges","aria-label":"Waiting for you",children:a.map(i=>t.jsx("li",{children:t.jsxs("button",{type:"button",className:"lk-chip","data-kind":i.key,"aria-pressed":s===i.key,disabled:!r,title:r?i.key==="needs"?"Open Needs you once unlocked":"Open your approvals once unlocked":void 0,onClick:()=>r==null?void 0:r(s===i.key?null:i.key),children:[t.jsx("span",{className:"ui-badge","aria-hidden":"true",children:i.n>99?"99+":i.n}),t.jsxs("span",{children:[t.jsxs("span",{className:"lk-sr",children:[i.n," "]}),i.text]})]})},i.key))})}function RG(e,n){const s=n?2:4;let r=0,a=0;for(const i of e){const l=Math.min(i==="medium"?2:1,s);a+l>s&&(a=0),a+=l,r=Math.max(r,a)}return r}function IG(e){return e.filter(n=>!(n.view.body.kind==="text"&&!n.view.body.sub))}function fS(e,n){const s=Object.fromEntries(new Intl.DateTimeFormat("en-CA",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(e).map(r=>[r.type,r.value]));return Math.round(Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day))/864e5)}function PG(e,n,s,r=new Date){if(e.state!=="stale"||!e.updatedAt)return null;const a=new Date(e.updatedAt);return Number.isNaN(a.getTime())?null:`from ${ym(s,()=>{const i=Tt(a,n),l=fS(r,n)-fS(a,n);return l<=0?i:l===1?`yesterday ${i}`:l<7?`${new Intl.DateTimeFormat("en-US",{timeZone:n,weekday:"short"}).format(a)} ${i}`:`${wr(a,n,{compact:!0})} ${i}`})}`}function MG({widgets:e,phone:n,timezone:s,clockView:r,now:a}){const i=IG(e);if(i.length===0)return null;const l=i.map(c=>({w:c,size:n||c.view.body.kind==="text"?"small":c.size})),o=RG(l.map(({size:c})=>c),n);return t.jsx("div",{className:"lk-widgets",children:t.jsx("div",{className:"lk-grid","data-phone":n?"true":void 0,"data-cols":o,children:l.map(({w:c,size:u})=>{const h=PG(c.view,s,r,a);return t.jsxs("div",{className:"wg-frame","data-variant":"compact","data-size":u,"data-kind":c.view.body.kind,"data-stale":h?"true":void 0,role:"group","aria-label":c.title,children:[t.jsx("div",{className:"wg-body",children:t.jsx(wm,{body:c.view.body,size:u})}),t.jsxs("span",{className:"wg-compact-title",children:[c.title,h?t.jsxs("span",{className:"wg-compact-from",children:[" · ",h]}):null]})]},c.key??c.id)})})})}function OG({text:e}){const n=/^(.*?)[\s\u202f]?([AaPp]\.?[Mm]\.?)$/.exec(e);return t.jsx("p",{className:"lk-time","aria-label":e,children:n?t.jsxs(t.Fragment,{children:[n[1],t.jsx("span",{className:"lk-ampm","aria-hidden":"true",children:n[2]})]}):e})}function mS(e,n){const s=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(e).map(a=>[a.type,a.value])),r=Date.UTC(Number(s.year),Number(s.month)-1,Number(s.day),Number(s.hour)%24,Number(s.minute));return Math.round((r-Math.floor(e.getTime()/6e4)*6e4)/6e4)}function DG(e,n,s){try{const r=mS(e,n)-mS(e,s);if(r===0)return"Same time";const a=u=>new Intl.DateTimeFormat("en-CA",{timeZone:u,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),i=a(n)!==a(s)?r>0?", tomorrow":", yesterday":"",l=Math.floor(Math.abs(r)/60),o=Math.abs(r)%60;return`${o===0?`${l} h`:l===0?`${o} min`:`${l} h ${o}`} ${r>0?"ahead":"behind"}${i}`}catch{return""}}function LG(e,n,s){const r=s??{date:null,zone:null};return ym(s,()=>({time:Tt(e,n),day:r.date==="off"?null:wr(e,n,{weekday:!0}),zone:r.zone?{label:r.zone.label,time:Tt(e,r.zone.timezone),offset:DG(e,r.zone.timezone,n)}:null}))}function CI({data:e,now:n,phone:s,pad:r=!1,after:a,onPick:i}){const l=(e==null?void 0:e.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,o=LG(n,l,e==null?void 0:e.clockView),c=Oy(e==null?void 0:e.background,e==null?void 0:e.image),u=(e==null?void 0:e.focus)??null,h=u?ym(e==null?void 0:e.clockView,()=>s?zG(uu(u,l,n)):`${Ai[u.mode]} ${uu(u,l,n)}`):"";return t.jsxs(t.Fragment,{children:[c==="earth"?t.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo","data-earth":"true",src:F7(s),alt:"",decoding:"async"}),t.jsx("div",{className:"lk-scrim"})]}):c==="image"&&(e!=null&&e.image)?t.jsxs("div",{className:"lk-ground","aria-hidden":"true",children:[t.jsx("img",{className:"lk-photo",src:e.image,alt:""}),t.jsx("div",{className:"lk-scrim"})]}):t.jsx("div",{className:"ui-fieldbg lk-ground","aria-hidden":"true"}),t.jsxs("header",{className:"lk-top",children:[t.jsxs("span",{className:"lk-brand",children:[t.jsx(su,{size:"sm"}),t.jsx("span",{children:"buddi"})]}),t.jsx("span",{className:"lk-top-spacer"}),u?t.jsxs("span",{className:"lk-chip","data-kind":"focus",children:[t.jsx(oe,{name:"moon",size:13}),t.jsx("span",{children:h})]}):null]}),t.jsxs("div",{className:"lk-main",children:[o.day?t.jsx("p",{className:"lk-date",children:o.day}):null,t.jsx(OG,{text:o.time}),o.zone?t.jsxs("p",{className:"lk-zone",children:[t.jsx("span",{className:"lk-zone-name",children:o.zone.label}),t.jsx("span",{className:"lk-zone-time",children:o.zone.time}),o.zone.offset?t.jsx("span",{className:"lk-zone-off",children:o.zone.offset}):null]}):null,r||!e?null:t.jsx(TG,{approvals:e.approvals,needs:e.needs??0,after:a??null,...i?{onPick:i}:{}}),r||!e?null:t.jsx(MG,{widgets:e.widgets,phone:s,timezone:l,clockView:e.clockView,now:n})]})]})}function FG({value:e,disabled:n,onDigit:s,onBack:r,onSubmit:a}){return t.jsxs("div",{className:"lk-pad",role:"group","aria-label":"PIN pad",children:[["1","2","3","4","5","6","7","8","9"].map(i=>t.jsx("button",{type:"button",className:"lk-key",disabled:n,onClick:()=>s(i),children:i},i)),t.jsx("button",{type:"button",className:"lk-key","data-kind":"quiet","aria-label":"Delete",disabled:n||e.length===0,onClick:r,children:t.jsx($G,{})}),t.jsx("button",{type:"button",className:"lk-key",disabled:n,onClick:()=>s("0"),children:"0"}),t.jsx("button",{type:"button",className:"lk-key","data-kind":"go","aria-label":"Unlock",disabled:n||e.length<4,onClick:a,children:t.jsx(SI,{size:18})})]})}function _G({initial:e,onUnlocked:n}){const s=fs(wG),r=gI(),[a,i]=d.useState(null),l=a??e,[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState((e==null?void 0:e.waitUntil)??null),[p,g]=d.useState(!1),[x,k]=d.useState(!1),[j,v]=d.useState(!1),[w,y]=d.useState(!1),[N,b]=d.useState(!1),[S,C]=d.useState(null),T=d.useRef(null),E=CG(f),R=E>0,M=d.useRef(n),O=d.useRef(S);O.current=S,M.current=q=>{O.current&&(window.location.hash=to),n(q)};const I=q=>{var J;C(q),s&&q?y(!0):(J=T.current)==null||J.focus()},z=d.useRef(0),U=d.useRef(0),D=d.useRef(0),P=d.useCallback(()=>{const q=++z.current;D.current=Date.now(),A.lockScreen().then(J=>{q<U.current||(U.current=q,k(!1),i(J),m(J.waitUntil),J.locked||M.current(J))}).catch(J=>{J instanceof he&&J.status===401?window.location.reload():Oh(J)&&k(!0)})},[]);d.useEffect(()=>{P();const q=window.setInterval(P,yG),J=()=>{document.visibilityState==="visible"&&P()},Z=()=>{Date.now()-D.current>=bG&&P()};return document.addEventListener("visibilitychange",J),document.addEventListener("resume",Z),window.addEventListener("focus",Z),window.addEventListener("pageshow",Z),window.addEventListener("online",P),()=>{window.clearInterval(q),document.removeEventListener("visibilitychange",J),document.removeEventListener("resume",Z),window.removeEventListener("focus",Z),window.removeEventListener("pageshow",Z),window.removeEventListener("online",P)}},[P]),kI((a==null?void 0:a.widgets.some(q=>q.id===wI&&q.view.body.kind!=="clocks"))??!1,P),d.useEffect(()=>{var q;!s&&!j&&!R&&((q=T.current)==null||q.focus())},[s,j,R,p]),d.useEffect(()=>{!R&&f&&h(null)},[R,f]);const K=q=>{q==null||q.preventDefault(),!(p||R||o.length<4)&&(g(!0),A.unlock(o).then(J=>{var fe;if(c(""),J.locked){g(!1);return}if((fe=window.matchMedia)==null?void 0:fe.call(window,"(prefers-reduced-motion: reduce)").matches){M.current(J);return}b(!0),window.setTimeout(()=>M.current(J),240)}).catch(J=>{if(g(!1),c(""),!(J instanceof he))return h("Something went wrong. Try again.");const Z=J.detail??{};if(J.status===403||J.status===429){Z.waitUntil&&m(Z.waitUntil);const fe=Z.triesLeft??0;h(Z.waitUntil?"That PIN isn’t right.":`That PIN isn’t right. ${fe} ${fe===1?"try":"tries"} left.`)}else Oh(J)?h("buddi isn’t answering. Try again in a moment."):h(J.message)}))},F=(a==null?void 0:a.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,Q=Oy(l==null?void 0:l.background,l==null?void 0:l.image),_=(a==null?void 0:a.owner)??null,re=x?{tone:"critical",text:"buddi isn’t answering. The lock stays until it does."}:R?{tone:"critical",text:`Too many tries. Try again in ${EG(E)}.`}:u?{tone:"critical",text:u}:S?{tone:void 0,text:S==="needs"?"Unlock to open what needs you.":"Unlock to open your approvals."}:{tone:void 0,text:l?NG(l,F,r,a==null?void 0:a.clockView):"Locked"},Y=q=>q.replace(/\D/g,"").slice(0,8),B=t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face","aria-hidden":"true",children:(_??"You").slice(0,1).toUpperCase()}),_?t.jsx("span",{className:"lk-owner",children:_}):null]});return t.jsxs("div",{className:"lk","data-bg":Q,"data-phone":s?"true":void 0,"data-view":w?"pad":"glance","data-opening":N?"true":void 0,role:"dialog","aria-modal":"true","aria-label":"buddi is locked","data-testid":"lock-screen",children:[t.jsx(CI,{data:a??(l?{...UG(l)}:null),now:r,phone:s,pad:w,after:S,onPick:I}),t.jsx("footer",{className:"lk-unlock",children:s&&!w?t.jsxs(t.Fragment,{children:[t.jsxs("button",{type:"button",className:"lk-chip lk-enter",onClick:()=>y(!0),children:[t.jsx(dS,{size:14}),t.jsx("span",{children:"Enter PIN"})]}),t.jsx("p",{className:"lk-note","data-tone":re.tone,role:"status","aria-live":"polite",children:re.text})]}):s?t.jsxs(t.Fragment,{children:[B,t.jsx("div",{className:"lk-dots","aria-hidden":"true","data-state":u?"wrong":void 0,children:o.length===0?t.jsx("span",{className:"lk-dots-empty",children:"Enter your PIN"}):Array.from(o).map((q,J)=>t.jsx("span",{className:"lk-dot"},J))}),t.jsx("span",{className:"lk-sr","aria-live":"polite",children:o.length===1?"1 digit entered":`${o.length} digits entered`}),t.jsx("p",{className:"lk-note","data-tone":re.tone,role:"status","aria-live":"polite",children:re.text}),t.jsx(FG,{value:o,disabled:R||p,onDigit:q=>{h(null),c(Y(o+q))},onBack:()=>c(o.slice(0,-1)),onSubmit:()=>K()}),t.jsxs("div",{className:"lk-pad-foot",children:[t.jsx("button",{type:"button",className:"lk-link",onClick:()=>v(!0),children:"Forgot PIN?"}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>{y(!1),c(""),h(null)},children:"Cancel"})]})]}):t.jsxs(t.Fragment,{children:[B,t.jsxs("form",{className:"lk-pin","data-state":u&&!R?"wrong":R?"wait":void 0,onSubmit:K,children:[t.jsx(dS,{size:15}),t.jsx("input",{ref:T,type:"password",inputMode:"numeric",autoComplete:"off",maxLength:8,"aria-label":"PIN","aria-describedby":"lk-note",placeholder:R?"Wait a moment":"Enter your PIN",disabled:R,value:o,onChange:q=>{h(null),c(Y(q.target.value))}}),t.jsx("button",{type:"submit",className:"lk-go","aria-label":"Unlock",disabled:p||R||o.length<4,children:t.jsx(SI,{})})]}),t.jsx("p",{className:"lk-note",id:"lk-note","data-tone":re.tone,role:"status","aria-live":"polite",children:re.text}),t.jsx("button",{type:"button",className:"lk-link",onClick:()=>v(!0),children:"Forgot PIN?"})]})}),j?t.jsx(AG,{onClose:()=>v(!1)}):null]})}function zG(e){return e.slice(0,1).toUpperCase()+e.slice(1)}function UG(e){return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,background:e.background,image:e.image,focus:null,approvals:0,needs:0,widgets:[]}}const BG=3e4,WG=5e3,HG="buddi-lock",Mv="buddi-locked",KG=Fe("lock");function EI(){var n;const e=navigator;return/mac|iphone|ipad|ipod/i.test(((n=e.userAgentData)==null?void 0:n.platform)||navigator.platform||navigator.userAgent)}function VG(e=EI()){return e?"⌃⌘L":"Ctrl+Alt+L"}function GG(e,n=EI()){return!(e.code==="KeyL"||e.key.toLowerCase()==="l")||!e.ctrlKey||e.shiftKey?!1:n?e.metaKey&&!e.altKey:e.altKey&&!e.metaKey}const $I=d.createContext({pin:!1,state:null,lockNow:()=>{},update:()=>{},shortcut:"⌃⌘L"});function bm(){return d.useContext($I)}function Cd(e){try{e?localStorage.setItem(Mv,"1"):localStorage.removeItem(Mv)}catch{}}function YG(){try{return localStorage.getItem(Mv)==="1"}catch{return!1}}function qG(){try{return typeof BroadcastChannel>"u"?null:new BroadcastChannel(HG)}catch{return null}}function QG({children:e}){const[n,s]=d.useState("checking"),[r,a]=d.useState(null),i=d.useRef(null),l=d.useRef(Date.now()),o=d.useRef(0),c=d.useRef(0),u=d.useRef(0),h=d.useCallback((x,k)=>{x&&a(x),s(k?"locked":"open"),Cd(k),k||(l.current=Date.now())},[]),f=d.useCallback(()=>{A.lockState().then(x=>h(x,x.locked)).catch(x=>{if(x instanceof he&&x.status===401)return s("open");h(null,YG())})},[h]);d.useEffect(()=>{f()},[f]);const m=d.useCallback((x="owner")=>{var k;if(!(r!=null&&r.pin)){window.location.hash=KG;return}s("locked"),Cd(!0),x==="owner"&&((k=i.current)==null||k.postMessage({type:"locked"})),(x==="idle"?A.lockNow("idle",Date.now()-l.current):A.lockNow(x)).then(j=>{var v;x==="idle"&&j.locked&&((v=i.current)==null||v.postMessage({type:"locked"})),h(j,j.locked)}).catch(()=>f())},[r==null?void 0:r.pin,h,f]);d.useEffect(()=>{const x=()=>{s("locked"),Cd(!0),f()};return window.addEventListener(Sx,x),()=>window.removeEventListener(Sx,x)},[f]),d.useEffect(()=>{const x=qG();if(i.current=x,!!x)return x.onmessage=k=>{const j=k.data;(j==null?void 0:j.type)==="locked"?(s("locked"),Cd(!0)):(j==null?void 0:j.type)==="unlocked"?f():(j==null?void 0:j.type)==="activity"&&typeof j.at=="number"&&(l.current=Math.max(l.current,j.at))},()=>{x.close(),i.current=null}},[f]),d.useEffect(()=>{const x=k=>{GG(k)&&(k.preventDefault(),n==="open"&&m("owner"))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[n,m]);const p=r!=null&&r.pin?r.delayMinutes:null;d.useEffect(()=>{if(n!=="open"||!(r!=null&&r.pin))return;c.current=l.current;const x=()=>{var b;const N=Date.now();l.current=N,N-u.current>1e4&&(u.current=N,(b=i.current)==null||b.postMessage({type:"activity",at:N}))},k=()=>{const N=Date.now();l.current<=c.current||N-o.current<BG||(o.current=N,c.current=l.current,A.lockActivity().catch(()=>{}))},j=()=>{if(p!==null&&Date.now()-l.current>=p*6e4){m("idle");return}k()},v=["pointerdown","pointermove","keydown","wheel","touchstart"];for(const N of v)window.addEventListener(N,x,{passive:!0,capture:!0});const w=window.setInterval(j,WG),y=()=>{document.visibilityState==="visible"&&j()};return document.addEventListener("visibilitychange",y),()=>{for(const N of v)window.removeEventListener(N,x,{capture:!0});window.clearInterval(w),document.removeEventListener("visibilitychange",y)}},[n,r==null?void 0:r.pin,p,m]);const g=d.useMemo(()=>({pin:(r==null?void 0:r.pin)===!0,state:r,lockNow:()=>m("owner"),update:x=>h(x,x.locked),shortcut:VG()}),[r,m,h]);return n==="checking"?null:n==="locked"?t.jsx(_G,{initial:r,onUnlocked:x=>{var k;(k=i.current)==null||k.postMessage({type:"unlocked"}),h(x,!1)}}):t.jsx($I.Provider,{value:g,children:e})}const AI="a connection needs you";function JG({attention:e,place:n,onNavigate:s,theme:r,onTheme:a,plugins:i=[],updateAvailable:l=!1,settingsDot:o,version:c,stale:u=!1,reload:h,timezone:f,status:m}){return t.jsxs("nav",{className:"rail","aria-label":"Places",children:[t.jsx("a",{className:"rail-mark",href:$n,onClick:p=>{p.preventDefault(),s($n)},"aria-label":"buddi home",children:t.jsx(su,{})}),dU.filter(p=>p.route!==on).map(p=>t.jsx(qp,{label:p.label,href:p.route,active:n===p.route,badge:p.route===$n?e:0,onClick:()=>s(p.route),children:pS[p.route]},p.route)),i.map(p=>{const g=_r(p.plugin,p.id);return t.jsx(qp,{label:p.title,href:g,active:n===g,badge:0,onClick:()=>s(g),children:t.jsx(oe,{name:dI(p.icon)})},g)}),t.jsx("div",{className:"rail-spacer"}),t.jsx(qp,{label:"Settings",href:on,active:n===on,badge:0,dot:l?"a newer buddi is ready":o,onClick:()=>s(on),children:pS[on]}),m,t.jsx(ZG,{theme:r,onTheme:a,onNavigate:s,version:c,stale:u,reload:h,timezone:f})]})}const XG=[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}];function ZG({theme:e,onTheme:n,onNavigate:s,version:r,stale:a,reload:i=()=>window.location.reload(),timezone:l}){var y,N,b;const o=ge(()=>A.owner(),[]),c=bm(),u=ge(()=>A.focus(),[],6e4),h=((y=u.data)==null?void 0:y.focus)??null,f=(S,C)=>{A.setFocus(S,C).finally(()=>u.reload())},m=((b=(N=o.data)==null?void 0:N.preferredName)==null?void 0:b.trim())||null,p=(m??"You").slice(0,1).toUpperCase(),[g]=d.useState(EU),[x]=d.useState(nY),k=jm(),j=m?`You: ${m}`:"You",v=h?`${Ai[h.mode]} ${uu(h,l)}`:null,w=[j,v,a?"reload to update":null].filter(Boolean).join(", ");return t.jsx("div",{className:"rail-owner",children:t.jsxs(Su,{modal:!1,children:[t.jsx(Cu,{asChild:!0,children:t.jsxs("button",{type:"button",className:"rail-owner-btn","aria-label":w,children:[t.jsx("span",{className:"rail-owner-face","aria-hidden":"true",children:p}),a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"owner-dot","aria-hidden":"true"}):null,h?t.jsx("span",{className:"rail-focus","data-testid":"owner-focus","aria-hidden":"true",children:t.jsx(oe,{name:"moon",size:10})}):null]})}),t.jsx(ko,{children:t.jsxs(Eu,{className:"ui-menu rail-owner-menu",side:"right",align:"end",sideOffset:10,children:[t.jsxs("div",{className:"rail-owner-head",children:[t.jsx("span",{className:"rail-owner-face","data-size":"lg","aria-hidden":"true",children:p}),t.jsxs("span",{className:"rail-owner-who",children:[t.jsx("span",{className:"rail-owner-name",children:m??"You"}),t.jsx("span",{className:"rail-owner-sub",children:"On this Mac"})]})]}),t.jsx(la,{className:"ui-menu-sep"}),t.jsx(tY,{focus:h,timezone:l,onSwitch:f}),t.jsx(la,{className:"ui-menu-sep"}),t.jsx(Wi,{className:"ui-menu-label",children:"Theme"}),t.jsx("div",{className:"rail-owner-theme",children:t.jsx(Gt,{label:"Theme",options:XG,value:e,onChange:n})}),t.jsx(la,{className:"ui-menu-sep"}),c.pin?t.jsxs(Bs,{className:"ui-menu-item rail-owner-reload",onSelect:()=>c.lockNow(),children:[t.jsx("span",{children:"Lock now"}),t.jsx("kbd",{className:"rail-owner-kbd",children:c.shortcut})]}):t.jsx(Bs,{className:"ui-menu-item",onSelect:()=>s(Fe("lock")),children:"Set up a lock screen…"}),t.jsx(Bs,{className:"ui-menu-item",onSelect:()=>s(Fe("appearance")),children:"Change appearance"}),k?t.jsx(Bs,{className:"ui-menu-item",onSelect:()=>{Py(k)},children:"Install the app"}):null,g||a?t.jsxs(Bs,{className:"ui-menu-item rail-owner-reload","data-update":a?"true":void 0,onSelect:()=>i(),children:[t.jsx("span",{children:a?"Reload to update":"Reload"}),x?t.jsx("kbd",{className:"rail-owner-kbd",children:x}):null]}):null,r?t.jsxs(t.Fragment,{children:[t.jsx(la,{className:"ui-menu-sep"}),t.jsxs(Bs,{className:"ui-menu-item rail-owner-version","data-update":r.updateAvailable?"true":void 0,onSelect:()=>s(Fe("system")),children:[t.jsxs("span",{className:"mono",children:["buddi ",r.current]}),r.updateAvailable&&r.latest?t.jsxs("span",{className:"rail-owner-update",children:["A newer buddi is ready: ",r.latest]}):null]})]}):null]})})]})})}const Ai={normal:"Off","urgent-only":"Urgent only","do-not-disturb":"Do not disturb"},eY=[{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 uu(e,n,s=new Date){if(!e.until)return"until you turn it off";const r=new Date(e.until),a=n??Intl.DateTimeFormat().resolvedOptions().timeZone,i=c=>new Intl.DateTimeFormat("en-CA",{timeZone:a,dateStyle:"short"}).format(c),l=Tt(r,a);return i(r)===i(s)?`until ${l}`:`until ${new Intl.DateTimeFormat("en-US",{timeZone:a,weekday:"short"}).format(r)} ${l}`}function tY({focus:e,timezone:n,onSwitch:s}){return t.jsxs(j3,{children:[t.jsxs(w3,{className:"ui-menu-item rail-owner-focus",children:[t.jsx("span",{children:"Focus"}),t.jsx("span",{className:"rail-owner-kbd",children:e?Ai[e.mode]:"Off"})]}),t.jsx(ko,{children:t.jsxs(y3,{className:"ui-menu rail-owner-menu",sideOffset:6,children:[t.jsx("p",{className:"ui-menu-empty",role:"status",children:e?`${Ai[e.mode]} ${uu(e,n)}${e.by==="schedule"?", from a schedule":""}.`:"No focus is on."}),["do-not-disturb","urgent-only"].map(r=>t.jsxs(IA,{children:[t.jsx(la,{className:"ui-menu-sep"}),t.jsx(Wi,{className:"ui-menu-label",children:Ai[r]}),eY.map(a=>t.jsx(Bs,{className:"ui-menu-item","aria-label":`${Ai[r]} ${a.label.toLowerCase()}`,onSelect:()=>s(r,a.value),children:a.label},a.value))]},r)),e?t.jsxs(t.Fragment,{children:[t.jsx(la,{className:"ui-menu-sep"}),t.jsx(Bs,{className:"ui-menu-item",onSelect:()=>s("normal"),children:"Turn off"})]}):null]})})]})}function nY(){const e=window.navigator.userAgent;return/iPhone|iPad|Android|Mobile/.test(e)?null:/Mac/.test(e)?"⌘R":"Ctrl+R"}function qp({label:e,href:n,active:s,badge:r,dot:a,onClick:i,children:l}){return t.jsxs("a",{className:"rail-link",href:n,"data-active":s?"true":void 0,"aria-current":s?"page":void 0,"aria-label":r>0?`${e}, ${r} waiting`:a?`${e}, ${a}`:e,onClick:o=>{o.preventDefault(),i()},children:[t.jsxs("span",{className:"rail-icon",children:[l,r>0?t.jsx("span",{className:"rail-badge","aria-hidden":"true",children:r>99?"99+":r}):null,r===0&&a?t.jsx("span",{className:"ui-badge rail-dot","data-kind":"dot","data-testid":"rail-dot","aria-hidden":"true"}):null]}),t.jsx("span",{className:"rail-label",children:e})]})}const pS={[va]:t.jsx(oe,{name:"files"}),[$n]:t.jsx(oe,{name:"home"}),[da]:t.jsx(oe,{name:"chat"}),[bt]:t.jsx(oe,{name:"agents"}),[At]:t.jsx(oe,{name:"activity"}),[on]:t.jsx(oe,{name:"settings"})},du=e=>`${e.plugin}:${e.id}`,sY=new Set;let Dy=sY,gS=!1;const Ov=new Set;function Dv(e){Dy=e;for(const n of Ov)n()}function rY(e){return Ov.add(e),()=>Ov.delete(e)}const xS=()=>Dy;function aY(){gS||(gS=!0,Promise.resolve().then(()=>A.rail()).then(e=>Dv(new Set(Array.isArray(e==null?void 0:e.hidden)?e.hidden.filter(n=>typeof n=="string"):[]))).catch(()=>{}))}async function iY(e,n){const s=Dy,r=new Set(s);n?r.add(du(e)):r.delete(du(e)),Dv(r);try{await A.setRailHidden(e.plugin,e.id,n)}catch(a){throw Dv(s),a}}function TI(){return d.useEffect(aY,[]),d.useSyncExternalStore(rY,xS,xS)}function lY(e,n){return e.filter(s=>!n.has(du(s)))}function oY(e){return e instanceof HTMLElement?e.isContentEditable?!0:e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT":!1}function cY(e,n=!0,s){d.useEffect(()=>{if(!n)return;const r=a=>{if(a.key!=="/"||a.defaultPrevented||a.ctrlKey||a.metaKey||a.altKey||oY(a.target))return;a.preventDefault();const i=document.getElementById(yv);if(i instanceof HTMLTextAreaElement){!i.disabled&&!i.hidden&&i.focus();return}s?s():e($n)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,n,s])}const RI="buddi.theme";function uY(e=II()){try{const n=e==null?void 0:e.getItem(RI);return n==="light"||n==="dark"||n==="system"?n:"system"}catch{return"system"}}function dY(e,n=II()){try{n==null||n.setItem(RI,e)}catch{}}function hY(e,n=document.documentElement){n&&(e==="system"?n.removeAttribute("data-theme"):n.setAttribute("data-theme",e))}function II(){try{return window.localStorage}catch{return}}const PI="buddi.ground",MI="buddi.pageWidth";function fY(e=LI()){const n=a=>{try{return(e==null?void 0:e.getItem(a))??null}catch{return null}},s=n(PI),r=n(MI);return{theme:uY(e),ground:s==="sand"?"sand":"blue",width:r==="narrow"||r==="full"?r:"wide"}}function OI(e,n=document.documentElement){n&&(hY(e.theme,n),e.ground==="sand"?n.setAttribute("data-ground","sand"):n.removeAttribute("data-ground"),e.width==="wide"?n.removeAttribute("data-width"):n.setAttribute("data-width",e.width))}function mY(e,n=LI()){dY(e.theme,n);try{n==null||n.setItem(PI,e.ground),n==null||n.setItem(MI,e.width)}catch{}}let Kl=null;const Lv=new Set;function Fv(){return Kl||(Kl=fY()),Kl}function pY(e){return Lv.add(e),()=>Lv.delete(e)}function gY(e){Kl={...Fv(),...e},OI(Kl),mY(Kl);for(const n of Lv)n()}function DI(){return[d.useSyncExternalStore(pY,Fv,Fv),gY]}function LI(){try{return window.localStorage}catch{return}}const vS=7,xY=1e4;function vY({timezone:e,embedded:n,agents:s=[],navigate:r}){const{data:a,error:i,reload:l}=ge(()=>A.sentinels(),[],3e4),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),[x,k]=d.useState(!1),[j,v]=d.useState(null),w=a==null?void 0:a.alerts,y=(w==null?void 0:w.open)??[],N=D=>{r?r(D):window.location.hash=D},b=D=>{var P;return D?((P=s.find(K=>K.id===D))==null?void 0:P.name)??null:null},S=async D=>{c(null);try{await D()}catch(P){c(P instanceof he||P instanceof Error?P.message:String(P))}finally{l()}},C=D=>h({...D,id:Date.now()}),T=(D,P,K)=>S(async()=>{const{keys:F}=await A.snoozeAlerts(D,!0,K);C({title:P,undo:()=>A.snoozeAlerts(F,!1)})}),E=D=>S(async()=>{const{id:P}=await A.muteAlert(D.keys[0],D.stop.scope);C({title:"You won’t hear about this again",body:"Turn it back on in Settings → Watchers.",undo:()=>A.unmuteAlert(P)})}),R=D=>S(async()=>{const{agentId:P,conversationId:K}=await A.askAboutAlerts(D.keys);N(at(P,K))}),M=D=>S(async()=>{const[P]=(await A.actOnAlerts([{key:D.key,action:D.index}])).results;if(P!=null&&P.error)throw new Error(P.error);P!=null&&P.approvalId?C({title:"Waiting for your approval",body:"Decide it in Needs you on Home."}):C({title:`${D.label}: done`})}),O=(D,P)=>{P.kind==="open"?N(P.place==="files"?va:P.plugin&&P.page?_r(P.plugin,P.page,P.item):va):P.kind==="ask"?R(D):P.kind==="dismiss"?T(D.keys,"Set aside until it changes"):P.kind==="fill"?m(P):P.confirm?g(P):M(P)},I=()=>{const D=y.flatMap(P=>P.keys);T(D,`Cleared ${y.length} for a week`,vS)},z=w==null?void 0:w.recap,U=jY((z==null?void 0:z.nextAt)??null,e);return t.jsxs(gs,{embedded:n,title:"Alerts",lede:"What needs a decision from you.",children:[t.jsx(ae,{message:i??o}),t.jsxs(Xe,{flush:!0,title:"Needs a decision",tool:y.length>0?String(y.length):void 0,actions:y.length>1?t.jsx($,{size:"sm",variant:"ghost",onClick:I,children:"Clear all"}):void 0,children:[a?y.length===0?t.jsxs("div",{className:"al-empty",children:[t.jsx(oe,{name:"check"}),t.jsxs("div",{children:[t.jsx("p",{className:"al-empty-title",children:"Nothing needs a decision."}),t.jsxs("p",{className:"al-empty-line",children:["Your watchers are quiet. What they notice in passing waits for ",U,"."]})]})]}):t.jsx("ul",{className:"al-list",children:y.map(D=>t.jsx(jS,{group:D,agentName:b(D.agentId),onAct:O,onStop:E,onNotNow:P=>void T(P.keys,"Snoozed for a week",vS)},D.id))}):null,z&&z.count>0?t.jsxs("p",{className:"al-recap","data-testid":"recap-line",children:[t.jsxs("span",{children:[z.count," ",z.count===1?"note":"notes"," saved for ",U]}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>k(!0),children:"Preview"})]}):null]}),w&&(w.snoozed.length>0||w.resolved.length>0)?t.jsxs("p",{className:"al-quiet",children:[w.snoozed.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="snoozed",onClick:()=>v(j==="snoozed"?null:"snoozed"),children:[w.snoozed.length," snoozed"]}):null,w.snoozed.length>0&&w.resolved.length>0?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,w.resolved.length>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":j==="resolved",onClick:()=>v(j==="resolved"?null:"resolved"),children:[w.resolved.length," resolved this week"]}):null]}):null,j==="snoozed"&&w?t.jsx(Xe,{flush:!0,title:"Snoozed",children:t.jsx("ul",{className:"al-list",children:w.snoozed.map(D=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:D.title}),t.jsx("p",{className:"al-sub",children:D.snoozedUntil?`Back ${Ge(D.snoozedUntil)}`:"Until it changes"})]}),t.jsx("div",{className:"al-actions",children:t.jsx($,{size:"sm",onClick:()=>void S(async()=>{await A.snoozeAlerts(D.keys,!1)}),children:"Bring back"})})]},D.id))})}):null,j==="resolved"&&w?t.jsx(Xe,{flush:!0,title:"Resolved this week",children:t.jsx("ul",{className:"al-list",children:w.resolved.map(D=>t.jsx("li",{className:"al-row",children:t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:D.title}),t.jsx("p",{className:"al-sub",children:D.resolvedAt?`Resolved ${Ge(D.resolvedAt)}`:null})]})},D.id))})}):null,x&&z?t.jsxs(Ye,{title:wY(U),onClose:()=>k(!1),children:[t.jsxs("p",{className:"al-form-note",children:["What the watchers noted. buddi reads them out in ",U,"; nothing here needs you now, but you can act on one early."]}),t.jsx("ul",{className:"al-list al-list-sheet",children:z.groups.map(D=>t.jsx(jS,{group:D,agentName:b(D.agentId),recap:!0,onAct:(P,K)=>{K.kind!=="fill"&&k(!1),O(P,K)},onStop:P=>{E(P)}},D.id))})]}):null,f?t.jsx(yY,{action:f,onClose:()=>m(null),onSaved:D=>{m(null),k(!1),C({title:`Saved ${D}`}),l()}}):null,p?t.jsx(Ut,{title:p.label,onClose:()=>g(null),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>g(null),children:"Cancel"}),t.jsx($,{variant:p.tone==="danger"?"danger":"accent",onClick:()=>{const D=p;g(null),M(D)},children:p.label})]}),children:t.jsx("p",{children:p.confirm})}):null,u?t.jsx(iu,{title:u.title,...u.body?{body:u.body}:{},duration:xY,...u.undo?{onUndo:()=>{const D=u.undo;S(async()=>{await D()})}}:{},onGone:()=>h(null)},u.id):null]})}function jY(e,n,s=Date.now()){if(!e)return"the weekly recap";const r=new Date(e);return Number.isNaN(r.getTime())||r.getTime()-s>7*864e5?"the weekly recap":`${new Intl.DateTimeFormat("en",{weekday:"long",timeZone:n}).format(r)}’s recap`}function wY(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ed(e,n){return e.kind==="ask"?e.label??(n?`Ask ${n}`:"Ask about it"):e.label}function jS({group:e,agentName:n,recap:s,onAct:r,onNotNow:a,onStop:i}){const[l,o]=d.useState(!1),[c,u,...h]=e.actions,f=e.actions.some(p=>p.kind==="ask"),m=e.items.length>1;return t.jsxs("li",{className:"al-row","data-urgent":e.urgent&&!s?"true":void 0,children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:e.title}),e.line?t.jsx("p",{className:"al-line",children:e.line}):null,t.jsxs("p",{className:"al-sub",children:[n?t.jsx("span",{children:n}):null,n&&!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,s?null:t.jsxs("span",{children:["noticed ",Ge(e.since)]}),m?t.jsxs(t.Fragment,{children:[n||!s?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(p=>!p),children:l?"Hide":`Show the ${e.items.length}`})]}):null]}),l&&m?t.jsx("ul",{className:"al-items",children:e.items.map(p=>t.jsxs("li",{className:"al-item",children:[p.subject?t.jsx("span",{className:"al-item-who",children:p.subject.label}):null,t.jsx("span",{className:"al-item-note",children:p.subject?p.note:p.line}),p.actions&&p.actions.length>0?t.jsx("span",{className:"al-item-actions",children:p.actions.map((g,x)=>t.jsx($,{size:"sm",variant:g.kind==="run"&&g.tone==="danger"?"danger-ghost":"ghost",onClick:()=>r(e,g),children:Ed(g,n)},x))}):null]},p.key))}):null]}),t.jsxs("div",{className:"al-actions",children:[c?t.jsx($,{size:"sm",variant:"accent",onClick:()=>r(e,c),children:Ed(c,n)}):null,u?t.jsx($,{size:"sm",variant:u.kind==="run"&&u.tone==="danger"?"danger-ghost":void 0,onClick:()=>r(e,u),children:Ed(u,n)}):null,a?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a(e),children:"Not now"}):null,t.jsx("span",{className:"al-more",children:t.jsx(ss,{label:`More for ${e.title}`,sheet:{title:e.title},items:[...h.map(p=>({label:Ed(p,n),...p.kind==="run"&&p.tone==="danger"?{tone:"critical"}:{},onSelect:()=>r(e,p)})),!f&&{label:n?`Ask ${n}`:"Ask about it",onSelect:()=>r(e,{kind:"ask",label:null})},"separator",{label:"Stop telling me this",hint:"Undo in Settings → Watchers",onSelect:()=>i(e)}]})})]})]})}function yY({action:e,onClose:n,onSaved:s}){const r=e.fields.length===1,[a,i]=d.useState(()=>Object.fromEntries(e.fields.map(p=>[p.key,r&&p.value!==null?String(p.value):""]))),[l,o]=d.useState({}),[c,u]=d.useState(!1),[h,f]=d.useState(null),m=async()=>{const p=e.fields.filter(g=>(a[g.key]??"").trim()!=="").map(g=>({key:g.key,action:g.index,value:(a[g.key]??"").trim()}));if(p.length===0){n();return}u(!0),f(null);try{const{results:g}=await A.actOnAlerts(p),x=Object.fromEntries(g.filter(k=>k.error).map(k=>[k.key,k.error]));o(x),Object.keys(x).length===0&&s(p.length)}catch(g){f(g instanceof Error?g.message:String(g))}finally{u(!1)}};return t.jsx(Ye,{title:e.title,onClose:n,foot:t.jsxs("div",{className:"al-form-foot",children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:c,onClick:()=>void m(),children:c?"Saving…":"Save"})]}),children:t.jsxs("div",{className:"al-form",children:[t.jsx(ae,{message:h}),t.jsx("p",{className:"al-form-note",children:r?"Check it and save.":"Type what each is today. Leave the ones you don’t know; they stay as they are."}),t.jsx("div",{className:"al-form-rows",children:e.fields.map(p=>t.jsxs("label",{className:"al-form-row",children:[t.jsxs("span",{className:"al-form-label",children:[t.jsx("span",{children:p.label}),p.hint?t.jsx("span",{className:"al-form-hint",children:p.hint}):null]}),t.jsx("input",{type:p.type==="date"?"date":"text",inputMode:p.type==="number"?"decimal":void 0,value:a[p.key]??"",placeholder:"—","aria-label":p.label,onChange:g=>i(x=>({...x,[p.key]:g.target.value}))}),l[p.key]?t.jsx("span",{className:"al-form-error",children:l[p.key]}):null]},p.key))})]})})}function bY({mutes:e,onChanged:n}){const[s,r]=d.useState(null);return e.length===0?null:t.jsxs(Xe,{flush:!0,title:"Silenced",tool:String(e.length),children:[t.jsx(ae,{message:s}),t.jsx("ul",{className:"al-list",children:e.map(a=>t.jsxs("li",{className:"al-row",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title al-silenced-label",children:a.label}),t.jsxs("p",{className:"al-sub",children:["You said “Stop telling me this” ",Ge(a.createdAt)]})]}),t.jsx("div",{className:"al-actions",children:t.jsx($,{size:"sm",onClick:()=>{r(null),A.unmuteAlert(a.id).then(n,i=>r(i instanceof Error?i.message:String(i)))},children:"Tell me again"})})]},a.id))})]})}const wS=5e3,yS=50;function kY({timezone:e,embedded:n}){var j;const[s,r]=d.useState(""),[a,i]=d.useState(""),[l,o]=d.useState(null),c=ge(()=>A.eventKinds(),[]),{data:u,error:h}=ge(()=>A.events({kind:s||void 0,q:a||void 0,limit:yS}),[s,a],wS),[f,m]=d.useState({events:[],cursor:null,busy:!1,error:null});d.useEffect(()=>{m({events:[],cursor:null,busy:!1,error:null})},[s,a]);const p=f.events.length>0?f.cursor:(u==null?void 0:u.nextCursor)??null,g=async()=>{if(p){m(v=>({...v,busy:!0,error:null}));try{const v=await A.events({kind:s||void 0,q:a||void 0,before:p,limit:yS});m(w=>({events:[...w.events,...v.events],cursor:v.nextCursor,busy:!1,error:null}))}catch(v){m(w=>({...w,busy:!1,error:v instanceof Error?v.message:String(v)}))}}},x=new Set(((u==null?void 0:u.events)??[]).map(v=>v.id)),k=[...(u==null?void 0:u.events)??[],...f.events.filter(v=>!x.has(v.id))];return t.jsxs(gs,{embedded:n,title:"Events",lede:"The append-only log. Everything the installation did, including what you do here.",children:[t.jsxs(ne,{children:[t.jsxs("select",{"aria-label":"Event kind",value:s,onChange:v=>r(v.target.value),children:[t.jsx("option",{value:"",children:"every kind"}),(((j=c.data)==null?void 0:j.kinds)??[]).map(v=>t.jsxs("option",{value:v.kind,children:[v.kind," (",v.count,")"]},v.kind))]}),t.jsx("input",{"aria-label":"Payload contains",placeholder:"payload contains…",value:a,onChange:v=>i(v.target.value),size:28}),s||a?t.jsx($,{onClick:()=>{r(""),i("")},children:"Clear"}):null,t.jsxs("span",{className:"muted",children:["refreshes every ",wS/1e3,"s"]})]}),t.jsx(ae,{message:h}),t.jsx(Xe,{flush:!0,children:!u||k.length===0?t.jsx(Ne,{children:"No events match."}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"#"}),t.jsx("th",{children:"When"}),t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"Payload"})]})}),t.jsx("tbody",{children:k.map(v=>t.jsxs("tr",{"data-clickable":"true",onClick:()=>o(v),children:[t.jsx("td",{className:"mono muted",children:v.id}),t.jsxs("td",{className:"nowrap",children:[mt(v.createdAt,e),t.jsx("div",{className:"sub",children:Ge(v.createdAt)})]}),t.jsx("td",{className:"mono nowrap",children:v.kind}),t.jsx("td",{className:"mono muted",children:fr(Cs(v.payload).replace(/\s+/g," "),120)})]},v.id))})]})}),p||f.error?t.jsxs(ne,{children:[t.jsxs("span",{className:"muted",children:[k.length," shown",p?", older ones are kept":"","."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),f.error?t.jsx("span",{className:"critical",children:f.error}):null,p?t.jsx($,{disabled:f.busy,onClick:()=>void g(),children:f.busy?"Loading…":"Load older"}):null]}):null,l?t.jsxs(Ye,{title:l.kind,onClose:()=>o(null),children:[t.jsxs("p",{className:"muted",children:["Event ",l.id," · ",mt(l.createdAt,e),l.conversationId?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:`#/conversations/${l.conversationId}`,children:"conversation"})]}):null]}),t.jsx(zt,{children:Cs(l.payload)})]}):null]})}const bS=["pending","leased","suspended","failed","succeeded","cancelled"],Jo=50,NY=1e4,SY=(e,n,s=`${n}s`)=>e===1?n:s;function CY({timezone:e,embedded:n,initialState:s}){var F,Q;const[r,a]=d.useState(s??""),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=r==="failed",{data:g,error:x,reload:k}=ge(()=>A.jobs({...r?{state:r}:{},...r?{}:{dismissed:"0"},limit:String(Jo)}),[r],1e4),j=ge(()=>A.jobFailures(),[],1e4),[v,w]=d.useState({jobs:[],done:!1,busy:!1});d.useEffect(()=>{w({jobs:[],done:!1,busy:!1})},[r]);const y=async()=>{w(_=>({..._,busy:!0}));try{const _=await A.jobs({...r?{state:r}:{dismissed:"0"},limit:String(Jo),offset:String(Jo+v.jobs.length)});w(re=>({jobs:[...re.jobs,..._.jobs],done:_.jobs.length<Jo,busy:!1}))}catch(_){c(_ instanceof Error?_.message:String(_)),w(re=>({...re,busy:!1}))}},N=new Set(((g==null?void 0:g.jobs)??[]).map(_=>_.id)),b=[...(g==null?void 0:g.jobs)??[],...v.jobs.filter(_=>!N.has(_.id))],S=(g==null?void 0:g.counts)??{},C=r?S[r]??0:bS.reduce((_,re)=>_+(S[re]??0),0),T=!v.done&&b.length<C&&((g==null?void 0:g.jobs.length)??0)>=Jo,E=((F=j.data)==null?void 0:F.open)??[],R=((Q=j.data)==null?void 0:Q.dismissed)??[],M=E.reduce((_,re)=>_+re.count,0),O=R.reduce((_,re)=>_+re.count,0),I=()=>{k(),j.reload()},z=_=>h({..._,id:Date.now()}),U=async _=>{c(null);try{await _()}catch(re){c(re instanceof Error?re.message:String(re))}finally{I()}},D=async _=>{await U(async()=>{await _,l(null)})},P=_=>U(async()=>{const{ids:re}=await A.dismissJobs(_==="all"?{all:!0}:{ids:_});re.length!==0&&z({title:`Dismissed ${re.length===1?"it":re.length}`,body:"Kept under Dismissed, below.",undo:()=>A.undismissJobs(re)})}),K=(_,re)=>U(async()=>{const{jobs:Y}=await A.retryJobs({ids:_});if(Y.length===0)return;const B=Y.length===1;z({title:`Retrying ${B?"it":Y.length}`,body:re?`${B?"It runs":"They run"} as soon as a worker is free.`:`If what broke ${B?"it":"them"} hasn’t changed, ${B?"it":"they"} will fail the same way.`})});return t.jsxs(gs,{embedded:n,title:"Jobs",lede:`${g!=null&&g.paused?"Paused: nothing is being claimed. ":""}Bounded retries with backoff; past the budget a job waits for you.`,actions:n?void 0:t.jsx($,{size:"sm",variant:g!=null&&g.paused?"accent":void 0,onClick:()=>D(A.setPaused(!((g==null?void 0:g.paused)??!1))),children:g!=null&&g.paused?"Resume the queue":"Pause the queue"}),children:[t.jsx(ae,{message:x??j.error??o}),E.length>0?t.jsxs(Xe,{flush:!0,title:"Gave up",tool:String(M),actions:M>1?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>void P("all"),children:"Dismiss all"}):void 0,children:[t.jsx("ul",{className:"al-list",children:E.map(_=>t.jsx(NS,{group:_,timezone:e,onOpen:l,onRetry:re=>void K(re,_.likelyFixed),onDismiss:re=>void P(re)},_.key))}),t.jsx("p",{className:"al-recap",children:t.jsx("span",{children:"These will not run again on their own. Dismissed jobs stay on record; any failed job older than 14 days is dismissed for you."})})]}):p&&j.data?t.jsx(Xe,{flush:!0,children:t.jsxs("div",{className:"al-empty",children:[t.jsx(oe,{name:"check"}),t.jsxs("div",{children:[t.jsx("p",{className:"al-empty-title",children:"No failed job needs you."}),t.jsx("p",{className:"al-empty-line",children:O>0?"The ones you dismissed stay on record, below.":"Every job either ran or is still on its way."})]})]})}):null,O>0||p?t.jsxs("p",{className:"al-quiet jb-quiet",children:[O>0?t.jsxs("button",{type:"button",className:"wb-link","aria-expanded":f,onClick:()=>m(_=>!_),children:[O," dismissed"]}):null,O>0&&p?t.jsx("span",{"aria-hidden":"true",children:"·"}):null,p?t.jsx("button",{type:"button",className:"wb-link",onClick:()=>a(""),children:"Show the whole queue"}):null]}):null,f&&R.length>0?t.jsx(Xe,{flush:!0,title:"Dismissed",children:t.jsx("ul",{className:"al-list",children:R.map(_=>t.jsx(NS,{group:_,timezone:e,dismissed:!0,onOpen:l,onRetry:re=>void K(re,_.likelyFixed)},_.key))})}):null,p?null:t.jsx(Xe,{flush:!0,title:"Queue",actions:t.jsxs("select",{"aria-label":"Job state",value:r,onChange:_=>a(_.target.value),children:[t.jsx("option",{value:"",children:"every state"}),bS.map(_=>t.jsxs("option",{value:_,children:[_," (",S[_]??0,")"]},_))]}),children:!g||b.length===0?t.jsx(Ne,{children:"No jobs match."}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"State"}),t.jsx("th",{className:"num",children:"Attempts"}),t.jsx("th",{children:"Last error"}),t.jsx("th",{children:"Updated"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:b.map(_=>t.jsxs("tr",{children:[t.jsxs("td",{className:"clickable",onClick:()=>l(_),children:[_.kind,t.jsx("div",{className:"sub mono",children:qc(_.id)})]}),t.jsxs("td",{children:[t.jsx(Ru,{state:_.state}),_.suspendedReason?t.jsx("div",{className:"sub",children:fr(_.suspendedReason,40)}):null,_.acknowledgedAt?t.jsx("div",{className:"sub",children:"dismissed"}):null]}),t.jsxs("td",{className:"num",children:[_.attempts,"/",_.maxAttempts]}),t.jsx("td",{className:_.lastError?"critical":"muted",children:_.lastError?fr(_.lastError,80):"—"}),t.jsxs("td",{className:"nowrap",children:[mt(_.updatedAt,e),t.jsx("div",{className:"sub",children:Ge(_.updatedAt)})]}),t.jsx("td",{children:t.jsxs(ne,{align:"end",children:[["failed","cancelled","suspended"].includes(_.state)?t.jsx($,{size:"sm",onClick:()=>D(A.retryJob(_.id)),children:"Retry"}):null,["pending","leased","suspended","failed"].includes(_.state)?t.jsx($,{size:"sm",variant:"danger",onClick:()=>D(A.cancelJob(_.id)),children:"Cancel"}):null]})})]},_.id))})]})}),T&&!p?t.jsxs(ne,{children:[t.jsxs("span",{className:"muted",children:[b.length," of ",C," shown."]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{disabled:v.busy,onClick:()=>void y(),children:v.busy?"Loading…":"Load older"})]}):null,i?t.jsxs(Ye,{title:i.kind,onClose:()=>l(null),children:[t.jsx("p",{className:"muted mono",children:i.id}),i.lastError?t.jsx(pe,{title:"Last error",children:t.jsx(zt,{children:i.lastError})}):null,t.jsx(pe,{title:"Payload",children:t.jsx(zt,{children:Cs(i.payload)})}),t.jsx(pe,{title:"Result",children:t.jsx(zt,{children:Cs(i.result)})}),i.conversationId?t.jsx("p",{children:t.jsx("a",{href:`#/conversations/${i.conversationId}`,children:"open the transcript"})}):null]}):null,u?t.jsx(iu,{title:u.title,...u.body?{body:u.body}:{},duration:NY,...u.undo?{onUndo:()=>{const _=u.undo;U(async()=>{await _()})}}:{},onGone:()=>h(null)},u.id):null]})}function kS(e){var s;if(e.missionName)return e.missionName;const n=(s=e.job.payload)==null?void 0:s.prompt;return typeof n=="string"&&n.trim()!==""?fr(n.trim().split(`
|
|
124
|
-
`)[0],48):e.job.kind==="agent-run"?"Agent run":e.job.kind}function NS({group:e,timezone:n,dismissed:s,onOpen:r,onRetry:a,onDismiss:i}){var g;const[l,o]=d.useState(!1),c=e.jobs.length>1,u=e.jobs.map(x=>x.job.id),h=e.agents.map(x=>x.name??x.id),f=e.jobs[0],m=e.jobs.every(x=>x.job.acknowledgedBy==="auto"),p=s?m?"dismissed on its own after 14 days":`dismissed ${Ge(((g=e.jobs[0])==null?void 0:g.job.acknowledgedAt)??e.lastAt)}`:`gave up ${Ge(e.lastAt)}`;return t.jsxs("li",{className:"al-row","data-urgent":s?void 0:"true",children:[t.jsxs("div",{className:"al-main",children:[t.jsx("p",{className:"al-title",children:c?`${e.label} · ${e.count}`:e.label}),s?null:t.jsx("p",{className:"al-line",children:e.reason}),t.jsxs("p",{className:"al-sub",children:[h.length>0?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:h.join(", ")}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,!c&&f?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(f.job),children:kS(f)}),t.jsx("span",{"aria-hidden":"true",children:"·"})]}):null,t.jsx("span",{title:mt(e.lastAt,n),children:p}),c?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link al-toggle","aria-expanded":l,onClick:()=>o(x=>!x),children:l?"Hide":`Show the ${e.count}`})]}):null]}),l&&c?t.jsx("ul",{className:"al-items",children:e.jobs.map(x=>t.jsxs("li",{className:"al-item jb-item",children:[x.agentName||x.agentId?t.jsx("span",{className:"al-item-who",children:x.agentName??x.agentId}):null,t.jsxs("span",{className:"al-item-note",children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>r(x.job),children:kS(x)})," · ",pw(new Date(x.job.updatedAt),n)," · tried ",x.job.attempts," ",SY(x.job.attempts,"time")]}),t.jsxs("span",{className:"jb-item-acts",children:[t.jsx("button",{type:"button",className:"wb-link",onClick:()=>a([x.job.id]),children:"Retry"}),i?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("button",{type:"button",className:"wb-link",onClick:()=>i([x.job.id]),children:"Dismiss"})]}):null]})]},x.job.id))}):null]}),t.jsxs("div",{className:"al-actions",children:[t.jsx($,{size:"sm",variant:e.likelyFixed&&!s?"accent":void 0,onClick:()=>a(u),children:c?"Retry all":"Retry"}),i?t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(u),children:"Dismiss"}):null]})]})}const EY=[{id:"conversations",label:"Conversations"},{id:"jobs",label:"Jobs"},{id:"approvals",label:"Approvals"},{id:"alerts",label:"Alerts"},{id:"events",label:"Events"}];function $Y({hash:e,timezone:n,navigate:s,agents:r}){var u,h;const a=/^#\/activity\/conversations\/(.+)$/.exec(e),i=f=>{var m;return((m=r.find(p=>p.id===f))==null?void 0:m.name)??f};if(a){let f=a[1];try{f=decodeURIComponent(f)}catch{}return t.jsx(RY,{id:f,timezone:n,navigate:s,nameOf:i})}const l=((u=/^#\/activity\/([a-z]+)/.exec(e))==null?void 0:u[1])??"conversations",o=(h=/[?&]state=([a-z]+)/.exec(e))==null?void 0:h[1],c=f=>m=>{m.preventDefault(),s(f)};return t.jsxs("div",{className:"ui-page",children:[t.jsx(Pi,{title:"Activity",lede:"Everything your agents ran, newest first.",actions:t.jsx(MY,{})}),t.jsx(OY,{}),t.jsx(Co,{children:EY.map(f=>{const m=f.id==="conversations"?At:`${At}/${f.id}`;return t.jsx(Ki,{href:m,active:l===f.id,onClick:c(m),children:f.label},f.id)})}),l==="conversations"?t.jsx(AY,{timezone:n,navigate:s,nameOf:i,agents:r}):null,l==="jobs"?t.jsx(CY,{timezone:n,embedded:!0,initialState:o},o??""):null,l==="approvals"?t.jsx(TY,{timezone:n,nameOf:i}):null,l==="alerts"?t.jsx(vY,{timezone:n,embedded:!0,agents:r,navigate:s}):null,l==="events"?t.jsx(kY,{timezone:n,embedded:!0}):null]})}function AY({timezone:e,navigate:n,nameOf:s,agents:r}){const{data:a,error:i}=ge(()=>A.conversations(),[],3e4);return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:i}),t.jsx(Xe,{flush:!0,children:a?a.conversations.length===0?t.jsx(es,{icon:"activity",title:"Nothing has run yet",children:"Conversations and runs show up here as your agents work."}):t.jsx(ct,{children:a.conversations.map(l=>t.jsx(rt,{href:Zc(l.id),onClick:()=>n(Zc(l.id)),lead:t.jsx(jn,{agents:r,id:l.agentId,size:"sm"}),title:l.opening?fr(l.opening,100):"Untitled conversation",sub:`${s(l.agentId)}, ${l.messageCount} message${l.messageCount===1?"":"s"}, ${l.runs} run${l.runs===1?"":"s"}, ${L_(l.usage)}`,side:t.jsx("span",{title:mt(l.lastMessageAt??l.createdAt,e),children:Ge(l.lastMessageAt??l.createdAt)})},l.id))}):t.jsx(Ne,{children:"Loading…"})})]})}function TY({timezone:e,nameOf:n}){const{data:s,error:r}=ge(()=>A.approvals(),[],1e4),a=[...(s==null?void 0:s.pending)??[],...(s==null?void 0:s.recent)??[]];return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:r}),t.jsx(Xe,{flush:!0,children:s?a.length===0?t.jsx(es,{icon:"bell",title:"No approvals yet",children:"When an agent asks before acting, the request and your answer are kept here."}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Tool"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Asked by"}),t.jsx("th",{children:"Decided"}),t.jsx("th",{children:"Created"})]})}),t.jsx("tbody",{children:a.map(i=>t.jsxs("tr",{children:[t.jsxs("td",{children:[i.tool,t.jsx("div",{className:"sub mono",children:qc(i.id)})]}),t.jsx("td",{children:t.jsx(Ru,{state:i.state})}),t.jsx("td",{children:n(i.agentId)}),t.jsx("td",{className:"nowrap",children:i.decidedAt?t.jsxs(t.Fragment,{children:[mt(i.decidedAt,e),t.jsxs("div",{className:"sub",children:["via ",i.decidedVia??"—"]})]}):t.jsx("span",{className:"muted",children:"—"})}),t.jsxs("td",{className:"nowrap",children:[mt(i.createdAt,e),t.jsx("div",{className:"sub",children:Ge(i.createdAt)})]})]},i.id))})]}):t.jsx(Ne,{children:"Loading…"})})]})}function RY({id:e,timezone:n,navigate:s,nameOf:r}){const[a,i]=d.useState(null),[l,o]=d.useState(null);d.useEffect(()=>{let u=!1;return A.conversation(e).then(h=>{u||i(h)}).catch(h=>{u||o(h instanceof Error?h.message:String(h))}),()=>{u=!0}},[e]);const c=u=>h=>{h.preventDefault(),s(u)};return t.jsxs("div",{className:"ui-page",children:[t.jsx("p",{className:"page-crumbs",children:t.jsx("a",{href:At,onClick:c(At),children:"Activity"})}),t.jsxs("header",{className:"ui-page-head",children:[t.jsxs("div",{className:"ui-page-head-row",children:[t.jsxs("h2",{className:"ui-page-title",children:[t.jsx($,{size:"sm",onClick:()=>s(At),children:"← Back"}),t.jsx("span",{children:"Transcript"})]}),a?t.jsx("div",{className:"ui-page-actions",children:t.jsx(lt,{size:"sm",href:at(a.agentId,e),onClick:c(at(a.agentId,e)),children:"Open in chat"})}):null]}),t.jsx("p",{className:"ui-page-lede mono",children:e})]}),t.jsx(ae,{message:l}),a?t.jsxs(t.Fragment,{children:[t.jsxs(dm,{children:[t.jsx(Tr,{label:"Agent",value:r(a.agentId),size:"sm"}),t.jsx(Tr,{label:"Runs",value:a.runs.length}),t.jsx(Tr,{label:"Tokens",value:`${xn(a.usage.input)} / ${xn(a.usage.output)}`,note:Nx(a.usage)?`input / output, ${Nx(a.usage)}`:"input / output"}),t.jsx(Tr,{label:"Started",value:mt(a.createdAt,n),size:"sm"})]}),a.runs.length>0?t.jsx(Xe,{title:"Runs",flush:!0,children:t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Started"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{className:"num",children:"Turns"}),t.jsx("th",{children:"Stopped"}),t.jsx("th",{className:"num",children:"Tokens"}),t.jsx("th",{className:"num",children:"Cached"})]})}),t.jsx("tbody",{children:a.runs.map((u,h)=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[mt(u.startedAt,n)," ",u.resumed?t.jsx(Ae,{children:"resumed"}):null]}),t.jsx("td",{className:"nowrap",children:mt(u.finishedAt,n)}),t.jsx("td",{className:"num",children:u.turns??"—"}),t.jsxs("td",{children:[u.stopped??"—",u.actionId?t.jsxs("div",{className:"sub mono",children:["action ",qc(u.actionId)]}):null]}),t.jsxs("td",{className:"num muted nowrap",children:[xn(u.usage.input)," / ",xn(u.usage.output)]}),t.jsx("td",{className:"num muted nowrap",children:u.usage.cacheRead||u.usage.cacheWrite?xn((u.usage.cacheRead??0)+(u.usage.cacheWrite??0)):"—"})]},h))})]})}):null,t.jsx(pe,{title:"Messages",children:t.jsx(ue,{children:a.messages.map(u=>t.jsxs("article",{className:"transcript-msg",children:[t.jsxs("header",{className:"transcript-who",children:[u.speaker===SS?"approved action, result":u.role,", ",mt(u.createdAt,n)]}),t.jsxs("div",{className:"transcript-body",children:[u.blocks.length===0?t.jsx("span",{className:"muted",children:"(empty)"}):null,u.speaker===SS?u.blocks.map((h,f)=>t.jsx(IY,{block:h},f)):u.blocks.map((h,f)=>t.jsx(PY,{block:h},f))]})]},u.id))})})]}):t.jsx(Ne,{children:"Loading…"})]})}const SS="approval:resume";function IY({block:e}){return t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:"← approved action"}),t.jsx(zt,{children:e.type==="text"?e.text??"":Cs(e)})]})}function PY({block:e}){return e.type==="text"?t.jsx("div",{className:"transcript-text",children:t.jsx(pr,{text:e.text??""})}):e.type==="thinking"?t.jsxs("details",{className:"transcript-thinking",children:[t.jsx("summary",{children:"Thoughts"}),t.jsx("div",{className:"transcript-thinking-text",children:t.jsx(pr,{text:e.text??""})})]}):e.type==="thinking_hidden"?t.jsx("div",{className:"transcript-thinking-hidden",children:"Thinking (hidden)"}):e.ref===void 0&&e.type==="provider_native"?t.jsx(t.Fragment,{}):e.type==="tool_use"?t.jsxs("div",{className:"transcript-tool",children:[t.jsxs("div",{className:"transcript-tool-name mono",children:["→ ",e.name]}),t.jsx(zt,{children:Cs(e.input)})]}):e.type==="tool_result"?t.jsxs("div",{className:"transcript-tool","data-tone":e.isError?"critical":void 0,children:[t.jsxs("div",{className:"transcript-tool-name mono",children:["← ",e.isError?"error":"result"]}),t.jsx(zt,{children:e.content??""})]}):t.jsxs("div",{className:"transcript-tool",children:[t.jsx("div",{className:"transcript-tool-name mono",children:e.type}),t.jsx(zt,{children:Cs(e.ref)})]})}function MY(){const{data:e,reload:n}=ge(()=>A.overview(),[],1e4),[s,r]=d.useState(!1);if(!e)return null;const a=()=>{r(!0),A.setPaused(!e.paused).then(n,n).finally(()=>r(!1))};return t.jsx($,{size:"sm",variant:e.paused?"accent":void 0,disabled:s,onClick:a,children:e.paused?"Resume all":"Pause all"})}function OY(){const{data:e,reload:n}=ge(()=>A.overview(),[],1e4);if(d.useEffect(()=>(window.addEventListener($i,n),()=>window.removeEventListener($i,n)),[n]),!e)return null;const s=a=>e.jobs[a]??0,r=s("leased");return t.jsxs(dm,{children:[t.jsx(Tr,{label:"Jobs done",value:xn(s("succeeded"))}),t.jsx(Tr,{label:"Failed",value:xn(s("failed")),...s("failed")>0?{tone:"critical"}:{}}),t.jsx(Tr,{label:"Queued",value:xn(s("pending")),note:`${r} running`}),t.jsx(Tr,{label:"Approvals",value:xn(e.approvals.pending),note:"waiting for you"})]})}const DY=["replay-all","coalesce","latest-only","skip-after-deadline"];function FI({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=ge(()=>A.missions(),[],3e4),l=((r==null?void 0:r.missions)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await h,i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(gs,{embedded:n,title:"Missions",lede:"Standing schedules. A disabled mission materializes nothing.",children:[t.jsx(ae,{message:a??o}),!r||l.length===0?t.jsxs(es,{icon:"calendar",title:"No missions yet",children:["Run ",t.jsx("code",{children:"buddi missions add-defaults"})," for the standard set."]}):t.jsx(ue,{children:l.map(h=>t.jsx(LY,{mission:h,timezone:e,onRun:u},h.id))})]})}function LY({mission:e,timezone:n,onRun:s}){const[r,a]=d.useState(!1);return t.jsxs(Ps,{tone:e.enabled&&!e.pausedReason?"good":"muted",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"mono muted",children:e.id})]}),meta:t.jsxs(t.Fragment,{children:[t.jsx(Ae,{mono:!0,children:e.agentId}),e.alwaysDeliver?t.jsx(Ae,{children:"always delivers"}):null,e.enabled?null:t.jsx(Ae,{tone:"warning",children:e.endedAt?"ended":"disabled"}),e.pausedReason?t.jsx(Ae,{tone:"warning",children:e.pausedReason}):null]}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",onClick:()=>s(A.setMissionEnabled(e.id,!e.enabled)),children:e.enabled?"Disable":"Enable"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a(i=>!i),"aria-expanded":r,children:r?"Less":"More"})]}),children:[e.stillUsefulAskedAt?t.jsx(G,{tone:"warning",title:"Still useful?",action:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",onClick:()=>s(A.answerStillUseful(e.id,"stop")),children:"Stop"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>s(A.keepMission(e.id)),children:"Keep"})]}),children:`It has run ${e.quietRuns??"many"} times in a row without anything to tell you.`}):null,e.stopWhen||e.endsAt?t.jsxs("p",{className:"ui-card-meta",children:[e.stopWhen?`Stops itself when ${e.stopWhen}. `:"",e.endedAt?`Ended ${mt(e.endedAt,n)}.`:e.endsAt?`Ends ${mt(e.endsAt,n)}.`:""]}):null,t.jsxs("p",{className:"ui-card-meta",children:[e.schedule?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:e.schedule.cron})," ",e.schedule.timezoneExplicit===!1?t.jsx("span",{title:e.schedule.timezone,children:"follows your timezone"}):e.schedule.timezone," ","· rev"," ",e.schedule.revision," · next"," ",e.nextRun?`${mt(e.nextRun,n)} (${Ge(e.nextRun)})`:"—"]}):"no schedule — enqueued by hand or by a sentinel",t.jsx("br",{}),"Last notification:"," ",e.lastNotification?`${e.lastNotification.kind==="mission.delivered"?"delivered":"silent"} ${Ge(e.lastNotification.at)}${e.lastNotification.reason?` — ${e.lastNotification.reason}`:""}`:"none"]}),r?t.jsxs("div",{className:"ui-card-foot",children:[e.schedule?t.jsxs(ne,{children:[t.jsx(ie,{inline:!0,label:"Misfire policy",children:t.jsx("select",{value:e.schedule.misfirePolicy,onChange:i=>s(A.setMisfirePolicy(e.id,i.target.value)),children:DY.map(i=>t.jsx("option",{value:i,children:i},i))})}),t.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,t.jsx(pe,{title:"Prompt",children:t.jsx(zt,{children:e.prompt})}),t.jsx(pe,{title:"Recent occurrences",children:t.jsx(Xe,{flush:!0,children:e.occurrences.length===0?t.jsx(Ne,{children:"Never run."}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Scheduled"}),t.jsx("th",{children:"State"}),t.jsx("th",{children:"Finished"}),t.jsx("th",{children:"Detail"})]})}),t.jsx("tbody",{children:e.occurrences.map(i=>t.jsxs("tr",{children:[t.jsx("td",{className:"nowrap",children:mt(i.scheduledAt,n)}),t.jsx("td",{children:t.jsx(Ru,{state:i.state})}),t.jsx("td",{className:"nowrap",children:mt(i.finishedAt,n)}),t.jsxs("td",{className:i.error?"critical":"muted",children:[i.error?fr(i.error,120):null,i.runConversationId?t.jsx("a",{href:`#/conversations/${i.runConversationId}`,children:"transcript"}):null]})]},i.id))})]})})})]}):null]})}function FY(e,n){const s=`${e} offer${e===1?"":"s"}`,r=n?` from ${n}`:"";return`Dismiss ${s}${r}? They stop appearing everywhere. Nothing runs, and you can still see them under "Dismissed and lapsed" for a week.`}function _I({ids:e,agentName:n,onDone:s}){const r=e.length,[a,i]=d.useState(!1),[l,o]=d.useState(!1);return r<=0?null:a?t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:FY(r,n)}),t.jsx($,{size:"sm",variant:"danger",disabled:l,onClick:()=>{o(!0),A.dismissOffers(e).then(()=>{i(!1),s()}).finally(()=>o(!1))},children:`Dismiss ${r}`}),t.jsx($,{size:"sm",variant:"ghost",disabled:l,onClick:()=>i(!1),children:"Keep them"})]}):t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(!0),children:"Dismiss all"})}function zI({embedded:e,agentId:n,agentName:s}){const{data:r,error:a,reload:i}=ge(()=>A.offers(),[],2e4),l=j=>!n||j.agentId===n,o=((r==null?void 0:r.offers)??[]).filter(l),c=((r==null?void 0:r.closed)??[]).filter(l),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(null),x=async(j,v)=>{h(null),m(j);try{const w=await A.takeOffer(j);g(w.jobId?`On it — ${v}. Started as job ${w.jobId}.`:`Taken — ${v}. No worker is running here, so nothing has started yet.`),i()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}},k=async(j,v)=>{h(null),m(j);try{await A.dismissOffer(j),g(`Dismissed — ${v}. It will not come back.`),i()}catch(w){h(w instanceof Error?w.message:String(w))}finally{m(null)}};return t.jsxs(gs,{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:[t.jsx(ae,{message:a??u}),p?t.jsx(G,{tone:"good",role:"status",children:p}):null,o.length>0?t.jsxs(ne,{children:[t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx(_I,{ids:o.map(j=>j.id),agentName:s,onDone:()=>{g(null),i()}})]}):null,!r||o.length===0?t.jsx(es,{icon:"bulb",title:"Nothing on offer",children:"When an agent works out something you might want done, it waits here."}):t.jsx(ue,{children:o.map(j=>t.jsx(Ps,{tone:"accent",title:j.label,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ae,{mono:!0,children:j.agentId}),t.jsxs("span",{className:"muted",children:["expires ",Ge(j.expiresAt)]})]}),actions:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"ghost",disabled:f===j.id,onClick:()=>void k(j.id,j.label),children:"Not now"}),t.jsx($,{variant:"accent",size:"sm",disabled:f===j.id,onClick:()=>void x(j.id,j.label),children:"Take"})]}),children:t.jsx("p",{className:"ui-card-meta",children:j.prompt})},j.id))}),c.length>0?t.jsxs(Zt,{summary:`Dismissed and lapsed (${c.length})`,boxed:!0,children:[t.jsx(Xe,{flush:!0,children:t.jsx(ct,{children:c.map(j=>t.jsx(rt,{title:j.label,sub:`${j.agentId} — ${U_(j)}`,side:Ge(j.dismissedAt??j.lapsedAt??j.createdAt)},j.id))})}),t.jsx("p",{className:"muted",children:"These stop being shown a week after they closed."})]}):null]})}const _Y={work:"Work",money:"Money",home:"Home",health:"Health",learning:"Learning",life:"Life"},Ly=e=>_Y[e]??km(e);function km(e){return e.charAt(0).toUpperCase()+e.slice(1)}function dn(e){return e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function io(e){return e.replace(/\.0$/,"")}function zY(e){return e.avatar?A.marketAssetUrl(e.avatar):void 0}const UY={mailbox:{title:"your mailbox",fix:"Add a mailbox",route:mr("email","settings")},"image-account":{title:"a drawing account",fix:"Choose a drawing account",route:mr("image","settings")}};function Fy(e){return UY[e.replace(/\?$/,"")]??{title:e,fix:"Set it up",route:Fe()}}const Nm=e=>km(e);function _y(e){return e.kind==="plugin"?e.title:Fy(e.name).title}function tf(e){if(e.kind==="need"){const n=Fy(e.name);return{label:n.fix,route:n.route}}return e.fix==="enable"?{label:`Turn on ${e.title}`,route:Fe("plugins")}:e.fix==="update"?{label:`Update ${e.title}`,route:Fe("plugins")}:e.byBuddi?null:{label:`Install ${e.title}`,route:Fe("plugins")}}function BY(e,n,s){const r=new Set((e.missing??[]).map(o=>o.name)),i=[...Object.keys(e.requires),...Object.keys(e.optional)].filter(o=>!r.has(o)&&n.has(o)).map(Nm),l=e.needs.includes("mailbox")||e.needs.includes("mailbox?");return s===!0&&l&&!r.has("mailbox")&&i.push("your mailbox"),i}function Qp(e){return km(e.replace(/\.md$/i,"").replace(/[-_]+/g," ").trim())}const CS=(e,n)=>e.includes(n),WY={email:{title:"Mail",line:e=>CS(e,"email.draft")||CS(e,"email.*")?"Reads and searches your mail. Writes drafts; you send them.":"Searches and reads your mail."},calendar:{title:"Calendar",line:()=>"Reads your calendars. Never adds or moves an event."},weather:{title:"Weather",line:()=>"Reads the forecast for your places."},reminder:{title:"Reminders",line:e=>e.some(n=>n.startsWith("schedule."))?"Sets reminders and runs its own missions.":"Sets reminders."},memory:{title:"Memory",line:()=>"Remembers what you tell it. You can read every note."},owner:{title:"You",line:()=>"Messages you when something needs you."},web:{title:"Web",line:()=>"Searches and reads web pages."},artifacts:{title:"Files",line:()=>"Reads what you share in Files."},finance:{title:"Finance",line:()=>"Reads your accounts, cards, loans and statements."},image:{title:"Image",line:()=>"Makes pictures with your drawing account."},speech:{title:"Speech",line:()=>"Says words out loud."},goal:{title:"Goals",line:()=>"Keeps your goals and progress."},canvas:{title:"Canvas",line:()=>"Draws on the canvas beside your chat."}},HY={schedule:"reminder",browser:"web"};function nf(e,n=new Map){const s=[],r=new Map;for(const a of e){const i=a.replace(/\?$/,""),l=i.split(".")[0]??i,o=HY[l]??l;r.has(o)||(r.set(o,[]),s.push(o)),r.get(o).push(i)}return s.map(a=>{const i=r.get(a),l=WY[a],o=i.some(u=>n.get(u)==="gated"||u.endsWith(".*")&&[...n].some(([h,f])=>f==="gated"&&h.startsWith(u.slice(0,-1)))),c=l?l.line(i):`${i.length===1?"One of its tools":`${i.length} of its tools`}.`;return[(l==null?void 0:l.title)??km(a),o&&!/asks you/i.test(c)?`${c} Asks you first before it changes anything.`:c]})}function ES(e){return e.length===0?"Nothing beyond its own chat.":`Reaches ${dn(e.map(([n])=>n))}.`}function sf(e){return new Map((e??[]).filter(n=>n.tier).map(n=>[n.name,n.tier]))}function rl({entry:e,size:n}){const s=zY(e);return t.jsx("span",{className:"cat-face","data-size":n,children:t.jsx(On,{id:e.name,name:e.title,size:n==="xxl"?"xl":n,face:{tools:e.tools,...s?{picture:s}:{}}})})}const UI=800,KY=e=>{var n;return((n=/^.*?[.!?](?=\s|$)/.exec(e.trim()))==null?void 0:n[0])??e.trim()},Vl=e=>e instanceof he?e.message:String(e);function ra({entry:e,children:n}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(rl,{entry:e,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsx("span",{children:n}),t.jsxs("span",{className:"plugins-sheet-by",children:["by ",e.author.name,e.trust==="by-buddi"?t.jsxs(t.Fragment,{children:[" · ",t.jsx(Ae,{tone:"accent",children:"by buddi"})]}):null]})]})]})}function Jp({state:e,children:n}){return t.jsxs("li",{className:"cat-step","data-state":e,children:[t.jsx("span",{className:"cat-step-mark",children:e==="done"?t.jsx(oe,{name:"check",size:12}):e==="failed"?t.jsx(oe,{name:"alert",size:14}):null}),t.jsx("span",{children:n})]})}function Xp(e){const n=e.kind==="plugin"?["Installing","Installed"]:["Adding","Added"];return e.state==="done"?{state:"done",words:`${n[1]} ${e.title}`}:e.state==="failed"?{state:"failed",words:e.kind==="plugin"?`${e.title} didn’t install`:`${e.title} wasn’t added`}:e.state==="waiting"?{state:"next",words:`${n[0]} ${e.title}`}:{state:"now",words:`${n[0]} ${e.title}…`}}function VY(e){const[n,s]=d.useState(null),[r,a]=d.useState(null);return d.useEffect(()=>{if(s(null),a(null),!e)return;let i=!1,l;const o=()=>{A.catalogueJob(e).then(c=>{i||(s(c),c.state==="running"&&(l=window.setTimeout(o,UI)))}).catch(c=>{i||a(Vl(c))})};return o(),()=>{i=!0,l!==void 0&&window.clearTimeout(l)}},[e]),{job:n,error:r,setJob:s}}function BI({entry:e,navigate:n,onClose:s,onAdded:r}){var Oe;const a=fs("(max-width: 720px)"),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState({}),[f,m]=d.useState(""),[p,g]=d.useState([]),[x,k]=d.useState(!1),[j,v]=d.useState(null),[w,y]=d.useState(!1),[N,b]=d.useState(null),{job:S,error:C,setJob:T}=VY(j),[E,R]=d.useState(!1),[M,O]=d.useState(null),[I,z]=d.useState(!1),U=d.useRef(!1),[D,P]=d.useState([]);d.useEffect(()=>{if(!i||i.plugins.length===0)return;let W=!1;return Promise.resolve().then(()=>A.market()).then(se=>{W||P((se==null?void 0:se.plugins)??[])}).catch(()=>{}),()=>{W=!0}},[i]),d.useEffect(()=>{let W=!1;return A.cataloguePlan(e.name).then(se=>{W||(l(se),h(Object.fromEntries(se.fills.map(X=>[X.id,X.value]))),m(se.handle))}).catch(se=>{W||c(Vl(se))}),()=>{W=!0}},[e.name]),d.useEffect(()=>{(S==null?void 0:S.state)==="done"&&S.agent&&!U.current&&(U.current=!0,r==null||r(S.agent))},[S,r]);const K=()=>{i&&(y(!0),b(null),U.current=!1,A.catalogueInstall(e.name,{version:i.version,fills:u,handle:f,missionsOn:p,tools:i.tools.map(W=>W.name)}).then(W=>v(W.jobId)).catch(W=>b(Vl(W))).finally(()=>y(!1)))},F=()=>{v(null),K()},Q=e.title,_=S==null?void 0:S.agent,re=W=>{_&&(W&&ku(_.id,W),s(),n(at(_.id)))},Y=W=>{S&&(R(!0),O(null),A.catalogueConfirm(S.id,W).then(se=>{T(se),W||s()}).catch(se=>O(Vl(se))).finally(()=>R(!1)))};if((S==null?void 0:S.state)==="confirm"&&S.confirm){const W=nf(S.confirm.tools.map(X=>X.name),sf(S.confirm.tools)),se=S.steps.filter(X=>X.kind==="plugin"&&X.state==="done").map(X=>X.title);return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:["Add ",Q]}),onClose:s,foot:t.jsxs(ne,{children:[t.jsx(ot,{}),t.jsx($,{variant:"ghost",disabled:E,onClick:()=>Y(!1),children:"Don’t add it"}),t.jsxs($,{variant:"accent",disabled:E,onClick:()=>Y(!0),children:["Add ",Q]})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-confirm",children:S.steps.filter(X=>X.kind==="plugin").map(X=>{const{state:je,words:be}=Xp(X);return t.jsx(Jp,{state:je,children:be},`${X.kind}-${X.name}`)})}),t.jsxs(G,{tone:"warning",title:`${Q} would get more than the list showed.`,children:[se.length>0?`With ${dn(se)} installed, `:"","its tools resolved to a different set",S.confirm.unshown.length>0?`, including ${dn(S.confirm.unshown)}`:"",". Look at what it can reach before you add it."]}),t.jsx(ae,{message:M}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[ES(W)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>z(!I),children:I?"Hide":"See all"})]}),I?t.jsx("dl",{className:"cat-reach",children:W.map(([X,je])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:X}),t.jsx("dd",{children:je})]},X))}):null]}),t.jsx("p",{className:"cat-small",children:"The plugins stay installed either way; Settings → Plugins removes them."})]})}if(j&&(!S||S.state==="running")){const W=S==null?void 0:S.steps[S.steps.length-1],se=(S==null?void 0:S.approvalId)&&(W==null?void 0:W.state)==="adding";return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:["Add ",Q]}),onClose:s,foot:t.jsx(ne,{align:"end",children:t.jsx($,{onClick:s,children:"Close"})}),children:[t.jsx("ol",{className:"cat-steps","aria-live":"polite","data-testid":"cat-progress",children:((S==null?void 0:S.steps)??[]).map(X=>{const{state:je,words:be}=Xp(X);return t.jsx(Jp,{state:je,children:be},`${X.kind}-${X.name}`)})}),se?t.jsxs(G,{tone:"accent",action:t.jsx($,{size:"sm",onClick:()=>{s(),n(to)},children:"Open it"}),children:["Adding ",Q," waits for your approval in Needs you."]}):null,t.jsx(ae,{message:C}),t.jsxs("p",{className:"cat-small",children:["You can close this; it carries on, and ",Q," joins the team when it’s done."]})]})}if((S==null?void 0:S.state)==="done"){const W=S.steps.filter(je=>je.kind==="plugin").map(je=>je.title),se=(i==null?void 0:i.missions.length)??e.missions.length,X=p.length;return t.jsxs(Ye,{title:t.jsx(ra,{entry:e,children:Q}),onClose:s,foot:t.jsxs(ne,{children:[t.jsx($,{variant:"ghost",onClick:()=>{s(),n(un())},children:"Back to teammates"}),t.jsx(ot,{}),t.jsx($,{variant:"accent",onClick:()=>re(),children:"Say hello"})]}),children:[t.jsxs("div",{className:"cat-done","data-testid":"cat-done",children:[t.jsx(rl,{entry:e,size:"xxl"}),t.jsxs("p",{className:"cat-done-title",children:[Q," is on your team."]}),t.jsxs("p",{className:"cat-small",children:["@",(_==null?void 0:_.handle)??f,W.length?` · ${dn(W)} installed`:"",se>0&&X<se?` · ${se-X===1?"a mission":"missions"} off until you turn ${se-X===1?"it":"them"} on`:""]})]}),e.examples.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Try one"}),t.jsx("div",{className:"wb-starters",children:e.examples.map(je=>t.jsx("button",{type:"button",className:"wb-starter",onClick:()=>re(je),children:je},je))})]}):null]})}if((S==null?void 0:S.state)==="failed"){const W=S.steps.find(se=>se.kind==="plugin"&&se.state==="failed");return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:[Q," wasn’t added"]}),onClose:s,foot:t.jsxs(ne,{children:[t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Close"}),t.jsx($,{variant:"accent",disabled:w,onClick:F,children:"Try again"})]}),children:[t.jsx("ol",{className:"cat-steps","data-testid":"cat-failed",children:S.steps.map(se=>{const{state:X,words:je}=Xp(se);return t.jsx(Jp,{state:X==="now"?"next":X,children:X==="now"?je.replace(/…$/,""):je},`${se.kind}-${se.name}`)})}),t.jsx(G,{tone:"critical",title:`${S.error??"It stopped before it finished"}.`,action:S.approvalId?t.jsx($,{size:"sm",onClick:()=>{s(),n(to)},children:"Open the approval"}):void 0,children:t.jsxs("p",{children:["Nothing was added and nothing else changed.",W?t.jsxs(t.Fragment,{children:[" ",W.title," waits in"," ",t.jsx("a",{href:Fe("plugins"),onClick:se=>{se.preventDefault(),s(),n(Fe("plugins"))},children:"Settings → Plugins"})," ","if you’d rather look at it there."]}):null]})}),t.jsx(ae,{message:N})]})}const B=(i==null?void 0:i.plugins.filter(W=>W.fix==="install"&&W.byBuddi))??[],q=(i==null?void 0:i.blocked)??[],J=q[0],Z=J?tf(J):null,fe=nf(i?i.tools.map(W=>W.name):e.tools,sf([...((Oe=e.claims)==null?void 0:Oe.tools)??[],...((i==null?void 0:i.tools)??[]).filter(W=>W.tier!=="unknown")])),ve=W=>{var se;return((se=e.missions.find(X=>X.id===W))==null?void 0:se.when)??""};return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:["Add ",Q]}),onClose:s,foot:t.jsxs(ne,{children:[a?null:t.jsx("span",{className:"plugins-foot-note",children:B.length?`Installs ${dn(B.map(W=>W.title))}, then adds ${Q}.`:"Nothing runs until you add it."}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsxs($,{variant:"accent",disabled:!i||q.length>0||w||f.length<2,onClick:K,children:["Add ",Q]})]}),children:[t.jsxs("p",{className:"cat-lede",children:[e.pitch," One approval adds it; you can change or remove it from its page."]}),t.jsx(ae,{message:o??N}),!i&&!o?t.jsx(Ne,{children:"Reading what it needs…"}):i?t.jsxs(ue,{divided:!0,gap:"lg",children:[B.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Installed on the way"}),t.jsx("ul",{className:"cat-plugins",children:B.map(W=>{const se=D.find(X=>X.name===W.name);return t.jsxs("li",{children:[t.jsx(Hn,{svg:se==null?void 0:se.iconSvg}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsxs("span",{className:"cat-plugin-name",children:[W.title," ",W.version?t.jsx("span",{className:"plugins-ver",children:W.version}):null]}),t.jsx("span",{className:"cat-small",children:se!=null&&se.summary?KY(se.summary):"Made by buddi; installed only if it matches what withbuddi.com lists."})]}),t.jsx(Ae,{tone:"accent",children:"by buddi"})]},W.name)})})]}):null,J?t.jsxs(G,{tone:"warning",action:Z?t.jsx($,{size:"sm",onClick:()=>{s(),n(Z.route)},children:Z.label}):void 0,children:[Q," needs ",dn(q.map(_y))," first. Add ",q.length===1?"it":"them",", then come back; nothing is added until then."]}):null,i.fills.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["A few picks ",t.jsx("span",{className:"cat-block-aside",children:"filled in for you"})]}),t.jsx("div",{className:"cat-fills",children:i.fills.map(W=>t.jsx(ie,{label:t.jsxs(t.Fragment,{children:[W.label,W.optional?t.jsx("span",{className:"faint",children:" · optional"}):null]}),children:W.choices&&W.choices.length>0?t.jsxs("select",{value:u[W.id]??"",onChange:se=>h({...u,[W.id]:se.target.value}),children:[W.kind==="calendar"?t.jsx("option",{value:"",children:"All of them"}):null,W.choices.map(se=>t.jsx("option",{value:se,children:se},se))]}):W.kind==="time"?t.jsx("input",{type:"time",value:u[W.id]??"",onChange:se=>h({...u,[W.id]:se.target.value})}):t.jsx("input",{value:u[W.id]??"",onChange:se=>h({...u,[W.id]:se.target.value})})},W.id))})]}):null,t.jsx("div",{className:"cat-block",children:t.jsx(ie,{label:"Handle",hint:"How you call it in chat and on Telegram.",children:t.jsxs("span",{className:"cat-handle",children:[t.jsx("span",{className:"mono faint",children:"@"}),t.jsx("input",{className:"mono","aria-label":"Handle",value:f,onChange:W=>m(W.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]})})}),i.missions.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Missions ",t.jsx("span",{className:"cat-block-aside",children:"off unless you turn one on"})]}),t.jsx("ul",{className:"cat-missions","data-switches":"true",children:i.missions.map(W=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:W.name}),t.jsx("span",{className:"cat-mission-when",children:ve(W.id)}),t.jsx(Tu,{checked:p.includes(W.id),label:`Turn on ${W.name}`,onChange:se=>g(se?[...p,W.id]:p.filter(X=>X!==W.id))})]},W.id))})]}):null,t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[ES(fe)," ",t.jsx("button",{type:"button",className:"plugins-link cat-link",onClick:()=>k(!x),children:x?"Hide":"See all"})]}),x?t.jsx("dl",{className:"cat-reach",children:fe.map(([W,se])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:W}),t.jsx("dd",{children:se})]},W))}):null]})]}):null]})}function GY(e){const n=[];let s=null,r=0;for(const a of e){const i=/^@@ -\d+,\d+ \+(\d+),(\d+) @@$/.exec(a);if(i){const c=Number(i[2])===0?Number(i[1])+1:Number(i[1]);n.length>0&&c-1>r&&n.push({kind:"gap",count:c-1-r}),s=c;continue}const l=a.startsWith("+ ")?"add":a.startsWith("- ")?"del":"ctx",o=l==="ctx"&&!a.startsWith(" ")?a:a.slice(2);l==="del"||s===null?n.push({kind:l,text:o,n:null}):(n.push({kind:l,text:o,n:s}),r=s,s+=1)}return n}function $S({lines:e,label:n}){return t.jsx("div",{className:"cat-diff",role:"region","aria-label":n,children:GY(e).map((s,r)=>s.kind==="gap"?t.jsxs("div",{className:"cat-diff-line","data-kind":"gap",children:[t.jsx("span",{className:"cat-diff-n","aria-hidden":"true"}),t.jsx("span",{className:"cat-diff-k","aria-hidden":"true"}),t.jsxs("span",{children:["⋯ ",s.count," ",s.count===1?"line":"lines"]})]},r):t.jsxs("div",{className:"cat-diff-line","data-kind":s.kind,children:[t.jsx("span",{className:"cat-diff-n","aria-hidden":"true",children:s.n??""}),t.jsx("span",{className:"cat-diff-k","aria-hidden":"true",children:s.kind==="add"?"+":s.kind==="del"?"-":" "}),t.jsx("span",{children:s.text||" "})]},r))})}function WI({entry:e,agentId:n,onClose:s,onUpdated:r}){const[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(!1);d.useEffect(()=>{let w=!1;return A.catalogueUpdatePlan(e.name,n).then(y=>{w||i(y)}).catch(y=>{w||o(Vl(y))}),()=>{w=!0}},[e.name,n]);const g=io((a==null?void 0:a.version)??e.version),x=w=>{a&&(f(!0),o(null),A.catalogueUpdate(e.name,n,a.plan,w).then(()=>{p(!0),r==null||r()}).catch(y=>{o(Vl(y)),A.catalogueUpdatePlan(e.name,n).then(i).catch(()=>{})}).finally(()=>f(!1)))};if(m)return t.jsx(Ye,{title:t.jsxs(ra,{entry:e,children:[e.title," ",g]}),onClose:s,foot:t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",onClick:s,children:"Done"})}),children:t.jsx(G,{tone:"good",title:`${e.title} is on ${g}.`,role:"status",children:a!=null&&a.edited?"Your version is in the trash folder if you want any of it back.":"Your picks and missions are as they were."})});if(!a)return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:["Update ",e.title]}),onClose:s,children:[t.jsx(ae,{message:l}),l?null:t.jsx(Ne,{children:"Reading what changed…"})]});const k=a.personaDiff.filter(w=>w.startsWith("+ ")).length,j=a.personaDiff.filter(w=>w.startsWith("- ")).length;if(a.edited)return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:[e.title," ",g," is out"]}),onClose:s,foot:t.jsxs(ne,{children:[c?null:t.jsx($,{variant:"ghost",onClick:()=>u(!0),children:"See what changed"}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Keep mine"}),t.jsx($,{variant:"danger",disabled:h,onClick:()=>x(!0),children:"Replace my changes"})]}),children:[t.jsx(G,{tone:"accent",children:a.replacesOwn&&a.replacesOwn.length>0?`${g} brings ${a.replacesOwn.length===1?"a skill":"skills"} named like your own (${dn(a.replacesOwn)}), so nothing is updated on its own. Yours stay exactly as they are unless you replace them; replaced, they go to the trash folder.`:a.via?`${e.title} replaces your @${a.handle}. You’ve changed @${a.handle}, so nothing is replaced on its own. Your file stays exactly as it is unless you replace it; its handle, chats, memory and missions stay either way.`:`You’ve changed ${e.title} since you added it, so nothing is updated on its own. Your file stays exactly as it is unless you replace it.`}),t.jsx(ae,{message:l}),t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["New in ",g]}),t.jsx("p",{className:"cat-prose",children:a.changes})]}),t.jsxs("div",{className:"cat-block",children:[t.jsxs("h3",{className:"cat-block-title",children:["Your file and ",g," ",t.jsx("button",{type:"button",className:"cat-block-aside plugins-link",onClick:()=>u(!c),children:c?"Hide":"See what changed"})]}),c?t.jsxs(t.Fragment,{children:[t.jsx($S,{lines:a.personaDiff,label:`Your ${e.title} against ${g}`}),t.jsxs("p",{className:"cat-small",children:["Lines marked − are in your file and not in ",g,"; + is new in ",g,". Replacing keeps your picks, and drops what you wrote by hand."]})]}):t.jsxs("p",{className:"cat-small",children:[j===1?"1 line":`${j} lines`," only in your file, ",k===1?"1 line":`${k} lines`," new in ",g,"."]})]})]})]});const v=a.added.length>0?`New: ${dn(nf(a.added.map(w=>w.name),sf(a.added)).map(([w])=>w))}. The approval lists each tool.`:"No new tools. It reaches what it reaches today.";return t.jsxs(Ye,{title:t.jsxs(ra,{entry:e,children:["Update ",e.title," to ",g]}),onClose:s,foot:t.jsxs(ne,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Your picks and handle stay."}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Not now"}),t.jsxs($,{variant:"accent",disabled:h,onClick:()=>x(!1),children:["Update ",e.title]})]}),children:[t.jsx("p",{className:"cat-lede",children:a.changes}),t.jsx(ae,{message:l}),t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What changes in its file"}),a.personaDiff.length>0?t.jsx($S,{lines:a.personaDiff,label:a.via?`@${a.handle} against ${e.title} ${g}`:`${e.title} ${io(a.fromVersion)} against ${g}`}):t.jsx("p",{className:"cat-prose",children:"Its persona stays word for word."})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"What it can reach"}),t.jsxs("p",{className:"cat-prose",children:[v,a.removed.length>0?` No longer: ${a.removed.join(", ")}.`:""]})]}),t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Missions"}),t.jsxs("p",{className:"cat-prose",children:[a.missionsAdded.length>0?`${dn(a.missionsAdded.map(w=>w.name))} added, off until you turn ${a.missionsAdded.length===1?"it":"them"} on.`:"None added.",(a.missionsChanged??[]).length>0?" Their prompt, hour and switch stay yours.":" Yours stay as they are."]}),(a.missionsChanged??[]).map(w=>t.jsxs("p",{className:"cat-prose",children:[w.name,": new settings — ",w.words,"."]},w.id))]}),a.retires&&a.retires.length>0?t.jsxs("div",{className:"cat-block",children:[t.jsx("h3",{className:"cat-block-title",children:"Skills"}),t.jsxs("p",{className:"cat-prose",children:[g," no longer has ",dn(a.retires),"; ",a.retires.length===1?"it goes":"they go"," to the trash folder."]})]}):null]})]})}function Hr(e){if(e.state==="unavailable")return"unavailable";const n=e.installed;return e.state!=="installed"||!n?"ready":n.drift==="update"?"update":n.drift==="edited-update"?"edited":"added"}function zy(){const e=ge(()=>A.plugins(),[]);return d.useMemo(()=>{var n;return new Set((((n=e.data)==null?void 0:n.installed)??[]).filter(s=>s.loaded&&s.enabled!==!1).map(s=>s.name))},[e.data])}function Uy(){return t.jsx(oe,{name:"check",size:14})}function YY({entry:e,loaded:n,mailbox:s}){const r=Hr(e);if(r==="unavailable")return t.jsx("span",{className:"cat-chips",children:t.jsx("span",{className:"cat-chip","data-need":"true",children:"Needs a newer buddi"})});const a=e.missing??[];if(a.length>0)return t.jsx("span",{className:"cat-chips",children:t.jsxs("span",{className:"cat-chip","data-need":"true",children:["Needs ",dn(a.map(_y))]})});if(r!=="ready")return null;const i=BY(e,n,s);if(i.length===0)return null;const l=`Uses ${dn(i)}`;return t.jsx("span",{className:"cat-uses",title:l,children:l})}function qY({entry:e,onAdd:n,onUpdate:s}){const r=Hr(e),a=i=>l=>{l.stopPropagation(),i()};return r==="added"?t.jsxs("span",{className:"cat-added",children:[t.jsx(Uy,{}),"Added"]}):r==="update"?t.jsx($,{size:"sm",onClick:a(s),"aria-label":`Update ${e.title}`,children:"Update"}):r==="edited"?t.jsx($,{size:"sm",onClick:a(s),children:"See what changed"}):r==="unavailable"?null:t.jsx($,{size:"sm",variant:"accent",onClick:a(n),"aria-label":`Add ${e.title}`,children:"Add"})}function QY({entry:e}){var a,i,l,o;const n=Hr(e),s=io(e.version),r=(a=e.installed)==null?void 0:a.handle;return(i=e.installed)!=null&&i.via&&n==="update"?t.jsxs("p",{className:"cat-note",children:["Replaces your @",r,": it keeps its handle, chats, memory and missions."]}):(l=e.installed)!=null&&l.via&&n==="edited"?t.jsxs("p",{className:"cat-note",children:["Replaces your @",r,", which you’ve changed."]}):n==="update"?t.jsxs("p",{className:"cat-note",children:[s," is out: ",e.changes.charAt(0).toLowerCase()+e.changes.slice(1)]}):n==="edited"?t.jsxs("p",{className:"cat-note",children:["You’ve changed ",e.title,"; ",s," is out."]}):n==="added"?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",(o=e.installed)==null?void 0:o.handle]}):n==="unavailable"?t.jsx("p",{className:"cat-note","data-quiet":"true",children:e.reason}):null}function HI({entry:e,loaded:n,mailbox:s,onOpen:r,onAdd:a,onUpdate:i}){return t.jsx("div",{className:"cat-card","data-state":Hr(e),"data-testid":`cat-card-${e.name}`,children:t.jsxs(Ps,{onClick:r,label:`${e.title}: details`,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx(rl,{entry:e,size:"lg"}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.title}),t.jsx("div",{className:"cat-card-kind",children:Ly(e.category)})]})]}),t.jsx("p",{className:"cat-pitch",children:e.pitch}),t.jsx(QY,{entry:e}),t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(YY,{entry:e,loaded:n,mailbox:s}),t.jsx(ot,{}),t.jsx(qY,{entry:e,onAdd:a,onUpdate:i})]})]})})}function JY({row:e,agents:n,navigate:s,pages:r}){const a=Ny(e.plugin,e.agent,()=>window.dispatchEvent(new Event(Fr))),i=a.created??(e.state==="installed"?{id:e.agent,handle:e.handle,name:e.name}:null),l=r?CT(e.plugin,r.all):Nm(e.plugin);return t.jsx("div",{className:"cat-card","data-state":i?"added":"ready","data-testid":`cat-card-${e.agent}`,children:t.jsxs(Ps,{onClick:i?()=>s(Ft(i.id)):void 0,label:i?`Open @${i.handle}`:void 0,children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("span",{className:"cat-face","data-size":"lg",children:t.jsx(On,{id:e.agent,name:e.name,size:"lg",face:n.find(o=>o.id===e.agent)})}),t.jsxs("div",{className:"cat-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.name}),t.jsxs("div",{className:"cat-card-kind",children:["From ",l]})]})]}),t.jsx("p",{className:"cat-pitch",children:e.text}),i?t.jsxs("p",{className:"cat-note","data-quiet":"true",children:["On your team as @",i.handle]}):null,t.jsxs("div",{className:"cat-card-foot",children:[t.jsx(ae,{message:a.failure}),t.jsx(ot,{}),i?t.jsxs("span",{className:"cat-added",children:[t.jsx(Uy,{}),"Added"]}):t.jsx($,{size:"sm",variant:"accent",disabled:a.busy,onClick:o=>{o.stopPropagation(),a.accept()},"aria-label":`Add ${e.name}`,children:"Add"})]})]})})}function XY({n:e=6}){return t.jsx("div",{className:"cat-grid","aria-busy":"true","aria-label":"Loading the catalogue","data-testid":"cat-loading",children:Array.from({length:e},(n,s)=>t.jsxs("div",{className:"ui-card cat-skel",children:[t.jsxs("div",{className:"cat-card-head",children:[t.jsx("i",{className:"cat-skel-face"}),t.jsxs("span",{className:"cat-card-name",children:[t.jsx("i",{className:"cat-skel-line","data-w":"40"}),t.jsx("i",{className:"cat-skel-line","data-w":"20"})]})]}),t.jsx("i",{className:"cat-skel-line","data-w":"90"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"})]},s))})}function ZY(e,n,s){const r=e.find(a=>a.roles.includes(zr));r&&(s.trim()&&ku(r.id,`I'd like a teammate for this: ${s.trim()}`),n(at(r.id)))}function eq({sheet:e,view:n,navigate:s,onClose:r,onChanged:a}){const i=e?n==null?void 0:n.agents.find(l=>l.name===e.name):void 0;return!e||!i?null:e.kind==="update"&&i.installed?t.jsx(WI,{entry:i,agentId:i.installed.agentId,onClose:r,onUpdated:a}):t.jsx(BI,{entry:i,navigate:s,onClose:r,onAdded:a})}const tq=[{value:"all",label:"All"},{value:"work",label:"Work"},{value:"money",label:"Money"},{value:"home",label:"Home"},{value:"health",label:"Health"},{value:"learning",label:"Learning"},{value:"life",label:"Life"}];function nq(e,n){return[e.title,e.pitch,e.about,e.description,Ly(e.category)].some(s=>s.toLowerCase().includes(n))}function sq({name:e,agents:n,navigate:s,pluginPages:r}){const[a,i]=d.useState(0),l=ge(()=>A.catalogue(a>0),[a]),o=zy(),[c,u]=d.useState(""),[h,f]=d.useState("all"),[m,p]=d.useState(null),g=l.data,x=()=>{l.reload(),window.dispatchEvent(new Event(Fr))},k=()=>i(T=>T+1),j=t.jsx(eq,{sheet:m,view:g,navigate:s,onClose:()=>p(null),onChanged:x}),v=e?g==null?void 0:g.agents.find(T=>T.name===e):void 0,w=d.useRef(!1);if(d.useEffect(()=>{w.current||!v||!Q3(window.location.hash,v.name)||(w.current=!0,Hr(v)==="ready"&&p({kind:"install",name:v.name}))},[v]),e&&g&&!g.unavailable&&v)return t.jsxs(t.Fragment,{children:[t.jsx(iq,{entry:v,loaded:o,agents:n,navigate:s,onAdd:()=>p({kind:"install",name:v.name}),onUpdate:()=>p({kind:"update",name:v.name})}),j]});const y=c.trim().toLowerCase(),b=((g==null?void 0:g.agents)??[]).filter(T=>(h==="all"||T.category===h)&&(!y||nq(T,y))),S=((g==null?void 0:g.fromPlugins)??[]).filter(T=>h==="all"&&(!y||[T.name,T.text,T.description].some(E=>E.toLowerCase().includes(y)))),C=T=>()=>s(T);return t.jsxs(Yw,{children:[t.jsx(Pi,{before:t.jsx(xc,{inline:!0,items:[{label:"Agents",href:bt,onClick:C(bt)}]}),title:"Add a teammate",lede:"Agents tested with the plugins they use. Adding one is one approval, and it becomes a file on this computer you can change."}),e&&g&&!g.unavailable&&!v?t.jsxs(G,{tone:"warning",children:["The catalogue lists no teammate called “",e,"”. Here is everyone it does list."]}):null,t.jsxs("div",{className:"cat-bar",children:[t.jsxs("div",{className:"cat-search",children:[t.jsx(oe,{name:"search",size:16}),t.jsx(hm,{label:"Search teammates",value:c,placeholder:"Search: meals, money, a language…",onChange:u})]}),t.jsx("div",{className:"cat-cats",children:t.jsx(mT,{label:"Category",options:tq,value:h,onChange:f})})]}),g&&!g.unavailable?g.stale?t.jsxs("p",{className:"plugins-quiet","data-testid":"cat-stale",children:[t.jsx(oe,{name:"globe",size:14}),"From the list kept ",g.fetchedAt?rq(g.fetchedAt):"earlier",": withbuddi.com didn’t answer just now."," ",t.jsx("button",{type:"button",className:"plugins-link",onClick:k,children:"Try again"})]}):t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(oe,{name:"globe",size:14}),"Opening this page fetched the list from withbuddi.com. Nothing else leaves."]}):null,l.error&&!g?t.jsx(Ne,{warm:!0,title:"The catalogue didn’t load",action:t.jsx($,{variant:"accent",size:"sm",onClick:k,children:"Try again"}),children:l.error}):g?g.unavailable?t.jsx(Ne,{warm:!0,title:"The catalogue needs withbuddi.com",action:t.jsx($,{variant:"accent",size:"sm",disabled:l.loading,onClick:k,children:"Try again"}),children:"This computer can’t reach it right now, and there’s no saved copy yet. Try again when you’re online."}):b.length+S.length>0?t.jsxs("div",{className:"cat-grid","data-testid":"cat-grid",children:[b.map(T=>t.jsx(HI,{entry:T,loaded:o,mailbox:g.mailbox,onOpen:()=>s(un(T.name)),onAdd:()=>p({kind:"install",name:T.name}),onUpdate:()=>p({kind:"update",name:T.name})},T.name)),S.map(T=>t.jsx(JY,{row:T,agents:n,navigate:s,pages:r},`${T.plugin}/${T.agent}`))]}):t.jsx(Ne,{warm:!0,title:"No teammate for that yet",action:t.jsxs("span",{className:"cat-empty-acts",children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>{u(""),f("all")},children:"Show all"}),t.jsx($,{size:"sm",variant:"accent",onClick:()=>ZY(n,s,c),children:"Ask Agent Father"})]}),children:y?t.jsxs(t.Fragment,{children:["Nothing in the catalogue does “",c.trim(),"”. Agent Father can make one for you; your words go with you."]}):"Nothing in this category yet."}):t.jsx(XY,{}),g&&!g.unavailable&&g.delisted.length>0?t.jsx(Xe,{title:"No longer in the catalogue",children:t.jsx("ul",{className:"cat-plugins","data-testid":"cat-delisted",children:g.delisted.map(T=>t.jsxs("li",{children:[t.jsx(jn,{agents:n,id:T.agentId,size:"sm"}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("a",{className:"cat-plugin-name",href:Ft(T.agentId),onClick:E=>{E.preventDefault(),s(Ft(T.agentId))},children:T.name??`@${T.handle}`}),t.jsxs("span",{className:"cat-small",children:["@",T.handle," keeps working as it is; no updates will come."]})]})]},T.agentId))})}):null,j]})}function rq(e){const n=Math.round((Date.now()-Date.parse(e))/36e5);if(!Number.isFinite(n)||n<1)return"an hour ago";if(n<24)return`${n} h ago`;const s=Math.round(n/24);return s===1?"yesterday":`${s} days ago`}function wi({title:e,children:n}){return t.jsxs("section",{className:"cat-row",children:[t.jsx("h2",{className:"cat-row-title",children:e}),t.jsx("div",{className:"cat-row-body",children:n})]})}function aq({entry:e,loaded:n,navigate:s}){const r=new Map((e.missing??[]).map(i=>[i.name,i])),a=[...Object.keys(e.requires).map(i=>({name:i,needed:!0,need:!1})),...Object.keys(e.optional).map(i=>({name:i,needed:!1,need:!1})),...e.needs.map(i=>({name:i.replace(/\?$/,""),needed:!i.endsWith("?"),need:!0}))];return a.length===0?t.jsx("p",{className:"cat-small",children:"None. It works with what buddi has."}):t.jsx("ul",{className:"cat-plugins",children:a.map(({name:i,needed:l,need:o})=>{const c=r.get(i),u=c?tf(c):null,h=o?Fy(i).title:(c==null?void 0:c.kind)==="plugin"?c.title:Nm(i),f=o?l&&!c:n.has(i);return t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(oe,{name:o?i==="mailbox"?"mail":"key":"plug",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:h.charAt(0).toUpperCase()+h.slice(1)}),t.jsx("span",{className:"cat-small",children:l?"Needed":"Better with it"})]}),u?t.jsx($,{size:"sm",onClick:()=>s(u.route),children:u.label}):c?t.jsx("span",{className:"cat-small",children:"Installed when you add it"}):f?t.jsxs("span",{className:"cat-added",children:[t.jsx(Uy,{}),o?"You have one":"Installed"]}):t.jsx("span",{className:"cat-small",children:o?"Optional":"Not installed"})]},`${o?"need":"plugin"}-${i}`)})})}function iq({entry:e,loaded:n,agents:s,navigate:r,onAdd:a,onUpdate:i}){var g,x,k,j;const l=Hr(e),c=(g=e.installed)==null?void 0:g.agentId,u=io(e.version),h=(x=e.installed)!=null&&x.via?e.installed:void 0,f=v=>{c&&(v&&ku(c,v),r(at(c)))},m=nf(e.tools,sf((k=e.claims)==null?void 0:k.tools)),p=e.replaces.map(v=>Qp(v.split("/")[1]??v));return t.jsxs(Yw,{children:[t.jsxs("a",{className:"cat-back",href:un(),onClick:v=>{v.preventDefault(),r(un())},children:[t.jsx(oe,{name:"chevron-left",size:12}),"Teammates"]}),t.jsxs("header",{className:"cat-hero",children:[t.jsx(rl,{entry:e,size:"xxl"}),t.jsxs("div",{className:"cat-hero-text",children:[t.jsx("h1",{className:"cat-hero-title",children:e.title}),t.jsx("p",{className:"cat-hero-pitch",children:e.pitch}),t.jsxs("p",{className:"cat-hero-meta",children:[e.trust==="by-buddi"?t.jsx(Ae,{tone:"accent",children:"by buddi"}):null,t.jsx("span",{children:Ly(e.category)}),t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsx("span",{className:"mono",children:h?e.version:((j=e.installed)==null?void 0:j.version)??e.version}),e.installed?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-hidden":"true",children:"·"}),t.jsxs("span",{children:["on your team as ",t.jsxs("span",{className:"mono",children:["@",e.installed.handle]})]})]}):null]})]}),t.jsx("div",{className:"cat-hero-act",children:l==="ready"?t.jsxs($,{variant:"accent",onClick:a,children:["Add ",e.title]}):l==="update"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),t.jsx($,{variant:"accent",onClick:i,children:h?`Update @${h.handle} to ${e.title}`:`Update to ${u}`})]}):l==="edited"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>f(),children:"Open chat"}),t.jsx($,{onClick:i,children:"See what changed"})]}):l==="unavailable"?null:t.jsx($,{variant:"accent",onClick:()=>f(),children:"Open chat"})})]}),l==="edited"&&h?t.jsxs(G,{tone:"accent",children:[e.title," replaces your @",h.handle,". You’ve changed it, so it isn’t replaced on its own: your file stays as it is unless you replace it."]}):l==="edited"?t.jsxs(G,{tone:"accent",children:["You’ve changed ",e.title," since you added it, so ",u," isn’t applied on its own. Your file stays as it is unless you replace it."]}):l==="unavailable"?t.jsx(G,{tone:"warning",children:e.reason}):null,t.jsx(Xe,{flush:!0,children:t.jsxs("div",{className:"cat-rows",children:[t.jsxs(wi,{title:"What it does",children:[t.jsx("p",{className:"cat-prose",children:e.about}),p.length>0?t.jsxs("p",{className:"cat-small",children:["Does what ",dn(p)," did. If you have ",dn(p)," and haven’t changed it, it’s offered as an update."]}):null]}),e.examples.length>0?t.jsxs(wi,{title:"Ask it",children:[t.jsx("div",{className:"wb-starters",children:e.examples.map(v=>t.jsx("button",{type:"button",className:"wb-starter",disabled:!c,onClick:()=>f(v),children:v},v))}),c?null:t.jsx("p",{className:"cat-small",children:"Once it’s on your team, a tap opens a chat with it."})]}):null,t.jsx(wi,{title:"Skills",children:e.skills.length===0?t.jsx("p",{className:"cat-small",children:"None. It works from its persona."}):t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"cat-plugins","data-testid":"cat-skills",children:e.skills.map(v=>t.jsxs("li",{children:[t.jsx("span",{className:"ui-app-icon","aria-hidden":"true",children:t.jsx(oe,{name:"files",size:14})}),t.jsxs("span",{className:"cat-plugin-text",children:[t.jsx("span",{className:"cat-plugin-name",children:Qp(v.name)}),v.description?t.jsx("span",{className:"cat-small",children:v.description}):null,t.jsx(Zt,{summary:"Read it",children:t.jsx(zt,{label:`${Qp(v.name)}: the skill's text`,children:v.text})})]})]},v.name))}),t.jsxs("p",{className:"cat-small",children:["Plain text, no code."," ",c?t.jsxs(t.Fragment,{children:["Read and change them on ",t.jsx("a",{href:Ft(c,"skills"),onClick:v=>{v.preventDefault(),r(Ft(c,"skills"))},children:"its Skills tab"}),"."]}):"Once it’s on your team they’re files you can read and change."]})]})}),t.jsxs(wi,{title:"What it can reach",children:[t.jsx("dl",{className:"cat-reach",children:m.map(([v,w])=>t.jsxs("div",{className:"cat-reach-row",children:[t.jsx("dt",{children:v}),t.jsx("dd",{children:w})]},v))}),t.jsx("p",{className:"cat-small",children:"Anything that sends or pays still asks you first, every time. You can change any of this on its page."})]}),t.jsx(wi,{title:"Missions",children:e.missions.length>0?t.jsx("ul",{className:"cat-missions",children:e.missions.map(v=>t.jsxs("li",{children:[t.jsx("span",{className:"cat-mission-name",children:v.name}),t.jsx("span",{className:"cat-mission-when",children:v.when}),t.jsx("span",{className:"cat-off",children:"off until you turn it on"})]},v.id))}):t.jsx("p",{className:"cat-small",children:"None. It works when you ask."})}),t.jsx(wi,{title:"Plugins",children:t.jsx(aq,{entry:e,loaded:n,navigate:r})}),t.jsxs(wi,{title:"Version",children:[t.jsxs("p",{className:"cat-prose",children:[t.jsx("span",{className:"mono",children:e.version})," · ",e.changes]}),t.jsx("p",{className:"cat-small",children:"Reviewed in withbuddi/buddi-market. An update always asks you, and never touches a file you changed."})]})]})})]})}function lq(e){var r,a;const n=ge(()=>A.agents(),[e]),s=(a=(r=n.data)==null?void 0:r.catalogue)==null?void 0:a[e];return{entry:s?{...s,agentId:e}:void 0,reload:n.reload}}function oq({entry:e,navigate:n,onUpdated:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=e.delisted?null:e.drift==="update"?"update":e.drift==="edited-update"?"edited":null,h=()=>{c(!0),l(null),A.catalogue().then(f=>{const m=f.agents.find(p=>p.name===e.package);m?a(m):l(f.unavailable??`The catalogue no longer lists ${e.title}.`)}).catch(f=>l(f instanceof he?f.message:String(f))).finally(()=>c(!1))};return t.jsxs(t.Fragment,{children:[t.jsxs("p",{className:"agent-catalogue-line","data-testid":"agent-catalogue-line","data-delisted":e.delisted?"true":void 0,children:[e.delisted?t.jsx("span",{children:"No longer in the catalogue"}):t.jsx("a",{href:un(e.package),onClick:f=>{f.preventDefault(),n(un(e.package))},children:"From the catalogue"}),t.jsx("span",{"aria-hidden":"true",children:" · "}),t.jsxs("span",{children:[e.title," ",e.via?`(was ${e.via.split("/")[1]??e.via})`:io(e.version)]}),e.delisted?t.jsx("span",{className:"muted",children:" · it keeps working; no updates will come"}):null,u?t.jsx($,{size:"sm",variant:u==="update"?"accent":void 0,disabled:o,onClick:h,children:u==="update"&&e.latest?`Update to ${io(e.latest)}`:u==="update"?"Update":"See what changed"}):null]}),i?t.jsx(ae,{message:i}):null,r?t.jsx(WI,{entry:r,agentId:e.agentId,onClose:()=>a(null),onUpdated:s}):null]})}function cq(e){return typeof e=="string"?e:e.name??e.id??"a mission"}function uq({agentId:e,name:n,navigate:s}){const[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=()=>{a(!1),m(null),s(bt)},g=y=>y instanceof he?y.message:String(y),x=()=>{a(!0),c(null),l(null),A.agentRemovePreview(e).then(l).catch(y=>c(g(y)))},k=()=>{h(!0),c(null),A.removeAgent(e).then(y=>{var b;window.dispatchEvent(new Event(Fr));const N=(b=y.result)==null?void 0:b.delegateListsNotUpdated;if(Array.isArray(N)&&N.length>0){m(N.map(S=>String((S==null?void 0:S.handle)??(S==null?void 0:S.id)??"")));return}a(!1),s(bt)}).catch(y=>c(g(y))).finally(()=>h(!1))},j=(i==null?void 0:i.pausesMissions.map(cq))??[],v=(i==null?void 0:i.unusedPlugins)??[],w=((i==null?void 0:i.handedWorkBy)??[]).map(y=>`@${y}`);return t.jsxs(Xe,{children:[t.jsxs(ne,{children:[t.jsxs("div",{className:"agent-remove-text",children:[t.jsx("strong",{children:"Remove from team"}),t.jsx("span",{className:"muted",children:"Its file goes to the trash folder; what it remembers and its conversations stay."})]}),t.jsxs($,{variant:"danger-ghost",onClick:x,children:["Remove ",n,"…"]})]}),r&&f?t.jsx(Ut,{title:`${n} is off your team`,onClose:p,foot:t.jsx($,{variant:"accent",onClick:p,children:"Done"}),children:t.jsxs(G,{tone:"warning",title:"Cleanup is incomplete",role:"status",children:["The delegate list of ",dn(f.map(y=>`@${y}`))," could not be updated and still names it. That entry reaches nobody; edit the list to remove it."]})}):r?t.jsxs(Ut,{title:`Remove ${n} from your team?`,onClose:()=>a(!1),foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>a(!1),children:"Cancel"}),t.jsx($,{variant:"danger",disabled:u||!i,onClick:k,children:"Remove from team"})]}),children:[t.jsx(ae,{message:o}),i?t.jsxs("div",{className:"ui-stack","data-testid":"remove-preview",children:[t.jsxs("p",{children:["@",i.handle,"’s folder moves to the trash folder, so it can be brought back by hand."]}),j.length>0?t.jsxs("p",{children:["Its ",j.length===1?"mission":"missions"," ",dn(j)," ",j.length===1?"is":"are"," paused."]}):null,w.length>0?t.jsxs("p",{children:[dn(w)," will stop handing work to it."]}):null,v.length>0?t.jsxs("p",{children:["No other agent uses ",dn(v.map(Nm)),"; it stays installed."," ",t.jsxs("a",{href:Fe("plugins"),onClick:y=>{y.preventDefault(),a(!1),s(Fe("plugins"))},children:["Remove ",v.length===1?"it":"them"," in Settings → Plugins"]}),"."]}):null]}):o?null:t.jsx("p",{className:"muted",children:"Reading what it would change…"})]}):null]})}const KI=["January","February","March","April","May","June","July","August","September","October","November","December"],rf=e=>e?{day:String(e.day),month:String(e.month),year:e.year?String(e.year):""}:{day:"",month:"",year:""};function af(e){if(e.day===""&&e.month===""&&e.year.trim()==="")return null;if(e.day===""||e.month==="")return"incomplete";const s=e.year.trim();return s!==""&&!/^\d{4}$/.test(s)?"incomplete":{day:Number(e.day),month:Number(e.month),year:s===""?null:Number(s)}}const dq=(e,n)=>(e??null)===(n??null)||!!e&&!!n&&e.day===n.day&&e.month===n.month&&(e.year??null)===(n.year??null),VI=(e,n=!0)=>`${e.day} ${KI[e.month-1]}${n&&e.year?` ${e.year}`:""}`;function _v({label:e,hint:n,value:s,onChange:r}){const a=af(s)==="incomplete";return t.jsx(ie,{group:!0,label:e,hint:a?"A day and a month; the year is optional, four digits.":n,children:t.jsxs("div",{className:"day-month",children:[t.jsxs("select",{"aria-label":`${e}: day`,value:s.day,onChange:i=>r({...s,day:i.target.value}),children:[t.jsx("option",{value:"",children:"Day"}),Array.from({length:31},(i,l)=>t.jsx("option",{value:String(l+1),children:l+1},l+1))]}),t.jsxs("select",{"aria-label":`${e}: month`,value:s.month,onChange:i=>r({...s,month:i.target.value}),children:[t.jsx("option",{value:"",children:"Month"}),KI.map((i,l)=>t.jsx("option",{value:String(l+1),children:i},i))]}),t.jsx("input",{"aria-label":`${e}: year (optional)`,inputMode:"numeric",placeholder:"Year",maxLength:4,value:s.year,onChange:i=>r({...s,year:i.target.value.replace(/\D/g,"")})})]})})}const hq=8e3;function fq(e){return e.kind==="policy"&&e.state==="open"&&String(e.payload.plugin??"")==="memory"&&e.ruleKind==="person"}function mq(e){if(!e.next)return null;const n=e.next.what==="birthday"?"Birthday":"Anniversary",s=e.next.turning===null?"":e.next.what==="birthday"?` · turns ${e.next.turning}`:` · ${e.next.turning} years`;if(e.next.inDays===0)return`${n} today${s}`;if(e.next.inDays===1)return`${n} tomorrow${s}`;if(e.next.inDays<=14)return`${n} in ${e.next.inDays} days${s}`;if(e.next.inDays<=31)return`${n} in ${Math.round(e.next.inDays/7)} weeks`;const r=e[e.next.what];return r?`${n} ${VI(r,!1)}`:null}function AS({name:e,small:n}){return t.jsx("span",{className:"person-face","data-size":n?"sm":void 0,"aria-hidden":"true",children:e.trim().charAt(0).toUpperCase()})}function pq(){var k,j;const e=ge(()=>A.people(),[],6e4),n=ge(()=>A.proposals(),[],6e4),[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=async(v,w)=>{f(v),u(null);try{return await w(),e.reload(),n.reload(),!0}catch(y){return u(y instanceof he?y.message:String(y)),!1}finally{f(null)}},p=(((k=n.data)==null?void 0:k.open)??[]).filter(fq),g=((j=e.data)==null?void 0:j.people)??[],x=v=>[v.relationship,v.birthday?`born ${VI(v.birthday)}`:null].filter(Boolean).join(" · ")||"No details yet";return t.jsxs(ue,{gap:"lg",children:[c?t.jsx(G,{tone:"critical",children:c}):null,p.length>0?t.jsxs(G,{tone:"accent",title:p.length===1?"One person to keep?":`${p.length} people to keep?`,children:[t.jsx("p",{children:"Your agents and your notes name them. Keep them as people and every agent knows who they are; nothing is added until you say so."}),t.jsx(Xe,{flush:!0,children:t.jsx(ct,{children:p.map(v=>{var w;return t.jsx(rt,{lead:t.jsx(AS,{name:String(((w=v.payload.matcher)==null?void 0:w.person)??"?"),small:!0}),title:String(v.payload.action??""),sub:t.jsx("span",{className:"person-from",children:v.why}),side:t.jsxs("span",{className:"person-side",children:[t.jsx($,{variant:"ghost",size:"sm",disabled:h!==null,onClick:()=>void m(`discard:${v.id}`,()=>A.discardProposal(v.id,"Not a person")),children:"Not a person"}),t.jsx($,{size:"sm",disabled:h!==null,onClick:()=>void m(`keep:${v.id}`,()=>A.keepProposal(v.id)),children:"Keep"})]})},v.id)})})}),p.length>1?t.jsx(ne,{align:"end",children:t.jsxs($,{variant:"accent",size:"sm",disabled:h!==null,onClick:()=>void m("keep-all",()=>A.keepAllProposals(p.map(v=>v.id))),children:["Keep all (",p.length,")"]})}):null]}):null,t.jsxs(pe,{title:"People",aside:"every agent knows who they are",panel:!0,flush:!0,actions:t.jsx($,{variant:"accent",size:"sm",onClick:()=>r("new"),children:"Add a person"}),children:[e.data?g.length===0?t.jsx(Ne,{children:"Nobody yet. Tell any agent “Marion is my wife, her birthday is 14 March”, or add someone here. Agents ask before they add anyone you did not tell them about."}):t.jsx(ct,{children:g.map(v=>{const w=mq(v);return t.jsx(rt,{label:`${v.name}: edit`,onClick:()=>r(v),lead:t.jsx(AS,{name:v.name}),title:v.name,sub:x(v),side:t.jsxs("span",{className:"person-side",children:[w?t.jsx(Ae,{tone:v.next&&v.next.inDays<=7?"accent":void 0,children:w}):null,v.reminders?t.jsx("span",{className:"person-bell",title:"Reminders on","aria-label":"Reminders on",children:t.jsx(oe,{name:"bell",size:14})}):null]})},v.id)})}):t.jsx(Ne,{children:e.error??"Loading…"}),t.jsx("p",{className:"person-note",children:"Agents read each person in one line: name, who they are to you, how to address them, their dates. Notes are read only when an agent looks the person up."})]}),s?t.jsx(gq,{person:s==="new"?null:s,onClose:()=>r(null),onSaved:()=>{r(null),e.reload()},onForget:v=>{r(null),i(v)}}):null,a?t.jsx(Ye,{title:`Forget ${a.name}?`,onClose:()=>i(null),foot:t.jsxs(ne,{children:[t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:()=>i(null),children:"Cancel"}),t.jsx($,{variant:"danger",disabled:h!==null,onClick:()=>{const v=a;m(`forget:${v.id}`,()=>A.forgetPerson(v.id)).then(w=>{i(null),w&&o({id:Date.now(),person:v})})},children:"Forget"})]}),children:t.jsxs("p",{children:["Every agent stops knowing who ",a.name," is",a.reminders!==null?", and the reminders for their dates are removed":"",". Notes that mention them stay in Notes."]})}):null,l?t.jsx(iu,{title:`Forgot ${l.person.name}.`,duration:hq,onUndo:()=>{const v=l.person;m(`restore:${v.id}`,()=>A.restorePerson(v.id))},onGone:()=>o(null)},l.id):null]})}function gq({person:e,onClose:n,onSaved:s,onForget:r}){const[a,i]=d.useState((e==null?void 0:e.name)??""),[l,o]=d.useState((e==null?void 0:e.relationship)??""),[c,u]=d.useState((e==null?void 0:e.addressAs)??""),[h,f]=d.useState(rf(e==null?void 0:e.birthday)),[m,p]=d.useState(rf(e==null?void 0:e.anniversary)),[g,x]=d.useState((e==null?void 0:e.notes)??""),[k,j]=d.useState((e==null?void 0:e.reminders)===!0),[v,w]=d.useState(!1),[y,N]=d.useState(null),b=af(h),S=af(m),C=b==="incomplete"||S==="incomplete",T=b!==null&&b!=="incomplete"||S!==null&&S!=="incomplete",E=async()=>{if(!C){w(!0),N(null);try{const R=M=>M.trim()===""?null:M.trim();await A.savePerson({...e?{id:e.id}:{},name:a.trim(),relationship:R(l),addressAs:R(c),birthday:b,anniversary:S,notes:R(g),reminders:T&&k}),s()}catch(R){N(R instanceof he?R.message:String(R))}finally{w(!1)}}};return t.jsx(Ye,{title:e?e.name:"Add a person",onClose:n,foot:t.jsxs(ne,{children:[e?t.jsx($,{variant:"danger-ghost",disabled:v,onClick:()=>r(e),children:"Forget…"}):null,t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:v||a.trim()===""||C,onClick:()=>void E(),children:v?"Saving…":"Save"})]}),children:t.jsxs(ue,{gap:"lg",children:[t.jsxs(Es,{children:[t.jsx(ie,{label:"Name",children:t.jsx("input",{value:a,maxLength:80,placeholder:"Marion",autoFocus:!e,onChange:R=>i(R.target.value)})}),t.jsx(ie,{label:"Who they are to you",children:t.jsx("input",{value:l,maxLength:60,placeholder:"wife, brother, accountant…",onChange:R=>o(R.target.value)})})]}),t.jsx(ie,{label:"How to address them",hint:"What agents call them when they write to you about them, or to them for you.",children:t.jsx("input",{value:c,maxLength:80,placeholder:a.trim()||"Mum, Dr Lee…",onChange:R=>u(R.target.value)})}),t.jsx(_v,{label:"Birthday",hint:"The year is optional.",value:h,onChange:f}),t.jsx(_v,{label:"Anniversary",hint:"A wedding, the day you met: the year is optional.",value:m,onChange:p}),t.jsx(ie,{label:"Notes",hint:"Gift ideas, allergies, what they are into. Read when an agent looks them up.",children:t.jsx("textarea",{rows:3,maxLength:1e3,value:g,onChange:R=>x(R.target.value)})}),t.jsxs("div",{className:"person-remind","data-off":T?void 0:"true",children:[t.jsxs("div",{className:"person-remind-text",children:[t.jsx("div",{className:"person-remind-title",children:"Remind me of their dates"}),t.jsx("div",{className:"ui-field-hint",children:T?"A week before and on the day, from the front desk, with an offer to find something.":"Add a birthday or an anniversary first."})]}),t.jsx(Tu,{checked:T&&k,disabled:!T,onChange:j,label:"Remind me of their dates"})]}),y?t.jsx(G,{tone:"critical",children:y}):null]})})}const xq=["fact","observation","todo"];function GI({embedded:e,agents:n,timezone:s,agentId:r,initialTab:a="people"}){const{data:i,error:l,reload:o}=ge(()=>A.memory(r),[r],3e4),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,x]=d.useState(a),k=S=>{var C;return S==="shared"?"Everyone":((C=n.find(T=>T.id===S))==null?void 0:C.name)??S},j=async S=>{p(null);try{await S,o()}catch(C){p(C instanceof he?C.message:String(C))}},v={nameOf:k,timezone:s,onChangePreference:S=>u({key:S.key,scope:S.scope}),onForgetPreference:S=>void j(A.forgetPreference({key:S.key,scope:S.scope})),onEditNote:S=>f(S),onForgetNote:S=>void j(A.forgetNote(S.id))},w=r?k(r):"",y=r&&i?{preferences:i.preferences.filter(S=>S.scope===r),notes:i.notes.filter(S=>S.scope===r)}:null,N=r&&i?{preferences:i.preferences.filter(S=>S.scope==="shared"),notes:i.notes.filter(S=>S.scope==="shared")}:null,b=t.jsx($,{variant:"accent",size:"sm",onClick:()=>u({key:"",scope:r??"shared"}),children:"Add a preference"});return t.jsxs(gs,{embedded:e,title:"Memory",lede:"What your agents have kept about you. Correct anything here; they see the change on their next turn.",children:[t.jsx(ae,{message:l??m}),y&&N?t.jsxs(ue,{gap:"lg",children:[t.jsx(pe,{title:"Preferences",aside:`what you told ${w} alone`,actions:b,panel:!0,flush:!0,children:t.jsx(Zp,{preferences:y.preferences,empty:`Nothing stated to ${w} alone yet.`,...v})}),t.jsx(pe,{title:"Notes",aside:`what ${w} wrote down for itself`,panel:!0,flush:!0,children:t.jsx(eg,{notes:y.notes,empty:`${w} has kept no private notes yet.`,...v})}),t.jsx(Zt,{summary:`Shared with every agent, which ${w} also reads · ${N.preferences.length} preferences, ${N.notes.length} notes`,children:t.jsxs(ue,{gap:"lg",children:[t.jsx(pe,{title:"Shared preferences",panel:!0,flush:!0,children:t.jsx(Zp,{preferences:N.preferences,empty:"No shared preferences.",...v})}),t.jsx(pe,{title:"Shared notes",panel:!0,flush:!0,children:t.jsx(eg,{notes:N.notes,empty:"No shared notes.",...v})})]})})]}):t.jsxs(ue,{gap:"lg",children:[t.jsx(Co,{label:"Memory",children:[["people","People"],["preferences","Preferences",i==null?void 0:i.preferences.length],["notes","Notes",i==null?void 0:i.notes.length]].map(([S,C,T])=>t.jsx(Ki,{href:`${Fe("memory")}?tab=${S}`,active:g===S,...T?{count:T}:{},onClick:E=>{E.preventDefault(),x(S)},children:C},S))}),g==="people"?t.jsx(pq,{}):null,g==="preferences"?t.jsx(pe,{title:"Preferences",aside:"what you said you want, one current value each",actions:b,panel:!0,flush:!0,children:i?t.jsx(Zp,{preferences:i.preferences,empty:'Nothing stated yet. Tell any agent "from now on…" or add one here.',...v}):t.jsx(Ne,{children:"Loading…"})}):null,g==="notes"?t.jsx(pe,{title:"Notes",aside:"what an agent wrote down, with who wrote it",panel:!0,flush:!0,children:i?t.jsx(eg,{notes:i.notes,empty:"No notes yet. An agent writes one when you state something durable about your life.",...v}):t.jsx(Ne,{children:"Loading…"})}):null]}),c?t.jsx(vq,{agents:n,existing:(i==null?void 0:i.preferences)??[],initial:c,onClose:()=>u(null),onSave:async S=>{await j((async()=>{await A.setPreference(S),c.key===S.key&&c.scope!==S.scope&&await A.forgetPreference({key:c.key,scope:c.scope})})()),u(null)}}):null,h?t.jsx(jq,{note:h,agents:n,onClose:()=>f(null),onSave:S=>j(A.updateNote(h.id,S)).then(()=>f(null))}):null]})}function Zp({preferences:e,empty:n,nameOf:s,onChangePreference:r,onForgetPreference:a}){return e.length===0?t.jsx(Ne,{children:n}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Preference"}),t.jsx("th",{children:"Value"}),t.jsx("th",{children:"Who sees it"}),t.jsx("th",{className:"num",children:"Since"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:e.map(i=>t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:i.key}),t.jsx("td",{children:i.value}),t.jsx("td",{children:t.jsx(YI,{scope:i.scope,name:s(i.scope)})}),t.jsxs("td",{className:"num muted",title:i.updatedAt??"",children:[i.updatedAt?Ge(i.updatedAt,Date.now()):"",i.revision>1?` · rev ${i.revision}`:""]}),t.jsx("td",{className:"num",children:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",onClick:()=>r(i),title:"Store a new value for this key",children:"Change"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a(i),children:"Forget"})]})})]},`${i.scope}:${i.key}`))})]})}function eg({notes:e,empty:n,nameOf:s,timezone:r,onEditNote:a,onForgetNote:i}){return e.length===0?t.jsx(Ne,{children:n}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Note"}),t.jsx("th",{children:"Kind"}),t.jsx("th",{children:"Who sees it"}),t.jsx("th",{children:"Written by"}),t.jsx("th",{className:"num",children:"When"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:e.map(l=>t.jsxs("tr",{children:[t.jsx("td",{className:"memory-note",children:l.content}),t.jsx("td",{children:t.jsx(Ae,{tone:l.kind==="todo"?"warning":l.kind==="fact"?"good":void 0,children:l.kind})}),t.jsx("td",{children:t.jsx(YI,{scope:l.scope,name:s(l.scope)})}),t.jsx("td",{className:"muted",children:l.createdByAgent?s(l.createdByAgent):""}),t.jsxs("td",{className:"num muted",title:l.createdAt??"",children:[l.createdAt?Ge(l.createdAt,Date.now()):"",l.expiresAt?t.jsxs("span",{className:"memory-expires",children:[" · until ",wr(new Date(l.expiresAt),r,{year:!0,compact:!0})]}):null]}),t.jsx("td",{className:"num",children:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",onClick:()=>a(l),children:"Edit"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(l),children:"Forget"})]})})]},l.id))})]})}function YI({scope:e,name:n}){return t.jsx(Ae,{tone:e==="shared"?"accent":void 0,title:e==="shared"?"Every agent reads this":`Only ${n} reads this`,children:n})}function qI({value:e,agents:n,onChange:s}){return t.jsxs("select",{value:e,onChange:r=>s(r.target.value),children:[t.jsx("option",{value:"shared",children:"Everyone"}),n.map(r=>t.jsxs("option",{value:r.id,children:["Only ",r.name]},r.id))]})}function vq({agents:e,existing:n,initial:s,onClose:r,onSave:a}){const i=n.find(v=>v.key===s.key&&v.scope===s.scope),[l,o]=d.useState(s.key),[c,u]=d.useState((i==null?void 0:i.value)??""),[h,f]=d.useState(s.scope),[m,p]=d.useState(!1),g=l.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),x=n.find(v=>v.key===g&&v.scope===h),k=!i||g!==i.key||c.trim()!==i.value||h!==i.scope,j=g!==""&&c.trim()!==""&&k;return t.jsx(Ye,{title:"A preference",onClose:r,children:t.jsxs(ue,{children:[t.jsx(G,{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.'}),t.jsx(ie,{label:"Key",hint:g&&g!==l?`Stored as ${g}`:"Short and stable, like reporting_currency or tone.",children:t.jsx("input",{value:l,autoFocus:s.key==="",onChange:v=>o(v.target.value),placeholder:"reporting_currency"})}),t.jsx(ie,{label:"Value",children:t.jsx("textarea",{rows:3,value:c,maxLength:2e3,autoFocus:s.key!=="",onChange:v=>u(v.target.value),placeholder:"EUR"})}),t.jsx(ie,{label:"Who should know",hint:"Shared reaches every agent. Private stays with one.",children:t.jsx(qI,{value:h,agents:e,onChange:f})}),x&&x!==i?t.jsxs(G,{tone:"warning",children:['This replaces the value already stored for this key here, "',x.value,'" (revision ',x.revision,")."]}):null,i&&h!==i.scope?t.jsxs(G,{children:["It moves: the copy for ",i.scope==="shared"?"everyone":"that agent"," is retired and this one takes over."]}):null,t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!j||m,onClick:()=>{p(!0),a({key:g,value:c.trim(),scope:h}).finally(()=>p(!1))},children:i?"Save change":"Save"})]})]})})}function jq({note:e,agents:n,onClose:s,onSave:r}){var p;const[a,i]=d.useState(e.content),[l,o]=d.useState(e.scope),[c,u]=d.useState(e.kind),[h,f]=d.useState(!1),m=a.trim()!==e.content||l!==e.scope||c!==e.kind;return t.jsx(Ye,{title:"A note",onClose:s,children:t.jsxs(ue,{children:[t.jsx(ie,{label:"What it says",hint:"One sentence that makes sense months from now, on its own.",children:t.jsx("textarea",{rows:4,value:a,maxLength:2e3,autoFocus:!0,onChange:g=>i(g.target.value)})}),t.jsxs(Es,{children:[t.jsx(ie,{label:"Kind",children:t.jsx("select",{value:c,onChange:g=>u(g.target.value),children:xq.map(g=>t.jsx("option",{value:g,children:g},g))})}),t.jsx(ie,{label:"Who sees it",children:t.jsx(qI,{value:l,agents:n,onChange:o})})]}),e.createdByAgent?t.jsxs("p",{className:"muted",children:["Written by ",((p=n.find(g=>g.id===e.createdByAgent))==null?void 0:p.name)??e.createdByAgent,e.createdAt?`, ${Ge(e.createdAt,Date.now())}`:"",". Editing keeps that record."]}):null,t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!m||a.trim()===""||h,onClick:()=>{f(!0);const g={};a.trim()!==e.content&&(g.content=a.trim()),l!==e.scope&&(g.scope=l),c!==e.kind&&(g.kind=c),r(g).finally(()=>f(!1))},children:"Save"})]})]})})}const lf="host.exec",wq={bundle:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M3.4 6.4 10 3.2l6.6 3.2v7.2L10 16.8l-6.6-3.2Z"}),t.jsx("path",{d:"M3.4 6.4 10 9.6l6.6-3.2M10 9.6v7.2"})]})],folder:[16,1.5,t.jsx("path",{d:"M2.2 4.4a1 1 0 0 1 1-1h3l1.4 1.6h5.2a1 1 0 0 1 1 1v6.6a1 1 0 0 1-1 1H3.2a1 1 0 0 1-1-1Z"})],doc:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M4.4 1.9h4.8l3 3v8.2a1 1 0 0 1-1 1H4.4a1 1 0 0 1-1-1V2.9a1 1 0 0 1 1-1Z"}),t.jsx("path",{d:"M9 2v3h3"})]})],script:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"1.9",y:"2.6",width:"12.2",height:"10.8",rx:"1.4"}),t.jsx("path",{d:"m4.6 6.4 2 1.6-2 1.6M8.4 10h3"})]})],font:[16,1.5,t.jsx("path",{d:"M3.4 13 8 3l4.6 10M5 9.6h6"})],image:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("rect",{x:"2",y:"2.6",width:"12",height:"10.8",rx:"1.4"}),t.jsx("circle",{cx:"5.8",cy:"6.2",r:"1.2"}),t.jsx("path",{d:"m2.4 12 3.8-3.6 2.6 2.4 2-1.8 3 2.6"})]})],upload:[20,1.6,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M10 13.2V3.6M6.2 7.2 10 3.4l3.8 3.8"}),t.jsx("path",{d:"M3.6 12.6v2.6a1.4 1.4 0 0 0 1.4 1.4h10a1.4 1.4 0 0 0 1.4-1.4v-2.6"})]})],shield:[16,1.5,t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M8 1.8 13 3.6v4c0 3-2.1 5.4-5 6.6-2.9-1.2-5-3.6-5-6.6v-4Z"}),t.jsx("path",{d:"m5.8 8 1.6 1.6 2.8-3"})]})]};function qa({name:e,size:n}){const[s,r,a]=wq[e];return t.jsx("svg",{width:n??s,height:n??s,viewBox:`0 0 ${s} ${s}`,"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",children:a})}function By({size:e}){return t.jsx("span",{className:"ui-app-icon","data-size":e,"aria-hidden":"true",children:t.jsx(qa,{name:"bundle",size:e?22:18})})}const yq={skill:"doc",script:"script",font:"font",image:"image",data:"doc",template:"doc",other:"doc"},bq={skill:"The skill",script:"Script",font:"Font",image:"Picture",data:"Data",template:"Template",other:"File"};function kq(e){const n=[],s=new Set,r=[...e].sort((a,i)=>a.path==="SKILL.md"?-1:i.path==="SKILL.md"?1:a.path.localeCompare(i.path));for(const a of r){const i=a.path.split("/");i.slice(0,-1).forEach((l,o)=>{const c=i.slice(0,o+1).join("/");s.has(c)||(s.add(c),n.push({dir:c,name:`${i[o]}/`,depth:o}))}),n.push({file:a,name:i[i.length-1],depth:i.length-1})}return n}function QI({files:e,selected:n,onSelect:s}){return t.jsx("ul",{className:"skb-tree",role:s?"listbox":void 0,"aria-label":"Files in the bundle",children:kq(e).map(r=>"dir"in r?t.jsxs("li",{className:"skb-node","data-dir":"true","data-depth":Math.min(r.depth,6),children:[t.jsx(qa,{name:"folder",size:14}),t.jsx("span",{className:"skb-name",children:r.name})]},`d:${r.dir}`):t.jsxs("li",{className:"skb-node","data-depth":Math.min(r.depth,6),"data-kind":r.file.kind,"data-selected":n===r.file.path?"true":void 0,role:s?"option":void 0,"aria-selected":s?n===r.file.path:void 0,tabIndex:s?0:void 0,onClick:s?()=>s(r.file.path):void 0,onKeyDown:s?a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),s(r.file.path))}:void 0,children:[t.jsx(qa,{name:yq[r.file.kind],size:14}),t.jsx("span",{className:"skb-name",title:r.file.path,children:r.name}),r.file.kind==="script"?t.jsx("span",{className:"skb-flag",children:r.file.setup?"setup":"script"}):null,t.jsx("span",{className:"skb-size",children:Mr(r.file.size)})]},r.file.path))})}function Nq(e,n){const s=e.setup?"A setup script. It didn’t run when you uploaded the bundle and never runs on its own. ":"";return n.untrusted?`${s}It can’t run until you mark the bundle as yours. Then it runs only when an agent you allow runs it with ${lf}, and asks you first.`:n.run.length?`${s}It runs only when ${ri(n.run)} ${n.run.length>1?"run":"runs"} it with ${lf}, and asks you first. It can read this bundle’s files, not change them.`:n.held?`${s}Nobody holding this skill can run scripts, so it never runs.`:`${s}It runs only when an agent you allow runs it, and asks you first. It can read the bundle’s files, not change them.`}function JI({file:e,skillView:n,read:s,imageUrl:r,reach:a}){const[i,l]=d.useState(null);if(d.useEffect(()=>{if(e.kind==="skill")return;let c=!0;return l({path:e.path}),s(e.path).then(u=>{c&&l({path:e.path,file:u.file})},u=>{c&&l({path:e.path,error:u instanceof he?u.message:String(u)})}),()=>{c=!1}},[e.path,e.kind]),e.kind==="skill")return t.jsx("div",{className:"skb-view",children:n});const o=(i==null?void 0:i.path)===e.path?i.file:void 0;return t.jsxs("div",{className:"skb-view",children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsxs("span",{className:"skb-view-kind",children:[bq[e.kind]," · ",Mr(e.size)]}),t.jsx("span",{className:"skills-file mono",children:e.path})]}),e.kind==="script"?t.jsxs("p",{className:"skb-script-note",children:[t.jsx(qa,{name:"shield",size:14}),t.jsx("span",{children:Nq(e,a)})]}):null,i!=null&&i.error?t.jsx(ae,{message:i.error}):e.kind==="font"?t.jsxs("div",{className:"skb-blank",children:[t.jsx(qa,{name:"font",size:20}),t.jsx("span",{children:"A font. The skill’s scripts or documents set text with it; there’s nothing to read here."})]}):e.kind==="image"&&(o!=null&&o.image)?t.jsx("div",{className:"skb-picture",children:t.jsx("img",{src:r(e.path),alt:e.path})}):o?o.binary||o.text===void 0?t.jsxs("div",{className:"skb-blank",children:[t.jsx(qa,{name:"doc",size:20}),t.jsxs("span",{children:["Not text, so there’s nothing to read here. ",Mr(e.size),"."]})]}):t.jsx(zt,{label:e.path,children:o.text}):t.jsx("p",{className:"skills-note",children:"Reading the file…"})]})}function XI({children:e}){return t.jsx("div",{className:"skb-files",children:e})}function ZI({children:e}){return t.jsxs("p",{className:"skb-promise",children:[t.jsx(qa,{name:"shield",size:16}),t.jsx("span",{children:e})]})}const Sq="Up to 20 MB and 500 files. Nothing in it runs when you upload it.";function Cq({initialRefusal:e,onClose:n,onMd:s,onStaged:r}){var x;const[a,i]=d.useState(!1),[l,o]=d.useState(e??null),[c,u]=d.useState(null),[h,f]=d.useState(null),m=d.useRef(null),p=k=>{if(!(!k||c)){if(f(null),/\.md$/i.test(k.name)){s(k);return}if(!/\.zip$/i.test(k.name)){o({kind:"notzip",filename:k.name});return}if(k.size>aW){o({kind:"big",filename:k.name,size:k.size});return}u(k.name),Jt.uploadBundle(k).then(j=>r(j),j=>{u(null),j instanceof KT?o(j.refusal):f(j instanceof he?j.message:String(j))})}},g=l?mW(l):null;return t.jsxs(Ye,{title:"Upload a skill",onClose:n,children:[t.jsx("input",{ref:m,type:"file",accept:".zip,.md,application/zip,text/markdown",hidden:!0,"data-testid":"skill-drop-file",onChange:k=>{var j;p((j=k.target.files)==null?void 0:j[0]),k.target.value=""}}),t.jsxs("div",{className:"skills-sheet skb-drop-sheet",children:[g?t.jsx(G,{tone:"critical",title:g.title,role:"alert",children:t.jsxs("div",{className:"skb-refusal",children:[g.body,(x=g.items)!=null&&x.length?t.jsx("ul",{className:"skb-refused",children:g.items.map(k=>t.jsxs("li",{children:[t.jsx("span",{className:"mono",children:k.path})," ",k.rest]},k.path))}):null]})}):null,t.jsx(ae,{message:h}),t.jsxs("div",{className:"skb-drop","data-over":a?"true":void 0,"data-testid":"skill-drop",onDragOver:k=>{k.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:k=>{var j;k.preventDefault(),i(!1),p((j=k.dataTransfer.files)==null?void 0:j[0])},children:[t.jsx("span",{className:"skb-drop-glyph",children:t.jsx(qa,{name:"upload",size:24})}),t.jsx("span",{className:"skb-drop-title",children:c?`Reading “${c}”…`:a?"Drop to read it":g?"Drop another file here":"Drop a .zip or a .md here"}),t.jsx($,{variant:g?void 0:"accent",disabled:c!==null,onClick:()=>{var k;return(k=m.current)==null?void 0:k.click()},children:g?"Choose another file":"Choose a file"}),t.jsx("span",{className:"skb-drop-limits",children:Sq})]}),t.jsxs("section",{className:"skills-sec skb-shape","aria-label":"What a bundle looks like",children:[t.jsx("h3",{className:"skills-sec-title",children:"What a bundle looks like"}),t.jsxs("dl",{className:"skb-shape-tree",children:[t.jsx("dt",{className:"mono",children:"cover-art-kit/"}),t.jsx("dd",{}),t.jsx("dt",{className:"mono","data-in":"true",children:"SKILL.md"}),t.jsx("dd",{children:"the skill: a name, when it’s used, the steps"}),t.jsx("dt",{className:"mono","data-in":"true",children:"scripts/"}),t.jsx("dd",{children:"run only by an agent you allow, asking first"}),t.jsx("dt",{className:"mono","data-in":"true",children:"assets/"}),t.jsx("dd",{children:"fonts, templates, pictures it reads"})]})]})]})]})}function Eq({checked:e,onChange:n,lead:s,title:r,sub:a}){return t.jsxs("label",{className:"skills-pick-row",children:[t.jsx("input",{type:"checkbox",checked:e,onChange:i=>n(i.target.checked)}),s,t.jsxs("span",{className:"skills-pick-text",children:[t.jsx("span",{className:"skills-pick-title",children:r}),a?t.jsx("span",{className:"skills-pick-sub",children:a}):null]})]})}function $q({staged:e,agents:n,faces:s,onClose:r,onBack:a,onAdded:i}){var b,S;const l=e.files.filter(C=>C.kind==="script"),[o,c]=d.useState(((b=l.find(C=>C.setup))==null?void 0:b.path)??((S=l[0])==null?void 0:S.path)??"SKILL.md"),[u,h]=d.useState([]),[f,m]=d.useState(!1),[p,g]=d.useState(!1),[x,k]=d.useState(null),j=n.filter(C=>C.canRunScripts).map(C=>C.name),v=e.files.find(C=>C.path===o)??e.files[0],w=C=>{Jt.discardBundle(e.id).catch(()=>{}),C()},y=async()=>{g(!0),k(null);try{const{skill:C}=await Jt.acceptBundle(e.id,{agents:u,mine:f});i(C)}catch(C){k(C instanceof he?C.message:String(C)),g(!1)}},N=l.some(C=>C.setup);return t.jsxs(Ye,{size:"wide",title:t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(By,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.filename}),t.jsxs("span",{className:"skills-sheet-by",children:[e.files.length," files · ",Mr(e.size)," unpacked · read, not saved yet"]})]})]}),onClose:()=>w(r),foot:t.jsxs(ne,{children:[t.jsx($,{variant:"ghost",onClick:()=>w(a),children:"Choose another file"}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:()=>w(r),children:"Cancel"}),t.jsx($,{variant:"accent",disabled:p,onClick:()=>void y(),children:"Add the skill"})]}),children:[l.length?t.jsxs(G,{title:`${l.length} script${l.length>1?"s":""} inside. None of them ran.`,children:["They run later only when an agent you allow runs them, after you mark the bundle as yours, and each run asks you first",N?" — setup scripts too.":"."]}):null,t.jsx(ae,{message:x}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec","aria-label":"From its SKILL.md",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"From its SKILL.md"})}),t.jsx(Xt,{items:[{label:"Name",value:e.skill.title},{label:"When it’s used",value:e.skill.description},{label:"First lines",value:t.jsxs("span",{className:"skb-first",children:[e.skill.firstLines,e.skill.firstLines.length>=160?"…":""]})}]})]}),t.jsxs("section",{className:"skills-sec","aria-label":"What’s inside",children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:"What’s inside"}),t.jsxs("span",{className:"skills-sec-aside skills-note",children:[Mr(e.size)," unpacked · ",Mr(e.packed)," as a .zip"]})]}),t.jsxs(XI,{children:[t.jsx(QI,{files:e.files,selected:v.path,onSelect:c}),t.jsx(JI,{file:v,read:C=>Jt.stagedFile(e.id,C),imageUrl:C=>Jt.stagedImageUrl(e.id,C),reach:{run:[],held:!1,untrusted:!1},skillView:t.jsx(Aq,{staged:e})})]}),t.jsx("p",{className:"skills-note",children:"Checked: every file stays inside the bundle, no links, nothing over the limits. Pick a file to read it before you add it."})]}),t.jsxs("section",{className:"skills-sec","aria-label":"Who uses it",children:[t.jsx("header",{className:"skills-sec-head",children:t.jsx("h3",{className:"skills-sec-title",children:"Who uses it"})}),t.jsx("div",{className:"skills-who",children:n.filter(C=>C.writable).map(C=>t.jsx(Eq,{checked:u.includes(C.id),onChange:T=>h(T?[...u,C.id]:u.filter(E=>E!==C.id)),lead:t.jsx(On,{id:C.id,name:C.name,size:"sm",face:s.find(T=>T.id===C.id)}),title:C.name,sub:C.canRunScripts&&l.length?"can run scripts":void 0},C.id))}),t.jsx("p",{className:"skills-note",children:l.length?j.length?`Only ${ri(j)} ${j.length>1?"have":"has"} a tool that runs scripts; the others read the text. You can change this later.`:"No agent has a tool that runs scripts, so they all read the text only. You can change this later.":"You can change this later. With nobody ticked it’s kept and does nothing."})]}),t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:f,onChange:C=>m(C.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:l.length?"I wrote it, or I’ve read it and its scripts and trust them. Otherwise agents read its text as outside text and its scripts can’t run.":"I wrote it, or I’ve read it and trust it. Otherwise agents read its text as outside text."})]})]})})]})]})}function Aq({staged:e}){const[n,s]=d.useState(null);return d.useEffect(()=>{let r=!0;return Jt.stagedFile(e.id,"SKILL.md").then(a=>{r&&s(a.file.text??"")},()=>{r&&s("")}),()=>{r=!1}},[e.id]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx("span",{className:"skb-view-kind",children:"The skill"}),t.jsx("span",{className:"skills-file mono",children:"SKILL.md"})]}),n===null?t.jsx("p",{className:"skills-note",children:"Reading the file…"}):t.jsx(zt,{label:"SKILL.md",children:n})]})}const Tq=5e4,Vi=e=>e instanceof he?e.message:String(e),Rq=e=>n=>{n.stopPropagation(),e==null||e()};function Iq({faces:e,navigate:n,command:s,openSkill:r,openFile:a}){const i=ge(()=>Jt.list(),[]),[l,o]=d.useState(r?{id:r,...a?{file:a}:{}}:null),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,x]=d.useState(null),k=d.useRef(null);d.useEffect(()=>{r&&o({id:r,...a?{file:a}:{}})},[r,a]),d.useEffect(()=>{s&&u(s.kind==="write"?{kind:"write"}:{kind:"drop"})},[s]);const j=N=>{var S;const b=(S=N.target.files)==null?void 0:S[0];N.target.value="",b&&v(b)},v=N=>{if(!/\.md$/i.test(N.name)){f(`“${N.name}” isn’t a .md file. A skill is one Markdown file.`);return}if(N.size>Tq){f(`“${N.name}” is over 50 KB. A skill is a short text.`);return}const b=new FileReader;b.onload=()=>{f(null),u({kind:"upload",file:{name:N.name,size:N.size,...xW(N.name,String(b.result))}})},b.readAsText(N)},w=N=>{p(null),N!==void 0&&x(N),i.reload()};return t.jsxs(t.Fragment,{children:[t.jsx("input",{ref:k,type:"file",accept:".md,text/markdown",hidden:!0,"data-testid":"skill-file",onChange:j}),h?t.jsx(G,{tone:"warning",action:t.jsx($,{size:"sm",onClick:()=>{f(null),u({kind:"drop"})},children:"Pick another file"}),children:h}):null,t.jsx(ae,{message:m}),g?t.jsx(G,{tone:"good",role:"status",children:g}):null,t.jsx(Pq,{view:i,onOpen:N=>o({id:N.id}),onAct:(N,b)=>y(N,b)}),t.jsx(eP,{view:i.data,faces:e,open:l,setOpen:o,dialog:c,setDialog:u,navigate:n,onChanged:w,onFailed:p}),(c==null?void 0:c.kind)==="write"&&i.data?t.jsx(RS,{agents:i.data.agents,faces:e,onClose:()=>u(null),onSaved:N=>{u(null),w(`Saved “${N.title}”.`)}}):null,(c==null?void 0:c.kind)==="drop"?t.jsx(Cq,{onClose:()=>u(null),onMd:N=>{u(null),v(N)},onStaged:N=>u({kind:"zip",staged:N})}):null,(c==null?void 0:c.kind)==="zip"&&i.data?t.jsx($q,{staged:c.staged,agents:i.data.agents,faces:e,onClose:()=>u(null),onBack:()=>u({kind:"drop"}),onAdded:N=>{u(null),w(`Added “${N.title}”.`),o({id:N.id})}}):null,(c==null?void 0:c.kind)==="upload"&&i.data?t.jsx(RS,{agents:i.data.agents,faces:e,upload:c.file,onClose:()=>u(null),onSaved:N=>{u(null),w(`Saved “${N.title}”.`)}}):null]});function y(N,b){x(null),b==="trust"?Jt.trust(N.id).then(()=>w(),S=>p(Vi(S))):b==="download"?GT(N.id):b==="plugin"?n(Fe("plugins")):b==="edit"?(u(null),o({id:N.id,edit:!0})):u({kind:b,id:N.id})}}function Pq({view:e,onOpen:n,onAct:s}){if(!e.data&&e.error)return t.jsx(Ne,{warm:!0,title:"Couldn’t load your skills",action:t.jsx($,{variant:"accent",size:"sm",onClick:e.reload,children:"Try again"}),children:"buddi didn’t answer. Your skill files are untouched."});if(!e.data)return t.jsx(Oq,{});const{skills:r,agents:a}=e.data;return r.length===0?t.jsx(Ne,{warm:!0,title:"No skills yet",children:"A skill teaches an agent one kind of task, in plain words. Write one here, or upload a .md file you already have."}):t.jsx(Xe,{flush:!0,children:cy.map(i=>{const l=r.filter(o=>o.group===i.id);return l.length?t.jsxs("section",{className:"skills-group","aria-label":i.title,children:[t.jsxs("header",{className:"skills-group-head",children:[t.jsx("h3",{className:"skills-group-title",children:i.title}),t.jsx("span",{className:"skills-group-aside",children:i.aside})]}),t.jsx(ct,{children:l.map(o=>t.jsx(Mq,{row:o,agents:a,onOpen:n,onAct:s},o.id))})]},i.id):null})})}function Mq({row:e,agents:n,onOpen:s,onAct:r}){var o,c,u;const a=e.untrusted?["trust","Mark as mine"]:dW(e)?["picker","Choose agents"]:null,i=uW(e,n),l=fW(e,n);return t.jsx(rt,{onClick:()=>s(e),label:`${e.title}: details`,lead:e.bundle?t.jsx(By,{}):t.jsx(Hn,{icon:"files"}),title:e.bundle?t.jsxs("span",{className:"skb-title",children:[e.title,t.jsx(so,{children:"bundle"})]}):e.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:e.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[i," · ",wc(e,n,!0)]}),l?t.jsx("span",{className:"skills-line skb-scripts",children:l}):null,e.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:hy(e,n)}):null]}),side:t.jsxs("span",{className:"skills-side",children:[a?t.jsx($,{size:"sm",onClick:Rq(()=>r(e,a[0])),children:a[1]}):null,t.jsx(ss,{label:`More for ${e.title}`,sheet:{title:e.title,sub:i},items:[{label:"Choose agents…",hint:"Give it or take it away",onSelect:()=>r(e,"picker")},e.editable?{label:e.bundle?"Edit SKILL.md":"Edit text",onSelect:()=>r(e,"edit")}:null,{label:"Download",hint:e.bundle?".zip with its files":".md file",onSelect:()=>r(e,"download")},((o=e.from)==null?void 0:o.kind)==="plugin"?{label:`Open ${uy(e.from.plugin)}`,onSelect:()=>r(e,"plugin")}:null,e.deletable&&((c=e.from)==null?void 0:c.kind)!=="plugin"?"separator":null,e.deletable&&((u=e.from)==null?void 0:u.kind)!=="plugin"?{label:"Delete…",tone:"critical",onSelect:()=>r(e,"delete")}:null]})]})})}function Oq(){return t.jsx(Xe,{flush:!0,children:t.jsxs("div",{className:"skills-group skills-loading","aria-busy":"true","aria-label":"Loading skills",children:[t.jsx("header",{className:"skills-group-head",children:t.jsx("i",{className:"cat-skel-line","data-w":"20"})}),t.jsx(ct,{children:[0,1,2].map(e=>t.jsxs("div",{className:"ui-list-row",children:[t.jsx("span",{className:"ui-app-icon"}),t.jsxs("span",{className:"ui-list-main skills-skel",children:[t.jsx("i",{className:"cat-skel-line","data-w":"40"}),t.jsx("i",{className:"cat-skel-line","data-w":"70"})]})]},e))})]})})}function eP({view:e,faces:n,open:s,setOpen:r,dialog:a,setDialog:i,navigate:l,onChanged:o,onFailed:c}){if(!e)return null;const u=m=>e.skills.find(p=>p.id===m),h=s?u(s.id):void 0,f=a&&"id"in a?u(a.id):void 0;return t.jsxs(t.Fragment,{children:[h?t.jsx(Dq,{row:h,agents:e.agents,faces:n,initialEdit:!!(s!=null&&s.edit),...s!=null&&s.file?{initialFile:s.file}:{},onClose:()=>r(null),onPicker:()=>i({kind:"picker",id:h.id}),onDelete:()=>i({kind:"delete",id:h.id}),onChanged:o,onFailed:c,navigate:l},`${h.id}-${s!=null&&s.edit?"edit":"read"}`):null,(a==null?void 0:a.kind)==="picker"&&f?t.jsx(Lq,{row:f,agents:e.agents,faces:n,onCancel:()=>i(null),onSaved:()=>{i(null),o()}}):null,(a==null?void 0:a.kind)==="delete"&&f?t.jsx(_q,{row:f,agents:e.agents,onCancel:()=>i(null),onDeleted:m=>{i(null),r(null),o(m)}}):null]})}function tP({title:e,sub:n}){return t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(Hn,{icon:"files",size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e}),t.jsx("span",{className:"skills-sheet-by",children:n})]})]})}function ic({title:e,aside:n,children:s}){return t.jsxs("section",{className:"skills-sec","aria-label":e,children:[t.jsxs("header",{className:"skills-sec-head",children:[t.jsx("h3",{className:"skills-sec-title",children:e}),n?t.jsx("span",{className:"skills-sec-aside",children:n}):null]}),s]})}function TS({file:e,body:n,text:s}){const[r,a]=d.useState("read");return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"skills-text-bar",children:[t.jsx(Gt,{label:"Show the text as",value:r,onChange:a,options:[{value:"read",label:"Read"},{value:"source",label:"Source"}]}),t.jsx("span",{className:"skills-file mono",children:e})]}),r==="read"?t.jsx(pr,{className:"wb-md skills-md",text:n}):t.jsx(zt,{label:e,children:s})]})}function Dq({row:e,agents:n,faces:s,initialEdit:r,initialFile:a,onClose:i,onPicker:l,onDelete:o,onChanged:c,onFailed:u,navigate:h}){var Y,B,q,J;const f=ge(()=>Jt.detail(e.id),[e.id,e.updatedAt,e.untrusted,(Y=e.learned)==null?void 0:Y.version]),[m,p]=d.useState(!!r&&e.editable),[g,x]=d.useState(null),[k,j]=d.useState(!1),[v,w]=d.useState(null),[y,N]=d.useState(r?"SKILL.md":a??"SKILL.md"),b=((B=f.data)==null?void 0:B.text)??"",S=qT(wc(e,n)),C=pW(e,n),T=((q=e.from)==null?void 0:q.kind)==="plugin"?uy(e.from.plugin):null,E=Z=>s.find(fe=>fe.id===Z),R=e.bundle??null,M=((J=f.data)==null?void 0:J.bundle)??null,O=(R==null?void 0:R.scripts.length)??0,I=Z=>{var fe;return((fe=n.find(ve=>ve.id===Z))==null?void 0:fe.canRunScripts)===!0},z=QT(e,n).filter(I).map(Z=>Gs(n,Z)),U=async(Z,fe)=>{j(!0),w(null);try{await Z(),fe==null||fe(),c()}catch(ve){w(Vi(ve)),u(Vi(ve))}finally{j(!1)}},D=Z=>{U(()=>Jt.grant(e.id,{agents:fy(e).filter(fe=>fe!==Z)}))},P=()=>{U(()=>Jt.saveText(e.id,g??b),()=>{p(!1),x(null)})},K=()=>{N("SKILL.md"),p(!0)},F=(Z,fe)=>{var ve,Oe;if(R)return O?I(Z)?t.jsxs("span",{className:"skb-can",children:["Can run its scripts with ",t.jsx("span",{className:"mono",children:lf}),", asking each time"]}):"Reads the text only: it has no tool that runs scripts":"Uses the text and its files";if(((ve=e.learned)==null?void 0:ve.by)===Z)return"Proposed it";if(((Oe=e.from)==null?void 0:Oe.kind)==="catalogue"&&e.from.agent===Z)return"Came with it";if(fe==="home")return"In its own folder"},Q=t.jsx("textarea",{className:"skills-editor",value:g??b,onChange:Z=>x(Z.target.value),"aria-label":`Text of ${e.title}`,spellCheck:!1,autoFocus:!0}),_=R&&M?`Bundle · ${M.files.length} files · ${Mr(M.size)} · ${wc(e,n)}`:R?`Bundle · ${R.files+1} files · ${Mr(R.size)} · ${wc(e,n)}`:S,re=(M==null?void 0:M.files.find(Z=>Z.path===y))??(M==null?void 0:M.files[0]);return t.jsxs(Ye,{size:"wide",title:R?t.jsxs("span",{className:"skills-sheet-title",children:[t.jsx(By,{size:"lg"}),t.jsxs("span",{className:"skills-sheet-name",children:[t.jsx("span",{children:e.title}),t.jsx("span",{className:"skills-sheet-by",children:_})]})]}):t.jsx(tP,{title:e.title,sub:S}),onClose:i,foot:m?t.jsxs(ne,{align:"end",children:[t.jsx($,{variant:"ghost",disabled:k,onClick:()=>{p(!1),x(null)},children:"Cancel"}),t.jsx($,{variant:"accent",disabled:k||!f.data,onClick:P,children:R?"Save SKILL.md":"Save"})]}):t.jsxs(ne,{children:[e.deletable&&!T?t.jsx($,{variant:"danger-ghost",onClick:o,children:"Delete…"}):null,t.jsx(ot,{}),t.jsx($,{onClick:()=>GT(e.id),children:R?"Download .zip":"Download"}),e.editable?t.jsx($,{variant:e.untrusted?void 0:"accent",onClick:K,children:R?"Edit SKILL.md":"Edit text"}):null]}),children:[e.untrusted?t.jsxs(G,{tone:"warning",action:t.jsx($,{size:"sm",variant:"accent",disabled:k,onClick:()=>void U(()=>Jt.trust(e.id)),children:"Mark as mine"}),children:[hy(e,n)," Mark it as yours once you’ve read it",O?" and its scripts":"","."]}):null,t.jsx(ae,{message:v}),t.jsxs("div",{className:"skills-sheet",children:[t.jsx(ic,{title:"When it’s used",children:t.jsx("p",{className:"skills-desc",children:e.description})}),t.jsxs(ic,{title:"Used by",aside:t.jsx($,{size:"sm",onClick:l,children:"Change…"}),children:[O?t.jsx(ZI,{children:e.untrusted?"Its scripts can’t run until you mark it as yours. Then they run only when an agent you allow runs them, and ask first. Nothing ran when it was uploaded.":"Scripts run only when an agent you allow runs them, and ask first. Nothing ran when it was uploaded."}):null,e.every?t.jsx(ct,{children:t.jsx(rt,{lead:t.jsx(Hn,{icon:"agents"}),title:dy(e,n),sub:O?z.length?`Now, and any you add later. ${ri(z)} can run its scripts, asking each time.`:"Now, and any you add later. None of them can run its scripts.":"Now, and any you add later."})}):e.holders.length?t.jsx("div",{className:R?"skb-holders":void 0,children:t.jsx(ct,{children:e.holders.map(Z=>{const fe=n.find(ve=>ve.id===Z.agent);return t.jsx(rt,{lead:t.jsx(On,{id:Z.agent,name:(fe==null?void 0:fe.name)??Z.agent,size:"sm",face:E(Z.agent)}),title:t.jsxs(t.Fragment,{children:[(fe==null?void 0:fe.name)??Z.agent," ",t.jsxs("span",{className:"skills-handle",children:["@",(fe==null?void 0:fe.handle)??Z.agent]})]}),sub:F(Z.agent,Z.how),side:Z.how==="home"?void 0:t.jsx($,{size:"sm",variant:"ghost",disabled:k,onClick:()=>D(Z.agent),"aria-label":`Take away from ${(fe==null?void 0:fe.name)??Z.agent}`,children:"Take away"})},Z.agent)})})}):t.jsx("p",{className:"skills-note",children:"No agent uses it yet, so it does nothing. Choose who should."})]}),R?t.jsxs(ic,{title:"Files",aside:M?t.jsxs("span",{className:"skills-note",children:[M.files.length," files · ",Mr(M.size)]}):void 0,children:[!f.data||!M||!re?f.error?t.jsx(ae,{message:f.error}):t.jsx(Ne,{children:"Reading the bundle…"}):t.jsxs(XI,{children:[t.jsx(QI,{files:M.files,selected:re.path,onSelect:m?null:N}),t.jsx(JI,{file:re,read:Z=>Jt.file(e.id,Z),imageUrl:Z=>Jt.imageUrl(e.id,Z),reach:{run:z,held:e.every||e.holders.length>0,untrusted:e.untrusted!==null},skillView:m?Q:t.jsx(TS,{file:CN(e),body:f.data.body,text:b})})]}),t.jsx("p",{className:"skills-note",children:"Read only, except SKILL.md. To change any other file, upload the bundle again."})]}):t.jsxs(ic,{title:"The text",children:[f.data?m?Q:t.jsx(TS,{file:CN(e),body:f.data.body,text:b}):f.error?t.jsx(ae,{message:f.error}):t.jsx(Ne,{children:"Reading the file…"}),m&&C?t.jsx("p",{className:"skills-note",children:C}):null,T?t.jsxs("p",{className:"skills-note",children:["Comes with ",T,", so it’s changed there. To stop an agent using it, take it away above."," ",t.jsx("a",{href:Fe("plugins"),onClick:Z=>{Z.preventDefault(),h(Fe("plugins"))},children:"Open Plugins"})]}):null]})]})]})}function of({checked:e,disabled:n,onChange:s,lead:r,title:a,sub:i}){return t.jsxs("label",{className:"skills-pick-row","data-disabled":n?"true":void 0,children:[t.jsx("input",{type:"checkbox",checked:e,disabled:n,onChange:l=>s(l.target.checked)}),r,t.jsxs("span",{className:"skills-pick-text",children:[t.jsx("span",{className:"skills-pick-title",children:a}),i?t.jsx("span",{className:"skills-pick-sub",children:i}):null]})]})}function nP({label:e,value:n,onChange:s}){return t.jsxs("div",{className:"cat-search",children:[t.jsx(oe,{name:"search",size:16}),t.jsx(hm,{label:e,value:n,placeholder:e,onChange:s})]})}function Lq({row:e,agents:n,faces:s,onCancel:r,onSaved:a}){var N;const[i,l]=d.useState(e.every),[o,c]=d.useState(fy(e)),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),x=u.trim().toLowerCase(),k=n.filter(b=>!x||`${b.name} ${b.handle}`.toLowerCase().includes(x)),j=(b,S)=>c(S?[...o,b]:o.filter(C=>C!==b)),v=((N=e.bundle)==null?void 0:N.scripts.length)??0,w=v?[["Can run its scripts",k.filter(b=>b.canRunScripts)],["Text only",k.filter(b=>!b.canRunScripts)]]:[[null,k]],y=async()=>{m(!0),g(null);try{await Jt.grant(e.id,i?{every:!0,agents:[]}:{agents:o}),a()}catch(b){g(Vi(b))}finally{m(!1)}};return t.jsx(Ut,{title:`Who uses “${e.title}”?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:f,onClick:()=>void y(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[v?t.jsxs(ZI,{children:[v," script",v>1?"s":""," come",v>1?"":"s"," with it. Only an agent with a tool that runs commands can run them, and it asks you each time",e.untrusted?", once you’ve marked it as yours":"","."]}):null,t.jsx(nP,{label:"Find an agent",value:u,onChange:h}),t.jsx(ae,{message:p}),t.jsxs("div",{className:"skills-pick-list",children:[x||!e.shareable?null:t.jsx(of,{checked:i,onChange:l,lead:t.jsx(Hn,{icon:"agents"}),title:"Every agent",sub:v?"Now and later. Scripts still ask each time.":"Now, and any you add later."}),w.map(([b,S])=>S.length?t.jsxs("div",{className:"skills-pick-group",role:b?"group":void 0,"aria-label":b??void 0,children:[b?t.jsxs("div",{className:"skills-pick-group-title",children:[b,b==="Text only"?" · no tool that runs scripts":" · asking you each time"]}):null,S.map(C=>{const T=e.home===C.id,E=(e.shadowedBy??[]).includes(C.id),R=T||E||!C.writable;return t.jsx(of,{checked:!E&&(i||T||o.includes(C.id)),disabled:i||R,onChange:M=>j(C.id,M),lead:t.jsx(On,{id:C.id,name:C.name,size:"sm",face:s.find(M=>M.id===C.id)}),title:t.jsxs(t.Fragment,{children:[C.name," ",t.jsxs("span",{className:"skills-handle",children:["@",C.handle]})]}),sub:T?"Its own skill, in its folder":E?"Has its own skill of this name, and uses that":C.writable?v&&C.canRunScripts?t.jsxs("span",{className:"skb-can",children:["With ",t.jsx("span",{className:"mono",children:lf})]}):void 0:"Ships with buddi, so its file doesn’t change"},C.id)})]},b??"all"):null),k.length?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No agent called “",u.trim(),"”."]})]}),t.jsx("p",{className:"skills-note",children:"Saved in each agent’s file, so the file stays the record."})]})})}function Fq({agent:e,view:n,onCancel:s,onSaved:r}){const a=v=>YT(v,e.id),[i,l]=d.useState(n.skills.filter(a).map(v=>v.id)),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=o.trim().toLowerCase(),g=v=>!p||`${v.title} ${v.description}`.toLowerCase().includes(p),x=v=>v.every||v.home===e.id||!e.writable,k=async()=>{h(!0),m(null);try{for(const v of n.skills){if(x(v))continue;const w=i.includes(v.id);if(w===a(v))continue;const y=fy(v);await Jt.grant(v.id,{agents:w?[...y,e.id]:y.filter(N=>N!==e.id)})}r()}catch(v){m(Vi(v))}finally{h(!1)}},j=n.skills.some(g);return t.jsx(Ut,{title:`Skills ${e.name} uses`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:u||!e.writable,onClick:()=>void k(),children:"Save"})]}),children:t.jsxs("div",{className:"skills-pick",children:[t.jsx(nP,{label:"Find a skill",value:o,onChange:c}),t.jsx(ae,{message:f}),e.writable?null:t.jsxs("p",{className:"skills-note",children:[e.name," ships with buddi, so its file doesn’t change. Ask Agent Father to make it yours first."]}),t.jsxs("div",{className:"skills-pick-list",children:[cy.map(v=>{const w=n.skills.filter(y=>y.group===v.id&&g(y));return w.length?t.jsxs("div",{className:"skills-pick-group",role:"group","aria-label":v.title,children:[t.jsx("div",{className:"skills-pick-group-title",children:v.title}),w.map(y=>t.jsx(of,{checked:i.includes(y.id),disabled:x(y),onChange:N=>l(N?[...i,y.id]:i.filter(b=>b!==y.id)),title:y.title,sub:y.every?a(y)?"Every agent uses it":dy(y,n.agents):y.home===e.id?"Its own skill, in its folder":y.description},y.id))]},v.id):null}),j?null:t.jsxs("p",{className:"skills-note skills-pick-none",children:["No skill matches “",o.trim(),"”."]})]})]})})}function RS({agents:e,faces:n,upload:s,onClose:r,onSaved:a}){const[i,l]=d.useState((s==null?void 0:s.title)??""),[o,c]=d.useState((s==null?void 0:s.description)??""),[u,h]=d.useState((s==null?void 0:s.body)??""),[f,m]=d.useState([]),[p,g]=d.useState(!1),[x,k]=d.useState(!1),[j,v]=d.useState(null),w=i.trim()!==""&&o.trim()!==""&&u.trim()!=="",y=s?`${Math.max(1,Math.round(s.size/1024))} KB`:"",N=async()=>{k(!0),v(null);try{const{skill:b}=await Jt.create({title:i.trim(),description:o.trim(),body:u,agents:f,...s?{upload:{filename:s.name,mine:p}}:{}});a(b)}catch(b){v(Vi(b))}finally{k(!1)}};return t.jsxs(Ye,{size:"wide",title:s?t.jsx(tP,{title:s.name,sub:`${y} · read, not saved yet`}):"Write a skill",onClose:r,foot:t.jsxs(ne,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!w||x,onClick:()=>void N(),children:"Save skill"})]}),children:[t.jsx(ae,{message:j}),t.jsxs("div",{className:"skills-sheet",children:[t.jsxs("section",{className:"skills-sec skills-form",children:[t.jsx(ie,{label:"Name",hint:"Short, like a task: “Weekly money recap”.",children:t.jsx("input",{value:i,onChange:b=>l(b.target.value),autoFocus:!s})}),t.jsx(ie,{label:"When it’s used",hint:"One line. Agents read it to decide when the skill applies.",children:t.jsx("input",{value:o,onChange:b=>c(b.target.value),placeholder:"When I ask about the week’s spending"})}),t.jsx(ie,{label:"The text",hint:"Plain Markdown: steps, rules, what a good answer looks like.",children:t.jsx("textarea",{className:"skills-editor",value:u,onChange:b=>h(b.target.value),spellCheck:!1,placeholder:`1. Total spent this week.
|
|
125
|
-
2. The three biggest charges.
|
|
126
|
-
3. Anything odd.`})})]}),t.jsxs(ic,{title:"Who uses it",children:[t.jsx("div",{className:"skills-who",children:e.map(b=>t.jsx(of,{checked:f.includes(b.id),disabled:!b.writable,onChange:S=>m(S?[...f,b.id]:f.filter(C=>C!==b.id)),lead:t.jsx(On,{id:b.id,name:b.name,size:"sm",face:n.find(S=>S.id===b.id)}),title:b.name},b.id))}),t.jsx("p",{className:"skills-note",children:"You can change this later. With nobody ticked it’s kept and does nothing."})]}),s?t.jsx("section",{className:"skills-sec",children:t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:p,onChange:b=>g(b.target.checked)}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Mark as mine"}),t.jsx("span",{className:"plugins-check-hint",children:"I wrote it, or I’ve read it and trust it. Otherwise agents read it as outside text."})]})]})}):null]})]})}function _q({row:e,agents:n,onCancel:s,onDeleted:r}){const a=ge(()=>Jt.detail(e.id),[e.id]),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=d.useMemo(()=>a.data?gW(e,a.data.onDelete,n):null,[a.data,e,n]),h=async()=>{l(!0),c(null);try{const f=await Jt.remove(e.id);r(`Deleted “${e.title}”.${f.movedTo?" The file is in the trash folder.":f.versionsKept?" Its earlier versions are kept.":""}`)}catch(f){c(Vi(f)),l(!1)}};return t.jsxs(Ut,{title:`Delete “${e.title}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:i||!a.data,onClick:()=>void h(),children:"Delete"})]}),children:[t.jsx(ae,{message:o??a.error}),t.jsx("p",{className:"skills-dialog-text",children:u??"Checking who uses it…"})]})}function zq(e){var n;return((n=cy.find(s=>s.id===e.group))==null?void 0:n.title)??""}function Uq({agentId:e,agentName:n,faces:s=[],navigate:r}){const a=ge(()=>Jt.list(),[e]),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),x=N=>{m(null),g(N??null),a.reload()},k=N=>{Jt.trust(N.id).then(()=>x(),b=>m(b instanceof Error?b.message:String(b)))};if(!a.data)return a.error?t.jsx(Ne,{warm:!0,title:"Couldn’t load the skills",action:t.jsx($,{variant:"accent",size:"sm",onClick:a.reload,children:"Try again"}),children:"buddi didn’t answer. The skill files are untouched."}):t.jsx(Ne,{children:"Loading…"});const j=a.data,v=j.agents.find(N=>N.id===e)??{id:e,handle:e,name:n,writable:!1},w=j.skills.filter(N=>YT(N,e)),y=VT();return t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:f}),p?t.jsx(G,{tone:"good",role:"status",children:p}):null,t.jsx(Xe,{flush:!0,title:"Skills",actions:t.jsxs(t.Fragment,{children:[t.jsxs("a",{className:"skills-all",href:y,onClick:N=>{N.preventDefault(),r(y)},children:["All skills",t.jsx(oe,{name:"chevron-right",size:12})]}),t.jsx($,{size:"sm",onClick:()=>h(!0),children:"Choose skills…"})]}),children:w.length?t.jsx("div",{className:"skills-group",children:t.jsx(ct,{children:w.map(N=>t.jsx(rt,{onClick:()=>l({id:N.id}),label:`${N.title}: details`,lead:t.jsx(Hn,{icon:"files"}),title:N.title,sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"skills-line",children:N.description}),t.jsxs("span",{className:"skills-line skills-meta",children:[zq(N)," · ",N.every?"every agent uses it":wc(N,j.agents,!0)]}),N.untrusted?t.jsx("span",{className:"skills-status","data-tone":"warning",children:hy(N,j.agents)}):null]}),side:t.jsx("span",{className:"skills-side",children:N.untrusted?t.jsx($,{size:"sm",onClick:b=>{b.stopPropagation(),k(N)},children:"Mark as mine"}):t.jsx("span",{className:"skills-chevron","aria-hidden":"true",children:t.jsx(oe,{name:"chevron-right",size:14})})})},N.id))})}):t.jsxs(Ne,{children:[n," uses no skills yet. Choose some, or write one on the Skills page."]})}),t.jsx(eP,{view:j,faces:s,open:i,setOpen:l,dialog:o,setDialog:c,navigate:r,onChanged:x,onFailed:m}),u?t.jsx(Fq,{agent:v,view:j,onCancel:()=>h(!1),onSaved:()=>{h(!1),x()}}):null]})}function sP({timezone:e,embedded:n,agentId:s}){const{data:r,error:a,reload:i}=ge(()=>A.reminders(),[],3e4),l=((r==null?void 0:r.reminders)??[]).filter(h=>!s||h.agentId===s),[o,c]=d.useState(null),u=async h=>{c(null);try{await A.cancelReminder(h),i()}catch(f){c(f instanceof Error?f.message:String(f))}};return t.jsxs(gs,{embedded:n,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:[t.jsx(ae,{message:a??o}),t.jsx(Xe,{flush:!0,children:r?l.length===0?t.jsx(es,{icon:"bell",title:"No reminders",children:"Ask any agent to remind you of something, and it shows up here."}):t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Due"}),t.jsx("th",{children:"Agent"}),t.jsx("th",{children:"Note"}),t.jsx("th",{children:"State"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:l.map(h=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nowrap",children:[mt(h.dueAt,e),t.jsx("div",{className:"sub",children:Ge(h.dueAt)})]}),t.jsx("td",{className:"mono",children:h.agentId}),t.jsxs("td",{children:[h.text,h.context?t.jsx(Zt,{summary:"context",children:t.jsx(zt,{children:Cs(h.context)})}):null]}),t.jsxs("td",{children:[t.jsx(Ru,{state:h.state}),h.cancelReason?t.jsx("div",{className:"sub",children:h.cancelReason}):null]}),t.jsx("td",{children:h.state==="pending"?t.jsx($,{size:"sm",variant:"danger",onClick:()=>u(h.id),children:"Cancel"}):null})]},h.id))})]}):t.jsx(Ne,{children:"Loading…"})})]})}const Bq=/(flux|klein|schnell|qwen[-_]?image|image)/i;function rP(e){return e.kind==="image"||e.kind===void 0&&Bq.test(e.id)}function Wq(e){const n=((e==null?void 0:e.models)??[]).filter(s=>!rP(s));return[...n.filter(s=>s.loaded),...n.filter(s=>!s.loaded)].map(s=>s.id)}function zv(e){return Wq(e)[0]}function Wy(e){return(e==null?void 0:e.detectedContextWindowSource)==="mlxh"}function Hq(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 aP(e){let n=e;try{n=new URL(e).host}catch{}return`mlxh is not answering on ${n}. Start it with \`mlxh serve\`, or \`mlxh service install\` to keep it running.`}const iP="an image model; pick it in the Image plugin, not here";function Hy({accountId:e,label:n,value:s,onChange:r,disabled:a=!1}){const[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),p=d.useRef(0),g=async v=>{if(!e)return;const w=++p.current;c(!0),h("");try{const y=await A.accountModels(e,v);w===p.current&&l(y)}catch(y){w===p.current&&h(y instanceof Error?y.message:"Could not load models. Custom entry is still available.")}finally{w===p.current&&c(!1)}};if(d.useEffect(()=>(l(null),m(!1),h(""),g(!1),()=>{p.current++}),[e]),!e)return t.jsxs(t.Fragment,{children:[t.jsx(ie,{label:n,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:v=>r(v.target.value)})}),t.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 x=(i==null?void 0:i.models)??[],k=!!s&&!x.some(v=>v.id===s),j=[i&&!x.length?"This account returned no models. You can enter a custom model.":null,i!=null&&i.truncated?"Showing the first part of this provider’s list. Custom model entry is available.":null,i?"Uses saved account settings. Listed models may not support every agent tool. Your selection is unchanged until you save.":null].filter(Boolean);return t.jsxs(t.Fragment,{children:[t.jsx(ie,{label:n,children:t.jsxs("select",{value:f?"__buddi_custom__":s,disabled:a,onChange:v=>{v.target.value==="__buddi_custom__"?m(!0):(m(!1),r(v.target.value))},children:[t.jsx("option",{value:"",disabled:!0,children:"Choose a model"}),k&&t.jsxs("option",{value:s,children:[s," (current",i?", not listed":"",")"]}),x.map(v=>t.jsxs("option",{value:v.id,children:[v.name===v.id?v.id:`${v.name} — ${v.id}`,v.isDefault?" (provider default)":"",v.image?` — ${iP}`:""]},v.id)),t.jsx("option",{value:"__buddi_custom__",children:"Custom model…"})]})}),t.jsx($,{disabled:a||o,onClick:()=>void g(!0),children:o?"Loading models…":"Refresh models"}),f&&t.jsx(ie,{label:`Custom ${n.toLowerCase()}`,children:t.jsx("input",{required:!0,maxLength:150,value:s,disabled:a,onChange:v=>r(v.target.value)})}),u&&t.jsx("p",{role:"alert",className:"ui-toolbar-note critical",children:u}),j.length>0&&t.jsx("p",{className:"ui-toolbar-note",children:j.join(" ")})]})}function Kq(e,n){const s=new Set(n),r=[],a=new Set;for(const i of e){for(const o of i.tools)a.add(o.name);const l=i.tools.filter(o=>s.has(o.name));l.length!==0&&(i.glob&&l.length===i.tools.length?r.push(i.glob):r.push(...l.map(o=>o.name)))}return r.push(...n.filter(i=>!a.has(i))),r}function Vq(e,n){return[...e].sort().join(",")===[...n].sort().join(",")}const Gq="This agent will not remember anything between conversations.";function Yq({view:e,chosen:n,onChange:s,disabled:r}){var N;const[a,i]=d.useState(""),[l,o]=d.useState(null),[c,u]=d.useState(()=>new Set),h=b=>u(S=>{const C=new Set(S);return C.has(b)?C.delete(b):C.add(b),C}),f=b=>{i(b),u(new Set)},m=d.useId(),p=new Set(n),g=new Set(e.groups.flatMap(b=>b.tools.filter(S=>S.core).map(S=>S.name))),x=(b,S)=>{const C=S.filter(T=>p.has(T));if(C.length!==0){if(C.some(T=>g.has(T))){o({plugin:b,names:C});return}s(n.filter(T=>!C.includes(T)))}},k=b=>{s([...n,...b.filter(S=>!p.has(S))])},j=a.trim().toLowerCase(),v=(b,S)=>j===""||b.toLowerCase().includes(j)||S.toLowerCase().includes(j),w=e.groups.map(b=>({group:b,tools:b.tools.filter(S=>v(S.name,S.description))})).filter(b=>b.tools.length>0),y=(((N=e.suggested)==null?void 0:N.tools)??[]).filter(b=>!p.has(b.name));return t.jsxs("div",{className:"tool-picker",children:[e.suggested&&y.length>0?t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":`${m}-suggested`,children:[t.jsx("div",{className:"tool-picker-head",children:t.jsx("span",{id:`${m}-suggested`,className:"tool-picker-plugin",children:e.suggested.label})}),t.jsx("ul",{className:"ui-list tool-picker-list","aria-label":e.suggested.label,children:y.map(b=>t.jsxs("li",{className:"ui-list-row",children:[t.jsxs("span",{className:"ui-list-main",children:[t.jsx("span",{className:"ui-list-title mono",children:b.name}),t.jsx("span",{className:"ui-list-sub",children:b.description})]}),t.jsx($,{size:"sm",disabled:r,"aria-label":`Add ${b.name}`,onClick:()=>k([b.name]),children:"Add"})]},b.name))})]}):null,t.jsxs("label",{className:"tool-picker-search",children:[t.jsx("span",{className:"ui-field-label",children:"Find a tool"}),t.jsx("input",{type:"search",value:a,placeholder:"Name or what it does",onChange:b=>f(b.target.value)})]}),w.length===0?t.jsxs(Ne,{children:["No installed tool matches “",a.trim(),"”."]}):null,w.map(({group:b,tools:S})=>{const C=b.tools.filter(I=>I.grantable).map(I=>I.name),T=b.tools.filter(I=>p.has(I.name)).length,E=!!b.glob&&T===b.tools.length,R=`${m}-${b.plugin}`,M=`${m}-${b.plugin}-list`,O=j!==""?!c.has(b.plugin):c.has(b.plugin);return t.jsxs("div",{className:"tool-picker-group",role:"group","aria-labelledby":R,"data-open":O?"true":void 0,children:[t.jsxs("div",{className:"tool-picker-head",children:[t.jsxs("button",{type:"button",className:"tool-picker-toggle","aria-expanded":O,"aria-controls":M,onClick:()=>h(b.plugin),children:[t.jsx(qq,{}),t.jsx("span",{id:R,className:"tool-picker-plugin",children:b.plugin}),t.jsx("span",{className:"muted",children:E?`all ${b.tools.length}`:`${T} of ${b.tools.length} granted`})]}),t.jsx($,{size:"sm",variant:"ghost","aria-label":`All ${b.plugin} tools`,disabled:r||C.every(I=>p.has(I)),onClick:()=>k(C),children:"all"}),t.jsx($,{size:"sm",variant:"ghost","aria-label":`No ${b.plugin} tools`,disabled:r||!C.some(I=>p.has(I)),onClick:()=>x(b.plugin,C),children:"none"})]}),(l==null?void 0:l.plugin)===b.plugin?t.jsx(G,{tone:"warning",role:"alert",children:t.jsxs("div",{className:"tool-picker-confirm",children:[t.jsx("span",{children:Gq}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{size:"sm",onClick:()=>o(null),children:"Keep"}),t.jsx($,{size:"sm",variant:"danger",onClick:()=>{s(n.filter(I=>!l.names.includes(I))),o(null)},children:"Remove"})]})}):null,t.jsx("ul",{id:M,className:"ui-list tool-picker-list",hidden:!O,children:S.map(I=>{const z=`${m}-${I.name}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:z,checked:p.has(I.name),disabled:r||!I.grantable,onChange:U=>U.target.checked?k([I.name]):x(b.plugin,[I.name])}),t.jsxs("label",{htmlFor:z,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[t.jsx("span",{className:"mono",children:I.name}),I.core?t.jsx(Ae,{tone:"accent",children:"core"}):null,I.gated?t.jsx(Ae,{tone:"warning",children:"asks you"}):null]}),t.jsx("span",{className:"ui-list-sub",children:I.grantable?I.description:`${I.description} Granted only by editing the file by hand.`})]})]},I.name)})})]},b.plugin)})]})}function qq(){return t.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:t.jsx("path",{d:"M2.8 4.2 5.5 6.9l2.7-2.7"})})}const _s={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."},La=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function lP(e){let n;try{n=JSON.parse(e.trim())}catch{throw new Error(_s.json)}if(!La(n))throw new Error(_s.json);let s,r=n;if("mcpServers"in n){const u=n.mcpServers;if(!La(u))throw new Error(_s.empty);const h=Object.keys(u);if(h.length===0)throw new Error(_s.empty);if(h.length>1)throw new Error(`It names ${h.length} servers (${h.join(", ")}). Paste one at a time.`);s=h[0];const f=u[s];if(!La(f))throw new Error(_s.url);r=f}if("command"in r)throw new Error(_s.command);if(typeof r.type=="string"&&r.type.toLowerCase()==="sse")throw new Error(_s.sse);const a=typeof r.url=="string"?r.url.trim():"";if(a==="")throw new Error(_s.url);const i=La(r.headers)?Object.entries(r.headers).filter(u=>typeof u[1]=="string"&&u[0].trim()!==""):[],l=i.find(([u])=>u.toLowerCase()==="authorization")??i[0];let o,c=!1;if(l){const[u,h]=l,f=/^(Bearer|Basic)\s+/i.exec(h.trim()),m=f?`${f[1].charAt(0).toUpperCase()}${f[1].slice(1).toLowerCase()} `:"";let p=f?h.trim().slice(f[0].length).trim():h.trim();/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$/i.test(p)&&(c=!0,p=""),o={name:u.trim(),prefix:m,value:p}}return{url:a,...s?{name:s}:{},...o?{header:o}:{},dropped:i.filter(u=>u!==l).map(([u])=>u),placeholder:c}}const kc={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 oP(e){return/TOKEN|KEY|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH/i.test(e)}const cP=/^[A-Za-z_][A-Za-z0-9_]*$/;function Qq(e){return/\$\{[^}]*\}|^\$[A-Z_][A-Z0-9_]*$|^<[^>]+>$|^your[_-]/i.test(e.trim())}function uP(e,n){const s=Qq(n);return{name:e,value:s?"":n,secret:oP(e),placeholder:s}}function dP(e){const n=[];let s="",r=!1,a=null;for(let i=0;i<e.length;i+=1){const l=e[i];if(a==="'"){l==="'"?a=null:s+=l;continue}if(a==='"'){if(l==='"')a=null;else if(l==="\\"&&i+1<e.length&&'"\\$`\n'.includes(e[i+1])){const o=e[++i];o!==`
|
|
127
|
-
`&&(s+=o)}else s+=l;continue}if(l==="\\"){const o=e[i+1];if(o===void 0)continue;if(i+=1,o===`
|
|
128
|
-
`||o==="\r"&&e[i+1]===`
|
|
129
|
-
`){o==="\r"&&(i+=1);continue}s+=o,r=!0;continue}if(l==="'"||l==='"'){a=l,r=!0;continue}if(/\s/.test(l)){r&&(n.push(s),s="",r=!1);continue}s+=l,r=!0}if(a)throw new Error(kc.quote);return r&&n.push(s),n}function Jq(e){const n=dP(e.trim());let s=0;n[s]==="claude"&&(s+=1),n[s]==="mcp"&&(s+=1),n[s]==="add"&&(s+=1);const r=[],a=[];let i="stdio",l,o;const c=h=>{const f=h.indexOf("="),m=f>0?h.slice(0,f).trim():"";if(!cP.test(m))throw new Error(kc.env);r.push(uP(m,h.slice(f+1)))},u=[];for(;s<n.length;s+=1){const h=n[s];if(h==="--"){o=n.slice(s+1);break}const[f,m]=h.startsWith("--")&&h.includes("=")?[h.slice(0,h.indexOf("=")),h.slice(h.indexOf("=")+1)]:[h,void 0];if(f==="-e"||f==="--env"){if(m!==void 0){c(m);continue}let p=!1;for(;s+1<n.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(n[s+1]);)c(n[++s]),p=!0;if(!p)throw new Error(kc.env);continue}if(f==="-s"||f==="--scope"){m===void 0&&(s+=1);continue}if(f==="-t"||f==="--transport"){i=(m??n[++s]??"stdio").toLowerCase();continue}if(f==="-H"||f==="--header"){const p=m??n[++s];p&&a.push(p);continue}if(!(f.startsWith("-")&&l===void 0)){if(l===void 0){l=h;continue}u.push(h)}}if(o===void 0?o=u:u.length>0&&(o=[...u,...o]),i==="http"||i==="sse"||o.length===1&&/^https?:\/\//i.test(o[0])){const h=o[0];if(!h)throw new Error(_s.url);const f={};for(const m of a){const p=m.indexOf(":");p>0&&(f[m.slice(0,p).trim()]=m.slice(p+1).trim())}return{kind:"remote",config:lP(JSON.stringify({mcpServers:{[l??"server"]:{type:i,url:h,headers:f}}}))}}if(!l||o.length===0)throw new Error(kc.claude);return{kind:"program",program:{name:l,command:o[0],args:o.slice(1),env:r}}}function Xq(e){const n=e.trim();if(/^claude\s+mcp\s+add\b/.test(n))return Jq(n);let s;try{s=JSON.parse(n)}catch{throw new Error(_s.json)}if(!La(s))throw new Error(_s.json);let r,a=s;if("mcpServers"in s){const c=s.mcpServers;if(!La(c))throw new Error(_s.empty);const u=Object.keys(c);u.length===1&&La(c[u[0]])&&(r=u[0],a=c[r])}if(!("command"in a))return{kind:"remote",config:lP(n)};const i=typeof a.command=="string"?a.command.trim():"";if(i==="")throw new Error(kc.command);const l=Array.isArray(a.args)?a.args.map(c=>String(c)):[],o=La(a.env)?Object.entries(a.env).filter(([c])=>cP.test(c)).map(([c,u])=>uP(c,String(u??""))):[];return{kind:"program",program:{...r?{name:r}:{},command:i,args:l,env:o}}}function Ky({code:e,label:n="Your code",large:s=!1}){const[r,a]=d.useState(!1),i=async()=>{var l;try{await((l=navigator.clipboard)==null?void 0:l.writeText(e)),a(!0)}catch{}};return t.jsxs(ne,{valign:"end",children:[t.jsx(ie,{label:n,grow:!0,children:t.jsx("input",{readOnly:!0,value:e,"data-code":s?"large":void 0,spellCheck:!1,onFocus:l=>l.currentTarget.select()})}),t.jsx($,{onClick:()=>void i(),children:r?"Copied":"Copy"})]})}function hP(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 Zq="It can delete or destroy something, so it asks you every time and is never remembered.";function eQ(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 fP="buddi-connections",tQ="/connections/callback",nQ="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.",mP="Services and programs your team can use, and the tools each one brings.",Vy=(e,n,s)=>`${e} ${e===1?n:s}`;function IS(e,n){return e.transport==="stdio"?void 0:n.find(s=>Yy(s.url,e.url))}function Gy({connection:e,card:n,size:s}){return n?t.jsx(Hn,{letter:n.name.slice(0,1).toUpperCase(),size:s}):t.jsx(Hn,{icon:(e==null?void 0:e.transport)==="stdio"?"terminal":"globe",size:s})}function pP({connection:e}){const n=hP(e);return t.jsx(Ae,{tone:n.tone,dot:n.dot,children:n.label})}const tg=e=>n=>{n.stopPropagation(),e()},th=[{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"}],gP="buddi.connections.add-way";function sQ(){try{const e=window.localStorage.getItem(gP);return th.some(n=>n.value===e)?e:"address"}catch{return"address"}}function rQ({embedded:e,timezone:n,connection:s}={}){const r=ge(()=>A.connections(),[],3e4),[a,i]=d.useState(null),[l,o]=d.useState(s??null);d.useEffect(()=>{s&&o(s)},[s]);const[c,u]=d.useState(null),[h,f]=d.useState(null),m=r.data,p=b=>{var S;return((S=m==null?void 0:m.agents.find(C=>C.id===b))==null?void 0:S.name)??b},g=n??Intl.DateTimeFormat().resolvedOptions().timeZone,x=(m==null?void 0:m.connections)??[],k=(m==null?void 0:m.catalog)??[],j=k.filter(b=>!x.some(S=>S.transport!=="stdio"&&Yy(b.url,S.url))),v=l?x.find(b=>b.id===l):void 0,w=c?x.find(b=>b.id===c):void 0,y=h?x.find(b=>b.id===h):void 0,N=b=>{o(null),i(b)};return t.jsxs(gs,{embedded:e,title:"Connections",lede:mP,children:[t.jsxs(ue,{gap:"lg",children:[t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(oe,{name:"plug",size:14}),t.jsxs("span",{children:["A connection is a service or program buddi talks to; a plugin is code buddi installs and runs."," ",t.jsx("a",{href:Fe("plugins"),children:"Plugins"})]})]}),!m&&!r.error?t.jsx(Ne,{children:"Reading your connections…"}):null,t.jsx(ae,{message:r.error}),m&&!m.vault?t.jsx(G,{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,m?t.jsx(Xe,{flush:!0,title:"Your connections",tool:x.length>0?Vy(x.length,"connection","connections"):void 0,children:x.length===0?t.jsx(Ne,{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."}):t.jsx("div",{className:"connections-rows",children:t.jsx(ct,{children:x.map(b=>t.jsx(aQ,{connection:b,card:IS(b,k),twin:b.slug!==null&&x.some(S=>S.id!==b.id&&S.name===b.name),onOpen:()=>o(b.id),onFlow:N},b.id))})})}):null,m&&j.length>0?t.jsx(Xe,{title:"Connect a service",children:t.jsx("div",{className:"connections-tiles",children:j.map(b=>t.jsxs("div",{className:"connections-tile",children:[t.jsx(Gy,{card:b}),t.jsxs("span",{className:"connections-tile-main",children:[t.jsx("span",{className:"connections-tile-name",children:b.name}),t.jsx("span",{className:"connections-tile-blurb",children:b.blurb})]}),t.jsx($,{size:"sm",onClick:()=>N({step:"address",card:b}),"aria-label":`Connect ${b.name}`,children:"Connect"})]},b.id))})}):null,m?t.jsx(uQ,{onFlow:b=>N({step:b})}):null]}),v?t.jsx(lQ,{connection:v,card:IS(v,k),agentName:p,timezone:g,onClose:()=>o(null),onFlow:N,onDisconnect:()=>u(v.id),onHolders:()=>f(v.id)}):null,y&&m?t.jsx(oQ,{connection:y,agents:m.agents,onCancel:()=>f(null),onDone:()=>{f(null),r.reload()}},y.id):null,w?t.jsx(cQ,{connection:w,agentName:p,onCancel:()=>u(null),onDone:()=>{u(null),o(null),r.reload()}},w.id):null,a&&m?t.jsx(dQ,{start:a,agents:m.agents,catalog:m.catalog,tokens:m.tokens??m.vault,onClose:()=>{i(null),r.reload()}}):null]})}function aQ({connection:e,card:n,twin:s,onOpen:r,onFlow:a}){const i=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=i?"its tools are not reviewed yet":Vy(e.toolCount,"tool","tools");return t.jsx(rt,{onClick:r,label:`${l}: details`,lead:t.jsx(Gy,{connection:e,card:n}),title:l,sub:t.jsx("span",{className:"connections-sub","data-kind":o?"program":void 0,children:`${c} · ${u}`}),side:t.jsxs("span",{className:"plugins-side",children:[i?t.jsx("span",{className:"connections-act",children:t.jsx($,{size:"sm",variant:"accent",onClick:tg(()=>a({step:e.signedIn?"review":"consent",connection:e})),children:"Finish"})}):e.state==="needs-reconnect"&&e.authKind!=="none"?t.jsx("span",{className:"connections-act",children:t.jsx($,{size:"sm",onClick:tg(()=>a({step:"consent",connection:e,keepGrants:!0})),children:"Sign in"})}):e.state==="needs-review"?t.jsx("span",{className:"connections-act",children:t.jsx($,{size:"sm",onClick:tg(()=>a({step:"review",connection:e,keepGrants:!0})),children:"Review"})}):null,t.jsx(pP,{connection:e}),t.jsx(oe,{name:"chevron-right",size:14})]})})}const iQ={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 lQ({connection:e,card:n,agentName:s,timezone:r,onClose:a,onFlow:i,onHolders:l,onDisconnect:o}){const c=e.state==="pending-review",u=e.transport==="stdio"?e.program:void 0,h=()=>i({step:"consent",connection:e,keepGrants:!0}),f=()=>i({step:"review",connection:e,keepGrants:!0}),m=()=>i({step:e.signedIn?"review":"consent",connection:e});return t.jsxs(Ye,{title:t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Gy,{connection:e,card:n,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsx("span",{children:e.name}),t.jsxs("span",{className:"plugins-sheet-by",children:[u?"A program on this computer":"A service at an address"," · ",t.jsx(pP,{connection:e})]})]})]}),onClose:a,foot:t.jsxs(ne,{children:[t.jsx($,{variant:"danger-ghost",onClick:o,children:"Disconnect…"}),t.jsx(ot,{}),u?t.jsx($,{onClick:()=>i({step:"program",connection:e,keepGrants:!0}),children:"Change"}):null,e.authKind!=="none"&&!c?t.jsx($,{variant:e.state==="needs-reconnect"?"accent":void 0,onClick:h,children:"Reconnect"}):null,c?t.jsx($,{variant:"accent",onClick:m,children:"Finish"}):t.jsx($,{variant:e.state==="needs-review"?"accent":void 0,onClick:f,children:"Review again"})]}),children:[c?t.jsx(G,{children:"Not finished: its tools are not reviewed yet, so no agent can use them."}):null,e.state==="needs-reconnect"?t.jsx(G,{tone:"warning",action:e.authKind!=="none"?t.jsx($,{size:"sm",variant:"accent",onClick:h,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"?t.jsxs(G,{tone:"warning",action:t.jsx($,{size:"sm",variant:"accent",onClick:f,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?t.jsx(G,{tone:"critical",children:u?`It stopped answering at ${mt(e.unreachableSince,r)}; the next call starts it again.`:`Unreachable since ${mt(e.unreachableSince,r)}, retrying.`}):null,u!=null&&u.changedSinceReview?t.jsx(G,{tone:"warning",children:"Its command changed since you reviewed it, so its tools wait until you review it again."}):null,e.phase==="starting"?t.jsx(G,{tone:"accent",role:"status",children:"Starting it… The first start can take a minute or two while it downloads."}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(Xt,{items:[u?{label:"Command",value:t.jsx("span",{className:"connections-line",children:u.line})}:{label:"Address",value:t.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:t.jsx("span",{className:"mono",children:u.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")})}]:[],...u?[]:[{label:"Signs in with",value:iQ[e.authKind]}],{label:"Tools",value:c?"Not reviewed yet":`${Vy(e.toolCount,"tool","tools")}${e.reviewedAt?` · reviewed ${Ge(e.reviewedAt)}`:""}`},...c?[]:[{label:"Held by",value:t.jsxs("span",{className:"connections-holders",children:[t.jsx("span",{children:e.agents.length===0?"No agent holds these tools yet.":e.agents.map(s).join(", ")}),t.jsx($,{size:"sm",onClick:l,"aria-label":"Change who holds it",children:e.agents.length===0?"Give them":"Change"})]})}]]})}),e.stderr&&e.stderr.length>0?t.jsx(pe,{title:"What the program last said",children:t.jsx(zt,{label:"Its last lines on stderr",children:e.stderr.join(`
|
|
130
|
-
`)})}):null,n&&!c?t.jsxs("div",{className:"connections-another",children:[t.jsxs("p",{children:["Another ",n.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."]}),t.jsx($,{size:"sm",onClick:()=>i({step:"address",card:n}),children:"Add another account"})]}):null]})}function oQ({connection:e,agents:n,onCancel:s,onDone:r}){const[a,i]=d.useState(()=>new Set(e.agents)),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=(p,g)=>i(x=>{const k=new Set(x);return g?k.add(p):k.delete(p),k}),f=a.size===e.agents.length&&e.agents.every(p=>a.has(p)),m=async()=>{o(!0),u(null);try{const p=await A.grantConnection(e.id,[...a],!0);p.failed.length>0?u(p.failed.map(g=>`${g.agent}: ${g.message}`).join("; ")):r()}catch(p){u(xr(p))}finally{o(!1)}};return t.jsxs(Ut,{title:`Who holds ${e.name}`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:l,onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:l||f,onClick:()=>void m(),children:"Save"})]}),children:[t.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."}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(p=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(p.id),onChange:g=>h(p.id,g.target.checked)}),t.jsxs("span",{children:[p.name,p.frontDesk?" (front desk)":""]})]},p.id))}),t.jsx(ae,{message:c})]})}function cQ({connection:e,agentName:n,onCancel:s,onDone:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=e.agents.map(n),u=async()=>{i(!0),o(null);try{await A.disconnect(e.id),r()}catch(h){o(xr(h))}finally{i(!1)}};return t.jsxs(Ut,{title:`Disconnect ${e.name}?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:a,onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:a,onClick:()=>void u(),children:"Disconnect"})]}),children:[t.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."]}),t.jsx(ae,{message:l})]})}function uQ({onFlow:e}){const[n,s]=d.useState(sQ),r=th.find(i=>i.value===n)??th[0],a=i=>{s(i);try{window.localStorage.setItem(gP,i)}catch{}};return t.jsx(Xe,{title:"Add your own",actions:t.jsx(Gt,{label:"How to add it",options:th.map(({value:i,label:l})=>({value:i,label:l})),value:n,onChange:a}),children:t.jsxs("div",{className:"connections-add",children:[t.jsx("p",{className:"connections-add-text",children:r.text}),t.jsx($,{variant:"accent",onClick:()=>e(n),children:r.button})]})})}function dQ({start:e,agents:n,catalog:s=[],tokens:r=!0,onClose:a,pollMs:i=2e3}){const[l,o]=d.useState(e.step),[c,u]=d.useState(e.connection),[h,f]=d.useState("unknown"),[m,p]=d.useState(null),[g,x]=d.useState(null),k=(m==null?void 0:m.url)??(c==null?void 0:c.url),j=e.card??s.find(y=>k!==void 0&&Yy(y.url,k)),v=(c==null?void 0:c.name)??(j==null?void 0:j.name)??(m==null?void 0:m.name)??"the service",w=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 t.jsxs(Ye,{title:w,onClose:a,size:"wide",children:[l==="paste"?t.jsx(hQ,{onRead:y=>{y.kind==="program"?(x(y.program),o("program")):(p(y.config),o("address"))}}):null,l==="address"?t.jsx(fQ,{card:j,pasted:m,onDone:(y,N)=>{u(y),N==="none"?o("review"):(f(N),o("consent"))}}):null,l==="program"?t.jsx(yQ,{connection:c,pasted:g,tokens:r,onDone:y=>{var N;x(null),u(y),e.keepGrants&&!((N=y.program)!=null&&N.changedSinceReview)&&y.state!=="pending-review"?a():o("review")}}):null,l==="consent"&&c?t.jsx(gQ,{connection:c,signIn:h,card:j,pasted:m==null?void 0:m.header,placeholder:(m==null?void 0:m.placeholder)??!1,tokens:r,pollMs:i,onSignedIn:y=>{p(null),u(y),e.keepGrants?a():o("review")}}):null,l==="review"&&c?t.jsx(bQ,{connection:c,onKept:y=>{u(y),e.keepGrants?a():o("grant")}}):null,l==="grant"&&c?t.jsx(kQ,{connection:c,agents:n,onDone:a}):null]})}function Yy(e,n){const s=r=>r.trim().replace(/\/+$/,"").toLowerCase();return s(e)===s(n)}function xr(e){return e instanceof Error?e.message:String(e)}function hQ({onRead:e}){const[n,s]=d.useState(""),[r,a]=d.useState(null),i=()=>{try{const l=Xq(n);s(""),a(null),e(l)}catch(l){a(xr(l))}};return t.jsxs("form",{className:"ui-stack",onSubmit:l=>{l.preventDefault(),i()},children:[t.jsxs("p",{children:["Paste the block another app uses for this server, the one with ",t.jsx("span",{className:"mono",children:"mcpServers"}),", or the"," ",t.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."]}),t.jsx(ie,{label:"Config",hint:"A url for a remote server, or a command for a program on this computer.",children:t.jsx("textarea",{className:"mono",rows:8,required:!0,autoFocus:!0,spellCheck:!1,autoComplete:"off",value:n,placeholder:'{ "mcpServers": { "github": { "url": "…", "headers": { "Authorization": "Bearer …" } } } }',onChange:l=>s(l.target.value)})}),t.jsx(ae,{message:r}),t.jsx(ne,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:n.trim()==="",children:"Read it"})})]})}function fQ({card:e,pasted:n,onDone:s}){var m,p;const[r,a]=d.useState((n==null?void 0:n.url)??(e==null?void 0:e.url)??""),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=async()=>{l(!0),c(null);try{const g=await A.addConnection(r.trim(),(e==null?void 0:e.name)??(n==null?void 0:n.name));s(g.connection,g.signIn)}catch(g){c(xr(g))}finally{l(!1)}},h=((m=e==null?void 0:e.auth)==null?void 0:m.recommended)==="token",f=((p=e==null?void 0:e.auth)==null?void 0:p.recommended)==="device"&&e.auth.device!==void 0;return t.jsxs("form",{className:"ui-stack",onSubmit:g=>{g.preventDefault(),u()},children:[e?t.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."]}):t.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."}),t.jsx(ie,{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:t.jsx("input",{required:!0,autoFocus:!e&&!n,spellCheck:!1,value:r,placeholder:"https://",onChange:g=>a(g.target.value)})}),e&&!e.verified?t.jsxs("p",{className:"ui-card-meta",children:["This address is the one ",e.name," published; buddi has not checked it since."]}):null,f?t.jsxs("p",{className:"ui-card-meta",children:[e.name," signs in with a code you type on its site. The next screen shows it."]}):h?t.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?t.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,n!=null&&n.header?t.jsx("p",{className:"ui-card-meta",children:n.placeholder?`Your config has a placeholder where the ${n.header.name} header's token goes. You paste the token itself on the next screen.`:`The ${n.header.name} header from your config waits for the sign-in screen. buddi tries it before it keeps it.`}):null,n&&n.dropped.length>0?t.jsxs("p",{className:"ui-card-meta",children:["buddi sends one header, so ",n.dropped.join(", ")," ",n.dropped.length===1?"was":"were"," left out."]}):null,t.jsx(ae,{message:o}),t.jsx(ne,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:i||r.trim()==="",children:i?"Opening…":"Continue"})})]})}const mQ={device:"Device",oauth:"Sign in",token:"Token",client:"Client id"};function pQ(e,n,s="none"){const r=e==="manual"?["token","client"]:["oauth","token"],a=n?r:r.filter(i=>i!=="token");return s==="first"?["device",...a]:s==="offered"?[...a.filter(i=>i!=="client"),"device",...a.filter(i=>i==="client")]:a}function gQ({connection:e,signIn:n,card:s,pasted:r,placeholder:a,tokens:i,pollMs:l,onSignedIn:o}){var K,F;const[c,u]=d.useState(n),h=(K=s==null?void 0:s.auth)!=null&&K.device?s.auth.recommended==="device"?"first":"offered":"none",f=pQ(c,i,h),m=r!==void 0||h!=="first"&&(e.authKind==="token"||((F=s==null?void 0:s.auth)==null?void 0:F.recommended)==="token"),[p,g]=d.useState(()=>m&&f.includes("token")?"token":f[0]),x=f.includes(p)?p:f[0],[k,j]=d.useState(nQ),[v,w]=d.useState(""),[y,N]=d.useState(null),[b,S]=d.useState(!1),[C,T]=d.useState(null),[E,R]=d.useState(!1),[M,O]=d.useState(null),I=`${location.origin}${tQ}`,z=d.useRef(o);z.current=o,d.useEffect(()=>{if(!E)return;let Q=!1;const _=async()=>{if(!Q){Q=!0;try{z.current(await A.connection(e.id))}catch(J){T(xr(J))}}},re=typeof BroadcastChannel=="function"?new BroadcastChannel(fP):null;re&&(re.onmessage=J=>{var Z;((Z=J.data)==null?void 0:Z.id)===e.id&&_()});let Y;const B=Date.now(),q=async()=>{if(!Q){try{const J=await A.connection(e.id);if((!e.signedIn||e.authKind==="token")&&J.signedIn&&J.authKind==="oauth"){_();return}}catch{}if(Date.now()-B>10*6e4){R(!1),T("The sign-in did not come back within ten minutes. Start it again.");return}Y=window.setTimeout(()=>void q(),l)}};return Y=window.setTimeout(()=>void q(),l),()=>{Q=!0,re==null||re.close(),window.clearTimeout(Y)}},[E,e,l]);const U=async Q=>{var _;S(!0),T(null);try{const{authorizeUrl:re}=await A.connectionConsent(e.id,Q);N(re)}catch(re){re instanceof he&&((_=re.detail)==null?void 0:_.code)==="client-id"?(j(re.message),u("manual"),g("client")):T(xr(re))}finally{S(!1)}};d.useEffect(()=>{x!=="oauth"||y!==null||U()},[x]);const D=Q=>{const _=window.open(Q,"_blank");_?(_.opener=null,O(null)):O(Q),R(!0)},P=Q=>{g(Q),N(null),T(null),R(!1),O(null)};return t.jsxs("div",{className:"ui-stack",children:[f.length>1?t.jsx(Gt,{label:"How to sign in",options:f.map(Q=>({value:Q,label:mQ[Q]})),value:x,onChange:P}):null,x==="oauth"?t.jsxs(t.Fragment,{children:[t.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."]}),b?t.jsxs(Ne,{children:["Getting ",e.name,"’s sign-in page…"]}):null]}):null,x==="client"?t.jsxs(t.Fragment,{children:[t.jsx(G,{tone:"warning",children:k}),t.jsx(ie,{label:"Client id",children:t.jsx("input",{required:!0,spellCheck:!1,value:v,onChange:Q=>{w(Q.target.value),N(null),R(!1)}})}),t.jsxs("p",{className:"ui-card-meta",children:["Its redirect address: ",t.jsx("span",{className:"mono",children:I})]})]}):null,x==="token"?t.jsx(jQ,{connection:e,card:s,pasted:r,placeholder:a,onSignedIn:o}):null,x==="device"?t.jsx(vQ,{connection:e,service:(s==null?void 0:s.name)??e.name,pollMs:l,onSignedIn:o}):null,(x==="oauth"||x==="client")&&E?t.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to say yes on ",e.name,"’s page…"]}):null,(x==="oauth"||x==="client")&&M?t.jsx("p",{children:t.jsxs("a",{href:M,target:"_blank",rel:"noopener noreferrer",children:["Open ",e.name,"’s sign-in page"]})}):null,x==="oauth"||x==="client"?t.jsx(ae,{message:C}):null,x==="oauth"?t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>{y&&D(y)},disabled:y===null,children:E?"Open it again":`Sign in to ${e.name}`})}):null,x==="client"?t.jsx(ne,{align:"end",children:y===null?t.jsx($,{variant:"accent",onClick:()=>void U(v.trim()),disabled:b||v.trim()==="",children:b?"Checking…":"Continue"}):t.jsx($,{variant:"accent",onClick:()=>D(y),children:E?"Open it again":`Open ${e.name}’s sign-in page`})}):null]})}function xQ(e){try{const n=new URL(e);return`${n.host}${n.pathname==="/"?"":n.pathname.replace(/\/$/,"")}`}catch{return e}}function vQ({connection:e,service:n,pollMs:s,onSignedIn:r}){const[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(0),[h,f]=d.useState(null),[m,p]=d.useState(!1),g=d.useRef(r);g.current=r,d.useEffect(()=>{let j=!1,v;i(null),o(null),f(null),p(!1);const w=async()=>{var y,N;if(!j){try{const b=await A.connection(e.id);if(j)return;if(((y=b.device)==null?void 0:y.state)==="done"){g.current(b);return}if(((N=b.device)==null?void 0:N.state)==="failed"){o(b.device.reason??"The sign-in did not finish. Start again.");return}}catch{}v=window.setTimeout(()=>void w(),s)}};return(async()=>{try{const y=await A.connectionDevice(e.id);if(j)return;i({userCode:y.userCode,verificationUri:y.verificationUri}),v=window.setTimeout(()=>void w(),s)}catch(y){j||o(xr(y))}})(),()=>{j=!0,window.clearTimeout(v)}},[e.id,s,c]);const x=j=>{const v=window.open(j,"_blank");p(!0),v?(v.opener=null,f(null)):f(j)},k=a?xQ(a.verificationUri):"";return t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:[a?`Open ${k}, type this code there and say yes.`:`Type a code on ${n}’s site and say yes there.`," buddi keeps the sign-in in its vault and sends it only to"," ",t.jsx("span",{className:"mono",children:e.host}),". No agent ever sees it."]}),a===null&&l===null?t.jsxs(Ne,{children:["Asking ",n," for a code…"]}):null,a&&l===null?t.jsxs(t.Fragment,{children:[t.jsx(Ky,{code:a.userCode,label:`Your code for ${n}`,large:!0}),m?t.jsxs(G,{tone:"accent",role:"status",children:["Waiting for you to approve on ",n,"…"]}):null,h?t.jsx("p",{children:t.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:["Open ",k]})}):null,t.jsx(ne,{align:"end",children:t.jsxs($,{variant:"accent",onClick:()=>x(a.verificationUri),children:["Open ",k]})})]}):null,l!==null?t.jsxs(t.Fragment,{children:[t.jsx(ae,{message:l}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>u(j=>j+1),children:"Start again"})})]}):null]})}function jQ({connection:e,card:n,pasted:s,placeholder:r,onSignedIn:a}){var j,v;const[i,l]=d.useState((s==null?void 0:s.value)??""),[o,c]=d.useState((s==null?void 0:s.name)??"Authorization"),[u,h]=d.useState((s==null?void 0:s.prefix)??(s?"":"Bearer ")),[f,m]=d.useState(!1),[p,g]=d.useState(null),x=async()=>{m(!0),g(null);try{const w=await A.connectionToken(e.id,{token:i.trim(),header:o.trim(),prefix:u});l(""),a(w.connection)}catch(w){g(xr(w))}finally{m(!1)}},k=(j=n==null?void 0:n.auth)==null?void 0:j.tokenPage;return t.jsxs("form",{className:"ui-stack",onSubmit:w=>{w.preventDefault(),x()},children:[t.jsxs("p",{children:[k?`Make a token on ${e.name}’s site and paste it here.`:`Paste a token ${e.name} gave you.`," buddi tries it on"," ",t.jsx("span",{className:"mono",children:e.host})," first, keeps it in its vault, and sends it only there. No agent ever sees it."]}),k?t.jsx("p",{children:t.jsxs("a",{href:k,target:"_blank",rel:"noopener noreferrer",children:["Make a token on ",e.name]})}):null,r?t.jsx(G,{tone:"accent",children:"Your config had a placeholder where the token goes. Paste the token itself."}):null,t.jsx(ie,{label:"Token",hint:(v=n==null?void 0:n.auth)==null?void 0:v.tokenHint,children:t.jsx("input",{type:"password",required:!0,autoFocus:!(s!=null&&s.value),autoComplete:"off",spellCheck:!1,value:i,onChange:w=>l(w.target.value)})}),t.jsxs(Es,{columns:2,dense:!0,children:[t.jsx(ie,{label:"Header",hint:"Most services want Authorization.",children:t.jsx("input",{required:!0,spellCheck:!1,value:o,onChange:w=>c(w.target.value)})}),t.jsx(ie,{label:"Before the token",hint:"Usually “Bearer ”, with its space. Empty for none.",children:t.jsx("input",{spellCheck:!1,value:u,onChange:w=>h(w.target.value)})})]}),t.jsx(ae,{message:p}),t.jsx(ne,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:f||i.trim()===""||o.trim()==="",children:f?"Trying it…":"Try it and keep it"})})]})}function wQ(e){return e!==""&&/^[A-Za-z0-9_@%+=:,./-]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function yQ({connection:e,pasted:n,tokens:s=!0,onDone:r}){const a=e==null?void 0:e.program,i=d.useRef(0),l=()=>(i.current+=1,i.current),[o,c]=d.useState((e==null?void 0:e.name)??(n==null?void 0:n.name)??""),[u,h]=d.useState((a==null?void 0:a.command)??(n==null?void 0:n.command)??""),[f,m]=d.useState(()=>((a==null?void 0:a.args)??(n==null?void 0:n.args)??[]).map(I=>({key:l(),value:I}))),[p,g]=d.useState(()=>a?a.env.map(I=>({key:l(),name:I.name,value:I.value??"",secret:I.secret,kept:I.secret})):((n==null?void 0:n.env)??[]).map(I=>({key:l(),name:I.name,value:I.value,secret:I.secret,kept:!1}))),[x,k]=d.useState(!1),[j,v]=d.useState(null),w=/\s/.test(u.trim())?dP(u.trim()):[u.trim()],y=w[0]??"",N=[...w.slice(1),...f.map(I=>I.value)],b=[y,...N].filter((I,z)=>z>0||I!==""),S=()=>{w.length<2||(h(y),m(I=>[...w.slice(1).map(z=>({key:l(),value:z})),...I]))},C=b.map(wQ).join(" "),T=p.filter(I=>I.secret&&I.value===""&&!I.kept).map(I=>I.name||"a variable"),E=((n==null?void 0:n.env)??[]).filter(I=>I.placeholder).map(I=>I.name),R=(I,z)=>m(U=>U.map(D=>D.key===I?{...D,value:z}:D)),M=(I,z)=>g(U=>U.map(D=>D.key===I?{...D,...z}:D)),O=async()=>{k(!0),v(null);const I={name:o.trim(),command:y,args:N,env:p.filter(z=>z.name.trim()!=="").map(z=>({name:z.name.trim(),value:z.value,secret:z.secret}))};try{r(e?await A.updateProgram(e.id,I):(await A.addProgram(I)).connection),g(z=>z.map(U=>U.secret?{...U,value:""}:U))}catch(z){v(xr(z))}finally{k(!1)}};return t.jsxs("form",{className:"ui-stack",onSubmit:I=>{I.preventDefault(),O()},children:[t.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."}),t.jsxs(Es,{columns:2,children:[t.jsx(ie,{label:"Name",children:t.jsx("input",{required:!0,autoFocus:!n&&!e,maxLength:80,spellCheck:!1,value:o,onChange:I=>c(I.target.value)})}),t.jsx(ie,{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:t.jsx("input",{required:!0,spellCheck:!1,autoComplete:"off",className:"mono",value:u,placeholder:"npx",onChange:I=>h(I.target.value),onBlur:S})})]}),t.jsx(ie,{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:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[f.map((I,z)=>t.jsxs("div",{className:"connections-row",children:[t.jsx("input",{"aria-label":`Argument ${z+1}`,className:"mono",spellCheck:!1,autoComplete:"off",value:I.value,onChange:U=>R(I.key,U.target.value)}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>m(U=>U.filter(D=>D.key!==I.key)),"aria-label":`Remove argument ${z+1}`,children:"Remove"})]},I.key)),t.jsx(ne,{children:t.jsx($,{size:"sm",onClick:()=>m(I=>[...I,{key:l(),value:""}]),children:"Add an argument"})})]})}),t.jsx(ie,{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:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[p.map((I,z)=>t.jsxs("div",{className:"connections-row","data-kind":"env",children:[t.jsx("input",{"aria-label":`Variable ${z+1} name`,className:"mono",spellCheck:!1,autoComplete:"off",placeholder:"NAME",value:I.name,onChange:U=>{const D=U.target.value;M(I.key,I.value===""&&!I.kept?{name:D,secret:oP(D)}:{name:D})}}),t.jsx("input",{"aria-label":`Variable ${z+1} value`,type:I.secret?"password":"text",spellCheck:!1,autoComplete:"off",placeholder:I.kept&&I.value===""?"Kept. Type to replace it.":"value",value:I.value,onChange:U=>M(I.key,{value:U.target.value})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:I.secret,onChange:U=>M(I.key,{secret:U.target.checked,kept:U.target.checked&&I.kept})}),t.jsx("span",{children:"Secret"})]}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>g(U=>U.filter(D=>D.key!==I.key)),"aria-label":`Remove variable ${z+1}`,children:"Remove"})]},I.key)),t.jsx(ne,{children:t.jsx($,{size:"sm",onClick:()=>g(I=>[...I,{key:l(),name:"",value:"",secret:!1,kept:!1}]),children:"Add a variable"})})]})}),E.length>0?t.jsxs(G,{tone:"accent",children:["Your config had a placeholder for ",E.join(", "),". Type the value itself."]}):null,!s&&p.some(I=>I.secret)?t.jsx(G,{tone:"warning",children:"This installation has no vault, so a secret cannot be kept. Turn the vault on first, or switch Secret off."}):null,t.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."}),t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[t.jsx("span",{className:"ui-field-label",children:"It will run"}),t.jsx(zt,{label:"The command line",children:C||"…"})]}),t.jsx(ae,{message:j}),t.jsx(ne,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:x||o.trim()===""||u.trim()===""||T.length>0,title:T.length>0?`Give ${T.join(", ")} a value.`:void 0,children:x?"Saving…":e?"Save":"Continue"})})]})}function bQ({connection:e,onKept:n}){const s=ge(()=>A.connectionReview(e.id),[e.id]),[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=s.data,h=r??(u==null?void 0:u.slug)??"",f=async()=>{var p;if(u){l(!0),c(null);try{n(await A.saveConnectionReview(e.id,{hash:u.hash,...u.slugEditable?{slug:h}:{}}))}catch(g){g instanceof he&&((p=g.detail)==null?void 0:p.code)==="changed"&&s.reload(),c(xr(g))}finally{l(!1)}}};if(!u)return s.error?t.jsx(ae,{message:s.error}):e.transport==="stdio"?t.jsxs(Ne,{children:["Starting ",e.name,"… The first start can take a minute or two while it downloads."]}):t.jsxs(Ne,{children:["Reading what ",e.name," offers…"]});const m=u.tools.filter(p=>p.problem===null).length;return t.jsxs("div",{className:"ui-stack",children:[t.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?t.jsx(G,{tone:"warning",title:"This runs on this computer as you",children:t.jsxs(ue,{gap:"sm",children:[t.jsx(zt,{label:"The command",children:u.program.line}),t.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?t.jsxs("p",{className:"ui-card-meta",children:["Variables: ",u.program.env.map(p=>`${p.name}${p.secret?" (secret)":""}`).join(", ")]}):null]})}):t.jsxs("p",{className:"ui-card-meta",children:["buddi talks to ",t.jsx("span",{className:"mono",children:u.host})," for these tools, and nowhere else."]}),u.annotatedNothing?t.jsxs(G,{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?t.jsxs(G,{tone:"warning",title:`${e.name} changed its tools since your last review.`,children:[t.jsxs("ul",{className:"connections-changes","aria-label":"What changed",children:[u.changes.added.length>0?t.jsxs("li",{children:["New: ",t.jsx("span",{className:"mono",children:u.changes.added.join(", ")})]}):null,u.changes.changed.length>0?t.jsxs("li",{children:["Changed: ",t.jsx("span",{className:"mono",children:u.changes.changed.join(", ")})]}):null,u.changes.removed.length>0?t.jsxs("li",{children:["Gone: ",t.jsx("span",{className:"mono",children:u.changes.removed.join(", ")})]}):null]}),t.jsx("p",{children:"Until you keep this list, the new and changed tools wait; the others keep working."})]}):null,u.slugEditable?t.jsx(ie,{label:"Its name in buddi",hint:`Tools are called mcp.${h||"…"}.<tool>. Lower case, letters, digits, _ and -.`,children:t.jsx("input",{required:!0,spellCheck:!1,maxLength:24,value:h,onChange:p=>a(p.target.value.toLowerCase())})}):null,u.tools.length===0?t.jsxs(Ne,{children:[e.name," lists no tools."]}):t.jsx("div",{className:"ui-list","aria-label":"Tools",children:u.tools.map(p=>{const g=eQ(p),x=u.slugEditable?p.fullName.replace(/^mcp\.[^.]+\./,`mcp.${h||u.slug}.`):p.fullName;return t.jsx("div",{className:"ui-list-row connections-tool",children:t.jsxs("div",{className:"ui-stack","data-gap":"sm",children:[t.jsxs("div",{className:"ui-card-head",children:[t.jsx("span",{className:"mono",children:x}),p.problem?t.jsx(Ae,{tone:"muted",children:"Cannot be used"}):t.jsx(Ae,{tone:g.tone,children:g.label}),p.change==="added"?t.jsx(so,{children:"New"}):p.change==="changed"?t.jsx(so,{children:"Changed"}):null]}),p.description?t.jsx("p",{className:"ui-card-meta",children:p.description}):null,!p.problem&&p.tier==="gated"?t.jsx("p",{className:"ui-card-meta",children:p.destructive?Zq:"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?t.jsxs("p",{className:"ui-card-meta",children:["Left out: ",p.problem,"."]}):null]})},p.name)})}),t.jsx(ae,{message:o}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>void f(),disabled:i||u.slugEditable&&h.trim()==="",children:m===1?"Keep this tool":`Keep these ${m} tools`})})]})}function kQ({connection:e,agents:n,onDone:s}){var k;const r=n.find(j=>j.frontDesk)??n[0],[a,i]=d.useState(()=>new Set(r?[r.id]:[])),o=(((k=ge(()=>A.connectionTools(e.id),[e.id]).data)==null?void 0:k.tools)??[]).filter(j=>j.tier==="gated"),[c,u]=d.useState(()=>new Set),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=(j,v)=>{i(w=>{const y=new Set(w);return v?y.add(j):y.delete(j),y})},x=async()=>{f(!0),p(null);try{const j=await A.grantConnection(e.id,[...a]);if(j.failed.length>0){p(j.failed.map(v=>`${v.agent}: ${v.message}`).join(" "));return}for(const v of j.granted)for(const w of c)await A.setRememberedApproval(v,w,!0);s()}catch(j){p(xr(j))}finally{f(!1)}};return t.jsxs("div",{className:"ui-stack",children:[t.jsxs("p",{children:[r?`Give these tools to ${r.name}?`:"Which agents get these tools?"," Each one you tick gets ",t.jsx("span",{className:"mono",children:e.grant})," on its tools line."]}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Agents",children:n.map(j=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.has(j.id),onChange:v=>g(j.id,v.target.checked)}),t.jsxs("span",{children:[j.name,j.frontDesk?" (front desk)":""]})]},j.id))}),t.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?t.jsxs("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approval",children:[t.jsx("p",{children:"These ask you first. Tick one to remember your approval for the agents above, so it asks only once."}),o.map(j=>t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",disabled:!j.rememberable,checked:c.has(j.tool),onChange:v=>u(w=>{const y=new Set(w);return v.target.checked?y.add(j.tool):y.delete(j.tool),y})}),t.jsx("span",{className:"mono",children:j.tool})]}),j.why?t.jsx("p",{className:"ui-card-meta",children:j.why}):null]},j.tool))]}):null,t.jsx(ae,{message:m}),t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:s,disabled:h,children:"Not now"}),t.jsx($,{variant:"accent",onClick:()=>void x(),disabled:h||a.size===0,children:"Give them"})]})]})}const NQ=(e,n,s)=>`${e} ${e===1?n:s}`;function SQ(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 CQ({agentId:e,agentName:n,readOnly:s,version:r,onSaved:a}){const[i,l]=d.useState({}),o=ge(()=>A.connections().then(w=>(l({}),w)),[r]),[c,u]=d.useState(null),[h,f]=d.useState(null),m=Fe("connections"),p=async(w,y)=>{u(w.id),f(null);try{const N=await A.setConnectionHolder(w.id,e,y);l(b=>({...b,[w.id]:N.held})),a==null||a()}catch(N){f(N instanceof Error?N.message:String(N))}finally{u(null)}},g=o.data,x=(g==null?void 0:g.connections)??[],k=w=>i[w.id]??w.agents.includes(e),j=g?g.agents.some(w=>w.id===e):!0,v=x.filter(k).length;return t.jsxs(pe,{title:"Connections",aside:g&&x.length>0?`holds ${v} of ${x.length} · saved as you change them`:void 0,panel:!0,children:[t.jsx(ae,{message:o.error??h}),g?x.length===0?t.jsxs("p",{className:"ui-card-meta",children:["Nothing is connected yet. ",t.jsx("a",{href:m,children:"Connect a service in Connections"})]}):j?t.jsxs(t.Fragment,{children:[s?t.jsx(G,{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,t.jsx("ul",{className:"ui-list delegate-list","aria-label":`Connections ${n} holds`,children:x.map(w=>{const y=k(w),N=SQ(w),b=w.transport==="stdio"?"on this computer":w.host,S=w.slug?NQ(w.toolCount,"tool","tools"):"tools not reviewed",C=`holds-${e}-${w.id}`;return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",role:"switch",id:C,checked:y,"aria-checked":y,disabled:s||c!==null||N!==null&&!y,onChange:T=>void p(w,T.target.checked)}),t.jsxs("label",{htmlFor:C,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[w.name,N?t.jsxs(t.Fragment,{children:[" ",t.jsx(Ae,{tone:"warning",children:hP(w).label})]}):null]}),t.jsx("span",{className:"ui-list-sub",children:`${b} · ${S}`}),N?t.jsxs("span",{className:"ui-list-sub",children:[N," ",t.jsx("a",{href:m,children:"Open Connections"})]}):null]})]},w.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[n," makes and changes agents, so it holds no connections."]}):o.error?null:t.jsx(Ne,{children:"Loading the connections…"})]})}const EQ=(e,n)=>!!e&&!!n&&e.kind===n.kind&&(e.kind==="mascot"?e.role===n.role:e.kind==="emoji"?e.value===n.value:!0);async function xP(e){const n=await fetch(el(e));if(!n.ok)throw new Error(`The picture could not be read (${n.status}).`);const s=await n.blob();return new File([s],`buddi-blob-${e}.png`,{type:"image/png"})}function $Q({face:e,onPick:n,label:s=L.assistant.face,kept:r,disabled:a,disableEmoji:i,children:l}){return t.jsxs("div",{className:"meet-faces",role:"group","aria-label":s,children:[t.jsxs("div",{className:"meet-face-row",children:[r?t.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:a,onClick:()=>n({kind:"kept",url:r}),children:t.jsx("img",{src:r,alt:""})}):null,j6.map(o=>{const c={kind:"mascot",role:o},u=EQ(e,c);return t.jsx("button",{type:"button",className:"meet-face","data-kind":"image","data-chosen":u?"true":void 0,"aria-pressed":u,"aria-label":L.assistant.mascot(o),disabled:a,onClick:()=>n(c),children:t.jsx("img",{src:el(o),alt:""})},o)})]}),t.jsx("div",{className:"meet-face-row",children:y6.map(o=>{const c=(e==null?void 0:e.kind)==="emoji"&&e.value===o;return t.jsx("button",{type:"button",className:"meet-face","data-chosen":c?"true":void 0,"aria-pressed":c,disabled:a||i,onClick:()=>n({kind:"emoji",value:o}),children:o},o)})}),l]})}const AQ=["mirror","en","fr"],TQ=[{value:"3h",label:"3 hours"},{value:"1d",label:"A day"},{value:"1w",label:"A week"},{value:"never",label:"Never"}],ng=10,sg=500,vP=[{id:"identity",label:"Identity"},{id:"brain",label:"Brain"},{id:"tools",label:"Tools"},{id:"team",label:"Team"}],PS=e=>{var n;return e==="access"?"tools":((n=vP.find(s=>s.id===e))==null?void 0:n.id)??"identity"};function RQ({agentId:e,section:n,navigate:s}){var x,k,j;const{data:r,error:a,reload:i}=ge(()=>A.agents(),[]),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(PS(n));d.useEffect(()=>f(PS(n)),[n]);const m=v=>{f(v),s==null||s(Ft(e,"setup",v))},p=async v=>{o(null),u(null);try{const w=await v;u(w.changed.length===0?`No file change needed. ${w.note}.`:`Changed ${w.changed.join(", ")}. ${w.note}.`),i()}catch(w){o(w instanceof Error?w.message:String(w))}},g=r==null?void 0:r.agents.find(v=>v.id===e);return t.jsxs(ue,{gap:"lg",children:[t.jsx(Co,{level:"secondary",label:"Setup",children:vP.map(v=>t.jsx(Ki,{href:Ft(e,"setup",v.id),active:h===v.id,onClick:w=>{w.preventDefault(),m(v.id)},children:v.label},v.id))}),t.jsx(ae,{message:a??l}),c?t.jsx(G,{tone:"good",role:"status",children:c}):null,r?g?t.jsx(IQ,{agent:g,all:r.agents,engine:r.engines.find(v=>v.id===g.id),providers:r.providers,accounts:r.providerAccounts,shown:h,onShow:m,onRun:p,onSaved:i},`${g.id}:${(x=r.engines.find(v=>v.id===g.id))==null?void 0:x.model}:${(j=(k=r.providerAccounts)==null?void 0:k.bindings.find(v=>v.agentId===g.id))==null?void 0:j.accountId}`):t.jsx(Ne,{children:"This agent is not installed as a file."}):t.jsx(Ne,{children:"Loading…"})]})}function IQ({agent:e,all:n,engine:s,providers:r,accounts:a,shown:i,onShow:l,onRun:o,onSaved:c}){const u=(s==null?void 0:s.provider)??e.provider.kind,h=r.find(b=>b.kind===u),f=(s==null?void 0:s.model)??e.model,[m,p]=d.useState(String((s==null?void 0:s.maxTurns)??e.maxTurns)),[g,x]=d.useState(null),k=b=>{o(A.setAgentEngine(e.id,b))},j=b=>{const S=r.find(C=>C.kind===b);k({provider:b,model:(S==null?void 0:S.defaultModel)??f})},v=(h==null?void 0:h.models.map(b=>b.id))??[],w=v.includes(f)?v:[f,...v],y=s?s.available:!0,N=(s==null?void 0:s.unavailableReason)??"no credential";return t.jsxs(t.Fragment,{children:[t.jsx("div",{hidden:i!=="identity",children:t.jsxs(ue,{gap:"lg",children:[y?null:t.jsxs(G,{tone:"warning",children:["This agent cannot run right now."," ",t.jsx("a",{href:Ft(e.id,"setup","brain"),onClick:b=>{b.preventDefault(),l("brain")},children:"See Brain."})]}),t.jsx(PQ,{agent:e,onSaved:c})]})}),t.jsx("div",{hidden:i!=="brain",children:t.jsxs(ue,{gap:"lg",children:[y?null:t.jsxs(G,{tone:"warning",children:["This agent cannot run right now: ",N,"."]}),t.jsx(pe,{panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsxs(pe,{title:"Runs on",children:[a?t.jsx(zQ,{agentId:e.id,accounts:a,onRun:o}):t.jsxs(Es,{children:[t.jsx(ie,{label:"Provider",children:t.jsx("select",{value:u,onChange:b=>j(b.target.value),children:r.map(b=>t.jsxs("option",{value:b.kind,children:[b.kind,b.usable?"":" (no credential)"]},b.kind))})}),t.jsxs(ie,{label:"Model",children:[t.jsx("input",{list:`models-${e.id}`,defaultValue:f,onBlur:b=>{b.target.value.trim()!==""&&b.target.value.trim()!==f&&k({model:b.target.value.trim()})}}),t.jsx("datalist",{id:`models-${e.id}`,children:w.map(b=>t.jsx("option",{value:b},b))})]})]}),a?null:t.jsxs("p",{className:"ui-card-meta",children:[(s==null?void 0:s.credentialKind)??e.provider.credentialKind," from"," ",t.jsx("span",{className:"mono",children:(s==null?void 0:s.credentialEnv)??e.provider.credentialEnv}),h&&!h.usable?` · default model ${h.defaultModel} (${h.defaultFrom})`:""]}),s!=null&&s.restartRequired?t.jsx("p",{className:"warning",children:"This file has changed since the service loaded it. Run `buddi service restart`."}):null]}),t.jsx(pe,{title:"Behaviour",aside:"saved as you change them",children:t.jsxs(Es,{children:[t.jsx(ie,{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?t.jsx("span",{className:"critical save-error",role:"alert",children:g}):null,children:t.jsx("input",{type:"number",min:ng,max:sg,value:m,onChange:b=>{p(b.target.value),x(null)},onBlur:()=>{const b=Number(m);if(!Number.isInteger(b)||b<ng||b>sg){x(`Between ${ng} and ${sg}.`);return}b!==((s==null?void 0:s.maxTurns)??e.maxTurns)&&k({maxTurns:b})}})}),t.jsx(ie,{label:"Language",hint:"Mirror answers in whatever language you write.",children:t.jsx("select",{value:(s==null?void 0:s.language)??e.language,onChange:b=>k({language:b.target.value}),children:AQ.map(b=>t.jsx("option",{value:b,children:b},b))})}),s?t.jsx(ie,{label:"New chat after",hint:"Idle time before your next message starts a fresh conversation, with a carried-over note. A transcript that grows too long starts one either way.",children:t.jsx("select",{"aria-label":"New chat after",value:s.idleRollover??"3h",onChange:b=>k({idleRollover:b.target.value==="3h"?null:b.target.value}),children:TQ.map(b=>t.jsx("option",{value:b.value,children:b.label},b.value))})}):null,F$(_$(s??{id:e.id,provider:u},a))?t.jsx(ie,{label:"Thinking",hint:"Reasoning before the answer. Off is faster and cheaper.",children:t.jsxs("select",{"aria-label":"Thinking",value:(s==null?void 0:s.thinking)??"default",onChange:b=>k({thinking:b.target.value==="default"?null:b.target.value}),children:[t.jsx("option",{value:"default",children:"Model default"}),t.jsx("option",{value:"on",children:"On"}),t.jsx("option",{value:"off",children:"Off"})]})}):t.jsx(ie,{label:"Thinking",hint:r4,children:t.jsx("span",{className:"ui-card-meta",children:"Up to the model"})})]})})]})}),t.jsx(Zt,{summary:"Built-in context",boxed:!0,children:t.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."})})]})}),t.jsx("div",{hidden:i!=="tools",children:t.jsxs(ue,{gap:"lg",children:[t.jsx(MQ,{agent:e,all:n,onSaved:c}),s&&e.tools.some(b=>b==="browser.*"||b.startsWith("browser."))?t.jsx(pe,{title:"Where it may look",aside:"saved as you change it",panel:!0,children:t.jsxs("div",{className:"br-adv-row",children:[t.jsxs("span",{className:"br-adv-head",children:[t.jsxs("span",{className:"br-adv-title",children:["Pages for ",e.name]}),t.jsxs("span",{className:"br-adv-hint",children:["A conversation’s Use my Chrome comes first, then this, then ",t.jsx("a",{href:rU,children:"Browser & apps"}),". A rule never allows what is off there."]})]}),t.jsx(pv,{value:s.browser??"auto",label:`Where ${e.name} may look`,apps:!1,onChange:b=>k({browser:b})})]})}):null,t.jsx(CQ,{agentId:e.id,agentName:e.name,readOnly:e.isExample===!0,version:e.tools.join(","),onSaved:c})]})}),t.jsx("div",{hidden:i!=="team",children:t.jsx(ue,{gap:"lg",children:t.jsx(HQ,{agent:e,all:n,onSaved:c})})})]})}function jP({dirty:e,busy:n,failure:s,label:r,onSave:a}){return t.jsxs(t.Fragment,{children:[s?t.jsx("span",{className:"critical save-error",role:"alert",children:s}):t.jsx("span",{className:e?"warning":"muted",children:e?"Not saved yet.":"Saved. Applies to new runs."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{variant:"accent",disabled:!e||n,onClick:a,children:r})]})}const wP=t.jsx(G,{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 PQ({agent:e,onSaved:n}){var O;const[s,r]=d.useState(e.name),[a,i]=d.useState(e.handle),[l,o]=d.useState(e.description),[c,u]=d.useState(e.avatar??""),[h,f]=d.useState(!1),m=ge(()=>A.agentFile(e.id),[e.id]),[p,g]=d.useState(null),x=((O=m.data)==null?void 0:O.persona.trim())??"",k=p??x,j=m.data!==void 0&&p!==null&&p.trim()!==x,[v,w]=d.useState(!1),[y,N]=d.useState(null),[b,S]=d.useState(null),C=s.trim()!==e.name||a.trim().replace(/^@/,"")!==e.handle||l.trim()!==e.description||c.trim()!==(e.avatar??"")||j,T=c.trim()!==""&&(c.trim()!==(e.avatar??"")||!e.picture),E=Uv(T?{...e,avatar:c.trim()}:e),R={...E?{avatar:E}:{},...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...!T&&e.picture?{picture:e.picture}:{}},M=async()=>{w(!0),N(null),S(null);try{const I=await A.updateAgentFile(e.id,{name:s.trim(),handle:a.trim().replace(/^@/,""),description:l.trim(),...c.trim()===""?{}:{avatar:c.trim()},...j&&k.trim()!==""?{persona:k.trim()}:{}});e.picture&&c.trim()!==""&&c.trim()!==(e.avatar??"")&&(await A.removeAgentPicture(e.id),window.dispatchEvent(new Event(Fr))),g(null),m.reload(),S(I.message),n()}catch(I){N(I instanceof Error?I.message:String(I))}finally{w(!1)}};return t.jsx(pe,{title:"Who it is",aside:t.jsx("span",{className:"mono",children:e.id}),panel:!0,foot:e.isExample?void 0:t.jsx(jP,{dirty:C,busy:v,failure:y,label:"Save who it is",onSave:()=>void M()}),children:t.jsxs(ue,{children:[e.isExample?wP:null,b?t.jsx(G,{tone:"good",role:"status",children:b}):null,t.jsxs(Es,{children:[t.jsx(ie,{label:"Name",hint:"What it is called, everywhere.",children:t.jsx("input",{value:s,disabled:v||e.isExample,onChange:I=>r(I.target.value)})}),t.jsx(ie,{label:"Handle",hint:"What you type to reach it. One handle, one agent.",children:t.jsx("input",{value:a,disabled:v||e.isExample,onChange:I=>i(I.target.value)})})]}),t.jsxs(ne,{children:[t.jsx(On,{id:e.id,name:s.trim()||e.name,size:"xl",face:R}),t.jsx($,{"aria-expanded":h,onClick:()=>f(I=>!I),children:h?"Hide faces":"Change face"})]}),h?t.jsx(FQ,{agent:e,avatar:c,onEmoji:u,onChanged:n,disabled:v}):null,t.jsx(ie,{label:"Description",hint:"One or two sentences. Its colleagues read this.",children:t.jsx("textarea",{rows:2,value:l,disabled:v||e.isExample,onChange:I=>o(I.target.value)})}),t.jsx(ie,{label:"Persona",hint:t.jsxs(t.Fragment,{children:["Who it is and how it works, in its own file. It reads this before every conversation; ",t.jsx("code",{children:"{{today}}"})," is filled in with the date at run time."]}),wide:!0,children:m.error?t.jsx(ae,{message:m.error}):m.data?t.jsx("textarea",{className:"setup-persona",value:k,rows:Math.max(6,k.split(`
|
|
131
|
-
`).length+1),disabled:v||e.isExample,onChange:I=>g(I.target.value)}):t.jsx(Ne,{children:"Reading its file…"})})]})})}function MQ({agent:e,all:n,onSaved:s}){var T;const r=ge(()=>A.agentTools(e.id),[e.id,e.tools.join(",")]),[a,i]=d.useState(null),[l,o]=d.useState(()=>new Set((e.roles??[]).filter(P0))),[c,u]=d.useState((e.roles??[]).filter(E=>!P0(E)).join(", ")),[h,f]=d.useState(!1),[m,p]=d.useState(null),[g,x]=d.useState(null),k=(E,R)=>E.split(R).map(M=>M.trim()).filter(M=>M!==""),j=((T=r.data)==null?void 0:T.granted)??e.tools,v=a??j,w=r.data!==void 0&&!Vq(v,j),y=M0(l,k(c,/[\n,]/)),N=E=>o(R=>{const M=new Set(R);return M.has(E)?M.delete(E):M.add(E),M}),S=w||!((E,R)=>E.join(",")===R.join(","))(y,M0(new Set(e.roles??[]),e.roles??[])),C=async()=>{f(!0),p(null),x(null);try{const E=await A.updateAgentFile(e.id,{...w&&r.data?{tools:Kq(r.data.groups,v)}:{},roles:y});x(E.message),i(null),r.reload(),s()}catch(E){p(E instanceof Error?E.message:String(E))}finally{f(!1)}};return t.jsx(pe,{title:"Roles and tools",panel:!0,foot:e.isExample?void 0:t.jsx(jP,{dirty:S,busy:h,failure:m,label:"Save roles and tools",onSave:()=>void C()}),children:t.jsxs(ue,{children:[e.isExample?wP:null,g?t.jsx(G,{tone:"good",role:"status",children:g}):null,t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",id:`roles-${e.id}`,children:"Roles"}),t.jsx("div",{className:"role-chips",role:"group","aria-labelledby":`roles-${e.id}`,children:Lw.map(E=>{const R=vU(n,E.id),M=R&&R.id!==e.id?R:void 0;return t.jsxs("button",{type:"button",className:"role-chip","aria-pressed":l.has(E.id),"data-on":l.has(E.id)?"true":void 0,disabled:h||e.isExample,onClick:()=>N(E.id),children:[t.jsx("span",{className:"role-chip-label",children:E.label}),t.jsx("span",{className:"role-chip-meaning",children:E.meaning}),M?t.jsxs("span",{className:"role-chip-holder",children:["Held by ",M.name,". If both claim it, the one listed first keeps it."]}):null]},E.id)})}),t.jsx("span",{className:"ui-field-hint",children:"Where buddi sends things when you do not say who. Tools are granted below."})]}),t.jsx(ie,{label:"Other roles",hint:"Only a plugin that asks for a role by name reads these. Comma separated.",children:t.jsx("input",{value:c,disabled:h||e.isExample,onChange:E=>u(E.target.value)})}),t.jsxs("div",{className:"ui-field",children:[t.jsxs("span",{className:"ui-field-label",children:["Tools · ",j.length," granted"]}),r.error?t.jsx(ae,{message:r.error}):r.data?t.jsx(Yq,{view:r.data,chosen:v,onChange:i,disabled:h||e.isExample}):t.jsx(Ne,{children:"Loading the installed tools…"})]}),t.jsx(OQ,{agentId:e.id,version:j.join(","),disabled:h||e.isExample}),DQ(j)?t.jsx(LQ,{agentId:e.id}):null]})})}function OQ({agentId:e,version:n,disabled:s}){var g;const r=ge(()=>Promise.resolve().then(()=>A.rememberedApprovals(e)),[e,n]),a=ge(()=>Promise.resolve().then(()=>A.connections()).catch(()=>null),[]),[i,l]=d.useState(null),[o,c]=d.useState(null),u=((g=r.data)==null?void 0:g.tools)??[];if(u.length===0)return null;const h=async(x,k)=>{l(x),c(null);try{await A.setRememberedApproval(e,x,k),r.reload()}catch(j){c(j instanceof Error?j.message:String(j))}finally{l(null)}},f=new Map;for(const x of u)f.set(x.connection,[...f.get(x.connection)??[],x]);const m=x=>{var k,j;return((j=(k=a.data)==null?void 0:k.connections.find(v=>v.slug===x))==null?void 0:j.name)??x},p=x=>x.tool.split(".").slice(2).join(".")||x.tool;return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Connection tools that ask first"}),t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Remembered approvals",children:[...f].map(([x,k])=>{const j=k.filter(N=>N.rememberable),v=k.filter(N=>!N.rememberable),w=j.filter(N=>N.remembered),y=t.jsxs("span",{className:"remembered-summary",children:[t.jsx("span",{className:"remembered-name",children:m(x)}),t.jsxs("span",{className:"ui-card-meta",children:[` · ${k.length} ask first`,w.length>0?` · ${w.length} remembered: ${w.map(p).join(", ")}`:""]})]});return t.jsxs(Zt,{summary:y,boxed:!0,children:[t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":`${m(x)}: remember my approval`,children:j.map(N=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:N.remembered,disabled:s||i!==null,onChange:b=>void h(N.tool,b.target.checked),"aria-label":`Remember my approval for ${N.tool}`}),t.jsx("span",{className:"mono",children:p(N)})]},N.tool))}),v.length>0?t.jsxs("p",{className:"ui-card-meta remembered-always",children:["These can delete or destroy something, so they always ask and are never remembered:"," ",t.jsx("span",{className:"mono",children:v.map(p).join(", ")})]}):null]},x)})}),t.jsx(ae,{message:o}),t.jsx("span",{className:"ui-field-hint",children:"Tick a tool to remember your approval: it asks once, then runs for this agent."})]})}function DQ(e){return e.some(n=>n==="owner.notify"||n==="owner.*"||n==="owner.notify?"||n==="owner.*?")}function LQ({agentId:e}){var h,f;const n=ge(()=>A.notificationSettings(),[]),[s,r]=d.useState(null),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=s??((f=(h=n.data)==null?void 0:h.settings.agents)==null?void 0:f.muted.includes(e))??!1,u=m=>{i(!0),o(null),r(m),A.setAgentMuted(e,m).then(p=>r(p.agents.muted.includes(e))).catch(p=>{r(!m),o(p instanceof Error?p.message:String(p))}).finally(()=>i(!1))};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Messages to you"}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:c,disabled:a||!n.data,onChange:m=>u(m.target.checked),"aria-label":"Mute this agent's messages"}),t.jsx("span",{children:"Mute its messages"})]}),t.jsx(ae,{message:n.error??l}),t.jsx("span",{className:"ui-field-hint",children:"With owner.notify it can message you itself; muted, it is refused and told so."})]})}function Uv(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 FQ({agent:e,avatar:n,onEmoji:s,onChanged:r,disabled:a}){const[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=n.trim()!==""&&(n.trim()!==(e.avatar??"")||!e.picture),m=i??(f?{kind:"emoji",value:n.trim()}:e.picture?{kind:"kept",url:e.picture}:null),p=async g=>{if(h(null),g.kind==="emoji"){s(g.value);return}if(g.kind==="kept"){s(e.avatar??"");return}l(g),c(!0);try{await A.uploadAgentPicture(e.id,await xP(g.role)),s(e.avatar??""),r(),window.dispatchEvent(new Event(Fr))}catch(x){h(x instanceof Error?x.message:String(x))}finally{l(null),c(!1)}};return t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Face"}),t.jsx($Q,{face:m,label:"Face",kept:e.picture,disabled:a||o,disableEmoji:e.isExample,onPick:g=>void p(g),children:t.jsx(_Q,{agent:e,onChanged:r})}),u?t.jsx("span",{className:"critical save-error",role:"alert",children:u}):null]})}function _Q({agent:e,onChanged:n}){const[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(0);d.useEffect(()=>{if(!s)return i(null);const S=URL.createObjectURL(s);return i(S),()=>URL.revokeObjectURL(S)},[s]);const g=S=>{r(null),p(C=>C+1),f(S),n(),window.dispatchEvent(new Event(Fr))},x=async S=>{o(!0),u(null),f(null);try{g(await S())}catch(C){u(C instanceof Error?C.message:String(C))}finally{o(!1)}},k=()=>x(async()=>(await A.uploadAgentPicture(e.id,s)).note??null),j=()=>x(async()=>(await A.removeAgentPicture(e.id),null)),v={avatar:Uv(e),...e.accent?{accent:e.accent}:{},roles:e.roles,tools:e.tools,...a??e.picture?{picture:a??e.picture}:{}},[w,y]=d.useState(!1),N=d.useRef(null),b=S=>{u(null),f(null),r(S??null)};return t.jsxs("div",{className:"setup-upload","data-dragging":w?"true":void 0,onDragOver:S=>{S.preventDefault(),l||y(!0)},onDragLeave:()=>y(!1),onDrop:S=>{var C;S.preventDefault(),y(!1),l||b((C=S.dataTransfer.files)==null?void 0:C[0])},children:[t.jsxs(ne,{children:[t.jsx(On,{id:e.id,name:e.name,size:"xl",face:v}),t.jsx("input",{ref:N,className:"sr-only",type:"file","aria-label":"Choose a picture",accept:"image/png,image/gif,image/svg+xml,.png,.gif,.svg",disabled:l,onChange:S=>{var C;return b((C=S.target.files)==null?void 0:C[0])}},m),t.jsx($,{disabled:l,onClick:()=>{var S;return(S=N.current)==null?void 0:S.click()},children:"Upload a picture"}),t.jsx("span",{className:"setup-upload-name",children:s?s.name:"or drop one here"}),t.jsx("span",{className:"ui-toolbar-spacer"}),e.picture&&!s?t.jsx($,{variant:"ghost",disabled:l,onClick:()=>void j(),children:"Remove picture"}):null,t.jsx($,{variant:"accent",disabled:!s||l,onClick:()=>void k(),children:"Save picture"})]}),c?t.jsx("span",{className:"critical save-error",role:"alert",children:c}):t.jsx("span",{className:"ui-field-hint",children:h??"Your own picture: a PNG, GIF or SVG up to 1 MB, kept as a square PNG; a GIF keeps its first frame."})]})}function zQ({agentId:e,accounts:n,onRun:s}){const r=n.bindings.find(p=>p.agentId===e),[a,i]=d.useState((r==null?void 0:r.accountId)??""),[l,o]=d.useState((r==null?void 0:r.model)??""),[c,u]=d.useState(!1),h=n.accounts.find(p=>p.id===a),f=a!==((r==null?void 0:r.accountId)??"")||l!==((r==null?void 0:r.model)??""),m=n.accounts.find(p=>p.id===(r==null?void 0:r.accountId));return t.jsxs("div",{className:"ui-stack",children:[t.jsxs(ne,{valign:"end",children:[t.jsx(ie,{label:"Account",children:t.jsxs("select",{value:a,disabled:c,onChange:p=>{var g;i(p.target.value),o(((g=n.accounts.find(x=>x.id===p.target.value))==null?void 0:g.defaultModel)??"")},children:[t.jsx("option",{value:"",children:"Choose an account"}),n.accounts.map(p=>t.jsxs("option",{value:p.id,disabled:!p.enabled,children:[p.label,p.enabled?p.configured?"":" (needs credential)":" (disabled)"]},p.id))]})}),t.jsx(Hy,{accountId:h!=null&&h.configured?a:void 0,label:"Model",value:l,onChange:o,disabled:c},`${a}:${h==null?void 0:h.revision}`)]}),t.jsxs(ne,{children:[f&&a&&l.trim()?t.jsxs("span",{className:"warning",children:["Not saved yet. New runs still use ",m?`${m.label}, ${(r==null?void 0:r.model)??""}`:"nothing","."]}):t.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."}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsx($,{variant:"accent",disabled:c||!a||!l.trim()||!f,onClick:()=>{u(!0),s(A.assignProviderAccount(e,a,l).finally(()=>u(!1)))},children:"Save account selection"})]})]})}const UQ=["platform.create_agent","platform.update_agent","platform.write_skill","platform.delete_agent","platform.accept_plugin_agent","platform.accept_plugin_skill"],rg=e=>e.tools.some(n=>UQ.includes(n)),BQ=["front-desk","maker"],WQ={"front-desk":"Can ask: everyone, as the front desk",maker:"Can ask: everyone, as the maker",list:"Can ask: everyone"};function HQ({agent:e,all:n,onSaved:s}){const[r,a]=d.useState(e.delegates),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(e.delegates),[p,g]=d.useState(e.asksEveryone),[x,k]=d.useState(!1),j=n.filter(E=>E.id!==e.id),v=BQ.find(E=>{var R;return(R=e.roles)==null?void 0:R.includes(E)}),w=p===void 0||x,y=x||[...r].sort().join(",")!==[...f].sort().join(","),N=n.filter(E=>E.id!==e.id&&(E.delegates.includes(e.id)||E.asksEveryone!==void 0&&!rg(e))),b=E=>a(R=>R.includes(E)?R.filter(M=>M!==E):[...R,E]),S=async E=>{l(!0),c(null),h(!1);try{const R=await A.setDelegates(e.id,E);m(R.delegates),a(R.delegates),g(R.asksEveryone),k(!1),h(!0),s()}catch(R){c(R instanceof Error?R.message:String(R))}finally{l(!1)}},C=()=>{a(j.filter(E=>!rg(E)).map(E=>E.id)),k(!0),h(!1)},T=y?"Not saved yet.":u?"Saved. Applies to the next run.":w?r.length===0?"Asks nobody.":`May ask ${r.length} agent${r.length===1?"":"s"}.`:"Asks everyone.";return t.jsx(pe,{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:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:y?"warning":"muted",children:T}),t.jsx("span",{className:"ui-toolbar-spacer"}),w&&v!==void 0?t.jsx($,{disabled:i,onClick:()=>void S(["*"]),children:"Let it ask everyone"}):null,w?t.jsx($,{variant:"accent",disabled:!y||i,onClick:()=>void S(r),children:"Save who it can ask"}):t.jsx($,{variant:"accent",disabled:i,onClick:C,children:"Limit to…"})]}),children:t.jsxs(ue,{divided:!0,children:[t.jsxs(pe,{title:"Can ask",children:[e.isExample?t.jsx(G,{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,t.jsx(ae,{message:o}),w?j.length===0?t.jsx(Ne,{children:"Nobody else is installed."}):t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Only the agents ticked here. New teammates must be added here before it can ask them."}),t.jsx("ul",{className:"ui-list delegate-list","aria-label":"Agents this one may ask",children:j.map(E=>{const R=rg(E);return t.jsxs("li",{className:"ui-list-row",children:[t.jsx("input",{type:"checkbox",id:`can-ask-${e.id}-${E.id}`,checked:r.includes(E.id),disabled:R||e.isExample||i,onChange:()=>b(E.id)}),t.jsxs("label",{htmlFor:`can-ask-${e.id}-${E.id}`,className:"ui-list-main",children:[t.jsxs("span",{className:"ui-list-title",children:[E.name," ",t.jsxs("span",{className:"mono muted",children:["@",E.handle]})]}),t.jsx("span",{className:"ui-list-sub",children:R?"Makes and changes agents. Never reachable by delegation.":E.description})]})]},E.id)})})]}):t.jsxs("p",{className:"ui-card-meta",children:[WQ[p??"list"],". New agents are included without being added here; agents that make and change agents are never reachable by delegation."]})]}),t.jsx(pe,{title:"Asked by",children:N.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No other agent may hand work to ",e.name,"."]}):t.jsx(hB,{children:N.map(E=>t.jsx(Ae,{children:E.name},E.id))})})]})})}const KQ=[{id:"team",label:"Team"},{id:"missions",label:"Missions"},{id:"offers",label:"Offers"},{id:"reminders",label:"Reminders"},{id:"skills",label:"Skills"}],VQ=[{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 GQ(e){const n=J3(e.hash);return n?t.jsx(sq,{name:n.name,agents:e.agents,navigate:e.navigate,pluginPages:e.pluginPages}):t.jsx(YQ,{...e})}function YQ({hash:e,timezone:n,navigate:s,agents:r,attention:a,defaultAgentId:i}){var j,v,w,y,N;const l=Y3(e),o=((j=/[?&]tab=([a-z]+)/.exec(e))==null?void 0:j[1])??"team",c=b=>S=>{S.preventDefault(),s(b)},u=ge(()=>A.agents(),[]),h=pm(),f=ge(()=>A.offers(),[],2e4),m=MR(),p=(((v=f.data)==null?void 0:v.offers.length)??0)+m.offers.length,g=((y=(w=u.data)==null?void 0:w.default)==null?void 0:y.defaultAgentId)??i??null,[x,k]=d.useState(null);return t.jsxs("div",{className:"ui-page",children:[t.jsx(Pi,{title:"Agents",lede:o==="skills"?`Skills are short texts an agent follows for one kind of task. Each is a file on ${h}, or a folder when scripts and files come with it.`:`Your team. Each one is a file on ${h} — what it can reach is listed on its page.`,actions:o==="skills"?t.jsxs(t.Fragment,{children:[t.jsx($,{onClick:()=>k({kind:"upload",at:Date.now()}),children:"Upload"}),t.jsx($,{variant:"accent",onClick:()=>k({kind:"write",at:Date.now()}),children:"Write a skill"})]}):t.jsx(lt,{variant:"accent",href:un(),onClick:c(un()),children:"Add a teammate"})}),t.jsx(Co,{children:KQ.map(b=>t.jsx(Ki,{href:b.id==="team"?bt:`${bt}?tab=${b.id}`,active:o===b.id,count:b.id==="offers"?p:void 0,onClick:c(b.id==="team"?bt:`${bt}?tab=${b.id}`),children:b.label},b.id))}),o==="missions"?t.jsx(FI,{timezone:n,embedded:!0}):null,o==="offers"?t.jsx(OR,{offers:m.offers,reload:m.reload}):null,o==="offers"?t.jsx(zI,{embedded:!0}):null,o==="reminders"?t.jsx(sP,{timezone:n,embedded:!0}):null,o==="skills"?t.jsx(Iq,{faces:r,navigate:s,command:x,openSkill:cW(e),openFile:oW(e)}):null,o==="team"?t.jsx(qQ,{data:u.data,error:u.error,reload:u.reload}):null,o==="team"?r.length===0?t.jsx(es,{icon:"agents",title:"No agents yet",children:"Each agent is a file in the installation's agents folder."}):t.jsx("div",{className:"agents-grid",children:GA(r,g).map(b=>{const S=rm(a.get(b.id));return t.jsxs("div",{className:"ui-card agent-card","data-interactive":"true",...Hi(So(b)),"data-unavailable":b.available?void 0:"true",children:[t.jsx("div",{className:"agent-card-top"}),t.jsx("div",{className:"agent-card-face",children:t.jsx(On,{id:b.id,name:b.name,size:"xl",unavailable:!b.available,face:b})}),t.jsxs("div",{children:[t.jsxs("div",{className:"ui-card-title",children:[t.jsx("a",{className:"agent-card-link",href:Ft(b.id,"conversations"),onClick:c(Ft(b.id,"conversations")),children:b.name}),t.jsxs("span",{className:"agent-card-handle mono faint",children:["@",b.handle]})]}),t.jsx("p",{className:"ui-card-meta agent-card-desc",children:b.description})]}),t.jsxs("div",{className:"ui-row",children:[b.id===g?t.jsx(so,{children:"front desk"}):null,S?t.jsx(Ae,{tone:"critical",dot:!0,children:"waiting for you"}):b.available?t.jsx(Ae,{tone:"good",dot:!0,children:"ready"}):t.jsx(Ae,{tone:"warning",children:fr(b.unavailableReason??"cannot run",60)}),t.jsx(Ae,{mono:!0,children:b.model}),t.jsx(lt,{className:"agent-card-talk",size:"sm",href:at(b.id),onClick:c(at(b.id)),"aria-label":`Talk to ${b.name}`,children:"Talk"})]})]},b.id)})}):null,l?t.jsx(Ye,{title:((N=r.find(b=>b.id===l.agentId))==null?void 0:N.name)??l.agentId,size:"wide",onClose:()=>s(bt),children:t.jsx(QQ,{agentId:l.agentId,agent:r.find(b=>b.id===l.agentId),agents:r,tab:l.tab??"conversations",...l.section?{section:l.section}:{},timezone:n,navigate:s,attention:a})}):null]})}function qQ({data:e,error:n,reload:s}){const r=e==null?void 0:e.default,[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null);if(n)return t.jsx(ae,{message:n});if(!r||r.choices.length===0)return null;const m=r.defaultAgentId,p=a??m??"",g=p!==""&&p!==m,x=r.problem,k=v=>v.map(w=>{var y;return((y=r.choices.find(N=>N.id===w))==null?void 0:y.name)??w}).join(" and "),j=async()=>{o(!0),u(null),f(null);try{const v=await A.setDefaultAgent(p);f(v.note),i(null),s()}catch(v){u(v instanceof Error?v.message:String(v))}finally{o(!1)}};return t.jsx(Xe,{children:t.jsxs("div",{className:"ui-stack",children:[t.jsx(ae,{message:c}),(x==null?void 0:x.code)==="multiple-defaults"?t.jsx(G,{tone:"warning",role:"status",children:`Two agents claim default in their files: ${k(x.agents)}. The one chosen here wins.`}):(x==null?void 0:x.code)==="no-default-agent"?t.jsx(G,{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,h?t.jsx(G,{tone:"good",role:"status",children:h}):null,t.jsxs(ne,{children:[t.jsxs("div",{className:"default-agent-text",children:[t.jsx("h3",{className:"default-agent-title",children:"Default agent"}),t.jsx("span",{className:"ui-field-hint",children:"Where a chat that names nobody lands."})]}),t.jsx("span",{className:"ui-toolbar-spacer"}),t.jsxs("select",{"aria-label":"Default agent",value:p,disabled:l,onChange:v=>i(v.target.value),children:[p===""?t.jsx("option",{value:"",children:"Choose an agent"}):null,r.choices.map(v=>t.jsxs("option",{value:v.id,disabled:!v.available,children:[v.name," @",v.handle,v.available?"":" (cannot run)"]},v.id))]}),t.jsx($,{variant:"accent",disabled:l||!g,onClick:()=>void j(),children:"Save"})]})]})})}function QQ({agentId:e,agent:n,agents:s,tab:r,section:a,timezone:i,navigate:l,attention:o}){const c=p=>g=>{g.preventDefault(),l(p)},u=rm(o.get(e)),h=(n==null?void 0:n.name)??e,f=lq(e),m=n!==void 0&&!n.roles.includes(zr)&&!n.roles.includes($u);return t.jsxs("div",{className:"ui-stack","data-gap":"lg",children:[t.jsxs("header",{className:"agent-head",children:[t.jsx(On,{id:e,name:h,size:"xl",unavailable:n?!n.available:!1,face:n}),t.jsxs("div",{className:"agent-head-text",children:[t.jsx("p",{className:"ui-page-lede",children:(n==null?void 0:n.description)??"This agent is not in the roster right now."}),f.entry?t.jsx(oq,{entry:f.entry,navigate:l,onUpdated:f.reload}):null,t.jsxs("div",{className:"ui-row",children:[n?t.jsxs("span",{className:"muted mono",children:["@",n.handle]}):null,n?t.jsx("span",{className:"muted",children:n.model}):null,u?t.jsx(Ae,{tone:"critical",children:u}):n&&!n.available?t.jsx(Ae,{tone:"warning",children:n.unavailableReason??"cannot run"}):null]})]}),t.jsx("div",{className:"ui-page-actions",children:t.jsxs(lt,{variant:"accent",href:at(e),onClick:c(at(e)),children:["Talk to ",h]})})]}),n&&!n.available?t.jsxs(G,{tone:"warning",role:"status",children:[qA(n)," ",t.jsx("a",{href:Fe(Vx(n).section),children:Vx(n).label})]}):null,t.jsx(Co,{children:VQ.map(p=>t.jsx(Ki,{href:Ft(e,p.id),active:r===p.id,onClick:c(Ft(e,p.id)),children:p.label},p.id))}),r==="conversations"?t.jsx(JQ,{agentId:e,navigate:l}):null,r==="missions"?t.jsx(FI,{timezone:i,embedded:!0,agentId:e}):null,r==="offers"?t.jsx(zI,{embedded:!0,agentId:e,agentName:h}):null,r==="reminders"?t.jsx(sP,{timezone:i,embedded:!0,agentId:e}):null,r==="memory"?t.jsx(GI,{embedded:!0,agents:s,timezone:i,agentId:e}):null,r==="skills"?t.jsx(Uq,{agentId:e,agentName:h,faces:s,navigate:l}):null,r==="setup"?t.jsx(RQ,{agentId:e,section:a,navigate:l}):null,r==="setup"&&m?t.jsx(uq,{agentId:e,name:h,navigate:l}):null]})}function JQ({agentId:e,navigate:n}){const{data:s,error:r}=ge(()=>Je.conversations(e,50),[e]);if(r)return t.jsx(Ne,{children:r});const a=(s==null?void 0:s.conversations)??[];return t.jsx(Xe,{flush:!0,children:s?a.length===0?t.jsx(es,{icon:"chat",title:"No conversations yet",children:"Say hello, and the conversation shows up here."}):t.jsx(ct,{children:a.map(i=>t.jsx(rt,{href:at(e,i.id),onClick:()=>n(at(e,i.id)),title:fr(i.preview||i.opening||"Untitled conversation",90),sub:`${i.messageCount} message${i.messageCount===1?"":"s"}`,side:Ge(i.lastMessageAt??i.startedAt??i.createdAt??null)},i.id))}):t.jsx(Ne,{children:"Loading…"})})}const XQ=3e4;function yP(){const{data:e,reload:n}=ge(()=>A.recovery(),[],XQ),s=d.useRef(n);return s.current=n,d.useEffect(()=>{const r=()=>s.current(),a=()=>{document.visibilityState==="visible"&&r()};return window.addEventListener("focus",r),document.addEventListener("visibilitychange",a),()=>{window.removeEventListener("focus",r),document.removeEventListener("visibilitychange",a)}},[]),{data:e,reload:n}}function MS(e){return e.kind==="account"?e.accountId?FA(e.accountId):Fe("accounts"):e.kind==="telegram"?Fe("telegram"):e.kind==="connection"?e.connectionId?_A(e.connectionId):Fe("connections"):e.kind==="email"?e.settingsRoute:Fe("secrets")}function ZQ(e){return e.install?lU(e.install):zx}const eJ=Fe("system");function tJ(e){return e.loadsAtRestart?`installed — loads at the next restart${e.waiting?`; ${e.waiting.note}`:""}`:e.waiting?`${e.name} — ${e.waiting.note}`:e.source}const bP="This buddi was restored from a backup. Nothing runs on its own until you finish the checklist.";function nJ({view:e,onLeft:n}){const{secrets:s,plugins:r,pending:a,grants:i}=e.checklist,l=e.checklist.keptTables??[],[o,c]=d.useState(!0),[u,h]=d.useState([]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[x,k]=d.useState(!1),j=r.filter(N=>!N.installed||N.waiting!==void 0||N.loadsAtRestart===!0),v=a.jobs+a.missions+a.approvals+a.telegramChats,w=N=>{h(b=>b.includes(N)?b.filter(S=>S!==N):[...b,N])},y=()=>{m(!0),g(null),sm({kind:"recovery"},()=>A.leaveRecovery({dropPending:o,keepGrants:u})).then(N=>{N&&N.restarting===!1&&no(),k(!0),n==null||n()}).catch(N=>g(N instanceof he?N.message:String(N))).finally(()=>m(!1))};return t.jsx(Xe,{title:"Back from a backup",children:t.jsxs(ue,{divided:!0,children:[t.jsxs(pe,{children:[t.jsx(Xt,{items:[{label:"Restored",value:e.restoredAt??"just now"},{label:"From",value:t.jsx("span",{className:"mono",children:e.archive??"—"})}]}),t.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."})]}),t.jsx(pe,{title:"Keys to paste again",children:s.length===0?t.jsx(Ne,{children:"Nothing is missing."}):t.jsx(ct,{children:s.map(N=>t.jsx(rt,{title:N.label??N.name,sub:N.name?t.jsx("span",{className:"mono",children:N.name}):void 0,side:N.signIn?t.jsx(lt,{size:"sm",href:MS(N),"aria-label":`Sign in again: ${N.label??N.name}`,children:"Sign in again"}):t.jsx(lt,{size:"sm",href:MS(N),"aria-label":`Fix ${N.label??N.name}`,children:"Fix"})},`${N.kind}:${N.accountId??N.name}`))})}),t.jsx(pe,{title:"Add-ons to install again",children:j.length===0&&l.length===0?t.jsx(Ne,{children:"Everything the backup named is installed."}):t.jsxs(ct,{children:[j.map(N=>t.jsx(rt,{title:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"mono",children:N.name})," ",N.version]}),sub:tJ(N),side:N.loadsAtRestart?t.jsx(lt,{size:"sm",href:eJ,"aria-label":`Restart to load ${N.name}`,children:"Restart"}):N.installed?void 0:t.jsx(lt,{size:"sm",href:ZQ(N),"aria-label":`Install ${N.name} again`,children:N.install?"Install":"Find it"})},N.name)),l.map(N=>t.jsx(rt,{title:t.jsx("span",{className:"mono",children:N.table}),sub:N.sentence},`kept:${N.table}`))]})}),t.jsx(pe,{title:"Work that was waiting",children:v===0?t.jsx(Ne,{children:"Nothing was in flight when the backup was taken."}):t.jsxs(ue,{gap:"sm",children:[t.jsx(Xt,{items:[{label:"Jobs",value:String(a.jobs)},{label:"Missions",value:String(a.missions)},{label:"Waiting for an answer",value:String(a.approvals)},{label:"Phones",value:String(a.telegramChats)}]}),t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:N=>c(N.target.checked)}),t.jsx("span",{children:"Drop it. It was queued somewhere else, days ago."})]})]})}),t.jsx(pe,{title:"Standing permissions",children:i.length===0?t.jsx(Ne,{children:"No agent had a standing permission."}):t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"Each of these lets an agent act without asking. Keep only the ones you meant."}),t.jsx("ul",{className:"recovery-list",children:i.map(N=>t.jsx("li",{children:t.jsxs("label",{className:"recovery-check",children:[t.jsx("input",{type:"checkbox",checked:u.includes(N.id),onChange:()=>w(N.id),"aria-label":`Keep ${N.tool} for ${N.agent}`}),t.jsxs("span",{children:[t.jsx("span",{className:"mono",children:N.tool})," for ",N.agent," ",t.jsx("span",{className:"ui-card-meta",children:N.scope}),N.description?t.jsxs("span",{className:"ui-card-meta",children:[" — ",N.description]}):null]})]})},N.id))})]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:p}),x?t.jsx(G,{tone:"good",role:"status",children:"Turning everything back on. This page comes back in a few seconds."}):t.jsx("p",{className:"ui-card-meta",children:"Leaving starts the schedules, the watchers and the phone again. buddi restarts itself to do it."}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",disabled:f||x,onClick:y,children:"Leave recovery mode"})})]})})]})})}function kP({days:e,mailbox:n,money:s,pictures:r}){const a=[];(n||e)&&a.push("chief-of-staff"),s&&a.push("cfo"),r&&a.push("illustrator");for(const i of["researcher","tutor"])a.length<3&&a.push(i);return a.slice(0,4)}function sJ(e,n,s=4){const r=i=>!!i&&Hr(i)==="ready"&&i.addable,a=kP(n).map(i=>e.find(l=>l.name===i)).filter(r);for(const i of["researcher","tutor"]){if(a.length>=3)break;const l=e.find(o=>o.name===i);r(l)&&!a.includes(l)&&a.push(l)}return a.slice(0,s)}const OS=["researcher","tutor"];function DS(e,n){return e==="chief-of-staff"?n.days?"because you set up My days":"because you added a mailbox":e==="cfo"?"because you set up My money":e==="illustrator"?"because you set up Pictures":"popular"}function rJ(e,n,s=4){const r=[];for(const a of kP(n).filter(i=>!OS.includes(i))){const i=e.find(h=>h.name===a);if(!i||Hr(i)!=="ready")continue;if(i.addable){r.push({entry:i,reason:DS(a,n)});continue}const l=i.missing??[],o=l.find(h=>tf(h)!==null)??l[0];if(!o)continue;const c=tf(o),u=c?c.label.charAt(0).toLowerCase()+c.label.slice(1):`${_y(o)} is here`;r.push({entry:i,reason:DS(a,n),blocked:{step:u,fix:c}})}for(const a of OS){if(r.length>=3)break;const i=e.find(l=>l.name===a);i&&Hr(i)==="ready"&&i.addable&&r.push({entry:i,reason:"popular"})}return r.slice(0,s)}function aJ(e,n){const s=e.filter(r=>r.id!==n&&!r.roles.includes($u)&&!r.roles.includes(zr));return e.length>0&&s.length<=1}async function iJ(e,n=UI){try{const{jobId:s}=await A.catalogueInstall(e.name,{version:e.version,tools:e.tools});for(;;){const r=await A.catalogueJob(s);if(r.state!=="running")return r;await new Promise(a=>setTimeout(a,n))}}catch(s){return{error:s instanceof he?s.message:String(s)}}}function lJ({entry:e,checked:n,onChange:s,reason:r}){return t.jsxs("label",{className:"cat-pick","data-checked":n?"true":void 0,"data-testid":`cat-pick-${e.name}`,children:[t.jsx("input",{type:"checkbox",checked:n,onChange:a=>s(a.target.checked)}),t.jsx(rl,{entry:e,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsxs("span",{className:"cat-pick-name",children:[e.title,r?t.jsx("span",{className:"cat-pick-why",children:r}):null]}),t.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]})]})}function oJ({suggestion:e,onFix:n}){const{entry:s,reason:r,blocked:a}=e;return t.jsxs("div",{className:"cat-pick","data-blocked":"true","data-testid":`cat-pick-${s.name}`,children:[t.jsx("input",{type:"checkbox",checked:!1,disabled:!0,"aria-label":`${s.title}: not ready yet`,onChange:()=>{}}),t.jsx(rl,{entry:s,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsxs("span",{className:"cat-pick-name",children:[s.title," · ready once you ",a==null?void 0:a.step,t.jsx("span",{className:"cat-pick-why",children:r})]}),t.jsx("span",{className:"cat-pick-pitch",children:s.pitch})]}),a!=null&&a.fix?t.jsx($,{size:"sm",onClick:()=>n(a.fix.route),children:a.fix.label}):null]})}function cJ({entry:e,added:n,onOpen:s,onAdd:r}){return t.jsxs("div",{className:"cat-suggest",role:"button",tabIndex:0,"aria-label":`${e.title}: details`,"data-testid":`cat-suggest-${e.name}`,onClick:s,onKeyDown:a=>{a.target===a.currentTarget&&a.key==="Enter"&&s()},children:[t.jsx(rl,{entry:e,size:"lg"}),t.jsxs("span",{className:"cat-pick-text",children:[t.jsx("span",{className:"cat-pick-name",children:e.title}),t.jsx("span",{className:"cat-pick-pitch",children:e.pitch})]}),n?t.jsxs("span",{className:"cat-added",children:[t.jsx(oe,{name:"check",size:14}),"Added"]}):t.jsx($,{size:"sm",variant:"accent","aria-label":`Add ${e.title}`,onClick:a=>{a.stopPropagation(),r()},children:"Add"})]})}function uJ({navigate:e}){const[n,s]=d.useState(null),[r,a]=d.useState(null),[i,l]=d.useState([]),o=zy();d.useEffect(()=>{let u=!1;return A.catalogue().then(h=>{u||s(h.unavailable?[]:h.agents)}).catch(()=>{u||s([])}),()=>{u=!0}},[]);const c=d.useMemo(()=>n===null?null:sJ(n,{days:!0,mailbox:!0,money:o.has("finance"),pictures:o.has("image")},3),[n,o]);return!c||c.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"cat-suggest-lede",children:"Teammates who could take a job off your hands, from what you set up:"}),t.jsx("div",{className:"cat-suggests","data-testid":"home-suggestions",children:c.map(u=>t.jsx(cJ,{entry:u,added:i.includes(u.name),onOpen:()=>e(un(u.name)),onAdd:()=>a(u)},u.name))}),r?t.jsx(BI,{entry:r,navigate:e,onClose:()=>a(null),onAdded:()=>{l(u=>[...u,r.name]),window.dispatchEvent(new Event(Fr))}}):null]})}function dJ({setUp:e,navigate:n}){var w;const[s,r]=d.useState(null),[a,i]=d.useState([]),[l,o]=d.useState("picking"),[c,u]=d.useState([]),[h,f]=d.useState([]),m=JSON.stringify(e);if(d.useEffect(()=>{let y=!1;return A.catalogue().then(N=>{if(y)return;const b=N.unavailable?[]:rJ(N.agents,e);r(b),i(b.filter(S=>!S.blocked).map(S=>S.entry.name))}).catch(()=>{y||r([])}),()=>{y=!0}},[m]),!s||s.length===0)return null;const p=s.filter(y=>!y.blocked).map(y=>y.entry),g=s.some(y=>!y.blocked&&y.reason!=="popular"),x=()=>n(un()),k=async()=>{o("adding");const y=[],N=[];for(const b of p.filter(S=>a.includes(S.name))){const S=await iJ(b);"error"in S&&!("state"in S)?N.push({entry:b,error:S.error}):S.state==="done"?y.push(b):S.state==="confirm"?N.push({entry:b,error:"it gets more than its card showed, so it waits for your approval in Needs you"}):N.push({entry:b,error:S.error??"it stopped before it finished"})}u(y),f(N),o("added"),y.length>0&&window.dispatchEvent(new Event(Fr))},j=a.length,v=l==="adding"?`Adding ${j===1?((w=p.find(y=>y.name===a[0]))==null?void 0:w.title)??"1":j}…`:j>0&&j===p.length?"Add these":j>0?`Add these ${j}`:"Tick one to add";return t.jsx("section",{className:"handover-team","aria-label":"Who do you want on your team?","data-testid":"handover-team",children:l==="added"?t.jsxs(t.Fragment,{children:[c.length>0?t.jsxs(G,{tone:"good",role:"status",title:`${dn(c.map(y=>y.title))} ${c.length===1?"is":"are"} on your team.`,action:t.jsx($,{variant:"ghost",size:"sm",onClick:x,children:"See all teammates"}),children:["Say hello in Chat. ",c.length===1?"Its missions are":"Their missions are"," off until you turn them on."]}):null,h.length>0?t.jsxs(G,{tone:"critical",role:"alert",title:`${dn(h.map(y=>y.entry.title))} ${h.length===1?"wasn’t":"weren’t"} added.`,action:c.length===0?t.jsx($,{variant:"ghost",size:"sm",onClick:x,children:"See all teammates"}):void 0,children:[h.map(y=>`${y.entry.title}: ${y.error.replace(/[.\s]+$/,"")}.`).join(" ")," Nothing else changed; try again from the catalogue."]}):null]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"handover-team-head",children:[t.jsx("h2",{className:"handover-team-title",children:"Who do you want on your team?"}),t.jsx("p",{className:"cat-small",children:g?"Picked from what you just set up. Their plugins are already in, so one click adds them all.":"A few teammates people often start with. One click adds the ones you tick."})]}),t.jsx("div",{className:"cat-picks",children:s.map(y=>y.blocked?t.jsx(oJ,{suggestion:y,onFix:n},y.entry.name):t.jsx(lJ,{entry:y.entry,reason:y.reason,checked:a.includes(y.entry.name),onChange:N=>i(N?[...a,y.entry.name]:a.filter(b=>b!==y.entry.name))},y.entry.name))}),t.jsx("div",{className:"handover-team-foot",children:t.jsxs(ne,{children:[t.jsx($,{variant:"ghost",onClick:x,children:"See all teammates"}),t.jsx(ot,{}),t.jsx($,{variant:"accent",disabled:j===0||l==="adding"||p.length===0,onClick:()=>void k(),children:v})]})})]})})}const LS=3,hJ=40;function fJ({agent:e,navigate:n}){var g;const s=d.useRef(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(null),u=ge(()=>Je.conversations(e.id,LS),[e.id],3e4),h=fs(Gw),f=fs("(pointer: coarse)");d.useEffect(()=>{var x;!h&&!f&&((x=s.current)==null||x.focus())},[]);const m=(x,k)=>{a(!0),l(null),(async()=>{try{const{conversationId:j}=await Je.startConversation(e.id),v=await Je.send(e.id,{conversationId:j,text:x,...k.length>0?{attachmentIds:k.map(w=>w.artifactId)}:{}});n(at(e.id,v.conversationId))}catch(j){l(j instanceof he?j.message:String(j)),c({text:x,at:Date.now()}),a(!1)}})()},p=(((g=u.data)==null?void 0:g.conversations)??[]).slice(0,LS);return t.jsxs("div",{className:"home-ask",children:[i?t.jsx(ae,{message:i}):null,t.jsx(yy,{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?t.jsxs("div",{className:"home-continue",children:[t.jsx("span",{className:"home-continue-label",id:`home-continue-${e.id}`,children:"Continue"}),t.jsx("ul",{className:"home-continue-chips","aria-labelledby":`home-continue-${e.id}`,children:p.map(x=>{const k=at(e.id,x.id),j=x.opening??x.preview??"Untitled conversation",v=gw(x.lastMessageAt??x.createdAt??x.startedAt??null);return t.jsx("li",{children:t.jsxs("a",{className:"home-continue-chip",href:k,title:j,onClick:w=>{w.preventDefault(),n(k)},children:[t.jsx("span",{className:"home-continue-title",children:fr(j,hJ)}),v?t.jsx("span",{className:"home-continue-when",children:v}):null]})},x.id)})})]}):null]})}function mJ(e){const n=e.indexOf("?");if(n===-1)return;const s=new URLSearchParams(e.slice(n+1)).get("tip");return s&&/^[a-z0-9-]{1,40}$/.test(s)?s:void 0}function pJ({navigate:e,preview:n,hidden:s}){var c;const r=ge(()=>A.currentTip(n),[n]),[a,i]=d.useState(null),l=((c=r.data)==null?void 0:c.tip)??null;if(!l||a===l.id||s)return null;const o=u=>{i(l.id),!n&&(u==="dismiss"?A.dismissTip(l.id):A.laterTip(l.id)).catch(()=>{})};return t.jsx("div",{className:"home-tip","data-tip":l.id,children:t.jsxs(G,{children:[t.jsxs("div",{className:"ui-notice-row",children:[t.jsx("p",{className:"ui-notice-body",children:l.text}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":"Not now",title:"Not now",onClick:()=>o("later"),children:t.jsx(oe,{name:"close"})})]}),t.jsxs(ne,{children:[t.jsx(ot,{}),t.jsx($,{variant:"ghost",size:"sm",onClick:()=>o("dismiss"),children:"Not this again"}),t.jsx($,{variant:"accent",size:"sm",onClick:()=>e(l.action.route),children:l.action.label})]})]})})}const Bv="buddi.tipsOpen";function gJ(e){return bu(e,{compact:!0})}function xJ(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 ${gJ(e.shownAt)}`:"Shown"}}function vJ(){try{return window.localStorage.getItem(Bv)==="1"}catch{return!1}}function jJ(){const e=ge(()=>A.tips(),[]),[n,s]=d.useState(vJ),r=d.useCallback(a=>{s(a);try{a?window.localStorage.setItem(Bv,"1"):window.localStorage.removeItem(Bv)}catch{}},[]);return{open:n,setOpen:r,list:e}}function wJ({tips:e}){const{open:n,setOpen:s,list:r}=e,a=!!r.data&&!r.data.enabled&&r.data.tips.some(i=>i.status==="today");return t.jsxs("button",{type:"button",className:"ui-icon-btn home-tips-btn","aria-label":a?"Tips, one due today":"Tips","aria-pressed":n,title:"Tips","data-open":n,onClick:()=>{n||r.reload(),s(!n)},children:[t.jsx(oe,{name:"bulb"}),a?t.jsx("span",{className:"home-tips-dot","data-testid":"tips-dot"}):null]})}function yJ({tips:e,navigate:n}){var k,j;const{open:s,setOpen:r,list:a}=e,[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null);if(!s)return null;const f=((k=a.data)==null?void 0:k.tips)??null,m=u??((j=a.data)==null?void 0:j.enabled)??!0,p=v=>l(v instanceof he?v.message:String(v)),g=v=>{c(v),l(null),A.restoreTip(v).then(()=>a.reload(),p).finally(()=>c(null))},x=v=>{c("switch"),l(null),h(v),A.saveTipsSettings(v).then(w=>{h(w.enabled),a.reload()}).catch(w=>{h(!v),p(w)}).finally(()=>c(null))};return t.jsx("div",{className:"home-tips","data-testid":"tips-section",children:t.jsxs(pe,{title:"Tips",children:[t.jsx(ae,{message:a.error??i}),t.jsx("div",{className:"tips-grid",children:(f??[]).map(v=>t.jsx("div",{className:"tips-card","data-tip":v.id,"data-status":v.status,children:t.jsxs(Ps,{tone:v.status==="today"?"accent":void 0,children:[t.jsx("div",{children:t.jsx(Ae,{tone:v.status==="today"?"accent":"muted",children:xJ(v)})}),t.jsx("p",{className:"tips-card-text",children:v.text}),t.jsxs(ne,{children:[t.jsx(ot,{}),v.status==="dismissed"?t.jsx($,{size:"sm",disabled:o===v.id,onClick:()=>g(v.id),children:"Bring back"}):t.jsx($,{size:"sm",variant:v.status==="today"?"accent":void 0,onClick:()=>n(v.action.route),children:v.action.label})]})]})},v.id))}),t.jsxs(ne,{children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:m,disabled:o==="switch"||f===null,onChange:v=>x(v.target.checked)}),t.jsx("span",{children:"Tips on Home"})]}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}function bJ(e){return e.length<=1?e[0]??"":e.length<=4?`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`:`${e.slice(0,3).join(", ")} and ${e.length-3} more`}function kJ({glance:e,team:n,onClose:s}){if(!e.today||!e.note)return null;const r=n.filter(a=>a.available).slice(0,8);return t.jsxs("section",{className:"bd-card","aria-label":"Your birthday",children:[e.image?t.jsxs("figure",{className:"bd-art",children:[t.jsx("img",{src:Ur(e.image),alt:"A picture your team made for your birthday"}),t.jsx("figcaption",{children:"Made for you"})]}):null,t.jsxs("div",{className:"bd-body",children:[t.jsx("p",{className:"bd-kicker",children:"From your team"}),t.jsx("p",{className:"bd-note",children:e.note}),r.length>0?t.jsxs("div",{className:"bd-foot",children:[t.jsx("span",{className:"bd-faces",children:r.slice(0,4).map(a=>t.jsx(jn,{agents:n,id:a.id,size:"sm"},a.id))}),t.jsx("span",{className:"bd-sign",children:bJ(r.map(a=>a.name))})]}):null]}),t.jsx("button",{type:"button",className:"ui-icon-btn bd-close","data-size":"sm","aria-label":"Put it away for today",title:"Put it away for today",onClick:s,children:t.jsx(oe,{name:"close"})})]})}const NJ="Write these down; they open your backups and only you have them.";function SJ(){const e=ge(()=>A.passphraseNotice(),[]),[n,s]=d.useState(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(null),p=e.data;if(o||!p||!p.show)return null;const g="passphrase"in p?p.passphrase:f,x=()=>{g!==null&&navigator.clipboard.writeText(g).then(()=>s("done"),()=>s("failed"))},k=()=>{a(!0),l(null),A.revealBackupPassphrase(u).then(v=>{m(v.passphrase),h("")}).catch(v=>l(v instanceof he?v.message:String(v))).finally(()=>a(!1))},j=()=>{a(!0),l(null),A.acknowledgePassphrase().then(()=>c(!0)).catch(v=>l(v instanceof he?v.message:String(v))).finally(()=>a(!1))};return t.jsx(pe,{title:"Your backup passphrase",panel:!0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:i}),t.jsx("p",{className:"ui-card-meta",children:NJ}),g!==null?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"backup-phrase mono","aria-label":"Your backup passphrase",children:g}),t.jsx("p",{className:"ui-card-meta",children:"Later, Settings → Backup shows them again behind your PIN."}),t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:x,children:n==="done"?"Copied":n==="failed"?"Could not copy":"Copy"}),t.jsx($,{variant:"accent",disabled:r,onClick:j,children:"I saved it"})]})]}):t.jsxs(t.Fragment,{children:[t.jsx(ie,{label:"Your PIN",hint:"The one that unlocks this dashboard.",children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:"off",value:u,onChange:v=>h(v.target.value),onKeyDown:v=>{v.key==="Enter"&&u!==""&&k()}})}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",disabled:r||u==="",onClick:k,children:"Show the words"})})]})]})})}const NP="buddi.needsYouView";function CJ(){try{return window.localStorage.getItem(NP)==="list"?"list":"deck"}catch{return"deck"}}function EJ(e){try{window.localStorage.setItem(NP,e)}catch{}}function $J(e,n,s){const r=(n.alsoFrom??[]).filter(a=>a!==n.agentId).map(s);return r.length===0?e:`${e} · also ${r.join(", ")}`}function AJ({rows:e,agents:n,label:s,onOpen:r,onDone:a}){const[i,l]=d.useState(0);if(e.length===0)return t.jsx(Ne,{mascot:!0,children:"Nothing needs you. Your agents are on it."});const o=Math.min(i,e.length-1),c=e[o],u=e.length>1,h=x=>l((o+x+e.length)%e.length),f=()=>r(c),m=()=>a(c),p=x=>{const k=x.target;k.closest('input, textarea, select, [contenteditable="true"]')||(x.key==="ArrowRight"&&u?(x.preventDefault(),h(1)):x.key==="ArrowLeft"&&u?(x.preventDefault(),h(-1)):x.key==="Enter"&&!k.closest("button, a")?(x.preventDefault(),(c.link||c.agentId)&&f()):(x.key==="d"||x.key==="Delete")&&!x.metaKey&&!x.ctrlKey&&!x.altKey&&(x.preventDefault(),m()))},g=t.jsxs("span",{className:"home-deck-from",children:[c.agentId?t.jsx(jn,{agents:n,id:c.agentId,size:"sm"}):null,t.jsx("span",{children:s(c)})]});return t.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:t.jsx(Ps,{as:"article",title:g,meta:t.jsx("span",{className:"ui-card-meta",children:c.state==="held"?"today":Ge(c.createdAt)}),actions:t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"home-deck-count","aria-live":"polite",children:[o+1," of ",e.length]}),t.jsx($,{size:"sm",variant:"ghost","aria-label":"Previous",disabled:!u,onClick:()=>h(-1),children:t.jsx(oe,{name:"chevron-left"})}),t.jsx($,{size:"sm",variant:"ghost","aria-label":"Next",disabled:!u,onClick:()=>h(1),children:t.jsx(oe,{name:"chevron-right"})})]}),foot:t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:m,children:"Done"}),c.link||c.agentId?t.jsx($,{variant:"accent",onClick:f,children:"Open"}):null]}),children:t.jsxs("div",{className:"home-deck-body",children:[t.jsx("p",{className:"home-deck-title",children:Qc(c)}),c.text?t.jsx("p",{className:"home-deck-text",children:c.text}):null,c.action?t.jsx("p",{className:"home-deck-text",children:t.jsx("strong",{children:c.action})}):null]})})})}function TJ({timezone:e,navigate:n,agents:s,defaultAgentId:r,attention:a,update:i,connectionSignals:l=[],hash:o="",pluginPages:c}){var qe,yt,le,Ce,Ze,xt,Ct,It,Ot,bn,fn,Kn,en,kn,Pt,mn,tn,Te,st;const u=ge(()=>A.overview(),[],15e3),h=ge(()=>A.approvals(),[],1e4),f=ge(()=>A.missions(),[],6e4),m=ge(()=>A.reminders(),[],6e4),p=ge(()=>A.conversations(),[],3e4),g=ge(()=>A.offers(),[],3e4),x=ge(()=>A.proposals(),[],6e4),k=ge(()=>A.agentOffers(),[],6e4),j=ge(()=>A.owner(),[]),v=ge(()=>A.birthday(),[],5*6e4),w=ge(()=>A.notificationsNeedingYou(),[],3e4),y=d.useMemo(()=>GA(s,r??null),[s,r]),N=aJ(s,r),{busy:b,note:S,failure:C,decide:T}=by(()=>{h.reload(),u.reload()}),E=u.data,R=s.find(H=>H.id===r)??null,M=H=>{var de;return((de=s.find(et=>et.id===H))==null?void 0:de.name)??H},O=H=>de=>{de.preventDefault(),n(H)},I=((qe=h.data)==null?void 0:qe.pending)??[],z=((yt=E==null?void 0:E.jobs)==null?void 0:yt.failed)??0,U=((le=E==null?void 0:E.sentinels)==null?void 0:le.openUrgent)??0,D=((Ce=x.data)==null?void 0:Ce.open.length)??0,P=(((Ze=k.data)==null?void 0:Ze.offers)??[]).filter(H=>!I.some(de=>PR(de,H.plugin,H.agent))),K=IJ(((xt=w.data)==null?void 0:xt.notifications)??[],I),[F,Q]=d.useState(new Set),[_,re]=d.useState(CJ),Y=K.filter(H=>!F.has(H.id)),B=H=>{Q(de=>new Set(de).add(H.id)),A.notificationSeen(H.id).catch(()=>{})},q=H=>{B(H);const de=H.link??(H.agentId?at(H.agentId):null);de&&n(de)},J=H=>$J(H.agentId?M(H.agentId):H.pluginId?CT(H.pluginId,c==null?void 0:c.all):RJ[H.kind],H,M),Z=DJ(E==null?void 0:E.dismissed,()=>u.reload()),fe=(((Ct=E==null?void 0:E.sentinels)==null?void 0:Ct.errors)??[]).filter(H=>!Z.is(`watcher-error:${H.sentinelId}`,H.error)),ve=((E==null?void 0:E.mail)??[]).filter(H=>H.lastError&&!Z.is(`source-error:${H.sourceId}`,H.lastError)),Oe=PJ(a),W=l.filter(H=>!Z.is(`connection:${H.id}`,H.sentence)),se=(((It=E==null?void 0:E.needsYou)==null?void 0:It.recovery)??0)>0,X=I.length+Oe.length+(z>0?1:0)+(U>0?1:0)+(D>0?1:0)+P.length+K.length+W.length+(se?1:0);d.useEffect(()=>{var H,de;o===to&&((de=(H=document.getElementById(Wv))==null?void 0:H.scrollIntoView)==null||de.call(H,{behavior:"smooth",block:"start"}))},[o]);const je=d.useMemo(()=>{var H,de;return zJ(((H=f.data)==null?void 0:H.missions)??[],((de=m.data)==null?void 0:de.reminders)??[])},[f.data,m.data]),be=(((Ot=p.data)==null?void 0:Ot.conversations)??[]).slice(0,5),xe=((bn=g.data)==null?void 0:bn.offers)??[],we=xe.slice(0,LJ),Ie=jJ(),ke=xe.length-we.length,me=vI(()=>u.reload()),$e=mG(),_e=d.useMemo(()=>pG($e.answer),[$e.answer]),Le=GJ((E==null?void 0:E.needsYou)??{approvals:I.length,questions:Oe.length,failed:z,urgent:U,proposals:D,agentsToSetUp:P.length,asks:K.length,signIns:W.length,recovery:se?1:0},(E==null?void 0:E.paused)??!1);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"home-band",children:[t.jsxs("header",{className:"home-top",children:[t.jsxs("div",{className:"home-top-text",children:[t.jsxs("p",{className:"home-date",children:[t.jsx("span",{children:HJ(E==null?void 0:E.now,e)}),t.jsx(K7,{glances:E==null?void 0:E.glances,navigate:n,except:_e,hiding:me}),t.jsx(wJ,{tips:Ie})]}),t.jsx("h1",{className:"home-greeting",children:(fn=v.data)!=null&&fn.today?BJ(v.data.name??((Kn=j.data)==null?void 0:Kn.preferredName)??((en=j.data)==null?void 0:en.displayName)):WJ(E==null?void 0:E.now,e,((kn=j.data)==null?void 0:kn.preferredName)||((Pt=j.data)==null?void 0:Pt.displayName))}),t.jsx(YJ,{items:Le,navigate:n})]}),t.jsx("div",{className:"home-side",children:t.jsx(tT,{size:"lg",anim:"idle"})})]}),(mn=v.data)!=null&&mn.today&&v.data.note&&!Z.is("birthday",v.data.date)?t.jsx(kJ,{glance:v.data,team:y,onClose:()=>Z.close("birthday",v.data.date)}):null]}),t.jsxs("div",{className:"home",children:[R?t.jsx(fJ,{agent:R,navigate:n},R.id):null,t.jsx(yJ,{tips:Ie,navigate:n}),t.jsx(pJ,{navigate:n,preview:mJ(o),hidden:Ie.open}),t.jsx(SJ,{}),i&&i.updateAvailable&&!i.checkout&&i.latest&&!Z.is("update",i.latest)?t.jsx(G,{tone:"accent",action:t.jsx(Ml,{label:"Not now — tell me at the next version",onClick:()=>Z.close("update",i.latest)}),children:t.jsxs("p",{children:["A newer buddi is ready: ",t.jsx("span",{className:"mono",children:i.latest}),"."," ",t.jsx("a",{href:Fe("system"),onClick:O(Fe("system")),children:"Upgrade from Settings → Version."})]})}):null,fe.map(H=>t.jsxs(G,{tone:"warning",action:t.jsx(Ml,{label:"Hide until the error changes",onClick:()=>Z.close(`watcher-error:${H.sentinelId}`,H.error)}),children:["Watcher ",H.sentinelId," failed: ",H.error]},H.sentinelId)),ve.map(H=>t.jsxs(G,{tone:"warning",action:t.jsx(Ml,{label:"Hide until the error changes",onClick:()=>Z.close(`source-error:${H.sourceId}`,H.lastError)}),children:["Source ",H.sourceId,": ",H.lastError]},H.sourceId)),t.jsx(ae,{message:u.error??h.error??C}),S?t.jsx(G,{tone:"good",role:"status",children:S}):null,X>0?t.jsx("div",{id:Wv,className:"home-needs",children:t.jsx(pe,{title:"Needs you",aside:t.jsx("a",{href:Bx,onClick:O(Bx),children:"All notifications"}),actions:K.length>0?t.jsx(Gt,{label:"Show what needs you as",options:[{value:"list",label:"List"},{value:"deck",label:"Deck"}],value:_,onChange:H=>{re(H),EJ(H)}}):void 0,children:t.jsxs(ue,{children:[I.map(H=>t.jsx(ky,{action:H,timezone:e,busy:b===H.id,onDecide:T,agentName:M(H.agentId)},H.id)),U>0?t.jsx(G,{tone:"warning",children:t.jsx("a",{href:`${At}/alerts`,onClick:O(`${At}/alerts`),children:VJ(U,((tn=E==null?void 0:E.sentinels)==null?void 0:tn.decisions)??[])})}):null,Oe.length>0||K.length>0&&_==="list"?t.jsx(Xe,{flush:!0,children:t.jsxs(ct,{children:[Oe.map(H=>t.jsx(rt,{href:H.route,onClick:()=>n(H.route),lead:t.jsx(jn,{agents:s,id:H.agentId,size:"sm"}),title:"Asked you a question",sub:`${M(H.agentId)} · waiting for your answer`,side:Ge(H.at)},H.agentId)),_==="list"?Y.map(H=>t.jsx(rt,{href:H.link??void 0,onClick:()=>q(H),lead:H.agentId?t.jsx(jn,{agents:s,id:H.agentId,size:"sm"}):void 0,title:Qc(H),sub:H.action?`${J(H)} · ${H.action}`:J(H),side:H.state==="held"?"today":Ge(H.createdAt)},H.id)):null]})}):null,K.length>0&&_==="deck"?t.jsx(AJ,{rows:Y,agents:s,label:J,onOpen:q,onDone:B}):null,z>0?t.jsx(G,{tone:"critical",children:t.jsxs("a",{href:`${At}/jobs?state=failed`,onClick:O(`${At}/jobs?state=failed`),children:[z," failed job",z===1?"":"s",". See why, then retry or dismiss ",z===1?"it":"them","."]})}):null,D>0?t.jsx(G,{tone:"accent",children:t.jsxs("a",{href:Fe("proposals"),onClick:O(Fe("proposals")),children:[D," proposal",D===1?"":"s"," from your agents to keep or discard."]})}):null,W.map(H=>t.jsx(G,{tone:"accent",action:t.jsx(Ml,{label:"Not now — tell me if it changes",onClick:()=>Z.close(`connection:${H.id}`,H.sentence)}),children:t.jsxs("p",{children:[H.sentence," ",t.jsx("a",{href:Fe("connections"),onClick:O(Fe("connections")),children:"Settings → Connections."})]})},H.id)),P.map(H=>t.jsx(Xe,{children:t.jsx(Sy,{plugin:H.plugin,agent:H.agent,text:H.text,label:`Create @${H.handle}`,handle:H.handle,onDismiss:()=>{A.dismissAgentOffer(H.plugin,H.agent).then(()=>k.reload())}})},`${H.plugin}/${H.agent}`)),se?t.jsx(G,{tone:"warning",children:t.jsxs("p",{children:[bP," ",t.jsx("a",{href:Wx,onClick:O(Wx),children:"Open the checklist."})]})}):null]})})}):null,t.jsx(jG,{widgets:$e,navigate:n}),t.jsxs(pe,{title:"Your team",aside:N?t.jsx("a",{href:un(),onClick:O(un()),children:"See all teammates"}):t.jsx("a",{href:bt,onClick:O(bt),children:"All agents"}),children:[s.length===0?t.jsx(Ne,{mascot:!0,children:"No agents yet. Add one under Agents."}):t.jsxs("div",{className:"home-team",children:[y.map(H=>{const de=rm(a.get(H.id));return t.jsxs("a",{className:"home-face",...Hi(So(H)),href:at(H.id),onClick:O(at(H.id)),"data-waiting":de?"true":void 0,"data-unavailable":H.available?void 0:"true",children:[t.jsx(On,{id:H.id,name:H.name,size:"lg",unavailable:!H.available,face:H}),t.jsxs("span",{className:"home-face-text",children:[t.jsx("span",{className:"home-face-name",children:H.name}),t.jsx("span",{className:"home-face-status",children:de?qJ(de):H.available?fr(H.description,60):H.unavailableReason??"Cannot run right now."})]})]},H.id)}),N?null:t.jsxs("a",{className:"team-add",href:un(),onClick:O(un()),"data-testid":"team-add",children:[t.jsx(oe,{name:"plus",size:14}),"Add a teammate"]})]}),N?t.jsx(uJ,{navigate:n}):null]}),we.length>0?t.jsx(pe,{title:"On offer",aside:t.jsxs("span",{className:"ui-row",children:[ke>0?t.jsxs("a",{href:`${bt}?tab=offers`,onClick:O(`${bt}?tab=offers`),children:[ke," more"]}):null,t.jsx(_I,{ids:xe.map(H=>H.id),onDone:()=>g.reload()})]}),children:t.jsx("div",{className:"home-offers",children:we.map(H=>t.jsx(_J,{offer:H,agents:s,open:O(Ft(H.agentId,"offers")),onDismissed:()=>g.reload()},H.id))})}):null,t.jsx(P7,{}),(st=(Te=x.data)==null?void 0:Te.digest)!=null&&st.latest&&OJ(x.data.digest.latest,E==null?void 0:E.now,Z.is)?t.jsx(KJ,{digest:x.data.digest.latest,go:O,onClose:()=>Z.close(SP,x.data.digest.latest.at)}):null,t.jsxs("div",{className:"home-columns",children:[t.jsx(pe,{title:"Coming up",aside:t.jsx("a",{href:`${bt}?tab=missions`,onClick:O(`${bt}?tab=missions`),children:"All missions"}),children:t.jsx(Xe,{flush:!0,children:je.length===0?t.jsx(Ne,{mascot:!0,children:"Nothing scheduled. Missions and reminders will show here."}):t.jsx(ct,{children:je.map(H=>t.jsx(rt,{href:H.route,onClick:()=>n(H.route),lead:t.jsx(jn,{agents:s,id:H.agentId,size:"sm"}),title:H.title,sub:`${H.kind} for ${M(H.agentId)}`,side:Ge(H.at)},H.key))})})}),t.jsx(pe,{title:"Lately",aside:t.jsx("a",{href:At,onClick:O(At),children:"All activity"}),children:t.jsx(Xe,{flush:!0,children:be.length===0?t.jsx(Ne,{mascot:!0,children:"Nothing has run yet. Say hello to someone on your team."}):t.jsx(ct,{children:be.map(H=>t.jsx(rt,{href:at(H.agentId,H.id),onClick:()=>n(at(H.agentId,H.id)),lead:t.jsx(jn,{agents:s,id:H.agentId,size:"sm"}),title:H.opening?fr(H.opening,80):"Untitled conversation",sub:`${M(H.agentId)}, ${H.messageCount} message${H.messageCount===1?"":"s"}`,side:Ge(H.lastMessageAt??H.createdAt)},H.id))})})})]}),((E==null?void 0:E.home)??[]).filter(H=>!Z.is(FS(H.id),_S)).map(H=>t.jsx(QJ,{block:H,onHide:()=>Z.close(FS(H.id),_S)},H.id)),E!=null&&E.jobs&&E.missions?t.jsxs("p",{className:"home-foot muted",children:[xn(E.jobs.pending??0)," queued, ",xn(E.jobs.leased??0)," running, ",xn(E.missions.enabled)," of ",xn(E.missions.total)," missions on."," ",E.paused?t.jsx(Ae,{tone:"warning",children:"paused"}):t.jsx(Ae,{tone:"good",children:"running"})," ",t.jsx("a",{href:Zc("").replace(/\/conversations\/$/,""),onClick:O(At),children:"Activity"})," · ",t.jsx("a",{href:Fe("system"),onClick:O(Fe("system")),children:"System"})]}):null]})]})}const RJ={approval:"Approval",question:"Question",watcher:"Watcher",reminder:"Reminder",failure:"Failure",recap:"Report",plugin:"Plugin",agent:"Message"};function IJ(e,n){const s=new Set(n.map(r=>r.id));return e.filter(r=>r.needsOwner===!0&&r.kind!=="approval"&&r.kind!=="question"&&r.actedAt===null&&r.state!=="stored"&&r.seenAt===null&&!(r.actionId&&s.has(r.actionId)))}function PJ(e){const n=[];for(const s of e.values())s.question&&n.push({agentId:s.agentId,at:s.question.at,route:at(s.agentId,s.question.conversationId)});return n.sort((s,r)=>s.at.localeCompare(r.at))}const SP="digest",MJ=3*864e5;function FS(e){return`block:${e}`}const _S="hidden";function OJ(e,n,s){if(s(SP,e.at))return!1;const r=Date.parse(e.at),a=n?Date.parse(n):Date.now();return Number.isFinite(r)&&a-r<MJ}function DJ(e,n){const[s,r]=d.useState({});return{is:(l,o)=>(s[l]??(e==null?void 0:e[l]))===o,close:(l,o)=>{r(c=>({...c,[l]:o})),A.homeDismiss(l,o).then(n,()=>{r(c=>{const u={...c};return delete u[l],u})})}}}function Ml({label:e,onClick:n}){return t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":e,title:e,onClick:n,children:t.jsx(oe,{name:"close"})})}const LJ=6,FJ=500;function _J({offer:e,agents:n,open:s,onDismissed:r}){const[a,i]=d.useState(!1),l=d.useRef(null),o=d.useRef(!1),c=()=>{a||(i(!0),A.dismissOffer(e.id).then(r).finally(()=>i(!1)))},u=()=>{l.current!==null&&clearTimeout(l.current),l.current=null};return t.jsxs("span",{className:"home-offer-chip",children:[t.jsxs("a",{className:"home-offer",href:Ft(e.agentId,"offers"),onClick:h=>{if(o.current){o.current=!1,h.preventDefault();return}s(h)},title:e.prompt,onTouchStart:()=>{o.current=!1,u(),l.current=setTimeout(()=>{o.current=!0,c()},FJ)},onTouchEnd:u,onTouchMove:u,onTouchCancel:u,children:[t.jsx(jn,{agents:n,id:e.agentId,size:"sm"}),t.jsx("span",{children:e.label})]}),t.jsx("button",{type:"button",className:"home-offer-x","aria-label":`Dismiss ${e.label}`,disabled:a,onClick:c,children:"×"})]})}function zJ(e,n){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:Ft(r.agentId,"missions")});for(const r of n)r.state==="pending"&&s.push({key:`r-${r.id}`,at:r.dueAt,title:r.text,kind:"Reminder",agentId:r.agentId,route:Ft(r.agentId,"reminders")});return s.sort((r,a)=>r.at.localeCompare(a.at)).slice(0,5)}function UJ(e,n){try{const s=new Intl.DateTimeFormat("en-GB",{hour:"numeric",hourCycle:"h23",timeZone:n}).format(e?new Date(e):new Date);return Number(s)}catch{return new Date().getHours()}}function BJ(e){return e?`Happy birthday, ${e}.`:"Happy birthday."}function WJ(e,n,s){const r=UJ(e,n),a=s!=null&&s.trim()?`, ${s.trim()}`:"";return r<5?`Still up${a}?`:r<12?`Good morning${a}.`:r<18?`Good afternoon${a}.`:`Good evening${a}.`}function HJ(e,n){try{return wr(e?new Date(e):new Date,n,{weekday:!0})}catch{return mt(e??null,n)}}function KJ({digest:e,go:n,onClose:s}){var i,l;const r=e.summary??[],a=Object.entries(((i=e.feedback)==null?void 0:i.byAgent)??{}).map(([o,c])=>[o,[c.up>0?`${c.up} 👍`:"",c.down>0?`${c.down} 👎`:"",c.neutral>0?`${c.neutral} other`:""].filter(Boolean).join(" ")]).filter(([,o])=>o!=="").map(([o,c])=>{var u;return`${((u=e.agentNames)==null?void 0:u[o])??o}: ${c}`});return r.length===0&&a.length===0?null:t.jsx(pe,{title:"What buddi learned this week",aside:t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:Ge(e.at)}),s?t.jsx(Ml,{label:"Hide until next week",onClick:s}):null]}),children:t.jsx(Xe,{children:t.jsxs(ue,{divided:!0,children:[r.length>0?t.jsx("ul",{className:"home-digest-list","data-plain":"",children:r.map(o=>t.jsxs("li",{children:[o.text,o.link?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:o.link.route,onClick:n(o.link.route),children:o.link.label})]}):null]},o.key))}):null,a.length>0?t.jsxs("div",{"data-testid":"digest-reactions",children:[t.jsx("p",{className:"ui-card-meta",children:"Your reactions"}),t.jsxs("ul",{className:"home-digest-list",children:[a.map(o=>t.jsx("li",{children:o},o)),(((l=e.feedback)==null?void 0:l.notes)??[]).map((o,c)=>{var u;return t.jsxs("li",{children:["What was off (",((u=e.agentNames)==null?void 0:u[o.agentId])??o.agentId,"): ",o.note]},`note-${c}`)})]})]}):null]})})})}function VJ(e,n){const s=n[0];return s?e>1?`${s.title} And ${e-1} more to decide on.`:s.title:`${e} alert${e===1?"":"s"} from your watchers need${e===1?"s":""} a decision.`}const Wv="home-needs";function GJ(e,n=!1){const s=(a,i,l=`${i}s`)=>a===1?i:l,r=[];return e.approvals>0&&r.push({key:"approvals",count:e.approvals,label:s(e.approvals,"approval")}),e.questions>0&&r.push({key:"questions",count:e.questions,label:s(e.questions,"question")}),e.urgent>0&&r.push({key:"urgent",count:e.urgent,label:s(e.urgent,"urgent alert"),tone:"critical",route:`${At}/alerts`}),e.failed>0&&r.push({key:"failed",count:e.failed,label:s(e.failed,"failed job"),tone:"critical",route:`${At}/jobs?state=failed`}),n&&r.push({key:"paused",count:null,label:"Paused",route:`${At}/jobs`}),e.proposals>0&&r.push({key:"proposals",count:e.proposals,label:s(e.proposals,"proposal"),route:Fe("proposals")}),e.asks>0&&r.push({key:"asks",count:e.asks,label:s(e.asks,"request")}),e.signIns>0&&r.push({key:"signins",count:e.signIns,label:s(e.signIns,"connection to check","connections to check")}),e.agentsToSetUp>0&&r.push({key:"agents",count:e.agentsToSetUp,label:s(e.agentsToSetUp,"agent to set up","agents to set up")}),e.recovery>0&&r.push({key:"recovery",count:null,label:"Restore to finish"}),r}function YJ({items:e,navigate:n}){if(e.length===0)return t.jsx("p",{className:"home-calm",children:"Nothing needs you. Your agents are on it."});const s=()=>{var r,a;(a=(r=document.getElementById(Wv))==null?void 0:r.scrollIntoView)==null||a.call(r,{behavior:"smooth",block:"start"})};return t.jsx("p",{className:"home-counts",children:e.map((r,a)=>{const i=t.jsxs(t.Fragment,{children:[r.count!==null?t.jsxs(t.Fragment,{children:[t.jsx("strong",{children:r.count})," "]}):null,r.label]});return t.jsxs(d.Fragment,{children:[a>0?t.jsx("span",{className:"home-count-sep","aria-hidden":"true",children:"·"}):null,r.route?t.jsx("a",{className:"home-count","data-tone":r.tone,href:r.route,onClick:l=>{l.preventDefault(),n(r.route)},children:i}):t.jsx("button",{type:"button",className:"home-count","data-tone":r.tone,onClick:s,children:i})]},r.key)})})}function qJ(e){return e.charAt(0).toUpperCase()+e.slice(1)}function QJ({block:e,onHide:n}){const[s,r]=d.useState(!1),a=e.sensitive===!0&&!s;d.useEffect(()=>{if(!e.sensitive||!s)return;const l=()=>{document.visibilityState==="hidden"&&r(!1)};return document.addEventListener("visibilitychange",l),window.addEventListener("blur",l),()=>{document.removeEventListener("visibilitychange",l),window.removeEventListener("blur",l)}},[e.sensitive,s]);const i=t.jsxs("span",{className:"ui-row",children:[e.rows.length>0&&e.rowsTitle&&!a?t.jsxs("span",{className:"muted",children:[e.rowsTitle.toLowerCase()," below"]}):null,e.sensitive?t.jsx($,{size:"sm",variant:"ghost","aria-pressed":!a,onClick:()=>r(l=>!l),children:a?"Show":"Hide"}):null,t.jsx(Ml,{label:`Hide ${e.title} from Home`,onClick:n})]});return t.jsxs(pe,{title:e.title,aside:i,children:[e.note?t.jsx(G,{tone:"warning",children:e.note}):null,e.stats.length>0?t.jsx(dm,{children:e.stats.map(l=>t.jsx(Tr,{label:l.label,value:a?"••••":l.value,note:a?void 0:l.note,tone:a?void 0:l.tone},l.label))}):null,e.rows.length>0?a?t.jsxs("p",{className:"muted",children:[e.rows.length," item",e.rows.length===1?"":"s"," hidden."]}):t.jsx(Xe,{flush:!0,children:t.jsx(ct,{children:e.rows.map((l,o)=>t.jsx(rt,{title:l.title,sub:l.sub,side:l.side?t.jsx("span",{className:l.tone==="critical"?"critical":l.tone==="good"?"good":void 0,children:l.side}):void 0},`${l.title}-${o}`))})}):null]})}const JJ="Cloudflare needs a minute or two before the first sign-in works; if its page says it can’t find the application, reload.";async function XJ(e){var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(e))}catch{}}function cf({text:e,disabled:n}){return t.jsxs("div",{className:"tailscale-command",children:[t.jsx("code",{className:"mono",children:e}),t.jsx($,{size:"sm",disabled:n,onClick:()=>{XJ(e)},children:"Copy"})]})}function ZJ({id:e}){const n=e==="tailscale"?t.jsxs(t.Fragment,{children:[t.jsx("circle",{cx:"5",cy:"5",r:"1.6"}),t.jsx("circle",{cx:"10",cy:"5",r:"1.6"}),t.jsx("circle",{cx:"15",cy:"5",r:"1.6"}),t.jsx("circle",{cx:"5",cy:"10",r:"1.6"}),t.jsx("circle",{cx:"10",cy:"10",r:"1.6"}),t.jsx("circle",{cx:"15",cy:"10",r:"1.6"}),t.jsx("circle",{cx:"10",cy:"15",r:"1.6"})]}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:"M5.6 14.8h8.6a3.2 3.2 0 0 0 .4-6.4 4.6 4.6 0 0 0-8.9-.9A3.7 3.7 0 0 0 5.6 14.8Z"}),t.jsx("path",{d:"M8.4 11.4l1.4 1.4 2.8-2.8"})]});return t.jsx("span",{className:"access-glyph","aria-hidden":"true",children:t.jsx("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:n})})}const eX={ready:t.jsx(Ae,{tone:"good",children:"Ready"}),waiting:t.jsx(Ae,{children:"Waiting"}),"needs-setup":t.jsx(Ae,{tone:"warning",children:"Needs setup"}),unanswered:t.jsx(Ae,{tone:"warning",children:"Not answering"}),off:null};function tX(){var i,l;const e=ge(()=>A.access(),[]),[n,s]=d.useState(null),r=((i=e.data)==null?void 0:i.proxied)===!0,a=(((l=e.data)==null?void 0:l.providers)??[]).filter(o=>o.id==="tailscale"||o.id==="cloudflare-access");return t.jsxs(pe,{title:"Sign in from elsewhere",aside:"checked by buddi on every visit",panel:!0,flush:!0,children:[t.jsx(ae,{message:e.error}),r?t.jsx("div",{className:"access-locked",children:t.jsx(G,{tone:"warning",children:"Change this from the computer buddi runs on."})}):null,t.jsx(ct,{children:a.map(o=>t.jsxs(d.Fragment,{children:[t.jsx(rt,{onClick:()=>s(n===o.id?null:o.id),label:`${o.title}: ${o.status.sentence}`,lead:t.jsx(ZJ,{id:o.id}),title:o.title,sub:o.status.sentence,side:t.jsxs("span",{className:"access-side",children:[eX[o.status.state],t.jsx("span",{className:"access-chevron","data-open":n===o.id?"true":void 0,children:t.jsx(oe,{name:"chevron-right",size:14})})]})}),n===o.id?t.jsx("div",{className:"access-body",children:o.id==="tailscale"?t.jsx(nX,{embedded:!0,onSaved:e.reload}):t.jsx(aX,{enabled:o.enabled,locked:r,onSaved:e.reload})}):null]},o.id))}),t.jsxs("p",{className:"access-foot",children:["Every way in gives the same session: 12 hours idle, approvals as here, the lock screen. A sign-in link from"," ",t.jsx("span",{className:"mono",children:"buddi dashboard --token"})," works everywhere."]})]})}function nX({embedded:e,onSaved:n}={}){var x;const s=ge(()=>A.tailscale(),[]),[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,h]=d.useState(!1),f=s.data,m=r??((f==null?void 0:f.login)||((x=f==null?void 0:f.self)==null?void 0:x.login)||""),p=(f==null?void 0:f.proxied)===!0,g=k=>{l(!0),c(null),h(!1),A.setTailscale({enabled:k,login:m.trim()}).then(()=>{h(!0),n==null||n()}).catch(j=>c(j instanceof he?j.message:String(j))).finally(()=>{l(!1),s.reload()})};return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error??o}),t.jsx("p",{className:"ui-card-meta",children:f?f.available&&f.self?`Tailscale is running on this machine as ${f.self.login}.`:f.available?"Tailscale is running on this machine.":"Tailscale is not running here.":"…"}),p?t.jsxs(t.Fragment,{children:[e?null:t.jsx(G,{tone:"warning",children:"Change this from the computer buddi runs on."}),t.jsx("p",{className:"ui-card-meta",children:f!=null&&f.enabled?`On, for ${m}`:"Off"})]}):null,t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(f==null?void 0:f.enabled)??!1,disabled:i||!f||p,onChange:k=>g(k.target.checked)}),t.jsx("span",{children:"Let this Tailscale login sign in"})]}),t.jsx(ie,{label:"Tailscale login",children:t.jsx("input",{type:"text",value:m,placeholder:"you@example.com",disabled:i||!f||p,onChange:k=>a(k.target.value)})}),t.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:"}),t.jsx(cf,{text:(f==null?void 0:f.serveCommand)??"tailscale serve",disabled:i||!f}),t.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."}),u?t.jsx(G,{tone:"good",role:"status",children:"Saved."}):null,t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",disabled:i||!f||p,onClick:()=>g((f==null?void 0:f.enabled)??!1),children:"Save"})})]})}const sX=["teamDomain","aud","email","publicOrigin"];function rX({onSaved:e,extra:n}={}){const s=ge(()=>A.cloudflareAccess(),[]),[r,a]=d.useState(!1),[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(null),[f,m]=d.useState(null),[p,g]=d.useState(!1),x=s.data,k=i??{teamDomain:(x==null?void 0:x.teamDomain)??"",aud:(x==null?void 0:x.aud)??"",email:(x==null?void 0:x.email)??"",publicOrigin:(x==null?void 0:x.publicOrigin)??""},j=(x==null?void 0:x.proxied)===!0,v=o||!x||j,w=(T,E)=>l({...k,[T]:E}),y=[k.teamDomain.trim()===""?"the team domain":null,k.aud.trim()===""?"the AUD tag":null,k.email.trim()===""?"your email":null].filter(T=>T!==null),N=y.length>0?`To turn this on, fill in ${y.length===1?y[0]:`${y.slice(0,-1).join(", ")} and ${y[y.length-1]}`}.`:null,b=T=>{if(T&&N){a(!0);return}a(!1),c(!0),h(null),g(!1),m(null),A.setCloudflareAccess({enabled:T,...k}).then(E=>{g(!0),E.test&&m(E.test.ok?{ok:!0,sentence:`${E.teamDomain} answered with ${E.test.keys} signing key${E.test.keys===1?"":"s"}.${E.publicOrigin?` Open ${E.publicOrigin} from another device to finish.`:""}`}:{ok:!1,sentence:E.test.error??"Cloudflare’s signing keys could not be fetched."}),l(null),e==null||e()}).catch(E=>h(E instanceof he?E.message:String(E))).finally(()=>{c(!1),s.reload()})},S=()=>{c(!0),h(null),m(null),A.testCloudflareAccess({teamDomain:k.teamDomain}).then(T=>m({ok:T.ok,sentence:T.ok&&k.publicOrigin?`${T.sentence} Open ${k.publicOrigin} from another device to finish.`:T.sentence})).catch(T=>h(T instanceof he?T.message:String(T))).finally(()=>c(!1))},C=T=>x==null?void 0:x.setup.fields.find(E=>E.key===T);return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error??u}),j?t.jsx("p",{className:"ui-card-meta",children:x!=null&&x.enabled?`On, for ${x.email} at ${x.teamDomain}`:"Off"}):null,t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(x==null?void 0:x.enabled)??!1,disabled:v,onChange:T=>b(T.target.checked)}),t.jsx("span",{children:"Let this email sign in through Cloudflare"})]}),t.jsx("ol",{className:"access-steps",children:((x==null?void 0:x.setup.steps)??[]).map(T=>t.jsxs("li",{children:[t.jsx("span",{children:T.text}),T.command?t.jsx(cf,{text:T.command,disabled:v}):null]},T.text))}),t.jsx("div",{className:"access-grid",children:sX.map(T=>{const E=C(T);return t.jsx(ie,{label:(E==null?void 0:E.label)??T,hint:E==null?void 0:E.hint,children:t.jsx("input",{type:T==="email"?"email":"text",className:T==="aud"?"mono":void 0,value:k[T],placeholder:E==null?void 0:E.placeholder,disabled:v,spellCheck:!1,autoComplete:"off",onChange:R=>w(T,R.target.value)})},T)})}),N&&!j&&!((x==null?void 0:x.enabled)??!1)?r?t.jsx(G,{tone:"critical",role:"alert",children:N}):t.jsx("p",{className:"ui-card-meta",children:N}):null,f?t.jsx(G,{tone:f.ok?"good":"critical",role:"status",children:f.sentence}):null,t.jsx("p",{className:"ui-card-meta",children:"buddi checks Cloudflare’s signature on every visit and never trusts a header alone. Anyone Cloudflare signs in with this email, on any device, is signed in to buddi."}),p&&!f?t.jsx(G,{tone:"good",role:"status",children:"Saved."}):null,n??null,t.jsxs(ne,{align:"end",children:[t.jsx($,{disabled:v||k.teamDomain.trim()==="",onClick:S,children:"Test my setup"}),t.jsx($,{variant:"accent",disabled:v,onClick:()=>b((x==null?void 0:x.enabled)??!1),children:"Save"})]})]})}const zS=["running","waiting","removing"];function aX({enabled:e,locked:n,onSaved:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState(!1);d.useEffect(()=>{n||A.cloudflareSetup().then(a).catch(()=>a(null))},[n]);const p=(r==null?void 0:r.progress.state)??"idle",g=zS.includes(p);d.useEffect(()=>{if(!g)return;const v=window.setInterval(()=>{A.cloudflareSetup().then(w=>{a(w),zS.includes(w.progress.state)||s==null||s()}).catch(()=>{})},1500);return()=>window.clearInterval(v)},[g,s]);const x=n?"manual":i??(p!=="idle"?"run":e||r!=null&&r.record?"manual":r?"offer":null),k=(v,w)=>{h(!0),c(null),v().then(y=>{a(y),w&&l(w),s==null||s()}).catch(y=>c(y instanceof he?y.message:String(y))).finally(()=>h(!1))},j=()=>k(()=>A.removeCloudflareSetup(),"run");if(x===null)return t.jsx("p",{className:"ui-card-meta",children:"…"});if(x==="manual"){const v=r!=null&&r.record&&!n?t.jsxs("p",{className:"ui-card-meta",children:["Set up by buddi for ",r.record.host," on ",r.record.zone,"."]}):null;return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:o}),t.jsx(rX,{onSaved:s,extra:v}),r!=null&&r.record&&!n?t.jsxs(ne,{align:"end",children:[t.jsx($,{disabled:u,onClick:j,children:"Remove what buddi made"}),t.jsx($,{disabled:u,onClick:()=>l("form"),children:"Set it up again"})]}):null]})}return x==="offer"?t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"buddi can make the tunnel, the DNS record and the Access application for you, with one Cloudflare API token. You run one command; buddi does the rest and tests it."}),t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:()=>l("manual"),children:"I’ll do it myself"}),t.jsx($,{variant:"accent",onClick:()=>l("form"),children:"Set it up for me"})]})]}):x==="form"?t.jsx(lX,{setup:r,busy:u,failed:o,onCancel:()=>{c(null),l(null)},onStart:v=>k(()=>A.startCloudflareSetup(v),"run")}):t.jsx(oX,{progress:(r==null?void 0:r.progress)??null,busy:u,failed:o,onStop:()=>k(()=>A.stopCloudflareSetup()),onRetry:()=>l("form"),onAdopt:()=>{const v=r==null?void 0:r.progress;v&&k(()=>A.startCloudflareSetup({host:v.host,email:v.email,adopt:!0}),"run")},onRemove:j,onAgain:()=>l("form"),tokenStored:(r==null?void 0:r.tokenStored)??!1,forgot:f,onForget:()=>k(()=>A.forgetCloudflareToken().then(v=>(m(!0),v)))})}function iX(e,n){const s=e.trim().toLowerCase().replace(/\.$/,""),r=n.filter(a=>s.endsWith(`.${a.name.toLowerCase()}`)).sort((a,i)=>i.name.length-a.name.length)[0];return r?{name:s.slice(0,-(r.name.length+1)),zone:r.name}:null}function lX({setup:e,busy:n,failed:s,onCancel:r,onStart:a}){var U,D;const i=((U=e==null?void 0:e.record)==null?void 0:U.host)??(e==null?void 0:e.progress.host)??"",[l,o]=d.useState(""),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null),[g,x]=d.useState("buddi"),[k,j]=d.useState(""),[v,w]=d.useState(i),[y,N]=d.useState(((D=e==null?void 0:e.record)==null?void 0:D.email)??(e==null?void 0:e.progress.email)??""),b=d.useRef({token:"",seq:0}),S=(e==null?void 0:e.tokenStored)===!0,C=l.trim(),T=()=>{if(!C&&!S)return;const P=b.current.seq+1;b.current={token:C,seq:P},f(!0),p(null),A.cloudflareZones(C?{token:C}:{}).then(({zones:K})=>{var _;if(b.current.seq!==P)return;u(K);const F=iX(i,K),Q=(_=K.find(re=>{var Y;return re.name===((Y=e==null?void 0:e.record)==null?void 0:Y.zone)}))==null?void 0:_.name;F?(F.name&&x(F.name),j(F.zone)):j(Q??(K.length===1?K[0].name:""))}).catch(K=>{b.current.seq===P&&(u(null),p(K instanceof he?K.message:String(K)))}).finally(()=>{b.current.seq===P&&f(!1)})};d.useEffect(()=>{S&&T()},[]);const E=P=>{o(P),u(null),p(null),f(!1),b.current={token:"",seq:b.current.seq+1}},R=c!==null&&c.length>0,M=g.trim().replace(/\.+$/,""),O=R?M&&k?`${M}.${k}`:"":v.trim(),I=c!==null&&!h&&O!==""&&y.trim()!=="",z={autoComplete:"off",spellCheck:!1,disabled:n};return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s}),t.jsx("p",{className:"ui-card-meta",children:"Open Cloudflare: the token form comes pre-filled with these permissions. Name it, create it, paste it here."}),t.jsx("ul",{className:"access-perms",children:((e==null?void 0:e.permissions)??[]).map(P=>t.jsx("li",{className:"mono",children:P},P))}),t.jsx(ne,{children:t.jsx(lt,{size:"sm",href:(e==null?void 0:e.tokenUrl)??"https://dash.cloudflare.com/profile/api-tokens",target:"_blank",rel:"noreferrer",children:"Open Cloudflare ↗"})}),t.jsx(ie,{label:"API token",hint:"Kept as an owner secret, used only to set this up and to remove it.",action:t.jsx($,{disabled:n||h||!C&&!S,onClick:T,children:"Check the token"}),children:t.jsx("input",{type:"password",className:"mono",value:l,placeholder:S?"Kept. Paste a new one to replace it":"Paste the token",...z,onChange:P=>E(P.target.value),onBlur:()=>{C&&b.current.token!==C&&T()}})}),h?t.jsx("p",{className:"ui-card-meta",role:"status",children:"Checking the token with Cloudflare…"}):null,t.jsx(ae,{message:m}),c!==null?t.jsxs("div",{className:"access-grid",children:[R?t.jsxs(t.Fragment,{children:[t.jsx(ie,{label:"Name",hint:O?`Makes ${O}.`:"The part in front of the domain.",children:t.jsx("input",{type:"text",value:g,placeholder:"buddi",...z,onChange:P=>x(P.target.value)})}),t.jsx(ie,{label:"Domain",hint:"One of the domains the token can edit.",children:t.jsxs("select",{value:k,disabled:n,onChange:P=>j(P.target.value),children:[k===""?t.jsx("option",{value:"",children:"Choose a domain"}):null,c.map(P=>t.jsx("option",{value:P.name,children:P.name},P.id))]})})]}):t.jsx(ie,{label:"Hostname",hint:"The token lists no domain; type the full name.",children:t.jsx("input",{type:"text",value:v,placeholder:"buddi.example.com",...z,onChange:P=>w(P.target.value)})}),t.jsx(ie,{label:"Your email",hint:"The one Cloudflare will let in.",children:t.jsx("input",{type:"email",value:y,placeholder:"you@example.com",...z,onChange:P=>N(P.target.value)})})]}):null,t.jsxs(ne,{align:"end",children:[t.jsx($,{disabled:n,onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:n||!I,onClick:()=>a({...C?{token:C}:{},host:O,email:y.trim(),...R?{zone:k}:{}}),children:"Set it up"})]})]})}const US="To revoke it in Cloudflare: My Profile → API Tokens.";function oX({progress:e,busy:n,failed:s,onStop:r,onRetry:a,onAdopt:i,onRemove:l,onAgain:o,tokenStored:c=!1,forgot:u=!1,onForget:h}){if(!e)return t.jsx("p",{className:"ui-card-meta",children:"…"});if(e.state==="removed"||e.state==="removing"){const m=e.state==="removed"&&!e.error&&c&&h!==void 0;return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s}),e.state==="removing"?t.jsx("p",{className:"ui-card-meta",children:"Removing what buddi made…"}):null,e.state==="removed"&&e.removed.length>0?t.jsxs(G,{tone:"good",role:"status",children:["Removed ",cX(e.removed),". Signing in through Cloudflare is off."]}):null,e.error?t.jsx(G,{tone:"critical",role:"alert",children:e.error}):null,e.uninstall?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"The connector is still installed on this computer. To remove it too:"}),t.jsx(cf,{text:e.uninstall})]}):null,m?t.jsxs("div",{children:[t.jsx("p",{children:"Your Cloudflare API token is still kept here, and still valid in Cloudflare."}),t.jsx("p",{className:"ui-card-meta",children:US})]}):null,e.state==="removed"&&u&&!c?t.jsxs(G,{role:"status",children:["Forgotten here. ",US]}):null,t.jsxs(ne,{align:"end",children:[e.error&&e.state==="removed"?t.jsx($,{disabled:n,onClick:l,children:"Remove again"}):null,m?t.jsx($,{disabled:n,onClick:h,children:"Forget the token"}):null,t.jsx($,{variant:"accent",disabled:n,onClick:o,children:"Set it up again"})]})]})}const f=e.state==="running"||e.state==="waiting";return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s}),e.state==="done"&&e.url?t.jsxs(G,{tone:"good",role:"status",children:["Done. Open ",e.url," from another device and sign in as ",e.email,". ",JJ]}):null,e.state==="stopped"&&e.error?t.jsx(G,{role:"status",children:e.error}):null,t.jsx("ol",{className:"cat-steps access-run","aria-live":"polite",children:e.steps.map(m=>t.jsxs("li",{className:"cat-step","data-state":m.state,children:[t.jsx("span",{className:"cat-step-mark",children:m.state==="done"?t.jsx(oe,{name:"check",size:12}):m.state==="failed"?t.jsx(oe,{name:"alert",size:14}):null}),t.jsxs("div",{className:"access-run-text",children:[t.jsx("span",{children:m.state==="now"&&m.id!=="connector"?`${m.text}…`:m.text}),m.state==="failed"&&m.why?t.jsx("span",{className:"access-run-why",children:m.why}):null,m.id==="connector"&&m.state!=="done"&&e.install?t.jsxs("div",{className:"access-run-more",children:[t.jsx("span",{className:"ui-card-meta",children:"Run this once in a terminal on this computer. buddi never runs sudo itself."}),t.jsx(cf,{text:e.install.command}),t.jsx("span",{className:"ui-card-meta",children:e.install.note})]}):null]})]},m.id))}),t.jsxs(ne,{align:"end",children:[f?t.jsx($,{disabled:n,onClick:r,children:"Stop waiting"}):null,e.state==="failed"||e.state==="done"||e.state==="stopped"?t.jsx($,{disabled:n,onClick:l,children:"Remove what buddi made"}):null,e.state==="failed"&&e.adoptable?t.jsx($,{disabled:n,onClick:a,children:"Try again"}):null,e.state==="failed"&&e.adoptable?t.jsx($,{variant:"accent",disabled:n,onClick:i,children:"Use it anyway"}):null,e.state==="failed"&&!e.adoptable||e.state==="stopped"?t.jsx($,{variant:"accent",disabled:n,onClick:a,children:"Try again"}):null]})]})}function cX(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}const uX=2e3,dX={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 Hv(e){return dX[e.phase]??e.detail??e.phase}const hX=new Set(["done","failed","rolled-back"]);function CP(e){return e!==void 0&&(hX.has(e.phase)||!!e.finishedAt)}function fX(e,n=!1){const[s,r]=d.useState(void 0),[a,i]=d.useState(!1),[l,o]=d.useState(null),c=d.useRef(!1);return d.useEffect(()=>{if(!e){r(void 0),i(!1),c.current=!1;return}let u=!1;const h=()=>{n&&c.current||A.backupJob(e).then(m=>{if(!u){if(n&&(KA({step:Hv(m)}),(m.phase==="failed"||m.phase==="rolled-back")&&no()),c.current){window.location.reload();return}r(m),o(null),CP(m)&&(u=!0)}}).catch(m=>{if(!u){if(m instanceof he&&m.status!==0&&m.status<500){n&&no(),o(m.message);return}c.current=!0,n||i(!0)}})};h();const f=window.setInterval(h,uX);return()=>{u=!0,window.clearInterval(f)}},[e,n]),{job:s,away:a,error:l}}function mX({job:e,away:n,error:s}){return s?t.jsx(ae,{message:s}):n?t.jsx(G,{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"?t.jsxs(G,{tone:"critical",role:"alert",children:[Hv(e)," ",e.error??""]}):t.jsxs(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:[Hv(e),e.copyLate?" The backup was made, but the copy to your folder did not go through.":"",e.error?` ${e.error}`:""]}):null}function pX(){var v,w,y,N,b,S,C;const e=ge(()=>A.backups(),[],3e4),n=yP(),s=ge(()=>A.service(),[]),[r,a]=d.useState(null),[i,l]=d.useState(!1),o=fX(r,i),[c,u]=d.useState(null),[h,f]=d.useState(!1),[m,p]=d.useState(null),g=((v=e.data)==null?void 0:v.supervised)??((w=s.data)==null?void 0:w.supervised),x=m!==null||g===!1,k=((y=e.data)==null?void 0:y.archives)??[],j=(T,E=!1)=>{f(!0),u(null),l(E),T().then(R=>{var M;E&&R.job&&nm({kind:"restore",patienceMs:HA}),a(((M=R.job)==null?void 0:M.id)??null)}).catch(R=>{R instanceof he&&R.status===409?p(R.message):u(R instanceof he?R.message:String(R))}).finally(()=>{f(!1),e.reload()})};return d.useEffect(()=>{CP(o.job)&&e.reload()},[(N=o.job)==null?void 0:N.phase]),t.jsxs(ue,{gap:"lg",children:[(b=n.data)!=null&&b.active?t.jsx(nJ,{view:n.data,onLeft:n.reload}):null,t.jsx(ae,{message:e.error??c}),t.jsx(mX,{...o}),t.jsx(xX,{onSaved:()=>e.reload()}),t.jsx(pe,{title:"Backups",panel:!0,actions:t.jsx($,{variant:"accent",size:"sm",disabled:h,onClick:()=>j(()=>A.startBackup(!0)),children:"Back up now"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs("p",{className:"ui-card-meta",children:["Kept in ",t.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."]})}),t.jsx(pe,{children:e.data&&k.length===0?t.jsx(es,{icon:"archive",title:"No backups yet",children:"Make one now, or turn on the nightly backup."}):e.data?t.jsxs(Gr,{children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:"Name"}),t.jsx("th",{children:"Taken"}),t.jsx("th",{children:"Size"}),t.jsx("th",{children:"State"}),t.jsx("th",{})]})}),t.jsx("tbody",{children:k.map(T=>{var E;return t.jsx(vX,{archive:T,busy:h,database:(E=e.data)==null?void 0:E.database,checkout:x,onVerify:()=>j(()=>A.verifyArchive(T.name)),onRestore:(R,M)=>j(()=>A.restoreArchive({name:T.name,...R?{passphrase:R}:{},...M?{confirm:M}:{}}),!0)},T.name)})})]}):t.jsx(Ne,{children:"Loading…"})})]})}),t.jsx(yX,{}),t.jsx(bX,{busy:h,checkout:x,checkoutSaid:m,database:(C=e.data)==null?void 0:C.database,onRestore:(T,E,R)=>j(()=>A.restoreUpload(T,{passphrase:E,confirm:R}),!0)})]})}const gX={enabled:!1,time:"03:00",keep:7,encryptLocal:!0,copyTo:null};function xX({onSaved:e}){var p;const n=ge(()=>A.backupSchedule(),[]),[s,r]=d.useState(null),[a,i]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1);d.useEffect(()=>{n.data&&r(n.data)},[n.data]);const h={...gX,...s??n.data??{}};if(((p=n.data)==null?void 0:p.supervised)===!1)return t.jsx(pe,{title:"Every night",panel:!0,children:t.jsx(pe,{children:t.jsx(G,{tone:"warning",children:n.data.error??"This installation schedules its own backups."})})});const f=g=>{u(!1),r({...h,...g})},m=()=>{i(!0),o(null),A.setBackupSchedule(h).then(g=>{r(g),u(!0),e()}).catch(g=>o(g instanceof he?g.message:String(g))).finally(()=>i(!1))};return t.jsx(pe,{title:"Every night",panel:!0,foot:t.jsx($,{variant:"accent",disabled:a,onClick:m,children:"Save"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:l}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.enabled,onChange:g=>f({enabled:g.target.checked})}),t.jsx("span",{children:"Back this buddi up on its own"})]}),t.jsxs(Es,{children:[t.jsx(ie,{label:"At",children:t.jsx("input",{type:"time",value:h.time,onChange:g=>f({time:g.target.value})})}),t.jsx(ie,{label:"Keep",hint:"How many to keep before the oldest is thrown away.",children:t.jsx("input",{type:"number",min:1,max:365,value:h.keep,onChange:g=>f({keep:Number(g.target.value)||1})})})]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:h.encryptLocal,onChange:g=>f({encryptLocal:g.target.checked})}),t.jsx("span",{children:"Lock each one with the passphrase"})]})]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ie,{label:"Also copy to a folder",hint:"A second disk, or a folder that syncs somewhere. Left empty, backups stay on this machine.",children:t.jsx("input",{type:"text",value:h.copyTo??"",placeholder:"/Volumes/backup/buddi",onChange:g=>f({copyTo:g.target.value===""?null:g.target.value})})}),c?t.jsxs(G,{tone:"good",role:"status",children:["Saved.",h.lastRunAt?` Last run ${Ge(h.lastRunAt)}.`:""]}):null]})})]})})}function vX({archive:e,busy:n,database:s,checkout:r,onVerify:a,onRestore:i}){const[l,o]=d.useState(!1),[c,u]=d.useState(""),[h,f]=d.useState("");return t.jsxs(t.Fragment,{children:[t.jsxs("tr",{children:[t.jsx("td",{className:"mono",children:e.name}),t.jsx("td",{children:Ge(e.createdAt)}),t.jsx("td",{children:ps(e.bytes)}),t.jsxs("td",{children:[e.encrypted?t.jsx(Ae,{tone:"good",children:"locked"}):t.jsx(Ae,{tone:"muted",children:"plain"})," ",e.envelopeOk===!1?t.jsx(Ae,{tone:"critical",children:"damaged"}):null]}),t.jsx("td",{children:t.jsxs(ne,{align:"end",children:[t.jsx($,{size:"sm",disabled:n,onClick:a,children:"Verify"}),t.jsx($,{size:"sm",variant:"ghost",onClick:()=>o(!l),children:"Restore…"})]})})]}),l?t.jsx("tr",{children:t.jsx("td",{colSpan:5,children:r?t.jsx(G,{tone:"warning",children:EP}):t.jsx(AP,{what:`${e.name}, taken ${Ge(e.createdAt)}, ${ps(e.bytes)}`,database:s,needsPassphrase:e.encrypted,passphrase:c,onPassphrase:u,confirm:h,onConfirm:f,busy:n,onCancel:()=>o(!1),onGo:()=>i(c,h)})})}):null]})}const EP="Restoring needs the packaged installation. In a checkout, run: buddi backup restore <file>";function jX(e){const n=e.split(/\r?\n/).map(r=>r.trim()).filter(r=>r!==""),s=n[0]==="buddi backup passphrase"?n[1]:n.length===1?n[0]:void 0;return s===void 0||s===""?void 0:s}function wX(e){return new Promise((n,s)=>{const r=new FileReader;r.onload=()=>n(String(r.result??"")),r.onerror=()=>s(r.error??new Error("unreadable")),r.readAsText(e)})}function $P({archive:e,onPassphrase:n}){const[s,r]=d.useState(null);return t.jsx(ie,{label:"Or read it from its .passphrase.txt",hint:s??(e?`Uninstall leaves ${e}.passphrase.txt beside the backup it took.`:"Uninstall leaves one beside the backup it took."),children:t.jsx("input",{type:"file",accept:".txt,text/plain","aria-label":"The passphrase file",onChange:a=>{var l;const i=(l=a.target.files)==null?void 0:l[0];i&&wX(i).then(o=>{const c=jX(o);if(c===void 0){r(`${i.name} has no passphrase in it.`);return}n(c),r(`Read from ${i.name}.`)},()=>r(`${i.name} could not be read.`))}})})}function AP({what:e,database:n,needsPassphrase:s,passphrase:r,onPassphrase:a,confirm:i,onConfirm:l,busy:o,onCancel:c,onGo:u}){const h=n??"",f=h===""?i.trim()!=="":i.trim()===h;return t.jsxs(ue,{gap:"sm",children:[t.jsxs(G,{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?t.jsxs(t.Fragment,{children:[t.jsx(ie,{label:"The passphrase this one was locked with",children:t.jsx("input",{type:"password",autoComplete:"off",value:r,onChange:m=>a(m.target.value)})}),t.jsx($P,{onPassphrase:a})]}):null,t.jsx(ie,{label:h?`Type ${h} to confirm`:"Type the name of this database to confirm",hint:h?void 0:"The same name buddi shows on the System tab.",children:t.jsx("input",{value:i,onChange:m=>l(m.target.value)})}),t.jsxs(ne,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:c,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:o||!f||s&&r==="",onClick:u,children:"Restore"})]})]})}function yX(){const[e,n]=d.useState(null),[s,r]=d.useState(""),[a,i]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(!1),[h,f]=d.useState(!1),[m,p]=d.useState(""),g=()=>{i(!0),o(null),A.revealBackupPassphrase(h?m:void 0).then(k=>{n(k.passphrase),f(!1),p("")}).catch(k=>{if(k instanceof he&&k.status===403&&!h){f(!0);return}o(k instanceof he?k.message:String(k))}).finally(()=>i(!1))},x=()=>{i(!0),o(null),A.setBackupPassphrase(s.trim()).then(k=>{n(k.passphrase),r(""),u(!0)}).catch(k=>o(k instanceof he?k.message:String(k))).finally(()=>i(!1))};return t.jsx(pe,{title:"The passphrase",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:l}),t.jsx("p",{className:"ui-card-meta",children:"This is the only thing that opens an encrypted backup. Write it down."}),e?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"backup-phrase mono",children:e}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"ghost",onClick:()=>n(null),children:"Hide"})})]}):t.jsxs(t.Fragment,{children:[h?t.jsx(ie,{label:"Your PIN",hint:"The one that unlocks this dashboard.",children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:"off",value:m,onChange:k=>p(k.target.value),onKeyDown:k=>{k.key==="Enter"&&m!==""&&g()}})}):null,t.jsx(ne,{align:"end",children:t.jsx($,{disabled:a||h&&m==="",onClick:g,children:"Reveal"})})]}),c?t.jsx(G,{tone:"good",role:"status",children:"Saved. Backups made from now on use it; older ones keep the one they were made with."}):null]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ie,{label:"Use my own",hint:"Six words you can read out loud beat a short one nobody can.",children:t.jsx("input",{type:"text",autoComplete:"off",value:s,onChange:k=>{u(!1),r(k.target.value)}})}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",disabled:a||s.trim()==="",onClick:x,children:"Use this one"})})]})})]})})}function bX({busy:e,checkout:n,checkoutSaid:s,database:r,onRestore:a}){const[i,l]=d.useState(null),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(!1);return n?t.jsx(pe,{title:"Restore from a file",panel:!0,children:t.jsx(pe,{children:t.jsx(G,{tone:"warning",children:s??EP})})}):t.jsx(pe,{title:"Restore from a file",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx("p",{className:"ui-card-meta",children:"A backup from another buddi, or one you keep somewhere else."}),t.jsxs(Es,{children:[t.jsx(ie,{label:"The backup file",children:t.jsx("input",{type:"file",onChange:p=>{var g;m(!1),l(((g=p.target.files)==null?void 0:g[0])??null)}})}),t.jsx(ie,{label:"Its passphrase",hint:"Only if it was locked with one.",children:t.jsx("input",{type:"password",autoComplete:"off",value:o,onChange:p=>c(p.target.value)})})]}),i!=null&&i.name.endsWith(".age")?t.jsx($P,{archive:i.name,onPassphrase:c}):null,f?null:t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",disabled:e||!i,onClick:()=>m(!0),children:"Restore"})})]})}),f&&i?t.jsx(pe,{children:t.jsx(AP,{what:`${i.name}, ${ps(i.size)}`,database:r,needsPassphrase:!1,passphrase:o,onPassphrase:c,confirm:u,onConfirm:h,busy:e,onCancel:()=>m(!1),onGo:()=>a(i,o,u)})}):null]})})}const TP="gemini-2.5-pro";function Sm(e){return e.replace(/^models\//,"")}const qy=/(image|tts|audio|live|embedding|vision|robotics|transcribe)/;function RP(e){const n=e.map(Sm);let s;for(const r of n){const a=/^gemini-(\d+(?:\.\d+)*)-pro(?:-(.+))?$/.exec(r);if(!a||qy.test(a[2]??""))continue;const i=a[1].split(".").map(Number),l=(a[2]??"")!=="";(!s||uf(i,s.version)>0||uf(i,s.version)===0&&s.preview&&!l)&&(s={id:r,version:i,preview:l})}return(s==null?void 0:s.id)??n.find(r=>r.startsWith("gemini-"))}function IP(e){let n;for(const s of e.map(Sm)){const r=/^gemini-(\d+(?:\.\d+)*)-flash(?:-(.+))?$/.exec(s);if(!r||/lite/.test(r[2]??"")||qy.test(r[2]??""))continue;const a=r[1].split(".").map(Number),i=(r[2]??"")!=="";(!n||uf(a,n.version)>0||uf(a,n.version)===0&&n.preview&&!i)&&(n={id:s,version:a,preview:i})}return n==null?void 0:n.id}function PP(e){return/^gemini-[\d.]+-pro(?:-|$)/.test(Sm(e))}function kX(e){return[...new Set(e.map(Sm).filter(n=>n.startsWith("gemini-")&&!qy.test(n)))]}function MP(e){return e.httpStatus===429||e.state==="rate-limited"||e.state==="quota-exhausted"}function uf(e,n){for(let s=0;s<Math.max(e.length,n.length);s+=1){const r=(e[s]??0)-(n[s]??0);if(r!==0)return r}return 0}function OP(e,n){if(!n||e.kind!=="openai-compatible")return!1;const s=r=>r.replace(/\/+$/,"");return s(e.baseUrl)===s(n)}function NX({embedded:e,account:n}={}){const{data:s,error:r,reload:a,loading:i}=ge(()=>A.providerAccounts(),[]),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,x]=d.useState(!1),[k,j]=d.useState(n??null);d.useEffect(()=>{n&&j(n)},[n]);const v=s==null?void 0:s.accounts.some(S=>{var C;return((C=S.login)==null?void 0:C.state)==="pending"&&S.login.expiresAt&&Date.parse(S.login.expiresAt)>Date.now()});d.useEffect(()=>{if(!v)return;const S=setInterval(a,2e3);return()=>clearInterval(S)},[v,a]);const w=async(S,C)=>{o(!0),u(null),f(""),x(!1);try{const T=await S();return f((T==null?void 0:T.warning)??C),a(),!0}catch(T){return u(T instanceof Error?T.message:"Could not apply change."),a(),!1}finally{o(!1)}},y=(s==null?void 0:s.accounts)??[],N=y.find(S=>S.id===k)??y[0],b=S=>{var C;return OP(S,(C=s==null?void 0:s.gemini)==null?void 0:C.baseUrl)?"Gemini":DP(S)};return t.jsxs(gs,{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:[t.jsx(ae,{message:r??c}),h&&t.jsx(G,{tone:"good",role:"status",children:h}),g&&t.jsx(G,{role:"status",children:i?"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&&t.jsx(Ne,{children:"Loading accounts…"}),r&&t.jsx(ne,{children:t.jsx($,{onClick:a,children:"Retry"})}),s&&t.jsxs(t.Fragment,{children:[(s.vault.locked||s.vault.kind==="none")&&t.jsx(G,{tone:"warning",children:s.vault.advice||"Run buddi init on the host to configure secure credential storage."}),m&&t.jsx(Ye,{title:"Add an account",onClose:()=>p(!1),children:t.jsx("div",{id:"new-provider-account",children:t.jsx(MX,{accounts:y,codexEnabled:s.codexEnabled,anthropicOAuthEnabled:s.anthropicOAuthEnabled,gemini:s.gemini,busy:l,run:w,onDone:S=>{p(!1),S&&j(S)}})})}),t.jsx(pe,{title:"Accounts",aside:`Secrets live in the ${SX(s.vault.kind)}; Postgres holds names and assignments only.`,actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",size:"sm",disabled:l||i,onClick:()=>{u(null),f(""),x(!0),a()},children:i?"Refreshing…":"Refresh status"}),t.jsx($,{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:y.length===0?t.jsx(es,{icon:"chip",title:"No accounts yet",children:"Add one to give your agents a model to run on."}):t.jsxs("div",{className:"accounts",children:[t.jsx("nav",{className:"accounts-list","aria-label":"Accounts",children:y.map(S=>t.jsxs("button",{type:"button",className:"accounts-row","aria-pressed":(N==null?void 0:N.id)===S.id,onClick:()=>j(S.id),children:[t.jsx(CX,{kind:S.kind,auth:S.auth}),t.jsxs("span",{className:"accounts-row-text",children:[t.jsx("span",{className:"accounts-row-name",children:S.label}),df(S)?t.jsxs("span",{className:"accounts-row-sub","data-tone":"warning",children:[b(S)," · back at ",Qy(df(S).until)]}):t.jsxs("span",{className:"accounts-row-sub",children:[b(S)," · ",S.assignedAgents.length===0?"no agents":`${S.assignedAgents.length} agent${S.assignedAgents.length===1?"":"s"}`]})]}),t.jsx(FP,{account:S})]},S.id))}),N?t.jsx(RX,{account:N,provider:b(N),anthropicOAuthEnabled:s.anthropicOAuthEnabled,busy:l,run:w},`${N.id}:${N.revision}`):null]})})]})]})}function SX(e){return e==="keychain"?"macOS Keychain":e==="file"?"encrypted file vault":e==="none"?"vault (none configured)":e}function DP(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":Wy(e)?"mlxh":"OpenAI-compatible"}function LP(e){return e.detectedContextWindowSource==="mlxh"?Hq(e.detectedContextWindowTokens):e.detectedContextWindowSource!=="provider"?"assumed":e.kind==="codex"?"from ChatGPT":"from the provider"}function CX({kind:e,auth:n}){const s=e==="anthropic"?"A":e==="codex"?"G":e==="openai"?"O":"∞",r=e==="anthropic"?"3":e==="codex"?"2":e==="openai"?"5":"4";return t.jsx("span",{className:"ui-avatar","data-tint":r,"aria-hidden":"true",title:`${e} · ${n}`,children:s})}function EX(e){return e==="connected"?"good":["rate-limited","quota-exhausted","provider-unavailable"].includes(e)?"warning":"critical"}function df(e,n=Date.now()){const s=e.rateLimit;return e.enabled&&e.configured&&s&&Date.parse(s.until)>n?s:null}const $X=()=>Intl.DateTimeFormat().resolvedOptions().timeZone;function Qy(e,n=new Date,s=$X()){const r=new Date(e),a=i=>i.toLocaleDateString("en-CA",{timeZone:s});return a(r)===a(n)?Tt(r,s):a(r)===a(new Date(n.getTime()+864e5))?`tomorrow at ${Tt(r,s)}`:pw(r,s)}function FP({account:e,long:n}){const s=df(e);if(s){const i=`Rate-limited until ${Qy(s.until)}`;return t.jsx("span",{title:i,children:t.jsx(Ae,{tone:"warning",children:n?i:"Rate-limited"})})}const r=e.enabled?e.configured?"good":"warning":void 0,a=e.enabled?e.configured?"Configured":"Needs credential":"Disabled";return t.jsx(Ae,{tone:r,children:a})}function AX({id:e}){const[n,s]=d.useState(!1),r=()=>{var a;(a=navigator.clipboard)==null||a.writeText(e).then(()=>{s(!0),window.setTimeout(()=>s(!1),1600)}).catch(()=>{})};return t.jsxs("span",{className:"accounts-id",children:[t.jsx("code",{className:"accounts-id-text",children:e}),t.jsx($,{variant:"ghost",size:"sm",onClick:r,"aria-label":"Copy the id of this account",children:n?"Copied":"Copy"})]})}function TX({account:e,provider:n}){const s=df(e);if(!s)return null;const r=s.provider??n,a=Qy(s.until);if(s.scope==="day"){const i=e.assignedAgents,l=i.length===1?i[0]:"its agents",o=s.provider==="ChatGPT",c=o?"This ChatGPT plan has reached its usage limit":s.limit!==null?`${s.freeTier?`${r}'s free tier allows`:`${r} allows this account`} ${s.limit.toLocaleString()} ${s.unit??"requests"} a day`:`${r} says this account has used today's allowance`,u=s.freeTier&&s.provider==="Gemini"?", or turn on billing for the key at aistudio.google.com":"";return t.jsx(G,{tone:"warning",title:c,action:i.length>0?t.jsx(lt,{size:"sm",href:i.length===1?Ft(i[0],"setup","brain"):bt,children:i.length===1?`Change ${i[0]}'s account`:"Change their accounts"}):void 0,children:t.jsxs("p",{children:["It resets ",/^tomorrow/.test(a)?a:`at ${a}`,". Until then buddi doesn't send this account's requests to ",r,", so ",i.length?`${l}'s runs stop with this note`:"a run on it stops with this note"," instead of failing again and again. To keep going ",o?"before then":"today",", ",i.length?`give ${l} another account`:"use another account",u,"."]})})}return t.jsx(G,{tone:"warning",title:`${r} asked buddi to slow down`,children:t.jsxs("p",{children:["It said to wait until ",a,". A run that meets this waits and tries again — up to a minute during a conversation, longer for work in the background."]})})}function Jy(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 RX({account:e,provider:n,busy:s,run:r,anthropicOAuthEnabled:a}){const[i,l]=d.useState(!1),[o,c]=d.useState(!1);return t.jsxs("section",{className:"accounts-detail","aria-label":e.label,children:[t.jsxs("div",{className:"ui-card-head",children:[t.jsx("h3",{className:"ui-card-title",children:e.label}),t.jsx(FP,{account:e,long:!0})]}),t.jsx(Xt,{items:[{label:"Provider",value:n},{label:"Default model",value:t.jsx("span",{className:"mono",children:e.defaultModel||"—"})},{label:"Context window",value:t.jsx("span",{className:"mono",children:`${(e.contextWindowTokens??e.detectedContextWindowTokens??0).toLocaleString()} tokens${e.contextWindowTokens?"":` (${LP(e)})`}`})},...e.baseUrl?[{label:"Endpoint",value:t.jsx("span",{className:"mono",children:e.baseUrl})}]:[],{label:"Used by",value:e.assignedAgents.length?t.jsx("span",{className:"ui-row",children:e.assignedAgents.map(u=>t.jsx("a",{href:Ft(u,"setup","brain"),children:u},u))}):t.jsxs("span",{className:"ui-row",children:[t.jsx("span",{className:"muted",children:"No agents"}),t.jsx("a",{href:bt,children:"Assign to an agent"})]})},...e.tokenExpiresAt?[{label:"Access token",value:`expires ${mt(e.tokenExpiresAt,Intl.DateTimeFormat().resolvedOptions().timeZone)} (not your subscription renewal date)`}]:[],{label:"ID",value:t.jsx(AX,{id:e.id})}]}),t.jsx(TX,{account:e,provider:n}),e.removalPending&&t.jsx(G,{tone:"warning",children:"Removal is pending. Unlock the vault, then retry Remove account."}),e.reconnectRequired&&t.jsxs(G,{tone:"warning",children:["Token refresh did not finish. Reconnect this ",e.kind==="codex"?"ChatGPT":"Claude"," account."]}),e.auth==="anthropic-oauth"&&t.jsx(UP,{account:e,enabled:!!a,busy:s,run:r}),e.kind==="codex"&&t.jsx(_P,{account:e,busy:s,run:r}),e.auth==="device-key"&&t.jsx(zP,{account:e,busy:s,run:r}),t.jsxs(ne,{children:[t.jsx($,{disabled:s||e.removalPending,onClick:()=>l(!0),children:"Edit account"}),t.jsx($,{disabled:s||e.removalPending,onClick:()=>void r(()=>A.saveProviderAccount({...Jy(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"&&t.jsx($,{disabled:s||!e.enabled||!e.configured,onClick:()=>void r(()=>A.testProviderAccount(e.id),"Connection test finished."),children:"Test connection"}),t.jsx($,{variant:"danger",disabled:s||e.assignedAgents.length>0,title:e.assignedAgents.length?"Reassign its agents before removing this account":void 0,onClick:()=>c(!0),children:"Remove account"})]}),e.test&&t.jsxs(t.Fragment,{children:[t.jsxs(G,{role:"status",tone:EX(e.test.state),children:[t.jsx("p",{children:e.test.message}),e.test.retryAt?t.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)&&t.jsx("p",{children:"The provider did not supply a usable Retry-After time. Reset time is unknown."})]}),t.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&&t.jsx(Ye,{title:`Edit ${e.label}`,onClose:()=>l(!1),children:t.jsx(IX,{account:e,busy:s,run:r,onDone:()=>l(!1)})}),o&&t.jsxs(G,{tone:"critical",children:[t.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."]}),t.jsxs(ne,{children:[t.jsx($,{variant:"danger",disabled:s,onClick:()=>void r(()=>A.removeProviderAccount(e.id,e.revision),"Account removed from Buddi."),children:"Confirm removal"}),t.jsx($,{disabled:s,onClick:()=>c(!1),children:"Cancel"})]})]}),t.jsx(Zt,{summary:"Details",children:t.jsxs("div",{className:"ui-prose muted",children:[e.kind==="codex"?t.jsxs(t.Fragment,{children:[t.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."}),t.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."}),t.jsx("p",{children:"After connecting, assign this account to an agent and send a test message. Model turns use your subscription allowance."})]}):t.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"&&t.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"&&t.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."}),t.jsx("p",{children:"Subscription login is separate from API-key access."})]})})]})}function _P({account:e,busy:n,run:s}){var r,a,i;return t.jsxs(t.Fragment,{children:[t.jsxs(ne,{children:[t.jsx($,{disabled:n||!e.enabled||e.removalPending||((r=e.login)==null?void 0:r.state)==="pending",onClick:()=>void s(()=>A.codexAccountAction(e.id,"login",e.revision),"Complete device sign-in below."),children:e.configured?"Reconnect ChatGPT":"Connect ChatGPT"}),((a=e.login)==null?void 0:a.state)==="pending"&&t.jsx($,{disabled:n,onClick:()=>void s(()=>A.codexAccountAction(e.id,"cancel-login",e.revision),"Sign-in cancelled."),children:"Cancel sign-in"}),t.jsx($,{disabled:n||!e.configured,onClick:()=>void s(()=>A.codexAccountAction(e.id,"logout",e.revision),"Subscription disconnected from Buddi. Your regular Codex login is unchanged."),children:"Disconnect"})]}),((i=e.login)==null?void 0:i.state)==="pending"&&t.jsxs(G,{tone:"accent",role:"status",children:[t.jsx("p",{children:"Open openai.com, type this code there and approve buddi."}),e.login.userCode&&t.jsx(Ky,{code:e.login.userCode,large:!0}),e.login.verificationUrl&&t.jsx(ne,{children:t.jsx(lt,{variant:"accent",href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open openai.com"})}),e.login.expiresAt&&t.jsxs("p",{className:"muted",children:["The code works until ",Tt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),". Start again after that; this is the sign-in timeout, not your subscription expiry."]})]}),e.login&&e.login.state!=="pending"&&t.jsx("p",{role:"status",className:"muted",children:e.login.message??`Sign-in ${e.login.state}.`})]})}function IX({account:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i}){const[l,o]=d.useState((e==null?void 0:e.label)??""),[c,u]=d.useState((e==null?void 0:e.kind)??"anthropic"),[h,f]=d.useState((e==null?void 0:e.auth)??"api-key"),[m,p]=d.useState((e==null?void 0:e.baseUrl)??""),[g,x]=d.useState((e==null?void 0:e.defaultModel)??"claude-sonnet-5"),[k,j]=d.useState(""),[v,w]=d.useState(e!=null&&e.contextWindowTokens?String(e.contextWindowTokens):""),y=b=>{u(b),f(b==="codex"?"chatgpt":"api-key"),j(""),p(b==="openai-compatible"?"http://localhost:11434/v1":""),x(b==="anthropic"?"claude-sonnet-5":b==="openai"?"gpt-5":"")},N=!l.trim()||!g.trim();return t.jsxs("form",{className:"ui-stack",onSubmit:b=>{b.preventDefault();const S=k;j(""),s(()=>A.saveProviderAccount({...e?{id:e.id,revision:e.revision}:{},label:l,kind:c,auth:h,baseUrl:m,defaultModel:g,enabled:(e==null?void 0:e.enabled)??!0,contextWindowTokens:v.trim()?Number(v):null,...S.trim()?{secret:S}:{}}),"Account saved. Agent model selections are unchanged.").then(C=>{C&&r()})},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(ie,{label:"Account name",children:t.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:l,onChange:b=>o(b.target.value),placeholder:"Anthropic — Personal"})}),t.jsx(ie,{label:"Provider",children:t.jsxs("select",{disabled:!!e,value:h==="anthropic-oauth"?"anthropic-oauth":h==="device-key"?"ollama-cloud":c,onChange:b=>{b.target.value==="anthropic-oauth"?(y("anthropic"),f("anthropic-oauth")):y(b.target.value)},children:[t.jsx("option",{value:"anthropic",children:"Anthropic API"}),t.jsx("option",{value:"openai",children:"OpenAI API"}),t.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint"}),(e==null?void 0:e.auth)==="device-key"&&t.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),(i||(e==null?void 0:e.auth)==="anthropic-oauth")&&t.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),(a||(e==null?void 0:e.kind)==="codex")&&t.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),c==="openai-compatible"&&h!=="device-key"&&t.jsxs(t.Fragment,{children:[t.jsx(ie,{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:t.jsx("input",{required:!0,type:"url",value:m,onChange:b=>p(b.target.value)})}),t.jsx(ie,{label:"Authentication",children:t.jsxs("select",{disabled:!!e,value:h,onChange:b=>{f(b.target.value),j("")},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),t.jsx(ne,{valign:"end",children:t.jsx(Hy,{accountId:e!=null&&e.configured&&e.enabled?e.id:void 0,label:"Default model",value:g,onChange:x,disabled:n},`${e==null?void 0:e.id}:${e==null?void 0:e.revision}`)}),t.jsx(ie,{label:"Context window",hint:Wy(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:t.jsx("input",{type:"number",inputMode:"numeric",min:8e3,max:2e6,step:1e3,value:v,placeholder:e!=null&&e.detectedContextWindowTokens?`${e.detectedContextWindowTokens} (${LP(e)})`:"assumed from the model",onChange:b=>w(b.target.value)})}),c==="codex"&&t.jsx("p",{className:"muted",children:"Pick a model from the list once the account is connected."}),h==="anthropic-oauth"&&t.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."}),h==="api-key"&&t.jsx(ie,{label:e?"Replacement API key (leave blank to keep)":"API key",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:k,onChange:b=>j(b.target.value)})}),e&&t.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."}),t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:r,children:"Cancel"}),t.jsx($,{type:"submit",variant:"accent",disabled:N,children:"Save account"})]})]}),N&&t.jsx("p",{className:"muted",children:"Enter an account name and default model to enable Save account. The example name is a placeholder."})]})}function zP({account:e,busy:n,run:s}){var o;const r=((o=e.login)==null?void 0:o.state)==="pending"&&e.login.attemptId?e.login:null,a=d.useRef(s);a.current=s,d.useEffect(()=>{if(!(r!=null&&r.attemptId))return;let c=!1,u=!1;const h=setInterval(()=>{c||u||(u=!0,A.ollamaPoll(e.id,r.attemptId).then(f=>{c||f.state==="waiting"||(c=!0,f.state==="connected"?a.current(async()=>{},`Connected as ${f.username}, device ${f.deviceName}.`):a.current(async()=>{throw new Error(f.message)},""))}).catch(()=>{}).finally(()=>{u=!1}))},2e3);return()=>{c=!0,clearInterval(h)}},[e.id,r==null?void 0:r.attemptId]);const i=()=>{const c=typeof window.open=="function"?window.open("","_blank"):null;s(async()=>{try{const u=await A.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 t.jsxs(t.Fragment,{children:[l&&t.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}.`}),t.jsxs(ne,{children:[t.jsx($,{disabled:n||!e.enabled||e.removalPending||!!r,onClick:i,children:e.configured?"Reconnect Ollama":"Connect Ollama"}),t.jsx($,{disabled:n||!l||e.removalPending,onClick:()=>void s(async()=>({warning:(await A.ollamaDisconnect(e.id,e.revision)).note}),"Disconnected."),children:"Disconnect"})]}),r&&t.jsxs(G,{tone:"accent",role:"status",children:[t.jsxs("p",{children:[t.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."]}),t.jsxs("p",{className:"muted",children:["buddi stops waiting at ",r.expiresAt&&Tt(new Date(r.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"."]})]})]})}function UP({account:e,enabled:n,busy:s,run:r}){var l,o,c,u,h;const[a,i]=d.useState("");return d.useEffect(()=>{i("")},[(l=e.login)==null?void 0:l.attemptId,(o=e.login)==null?void 0:o.state]),t.jsxs(t.Fragment,{children:[!n&&t.jsx(G,{tone:"warning",children:"Claude subscription sign-in is turned off on this host."}),t.jsxs(ne,{children:[t.jsx($,{disabled:s||!n||!e.enabled||e.removalPending||((c=e.login)==null?void 0:c.state)==="pending",onClick:()=>void r(()=>A.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"&&t.jsx($,{disabled:s,onClick:()=>{i(""),r(()=>A.anthropicAccountAction(e.id,"cancel-login",e.revision),"Claude sign-in cancelled.")},children:"Cancel sign-in"}),t.jsx($,{disabled:s||!e.configured||e.removalPending,onClick:()=>{i(""),r(()=>A.anthropicAccountAction(e.id,"logout",e.revision),"Claude disconnected from Buddi. This does not revoke access at Anthropic.")},children:"Disconnect Claude"})]}),((h=e.login)==null?void 0:h.state)==="pending"&&t.jsxs("form",{className:"ui-notice","data-tone":"accent",onSubmit:f=>{f.preventDefault();const m=a;i(""),r(()=>A.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:[t.jsx("p",{children:t.jsx("a",{href:e.login.verificationUrl,target:"_blank",rel:"noreferrer",children:"Open Claude consent page"})}),t.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&&Tt(new Date(e.login.expiresAt),Intl.DateTimeFormat().resolvedOptions().timeZone),"; restarting Buddi also ends it."]}),t.jsx(ie,{label:"Claude authorization code",children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,maxLength:8192,value:a,onChange:f=>i(f.target.value),disabled:s})}),t.jsx(ne,{align:"end",children:t.jsx($,{type:"submit",variant:"accent",disabled:s||!a.trim(),children:"Complete Claude sign-in"})})]})]})}const ag={anthropic:"claude-sonnet-5",openai:"gpt-5",codex:"gpt-5.5"};function ig(e,n,s){return Kv(e==="codex"?"ChatGPT subscription":e==="anthropic"?n==="anthropic-oauth"?"Claude subscription":"Anthropic API":e==="openai"?"OpenAI API":n==="device-key"?"Ollama Cloud":"Local endpoint",s)}function Kv(e,n){const s=new Set(n.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 PX="That key was refused. Check it and paste it again.";function MX({accounts:e,busy:n,run:s,onDone:r,codexEnabled:a,anthropicOAuthEnabled:i,gemini:l}){const o=e.map(X=>X.label),[c,u]=d.useState(null),[h,f]=d.useState("anthropic"),[m,p]=d.useState("api-key"),[g,x]=d.useState(()=>ig("anthropic","api-key",o)),[k,j]=d.useState(!1),[v,w]=d.useState(""),[y,N]=d.useState(""),[b,S]=d.useState(null),[C,T]=d.useState(!1),[E,R]=d.useState(""),[M,O]=d.useState(""),[I,z]=d.useState(!1),[U,D]=d.useState(!1),[P,K]=d.useState(!1),[F,Q]=d.useState(void 0),_=(X,je,be=!1)=>{f(X),p(je),N(""),S(null),R(""),O(""),z(!1),D(be),K(!1),Q(void 0),w(be?"":X==="openai-compatible"?"http://localhost:11434/v1":""),k||x(be?ig(X,"device-key",o):ig(X,je,o))},re=X=>{_("openai-compatible",X?"api-key":"device-key",!0),X&&A.ollama().then(je=>w(je.cloudBaseUrl)).catch(()=>{})},Y=()=>{l&&(_("openai-compatible","api-key"),K(!0),w(l.baseUrl),k||x(Kv("Gemini",o)))},B=()=>{_("openai-compatible","none"),Q(null),k||x(Kv("mlxh",o)),A.mlxh().then(X=>{Q(X),w(X.baseUrl)}).catch(()=>Q(void 0))},q=F!==void 0,J=c?e.find(X=>X.id===c):void 0;if(c)return J?t.jsx(OX,{account:J,busy:n,run:s,anthropicOAuthEnabled:i,onDone:()=>r(J.id)}):t.jsx(Ne,{children:"Saving…"});const Z=h==="openai-compatible"&&m!=="device-key",fe=h==="codex"||m==="anthropic-oauth"||m==="device-key",ve=!fe&&(m==="none"||y.trim()!=="")&&(!Z||v.trim()!==""),Oe=async()=>{var X,je;T(!0),R("");try{const be=await A.probeModels({kind:h,auth:m,...Z?{baseUrl:v}:{},...y.trim()?{secret:y}:{}});S(be),M||O(((X=be.models.find(xe=>xe.isDefault))==null?void 0:X.id)??((je=be.models[0])==null?void 0:je.id)??"")}catch(be){R(be instanceof Error?be.message:"Could not load models. You can still enter a custom model.")}finally{T(!1)}},W=M.trim(),se=!g.trim()||Z&&!v.trim()||Z&&!P&&!q&&!W||P&&!y.trim()||q&&!(F!=null&&F.running);return t.jsxs("form",{className:"ui-stack",onSubmit:X=>{var we;X.preventDefault();const je=y;N("");let be=W||(q?zv(F)??((we=F==null?void 0:F.models[0])==null?void 0:we.id):void 0)||(m==="device-key"?Vd:ag[h])||"claude-sonnet-5",xe;(async()=>{if(P){be=TP;try{const _e=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:v,secret:je})).models.map(Le=>Le.id);be=RP(_e)??be,xe=PP(be)?IP(_e):void 0}catch{}}let Ie,ke=!1;!await s(async()=>{if(Ie=await A.saveProviderAccount({label:g,kind:h,auth:m,baseUrl:v,defaultModel:be,enabled:!0,...je.trim()?{secret:je}:{}}),m!=="api-key")return Ie;const $e=await A.testProviderAccount(Ie.id);if($e.state==="connected")return Ie;if(jw($e)){const _e=Ie.id;Ie=void 0;try{const Le=(await A.providerAccounts()).accounts.find(qe=>qe.id===_e);Le&&await A.removeProviderAccount(_e,Le.revision)}catch{}throw new Error(PX)}if(P&&xe&&MP($e)){const _e=(await A.providerAccounts()).accounts.find(Le=>Le.id===Ie.id);if(_e&&(await A.saveProviderAccount({...Jy(_e),defaultModel:xe}),(await A.testProviderAccount(Ie.id)).state==="connected"))return{...Ie,warning:`Account saved. Google's free tier has no Pro allowance, so it starts on ${xe}; turn on billing at Google to use Pro.`}}return ke=!0,{...Ie,warning:`Account saved. ${$e.message}`}},"Account saved.")||!Ie||(P||q||ke?u(Ie.id):W||!fe?r(Ie.id):u(Ie.id))})()},children:[t.jsxs("fieldset",{disabled:n,className:"ui-fields","data-stack":"true",children:[t.jsx(ie,{label:"Provider",children:t.jsxs("select",{value:m==="anthropic-oauth"?"anthropic-oauth":U?"ollama-cloud":P?"gemini":q?"mlxh":h,onChange:X=>{if(X.target.value==="anthropic-oauth")_("anthropic","anthropic-oauth");else if(X.target.value==="gemini")Y();else if(X.target.value==="mlxh")B();else if(X.target.value==="ollama-cloud")_("openai-compatible","device-key",!0);else{const je=X.target.value;_(je,je==="codex"?"chatgpt":"api-key")}},children:[t.jsx("option",{value:"anthropic",children:"Anthropic API"}),t.jsx("option",{value:"openai",children:"OpenAI API"}),l&&t.jsx("option",{value:"gemini",children:"Gemini (Google AI key)"}),t.jsx("option",{value:"ollama-cloud",children:"Ollama Cloud"}),t.jsx("option",{value:"mlxh",children:"mlxh, local MLX models on this Mac"}),t.jsx("option",{value:"openai-compatible",children:"OpenAI-compatible endpoint (Ollama, OpenRouter, vLLM…)"}),i&&t.jsx("option",{value:"anthropic-oauth",children:"Claude subscription"}),a&&t.jsx("option",{value:"codex",children:"ChatGPT subscription"})]})}),t.jsx(ie,{label:"Account name",hint:"Proposed from the provider. Change it to anything you will recognise.",children:t.jsx("input",{autoFocus:!0,required:!0,maxLength:100,value:g,onChange:X=>{x(X.target.value),j(!0)},placeholder:"Anthropic — Personal"})}),U&&t.jsxs("label",{className:"ui-row",children:[t.jsx("input",{type:"checkbox",checked:m==="api-key",onChange:X=>re(X.target.checked)}),t.jsx("span",{children:"Use a key instead"})]}),Z&&t.jsxs(t.Fragment,{children:[t.jsx(ie,{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:t.jsx("input",{required:!0,type:"url",value:v,onChange:X=>{w(X.target.value),S(null)}})}),!P&&!q&&t.jsx(ie,{label:"Authentication",children:t.jsxs("select",{value:m,onChange:X=>{p(X.target.value),N(""),S(null)},children:[t.jsx("option",{value:"api-key",children:"API key"}),t.jsx("option",{value:"none",children:"No key (local/self-hosted)"})]})})]}),m==="api-key"&&t.jsx(ie,{label:"API key",hint:"Stored in the vault, never shown again.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,value:y,onChange:X=>{N(X.target.value),S(null)}})}),q?F===null?t.jsx("p",{className:"muted",children:"Looking for mlxh on this computer…"}):F!=null&&F.running?t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{className:"muted",children:["mlxh answers with ",F.models.length===1?"one model":`${F.models.length} models`,". No key: mlxh takes any. buddi starts on ",zv(F)??"the first","; the next step lists the rest. A model that is not loaded takes up to a minute on its first answer."]}),F.models.some(X=>X.kind==="image")?t.jsxs("p",{className:"muted",children:[F.models.filter(X=>X.kind==="image").map(X=>X.id).join(", "),": ",iP,"."]}):null]}):t.jsx(G,{tone:"warning",children:aP((F==null?void 0:F.baseUrl)??v)}):P&&l?t.jsxs("p",{className:"muted",children:[t.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."]}):fe?t.jsx("p",{className:"muted",children:h==="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."}):t.jsxs("div",{className:"ui-field",children:[t.jsx("span",{className:"ui-field-label",children:"Model"}),b?t.jsxs("div",{className:"ui-row",children:[t.jsxs("select",{"aria-label":"Model",value:I?"__custom__":M,onChange:X=>{X.target.value==="__custom__"?(z(!0),O("")):(z(!1),O(X.target.value))},children:[b.models.map(X=>t.jsxs("option",{value:X.id,children:[X.name===X.id?X.id:`${X.name} — ${X.id}`,X.isDefault?" (provider default)":"",X.thinks?" · thinks":""]},X.id)),t.jsx("option",{value:"__custom__",children:"Custom model…"})]}),t.jsx($,{size:"sm",disabled:C||!ve,onClick:()=>void Oe(),children:C?"Loading…":"Reload"})]}):t.jsxs("div",{className:"ui-row",children:[t.jsx($,{disabled:C||!ve,onClick:()=>void Oe(),children:C?"Loading models…":"Load models"}),Z?t.jsx("span",{className:"muted",children:"Ask the endpoint what it serves."}):t.jsxs("span",{className:"muted",children:["Optional now: ",ag[h]," is used until you pick one."]})]}),I||Z&&!b?t.jsx("input",{"aria-label":"Custom model",required:Z,maxLength:150,value:M,onChange:X=>O(X.target.value),placeholder:Z?"qwen3:8b":ag[h]}):null,E?t.jsx("span",{className:"ui-field-hint critical",role:"alert",children:E}):null,b!=null&&b.truncated?t.jsx("span",{className:"ui-field-hint",children:"Showing the first part of the provider’s list."}):null]}),t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:()=>r(),children:"Cancel"}),t.jsx($,{type:"submit",variant:"accent",disabled:se,children:"Save account"})]})]}),se&&!q&&t.jsxs("p",{className:"muted",children:["Enter an account name",P?" and a key":Z?", an endpoint and a model":""," to enable Save account."]})]})}function OX({account:e,busy:n,run:s,anthropicOAuthEnabled:r,onDone:a}){const[i,l]=d.useState(e.defaultModel),o=e.configured;return t.jsxs(ue,{gap:"lg",children:[t.jsxs(G,{tone:"good",children:["Saved “",e.label,"”."]}),e.auth==="anthropic-oauth"&&!o?t.jsx(UP,{account:e,enabled:!!r,busy:n,run:s}):null,e.kind==="codex"&&!o?t.jsx(_P,{account:e,busy:n,run:s}):null,e.auth==="device-key"&&!o?t.jsx(zP,{account:e,busy:n,run:s}):null,o?t.jsxs(t.Fragment,{children:[t.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."}),t.jsx(ne,{valign:"end",children:t.jsx(Hy,{accountId:e.enabled?e.id:void 0,label:"Default model",value:i,onChange:l,disabled:n},`${e.id}:${e.revision}`)}),t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:a,children:"Skip for now"}),t.jsx($,{variant:"accent",disabled:n||!i.trim(),onClick:()=>{if(i===e.defaultModel){a();return}s(()=>A.saveProviderAccount({...Jy(e),defaultModel:i}),"Default model saved.").then(c=>{c&&a()})},children:"Done"})]})]}):t.jsx(ne,{children:t.jsx($,{onClick:a,children:"Finish later"})})]})}async function Gi(e,n,s,r){s(!0),r(null);try{return(await A.secretsAct(e,n)).result}catch(a){return r(a instanceof Error?a.message:String(a)),null}finally{s(!1)}}const BP="Passwords, keys and links your agents use without ever seeing them. Each goes only where you allow.";function DX(e,n){if(n==="mail")return"mail";if(n==="models")return"chip";if(n==="connections")return"plug";if(n==="plugin:calendar")return"calendar";const s=e.bindings.map(r=>r.kind);return s.some(r=>r.startsWith("browser."))?"globe":s.includes("developer.env")?"terminal":"key"}function LX({embedded:e,timezone:n,secret:s,adding:r,navigate:a}={}){const i=ge(()=>A.secrets(),[]),l=ge(()=>A.providerAccounts(),[]),o=d.useMemo(()=>{var g;return new Map((((g=l.data)==null?void 0:g.accounts)??[]).map(x=>[x.id,{label:x.label,provider:DP(x)}]))},[l.data]),[c,u]=d.useState(s?{what:"replace",name:s}:r?{what:"add"}:null);d.useEffect(()=>{s&&u({what:"replace",name:s})},[s]),d.useEffect(()=>{r&&u({what:"add"})},[r]);const h=()=>{u(null),(s||r)&&a&&a(Fe("secrets"))},f=i.data,m=d.useMemo(()=>{const g=new Map;for(const x of(f==null?void 0:f.secrets)??[]){const k=ya(x);g.set(k,[...g.get(k)??[],x])}return[...g.entries()].sort(([x],[k])=>rK(x,k))},[f]),p=c&&c.what!=="add"?(f==null?void 0:f.secrets.find(g=>g.name===c.name))??null:null;return t.jsxs(gs,{embedded:e,title:"Keys and secrets",lede:BP,actions:e?void 0:t.jsx($,{variant:"accent",size:"sm",onClick:()=>u({what:"add"}),children:"Add a secret"}),children:[t.jsxs(ue,{gap:"lg",children:[!f&&!i.error?t.jsx(Ne,{children:"Opening the vault…"}):null,i.error?t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:i.error}),t.jsx(ne,{children:t.jsx($,{onClick:i.reload,children:"Retry"})})]}):null,f&&f.secrets.length===0?t.jsx(Xe,{children:t.jsx(es,{icon:"lock",title:"Nothing stored yet.",children:"Add a site password or an API token, and say where an agent may use it. Mailbox passwords and calendar links show up here as you add them."})}):null,f&&f.secrets.length>0?t.jsx(Xe,{flush:!0,children:m.map(([g,x])=>{const k=sK(g);return t.jsxs("section",{className:"secrets-group","aria-label":k.title,children:[t.jsxs("header",{className:"secrets-group-head",children:[t.jsx("h3",{className:"secrets-group-title",children:k.title}),t.jsx("span",{className:"secrets-group-aside",children:k.aside})]}),t.jsx(ct,{children:x.map(j=>t.jsx(_X,{secret:j,group:g,accounts:o,timezone:n,onOpen:v=>u({what:v,name:j.name})},j.name))})]},g)})}):null,f&&f.ownKeys.length>0?t.jsx(Zt,{summary:`buddi’s own keys · ${f.ownKeys.length}`,children:t.jsxs("p",{className:"secrets-note",children:["The keys buddi itself runs on, read from its environment:"," ",f.ownKeys.map((g,x)=>t.jsxs("span",{children:[x>0?", ":"",t.jsx("code",{className:"mono",children:g})]},g)),". They aren’t changed here, and buddi hides them in whatever it sends out, like your own."]})}):null]}),(c==null?void 0:c.what)==="add"&&f?t.jsx(BX,{destinations:f.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="sheet"?t.jsx(zX,{secret:p,accounts:o,timezone:n,onClose:h,onOpen:g=>u({what:g,name:p.name})}):null,p&&(c==null?void 0:c.what)==="replace"?t.jsx(WX,{secret:p,title:yc(p,o),onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="rename"?t.jsx(HX,{secret:p,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="places"&&f?t.jsx(KX,{secret:p,title:yc(p,o),destinations:f.destinations,onClose:h,onChanged:i.reload}):null,p&&(c==null?void 0:c.what)==="delete"?t.jsx(VX,{secret:p,title:yc(p,o),onClose:h,onChanged:i.reload}):null]})}const hf=e=>n=>{n.stopPropagation(),e==null||e()};function WP({fix:e,onOpen:n}){return"href"in e?t.jsx(lt,{size:"sm",href:e.href,onClick:hf(),children:e.label}):t.jsx($,{size:"sm",onClick:hf(()=>n(e.action)),children:e.label})}function FX(e,n,s){if(n==="mine")return[{label:"Replace value…",onSelect:()=>s("replace")},{label:"Rename…",onSelect:()=>s("rename")},{label:"Change where it may go…",hint:"Places, and when it asks",onSelect:()=>s("places")},{label:"Usage history",onSelect:()=>s("sheet")},"separator",{label:"Delete…",tone:"critical",onSelect:()=>s("delete")}];if(n==="mail"){const r=(e.usedBy??[]).find(a=>a.kind==="mailbox");return[r&&!e.unused?{label:"Set a new password",hint:"On the Email page, which tests it first",onSelect:()=>{window.location.hash=gv(r.id)}}:null,{label:"Usage history",onSelect:()=>s("sheet")},Pl(e)?"separator":null,Pl(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}return[{label:n==="plugin:calendar"?"Replace link…":"Replace value…",onSelect:()=>s("replace")},{label:"Usage history",onSelect:()=>s("sheet")},Pl(e)?"separator":null,Pl(e)?{label:"Remove…",tone:"critical",onSelect:()=>s("delete")}:null]}function _X({secret:e,group:n,accounts:s,timezone:r,onOpen:a}){const i=yc(e,s),l=lK(e,s),o=iK(e,r),c=[o??jy(e),o&&!e.lastUse?null:dK(e)].filter(Boolean).join(" · "),u=vR(e),h=jR(e),f=xv(e),m=fR(n)?gR(e):null;return t.jsx(rt,{onClick:()=>a("sheet"),label:`${i}: details`,lead:t.jsx(Hn,{icon:DX(e,n)}),title:t.jsxs(t.Fragment,{children:[i,l?t.jsx("span",{className:"secrets-tag",children:l}):null]}),sub:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"secrets-line",children:c}),u?t.jsx("span",{className:"secrets-status","data-tone":"warning",children:u.text}):null,h?t.jsx("span",{className:"secrets-status",children:h}):null,f?t.jsx("span",{className:"secrets-status",children:f}):null]}),side:t.jsxs("span",{className:"secrets-side",children:[u!=null&&u.fix?t.jsx(WP,{fix:u.fix,onOpen:a}):null,h&&Pl(e)||e.login&&n==="mine"?t.jsx($,{size:"sm",variant:"ghost",onClick:hf(()=>a("delete")),children:"Remove…"}):null,m?t.jsxs("a",{className:"secrets-managed",href:m.href,onClick:hf(),children:[m.label,t.jsx(oe,{name:"chevron-right",size:12})]}):t.jsx(ss,{label:`More for ${i}`,items:FX(e,n,a),sheet:{title:i,sub:c}})]})})}function zX({secret:e,accounts:n,timezone:s,onClose:r,onOpen:a}){const i=ya(e),l=yc(e,n),o=vR(e),c=jR(e),u=[...new Set(e.bindings.map(m=>m.rule))],h=e.lastUse,f=(e.usedBy??[]).map(m=>({label:m.kind==="mailbox"?"Mailbox":m.kind==="model-account"?"Model account":"Connection",value:t.jsx("code",{className:"mono secrets-mono",children:m.id})}));return t.jsx(Ye,{title:l,onClose:r,foot:i==="mine"?t.jsxs(ne,{children:[t.jsx($,{variant:"danger-ghost",onClick:()=>a("delete"),children:"Delete…"}),t.jsx(ot,{}),t.jsx($,{onClick:()=>a("rename"),children:"Rename…"}),t.jsx($,{variant:"accent",onClick:()=>a("replace"),children:"Replace value…"})]}):void 0,children:t.jsxs(ue,{gap:"lg",children:[t.jsx(Xt,{items:[{label:"Where it may go",value:jy(e)||"Nowhere yet"},...u.length===1&&i==="mine"?[{label:"Asks you",value:fK[u[0]]}]:[],{label:"Last used",value:h?`${Ge(h.at)}${h.agentId?` by ${h.agentId}`:""}`:"Never"}]}),o?t.jsx(G,{tone:"warning",action:o.fix?t.jsx(WP,{fix:o.fix,onOpen:a}):void 0,children:o.text}):null,c?Pl(e)?t.jsxs(G,{action:t.jsx($,{size:"sm",onClick:()=>a("delete"),children:"Remove…"}),children:[c," Nothing removes it but you."]}):t.jsx(G,{children:c}):null,xv(e)?t.jsx(G,{children:xv(e)}):null,t.jsxs(ue,{gap:"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Usage history"}),t.jsx(UX,{name:e.name,timezone:s})]}),t.jsx(Zt,{summary:"Details",children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Xt,{items:[{label:"Stored as",value:t.jsx("code",{className:"mono secrets-mono",children:e.name})},...e.bindings.map((m,p)=>({key:`b${p}`,label:p===0?"Bindings":"",value:t.jsxs("code",{className:"mono secrets-mono",children:[m.kind," ",cR(m.kind,m.target)," · ",m.rule]})})),...e.totp?[{label:"One-time code",value:"buddi fills the current code, never the seed"}]:[],...f]}),t.jsx("p",{className:"secrets-note",children:"What buddi keeps for it, never the value. “Held back” means buddi declined to hand the value over — not bound to that place, no value stored, or the vault locked — so it never left."})]})})]})})}function UX({name:e,timezone:n}){const s=ge(()=>A.secretUses(e,50),[e]);if(s.error)return t.jsx(ae,{message:s.error});if(!s.data)return t.jsx(Ne,{children:"Reading the history…"});const r=s.data.uses;return r.length===0?t.jsx("p",{className:"secrets-note",children:"Nothing has used it yet."}):t.jsx(ct,{children:r.map((a,i)=>{const l=xK(a);return t.jsx(rt,{title:t.jsx("span",{className:"secrets-history","data-tone":l.tone,children:l.text}),sub:`${mt(a.at,n??"UTC")} · ${a.agent??(a.plugin?`the ${a.plugin} plugin`:"you")}`},i)})})}function HP({title:e,result:n,scrubbed:s,busy:r,failure:a,onScrub:i}){const l=ZH(n);return t.jsxs(ue,{gap:"sm",children:[t.jsxs(G,{tone:"good",role:"status",children:["Saved “",e,"”. Its value is never shown again."]}),t.jsx("p",{className:"secrets-note",children:l||"Nothing of the value sits where buddi already holds text."}),t.jsx(ae,{message:a}),l?t.jsx(ne,{children:t.jsx($,{variant:"accent",disabled:r||s!==null,onClick:i,children:s===null?"Scrub the history":eK(s)||"Nothing of it was left to replace."})}):null]})}function KP({destinations:e,bindings:n,disabled:s,onChange:r}){const a=(i,l)=>{r(n.map((o,c)=>c===i?{...o,...l}:o))};return t.jsxs(ue,{gap:"sm",children:[n.map((i,l)=>{const o=e.find(h=>h.kind===i.kind),c=(o==null?void 0:o.maxRule)??i.rule,u=o?e:[...e,{kind:i.kind,plugin:"",maxRule:i.rule}];return t.jsxs("div",{className:"secrets-place",children:[t.jsx(ie,{label:"Kind of place",children:t.jsx("select",{value:i.kind,disabled:s,onChange:h=>{var p;const f=h.target.value,m=(p=e.find(g=>g.kind===f))==null?void 0:p.maxRule;a(l,{kind:f,rule:m?qh(m):i.rule})},children:u.map(h=>t.jsx("option",{value:h.kind,children:mK(h.kind)},h.kind))})}),t.jsx(ie,{label:"The place",children:t.jsx("input",{type:"text",spellCheck:!1,disabled:s,value:i.target,placeholder:gK(i.kind),onChange:h=>a(l,{target:h.target.value})})}),t.jsx(ie,{label:"Asks you",children:t.jsx("select",{value:i.rule,disabled:s,onChange:h=>a(l,{rule:h.target.value}),children:lR(c).map(h=>t.jsx("option",{value:h,children:pK[h]},h))})}),t.jsx($,{size:"sm",variant:"ghost",disabled:s,onClick:()=>r(n.filter((h,f)=>f!==l)),children:"Remove"}),t.jsxs("p",{className:"ui-field-hint secrets-place-hint",children:["The place: ",GH(i.kind),"."]})]},l)}),n.length===0?t.jsx("p",{className:"ui-field-hint",children:VH}):null,e.length?t.jsx(ne,{children:t.jsx($,{size:"sm",disabled:s,onClick:()=>r([...n,{kind:e[0].kind,target:"",rule:qh(e[0].maxRule)}]),children:"Add a place"})}):t.jsx("p",{className:"ui-field-hint",children:"Nothing installed here takes a secret yet, so there is nowhere to send one."})]})}function VP(e){const n=e.map(r=>JH(r.kind,r.target)),s=n.findIndex(r=>!r.ok);return s!==-1?{ok:!1,error:`Place ${s+1}: ${n[s].error}`}:{ok:!0,bindings:e.map((r,a)=>({kind:r.kind,target:n[a].target,rule:r.rule}))}}function BX({destinations:e,onClose:n,onChanged:s}){const[r,a]=d.useState(""),[i,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(()=>e.length?[{kind:e[0].kind,target:"",rule:qh(e[0].maxRule)}]:[]),[f,m]=d.useState(!1),[p,g]=d.useState(null),[x,k]=d.useState(null),[j,v]=d.useState(null),w=async()=>{const N=VP(u);if(!N.ok){g(N.error);return}const b=i;l("");const S=await Gi("secrets.put",{name:r.trim(),value:b,totp:o,bindings:N.bindings},m,g);S!==null&&(k({name:r.trim(),result:S}),s())},y=async()=>{const N=await Gi("secrets.scrub_history",{name:(x==null?void 0:x.name)??""},m,g);N!==null&&(v(N),s())};return x?t.jsx(Ye,{title:"Add a secret",onClose:n,foot:t.jsx(ne,{align:"end",children:t.jsx($,{onClick:n,children:"Done"})}),children:t.jsx(HP,{title:x.name,result:x.result,scrubbed:j,busy:f,failure:p,onScrub:()=>void y()})}):t.jsx(Ye,{title:"Add a secret",size:"wide",onClose:n,foot:t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:n,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-add",variant:"accent",disabled:f,children:"Save secret"})]}),children:t.jsxs("form",{id:"secrets-add",className:"ui-stack","data-gap":"lg",onSubmit:N=>{N.preventDefault(),w()},children:[t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx(ie,{label:"Name",hint:"What agents ask for it by. Saving a name that exists replaces that secret’s value.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,value:r,onChange:N=>a(N.target.value),placeholder:"PNC password"})}),t.jsx(ie,{label:"Value",hint:"Kept in the vault and never shown again, not even here.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,value:i,onChange:N=>l(N.target.value)})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:N=>c(N.target.checked)}),t.jsx("span",{children:"It’s a one-time-code seed — buddi fills the current code, never the seed"})]})]}),t.jsxs("fieldset",{disabled:f,className:"ui-stack","data-gap":"sm",children:[t.jsx("h3",{className:"secrets-sheet-head",children:"Where it may go"}),t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(KP,{destinations:e,bindings:u,disabled:f,onChange:h})]}),p?t.jsx(G,{tone:"critical",role:"alert",children:p}):null]})})}function WX({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=d.useState(""),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),g=async()=>{const k=a;i("");const j=await Gi("secrets.put",{name:e.name,value:k,totp:e.totp,bindings:e.bindings.map(({kind:v,target:w,rule:y})=>({kind:v,target:w,rule:y}))},o,u);j!==null&&(f(j),r())},x=async()=>{const k=await Gi("secrets.scrub_history",{name:e.name},o,u);k!==null&&(p(k),r())};return h?t.jsx(Ut,{title:`Replaced the value of “${n}”`,onClose:s,foot:t.jsx($,{variant:"accent",onClick:s,children:"Done"}),children:t.jsx(HP,{title:n,result:h,scrubbed:m,busy:l,failure:c,onScrub:()=>void x()})}):t.jsx(Ut,{title:`Replace the value of “${n}”`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-replace",variant:"accent",disabled:l||a==="",children:"Save value"})]}),children:t.jsxs("form",{id:"secrets-replace",className:"ui-stack","data-gap":"sm",onSubmit:k=>{k.preventDefault(),a!==""&&g()},children:[t.jsx(ie,{label:"New value",hint:"Kept in the vault and never shown again. Where it may go stays the same.",children:t.jsx("input",{type:"password",autoComplete:"new-password",spellCheck:!1,required:!0,autoFocus:!0,disabled:l,value:a,onChange:k=>i(k.target.value)})}),t.jsx(ae,{message:c})]})})}function HX({secret:e,onClose:n,onChanged:s}){const[r,a]=d.useState(e.name),[i,l]=d.useState(!1),[o,c]=d.useState(null),u=r.trim()!==""&&r.trim()!==e.name,h=async()=>{await Gi("secrets.rename",{name:e.name,to:r.trim()},l,c)!==null&&(s(),n())};return t.jsx(Ut,{title:`Rename “${e.name}”`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-rename",variant:"accent",disabled:i||!u,children:"Rename"})]}),children:t.jsxs("form",{id:"secrets-rename",className:"ui-stack","data-gap":"sm",onSubmit:f=>{f.preventDefault(),u&&h()},children:[t.jsx(ie,{label:"Name",hint:"What agents ask for it by. One that uses the old name needs the new one.",children:t.jsx("input",{required:!0,autoFocus:!0,maxLength:200,disabled:i,value:r,onChange:f=>a(f.target.value)})}),t.jsx(ae,{message:o})]})})}function KX({secret:e,title:n,destinations:s,onClose:r,onChanged:a}){const[i,l]=d.useState(()=>e.bindings.length?e.bindings.map(m=>({kind:m.kind,target:XH(m.target),rule:m.rule})):s.length?[{kind:s[0].kind,target:"",rule:qh(s[0].maxRule)}]:[]),[o,c]=d.useState(!1),[u,h]=d.useState(null),f=async()=>{const m=VP(i);if(!m.ok){h(m.error);return}await Gi("secrets.rebind",{name:e.name,bindings:m.bindings},c,h)!==null&&(a(),r())};return t.jsx(Ye,{title:`Where “${n}” may go`,size:"wide",onClose:r,foot:t.jsxs(ne,{align:"end",children:[t.jsx($,{onClick:r,children:"Cancel"}),t.jsx($,{type:"submit",form:"secrets-places",variant:"accent",disabled:o,children:"Save"})]}),children:t.jsxs("form",{id:"secrets-places",className:"ui-stack","data-gap":"sm",onSubmit:m=>{m.preventDefault(),f()},children:[t.jsx("p",{className:"secrets-note",children:"Agents can use it only in these places. Anywhere else, buddi holds it back and the row says so."}),t.jsx(KP,{destinations:s,bindings:i,disabled:o,onChange:l}),u?t.jsx(G,{tone:"critical",role:"alert",children:u}):null]})})}function VX({secret:e,title:n,onClose:s,onChanged:r}){const[a,i]=d.useState(!1),[l,o]=d.useState(null),c=!!(e.unused||e.login),u=async()=>{await Gi("secrets.delete",{name:e.name},i,o)!==null&&(r(),s())};return t.jsxs(Ut,{title:`${c?"Remove":"Delete"} “${n}”?`,onClose:s,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:a,onClick:()=>void u(),children:c?"Remove":"Delete"})]}),children:[t.jsxs("p",{className:"secrets-dialog-text",children:[hK(e)," The value is gone for good; its usage history stays, under its name."]}),t.jsx(ae,{message:l})]})}function GX({timezone:e,embedded:n}){var p;const{data:s,error:r,reload:a}=ge(()=>A.sentinels(),[],3e4),[i,l]=d.useState(null),[o,c]=d.useState(null),u=(s==null?void 0:s.installed)??[],h=((s==null?void 0:s.runs)??[]).filter(g=>g.lastError),f=u.filter(g=>!g.enabled),m=(g,x)=>{l(g),c(null),A.setSentinelEnabled(g,x).catch(k=>c(k instanceof he?k.message:String(k))).finally(()=>{l(null),a()})};return t.jsxs(gs,{embedded:n,title:"Watchers",children:[t.jsx(ae,{message:r??o}),t.jsx(G,{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."}),h.length>0?t.jsx(G,{tone:"warning",children:h.length===1?"One watcher failed on its last run.":`${h.length} watchers failed on their last run.`}):null,f.length>0?t.jsxs(G,{tone:"warning",children:[f.length===1?"One watcher is off.":`${f.length} watchers are off.`," A watcher that is off does not run, and what it already found stays as it was."]}):null,t.jsx(pe,{title:"Installed",aside:t.jsx("a",{href:`${At}/alerts`,children:"See what they found"}),panel:!0,flush:!0,children:s?u.length===0?t.jsx(es,{icon:"eye",title:"No watchers are installed",children:"Plugins bring their own."}):t.jsx(ct,{children:u.map(g=>{const x=s.runs.find(k=>k.sentinelId===g.id);return t.jsx(rt,{lead:t.jsx(Ae,{tone:g.enabled?x!=null&&x.lastError?"critical":x?"good":void 0:"muted",children:g.enabled?x!=null&&x.lastError?"failed":x?"ok":"never ran":"off"}),title:g.description,sub:`${g.id}, every ${YX(g.every)}${x!=null&&x.lastError?`. ${x.lastError}`:""}`,side:t.jsxs(t.Fragment,{children:[t.jsx("span",{title:x?mt(x.lastRunAt,e):void 0,children:x?Ge(x.lastRunAt):"never ran"}),t.jsx($,{size:"sm",disabled:i===g.id,onClick:()=>m(g.id,!g.enabled),children:g.enabled?"Turn off":"Turn on"})]})},g.id)})}):t.jsx(Ne,{children:"Loading…"})}),t.jsx(bY,{mutes:((p=s==null?void 0:s.alerts)==null?void 0:p.mutes)??[],onChanged:a})]})}function YX(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 n=Math.max(1,Math.round(e/60));return n===1?"minute":`${n} minutes`}const BS=4,qX={time:"profile",date:"profile",zone:null};function QX({data:e,phone:n}){const s=d.useRef(null),r=gI(),[a,i]=d.useState(.4),l=n?390:1280,o=n?780:800;d.useEffect(()=>{const u=s.current;if(!u)return;const h=()=>i(u.clientWidth/l||.4);if(h(),typeof ResizeObserver>"u")return;const f=new ResizeObserver(h);return f.observe(u),()=>f.disconnect()},[l]);const c=(e==null?void 0:e.owner)??null;return t.jsx("div",{ref:s,className:"lke-preview","data-phone":n?"true":void 0,style:{aspectRatio:`${l} / ${o}`},role:"img","aria-label":"Preview of the lock screen",children:t.jsxs("div",{className:"lk","data-preview":"true","data-bg":Oy(e==null?void 0:e.background,e==null?void 0:e.image),"data-phone":n?"true":void 0,"data-view":"glance",style:{width:l,height:o,transform:`scale(${a})`},"aria-hidden":"true",children:[t.jsx(CI,{data:e??null,now:r,phone:n}),t.jsx("footer",{className:"lk-unlock",children:n?t.jsxs("span",{className:"lk-chip lk-enter",children:[t.jsx(oe,{name:"lock",size:14}),t.jsx("span",{children:"Enter PIN"})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"lk-who",children:[t.jsx("span",{className:"lk-face",children:(c??"You").slice(0,1).toUpperCase()}),c?t.jsx("span",{className:"lk-owner",children:c}):null]}),t.jsxs("span",{className:"lk-pin",children:[t.jsx(oe,{name:"lock",size:15}),t.jsx("span",{className:"lke-pin-hint",children:"Enter your PIN"})]})]})})]})})}function JX({info:e,placement:n,index:s,count:r,onSize:a,onSettings:i,onMove:l,onRemove:o}){var u;const c=n.label??e.title;return t.jsxs("li",{className:"lke-row","data-key":n.key,children:[t.jsxs("span",{className:"lke-row-text",children:[t.jsx("span",{className:"lke-row-title",children:c}),t.jsx("span",{className:"lke-row-sub",children:e.builtIn?"Built in":`${e.plugin} plugin`})]}),t.jsxs("span",{className:"lke-row-tools",children:[e.sizes.length>1?t.jsx(Gt,{label:`Size of ${c}`,options:["small","medium"].filter(h=>e.sizes.includes(h)).map(h=>({value:h,label:h==="small"?"Small":"Medium"})),value:n.size,onChange:a}):null,t.jsxs("span",{className:"lke-row-acts",children:[(((u=e.settings)==null?void 0:u.length)??0)>0?t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Settings for ${c}`,title:"Settings",onClick:i,children:t.jsx(oe,{name:"settings",size:14})}):null,t.jsxs("span",{className:"lke-move",children:[t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} earlier`,title:"Move earlier",disabled:s===0,onClick:()=>l(-1),children:t.jsx(oe,{name:"chevron-left"})}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Move ${c} later`,title:"Move later",disabled:s===r-1,onClick:()=>l(1),children:t.jsx(oe,{name:"chevron-right"})})]}),t.jsx("button",{type:"button",className:"ui-icon-btn","data-size":"sm","aria-label":`Take ${c} off the lock screen`,title:"Take off the lock screen",onClick:o,children:t.jsx(oe,{name:"close",size:12})})]})]})]})}function WS(e){return e?"place"in e?`place:${e.place}`:`town:${e.timezone}:${e.label}`:""}function XX({clock:e,onClock:n,version:s}){var Q,_,re;const r=e??qX,a=ge(()=>A.lockScreen(),[s]),i=ge(()=>A.widgets("lock"),[]),l=ge(()=>A.owner(),[]),[o,c]=d.useState(void 0),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[x,k]=d.useState(null),[j,v]=d.useState(null);d.useEffect(()=>{i.data&&c(i.data)},[i.data]);const w=((Q=a.data)==null?void 0:Q.timezone)??Intl.DateTimeFormat().resolvedOptions().timeZone,y=(o==null?void 0:o.lock)??[],N=new Map(((o==null?void 0:o.available)??[]).map(Y=>[Y.id,Y])),b=y.length>=BS,S=Y=>{if(!o)return Promise.resolve(!1);const B=o;return m(null),c({...o,lock:Y,arranged:{...o.arranged,lock:!0}}),A.saveWidgets("lock",Y).then(q=>(c(q),a.reload(),!0),q=>(c(B),m(`Couldn't save the lock screen's widgets: ${q instanceof Error?q.message:String(q)}`),!1))},C=(Y,B)=>{const q=y.slice(),[J]=q.splice(Y,1);q.splice(Y+B,0,J),S(q)},T=(Y,B)=>{const q=N.get(Y);!q||b||S([...y,{key:bI(),widget:Y,size:q.sizes.includes("small")?"small":q.sizes[0],settings:B}])},E=Y=>{if(Y==="find"){k({query:"",found:[],busy:!1});return}if(k(null),Y==="")return n({...r,zone:null});if(Y.startsWith("place:"))return n({...r,zone:{place:Y.slice(6)}});const B=r.zone&&!("place"in r.zone)?r.zone:j;B&&n({...r,zone:B})},R=()=>{if(!x||x.query.trim().length<2)return;const Y=x.query.trim();k({query:x.query,found:[],busy:!0}),A.findPlace(Y).then(({found:B})=>{var fe;const q=B.filter(ve=>ve.timezone);if(q.length===0){k({query:Y,found:[],busy:!1,missed:`Nothing with a timezone found for “${Y}”.`});return}const J=q[0],Z={label:((fe=J.name.split(",")[0])==null?void 0:fe.trim())||J.name,timezone:J.timezone};v(Z),k(null),n({...r,zone:Z})}).catch(()=>k({query:Y,found:[],busy:!1,missed:"The place finder didn’t answer. Try again in a moment."}))},M=new Date,O=Y=>wu({dateFormat:Y},()=>wr(M,w,{weekday:!0})),I=(((_=l.data)==null?void 0:_.places)??[]).filter(Y=>Y.timezone&&Y.timezone!==w),z=r.zone&&!("place"in r.zone)?r.zone:j,U=((o==null?void 0:o.home)??[]).filter(Y=>N.has(Y.widget)&&!N.get(Y.widget).sensitive),D=((o==null?void 0:o.available)??[]).filter(Y=>!Y.sensitive),P=((o==null?void 0:o.available)??[]).filter(Y=>Y.sensitive).map(Y=>Y.title),K=p?y.find(Y=>Y.key===p):void 0,F=K?N.get(K.widget):void 0;return t.jsxs(pe,{title:"What it shows",aside:"Every change is kept at once.",panel:!0,children:[t.jsxs("div",{className:"lke",children:[t.jsxs("div",{className:"lke-look",children:[t.jsx(QX,{data:a.data,phone:u}),t.jsxs("div",{className:"lke-look-foot",children:[t.jsx(Gt,{label:"Preview on",options:[{value:"desk",label:"Desk"},{value:"phone",label:"Phone"}],value:u?"phone":"desk",onChange:Y=>h(Y==="phone")}),t.jsxs("span",{className:"lke-look-note",children:["As it shows now",(re=a.data)!=null&&re.focus?", with your focus on":"","."]})]})]}),t.jsxs("div",{className:"lke-controls",children:[t.jsx(ae,{message:f}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Clock",children:[t.jsx("p",{className:"lke-group-title",children:"Clock"}),t.jsxs("div",{className:"wg-field",role:"group","aria-label":"Time",children:[t.jsx("span",{className:"wg-field-label",children:"Time"}),t.jsx(Gt,{label:"Time",options:[{value:"profile",label:M$()},{value:"12h",label:"12-hour"},{value:"24h",label:"24-hour"}],value:r.time,onChange:Y=>n({...r,time:Y})})]}),t.jsx(ie,{label:"Date",children:t.jsxs("select",{value:r.date,onChange:Y=>n({...r,date:Y.target.value}),children:[t.jsxs("option",{value:"profile",children:["Profile · ",O(null)]}),t.jsx("option",{value:"short",children:O("short")}),t.jsx("option",{value:"long",children:O("long")}),t.jsx("option",{value:"iso",children:O("iso")}),t.jsx("option",{value:"off",children:"No date"})]})}),t.jsx(ie,{label:"A second clock",hint:"A place in another zone, under the time.",children:t.jsxs("select",{value:x?"find":WS(r.zone),onChange:Y=>E(Y.target.value),children:[t.jsx("option",{value:"",children:"None"}),I.map(Y=>t.jsxs("option",{value:`place:${Y.id}`,children:[Y.label," — ",Y.name.split(",")[0]]},Y.id)),r.zone&&"place"in r.zone&&!I.some(Y=>Y.id===r.zone.place)?t.jsx("option",{value:WS(r.zone),children:"A place no longer in another zone"}):null,z?t.jsx("option",{value:`town:${z.timezone}:${z.label}`,children:z.label}):null,t.jsx("option",{value:"find",children:"Another town…"})]})}),x?t.jsxs("div",{className:"wg-field-stack",children:[t.jsxs("div",{className:"wg-find",children:[t.jsx("input",{autoFocus:!0,value:x.query,placeholder:"Find a town: Tokyo","aria-label":"Find a town for the second clock",onChange:Y=>k({...x,query:Y.target.value}),onKeyDown:Y=>{Y.key==="Enter"&&(Y.preventDefault(),R()),Y.key==="Escape"&&k(null)}}),t.jsx($,{size:"sm",disabled:x.busy||x.query.trim().length<2,onClick:R,children:x.busy?"Finding…":"Find"})]}),x.missed?t.jsx("span",{className:"ui-field-hint",children:x.missed}):null]}):null]}),t.jsxs("div",{className:"lke-group",role:"group","aria-label":"Widgets",children:[t.jsxs("div",{className:"lke-group-head",children:[t.jsxs("p",{className:"lke-group-title",children:["Widgets ",t.jsxs("span",{className:"lke-count",children:[y.length," of ",BS]})]}),b||!o?t.jsxs($,{size:"sm",disabled:!0,children:[t.jsx(oe,{name:"plus",size:12})," Add a widget"]}):t.jsx(ss,{label:"Add a widget",trigger:t.jsxs("button",{type:"button",className:"ui-btn","data-size":"sm",children:[t.jsx(oe,{name:"plus",size:12})," Add a widget"]}),items:[U.length>0?{heading:"As on Home"}:null,...U.map(Y=>({label:Y.label??N.get(Y.widget).title,hint:"same settings",onSelect:()=>T(Y.widget,Y.settings)})),U.length>0?"separator":null,{heading:"Every widget"},...D.map(Y=>({label:Y.title,onSelect:()=>T(Y.id,{})})),"separator",{label:"Get more widgets",hint:"Browse",onSelect:()=>{window.location.hash=Ux("widgets")}}]})]}),o?y.length===0?t.jsx("p",{className:"lke-empty",children:"No widgets: just the clock and the counts."}):t.jsx("ul",{className:"lke-list",children:y.map((Y,B)=>{const q=N.get(Y.widget);return q?t.jsx(JX,{info:q,placement:Y,index:B,count:y.length,onSize:J=>void S(y.map(Z=>Z.key===Y.key?{...Z,size:J}:Z)),onSettings:()=>g(Y.key),onMove:J=>C(B,J),onRemove:()=>void S(y.filter(J=>J.key!==Y.key))},Y.key):null})}):t.jsx("p",{className:"lke-empty","aria-busy":"true",children:"Reading the lock screen’s widgets…"}),t.jsxs("p",{className:"ui-field-hint",children:[b?"Four is the most it holds; take one off to add another. ":"","Each keeps its own settings, apart from Home’s.",P.length>0?` A sensitive widget — ${P.join(", ")} — never shows here.`:" A sensitive widget never shows here."," ","One with nothing to show right now stays off until it has."]})]}),t.jsxs("p",{className:"lke-note",children:[t.jsx(oe,{name:"moon",size:13}),t.jsx("span",{children:"Your focus shows at the top only while one is on. Approvals and what else needs you show as counts when there are some, never what they say."})]})]})]}),K&&F?t.jsx(jI,{info:F,placement:K,surface:"lock",onClose:()=>g(null),onSave:Y=>S(y.map(B=>B.key===K.key?{...B,settings:Y}:B)).then(B=>(B&&g(null),B)),onRemove:()=>{g(null),S(y.filter(Y=>Y.key!==K.key))}}):null]})}const ZX=[{id:"earth",label:"Earth"},{id:"field",label:"Buddi"},{id:"dawn",label:"Dawn"},{id:"sea",label:"Sea"},{id:"moss",label:"Moss"},{id:"dusk",label:"Dusk"}],eZ=[{value:"1",label:"1 min"},{value:"5",label:"5 min"},{value:"15",label:"15 min"},{value:"60",label:"1 hour"},{value:"never",label:"Never"}],tZ=e=>e.delayMinutes===null?"never":String(e.delayMinutes);function Vv(e){if(e instanceof he){const n=e.detail??{};return e.status===429||n.waitUntil?"Too many wrong tries. Wait a moment, then try again.":e.status===403&&typeof n.triesLeft=="number"?`${e.message} ${n.triesLeft} ${n.triesLeft===1?"try":"tries"} left.`:e.message}return"Something went wrong. Try again."}function nZ({kind:e,onClose:n,onDone:s}){const[r,a]=d.useState(""),[i,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(null),[f,m]=d.useState(!1),p=e==="remove",g=e!=="set",x=!f&&(!g||r.length>=4)&&(p||i.length>=4&&o.length>=4),k=y=>y.replace(/\D/g,"").slice(0,8),j=e==="set"?"Set a PIN":e==="change"?"Change your PIN":"Remove the PIN?",v=y=>{if(y==null||y.preventDefault(),!x)return;if(!p&&i!==o){h("The two PINs aren’t the same.");return}m(!0),h(null),(p?A.removePin(r):A.setPin(i,g?r:void 0)).then(s).catch(b=>{m(!1),h(Vv(b))})},w=(y,N,b,S)=>t.jsx(ie,{label:y,children:t.jsx("input",{type:"password",inputMode:"numeric",autoComplete:y==="Current PIN"?"current-password":"new-password",maxLength:8,autoFocus:S,value:N,onChange:C=>{h(null),b(k(C.target.value))}})});return t.jsx(Ut,{title:j,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:p?"danger":"accent",disabled:!x,onClick:()=>v(),children:p?"Remove PIN":e==="set"?"Set PIN":"Change PIN"})]}),children:t.jsxs("form",{className:"lk-form",onSubmit:v,children:[t.jsx("p",{className:"lk-honest",children:p?"The dashboard stops locking, on every device. You can set a PIN again any time.":"Four to eight digits. You type it to open the dashboard after it locks, on any device signed in to it."}),g?w("Current PIN",r,a,!0):null,p?null:w(e==="set"?"PIN":"New PIN",i,l,!g),p?null:w("The same again",o,c,!1),u?t.jsx(G,{tone:"critical",children:u}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function sZ(e){const n=bm(),s=ge(()=>A.lockState(),[]),[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(!1),u=d.useRef(null),h=s.data??n.state,f=k=>{n.update(k),s.reload()},m=k=>{l(null),k.then(f).catch(j=>l(Vv(j)))},p=k=>{k&&(c(!0),l(null),A.uploadLockBackground(k).then(f).catch(j=>l(Vv(j))).finally(()=>{c(!1),u.current&&(u.current.value="")}))};if(!h)return t.jsx(pe,{title:"Lock screen",panel:!0,children:t.jsx(ae,{message:s.error?"Couldn’t read the lock screen’s settings.":null})});const g=h.pin,x=(k,j)=>t.jsxs("button",{type:"button",className:"lk-swatch","data-bg":k,"aria-pressed":h.background===k,"aria-label":j,title:j,onClick:()=>m(A.setLockSettings({background:k})),children:[k==="image"&&h.image?t.jsx("img",{src:h.image,alt:""}):k==="earth"?t.jsx("img",{src:Iv.thumb,alt:""}):t.jsx("span",{className:"lk-swatch-field"}),t.jsx("span",{className:"lk-swatch-label",children:j})]},k);return t.jsxs(t.Fragment,{children:[t.jsxs(pe,{title:"Lock screen",aside:"Kept for every device signed in to this dashboard.",actions:g?t.jsxs($,{size:"sm",onClick:()=>n.lockNow(),children:[t.jsx(oe,{name:"lock",size:13})," Lock now"]}):void 0,panel:!0,children:[t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx("p",{className:"lk-honest ui-section",children:"A privacy screen over this dashboard, on every device signed in to it: it locks when nobody has used it for a while, or when you lock it, and opens with your PIN. A new browser opens locked too. It isn’t a second sign-in — anyone who can run buddi on this computer can open it without the PIN. Telegram and buddi in your coding tools carry on as before."}),t.jsx(ae,{message:i}),t.jsxs("div",{className:"lk-pref ui-section",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"PIN"}),t.jsx("div",{className:"ui-field-hint",children:g?"Set. Kept hashed on this buddi; five wrong tries, then a wait that grows.":"Four to eight digits. Until you set one, nothing locks."})]}),g?t.jsxs(ne,{children:[t.jsx($,{size:"sm",variant:"ghost",onClick:()=>a("remove"),children:"Remove…"}),t.jsx($,{size:"sm",onClick:()=>a("change"),children:"Change…"})]}):t.jsx($,{size:"sm",variant:"accent",onClick:()=>a("set"),children:"Set a PIN"})]}),t.jsxs("div",{className:"lk-pref ui-section","data-off":g?void 0:"true","aria-disabled":g?void 0:"true",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"Lock after"}),t.jsx("div",{className:"ui-field-hint",children:g?t.jsxs(t.Fragment,{children:["Nobody using it for this long. Lock it yourself from your menu",t.jsxs("span",{className:"lk-shortcut",children:[", or with ",t.jsx("kbd",{className:"lk-kbd",children:n.shortcut})]}),"."]}):"Set a PIN first."})]}),t.jsx(Gt,{label:"Lock after",options:eZ,value:g?tZ(h):"",onChange:k=>{g&&m(A.setLockSettings({delayMinutes:k==="never"?null:Number(k)}))}})]}),t.jsxs("div",{className:"lk-pref ui-section","data-stack":"true",children:[t.jsxs("div",{className:"lk-pref-text",children:[t.jsx("div",{className:"lk-pref-label",children:"Background"}),t.jsx("div",{className:"ui-field-hint",children:"Behind the time and your widgets, on every device. A picture is kept as a JPEG of at most 2560 pixels, without its location or other details."})]}),t.jsxs("div",{className:"lk-swatches",role:"group","aria-label":"Background",children:[ZX.map(k=>x(k.id,k.label)),h.image?x("image","Your picture"):null,t.jsxs("label",{className:"lk-swatch","data-kind":"add","aria-busy":o?"true":void 0,children:[t.jsx("input",{ref:u,type:"file",accept:"image/jpeg,image/png",className:"lk-sr",disabled:o,onChange:k=>{var j;return p((j=k.target.files)==null?void 0:j[0])}}),t.jsx("span",{className:"lk-swatch-field","data-kind":"add",children:t.jsx(oe,{name:"plus",size:16})}),t.jsx("span",{className:"lk-swatch-label",children:o?"Adding…":h.image?"Replace":"Your picture"})]})]}),t.jsxs("p",{className:"lk-credit",children:["Earth: photo by ",t.jsx("a",{href:Kp.authorUrl,target:"_blank",rel:"noreferrer",children:Kp.author})," on ",t.jsx("a",{href:Kp.photoUrl,target:"_blank",rel:"noreferrer",children:"Unsplash"})]}),h.image?t.jsx(ne,{align:"end",children:t.jsx($,{size:"sm",variant:"ghost",onClick:()=>m(A.removeLockBackground()),children:"Remove picture"})}):null]})]}),r?t.jsx(nZ,{kind:r,onClose:()=>a(null),onDone:k=>{a(null),f(k)}}):null]}),t.jsx(XX,{clock:h.clock,onClock:k=>m(A.setLockSettings({clock:k})),version:`${h.background}:${h.image??""}:${JSON.stringify(h.clock??null)}`})]})}const lg=60;function GP(e){return e instanceof he?e.message:"Something went wrong. Try again."}function rZ(e,n,s=Date.now()){const r=`made ${wr(new Date(e.createdAt),n,{compact:!0})} ${e.createdVia==="cli"?"in the terminal":"here"}`;return`buddi_…${e.hint} · ${r} · ${e.lastUsedAt?`last used ${Ge(e.lastUsedAt,s)}`:"never used"}`}function aZ({onClose:e,onMade:n}){const[s,r]=d.useState(""),[a,i]=d.useState(!1),[l,o]=d.useState(null),[c,u]=d.useState(null),[h,f]=d.useState(!1),m=!a&&s.trim()!==""&&s.trim().length<=lg,p=g=>{g==null||g.preventDefault(),m&&(i(!0),o(null),A.createApiToken(s.trim()).then(x=>{u({token:x.token,name:x.apiToken.name}),n()}).catch(x=>o(GP(x))).finally(()=>i(!1)))};if(c){const g=()=>{var x;(x=navigator.clipboard)==null||x.writeText(c.token).then(()=>{f(!0),window.setTimeout(()=>f(!1),1600)}).catch(()=>{})};return t.jsx(Ut,{title:`Token for ${c.name}`,onClose:e,foot:t.jsx($,{variant:"accent",onClick:e,children:"Done"}),children:t.jsxs("div",{className:"at-form",children:[t.jsxs("div",{className:"at-secret",children:[t.jsx("code",{className:"at-secret-text","aria-label":"The token",children:c.token}),t.jsx($,{size:"sm",onClick:g,children:h?"Copied":"Copy"})]}),t.jsx(G,{tone:"warning",title:"Copy it now",children:"buddi keeps only a fingerprint of it, so it can’t show it again. Lost it? Revoke it and make another."}),t.jsx("p",{className:"at-text",children:"Send it as a header on every request:"}),t.jsx("code",{className:"at-try",children:`curl -H "Authorization: Bearer buddi_…" ${location.origin}/api/overview`})]})})}return t.jsx(Ut,{title:"Make a token",onClose:e,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:e,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!m,onClick:()=>p(),children:"Make token"})]}),children:t.jsxs("form",{className:"at-form",onSubmit:p,children:[t.jsx("p",{className:"at-text",children:"It acts as you on buddi’s HTTP API. Anything a gated tool does still waits for your approval here or on Telegram."}),t.jsx(ie,{label:"What will use it",hint:`So you can tell tokens apart later. Up to ${lg} characters.`,children:t.jsx("input",{autoFocus:!0,value:s,maxLength:lg,placeholder:"Home Assistant",onChange:g=>{o(null),r(g.target.value)}})}),l?t.jsx(G,{tone:"critical",children:l}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]})})}function iZ({token:e,onClose:n,onRevoked:s}){const[r,a]=d.useState(!1),[i,l]=d.useState(null),o=()=>{a(!0),l(null),A.revokeApiToken(e.id).then(()=>{s(),n()}).catch(c=>{a(!1),l(GP(c))})};return t.jsxs(Ut,{title:`Revoke “${e.name}”?`,onClose:n,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:r,onClick:o,children:"Revoke"})]}),children:[t.jsx("p",{className:"at-text",children:"A request carrying it is refused from now on. Whatever uses it stops working until you give it a new token."}),i?t.jsx(G,{tone:"critical",children:i}):null]})}function lZ({timezone:e}){var o;const n=ge(()=>A.apiTokens(),[]),[s,r]=d.useState(!1),[a,i]=d.useState(null),l=((o=n.data)==null?void 0:o.tokens)??[];return t.jsxs(ue,{gap:"lg",children:[t.jsx("p",{className:"ui-page-lede",children:"Let a script or another program use buddi without the dashboard. A token acts as you, minus the decisions only you make here."}),t.jsx(ae,{message:n.error?"Couldn’t read the API tokens.":null}),t.jsx(pe,{title:"Tokens",aside:"Kept as a fingerprint · shown once",actions:t.jsx($,{variant:"accent",size:"sm",onClick:()=>r(!0),children:"Make a token"}),panel:!0,flush:!0,children:n.data&&l.length===0?t.jsxs(Ne,{title:"No tokens yet.",children:["Make one here, or in a terminal with ",t.jsx("code",{className:"mono",children:"buddi api-token create <name>"}),"."]}):t.jsx(ct,{children:l.map(c=>t.jsx(rt,{lead:t.jsx(Hn,{icon:"key"}),title:c.name,sub:rZ(c,e),side:t.jsx($,{size:"sm",variant:"ghost",onClick:()=>i(c),children:"Revoke…"})},c.id))})}),t.jsxs(pe,{title:"What a token can’t do",panel:!0,children:[t.jsxs("ul",{className:"at-cant",children:[t.jsx("li",{children:"Approve anything, or make a change where your click is the approval. It can reject."}),t.jsx("li",{children:"Change what an agent may do without asking: its tools, who it hands work to, a connection given out, an “Always”."}),t.jsx("li",{children:"Install or run code buddi hasn’t run before: plugins, upgrades, program connections."}),t.jsx("li",{children:"Change how buddi is reached or unlocked — PIN, Tailscale, Telegram pairing, other tokens — or restore a backup."}),t.jsx("li",{children:"Read or store a secret: owner secrets, model account keys, the backup passphrase."})]}),t.jsxs("p",{className:"at-foot",children:["In a terminal: ",t.jsx("code",{className:"mono",children:"buddi api-token create"}),", ",t.jsx("code",{className:"mono",children:"list"}),", ",t.jsx("code",{className:"mono",children:"revoke"}),". Every route, and which a token may call: docs/api.md."]})]}),s?t.jsx(aZ,{onClose:()=>r(!1),onMade:()=>n.reload()}):null,a?t.jsx(iZ,{token:a,onClose:()=>i(null),onRevoked:()=>n.reload()}):null]})}function oZ({embedded:e}){const{data:n,error:s,reload:r}=ge(()=>A.owner(),[]);return t.jsxs(gs,{embedded:e,title:"You",lede:"What every agent knows about the person it is talking to.",children:[t.jsx(ae,{message:s}),n?t.jsxs(ue,{gap:"lg",children:[t.jsx(dZ,{initial:n,onSaved:r}),t.jsx(pZ,{initial:n})]}):null]})}const YP=new Date(Date.UTC(2026,9,1,14,5));function cZ(){return[["",`Auto (${wu({timeFormat:null},()=>Tt(YP,"UTC"))} here)`],["12h","12-hour · 2:05 PM"],["24h","24-hour · 14:05"]]}function uZ(){return[["",`Auto (${wu({dateFormat:null},()=>wr(YP,"UTC",{weekday:!0}))} here)`],["short","Thu, Oct 1"],["long","Thursday, 1 October"],["iso","2026-10-01"]]}function dZ({initial:e,onSaved:n}){var z,U,D;const[s,r]=d.useState(e.preferredName??""),[a,i]=d.useState(e.timezone??""),[l,o]=d.useState(e.timeFormat??""),[c,u]=d.useState(e.dateFormat??""),[h,f]=d.useState(e.language??""),[m,p]=d.useState(e.about??""),[g,x]=d.useState(e.fullName??""),[k,j]=d.useState(e.pronouns??""),[v,w]=d.useState(rf(e.birthday)),[y,N]=d.useState(!1),[b,S]=d.useState(!1),[C,T]=d.useState(null);d.useEffect(()=>{r(e.preferredName??""),i(e.timezone??""),o(e.timeFormat??""),u(e.dateFormat??""),f(e.language??""),p(e.about??""),x(e.fullName??""),j(e.pronouns??""),w(rf(e.birthday))},[e.preferredName,e.timezone,e.timeFormat,e.dateFormat,e.language,e.about,e.fullName,e.pronouns,(z=e.birthday)==null?void 0:z.day,(U=e.birthday)==null?void 0:U.month,(D=e.birthday)==null?void 0:D.year]);const E=af(v),R=s.trim()!==(e.preferredName??"")||a!==(e.timezone??"")||l!==(e.timeFormat??"")||c!==(e.dateFormat??"")||h.trim()!==(e.language??"")||m.trim()!==(e.about??"")||g.trim()!==(e.fullName??"")||k.trim()!==(e.pronouns??"")||E!=="incomplete"&&!dq(E,e.birthday),M=async()=>{N(!0),T(null);try{const P=await A.setOwner({preferredName:s.trim()===""?null:s.trim(),timezone:a===""?null:a,timeFormat:l===""?null:l,dateFormat:c===""?null:c,language:h.trim()===""?null:h.trim(),about:m.trim()===""?null:m.trim(),fullName:g.trim()===""?null:g.trim(),pronouns:k.trim()===""?null:k.trim(),...E!=="incomplete"?{birthday:E}:{}});mw({timeFormat:P.timeFormat??null,dateFormat:P.dateFormat??null}),window.dispatchEvent(new Event(kx)),S(!0),n()}catch(P){T(P instanceof he?P.message:String(P))}finally{N(!1)}},O=e.zones.length>0?e.zones:[e.detectedTimezone],I=P=>K=>{S(!1),P(K)};return t.jsx(pe,{title:"Your profile",aside:"read by every agent, as context",panel:!0,foot:t.jsxs(t.Fragment,{children:[b&&!R?t.jsx("span",{className:"muted",children:"Saved"}):null,t.jsx($,{variant:"accent",disabled:!R||y,onClick:()=>void M(),children:y?"Saving…":"Save"})]}),children:t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx(pe,{title:"Who you are",children:t.jsxs(Es,{children:[t.jsx(ie,{label:"Full name",hint:"For letters, forms and bookings.",children:t.jsx("input",{value:g,maxLength:120,placeholder:e.displayName??"Your full name",onChange:P=>I(x)(P.target.value)})}),t.jsx(ie,{label:"What the agents call you",hint:"How you like to be addressed.",children:t.jsx("input",{value:s,maxLength:80,placeholder:e.displayName??"Your name",onChange:P=>I(r)(P.target.value)})}),t.jsx(ie,{label:"Pronouns",hint:"Optional.",children:t.jsx("input",{value:k,maxLength:40,placeholder:"he/him, she/her, they/them…",onChange:P=>I(j)(P.target.value)})}),t.jsx(_v,{label:"Birthday",hint:"The year is optional. Your team greets you on the day.",value:v,onChange:I(w)})]})}),t.jsx(pe,{title:"Time and language",children:t.jsxs(Es,{children:[t.jsx(ie,{label:"Timezone",hint:`This host is in ${e.detectedTimezone}. Existing schedules keep the zone they were made in.`,children:t.jsxs("select",{value:a,onChange:P=>I(i)(P.target.value),children:[t.jsx("option",{value:"",children:"Not set (use the host's)"}),O.map(P=>t.jsx("option",{value:P,children:P},P))]})}),t.jsx(ie,{label:"Time",children:t.jsx("select",{value:l,onChange:P=>I(o)(P.target.value),children:cZ().map(([P,K])=>t.jsx("option",{value:P,children:K},P))})}),t.jsx(ie,{label:"Dates",hint:"Auto follows this browser's language. Agents write them your way too.",children:t.jsx("select",{value:c,onChange:P=>I(u)(P.target.value),children:uZ().map(([P,K])=>t.jsx("option",{value:P,children:K},P))})}),t.jsx(ie,{label:"Answer me in",hint:"A language, as you would say it. Blank mirrors whatever you write in.",children:t.jsx("input",{value:h,maxLength:40,placeholder:"English, français…",onChange:P=>I(f)(P.target.value)})})]})}),t.jsxs(pe,{title:"About you",children:[t.jsx(ie,{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:t.jsx("textarea",{rows:4,maxLength:1e3,value:m,placeholder:"I run a small studio and prefer short answers with the numbers first. Call me by my first name.",onChange:P=>I(p)(P.target.value)})}),C?t.jsx(G,{tone:"critical",children:C}):null]})]})})}const hZ=["Home","Work"];function fZ(e){const n=e.trim().toLowerCase();return n==="home"?"home":n==="work"?"briefcase":"pin"}function HS({label:e,empty:n}){return t.jsx("span",{className:"place-glyph","data-empty":n?"true":void 0,"aria-hidden":"true",children:t.jsx(oe,{name:fZ(e),size:18})})}function mZ(e){var s;const n=((s=e.name.split(",").pop())==null?void 0:s.trim())??"";return e.address?n&&!e.address.toLowerCase().includes(n.toLowerCase())?`${e.address} · ${n}`:e.address:e.name}function pZ({initial:e}){var c;const[n,s]=d.useState(e.places??[]);d.useEffect(()=>s(e.places??[]),[e]);const[r,a]=d.useState(null),i=e.timezone??e.detectedTimezone,l=hZ.filter(u=>!n.some(h=>h.label.toLowerCase()===u.toLowerCase())),o=d.useMemo(()=>new Date,[n]);return t.jsxs(pe,{title:"Places",aside:"the front desk, and plugins you allow",actions:t.jsx($,{size:"sm",onClick:()=>a({label:""}),children:"Add a place"}),panel:!0,flush:!0,children:[t.jsxs(ct,{children:[n.map(u=>t.jsx(rt,{label:`${u.label}: edit`,onClick:()=>a({place:u,label:u.label}),lead:t.jsx(HS,{label:u.label}),title:u.label,sub:mZ(u),side:u.timezone&&u.timezone!==i?t.jsxs(Ae,{children:[Tt(o,u.timezone)," there"]}):void 0},u.id)),l.map(u=>t.jsx(rt,{label:`${u}: add`,onClick:()=>a({label:u}),lead:t.jsx(HS,{label:u,empty:!0}),title:t.jsx("span",{className:"muted",children:u}),sub:"Not set",side:t.jsx($,{size:"sm",onClick:h=>{h.stopPropagation(),a({label:u})},children:"Add"})},u))]}),t.jsx("p",{className:"place-note",children:"Only the town is looked up, on Open-Meteo, to find where it is and its timezone. The address stays on this computer."}),r?t.jsx(gZ,{editing:r,zones:e.zones.length>0?e.zones:[e.detectedTimezone],onClose:()=>a(null),onSaved:u=>{s(u),a(null)}},((c=r.place)==null?void 0:c.id)??`new:${r.label}`):null]})}function gZ({editing:e,zones:n,onClose:s,onSaved:r}){const a=e.place,[i,l]=d.useState(e.label),[o,c]=d.useState((a==null?void 0:a.address)??""),[u,h]=d.useState(a?[{name:a.name,latitude:a.latitude,longitude:a.longitude,...a.timezone?{timezone:a.timezone}:{}}]:null),[f,m]=d.useState(0),[p,g]=d.useState((a==null?void 0:a.timezone)??""),[x,k]=d.useState(null),[j,v]=d.useState(null),[w,y]=d.useState((a==null?void 0:a.address)??""),N=u==null?void 0:u[f],b=()=>{o.trim().length<2||(k("find"),v(null),A.findPlace(o.trim()).then(R=>{var M;h(R.found),y(o.trim()),m(0),g(((M=R.found[0])==null?void 0:M.timezone)??""),R.found.length===0&&v("Nothing found by that name. Try the town, with its country.")}).catch(R=>v(R instanceof he?R.message:String(R))).finally(()=>k(null)))},S=()=>{N&&(k("save"),v(null),A.savePlace({...a?{id:a.id}:{},label:i.trim(),address:o.trim()===""?null:o.trim(),name:N.name,latitude:N.latitude,longitude:N.longitude,timezone:p===""?null:p}).then(R=>r(R.places)).catch(R=>v(R instanceof he?R.message:String(R))).finally(()=>k(null)))},C=()=>{a&&(k("remove"),v(null),A.removePlace(a.id).then(R=>r(R.places)).catch(R=>v(R instanceof he?R.message:String(R))).finally(()=>k(null)))},T=a?a.label:e.label?`Add ${e.label}`:"Add a place",E=p!==""&&!n.includes(p)?[p,...n]:n;return t.jsx(Ye,{title:T,onClose:s,foot:t.jsxs(ne,{children:[a?t.jsx($,{variant:"danger-ghost",disabled:x!==null,onClick:C,children:x==="remove"?"Removing…":"Remove"}):null,t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!N||i.trim()===""||x!==null,onClick:S,children:x==="save"?"Saving…":"Save"})]}),children:t.jsxs(ue,{gap:"lg",children:[t.jsx(ie,{label:"Name",hint:"What you call it: Home, Work, Mum's.",children:t.jsx("input",{value:i,maxLength:40,autoFocus:!e.label,onChange:R=>l(R.target.value)})}),t.jsx(ie,{label:"Address",hint:"A street address, or just the town.",action:t.jsx($,{disabled:o.trim().length<2||x!==null,onClick:b,children:x==="find"?"Finding…":"Find"}),children:t.jsx("input",{value:o,maxLength:200,autoFocus:!!e.label&&!a,placeholder:"12 Elm Street, Portland, Maine",onChange:R=>c(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),b())}})}),u&&u.length>0?t.jsx("div",{className:"place-found",role:"radiogroup","aria-label":"Which place",children:u.map((R,M)=>t.jsxs("button",{type:"button",role:"radio","aria-checked":M===f,className:"place-option","data-on":M===f?"true":void 0,onClick:()=>{m(M),g(R.timezone??"")},children:[t.jsx("span",{className:"place-radio","aria-hidden":"true"}),t.jsxs("span",{className:"place-option-text",children:[t.jsx("span",{className:"place-option-name",children:R.name}),t.jsxs("span",{className:"place-option-sub",children:[R.latitude.toFixed(2),", ",R.longitude.toFixed(2),R.timezone?` · ${R.timezone}`:""]})]})]},`${R.latitude},${R.longitude}`))}):t.jsx("p",{className:"place-note-inline",children:"Find it to pin it on the map; nothing is saved until you say Save."}),a&&u&&o.trim()!==w?t.jsx("p",{className:"place-note-inline",children:"The address changed. Find it again to move the pin, or save to keep it where it is."}):null,t.jsx(ie,{label:"Its timezone",hint:N?"From where it is. Change it if that is wrong.":"Filled in once the place is found.",children:t.jsxs("select",{value:p,disabled:!N,onChange:R=>g(R.target.value),children:[t.jsx("option",{value:"",children:"Not known"}),E.map(R=>t.jsx("option",{value:R,children:R},R))]})}),t.jsx(ae,{message:j})]})})}const xZ=2e6;function KS(e,n){const s=e.replace(/\r\n/g,`
|
|
132
|
-
`).replace(/\n+$/,"").split(`
|
|
133
|
-
`),r=n.replace(/\r\n/g,`
|
|
134
|
-
`).replace(/\n+$/,"").split(`
|
|
135
|
-
`);if(e.trim()===n.trim())return"(no change)";if(s.length*r.length>xZ)return[...s.map(c=>`-${c}`),...r.map(c=>`+${c}`)].join(`
|
|
136
|
-
`);const a=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--)a[c][u]=s[c]===r[u]?a[c+1][u+1]+1:Math.max(a[c+1][u],a[c][u+1]);const i=[];let l=0,o=0;for(;l<s.length&&o<r.length;)s[l]===r[o]?(i.push(` ${s[l]}`),l++,o++):a[l+1][o]>=a[l][o+1]?i.push(`-${s[l++]}`):i.push(`+${r[o++]}`);for(;l<s.length;)i.push(`-${s[l++]}`);for(;o<r.length;)i.push(`+${r[o++]}`);return i.join(`
|
|
137
|
-
`)}const qP={skill:"skill",policy:"rule",change:"change to itself"};function vZ(e){return e===null||typeof e!="object"||Array.isArray(e)?String(e??""):Object.entries(e).filter(([n,s])=>!/Id$/.test(n)&&s!==null&&s!==void 0&&s!=="").map(([n,s])=>`${n} ${typeof s=="object"?JSON.stringify(s):String(s)}`).join(" · ")}function Gv(e){return[...new Set(e.split(/[,\n]/).map(n=>n.trim().replace(/^[-*]\s+/,"")).filter(n=>n!==""))]}function jZ(e,n){const s=e.change;if(!s||s.part!=="tools")return[];if(n===e.editable)return s.added;const r=new Set(Gv(s.current??""));return Gv(n).filter(a=>!r.has(a))}function wZ(e){const n=i=>i.kind==="policy"&&i.ruleKind?`${String(i.payload.plugin??"")}\0${i.ruleKind}`:null,s=new Map;for(const i of e){const l=n(i);l&&s.set(l,(s.get(l)??0)+1)}const r=new Map,a=[];for(const i of e){const l=n(i);if(!l||(s.get(l)??0)<2){a.push(i);continue}let o=r.get(l);o||(o={key:l,label:i.ruleKindLabel||i.ruleKind||"Rules",plugin:String(i.payload.plugin??""),cards:[]},r.set(l,o),a.push(o)),o.cards.push(i)}return a}function yZ(e){return"cards"in e}function VS(e,n){return!n||e.kind==="policy"&&e.payload.plugin===n}function bZ({embedded:e,plugin:n}){const{data:s,error:r,reload:a}=ge(()=>A.proposals(),[],3e4),[i,l]=d.useState(null),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState({}),p=async(v,w,y=!1)=>{l(null),c(null),h(v),m(({[v]:N,...b})=>b);try{c(await w()),a()}catch(N){const b=N instanceof Error?N.message:String(N);y?m(S=>({...S,[v]:b})):l(b)}finally{h(null)}},g=MR(),x=((s==null?void 0:s.open)??[]).filter(v=>VS(v,n)),k=((s==null?void 0:s.closed)??[]).filter(v=>VS(v,n)),j=v=>t.jsx(EZ,{proposal:v,busy:u===v.id,refusal:f[v.id]??null,onKeep:w=>void p(v.id,async()=>{const y=await A.keepProposal(v.id,w);return`${v.title}: ${y.note}`},!0),onDiscard:w=>void p(v.id,async()=>(await A.discardProposal(v.id,w),`Discarded: ${v.title}. ${v.agent} will be told once and will not propose it again for 90 days.`))},v.id);return t.jsxs(gs,{embedded:e,title:"Proposals",lede:"What your agents learned and would like to keep: a procedure, a rule, a change to their own instructions. Keep what is right, correct what is nearly right, discard the rest. A few rules apply themselves, where their plugin allows it (one you always keep, one that only quiets mail sent to many); its own page lists them, with Undo.",children:[t.jsx(ae,{message:r??i}),n?t.jsxs(G,{role:"status",children:["Showing the rules ",n," proposes. ",t.jsx("a",{href:Fe("proposals"),children:"Show every proposal"})]}):null,o?t.jsx(G,{tone:"good",role:"status",children:o}):null,n?null:t.jsx(OR,{offers:g.offers,reload:g.reload}),!s||x.length===0?t.jsx(pe,{title:"Waiting",panel:!0,children:s?n?t.jsx(es,{icon:"bulb",title:`No rule from ${n} is waiting`,children:"It proposes one when you decide the same way several times running."}):t.jsx(es,{icon:"bulb",title:"Nothing proposed",children:"When an agent learns something worth keeping, it waits here."}):t.jsx(Ne,{children:"Loading…"})}):t.jsx(pe,{title:"Waiting",aside:`${x.length} to decide`,children:wZ(x).map(v=>yZ(v)?t.jsx(kZ,{group:v,busy:u===v.key,onKeepAll:()=>void p(v.key,async()=>{const w=await A.keepAllProposals(v.cards.map(y=>y.id));return`${v.label}: ${w.note}`}),card:w=>j(w)},v.key):j(v))}),k.length>0?t.jsx(pe,{title:`Kept, discarded and expired (${k.length})`,aside:"These stop being shown a week after they were decided.",panel:!0,flush:!0,children:t.jsx(ct,{children:k.map(v=>{var w;return t.jsx(rt,{title:v.title,sub:`${v.agent}: ${NZ(v)}`,side:v.kind==="skill"&&v.state==="kept"&&((w=v.skill)!=null&&w.live)?t.jsxs(ne,{align:"end",children:[t.jsx("span",{className:"muted",children:Ge(v.decidedAt??v.createdAt)}),t.jsx($,{size:"sm",variant:"ghost",disabled:u===v.id,onClick:()=>void p(v.id,async()=>{const y=v.skill;return await A.removeSkill(v.agent,y.name),`Removed ${y.name} from ${v.agent}. Its versions are kept, and ${v.agent} will not propose it again for 90 days.`}),children:"Remove this skill"})]}):Ge(v.decidedAt??v.createdAt)},v.id)})})}):null,!n&&(s!=null&&s.digest)?t.jsx(CZ,{schedule:s.digest.schedule,onSaved:a}):null]})}function kZ({group:e,busy:n,onKeepAll:s,card:r}){const a=e.cards.length,i=e.cards.some(l=>l.untrusted);return t.jsx(Ps,{tone:i?"warning":"accent",title:`${e.label} (${a})`,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ae,{children:qP.policy}),t.jsx(Ae,{mono:!0,children:e.plugin})]}),foot:t.jsx(ne,{align:"end",children:t.jsxs($,{variant:"accent",size:"sm",disabled:n,onClick:s,children:["Keep all (",a,")"]})}),children:t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{children:[a," rules of the same kind from ",e.plugin,", each learned from your own decisions. Keep all keeps every one of them as if you had kept each, in one go."]}),t.jsx(Zt,{summary:`Show each of the ${a}`,children:t.jsx(ue,{gap:"sm",children:e.cards.map(l=>r(l))})})]})})}function NZ(e){switch(e.state){case"kept":return e.decidedBy==="auto"?e.note??"Kept by itself.":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 SZ=Array.from({length:24},(e,n)=>n),GS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function CZ({schedule:e,onSaved:n}){const[s,r]=d.useState(e.day),[a,i]=d.useState(e.hour),[l,o]=d.useState(!1),[c,u]=d.useState(null),h=s!==e.day||a!==e.hour,f=async()=>{o(!0),u(null);try{await A.setDigestSchedule(s,a),u({tone:"good",text:`The digest now runs on ${GS[s]} at ${String(a).padStart(2,"0")}:00.`}),n()}catch(m){u({tone:"critical",text:m instanceof Error?m.message:String(m)})}finally{o(!1)}};return t.jsx(pe,{title:"Weekly digest",panel:!0,foot:t.jsx($,{variant:"accent",disabled:l||!h,onClick:()=>void f(),children:"Save"}),children:t.jsxs(ue,{children:[t.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: ${Ge(e.next)}.`:""]}),t.jsxs(ne,{children:[t.jsx(ie,{label:"Day",children:t.jsx("select",{value:s,disabled:l,onChange:m=>r(Number(m.target.value)),children:GS.map((m,p)=>t.jsx("option",{value:p,children:m},m))})}),t.jsx(ie,{label:`Hour (${e.timezone})`,children:t.jsx("select",{value:a,disabled:l,onChange:m=>i(Number(m.target.value)),children:SZ.map(m=>t.jsxs("option",{value:m,children:[String(m).padStart(2,"0"),":00"]},m))})})]}),c?t.jsx(G,{tone:c.tone,role:"status",children:c.text}):null]})})}function YS(e,n){return e==="tools"?Gv(n).join(`
|
|
138
|
-
`):n}function EZ({proposal:e,busy:n,refusal:s,onKeep:r,onDiscard:a}){const[i,l]=d.useState(e.editable??""),[o,c]=d.useState(""),u=e.editable!==null&&i!==e.editable,h=e.payload,f=e.echoes??[],m=e.kind==="change"?e.change??null:null,p=jZ(e,i);return t.jsx(Ps,{tone:e.untrusted?"warning":"accent",title:e.title,meta:t.jsxs(t.Fragment,{children:[t.jsx(Ae,{children:qP[e.kind]}),t.jsx(Ae,{mono:!0,children:e.agent}),e.untrusted?t.jsx(Ae,{tone:"warning",children:"untrusted text in view"}):null,p.length>0?t.jsx(Ae,{tone:"warning",children:"widens its tools"}):null]}),foot:t.jsxs(ne,{align:"end",children:[s?t.jsx("span",{className:"proposal-refusal",role:"alert",children:s}):null,t.jsx("input",{"aria-label":"Reason for discarding (optional)",placeholder:"Reason for discarding (optional)",value:o,maxLength:300,disabled:n,onChange:g=>c(g.target.value)}),t.jsx($,{variant:"ghost",size:"sm",disabled:n,onClick:()=>a(o.trim()||void 0),children:"Discard"}),t.jsx($,{variant:"accent",size:"sm",disabled:n||e.editable!==null&&i.trim()==="",onClick:()=>r(u?i:void 0),children:u?"Keep my version":"Keep"})]}),children:t.jsxs(ue,{gap:"sm",children:[e.why?t.jsx("p",{children:e.why}):null,t.jsxs("p",{className:"ui-card-meta",children:["Proposed by ",e.agent," ",Ge(e.createdAt),e.conversationId?t.jsxs(t.Fragment,{children:[" in ",t.jsx("a",{href:Zc(e.conversationId),children:e.turn?`this conversation, turn ${e.turn}`:"this conversation"})]}):null,"."]}),e.untrusted?t.jsxs(G,{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.",t.jsx("ul",{className:"proposal-sources",children:e.sources.map(g=>t.jsx("li",{className:"mono",children:g},g))}),f.length>0?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"proposal-echo-lede",children:"These sentences of it also appear in that text:"}),t.jsx("ul",{className:"proposal-sources","aria-label":"Sentences found in the untrusted text",children:f.map(g=>t.jsx("li",{children:t.jsx("mark",{className:"wb-diff-mark",children:g})},g))})]}):null]}):null,e.kind==="skill"?t.jsxs(t.Fragment,{children:[typeof h.when=="string"?t.jsxs("p",{className:"ui-card-meta",children:["When: ",h.when]}):null,e.skill?t.jsxs(ue,{gap:"sm",children:[t.jsxs("p",{className:"ui-card-meta",children:[e.agent," already has this skill (",t.jsxs("a",{href:Ft(e.agent,"skills"),children:[e.skill.name,", version ",e.skill.version]}),"). Keeping this writes version ",e.skill.version+1,"; the earlier ones stay readable."]}),t.jsx(Lh,{text:KS(e.skill.steps,i),marks:f,label:`Version ${e.skill.version} against this proposal`})]}):null,t.jsx(ie,{label:"The steps, as it would follow them",hint:"Correct them here and keep your version.",children:t.jsx("textarea",{rows:8,value:i,disabled:n,onChange:g=>l(g.target.value)})})]}):null,e.kind==="change"?t.jsxs(t.Fragment,{children:[p.length>0?t.jsxs(G,{tone:"warning",title:`Adds: ${p.join(", ")}`,children:["Keeping this lets ",e.agent," call tools it cannot call now."]}):null,m!=null&&m.refusal&&!u?t.jsx(G,{tone:"warning",title:"Keeping this as proposed will be refused.",children:m.refusal}):null,m&&m.current!==null?t.jsx(Lh,{text:KS(YS(m.part,m.current),YS(m.part,i)),marks:f,label:`${e.agent}'s ${m.part==="tools"?"tool list":"instructions"} now, against this proposal`}):typeof h.before=="string"?t.jsx(Zt,{summary:`What its ${h.part==="tools"?"tool list":"instructions"} said when proposed`,children:t.jsx(zt,{children:h.before})}):null,t.jsx(ie,{label:h.part==="tools"?"Proposed tool list":"Proposed instructions",hint:"Correct it here and keep your version.",children:t.jsx("textarea",{rows:8,value:i,disabled:n,onChange:g=>l(g.target.value)})})]}):null,e.kind==="policy"?t.jsx(Xt,{items:[{label:"Plugin",value:t.jsx("span",{className:"mono",children:String(h.plugin??"")})},{label:"Matches",value:t.jsx("span",{className:"mono",children:vZ(h.matcher??{})})},{label:"Does",value:String(h.action??"")},...Array.isArray(h.verdicts)&&h.verdicts.length>0?[{label:"Learned from",value:`${h.verdicts.length} ${h.verdicts.length===1?"decision":"decisions"}`}]:[]]}):null]})})}function QP(e){return e.length>1?"small or medium":`${e[0]} only`}function $Z(e){return["small","medium"].filter(n=>e.includes(n))}function JP({widget:e,size:n,svg:s}){var a;const r=(a=e.preview)==null?void 0:a[n];return t.jsxs("div",{className:"wg-frame","data-variant":"preview","data-size":n,"data-kind":r==null?void 0:r.kind,role:"img","aria-label":`${e.title}, ${n}: ${r?"a preview with sample data":"no preview"}`,children:[t.jsxs("div",{className:"wg-head",children:[t.jsx("span",{className:"wg-title",children:e.title}),r?t.jsx("span",{className:"wg-sample",children:"Sample"}):null]}),t.jsx("div",{className:"wg-body",children:r?t.jsx(wm,{body:r,size:n}):t.jsxs("span",{className:"wg-state",children:[t.jsx(Hn,{svg:s}),t.jsx("span",{className:"wg-state-sub",children:"No preview from this plugin."})]})})]})}function AZ(e){const n=[{label:"Home",path:e.home}];if(e.path===e.home||!e.path.startsWith(`${e.home}/`))return n;let s=e.home;for(const r of e.path.slice(e.home.length+1).split("/"))s=`${s}/${r}`,n.push({label:r,path:s});return n}function TZ({start:e,onPick:n,onClose:s}){const[r,a]=d.useState(null),[i,l]=d.useState(null),[o,c]=d.useState(""),u=(p,g=!1)=>{l(null),A.pluginFolders(p).then(x=>{a(x),c("")}).catch(x=>{g&&p!==void 0?u(void 0):l(x instanceof he?x.message:String(x))})};d.useEffect(()=>{u(e,!0)},[]);const h=o.trim().toLowerCase(),f=((r==null?void 0:r.folders)??[]).filter(p=>h===""||p.name.toLowerCase().includes(h)),m=r?AZ(r):[];return t.jsxs(Ye,{title:"Choose the folder",onClose:s,foot:t.jsxs(ne,{children:[t.jsx("span",{className:"plugins-foot-note mono",children:(r==null?void 0:r.path)??""}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",onClick:s,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:!r,onClick:()=>r&&n(r.path),children:"Use this folder"})]}),children:[t.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?t.jsx(xc,{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,t.jsx(hm,{label:"Find a folder here",value:o,placeholder:"Find a folder here…",onChange:c}),t.jsx(ae,{message:i}),r?f.length===0?t.jsx(Ne,{children:h===""?"No folders in here.":`No folder here is called anything like “${o.trim()}”.`}):t.jsx(Xe,{flush:!0,children:t.jsx(ct,{children:f.map(p=>t.jsx(rt,{onClick:()=>u(p.path),label:`Open ${p.name}`,lead:t.jsx(Hn,{icon:"folder"}),title:p.name,side:p.plugin?t.jsx(Ae,{tone:"accent",children:"package.json"}):void 0},p.path))})}):i?null:t.jsx(Ne,{children:"Reading the folders…"}),r!=null&&r.truncated?t.jsx("p",{className:"plugins-note",children:"Only the first 500 folders are listed; find one by name above."}):null]})}const RZ="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 qS(){return t.jsxs("p",{className:"plugins-quiet connections-quiet",children:[t.jsx(oe,{name:"globe",size:14}),t.jsxs("span",{children:["A plugin is code buddi installs and runs; a connection is a service or program buddi talks to."," ",t.jsx("a",{href:Fe("connections"),children:"Connections"})]})]})}const IZ=1500,PZ={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."},MZ="Restart buddi to apply it. In a checkout, stop it and run: buddi serve",XP=[{value:"npm",label:"From npm"},{value:"file",label:"A file"},{value:"directory",label:"A directory I built"}],ZP="buddi.plugins.install-mode";function OZ(){try{const e=window.localStorage.getItem(ZP);if(XP.some(n=>n.value===e))return e}catch{}return"npm"}function DZ(e){try{window.localStorage.setItem(ZP,e)}catch{}}const $d=".tgz",Or=(e,n,s)=>`${e} ${e===1?n:s}`;function eM(e){const n=[];return e.tools>0&&n.push(Or(e.tools,"tool","tools")),e.sentinels>0&&n.push(`${e.sentinels} on a timer`),e.views>0&&n.push(Or(e.views,"view","views")),e.agents>0&&n.push(`${Or(e.agents,"agent","agents")} proposed`),n.length===0?"nothing on its own":n.join(", ")}function Yv(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 tM(e){return e.kind==="registry"?"npm":e.kind==="tarball"?"a file":"a directory"}function Xy(e,n){return e.kind==="directory"?"you, from this machine":e.kind==="tarball"?"a file on this machine":n??"nobody npm will name"}function nM(e){return e.author?e.author.name:e.source.kind==="registry"?e.publisher??"nobody npm will name":"you"}function Cm({author:e}){return e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.name}):t.jsx(t.Fragment,{children:e.name})}function qv({value:e}){return e===void 0||e===""?t.jsx("span",{className:"muted",children:"none — this came off a disk"}):t.jsx("span",{className:"plugins-hash",children:e})}function sM(e){return e.length===0?"none; nothing leaves this computer":t.jsx("span",{className:"mono",children:e.join(", ")})}function Zy(e){return e.length===0?"Nothing beyond its own tables, its own folder and its own tools' approvals.":e.map(n=>`It ${n.words}.`).join(" ")}const ai=e=>e instanceof he?e.message:String(e);function LZ(e){const[n,s]=d.useState(void 0),[r,a]=d.useState(null);return d.useEffect(()=>{if(!e){s(void 0),a(null);return}let i=!1;const l=()=>{A.pluginJob(e).then(c=>{i||(s(c),(c.phase==="done"||c.phase==="failed")&&(i=!0))}).catch(c=>{i||(a(ai(c)),i=!0)})};l();const o=window.setInterval(l,IZ);return()=>{i=!0,window.clearInterval(o)}},[e]),{job:n,error:r}}function FZ({plugin:e,pages:n,navigate:s,variant:r}){const a=n.filter(i=>i.plugin===e);return a.length===0?null:t.jsx(t.Fragment,{children:a.map(i=>{const l=_r(i.plugin,i.id);return t.jsx(lt,{size:"sm",variant:r,href:l,"aria-label":`Open ${i.title}`,onClick:o=>{o.stopPropagation(),s&&(o.preventDefault(),s(l))},children:a.length===1?"Open":`Open ${i.title}`},i.id)})})}function rM({plugin:e}){var s;if(e.enabled===!1)return t.jsx(Ae,{children:"disabled"});const n=(s=e.needs)==null?void 0:s[0];return n?t.jsxs(Ae,{tone:"warning",children:["needs ",n.plugin]}):e.loadsAtRestart?t.jsx(Ae,{tone:"accent",children:"loads at restart"}):e.loaded&&e.setup?t.jsx(Ae,{tone:"warning",children:"needs setup"}):e.loaded?t.jsx(Ae,{tone:"good",dot:!0,children:"loaded"}):t.jsx(Ae,{tone:"critical",children:"did not load"})}function eb({entry:e}){var n;return e.trust==="by-buddi"?t.jsx(Ae,{tone:"accent",children:"by buddi"}):t.jsxs(Ae,{tone:"good",children:["reviewed ",((n=e.reviewed)==null?void 0:n.version)??e.version]})}const Qv=Fe("plugins"),og={installed:Qv,browse:`${Qv}?tab=browse`};function _Z({railPages:e=[],settingsPages:n=[],navigate:s,hash:r=""}={}){const a=ge(()=>A.plugins(),[],2e4),[i,l]=d.useState(null),{job:o,error:c}=LZ(i),[u,h]=d.useState(null),[f,m]=d.useState(()=>I0(r));d.useEffect(()=>m(I0(r)),[r]);const[p,g]=d.useState(()=>R0(r));d.useEffect(()=>g(R0(r)),[r]);const[x,k]=d.useState(null),[j,v]=d.useState(null),[w,y]=d.useState(null),[N,b]=d.useState(null),[S,C]=d.useState(!1),T=le=>{C(!0),A.market(le).then(b).catch(Ce=>b({plugins:[],unavailable:ai(Ce)})).finally(()=>C(!1))};d.useEffect(()=>{f==="browse"&&N===null&&!S&&T(!1)},[f]);const E=le=>{h(null),l(le)},R=le=>h(ai(le)),[M,O]=d.useState(!1),I=le=>{O(!0),k(null),le.then(Ce=>{E(Ce.job.id),m("installed")}).catch(R).finally(()=>O(!1))},z=d.useRef(null);d.useEffect(()=>{const le=uU(r);if(!(le===null||z.current===le)){z.current=le,m("installed"),I(A.stagePlugin(le));try{window.history.replaceState(window.history.state,"",Qv)}catch{}}},[r]);const U=le=>Ce=>{Ce.preventDefault(),m(le),k(null),s==null||s(og[le])};d.useEffect(()=>{((o==null?void 0:o.phase)==="done"||(o==null?void 0:o.phase)==="failed")&&a.reload()},[o==null?void 0:o.phase]);const D=a.data,P=(D==null?void 0:D.checkout)??!0,K=(D==null?void 0:D.installed)??[],F=le=>N==null?void 0:N.plugins.find(Ce=>Ce.installed!==void 0&&(Ce.installed.name??Ce.name)===le.name),Q=le=>e.some(Ce=>Ce.plugin===le),_=(le,Ce)=>Q(le)?t.jsx(FZ,{plugin:le,pages:e,navigate:s,variant:Ce}):void 0,re=le=>{const Ce=e.find(Ze=>Ze.plugin===le);Ce&&s&&s(_r(Ce.plugin,Ce.id))},Y=le=>{const Ce=n.find(Ze=>Ze.plugin===le);if(!(!Ce||!s))return()=>s(mr(Ce.plugin,Ce.id))},B=((N==null?void 0:N.plugins)??[]).filter(le=>le.update).length,q=(le,Ce)=>A.setPluginEnabled(le,Ce).then(Ze=>{c5(),y({name:le,notes:Ze.notes??[]}),a.reload()}),J=(le,Ce,Ze)=>A.uninstallPlugin(le,Ce?{purge:!0,confirm:Ze}:{}).then(xt=>{k(null),y({name:le,notes:xt.notes??[]}),a.reload()}),Z=le=>{h(null),q(le,!0).catch(R)},fe=(le,Ce)=>{const Ze=N==null?void 0:N.plugins.find(Ct=>{var It;return(((It=Ct.installed)==null?void 0:It.name)??Ct.name)===le&&Ct.installed!==void 0}),xt=Ze&&Ce?`${Ze.npm}@${Ce}`:void 0;I(xt?A.updatePlugin(le,Ce,xt):A.updatePlugin(le,Ce))},ve=le=>{h(null);const Ce=Ze=>{const xt=Ze.plugins.find(Ct=>{var It;return Ct.name===le||((It=Ct.installed)==null?void 0:It.name)===le});if(!xt){h(`${le} is not listed on withbuddi.com. Add it from npm, a file or a directory above, then install this one.`);return}I(A.stagePlugin(`${xt.npm}@${xt.version}`))};if(N&&N.plugins.length>0)return Ce(N);O(!0),A.market(!1).then(Ze=>{b(Ze),Ce(Ze)}).catch(R).finally(()=>O(!1))},Oe=(le,Ce)=>Ce===void 0?void 0:Ce.place==="settings"?mr(le,Ce.id):_r(le,Ce.id),W=le=>{var Ze;if(le.enabled===!1)return;const Ce=(Ze=le.needs)==null?void 0:Ze[0];if(Ce)switch(Ce.state){case"missing":return{label:`Install ${Ce.plugin}`,run:()=>ve(Ce.plugin)};case"disabled":return{label:`Enable ${Ce.plugin}`,run:()=>Z(Ce.plugin)};case"range":return{label:`Update ${Ce.plugin}`,run:()=>fe(Ce.plugin)};case"setup":{const xt=Oe(Ce.plugin,Ce.page),Ct=xt&&s?()=>s(xt):Y(Ce.plugin);return Ct?{label:`Set up ${Ce.plugin}`,run:Ct}:void 0}default:return{label:`See ${Ce.plugin}`,run:()=>k({kind:"installed",name:Ce.plugin})}}if(le.loaded&&le.setup){const xt=Oe(le.name,le.setup.page),Ct=xt&&s?()=>s(xt):Y(le.name);return Ct?{label:"Set it up",run:Ct}:void 0}},se=t.jsxs(Co,{label:"Plugins",children:[t.jsx(Ki,{href:og.installed,active:f==="installed",count:B,onClick:U("installed"),children:"Installed"}),t.jsx(Ki,{href:og.browse,active:f==="browse",onClick:U("browse"),children:"Browse"})]}),X=(D==null?void 0:D.staged)??[],je=GZ(X,(o==null?void 0:o.phase)==="done"?o.stagedId:void 0),be=X.find(le=>le.id===je),xe=X.filter(le=>le.id!==je),we=le=>{k(null),qZ(le),l(null),a.reload()},Ie=(x==null?void 0:x.kind)==="staged"?xe.find(le=>le.id===x.name):void 0,ke=(x==null?void 0:x.kind)==="installed"?K.find(le=>le.name===x.name):void 0,me=(x==null?void 0:x.kind)==="market"?N==null?void 0:N.plugins.find(le=>le.name===x.name):void 0,$e=w&&!(ke&&ke.name===w.name)&&w.notes.length>0?w.notes:null,_e=Ie?t.jsx(KZ,{staged:Ie,onClose:()=>k(null),onInstalled:we,onInstallFirst:ve,onGone:()=>{k(null),a.reload()}},Ie.id):ke?t.jsx(nee,{plugin:ke,listing:F(ke),notes:(w==null?void 0:w.name)===ke.name?w.notes:null,canOpen:Q(ke.name)&&ke.enabled!==!1,onOpen:()=>re(ke.name),onClose:()=>k(null),onDisable:()=>v({kind:"disable",name:ke.name}),onEnable:()=>Z(ke.name),onRemove:()=>v({kind:"remove",name:ke.name}),onUpdate:le=>fe(ke.name,le),onSettings:ke.enabled===!1?void 0:Y(ke.name),firstStep:W(ke),busy:M}):me?t.jsx(uee,{entry:me,canOpen:me.installed!==void 0&&Q(me.installed.name??me.name),onOpen:()=>{var le;return re(((le=me.installed)==null?void 0:le.name)??me.name)},onClose:()=>k(null),onInstall:()=>I(A.stagePlugin(`${me.npm}@${me.version}`)),onUpdate:le=>{var Ce;return fe(((Ce=me.installed)==null?void 0:Ce.name)??me.name,le)},busy:M}):null,Le=j?K.find(le=>le.name===j.name):void 0,qe=j?t.jsx(see,{kind:j.kind,name:j.name,canDisable:(Le==null?void 0:Le.enabled)!==!1,onCancel:()=>v(null),onDisableInstead:()=>v({kind:"disable",name:j.name}),onDisable:()=>q(j.name,!1).then(()=>v(null)),onRemove:(le,Ce)=>J(j.name,le,Ce).then(()=>v(null))},`${j.kind}:${j.name}`):null;if(f==="browse")return t.jsxs(ue,{gap:"lg",children:[t.jsx(qS,{}),se,t.jsx(ae,{message:u}),t.jsx(pee,{kind:p,onKind:g,navigate:s,market:N,loading:S,busy:M,onRetry:()=>T(!0),onOpen:le=>k({kind:"market",name:le.name}),onInstall:le=>I(A.stagePlugin(`${le.npm}@${le.version}`)),onUpdate:(le,Ce)=>{var Ze;return fe(((Ze=le.installed)==null?void 0:Ze.name)??le.name,Ce)}}),_e]});const yt=(D==null?void 0:D.builtIn)??[];return t.jsxs(ue,{gap:"lg",children:[t.jsx(qS,{}),se,t.jsx(ae,{message:a.error??u??c}),D!=null&&D.unavailable?t.jsx(G,{tone:"warning",children:D.unavailable}):null,$e?t.jsx(G,{role:"status",children:$e.join(" ")}):null,t.jsx(zZ,{trust:(D==null?void 0:D.trust)??"",job:o,busy:o!==void 0&&o.phase!=="done"&&o.phase!=="failed",onStaged:E,onFailed:h}),be?t.jsx(WZ,{staged:be,onInstalled:we,onGone:()=>a.reload(),onInstallFirst:ve},be.id):null,xe.length>0?t.jsx(Xe,{flush:!0,title:"Waiting for you",tool:Or(xe.length,"package","packages"),children:t.jsx("div",{className:"plugins-rows",children:t.jsx(ct,{children:xe.map(le=>t.jsx(HZ,{staged:le,onReview:()=>{iM(le),k({kind:"staged",name:le.id})},onReject:()=>{h(null),A.rejectStaged(le.id).then(()=>a.reload()).catch(R)}},le.id))})})}):null,D!=null&&D.restartNeeded?t.jsx(YZ,{checkout:P,waiting:K.filter(le=>le.loadsAtRestart)}):null,t.jsx(JZ,{list:K,firstStepFor:W}),t.jsx(Xe,{flush:!0,title:"Installed",tool:D?Or(K.length,"plugin","plugins"):void 0,children:D?K.length===0?t.jsx(Ne,{children:"Nothing installed yet. Only what buddi ships with is here."}):t.jsx("div",{className:"plugins-rows",children:t.jsx(ct,{children:K.map(le=>t.jsx(ZZ,{plugin:le,listing:F(le),open:le.enabled===!1?void 0:_(le.name,"ghost"),canOpen:Q(le.name)&&le.enabled!==!1,busy:M,onDetails:()=>k({kind:"installed",name:le.name}),onOpen:()=>re(le.name),onSettings:le.enabled===!1?void 0:Y(le.name),onDisable:()=>v({kind:"disable",name:le.name}),onEnable:()=>Z(le.name),onRemove:()=>v({kind:"remove",name:le.name}),onUpdate:Ce=>fe(le.name,Ce),firstStep:W(le)},le.name))})}):t.jsx(Ne,{children:"Loading…"})}),yt.length>0?t.jsx(ree,{plugins:yt,openFor:_}):null,_e,qe]})}function zZ({trust:e,job:n,busy:s,onStaged:r,onFailed:a}){const[i,l]=d.useState(OZ),[o,c]=d.useState(""),[u,h]=d.useState(!1),[f,m]=d.useState(null),[p,g]=d.useState(null),[x,k]=d.useState(!1),[j,v]=d.useState(!1),w=d.useRef(null),y=C=>a(ai(C)),N=C=>{l(C),DZ(C),g(null)},b=()=>{h(!0),A.stagePlugin(o.trim()).then(C=>{r(C.job.id),c("")}).catch(y).finally(()=>h(!1))},S=C=>{if(C){if(!C.name.toLowerCase().endsWith($d)){m(null),g(`${C.name} is not a ${$d}. A packed plugin is the file npm pack writes.`);return}g(null),m(C.name),h(!0),A.uploadPlugin(C).then(T=>r(T.job.id)).catch(y).finally(()=>h(!1))}};return t.jsxs(Xe,{title:"Add a plugin",actions:t.jsx(Gt,{label:"Where it comes from",options:XP,value:i,onChange:N}),children:[t.jsxs("div",{className:"plugins-add",children:[i==="file"?t.jsxs("div",{className:"plugins-drop",role:"group","aria-label":"A plugin file","data-state":x?"over":p?"refused":f?"chosen":void 0,onDragOver:C=>{C.preventDefault(),k(!0)},onDragLeave:()=>k(!1),onDrop:C=>{var T,E;C.preventDefault(),k(!1),S((E=(T=C.dataTransfer)==null?void 0:T.files)==null?void 0:E[0])},children:[t.jsx(oe,{name:"drop",size:20}),t.jsx("span",{className:"plugins-drop-text",children:p??(f?`${f} — reading it.`:t.jsxs(t.Fragment,{children:["Drop a ",t.jsx("span",{className:"mono",children:$d})," here: the file ",t.jsx("span",{className:"mono",children:"npm pack"})," ","writes. It is read the moment it lands."]}))}),t.jsx($,{variant:"accent",disabled:s||u,onClick:()=>{var C;return(C=w.current)==null?void 0:C.click()},children:"Choose a file"}),t.jsx("input",{ref:w,type:"file",accept:$d,hidden:!0,"aria-hidden":"true",tabIndex:-1,onChange:C=>{var T;S((T=C.target.files)==null?void 0:T[0]),C.target.value=""}})]}):t.jsxs("div",{className:"plugins-add-row",children:[t.jsxs(ne,{valign:"end",children:[t.jsx(ie,{grow:!0,label:i==="npm"?"Package":"The directory it is in",children:t.jsx("input",{type:"text",value:o,placeholder:i==="npm"?"buddi-plugin-weather":"/home/you/code/buddi-plugin-weather",onChange:C=>c(C.target.value)})}),i==="directory"?t.jsx($,{onClick:()=>v(!0),children:"Browse…"}):null,t.jsx($,{variant:"accent",disabled:s||u||o.trim()==="",onClick:b,children:"Read it first"})]}),t.jsx("span",{className:"ui-field-hint",children:i==="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."})]}),n?t.jsxs("p",{className:"plugins-status",role:"status","data-tone":n.phase==="failed"?"critical":void 0,children:[PZ[n.phase]," ",n.error??""]}):null,t.jsx("div",{className:"plugins-trust",children:t.jsx(G,{tone:"warning",children:e})})]}),j?t.jsx(TZ,{start:o.trim().startsWith("/")?o.trim():void 0,onClose:()=>v(!1),onPick:C=>{c(C),v(!1)}}):null]})}function UZ({staged:e}){var r,a;const n=((r=e.uses)==null?void 0:r.areas)??[],s=((a=e.uses)==null?void 0:a.dropped)??[];return t.jsxs("span",{className:"plugins-uses",children:[n.length===0?Zy([]):n.map(i=>t.jsxs("span",{children:["It ",i.words,". ",i.added?t.jsxs(Ae,{tone:"warning",children:["new in ",e.version]}):null]},i.use)),s.length>0?t.jsxs("span",{className:"muted",children:["No longer: ",s.map(i=>i.words).join("; "),"."]}):null]})}function aM(e,n,s){const[r,a]=d.useState(e.plan??null),[i,l]=d.useState(!1),[o,c]=d.useState(null);return{plan:r,busy:i,failed:o,approve:f=>{l(!0),c(null),A.approveStaged(e.id,{integrity:e.integrity??"",...f?{acknowledgeDrift:!0}:{}}).then(m=>{m.installed?n(e.name):m.plan&&a(m.plan)}).catch(m=>c(ai(m))).finally(()=>l(!1))},reject:()=>{l(!0),c(null),A.rejectStaged(e.id).then(()=>s()).catch(f=>c(ai(f))).finally(()=>l(!1))}}}function iM(e){e.openedAt||A.openedStaged(e.id).catch(()=>{})}function BZ({staged:e,onInstallFirst:n}){return t.jsxs("span",{className:"plugins-requires",children:[(e.requires??[]).map(s=>t.jsxs("span",{className:"plugins-require",children:[t.jsxs("span",{title:s.range,children:[t.jsx("span",{className:"mono",children:s.plugin})," ",s.rangeWords??s.range]}),s.state==="ok"?t.jsx("span",{className:"plugins-require-ok",children:s.installed?`${s.installed} is here`:"here"}):s.state==="missing"?t.jsxs(t.Fragment,{children:[t.jsx(Ae,{tone:"warning",children:"not installed"}),n?t.jsxs($,{size:"sm",onClick:()=>n(s.plugin),children:["Install ",s.plugin," first"]}):null]}):t.jsx(Ae,{tone:"warning",children:s.state==="disabled"?"disabled here":s.state==="range"?`${s.installed??"another version"} is here`:s.state==="failed"?"did not load here":"waiting here"})]},s.plugin)),(e.requires??[]).some(s=>s.state!=="ok")?t.jsx("span",{className:"muted",children:"It installs either way, and waits — tools and widgets off, nothing lost — until each is here and set up."}):null]})}function lM({staged:e,inSheet:n,onInstallFirst:s}){var a;const r=e.dependencies;return t.jsxs("div",{className:"plugins-staged","data-in":n?"sheet":void 0,children:[t.jsx("div",{className:"plugins-facts",children:t.jsx(Xt,{items:[...e.author?[{label:"By",value:t.jsx(Cm,{author:e.author})}]:[],{label:"From",value:e.uploadedName?`a file you chose · ${e.uploadedName}`:Yv(e.source)},{label:"Published by",value:Xy(e.source,e.publisher)},...e.previousSource&&e.previous?[{label:"Replaces",value:`${e.previous.version}, installed from ${Yv(e.previousSource)}`}]:e.source.kind==="directory"&&((a=e.previous)==null?void 0:a.version)===e.version?[{label:"Reinstalls",value:`${e.version}, the same version, its files read again from the folder`}]:[],...e.source.kind==="directory"?[]:[{label:"Installs as",value:e.installsAs?t.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:r.count===0?"none":`${r.count}${r.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${r.withScripts.join(", ")}`}`},{label:"What it reaches",value:t.jsx(UZ,{staged:e})},...(e.requires??[]).length>0?[{label:"Needs",value:t.jsx(BZ,{staged:e,onInstallFirst:s})}]:[],{label:"Integrity",value:t.jsx(qv,{value:e.integrity})},...e.stagedHash?[{label:"Files on disk",value:t.jsx(qv,{value:e.stagedHash})}]:[]]})}),t.jsxs("div",{className:"plugins-claim",children:[t.jsx("div",{className:"plugins-claim-head",children:"What it says about itself"}),t.jsx("div",{className:"plugins-claim-note",children:"From its own buddi.md. Nothing has checked it yet."}),e.claims.missing?t.jsx("p",{className:"plugins-claim-text",children:"It ships no buddi.md, so it says nothing about itself at all."}):t.jsxs("p",{className:"plugins-claim-text",children:["“",e.claims.text,"”"]}),t.jsx("div",{className:"plugins-facts",children:t.jsx(Xt,{items:[{label:"Schema it owns",value:e.claims.schema?t.jsx("span",{className:"mono",children:e.claims.schema}):"it claims none"},{label:"Hosts it reaches",value:e.claims.hosts.length===0?"it claims none":t.jsx("span",{className:"mono",children:e.claims.hosts.join(", ")})}]})})]})]})}function oM({plan:e,busy:n,onReject:s,onInstallAnyway:r}){return t.jsxs(Ps,{tone:"warning",title:"What it said, and what it does",meta:t.jsx(Ae,{tone:"warning",children:"read this first"}),foot:t.jsxs(ne,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Install anyway says you read these."}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",disabled:n,onClick:s,children:"Not this one"}),t.jsx($,{variant:"danger",disabled:n,onClick:r,children:"Install anyway"})]}),children:[t.jsx("p",{className:"plugins-note",children:"Its prose and its manifest do not agree. Neither is authoritative; the manifest is what actually runs."}),t.jsx("ul",{className:"plugins-drift",children:e.drift.map(a=>t.jsx("li",{children:a},a))}),t.jsx(cM,{unlocks:e.agents??[]})]})}function WZ({staged:e,onInstalled:n,onGone:s,onInstallFirst:r}){const{plan:a,busy:i,failed:l,approve:o,reject:c}=aM(e,n,s);d.useEffect(()=>iM(e),[e.id]);const u=(a==null?void 0:a.drift)??[];return t.jsxs(ue,{gap:"sm",children:[t.jsxs(Ps,{tone:"accent",title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),meta:t.jsx(Ae,{children:"read, not installed"}),foot:t.jsxs(ne,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",disabled:i,onClick:c,children:"Not this one"}),t.jsx($,{variant:"accent",disabled:i||u.length>0,onClick:()=>o(!1),children:"Install"})]}),children:[t.jsx(ae,{message:l}),t.jsx(lM,{staged:e,onInstallFirst:r})]}),a&&u.length>0?t.jsx(oM,{plan:a,busy:i,onReject:c,onInstallAnyway:()=>o(!0)}):null]})}function HZ({staged:e,onReview:n,onReject:s}){const r=Ge(e.createdAt);return t.jsx(rt,{onClick:n,label:`${e.name}: review`,lead:t.jsx(Hn,{svg:void 0}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version})]}),sub:`from ${tM(e.source)}${r?` · read ${r}`:""}`,side:t.jsxs("span",{className:"plugins-side",children:[t.jsxs("span",{className:"plugins-wait-extra",children:[t.jsx(Ae,{children:"read, not installed"}),t.jsx($,{size:"sm",variant:"ghost",onClick:lo(s),children:"Not this one"})]}),t.jsx($,{size:"sm",onClick:lo(n),children:"Review"})]})})}function KZ({staged:e,onClose:n,onInstalled:s,onGone:r,onInstallFirst:a}){const{plan:i,busy:l,failed:o,approve:c,reject:u}=aM(e,s,r),h=(i==null?void 0:i.drift)??[];return t.jsxs(Ye,{title:t.jsx(sb,{svg:void 0,name:e.name,version:e.version,by:e.author?t.jsx(Cm,{author:e.author}):Xy(e.source,e.publisher),pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(Ae,{children:"read, not installed"})]})}),onClose:n,foot:t.jsxs(ne,{children:[t.jsx("span",{className:"plugins-foot-note",children:"Nothing of it has run."}),t.jsx(ot,{}),t.jsx($,{variant:"ghost",disabled:l,onClick:u,children:"Not this one"}),t.jsx($,{variant:"accent",disabled:l||h.length>0,onClick:()=>c(!1),children:"Install"})]}),children:[t.jsx(ae,{message:o}),t.jsx(lM,{staged:e,inSheet:!0,onInstallFirst:a}),i&&h.length>0?t.jsx(oM,{plan:i,busy:l,onReject:u,onInstallAnyway:()=>c(!0)}):null]})}const VZ=10*60*1e3;function GZ(e,n,s=Date.now()){if(n&&e.some(i=>i.id===n))return n;const r=[...e].sort((i,l)=>(l.createdAt??"").localeCompare(i.createdAt??""))[0];if(!(r!=null&&r.createdAt))return null;const a=s-Date.parse(r.createdAt);return Number.isFinite(a)&&a<VZ?r.id:null}function YZ({checkout:e,waiting:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(null),l=qU(n),o=l?`${l} ${n.length===1?"is":"are"} installed.`:"A plugin was installed, disabled or enabled since buddi started, and this buddi has not caught up.";return t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:a}),t.jsxs(G,{tone:e?"warning":"accent",role:"status",action:e?void 0:t.jsx($,{size:"sm",variant:"accent",disabled:s,onClick:()=>{r(!0),i(null),sm({kind:"plugins",...l?{line:`Loading ${l}…`}:{line:"Applying your plugin changes…"}},()=>A.serviceAction("restart")).catch(c=>i(ai(c))).finally(()=>r(!1))},children:"Restart to load it"}),children:[o," ",e?MZ:`${l?n.length===1?"Its tools appear":"Their tools appear":"It takes effect"} once buddi restarts, which takes a few seconds. This page waits and comes back by itself.`]})]})}const tb="buddi.plugins.justInstalled";function qZ(e){try{window.sessionStorage.setItem(tb,e)}catch{}}function QZ(){try{return window.sessionStorage.getItem(tb)}catch{return null}}function JZ({list:e,firstStepFor:n}){var u;const[s,r]=d.useState(()=>QZ()),a=s?e.find(h=>h.name===s):void 0,i=a!==void 0&&(a.loaded||a.needs!==void 0),l=i&&(a.needs!==void 0||a.setup!==void 0),o=()=>{try{window.sessionStorage.removeItem(tb)}catch{}r(null)};if(d.useEffect(()=>{i&&!l&&o()},[i,l]),!a||!l)return null;const c=n(a);return t.jsx(G,{tone:"accent",role:"status",action:t.jsxs(t.Fragment,{children:[t.jsx($,{size:"sm",variant:"ghost",onClick:o,children:"Later"}),c?t.jsx($,{size:"sm",variant:"accent",onClick:()=>{o(),c.run()},children:c.label}):null]}),children:a.needs?`${a.name} is installed and waits. ${nb(a)}.`:`${a.name} is loaded. First: ${((u=a.setup)==null?void 0:u.note)??"set it up on its settings page."}`})}const lo=e=>n=>{n.stopPropagation(),e()},XZ=e=>e.unlocks.filter(n=>n.drift.state==="not-accepted").length;function nb(e){var n;return e.needs&&e.needs.length>0?e.needs.map(s=>s.state==="setup"&&s.note?`${s.words}: ${s.note}`:s.words).join(" · "):((n=e.setup)==null?void 0:n.note)??"Not set up yet. Its settings say what it needs."}function ZZ({plugin:e,listing:n,open:s,canOpen:r,busy:a,onDetails:i,onOpen:l,onSettings:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){const p=e.enabled===!1,g=XZ(e),x=!p&&(e.needs!==void 0||e.loaded&&e.setup!==void 0);return t.jsx(rt,{onClick:i,label:`${e.name}: details`,dimmed:p,lead:t.jsx(Hn,{svg:n==null?void 0:n.iconSvg}),title:t.jsxs(t.Fragment,{children:[e.name," ",t.jsx("span",{className:"plugins-ver",children:e.version}),g>0?t.jsxs("span",{className:"plugins-ask",children:[Or(g,"agent","agents")," to accept"]}):null]}),sub:x?t.jsx("span",{className:"plugins-sub","data-tone":"warning",children:nb(e)}):`by ${nM(e)} · from ${tM(e.source)} · ${eM(e.contribution)}`,side:t.jsxs("span",{className:"plugins-side",children:[x&&m?t.jsx($,{size:"sm",onClick:lo(m.run),children:m.label}):null,n!=null&&n.update?t.jsxs($,{size:"sm",disabled:a,onClick:lo(()=>f(n.update)),children:["Update to ",n.update]}):null,x?null:s,!x&&!r&&o?t.jsx($,{size:"sm",variant:"ghost",onClick:k=>{k.stopPropagation(),o()},children:"Settings"}):null,t.jsx(rM,{plugin:e}),t.jsx(ss,{label:`More for ${e.name}`,items:[{label:"Details",onSelect:i},r?{label:"Open its page",onSelect:l}:null,o?{label:"Its settings",onSelect:o}:null,e.source.kind==="directory"&&!a?{label:"Reinstall from folder",hint:"reads its files again",onSelect:()=>f()}:null,p?{label:"Enable",hint:"all of it comes back",onSelect:u}:{label:"Disable…",hint:"keeps its data",onSelect:c},"separator",{label:"Remove…",tone:"critical",onSelect:h}]})]})})}const eee={"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 cM({plugin:e,unlocks:n}){return n.length===0?null:t.jsxs(pe,{title:"Agents it would unlock",children:[t.jsx("div",{className:"plugins-unlocks",children:t.jsx(ct,{children:n.map(s=>t.jsx(tee,{plugin:e,unlock:s},s.id))})}),t.jsxs("p",{className:"plugins-note",children:["Nothing here is created by installing. Accept creates the agent with the tools listed; change or remove it"," ",t.jsx("a",{href:bt,children:"on the Agents page"}),"."]})]})}function tee({plugin:e,unlock:n}){const s=Ny(e,n.id),r=s.created?"up-to-date":n.drift.state,[a,i]=eee[r];return t.jsxs("div",{className:"plugins-unlock",children:[t.jsx(rt,{title:t.jsxs("span",{className:"plugins-handle",children:["@",n.handle]}),sub:s.created?"Accepted just now. It is on the Agents page.":n.drift.message,side:t.jsxs("span",{className:"plugins-side",children:[t.jsx(Ae,{tone:a,children:i}),e&&r==="not-accepted"?t.jsx($,{size:"sm",variant:"accent",disabled:s.busy,onClick:s.accept,children:"Accept"}):null]})}),t.jsx(ae,{message:s.failure}),s.created?t.jsx(IR,{agent:s.created}):null]})}function sb({svg:e,name:n,version:s,by:r,pills:a}){return t.jsxs("span",{className:"plugins-sheet-title",children:[t.jsx(Hn,{svg:e,size:"lg"}),t.jsxs("span",{className:"plugins-sheet-name",children:[t.jsxs("span",{children:[n," ",t.jsx("span",{className:"plugins-ver",children:s})]}),t.jsxs("span",{className:"plugins-sheet-by",children:["by ",r,a]})]})]})}function nee({plugin:e,listing:n,notes:s,canOpen:r,busy:a,onOpen:i,onSettings:l,onClose:o,onDisable:c,onEnable:u,onRemove:h,onUpdate:f,firstStep:m}){var v,w;const p=e.enabled===!1,g=e.author!==void 0&&e.source.kind==="directory",x=(n==null?void 0:n.summary)??e.description,k=(e.network??((w=(v=n==null?void 0:n.claims)==null?void 0:v.manifest)==null?void 0:w.network)??[]).map(y=>y.host),j=e.uses??(n==null?void 0:n.usesWords);return t.jsxs(Ye,{title:t.jsx(sb,{svg:n==null?void 0:n.iconSvg,name:e.name,version:e.version,by:e.author?t.jsx(Cm,{author:e.author}):nM(e),pills:t.jsxs(t.Fragment,{children:[n?t.jsxs(t.Fragment,{children:[" · ",t.jsx(eb,{entry:n})]}):null," · ",t.jsx(rM,{plugin:e})]})}),onClose:o,foot:t.jsxs(ne,{children:[t.jsx($,{variant:"danger-ghost",onClick:h,children:"Remove…"}),t.jsx(ot,{}),l?t.jsx($,{variant:"ghost",onClick:l,children:"Settings"}):null,r?t.jsx($,{onClick:i,children:"Open"}):null,p?t.jsx($,{onClick:u,children:"Enable"}):t.jsx($,{variant:"ghost",onClick:c,children:"Disable…"}),n!=null&&n.update?t.jsxs($,{variant:"accent",disabled:a,onClick:()=>f(n.update),children:["Update to ",n.update]}):t.jsx($,{disabled:a,onClick:()=>f(),children:e.source.kind==="directory"?"Reinstall from folder":"Check for an update"})]}),children:[e.error?t.jsx(G,{tone:"critical",children:e.error}):null,s&&s.length>0?t.jsx(G,{role:"status",children:s.join(" ")}):null,p?t.jsx(G,{children:"Disabled: its tools, pages and watchers are off and its missions are paused. Its data is kept."}):null,!p&&e.needs&&e.needs.length>0?t.jsxs(G,{tone:"warning",action:m?t.jsx($,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Waiting: ",nb(e),". Its tools and widgets stay off until then; its data is kept."]}):!p&&e.loaded&&e.setup?t.jsxs(G,{tone:"warning",action:m?t.jsx($,{size:"sm",variant:"accent",onClick:m.run,children:m.label}):void 0,children:["Not set up yet. ",e.setup.note??"Its settings say what it needs."]}):null,x?t.jsx("p",{className:"plugins-summary-full",children:x}):null,t.jsx("div",{className:"plugins-facts",children:t.jsx(Xt,{items:[{label:"From",value:Yv(e.source)},...g?[]:[{label:"Published by",value:Xy(e.source,e.publisher)}],{label:"Integrity",value:t.jsx(qv,{value:e.integrity})},{label:"Installed",value:Ge(e.installedAt)},...e.installedAs?[{label:"Installed as",value:e.installedAs}]:[],{label:"Contributes",value:eM(e.contribution)},...e.network||n?[{label:"Talks to hosts",value:sM(k)}]:[],...j?[{label:"Reaches in buddi",value:Zy(j)}]:[]]})}),t.jsx(cM,{plugin:e.name,unlocks:e.unlocks})]})}function see({kind:e,name:n,canDisable:s,onCancel:r,onDisableInstead:a,onDisable:i,onRemove:l}){const[o,c]=d.useState(!1),[u,h]=d.useState(""),[f,m]=d.useState(!1),[p,g]=d.useState(null),x=j=>{m(!0),g(null),j().catch(v=>g(ai(v))).finally(()=>m(!1))};if(e==="disable")return t.jsxs(Ut,{title:`Disable ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx($,{variant:"accent",disabled:f,onClick:()=>x(i),children:"Disable"})]}),children:[t.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."}),t.jsx(ae,{message:p})]});const k=!o||u.trim()===n;return t.jsxs(Ut,{title:`Remove ${n}?`,onClose:r,foot:t.jsxs(t.Fragment,{children:[s?t.jsx($,{variant:"ghost",size:"sm",disabled:f,onClick:a,children:"Disable instead"}):null,t.jsx(ot,{}),t.jsx($,{variant:"ghost",disabled:f,onClick:r,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:f||!k,onClick:()=>x(()=>l(o,u.trim())),children:o?"Remove and drop its data":"Remove"})]}),children:[t.jsxs("p",{className:"plugins-dialog-text",children:["This takes ",n," off this machine and stops its code loading. Its tables and the agents you accepted from it stay."]}),t.jsxs("div",{className:"plugins-purge","data-on":o?"true":void 0,children:[t.jsxs("label",{className:"plugins-check",children:[t.jsx("input",{type:"checkbox",checked:o,onChange:j=>{c(j.target.checked),h("")}}),t.jsxs("span",{children:[t.jsx("span",{className:"plugins-check-title",children:"Also drop its data"}),t.jsx("span",{className:"plugins-check-hint",children:"Its tables are gone for good; there is no undo."})]})]}),o?t.jsx(ie,{label:t.jsxs(t.Fragment,{children:["Type ",t.jsx("span",{className:"mono",children:n})," to confirm"]}),children:t.jsx("input",{autoFocus:!0,value:u,onChange:j=>h(j.target.value)})}):null]}),t.jsx(ae,{message:p})]})}function ree({plugins:e,openFor:n}){return t.jsxs(Zt,{boxed:!0,summary:`Ships with buddi · ${Or(e.length,"plugin","plugins")}`,children:[t.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."}),t.jsx("div",{className:"plugins-builtins",children:e.map(s=>{const r=(s.network??[]).map(i=>i.host),a=[s.description,s.author?`By ${s.author.name}.`:null,r.length>0?`Talks to ${r.join(", ")}.`:null].filter(Boolean).join(" ");return t.jsxs("div",{className:"plugins-builtin",title:a||void 0,children:[t.jsx("span",{className:"mono",children:s.name}),t.jsxs("span",{className:"plugins-builtin-n",children:[n(s.name,"ghost"),Or(s.contribution.tools,"tool","tools")]})]},s.name)})})]})}const aee=[{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 iee(e,n){const s=n.trim().toLowerCase();return s===""?!0:[e.title,e.summary,e.npm,...(e.widgets??[]).map(r=>r.title)].some(r=>r.toLowerCase().includes(s))}function lee({pricing:e}){return e.kind==="free"?t.jsx(t.Fragment,{children:"free"}):t.jsxs(t.Fragment,{children:[e.kind==="paid"?"paid":"a subscription",e.trialDays?` · ${e.trialDays} days to try`:"",e.note?` · ${e.note}`:"",e.vendor?t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:e.vendor,target:"_blank",rel:"noopener noreferrer",children:"its maker's page"})]}):null]})}function oee({entry:e,busy:n,onOpen:s,onInstall:r,onUpdate:a}){var i,l;return t.jsxs(Ps,{onClick:s,label:`${e.title}: details`,children:[t.jsxs("div",{className:"plugins-card-head",children:[t.jsx(Hn,{svg:e.iconSvg,size:"lg"}),t.jsxs("div",{className:"plugins-card-name",children:[t.jsx("h3",{className:"ui-card-title",children:e.title}),t.jsxs("div",{className:"plugins-card-by",children:["by ",((i=e.author)==null?void 0:i.name)??"someone who gave no name",(l=e.widgets)!=null&&l.length?` · ${Or(e.widgets.length,"widget","widgets")}`:""]})]})]}),t.jsx("p",{className:"plugins-summary",children:e.summary}),t.jsxs("div",{className:"plugins-card-foot",children:[t.jsx(eb,{entry:e}),e.installed?t.jsxs(Ae,{children:["installed ",e.installed.version]}):null,t.jsx(ot,{}),e.update?t.jsxs($,{size:"sm",disabled:n,onClick:lo(()=>a(e.update)),children:["Update to ",e.update]}):e.installed?null:t.jsx($,{size:"sm",variant:"accent",disabled:n,onClick:lo(r),children:"Install"})]})]})}function cee(e){var o,c;const n=(o=e.claims)==null?void 0:o.manifest,s=n==null?void 0:n.tools;if(!s)return;const r=s.filter(u=>u.tier==="auto").length,a=s.length-r,i=((c=n==null?void 0:n.sentinels)==null?void 0:c.length)??0,l=[r>0?`${r} run without asking`:null,a>0?`${a} ask${a===1?"s":""} you first`:null,i>0?`${i} on a timer`:null].filter(Boolean);return l.length===0?"none":l.join(", ")}function uee({entry:e,canOpen:n,busy:s,onOpen:r,onClose:a,onInstall:i,onUpdate:l}){var m,p,g,x,k,j,v,w;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(y=>y.host),u=cee(e),h=((j=(k=(x=e.claims)==null?void 0:x.manifest)==null?void 0:k.agents)==null?void 0:j.length)??0,f=(w=(v=e.claims)==null?void 0:v.package)==null?void 0:w.dependencies;return t.jsxs(Ye,{title:t.jsx(sb,{svg:e.iconSvg,name:e.title,version:e.version,by:e.author?t.jsx(Cm,{author:e.author}):"someone who gave no name",pills:t.jsxs(t.Fragment,{children:[" · ",t.jsx(eb,{entry:e}),e.installed?t.jsxs(t.Fragment,{children:[" · ",t.jsxs(Ae,{children:["installed ",e.installed.version]})]}):null]})}),onClose:a,foot:t.jsxs(ne,{children:[t.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."}),t.jsx(ot,{}),n?t.jsx($,{onClick:r,children:"Open"}):null,e.update?t.jsxs($,{variant:"accent",disabled:s,onClick:()=>l(e.update),children:["Update to ",e.update]}):e.installed?null:t.jsx($,{variant:"accent",disabled:s,onClick:i,children:"Install"})]}),children:[o?t.jsx("img",{className:"plugins-shot",src:A.marketAssetUrl(o),alt:`${e.title}, as it looks in buddi`}):null,t.jsx("p",{className:"plugins-summary-full",children:e.summary}),t.jsx(hee,{entry:e}),t.jsx("div",{className:"plugins-facts",children:t.jsx(Xt,{items:[{label:"Package",value:t.jsx("span",{className:"mono",children:`${e.npm}@${e.version}`})},...u?[{label:"Tools",value:u}]:[],...h>0?[{label:"Proposes",value:`${Or(h,"agent","agents")}, created only if you accept`}]:[],{label:"Talks to hosts",value:sM(c)},{label:"Reaches in buddi",value:Zy(e.usesWords??[])},...f?[{label:"Dependencies",value:f.count===0?"none":`${f.count}${f.withScripts.length===0?", none of which run install scripts":`, of which these run install scripts: ${f.withScripts.join(", ")}`}`}]:[],{label:"Licence",value:t.jsxs(t.Fragment,{children:[e.license??"not stated"," · ",t.jsx(lee,{pricing:e.pricing})]})}]})})]})}function dee(e){return[QP(e.sizes),e.settings>0?"settings per placement":null,e.sensitive?"hidden until you show it, never on the lock screen":null].filter(Boolean).join(" · ")}function hee({entry:e}){const n=e.widgets??[];return n.length===0?null:t.jsx(pe,{title:"Widgets",aside:t.jsx("span",{className:"plugins-note",children:"Sample data, drawn as Home draws it"}),children:t.jsx("div",{className:"plugins-widgets",children:n.map(s=>t.jsxs("div",{className:"plugins-widget",children:[t.jsxs("div",{className:"plugins-widget-head",children:[t.jsx("span",{className:"plugins-widget-title",children:s.title}),t.jsx("span",{className:"plugins-widget-sub",children:dee(s)})]}),t.jsx("div",{className:"plugins-widget-frames",children:$Z(s.sizes).map(r=>t.jsx(JP,{widget:s,size:r,svg:e.iconSvg},r))})]},s.id))})})}function fee(e){var s,r,a,i,l;const n=(s=e.claims)==null?void 0:s.manifest;return(((r=e.widgets)==null?void 0:r.length)??0)>0&&(((a=n==null?void 0:n.tools)==null?void 0:a.length)??0)===0&&(((i=n==null?void 0:n.sentinels)==null?void 0:i.length)??0)===0&&(((l=n==null?void 0:n.agents)==null?void 0:l.length)??0)===0}function mee({entries:e,busy:n,onOpen:s,onInstall:r}){return t.jsx("div",{className:"plugins-wgrid","data-testid":"browse-widgets",children:e.flatMap(a=>(a.widgets??[]).map(i=>{var o;const l=i.sizes[0]??"small";return t.jsxs("div",{className:"plugins-witem","data-size":l,children:[t.jsx("button",{type:"button",className:"plugins-witem-frame","aria-label":`${i.title}, from ${a.title}: details`,onClick:()=>s(a),children:t.jsx(JP,{widget:i,size:l,svg:a.iconSvg})}),t.jsxs("div",{className:"plugins-witem-foot",children:[t.jsxs("span",{className:"plugins-witem-text",children:[t.jsx("span",{className:"plugins-witem-title",children:i.title}),t.jsxs("span",{className:"plugins-witem-sub",children:[fee(a)?"A widget":`${a.title} plugin`," · by ",((o=a.author)==null?void 0:o.name)??"someone who gave no name"," · ",QP(i.sizes)]})]}),a.installed?t.jsx("span",{className:"plugins-witem-have",children:"Installed"}):t.jsx($,{size:"sm",variant:"accent",disabled:n,"aria-label":`Install ${a.title}`,onClick:()=>r(a),children:"Install"})]})]},`${a.npm}:${i.id}`)}))})}function pee({kind:e="all",onKind:n,navigate:s,market:r,loading:a,busy:i,onRetry:l,onOpen:o,onInstall:c,onUpdate:u}){const[h,f]=d.useState(""),[m,p]=d.useState("all"),g=(r==null?void 0:r.plugins)??[],x=[{value:"all",label:"All"},{value:"recommended",label:"Recommended"},...aee.filter(y=>g.some(N=>N.category===y.value))],k=g.filter(y=>{var N;return e==="widgets"&&(((N=y.widgets)==null?void 0:N.length)??0)===0||m==="recommended"&&(y.trust!=="by-buddi"||y.installed)||m!=="all"&&m!=="recommended"&&y.category!==m?!1:iee(y,h)}),j=h.trim(),v=t.jsx("div",{className:"plugins-kind",children:t.jsx(Gt,{label:"Show",options:gee,value:e,onChange:y=>n==null?void 0:n(y)})}),w=e==="plugins"||e==="widgets"?null:t.jsx(xee,{kind:e,navigate:s});return e==="agents"?t.jsxs(ue,{gap:"lg",children:[v,t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(oe,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."]}),w]}):t.jsxs(ue,{gap:"lg",children:[v,t.jsxs(ne,{children:[t.jsx(hm,{grow:!0,label:e==="widgets"?"Search widgets":"Search plugins",value:h,placeholder:e==="widgets"?"Search widgets: weather, calendar, news…":"Search plugins: weather, money, calendar…",onChange:f}),t.jsx(mT,{label:"Show",options:x,value:m,onChange:p})]}),t.jsxs("p",{className:"plugins-quiet",children:[t.jsx(oe,{name:"globe",size:14}),"Opening this tab fetched the list from withbuddi.com. Nothing else leaves."," ",t.jsx("button",{type:"button",className:"plugins-link",disabled:a,onClick:l,children:"Refresh"})]}),r===null||a&&r.unavailable?t.jsx(Ne,{children:"Asking withbuddi.com…"}):r.unavailable?t.jsx(G,{tone:"warning",action:t.jsx($,{size:"sm",disabled:a,onClick:l,children:"Try again"}),children:r.unavailable}):t.jsxs(t.Fragment,{children:[r.stale?t.jsxs(G,{tone:"warning",action:t.jsx($,{size:"sm",disabled:a,onClick:l,children:"Try again"}),children:["withbuddi.com did not answer, so this is the list as it was",r.fetchedAt?` ${Ge(r.fetchedAt)}`:" last time","."]}):null,k.length>0&&e==="widgets"?t.jsx(mee,{entries:k,busy:i,onOpen:o,onInstall:c}):k.length>0?t.jsx("div",{className:"plugins-grid",children:k.map(y=>t.jsx(oee,{entry:y,busy:i,onOpen:()=>o(y),onInstall:()=>c(y),onUpdate:N=>u(y,N)},y.npm))}):t.jsx(Ne,{warm:!0,title:"Nothing listed matches",children:j!==""?`No ${e==="widgets"?"widget":"plugin"} on withbuddi.com mentions “${j}”.`:e==="widgets"&&!g.some(y=>{var N;return(((N=y.widgets)==null?void 0:N.length)??0)>0})?"No plugin on withbuddi.com brings a widget yet.":g.length===0?"withbuddi.com lists no plugins yet.":"Nothing on this shelf yet."})]}),w]})}const gee=[{value:"all",label:"All"},{value:"plugins",label:"Plugins"},{value:"widgets",label:"Widgets"},{value:"agents",label:"Agents"}];function xee({kind:e,navigate:n}){const s=ge(()=>A.catalogue(),[]),r=zy(),a=c=>n==null?void 0:n(c),i=s.data;if(!i)return s.error?t.jsx(G,{tone:"warning",children:s.error}):t.jsx(Ne,{children:"Asking withbuddi.com…"});if(i.unavailable)return e==="agents"?t.jsx(G,{tone:"warning",children:i.unavailable}):null;const l=i.agents.filter(c=>Hr(c)==="ready"),o=e==="all"?l.slice(0,3):i.agents;return o.length===0?null:t.jsx(pe,{title:e==="all"?"Teammates":void 0,aside:t.jsx("a",{href:un(),onClick:c=>{c.preventDefault(),a(un())},children:e==="all"?`See all ${i.agents.length}`:"Open the catalogue"}),children:t.jsx("div",{className:"plugins-grid","data-testid":"browse-agents",children:o.map(c=>t.jsx(HI,{entry:c,loaded:r,onOpen:()=>a(un(c.name)),onAdd:()=>a(un(c.name)),onUpdate:()=>a(un(c.name))},c.name))})})}var Pu={},vee=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},uM={},Os={};let rb;const jee=[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];Os.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17};Os.getSymbolTotalCodewords=function(n){return jee[n]};Os.getBCHDigit=function(e){let n=0;for(;e!==0;)n++,e>>>=1;return n};Os.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');rb=n};Os.isKanjiModeEnabled=function(){return typeof rb<"u"};Os.toSJIS=function(n){return rb(n)};var Em={};(function(e){e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function n(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,a){if(e.isValid(r))return r;try{return n(r)}catch{return a}}})(Em);function dM(){this.buffer=[],this.length=0}dM.prototype={get:function(e){const n=Math.floor(e/8);return(this.buffer[n]>>>7-e%8&1)===1},put:function(e,n){for(let s=0;s<n;s++)this.putBit((e>>>n-s-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(e){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),e&&(this.buffer[n]|=128>>>this.length%8),this.length++}};var wee=dM;function Mu(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)}Mu.prototype.set=function(e,n,s,r){const a=e*this.size+n;this.data[a]=s,r&&(this.reservedBit[a]=!0)};Mu.prototype.get=function(e,n){return this.data[e*this.size+n]};Mu.prototype.xor=function(e,n,s){this.data[e*this.size+n]^=s};Mu.prototype.isReserved=function(e,n){return this.reservedBit[e*this.size+n]};var yee=Mu,hM={};(function(e){const n=Os.getSymbolSize;e.getRowColCoords=function(r){if(r===1)return[];const a=Math.floor(r/7)+2,i=n(r),l=i===145?26:Math.ceil((i-13)/(2*a-2))*2,o=[i-7];for(let c=1;c<a-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},e.getPositions=function(r){const a=[],i=e.getRowColCoords(r),l=i.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||a.push([i[o],i[c]]);return a}})(hM);var fM={};const bee=Os.getSymbolSize,QS=7;fM.getPositions=function(n){const s=bee(n);return[[0,0],[s-QS,0],[0,s-QS]]};var mM={};(function(e){e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const n={N1:3,N2:3,N3:40,N4:10};e.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},e.from=function(a){return e.isValid(a)?parseInt(a,10):void 0},e.getPenaltyN1=function(a){const i=a.size;let l=0,o=0,c=0,u=null,h=null;for(let f=0;f<i;f++){o=c=0,u=h=null;for(let m=0;m<i;m++){let p=a.get(f,m);p===u?o++:(o>=5&&(l+=n.N1+(o-5)),u=p,o=1),p=a.get(m,f),p===h?c++:(c>=5&&(l+=n.N1+(c-5)),h=p,c=1)}o>=5&&(l+=n.N1+(o-5)),c>=5&&(l+=n.N1+(c-5))}return l},e.getPenaltyN2=function(a){const i=a.size;let l=0;for(let o=0;o<i-1;o++)for(let c=0;c<i-1;c++){const u=a.get(o,c)+a.get(o,c+1)+a.get(o+1,c)+a.get(o+1,c+1);(u===4||u===0)&&l++}return l*n.N2},e.getPenaltyN3=function(a){const i=a.size;let l=0,o=0,c=0;for(let u=0;u<i;u++){o=c=0;for(let h=0;h<i;h++)o=o<<1&2047|a.get(u,h),h>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|a.get(h,u),h>=10&&(c===1488||c===93)&&l++}return l*n.N3},e.getPenaltyN4=function(a){let i=0;const l=a.data.length;for(let c=0;c<l;c++)i+=a.data[c];return Math.abs(Math.ceil(i*100/l/5)-10)*n.N4};function s(r,a,i){switch(r){case e.Patterns.PATTERN000:return(a+i)%2===0;case e.Patterns.PATTERN001:return a%2===0;case e.Patterns.PATTERN010:return i%3===0;case e.Patterns.PATTERN011:return(a+i)%3===0;case e.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(i/3))%2===0;case e.Patterns.PATTERN101:return a*i%2+a*i%3===0;case e.Patterns.PATTERN110:return(a*i%2+a*i%3)%2===0;case e.Patterns.PATTERN111:return(a*i%3+(a+i)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}e.applyMask=function(a,i){const l=i.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)i.isReserved(c,o)||i.xor(c,o,s(a,c,o))},e.getBestMask=function(a,i){const l=Object.keys(e.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){i(u),e.applyMask(u,a);const h=e.getPenaltyN1(a)+e.getPenaltyN2(a)+e.getPenaltyN3(a)+e.getPenaltyN4(a);e.applyMask(u,a),h<c&&(c=h,o=u)}return o}})(mM);var $m={};const Fa=Em,Ad=[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],Td=[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];$m.getBlocksCount=function(n,s){switch(s){case Fa.L:return Ad[(n-1)*4+0];case Fa.M:return Ad[(n-1)*4+1];case Fa.Q:return Ad[(n-1)*4+2];case Fa.H:return Ad[(n-1)*4+3];default:return}};$m.getTotalCodewordsCount=function(n,s){switch(s){case Fa.L:return Td[(n-1)*4+0];case Fa.M:return Td[(n-1)*4+1];case Fa.Q:return Td[(n-1)*4+2];case Fa.H:return Td[(n-1)*4+3];default:return}};var pM={},Am={};const Nc=new Uint8Array(512),ff=new Uint8Array(256);(function(){let n=1;for(let s=0;s<255;s++)Nc[s]=n,ff[n]=s,n<<=1,n&256&&(n^=285);for(let s=255;s<512;s++)Nc[s]=Nc[s-255]})();Am.log=function(n){if(n<1)throw new Error("log("+n+")");return ff[n]};Am.exp=function(n){return Nc[n]};Am.mul=function(n,s){return n===0||s===0?0:Nc[ff[n]+ff[s]]};(function(e){const n=Am;e.mul=function(r,a){const i=new Uint8Array(r.length+a.length-1);for(let l=0;l<r.length;l++)for(let o=0;o<a.length;o++)i[l+o]^=n.mul(r[l],a[o]);return i},e.mod=function(r,a){let i=new Uint8Array(r);for(;i.length-a.length>=0;){const l=i[0];for(let c=0;c<a.length;c++)i[c]^=n.mul(a[c],l);let o=0;for(;o<i.length&&i[o]===0;)o++;i=i.slice(o)}return i},e.generateECPolynomial=function(r){let a=new Uint8Array([1]);for(let i=0;i<r;i++)a=e.mul(a,new Uint8Array([1,n.exp(i)]));return a}})(pM);const gM=pM;function ab(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}ab.prototype.initialize=function(n){this.degree=n,this.genPoly=gM.generateECPolynomial(this.degree)};ab.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const s=new Uint8Array(n.length+this.degree);s.set(n);const r=gM.mod(s,this.genPoly),a=this.degree-r.length;if(a>0){const i=new Uint8Array(this.degree);return i.set(r,a),i}return r};var kee=ab,xM={},mi={},ib={};ib.isValid=function(n){return!isNaN(n)&&n>=1&&n<=40};var Yr={};const vM="[0-9]+",Nee="[A-Z $%*+\\-./:]+";let hu="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";hu=hu.replace(/u/g,"\\u");const See="(?:(?![A-Z0-9 $%*+\\-./:]|"+hu+`)(?:.|[\r
|
|
139
|
-
]))+`;Yr.KANJI=new RegExp(hu,"g");Yr.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");Yr.BYTE=new RegExp(See,"g");Yr.NUMERIC=new RegExp(vM,"g");Yr.ALPHANUMERIC=new RegExp(Nee,"g");const Cee=new RegExp("^"+hu+"$"),Eee=new RegExp("^"+vM+"$"),$ee=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");Yr.testKanji=function(n){return Cee.test(n)};Yr.testNumeric=function(n){return Eee.test(n)};Yr.testAlphanumeric=function(n){return $ee.test(n)};(function(e){const n=ib,s=Yr;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(i,l){if(!i.ccBits)throw new Error("Invalid mode: "+i);if(!n.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?i.ccBits[0]:l<27?i.ccBits[1]:i.ccBits[2]},e.getBestModeForData=function(i){return s.testNumeric(i)?e.NUMERIC:s.testAlphanumeric(i)?e.ALPHANUMERIC:s.testKanji(i)?e.KANJI:e.BYTE},e.toString=function(i){if(i&&i.id)return i.id;throw new Error("Invalid mode")},e.isValid=function(i){return i&&i.bit&&i.ccBits};function r(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.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: "+a)}}e.from=function(i,l){if(e.isValid(i))return i;try{return r(i)}catch{return l}}})(mi);(function(e){const n=Os,s=$m,r=Em,a=mi,i=ib,l=7973,o=n.getBCHDigit(l);function c(m,p,g){for(let x=1;x<=40;x++)if(p<=e.getCapacity(x,g,m))return x}function u(m,p){return a.getCharCountIndicator(m,p)+4}function h(m,p){let g=0;return m.forEach(function(x){const k=u(x.mode,p);g+=k+x.getBitsLength()}),g}function f(m,p){for(let g=1;g<=40;g++)if(h(m,g)<=e.getCapacity(g,p,a.MIXED))return g}e.from=function(p,g){return i.isValid(p)?parseInt(p,10):g},e.getCapacity=function(p,g,x){if(!i.isValid(p))throw new Error("Invalid QR Code version");typeof x>"u"&&(x=a.BYTE);const k=n.getSymbolTotalCodewords(p),j=s.getTotalCodewordsCount(p,g),v=(k-j)*8;if(x===a.MIXED)return v;const w=v-u(x,p);switch(x){case a.NUMERIC:return Math.floor(w/10*3);case a.ALPHANUMERIC:return Math.floor(w/11*2);case a.KANJI:return Math.floor(w/13);case a.BYTE:default:return Math.floor(w/8)}},e.getBestVersionForData=function(p,g){let x;const k=r.from(g,r.M);if(Array.isArray(p)){if(p.length>1)return f(p,k);if(p.length===0)return 1;x=p[0]}else x=p;return c(x.mode,x.getLength(),k)},e.getEncodedBits=function(p){if(!i.isValid(p)||p<7)throw new Error("Invalid QR Code version");let g=p<<12;for(;n.getBCHDigit(g)-o>=0;)g^=l<<n.getBCHDigit(g)-o;return p<<12|g}})(xM);var jM={};const Jv=Os,wM=1335,Aee=21522,JS=Jv.getBCHDigit(wM);jM.getEncodedBits=function(n,s){const r=n.bit<<3|s;let a=r<<10;for(;Jv.getBCHDigit(a)-JS>=0;)a^=wM<<Jv.getBCHDigit(a)-JS;return(r<<10|a)^Aee};var yM={};const Tee=mi;function oo(e){this.mode=Tee.NUMERIC,this.data=e.toString()}oo.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)};oo.prototype.getLength=function(){return this.data.length};oo.prototype.getBitsLength=function(){return oo.getBitsLength(this.data.length)};oo.prototype.write=function(n){let s,r,a;for(s=0;s+3<=this.data.length;s+=3)r=this.data.substr(s,3),a=parseInt(r,10),n.put(a,10);const i=this.data.length-s;i>0&&(r=this.data.substr(s),a=parseInt(r,10),n.put(a,i*3+1))};var Ree=oo;const Iee=mi,cg=["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 co(e){this.mode=Iee.ALPHANUMERIC,this.data=e}co.getBitsLength=function(n){return 11*Math.floor(n/2)+6*(n%2)};co.prototype.getLength=function(){return this.data.length};co.prototype.getBitsLength=function(){return co.getBitsLength(this.data.length)};co.prototype.write=function(n){let s;for(s=0;s+2<=this.data.length;s+=2){let r=cg.indexOf(this.data[s])*45;r+=cg.indexOf(this.data[s+1]),n.put(r,11)}this.data.length%2&&n.put(cg.indexOf(this.data[s]),6)};var Pee=co;const Mee=mi;function uo(e){this.mode=Mee.BYTE,typeof e=="string"?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}uo.getBitsLength=function(n){return n*8};uo.prototype.getLength=function(){return this.data.length};uo.prototype.getBitsLength=function(){return uo.getBitsLength(this.data.length)};uo.prototype.write=function(e){for(let n=0,s=this.data.length;n<s;n++)e.put(this.data[n],8)};var Oee=uo;const Dee=mi,Lee=Os;function ho(e){this.mode=Dee.KANJI,this.data=e}ho.getBitsLength=function(n){return n*13};ho.prototype.getLength=function(){return this.data.length};ho.prototype.getBitsLength=function(){return ho.getBitsLength(this.data.length)};ho.prototype.write=function(e){let n;for(n=0;n<this.data.length;n++){let s=Lee.toSJIS(this.data[n]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[n]+`
|
|
140
|
-
Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),e.put(s,13)}};var Fee=ho,bM={exports:{}};(function(e){var n={single_source_shortest_paths:function(s,r,a){var i={},l={};l[r]=0;var o=n.PriorityQueue.make();o.push(r,0);for(var c,u,h,f,m,p,g,x,k;!o.empty();){c=o.pop(),u=c.value,f=c.cost,m=s[u]||{};for(h in m)m.hasOwnProperty(h)&&(p=m[h],g=f+p,x=l[h],k=typeof l[h]>"u",(k||x>g)&&(l[h]=g,o.push(h,g),i[h]=u))}if(typeof a<"u"&&typeof l[a]>"u"){var j=["Could not find a path from ",r," to ",a,"."].join("");throw new Error(j)}return i},extract_shortest_path_from_predecessor_list:function(s,r){for(var a=[],i=r;i;)a.push(i),s[i],i=s[i];return a.reverse(),a},find_path:function(s,r,a){var i=n.single_source_shortest_paths(s,r,a);return n.extract_shortest_path_from_predecessor_list(i,a)},PriorityQueue:{make:function(s){var r=n.PriorityQueue,a={},i;s=s||{};for(i in r)r.hasOwnProperty(i)&&(a[i]=r[i]);return a.queue=[],a.sorter=s.sorter||r.default_sorter,a},default_sorter:function(s,r){return s.cost-r.cost},push:function(s,r){var a={value:s,cost:r};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};e.exports=n})(bM);var _ee=bM.exports;(function(e){const n=mi,s=Ree,r=Pee,a=Oee,i=Fee,l=Yr,o=Os,c=_ee;function u(j){return unescape(encodeURIComponent(j)).length}function h(j,v,w){const y=[];let N;for(;(N=j.exec(w))!==null;)y.push({data:N[0],index:N.index,mode:v,length:N[0].length});return y}function f(j){const v=h(l.NUMERIC,n.NUMERIC,j),w=h(l.ALPHANUMERIC,n.ALPHANUMERIC,j);let y,N;return o.isKanjiModeEnabled()?(y=h(l.BYTE,n.BYTE,j),N=h(l.KANJI,n.KANJI,j)):(y=h(l.BYTE_KANJI,n.BYTE,j),N=[]),v.concat(w,y,N).sort(function(S,C){return S.index-C.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function m(j,v){switch(v){case n.NUMERIC:return s.getBitsLength(j);case n.ALPHANUMERIC:return r.getBitsLength(j);case n.KANJI:return i.getBitsLength(j);case n.BYTE:return a.getBitsLength(j)}}function p(j){return j.reduce(function(v,w){const y=v.length-1>=0?v[v.length-1]:null;return y&&y.mode===w.mode?(v[v.length-1].data+=w.data,v):(v.push(w),v)},[])}function g(j){const v=[];for(let w=0;w<j.length;w++){const y=j[w];switch(y.mode){case n.NUMERIC:v.push([y,{data:y.data,mode:n.ALPHANUMERIC,length:y.length},{data:y.data,mode:n.BYTE,length:y.length}]);break;case n.ALPHANUMERIC:v.push([y,{data:y.data,mode:n.BYTE,length:y.length}]);break;case n.KANJI:v.push([y,{data:y.data,mode:n.BYTE,length:u(y.data)}]);break;case n.BYTE:v.push([{data:y.data,mode:n.BYTE,length:u(y.data)}])}}return v}function x(j,v){const w={},y={start:{}};let N=["start"];for(let b=0;b<j.length;b++){const S=j[b],C=[];for(let T=0;T<S.length;T++){const E=S[T],R=""+b+T;C.push(R),w[R]={node:E,lastCount:0},y[R]={};for(let M=0;M<N.length;M++){const O=N[M];w[O]&&w[O].node.mode===E.mode?(y[O][R]=m(w[O].lastCount+E.length,E.mode)-m(w[O].lastCount,E.mode),w[O].lastCount+=E.length):(w[O]&&(w[O].lastCount=E.length),y[O][R]=m(E.length,E.mode)+4+n.getCharCountIndicator(E.mode,v))}}N=C}for(let b=0;b<N.length;b++)y[N[b]].end=0;return{map:y,table:w}}function k(j,v){let w;const y=n.getBestModeForData(j);if(w=n.from(v,y),w!==n.BYTE&&w.bit<y.bit)throw new Error('"'+j+'" cannot be encoded with mode '+n.toString(w)+`.
|
|
141
|
-
Suggested mode is: `+n.toString(y));switch(w===n.KANJI&&!o.isKanjiModeEnabled()&&(w=n.BYTE),w){case n.NUMERIC:return new s(j);case n.ALPHANUMERIC:return new r(j);case n.KANJI:return new i(j);case n.BYTE:return new a(j)}}e.fromArray=function(v){return v.reduce(function(w,y){return typeof y=="string"?w.push(k(y,null)):y.data&&w.push(k(y.data,y.mode)),w},[])},e.fromString=function(v,w){const y=f(v,o.isKanjiModeEnabled()),N=g(y),b=x(N,w),S=c.find_path(b.map,"start","end"),C=[];for(let T=1;T<S.length-1;T++)C.push(b.table[S[T]].node);return e.fromArray(p(C))},e.rawSplit=function(v){return e.fromArray(f(v,o.isKanjiModeEnabled()))}})(yM);const Tm=Os,ug=Em,zee=wee,Uee=yee,Bee=hM,Wee=fM,Xv=mM,Zv=$m,Hee=kee,mf=xM,Kee=jM,Vee=mi,dg=yM;function Gee(e,n){const s=e.size,r=Wee.getPositions(n);for(let a=0;a<r.length;a++){const i=r[a][0],l=r[a][1];for(let o=-1;o<=7;o++)if(!(i+o<=-1||s<=i+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(i+o,l+c,!0,!0):e.set(i+o,l+c,!1,!0))}}function Yee(e){const n=e.size;for(let s=8;s<n-8;s++){const r=s%2===0;e.set(s,6,r,!0),e.set(6,s,r,!0)}}function qee(e,n){const s=Bee.getPositions(n);for(let r=0;r<s.length;r++){const a=s[r][0],i=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(a+l,i+o,!0,!0):e.set(a+l,i+o,!1,!0)}}function Qee(e,n){const s=e.size,r=mf.getEncodedBits(n);let a,i,l;for(let o=0;o<18;o++)a=Math.floor(o/3),i=o%3+s-8-3,l=(r>>o&1)===1,e.set(a,i,l,!0),e.set(i,a,l,!0)}function hg(e,n,s){const r=e.size,a=Kee.getEncodedBits(n,s);let i,l;for(i=0;i<15;i++)l=(a>>i&1)===1,i<6?e.set(i,8,l,!0):i<8?e.set(i+1,8,l,!0):e.set(r-15+i,8,l,!0),i<8?e.set(8,r-i-1,l,!0):i<9?e.set(8,15-i-1+1,l,!0):e.set(8,15-i-1,l,!0);e.set(r-8,8,1,!0)}function Jee(e,n){const s=e.size;let r=-1,a=s-1,i=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(a,o-c)){let u=!1;l<n.length&&(u=(n[l]>>>i&1)===1),e.set(a,o-c,u),i--,i===-1&&(l++,i=7)}if(a+=r,a<0||s<=a){a-=r,r=-r;break}}}function Xee(e,n,s){const r=new zee;s.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),Vee.getCharCountIndicator(c.mode,e)),c.write(r)});const a=Tm.getSymbolTotalCodewords(e),i=Zv.getTotalCodewordsCount(e,n),l=(a-i)*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 Zee(r,e,n)}function Zee(e,n,s){const r=Tm.getSymbolTotalCodewords(n),a=Zv.getTotalCodewordsCount(n,s),i=r-a,l=Zv.getBlocksCount(n,s),o=r%l,c=l-o,u=Math.floor(r/l),h=Math.floor(i/l),f=h+1,m=u-h,p=new Hee(m);let g=0;const x=new Array(l),k=new Array(l);let j=0;const v=new Uint8Array(e.buffer);for(let S=0;S<l;S++){const C=S<c?h:f;x[S]=v.slice(g,g+C),k[S]=p.encode(x[S]),g+=C,j=Math.max(j,C)}const w=new Uint8Array(r);let y=0,N,b;for(N=0;N<j;N++)for(b=0;b<l;b++)N<x[b].length&&(w[y++]=x[b][N]);for(N=0;N<m;N++)for(b=0;b<l;b++)w[y++]=k[b][N];return w}function ete(e,n,s,r){let a;if(Array.isArray(e))a=dg.fromArray(e);else if(typeof e=="string"){let u=n;if(!u){const h=dg.rawSplit(e);u=mf.getBestVersionForData(h,s)}a=dg.fromString(e,u||40)}else throw new Error("Invalid data");const i=mf.getBestVersionForData(a,s);if(!i)throw new Error("The amount of data is too big to be stored in a QR Code");if(!n)n=i;else if(n<i)throw new Error(`
|
|
142
|
-
The chosen QR Code version cannot contain this amount of data.
|
|
143
|
-
Minimum version required to store current data is: `+i+`.
|
|
144
|
-
`);const l=Xee(n,s,a),o=Tm.getSymbolSize(n),c=new Uee(o);return Gee(c,n),Yee(c),qee(c,n),hg(c,s,0),n>=7&&Qee(c,n),Jee(c,l),isNaN(r)&&(r=Xv.getBestMask(c,hg.bind(null,c,s))),Xv.applyMask(r,c),hg(c,s,r),{modules:c,version:n,errorCorrectionLevel:s,maskPattern:r,segments:a}}uM.create=function(n,s){if(typeof n>"u"||n==="")throw new Error("No input text");let r=ug.M,a,i;return typeof s<"u"&&(r=ug.from(s.errorCorrectionLevel,ug.M),a=mf.from(s.version),i=Xv.from(s.maskPattern),s.toSJISFunc&&Tm.setToSJISFunction(s.toSJISFunc)),ete(n,a,r,i)};var kM={},lb={};(function(e){function n(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(i){return[i,i]}))),r.length===6&&r.push("F","F");const a=parseInt(r.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+r.slice(0,6).join("")}}e.getOptions=function(r){r||(r={}),r.color||(r.color={});const a=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,i=r.width&&r.width>=21?r.width:void 0,l=r.scale||4;return{width:i,scale:i?4:l,margin:a,color:{dark:n(r.color.dark||"#000000ff"),light:n(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},e.getScale=function(r,a){return a.width&&a.width>=r+a.margin*2?a.width/(r+a.margin*2):a.scale},e.getImageWidth=function(r,a){const i=e.getScale(r,a);return Math.floor((r+a.margin*2)*i)},e.qrToImageData=function(r,a,i){const l=a.modules.size,o=a.modules.data,c=e.getScale(l,i),u=Math.floor((l+i.margin*2)*c),h=i.margin*c,f=[i.color.light,i.color.dark];for(let m=0;m<u;m++)for(let p=0;p<u;p++){let g=(m*u+p)*4,x=i.color.light;if(m>=h&&p>=h&&m<u-h&&p<u-h){const k=Math.floor((m-h)/c),j=Math.floor((p-h)/c);x=f[o[k*l+j]?1:0]}r[g++]=x.r,r[g++]=x.g,r[g++]=x.b,r[g]=x.a}}})(lb);(function(e){const n=lb;function s(a,i,l){a.clearRect(0,0,i.width,i.height),i.style||(i.style={}),i.height=l,i.width=l,i.style.height=l+"px",i.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(i,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=r()),c=n.getOptions(c);const h=n.getImageWidth(i.modules.size,c),f=u.getContext("2d"),m=f.createImageData(h,h);return n.qrToImageData(m.data,i,c),s(f,u,h),f.putImageData(m,0,0),u},e.renderToDataURL=function(i,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=e.render(i,l,c),h=c.type||"image/png",f=c.rendererOpts||{};return u.toDataURL(h,f.quality)}})(kM);var NM={};const tte=lb;function XS(e,n){const s=e.a/255,r=n+'="'+e.hex+'"';return s<1?r+" "+n+'-opacity="'+s.toFixed(2).slice(1)+'"':r}function fg(e,n,s){let r=e+n;return typeof s<"u"&&(r+=" "+s),r}function nte(e,n,s){let r="",a=0,i=!1,l=0;for(let o=0;o<e.length;o++){const c=Math.floor(o%n),u=Math.floor(o/n);!c&&!i&&(i=!0),e[o]?(l++,o>0&&c>0&&e[o-1]||(r+=i?fg("M",c+s,.5+u+s):fg("m",a,0),a=0,i=!1),c+1<n&&e[o+1]||(r+=fg("h",l),l=0)):a++}return r}NM.render=function(n,s,r){const a=tte.getOptions(s),i=n.modules.size,l=n.modules.data,o=i+a.margin*2,c=a.color.light.a?"<path "+XS(a.color.light,"fill")+' d="M0 0h'+o+"v"+o+'H0z"/>':"",u="<path "+XS(a.color.dark,"stroke")+' d="'+nte(l,i,a.margin)+'"/>',h='viewBox="0 0 '+o+" "+o+'"',m='<svg xmlns="http://www.w3.org/2000/svg" '+(a.width?'width="'+a.width+'" height="'+a.width+'" ':"")+h+' shape-rendering="crispEdges">'+c+u+`</svg>
|
|
145
|
-
`;return typeof r=="function"&&r(null,m),m};const ste=vee,ej=uM,SM=kM,rte=NM;function ob(e,n,s,r,a){const i=[].slice.call(arguments,1),l=i.length,o=typeof i[l-1]=="function";if(!o&&!ste())throw new Error("Callback required as last argument");if(o){if(l<2)throw new Error("Too few arguments provided");l===2?(a=s,s=n,n=r=void 0):l===3&&(n.getContext&&typeof a>"u"?(a=r,r=void 0):(a=r,r=s,s=n,n=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(s=n,n=r=void 0):l===2&&!n.getContext&&(r=s,s=n,n=void 0),new Promise(function(c,u){try{const h=ej.create(s,r);c(e(h,n,r))}catch(h){u(h)}})}try{const c=ej.create(s,r);a(null,e(c,n,r))}catch(c){a(c)}}Pu.create=ej.create;Pu.toCanvas=ob.bind(null,SM.render);Pu.toDataURL=ob.bind(null,SM.renderToDataURL);Pu.toString=ob.bind(null,function(e,n,s){return rte.render(e,s)});async function ate(e){const n=await Pu.toString(e,{type:"svg",margin:4,errorCorrectionLevel:"M"});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`}const ZS=10*6e4,ite=2e3;function CM(e,n){const[s,r]=d.useState(null),[a,i]=d.useState(null),[l,o]=d.useState(!1),[c,u]=d.useState(!1),h=d.useRef(e);h.current=e;const f=d.useRef(n);f.current=n;const m=d.useCallback(async()=>{const p=await A.telegramPairing();r(p),u(!1),o(!1),i(await ate(p.link).catch(()=>""))},[]);return d.useEffect(()=>{if(!s||l||c)return;let p=!1;const g=Math.min(Date.parse(s.expiresAt)||Date.now()+ZS,Date.now()+ZS),x=window.setInterval(()=>{if(Date.now()>=g){u(!0);return}h.current().then(k=>{var j;p||!k||(o(!0),(j=f.current)==null||j.call(f))}).catch(()=>{})},ite);return()=>{p=!0,window.clearInterval(x)}},[s,l,c]),{offer:s,square:a,paired:l,stale:c,ask:m}}function lte({offer:e,square:n,children:s}){return t.jsxs("div",{className:"meet-pair",children:[n?t.jsx("img",{className:"meet-qr",src:n,alt:e.link}):null,t.jsx("a",{className:"meet-link",href:e.link,target:"_blank",rel:"noreferrer",children:e.link}),s]})}function ote({offer:e,square:n,bot:s,status:r,paired:a}){const[i,l]=d.useState(!1),o=()=>{Promise.resolve().then(()=>{var c;return(c=navigator.clipboard)==null?void 0:c.writeText(e.link)}).then(()=>l(!0)).catch(()=>{})};return t.jsxs("div",{className:"tg-pair","data-testid":"pairing-tile",children:[t.jsx("div",{className:"tg-pair-tile",children:n?t.jsx("img",{className:"tg-pair-qr",src:n,alt:s?`QR code for @${s}`:"QR code for your buddi bot"}):null}),s?t.jsxs("span",{className:"tg-pair-bot",children:["@",s]}):null,t.jsxs("div",{className:"tg-pair-actions",children:[t.jsx($,{onClick:o,children:i?"Copied":"Copy link"}),t.jsx(lt,{variant:"accent",href:e.link,target:"_blank",rel:"noreferrer",children:"Open in Telegram"})]}),t.jsxs("p",{className:"tg-pair-status",role:"status","data-paired":a?"true":void 0,children:[a?null:t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),r]})]})}const EM=new Set(["approval","question"]),nh={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."}},cte=new Set(["agent"]),ute={maxUrgency:"now",muted:[]};function dte(e,n){var a;const s=nh[e.kind].label.toLowerCase();return e.kind!=="agent"||!e.agentId?s:`from ${((a=n.find(i=>i.id===e.agentId))==null?void 0:a.name)??e.agentId}`}function hte({timezone:e}){var j,v,w;const n=ge(()=>A.notificationSettings(),[]),s=ge(()=>A.agents(),[]),r=ge(()=>A.notifications(20),[],3e4),a=d.useRef(!1);d.useEffect(()=>{var y,N;a.current||!r.data||window.location.hash!==Bx||(a.current=!0,(N=(y=document.getElementById("notifications-recent"))==null?void 0:y.scrollIntoView)==null||N.call(y,{block:"start"}))},[r.data]);const[i,l]=d.useState(null),[o,c]=d.useState(!1),[u,h]=d.useState(!1),[f,m]=d.useState(null),p=((j=n.data)==null?void 0:j.channels)??[],g=i??((v=n.data)==null?void 0:v.settings),x=y=>{g&&(h(!1),l({...g,...y}))},k=()=>{g&&(c(!0),h(!1),m(null),A.saveNotificationSettings(g).then(()=>{h(!0),l(null),n.reload()}).catch(y=>m(y instanceof he?y.message:String(y))).finally(()=>c(!1)))};return t.jsxs(ue,{gap:"lg",children:[t.jsx(pe,{title:"Notifications",aside:"What buddi tells you when you are not looking at this page.",panel:!0,foot:t.jsx($,{variant:"accent",disabled:o||!g,onClick:k,children:"Save"}),children:t.jsxs(ue,{divided:!0,children:[t.jsx(ae,{message:n.error??f}),t.jsx(pe,{title:"Where buddi reaches you",children:g?p.length===0?t.jsxs("p",{className:"ui-card-meta",children:["No channel yet, so everything waits for you here. ",t.jsx("a",{href:Fe("telegram"),children:"Set up Telegram"})," and buddi can reach you on your phone."]}):t.jsxs(ue,{gap:"sm",children:[p.map(y=>{var N;return t.jsx(jte,{channel:y,checked:(g.defaultChannel??((N=p[0])==null?void 0:N.kind))===y.kind,onPick:()=>x({defaultChannel:y.kind})},y.kind)}),p.some(y=>y.kind==="telegram")?null:t.jsxs("p",{className:"ui-card-meta",children:["Telegram is not set up. ",t.jsx("a",{href:Fe("telegram"),children:"Set up Telegram"})]})]}):t.jsx(Ne,{children:"Loading…"})}),t.jsx(pe,{title:"By kind",children:g?t.jsxs(ue,{gap:"sm",children:[B_.filter(y=>!cte.has(y)).map(y=>t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:nh[y].label}),t.jsx("span",{className:"ui-field-hint",children:nh[y].hint})]}),t.jsxs("select",{"aria-label":nh[y].label,value:wte(g,y,p),onChange:N=>{const b={...g.perKind};N.target.value==="default"?delete b[y]:b[y]=N.target.value,x({perKind:b})},children:[t.jsx("option",{value:"default",children:"Default"}),p.map(N=>t.jsx("option",{value:N.kind,children:N.label},N.kind)),EM.has(y)?null:t.jsx("option",{value:"off",children:"Off"})]})]},y)),t.jsx("p",{className:"ui-field-hint",children:"Off keeps it in the list below and never sends it."})]}):null}),t.jsx(pe,{title:"Messages from your agents",children:g?t.jsx(fte,{settings:g,agents:((w=s.data)==null?void 0:w.agents)??[],onChange:x}):null}),t.jsx(pe,{title:"Focus schedules",children:g?t.jsxs(ue,{gap:"sm",children:[t.jsx(kte,{schedules:g.schedules,onChange:y=>x({schedules:y})}),t.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,")."]}),t.jsx("div",{className:"nt-times",children:t.jsx(ie,{label:"End of the day",children:t.jsx("input",{type:"time",value:g.endOfDay,onChange:y=>x({endOfDay:y.target.value})})})}),t.jsx("p",{className:"ui-field-hint",children:"At the end of the day, what could wait goes out as one message."})]}):null}),u?t.jsx(G,{tone:"good",role:"status",children:"Saved."}):null]})}),t.jsx(mte,{}),t.jsx("div",{id:"notifications-recent",className:"notifications-recent",children:t.jsxs(pe,{title:"The last twenty",panel:!0,flush:!0,children:[t.jsx(ae,{message:r.error}),r.data?r.data.notifications.length===0?t.jsx(Ne,{children:"Nothing yet. What buddi tells you will be listed here."}):t.jsx(ct,{children:r.data.notifications.map(y=>{var N;return t.jsx(rt,{title:Qc(y),sub:`${mt(y.createdAt,e)} · ${dte(y,((N=s.data)==null?void 0:N.agents)??[])} · ${yte(y,p)}`,side:t.jsx(bte,{row:y})},y.id)})}):t.jsx(Ne,{children:"Loading…"})]})})]})}function fte({settings:e,agents:n,onChange:s}){const r=e.perKind.agent!=="off",a=e.agents??ute,i=o=>{const c={...e.perKind};o?delete c.agent:c.agent="off",s({perKind:c})},l=(o,c)=>s({agents:{...a,muted:c?[...new Set([...a.muted,o])]:a.muted.filter(u=>u!==o)}});return t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:r,onChange:o=>i(o.target.checked)}),t.jsx("span",{children:"Agents may message you"})]}),t.jsxs("div",{className:"pref-row nt-kind",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Highest urgency"}),t.jsx("span",{className:"ui-field-hint",children:"End of the day holds every message for the end-of-day message."})]}),t.jsxs("select",{"aria-label":"Highest urgency for agents",value:a.maxUrgency,disabled:!r,onChange:o=>s({agents:{...a,maxUrgency:o.target.value==="today"?"today":"now"}}),children:[t.jsx("option",{value:"now",children:"Now"}),t.jsx("option",{value:"today",children:"End of the day"})]})]}),n.length>0?t.jsx("div",{className:"ui-stack","data-gap":"sm",role:"group","aria-label":"Muted agents",children:n.map(o=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a.muted.includes(o.id),disabled:!r,onChange:c=>l(o.id,c.target.checked),"aria-label":`Mute @${o.handle}`}),t.jsxs("span",{children:["Mute ",o.name," (@",o.handle,")"]})]},o.id))}):null,t.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 mte(){var u;const e=ge(()=>A.tipsSettings(),[]),[n,s]=d.useState(!1),[r,a]=d.useState(null),[i,l]=d.useState(null),o=i??((u=e.data)==null?void 0:u.enabled)??!0,c=h=>{s(!0),a(null),l(h),A.saveTipsSettings(h).then(f=>l(f.enabled)).catch(f=>{l(!h),a(f instanceof he?f.message:String(f))}).finally(()=>s(!1))};return t.jsx(pe,{title:"Tips",panel:!0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:e.error??r}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:o,disabled:n||!e.data,onChange:h=>c(h.target.checked)}),t.jsx("span",{children:"Tips on Home"})]}),t.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 pte({timezone:e}){return t.jsx(gte,{timezone:e,onChange:()=>{}})}function gte({timezone:e,onChange:n}){var C,T;const s=ge(()=>A.telegramBot(),[]),r=ge(()=>A.telegramDevices(),[]),[a,i]=d.useState(!1),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState(null),[m,p]=d.useState(null),g=d.useRef(new Set),x=CM(()=>A.telegramDevices().then(E=>E.devices.some(R=>!g.current.has(R.id))),()=>{r.reload(),n()}),k=((C=s.data)==null?void 0:C.configured)??!1,j=!k||a,v=()=>{var R;if(l.trim()===""||c)return;u(!0),f(null);const E=a&&(((R=s.data)==null?void 0:R.running)??!1);A.saveTelegramToken(l.trim()).then(M=>{o(""),i(!1),f(M.restartNeeded?{ok:!1,text:M.note??"Saved. It will be ready the next time buddi starts."}:E?{ok:!0,text:"Saved. The new bot takes over the next time buddi starts."}:{ok:!0,text:"Saved."}),s.reload(),n()}).catch(M=>f({ok:!1,text:M instanceof he?M.message:String(M)})).finally(()=>u(!1))},w=()=>{var E;p(null),g.current=new Set((((E=r.data)==null?void 0:E.devices)??[]).map(R=>R.id)),x.ask().catch(R=>p(R instanceof he?R.message:String(R)))},{offer:y,square:N,paired:b,stale:S}=x;return t.jsx(pe,{title:"Telegram",aside:"Talk to buddi from your phone.",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{title:"The bot",foot:j?t.jsxs(t.Fragment,{children:[a?t.jsx($,{variant:"ghost",onClick:()=>{i(!1),o("")},children:"Cancel"}):null,t.jsx($,{variant:"accent",disabled:c||l.trim()==="",onClick:v,children:"Save token"})]}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error}),!s.data&&!s.error?t.jsx(Ne,{children:"Loading…"}):k&&!a?t.jsxs("div",{className:"nt-channel",children:[t.jsx("span",{className:"pref-label",children:(T=s.data)!=null&&T.username?`Bot: @${s.data.username}`:"A bot token is saved."}),t.jsx($,{variant:"ghost",size:"sm",onClick:()=>{i(!0),f(null)},children:"Replace token"})]}):null,j?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Ask @BotFather for a bot and paste its token here."}),t.jsx(ie,{label:"Bot token",grow:!0,children:t.jsx("input",{type:"password",value:l,autoComplete:"off",spellCheck:!1,onChange:E=>o(E.target.value),onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),v())}})})]}):null,h?t.jsx(G,{tone:h.ok?"good":"warning",role:"status",children:h.text}):null]})}),t.jsxs(pe,{title:"Your devices",children:[t.jsx(ae,{message:r.error}),r.data?r.data.devices.length===0?t.jsx("p",{className:"ui-card-meta",children:"No phone is paired yet."}):t.jsx(ct,{children:r.data.devices.map(E=>t.jsx(rt,{title:E.name??`Telegram user ${E.userId}`,sub:`Paired ${mt(E.pairedAt,e)} · ${E.lastSeenAt?`last spoke ${Ge(E.lastSeenAt)}`:"has not spoken yet"}`,side:t.jsx(xte,{id:E.id,onGone:()=>{r.reload(),n()}})},E.id))}):r.error?null:t.jsx(Ne,{children:"Loading…"})]}),t.jsx(pe,{title:"Pair a device",foot:k&&(!y||b)?t.jsx($,{variant:y?void 0:"accent",onClick:w,children:"Pair a phone"}):k&&S?t.jsx($,{variant:"accent",onClick:w,children:"New code"}):void 0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:m}),k?b?t.jsx(G,{tone:"good",role:"status",children:"Paired."}):y&&S?t.jsx("p",{className:"ui-card-meta",children:"That code has run out."}):y?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"ui-card-meta",children:"Open this on your phone, then send /start to the bot."}),t.jsx(lte,{offer:y,square:N,children:t.jsx(vte,{text:y.link})}),t.jsxs("p",{className:"ui-field-hint",children:["The code works until ",mt(y.expiresAt,e),"."]})]}):t.jsx("p",{className:"ui-card-meta",children:"Pair another phone, or the first one if you skipped it."}):t.jsx("p",{className:"ui-card-meta",children:"Save a bot token first."})]})})]})})}function xte({id:e,onGone:n}){const[s,r]=d.useState(!1),[a,i]=d.useState(!1),[l,o]=d.useState(null);if(!s)return t.jsx($,{size:"sm",onClick:()=>r(!0),children:"Unpair"});const c=()=>{i(!0),o(null),A.unpairTelegramDevice(e).then(n).catch(u=>o(u instanceof he?u.message:String(u))).finally(()=>i(!1))};return t.jsxs("span",{className:"nt-channel",children:[t.jsx("span",{className:"ui-field-hint",role:l?"alert":void 0,children:l??"It will no longer reach your agents."}),t.jsx($,{size:"sm",variant:"ghost",disabled:a,onClick:()=>r(!1),children:"Keep"}),t.jsx($,{size:"sm",variant:"danger",disabled:a,onClick:c,children:"Unpair"})]})}function vte({text:e}){const[n,s]=d.useState(null),r=()=>{var a;if(!((a=navigator.clipboard)!=null&&a.writeText)){s("Select the link to copy it.");return}navigator.clipboard.writeText(e).then(()=>s("Copied."),()=>s("Select the link to copy it."))};return t.jsxs("span",{className:"nt-channel",children:[t.jsx($,{size:"sm",onClick:r,children:"Copy"}),n?t.jsx("span",{className:"ui-field-hint",role:"status",children:n}):null]})}function jte({channel:e,checked:n,onPick:s}){const[r,a]=d.useState(!1),[i,l]=d.useState(null),o=()=>{a(!0),l(null),A.testChannel(e.kind).then(()=>l({ok:!0,text:"Sent. Check that it arrived."})).catch(c=>l({ok:!1,text:c instanceof he?c.message:String(c)})).finally(()=>a(!1))};return t.jsxs("div",{className:"nt-channel",children:[t.jsxs("label",{children:[t.jsx("input",{type:"radio",name:"nt-default-channel",checked:n,onChange:s}),t.jsxs("span",{className:"nt-channel-text",children:[t.jsxs("span",{className:"pref-label",children:[e.label,e.where?`, ${e.where}`:""]}),t.jsxs("span",{className:"ui-field-hint",children:["The title and a few lines of each message go to ",e.label,"."]}),i?t.jsx("span",{className:"nt-channel-sent","data-tone":i.ok?void 0:"critical",role:"status",children:i.text}):null]})]}),t.jsx($,{size:"sm",disabled:r,onClick:o,children:"Send a test"})]})}function wte(e,n,s){const r=e.perKind[n];return r==="off"?EM.has(n)?"default":"off":r&&s.some(a=>a.kind===r)?r:"default"}function yte(e,n){var s;return e.channel&&e.channel!=="dashboard"?((s=n.find(r=>r.kind===e.channel))==null?void 0:s.label)??e.channel:"dashboard"}function bte({row:e}){return e.state==="failed"?t.jsxs("span",{className:"nt-state","data-tone":"critical",children:["Failed: ",e.error??"no reason given"]}):e.actedAt?t.jsx("span",{className:"nt-state",children:"Acted on"}):e.seenAt?t.jsx("span",{className:"nt-state",children:"Seen"}):e.state==="held"?t.jsx("span",{className:"nt-state",children:"Waiting"}):e.state==="stored"?t.jsx("span",{className:"nt-state",children:"Kept"}):e.state==="sent"?t.jsx("span",{className:"nt-state",children:"Sent"}):t.jsx("span",{className:"nt-state",children:"Not seen"})}const eC={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},tC={mode:"do-not-disturb",days:[...Ax],from:"22:00",to:"07:00"};function kte({schedules:e,onChange:n}){const s=(r,a)=>n(e.map((i,l)=>l===r?{...i,...a}:i));return t.jsxs(ue,{gap:"sm",children:[e.length===0?t.jsx("p",{className:"ui-card-meta",children:"No schedule: a focus is on only when you switch one on."}):null,e.map((r,a)=>{const i=a+1;return t.jsxs("div",{className:"nt-schedule",role:"group","aria-label":`Schedule ${i}`,children:[t.jsxs("select",{"aria-label":`Schedule ${i} mode`,value:r.mode,onChange:l=>s(a,{mode:l.target.value}),children:[t.jsx("option",{value:"do-not-disturb",children:"Do not disturb"}),t.jsx("option",{value:"urgent-only",children:"Urgent only"})]}),t.jsx("span",{className:"nt-days",children:Ax.map(l=>{const o=r.days.includes(l);return t.jsx("button",{type:"button",className:"nt-day","aria-pressed":o,"aria-label":`Schedule ${i} ${eC[l]}`,onClick:()=>s(a,{days:o?r.days.filter(c=>c!==l):Ax.filter(c=>c===l||r.days.includes(c))}),children:eC[l]},l)})}),t.jsx(ie,{label:"From",children:t.jsx("input",{type:"time","aria-label":`Schedule ${i} from`,value:r.from,onChange:l=>s(a,{from:l.target.value})})}),t.jsx(ie,{label:"To",children:t.jsx("input",{type:"time","aria-label":`Schedule ${i} to`,value:r.to,onChange:l=>s(a,{to:l.target.value})})}),t.jsx($,{size:"sm",variant:"ghost","aria-label":`Remove schedule ${i}`,onClick:()=>n(e.filter((l,o)=>o!==a)),children:"Remove"})]},a)}),t.jsx("div",{className:"nt-schedule-add",children:t.jsx($,{size:"sm",onClick:()=>n([...e,{...tC,days:[...tC.days]}]),children:"Add a schedule"})})]})}function Nte(){const[e,n]=d.useState(null),[s,r]=d.useState(!1),[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),h=()=>{u(!0),o(null),A.uninstallPlan().then(f=>{if(!f.available){i(f.reason);return}n(f),r(!0)}).catch(f=>o(f instanceof he?f.message:String(f))).finally(()=>u(!1))};return t.jsxs(pe,{title:"Remove buddi",children:[t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:l}),a?t.jsx(G,{children:a}):t.jsx("p",{className:"ui-card-meta",children:"Takes a last backup and gives you its passphrase first; nothing is deleted before you have both."}),t.jsx(ne,{align:"end",children:t.jsx($,{variant:"danger",disabled:c||a!==null,onClick:h,children:"Remove buddi from this Mac…"})})]}),s&&e?t.jsx(Ete,{plan:e,onClose:()=>r(!1)}):null]})}function Ste(e,n){const s=[];return e.service&&s.push(`The background service (${e.service}).`),n||(s.push(`Your data: agents, chats, memory, files and the database, in ${e.data}.`),e.keychain&&s.push(`The passwords and keys buddi keeps in the keychain (${e.keychain}).`)),e.app&&s.push(`buddi.app, moved to the Trash (${e.app}).`),s}const Cte=1e3;function Ete({plan:e,onClose:n}){const[s,r]=d.useState("plan"),[a,i]=d.useState(!1),[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(null),[g,x]=d.useState(!1),k=d.useRef(null);d.useEffect(()=>()=>{k.current!==null&&window.clearTimeout(k.current)},[]);const j=b=>{A.uninstallJob(b).then(S=>{if(f(S.detail??S.phase),!S.finishedAt){k.current=window.setTimeout(()=>j(b),Cte);return}if(S.phase!=="done"||!S.report){u(`The last backup did not finish: ${S.error??"no reason given"}. Nothing was removed.`),r("plan");return}p(S.report),r("words")}).catch(S=>{u(S instanceof he?S.message:String(S)),r("plan")})},v=()=>{u(null),r("backup"),A.uninstallBackup(e.token).then(b=>j(b.job.id)).catch(b=>{u(b instanceof he?b.message:String(b)),r("plan")})},w=()=>{u(null),r("removing"),A.uninstall({token:e.token,wroteItDown:!0,keepData:a}).catch(b=>{b instanceof he&&b.status===0||(u(b instanceof he?b.message:String(b)),r("words"))})},y=Ste(e,a),N=s==="plan"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"accent",onClick:v,children:"Take the last backup"})]}):s==="words"?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:n,children:"Cancel"}),t.jsx($,{variant:"danger",disabled:!l&&(m==null?void 0:m.passphrase)!==void 0,onClick:w,children:"Remove buddi"})]}):null;return t.jsx(Ut,{title:"Remove buddi from this Mac",onClose:s==="removing"?()=>{}:n,foot:N,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:c}),s==="plan"||s==="backup"?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"This removes:"}),t.jsx("ul",{className:"remove-list",children:y.map(b=>t.jsx("li",{children:b},b))}),t.jsxs("p",{className:"ui-card-meta",children:["First, one last backup goes to ",t.jsx("span",{className:"mono",children:e.backups}),", where it stays."]}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:a,disabled:s!=="plan",onChange:b=>i(b.target.checked)}),t.jsx("span",{children:"Keep my data for a reinstall"})]}),s==="backup"?t.jsxs(G,{role:"status",children:["Taking the last backup",h?`: ${h}`:"","…"]}):null]}):null,s==="words"&&m?t.jsxs(t.Fragment,{children:[t.jsxs("p",{children:["The last backup is ",t.jsx("span",{className:"mono",children:m.archive}),"."]}),m.passphrase?t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"These six words open it. They leave this Mac's keychain with the rest, so write them down now:"}),t.jsx("p",{className:"backup-phrase mono","aria-label":"Your backup passphrase",children:m.passphrase}),m.passphraseFile?t.jsxs("p",{className:"ui-card-meta",children:["They are also in ",t.jsx("span",{className:"mono",children:m.passphraseFile}),", which only you can read. Delete it once they are written down."]}):null,t.jsx(ne,{align:"end",children:t.jsx($,{onClick:()=>{navigator.clipboard.writeText(m.passphrase).then(()=>x(!0),()=>x(!1))},children:g?"Copied":"Copy"})}),t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:l,onChange:b=>o(b.target.checked)}),t.jsx("span",{children:"I wrote it down"})]})]}):null,t.jsx("ul",{className:"remove-list",children:y.map(b=>t.jsx("li",{children:b},b))})]}):null,s==="removing"?t.jsx(G,{role:"status",children:e.appFinishes?"Removing buddi. The app quits when it is done.":`Removing buddi. This page stops answering in a moment; what was removed is written to a log in ${e.backups}.`}):null]})})}function $te(){const e=ge(()=>A.cliTool(),[]),[n,s]=d.useState(!1),[r,a]=d.useState(null),[i,l]=d.useState(null),o=e.data;if(!(o!=null&&o.available))return null;const c=()=>{s(!0),a(null),l(null),A.installCliTool().then(h=>{l(h.lines),e.reload()}).catch(h=>a(h instanceof he?h.message:String(h))).finally(()=>s(!1))},u=o.installed[0];return t.jsx(pe,{title:"Command line",panel:!0,children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:r}),t.jsx("p",{className:"ui-card-meta",children:u?t.jsxs(t.Fragment,{children:["Terminal's ",t.jsx("span",{className:"mono",children:"buddi"})," is ",t.jsx("span",{className:"mono",children:u}),", and runs this app's buddi."]}):t.jsxs(t.Fragment,{children:["Use ",t.jsx("span",{className:"mono",children:"buddi"})," in Terminal: it runs this app's buddi and keeps working after updates. macOS asks for your password once."]})}),i?t.jsx(G,{tone:"good",role:"status",children:i.join(" ")}):null,t.jsx(ne,{align:"end",children:t.jsx($,{disabled:n,onClick:c,children:u?"Install Again":"Install Command Line Tool"})})]})})}const Ate={you:"person",appearance:"sun",notifications:"bell",telegram:"send",memory:"notebook",proposals:"bulb",accounts:"key",computer:"monitor",secrets:"key",connections:"globe",lock:"lock",api:"terminal",watchers:"eye",backup:"archive",system:"chip",plugins:"plug"};function Tte(e){const n=fU.map(r=>({id:r.id,route:Fe(r.id),label:r.label,icon:Ate[r.id],group:r.group})),s=[...e].sort((r,a)=>r.title.localeCompare(a.title,void 0,{sensitivity:"base"})||r.plugin.localeCompare(a.plugin)||r.id.localeCompare(a.id)).map(r=>({id:LA(r.plugin,r.id),route:mr(r.plugin,r.id),label:r.title,icon:dI(r.icon),group:"plugins"}));return[...n,...s]}function $M(e){return hU.map(n=>({id:n.id,label:n.label,entries:e.filter(s=>s.group===n.id)})).filter(n=>n.entries.length>0)}function AM(e,n,s){return n?`${e}, ${n} open`:s?`${e}, ${s}`:void 0}function Rte({entries:e,active:n,counts:s={},dots:r={},navigate:a}){var u;const i=d.useRef(null),l=$M(e),o=e.some(h=>h.id===n)?n:(u=e[0])==null?void 0:u.id,c=h=>{var g;const f=[...((g=i.current)==null?void 0:g.querySelectorAll("a.settings-nav-link"))??[]],m=f.indexOf(document.activeElement);if(m===-1)return;const p=x=>{var k;h.preventDefault(),(k=f[Math.max(0,Math.min(f.length-1,x))])==null||k.focus()};if(h.key==="ArrowDown")p(m+1);else if(h.key==="ArrowUp")p(m-1);else if(h.key==="Home")p(0);else if(h.key==="End")p(f.length-1);else if(h.key==="Enter"||h.key===" "){h.preventDefault();const x=f[m].getAttribute("href");x&&a(x)}};return t.jsx("nav",{className:"settings-nav","aria-label":"Settings sections",ref:i,onKeyDown:c,children:l.map(h=>t.jsxs("div",{className:"settings-nav-group",role:"group","aria-labelledby":`settings-nav-${h.id}`,children:[t.jsx("div",{className:"settings-nav-label",id:`settings-nav-${h.id}`,children:h.label}),h.entries.map(f=>{const m=f.id===n,p=s[f.id],g=r[f.id];return t.jsxs("a",{className:"settings-nav-link",href:f.route,"data-active":m?"true":void 0,"aria-current":m?"page":void 0,"aria-label":AM(f.label,p,g),tabIndex:f.id===o?0:-1,onClick:x=>{x.preventDefault(),a(f.route)},children:[t.jsx(oe,{name:f.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:f.label}),p?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:p>99?"99+":p}):g?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","data-testid":"settings-nav-dot","aria-hidden":"true"}):null]},f.id)})]},h.id))})}function Ite({entries:e,active:n,counts:s={},dots:r={},navigate:a}){const i=$M(e),l=e.find(o=>o.id===n)??e[0];return t.jsx("nav",{className:"settings-menu","aria-label":"Settings sections",children:t.jsxs(Su,{modal:!1,children:[t.jsx(Cu,{asChild:!0,children:t.jsxs("button",{type:"button",className:"settings-menu-trigger","aria-label":`Settings section: ${(l==null?void 0:l.label)??""}`,children:[l?t.jsx(oe,{name:l.icon,className:"settings-nav-icon"}):null,t.jsx("span",{className:"settings-nav-text",children:l==null?void 0:l.label}),t.jsx(oe,{name:"chevron-down",className:"settings-menu-chevron"})]})}),t.jsx(ko,{children:t.jsx(Eu,{className:"ui-menu settings-menu-list",align:"start",sideOffset:6,children:t.jsx(x3,{value:n,onValueChange:o=>{const c=e.find(u=>u.id===o);c&&a(c.route)},children:i.map((o,c)=>t.jsxs(IA,{children:[c>0?t.jsx(la,{className:"ui-menu-sep"}):null,t.jsx(Wi,{className:"ui-menu-label",children:o.label}),o.entries.map(u=>{const h=s[u.id],f=r[u.id];return t.jsxs(v3,{value:u.id,className:"ui-menu-item settings-menu-item","data-active":u.id===n?"true":void 0,"aria-label":AM(u.label,h,f),children:[t.jsxs("span",{className:"settings-menu-entry",children:[t.jsx(oe,{name:u.icon,className:"settings-nav-icon"}),t.jsx("span",{className:"settings-nav-text",children:u.label})]}),h?t.jsx("span",{className:"ui-badge settings-nav-count","aria-hidden":"true",children:h>99?"99+":h}):f?t.jsx("span",{className:"ui-badge settings-nav-dot","data-kind":"dot","aria-hidden":"true"}):null]},u.id)})]},o.id))})})})]})})}function Pte({hash:e,timezone:n,navigate:s,agents:r,pluginPages:a}){var w,y,N;const i=mU(e),l=ST(a!==void 0),o=a??l,c=DA(e),u=c?o.find(c.plugin,c.page):void 0,h=u?null:eU(e,o.settings);d.useEffect(()=>{h&&s(h,!0)},[h,s]);const f=fs(Gw),m=Tte(o.settings),g={proposals:((y=(w=ge(()=>Promise.resolve().then(()=>A.proposals()),[],3e4).data)==null?void 0:w.open)==null?void 0:y.length)??0},x=ge(()=>A.version(),[]),k=ge(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4),j={};x.data&&!x.data.checkout&&x.data.updateAvailable&&(j.system="a newer buddi is ready"),(((N=k.data)==null?void 0:N.signals)??[]).length>0&&(j.connections=AI);const v={entries:m,active:i,counts:g,dots:j,navigate:b=>s(b)};return t.jsxs("div",{className:"settings",children:[f?null:t.jsx(Rte,{...v}),t.jsx("div",{className:"settings-body",children:t.jsxs("div",{className:"ui-page",children:[i==="secrets"?t.jsx(Pi,{before:t.jsx(xc,{inline:!0,items:[{label:"Settings",href:on,onClick:()=>s(on)}]}),title:"Keys and secrets",lede:BP,actions:t.jsx(lt,{variant:"accent",size:"sm",href:_x,onClick:b=>{b.preventDefault(),s(_x)},children:"Add a secret"})}):i==="computer"?t.jsx(Pi,{before:t.jsx(xc,{inline:!0,items:[{label:"Settings",href:on,onClick:()=>s(on)}]}),title:"Browser & apps",lede:"Where agents may look"}):i==="plugins"||i==="connections"?t.jsx(Pi,{before:t.jsx(xc,{inline:!0,items:[{label:"Settings",href:on,onClick:()=>s(on)}]}),title:i==="plugins"?"Plugins":"Connections",lede:i==="plugins"?RZ:mP}):t.jsxs("header",{className:"ui-page-head",children:[t.jsx("h2",{className:"ui-page-title",children:"Settings"}),t.jsx("p",{className:"ui-page-lede",children:"How this installation runs, and where it reaches."})]}),f?t.jsx(Ite,{...v}):null,u?t.jsx(N7,{page:u,params:Ow(e),navigate:s,timezone:n,siblings:o.all.filter(b=>b.plugin===u.plugin)}):null,i==="you"?t.jsx(oZ,{embedded:!0}):null,i==="appearance"?t.jsx(Mte,{railPages:o.rail}):null,i==="notifications"?t.jsx(hte,{timezone:n}):null,i==="telegram"?t.jsx(pte,{timezone:n}):null,i==="memory"?t.jsx(GI,{embedded:!0,agents:r,timezone:n,initialTab:Xte(e)}):null,i==="proposals"?t.jsx(bZ,{embedded:!0,plugin:cU(e)}):null,i==="accounts"?t.jsx(NX,{embedded:!0,account:tU(e)}):null,i==="computer"?t.jsx(CH,{embedded:!0,timezone:n,navigate:s}):null,i==="secrets"?t.jsx(LX,{embedded:!0,timezone:n,secret:aU(e),adding:iU(e),navigate:s}):null,i==="connections"?t.jsx(rQ,{embedded:!0,timezone:n,connection:sU(e)}):null,i==="lock"?t.jsx(sZ,{navigate:s}):null,i==="api"?t.jsx(lZ,{timezone:n}):null,i==="watchers"?t.jsx(GX,{timezone:n,embedded:!0}):null,i==="backup"?t.jsx(pX,{}):null,i==="plugins"?t.jsx(_Z,{railPages:o.rail,settingsPages:o.settings,navigate:s,hash:e}):null,i==="system"?t.jsx(Lte,{timezone:n}):null]})})]})}function Mte({railPages:e}){const[n,s]=DI();return t.jsx(pe,{title:"Appearance",aside:"Kept in this browser only. Another browser keeps its own.",panel:!0,children:t.jsxs(ue,{divided:!0,gap:"lg",children:[t.jsx(mg,{label:"Theme",hint:"System follows your Mac.",children:t.jsx(Gt,{label:"Theme",options:[{value:"light",label:"Light"},{value:"dark",label:"Dark"},{value:"system",label:"System"}],value:n.theme,onChange:r=>s({theme:r})})}),t.jsx(mg,{label:"Background",hint:"Blue carries the first-run colours through the app. Sand is quieter.",children:t.jsx(Gt,{label:"Background",options:[{value:"blue",label:"Blue"},{value:"sand",label:"Sand"}],value:n.ground,onChange:r=>s({ground:r})})}),t.jsx(mg,{label:"Page width",hint:"How far pages stretch on a wide screen.",children:t.jsx(Gt,{label:"Page width",options:[{value:"narrow",label:"Narrow"},{value:"wide",label:"Wide"},{value:"full",label:"Full"}],value:n.width,onChange:r=>s({width:r})})}),t.jsx(Dte,{pages:e}),t.jsx(Ote,{})]})})}function Ote(){var c,u,h;const e=ge(()=>A.overview(),[]),[n,s]=d.useState(null),r=((c=e.data)==null?void 0:c.glances)??[],a=((u=e.data)==null?void 0:u.home)??[],i=((h=e.data)==null?void 0:h.dismissed)??{};if(r.length===0&&a.length===0)return null;const l=(f,m)=>{s(f),A.setGlanceHidden(f,!m).then(()=>e.reload()).finally(()=>s(null))},o=(f,m)=>{s(`block:${f}`),A.homeDismiss(`block:${f}`,m?null:"hidden").then(()=>e.reload()).finally(()=>s(null))};return t.jsxs(t.Fragment,{children:[r.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home glances"}),t.jsx("span",{className:"ui-field-hint",children:"The lines beside the date on Home, at most three. Kept for every browser."})]}),t.jsx(ue,{gap:"sm",children:r.map(f=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!f.hidden,disabled:n===f.id,onChange:m=>l(f.id,m.target.checked)}),t.jsx("span",{children:f.title})]},f.id))})]}):null,a.length>0?t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"Home sections"}),t.jsx("span",{className:"ui-field-hint",children:"What the plugins put on Home. Kept for every browser."})]}),t.jsx(ue,{gap:"sm",children:a.map(f=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:i[`block:${f.id}`]!=="hidden",disabled:n===`block:${f.id}`,onChange:m=>o(f.id,m.target.checked)}),t.jsx("span",{children:f.title})]},f.id))})]}):null]})}function Dte({pages:e}){const n=TI(),[s,r]=d.useState(null);if(e.length===0)return null;const a=(i,l)=>{r(null),iY(i,!l).catch(o=>r(o instanceof Error?o.message:String(o)))};return t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:"In the rail"}),t.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."})]}),t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s}),e.map(i=>t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:!n.has(du(i)),onChange:l=>a(i,l.target.checked)}),t.jsx("span",{children:i.title})]},du(i)))]})]})}function mg({label:e,hint:n,children:s}){return t.jsxs("div",{className:"pref-row ui-section",children:[t.jsxs("div",{className:"pref-text",children:[t.jsx("span",{className:"pref-label",children:e}),t.jsx("span",{className:"ui-field-hint",children:n})]}),s]})}function Lte({timezone:e}){const n=ge(()=>A.overview(),[],15e3),s=ge(()=>A.session(),[]),r=ge(()=>A.providerAccounts(),[]),a=n.data;return t.jsxs(ue,{gap:"lg",children:[t.jsx(ae,{message:n.error}),t.jsx(qte,{}),a?t.jsx(pe,{title:"The queue",panel:!0,actions:t.jsx($,{size:"sm",variant:a.paused?"accent":void 0,onClick:()=>{A.setPaused(!a.paused).then(()=>n.reload())},children:a.paused?"Resume the queue":"Pause the queue"}),children:t.jsxs("p",{className:"ui-card-meta",children:[a.paused?"Paused. Nothing is being claimed until you resume.":"Running. Jobs are claimed as they come due."," ",a.paused?t.jsx(Ae,{tone:"warning",children:"paused"}):t.jsx(Ae,{tone:"good",children:"running"})]})}):null,t.jsxs(pe,{title:"This host",panel:!0,children:[t.jsx(Xt,{items:[{label:"Time zone",value:e},{label:"Server time",value:a?mt(a.now,e):"…"},{label:"Bound to",value:s.data?`${s.data.host}:${s.data.port}`:"…"},{label:"Credential vault",value:r.data?_te(r.data.vault.kind):"…"}]}),r.data&&(r.data.vault.locked||r.data.vault.kind==="none")?t.jsx(G,{tone:"warning",children:r.data.vault.advice||"Run buddi init on the host to configure secure credential storage."}):null]}),t.jsx(Fte,{}),t.jsx(M7,{}),t.jsx($te,{}),t.jsx(tX,{}),t.jsx(pe,{title:"Mail and sources",panel:!0,children:a?a.mail.length===0?t.jsx(Ne,{children:"No sources are installed."}):t.jsx(Xt,{items:a.mail.map(i=>({key:i.sourceId,label:t.jsx("span",{className:"mono",children:i.sourceId}),value:i.lastError?t.jsx("span",{className:"critical",children:i.lastError}):t.jsxs("span",{children:["polled ",Ge(i.lastRunAt)]})}))}):t.jsx(Ne,{children:"Loading…"})}),t.jsx(Nte,{})]})}function Fte(){var u;const e=ge(()=>A.service(),[],1e4),[n,s]=d.useState(null),[r,a]=d.useState(!1),[i,l]=d.useState(null),o=(u=e.data)!=null&&u.supervised?e.data.status:void 0;if(!o)return null;const c=h=>{a(!0),l(null),sm({kind:h},()=>A.serviceAction(h)).then(()=>{s(null)}).catch(f=>{l(f.message),e.reload()}).finally(()=>{a(!1)})};return t.jsx(pe,{title:"Service",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsx(Xt,{items:[{label:"Database",value:t.jsx(nC,{state:o.database,pid:o.databasePid})},{label:"Gateway",value:t.jsx(nC,{state:o.gateway,pid:o.gatewayPid})},{label:"Supervisor",value:t.jsxs("span",{className:"mono",children:["pid ",o.supervisorPid]})}]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:i}),n?t.jsx(G,{tone:"warning",role:"alert",children:n==="stop"?"Stopping the gateway closes this dashboard. The database keeps running; run buddi in a terminal to bring the dashboard back.":"Restarting the gateway takes a few seconds. This page waits for it and comes back by itself."}):t.jsx("p",{className:"ui-card-meta",children:"Stopping the gateway ends this dashboard until buddi is run again."}),t.jsx(ne,{align:"end",children:n?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:r,onClick:()=>{s(null),l(null)},children:"Cancel"}),t.jsx($,{variant:n==="stop"?"danger":"accent",disabled:r,onClick:()=>{c(n)},children:n==="stop"?"Stop it":"Restart it"})]}):t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:()=>{s("stop")},children:"Stop gateway"}),t.jsx($,{variant:"accent",onClick:()=>{s("restart")},children:"Restart gateway"})]})})]})})]})})}function nC({state:e,pid:n}){return t.jsxs("span",{children:[t.jsx(Ae,{tone:e==="running"?"good":e==="stopped"?"warning":e==="failed"?"critical":"muted",children:e})," ",n===null?t.jsx("span",{className:"ui-card-meta",children:"no process"}):t.jsxs("span",{className:"mono",children:["pid ",n]})]})}function _te(e){return e==="keychain"?"macOS Keychain":e==="file"?"Encrypted file vault":e==="none"?"None":e}const zte=2e3,pf={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."},Ute=new Set(["done","failed","rolled-back"]),Bte="The check asks the npm registry for the newest version and sends nothing else.",Wte="This takes a backup, installs the new version and restarts buddi. This page waits for it and comes back by itself.",Hte=6e4;function pg(e,n){return e?{button:n?`Update to ${n}`:"Update",warning:`buddi takes a backup first, installs ${n??"the new version"} and restarts; it takes a minute or two. This page waits for it and comes back by itself.`}:{button:n?`Upgrade to ${n}`:"Upgrade",warning:Wte}}const Kte="A checkout upgrades with git pull, then buddi upgrade in a terminal.",Vte=15*6e4;function Gte(e,n=!1){const s=e.step==="starting"?"while starting":`at ${e.step??"an unknown step"}`,r=`The upgrade to ${e.to} failed ${s}: ${e.error??"no reason given"}. The backup taken first is ${e.backup??"not available"}. `;return n?r+`To go back to ${e.from}, choose Advanced → Restart with the Previous Version in the buddi menu.`:r+"Run buddi doctor in a terminal; it prints the way back."}function sC(e,n=Date.now()){const s=e[e.length-1];if((s==null?void 0:s.outcome)!=="failed")return null;const r=Date.parse(s.finishedAt??s.startedAt);return Number.isFinite(r)&&n-r<Vte?s:null}function Yte(e,n){const[s,r]=d.useState(void 0),[a,i]=d.useState(null),l=d.useRef(n);return l.current=n,d.useEffect(()=>{if(!e){r(void 0);return}let o=!1,c=!1;const u=()=>{o||c||A.upgradeJob(e).then(f=>{var m;o||(r(f),i(null),KA({step:pf[f.phase]??f.detail??f.phase}),(Ute.has(f.phase)||f.finishedAt)&&(o=!0,f.phase==="failed"&&(no(),(m=l.current)==null||m.call(l,f))))}).catch(f=>{o||(f instanceof he&&f.status!==0&&f.status<500?(o=!0,no(),i(f.message)):c=!0)})};u();const h=window.setInterval(u,zte);return()=>{o=!0,window.clearInterval(h)}},[e]),{job:s,error:a}}function qte(){var w;const[e,n]=d.useState(!1),s=ge(()=>A.version(),[],e?Hte:void 0);d.useEffect(()=>{var y;((y=s.data)==null?void 0:y.app)===!0&&n(!0)},[(w=s.data)==null?void 0:w.app]);const[r,a]=d.useState(null),[i,l]=d.useState(!1),[o,c]=d.useState(!1),[u,h]=d.useState(null),[f,m]=d.useState(null),p=d.useCallback(y=>{a(null),m(y)},[]),g=Yte(r,p),x=s.data,k=()=>{c(!0),h(null),A.checkVersion().catch(y=>h(y instanceof he?y.message:String(y))).finally(()=>{c(!1),s.reload()})},j=y=>{c(!0),h(null),A.setVersionCheck(y).catch(N=>h(N instanceof he?N.message:String(N))).finally(()=>{c(!1),s.reload()})},v=()=>{c(!0),h(null),m(null),sm({kind:"upgrade",line:x!=null&&x.latest?`Upgrading to ${x.latest}…`:"Upgrading…",step:pf.starting,patienceMs:HA},()=>A.startUpgrade(x==null?void 0:x.latest)).then(y=>{var N;l(!1),a(((N=y==null?void 0:y.job)==null?void 0:N.id)??null)}).catch(y=>h(y instanceof he?y.message:String(y))).finally(()=>c(!1))};return x!=null&&x.checkout?t.jsx(pe,{title:"Version",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsx(Xt,{items:[{label:"Running",value:t.jsx("span",{className:"mono",children:x.current})}]})}),t.jsx(pe,{children:t.jsx("p",{className:"ui-card-meta",children:Kte})})]})}):t.jsx(pe,{title:"Version",panel:!0,children:t.jsxs(ue,{divided:!0,children:[t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(ae,{message:s.error??u}),t.jsx(Xt,{items:[{label:"Running",value:x?t.jsx("span",{className:"mono",children:x.current}):"…"},{label:"Newest",value:x?x.updateAvailable&&x.latest?t.jsxs("span",{children:["A newer buddi is available: ",t.jsx("span",{className:"mono",children:x.latest})]}):x.processing?t.jsx("span",{children:x.processing.message}):x.checkedAt?t.jsxs("span",{children:["This is the latest, as of ",Ge(x.checkedAt),"."]}):t.jsx("span",{children:"Not checked yet."}):"…"}]}),x!=null&&x.error?t.jsxs(G,{tone:"warning",children:["The last check did not get an answer: ",x.error]}):null,t.jsx(ne,{align:"end",children:t.jsx($,{disabled:o,onClick:k,children:"Check now"})})]})}),t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsxs("label",{className:"backup-check",children:[t.jsx("input",{type:"checkbox",checked:(x==null?void 0:x.checkEnabled)??!1,disabled:o||!x,onChange:y=>j(y.target.checked)}),t.jsx("span",{children:"Check once a day"})]}),t.jsx("p",{className:"ui-card-meta",children:Bte})]})}),x!=null&&x.updateAvailable&&x.latest&&x.latestNotes?t.jsx(pe,{title:`What changes in ${x.latest}`,children:t.jsx(pr,{text:x.latestNotes})}):null,t.jsx(pe,{children:t.jsxs(ue,{gap:"sm",children:[t.jsx(Qte,{...g,job:g.job??f??void 0}),!g.job&&!f&&!g.error&&x&&sC(x.history)?t.jsx(G,{tone:"critical",role:"alert",children:Gte(sC(x.history),x.app===!0)}):null,i?t.jsx(G,{tone:"warning",role:"alert",children:pg((x==null?void 0:x.app)===!0,x==null?void 0:x.latest).warning}):null,t.jsx(ne,{align:"end",children:i?t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",disabled:o,onClick:()=>l(!1),children:"Cancel"}),t.jsx($,{variant:"accent",disabled:o,onClick:v,children:pg((x==null?void 0:x.app)===!0,x==null?void 0:x.latest).button})]}):x!=null&&x.processing&&r===null?null:t.jsx($,{variant:"accent",disabled:o||r!==null||!(x!=null&&x.updateAvailable),onClick:()=>l(!0),children:pg((x==null?void 0:x.app)===!0,x!=null&&x.updateAvailable?x.latest:void 0).button})})]})}),x&&x.history.length>0?t.jsx(pe,{title:"Upgrades so far",children:t.jsx(Xt,{items:x.history.slice().reverse().map(y=>({key:y.startedAt,label:t.jsxs("span",{className:"mono",children:[y.from," → ",y.to]}),value:t.jsx(Jte,{attempt:y})}))})}):null]})})}function Qte({job:e,error:n}){return n?t.jsx(ae,{message:n}):e?e.phase==="failed"?t.jsxs(G,{tone:"critical",role:"alert",children:[pf.failed," ",e.error??""," buddi is still running on the version it had."]}):t.jsx(G,{tone:e.phase==="done"?"good":void 0,role:"status",children:pf[e.phase]??e.detail??e.phase}):null}function Jte({attempt:e}){return t.jsxs("span",{children:[t.jsx(Ae,{tone:e.outcome==="done"?"good":e.outcome==="failed"?"critical":"warning",children:e.outcome})," ",Ge(e.startedAt),e.step?`, at ${e.step}`:"",e.error?`: ${e.error}`:"",e.backup?t.jsxs("span",{className:"ui-card-meta",children:[" Backup: ",t.jsx("span",{className:"mono",children:e.backup})]}):null]})}function Xte(e){var s;return((s=/[?&]tab=(people|preferences|notes)\b/.exec(e))==null?void 0:s[1])??"people"}const tt={back:"Back",checking:"Checking…",mailbox:{sheet:"Add a mailbox",which:"Which mailbox?",providers:{gmail:{name:"Gmail",line:"Google Mail, or Google Workspace.",mark:"G"},icloud:{name:"iCloud",line:"An @icloud.com, @me.com or @mac.com address.",mark:"i"},fastmail:{name:"Fastmail",line:"Fastmail, with your own domain or theirs.",mark:"F"},other:{name:"Other",line:"Any mailbox that offers IMAP.",mark:"@"}},address:"Address",password:"App password",otherPassword:"Password",how:{gmail:{text:"Google wants an app password, not your usual one. 2-Step Verification must be on.",link:"Make one",href:"https://myaccount.google.com/apppasswords"},icloud:{text:"Apple wants an app-specific password, made under Sign-In and Security.",link:"How",href:"https://support.apple.com/en-us/102654"},fastmail:{text:"Fastmail wants an app password with Mail (IMAP/SMTP) access.",link:"How",href:"https://www.fastmail.help/hc/en-us/articles/360058752854"},other:null},server:"Server details",serverHint:"Left empty, buddi tries imap. and smtp. at your domain.",imapHost:"IMAP host",smtpHost:"SMTP host",submit:"Add it",reading:"Mail Triage is reading it.",noTriage:"Saved. Mail Triage starts reading once you accept it on Home.",later:"More in Mail settings later."},calendar:{sheet:"Link your calendar",ask:"Your calendar’s private link",google:"Sign in with Google",googleLine:"Reads and, when you approve, changes your Google calendars.",or:"or paste a private link",field:"Private link",placeholder:"Paste the whole link",where:"Where do I find it?",help:[{name:"iCloud",text:"In the Calendar app or at icloud.com/calendar, share the calendar, tick Public Calendar, then copy the link."},{name:"Google",text:"Google Calendar on the web → Settings → pick the calendar → Integrate calendar → copy “Secret address in iCal format”."},{name:"Fastmail",text:"Settings → Calendars → Share beside the calendar → turn on the iCal link for anyone with it → copy it."}],submit:"Link it",starting:"Starting…",continue:"Continue to Google",waiting:"Waiting for Google… This finishes by itself when Google sends you back.",reading:"Signed in. Reading your calendars…",again:"Try again",found:e=>`Found ${e} ${e===1?"calendar":"calendars"}.`,events:e=>`Found your calendar: ${e} ${e===1?"event":"events"}.`,later:"More in Calendar settings later."},bank:{sheet:"Your bank",ask:"Statements, not a bank sign-in",line:"Finance never signs in to a bank, so nothing leaves this computer. Once we are done, hand me a statement — a PDF, a photo or your bank’s CSV export — and I read your accounts in.",ok:"Got it"}};function sh(e){return e instanceof he||e instanceof Error?e.message:String(e)}function Ti({state:e,children:n}){return e==="bad"?t.jsx("p",{className:"frs-line","data-tone":"bad",role:"alert",children:n}):t.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"wiz-pulse","data-done":e==="good"?"true":void 0,"aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:n})]})}const Zte=1400;function TM(e,n){const s=d.useRef(n);s.current=n,d.useEffect(()=>{if(!e)return;const r=window.setTimeout(()=>s.current(),Zte);return()=>window.clearTimeout(r)},[e])}function RM(){const e=d.useRef(null);return d.useEffect(()=>{const n=window.requestAnimationFrame(()=>{var s;return(s=e.current)==null?void 0:s.focus()});return()=>window.cancelAnimationFrame(n)},[]),e}const ene={gmail:{imapHost:"imap.gmail.com",imapPort:993,smtpHost:"smtp.gmail.com",smtpPort:465},icloud:{imapHost:"imap.mail.me.com",imapPort:993,smtpHost:"smtp.mail.me.com",smtpPort:587},fastmail:{imapHost:"imap.fastmail.com",imapPort:993,smtpHost:"smtp.fastmail.com",smtpPort:465}},tne=["gmail","icloud","fastmail","other"];function nne({onClose:e,onAdded:n}){const[s,r]=d.useState(null);return t.jsx(Ye,{title:tt.mailbox.sheet,onClose:e,children:s===null?t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:tt.mailbox.which}),t.jsx("div",{className:"frs-choices",role:"group","aria-label":tt.mailbox.which,children:tne.map(a=>{const i=tt.mailbox.providers[a];return t.jsxs("button",{type:"button",className:"wiz-opt frs-choice",onClick:()=>r(a),children:[t.jsx("span",{className:"frs-mark","data-provider":a,"aria-hidden":"true",children:i.mark}),t.jsxs("span",{className:"frs-choice-text",children:[t.jsx("span",{className:"wiz-opt-title",children:i.name}),t.jsx("span",{className:"wiz-opt-line",children:i.line})]}),t.jsx(oe,{name:"chevron-right"})]},a)})}),t.jsx("p",{className:"frs-later",children:tt.mailbox.later})]}):t.jsx(sne,{provider:s,onBack:()=>r(null),onClose:e,onAdded:n},s)})}function sne({provider:e,onBack:n,onClose:s,onAdded:r}){const a=RM(),[i,l]=d.useState(""),[o,c]=d.useState(""),[u,h]=d.useState(""),[f,m]=d.useState(""),[p,g]=d.useState({kind:"idle"});TM(p.kind==="good",s);const x=tt.mailbox.providers[e],k=tt.mailbox.how[e],j=i.trim()!==""&&o.trim()!==""&&p.kind!=="busy"&&p.kind!=="good",v=()=>{if(!j)return;g({kind:"busy"});const w=e==="other"?{...u.trim()?{imapHost:u.trim()}:{},...f.trim()?{smtpHost:f.trim()}:{}}:ene[e];Promise.resolve().then(()=>A.pageAct("email",{tool:"email.add_account",args:{address:i.trim(),password:o,...w}})).then(y=>{const N=y.result??{};c(""),g({kind:"good",line:N.triage==="needs-agent"?tt.mailbox.noTriage:tt.mailbox.reading}),r(N.address??i.trim().toLowerCase())}).catch(y=>g({kind:"bad",line:sh(y)}))};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsxs("h3",{className:"frs-ask",children:[t.jsx("span",{className:"frs-mark","data-provider":e,"aria-hidden":"true",children:x.mark}),x.name]}),t.jsxs("form",{className:"frs-form",onSubmit:w=>{w.preventDefault(),v()},children:[t.jsx(ie,{label:tt.mailbox.address,children:t.jsx("input",{ref:a,type:"email",autoComplete:"email",spellCheck:!1,value:i,onChange:w=>l(w.target.value)})}),t.jsx(ie,{label:e==="other"?tt.mailbox.otherPassword:tt.mailbox.password,hint:k?t.jsxs(t.Fragment,{children:[k.text," ",t.jsx("a",{href:k.href,target:"_blank",rel:"noreferrer",children:k.link})]}):void 0,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:o,onChange:w=>c(w.target.value)})}),e==="other"?t.jsx(Zt,{summary:tt.mailbox.server,children:t.jsxs("div",{className:"frs-form",children:[t.jsx("p",{className:"frs-later",children:tt.mailbox.serverHint}),t.jsx(ie,{label:tt.mailbox.imapHost,children:t.jsx("input",{spellCheck:!1,placeholder:"imap.example.com",value:u,onChange:w=>h(w.target.value)})}),t.jsx(ie,{label:tt.mailbox.smtpHost,children:t.jsx("input",{spellCheck:!1,placeholder:"smtp.example.com",value:f,onChange:w=>m(w.target.value)})})]})}):null,t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),p.kind==="busy"?t.jsx(Ti,{state:"busy",children:tt.checking}):null,p.kind==="good"?t.jsx(Ti,{state:"good",children:p.line}):null,p.kind==="bad"?t.jsx(Ti,{state:"bad",children:p.line}):null,t.jsx("p",{className:"frs-later",children:tt.mailbox.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsxs(ne,{children:[t.jsxs($,{variant:"ghost",onClick:n,disabled:p.kind==="busy",children:[t.jsx(oe,{name:"chevron-left"}),tt.back]}),t.jsx(ot,{}),t.jsx($,{variant:"accent",disabled:!j,onClick:v,children:tt.mailbox.submit})]})})]})}const rne=2e3,rC=8*6e4;function ane(e,n){let s="";try{s=new URL(e.trim().replace(/^webcals?:\/\//i,"https://")).hostname.toLowerCase()}catch{s=""}const r=/google\./.test(s)?"Google calendar":/icloud\.com$|me\.com$/.test(s)?"iCloud calendar":/fastmail\./.test(s)?"Fastmail calendar":/outlook\.|office365\.|live\.com$/.test(s)?"Outlook calendar":"My calendar",a=new Set(n.map(i=>i.toLowerCase()));if(!a.has(r.toLowerCase()))return r;for(let i=2;;i++)if(!a.has(`${r} ${i}`.toLowerCase()))return`${r} ${i}`}function ine({onClose:e,onLinked:n}){var D,P,K;const s=RM(),[r,a]=d.useState(null),[i,l]=d.useState(""),[o,c]=d.useState({kind:"idle"});TM(o.kind==="good",e);const u=()=>A.pageQuery("calendar","settings").then(F=>F.data??{});d.useEffect(()=>{let F=!1;return u().then(Q=>{F||a(Q)}).catch(()=>{F||a({})}),()=>{F=!0}},[]);const h=F=>{c({kind:"good",line:F}),n(F)},f=((D=r==null?void 0:r.calendars)==null?void 0:D.length)??0,m=()=>{if(i.trim()===""||o.kind==="busy"||o.kind==="good")return;c({kind:"busy",line:tt.checking});const F=ane(i,((r==null?void 0:r.calendars)??[]).map(Q=>Q.name));Promise.resolve().then(()=>A.pageAct("calendar",{tool:"calendar.add",args:{name:F,link:i.trim()}})).then(Q=>{var Y;l("");const _=((Y=Q.result)==null?void 0:Y.note)??"",re=/(\d+) events? read/.exec(_);h(re?tt.calendar.events(Number(re[1])):tt.calendar.found(1))}).catch(Q=>c({kind:"bad",line:sh(Q)}))},[p,g]=d.useState(null),[x,k]=d.useState(!1),[j,v]=d.useState(0),w=d.useRef(!1),y=d.useRef(void 0),N=(r==null?void 0:r.googleAvailable)===!0,b=d.useRef(null);d.useEffect(()=>{if(!N)return;let F=!1;const Q=async re=>{var Y,B;if(!(F||w.current)){window.clearTimeout(y.current);try{const q=Z=>{const fe=Z==null?void 0:Z[0];return fe&&fe.state==="waiting"&&fe.url?fe:void 0};let J=re?void 0:q((Y=(await A.pageQuery("calendar","sign_in")).data)==null?void 0:Y.rows);if(!J){if(F||w.current)return;await A.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}}),J=q((B=(await A.pageQuery("calendar","sign_in")).data)==null?void 0:B.rows)}if(F||w.current)return;if(!J)throw new Error("no address to open");b.current={id:J.id,at:Date.now()},g({id:J.id,url:J.url}),k(!1),y.current=window.setTimeout(()=>void Q(!0),rC)}catch{F||(b.current=null,g(null),k(!0))}}},_=()=>{const re=b.current;document.visibilityState!=="visible"||!re||w.current||Date.now()-re.at>=rC&&Q(!0)};return document.addEventListener("visibilitychange",_),Q(!1),()=>{F=!0,window.clearTimeout(y.current),document.removeEventListener("visibilitychange",_);const re=b.current;b.current=null,re&&!w.current&&A.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:re.id}}).catch(()=>{})}},[N,j]);const S=F=>{c({kind:"bad",line:F}),w.current=!1,g(null),v(Q=>Q+1)},[C,T]=d.useState(0),E=o.kind==="google"?((P=o.signIn)==null?void 0:P.id)??null:null;d.useEffect(()=>{if(C===0)return;let F=!1,Q=!1,_=!1;const re=()=>{F=!0,window.clearInterval(B)},Y=()=>{F||Q||(Q=!0,A.pageQuery("calendar","sign_in").then(async q=>{var ve,Oe,W,se;if(F)return;const J=((Oe=(ve=q.data)==null?void 0:ve.rows)==null?void 0:Oe[0])??null;if(!J)return;if(J.state==="waiting"){c(X=>{var je;return X.kind==="google"&&((je=X.signIn)==null?void 0:je.url)===J.url?X:{kind:"google",signIn:J}});return}if(J.state==="failed"){re(),S(J.problem||J.note);return}re(),J.state==="received"&&!_&&(_=!0,c({kind:"busy",line:tt.calendar.reading}),await A.pageAct("calendar",{tool:"calendar.google_finish",args:{id:J.id}}));const Z=await u();await A.pageAct("calendar",{tool:"calendar.google_dismiss",args:{id:J.id}}).catch(()=>{});const fe=(((W=Z.calendars)==null?void 0:W.length)??0)-f;h(tt.calendar.found(fe>0?fe:((se=Z.calendars)==null?void 0:se.length)??0))}).catch(q=>{re(),S(sh(q))}).finally(()=>{Q=!1}))},B=window.setInterval(Y,rne);return Y(),()=>{F=!0,window.clearInterval(B)}},[C]);const R=()=>{!p||o.kind==="google"||(w.current=!0,window.clearTimeout(y.current),c({kind:"google",signIn:{id:p.id,url:p.url,state:"waiting",note:"",problem:""}}),T(F=>F+1))},M=()=>{w.current=!0,window.clearTimeout(y.current),c({kind:"busy",line:tt.calendar.starting}),Promise.resolve().then(()=>A.pageAct("calendar",{tool:"calendar.google_sign_in",args:{}})).then(()=>{c({kind:"google",signIn:null}),T(F=>F+1)}).catch(F=>S(sh(F)))},O=()=>{const F=E??(o.kind!=="good"?p==null?void 0:p.id:void 0);window.clearTimeout(y.current),F&&A.pageAct("calendar",{tool:"calendar.google_cancel",args:{id:F}}).catch(()=>{}),e()},I=o.kind==="busy"||o.kind==="google"||o.kind==="good",z=o.kind==="google"?(K=o.signIn)==null?void 0:K.url:o.kind==="busy"||o.kind==="good"||p==null?void 0:p.url,U=o.kind==="google"&&p===null;return t.jsxs(Ye,{title:tt.calendar.sheet,onClose:O,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:tt.calendar.ask}),r!=null&&r.googleAvailable?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"frs-google",children:[z?t.jsxs(lt,{variant:"accent",size:"lg",href:z,target:"_blank",rel:"noreferrer",onClick:R,children:[U?tt.calendar.continue:tt.calendar.google,t.jsx(oe,{name:"external"})]}):t.jsxs($,{variant:"accent",size:"lg",disabled:I||!x,onClick:M,children:[tt.calendar.google,t.jsx(oe,{name:"external"})]}),t.jsx("span",{className:"wiz-opt-line",children:tt.calendar.googleLine})]}),t.jsx("div",{className:"frs-or",children:tt.calendar.or})]}):null,t.jsxs("form",{className:"frs-form",onSubmit:F=>{F.preventDefault(),m()},children:[t.jsx(ie,{label:tt.calendar.field,children:t.jsx("input",{ref:s,type:"url",inputMode:"url",autoComplete:"off",spellCheck:!1,placeholder:tt.calendar.placeholder,value:i,disabled:I,onChange:F=>l(F.target.value)})}),t.jsx(Zt,{summary:tt.calendar.where,children:t.jsx("dl",{className:"frs-help",children:tt.calendar.help.map(F=>t.jsxs("div",{children:[t.jsx("dt",{children:F.name}),t.jsx("dd",{children:F.text})]},F.name))})}),t.jsx("button",{type:"submit",hidden:!0,"aria-hidden":"true",tabIndex:-1})]}),o.kind==="busy"?t.jsx(Ti,{state:"busy",children:o.line}):null,o.kind==="google"?t.jsx(Ti,{state:"busy",children:tt.calendar.waiting}):null,o.kind==="good"?t.jsx(Ti,{state:"good",children:o.line}):null,o.kind==="bad"?t.jsx(Ti,{state:"bad",children:o.line}):null,t.jsx("p",{className:"frs-later",children:tt.calendar.later})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",disabled:I||i.trim()==="",onClick:m,children:tt.calendar.submit})})})]})}function lne({onClose:e,onUnderstood:n}){return t.jsxs(Ye,{title:tt.bank.sheet,onClose:e,children:[t.jsxs("div",{className:"wiz-sheet-body",children:[t.jsx("h3",{className:"frs-ask",children:tt.bank.ask}),t.jsx("p",{className:"frs-text",children:tt.bank.line})]}),t.jsx("div",{className:"ui-sheet-foot",children:t.jsx(ne,{align:"end",children:t.jsx($,{variant:"accent",onClick:()=>{n(),e()},children:tt.bank.ok})})})]})}function one(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 cne({progress:e}){return t.jsxs(ue,{gap:"sm",children:[t.jsx("span",{role:"status",children:one(e)}),t.jsx(qw,{value:(e==null?void 0:e.percent)??0,label:"Fetching the browser"})]})}const gf=["hello","brain","takeOn","reach","assistant","handover"],IM={hello:"you",brain:"model",takeOn:"take-on",reach:"reach",assistant:"agent",handover:"hello"};function PM(e){return((e==null?void 0:e.accounts)??[]).filter(n=>n.enabled&&n.configured&&n.removalPending!==!0)}function une(e){var i,l,o;const n=PM(e.accounts),s=e.assistant?(((i=e.accounts)==null?void 0:i.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 a=n.find(c=>c.id===r);if(a)return{accountId:a.id,label:a.label,model:(s==null?void 0:s.model)??a.defaultModel}}function MM(e){var i,l,o,c,u;const n=une(e),s=e.onboarding&&!e.onboarding.needs.agent?e.assistant:void 0,r=((i=e.onboarding)==null?void 0:i.details)??{},a=((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}:{},...n?{brain:n}:{},...Array.isArray(r.takeOn)?{takeOn:r.takeOn}:s?{takeOn:[]}:{},...r.reach?{reach:r.reach}:a.includes("reach")||s?{reach:{}}:{},...a.includes("browser")||((u=r.reach)==null?void 0:u.browser)===!0?{browser:e.browser??"other"}:{},...s?{assistant:s}:{}}}function OM(e,n){return n==="hello"?typeof e.name=="string"&&e.name!==""&&typeof e.clock=="string"&&e.clock!=="":n==="brain"?e.brain!==void 0:n==="takeOn"?e.takeOn!==void 0:n==="reach"?e.reach!==void 0:n==="assistant"?e.assistant!==void 0:!1}function rh(e){return gf.find(n=>!OM(e,n))??"handover"}function dne(e){const n=gf.indexOf(e);return n>0?gf[n-1]:null}function aC(e,n,s){return s===n?"now":OM(e,s)?"done":"todo"}function hne(e,n){return{...e}}const tj="buddi.firstRun.restore";function nj(e){try{e===null?window.sessionStorage.removeItem(tj):window.sessionStorage.setItem(tj,e)}catch{}}function DM(){try{return window.sessionStorage.getItem(tj)}catch{return null}}function fne(e){const n=MM(e),s=rh(n);return{answers:n,open:s,stay:s!=="handover"}}function mne(e){return e.trim().startsWith("sk-ant-")?"anthropic":"openai"}function pne(e){const n=e.normalize("NFKD").replace(/[̀-ͯ]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^[^a-z]+/,"").replace(/-+$/,"").slice(0,20).replace(/-+$/,"");return n===""?"assistant":n}const gne=6e4,xne=5*6e4,LM=1500,vne=2e3,jne="(max-width: 720px)";function Io(){const e=d.useRef(null);return d.useEffect(()=>{let n=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},a=()=>{const l=e.current;l&&r(l)&&l.focus()},i=()=>{a(),s=window.setTimeout(a,0)};return typeof window.requestAnimationFrame=="function"?n=window.requestAnimationFrame(i):i(),window.addEventListener("focus",a),()=>{n&&window.cancelAnimationFrame(n),window.clearTimeout(s),window.removeEventListener("focus",a)}},[]),e}const cb=d.createContext({busy:0,report:()=>{}});function wne({children:e}){const[n,s]=d.useState(0),r=d.useCallback(i=>s(l=>Math.max(0,l+(i?1:-1))),[]),a=d.useMemo(()=>({busy:n,report:r}),[n,r]);return t.jsx(cb.Provider,{value:a,children:e})}function gt({children:e}){const{busy:n}=d.useContext(cb);return t.jsxs("div",{className:"wiz-say",children:[t.jsx(Au,{state:n>0?"working":"idle",size:"sm",className:"wiz-say-face"}),t.jsx("div",{className:"wiz-bubble",children:e})]})}function it({children:e}){return t.jsx(t.Fragment,{children:e})}function ms({line:e}){const{report:n}=d.useContext(cb);return d.useEffect(()=>(n(!0),()=>n(!1)),[n]),t.jsxs("div",{className:"wiz-busy",role:"status","aria-live":"polite",children:[t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),e]})}const ub=d.createContext(null);function wn({children:e,actions:n}){const s=d.useContext(ub),r=n==null?null:s?xo.createPortal(n,s):t.jsx("div",{className:"wiz-dock-inline",children:n});return t.jsxs(t.Fragment,{children:[e?t.jsx("div",{className:"wiz-ask",children:e}):null,r]})}function $s({onClick:e,disabled:n}){return t.jsxs($,{variant:"ghost",size:"lg",onClick:e,disabled:n,children:[t.jsx(oe,{name:"chevron-left"}),L.back]})}function Po({children:e,onClick:n,disabled:s}){return t.jsxs($,{variant:"accent",size:"lg",onClick:n,disabled:s,children:[e,t.jsx(oe,{name:"arrow"})]})}function yne({navigate:e,timezone:n}){var fn,Kn,en,kn,Pt,mn,tn;const s=fs(jne),[r,a]=d.useState(void 0);d.useEffect(()=>{A.session().then(Te=>a(Te.platform)).catch(()=>{})},[]);const[i,l]=d.useState({}),[o,c]=d.useState(null),[u,h]=d.useState(void 0),[f,m]=d.useState(void 0),[p,g]=d.useState([]),[x,k]=d.useState(null),[j,v]=d.useState(null),[w,y]=d.useState(!1),[N,b]=d.useState(null),[S,C]=d.useState(null),[T,E]=d.useState(null),[R,M]=d.useState(null),[O,I]=d.useState(()=>DM()?"running":"idle"),[z,U]=d.useState({}),[D,P]=d.useState([]),[K,F]=d.useState(0),Q=d.useRef(void 0),[_,re]=d.useState(null),[Y,B]=d.useState(null),q=d.useCallback(()=>{Promise.resolve().then(()=>A.takeOnProgress()).then(Te=>{Te&&Array.isArray(Te.plugins)&&re(Te)}).catch(()=>{})},[]);d.useEffect(()=>{if(!(_!=null&&_.running))return;const Te=window.setInterval(q,vne);return()=>window.clearInterval(Te)},[_==null?void 0:_.running,q]);const J=d.useMemo(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||n}catch{return n}},[n]),Z=d.useRef(e);Z.current=e;const fe=d.useCallback(async(Te=!0,st=!1)=>{var xs,Vn,Gn,Ds,An,pi,Xs,yr,gi;const[H,de,et,Qe,Se,Ve]=await Promise.all([A.onboarding().catch(()=>{}),A.owner().catch(()=>{}),A.providerAccounts().catch(()=>{}),Je.agents().catch(()=>{}),A.browser().catch(()=>{}),A.providers().catch(()=>{})]);h(et),Array.isArray(H==null?void 0:H.offers)&&B(H.offers);const nt=(Vn=(xs=Ve==null?void 0:Ve.providers.find(ut=>ut.kind==="anthropic"))==null?void 0:xs.defaultModel)==null?void 0:Vn.trim();m(nt||void 0),g((de==null?void 0:de.zones)??[]),b(((Gn=H==null?void 0:H.details)==null?void 0:Gn.conversationId)??null);const Ue=(Qe==null?void 0:Qe.agents.find(ut=>ut.id===Qe.defaultAgentId))??(Qe==null?void 0:Qe.agents[0]);Ue&&k(Ue),C(H&&!H.needs.agent&&Ue?{id:Ue.id,name:Ue.name,avatar:((Ds=Ue.avatar)==null?void 0:Ds.kind)==="emoji"?Ue.avatar.value:"",description:Ue.description,...Ue.picture?{picture:Ue.picture}:{}}:null),Array.isArray((An=H==null?void 0:H.details)==null?void 0:An.takeOn)&&q();const rn={onboarding:H,owner:de,accounts:et,browser:(pi=Se==null?void 0:Se.browser)==null?void 0:pi.engine,...Ue?{assistant:{id:Ue.id,name:Ue.name,avatar:((Xs=Ue.avatar)==null?void 0:Xs.kind)==="emoji"?Ue.avatar.value:""}}:{}};if(st){const ut=fne(rn);if(l(ut.answers),c(ut.open),!ut.stay){const qr=(yr=H==null?void 0:H.details)==null?void 0:yr.conversationId;Z.current(qr&&Ue?at(Ue.id,qr):$n,!0)}return}if(Te&&(H==null?void 0:H.state)==="done"){const ut=(gi=H.details)==null?void 0:gi.conversationId;Z.current(ut&&Ue?at(Ue.id,ut):$n,!0);return}if(!Te)return;const pt=MM(rn);l(pt),c(ut=>ut??rh(pt))},[]);d.useEffect(()=>{fe()},[fe]);const ve=(Te,st={})=>{Promise.resolve().then(()=>A.onboardingStep(IM[Te],st)).catch(()=>{})},Oe=Te=>rh(Te)==="brain"&&z.brain?{...Te,brain:z.brain}:Te,W=(Te,st)=>{const H=Oe(st);H.brain&&(Q.current=H.brain),v(null),P([]),l(H),Te==="brain"&&H.brain?ve(Te,{accountId:H.brain.accountId}):Te==="reach"?ve(Te,H.reach?{reach:H.reach}:{}):Te!=="takeOn"&&ve(Te),c(rh(H))},se=(Te,st)=>{v(null),l(st),st.brain&&(Q.current=st.brain),Te==="brain"&&st.brain&&ve(Te,{accountId:st.brain.accountId})},X=Te=>{v(null),l(st=>hne(st)),c(Te)},je=()=>{if(!o)return;const Te=dne(o==="handover"?"handover":o);Te&&X(Te)},be=()=>{const Te=i.brain??Q.current,st=((_==null?void 0:_.plugins)??[]).filter(H=>H.state==="ready").map(H=>H.title);v(null),U({}),P([]),l({}),c("hello"),F(H=>H+1),(async()=>{var nt;const[H,de,et]=await Promise.all([Promise.resolve().then(()=>A.providerAccounts()).catch(()=>{}),Promise.resolve().then(()=>A.telegram()).catch(()=>{}),Promise.resolve().then(()=>A.browser()).catch(()=>{})]),Qe=PM(H),Se=Te&&Qe.some(Ue=>Ue.id===Te.accountId)?Te:void 0;H&&h(H),U(Se?{brain:Se}:{});const Ve=[...new Set(Qe.map(Ue=>Ue.label)),...de!=null&&de.paired?[L.startOver.telegram]:[],...((nt=et==null?void 0:et.browser)==null?void 0:nt.engine)==="chromium"?[L.startOver.browser]:[],...st];P(Ve.length>0?[L.startOver.said(Ve.join(", "))]:[])})()},xe=()=>{y(!0),A.skipOnboarding().then(()=>e($n)).catch(Te=>v(Te instanceof he?Te.message:String(Te))).finally(()=>y(!1))},we=ge(()=>A.version().catch(()=>({current:""})),[]),Ie=d.useRef(null);d.useEffect(()=>{Ie.current&&(Ie.current.scrollTop=0)},[o]);const ke=O==="running",me=Object.keys(i).length===0,$e={answers:i,accounts:u,claudeModel:f,zones:p,browserZone:J,assistantAgent:x,met:N,onMet:b,existing:S,progress:_,offers:Y,onProgress:q,navigate:e,onSettled:Te=>o&&W(o,Te),onKept:Te=>o&&se(o,Te),onBack:je,onTrouble:v,onReload:()=>void fe(!1),onPickAnotherBrain:()=>X("brain"),onSpoken:M},_e=(i.takeOn??[]).map(Te=>{var st;return((st=_h.find(H=>H.id===Te))==null?void 0:st.title)??Te}),Le=(_==null?void 0:_.plugins)??[],qe=Le.filter(Te=>Te.state==="ready").length,yt=Le.length===0?null:_!=null&&_.running?L.takeOn.installing(qe,Le.length):qe===Le.length?L.takeOn.installed:null,le=[(fn=i.reach)!=null&&fn.phone?L.reach.done.phone:null,(Kn=i.reach)!=null&&Kn.mailbox?L.reach.done.mailbox:null,(en=i.reach)!=null&&en.app||(kn=i.reach)!=null&&kn.browser?L.reach.done.app:null].filter(Te=>Te!==null),Ce={hello:{answer:L.hello.answer(i.name??""),sub:i.clock??null},brain:{answer:L.brain.answer(((Pt=i.brain)==null?void 0:Pt.label)??"")},takeOn:{answer:L.takeOn.answer(_e),sub:yt},reach:{answer:L.reach.answer(le)},assistant:{answer:((mn=i.assistant)==null?void 0:mn.name)??""}},Ze=gf.filter(Te=>Te!=="handover"),xt=o===null||o==="handover"?Ze.length:Ze.indexOf(o),Ct=Math.min(xt,Ze.length-1),It=R?null:t.jsxs("div",{className:"wiz-map-out",children:[t.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:xe,children:L.later}),o==="hello"&&me&&O==="idle"?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>I("form"),children:L.restore.offer}):!ke&&o!==null&&!(o==="hello"&&me)?t.jsx("button",{type:"button",className:"wiz-link",disabled:w,onClick:be,children:L.startOver.link}):null]}),Ot=r===void 0||r==="darwin"?L.tagline:L.taglineElsewhere,bn=o&&o!=="handover"?t.jsx("span",{className:"wiz-count",children:L.count(xt+1)}):t.jsx("span",{className:"wiz-count"});return t.jsx(ub.Provider,{value:T,children:t.jsx(wne,{children:t.jsxs(gT,{className:"wiz-ground",children:[t.jsx("div",{className:"wiz",ref:Ie,"data-phone":s?"true":void 0,"data-testid":"meet",children:t.jsxs("div",{className:"wiz-frame",children:[s?t.jsxs("div",{className:"wiz-strip",children:[t.jsx(su,{size:"sm"}),t.jsx("span",{className:"wiz-dots","aria-label":o&&o!=="handover"?L.count(xt+1):void 0,children:Ze.map(Te=>t.jsx("i",{"data-state":aC(i,o,Te)},Te))}),t.jsx("span",{className:"wiz-strip-name",children:o&&o!=="handover"?L.strip(xt+1,L.chapters[xt]??""):L.handover.starterLabel})]}):t.jsxs("nav",{className:"wiz-map","aria-label":"Chapters",children:[t.jsxs("div",{className:"wiz-head",children:[t.jsx(su,{size:"lg"}),t.jsxs("div",{children:[t.jsx("div",{className:"wiz-head-name",children:"buddi"}),t.jsx("div",{className:"wiz-head-line",children:Ot}),(tn=we.data)!=null&&tn.current?t.jsxs("div",{className:"wiz-head-version mono",children:["buddi ",we.data.current]}):null]})]}),Ze.map((Te,st)=>{const H=ke?Te==="hello"?"now":"todo":aC(i,o,Te),de=Ce[Te];return t.jsxs("div",{className:"wiz-ch","data-state":H,"aria-current":H==="now"?"step":void 0,children:[t.jsx("span",{className:"wiz-num","data-state":H,children:H==="done"?t.jsx(oe,{name:"check",size:12}):st+1}),t.jsxs("span",{className:"wiz-ch-label",children:[H==="done"?de.answer:L.chapters[st],H==="done"&&de.sub?t.jsx("span",{className:"wiz-ch-sub",children:de.sub}):null]}),H==="done"&&!ke?t.jsx("button",{type:"button",className:"wiz-link",onClick:()=>X(Te),children:L.change}):null]},Te)}),t.jsx("div",{className:"wiz-map-spacer"}),t.jsx("div",{className:"wiz-map-note",children:L.mapNotes[Ct]}),It]}),t.jsx("div",{className:"wiz-stage",role:"main",children:t.jsxs("div",{className:"wiz-column","data-width":o==="hello"?"narrow":o==="brain"?"mid":"wide",children:[t.jsxs(jB,{dock:t.jsxs(t.Fragment,{children:[bn,t.jsx("div",{className:"wiz-dock-actions",ref:E})]}),children:[ke?t.jsx(Xne,{onDone:Te=>{I("idle"),P([...Te?[L.restore.welcome(Te)]:[],L.restore.keys]),fe(!0,!0)},onFailed:Te=>{I("idle"),v(Te)}}):o==="hello"?t.jsx(bne,{...$e}):o==="brain"?t.jsx(Nne,{...$e}):o==="takeOn"?t.jsx(Une,{...$e}):o==="reach"?t.jsx(Bne,{...$e}):o==="assistant"?t.jsx(Yne,{...$e}):o==="handover"?t.jsx(qne,{...$e}):t.jsx(ms,{}),D.length>0||j?t.jsxs(it,{children:[D.map(Te=>t.jsx(gt,{children:Te},Te)),j?t.jsx(gt,{children:j}):null]}):null]},`${K}-${o??""}-${ke?"r":""}`),s?t.jsx("div",{className:"wiz-phone-out",children:It}):null]})})]})}),O==="form"?t.jsx(Jne,{onCancel:()=>I("idle"),onStarted:()=>I("running"),onTrouble:v}):null]})})})}function Mo({children:e}){return t.jsx("h1",{className:"wiz-title",children:e})}function iC(e){try{return Tt(new Date,e)}catch{return""}}function bne({answers:e,zones:n,browserZone:s,onSettled:r,onTrouble:a}){const i=Io(),[l,o]=d.useState(e.name??""),[c,u]=d.useState(e.clock??s),[h,f]=d.useState(!1),[m,p]=d.useState(!1),g=()=>{const x=l.trim();x===""||m||(p(!0),A.setOwner({preferredName:x,timezone:c}).then(()=>r({...e,name:x,clock:c})).catch(k=>a(k instanceof he?k.message:String(k))).finally(()=>p(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx(Mo,{children:L.hello.title}),t.jsx(it,{children:L.hello.opening.map(x=>t.jsx(gt,{children:x},x))}),t.jsxs(wn,{actions:t.jsx(Po,{onClick:g,disabled:m||l.trim()==="",children:L.hello.submit}),children:[t.jsxs("div",{className:"wiz-pair",children:[t.jsx(ie,{label:L.name.label,children:t.jsx("input",{ref:i,placeholder:L.name.placeholder,maxLength:80,value:l,onChange:x=>o(x.target.value),onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),g())}})}),h?t.jsx(ie,{label:L.clock.label,hint:L.clock.hint(iC(c)),children:t.jsx("select",{value:c,onChange:x=>u(x.target.value),children:(n.includes(c)?n:[c,...n]).map(x=>t.jsx("option",{value:x,children:x},x))})}):t.jsx(ie,{label:L.clock.label,hint:L.clock.hint(iC(c)),action:t.jsx($,{size:"lg",onClick:()=>f(!0),children:L.clock.change}),children:t.jsx("input",{value:c,readOnly:!0})})]}),t.jsx("div",{className:"wiz-foot",children:L.hello.foot})]})]})}const kne={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 Nne(e){const{accounts:n,answers:s,onSettled:r,onKept:a,onReload:i,onBack:l}=e,[o,c]=d.useState(null),[u,h]=d.useState("key"),[f,m]=d.useState(null),[p,g]=d.useState(!1),[x,k]=d.useState(null),[j,v]=d.useState(null),[w,y]=d.useState(null),N=(n==null?void 0:n.anthropicOAuthEnabled)===!0,b=(n==null?void 0:n.codexEnabled)===!0,S=n==null?void 0:n.gemini,[C,T]=d.useState(null);d.useEffect(()=>{let K=!1;const F=()=>{Promise.resolve().then(()=>A.ollama()).then(_=>{!K&&_&&k(_)}).catch(()=>{}),Promise.resolve().then(()=>A.mlxh()).then(_=>{!K&&_&&v(_)}).catch(()=>{K||v({running:!1,baseUrl:"",manager:!1,models:[]})})};F();const Q=window.setInterval(F,4e3);return()=>{K=!0,window.clearInterval(Q)}},[]);const E=async K=>{if(s.assistant??e.existing)try{await A.bindBrain({accountId:K.accountId,model:K.model})}catch(F){return F instanceof he?F.message:String(F)}return i(),a({...s,brain:K}),C==null||C.close(),T(null),c(null),y(null),null},R=async(K,F,Q)=>{g(!0),m(null);try{const _=await A.saveProviderAccount(K);let re=await A.testProviderAccount(_.id),Y=K.defaultModel,B=!1;if(re.state!=="connected"&&Q&&Q!==Y&&MP(re)){const J=(await A.providerAccounts()).accounts.find(Z=>Z.id===_.id);J&&(await A.saveProviderAccount({id:J.id,revision:J.revision,label:J.label,kind:J.kind,auth:J.auth,baseUrl:J.baseUrl,defaultModel:Q,enabled:J.enabled}),re=await A.testProviderAccount(_.id),re.state==="connected"&&(Y=Q,B=!0))}if(re.state!=="connected"){try{const J=(await A.providerAccounts()).accounts.find(Z=>Z.id===_.id);J&&await A.removeProviderAccount(_.id,J.revision)}catch{}return m(re.message),re}const q=await E({accountId:_.id,label:F,model:Y,...B?{freeTier:B}:{}});return q&&m(q),re}catch(_){return m(_ instanceof he?_.message:String(_)),null}finally{g(!1)}},M=async K=>{g(!0),m(null);try{const F=await A.saveProviderAccount(K);let Q;try{Q=await A.testProviderAccount(F.id)}finally{try{const _=(await A.providerAccounts()).accounts.find(re=>re.id===F.id);_&&await A.removeProviderAccount(F.id,_.revision)}catch{}}return Q.state!=="connected"&&m(Q.message),Q}catch(F){return m(F instanceof he?F.message:String(F)),null}finally{g(!1)}},O=(K,F,Q)=>{if(K.length<=1){R(F(K[0]??""),Q);return}y({models:K,make:F,label:Q})},I=K=>{if(K===o)return;C==null||C.close(),T(K==="free"&&typeof window.open=="function"?window.open("","_blank"):null),m(null),y(null),h("key"),c(K)},z=()=>{C==null||C.close(),T(null),y(null),m(null),c(null)},U=_M(x,j),D=["free",...N?["claude"]:[],...b?["chatgpt"]:[],"key","local"];let P=null;return w?P=t.jsxs(t.Fragment,{children:[t.jsx(it,{children:t.jsx(gt,{children:L.brain.model.ask})}),p?t.jsx(ms,{line:L.brain.checking.service}):f?t.jsx(it,{children:t.jsx(gt,{children:f})}):null,t.jsx(Sne,{busy:p,models:w.models,onBack:z,onUse:K=>void R(w.make(K),w.label)})]}):o==="key"?P=t.jsxs(t.Fragment,{children:[t.jsx(Gt,{label:L.brain.keyKinds.label,value:u,onChange:K=>{m(null),h(K)},options:[{value:"key",label:L.brain.keyKinds.key},...S?[{value:"gemini",label:L.brain.keyKinds.gemini}]:[],{value:"service",label:L.brain.keyKinds.service}]}),u==="gemini"&&S?t.jsx(Ene,{busy:p,problem:f,preset:S,onBack:z,onUse:R},"gemini"):u==="service"?t.jsx(Tne,{busy:p,problem:f,address:(x==null?void 0:x.cloudBaseUrl)??"",onBack:z,onOffer:O,onTrial:M,onUse:R},"service"):t.jsx(Cne,{busy:p,problem:f,onBack:z,onUse:R},"key")]}):o==="local"?P=t.jsx(Ane,{busy:p,problem:f,probe:x,mlxh:j,onBack:z,onOffer:O,onUse:R,onCloud:()=>I("free")}):o==="free"?P=t.jsx(Ine,{...e,busy:p,consent:C,onBack:z,onConnected:E}):o==="chatgpt"?P=t.jsx(One,{...e,busy:p,consent:C,onBack:z,onConnected:E}):o==="claude"&&(P=t.jsx(Lne,{...e,busy:p,problem:f,onBack:z,onConnected:E})),t.jsxs(t.Fragment,{children:[t.jsx(Mo,{children:L.brain.title}),t.jsx(it,{children:t.jsx(gt,{children:L.brain.ask})}),t.jsx("div",{className:"wiz-grid",role:"group","aria-label":L.brain.ask,children:D.map(K=>{const F=kne[K],Q=L.brain.cards[K];return t.jsxs("button",{type:"button",className:"wiz-opt","aria-pressed":o===K,"data-wide":F.wide?"true":void 0,onClick:()=>I(K),children:[t.jsx("span",{className:"wiz-glyph","data-tone":F.tone,"aria-hidden":"true",children:t.jsx(oe,{name:F.icon})}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:Q.title}),t.jsx("span",{className:"wiz-opt-line",children:K==="local"?U:Q.line}),"pill"in Q?t.jsx(Ae,{tone:"good",children:Q.pill}):null]})]},K)})}),P,P===null&&s.brain?t.jsxs(it,{children:[t.jsx(gt,{children:s.brain.freeTier?L.brain.worksOnFlash(s.brain.model):L.brain.works(s.brain.model)}),t.jsx(Pne,{...e}),s.brain.label===L.brain.ollama.label||s.brain.label===L.brain.mlxh.label?t.jsx(G,{tone:"warm",title:L.brain.ollama.honestTitle,children:L.brain.ollama.honest}):null]}):null,P===null?t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:l}),t.jsx(Po,{onClick:()=>s.brain&&r(s),disabled:!s.brain,children:L.brain.submit})]})}):null]})}function Sne({busy:e,models:n,onBack:s,onUse:r}){const[a,i]=d.useState(n[0]??"");return t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:s,disabled:e}),t.jsx($,{variant:"accent",size:"lg",disabled:e||a==="",onClick:()=>r(a),children:L.brain.model.submit})]}),children:t.jsx(ie,{label:L.brain.model.label,grow:!0,children:t.jsx("select",{value:a,onChange:l=>i(l.target.value),children:n.map(l=>t.jsx("option",{value:l,children:l},l))})})})}function FM({models:e,picked:n,disabled:s,onPick:r}){return t.jsx(ie,{label:L.brain.model.label,grow:!0,children:t.jsx("select",{value:n,disabled:s,onChange:a=>r(a.target.value),children:e.map(a=>t.jsx("option",{value:a,children:a},a))})})}function Cne({busy:e,problem:n,onBack:s,onUse:r}){const a=Io(),[i,l]=d.useState(""),[o,c]=d.useState(null),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(""),[x,k]=d.useState(!1),j=e||u,v=!x&&n!==null&&f.length>0,w=o??mne(i),y=()=>{const N=i.trim();N===""||j||(h(!0),k(!1),(async()=>{var T;let b=w==="anthropic"?"claude-sonnet-5":"gpt-5",S=f;if(v&&p!=="")b=p;else try{const E=await A.probeModels({kind:w,auth:"api-key",secret:N});b=((T=E.models.find(R=>R.isDefault))==null?void 0:T.id)??b,S=E.models.map(R=>R.id)}catch{S=[]}h(!1);const C=await r({label:w==="anthropic"?L.brain.key.anthropic:L.brain.key.openai,kind:w,auth:"api-key",baseUrl:"",defaultModel:b,enabled:!0,secret:N},w==="anthropic"?L.brain.key.anthropic:L.brain.key.openai);if(!(!C||C.state==="connected")){if(jw(C)){k(!0),m([]);return}m(S.includes(b)||S.length===0?S:[b,...S]),g(b)}})())};return t.jsxs(t.Fragment,{children:[j?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.key})}):x?t.jsx(it,{children:t.jsx(gt,{children:L.brain.key.refused})}):n?t.jsx(it,{children:t.jsx(gt,{children:n})}):null,t.jsxs(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:s,disabled:j}),t.jsx($,{variant:"accent",size:"lg",disabled:j||i.trim()==="",onClick:y,children:v?L.brain.model.retry:L.brain.key.submit})]}),children:[t.jsx(ie,{label:L.brain.key.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",autoComplete:"off",spellCheck:!1,placeholder:L.brain.key.placeholder,value:i,onChange:N=>{l(N.target.value),m([])},onKeyDown:N=>{N.key==="Enter"&&(N.preventDefault(),y())}})}),v?t.jsx(FM,{models:f,picked:p,disabled:j,onPick:g}):null,t.jsxs("button",{type:"button",className:"wiz-link",onClick:()=>c(w==="anthropic"?"openai":"anthropic"),children:[w==="anthropic"?L.brain.key.anthropic:L.brain.key.openai," · ",L.brain.key.which]})]})]})}function Ene({busy:e,problem:n,preset:s,onBack:r,onUse:a}){const i=Io(),[l,o]=d.useState(""),[c,u]=d.useState(!1),[h,f]=d.useState([]),[m,p]=d.useState(""),g=e||c,x=n!==null&&h.length>0,k=()=>{const j=l.trim();j===""||g||(u(!0),(async()=>{let v=TP,w;if(x&&m!=="")v=m;else try{const N=(await A.probeModels({kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,secret:j})).models.map(b=>b.id);v=RP(N)??v,w=PP(v)?IP(N):void 0,f(kX(N)),p(w??v)}catch{}u(!1),await a({label:L.brain.gemini.label,kind:"openai-compatible",auth:"api-key",baseUrl:s.baseUrl,defaultModel:v,enabled:!0,secret:j},L.brain.gemini.label,w)})())};return t.jsxs(t.Fragment,{children:[g?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.gemini})}):n?t.jsx(it,{children:t.jsx(gt,{children:n})}):null,t.jsxs(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:r,disabled:g}),t.jsx($,{variant:"accent",size:"lg",disabled:g||l.trim()==="",onClick:k,children:L.brain.gemini.submit})]}),children:[t.jsx(ie,{label:L.brain.gemini.field,grow:!0,children:t.jsx("input",{ref:i,type:"password",autoComplete:"off",spellCheck:!1,placeholder:L.brain.gemini.placeholder,value:l,onChange:j=>o(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),k())}})}),x?t.jsx(ie,{label:L.brain.model.label,grow:!0,children:t.jsx("select",{value:m,disabled:g,onChange:j=>p(j.target.value),children:h.map(j=>t.jsx("option",{value:j,children:j},j))})}):null,t.jsx("a",{className:"wiz-link",href:s.keyUrl,target:"_blank",rel:"noreferrer",children:L.brain.gemini.get})]})]})}function _M(e,n){return e===null||n===null?L.brain.local.looking:!e.running&&!n.running?L.brain.local.missing:L.brain.local.found({...e.running?{ollama:e.models.length}:{},...n.running?{mlxh:n.models.length}:{}})}const $ne=1e3;function lC({command:e}){const[n,s]=d.useState(!1);return d.useEffect(()=>{if(!n)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[n]),t.jsxs("div",{className:"rs-cmd",children:[t.jsx("code",{className:"rs-cmd-text",children:e}),t.jsx($,{size:"sm",onClick:()=>{var r;return void((r=navigator.clipboard)==null?void 0:r.writeText(e).then(()=>s(!0),()=>{}))},children:n?L.brain.ollama.copied:L.brain.ollama.copy})]})}const oC=e=>(e/1e9).toFixed(1);function Ane({busy:e,problem:n,probe:s,mlxh:r,onBack:a,onOffer:i,onUse:l,onCloud:o}){const c=(s==null?void 0:s.models)??[],u=zv(r),h=s==null?void 0:s.machine,[f,m]=d.useState(null),[p,g]=d.useState(null),x=d.useRef(null),k=f??(s==null?void 0:s.pull)??null,j=(k==null?void 0:k.state)==="pulling",v=O=>({label:L.brain.ollama.label,kind:"openai-compatible",auth:"none",baseUrl:(s==null?void 0:s.baseUrl)??"",defaultModel:O,enabled:!0});d.useEffect(()=>{if(!j)return;let O=!1;const I=window.setInterval(()=>{A.ollamaPullState().then(z=>{!O&&z.pull&&m(z.pull)},()=>{})},$ne);return()=>{O=!0,window.clearInterval(I)}},[j]),d.useEffect(()=>{(f==null?void 0:f.state)!=="done"||!s||x.current===f.model||(x.current=f.model,l(v(f.model),L.brain.ollama.label))},[f==null?void 0:f.state,f==null?void 0:f.model,s]);const w=O=>{g(null),x.current=null,A.ollamaPull(O).then(I=>m(I.pull),I=>g(I instanceof he?I.message:String(I)))},y=()=>{!(r!=null&&r.running)||!u||l({label:L.brain.mlxh.label,kind:"openai-compatible",auth:"none",baseUrl:r.baseUrl,defaultModel:u,enabled:!0},L.brain.mlxh.label)},N=s!==null&&r!==null&&!s.running&&!r.running,b=()=>{s&&i(c,v,L.brain.ollama.label)},S=(h==null?void 0:h.platform)==="darwin"?"this Mac":"this computer",C=(s==null?void 0:s.running)===!0&&c.length===0,T=h!==void 0&&!(r!=null&&r.running)&&(C||N||j),E=h!=null&&h.cloudSuggested?h.memoryGb<7?"memory":"gpu":null,R=h?t.jsxs("div",{className:"wiz-foot",children:[L.brain.ollama.cloud(E,h.memoryGb)," ",t.jsx("button",{type:"button",className:"wiz-link",onClick:o,children:L.brain.ollama.useCloud})]}):null;let M=null;if(T&&h){const O=(k==null?void 0:k.state)==="failed"?k:null;if(j&&k){const I=k.total>0?k.completed/k.total:0;M=t.jsxs("div",{className:"wiz-stack",children:[t.jsxs("div",{className:"wiz-busy","data-boxed":"true",children:[t.jsxs("span",{className:"wiz-pulse","aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:L.brain.ollama.fetching(k.model,oC(k.completed),k.total>0?oC(k.total):"")}),t.jsxs("span",{className:"wiz-busy-side",children:[Math.round(I*100),"%"]})]}),t.jsx(qw,{value:I*100,label:L.brain.ollama.fetch(k.model)}),t.jsx("div",{className:"wiz-foot",children:L.brain.ollama.fetchingFoot})]})}else if(C){const I=(O==null?void 0:O.model)??h.recommended.model;M=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(it,{children:t.jsx(gt,{children:O?L.brain.ollama.failed(O.error??""):L.brain.ollama.empty(S,h.memoryGb,h.recommended.model,h.recommended.sizeGb)})}),p?t.jsx(G,{tone:"critical",children:p}):null,t.jsxs(ne,{children:[t.jsx("span",{className:"wiz-foot",children:L.brain.ollama.emptyFoot(S)}),t.jsx(ot,{}),t.jsx($,{variant:"accent",size:"lg",disabled:e,onClick:()=>w(I),children:O?L.brain.ollama.again:L.brain.ollama.fetch(I)})]}),R]})}else h.installed?M=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(it,{children:t.jsx(gt,{children:L.brain.ollama.stopped(h.platform)})}),h.platform==="linux"?t.jsx(lC,{command:"ollama serve"}):null,R]}):M=t.jsxs("div",{className:"wiz-stack",children:[t.jsx(it,{children:t.jsx(gt,{children:L.brain.ollama.missing(S)})}),h.install.command?t.jsx(lC,{command:h.install.command}):null,t.jsxs(ne,{children:[t.jsx("span",{className:"wiz-foot",children:L.brain.ollama.missingHow(h.platform,S)}),t.jsx(ot,{}),h.platform==="linux"?null:t.jsx(lt,{size:"lg",href:h.install.url,target:"_blank",rel:"noreferrer",children:L.brain.ollama.download})]}),R]})}return t.jsxs(t.Fragment,{children:[e?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.ollama})}):n?t.jsx(it,{children:t.jsx(gt,{children:n})}):null,M,t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:a,disabled:e}),s!=null&&s.running&&c.length>0?t.jsx($,{variant:r!=null&&r.running?void 0:"accent",size:"lg",disabled:e,onClick:b,children:L.brain.ollama.connect}):null,r!=null&&r.running?t.jsx($,{variant:"accent",size:"lg",disabled:e||!u,onClick:y,children:L.brain.mlxh.connect}):null,N&&s&&!h?t.jsx(lt,{variant:"accent",size:"lg",href:s.downloadUrl,target:"_blank",rel:"noreferrer",children:L.brain.ollama.download}):null]}),children:T?null:t.jsxs("span",{className:"wiz-foot",children:[_M(s,r),r!=null&&r.running&&!u?` ${L.brain.mlxh.noBrain}`:"",N&&(r!=null&&r.baseUrl)?` ${aP(r.baseUrl)}`:""]})})]})}function Tne({busy:e,problem:n,address:s,onBack:r,onOffer:a,onTrial:i,onUse:l}){const o=Io(),[c,u]=d.useState(s),[h,f]=d.useState(""),[m,p]=d.useState(!1),[g,x]=d.useState([]),[k,j]=d.useState(""),[v,w]=d.useState(!1),y=e||m,N=!v&&n!==null&&g.length>0,b=()=>{c.trim()===""||y||(p(!0),w(!1),(async()=>{var z;const S=h.trim()?"api-key":"none",C=U=>({label:L.brain.service.label,kind:"openai-compatible",auth:S,baseUrl:c.trim(),defaultModel:U,enabled:!0,...h.trim()?{secret:h.trim()}:{}}),T=(U,D,P)=>{if(!(!U||U.state==="connected")){if(jw(U)){w(!0),x([]);return}x(D),j(P)}};if(S==="api-key"&&N&&k!==""){p(!1),T(await l(C(k),L.brain.service.label),g,k);return}let E=[],R;try{const U=await A.probeModels({kind:"openai-compatible",auth:S,baseUrl:c.trim(),...h.trim()?{secret:h.trim()}:{}});E=U.models.map(D=>D.id),R=(z=U.models.find(D=>D.isDefault))==null?void 0:z.id}catch{}p(!1);const M=R?[R]:E;if(S==="none"){a(M,C,L.brain.service.label);return}const O=M[0]??"";if(M.length<=1){T(await l(C(O),L.brain.service.label),E,O);return}const I=await i(C(O));(I==null?void 0:I.state)==="connected"?a(M,C,L.brain.service.label):T(I,E,O)})())};return t.jsxs(t.Fragment,{children:[y?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.service})}):v?t.jsx(it,{children:t.jsx(gt,{children:L.brain.key.refused})}):n?t.jsx(it,{children:t.jsx(gt,{children:n})}):null,t.jsxs(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:r,disabled:y}),t.jsx($,{variant:"accent",size:"lg",disabled:y||c.trim()==="",onClick:b,children:N?L.brain.model.retry:L.brain.service.submit})]}),children:[t.jsx(ie,{label:L.brain.service.address,grow:!0,children:t.jsx("input",{ref:o,value:c,placeholder:L.brain.service.addressPlaceholder,onChange:S=>{u(S.target.value),x([])}})}),t.jsx(ie,{label:L.brain.service.key,children:t.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,value:h,onChange:S=>{f(S.target.value),x([])}})}),N?t.jsx(FM,{models:g,picked:k,disabled:y,onPick:j}):null]})]})}const Rne=2e3;function Ine({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(0),p=d.useRef(-1),g=d.useRef(null),x=L.brain.cloud.label;d.useEffect(()=>{if(p.current===f)return;p.current=f,l(!0),c(null);const j=f===0?n:g.current;(async()=>{try{const v=((a==null?void 0:a.accounts)??[]).find(b=>b.auth==="device-key"),w=v?{id:v.id}:await A.saveProviderAccount({label:x,kind:"openai-compatible",auth:"device-key",baseUrl:"",defaultModel:Vd,enabled:!0}),y=(await A.providerAccounts()).accounts.find(b=>b.id===w.id),N=await A.ollamaConnect(y.id,y.revision);h({id:y.id,attemptId:N.attemptId,url:N.verificationUrl}),j&&(j.location.href=N.verificationUrl)}catch(v){j==null||j.close(),c(v instanceof he?v.message:String(v))}finally{l(!1)}})()},[f]),d.useEffect(()=>{if(!u)return;let j=!1,v=!1;const w=async()=>{if(!(j||v)){v=!0;try{const N=await A.ollamaPoll(u.id,u.attemptId);if(j||N.state==="waiting")return;if(j=!0,h(null),N.state==="failed"){c(N.message);return}l(!0),c(await k(u.id)),l(!1)}catch{}finally{v=!1}}},y=window.setInterval(()=>void w(),Rne);return()=>{j=!0,window.clearInterval(y)}},[u]);const k=async j=>{try{const v=(await A.accountModels(j).catch(()=>({models:[]}))).models.map(b=>b.id),w=v.length===0||v.includes(Vd)?Vd:v[0],y=(await A.providerAccounts()).accounts.find(b=>b.id===j);y&&y.defaultModel!==w&&await A.saveProviderAccount({id:y.id,revision:y.revision,label:y.label,kind:y.kind,auth:y.auth,baseUrl:y.baseUrl,defaultModel:w,enabled:y.enabled});const N=await A.testProviderAccount(j);return N.state!=="connected"?N.message:await r({accountId:j,label:x,model:w})}catch(v){return v instanceof he?v.message:String(v)}};return t.jsxs(t.Fragment,{children:[i||e?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.cloud})}):o?t.jsx(it,{children:t.jsx(gt,{children:o})}):u?t.jsx(it,{children:t.jsx(gt,{children:L.brain.cloud.waiting})}):null,t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:s,disabled:i||e}),u?t.jsx(lt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",children:L.brain.cloud.open}):o?t.jsx($,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{g.current=typeof window.open=="function"?window.open("","_blank"):null,m(j=>j+1)},children:L.brain.cloud.again}):null]})})]})}function Pne({answers:e,accounts:n,onKept:s,onTrouble:r}){var p;const a=e.brain,i=a?((n==null?void 0:n.accounts)??[]).find(g=>g.id===a.accountId):void 0,[l,o]=d.useState([]),[c,u]=d.useState(!1),h=Wy(i),f=(i==null?void 0:i.auth)==="device-key"||(i==null?void 0:i.kind)==="codex"||h||!!i&&OP(i,(p=n==null?void 0:n.gemini)==null?void 0:p.baseUrl);if(d.useEffect(()=>{if(!f||!i)return;let g=!1;return A.accountModels(i.id).then(x=>{const k=h?x.models.filter(j=>!rP({id:j.id,...j.image?{kind:"image"}:{}})):x.models;g||o(k.map(j=>j.id))}).catch(()=>{}),()=>{g=!0}},[f,i==null?void 0:i.id]),!f||!i||!a||l.length<2)return null;const m=g=>{g===a.model||c||(u(!0),r(null),(async()=>{try{await A.saveProviderAccount({id:i.id,revision:i.revision,label:i.label,kind:i.kind,auth:i.auth,baseUrl:i.baseUrl,defaultModel:g,enabled:i.enabled}),e.assistant&&await A.bindBrain({accountId:i.id,model:g}),s({...e,brain:{accountId:a.accountId,label:a.label,model:g}})}catch(x){r(x instanceof he?x.message:String(x))}finally{u(!1)}})())};return t.jsx(gt,{children:t.jsx(ie,{label:L.brain.model.change,children:t.jsx("select",{value:a.model,disabled:c,onChange:g=>m(g.target.value),children:(l.includes(a.model)?l:[a.model,...l]).map(g=>t.jsx("option",{value:g,children:g},g))})})})}const cC="gpt-5.5",Mne=2e3;function One({busy:e,consent:n,onBack:s,onConnected:r,accounts:a}){const[i,l]=d.useState(!0),[o,c]=d.useState(null),[u,h]=d.useState(null),[f,m]=d.useState(!1),[p,g]=d.useState(void 0),[x,k]=d.useState(0),j=d.useRef(-1),v=d.useRef(null),w=d.useRef(null),y=L.brain.chatgpt.label;d.useEffect(()=>()=>{const S=w.current;w.current=null,S&&A.codexAccountAction(S.id,"cancel-login",S.revision).catch(()=>{})},[]),d.useEffect(()=>{if(j.current===x)return;j.current=x,l(!0),c(null);const S=x===0?n:v.current;(async()=>{try{const C=((a==null?void 0:a.accounts)??[]).find(M=>M.kind==="codex"),T=C?{id:C.id}:await A.saveProviderAccount({label:y,kind:"codex",auth:"chatgpt",baseUrl:"",defaultModel:cC,enabled:!0}),E=(await A.providerAccounts()).accounts.find(M=>M.id===T.id),R=await A.codexAccountAction(E.id,"login",E.revision);if(!(R!=null&&R.verificationUrl)||!R.userCode)throw new Error((R==null?void 0:R.message)??L.brain.chatgpt.failed);w.current={id:E.id,revision:E.revision},h({id:E.id,revision:E.revision,url:R.verificationUrl,code:R.userCode}),m(!!S),S&&(S.location.href=R.verificationUrl)}catch(C){S==null||S.close(),c(C instanceof he||C instanceof Error?C.message:String(C))}finally{l(!1)}})()},[x]),d.useEffect(()=>{if(!u)return;let S=!1,C=!1;const T=async()=>{if(!(S||C)){C=!0;try{const R=(await A.providerAccounts()).accounts.find(O=>O.id===u.id);if(S)return;const M=R==null?void 0:R.login;if(!M||M.state==="pending")return;if(S=!0,w.current=null,h(null),M.state!=="connected"){c(M.message??L.brain.chatgpt.failed);return}g(M.account??null),l(!0),c(await N(u.id)),l(!1),g(void 0)}catch{}finally{C=!1}}},E=window.setInterval(()=>void T(),Mne);return()=>{S=!0,window.clearInterval(E)}},[u]);const N=async S=>{var C,T;try{const E=(await A.accountModels(S).catch(()=>({models:[]}))).models,R=((C=E.find(O=>O.isDefault))==null?void 0:C.id)??((T=E[0])==null?void 0:T.id)??cC,M=(await A.providerAccounts()).accounts.find(O=>O.id===S);return M&&M.defaultModel!==R&&await A.saveProviderAccount({id:M.id,revision:M.revision,label:M.label,kind:M.kind,auth:M.auth,baseUrl:M.baseUrl,defaultModel:R,enabled:M.enabled}),await r({accountId:S,label:y,model:R})}catch(E){return E instanceof he?E.message:String(E)}},b=()=>{const S=w.current;w.current=null,S&&A.codexAccountAction(S.id,"cancel-login",S.revision).catch(()=>{}),s()};return t.jsxs(t.Fragment,{children:[p!==void 0?t.jsxs(it,{children:[t.jsx(gt,{children:L.brain.chatgpt.signedIn(p)}),t.jsx(ms,{line:L.brain.checking.chatgpt})]}):i||e?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.chatgpt})}):o?t.jsx(it,{children:t.jsx(gt,{children:o})}):u?t.jsx(it,{children:f?t.jsx(ms,{line:L.brain.chatgpt.waiting}):t.jsx(gt,{children:L.brain.chatgpt.instruct})}):null,t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:b,disabled:i||e}),u?t.jsx(lt,{variant:"accent",size:"lg",href:u.url,target:"_blank",rel:"noreferrer",onClick:()=>m(!0),children:L.brain.chatgpt.open}):o?t.jsx($,{variant:"accent",size:"lg",disabled:i||e,onClick:()=>{v.current=typeof window.open=="function"?window.open("","_blank"):null,k(S=>S+1)},children:L.brain.chatgpt.again}):null]}),children:u?t.jsx(Ky,{code:u.code,label:L.brain.chatgpt.code,large:!0}):null})]})}const Dne="claude-sonnet-5";function Lne({busy:e,problem:n,onBack:s,onConnected:r,accounts:a,claudeModel:i}){const[l,o]=d.useState(!1),[c,u]=d.useState(null),[h,f]=d.useState(null),[m,p]=d.useState(""),g=d.useRef(null);d.useEffect(()=>()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{})},[]);const x=()=>{const w=g.current;g.current=null,w&&A.anthropicAccountAction(w.id,"cancel-login",w.revision).catch(()=>{}),s()},k=i??Dne,j=()=>{o(!0),u(null);const w=typeof window.open=="function"?window.open("","_blank"):null;(async()=>{try{const y=((a==null?void 0:a.accounts)??[]).find(T=>T.auth==="anthropic-oauth"),N=y?{id:y.id}:await A.saveProviderAccount({label:L.brain.claude.label,kind:"anthropic",auth:"anthropic-oauth",baseUrl:"",defaultModel:k,enabled:!0}),S=(await A.providerAccounts()).accounts.find(T=>T.id===N.id),C=await A.anthropicAccountAction(S.id,"login",S.revision);g.current={id:S.id,revision:S.revision+1},f({id:S.id,revision:S.revision+1,url:C.verificationUrl??"",attemptId:C.attemptId??""}),w&&C.verificationUrl?w.location.href=C.verificationUrl:w==null||w.close()}catch(y){w==null||w.close(),u(y instanceof he?y.message:String(y))}finally{o(!1)}})()},v=()=>{!h||m.trim()===""||(g.current=null,o(!0),(async()=>{try{await A.anthropicAccountAction(h.id,"complete-login",h.revision,{attemptId:h.attemptId,code:m.trim()});const w=await A.testProviderAccount(h.id);if(w.state!=="connected"){u(w.message);return}u(await r({accountId:h.id,label:L.brain.claude.label,model:k}))}catch(w){u(w instanceof he?w.message:String(w))}finally{o(!1)}})())};return t.jsxs(t.Fragment,{children:[l||e?t.jsx(it,{children:t.jsx(ms,{line:L.brain.checking.claude})}):n??c?t.jsx(it,{children:t.jsx(gt,{children:n??c})}):null,h?t.jsxs(t.Fragment,{children:[t.jsx(it,{children:t.jsx(gt,{children:L.brain.claude.waiting})}),t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:x,disabled:l}),t.jsx(lt,{size:"lg",href:h.url,target:"_blank",rel:"noreferrer",children:L.brain.claude.open}),t.jsx($,{variant:"accent",size:"lg",disabled:l||m.trim()==="",onClick:v,children:L.brain.claude.finish})]}),children:t.jsx(ie,{label:L.brain.claude.paste,grow:!0,children:t.jsx(Fne,{value:m,onChange:p})})})]}):t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:x,disabled:e||l}),t.jsx($,{variant:"accent",size:"lg",disabled:e||l,onClick:j,children:L.brain.claude.start})]})})]})}function Fne({value:e,onChange:n}){const s=Io();return t.jsx("input",{ref:s,type:"password",autoComplete:"off",spellCheck:!1,value:e,onChange:r=>n(r.target.value)})}const _ne={days:"calendar",mail:"mail",money:"money",voice:"bulb",code:"monitor",pictures:"files"};function zne(e){const n=(e==null?void 0:e.plugins)??[];if(n.length===0)return null;const s=n.map(a=>a.title),r=n.filter(a=>a.state==="failed");if(e!=null&&e.running){const a=n.filter(i=>i.state==="ready"||i.state==="failed").length;return{line:L.takeOn.fetching(s,Math.min(a+1,n.length),n.length),done:!1}}return r.length>0?{line:r.map(a=>L.takeOn.failed(a.title,a.reason??"")).join(" "),done:!0}:{line:L.takeOn.ready(s),done:!0}}function Une({answers:e,progress:n,offers:s,onProgress:r,onSettled:a,onBack:i,onTrouble:l}){const o=s?_h.filter(k=>s.includes(k.id)):_h,[c,u]=d.useState(()=>e.takeOn??[...S6]),[h,f]=d.useState(!1),m=o.filter(k=>c.includes(k.id)),p=k=>u(j=>j.includes(k)?j.filter(v=>v!==k):[...j,k]),g=k=>{h||(f(!0),Promise.resolve().then(()=>A.takeOn(k)).then(()=>{r(),a({...e,takeOn:k})}).catch(j=>l(j instanceof he?j.message:String(j))).finally(()=>f(!1)))},x=zne(n);return t.jsxs(t.Fragment,{children:[t.jsx(Mo,{children:L.takeOn.title}),t.jsx(it,{children:t.jsx(gt,{children:L.takeOn.ask})}),t.jsxs(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:i,disabled:h}),t.jsx($,{variant:"ghost",size:"lg",disabled:h,onClick:()=>g([]),children:L.takeOn.none}),t.jsx(Po,{onClick:()=>g(m.map(k=>k.id)),disabled:h||m.length===0,children:L.takeOn.submit})]}),children:[t.jsx("div",{className:"wiz-grid","data-cols":"3",role:"group","aria-label":L.takeOn.title,children:o.map(k=>{const j=c.includes(k.id);return t.jsxs("button",{type:"button",className:"wiz-opt","data-tile":"true","aria-pressed":j,onClick:()=>p(k.id),children:[t.jsxs("span",{className:"wiz-tile-top",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(oe,{name:_ne[k.id]})}),t.jsx("span",{className:"wiz-tick","aria-hidden":"true",children:j?t.jsx(oe,{name:"check",size:12}):null})]}),t.jsxs("span",{children:[t.jsx("span",{className:"wiz-opt-title",children:k.title}),t.jsx("span",{className:"wiz-opt-plugins",children:k.plugins})]}),t.jsx("span",{className:"wiz-opt-line",children:k.line})]},k.id)})}),m.length>0?t.jsxs("div",{className:"wiz-stack",children:[x?t.jsxs("div",{className:"wiz-busy","data-boxed":"true",role:"status",children:[t.jsxs("span",{className:"wiz-pulse","data-done":x.done?"true":void 0,"aria-hidden":"true",children:[t.jsx("i",{}),t.jsx("i",{}),t.jsx("i",{})]}),t.jsx("span",{children:x.line}),c.includes("mail")?t.jsx("span",{className:"wiz-busy-side",children:L.takeOn.builtIn}):null]}):null,t.jsx("div",{className:"wiz-foot",children:m.map(k=>k.note).join(" ")})]}):t.jsx("div",{className:"wiz-foot",children:L.takeOn.nothing})]})]})}function Bne({answers:e,progress:n,onSettled:s,onBack:r}){var x,k,j;const[a,i]=d.useState(((x=e.reach)==null?void 0:x.phone)===!0),[l,o]=d.useState(((k=e.reach)==null?void 0:k.mailbox)===!0),[c,u]=d.useState(((j=e.reach)==null?void 0:j.app)===!0),[h,f]=d.useState(e.browser),m=e.takeOn??[],p=m.includes("mail"),g=()=>{const v={phone:a,mailbox:l,app:c,browser:h==="chrome"||h==="chromium"||h==="installed"};h!==void 0&&Promise.resolve().then(()=>A.onboardingStep("browser")).catch(()=>{}),s({...e,reach:v,...h!==void 0?{browser:h}:{}})};return t.jsxs(t.Fragment,{children:[t.jsx(Mo,{children:L.reach.title}),t.jsx(it,{children:t.jsx(gt,{children:L.reach.ask})}),t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:r}),t.jsx(Po,{onClick:g,children:L.reach.submit})]}),children:t.jsxs("div",{className:"wiz-rows",children:[t.jsx(Wne,{paired:a,owner:e.name,onPaired:()=>i(!0)}),t.jsx(Hne,{wanted:p,added:l,onAdded:o}),m.includes("days")?t.jsx(Kne,{progress:n}):null,m.includes("money")?t.jsx(Vne,{}):null,t.jsx(Gne,{app:c,onApp:()=>u(!0),browser:h,onBrowser:f}),a?t.jsx(G,{tone:"good",role:"status",children:L.reach.phone.hello}):null]})})]})}function Wne({paired:e,owner:n,onPaired:s}){const[r,a]=d.useState(null),[i,l]=d.useState(!1),o=d.useRef(s);o.current=s,d.useEffect(()=>{let u=!1;return Promise.resolve().then(()=>A.telegram()).then(h=>{u||!h||(a(h),h.paired&&o.current())}).catch(()=>{u||a({configured:!1,running:!1,paired:!1})}),()=>{u=!0}},[]);const c=(r==null?void 0:r.configured)===!0&&r.running===!0;return t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","aria-hidden":"true",children:t.jsx(oe,{name:"chat"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:L.reach.phone.title}),t.jsx("span",{className:"wiz-opt-line",children:L.reach.phone.line})]}),t.jsx("span",{className:"wiz-row-side",children:e?t.jsx(Ae,{tone:"good",dot:!0,children:L.reach.phone.paired}):t.jsx($,{size:"lg",disabled:r===null,onClick:()=>l(!0),children:c?L.reach.phone.pair:L.reach.phone.setUp})}),i?t.jsx(Ye,{title:L.telegram.sheet,onClose:()=>l(!1),children:t.jsx(Zne,{ready:c,owner:n,onPaired:s,onDismiss:()=>l(!1)})}):null]})}function Hne({wanted:e,added:n,onAdded:s}){const r=zM("email"),[a,i]=d.useState(!1),[l,o]=d.useState(null);return d.useEffect(()=>{Promise.resolve().then(()=>A.pageQuery("email","accounts")).then(c=>{var h,f,m;const u=((m=(f=(h=c==null?void 0:c.data)==null?void 0:h.accounts)==null?void 0:f[0])==null?void 0:m.address)??null;o(u),s(u!==null)}).catch(()=>{})},[]),t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"mail","aria-hidden":"true",children:t.jsx(oe,{name:"mail"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:e?L.reach.mailbox.forTriage:L.reach.mailbox.title}),t.jsx("span",{className:"wiz-opt-line",children:r===!1?L.reach.mailbox.unavailable:L.reach.mailbox.line})]}),t.jsx("span",{className:"wiz-row-side",children:n||l?t.jsx(Ae,{tone:"good",dot:!0,mono:l!==null,children:l??L.reach.mailbox.added}):r?t.jsx($,{size:"lg",onClick:()=>i(!0),children:L.reach.mailbox.add}):null}),a?t.jsx(nne,{onClose:()=>i(!1),onAdded:c=>{o(c),s(!0)}}):null]})}function zM(e,n){const[s,r]=d.useState(void 0),a=(n==null?void 0:n.plugins.map(i=>`${i.title}:${i.state}`).join(","))??"";return d.useEffect(()=>{if(s)return;let i=!1;return Promise.resolve().then(()=>A.pages()).then(l=>{i||r(((l==null?void 0:l.pages)??[]).some(o=>o.plugin===e&&o.id==="settings"))}).catch(()=>{i||r(!1)}),()=>{i=!0}},[e,a]),s}function Kne({progress:e}){const n=zM("calendar",e),[s,r]=d.useState(!1),[a,i]=d.useState(!1);return d.useEffect(()=>{n&&Promise.resolve().then(()=>A.pageQuery("calendar","settings")).then(l=>{var o,c;(((c=(o=l==null?void 0:l.data)==null?void 0:o.calendars)==null?void 0:c.length)??0)>0&&i(!0)}).catch(()=>{})},[n]),t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"calendar","aria-hidden":"true",children:t.jsx(oe,{name:"calendar"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:L.reach.calendar.title}),t.jsx("span",{className:"wiz-opt-line",children:n===!1?L.reach.calendar.waiting:L.reach.calendar.line})]}),t.jsx("span",{className:"wiz-row-side",children:a?t.jsx(Ae,{tone:"good",dot:!0,children:L.reach.calendar.linked}):t.jsx($,{size:"lg",disabled:!n,onClick:()=>r(!0),children:L.reach.calendar.add})}),s?t.jsx(ine,{onClose:()=>r(!1),onLinked:()=>i(!0)}):null]})}function Vne(){const[e,n]=d.useState(!1),[s,r]=d.useState(!1);return t.jsxs("div",{className:"wiz-row",children:[t.jsx("span",{className:"wiz-glyph","data-tone":"finance","aria-hidden":"true",children:t.jsx(oe,{name:"money"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:L.reach.bank.title}),t.jsx("span",{className:"wiz-opt-line",children:L.reach.bank.line})]}),t.jsx("span",{className:"wiz-row-side",children:s?t.jsx(Ae,{dot:!0,children:L.reach.bank.later}):t.jsx($,{size:"lg",onClick:()=>n(!0),children:L.reach.bank.add})}),e?t.jsx(lne,{onClose:()=>n(!1),onUnderstood:()=>r(!0)}):null]})}function Gne({app:e,onApp:n,browser:s,onBrowser:r}){const a=mI(),i=jm(),l=a?null:i,o=typeof navigator>"u"?null:pI(navigator.userAgent),[c,u]=d.useState(null),[h,f]=d.useState("idle"),[m,p]=d.useState(null),[g,x]=d.useState(null),[k,j]=d.useState(void 0),v=d.useRef(!1),w=d.useRef(!0);d.useEffect(()=>(w.current=!0,Promise.resolve().then(()=>A.browser()).then(E=>{var M;if(!w.current)return;const R=E==null?void 0:E.browser;R?((M=R.install)==null?void 0:M.state)==="running"?(u("none"),v.current=!0,f("installing"),b()):u(R.engine):u("other")}).catch(()=>{w.current&&u("other")}),()=>{w.current=!1}),[]);const y=(E,R)=>{w.current&&(v.current=!1,f("failed"),p(E),x(R??null))},N=async E=>{f("launching");let R;try{R=await A.browserCheck()}catch(M){return y(M instanceof he?M.message:String(M))}if(w.current){if(R.ok){f("idle"),u(E),r(v.current?"installed":E);return}y(R.message,R.command)}},b=async()=>{var M,O;let E;try{E=await A.browser()}catch(I){return y(I instanceof he?I.message:String(I))}if(!w.current)return;const R=E.browser;if(!R)return y(L.browser.failed(""));if(((M=R.install)==null?void 0:M.state)==="running"){f("installing"),j(R.install.progress),window.setTimeout(()=>void b(),1e3);return}return R.engine!=="none"?N(R.engine):y(((O=R.install)==null?void 0:O.line)??"")},S=()=>{if(x(null),c==="chrome"||c==="chromium"){N(c);return}v.current=!0,f("installing"),j(void 0),Promise.resolve().then(()=>A.browserInstall()).then(()=>{w.current&&window.setTimeout(()=>void b(),1e3)}).catch(E=>y(E instanceof he?E.message:String(E)))},C=s==="chrome"||s==="chromium"||s==="installed",T=h==="installing"||h==="launching";return t.jsxs("div",{className:"wiz-row","data-wrap":h!=="idle"?"true":void 0,children:[t.jsx("span",{className:"wiz-glyph","data-tone":"good","aria-hidden":"true",children:t.jsx(oe,{name:"globe"})}),t.jsxs("span",{className:"wiz-row-text",children:[t.jsx("span",{className:"wiz-opt-title",children:a?L.reach.app.inApp.title:L.reach.app.title}),t.jsx("span",{className:"wiz-opt-line",children:a?L.reach.app.inApp.line:L.reach.app.line})]}),t.jsxs("span",{className:"wiz-row-side",children:[a?t.jsx(lt,{size:"lg",href:aR,target:"_blank",rel:"noreferrer",children:L.reach.app.inApp.extension}):e?t.jsx(Ae,{tone:"good",dot:!0,children:L.reach.app.installed}):l?t.jsx($,{size:"lg",onClick:()=>{l.prompt().then(()=>l.userChoice).then(E=>{(!E||E.outcome==="accepted")&&n()}).catch(()=>{})},children:L.reach.app.install}):null,C?t.jsx(Ae,{tone:"good",dot:!0,children:L.reach.app.ready(s==="chrome"?"chrome":"chromium")}):c===null||c==="other"?null:t.jsx($,{size:"lg",disabled:T,onClick:S,children:T?L.browser.installing:h==="failed"?L.browser.retry:c==="chrome"?L.reach.app.chrome:c==="chromium"?L.reach.app.chromium:L.reach.app.fetch})]}),!e&&!l&&o?t.jsx("span",{className:"wiz-row-note",children:o}):null,h==="installing"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:L.browser.needs}),t.jsx(cne,{progress:k})]}):h==="launching"?t.jsx("div",{className:"wiz-row-more",children:t.jsx(ms,{line:L.browser.launching})}):h==="failed"?t.jsxs("div",{className:"wiz-row-more",children:[t.jsx("span",{className:"wiz-opt-line",children:L.browser.failed(m??"")}),g?t.jsx(Qne,{command:g}):null]}):null]})}function Yne({answers:e,existing:n,navigate:s,onSettled:r,onTrouble:a,onReload:i,onBack:l}){const[o,c]=d.useState(()=>(n==null?void 0:n.name)??v6),[u,h]=d.useState(()=>n!=null&&n.picture||n!=null&&n.avatar?null:"buddi"),[f,m]=d.useState(n?null:L.assistant.purposeValue),[p,g]=d.useState(n?"":L.assistant.purposeValue);d.useEffect(()=>{if(!n)return;let b=!1;return A.firstAgentPersona().then(S=>{b||(m(S.persona),g(S.persona))},S=>{b||a(S instanceof he?S.message:String(S))}),()=>{b=!0}},[n==null?void 0:n.id]);const[x,k]=d.useState(!1),[j,v]=d.useState(null),w=_h.filter(b=>(e.takeOn??[]).includes(b.id)&&"mate"in b).map(b=>b.mate),y=U0.find(b=>b.id===u),N=()=>{if(o.trim()===""||x)return;k(!0);const b=!n||f!==null&&p.trim()!==""&&p.trim()!==f.trim()?{instructions:p.trim()}:{},S=n?A.updateFirstAgent({name:o.trim(),...b}):A.createFirstAgent({name:o.trim(),handle:pne(o),description:"",...b,...e.brain?{accountId:e.brain.accountId}:{}});(async()=>{var E;let C;try{C=await S}catch(R){R instanceof he&&R.status===409&&((E=R.detail)==null?void 0:E.code)==="assistant-exists"?(v(R.message),a(null)):a(R instanceof he?R.message:String(R)),k(!1);return}let T=null;try{y&&await A.uploadAgentPicture(C.id,await xP(y.role))}catch(R){T=R instanceof he?R.message:String(R)}k(!1),i(),r({...e,assistant:{id:C.id,name:o.trim(),avatar:y?"":(n==null?void 0:n.avatar)??""}}),T&&a(T)})()};return t.jsxs(t.Fragment,{children:[t.jsx(Mo,{children:L.assistant.title}),t.jsx(it,{children:t.jsxs(gt,{children:[L.assistant.ask,w.length>0?L.assistant.team(w):""]})}),t.jsxs(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($s,{onClick:l,disabled:x}),t.jsx(Po,{onClick:N,disabled:x||j!==null||o.trim()===""||f===null,children:L.assistant.submit})]}),children:[t.jsxs("div",{className:"wiz-meet",children:[t.jsxs("div",{className:"wiz-face",children:[t.jsx("span",{className:"wiz-face-tile","data-agent":(y==null?void 0:y.id)??"buddi","aria-hidden":"true",children:y?t.jsx("img",{src:el(y.role),alt:""}):n!=null&&n.picture?t.jsx("img",{src:n.picture,alt:""}):t.jsx("span",{className:"wiz-face-emoji",children:(n==null?void 0:n.avatar)??""})}),t.jsx("div",{className:"wiz-swatches",role:"group","aria-label":L.assistant.colour,children:U0.map(b=>t.jsx("button",{type:"button",className:"wiz-swatch","data-agent":b.id,"aria-label":L.assistant.swatch(b.label),"aria-pressed":u===b.id,onClick:()=>h(b.id)},b.id))}),t.jsx("span",{className:"wiz-face-cap",children:L.assistant.colour})]}),t.jsxs("div",{className:"wiz-stack",children:[t.jsx(ie,{label:L.assistant.name,children:t.jsx("input",{value:o,maxLength:60,onChange:b=>c(b.target.value)})}),t.jsx(ie,{label:L.assistant.purpose,hint:L.assistant.purposeHint,children:t.jsx("textarea",{className:"wiz-persona",value:p,maxLength:8e3,rows:7,onChange:b=>g(b.target.value)})})]})]}),j?t.jsx(G,{tone:"warm",role:"status",title:L.assistant.refusedTitle,action:t.jsx(lt,{href:bt,onClick:b=>{b.preventDefault(),s(bt)},children:L.assistant.toAgents}),children:j}):null]})]})}function qne({answers:e,assistantAgent:n,met:s,onMet:r,navigate:a,onPickAnotherBrain:i,onSpoken:l,progress:o,onProgress:c}){var z,U;const u=e.assistant,[h,f]=d.useState(s),[m,p]=d.useState([]),[g,x]=d.useState(!1),[k,j]=d.useState(!1),[v,w]=d.useState(!0),[y,N]=d.useState(!1),b=d.useRef(!1),S=d.useMemo(()=>n?[n]:[],[n]);d.useEffect(()=>{c()},[]),d.useEffect(()=>{if(!u||b.current)return;if(b.current=!0,s){f(s);return}let D=!1;return(async()=>{try{const P=await Je.startConversation(u.id);if(D)return;f(P.conversationId),r(P.conversationId),await A.onboardingStep(IM.handover,{conversationId:P.conversationId}).catch(()=>{}),await Je.send(u.id,{conversationId:P.conversationId,text:b6,opening:!0})}catch{D||(w(!1),x(!0))}})(),()=>{D=!0}},[u==null?void 0:u.id,s]),d.useEffect(()=>{if(!h)return;let D=!1;const P=Date.now(),K=()=>{Je.conversation(h).then(Q=>{if(D)return;p(Q.messages);const _=Date.now()-P;if(Q.messages.some(uC)){w(!1),x(!1),j(!1);return}const re=Q.runs??[],Y=re.some(q=>q.finishedAt===null),B=re.length>0&&!Y;j(Y&&_>=gne),(B||_>=xne)&&(w(!1),x(!0))}).catch(()=>{})};K();const F=window.setInterval(K,LM);return()=>{D=!0,window.clearInterval(F)}},[h]);const C=u&&h?at(u.id,h):null,T=m.some(uC);d.useEffect(()=>{T&&C&&l(C)},[T,C,l]);const E=e.takeOn??[],R=L.handover.starters({days:E.includes("days"),mail:E.includes("mail"),mailbox:((z=e.reach)==null?void 0:z.mailbox)===!0}),M={days:E.includes("days"),mailbox:((U=e.reach)==null?void 0:U.mailbox)===!0,money:E.includes("money"),pictures:E.includes("pictures")},O=(o==null?void 0:o.waiting)??[],I=D=>{!u||!h||y||(N(!0),Promise.resolve().then(()=>Je.send(u.id,{conversationId:h,text:D})).then(()=>a(at(u.id,h),!0)).catch(()=>N(!1)))};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"wiz-hello",children:t.jsx(ly,{messages:m,live:[],now:Date.now(),onOpen:()=>{},working:v,agents:S,agentName:(u==null?void 0:u.name)??"",...u?{agentId:u.id}:{},emptyHint:L.handover.waiting,plain:!0,workingLine:L.handover.looking((u==null?void 0:u.name)??"")})}),k&&!g?t.jsx(it,{children:t.jsx(gt,{children:L.handover.slow})}):null,g?t.jsxs(t.Fragment,{children:[t.jsx(it,{children:t.jsx(gt,{children:L.handover.silent})}),t.jsx(wn,{actions:t.jsx(Po,{onClick:i,children:L.handover.again})})]}):null,T?t.jsx("div",{className:"wiz-starters",role:"group","aria-label":L.handover.starterLabel,children:R.map(D=>t.jsx("button",{type:"button",className:"wiz-starter",disabled:y,onClick:()=>I(D),children:D},D))}):null,T?t.jsx(dJ,{setUp:M,navigate:D=>a(D,!0)}):null,T&&O.length>0?t.jsx(G,{tone:"warm",title:L.handover.waitingTitle(O.length),action:t.jsx($,{variant:"accent",onClick:()=>a($n,!0),children:L.handover.home}),children:L.handover.waitingBody(O)}):null,T&&C?t.jsx(wn,{actions:t.jsx(lt,{variant:"accent",size:"lg",href:C,onClick:D=>{D.preventDefault(),a(C,!0)},children:L.done.open})}):null]})}function Qne({command:e}){const[n,s]=d.useState("idle"),r=()=>{var a;if(!((a=navigator.clipboard)!=null&&a.writeText)){s("failed");return}navigator.clipboard.writeText(e).then(()=>s("done"),()=>s("failed"))};return t.jsxs(ue,{gap:"sm",children:[t.jsx(zt,{label:"The command to run",children:e}),t.jsxs(ne,{align:"end",children:[n==="failed"?t.jsx("span",{className:"ui-toolbar-note",children:"Select it to copy."}):null,t.jsx($,{size:"sm",onClick:r,children:n==="done"?"Copied":"Copy"})]})]})}function uC(e){return e.role==="assistant"&&(e.blocks??[]).some(n=>n.type==="text"&&n.text.trim()!=="")}function Jne({onCancel:e,onStarted:n,onTrouble:s}){const[r,a]=d.useState(null),[i,l]=d.useState(""),[o,c]=d.useState(!1),u=()=>{!r||o||(c(!0),s(null),A.firstRunRestore(r,i.trim()).then(h=>{nj(h.job.id),n()}).catch(h=>s(h instanceof he?h.message:String(h))).finally(()=>c(!1)))};return t.jsx(Ye,{title:L.restore.sheet,onClose:e,children:t.jsxs("div",{className:"wiz-restore",children:[t.jsx("p",{className:"wiz-foot",children:L.restore.lede}),t.jsx(ie,{label:L.restore.file,children:t.jsx("input",{type:"file",onChange:h=>{var f;return a(((f=h.target.files)==null?void 0:f[0])??null)}})}),t.jsx(ie,{label:L.restore.passphrase,hint:L.restore.passphraseHint,children:t.jsx("input",{type:"password",autoComplete:"off",value:i,onChange:h=>l(h.target.value)})}),t.jsxs(ne,{align:"end",children:[t.jsx($,{variant:"ghost",onClick:e,children:L.restore.cancel}),t.jsx($,{variant:"accent",disabled:o||!r,onClick:u,children:L.restore.submit})]})]})})}function Xne({onDone:e,onFailed:n}){const[s,r]=d.useState([]),a=d.useRef({onDone:e,onFailed:n});a.current={onDone:e,onFailed:n},d.useEffect(()=>{const l=DM();if(!l)return;let o=!1;const c=()=>{A.backupJob(l).then(h=>{o||(r(f=>f.includes(h.phase)?f:[...f,h.phase]),h.phase==="done"?(o=!0,nj(null),A.owner().then(f=>a.current.onDone(f.preferredName??void 0),()=>a.current.onDone(void 0))):(h.phase==="rolled-back"||h.phase==="failed")&&(o=!0,nj(null),a.current.onFailed(h.error??L.restore.phases[h.phase])))}).catch(()=>{})};c();const u=window.setInterval(c,LM);return()=>{o=!0,window.clearInterval(u)}},[]);const i=s.filter(l=>l in L.restore.phases);return t.jsxs(t.Fragment,{children:[t.jsx(Mo,{children:L.restore.title}),t.jsxs(it,{children:[t.jsx(gt,{children:L.restore.started}),i.map(l=>t.jsx(gt,{children:L.restore.phases[l]},l))]}),t.jsx(ms,{})]})}function Zne(e){return t.jsx(ub.Provider,{value:null,children:t.jsx("div",{className:"wiz-sheet-body",children:t.jsx(tse,{...e})})})}const ese=1600;function tse({ready:e,owner:n,onPaired:s,onDismiss:r}){const a=Io(),[i,l]=d.useState(""),[o,c]=d.useState(!1),[u,h]=d.useState(null),[f,m]=d.useState(null),{offer:p,square:g,paired:x,stale:k,ask:j}=CM(()=>A.telegram().then(b=>b.paired),s),v=d.useRef(!1);d.useEffect(()=>{!e||v.current||(v.current=!0,Promise.resolve().then(()=>A.telegramBot()).then(b=>m((b==null?void 0:b.username)??null)).catch(()=>{}),j().catch(b=>h(b instanceof he?b.message:String(b))))},[e,j]);const w=d.useRef(r);w.current=r,d.useEffect(()=>{if(!x)return;const b=window.setTimeout(()=>w.current(),ese);return()=>window.clearTimeout(b)},[x]);const y=()=>{i.trim()===""||o||(c(!0),h(null),(async()=>{try{const b=await A.saveTelegramToken(i.trim());if(l(""),m(b.botUsername??null),b.restartNeeded){h(b.note??L.telegram.restart);return}await j()}catch(b){h(b instanceof he?b.message:String(b))}finally{c(!1)}})())},N=()=>{h(null),j().catch(b=>h(b instanceof he?b.message:String(b)))};return p?t.jsxs(t.Fragment,{children:[t.jsx(it,{children:t.jsx(gt,{children:k&&!x?L.telegram.expired:L.telegram.scan})}),t.jsx(wn,{actions:x?t.jsx($,{variant:"accent",onClick:r,children:L.telegram.close}):t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:L.telegram.notNow}),k?t.jsx($,{variant:"accent",onClick:N,children:L.telegram.newCode}):null]}),children:k&&!x?null:t.jsx(ote,{offer:p,square:g,bot:f,paired:x,status:x?L.telegram.pairedWith(n):L.telegram.waiting})})]}):e&&!u?t.jsx(it,{children:t.jsx(ms,{line:L.telegram.making})}):e?t.jsxs(t.Fragment,{children:[t.jsx(it,{children:t.jsx(gt,{children:u})}),t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:L.telegram.notNow}),t.jsx($,{variant:"accent",onClick:N,children:L.telegram.newCode})]})})]}):t.jsxs(t.Fragment,{children:[t.jsxs(it,{children:[t.jsx(gt,{children:L.telegram.how}),u?t.jsx(gt,{children:u}):null]}),t.jsx(wn,{actions:t.jsxs(t.Fragment,{children:[t.jsx($,{variant:"ghost",onClick:r,children:L.telegram.notNow}),t.jsx($,{variant:"accent",disabled:o||i.trim()==="",onClick:y,children:L.telegram.submit})]}),children:t.jsx(ie,{label:L.telegram.field,grow:!0,children:t.jsx("input",{ref:a,type:"password",value:i,autoComplete:"off",spellCheck:!1,onChange:b=>l(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),y())}})})})]})}const gg={recovery:0,lost:1,paused:2},nse="Lost buddi. Retrying…",sse="The queue is paused. Nothing is being claimed until you resume it.";function rse(e){const n=[];return e.recovery&&n.push({id:"recovery",priority:gg.recovery,tone:"warning",text:bP,action:{label:"Finish the checklist",href:Wx}}),e.lost&&n.push({id:"lost",priority:gg.lost,tone:"critical",text:nse}),e.paused&&n.push({id:"paused",priority:gg.paused,tone:"warning",text:sse,action:{label:"Resume",onClick:()=>{A.setPaused(!1).catch(()=>{})}}}),n}function ase({banners:e,onNavigate:n}){if(e.length===0)return null;const s=[...e].sort((l,o)=>l.priority-o.priority),r=s[0],a=s.slice(1),i=r.action;return t.jsxs("div",{className:"shell-banner",role:"status","data-tone":r.tone,"data-banner":r.id,children:[t.jsx("span",{className:"shell-banner-dot","aria-hidden":"true"}),t.jsx("span",{className:"shell-banner-text",children:r.text}),a.length>0?t.jsxs("span",{className:"shell-banner-more",title:a.map(l=>l.text).join(`
|
|
146
|
-
`),children:["+",a.length," more"]}):null,i!=null&&i.href?t.jsx(lt,{size:"sm",href:i.href,onClick:l=>{l.preventDefault(),n(i.href)},children:i.label}):i?t.jsx($,{size:"sm",onClick:i.onClick,children:i.label}):null]})}const UM=1e4,ise=3e4,BM=6e3,db=/^(localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)$|\.localhost$/i;function lse(e){return db.test(e)?t.jsxs(t.Fragment,{children:["Is buddi running on this Mac? ",t.jsx("code",{children:"buddi status"})," says."]}):t.jsx(t.Fragment,{children:"Is Tailscale on, and the Mac it runs on awake?"})}async function WM(e){let n;const s=new Promise((r,a)=>{n=setTimeout(()=>a(new he(0,Mh)),e)});try{return{up:!0,version:await Promise.race([A.version(),s])}}catch(r){return Oh(r)?{up:!1}:{up:!0}}finally{clearTimeout(n)}}function HM(e){var n;return e.up&&_w((n=e.version)==null?void 0:n.web)?(window.location.reload(),!1):e.up}function ose({host:e,onRetry:n,retrying:s}){return t.jsxs("main",{className:"unreachable",role:"alert",children:[t.jsx("span",{className:"ui-blob","data-size":"lg","aria-hidden":"true",children:t.jsx("img",{src:el("core"),alt:""})}),t.jsxs("h1",{children:["buddi isn't answering at ",e,"."]}),t.jsx("p",{children:lse(e.replace(/:\d+$/,""))}),t.jsx("div",{className:"unreachable-actions",children:t.jsx($,{variant:"accent",onClick:n,disabled:s,children:s?"Retrying…":"Retry"})})]})}function cse({children:e}){const[n,s]=d.useState("checking"),[r,a]=d.useState(!1),i=d.useRef(!1),l=d.useCallback(async()=>{if(i.current)return;i.current=!0,a(!0);const o=await WM(BM);i.current=!1,a(!1),s(c=>c==="checking"?o.up?"up":"down":HM(o)?"up":"down")},[]);return d.useEffect(()=>{l()},[l]),d.useEffect(()=>{if(n!=="down")return;const o=window.setInterval(()=>void l(),UM);return()=>window.clearInterval(o)},[n,l]),n==="checking"?null:n==="down"?t.jsx(ose,{host:window.location.host,onRetry:()=>void l(),retrying:r}):t.jsx(t.Fragment,{children:e})}function use(e=ise){const[n,s]=d.useState(!1);return d.useEffect(()=>{let r;const a=()=>{clearTimeout(r);const l=Jc();if(l===null)return s(!1);const o=l+e-Date.now();o<=0?s(!0):r=setTimeout(a,o)};a();const i=xw(a);return()=>{i(),clearTimeout(r)}},[e]),n}function dse(){const e=use();return d.useEffect(()=>{if(!e)return;const n=window.setInterval(()=>{WM(BM).then(HM)},UM);return()=>window.clearInterval(n)},[e]),e}const hse={local:"Local",tailnet:"Tailnet",reconnecting:"Reconnecting…"},dC=(e,n,s=`${n}s`)=>e===1?n:s;function fse(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function mse(e){return e.includes("/")?e.split("/").pop().replace(/_/g," "):e}function pse(e,n){return n?"reconnecting":db.test(e)?"local":"tailnet"}function KM(e,n,s=fse()){const r=[],a=hse[e.link];if(r.push({key:"link",route:Fe("system"),dot:e.link==="reconnecting"?"warning":"good",text:a,label:`Connection: ${a}`}),e.focus){const u=`${Ai[e.focus.mode]} ${uu(e.focus,e.timezone,n)}`;r.push({key:"focus",route:Fe("notifications"),icon:"moon",text:u,label:`Focus: ${u}`})}const i=[];if(e.working>0&&i.push({key:"working",dot:"working",text:`${e.working} ${dC(e.working,"agent")} working`}),i.push(e.paused?{key:"queue",tone:"warning",text:"Queue paused"}:{key:"queue",text:"Queue running"}),e.failed>0&&i.push({key:"failed",tone:"critical",text:`${e.failed} failed`}),r.push({key:"work",route:e.failed>0?`${At}/jobs?state=failed`:`${At}/jobs`,parts:i,label:`Work: ${i.map(u=>u.text).join(", ")}`}),e.approvals>0){const u=`${dC(e.approvals,"approval")} waiting`;r.push({key:"approvals",route:to,count:e.approvals,text:u,label:`${e.approvals} ${u}`})}if(e.version){const u=e.version.updateAvailable&&e.version.latest?e.version.latest:null;r.push({key:"version",route:Fe("system"),end:!0,mono:`buddi ${e.version.current}`,update:u!==null,label:`buddi ${e.version.current}${u?`, a newer buddi is ready: ${u}`:""}`})}const l=e.timezone||s,o=Tt(n,l),c=l!==s;return r.push({key:"time",route:Fe("you"),end:!0,time:o,...c?{zone:mse(l)}:{},label:`Your time: ${o}${c?`, ${l}`:""}`}),r}function gse(e){var n;return e.link==="reconnecting"||e.failed>0?"critical":e.paused?"warning":e.approvals>0||(((n=e.version)==null?void 0:n.updateAvailable)??!1)?"attention":"good"}function VM(){const[e,n]=d.useState(()=>new Date);return d.useEffect(()=>{let s;const r=()=>{s=setTimeout(()=>{n(new Date),r()},6e4-Date.now()%6e4)};return r(),()=>clearTimeout(s)},[]),e}function xse(){const[e,n]=d.useState(()=>Jc()!==null);return d.useEffect(()=>xw(()=>n(Jc()!==null)),[]),e}function GM({item:e}){var n;return t.jsxs(t.Fragment,{children:[e.dot?t.jsx("span",{className:"shell-status-dot","data-tone":e.dot,"aria-hidden":"true"}):null,e.icon?t.jsx(oe,{name:e.icon,size:12}):null,e.count?t.jsx("span",{className:"ui-badge","aria-hidden":"true",children:e.count>99?"99+":e.count}):null,(n=e.parts)==null?void 0:n.map((s,r)=>t.jsxs(d.Fragment,{children:[r>0?t.jsx("span",{className:"shell-status-sep","aria-hidden":"true",children:"·"}):null,s.dot?t.jsx("span",{className:"shell-status-dot","data-tone":s.dot,"aria-hidden":"true"}):null,t.jsx("span",{"data-tone":s.tone,children:s.text})]},s.key)),e.text?t.jsx("span",{children:e.text}):null,e.mono?t.jsx("span",{className:"shell-status-mono",children:e.mono}):null,e.update?t.jsx("span",{className:"ui-badge","data-kind":"dot","data-testid":"status-update-dot","aria-hidden":"true"}):null,e.time?t.jsx("span",{className:"shell-status-time",children:e.time}):null,e.zone?t.jsx("span",{className:"shell-status-zone",children:e.zone}):null]})}function vse({status:e,onNavigate:n}){const s=VM(),r=bm(),a=KM(e,s),i=l=>t.jsx("a",{className:"shell-status-item","data-item":l.key,href:l.route,"aria-label":l.label,title:l.label,onClick:o=>{o.preventDefault(),n(l.route)},children:t.jsx(GM,{item:l})},l.key);return t.jsxs("footer",{className:"shell-status","aria-label":"Status",children:[a.filter(l=>!l.end).map(i),t.jsx("span",{className:"shell-status-spacer"}),a.filter(l=>l.end).map(i),r.pin?t.jsx("button",{type:"button",className:"shell-status-item shell-status-lock","data-item":"lock","aria-label":`Lock now (${r.shortcut})`,title:`Lock now (${r.shortcut})`,onClick:()=>r.lockNow(),children:t.jsx(oe,{name:"lock",size:13})}):null]})}function jse({status:e,onNavigate:n}){const s=VM(),r=bm(),a=gse(e);return t.jsx("div",{className:"rail-status",children:t.jsxs(Su,{modal:!1,children:[t.jsx(Cu,{asChild:!0,children:t.jsx("button",{type:"button",className:"rail-status-btn","aria-label":"Status",children:t.jsx("span",{className:"rail-status-dot","data-tone":a,"data-testid":"rail-status-dot","aria-hidden":"true"})})}),t.jsx(ko,{children:t.jsxs(Eu,{className:"ui-menu rail-status-menu",side:"right",align:"end",sideOffset:10,children:[t.jsx(Wi,{className:"ui-menu-label",children:"Status"}),KM(e,s).map(i=>t.jsx(Bs,{asChild:!0,onSelect:()=>n(i.route),children:t.jsx("a",{className:"ui-menu-item rail-status-item","data-item":i.key,href:i.route,"aria-label":i.label,children:t.jsx("span",{className:"rail-status-line",children:t.jsx(GM,{item:i})})})},i.key)),r.pin?t.jsxs(t.Fragment,{children:[t.jsx(la,{className:"ui-menu-sep"}),t.jsx(Bs,{className:"ui-menu-item rail-status-item","data-item":"lock",onSelect:()=>r.lockNow(),children:t.jsxs("span",{className:"rail-status-line",children:[t.jsx(oe,{name:"lock",size:12}),t.jsx("span",{children:"Lock now"})]})})]}):null]})})]})})}const wse=1e4;function YM(){return d.useSyncExternalStore(HU,F0,F0)}function yse(e){switch(e.kind){case"plugins":return{title:"Restarting buddi",line:e.line??"Loading your plugins…"};case"upgrade":return{title:"Upgrading buddi",line:e.line??"Upgrading…"};case"restore":return{title:"Restoring buddi",line:e.line??"Putting your backup in place…"};case"recovery":return{title:"Restarting buddi",line:e.line??"Turning schedules, watchers and the phone back on…"};case"stop":return{title:"buddi is stopped",line:"This page comes back by itself once buddi is started again."};default:return{title:"Restarting buddi",line:e.line??"Back in a few seconds…"}}}function hC(e){const n=Math.max(0,Math.floor(e/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function bse({command:e}){const[n,s]=d.useState(!1);return d.useEffect(()=>{if(!n)return;const r=window.setTimeout(()=>s(!1),1600);return()=>window.clearTimeout(r)},[n]),t.jsxs("div",{className:"rs-cmd",children:[t.jsx("code",{className:"rs-cmd-text",children:e}),t.jsx($,{size:"sm",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(e).then(()=>s(!0),()=>{})},children:n?"Copied":"Copy"})]})}function kse({state:e,elapsedMs:n,hostname:s=window.location.hostname,onReload:r=()=>Wl.reload()}){const a=yse(e),i=e.kind==="stop",l=!i&&n>=(e.patienceMs??_U),o=db.test(s),c=d.useRef(null);d.useEffect(()=>{var h;return(h=c.current)==null?void 0:h.focus()},[]);const u=i?o?"This starts it again, in Terminal on this computer:":"On the computer buddi runs on, this starts it again:":o?"This says what it’s doing, in Terminal on this computer:":"On the computer buddi runs on, this says what it’s doing. Is that computer awake, and Tailscale on?";return t.jsx("div",{className:"ui-fieldbg rs-field","data-quiet":"true",children:t.jsx("div",{ref:c,className:"rs",role:"dialog","aria-modal":"true","aria-labelledby":"rs-title",tabIndex:-1,"data-state":i?"stopped":l?"long":"waiting",children:t.jsxs("div",{className:"rs-body",children:[t.jsx("span",{className:"ui-mascot rs-blob","data-size":"lg","aria-hidden":"true",children:t.jsx(Au,{role:"core",state:i||l?"idle":"working",className:"ui-mascot-blob"})}),t.jsx("h1",{id:"rs-title",className:"rs-title",children:a.title}),t.jsx("p",{className:"rs-line",role:"status",children:l?"Still waiting — buddi may need a hand.":a.line}),!l&&e.step?t.jsx("p",{className:"rs-step",children:e.step}):null,i||l?null:t.jsx("div",{className:"rs-track","aria-hidden":"true",children:t.jsx("span",{})}),i||l?t.jsxs("div",{className:"rs-help",children:[t.jsx("p",{className:"rs-help-line",children:u}),t.jsx(bse,{command:i?"buddi service start":"buddi status"})]}):null,t.jsxs("div",{className:"rs-foot",children:[t.jsx("span",{className:"rs-meta",children:i?"Checking every few seconds.":l?`${hC(n)} · still checking every few seconds`:n>=wse?`${hC(n)} · this page reloads when buddi is back`:"This page reloads when buddi is back."}),i||l?t.jsx($,{size:"sm",variant:l?"accent":void 0,onClick:r,children:"Reload"}):null]})]})})})}function Nse(e){const[n,s]=d.useState(()=>Wl.now());return d.useEffect(()=>{if(!e)return;s(Wl.now());const r=window.setInterval(()=>s(Wl.now()),1e3);return()=>window.clearInterval(r)},[e]),e?Math.max(0,n-e.startedAt):0}function Sse({children:e}){const n=YM(),s=Nse(n),r=d.useRef(null);return d.useEffect(()=>{VU();let a=Jc()!==null;const i=xw(()=>{const o=Jc()!==null;a&&!o&&_0(),a=o}),l=()=>void _0();return window.addEventListener(tu,l),()=>{i(),window.removeEventListener(tu,l)}},[]),d.useEffect(()=>{const a=r.current;a&&(a.toggleAttribute("inert",n!==null),n?a.setAttribute("aria-hidden","true"):a.removeAttribute("aria-hidden"))},[n]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:r,className:"rs-host",children:e}),n?t.jsx(kse,{state:n,elapsedMs:s}):null]})}const Cse="(max-width: 1080px)",Ese="(max-width: 720px)";function $se(){const[e,n]=d.useState(()=>window.location.hash||$n);d.useEffect(()=>{const r=()=>n(window.location.hash||$n);return window.addEventListener("hashchange",r),()=>window.removeEventListener("hashchange",r)},[]);const s=d.useCallback((r,a=!1)=>{a?window.history.replaceState(null,"",r):window.location.hash=r,n(r)},[]);return[e,s]}function Ase(){const[e,n]=DI();d.useEffect(()=>{OI(e)},[e]);const s=d.useCallback(r=>n({theme:r}),[n]);return[e.theme,s]}const fC=new Map;function Tse(){var H,de,et,Qe;const[e,n]=$se(),[s,r]=d.useState("UTC"),[a,i]=d.useState({approvals:0,failed:0,paused:!1,running:0,needs:0}),[l,o]=Ase(),c=fs(Gw),[u,h]=d.useState(!1),[f,m]=d.useState([]),[p,g]=d.useState(null),[x,k]=d.useState(null),[j,v]=d.useState([]),[w,y]=d.useState(!1),[N,b]=d.useState(null),[S,C]=d.useState(null),[T,E]=d.useState(0),[R,M]=d.useState(null),O=e6(),I=f.find(Se=>Se.id===p)??null,z=I!==null&&T9(e),[U,D]=d.useState(!1),P=d.useCallback(()=>D(!0),[]);d.useEffect(()=>{z||D(!1)},[z]),cY(n,qd(e)===null,z?P:void 0);const K=fs(Cse),F=yP(),Q=ST(),_=TI(),re=ge(()=>Promise.resolve().then(()=>A.version()),[],$U),Y=re.data;LU(re.reload);const B=Y&&!Y.checkout&&Y.updateAvailable?Y:null,q=_w(Y==null?void 0:Y.web);FU(Y==null?void 0:Y.web);const J=((H=ge(()=>Promise.resolve().then(()=>A.connectionSignals()),[],6e4).data)==null?void 0:H.signals)??[],[Z,fe]=d.useState(null),ve=d.useMemo(()=>new Set(Z?[Z]:[]),[Z]),[Oe,W]=d.useState(new Map);d.useEffect(()=>{const Se=()=>{A.conversations().then(nt=>{const Ue=new Map;for(const rn of nt.conversations){const pt=rn.lastMessageAt??rn.createdAt,xs=Ue.get(rn.agentId);(!xs||pt>xs)&&Ue.set(rn.agentId,pt)}W(Ue)}).catch(()=>{})};Se();const Ve=window.setInterval(Se,3e4);return()=>window.clearInterval(Ve)},[e]);const[se,X]=d.useState(!1);d.useEffect(()=>{if(se)return;let Se=!1;return A.onboarding().then(Ve=>{Se||(X(!0),Ve.state==="pending"&&Ve.needs.model&&!qd(window.location.hash)&&n(K3,!0))}).catch(()=>{Se||X(!0)}),()=>{Se=!0}},[se,n]),d.useEffect(()=>{const Se=pU(e);Se&&n(Se,!0)},[e,n]),d.useEffect(()=>{let Se=!1;const Ve=()=>{Je.agents().then(Ue=>{Se||(m(Ue.agents),zD(Ue.commands),bU(Ue.defaultAgentId??null),g(Ue.defaultAgentId??null),k(rn=>{var pt;return rn??Ue.defaultAgentId??((pt=Ue.agents[0])==null?void 0:pt.id)??null}))}).catch(()=>{})};Ve();const nt=window.setInterval(Ve,15e3);return window.addEventListener("focus",Ve),window.addEventListener(Fr,Ve),()=>{Se=!0,window.clearInterval(nt),window.removeEventListener("focus",Ve),window.removeEventListener(Fr,Ve)}},[e]),d.useEffect(()=>{let Se=!1;const Ve=()=>{Je.groups().then(Ue=>{Se||v(Ue.groups)}).catch(()=>{})};Ve();const nt=window.setInterval(Ve,3e4);return()=>{Se=!0,window.clearInterval(nt)}},[e]);const je=VA(f,p),be=G3(e),xe=MA(e),we=xe?j.find(Se=>Se.id===xe.groupId)??null:null,Ie=xe?null:(be==null?void 0:be.agentId)??x;d.useEffect(()=>{be&&k(be.agentId)},[be==null?void 0:be.agentId]);const ke=d.useRef(null);be&&(ke.current=e);const me=Se=>{k(Se),n(at(Se))},$e=Se=>n(ki(Se)),_e=d.useCallback((Se,Ve,nt=!0)=>n(xe?ki(xe.groupId,Ve):at(Se,Ve),nt),[n,xe==null?void 0:xe.groupId]),[Le,qe]=d.useState(!1),[,yt]=d.useState(0);d.useEffect(()=>{const Se=()=>{yt(Ve=>Ve+1),A.session().then(Ve=>r(Ve.timezone)).catch(()=>{})};return window.addEventListener(kx,Se),()=>window.removeEventListener(kx,Se)},[]),d.useEffect(()=>{A.session().then(Se=>{mw({timeFormat:Se.timeFormat??null,dateFormat:Se.dateFormat??null}),r(Se.timezone),qe(!0)}).catch(()=>{})},[]);const le=_9(Le);H9(Le,le.refresh,()=>qe(!1)),d.useEffect(()=>{const Se=()=>{A.overview().then(nt=>{var Ue;return i({approvals:nt.approvals.pending,failed:nt.jobs.failed??0,paused:nt.paused,running:nt.running??0,needs:((Ue=nt.needsYou)==null?void 0:Ue.total)??nt.approvals.pending+(nt.jobs.failed??0)})}).catch(()=>{})};Se();const Ve=window.setInterval(Se,2e4);return window.addEventListener($i,Se),()=>{window.clearInterval(Ve),window.removeEventListener($i,Se)}},[]);const Ce=ge(()=>Promise.resolve().then(()=>A.focus()),[],6e4),Ze=d.useRef(Ce.reload);Ze.current=Ce.reload,d.useEffect(()=>{const Se=()=>Ze.current();return window.addEventListener($i,Se),()=>window.removeEventListener($i,Se)},[]);const xt=xse(),Ct=dse(),It=YM()!==null,Ot=fs(Ese);d.useEffect(()=>{if(!Le)return;if(e===gU){y(!0),n(da,!0);return}const Se=xU(e),Ve=new Date().toDateString();!Se||fC.get(Se)===Ve||(fC.set(Se,Ve),A.tipsSeenPage(Se).catch(()=>{}))},[e,Le,n]);const bn={link:pse(window.location.hostname,xt&&!It),focus:((de=Ce.data)==null?void 0:de.focus)??null,working:a.running,paused:a.paused,failed:a.failed,approvals:a.approvals,version:Y?{current:Y.current,latest:Y.latest,updateAvailable:!Y.checkout&&Y.updateAvailable}:void 0,timezone:s},fn=rse({recovery:((et=F.data)==null?void 0:et.active)===!0,lost:Ct&&!It,paused:a.paused}),Kn=qd(e),en=zA(e),kn=en===da,Pt=N?j.find(Se=>Se.id===N.groupId)??null:null,mn=Se=>v(Ve=>Ve.map(nt=>nt.id===Se.id?Se:nt)),tn=()=>b(null),Te=w?t.jsx(K9,{agents:f,onClose:()=>y(!1),onCreated:Se=>{v(Ve=>[...Ve,Se]),y(!1),n(ki(Se.id))}}):Pt&&(N==null?void 0:N.kind)==="members"?t.jsx(g9,{group:Pt,agents:f,onClose:tn,onSaved:mn}):Pt&&(N==null?void 0:N.kind)==="rename"?t.jsx(x9,{group:Pt,onClose:tn,onSaved:Se=>{mn(Se),tn()}}):Pt&&(N==null?void 0:N.kind)==="clear"?t.jsx(j9,{group:Pt,onClose:tn,onCleared:()=>{tn(),E(Se=>Se+1),n(ki(Pt.id),!0)}}):Pt&&(N==null?void 0:N.kind)==="delete"?t.jsx(w9,{group:Pt,agents:f,onClose:tn,onDeleted:Se=>{const Ve=j.findIndex(nt=>nt.id===Pt.id);tn(),v(nt=>nt.filter(Ue=>Ue.id!==Pt.id)),C({group:Pt,index:Ve,until:Se}),n(ke.current??da)}}):null,st=()=>{const Se=S;Se&&(C(null),Je.restoreGroup(Se.group.id).then(Ve=>{v(nt=>{if(nt.some(rn=>rn.id===Ve.id))return nt;const Ue=[...nt];return Ue.splice(Math.min(Math.max(Se.index,0),Ue.length),0,Ve),Ue}),n(ki(Ve.id))}).catch(()=>M(Se.group.name)))};return Kn?t.jsx(g0,{delayDuration:400,children:t.jsxs(s0,{swipeDirection:"right",children:[t.jsx(yne,{navigate:n,timezone:s}),t.jsx(r0,{className:"ui-toasts"})]})}):t.jsx(A6,{picture:(Qe=f.find(Se=>Se.id===p))==null?void 0:Qe.picture,children:t.jsx(g0,{delayDuration:400,children:t.jsxs(s0,{swipeDirection:"right",children:[Te,t.jsxs("div",{className:"wb-shell",children:[t.jsx(ase,{banners:fn,onNavigate:n}),t.jsxs("div",{className:"wb",children:[t.jsx(JG,{attention:a.needs,place:en,onNavigate:n,theme:l,onTheme:o,plugins:lY(Q.rail,_),updateAvailable:B!==null,settingsDot:J.length>0?AI:void 0,stale:q,timezone:s,version:Y&&!Y.checkout?{current:Y.current,latest:Y.latest,updateAvailable:Y.updateAvailable}:Y?{current:Y.current,updateAvailable:!1}:void 0,status:Ot?t.jsx(jse,{status:bn,onNavigate:n}):void 0}),kn&&!K?t.jsx(JA,{agents:je,currentId:Ie,attention:O,onSelect:me,lastActivity:Oe,working:ve,groups:j,currentGroupId:(we==null?void 0:we.id)??null,onSelectGroup:$e,onNewGroup:()=>y(!0)}):null,kn?t.jsx(y9,{timezone:s,agents:je,agentId:we?we.coordinator:Ie,defaultAgentId:p,group:we,...we?{onGroupAction:Se=>b({kind:Se,groupId:we.id})}:{},requestedConversationId:(xe==null?void 0:xe.conversationId)??(be==null?void 0:be.conversationId),requestedTab:be==null?void 0:be.tab,onConversationOpened:_e,onSelectAgent:me,onWorking:fe,attention:O,agentsInHeader:K,narrow:c,canvasOpen:u,onOpenCanvas:()=>h(!0),onCloseCanvas:()=>h(!1)},`room-${T}`):t.jsx("main",{"data-ground":Rse(en,e)?"plain":void 0,"data-layout":en===on?"split":void 0,children:t.jsx(Ise,{hash:e,place:en,timezone:s,navigate:n,agents:f,defaultAgentId:p,attention:O,pluginPages:Q,update:B,connectionSignals:J})})]}),Ot?null:t.jsx(vse,{status:bn,onNavigate:n})]}),z&&I?t.jsx(R9,{agent:I,agents:f,timezone:s,open:U,onOpenChange:D,navigate:n}):null,t.jsxs(L9,{placement:D9(z,U),children:[t.jsx(z9,{queue:le.queue,agents:f,navigate:n,onDismiss:le.dismiss}),S?t.jsx(iu,{title:`Deleted ${S.group.name}`,body:"Its history goes for good in a few seconds.",duration:G9,onUndo:st,onGone:()=>C(null)},S.group.id):null,R?t.jsx(iu,{title:`${R} is gone for good`,body:"Undo came too late to bring it back.",duration:6e3,onGone:()=>M(null)},`late-${R}`):null,t.jsx(r0,{className:"ui-toasts"})]})]})})})}function Rse(e,n){return Mw(n)!==null}function Ise({place:e,pluginPages:n,...s}){const r={...s,pluginPages:n},a=Mw(s.hash);if(a){const i=n.find(a.plugin,a.page);if(i)return t.jsx(cI,{page:i,item:a.item??null,params:Ow(s.hash),navigate:s.navigate,timezone:s.timezone,siblings:n.all.filter(l=>l.plugin===a.plugin)});if(n.all.length===0)return t.jsx(t.Fragment,{})}switch(e){case bt:return t.jsx(GQ,{...r});case At:return t.jsx($Y,{...s});case on:return t.jsx(Pte,{...r});case va:return t.jsx(C7,{...s});default:return t.jsx(TJ,{...r})}}function Pse(){"serviceWorker"in navigator&&window.addEventListener("load",()=>{const e=`./sw.js?v=${encodeURIComponent(Fw)}`;navigator.serviceWorker.register(e,{scope:"./"}).catch(()=>{})})}function Mse({search:e=location.search}){const[n,s]=d.useState(null),r=d.useRef(!1);return d.useEffect(()=>{if(r.current)return;r.current=!0;const a=new URLSearchParams(e);try{history.replaceState(null,"",location.pathname)}catch{}const i=a.get("state")??"",l=a.get("code")??void 0,o=a.get("error")??void 0;A.connectionCallback({state:i,...l?{code:l}:{},...o?{error:o}:{}}).then(c=>{s({ok:!0,name:c.name,cli:c.cli===!0});try{const u=new BroadcastChannel(fP);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]),t.jsx("main",{className:"ui-page connections-callback",children:t.jsxs(ue,{gap:"lg",children:[t.jsx("h2",{className:"ui-page-title",children:"Connections"}),n===null?t.jsx(G,{tone:"accent",role:"status",children:"Finishing the sign-in…"}):null,n!=null&&n.ok?t.jsxs(G,{tone:"good",role:"status",title:`Signed in to ${n.name}`,children:["buddi keeps the sign-in in its vault. You can close this tab; ",n.cli?"the terminal carries on.":"the other one carries on."]}):null,n&&!n.ok?t.jsx(G,{tone:"critical",role:"alert",title:"Nothing was connected",children:n.message}):null,n?t.jsx(lt,{href:"/#/settings/connections",children:"Back to Connections"}):null]})})}const mC=document.getElementById("root");mC&&EE(mC).render(t.jsx(d.StrictMode,{children:location.pathname==="/connections/callback"?t.jsx(Mse,{}):t.jsx(Sse,{children:t.jsx(cse,{children:t.jsx(QG,{children:t.jsx(Tse,{})})})})}));Pse();export{Dse as c,o2 as g};
|