import{r as P,j as n}from"./iframe-B8FSoBNY.js";import{c as V}from"./compiler-runtime-BXE7OOXE.js";import{r as ne}from"./full-conversation-normalized-LUbl1coD.js";import{E as ae}from"./empty-state-BXkyq69k.js";import"./collaborative-markdown-editor-Bj0GvTvv.js";import"./markdown-editor-Y4eMsgVb.js";import{g as se}from"./prompt-input-BLCttowi.js";import"./rich-message-BIkzo1SM.js";import"./CodeBlockPlugin-C3OWpvP8.js";import{u as ie,C as L}from"./ai-conversation-DcjS--ee.js";import{C as Y}from"./ai-message-DLdAGhWH.js";import{C as oe}from"./chat-input-B-915nCM.js";import{m as ue,g as le,M as me}from"./message-types-CEyA7Qm7.js";import{S as pe}from"./stack-CN4X31TA.js";import{c as ce}from"./createLucideIcon-CcBBUKX8.js";import{F as Q}from"./flex-DAJL4AFZ.js";import{B as D}from"./index-B0y2_lLF.js";import{H as te}from"./h-stack-DWHd8f97.js";import{T as de}from"./index-cFwdnc0b.js";import{B as U}from"./button-C7it2n8t.js";import"./preload-helper-PPVm8Dsz.js";import"./v-stack-Btoq6OB_.js";import"./create-slot-recipe-context-DAhDE6G_.js";import"./factory-DAJZwK4o.js";import"./create-recipe-context-BU56IzEo.js";import"./rich-text-theme-Bkhh9rAZ.js";import"./index-DaXC_qY_.js";import"./index-DpB4ozcR.js";import"./FloatingTextFormatToolbarPlugin-B6jc8xvg.js";import"./resource-badge-Bw5UoU4J.js";import"./file-text-D5m8MJlG.js";import"./tooltip-DZxUoouw.js";import"./portal-CZHfPTRw.js";import"./normalize-props-D7NI5JRu.js";import"./factory-BR3bc_RM.js";import"./tooltip-C_a-XGZ8.js";import"./use-presence-context-DK2PGZth.js";import"./create-split-props-u5h9OPvL.js";import"./computed-style-C0hzrq9-.js";import"./overflow-CkG1DOya.js";import"./icon-button-DHiUe7rR.js";import"./x-D42ziktz.js";import"./LexicalHistoryPlugin.prod-BQAibkDj.js";import"./TreeViewPlugin-CyVKCrKJ.js";import"./markdown-BLUemkxK.js";import"./textarea-rqmaWSc5.js";import"./use-field-context-DoxKQlMm.js";import"./table-BKNSzs2r.js";import"./ai-response-ySM6s0iN.js";import"./tool-invocation-timeline-B-cS0W6M.js";import"./trash-2-BO05slEk.js";import"./index-CXwl6T4k.js";import"./spinner-ZYH_gvW-.js";import"./mutation-observer-CAfGweIM.js";import"./link-DE5grRtm.js";import"./diff-bubble-_zZypMRt.js";import"./diff-editor-DV9BXqbn.js";const ge=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}]],ye=ce("message-circle",ge),fe=(t="")=>JSON.stringify(se(t)),ve=t=>{const{previousUserMessageCount:e,userMessageCount:r}=t;return e===0?!1:r>e};function he(t){const e=V.c(4),{userMessageCount:r}=t,{scrollToBottom:o}=ie(),a=P.useRef(r);let s,i;return e[0]!==o||e[1]!==r?(s=()=>{ve({previousUserMessageCount:a.current,userMessageCount:r})&&o(),a.current=r},i=[r,o],e[0]=o,e[1]=r,e[2]=s,e[3]=i):(s=e[2],i=e[3]),P.useEffect(s,i),null}const ke=fe(),Z=t=>{const e=V.c(43),{messages:r,streaming:o,emptyStateTitle:a,emptyStateDescription:s,chatInputPlaceholder:i,onSubmitMessage:l,actions:d,repoMenu:R,attachedResources:C,onClearAttachments:m,attachmentList:T,approvalPrompt:I}=t,p=o===void 0?!1:o;let b,c,g,w,y,f,v,h,k,x;if(e[0]!==s||e[1]!==a||e[2]!==r||e[3]!==p){const E=ue(r),F=E.length>0,N=E.reduce(xe,0);g=Q,f="relative",v="column",h="full",k="full",x="hidden",c=L.Root,y=n.jsx(he,{userMessageCount:N}),b=L.Viewport,w=F?n.jsx(pe,{gap:"sm",children:E.map(B=>{const K=le(B.role);return n.jsx(Y.Root,{from:K,children:n.jsx(Y.Content,{from:K,children:n.jsx(me,{message:B,streaming:p})})},B.id)})}):n.jsx(ae,{icon:n.jsx(ye,{size:48,strokeWidth:1.5}),title:a,description:s}),e[0]=s,e[1]=a,e[2]=r,e[3]=p,e[4]=b,e[5]=c,e[6]=g,e[7]=w,e[8]=y,e[9]=f,e[10]=v,e[11]=h,e[12]=k,e[13]=x}else b=e[4],c=e[5],g=e[6],w=e[7],y=e[8],f=e[9],v=e[10],h=e[11],k=e[12],x=e[13];let q;e[14]!==b||e[15]!==w?(q=n.jsx(b,{children:w}),e[14]=b,e[15]=w,e[16]=q):q=e[16];let j;e[17]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(L.ScrollToBottom,{"aria-label":"Scroll to latest message"}),e[17]=j):j=e[17];let u;e[18]!==c||e[19]!==y||e[20]!==q?(u=n.jsxs(c,{children:[y,q,j]}),e[18]=c,e[19]=y,e[20]=q,e[21]=u):u=e[21];let S;e[22]!==d||e[23]!==C||e[24]!==T||e[25]!==i||e[26]!==m||e[27]!==l||e[28]!==p?(S=n.jsx(D,{px:"sm",children:n.jsx(oe,{placeholder:i,defaultState:ke,streaming:p,onSubmit:l,actions:d,attachedResources:C,onClearAttachments:m,attachmentList:T})}),e[22]=d,e[23]=C,e[24]=T,e[25]=i,e[26]=m,e[27]=l,e[28]=p,e[29]=S):S=e[29];let M;e[30]!==R?(M=n.jsx(Q,{p:"2xs",justifyContent:"flex-end",children:R}),e[30]=R,e[31]=M):M=e[31];let A;return e[32]!==g||e[33]!==I||e[34]!==u||e[35]!==S||e[36]!==M||e[37]!==f||e[38]!==v||e[39]!==h||e[40]!==k||e[41]!==x?(A=n.jsxs(g,{position:f,direction:v,w:h,h:k,overflow:x,children:[u,I,S,M]}),e[32]=g,e[33]=I,e[34]=u,e[35]=S,e[36]=M,e[37]=f,e[38]=v,e[39]=h,e[40]=k,e[41]=x,e[42]=A):A=e[42],A};Z.__docgenInfo={description:"",methods:[],displayName:"ChatPanel",props:{messages:{required:!0,tsType:{name:"Array",elements:[{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}}]}}],raw:"SessionMessage[]"},description:""},streaming:{required:!1,tsType:{name:"boolean"},description:""},emptyStateTitle:{required:!0,tsType:{name:"string"},description:""},emptyStateDescription:{required:!0,tsType:{name:"string"},description:""},chatInputPlaceholder:{required:!0,tsType:{name:"string"},description:""},onSubmitMessage:{required:!1,tsType:{name:"signature",type:"function",raw:"(text: string, attachments: string[]) => void",signature:{arguments:[{type:{name:"string"},name:"text"},{type:{name:"Array",elements:[{name:"string"}],raw:"string[]"},name:"attachments"}],return:{name:"void"}}},description:""},actions:{required:!1,tsType:{name:"ReactNode"},description:""},repoMenu:{required:!1,tsType:{name:"ReactNode"},description:""},attachedResources:{required:!1,tsType:{name:"Array",elements:[{name:"string"}],raw:"string[]"},description:""},onClearAttachments:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:""},attachmentList:{required:!1,tsType:{name:"ReactNode"},description:""},approvalPrompt:{required:!1,tsType:{name:"ReactNode"},description:""}}};function xe(t,e){return t+(e.role==="user"?1:0)}const re=ne,At={title:"Chat UI/Chat Panel",component:Z,parameters:{layout:"padded",actions:{argTypesRegex:"^on[A-Z].*"}}},G={w:"960px",maxW:"100%",h:"680px",bg:"bg",borderWidth:"1px",borderColor:"border",borderRadius:"lg",p:"md"},Se=n.jsxs(te,{gap:"2",children:[n.jsx(U,{size:"xs",variant:"subtle",children:"Opencode"}),n.jsx(U,{size:"xs",variant:"subtle",children:"GPT-5.3 Codex"})]}),Te=n.jsxs(te,{gap:"2",children:[n.jsx(de,{textStyle:"label/S/medium",color:"fg.muted",children:"mono"}),n.jsx(U,{size:"xs",variant:"ghost",children:"main"})]}),be=re.slice(-18),X=10,qe=60,Me=t=>{if(!t)return[];const e=[];for(let r=0;r<t.length;r+=X)e.push(t.slice(r,r+X));return e},W=t=>t.type==="text",H=(t,e,r,o)=>t.map(a=>{if(a.id!==e)return a;const s=a.parts[r];if(!s||!W(s))return a;const i=[...a.parts];return i[r]={...s,text:o},{...a,parts:i}}),we=t=>{for(let e=t.length-1;e>=0;e-=1){const r=t[e];if(r.role!=="assistant")continue;const o=r.parts.findIndex(l=>W(l)&&l.text.trim().length>0);if(o===-1)continue;const a=r.parts[o];if(!a||!W(a))continue;const s=a.text;return{seededMessages:H(t,r.id,o,""),messageId:r.id,partIndex:o,sourceText:s}}return null},z=t=>{t.current!==null&&(clearInterval(t.current),t.current=null)},ee=t=>{const{timerRef:e,sourceText:r,onStart:o,onChunk:a,onComplete:s}=t;z(e);const i=Me(r);if(i.length===0){s();return}let l="",d=0;o(),e.current=setInterval(()=>{l+=i[d]??"",a(l),d+=1,d>=i.length&&(z(e),s())},qe)},je=(t,e)=>e.length===0?`Mock response: I received "${t}" and generated a draft answer.`:`Mock response: I received "${t}" with ${e.length} attachment(s): ${e.join(", ")}.`;function J(t){const e=V.c(20),{messages:r,streaming:o,onSubmitMessage:a,emptyStateTitle:s,emptyStateDescription:i,chatInputPlaceholder:l,actions:d,repoMenu:R}=t;let C;e[0]!==r?(C=r===void 0?[]:r,e[0]=r,e[1]=C):C=e[1];const m=C,T=o===void 0?!1:o,[I,p]=P.useState(m),[b,c]=P.useState(T),[g,w]=P.useState(m.length+1),y=P.useRef(null);let f,v;e[2]!==m||e[3]!==T?(f=()=>{if(z(y),w(m.length+1),!T){p(m),c(!1);return}const u=we(m);if(!u){p(m),c(T);return}p(u.seededMessages),ee({timerRef:y,sourceText:u.sourceText,onStart:()=>c(!0),onChunk:S=>{p(M=>H(M,u.messageId,u.partIndex,S))},onComplete:()=>c(!1)})},v=[m,T],e[2]=m,e[3]=T,e[4]=f,e[5]=v):(f=e[4],v=e[5]),P.useEffect(f,v);let h,k;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=()=>()=>{z(y)},k=[],e[6]=h,e[7]=k):(h=e[6],k=e[7]),P.useEffect(h,k);let x;e[8]!==g||e[9]!==a?(x=(u,S)=>{a?.(u,S);const M={id:`message-${g}`,role:"user",parts:[{type:"text",text:u}]},A=je(u,S),E=`message-${g+1}`,F={id:E,role:"assistant",parts:[{type:"text",text:""}]};w(Ce),p(N=>[...N,M,F]),ee({timerRef:y,sourceText:A,onStart:()=>c(!0),onChunk:N=>{p(B=>H(B,E,0,N))},onComplete:()=>c(!1)})},e[8]=g,e[9]=a,e[10]=x):x=e[10];const q=x;let j;return e[11]!==d||e[12]!==l||e[13]!==i||e[14]!==s||e[15]!==q||e[16]!==I||e[17]!==R||e[18]!==b?(j=n.jsx(Z,{messages:I,streaming:b,emptyStateTitle:s,emptyStateDescription:i,chatInputPlaceholder:l,onSubmitMessage:q,actions:d,repoMenu:R}),e[11]=d,e[12]=l,e[13]=i,e[14]=s,e[15]=q,e[16]=I,e[17]=R,e[18]=b,e[19]=j):j=e[19],j}function Ce(t){return t+2}const _={render:t=>n.jsx(D,{...G,children:n.jsx(J,{...t})}),args:{messages:[],streaming:!1,emptyStateTitle:"No active conversations",emptyStateDescription:"Start a conversation to see messages here.",chatInputPlaceholder:"Type a message...",actions:Se,repoMenu:Te,onSubmitMessage:(t,e)=>{console.log("Submitted",{text:t,attachments:e})}}},$={render:t=>n.jsx(D,{...G,children:n.jsx(J,{...t})}),args:{..._.args,messages:re}},O={render:t=>n.jsx(D,{...G,children:n.jsx(J,{...t})}),args:{..._.args,messages:be,streaming:!0}};_.parameters={..._.parameters,docs:{..._.parameters?.docs,source:{originalSource:`{
  render: args => <Box {...panelContainerStyles}>
      <MockChatPanelRenderer {...args} />
    </Box>,
  args: {
    messages: [],
    streaming: false,
    emptyStateTitle: "No active conversations",
    emptyStateDescription: "Start a conversation to see messages here.",
    chatInputPlaceholder: "Type a message...",
    actions: defaultActions,
    repoMenu: defaultRepoMenu,
    onSubmitMessage: (text: string, attachments: string[]) => {
      console.log("Submitted", {
        text,
        attachments
      });
    }
  }
}`,..._.parameters?.docs?.source}}};$.parameters={...$.parameters,docs:{...$.parameters?.docs,source:{originalSource:`{
  render: args => <Box {...panelContainerStyles}>
      <MockChatPanelRenderer {...args} />
    </Box>,
  args: {
    ...Empty.args,
    messages: conversationMessages
  }
}`,...$.parameters?.docs?.source}}};O.parameters={...O.parameters,docs:{...O.parameters?.docs,source:{originalSource:`{
  render: args => <Box {...panelContainerStyles}>
      <MockChatPanelRenderer {...args} />
    </Box>,
  args: {
    ...Empty.args,
    messages: streamingMessages,
    streaming: true
  }
}`,...O.parameters?.docs?.source}}};const Et=["Empty","Conversation","Streaming"];export{$ as Conversation,_ as Empty,O as Streaming,Et as __namedExportsOrder,At as default};
