import{j as t}from"./iframe-B8FSoBNY.js";import{c as q}from"./compiler-runtime-BXE7OOXE.js";import"./collaborative-markdown-editor-Bj0GvTvv.js";import"./markdown-editor-Y4eMsgVb.js";import"./prompt-input-BLCttowi.js";import{R as x}from"./rich-message-BIkzo1SM.js";import"./CodeBlockPlugin-C3OWpvP8.js";import{R as b}from"./ai-response-ySM6s0iN.js";import{T as w}from"./tool-invocation-timeline-B-cS0W6M.js";import{B as p}from"./index-B0y2_lLF.js";import{S as P}from"./spinner-ZYH_gvW-.js";import{T as y}from"./index-cFwdnc0b.js";const j=e=>e.type==="text"&&"text"in e,R=e=>e.type==="reasoning"&&"text"in e,h=e=>e.type==="tool",S=e=>e.type==="loading",I=e=>e.type==="error",M=e=>e.type==="token_usage",v=e=>e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e);function F(e){const r=q.c(7),{message:s,onOpenFile:a,toolInvocationTimeline:T}=e,g=T??w;let d;r[0]!==s.parts?(d=s.parts??[],r[0]=s.parts,r[1]=d):d=r[1];const u=d;let c;if(r[2]!==g||r[3]!==s.id||r[4]!==a||r[5]!==u){const i=[];for(let o=0;o<u.length;o++){const n=u[o],l=`${s.id}-${o}`;if(j(n)){i.push(t.jsx("div",{children:t.jsx(b,{children:n.text})},l));continue}if(R(n)){i.push(t.jsx(p,{padding:"0",css:{"& .rich-text, & .rich-text *":{color:"fg.subtle !important",fontSize:".75rem !important",fontWeight:"normal !important"}},children:t.jsx(x,{defaultState:n.text})},l));continue}if(h(n)){const k=[n];let m=o+1;for(;m<u.length;){const f=u[m];if(!h(f))break;k.push(f),m=m+1}o=m-1,i.push(t.jsx(p,{width:"full",children:t.jsx(g,{invocations:k,labeledBlocks:!0,onOpenFile:a})},l));continue}if(S(n)){i.push(t.jsxs(p,{display:"flex",alignItems:"center",gap:"2",py:"2",children:[t.jsx(P,{size:"sm"}),t.jsx(y,{fontSize:"sm",color:"fg.muted",children:"Thinking..."})]},l));continue}if(I(n)){i.push(t.jsx(p,{py:"2",children:t.jsx(y,{fontSize:"sm",color:"fg.error",children:n.errorType==="timeout"?"Session timed out.":n.errorType==="crash"?"Session crashed unexpectedly.":n.errorType==="permission"?"Permission denied.":"An error occurred."})},l));continue}if(M(n)){i.push(t.jsx(p,{py:"1",children:t.jsxs(y,{fontSize:"xs",color:"fg.subtle",children:["Tokens: ",v(n.inputTokens)," in / ",v(n.outputTokens)," out",n.cacheReadTokens?` / ${v(n.cacheReadTokens)} cache read`:""]})},l));continue}i.push(null)}c=t.jsx(t.Fragment,{children:i}),r[2]=g,r[3]=s.id,r[4]=a,r[5]=u,r[6]=c}else c=r[6];return c}F.__docgenInfo={description:"",methods:[],displayName:"MessagePartsRenderer",props:{message:{required:!0,tsType:{name:"signature",type:"object",raw:`{
  id: string;
  role: SessionMessageRole;
  parts: SessionMessagePart[];
  index?: number;
  createdAt?: number;
  modelId?: string;
  providerId?: string;
  tokens?: {
    input?: number;
    output?: number;
    reasoning?: number;
    cache?: { read?: number; write?: number };
  };
}`,signature:{properties:[{key:"id",value:{name:"string",required:!0}},{key:"role",value:{name:"union",raw:'"user" | "assistant" | "tool" | "system" | "developer"',elements:[{name:"literal",value:'"user"'},{name:"literal",value:'"assistant"'},{name:"literal",value:'"tool"'},{name:"literal",value:'"system"'},{name:"literal",value:'"developer"'}],required:!0}},{key:"parts",value:{name:"Array",elements:[{name:"union",raw:`| TextPart
| ReasoningPart
| ToolPart
| StepStartPart
| StepFinishPart
| PatchPart
| FilePart
| LoadingPart
| ErrorPart
| TokenUsagePart`,elements:[{name:"signature",type:"object",raw:'{ type: "text"; text: string }',signature:{properties:[{key:"type",value:{name:"literal",value:'"text"',required:!0}},{key:"text",value:{name:"string",required:!0}}]}},{name:"signature",type:"object",raw:'{ type: "reasoning"; text: string }',signature:{properties:[{key:"type",value:{name:"literal",value:'"reasoning"',required:!0}},{key:"text",value:{name:"string",required:!0}}]}},{name:"signature",type:"object",raw:`{
  type: "tool";
  tool: string;
  callId?: string;
  actionType?: ToolPartActionType;
  status?: ToolPartStatus;
  state?: {
    status?: string;
    input?: unknown;
    output?: unknown;
    errorText?: string;
    metadata?: unknown;
  };
}`,signature:{properties:[{key:"type",value:{name:"literal",value:'"tool"',required:!0}},{key:"tool",value:{name:"string",required:!0}},{key:"callId",value:{name:"string",required:!1}},{key:"actionType",value:{name:"union",raw:'"read" | "write" | "execute" | "network" | "other"',elements:[{name:"literal",value:'"read"'},{name:"literal",value:'"write"'},{name:"literal",value:'"execute"'},{name:"literal",value:'"network"'},{name:"literal",value:'"other"'}],required:!1}},{key:"status",value:{name:"union",raw:'"pending" | "running" | "completed" | "failed" | "denied"',elements:[{name:"literal",value:'"pending"'},{name:"literal",value:'"running"'},{name:"literal",value:'"completed"'},{name:"literal",value:'"failed"'},{name:"literal",value:'"denied"'}],required:!1}},{key:"state",value:{name:"signature",type:"object",raw:`{
  status?: string;
  input?: unknown;
  output?: unknown;
  errorText?: string;
  metadata?: unknown;
}`,signature:{properties:[{key:"status",value:{name:"string",required:!1}},{key:"input",value:{name:"unknown",required:!1}},{key:"output",value:{name:"unknown",required:!1}},{key:"errorText",value:{name:"string",required:!1}},{key:"metadata",value:{name:"unknown",required:!1}}]},required:!1}}]}},{name:"signature",type:"object",raw:'{ type: "step-start"; snapshot?: string }',signature:{properties:[{key:"type",value:{name:"literal",value:'"step-start"',required:!0}},{key:"snapshot",value:{name:"string",required:!1}}]}},{name:"signature",type:"object",raw:`{
  type: "step-finish";
  reason?: string;
  snapshot?: string;
  cost?: number;
  tokens?: unknown;
}`,signature:{properties:[{key:"type",value:{name:"literal",value:'"step-finish"',required:!0}},{key:"reason",value:{name:"string",required:!1}},{key:"snapshot",value:{name:"string",required:!1}},{key:"cost",value:{name:"number",required:!1}},{key:"tokens",value:{name:"unknown",required:!1}}]}},{name:"signature",type:"object",raw:'{ type: "patch"; hash?: string; files?: unknown }',signature:{properties:[{key:"type",value:{name:"literal",value:'"patch"',required:!0}},{key:"hash",value:{name:"string",required:!1}},{key:"files",value:{name:"unknown",required:!1}}]}},{name:"signature",type:"object",raw:'{ type: "file"; mediaType?: string; filename?: string; url: string }',signature:{properties:[{key:"type",value:{name:"literal",value:'"file"',required:!0}},{key:"mediaType",value:{name:"string",required:!1}},{key:"filename",value:{name:"string",required:!1}},{key:"url",value:{name:"string",required:!0}}]}},{name:"signature",type:"object",raw:'{ type: "loading" }',signature:{properties:[{key:"type",value:{name:"literal",value:'"loading"',required:!0}}]}},{name:"signature",type:"object",raw:'{ type: "error"; errorType: "timeout" | "crash" | "permission" | "other" }',signature:{properties:[{key:"type",value:{name:"literal",value:'"error"',required:!0}},{key:"errorType",value:{name:"union",raw:'"timeout" | "crash" | "permission" | "other"',elements:[{name:"literal",value:'"timeout"'},{name:"literal",value:'"crash"'},{name:"literal",value:'"permission"'},{name:"literal",value:'"other"'}],required:!0}}]}},{name:"signature",type:"object",raw:`{
  type: "token_usage";
  inputTokens: number;
  outputTokens: number;
  cacheReadTokens?: number;
  cacheWriteTokens?: number;
}`,signature:{properties:[{key:"type",value:{name:"literal",value:'"token_usage"',required:!0}},{key:"inputTokens",value:{name:"number",required:!0}},{key:"outputTokens",value:{name:"number",required:!0}},{key:"cacheReadTokens",value:{name:"number",required:!1}},{key:"cacheWriteTokens",value:{name:"number",required:!1}}]}}]}],raw:"SessionMessagePart[]",required:!0}},{key:"index",value:{name:"number",required:!1}},{key:"createdAt",value:{name:"number",required:!1}},{key:"modelId",value:{name:"string",required:!1}},{key:"providerId",value:{name:"string",required:!1}},{key:"tokens",value:{name:"signature",type:"object",raw:`{
  input?: number;
  output?: number;
  reasoning?: number;
  cache?: { read?: number; write?: number };
}`,signature:{properties:[{key:"input",value:{name:"number",required:!1}},{key:"output",value:{name:"number",required:!1}},{key:"reasoning",value:{name:"number",required:!1}},{key:"cache",value:{name:"signature",type:"object",raw:"{ read?: number; write?: number }",signature:{properties:[{key:"read",value:{name:"number",required:!1}},{key:"write",value:{name:"number",required:!1}}]},required:!1}}]},required:!1}}]}},description:""},streaming:{required:!1,tsType:{name:"boolean"},description:""},onOpenFile:{required:!1,tsType:{name:"signature",type:"function",raw:"(filePath: string) => void",signature:{arguments:[{type:{name:"string"},name:"filePath"}],return:{name:"void"}}},description:""},toolInvocationTimeline:{required:!1,tsType:{name:"signature",type:"function",raw:"(props: ToolInvocationTimelineProps) => ReactNode",signature:{arguments:[{type:{name:"ToolInvocationTimelineProps"},name:"props"}],return:{name:"ReactNode"}}},description:""}}};const G=e=>e==="user"||e==="assistant"||e==="developer"?e:"assistant",z=e=>{const r=e.parts??[];return r.length===0||r.some(a=>a.type==="text"&&"text"in a)?!1:r.some(a=>a.type==="reasoning"||a.type==="tool")},H=e=>{const r=[];for(const s of e){const a=r[r.length-1];if(a&&a.role===s.role&&z(s)){a.parts=[...a.parts??[],...s.parts??[]];continue}r.push({...s,parts:[...s.parts??[]]})}return r};export{F as M,G as g,H as m};
