import{j as i,L as c,s as l,al as p,T as d,am as m}from"./index-Dbk1Plmn.js";import{E as _}from"./entity_link-qYsgSBpl.js";function v(t){let e=0;for(const s of t.messages)e+=s.related_entities.length;return e}function y(t){var n,o;const e=((n=t.entity_type)==null?void 0:n.trim().toLowerCase())??"",s=((o=t.relationship_type)==null?void 0:o.trim().toUpperCase())??"";return e==="source"||s==="EMBEDS"}function k(t){let e=0;for(const s of t.messages)for(const n of s.related_entities)y(n)&&(e+=1);return e}function j(t){var n,o;const e=(n=t.role)==null?void 0:n.trim(),s=(o=t.sender_kind)==null?void 0:o.trim();return s&&(!e||e.toLowerCase()===s.toLowerCase())?s.toUpperCase():e?e.toUpperCase():s?s.toUpperCase():"MESSAGE"}function f(t){var s;const e=(s=t.turn_key)==null?void 0:s.trim();return e?e.endsWith(":assistant")?e.slice(0,-10):e:null}function h(t){return(t.sender_kind??t.role??"").trim().toLowerCase()==="user"}function C(t){const e=[],s=new Map;for(const n of t){const o=f(n),a=o??`message:${n.message_id}`;let r=s.get(a);r||(r={groupKey:a,turnKey:o,messages:[],userMessages:[],responseMessages:[]},e.push(r),s.set(a,r)),r.messages.push(n),h(n)?r.userMessages.push(n):r.responseMessages.push(n)}return e}function b({entity:t}){var s,n;const e=((s=t.title)==null?void 0:s.trim())||((n=t.canonical_name)==null?void 0:n.trim())||l(t.entity_id,10);return i.jsx("div",{className:"flex items-center justify-between gap-3 rounded border px-3 py-2",children:i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:p(t.relationship_type)}),t.entity_type?i.jsx(d,{type:t.entity_type,label:m(t.entity_type),humanize:!0}):null]}),i.jsx("div",{className:"mt-1 min-w-0",children:i.jsx(_,{id:t.entity_id,name:e,className:"truncate"})})]})})}function w({message:t}){const e=t.hook_summary;if(!e)return null;const s=t.turn_key;if(e.hook_event_count+e.tool_invocation_count+e.store_structured_calls+e.retrieve_calls+e.stored_entity_count+e.retrieved_entity_count+e.neotoma_tool_failures===0)return null;const o=[];e.hook_event_count>0&&o.push(`${e.hook_event_count} hook${e.hook_event_count===1?"":"s"}`),e.tool_invocation_count>0&&o.push(`${e.tool_invocation_count} tool${e.tool_invocation_count===1?"":"s"}`),e.stored_entity_count>0&&o.push(`${e.stored_entity_count} stored`),e.retrieved_entity_count>0&&o.push(`${e.retrieved_entity_count} retrieved`);const a=o.length>0?o.join(" · "):"hook activity",r=i.jsx("span",{className:"rounded bg-primary/10 px-1.5 py-0.5 text-[11px] font-medium text-primary",children:a});return s?i.jsx(c,{to:`/turns/${encodeURIComponent(s)}`,onClick:u=>u.stopPropagation(),title:"View turn detail",className:"rounded bg-primary/10 px-1.5 py-0.5 text-[11px] font-medium text-primary hover:bg-primary/20",children:a}):r}export{w as H,b as R,k as a,C as g,j as m,v as t};
