import{xt as e}from"./De2yIhEs.js";import{t}from"./Cj9ecUMW.js";import{J as n,Y as r,ft as i}from"./DVD-VP-F.js";import{r as a}from"./BrMTXoyD.js";var o=r();function s(){return{loading:!1,creating:!1,error:null,supportsCustomActions:!0,cpsVersion:null,requiredCustomActionsVersion:`1.0.0`,actions:[],definitions:[],quota:null,filters:{status:`active`},lastLoadedAt:null}}var c={cps_missing_proxy_key:`Custom Actions are available locally. Configure Direct OpenRouter or Sentient managed execution before running actions through that provider.`,quota_exceeded:`You reached the custom action quota for the selected provider path. Archive an existing action or adjust provider limits before retrying.`};const l=e(s());var u=t(()=>l);function d(){Object.assign(l,s())}function f(e){Object.assign(l,e)}function p(e){l.actions=a(e)}function m(e,t){if(e instanceof n){if(e.code&&c[e.code])return c[e.code];let n=e.payload;return n?.message?n.message:e.message||t}return e instanceof Error&&e.message||t}async function h(e=l.filters){l.loading=!0,l.error=null;try{try{let e=await o.getCapabilities({showNotifications:!1});l.supportsCustomActions=e.supports_custom_actions??!0,l.cpsVersion=e.cps_version??null}catch{}let[t,n]=await Promise.all([o.getCustomActions(e,{showNotifications:!1}),o.getActionDefinitions({showNotifications:!1})]);f({actions:a(t.actions),definitions:n,quota:t.quota,loading:!1,error:null,supportsCustomActions:!0,filters:e,lastLoadedAt:Date.now()})}catch(e){if(e instanceof n&&e.status===404){f({loading:!1,supportsCustomActions:!1,error:`Custom Actions API is not available in this plugin build. Refresh the plugin or enable local custom actions to use this page.`,actions:[],quota:null,lastLoadedAt:Date.now()});return}let t=m(e,`Failed to load custom actions`);f({loading:!1,error:t,actions:[],supportsCustomActions:!0}),i.error(t)}}async function g(e){l.creating=!0;try{let t=await o.createCustomAction(e,{showNotifications:!0});p([t.action,...l.actions]),l.quota=t.quota,l.error=null,i.success(`Custom action created`)}catch(e){let t=m(e,`Unable to create custom action`);throw i.error(t),e}finally{l.creating=!1}}async function _(e,t){try{let n=await o.updateCustomAction(e,t,{showNotifications:!0});p(l.actions.map(t=>t.id===e?n.action:t)),l.quota=n.quota,i.success(`Custom action updated`)}catch(e){let t=m(e,`Unable to update custom action`);throw i.error(t),e}}async function v(e){try{let t=await o.archiveCustomAction(e,{showNotifications:!0});p(l.actions.map(n=>n.id===e?t.action:n)),l.quota=t.quota,i.success(`Custom action archived`)}catch(e){let t=m(e,`Unable to archive custom action`);throw i.error(t),e}}async function y(e){try{let t=await o.reactivateCustomAction(e,{showNotifications:!0});p(l.actions.map(n=>n.id===e?t.action:n)),l.quota=t.quota,i.success(`Custom action reactivated`)}catch(e){let t=m(e,`Unable to reactivate custom action`);throw i.error(t),e}}function b(e){f({filters:e})}function x(e,t={status:`active`}){f({actions:a(e.actions),quota:e.quota,loading:!1,error:null,supportsCustomActions:!0,filters:t,lastLoadedAt:Date.now()})}const S={subscribe:u.subscribe,load:h,reload:()=>h(l.filters),hydrate:x,create:g,update:_,archive:v,reactivate:y,setFilters:b,reset:d};export{S as n,l as t};