@rizom/brain 0.2.0-alpha.873 → 0.2.0-alpha.875
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brain.js +10 -10
- package/dist/chunks/app-ekx3p63b.js +5 -0
- package/dist/chunks/{index-3tvzr6ge.js → index-02srst5t.js} +3 -3
- package/dist/chunks/{index-3tvzr6ge.js.map → index-02srst5t.js.map} +1 -1
- package/dist/chunks/{index-1vaa2761.js → index-5fa86d31.js} +2 -2
- package/dist/chunks/{index-nnwk2h8n.js → index-9kdd9kj5.js} +2 -2
- package/dist/chunks/{index-gnbfdewj.js → index-9mfc2kx2.js} +3 -3
- package/dist/chunks/{index-gnbfdewj.js.map → index-9mfc2kx2.js.map} +5 -5
- package/dist/chunks/{index-02pt9z7t.js → index-cywssss6.js} +2 -2
- package/dist/chunks/{index-wete5qfn.js → index-t822ntg2.js} +2 -2
- package/dist/chunks/{package-z5h1920s.js → package-c88dkedp.js} +3 -3
- package/dist/chunks/{package-z5h1920s.js.map → package-c88dkedp.js.map} +1 -1
- package/dist/entities.js +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1 -1
- package/dist/interfaces.js +1 -1
- package/dist/model.js +6 -6
- package/dist/model.js.map +5 -5
- package/dist/services.js +1 -1
- package/dist/testing.js +1 -1
- package/dist/ui/{studio-app-1edp4r57.js → studio-app-bb5xxwvn.js} +3 -3
- package/dist/ui/studio-asset-manifest.json +21 -21
- package/dist/ui/studio-chunks/{account-view-j9wkxck6.js → account-view-ak5tfxgg.js} +1 -1
- package/dist/ui/studio-chunks/{main-d5szcfbq.js → main-2g8gcg0r.js} +1 -1
- package/dist/ui/studio-chunks/{main-rt6yh800.js → main-2hbxfr9g.js} +1 -1
- package/dist/ui/studio-chunks/{main-pqx64crr.js → main-45xgzy0v.js} +2 -2
- package/dist/ui/studio-chunks/{main-pqx64crr.js.map → main-45xgzy0v.js.map} +5 -5
- package/dist/ui/studio-chunks/{main-fqzf25fv.js → main-q24zjy7e.js} +1 -1
- package/dist/ui/studio-chunks/{main-ggcgvxym.js → main-qyf00dty.js} +1 -1
- package/dist/ui/studio-chunks/{main-6qe1jp8h.js → main-tcyq2xnp.js} +1 -1
- package/dist/ui/studio-chunks/{studio-ask-panel-njthpfwq.js → studio-ask-panel-vjymeavp.js} +1 -1
- package/dist/ui/studio-chunks/{studio-chat-workspace-jw3pye8a.js → studio-chat-workspace-kzcn37qq.js} +1 -1
- package/package.json +1 -1
- package/dist/chunks/app-n0bqjatx.js +0 -5
- /package/dist/chunks/{app-n0bqjatx.js.map → app-ekx3p63b.js.map} +0 -0
- /package/dist/chunks/{index-1vaa2761.js.map → index-5fa86d31.js.map} +0 -0
- /package/dist/chunks/{index-nnwk2h8n.js.map → index-9kdd9kj5.js.map} +0 -0
- /package/dist/chunks/{index-02pt9z7t.js.map → index-cywssss6.js.map} +0 -0
- /package/dist/chunks/{index-wete5qfn.js.map → index-t822ntg2.js.map} +0 -0
- /package/dist/ui/{studio-app-1edp4r57.js.map → studio-app-bb5xxwvn.js.map} +0 -0
- /package/dist/ui/studio-chunks/{account-view-j9wkxck6.js.map → account-view-ak5tfxgg.js.map} +0 -0
- /package/dist/ui/studio-chunks/{main-d5szcfbq.js.map → main-2g8gcg0r.js.map} +0 -0
- /package/dist/ui/studio-chunks/{main-rt6yh800.js.map → main-2hbxfr9g.js.map} +0 -0
- /package/dist/ui/studio-chunks/{main-fqzf25fv.js.map → main-q24zjy7e.js.map} +0 -0
- /package/dist/ui/studio-chunks/{main-ggcgvxym.js.map → main-qyf00dty.js.map} +0 -0
- /package/dist/ui/studio-chunks/{main-6qe1jp8h.js.map → main-tcyq2xnp.js.map} +0 -0
- /package/dist/ui/studio-chunks/{studio-ask-panel-njthpfwq.js.map → studio-ask-panel-vjymeavp.js.map} +0 -0
- /package/dist/ui/studio-chunks/{studio-chat-workspace-jw3pye8a.js.map → studio-chat-workspace-kzcn37qq.js.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Fa as O,Ga as q,Ja as ge,Ma as w,Oa as be,Qa as Ae,Ra as ve}from"./main-
|
|
1
|
+
import{Fa as O,Ga as q,Ja as ge,Ma as w,Oa as be,Qa as Ae,Ra as ve}from"./main-2hbxfr9g.js";import{Sa as i,Ta as ye,Ua as he,Xa as me,Ya as fe}from"./main-cjvg98dr.js";import{$a as ae,Jb as pe}from"./main-2g8gcg0r.js";import"./main-t14ef5wt.js";import{Lc as l,Oc as oe,Qc as f,Sc as se,de as ue,ld as ie,md as le,yd as re,zd as ce}from"./main-45xgzy0v.js";import{Qf as de}from"./main-7fyr0wv3.js";import{Rf as _e}from"./main-y9skwxac.js";import{xg as N}from"./main-f886snck.js";var a=N(_e(),1);var n=N(oe(),1),Se="selection.md",P=(t)=>t.filename===Se;function it(t){let s=ae(),g=ie(),b=ue(),u=a.useMemo(()=>de({apiPath:t.chatApiPath,fetch:g}),[t.chatApiPath,g]),[r,H]=a.useState(null),[K,x]=a.useState("opening"),[ke,Ce]=a.useState(0),[_,Te]=a.useState(""),[z,R]=a.useState([]),[E,A]=a.useState(null),[I,Y]=a.useState(null),j=I!==null,p=a.useRef(!1),Pe=a.useRef(null),Q=a.useRef(null),W=a.useRef(null),v=t.agents.find((e)=>e.id===_)??null;a.useEffect(()=>{let e=!0;return x("opening"),u.openContextSession({version:1,sourceId:re,itemId:ce(t.entityType,t.entityId),titleSeed:(t.title.trim()||t.typeLabel).slice(0,160)}).then(({conversationId:o})=>{if(!e)return;H(o),x("open")}).catch(()=>{if(e)x("failed")}),()=>{e=!1}},[u,t.entityType,t.entityId,ke]);let{draftStore:we,draftKey:xe,currentDraftKey:Re,draft:X,uploads:L,setDraft:S,setUploads:y}=be({draftStore:t.draftStore,apiPath:t.chatApiPath,sessionId:r}),{pendingMessages:Ee,stream:G,sending:F,error:J,submitPrompt:V,respondToApproval:Ie,runSuggestedAction:Le,hasActiveStream:Fe,stopActiveStream:Ue,abortActiveStream:Z}=Ae({chatClient:u,queryClient:s,sessionId:r,apiPath:t.chatApiPath,draftStore:we,draftKey:xe,currentDraftKey:Re,mountedRef:p,adoptedSessionRef:Pe,uploads:L,uploading:j,uploadAttemptCount:0,navigateToSession:(e)=>{if(e)H(e)}}),{visibleMessages:$e,historyFailed:De,retryHistory:Me}=ve({chatClient:u,sessionId:r,sending:F,pendingMessages:Ee,stream:G});a.useEffect(()=>(p.current=!0,()=>{p.current=!1,Z()}),[Z]);let c=t.selection?.text??null,U=L.some(P),ee=a.useRef(c);ee.current=c,a.useEffect(()=>{if(!r)return;if(!c){if(U)y((o)=>o.filter((d)=>!P(d)));return}let e=Q.current;if(e?.text===c){if(!U)y((o)=>[...o,e.upload]);return}if(I===c)return;Y(c),u.upload(new Blob([c],{type:"text/markdown"}),Se).then((o)=>{if(Q.current={text:c,upload:o},!p.current||ee.current!==c)return;y((d)=>[...d.filter((C)=>!P(C)),o])}).catch(()=>{if(p.current)A("The selection could not be attached.")}).finally(()=>{if(p.current)Y((o)=>o===c?null:o)})},[u,r,c,U,I,y]);let D=a.useCallback((e,o)=>{let d=t.selection,C=me(t.savedBody,d);if(!C.trim()){A(`There is nothing in this ${t.typeLabel} to ask about yet.`);return}let M={id:crypto.randomUUID(),at:new Date().toISOString(),question:o,agent:e,rewrite:he(o)&&d!==null,selection:d};R((h)=>[...h,M]),S(""),b.requestAgentAnswer({entityType:t.entityType,id:t.entityId,agent:e.id,instruction:o,selection:C}).then(({response:h})=>R((T)=>T.map((m)=>m.id===M.id?{...m,answer:h}:m))).catch((h)=>{let T=pe(h),m=/no longer matches/i.test(T)?"the selection is not saved yet. Save, then ask again.":T;R((Ke)=>Ke.map((B)=>B.id===M.id?{...B,error:m}:B))})},[b,t.savedBody,t.entityId,t.entityType,t.selection,t.typeLabel,S]),te=a.useCallback((e)=>{let o=e.trim();if(!o)return;if(A(null),W.current=t.selection,v){D(v,o);return}V(o)},[D,t.selection,V,v]),Be=(e)=>{e.preventDefault(),te(X)},Ne=(e,o)=>{let d=t.onApply(e,o);A(d??(e.field==="selection"?"Replaced in the draft. Save to keep it.":`Put in the draft’s ${e.label.toLowerCase()}. Save to keep it.`))},ne=(e)=>({fields:t.fields,onApply:(o)=>Ne(o,e),onTryAnother:(o)=>te(`Try another ${o.label.toLowerCase()}.`)}),k=[...$e.map((e)=>({at:typeof e.timestamp==="string"?e.timestamp:"",key:e.id,node:n.jsxDEV(w,{message:e,client:u,disabled:F,speaker:"Your brain",onAction:Le,onApproval:Ie,proposals:ne(W.current)},e.id,!1,void 0,this)})),...z.map((e)=>({at:e.at,key:e.id,node:n.jsxDEV(ze,{turn:e,client:u,proposals:ne(e.selection),onRetry:()=>D(e.agent,e.question)},e.id,!1,void 0,this)}))].sort((e,o)=>e.at&&o.at?e.at.localeCompare(o.at):0),{ref:Oe,onScroll:qe}=le({resetKey:r,contentKey:`${k.length}:${G?.text.length??-1}:${z.filter((e)=>e.answer!==void 0||e.error!==void 0).length}:${E??""}`}),He=t.selection?"About the selection":`About this ${t.typeLabel}`;return n.jsxDEV("aside",{...l(i.panel),"aria-label":"Ask","data-studio-ask-panel":"",children:[n.jsxDEV("header",{...l(i.head),children:[n.jsxDEV("h2",{...l(i.title),children:"Ask"},void 0,!1,void 0,this),n.jsxDEV("span",{...l(i.about),"data-studio-ask-about":"",children:[He,t.selection&&n.jsxDEV("button",{type:"button",...l(i.clear),"aria-label":`Ask about the whole ${t.typeLabel}`,onClick:t.onClearSelection,children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n.jsxDEV(f,{type:"button",variant:"ghost",size:"sm",xstyle:i.close,"aria-label":"Close Ask","aria-keyshortcuts":"Control+j Meta+j",onClick:t.onClose,children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.agents.length>0&&n.jsxDEV("div",{...l(i.who),children:[n.jsxDEV("label",{htmlFor:"studio-ask-who",children:"Asking"},void 0,!1,void 0,this),n.jsxDEV(se,{id:"studio-ask-who",xstyle:i.whoSelect,value:_,onChange:(e)=>Te(e.currentTarget.value),children:[n.jsxDEV("option",{value:"",children:"Your brain"},void 0,!1,void 0,this),t.agents.map((e)=>n.jsxDEV("option",{value:e.id,children:e.label},e.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),n.jsxDEV("div",{ref:Oe,onScroll:qe,...l(i.thread),role:"log","aria-label":"Ask conversation","aria-live":"polite",children:[K==="failed"?n.jsxDEV("p",{...l(i.notice),children:["Chat could not open a conversation about this ",t.typeLabel,"."," ",n.jsxDEV(f,{type:"button",variant:"ghost",size:"sm",onClick:()=>Ce((e)=>e+1),children:"Try again"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):De?n.jsxDEV("p",{...l(i.notice),children:["The conversation could not be read."," ",n.jsxDEV(f,{type:"button",variant:"ghost",size:"sm",onClick:Me,children:"Try again"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):k.length===0?n.jsxDEV("p",{...l(i.notice),children:t.selection?"Ask about the selected passage, or have it rewritten.":`Ask about this ${t.typeLabel}. Select a passage to ask about it alone.`},void 0,!1,void 0,this):k.map((e)=>e.node),t.unsaved&&k.length>0&&n.jsxDEV("p",{...l(i.notice),children:["Ask reads the saved version of this ",t.typeLabel,"."]},void 0,!0,void 0,this),(J??E)&&n.jsxDEV("p",{...l(i.notice),role:"status",children:J??E},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.selection&&n.jsxDEV("div",{...l(i.starters),"aria-label":"Starters",children:ye.map((e)=>n.jsxDEV("button",{type:"button",...l(i.starter),onClick:()=>S(e.instruction),children:e.label},e.label,!1,void 0,this))},void 0,!1,void 0,this),n.jsxDEV(ge,{draft:X,sending:F,uploading:j,uploads:L.filter((e)=>!P(e)),uploadAttempts:[],onRetryUpload:()=>{},onDismissUpload:()=>{},onDraft:S,locked:K!=="open",onRemoveUpload:(e)=>y((o)=>o.filter((d)=>d.id!==e)),onFiles:async()=>{},allowFiles:!1,onSubmit:Be,onStop:Fe()?Ue:void 0,placeholder:fe({who:v?.label??null,selected:t.selection!==null,typeLabel:t.typeLabel})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ze(t){let{turn:s}=t,g={id:`${s.id}-question`,role:"user",content:s.question,timestamp:s.at},b=s.answer===void 0?"":s.rewrite?`\`\`\`proposal selection
|
|
2
2
|
${s.answer.trim()}
|
|
3
3
|
\`\`\``:s.answer,u={id:`${s.id}-answer`,role:"assistant",content:b,timestamp:s.at},r=async()=>{};return n.jsxDEV(n.Fragment,{children:[n.jsxDEV(w,{message:g,client:t.client,disabled:!1,onAction:r,onApproval:r},void 0,!1,void 0,this),s.error?n.jsxDEV("p",{className:q("",O.error),role:"alert",children:[s.agent.label," did not answer: ",s.error," ",n.jsxDEV(f,{type:"button",variant:"ghost",size:"sm",onClick:t.onRetry,children:"Ask again"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):s.answer===void 0?n.jsxDEV("p",{className:q("",O.empty),children:["Asking ",s.agent.label,"…"]},void 0,!0,void 0,this):n.jsxDEV(w,{message:u,client:t.client,disabled:!1,speaker:s.agent.label,onAction:r,onApproval:r,proposals:s.rewrite?t.proposals:void 0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}export{it as StudioAskPanel};
|
|
4
4
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{A as st,B as Je,C as ze,Ca as ct,aa as it,ba as at,ca as ne,da as ue,ea as rt,fa as lt}from"./main-6qe1jp8h.js";import{Fa as n,Ga as i,Ha as Le,Ia as q,Ja as ut,Ka as mt,La as ft,Ma as ht,Na as pt,Oa as vt,Pa as Y,Qa as yt,Ra as gt}from"./main-rt6yh800.js";import{$a as et,Nb as Ve,cb as Ke,hc as dt,ib as Oe,lb as de,nb as Fe}from"./main-d5szcfbq.js";import"./main-t14ef5wt.js";import{Hc as Z}from"./main-ggcgvxym.js";import{Ad as xe,Oc as H,Qc as R,Rc as Ee,Sc as Ge,Vc as Be,Wc as He,Yc as qe,ee as X,ld as tt,md as nt,xd as Ae,yd as Ne}from"./main-pqx64crr.js";import{Qf as ot}from"./main-7fyr0wv3.js";import{Rf as L}from"./main-y9skwxac.js";import{xg as I}from"./main-f886snck.js";var Q=I(L(),1);var O=I(H(),1),qt={stopped:"Stopped",disconnected:"Connection lost",failed:"Response failed"};function ke(e){let{interrupted:t}=e;return O.jsxDEV("section",{className:i("studio-chat-interruption",n.empty),role:t.kind==="stopped"?"status":"alert","aria-atomic":"true",children:[O.jsxDEV("strong",{children:qt[t.kind]},void 0,!1,void 0,this),O.jsxDEV("p",{children:"Any received text is kept here. Stopping the response does not undo completed actions; the server may still be working."},void 0,!1,void 0,this),t.detail&&O.jsxDEV("p",{children:t.detail},void 0,!1,void 0,this),t.retry&&O.jsxDEV(O.Fragment,{children:[O.jsxDEV("p",{children:"Sending again may repeat completed actions. Review the request before sending."},void 0,!1,void 0,this),O.jsxDEV(R,{type:"button",variant:"ghost",disabled:e.restoreBlocked||e.draftPending,onClick:()=>{if(!t.retry||e.draftPending)return;e.onRestore(t.retry)},children:"Review retry in composer"},void 0,!1,void 0,this),e.draftPending&&O.jsxDEV("p",{children:"Your composer draft is unchanged. Send or clear it before restoring this request."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var _=I(L(),1);var x=I(H(),1);function we(e){return x.jsxDEV("aside",{className:i("studio-chat-context",n.contextBody),tabIndex:0,"aria-label":"Conversation sources and attachments",children:x.jsxDEV("div",{className:i("studio-chat-context-list",n.cards),children:[e.session?.contextHandoff?x.jsxDEV("section",{className:i("studio-chat-context-card",n.contextItem),children:[x.jsxDEV("span",{className:i("studio-chat-context-kicker",n.kicker),children:"Linked context"},void 0,!1,void 0,this),x.jsxDEV("h3",{className:i("studio-chat-context-card-title",n.cardHeading,X.section),children:e.session.contextHandoff.titleSeed},void 0,!1,void 0,this),x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:[e.session.contextHandoff.sourceId," ·"," ",e.session.contextHandoff.itemId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null,e.cards.length===0&&e.progress.length===0?x.jsxDEV("p",{className:i("studio-chat-empty",n.empty),children:"No sources or attachments in this conversation yet."},void 0,!1,void 0,this):null,e.cards.map((t,o)=>x.jsxDEV("section",{className:i("studio-chat-context-card",n.contextItem),children:[x.jsxDEV("span",{className:i("studio-chat-context-kicker",n.kicker),children:t.kind==="sources"?"Sources":"Artifact"},void 0,!1,void 0,this),x.jsxDEV("h3",{className:i("studio-chat-context-card-title",n.cardHeading,X.section),children:t.kind==="sources"?t.title??`${t.sources.length} consulted`:t.kind==="attachment"?t.title:"Conversation context"},void 0,!1,void 0,this),t.kind==="sources"?x.jsxDEV(x.Fragment,{children:[x.jsxDEV("ul",{children:t.sources.slice(0,5).map((s)=>x.jsxDEV("li",{children:s.title??s.source},s.id,!1,void 0,this))},void 0,!1,void 0,this),t.sources.length>5?x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:[t.sources.length-5," more sources in the conversation."]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this):t.kind==="attachment"&&t.description?x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:t.description},void 0,!1,void 0,this):null]},`${t.kind}-${t.id}-${o}`,!0,void 0,this)),e.progress.map((t,o)=>x.jsxDEV("section",{className:i("studio-chat-context-card",n.contextItem),children:[x.jsxDEV("span",{className:i("studio-chat-context-kicker",n.kicker),children:"Durable job"},void 0,!1,void 0,this),x.jsxDEV("h3",{className:i("studio-chat-context-card-title",n.cardHeading,X.section),children:t.operationTarget??t.operationType},void 0,!1,void 0,this),x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:t.message??t.status},void 0,!1,void 0,this)]},`${t.type}-${o}`,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var Ot=86400000;function Ie(e,t){return new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).format(e)}function Lt(e,t){return Math.round((Date.parse(t)-Date.parse(e))/Ot)}function De(e,t,o){let s=Lt(Ie(e,o),Ie(t,o));if(s<=0)return"Today";if(s===1)return"Yesterday";if(s<7)return"This week";return"Earlier"}function Re(e,t,o){let s=[...e].sort((r,a)=>a.lastActiveAt.localeCompare(r.lastActiveAt));return["Today","Yesterday","This week","Earlier"].map((r)=>({label:r,sessions:s.filter((a)=>De(Date.parse(a.lastActiveAt),t,o)===r)})).filter((r)=>r.sessions.length>0)}function le(e){let t=e.contextHandoff;if(t?.sourceId!==Ne)return null;let o=xe(t.itemId);return o?{...o,title:t.titleSeed}:null}function Te(e,t,o){let s=le(e);if(s)return{kind:"entry",text:s.title};let r=Date.parse(e.lastActiveAt);if(Number.isNaN(r))return{kind:"time",text:""};let a=Math.floor((t-r)/60000),l=De(r,t,o);if(l==="Today"){if(a<1)return{kind:"time",text:"Just now"};if(a<60)return{kind:"time",text:`${a} ${a===1?"minute":"minutes"} ago`};let f=Math.floor(a/60);return{kind:"time",text:`${f} ${f===1?"hour":"hours"} ago`}}if(l==="Yesterday")return{kind:"time",text:"Yesterday"};if(l==="This week")return{kind:"time",text:new Intl.DateTimeFormat("en-GB",{weekday:"long",timeZone:o}).format(r)};return{kind:"time",text:new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",timeZone:o}).format(r)}}var P=I(L(),1);var A=I(H(),1);function Pe(e){let[t,o]=P.useState(!1),[s,r]=P.useState(e.title),[a,l]=P.useState(!1),[f,d]=P.useState(null),u=P.useRef(!1),p=P.useRef(!1),b=P.useRef(null);P.useEffect(()=>{if(t)b.current?.focus()},[t]);let y=P.useRef(null);P.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);let N=()=>{o(!1),d(null),requestAnimationFrame(()=>y.current?.querySelector("button")?.focus())},g=async()=>{if(p.current||!s.trim())return;p.current=!0,l(!0),d(null);try{if(await e.onRename(s.trim()),u.current)N()}catch(m){if(u.current)d(Ae(m,"Rename failed. Your proposed title is kept.")||"Rename failed. Your proposed title is kept.")}finally{if(p.current=!1,u.current)l(!1)}};return A.jsxDEV(A.Fragment,{children:[A.jsxDEV("span",{ref:y,children:A.jsxDEV(R,{type:"button",variant:"ghost","aria-expanded":t,disabled:t,onClick:()=>{r(e.title),o(!0)},children:"Rename"},void 0,!1,void 0,this)},void 0,!1,void 0,this),t&&A.jsxDEV("form",{className:i("studio-chat-rename",n.sessionControls),onSubmit:(m)=>{m.preventDefault(),g()},children:[A.jsxDEV("label",{children:["Conversation title",A.jsxDEV(Ee,{ref:b,xstyle:n.sessionFilterSelect,value:s,onChange:(m)=>r(m.target.value),required:!0,maxLength:48,disabled:a},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A.jsxDEV("div",{className:i("",n.actions),children:[A.jsxDEV(R,{type:"submit",disabled:a||!s.trim(),children:a?"Renaming…":"Save title"},void 0,!1,void 0,this),A.jsxDEV(R,{type:"button",variant:"ghost",disabled:a,onClick:N,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&A.jsxDEV("p",{role:"alert",children:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var c=I(H(),1);function Ue(e){let{currentSession:t,archivedSession:o,setConversationsOpen:s,detailsOpen:r,setDetailsOpen:a,renameCurrent:l}=e.sessions,f=_.useRef(null),d=_.useId(),u=e.draftPending?"Send or clear the draft before archiving or deleting.":void 0,p=t?le(t):null,b=p?.title??t?.contextHandoff?.titleSeed??void 0,y=p?e.entryHref(p.entityType,p.entityId):void 0,N=t?.title??(e.sessionId?"Conversation":"New conversation"),g=(v)=>y!==void 0?c.jsxDEV("a",{href:y,className:i("studio-chat-open-entry",n.openEntry,v&&n.openEntryIcon),"aria-label":v?"Open entry":void 0,onClick:(k)=>{if(!Oe(k))return;k.preventDefault(),e.onOpenEntry(y)},children:v?c.jsxDEV("span",{"aria-hidden":"true",children:"↗"},void 0,!1,void 0,this):"Open entry ↗"},void 0,!1,void 0,this):null,m=c.jsxDEV(R,{type:"button",variant:"ghost",xstyle:n.toolbarButton,"aria-label":"Conversation details and options","aria-haspopup":"dialog","aria-expanded":r,onClick:()=>a(!0),children:"•••"},void 0,!1,void 0,this),[w]=_.useState(()=>Symbol("chat thread"));return Z(w,e.phoneShown?{title:N,back:{label:"Conversations",onBack:()=>s(!0)},action:c.jsxDEV(c.Fragment,{children:[g(!0),m]},void 0,!0,void 0,this)}:null),c.jsxDEV(c.Fragment,{children:[c.jsxDEV("header",{className:i("studio-chat-thread-head",n.threadHead,n.phoneGoneFlex),children:[c.jsxDEV("h1",{className:i("studio-chat-session-heading",n.title),title:t?.title,children:N},void 0,!1,void 0,this),b&&c.jsxDEV("span",{className:i("studio-chat-about",n.about),"data-studio-chat-about":"",children:["About: ",b]},void 0,!0,void 0,this),c.jsxDEV("div",{className:i("studio-chat-head-actions",n.toolbar),children:[g(!1),c.jsxDEV("span",{ref:f,children:m},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c.jsxDEV(Be,{open:r,onOpenChange:(v)=>{if(a(v),!v)e.deletion.cancelDelete()},children:c.jsxDEV(He,{"aria-describedby":void 0,onCloseAutoFocus:(v)=>{v.preventDefault(),([...document.querySelectorAll('[aria-label="Conversation details and options"]')].find((D)=>D.offsetParent!==null)??f.current?.querySelector("button"))?.focus()},children:[c.jsxDEV(qe,{children:"Conversation details"},void 0,!1,void 0,this),c.jsxDEV("div",{className:i("studio-chat-details",n.details),children:[c.jsxDEV("p",{children:t?.title??"New conversation"},void 0,!1,void 0,this),c.jsxDEV("div",{className:i("studio-chat-session-actions",n.actions),children:[t&&c.jsxDEV(Pe,{title:t.title,onRename:l},t.id,!1,void 0,this),o&&c.jsxDEV("p",{role:"status",children:"Archived conversation. New messages here remain archived."},void 0,!1,void 0,this),e.sessionId&&!o?c.jsxDEV(R,{className:"studio-chat-header-action",variant:"ghost",type:"button",onClick:e.onArchive,disabled:e.archiveBlocked,"aria-describedby":u?d:void 0,children:e.archiving?"Archiving…":"Archive"},void 0,!1,void 0,this):null,e.sessionId&&(e.deletion.confirming?c.jsxDEV("section",{role:"group","aria-label":"Confirm conversation deletion",children:[c.jsxDEV("p",{children:"Delete this conversation permanently? This cannot be undone."},void 0,!1,void 0,this),c.jsxDEV("p",{children:"Deleting history does not undo completed actions or guarantee that remote work has stopped."},void 0,!1,void 0,this),e.deletion.deleteError&&c.jsxDEV("p",{role:"alert",children:e.deletion.deleteError},void 0,!1,void 0,this),c.jsxDEV(R,{type:"button",variant:"ghost",autoFocus:!0,"aria-label":"Cancel conversation deletion",disabled:e.deletion.deleting,onClick:e.deletion.cancelDelete,children:"Cancel"},void 0,!1,void 0,this),c.jsxDEV(R,{type:"button",variant:"danger","aria-label":"Permanently delete conversation",disabled:e.archiveBlocked,onClick:()=>void e.deletion.confirmDelete(),children:e.deletion.deleting?"Deleting…":"Delete permanently"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c.jsxDEV(R,{type:"button",variant:"danger","aria-label":"Delete conversation",disabled:e.archiveBlocked,"aria-describedby":u?d:void 0,onClick:e.deletion.requestDelete,children:"Delete conversation"},void 0,!1,void 0,this)),u&&c.jsxDEV("p",{id:d,children:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c.jsxDEV("details",{children:[c.jsxDEV("summary",{children:"Sources and attachments"},void 0,!1,void 0,this),c.jsxDEV(we,{cards:e.contextCards,progress:e.progress,session:t},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c.jsxDEV("details",{children:[c.jsxDEV("summary",{children:"File types and limits"},void 0,!1,void 0,this),c.jsxDEV("p",{id:"studio-chat-upload-guidance",children:Le},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var U=I(L(),1);var Ut=250;function Me(e){let{chatClient:t,queryClient:o,sessionId:s,studioBasePath:r,navigate:a}=e,[l,f]=U.useState(s===null),[d,u]=U.useState(!1),[p,b]=U.useState(""),[y,N]=U.useState({query:"",archived:!1,offset:0});U.useEffect(()=>{let E=window.setTimeout(()=>N((T)=>T.query===p.trim()?T:{...T,query:p.trim(),offset:0}),Ut);return()=>window.clearTimeout(E)},[p]);let g=Ke({queryKey:[...q.sessions,y],queryFn:()=>t.listSessions(y)}),m=g.data??[],w=m.find((E)=>E.id===s)??o.getQueriesData({queryKey:q.sessions}).flatMap(([,E])=>E??[]).find((E)=>E.id===s),v=U.useCallback(()=>{u(!1)},[]),k=U.useCallback((E,T=!1)=>{a(Fe(r,E),{preserveWork:T}),f(!1),v()},[a,r,v]),D=async(E)=>{if(!w)return;let T=await t.renameSession(w.id,E);if(!T.renamed)throw Error("The conversation could not be renamed.");o.setQueriesData({queryKey:q.sessions},(V)=>V?.map((W)=>W.id===w.id?{...W,title:T.title}:W)),o.invalidateQueries({queryKey:q.sessions})};return{sessions:m,currentSession:w,archivedSession:w?.archived===!0,sessionControls:{search:p,view:y,error:g.error?"Sessions could not be loaded.":null,onRetry:()=>{g.refetch()},onSearch:b,onView:N},sessionsLoading:g.isPending,navigateToSession:k,conversationsOpen:l,setConversationsOpen:f,detailsOpen:d,setDetailsOpen:u,closeDisclosures:v,renameCurrent:D}}var K=I(L(),1);function Qe(e){let{chatClient:t,draftKey:o,currentDraftKey:s,setUploads:r}=e,[a,l]=K.useState(!1),[f,d]=K.useState([]),u=K.useRef(null),p=K.useCallback(async(g)=>{if(u.current||g.length===0)return;let m=Symbol();if(u.current=m,l(!0),d((w)=>[...w.filter((v)=>!g.some((k)=>k.id===v.id)),...g.map((v)=>({id:v.id,file:v.file,status:"uploading"}))]),await Promise.all(g.map(async(w)=>{try{let v=await t.upload(w.file,w.file.name);if(u.current!==m||s.current!==o)return;r((k)=>[...k,v]),d((k)=>k.filter((D)=>D.id!==w.id))}catch(v){if(u.current!==m||s.current!==o)return;d((k)=>k.map((D)=>D.id===w.id?{...D,status:"failed",error:Y(v,"Upload failed")}:D))}})),u.current===m)u.current=null,l(!1)},[t,o,s,r]),b=K.useCallback(async(g)=>{let m=Array.from(g.target.files??[]);g.target.value="",await p(m.map((w)=>({id:crypto.randomUUID(),file:w,status:"uploading"})))},[p]),y=K.useCallback((g)=>{d((m)=>m.filter((w)=>w.id!==g))},[]),N=K.useCallback(()=>{u.current=null,l(!1),d([])},[]);return{uploading:a,uploadAttempts:f,runUploads:p,uploadFiles:b,dismissAttempt:y,reset:N}}var G=I(L(),1);function We(e){let{chatClient:t,queryClient:o,sessionId:s,draftKey:r,currentDraftKey:a,mountedRef:l,blocked:f,setSending:d,setError:u,navigateToSession:p}=e,[b,y]=G.useState(!1),N=G.useCallback(async()=>{if(!s||f)return;d(!0),y(!0);try{if(await t.archiveSession(s),await o.invalidateQueries({queryKey:q.sessions}),l.current&&a.current===r)p(void 0,!0)}catch(m){if(l.current&&a.current===r)u(Y(m,"Conversation could not be archived"))}finally{if(l.current&&a.current===r)d(!1),y(!1)}},[t,o,s,r,a,l,f,d,u,p]),g=G.useCallback(()=>y(!1),[]);return{archiving:b,archiveCurrent:N,reset:g}}var M=I(L(),1);function $e(e){let{chatClient:t,queryClient:o,sessionId:s,draftKey:r,currentDraftKey:a,mountedRef:l,blocked:f,setSending:d,navigateToSession:u}=e,[p,b]=M.useState(null),[y,N]=M.useState(!1),[g,m]=M.useState(null),w=M.useRef(0),v=M.useRef(!1),k=p===r,D=M.useCallback(()=>{w.current++,v.current=!1,b(null),N(!1),m(null)},[]);return{confirming:k,deleting:y,deleteError:g,requestDelete:()=>{if(!s||f||v.current)return;m(null),b(r)},cancelDelete:()=>{if(!v.current)b(null)},confirmDelete:async()=>{if(!s||!k||f||v.current)return;let W=w.current,B=()=>l.current&&a.current===r&&w.current===W;v.current=!0,N(!0),d(!0),m(null);try{if(!(await t.deleteSession(s)).deleted)throw Error("Deletion was not acknowledged");if(await o.cancelQueries({queryKey:q.messages(s)}),o.removeQueries({queryKey:q.messages(s)}),o.setQueriesData({queryKey:q.sessions},(J)=>J?.filter((z)=>z.id!==s)),o.invalidateQueries({queryKey:q.sessions}),B())b(null),u(void 0,!0)}catch{if(B())m("Deletion could not be confirmed. The conversation may already be deleted. Check history before trying again.")}finally{if(B())v.current=!1,N(!1),d(!1)}},reset:D}}var ee=I(L(),1);function _e(e){let{chatClient:t,handoff:o,sessionId:s,apiPath:r,draftStore:a,draftKey:l,currentDraftKey:f,mountedRef:d,setDraft:u,setError:p,navigateToSession:b}=e,y=ee.useRef(null);ee.useEffect(()=>{if(!o||s)return;let N=`${o.sourceId}\x00${o.itemId}`;if(y.current===N)return;y.current=N,u(o.prompt),p(null);let g=()=>d.current===!0&&f.current===l&&y.current===N;t.openContextSession({version:1,sourceId:o.sourceId,itemId:o.itemId,titleSeed:o.label}).then(({conversationId:m})=>{if(!g())return;a.adopt(l,Ve(r,m)),b(m,!0)}).catch((m)=>{if(!g())return;y.current=null,p(Y(m,"Context could not be attached"))})},[t,o,s,r,a,l,f,d,u,p,b])}var te=I(L(),1);function Ye(e){let{question:t,sessionId:o,setDraft:s}=e,r=te.useRef(null);te.useEffect(()=>{if(!t||o)return;if(r.current===t)return;r.current=t,s(t)},[t,o,s])}var ce=I(L(),1);function je(e){let{onChange:t,draft:o,uploadCount:s,uploadAttemptCount:r,sending:a,uploading:l}=e;ce.useEffect(()=>{t?.({hasDraft:Boolean(o||s||r),busy:a||l})},[o,s,r,a,l,t]),ce.useEffect(()=>()=>t?.({hasDraft:!1,busy:!1}),[t])}var Xe=I(L(),1);var S=I(H(),1);function Ze(e){let t=Date.now(),o=e.sessions.length>0||e.search!==""||e.view.query!==""||e.view.archived||e.view.offset>0,s=S.jsxDEV(R,{className:"studio-chat-new",type:"button",size:"sm","aria-label":"New conversation",onClick:e.onNew,children:"New"},void 0,!1,void 0,this),[r]=Xe.useState(()=>Symbol("conversations"));return Z(r,e.phoneHidden===!0?null:{title:"Conversations",action:s}),S.jsxDEV("aside",{className:i("studio-chat-session-picker",n.conversations,e.phoneHidden===!0&&n.conversationsHidden),"aria-label":"Conversations",children:[S.jsxDEV("div",{className:i("studio-chat-session-controls",n.sessionControls),children:[S.jsxDEV("div",{className:i("",n.railHead,n.phoneGoneFlex),children:[S.jsxDEV("h2",{className:i("",n.railTitle),children:"Conversations"},void 0,!1,void 0,this),S.jsxDEV(R,{className:"studio-chat-new",type:"button",variant:"secondary",size:"sm","aria-label":"New conversation",onClick:e.onNew,children:"New"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o&&S.jsxDEV(Je,{label:"Conversation search and filters",searchLabel:"Search conversations",search:e.search,onSearch:e.onSearch,filterLabel:"Filter",filterCount:e.view.archived?1:0,filtered:Boolean(e.view.query)||e.view.archived,onClear:()=>{e.onSearch(""),e.onView({...e.view,query:"",archived:!1,offset:0})},children:S.jsxDEV(Ge,{"aria-label":"Show conversations",value:e.view.archived?"archived":"active",onChange:(a)=>e.onView({...e.view,archived:a.target.value==="archived",offset:0}),children:[S.jsxDEV("option",{value:"active",children:"Active conversations"},void 0,!1,void 0,this),S.jsxDEV("option",{value:"archived",children:"Archived conversations"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),e.error&&S.jsxDEV("p",{role:"alert",children:[e.error," ",S.jsxDEV(R,{type:"button",variant:"ghost",onClick:e.onRetry,children:"Retry sessions"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),S.jsxDEV("div",{className:i("studio-chat-session-list",n.sessionList),children:[e.loading?S.jsxDEV("p",{className:i("studio-chat-empty",n.railEmpty),children:"Loading conversations…"},void 0,!1,void 0,this):null,!e.loading&&!e.error&&e.sessions.length===0?S.jsxDEV("p",{className:i("studio-chat-empty",n.railEmpty),children:e.view.query?"No conversations match this search.":e.view.offset>0?"No more conversations.":e.view.archived?"No archived conversations.":"No conversations yet."},void 0,!1,void 0,this):null,Re(e.sessions,t).map((a)=>S.jsxDEV("section",{"aria-label":a.label,children:[S.jsxDEV("h3",{className:i("",n.dayLabel),children:a.label},void 0,!1,void 0,this),a.sessions.map((l)=>{let f=l.id===e.activeSessionId,d=Te(l,t);return S.jsxDEV("button",{className:i("studio-chat-session",n.session,f&&n.activeSession),"data-active":f?"true":"false","aria-current":f?"true":void 0,type:"button",onClick:()=>e.onSelect(l.id),children:[S.jsxDEV("strong",{className:i("studio-chat-session-title",n.sessionTitle),children:l.title},void 0,!1,void 0,this),S.jsxDEV("small",{className:i("studio-chat-session-note",n.sessionNote),"data-note":d.kind,children:d.kind==="entry"?S.jsxDEV(S.Fragment,{children:[S.jsxDEV("span",{"aria-hidden":"true",className:i("",n.brainMark)},void 0,!1,void 0,this),d.text]},void 0,!0,void 0,this):S.jsxDEV("time",{dateTime:l.lastActiveAt,title:l.lastActiveAt,children:d.text},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},l.id,!0,void 0,this)})]},a.label,!0,void 0,this)),(e.view.offset>0||e.sessions.length>=25)&&S.jsxDEV(ze,{label:"Conversation pages",offset:e.view.offset,count:e.sessions.length,loading:e.loading,hasNext:e.sessions.length>=25,onPrevious:()=>e.onView({...e.view,offset:Math.max(0,e.view.offset-25)}),onNext:()=>e.onView({...e.view,offset:e.view.offset+25})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var h=I(H(),1);function Kt(e,t,o){return`${e==="/"?"":e.replace(/\/+$/,"")}/entities/${encodeURIComponent(t)}/${encodeURIComponent(o)}`}function io(e){let t=et(),o=tt(),s=Q.useMemo(()=>ot({apiPath:e.apiPath,fetch:o}),[e.apiPath,o]),{draftStore:r,draftKey:a,currentDraftKey:l,draft:f,uploads:d,setDraft:u,setUploads:p}=vt({draftStore:e.draftStore,apiPath:e.apiPath,sessionId:e.sessionId}),{uploading:b,uploadAttempts:y,runUploads:N,uploadFiles:g,dismissAttempt:m,reset:w}=Qe({chatClient:s,draftKey:a,currentDraftKey:l,setUploads:p}),v=at(),k=Me({chatClient:s,queryClient:t,sessionId:e.sessionId,studioBasePath:e.studioBasePath,navigate:e.navigate}),{navigateToSession:D,closeDisclosures:E}=k,T=Q.useRef(!1),V=Q.useRef(null),{pendingMessages:W,stream:B,sending:F,error:J,interrupted:z,setSending:me,setError:fe,submitPrompt:Ct,respondToApproval:he,runSuggestedAction:St,hasActiveStream:bt,stopActiveStream:kt,abortActiveStream:pe,reset:wt}=yt({chatClient:s,queryClient:t,sessionId:e.sessionId,apiPath:e.apiPath,draftStore:r,draftKey:a,currentDraftKey:l,mountedRef:T,adoptedSessionRef:V,uploads:d,uploading:b,uploadAttemptCount:y.length,navigateToSession:D});_e({chatClient:s,handoff:e.handoff,sessionId:e.sessionId,apiPath:e.apiPath,draftStore:r,draftKey:a,currentDraftKey:l,mountedRef:T,setDraft:u,setError:fe,navigateToSession:D}),Ye({question:e.question,sessionId:e.sessionId,setDraft:u});let ve=Boolean(f)||d.length>0,ye=ve||y.length>0,oe=F||b||ye,{archiving:ge,archiveCurrent:It,reset:Nt}=We({chatClient:s,queryClient:t,sessionId:e.sessionId,draftKey:a,currentDraftKey:l,mountedRef:T,blocked:oe,setSending:me,setError:fe,navigateToSession:D}),se=$e({chatClient:s,queryClient:t,sessionId:e.sessionId,draftKey:a,currentDraftKey:l,mountedRef:T,blocked:oe,setSending:me,navigateToSession:D});Q.useEffect(()=>(T.current=!0,()=>{T.current=!1,pe()}),[pe]),je({onChange:e.onNavigationStateChange,draft:f,uploadCount:d.length,uploadAttemptCount:y.length,sending:F,uploading:b});let{visibleMessages:j,contextCards:xt,historyFailed:ie,historyOpening:ae,historyReading:Dt,hasStoredHistory:Rt,retryHistory:Tt}=gt({chatClient:s,sessionId:e.sessionId,sending:F,pendingMessages:W,stream:B}),{ref:Ce,onScroll:Et,awayFromLatest:At,jumpToLatest:Pt}=nt({resetKey:e.sessionId,contentKey:`${j.length}:${B?.text.length??-1}`});Q.useEffect(()=>{if(E(),e.sessionId&&V.current===e.sessionId){V.current=null;return}wt(),w(),Nt(),se.reset()},[e.sessionId]);let Bt=(C)=>{C.preventDefault(),Ct(f)},Se=ct(e.workspaces),be=!ie&&(!e.sessionId||!ae)&&j.length===0?mt({types:e.types.map((C)=>C.entityType),workspaces:e.workspaces.map((C)=>C.id)}):[];return h.jsxDEV(dt,{value:(C)=>e.navigate(C),children:h.jsxDEV("div",{className:i("studio",st.frame,n.root,it.space),"data-view":"chat","data-studio-shell":"",children:[h.jsxDEV(lt,{contextLabel:"Chat",navigation:{types:e.types,workspaces:e.workspaces,activeEntityType:null,activeWorkspaceId:de,workspaceBadges:Se,selectEntityType:e.selectEntityType,selectWorkspace:e.selectWorkspace}},void 0,!1,void 0,this),h.jsxDEV("div",{className:ue("studio-chat-shell",n.shell,ne.shell,v&&ne.shellCollapsed),children:[h.jsxDEV("aside",{className:ue("rail studio-chat-studio-rail",ne.rail),children:h.jsxDEV(rt,{renderMode:"desktop",types:e.types,active:null,onSelect:e.selectEntityType,workspaces:e.workspaces,activeWorkspace:de,workspaceBadges:Se,onSelectWorkspace:e.selectWorkspace},void 0,!1,void 0,this)},void 0,!1,void 0,this),h.jsxDEV("main",{className:i("studio-chat-workspace",n.frame),children:h.jsxDEV("div",{className:i("studio-chat-room",n.room),children:[h.jsxDEV(Ze,{...k.sessionControls,activeSessionId:e.sessionId,loading:k.sessionsLoading,sessions:k.sessions,onNew:()=>D(),onSelect:D,phoneHidden:!k.conversationsOpen},void 0,!1,void 0,this),h.jsxDEV("section",{className:i("studio-chat-thread",n.thread,k.conversationsOpen&&n.threadHidden),"aria-label":"Conversation",children:[h.jsxDEV(Ue,{sessionId:e.sessionId,sessions:k,archiving:ge,archiveBlocked:oe,draftPending:ye,onArchive:()=>void It(),deletion:se,contextCards:xt,progress:B?.progress??[],entryHref:(C,re)=>Kt(e.studioBasePath,C,re),onOpenEntry:(C)=>e.navigate(C),phoneShown:!k.conversationsOpen},void 0,!1,void 0,this),h.jsxDEV("div",{ref:Ce,tabIndex:0,role:"region","aria-label":"Conversation messages",onScroll:Et,className:i("studio-chat-thread-scroll",n.threadScroll),children:h.jsxDEV("div",{className:i("studio-chat-manuscript",n.manuscript),children:[ie&&h.jsxDEV("section",{role:"alert",children:[h.jsxDEV("p",{children:[Rt?"Showing previously loaded messages. ":"","Conversation could not be loaded."]},void 0,!0,void 0,this),h.jsxDEV(R,{type:"button",variant:"ghost",disabled:Dt,onClick:Tt,children:"Retry conversation"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ae&&e.sessionId&&j.length===0?h.jsxDEV("p",{className:i("studio-chat-empty",n.empty),children:"Opening conversation…"},void 0,!1,void 0,this):null,!ie&&(!e.sessionId||!ae)&&j.length===0?h.jsxDEV(ft,{},void 0,!1,void 0,this):null,j.map((C)=>h.jsxDEV(ht,{message:C,client:s,disabled:F,speaker:"Your brain",reading:"manuscript",onAction:St,onApproval:he},C.id,!1,void 0,this)),B?.approvals.map((C)=>h.jsxDEV(pt,{approval:C,disabled:F,onDecision:he},C.approvalId,!1,void 0,this)),B&&B.progress.length>0&&h.jsxDEV("details",{className:i("studio-chat-progress",n.card),children:[h.jsxDEV("summary",{children:["Activity · ",B.progress.length," updates"]},void 0,!0,void 0,this),h.jsxDEV("pre",{className:i("",n.source),children:JSON.stringify(B.progress,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F?h.jsxDEV("p",{className:i("studio-chat-stream-status",n.empty),role:"status",children:"Responding…"},void 0,!1,void 0,this):null,z&&h.jsxDEV(ke,{interrupted:z,draftPending:ve,restoreBlocked:F||b,onRestore:(C)=>{u(C.text),p([...C.uploads]),Ce.current?.closest(".studio-chat-thread")?.querySelector("textarea")?.focus()}},void 0,!1,void 0,this),J?h.jsxDEV("p",{className:i("studio-chat-error",n.empty,n.error),role:"alert",children:J},void 0,!1,void 0,this):null,h.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),h.jsxDEV(ut,{above:be.length>0?h.jsxDEV("div",{"data-studio-chat-starters":"",className:i("studio-chat-starters",n.starters),"aria-label":"Ways to start",children:be.map((C)=>h.jsxDEV("button",{type:"button",className:i("",n.starter),onClick:()=>u(C),children:C},C,!1,void 0,this))},void 0,!1,void 0,this):void 0,onJumpToLatest:At?Pt:void 0,draft:f,sending:F,uploading:b,uploads:d,uploadAttempts:y,onRetryUpload:(C)=>void N([C]),onDismissUpload:m,onDraft:u,locked:ge||se.deleting,onRemoveUpload:(C)=>p((re)=>re.filter((Ht)=>Ht.id!==C)),onFiles:g,onSubmit:Bt,onStop:bt()?kt:void 0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}export{io as StudioChatWorkspace};
|
|
1
|
+
import{A as st,B as Je,C as ze,Ca as ct,aa as it,ba as at,ca as ne,da as ue,ea as rt,fa as lt}from"./main-tcyq2xnp.js";import{Fa as n,Ga as i,Ha as Le,Ia as q,Ja as ut,Ka as mt,La as ft,Ma as ht,Na as pt,Oa as vt,Pa as Y,Qa as yt,Ra as gt}from"./main-2hbxfr9g.js";import{$a as et,Nb as Ve,cb as Ke,hc as dt,ib as Oe,lb as de,nb as Fe}from"./main-2g8gcg0r.js";import"./main-t14ef5wt.js";import{Hc as Z}from"./main-qyf00dty.js";import{Ad as xe,Oc as H,Qc as R,Rc as Ee,Sc as Ge,Vc as Be,Wc as He,Yc as qe,ee as X,ld as tt,md as nt,xd as Ae,yd as Ne}from"./main-45xgzy0v.js";import{Qf as ot}from"./main-7fyr0wv3.js";import{Rf as L}from"./main-y9skwxac.js";import{xg as I}from"./main-f886snck.js";var Q=I(L(),1);var O=I(H(),1),qt={stopped:"Stopped",disconnected:"Connection lost",failed:"Response failed"};function ke(e){let{interrupted:t}=e;return O.jsxDEV("section",{className:i("studio-chat-interruption",n.empty),role:t.kind==="stopped"?"status":"alert","aria-atomic":"true",children:[O.jsxDEV("strong",{children:qt[t.kind]},void 0,!1,void 0,this),O.jsxDEV("p",{children:"Any received text is kept here. Stopping the response does not undo completed actions; the server may still be working."},void 0,!1,void 0,this),t.detail&&O.jsxDEV("p",{children:t.detail},void 0,!1,void 0,this),t.retry&&O.jsxDEV(O.Fragment,{children:[O.jsxDEV("p",{children:"Sending again may repeat completed actions. Review the request before sending."},void 0,!1,void 0,this),O.jsxDEV(R,{type:"button",variant:"ghost",disabled:e.restoreBlocked||e.draftPending,onClick:()=>{if(!t.retry||e.draftPending)return;e.onRestore(t.retry)},children:"Review retry in composer"},void 0,!1,void 0,this),e.draftPending&&O.jsxDEV("p",{children:"Your composer draft is unchanged. Send or clear it before restoring this request."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var _=I(L(),1);var x=I(H(),1);function we(e){return x.jsxDEV("aside",{className:i("studio-chat-context",n.contextBody),tabIndex:0,"aria-label":"Conversation sources and attachments",children:x.jsxDEV("div",{className:i("studio-chat-context-list",n.cards),children:[e.session?.contextHandoff?x.jsxDEV("section",{className:i("studio-chat-context-card",n.contextItem),children:[x.jsxDEV("span",{className:i("studio-chat-context-kicker",n.kicker),children:"Linked context"},void 0,!1,void 0,this),x.jsxDEV("h3",{className:i("studio-chat-context-card-title",n.cardHeading,X.section),children:e.session.contextHandoff.titleSeed},void 0,!1,void 0,this),x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:[e.session.contextHandoff.sourceId," ·"," ",e.session.contextHandoff.itemId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null,e.cards.length===0&&e.progress.length===0?x.jsxDEV("p",{className:i("studio-chat-empty",n.empty),children:"No sources or attachments in this conversation yet."},void 0,!1,void 0,this):null,e.cards.map((t,o)=>x.jsxDEV("section",{className:i("studio-chat-context-card",n.contextItem),children:[x.jsxDEV("span",{className:i("studio-chat-context-kicker",n.kicker),children:t.kind==="sources"?"Sources":"Artifact"},void 0,!1,void 0,this),x.jsxDEV("h3",{className:i("studio-chat-context-card-title",n.cardHeading,X.section),children:t.kind==="sources"?t.title??`${t.sources.length} consulted`:t.kind==="attachment"?t.title:"Conversation context"},void 0,!1,void 0,this),t.kind==="sources"?x.jsxDEV(x.Fragment,{children:[x.jsxDEV("ul",{children:t.sources.slice(0,5).map((s)=>x.jsxDEV("li",{children:s.title??s.source},s.id,!1,void 0,this))},void 0,!1,void 0,this),t.sources.length>5?x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:[t.sources.length-5," more sources in the conversation."]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this):t.kind==="attachment"&&t.description?x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:t.description},void 0,!1,void 0,this):null]},`${t.kind}-${t.id}-${o}`,!0,void 0,this)),e.progress.map((t,o)=>x.jsxDEV("section",{className:i("studio-chat-context-card",n.contextItem),children:[x.jsxDEV("span",{className:i("studio-chat-context-kicker",n.kicker),children:"Durable job"},void 0,!1,void 0,this),x.jsxDEV("h3",{className:i("studio-chat-context-card-title",n.cardHeading,X.section),children:t.operationTarget??t.operationType},void 0,!1,void 0,this),x.jsxDEV("p",{className:i("studio-chat-context-card-text",n.cardText),children:t.message??t.status},void 0,!1,void 0,this)]},`${t.type}-${o}`,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var Ot=86400000;function Ie(e,t){return new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).format(e)}function Lt(e,t){return Math.round((Date.parse(t)-Date.parse(e))/Ot)}function De(e,t,o){let s=Lt(Ie(e,o),Ie(t,o));if(s<=0)return"Today";if(s===1)return"Yesterday";if(s<7)return"This week";return"Earlier"}function Re(e,t,o){let s=[...e].sort((r,a)=>a.lastActiveAt.localeCompare(r.lastActiveAt));return["Today","Yesterday","This week","Earlier"].map((r)=>({label:r,sessions:s.filter((a)=>De(Date.parse(a.lastActiveAt),t,o)===r)})).filter((r)=>r.sessions.length>0)}function le(e){let t=e.contextHandoff;if(t?.sourceId!==Ne)return null;let o=xe(t.itemId);return o?{...o,title:t.titleSeed}:null}function Te(e,t,o){let s=le(e);if(s)return{kind:"entry",text:s.title};let r=Date.parse(e.lastActiveAt);if(Number.isNaN(r))return{kind:"time",text:""};let a=Math.floor((t-r)/60000),l=De(r,t,o);if(l==="Today"){if(a<1)return{kind:"time",text:"Just now"};if(a<60)return{kind:"time",text:`${a} ${a===1?"minute":"minutes"} ago`};let f=Math.floor(a/60);return{kind:"time",text:`${f} ${f===1?"hour":"hours"} ago`}}if(l==="Yesterday")return{kind:"time",text:"Yesterday"};if(l==="This week")return{kind:"time",text:new Intl.DateTimeFormat("en-GB",{weekday:"long",timeZone:o}).format(r)};return{kind:"time",text:new Intl.DateTimeFormat("en-GB",{day:"numeric",month:"short",timeZone:o}).format(r)}}var P=I(L(),1);var A=I(H(),1);function Pe(e){let[t,o]=P.useState(!1),[s,r]=P.useState(e.title),[a,l]=P.useState(!1),[f,d]=P.useState(null),u=P.useRef(!1),p=P.useRef(!1),b=P.useRef(null);P.useEffect(()=>{if(t)b.current?.focus()},[t]);let y=P.useRef(null);P.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);let N=()=>{o(!1),d(null),requestAnimationFrame(()=>y.current?.querySelector("button")?.focus())},g=async()=>{if(p.current||!s.trim())return;p.current=!0,l(!0),d(null);try{if(await e.onRename(s.trim()),u.current)N()}catch(m){if(u.current)d(Ae(m,"Rename failed. Your proposed title is kept.")||"Rename failed. Your proposed title is kept.")}finally{if(p.current=!1,u.current)l(!1)}};return A.jsxDEV(A.Fragment,{children:[A.jsxDEV("span",{ref:y,children:A.jsxDEV(R,{type:"button",variant:"ghost","aria-expanded":t,disabled:t,onClick:()=>{r(e.title),o(!0)},children:"Rename"},void 0,!1,void 0,this)},void 0,!1,void 0,this),t&&A.jsxDEV("form",{className:i("studio-chat-rename",n.sessionControls),onSubmit:(m)=>{m.preventDefault(),g()},children:[A.jsxDEV("label",{children:["Conversation title",A.jsxDEV(Ee,{ref:b,xstyle:n.sessionFilterSelect,value:s,onChange:(m)=>r(m.target.value),required:!0,maxLength:48,disabled:a},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A.jsxDEV("div",{className:i("",n.actions),children:[A.jsxDEV(R,{type:"submit",disabled:a||!s.trim(),children:a?"Renaming…":"Save title"},void 0,!1,void 0,this),A.jsxDEV(R,{type:"button",variant:"ghost",disabled:a,onClick:N,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&A.jsxDEV("p",{role:"alert",children:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var c=I(H(),1);function Ue(e){let{currentSession:t,archivedSession:o,setConversationsOpen:s,detailsOpen:r,setDetailsOpen:a,renameCurrent:l}=e.sessions,f=_.useRef(null),d=_.useId(),u=e.draftPending?"Send or clear the draft before archiving or deleting.":void 0,p=t?le(t):null,b=p?.title??t?.contextHandoff?.titleSeed??void 0,y=p?e.entryHref(p.entityType,p.entityId):void 0,N=t?.title??(e.sessionId?"Conversation":"New conversation"),g=(v)=>y!==void 0?c.jsxDEV("a",{href:y,className:i("studio-chat-open-entry",n.openEntry,v&&n.openEntryIcon),"aria-label":v?"Open entry":void 0,onClick:(k)=>{if(!Oe(k))return;k.preventDefault(),e.onOpenEntry(y)},children:v?c.jsxDEV("span",{"aria-hidden":"true",children:"↗"},void 0,!1,void 0,this):"Open entry ↗"},void 0,!1,void 0,this):null,m=c.jsxDEV(R,{type:"button",variant:"ghost",xstyle:n.toolbarButton,"aria-label":"Conversation details and options","aria-haspopup":"dialog","aria-expanded":r,onClick:()=>a(!0),children:"•••"},void 0,!1,void 0,this),[w]=_.useState(()=>Symbol("chat thread"));return Z(w,e.phoneShown?{title:N,back:{label:"Conversations",onBack:()=>s(!0)},action:c.jsxDEV(c.Fragment,{children:[g(!0),m]},void 0,!0,void 0,this)}:null),c.jsxDEV(c.Fragment,{children:[c.jsxDEV("header",{className:i("studio-chat-thread-head",n.threadHead,n.phoneGoneFlex),children:[c.jsxDEV("h1",{className:i("studio-chat-session-heading",n.title),title:t?.title,children:N},void 0,!1,void 0,this),b&&c.jsxDEV("span",{className:i("studio-chat-about",n.about),"data-studio-chat-about":"",children:["About: ",b]},void 0,!0,void 0,this),c.jsxDEV("div",{className:i("studio-chat-head-actions",n.toolbar),children:[g(!1),c.jsxDEV("span",{ref:f,children:m},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c.jsxDEV(Be,{open:r,onOpenChange:(v)=>{if(a(v),!v)e.deletion.cancelDelete()},children:c.jsxDEV(He,{"aria-describedby":void 0,onCloseAutoFocus:(v)=>{v.preventDefault(),([...document.querySelectorAll('[aria-label="Conversation details and options"]')].find((D)=>D.offsetParent!==null)??f.current?.querySelector("button"))?.focus()},children:[c.jsxDEV(qe,{children:"Conversation details"},void 0,!1,void 0,this),c.jsxDEV("div",{className:i("studio-chat-details",n.details),children:[c.jsxDEV("p",{children:t?.title??"New conversation"},void 0,!1,void 0,this),c.jsxDEV("div",{className:i("studio-chat-session-actions",n.actions),children:[t&&c.jsxDEV(Pe,{title:t.title,onRename:l},t.id,!1,void 0,this),o&&c.jsxDEV("p",{role:"status",children:"Archived conversation. New messages here remain archived."},void 0,!1,void 0,this),e.sessionId&&!o?c.jsxDEV(R,{className:"studio-chat-header-action",variant:"ghost",type:"button",onClick:e.onArchive,disabled:e.archiveBlocked,"aria-describedby":u?d:void 0,children:e.archiving?"Archiving…":"Archive"},void 0,!1,void 0,this):null,e.sessionId&&(e.deletion.confirming?c.jsxDEV("section",{role:"group","aria-label":"Confirm conversation deletion",children:[c.jsxDEV("p",{children:"Delete this conversation permanently? This cannot be undone."},void 0,!1,void 0,this),c.jsxDEV("p",{children:"Deleting history does not undo completed actions or guarantee that remote work has stopped."},void 0,!1,void 0,this),e.deletion.deleteError&&c.jsxDEV("p",{role:"alert",children:e.deletion.deleteError},void 0,!1,void 0,this),c.jsxDEV(R,{type:"button",variant:"ghost",autoFocus:!0,"aria-label":"Cancel conversation deletion",disabled:e.deletion.deleting,onClick:e.deletion.cancelDelete,children:"Cancel"},void 0,!1,void 0,this),c.jsxDEV(R,{type:"button",variant:"danger","aria-label":"Permanently delete conversation",disabled:e.archiveBlocked,onClick:()=>void e.deletion.confirmDelete(),children:e.deletion.deleting?"Deleting…":"Delete permanently"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c.jsxDEV(R,{type:"button",variant:"danger","aria-label":"Delete conversation",disabled:e.archiveBlocked,"aria-describedby":u?d:void 0,onClick:e.deletion.requestDelete,children:"Delete conversation"},void 0,!1,void 0,this)),u&&c.jsxDEV("p",{id:d,children:u},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c.jsxDEV("details",{children:[c.jsxDEV("summary",{children:"Sources and attachments"},void 0,!1,void 0,this),c.jsxDEV(we,{cards:e.contextCards,progress:e.progress,session:t},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c.jsxDEV("details",{children:[c.jsxDEV("summary",{children:"File types and limits"},void 0,!1,void 0,this),c.jsxDEV("p",{id:"studio-chat-upload-guidance",children:Le},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var U=I(L(),1);var Ut=250;function Me(e){let{chatClient:t,queryClient:o,sessionId:s,studioBasePath:r,navigate:a}=e,[l,f]=U.useState(s===null),[d,u]=U.useState(!1),[p,b]=U.useState(""),[y,N]=U.useState({query:"",archived:!1,offset:0});U.useEffect(()=>{let E=window.setTimeout(()=>N((T)=>T.query===p.trim()?T:{...T,query:p.trim(),offset:0}),Ut);return()=>window.clearTimeout(E)},[p]);let g=Ke({queryKey:[...q.sessions,y],queryFn:()=>t.listSessions(y)}),m=g.data??[],w=m.find((E)=>E.id===s)??o.getQueriesData({queryKey:q.sessions}).flatMap(([,E])=>E??[]).find((E)=>E.id===s),v=U.useCallback(()=>{u(!1)},[]),k=U.useCallback((E,T=!1)=>{a(Fe(r,E),{preserveWork:T}),f(!1),v()},[a,r,v]),D=async(E)=>{if(!w)return;let T=await t.renameSession(w.id,E);if(!T.renamed)throw Error("The conversation could not be renamed.");o.setQueriesData({queryKey:q.sessions},(V)=>V?.map((W)=>W.id===w.id?{...W,title:T.title}:W)),o.invalidateQueries({queryKey:q.sessions})};return{sessions:m,currentSession:w,archivedSession:w?.archived===!0,sessionControls:{search:p,view:y,error:g.error?"Sessions could not be loaded.":null,onRetry:()=>{g.refetch()},onSearch:b,onView:N},sessionsLoading:g.isPending,navigateToSession:k,conversationsOpen:l,setConversationsOpen:f,detailsOpen:d,setDetailsOpen:u,closeDisclosures:v,renameCurrent:D}}var K=I(L(),1);function Qe(e){let{chatClient:t,draftKey:o,currentDraftKey:s,setUploads:r}=e,[a,l]=K.useState(!1),[f,d]=K.useState([]),u=K.useRef(null),p=K.useCallback(async(g)=>{if(u.current||g.length===0)return;let m=Symbol();if(u.current=m,l(!0),d((w)=>[...w.filter((v)=>!g.some((k)=>k.id===v.id)),...g.map((v)=>({id:v.id,file:v.file,status:"uploading"}))]),await Promise.all(g.map(async(w)=>{try{let v=await t.upload(w.file,w.file.name);if(u.current!==m||s.current!==o)return;r((k)=>[...k,v]),d((k)=>k.filter((D)=>D.id!==w.id))}catch(v){if(u.current!==m||s.current!==o)return;d((k)=>k.map((D)=>D.id===w.id?{...D,status:"failed",error:Y(v,"Upload failed")}:D))}})),u.current===m)u.current=null,l(!1)},[t,o,s,r]),b=K.useCallback(async(g)=>{let m=Array.from(g.target.files??[]);g.target.value="",await p(m.map((w)=>({id:crypto.randomUUID(),file:w,status:"uploading"})))},[p]),y=K.useCallback((g)=>{d((m)=>m.filter((w)=>w.id!==g))},[]),N=K.useCallback(()=>{u.current=null,l(!1),d([])},[]);return{uploading:a,uploadAttempts:f,runUploads:p,uploadFiles:b,dismissAttempt:y,reset:N}}var G=I(L(),1);function We(e){let{chatClient:t,queryClient:o,sessionId:s,draftKey:r,currentDraftKey:a,mountedRef:l,blocked:f,setSending:d,setError:u,navigateToSession:p}=e,[b,y]=G.useState(!1),N=G.useCallback(async()=>{if(!s||f)return;d(!0),y(!0);try{if(await t.archiveSession(s),await o.invalidateQueries({queryKey:q.sessions}),l.current&&a.current===r)p(void 0,!0)}catch(m){if(l.current&&a.current===r)u(Y(m,"Conversation could not be archived"))}finally{if(l.current&&a.current===r)d(!1),y(!1)}},[t,o,s,r,a,l,f,d,u,p]),g=G.useCallback(()=>y(!1),[]);return{archiving:b,archiveCurrent:N,reset:g}}var M=I(L(),1);function $e(e){let{chatClient:t,queryClient:o,sessionId:s,draftKey:r,currentDraftKey:a,mountedRef:l,blocked:f,setSending:d,navigateToSession:u}=e,[p,b]=M.useState(null),[y,N]=M.useState(!1),[g,m]=M.useState(null),w=M.useRef(0),v=M.useRef(!1),k=p===r,D=M.useCallback(()=>{w.current++,v.current=!1,b(null),N(!1),m(null)},[]);return{confirming:k,deleting:y,deleteError:g,requestDelete:()=>{if(!s||f||v.current)return;m(null),b(r)},cancelDelete:()=>{if(!v.current)b(null)},confirmDelete:async()=>{if(!s||!k||f||v.current)return;let W=w.current,B=()=>l.current&&a.current===r&&w.current===W;v.current=!0,N(!0),d(!0),m(null);try{if(!(await t.deleteSession(s)).deleted)throw Error("Deletion was not acknowledged");if(await o.cancelQueries({queryKey:q.messages(s)}),o.removeQueries({queryKey:q.messages(s)}),o.setQueriesData({queryKey:q.sessions},(J)=>J?.filter((z)=>z.id!==s)),o.invalidateQueries({queryKey:q.sessions}),B())b(null),u(void 0,!0)}catch{if(B())m("Deletion could not be confirmed. The conversation may already be deleted. Check history before trying again.")}finally{if(B())v.current=!1,N(!1),d(!1)}},reset:D}}var ee=I(L(),1);function _e(e){let{chatClient:t,handoff:o,sessionId:s,apiPath:r,draftStore:a,draftKey:l,currentDraftKey:f,mountedRef:d,setDraft:u,setError:p,navigateToSession:b}=e,y=ee.useRef(null);ee.useEffect(()=>{if(!o||s)return;let N=`${o.sourceId}\x00${o.itemId}`;if(y.current===N)return;y.current=N,u(o.prompt),p(null);let g=()=>d.current===!0&&f.current===l&&y.current===N;t.openContextSession({version:1,sourceId:o.sourceId,itemId:o.itemId,titleSeed:o.label}).then(({conversationId:m})=>{if(!g())return;a.adopt(l,Ve(r,m)),b(m,!0)}).catch((m)=>{if(!g())return;y.current=null,p(Y(m,"Context could not be attached"))})},[t,o,s,r,a,l,f,d,u,p,b])}var te=I(L(),1);function Ye(e){let{question:t,sessionId:o,setDraft:s}=e,r=te.useRef(null);te.useEffect(()=>{if(!t||o)return;if(r.current===t)return;r.current=t,s(t)},[t,o,s])}var ce=I(L(),1);function je(e){let{onChange:t,draft:o,uploadCount:s,uploadAttemptCount:r,sending:a,uploading:l}=e;ce.useEffect(()=>{t?.({hasDraft:Boolean(o||s||r),busy:a||l})},[o,s,r,a,l,t]),ce.useEffect(()=>()=>t?.({hasDraft:!1,busy:!1}),[t])}var Xe=I(L(),1);var S=I(H(),1);function Ze(e){let t=Date.now(),o=e.sessions.length>0||e.search!==""||e.view.query!==""||e.view.archived||e.view.offset>0,s=S.jsxDEV(R,{className:"studio-chat-new",type:"button",size:"sm","aria-label":"New conversation",onClick:e.onNew,children:"New"},void 0,!1,void 0,this),[r]=Xe.useState(()=>Symbol("conversations"));return Z(r,e.phoneHidden===!0?null:{title:"Conversations",action:s}),S.jsxDEV("aside",{className:i("studio-chat-session-picker",n.conversations,e.phoneHidden===!0&&n.conversationsHidden),"aria-label":"Conversations",children:[S.jsxDEV("div",{className:i("studio-chat-session-controls",n.sessionControls),children:[S.jsxDEV("div",{className:i("",n.railHead,n.phoneGoneFlex),children:[S.jsxDEV("h2",{className:i("",n.railTitle),children:"Conversations"},void 0,!1,void 0,this),S.jsxDEV(R,{className:"studio-chat-new",type:"button",variant:"secondary",size:"sm","aria-label":"New conversation",onClick:e.onNew,children:"New"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o&&S.jsxDEV(Je,{label:"Conversation search and filters",searchLabel:"Search conversations",search:e.search,onSearch:e.onSearch,filterLabel:"Filter",filterCount:e.view.archived?1:0,filtered:Boolean(e.view.query)||e.view.archived,onClear:()=>{e.onSearch(""),e.onView({...e.view,query:"",archived:!1,offset:0})},children:S.jsxDEV(Ge,{"aria-label":"Show conversations",value:e.view.archived?"archived":"active",onChange:(a)=>e.onView({...e.view,archived:a.target.value==="archived",offset:0}),children:[S.jsxDEV("option",{value:"active",children:"Active conversations"},void 0,!1,void 0,this),S.jsxDEV("option",{value:"archived",children:"Archived conversations"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),e.error&&S.jsxDEV("p",{role:"alert",children:[e.error," ",S.jsxDEV(R,{type:"button",variant:"ghost",onClick:e.onRetry,children:"Retry sessions"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),S.jsxDEV("div",{className:i("studio-chat-session-list",n.sessionList),children:[e.loading?S.jsxDEV("p",{className:i("studio-chat-empty",n.railEmpty),children:"Loading conversations…"},void 0,!1,void 0,this):null,!e.loading&&!e.error&&e.sessions.length===0?S.jsxDEV("p",{className:i("studio-chat-empty",n.railEmpty),children:e.view.query?"No conversations match this search.":e.view.offset>0?"No more conversations.":e.view.archived?"No archived conversations.":"No conversations yet."},void 0,!1,void 0,this):null,Re(e.sessions,t).map((a)=>S.jsxDEV("section",{"aria-label":a.label,children:[S.jsxDEV("h3",{className:i("",n.dayLabel),children:a.label},void 0,!1,void 0,this),a.sessions.map((l)=>{let f=l.id===e.activeSessionId,d=Te(l,t);return S.jsxDEV("button",{className:i("studio-chat-session",n.session,f&&n.activeSession),"data-active":f?"true":"false","aria-current":f?"true":void 0,type:"button",onClick:()=>e.onSelect(l.id),children:[S.jsxDEV("strong",{className:i("studio-chat-session-title",n.sessionTitle),children:l.title},void 0,!1,void 0,this),S.jsxDEV("small",{className:i("studio-chat-session-note",n.sessionNote),"data-note":d.kind,children:d.kind==="entry"?S.jsxDEV(S.Fragment,{children:[S.jsxDEV("span",{"aria-hidden":"true",className:i("",n.brainMark)},void 0,!1,void 0,this),d.text]},void 0,!0,void 0,this):S.jsxDEV("time",{dateTime:l.lastActiveAt,title:l.lastActiveAt,children:d.text},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},l.id,!0,void 0,this)})]},a.label,!0,void 0,this)),(e.view.offset>0||e.sessions.length>=25)&&S.jsxDEV(ze,{label:"Conversation pages",offset:e.view.offset,count:e.sessions.length,loading:e.loading,hasNext:e.sessions.length>=25,onPrevious:()=>e.onView({...e.view,offset:Math.max(0,e.view.offset-25)}),onNext:()=>e.onView({...e.view,offset:e.view.offset+25})},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var h=I(H(),1);function Kt(e,t,o){return`${e==="/"?"":e.replace(/\/+$/,"")}/entities/${encodeURIComponent(t)}/${encodeURIComponent(o)}`}function io(e){let t=et(),o=tt(),s=Q.useMemo(()=>ot({apiPath:e.apiPath,fetch:o}),[e.apiPath,o]),{draftStore:r,draftKey:a,currentDraftKey:l,draft:f,uploads:d,setDraft:u,setUploads:p}=vt({draftStore:e.draftStore,apiPath:e.apiPath,sessionId:e.sessionId}),{uploading:b,uploadAttempts:y,runUploads:N,uploadFiles:g,dismissAttempt:m,reset:w}=Qe({chatClient:s,draftKey:a,currentDraftKey:l,setUploads:p}),v=at(),k=Me({chatClient:s,queryClient:t,sessionId:e.sessionId,studioBasePath:e.studioBasePath,navigate:e.navigate}),{navigateToSession:D,closeDisclosures:E}=k,T=Q.useRef(!1),V=Q.useRef(null),{pendingMessages:W,stream:B,sending:F,error:J,interrupted:z,setSending:me,setError:fe,submitPrompt:Ct,respondToApproval:he,runSuggestedAction:St,hasActiveStream:bt,stopActiveStream:kt,abortActiveStream:pe,reset:wt}=yt({chatClient:s,queryClient:t,sessionId:e.sessionId,apiPath:e.apiPath,draftStore:r,draftKey:a,currentDraftKey:l,mountedRef:T,adoptedSessionRef:V,uploads:d,uploading:b,uploadAttemptCount:y.length,navigateToSession:D});_e({chatClient:s,handoff:e.handoff,sessionId:e.sessionId,apiPath:e.apiPath,draftStore:r,draftKey:a,currentDraftKey:l,mountedRef:T,setDraft:u,setError:fe,navigateToSession:D}),Ye({question:e.question,sessionId:e.sessionId,setDraft:u});let ve=Boolean(f)||d.length>0,ye=ve||y.length>0,oe=F||b||ye,{archiving:ge,archiveCurrent:It,reset:Nt}=We({chatClient:s,queryClient:t,sessionId:e.sessionId,draftKey:a,currentDraftKey:l,mountedRef:T,blocked:oe,setSending:me,setError:fe,navigateToSession:D}),se=$e({chatClient:s,queryClient:t,sessionId:e.sessionId,draftKey:a,currentDraftKey:l,mountedRef:T,blocked:oe,setSending:me,navigateToSession:D});Q.useEffect(()=>(T.current=!0,()=>{T.current=!1,pe()}),[pe]),je({onChange:e.onNavigationStateChange,draft:f,uploadCount:d.length,uploadAttemptCount:y.length,sending:F,uploading:b});let{visibleMessages:j,contextCards:xt,historyFailed:ie,historyOpening:ae,historyReading:Dt,hasStoredHistory:Rt,retryHistory:Tt}=gt({chatClient:s,sessionId:e.sessionId,sending:F,pendingMessages:W,stream:B}),{ref:Ce,onScroll:Et,awayFromLatest:At,jumpToLatest:Pt}=nt({resetKey:e.sessionId,contentKey:`${j.length}:${B?.text.length??-1}`});Q.useEffect(()=>{if(E(),e.sessionId&&V.current===e.sessionId){V.current=null;return}wt(),w(),Nt(),se.reset()},[e.sessionId]);let Bt=(C)=>{C.preventDefault(),Ct(f)},Se=ct(e.workspaces),be=!ie&&(!e.sessionId||!ae)&&j.length===0?mt({types:e.types.map((C)=>C.entityType),workspaces:e.workspaces.map((C)=>C.id)}):[];return h.jsxDEV(dt,{value:(C)=>e.navigate(C),children:h.jsxDEV("div",{className:i("studio",st.frame,n.root,it.space),"data-view":"chat","data-studio-shell":"",children:[h.jsxDEV(lt,{contextLabel:"Chat",navigation:{types:e.types,workspaces:e.workspaces,activeEntityType:null,activeWorkspaceId:de,workspaceBadges:Se,selectEntityType:e.selectEntityType,selectWorkspace:e.selectWorkspace}},void 0,!1,void 0,this),h.jsxDEV("div",{className:ue("studio-chat-shell",n.shell,ne.shell,v&&ne.shellCollapsed),children:[h.jsxDEV("aside",{className:ue("rail studio-chat-studio-rail",ne.rail),children:h.jsxDEV(rt,{renderMode:"desktop",types:e.types,active:null,onSelect:e.selectEntityType,workspaces:e.workspaces,activeWorkspace:de,workspaceBadges:Se,onSelectWorkspace:e.selectWorkspace},void 0,!1,void 0,this)},void 0,!1,void 0,this),h.jsxDEV("main",{className:i("studio-chat-workspace",n.frame),children:h.jsxDEV("div",{className:i("studio-chat-room",n.room),children:[h.jsxDEV(Ze,{...k.sessionControls,activeSessionId:e.sessionId,loading:k.sessionsLoading,sessions:k.sessions,onNew:()=>D(),onSelect:D,phoneHidden:!k.conversationsOpen},void 0,!1,void 0,this),h.jsxDEV("section",{className:i("studio-chat-thread",n.thread,k.conversationsOpen&&n.threadHidden),"aria-label":"Conversation",children:[h.jsxDEV(Ue,{sessionId:e.sessionId,sessions:k,archiving:ge,archiveBlocked:oe,draftPending:ye,onArchive:()=>void It(),deletion:se,contextCards:xt,progress:B?.progress??[],entryHref:(C,re)=>Kt(e.studioBasePath,C,re),onOpenEntry:(C)=>e.navigate(C),phoneShown:!k.conversationsOpen},void 0,!1,void 0,this),h.jsxDEV("div",{ref:Ce,tabIndex:0,role:"region","aria-label":"Conversation messages",onScroll:Et,className:i("studio-chat-thread-scroll",n.threadScroll),children:h.jsxDEV("div",{className:i("studio-chat-manuscript",n.manuscript),children:[ie&&h.jsxDEV("section",{role:"alert",children:[h.jsxDEV("p",{children:[Rt?"Showing previously loaded messages. ":"","Conversation could not be loaded."]},void 0,!0,void 0,this),h.jsxDEV(R,{type:"button",variant:"ghost",disabled:Dt,onClick:Tt,children:"Retry conversation"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ae&&e.sessionId&&j.length===0?h.jsxDEV("p",{className:i("studio-chat-empty",n.empty),children:"Opening conversation…"},void 0,!1,void 0,this):null,!ie&&(!e.sessionId||!ae)&&j.length===0?h.jsxDEV(ft,{},void 0,!1,void 0,this):null,j.map((C)=>h.jsxDEV(ht,{message:C,client:s,disabled:F,speaker:"Your brain",reading:"manuscript",onAction:St,onApproval:he},C.id,!1,void 0,this)),B?.approvals.map((C)=>h.jsxDEV(pt,{approval:C,disabled:F,onDecision:he},C.approvalId,!1,void 0,this)),B&&B.progress.length>0&&h.jsxDEV("details",{className:i("studio-chat-progress",n.card),children:[h.jsxDEV("summary",{children:["Activity · ",B.progress.length," updates"]},void 0,!0,void 0,this),h.jsxDEV("pre",{className:i("",n.source),children:JSON.stringify(B.progress,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F?h.jsxDEV("p",{className:i("studio-chat-stream-status",n.empty),role:"status",children:"Responding…"},void 0,!1,void 0,this):null,z&&h.jsxDEV(ke,{interrupted:z,draftPending:ve,restoreBlocked:F||b,onRestore:(C)=>{u(C.text),p([...C.uploads]),Ce.current?.closest(".studio-chat-thread")?.querySelector("textarea")?.focus()}},void 0,!1,void 0,this),J?h.jsxDEV("p",{className:i("studio-chat-error",n.empty,n.error),role:"alert",children:J},void 0,!1,void 0,this):null,h.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),h.jsxDEV(ut,{above:be.length>0?h.jsxDEV("div",{"data-studio-chat-starters":"",className:i("studio-chat-starters",n.starters),"aria-label":"Ways to start",children:be.map((C)=>h.jsxDEV("button",{type:"button",className:i("",n.starter),onClick:()=>u(C),children:C},C,!1,void 0,this))},void 0,!1,void 0,this):void 0,onJumpToLatest:At?Pt:void 0,draft:f,sending:F,uploading:b,uploads:d,uploadAttempts:y,onRetryUpload:(C)=>void N([C]),onDismissUpload:m,onDraft:u,locked:ge||se.deleting,onRemoveUpload:(C)=>p((re)=>re.filter((Ht)=>Ht.id!==C)),onFiles:g,onSubmit:Bt,onStop:bt()?kt:void 0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}export{io as StudioChatWorkspace};
|
|
2
2
|
|
|
3
3
|
//# debugId=F653EF7BE547482964756E2164756E21
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{B as a}from"./index-1vaa2761.js";import"./index-e0qz6mam.js";import"./index-wete5qfn.js";import"./index-n3cy8ttx.js";import"./index-gnbfdewj.js";import"./index-m2qv3p6y.js";import"./index-0k63cxm5.js";import"./index-rwrp530c.js";import"./index-njqkf4cd.js";import"./index-74vg6r70.js";import"./index-cyq5dhvm.js";export{a as App};
|
|
3
|
-
|
|
4
|
-
//# debugId=B0224EA8233B0C3764756E2164756E21
|
|
5
|
-
//# sourceMappingURL=app-n0bqjatx.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/ui/studio-chunks/{account-view-j9wkxck6.js.map → account-view-ak5tfxgg.js.map}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/ui/studio-chunks/{studio-ask-panel-njthpfwq.js.map → studio-ask-panel-vjymeavp.js.map}
RENAMED
|
File without changes
|
|
File without changes
|