import{a as e,n as t}from"./lit-xS7RrYW6.js";import{r as n,t as r}from"./string-coerce-CuNcS1Hz.js";import{I as i,L as a,O as o,R as s,U as c,W as l,c as u}from"./index-Bt8RaTD0.js";var d=[`off`,`minimal`,`low`,`medium`,`high`],f=[``,`off`,`on`,`full`],p=[``,`on`,`off`],m=[``,`off`,`on`,`stream`],h=[10,25,50,100];function g(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]??null:null}function _(e){return a(e)??r(e)}function v(e){var t,n;let r=e.thinkingDefault?`默认（${e.thinkingDefault}）`:`继承`,i=(t=e.thinkingLevels)!=null&&t.length?e.thinkingLevels:((n=e.thinkingOptions)!=null&&n.length?e.thinkingOptions:d).map(e=>({id:_(e),label:e}));return[{value:``,label:r},...i.map(e=>({value:_(e.id),label:e.label}))]}function y(e,t){return!t||e.includes(t)?[...e]:[...e,t]}function b(e,t){return!t||e.some(e=>e.value===t)?[...e]:[...e,{value:t,label:`${t}（自定义）`}]}function x(){return f.map(e=>({value:e,label:e===``?`继承`:e===`off`?`关闭（显式）`:e===`on`?`开启`:e===`full`?`完整`:e}))}var S={on:`开启`,off:`关闭`};function C(){return p.map(e=>({value:e,label:e===``?`继承`:S[e]??e}))}function w(e){return e||null}function T(e,t,n){let i=r(t);return i?e.filter(e=>{var t;let a=r(e.key),s=r(e.label),l=r(e.kind),u=r(e.displayName),d=r(o(e.agentRuntime));if(a.includes(i)||s.includes(i)||l.includes(i)||u.includes(i)||d.includes(i))return!0;let f=c(e.key);return(f?r((t=g(n,f.agentId))==null?void 0:t.name):``).includes(i)}):e}function E(e,t,n){let r=n===`asc`?1:-1;return[...e].toSorted((e,n)=>{let i=0;switch(t){case`key`:i=(e.key??``).localeCompare(n.key??``);break;case`kind`:i=(e.kind??``).localeCompare(n.kind??``);break;case`updated`:i=(e.updatedAt??0)-(n.updatedAt??0);break;case`tokens`:i=(e.totalTokens??e.inputTokens??e.outputTokens??0)-(n.totalTokens??n.inputTokens??n.outputTokens??0);break}return i*r})}function D(e,t,n){let r=t*n;return e.slice(r,r+n)}function O(e){let t=Number(e.trim());return Number.isFinite(t)&&t>0}function k(e){return r(e.searchQuery).length>0||O(e.activeMinutes)||O(e.limit)||!e.includeGlobal||!e.includeUnknown||!e.showArchived}function A(e){switch(e){case`manual`:return`手动`;case`auto-threshold`:return`自动阈值`;case`overflow-retry`:return`溢出重试`;case`timeout-retry`:return`超时重试`;default:return e}}function j(e){return typeof e.tokensBefore==`number`&&typeof e.tokensAfter==`number`&&Number.isFinite(e.tokensBefore)&&Number.isFinite(e.tokensAfter)?`${e.tokensBefore.toLocaleString()} → ${e.tokensAfter.toLocaleString()} 个 token`:typeof e.tokensBefore==`number`&&Number.isFinite(e.tokensBefore)?`之前 ${e.tokensBefore.toLocaleString()} 个 token`:`token 增量不可用`}function M(e){return e instanceof Element&&!!e.closest(`a, button, input, label, select, textarea`)}function N(t){return e`
    <label class=${[`session-filter-check`,`session-filter-toggle`,t.extraClass??``,t.checked?`session-filter-check--active`:``].filter(Boolean).join(` `)} data-tooltip=${t.title}>
      <input
        name=${t.name}
        class="session-filter-check__input"
        type="checkbox"
        .checked=${t.checked}
        @change=${e=>t.onChange(e.target.checked)}
      />
      <span class="session-filter-check__mark" aria-hidden="true">${s.check}</span>
      <span class="session-filter-check__label">${t.label}</span>
    </label>
  `}function P(n){var r;let i=((r=n.result)==null?void 0:r.sessions)??[],a=T(i,n.searchQuery,n.agentIdentityById),o=E(a,n.sortColumn,n.sortDir),c=o.length,l=Math.max(1,Math.ceil(c/n.pageSize)),u=Math.min(n.page,l-1),d=D(o,u,n.pageSize),f=i.length===0?k(n):a.length===0,p=`在过去 ${n.activeMinutes.trim()} 分钟内更新。`,m=!n.filtersCollapsed,g=m?`隐藏筛选器`:`显示筛选器`,_=(t,r,i=``)=>{let a=n.sortColumn===t,o=a&&n.sortDir===`asc`?`desc`:`asc`;return e`
      <th
        class=${i}
        data-sortable
        data-sort-dir=${a?n.sortDir:``}
        @click=${()=>n.onSortChange(t,a?o:`desc`)}
      >
        ${r}
        <span class="data-table-sort-icon">${s.arrowUpDown}</span>
      </th>
    `};return e`
    <section class="card">
      <div class="row" style="justify-content: space-between; margin-bottom: 12px;">
        <div>
          <div class="card-title">${`会话`}</div>
          <div class="card-sub">
            ${n.result?`存储：${n.result.path}`:`活动会话密钥和每个会话的覆盖设置。`}
          </div>
        </div>
        <div style="display:flex;align-items:center;gap:8px;">
          <button
            class="btn btn--sm btn--icon ${n.archiveEnabled?`active`:``}"
            title=${n.archiveEnabled?`自动重置已启用，会话将按计划清空`:`自动重置已关闭，会话历史持续保留`}
            aria-label=${n.archiveEnabled?`自动重置已启用`:`自动重置已关闭`}
            aria-pressed=${String(!!n.archiveEnabled)}
            @click=${()=>{var e;return(e=n.onToggleArchive)==null?void 0:e.call(n)}}
          >
            ${s.archive}
          </button>
          <button class="btn" ?disabled=${n.loading} @click=${n.onRefresh}>
            ${n.loading?`加载中…`:`刷新`}
          </button>
        </div>
      </div>

      <div class="sessions-filter-panel">
        <div class="sessions-filter-panel__header">
          <div class="sessions-filter-panel__title">${`筛选`}</div>
          <button
            class="sessions-filter-panel__toggle"
            type="button"
            aria-expanded=${String(m)}
            aria-controls="sessions-filter-bar"
            @click=${n.onToggleFiltersCollapsed}
          >
            ${m?s.chevronDown:s.chevronRight}
            <span>${g}</span>
          </button>
        </div>

        ${m?e`
              <div
                id="sessions-filter-bar"
                class="sessions-filter-bar"
                aria-label="Session filters"
              >
                <div class="session-filter-primary-row">
                  <label class="session-filter-field" data-tooltip=${p}>
                    <span class="session-filter-label">${`活跃`}</span>
                    <input
                      class="session-filter-input session-filter-input--minutes"
                      placeholder=${`分钟`}
                      .value=${n.activeMinutes}
                      ?disabled=${n.showArchived}
                      @input=${e=>n.onFiltersChange({activeMinutes:e.target.value,limit:n.limit,includeGlobal:n.includeGlobal,includeUnknown:n.includeUnknown,showArchived:n.showArchived})}
                    />
                  </label>
                  <label class="session-filter-field" data-tooltip=${`要加载的最大会话数。`}>
                    <span class="session-filter-label">${`限制`}</span>
                    <input
                      class="session-filter-input session-filter-input--limit"
                      .value=${n.limit}
                      @input=${e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:e.target.value,includeGlobal:n.includeGlobal,includeUnknown:n.includeUnknown,showArchived:n.showArchived})}
                    />
                  </label>
                </div>
                <div
                  class="session-filter-toggle-group"
                  role="group"
                  aria-label=${`会话来源筛选器`}
                >
                  ${N({name:`includeGlobal`,checked:n.includeGlobal,label:`全局`,title:`包含全局会话。`,onChange:e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:n.limit,includeGlobal:e,includeUnknown:n.includeUnknown,showArchived:n.showArchived})})}
                  ${N({name:`includeUnknown`,checked:n.includeUnknown,label:`未知`,title:`包含未知会话。`,onChange:e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:n.limit,includeGlobal:n.includeGlobal,includeUnknown:e,showArchived:n.showArchived})})}
                  ${N({name:`showArchived`,checked:n.showArchived,label:`显示已归档`,title:`包含已归档会话。`,extraClass:`session-archive-toggle`,onChange:e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:n.limit,includeGlobal:n.includeGlobal,includeUnknown:n.includeUnknown,showArchived:e})})}
                </div>
              </div>
            `:t}
      </div>

      ${n.error?e`<div class="callout danger" style="margin-bottom: 12px;">${n.error}</div>`:t}

      <div class="data-table-wrapper">
        <div class="data-table-toolbar">
          <div class="data-table-search">
            <input
              type="text"
              placeholder=${`按密钥、代理、标签、类型筛选…`}
              .value=${n.searchQuery}
              @input=${e=>n.onSearchChange(e.target.value)}
            />
          </div>
        </div>

        ${n.selectedKeys.size>0?e`
              <div class="data-table-bulk-bar">
                <span>${`已选择 ${String(n.selectedKeys.size)} 项`}</span>
                <button class="btn btn--sm" @click=${n.onDeselectAll}>${`取消选择`}</button>
                <button
                  class="btn btn--sm danger"
                  ?disabled=${n.loading}
                  @click=${n.onDeleteSelected}
                >
                  ${s.trash} ${`删除`}
                </button>
              </div>
            `:t}

        <div class="data-table-container">
          <table class="data-table sessions-table">
            <thead>
              <tr>
                <th class="data-table-checkbox-col">
                  ${d.length>0?e`<input
                        type="checkbox"
                        .checked=${d.length>0&&d.every(e=>n.selectedKeys.has(e.key))}
                        .indeterminate=${d.some(e=>n.selectedKeys.has(e.key))&&!d.every(e=>n.selectedKeys.has(e.key))}
                        @change=${()=>{d.every(e=>n.selectedKeys.has(e.key))?n.onDeselectPage(d.map(e=>e.key)):n.onSelectPage(d.map(e=>e.key))}}
                        aria-label=${`选择本页全部`}
                      />`:t}
                </th>
                ${_(`key`,`密钥`,`data-table-key-col`)}
                <th>${`标签`}</th>
                ${_(`kind`,`类型`)}
                <th>${`运行时`}</th>
                ${_(`updated`,`已更新`)} ${_(`tokens`,`Token`)}
                <th>${`压缩`}</th>
                <th>${`思考`}</th>
                <th>${`快速`}</th>
                <th>${`详细`}</th>
                <th>${`推理`}</th>
              </tr>
            </thead>
            <tbody>
              ${d.length===0?e`
                    <tr>
                      <td colspan="12" class="data-table-empty-cell">
                        ${f?e`
                              <div class="data-table-empty-state" role="status" aria-live="polite">
                                <div>${`没有会话符合你的筛选条件。`}</div>
                                <button class="btn btn--sm" @click=${n.onClearFilters}>
                                  ${`显示全部`}
                                </button>
                              </div>
                            `:`未找到会话。`}
                      </td>
                    </tr>
                  `:d.flatMap(e=>F(e,n))}
            </tbody>
          </table>
        </div>

        ${c>0?e`
              <div class="data-table-pagination">
                <div class="data-table-pagination__info">
                  ${u*n.pageSize+1}-${Math.min((u+1)*n.pageSize,c)}
                  of ${c} row${c===1?``:`s`}
                </div>
                <div class="data-table-pagination__controls">
                  <select
                    style="height: 32px; padding: 0 8px; font-size: 13px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--card);"
                    .value=${String(n.pageSize)}
                    @change=${e=>n.onPageSizeChange(Number(e.target.value))}
                  >
                    ${h.map(t=>e`<option value=${t}>${t} per page</option>`)}
                  </select>
                  <button ?disabled=${u<=0} @click=${()=>n.onPageChange(u-1)}>
                    Previous
                  </button>
                  <button
                    ?disabled=${u>=l-1}
                    @click=${()=>n.onPageChange(u+1)}
                  >
                    ${`下一步`}
                  </button>
                </div>
              </div>
            `:t}
      </div>
    </section>
  `}function F(r,a){let s=r.updatedAt?l(r.updatedAt):`不适用`,d=r.thinkingLevel??``,f=d?_(d):``,p=b(v(r),f),h=r.fastMode===!0?`on`:r.fastMode===!1?`off`:``,S=b(C(),h),T=r.verboseLevel??``,E=b(x(),T),D=r.reasoningLevel??``,O=y(m,D),k=r.latestCompactionCheckpoint,N=r.compactionCheckpointCount??0,P=N>0||!!k,F=a.expandedCheckpointKey===r.key,I=a.checkpointItemsByKey[r.key]??[],L=a.checkpointErrorByKey[r.key],R=`session-checkpoints-${encodeURIComponent(r.key)}`,z=n(r.displayName)??null,B=n(r.label)??``,V=!!(z&&z!==r.key&&z!==B),H=c(r.key),U=H?g(a.agentIdentityById,H.agentId):null,W=n(U==null?void 0:U.emoji)??``,G=n(U==null?void 0:U.name)??``,K=G&&H?`${W?`${W} `:``}${G} (${H.channel})`:null,q=K??r.key,J=r.kind!==`global`,Y=J?`${i(`chat`,a.basePath)}?session=${encodeURIComponent(r.key)}`:null,X=r.kind===`cron`?`data-table-badge--cron`:r.kind===`direct`?`data-table-badge--direct`:r.kind===`group`?`data-table-badge--group`:r.kind===`global`?`data-table-badge--global`:`data-table-badge--unknown`,Z=[`session-data-row`,P?`session-data-row--expandable`:``,F?`session-data-row--expanded`:``].filter(Boolean).join(` `),Q=()=>{P&&a.onToggleCheckpointDetails(r.key)};return[e`<tr
      class=${Z}
      tabindex=${P?`0`:t}
      aria-expanded=${P?String(F):t}
      aria-controls=${P?R:t}
      @click=${e=>{!P||M(e.target)||Q()}}
      @keydown=${e=>{!P||M(e.target)||(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Q())}}
    >
      <td class="data-table-checkbox-col">
        <input
          type="checkbox"
          .checked=${a.selectedKeys.has(r.key)}
          @change=${()=>a.onToggleSelect(r.key)}
          aria-label=${`选择会话`}
        />
      </td>
      <td class="data-table-key-col">
        <div
          class=${K?`session-key-cell`:`mono session-key-cell`}
          title=${q}
        >
          ${J?e`<a
                href=${Y}
                class="session-link"
                @click=${e=>{e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||a.onNavigateToChat&&(e.preventDefault(),a.onNavigateToChat(r.key))}}
                >${K??r.key}</a
              >`:K??r.key}
          ${V?e`<span class="muted session-key-display-name">${z}</span>`:t}
        </div>
      </td>
      <td>
        <input
          .value=${r.label??``}
          ?disabled=${a.loading}
          placeholder=${`（可选）`}
          style="width: 100%; max-width: 140px; padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);"
          @change=${e=>{let t=n(e.target.value)??null;a.onPatch(r.key,{label:t})}}
        />
      </td>
      <td>
        <span class="data-table-badge ${X}">${r.kind}</span>
      </td>
      <td class="session-runtime-cell">
        <span class="mono">${o(r.agentRuntime)}</span>
      </td>
      <td>${s}</td>
      <td class="session-token-cell">${u(r)}</td>
      <td>
        <div style="display: grid; gap: 6px;">
          <span class="muted" style="font-size: 12px;">
            ${N>0?`${String(N)} 个检查点`:`无`}
          </span>
          ${k?e`
                <span style="font-size: 12px;">
                  ${A(k.reason)} ·
                  ${l(k.createdAt)}
                </span>
              `:t}
          ${P?e`
                <button
                  class="btn btn--sm session-checkpoint-toggle"
                  ?disabled=${a.checkpointLoadingKey===r.key}
                  aria-expanded=${String(F)}
                  aria-controls=${R}
                  @click=${()=>a.onToggleCheckpointDetails(r.key)}
                >
                  ${F?`隐藏检查点`:`显示检查点`}
                </button>
              `:t}
        </div>
      </td>
      <td>
        <select
          ?disabled=${a.loading}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;a.onPatch(r.key,{thinkingLevel:w(t)})}}
        >
          ${p.map(t=>e`<option value=${t.value} ?selected=${f===t.value}>
                ${t.label}
              </option>`)}
        </select>
      </td>
      <td>
        <select
          ?disabled=${a.loading}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;a.onPatch(r.key,{fastMode:t===``?null:t===`on`})}}
        >
          ${S.map(t=>e`<option value=${t.value} ?selected=${h===t.value}>
                ${t.label}
              </option>`)}
        </select>
      </td>
      <td>
        <select
          ?disabled=${a.loading}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;a.onPatch(r.key,{verboseLevel:t||null})}}
        >
          ${E.map(t=>e`<option value=${t.value} ?selected=${T===t.value}>
                ${t.label}
              </option>`)}
        </select>
      </td>
      <td>
        <select
          ?disabled=${a.loading}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;a.onPatch(r.key,{reasoningLevel:t||null})}}
        >
          ${O.map(t=>e`<option value=${t} ?selected=${D===t}>
                ${t||`继承`}
              </option>`)}
        </select>
      </td>
    </tr>`,...F&&P?[e`<tr id=${R} class="session-checkpoint-details-row">
            <td colspan="12" style="padding: 0;">
              <div
                style="padding: 14px 16px; border-top: 1px solid var(--border); background: var(--surface-2, rgba(127, 127, 127, 0.05));"
              >
                ${a.checkpointLoadingKey===r.key?e`<div class="muted">${`正在加载检查点…`}</div>`:L?e`<div class="callout danger">${L}</div>`:I.length===0?e`<div class="muted">${`此会话没有记录压缩检查点。`}</div>`:e`
                          <div style="display: grid; gap: 10px;">
                            ${I.map(t=>e`
                                <div
                                  style="border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; display: grid; gap: 8px;"
                                >
                                  <div
                                    style="display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap;"
                                  >
                                    <strong>
                                      ${A(t.reason)} ·
                                      ${l(t.createdAt)}
                                    </strong>
                                    <span class="muted" style="font-size: 12px;">
                                      ${j(t)}
                                    </span>
                                  </div>
                                  ${t.summary?e`<div style="white-space: pre-wrap;">
                                        ${t.summary}
                                      </div>`:e`<div class="muted">${`未捕获摘要。`}</div>`}
                                  <div style="display: flex; gap: 8px; flex-wrap: wrap;">
                                    <button
                                      class="btn btn--sm"
                                      ?disabled=${a.checkpointBusyKey===t.checkpointId}
                                      @click=${()=>a.onBranchFromCheckpoint(r.key,t.checkpointId)}
                                    >
                                      ${`从检查点创建分支`}
                                    </button>
                                    <button
                                      class="btn btn--sm"
                                      ?disabled=${a.checkpointBusyKey===t.checkpointId}
                                      @click=${()=>a.onRestoreCheckpoint(r.key,t.checkpointId)}
                                    >
                                      ${`恢复检查点`}
                                    </button>
                                  </div>
                                </div>
                              `)}
                          </div>
                        `}
              </div>
            </td>
          </tr>`]:[]]}export{P as renderSessions};
//# sourceMappingURL=sessions-Bfg2Wer6.js.map