import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Gt as t,er as n}from"./control-ui-foundation-CeFMP1Ly.js";import{b as r,fl as i,fs as a,ml as o,ms as s,w as c}from"./control-ui-core-pH6nakZ-.js";import{G as l,J as u,W as d,Z as f,h as p,m,rt as h}from"./lit-runtime-BEtFSUCp.js";import{Cn as g,ln as _,m as ee,p as te}from"./control-ui-core-DGVkFhVB.js";import{Gt as v,Ht as y,It as b,N as x,Nt as ne,Rt as S,qt as C}from"./control-ui-core-Br5DB0Zj.js";import{In as re,Ln as w}from"./control-ui-boot-wpHCbPL9.js";import{a as T,n as ie,r as ae}from"./gateway-runtime-DUNO4Mi1.js";import{Ca as oe,hn as se,mn as ce,on as E,sn as D,un as O,vn as k,wa as A}from"./control-ui-boot-Cdpgu1Gm.js";import{n as j,t as M}from"./settings-workspace-Bo4nqRhI.js";import{n as N,t as P}from"./gateway-page-controller-bzyUg03c.js";var F;function I(){return(I=e((()=>{t(),F=/^[A-Z][A-Z0-9_]{0,127}$/})))()}function L(e){return R.test(e)}var R;function z(){return(z=e((()=>{R=/_?(API_KEY|TOKEN|PASSWORD|PRIVATE_KEY|SECRET)$/i})))()}function B(e){let t={},n=e.replace(/\r\n?/gu,`
`);V.lastIndex=0;let r;for(;(r=V.exec(n))!==null;){let e=r[1];if(!e)continue;let n=(r[2]??``).trim(),i=n[0];n=n.replace(/^(['"`])([\s\S]*)\1$/gmu,`$2`),i===`"`&&(n=n.replace(/\\n/gu,`
`).replace(/\\r/gu,`\r`)),t[e]=n}return t}var V;function H(){return(H=e((()=>{V=/^\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?$/gmu})))()}function U(e={}){return{client:e.client??null,connected:e.connected??!1,entries:[],loaded:!1,loading:!1,busy:!1,error:null}}async function W(e){return(await e.request(`secrets.store.list`,{})).entries}async function G(e){let t=e.client;if(!t||!e.connected||e.loading)return!1;e.loading=!0,e.error=null;try{let n=await W(t);return e.client===t&&e.connected?(e.entries=n,e.loaded=!0,!0):!1}catch(n){return e.client===t&&(e.error=a(n)),!1}finally{e.client===t&&(e.loading=!1)}}async function K(e,t){let n=e.client;if(!n||!e.connected||e.busy)return null;e.busy=!0,e.error=null;let r=null,i;try{r=await t(n)}catch(e){i=e}try{let t=await W(n);e.client===n&&e.connected&&(e.entries=t,e.loaded=!0)}catch(e){i??=e}finally{e.client===n&&(e.busy=!1,e.error=i?a(i):null)}return i?null:r}function le(e,t){return K(e,e=>e.request(`secrets.store.set`,{name:t.name,value:t.value,kind:t.kind,...t.kind===`secret`?{allowedHosts:t.allowedHosts.split(/[\s,]+/u).map(e=>e.trim()).filter(Boolean)}:{}}))}function ue(e,t){return K(e,e=>e.request(`secrets.store.delete`,{name:t}))}function de(e,t){let n=B(e),r=Object.keys(n).filter(e=>!F.test(e));return{entries:Object.entries(n).map(([e,n])=>({name:e,value:n,kind:t&&L(e)?`secret`:`env`})),invalidNames:r}}async function fe(e,t){let n=e.client;if(!n||!e.connected||e.busy||t.length===0)return null;e.busy=!0,e.error=null;let r=0,i=0,o;try{for(let a of t){let t=await n.request(`secrets.store.set`,a);r+=1,i=Math.max(i,t.warningCount??0);let o=await W(n);e.client===n&&e.connected&&(e.entries=o,e.loaded=!0)}}catch(e){o=Error(C(`secretsStore.partial`,{saved:String(r),total:String(t.length),error:a(e)}))}try{if(o){let t=await W(n);e.client===n&&e.connected&&(e.entries=t,e.loaded=!0)}}catch(e){o??=e}finally{e.client===n&&(e.busy=!1,e.error=o?a(o):null)}return o?null:{saved:r,warningCount:i}}function q(){return(q=e((()=>{I(),z(),H(),y(),s()})))()}function pe(e){let t=r(e.updatedAtMs,{fallback:C(`common.unknown`)});return e.updatedBy?C(`secretsStore.by`,{time:t,name:e.updatedBy}):t}function me(e,t){return!e.canSet&&!e.canDelete?u``:u`
    <wa-dropdown
      class="secrets-store__menu"
      placement="bottom-end"
      @wa-select=${n=>{n.detail.item.value===`edit`&&e.canSet?e.onOpenEdit(t):n.detail.item.value===`delete`&&e.canDelete&&e.onDelete(t)}}
    >
      <button
        slot="trigger"
        type="button"
        class="btn btn--sm btn--ghost secrets-store__menu-trigger"
        aria-label=${`${C(`secretsStore.actions`)}: ${t.name}`}
        title=${C(`secretsStore.actions`)}
        ?disabled=${e.busy}
      >
        ${b(`moreHorizontal`)}
      </button>
      ${e.canSet?u`<wa-dropdown-item value="edit">${C(`secretsStore.edit`)}</wa-dropdown-item>`:l}
      ${e.canDelete?u`<wa-dropdown-item value="delete" variant="danger"
            >${C(`common.delete`)}</wa-dropdown-item
          >`:l}
    </wa-dropdown>
  `}function he(e){return e.canList?e.loading&&!e.entries.length?O(C(`common.loading`)):e.entries.length?u`
    <div class="secrets-store__table-wrap">
      <table class="secrets-store__table">
        <thead>
          <tr>
            <th scope="col">${C(`secretsStore.name`)}</th>
            <th scope="col">${C(`secretsStore.access`)}</th>
            <th scope="col">${C(`secretsStore.value`)}</th>
            <th scope="col">${C(`secretsStore.allowedHosts`)}</th>
            <th scope="col">${C(`secretsStore.updated`)}</th>
            <th scope="col" class="secrets-store__actions-heading">
              <span class="settings-control__sr-label">${C(`secretsStore.actions`)}</span>
            </th>
          </tr>
        </thead>
        <tbody>
          ${p(e.entries,e=>e.name,t=>u`
              <tr tabindex="0" aria-label=${t.name}>
                <td><code class="secrets-store__name">${t.name}</code></td>
                <td>
                  <span class="secrets-store__mode secrets-store__mode--${t.kind}"
                    >${C(t.kind===`secret`?`secretsStore.protectedSecret`:`secretsStore.agentReadable`)}</span
                  >
                </td>
                <td>
                  <span
                    class="secrets-store__value ${t.kind===`secret`?`secrets-store__value--secret`:``}"
                    title=${t.kind===`env`?t.value:l}
                    >${t.kind===`env`?t.value:Y}</span
                  >
                </td>
                <td>
                  <span class="secrets-store__hosts">
                    ${t.kind===`secret`&&(t.allowedHosts?.length??0)>0?t.allowedHosts?.join(`, `):C(`secretsStore.noAllowedHosts`)}
                  </span>
                </td>
                <td>
                  <time
                    class="secrets-store__updated"
                    datetime=${new Date(t.updatedAtMs).toISOString()}
                    title=${new Intl.DateTimeFormat(v.getLocale(),{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.updatedAtMs))}
                    >${pe(t)}</time
                  >
                </td>
                <td class="secrets-store__actions-cell">${me(e,t)}</td>
              </tr>
            `)}
        </tbody>
      </table>
    </div>
  `:u`
      <div class="secrets-store__empty">
        ${O(C(`tabs.secrets`))} ${D(J,C(`common.docs`))}
      </div>
    `:O(C(`secretsStore.unavail`))}function ge(e){if(!e.dialogMode)return l;let t=e.dialogMode===`edit`;return u`
    <openclaw-modal-dialog
      label=${C(t?`secretsStore.edit`:`secretsStore.add`)}
      description=${C(`secretsStore.hint`)}
      @modal-cancel=${e.onCloseDialog}
    >
      <form
        class="secrets-store-dialog"
        aria-busy=${e.busy?`true`:`false`}
        @submit=${t=>{t.preventDefault(),e.onSubmitDraft()}}
      >
        <div class="secrets-store-dialog__header">
          <h2>${C(t?`secretsStore.edit`:`secretsStore.add`)}</h2>
        </div>
        <label class="secrets-store-field">
          <span>${C(`secretsStore.name`)}</span>
          <input
            class="settings-input mono"
            name="name"
            autocomplete="off"
            spellcheck="false"
            autofocus
            ?readonly=${t}
            ?disabled=${e.busy}
            .value=${e.draft.name}
            @input=${t=>e.onDraftNameChange(t.currentTarget.value)}
          />
        </label>
        <label class="secrets-store-field">
          <span>${C(`secretsStore.value`)}</span>
          <textarea
            class="settings-input secrets-store-dialog__value"
            name="value"
            autocomplete="off"
            spellcheck="false"
            ?disabled=${e.busy}
            .value=${e.draft.value}
            @input=${t=>e.onDraftValueChange(t.currentTarget.value)}
          ></textarea>
        </label>
        <fieldset class="secrets-store-modes">
          <legend>${C(`secretsStore.accessMode`)}</legend>
          <label
            class="secrets-store-mode ${e.draft.kind===`secret`?`secrets-store-mode--selected`:``}"
          >
            <input
              type="radio"
              name="access-mode"
              value="secret"
              .checked=${e.draft.kind===`secret`}
              ?disabled=${e.busy}
              @change=${()=>e.onDraftKindChange(`secret`)}
            />
            <span>
              <strong>${C(`secretsStore.protectedSecret`)}</strong>
              <small>${C(`secretsStore.protectedSecretHint`)}</small>
            </span>
          </label>
          <label
            class="secrets-store-mode ${e.draft.kind===`env`?`secrets-store-mode--selected secrets-store-mode--risk`:``}"
          >
            <input
              type="radio"
              name="access-mode"
              value="env"
              .checked=${e.draft.kind===`env`}
              ?disabled=${e.busy}
              @change=${()=>e.onDraftKindChange(`env`)}
            />
            <span>
              <strong>${C(`secretsStore.agentReadable`)}</strong>
              <small>${C(`secretsStore.agentReadableHint`)}</small>
            </span>
          </label>
        </fieldset>
        ${e.draft.kind===`secret`?u`
              <label class="secrets-store-field">
                <span>${C(`secretsStore.allowedHosts`)}</span>
                <textarea
                  class="settings-input secrets-store-dialog__hosts mono"
                  name="allowed-hosts"
                  autocomplete="off"
                  spellcheck="false"
                  placeholder=${C(`secretsStore.allowedHostsPlaceholder`)}
                  ?disabled=${e.busy}
                  .value=${e.draft.allowedHosts}
                  @input=${t=>e.onDraftAllowedHostsChange(t.currentTarget.value)}
                ></textarea>
                <small>${C(`secretsStore.allowedHostsHint`)}</small>
              </label>
            `:l}
        ${e.formError?u`<div class="callout danger" role="alert">${e.formError}</div>`:l}
        <div class="secrets-store-dialog__actions">
          <button class="btn primary" type="submit" ?disabled=${e.busy}>
            ${e.busy?C(`common.saving`):C(`common.save`)}
          </button>
          <button class="btn" type="button" ?disabled=${e.busy} @click=${e.onCloseDialog}>
            ${C(`common.cancel`)}
          </button>
        </div>
      </form>
    </openclaw-modal-dialog>
  `}function _e(e){return e.bulkOpen?u`
    <openclaw-modal-dialog label=${C(`secretsStore.bulk`)} @modal-cancel=${e.onCloseBulk}>
      <form
        class="secrets-store-dialog"
        aria-busy=${e.busy?`true`:`false`}
        @submit=${t=>{t.preventDefault(),e.onSubmitBulk()}}
      >
        <div class="secrets-store-dialog__header">
          <h2>${C(`secretsStore.bulk`)}</h2>
        </div>
        <label class="secrets-store-field">
          <span>${C(`secretsStore.value`)}</span>
          <textarea
            class="settings-input secrets-store-dialog__bulk"
            name="bulk-values"
            autocomplete="off"
            spellcheck="false"
            autofocus
            ?disabled=${e.busy}
            .value=${e.bulkRaw}
            @input=${t=>e.onBulkRawChange(t.currentTarget.value)}
          ></textarea>
        </label>
        <div class="secrets-store-bulk__summary" aria-live="polite">
          ${C(e.bulkSecretCount===1?`secretsStore.detectedOne`:`secretsStore.detected`,{count:String(e.bulkSecretCount)})}
        </div>
        <label class="secrets-store-checkbox">
          <input
            type="checkbox"
            .checked=${e.bulkAutoDetect}
            ?disabled=${e.busy}
            @change=${t=>e.onBulkAutoDetectChange(t.currentTarget.checked)}
          />
          <span>
            <strong>${C(`secretsStore.detect`)}</strong>
          </span>
        </label>
        ${e.bulkInvalidNames.length?u`<div class="callout danger" role="alert">
              ${C(`secretsStore.badName`)} ${e.bulkInvalidNames.join(`, `)}
            </div>`:l}
        ${e.formError?u`<div class="callout danger" role="alert">${e.formError}</div>`:l}
        <div class="secrets-store-dialog__actions">
          <button
            class="btn primary"
            type="submit"
            ?disabled=${e.busy||!e.bulkEntryCount||e.bulkInvalidNames.length>0}
          >
            ${e.busy?C(`common.saving`):C(`common.save`)}
          </button>
          <button class="btn" type="button" ?disabled=${e.busy} @click=${e.onCloseBulk}>
            ${C(`common.cancel`)}
          </button>
        </div>
      </form>
    </openclaw-modal-dialog>
  `:l}function ve(e){let t=e.canSet?u`
        <button
          class="btn btn--sm"
          type="button"
          ?disabled=${e.busy}
          @click=${e.onOpenBulk}
        >
          ${C(`secretsStore.bulk`)}
        </button>
        <button
          class="btn btn--sm primary"
          type="button"
          ?disabled=${e.busy}
          @click=${e.onOpenAdd}
        >
          ${b(`plus`)} ${C(`secretsStore.add`)}
        </button>
      `:void 0;return u`
    ${ce(u`
        ${e.error?u`<div class="callout danger secrets-store__message" role="alert">
              <span>${e.error}</span>
              ${e.canList?u`<button class="btn btn--sm" type="button" @click=${e.onRefresh}>
                    ${C(`common.retry`)}
                  </button>`:l}
            </div>`:l}
        ${e.notice?u`<div
              class="callout success secrets-store__message"
              role="status"
              aria-live="polite"
            >
              ${e.notice}
            </div>`:l}
        ${k({title:C(`tabs.secrets`),actions:t,count:e.entries.length},he(e))}
      `,{wide:!0})}
    ${ge(e)} ${_e(e)}
  `}var J,Y;function X(){return(X=e((()=>{d(),m(),S(),ne(),E(),x(),y(),c(),J=`https://docs.openclaw.ai/gateway/secrets#shared-secret-store`,Y=`••••••••`})))()}var Z,Q;function $(){return($=e((()=>{w(),d(),f(),I(),z(),_(),ee(),oe(),E(),M(),y(),ae(),q(),N(),o(),X(),Z=65536,Q=class extends i{constructor(...e){super(...e),this.store=U(),this.dialogMode=null,this.draft={name:``,value:``,kind:`env`,allowedHosts:``},this.secretKindOverridden=!1,this.bulkOpen=!1,this.bulkRaw=``,this.bulkAutoDetect=!0,this.formError=null,this.notice=null,this.gateway=new P(this,{getGateway:()=>this.context?.gateway,invalidateRequests:e=>this.resetGatewayState(e.snapshot),onSnapshot:e=>{e.initial&&this.resetGatewayState(e.snapshot)},ensureInitialData:()=>this.ensureInitialData()})}resetGatewayState(e){this.store=U({client:e?.client??null,connected:e?.phase===`connected`}),this.dialogMode=null,this.bulkOpen=!1,this.formError=null,this.notice=null}get canList(){return this.canCall(`secrets.store.list`)}get canSet(){return this.canCall(`secrets.store.set`)}get canDelete(){return this.canCall(`secrets.store.delete`)}canCall(e){return T(this.gateway.snapshot??{},e)===!0&&ie(this.gateway.snapshot,e,`operator.admin`)}ensureInitialData(){this.canList&&!this.store.loaded&&!this.store.loading&&this.runStoreTask(e=>G(e))}async runStoreTask(e){let t=this.store;try{let n=e(t);return this.requestUpdate(),await n}finally{this.store===t&&this.requestUpdate()}}refresh(){this.canList&&this.runStoreTask(e=>G(e))}openAdd(){this.canSet&&(this.notice=null,this.formError=null,this.secretKindOverridden=!1,this.draft={name:``,value:``,kind:`env`,allowedHosts:``},this.dialogMode=`add`)}openEdit(e){this.canSet&&(this.notice=null,this.formError=null,this.secretKindOverridden=!0,this.draft={name:e.name,value:e.kind===`env`?e.value:``,kind:e.kind,allowedHosts:e.kind===`secret`?(e.allowedHosts??[]).join(`
`):``},this.dialogMode=`edit`)}closeDialog(){this.store.busy||(this.dialogMode=null,this.formError=null)}patchDraft(e){this.draft={...this.draft,...e},this.formError=null}changeDraftName(e){let t=e.toUpperCase();this.patchDraft({name:t,...this.secretKindOverridden?{}:{kind:L(t)?`secret`:`env`}})}validateValue(e,t){return t===`secret`&&e.length===0?C(`secretsStore.required`):new TextEncoder().encode(e).byteLength>Z?C(`secretsStore.tooLarge`):null}validateDraft(){return F.test(this.draft.name)?this.validateValue(this.draft.value,this.draft.kind):C(`secretsStore.badName`)}submitDraft(){if(!this.canSet||!this.dialogMode)return;let e=this.validateDraft();if(e){this.formError=e;return}let t={...this.draft};this.runStoreTask(async e=>{let n=await le(e,t);if(this.store!==e)return;if(!n){this.formError=e.error;return}this.dialogMode=null,this.formError=null;let r=C(t.kind===`secret`?`secretsStore.savedProtected`:`secretsStore.savedReadable`,{name:t.name});this.notice=n.warningCount?`${r} ${C(`secretsStore.warnings`,{count:String(n.warningCount)})}`:r})}openBulk(){this.canSet&&(this.notice=null,this.formError=null,this.bulkRaw=``,this.bulkAutoDetect=!0,this.bulkOpen=!0)}closeBulk(){this.store.busy||(this.bulkOpen=!1,this.formError=null)}get bulkParsed(){return de(this.bulkRaw,this.bulkAutoDetect)}submitBulk(){if(!this.canSet||!this.bulkOpen)return;let e=this.bulkParsed;if(e.invalidNames.length>0){this.formError=`${C(`secretsStore.badName`)} ${e.invalidNames.join(`, `)}`;return}if(e.entries.length===0){this.formError=C(`secretsStore.required`);return}for(let t of e.entries){let e=this.validateValue(t.value,t.kind);if(e){this.formError=`${t.name}: ${e}`;return}}this.runStoreTask(async t=>{let n=await fe(t,e.entries);if(this.store!==t)return;if(!n){this.formError=t.error;return}this.bulkOpen=!1,this.formError=null;let r=C(`secretsStore.savedMany`,{count:String(n.saved),protected:String(e.entries.filter(e=>e.kind===`secret`).length),readable:String(e.entries.filter(e=>e.kind===`env`).length)});this.notice=n.warningCount?`${r} ${C(`secretsStore.warnings`,{count:String(n.warningCount)})}`:r})}async removeEntry(e){let t=this.context.gateway,n=this.store.client;if(!(!n||!this.canDelete||!await A({title:C(`common.delete`),message:C(`secretsStore.confirmDelete`,{name:e.name}),confirmLabel:C(`common.delete`),danger:!0}))){if(this.notice=null,this.context.gateway!==t||this.store.client!==n||!this.canDelete){this.store.error=C(`secretsStore.deleteFailed`),this.requestUpdate();return}await this.runStoreTask(async t=>{await ue(t,e.name)&&this.store===t&&(this.notice=C(`secretsStore.deleted`,{name:e.name}))})}}render(){let e=this.bulkParsed,t=ve({entries:this.store.entries,loading:this.store.loading,busy:this.store.busy,error:this.store.error,notice:this.notice,canList:this.canList,canSet:this.canSet,canDelete:this.canDelete,dialogMode:this.dialogMode,draft:this.draft,formError:this.formError,bulkOpen:this.bulkOpen,bulkRaw:this.bulkRaw,bulkAutoDetect:this.bulkAutoDetect,bulkSecretCount:e.entries.filter(e=>e.kind===`secret`).length,bulkEntryCount:e.entries.length,bulkInvalidNames:e.invalidNames,onRefresh:()=>this.refresh(),onOpenAdd:()=>this.openAdd(),onOpenEdit:e=>this.openEdit(e),onCloseDialog:()=>this.closeDialog(),onDraftNameChange:e=>this.changeDraftName(e),onDraftValueChange:e=>this.patchDraft({value:e}),onDraftAllowedHostsChange:e=>this.patchDraft({allowedHosts:e}),onDraftKindChange:e=>{this.secretKindOverridden=!0,this.patchDraft({kind:e})},onSubmitDraft:()=>this.submitDraft(),onOpenBulk:()=>this.openBulk(),onCloseBulk:()=>this.closeBulk(),onBulkRawChange:e=>{this.bulkRaw=e,this.formError=null},onBulkAutoDetectChange:e=>{this.bulkAutoDetect=e,this.formError=null},onSubmitBulk:()=>this.submitBulk(),onDelete:e=>void this.removeEntry(e)});return u`
      ${se({title:g(`secrets`),subtitle:C(`secretsStore.hint`)})}
      ${j(t)}
    `}},n([re({context:te,subscribe:!0})],Q.prototype,`context`,void 0),n([h()],Q.prototype,`store`,void 0),n([h()],Q.prototype,`dialogMode`,void 0),n([h()],Q.prototype,`draft`,void 0),n([h()],Q.prototype,`secretKindOverridden`,void 0),n([h()],Q.prototype,`bulkOpen`,void 0),n([h()],Q.prototype,`bulkRaw`,void 0),n([h()],Q.prototype,`bulkAutoDetect`,void 0),n([h()],Q.prototype,`formError`,void 0),n([h()],Q.prototype,`notice`,void 0),customElements.get(`openclaw-secrets-page`)||customElements.define(`openclaw-secrets-page`,Q)})))()}$();
//# sourceMappingURL=secrets-page-knnZEJpx.js.map