import{i as e,n as t}from"./lit-Cl9PTnWs.js";import{r as n}from"./i18n-Ber8EPgj.js";import{a as r,i,r as a,t as o}from"./cognitive-shared-hZ0I1rin.js";function s(e){let t=Date.now()-e;if(t<0)return n(`common.justNow`)??`刚刚`;let r=Math.floor(t/1e3);if(r<60)return n(`common.justNow`)??`刚刚`;let i=Math.floor(r/60);if(i<60)return`${i}分钟前`;let a=Math.floor(i/60);if(a<24)return`${a}小时前`;let o=Math.floor(a/24);return o<30?`${o}天前`:`${Math.floor(o/30)}个月前`}function c(e){if(e<1e3)return`${e}ms`;let t=e/1e3;return t<60?`${t.toFixed(1)}s`:`${Math.floor(t/60)}m ${Math.floor(t%60)}s`}function l(e){return e>=.7?`color: #ef4444; border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.08);`:e>=.4?`color: #eab308; border-color: rgba(234,179,8,0.3); background: rgba(234,179,8,0.08);`:`color: var(--muted);`}function u(t){if(!t)return e`<span class="pill" style="opacity:0.6;">无回应</span>`;let{label:n,style:r}={accepted:{label:`已接受`,style:`color: #22c55e; border-color: rgba(34,197,94,0.3); background: rgba(34,197,94,0.08);`},modified:{label:`已修改`,style:`color: #eab308; border-color: rgba(234,179,8,0.3); background: rgba(234,179,8,0.08);`},rejected:{label:`已拒绝`,style:`color: #ef4444; border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.08);`}}[t];return e`<span class="pill" style="${r}">${n}</span>`}function d(t){let{label:n,style:r}={success:{label:`成功`,style:`color: #22c55e; border-color: rgba(34,197,94,0.3); background: rgba(34,197,94,0.08);`},failure:{label:`失败`,style:`color: #ef4444; border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.08);`},skipped:{label:`已跳过`,style:`color: var(--muted); opacity: 0.6;`}}[t];return e`<span class="pill" style="${r}">${n}</span>`}function f(n){return n.length===0?e`<div class="callout info">暂无进化记录。</div>`:e`
    <div style="position: relative; padding-left: 24px;">
      <!-- Vertical timeline line -->
      <div
        style="
        position: absolute;
        left: 8px;
        top: 0;
        bottom: 0;
        width: 2px;
        background: var(--border, #e5e7eb);
      "
      ></div>

      ${n.map(n=>{let r=n.candidate,i=n.decision;return e`
          <div style="position: relative; margin-bottom: 16px;">
            <!-- Timeline dot -->
            <div
              style="
              position: absolute;
              left: -20px;
              top: 14px;
              width: 12px;
              height: 12px;
              border-radius: 50%;
              background: ${i?.shouldSuggest?`#3b82f6`:`var(--muted, #9ca3af)`};
              border: 2px solid var(--bg, #fff);
            "
            ></div>

            <div class="card" style="padding: 12px;">
              <!-- Header: task summary + time -->
              <div
                style="display:flex; align-items:flex-start; justify-content:space-between; gap:8px; margin-bottom:8px; flex-wrap:wrap;"
              >
                <div style="font-weight:600; flex:1; min-width:200px;">${r.taskSummary}</div>
                <span class="text-muted" style="font-size:0.85em; white-space:nowrap;"
                  >${s(n.timestamp)}</span
                >
              </div>

              <!-- Badges row -->
              <div
                style="display:flex; align-items:center; gap:6px; margin-bottom:8px; flex-wrap:wrap;"
              >
                <span class="pill">${r.domain}</span>
                <span class="pill" style="font-size:0.8em;"
                  >${r.toolCalls.length}次调用 · ${r.uniqueToolCount}个独立</span
                >
                <span class="pill" style="font-size:0.8em;">${c(r.durationMs)}</span>
                ${r.hasTrialAndError?e`<span class="pill warning" style="font-size:0.8em;">试错</span>`:t}
                ${i?e`
                      <span
                        class="pill"
                        style="font-size:0.8em; ${l(i.complexityScore)}"
                      >
                        复杂度：${(i.complexityScore*100).toFixed(0)}%
                      </span>
                      <span
                        class="pill ${i.shouldSuggest?`success`:``}"
                        style="font-size:0.8em;"
                      >
                        ${i.shouldSuggest?`已建议`:`跳过`}
                      </span>
                      <span class="pill" style="font-size:0.8em;">
                        置信度：${(i.confidence*100).toFixed(0)}%
                      </span>
                    `:t}
              </div>

              <!-- Decision reasoning -->
              ${i?.reasoning?e`
                    <div class="text-muted" style="font-size:0.85em; margin-bottom:8px;">
                      ${i.reasoning}
                    </div>
                  `:t}

              <!-- User response -->
              <div style="display:flex; align-items:center; gap:6px; margin-bottom:8px;">
                ${u(n.userResponse)}
                ${n.savedSkillPath?e`<span class="text-muted" style="font-size:0.8em;"
                      >→ ${n.savedSkillPath}</span
                    >`:t}
              </div>

              <!-- Skill draft preview -->
              ${n.draft?e`
                    <div class="callout info" style="padding:8px 12px; margin-top:4px;">
                      <div style="font-weight:600; margin-bottom:4px;">草稿：${n.draft.name}</div>
                      <div class="text-muted" style="font-size:0.85em; margin-bottom:4px;">
                        ${n.draft.description}
                      </div>
                      ${n.draft.triggerPhrases.length>0?e`
                            <div style="display:flex; gap:4px; flex-wrap:wrap;">
                              ${n.draft.triggerPhrases.map(t=>e`<span class="pill" style="font-size:0.75em;">"${t}"</span>`)}
                            </div>
                          `:t}
                    </div>
                  `:t}
            </div>
          </div>
        `})}
    </div>
  `}function p(t){return t.length===0?e`<div class="callout info">暂无审计日志。</div>`:e`
    <div style="overflow-x: auto;">
      <table style="width:100%; border-collapse:collapse; font-size:0.9em;">
        <thead>
          <tr style="border-bottom:2px solid var(--border, #e5e7eb); text-align:left;">
            <th style="padding:8px 12px;">时间</th>
            <th style="padding:8px 12px;">操作</th>
            <th style="padding:8px 12px;">执行者</th>
            <th style="padding:8px 12px;">目标</th>
            <th style="padding:8px 12px;">结果</th>
          </tr>
        </thead>
        <tbody>
          ${t.map(t=>e`
              <tr style="border-bottom:1px solid var(--border, #e5e7eb);">
                <td style="padding:8px 12px; white-space:nowrap; color:var(--muted, #9ca3af);">
                  ${s(t.timestamp)}
                </td>
                <td style="padding:8px 12px;">${t.operation}</td>
                <td style="padding:8px 12px;">${t.actor}</td>
                <td
                  style="padding:8px 12px; max-width:260px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;"
                  title=${t.target}
                >
                  ${t.target}
                </td>
                <td style="padding:8px 12px;">${d(t.outcome)}</td>
              </tr>
            `)}
        </tbody>
      </table>
    </div>
  `}function m(t){if(t.loading)return e`<div class="page-loader">${n(`common.loading`)}</div>`;if(t.error)return e`<div class="callout danger">${t.error}</div>`;let s=o(t.personaList);if(!s||s.agents.length===0)return a(`暂无用户数据`,`先与机器人对话后，画像会自动生成。`);let c=r({list:s,selectedUserId:t.userId,selectedAgentId:t.agentId,onUserSelect:t.onUserSelect,onRefresh:t.onRefresh,headerTitle:`用户`});if(!t.agentId||!t.userId)return i(c,a(`请选择一个用户查看进化记录`,`点击左侧用户卡片查看进化历史。`));let l=t.records,u=t.auditEntries,d=l.toSorted((e,t)=>t.timestamp-e.timestamp),m=u.toSorted((e,t)=>t.timestamp-e.timestamp);return i(c,e`
    <div class="stack">
      <!-- Evolution Records Timeline -->
      <div class="card">
        <div
          style="display:flex; align-items:center; justify-content:space-between; margin-bottom:12px;"
        >
          <h4 style="margin:0;">进化记录</h4>
          <span class="text-muted" style="font-size:0.85em;">${d.length}条记录</span>
        </div>
        ${f(d)}
      </div>

      <!-- Audit Log -->
      <div class="card">
        <div
          style="display:flex; align-items:center; justify-content:space-between; margin-bottom:12px;"
        >
          <h4 style="margin:0;">审计日志</h4>
          <span class="text-muted" style="font-size:0.85em;">${m.length}条审计</span>
        </div>
        ${p(m)}
      </div>
    </div>
  `)}export{m as renderEvolution};
//# sourceMappingURL=evolution-CWiqCQAK.js.map