import{n as e}from"./rolldown-runtime-DaJ6WEGw.js";import{m as t,p as n,u as r}from"./control-ui-foundation-6sbDnmF4.js";import{Da as i,Ii as a,Io as o,Jo as s,Ka as c,Ko as l,Lo as u,Po as d,Qi as f,Vo as p,da as ee,qa as m,uc as h}from"./control-ui-core-DENrrOFp.js";import{dt as g,ft as _}from"./control-ui-foundation-EMTIMJQU.js";import{$ as v,J as y,U as b,X as x,z as S}from"./lit-runtime-DRK0WlLJ.js";import{ot as C,rt as te}from"./control-ui-foundation-BMJqgJ7G.js";import{X as ne,ft as re,g as ie,ot as ae,p as oe,pt as se}from"./control-ui-core-D08sO3TC.js";import{o as w,t as ce}from"./control-ui-core-DTinBYL8.js";import{it as le,rt as ue}from"./control-ui-core-DYkQMwnN.js";import{n as de,t as fe}from"./settings-workspace-CkAuViph.js";import{l as T,o as E,t as D,u as O}from"./settings-ui-tqfn2bXq.js";function k(e){return typeof e==`string`&&e.trim()||null}function A(e){return e&&typeof e==`object`?e:null}function j(e,t=Date.now()){let n=A(e),r=k(n?.runId),i=A(n?.data),a=n?.stream===`tool`,o=n?.stream===`item`&&k(i?.kind)===`answer_candidate`;if(!n||!a&&!o||!r||!i)return null;let s=k(n.sessionKey),c=k(n.agentId);return{stream:a?`tool`:`item`,runId:r,ts:typeof n.ts==`number`?n.ts:t,receivedAt:t,...s?{sessionKey:s}:{},...c?{agentId:c}:{},data:i}}function M(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=A(e);if(!t)return null;if(typeof t.text==`string`)return t.text;let n=t.content;if(!Array.isArray(n))return null;let r=n.map(e=>{let t=A(e);return t?.type===`text`&&typeof t.text==`string`?t.text:null}).filter(e=>!!e);return r.length>0?r.join(`
`):null}function N(e){let t=M(e);if(t!==null)return t;if(e==null)return null;try{return JSON.stringify(e,null,2)}catch{return o(e)}}function P(e){return W.reduce((e,[t,n])=>e.replace(t,n),e)}function F(e){let t=N(e);if(!t)return{truncated:!1};let n=p(P(t),H);return{text:n.text,truncated:n.truncated}}function I(e){if(e==null)return 0;if(Array.isArray(e))return e.length;let t=A(e);return t?Object.keys(t).length:1}function L(e){return e?.isError===!0||e?.is_error===!0}function R(e){if(k(e.phase)!==`result`)return`running`;let t=A(e.result);if(L(e)||L(t))return`error`;let n=k(e.status)??k(t?.status);if(n&&/error|fail|failed|failure/i.test(n))return`error`;let r=Number(t?.exitCode??e.exitCode);return Number.isFinite(r)&&r!==0?`error`:`done`}function z(e){return U[e]}function B(e,t,n){let r=`${n} argument${n===1?``:`s`} hidden`;return`${e} ${z(t)}; ${r}`}function V(e,t){let n=t.data??{};if(t.stream===`item`)return me(e,t);let r=k(n.toolCallId);if(!r)return e;let i=k(n.name)??`tool`,a=`${t.runId}:${r}`,o=t.receivedAt,s=typeof t.ts==`number`?t.ts:o,c=R(n),l=F(n.phase===`update`?n.partialResult:n.phase===`result`?n.result:null),u=e.find(e=>e.id===a),d=n.args===void 0?u?.hiddenArgumentCount??0:I(n.args),f=l.text??u?.outputPreview,p={id:a,toolCallId:r,runId:t.runId,...t.sessionKey?{sessionKey:t.sessionKey}:{},toolName:i,entryKind:`tool`,status:c,startedAt:u?.startedAt??s,updatedAt:o,durationMs:Math.max(0,o-(u?.startedAt??s)),outputTruncated:l.truncated||u?.outputTruncated===!0,summary:B(i,c,d),hiddenArgumentCount:d,...f?{outputPreview:f}:{}};return(u?e.map(e=>e.id===a?p:e):[...e,p]).slice(-100)}function pe(e){return e===`candidate`||e===`superseded`||e===`selected`?e:null}function me(e,t){let n=k(t.data.itemId),r=pe(t.data.status);if(!n||!r)return e;let i=`${t.runId}:answer_candidate:${n}`,a=e.find(e=>e.id===i),o=t.receivedAt,s=a?.startedAt??t.ts,c=F(t.data.progressText),l={id:i,toolCallId:n,itemId:n,runId:t.runId,...t.sessionKey?{sessionKey:t.sessionKey}:{},toolName:`answer_candidate`,entryKind:`answer_candidate`,candidateStatus:r,status:r===`candidate`?`running`:`done`,startedAt:s,updatedAt:o,durationMs:Math.max(0,o-s),outputTruncated:c.truncated||a?.outputTruncated===!0,summary:`answer_candidate.${r}`,hiddenArgumentCount:0,...c.text?{outputPreview:c.text}:{}};return(a?e.map(e=>e.id===i?l:e):[...e,l]).slice(-100)}var H,U,W,he=e((()=>{u(),H=2e3,U={running:`running`,done:`completed`,error:`failed`},W=[[/\b(Authorization|Cookie|Set-Cookie)\s*:\s*[^\n\r]+/gi,`$1: [redacted]`],[/\b(Bearer\s+)[A-Za-z0-9._~+/=-]{12,}/gi,`$1[redacted]`],[/\b(api[_.-]?key|token|secret|password|passwd|authorization)\b(["'])(\s*:\s*)"(?:\\.|[^"\\\r\n])*"/gi,`$1$2$3"[redacted]"`],[/\b(api[_.-]?key|token|secret|password|passwd|authorization)\b(["'])(\s*:\s*)'(?:\\.|[^'\\\r\n])*'/gi,`$1$2$3'[redacted]'`],[/\b(api[_.-]?key|token|secret|password|passwd|authorization)\b(\s*[:=]\s*)["']?[^"',\s}]+/gi,`$1$2[redacted]`],[/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g,`[redacted private key]`],[/(^|[\s"'`=])(?:\/Users\/|\/home\/|\/var\/folders\/|[A-Za-z]:\\)[^\s"'`,;]+/g,`$1[redacted path]`]]})),ge=e((()=>{}));function _e(e){return d(e,{hour:`numeric`,minute:`2-digit`,second:`2-digit`},``)}function ve(e){return!Number.isFinite(e)||e<0?w(`common.na`):r(e,{spaced:!0})??`0ms`}function G(e){return w(`activity.status.${e}`)}function K(e){return e===1?w(`activity.argumentHiddenOne`):w(`activity.argumentsHidden`,{count:String(e)})}function q(e){return e.entryKind===`answer_candidate`?w(`activity.answerCandidate.${e.candidateStatus??`candidate`}`):w(`activity.entrySummary`,{argumentSummary:K(e.hiddenArgumentCount),status:G(e.status),tool:e.toolName})}function J(e){return e.entryKind===`answer_candidate`?w(`activity.answerCandidate.title`):e.toolName}function ye(e,t){return t?C([e.toolName,J(e),e.candidateStatus,e.status,e.summary,q(e),e.outputPreview,e.runId,e.toolCallId,e.sessionKey].filter(Boolean).join(` `)).includes(t):!0}function be(e){return te(e.map(e=>e.toolName))}function xe(e){let t=C(e.filterText);return e.entries.filter(n=>!e.statusFilters[n.status]||e.toolFilter&&n.toolName!==e.toolFilter?!1:ye(n,t))}function Se(e,t){return v`
    <label class="activity-status-filter">
      <input
        type="checkbox"
        .checked=${e.statusFilters[t]}
        @change=${n=>e.onStatusToggle(t,n.target.checked)}
      />
      <span>${G(t)}</span>
    </label>
  `}function Ce(e){return Z[e]}function we(e,t){let n=e.expandedIds.has(t.id);return v`
    <details
      class="activity-entry activity-entry--${t.status}"
      role="listitem"
      .open=${n}
      @toggle=${n=>e.onEntryToggle(t.id,n.currentTarget.open)}
    >
      <summary class="activity-entry__summary">
        <span class="activity-entry__chevron" aria-hidden="true">${ue.chevronRight}</span>
        <span class="activity-entry__main">
          <span class="activity-entry__title">
            ${T({kind:Ce(t.status),label:G(t.status)})}
            <span class="activity-entry__tool mono">${J(t)}</span>
          </span>
          <span class="activity-entry__text">${q(t)}</span>
        </span>
        <span class="activity-entry__meta">
          <span>${_e(t.updatedAt)}</span>
          <span>${ve(t.durationMs)}</span>
        </span>
      </summary>
      <div class="activity-entry__body">
        <div class="activity-entry__facts">
          ${t.entryKind===`answer_candidate`?v`<span class="mono"
                >${w(`activity.answerCandidate.itemId`)}: ${t.itemId}</span
              >`:v`
                <span>${K(t.hiddenArgumentCount)}</span>
                <span class="mono">${w(`activity.toolCallId`)}: ${t.toolCallId}</span>
              `}
          <span class="mono">${w(`activity.runId`)}: ${t.runId}</span>
          ${t.sessionKey?v`<span class="mono">${w(`activity.session`)}: ${t.sessionKey}</span>`:x}
        </div>
        ${t.outputPreview?v`
              <pre class="activity-entry__preview">${t.outputPreview}</pre>
              ${t.outputTruncated?v`<div class="activity-entry__note">${w(`activity.outputTruncated`)}</div>`:x}
            `:v`<div class="activity-entry__note">${w(`activity.noOutputPreview`)}</div>`}
      </div>
    </details>
  `}function Y(e){let t=be(e.entries),n=xe(e),r=e.filterText.trim()||e.toolFilter||X.some(t=>!e.statusFilters[t]);return v`
    <section class="activity-page" aria-label=${w(`activity.title`)}>
      <div class="settings-section__header">
        <h2 class="settings-section__heading">${w(`activity.title`)}</h2>
        <div class="settings-section__actions">
          <span class="activity-count" aria-live="polite">
            ${w(`activity.visibleCount`,{visible:String(n.length),total:String(e.entries.length)})}
          </span>
          <button
            type="button"
            class="btn btn--sm"
            ?disabled=${n.length===0}
            @click=${e.onExpandAll}
          >
            ${w(`activity.expandAll`)}
          </button>
          <button
            type="button"
            class="btn btn--sm"
            ?disabled=${e.expandedIds.size===0}
            @click=${e.onCollapseAll}
          >
            ${w(`activity.collapseAll`)}
          </button>
          <button
            type="button"
            class="btn btn--sm danger"
            ?disabled=${e.entries.length===0}
            @click=${e.onClear}
          >
            ${w(`activity.clear`)}
          </button>
        </div>
      </div>
      <div class="settings-group activity-group">
        ${E({title:w(`activity.search`),control:v`
            <input
              class="settings-input"
              type="search"
              aria-label=${w(`activity.search`)}
              .value=${e.filterText}
              placeholder=${w(`activity.searchPlaceholder`)}
              @input=${t=>e.onFilterTextChange(t.target.value)}
            />
          `})}
        ${E({title:w(`activity.toolFilter`),control:v`
            <select
              class="settings-select"
              aria-label=${w(`activity.toolFilter`)}
              .value=${e.toolFilter}
              @change=${t=>e.onToolFilterChange(t.target.value)}
            >
              <option value="">${w(`activity.allTools`)}</option>
              ${t.map(e=>v`<option value=${e}>${e}</option>`)}
            </select>
          `})}
        ${E({title:w(`activity.statusFilters`),control:v`
            <span
              role="group"
              aria-label=${w(`activity.statusFilters`)}
              class="activity-status-filters"
            >
              ${X.map(t=>Se(e,t))}
            </span>
          `})}
        ${E({title:w(`activity.autoFollow`),control:O({checked:e.autoFollow,ariaLabel:w(`activity.autoFollow`),onChange:t=>e.onToggleAutoFollow(t)})})}
        <div
          class="activity-stream"
          role="list"
          aria-label=${w(`activity.streamLabel`)}
          @scroll=${e.onScroll}
        >
          ${n.length===0?v`
                <div class="activity-empty">
                  ${e.entries.length===0||!r?w(`activity.empty`):w(`activity.emptyFiltered`)}
                </div>
              `:n.map(t=>we(e,t))}
        </div>
      </div>
    </section>
  `}var X,Z,Te=e((()=>{y(),le(),D(),ce(),u(),h(),ge(),X=[`running`,`done`,`error`],Z={running:`warn`,done:`ok`,error:`danger`}})),Q,$;e((()=>{g(),y(),S(),ne(),se(),oe(),fe(),a(),ee(),s(),m(),he(),Te(),t(),$=class extends l{constructor(...e){super(...e),this.entries=[],this.filterText=``,this.statusFilters={running:!0,done:!0,error:!0},this.toolFilter=``,this.expandedIds=new Set,this.autoFollow=!0,this.atBottom=!0,this.sessionKey=``,this.scrollFrame=null,this.subscriptions=new c(this).effect(()=>this.context?.gateway,e=>{this.applyGatewaySnapshot(e,e.snapshot,!0);let t=e.subscribeEvents(t=>{this.applyGatewayEvent(e,t,Date.now())}),n=e.subscribe(t=>this.applyGatewaySnapshot(e,t,!1));return()=>{n(),t()}})}updated(e){this.autoFollow&&this.atBottom&&(e.has(`entries`)||e.has(`autoFollow`))&&this.scheduleScroll(e.has(`autoFollow`))}disconnectedCallback(){this.subscriptions.clear(),this.scrollFrame!==null&&(cancelAnimationFrame(this.scrollFrame),this.scrollFrame=null),super.disconnectedCallback()}applyGatewaySnapshot(e,t,n){let r=this.sessionKey;this.sessionKey=f(ie().sessionKey,t.hello),(n||this.sessionKey!==r)&&this.rebuildEntries(e,t)}rebuildEntries(e,t){let n=[],r=e.eventLog,i=Q?r.indexOf(Q):-1,a=i<0?r:r.slice(0,i);for(let e of a.toReversed())n=this.reduceGatewayEvent(n,t,e.event,e.payload,e.ts);(n.length>0||this.entries.length>0)&&(this.entries=n),this.expandedIds.size>0&&(this.expandedIds=new Set),this.atBottom=!0}applyGatewayEvent(e,t,n){if(this.context.gateway!==e)return;let r=this.reduceGatewayEvent(this.entries,e.snapshot,t.event,t.payload,n);r!==this.entries&&(this.entries=r)}reduceGatewayEvent(e,t,n,r,a){if(n!==`agent`&&n!==`session.tool`)return e;let o=j(r,a);return!o||!i({sessionKey:this.sessionKey,assistantAgentId:t.assistantAgentId,hello:t.hello},o.sessionKey,o.agentId)?e:V(e,o)}scheduleScroll(e=!1){this.scrollFrame!==null&&cancelAnimationFrame(this.scrollFrame),this.updateComplete.then(()=>{this.isConnected&&(this.scrollFrame=requestAnimationFrame(()=>{this.scrollFrame=null;let t=this.querySelector(`.activity-stream`);if(!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight;!e&&(!this.autoFollow||!this.atBottom&&n>=120)||(t.scrollTop=t.scrollHeight,this.atBottom=!0)}))})}handleScroll(e){let t=e.currentTarget;if(!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight;this.atBottom=n<120}clearEntries(){Q=this.context.gateway.eventLog[0],this.entries=[],this.expandedIds=new Set,this.atBottom=!0}render(){let e=Y({entries:this.entries,filterText:this.filterText,statusFilters:this.statusFilters,toolFilter:this.toolFilter,expandedIds:this.expandedIds,autoFollow:this.autoFollow,onFilterTextChange:e=>this.filterText=e,onToolFilterChange:e=>this.toolFilter=e,onStatusToggle:(e,t)=>{this.statusFilters={...this.statusFilters,[e]:t}},onToggleAutoFollow:e=>{this.autoFollow=e,e&&this.scheduleScroll(!0)},onClear:()=>this.clearEntries(),onExpandAll:()=>{this.expandedIds=new Set(this.entries.map(e=>e.id))},onCollapseAll:()=>{this.expandedIds=new Set},onEntryToggle:(e,t)=>{let n=new Set(this.expandedIds);t?n.add(e):n.delete(e),this.expandedIds=n},onScroll:e=>this.handleScroll(e)});return v`
      <section class="content-header">
        <div>
          <div class="page-title">${ae(`activity`)}</div>
        </div>
      </section>
      ${de(e,{fillHeight:!0})}
    `}},n([_({context:re,subscribe:!0})],$.prototype,`context`,void 0),n([b()],$.prototype,`entries`,void 0),n([b()],$.prototype,`filterText`,void 0),n([b()],$.prototype,`statusFilters`,void 0),n([b()],$.prototype,`toolFilter`,void 0),n([b()],$.prototype,`expandedIds`,void 0),n([b()],$.prototype,`autoFollow`,void 0),n([b()],$.prototype,`atBottom`,void 0),customElements.get(`openclaw-activity-page`)||customElements.define(`openclaw-activity-page`,$)}))();
//# sourceMappingURL=activity-page-B1EDeCWj.js.map