@rizom/brain 0.2.0-alpha.797 → 0.2.0-alpha.798
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 +4 -4
- package/dist/chunks/{app-y52qw8p8.js → app-n2spv8qr.js} +2 -2
- package/dist/chunks/{index-hjh2fs5f.js → index-mspwyc3a.js} +2 -2
- package/dist/chunks/{index-zadma995.js → index-r1hwjqtq.js} +3 -3
- package/dist/chunks/{index-zadma995.js.map → index-r1hwjqtq.js.map} +1 -1
- package/dist/chunks/{package-gap39evv.js → package-p4q00bfd.js} +3 -3
- package/dist/chunks/{package-gap39evv.js.map → package-p4q00bfd.js.map} +1 -1
- package/dist/model.js +4 -4
- package/dist/model.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/ui/{studio-app-a6dcmrh1.js → studio-app-wft7ba0t.js} +1 -1
- package/dist/ui/studio-asset-manifest.json +5 -5
- package/dist/ui/studio-chunks/studio-chat-workspace-wy37fxat.js +3 -0
- package/dist/ui/studio-chunks/{studio-chat-workspace-3gbjq8vn.js.map → studio-chat-workspace-wy37fxat.js.map} +4 -4
- package/package.json +1 -1
- package/dist/ui/studio-chunks/studio-chat-workspace-3gbjq8vn.js +0 -3
- /package/dist/chunks/{app-y52qw8p8.js.map → app-n2spv8qr.js.map} +0 -0
- /package/dist/chunks/{index-hjh2fs5f.js.map → index-mspwyc3a.js.map} +0 -0
- /package/dist/ui/{studio-app-a6dcmrh1.js.map → studio-app-wft7ba0t.js.map} +0 -0
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ge as k,he as V,ie as U}from"./chunks/index-
|
|
2
|
+
import{ge as k,he as V,ie as U}from"./chunks/index-r1hwjqtq.js";import{$e as N,Ae as A,Be as x,af as O,bf as z,cf as M,df as q,ef as J,ff as L,hf as _,if as j,je as E,me as I}from"./chunks/index-eh14snbv.js";import"./chunks/index-2fzk7ry8.js";import{mf as D}from"./chunks/index-v1w1v20e.js";import{Al as P,Bl as w,Po as B,oj as C,pg as h}from"./chunks/index-bm3cdksa.js";import{aq as p}from"./chunks/index-jnhy5rdc.js";import{Gt as S,It as v}from"./chunks/index-fgy1pfas.js";import"./chunks/index-acmkz3bm.js";import"./chunks/index-scaa1esw.js";import"./chunks/index-ntzw85st.js";import"./chunks/index-ew0x69wp.js";import{mkdtemp as K,rm as b}from"fs/promises";import{tmpdir as X}from"os";import{join as m}from"path";var y="none";function s(){return Promise.reject(Error("A test brain has no AI provider"))}function W(e){return{specificationVersion:"v3",provider:"test-brain",modelId:e,supportedUrls:{},doGenerate:s,doStream:s}}function T(e){let r={...e};return{generateText:s,generateObject:s,judge:s,generateImage:s,getModel:()=>W(r.model??"none"),canGenerateImages:()=>!1,getConfig:()=>({...r}),updateConfig:(o)=>{r={...r,...o}}}}function R(){return{identity:{model:"test:none",dimensions:1536,promptRevision:0},embedQuery:s,embedDocuments:s}}var Y="shell",ee=20;function te(e){if("needsConfirmation"in e)return{needsConfirmation:!0,summary:e.summary};if(!e.success)return{success:!1,error:e.error,...p({code:e.code})};return{success:!0,...p({data:e.data,message:e.message})}}function re(e,r){if(e.status==="completed"||e.status==="failed")return!0;return e.status==="pending"&&e.lastError!==null&&e.scheduledFor>r}function ne(e,r){return e.flatMap((o)=>{if(!D(o))throw Error("A test brain runs packages configured with use(), as defineBrain does");return P(o.definition,o.config,r)})}async function F(e,r){let o=k(r.directory);V(o,r.brainVersion);let f=ne(e.plugins,{name:o.name,version:o.version}),a=await K(m(r.temporaryRoot??X(),"rizom-test-brain-")),g={...E({dataDir:a,cacheDir:m(a,"cache"),distDir:m(a,"dist")}),embedding:{enabled:!1}},i;try{await new J(v.createFresh({level:S.WARN,context:"test-brain"}),{getStandardConfigWithDirectories:async()=>g,migrateEntities:O,migrateJobQueue:z,migrateConversations:M,migrateRuntimeState:q}).runAllMigrations();let t=_({name:o.name,version:o.version,logLevel:"warn",plugins:f,shellConfig:{...g,dataDir:m(a,"brain-data"),ai:{model:y}}}),n=I(j(t));i=N.createFresh(n,{aiService:T(A(n)),embeddingService:R()}),await i.initialize()}catch(t){throw await b(a,{recursive:!0,force:!0}),t}let Z=f.map((t)=>t.id),H,Q=async()=>{try{await i.shutdown()}finally{await b(a,{recursive:!0,force:!0})}};return Object.freeze({async tool(t,n){let l=i.getMCPService().listTools(),d=l.find(({tool:u})=>u.name===t);if(!d)throw Error(`No tool "${t}"; this brain has ${l.map(({tool:u})=>u.name).join(", ")}`);return te(await d.tool.handler(n,L()))},request:(t,n)=>h(i.getMessageBus(),t,n,Y),async fetch(t){let n=x(B(i),t.method.toUpperCase(),new URL(t.url).pathname);if(!n)return new Response("Not Found",{status:404});if(n.sharedHostAdmission==="deny")return new Response("Unauthorized",{status:401});return n.handler(t)},entities:C(i.getEntityService(),"restricted"),jobs:Object.freeze({async wait(t,n){let l=i.getJobQueueService(),d=async()=>{let c=await l.getStatus(n);if(!c||!Z.some((G)=>c.type===`${G}:${t.name}`))return null;if(re(c,Date.now()))return c;return await Bun.sleep(ee),d()},u=await d();return u?w(t,u):null}}),stop:()=>H??=Q()})}function Ee(e){return F(e,{brainVersion:U.version,directory:process.cwd()})}export{Ee as startTestBrain};
|
|
3
3
|
|
|
4
4
|
//# debugId=2715038A06CA0DA564756E2164756E21
|
|
5
5
|
//# sourceMappingURL=testing.js.map
|
|
@@ -246,6 +246,6 @@ ${u}`:`# ${l}`}}var ye=F(xe(),1),X2=15000,W2=2;function zd(e){return ye.jsxDEV("
|
|
|
246
246
|
|
|
247
247
|
[Open the Inbox item](${i.backlink})`;return{draft:s,body:i.body?`${i.body}
|
|
248
248
|
|
|
249
|
-
${l}`:l}}function cI(){let e=window.history.state;return Od(e)?e:{}}function Jz(e){let{api:i,queryClient:s,history:l,studioBasePath:a,routeTarget:u,routePathname:f,routeSearch:h,currentStudioPathname:p,createMode:g,entityType:y,collectionType:v,activeType:S,entityCollectionQuery:w,preferredMobilePane:A,dispatchEditor:C,setMobilePane:E,setBodyMode:M,setFieldAssistState:B}=e,P=S?.capabilities.canCreate===!0,q=S?.hierarchy.nested!==!1,[Q,V]=Li.useState(null),[ve,ue]=Li.useState(0),Oe=Li.useRef(null),U=Li.useRef(0),fe=Li.useRef(y);fe.current=y,Li.useEffect(()=>{if(u.kind==="grouping"){C({type:"collectionChanged"});return}if(!y||u.kind==="workspace"||u.kind==="not-found")return;let ie=u.kind==="entity"&&u.entityType===y?u.id:null,J=++U.current;C({type:"collectionChanged"}),E("details"),B({kind:"idle"});let ce=!0,Se=()=>ce&&J===U.current;return s.fetchQuery({...xy(i,y),staleTime:0}).then(async(Fe)=>{if(!ce||J!==U.current)return;let _e=Dz(Fe,A.current,g&&ie===null);if(E(_e),window.matchMedia("(max-width: 640px)").matches&&_e!=="details")M(_e==="write"?"source":"preview");if(g&&ie===null){if(!P){V(`Creating ${y} is not allowed.`);return}let mt=Kz(window.history.state,y,()=>window.history.replaceState(Fz(cI()),"",window.location.href)),et=Zz(Fe.fields,mt);C({type:"creationStarted",draft:et.draft,body:et.body,...Fe.isSingleton&&{singleton:!0},...mt&&{prefilled:!0},...!mt&&!Fe.isSingleton&&{prefix:q?Vc(h).prefix:null}});return}if(ie!==null)return s.fetchQuery({...Qc(i,y,ie),staleTime:0}).then((mt)=>{if(!ce||J!==U.current)return;let et=Pc(mt),ze=Oe.current,Ce=qn(a,y,ie),$t=ze?.pathname===Ce?ze.save:{kind:"idle"};if(ze?.pathname===Ce)Oe.current=null;C({type:"documentOpened",document:et,save:$t})});if(Fe.isSingleton){let mt=await s.ensureQueryData(ky(i,y,Vc("?scope=collection")));if(!Se())return;let et=mt.entities[0];if(et)return s.fetchQuery({...Qc(i,y,et.id),staleTime:0}).then((ze)=>{if(!ce||J!==U.current)return;let Ce=Pc(ze);C({type:"documentOpened",document:Ce})});C({type:"creationStarted",singleton:!0,draft:Ty(Fe.fields)})}return}).catch((Fe)=>{if(ce&&J===U.current)V(Hr(Fe))}),()=>{ce=!1}},[g,p,y,ve,s,f,h,u,P,q]);let Y=Li.useCallback((ie,J={kind:"idle"},ce=y)=>{if(!ce||!y)return;let Se=qn(a,ce,ie);if(!(ce===y&&u.kind==="entity"&&u.entityType===y&&u.id===ie)){Oe.current={pathname:Se,save:J};let et=`${gi(a,v??y)}${yi(w)}`,ze=g&&J.kind==="saved",Ce=l.location.state,$t=!ze||Od(Ce)&&Ce.studioCollectionPath===et;l[ze?"replace":"push"](`${Se}${yi(w)}`,$t?{studioCollectionPath:et}:void 0,J.kind==="saved"?{ignoreBlocker:!0}:void 0);return}let _e=++U.current,mt=y;s.fetchQuery({...Qc(i,y,ie),staleTime:0}).then((et)=>{if(_e!==U.current||fe.current!==mt)return;let ze=Pc(et);C({type:"documentOpened",document:ze,save:J}),B({kind:"idle"})}).catch((et)=>{if(_e===U.current)V(Hr(et))})},[a,p,u,g,y,v,w,s,l]),re=Li.useCallback(()=>{ue((ie)=>ie+1)},[]),rt=Li.useCallback(()=>{U.current+=1},[]),W=Li.useCallback(()=>U.current,[]);return{openEntity:Y,loadError:Q,setLoadError:V,retryOpen:re,supersedeOpen:rt,currentOpenRequest:W,pendingOpenState:Oe}}var Zo=F(yt(),1);function e3(e){let{api:i,queryClient:s,history:l,studioBasePath:a,entityType:u,collectionType:f,entityCollectionQuery:h,groupReturnPath:p,activeCapabilities:g,schema:y,editor:v,dispatchEditor:S,createPath:w,syncStatus:A,deleting:C,saveEntityMutation:E,deleteEntityMutation:M,openEntity:B,currentOpenRequest:P,setMobilePane:q,setFieldAssistState:Q}=e,{mode:V,draft:ve,body:ue,save:Oe}=v,[U,fe]=Zo.useState(null),Y=Zo.useRef(0);Zo.useEffect(()=>{if(Oe.kind!=="saved"||!A?.git)return;if(ng({save:Oe,git:A.git,baselineCommit:U}).committed==="done")return;if(Date.now()-Y.current>20000)return;let ce=window.setTimeout(()=>{s.invalidateQueries({queryKey:bn.syncStatus()})},900);return()=>window.clearTimeout(ce)},[Oe,A,U,s]);let re=Zo.useCallback((J,ce)=>{if(!u||V.kind!=="edit"||g?.canUpdate!==!0||g.canAssist!==!0||ue.trim().length===0)return;Q({kind:"loading",field:ce,variant:J}),i.requestFieldAssist({variant:J,entityType:u,id:V.entity.id,targetField:ce}).then((Se)=>{let Fe=Se.variant==="summarize"?Se.suggestion:Se.suggestions;Q({kind:"suggested",field:Se.targetField,variant:Se.variant,suggestion:Fe})}).catch((Se)=>{Q({kind:"error",field:ce,message:$n(Se)})})},[g,ue,u,V]),rt=Zo.useCallback((J,ce)=>{S({type:"fieldAssistApplied",field:J,suggestion:ce}),Q({kind:"idle"})},[]),W=Zo.useCallback(()=>{if(!u||V.kind==="browse"||!y||u===El&&!y.groupingDefinitions||Md(v)||(V.kind==="create"&&y.isSingleton||u===El)&&!Gm(v))return;if(V.kind==="create"?g?.canCreate!==!0:g?.canUpdate!==!0)return;Y.current=Date.now(),fe(A?.git?.lastCommit??null),S({type:"saveStarted"});let J=y.hasBody?{body:ue}:{},ce=wy(y.fields,ve),Se=V.kind==="create"?{kind:"create",entityType:u,...w&&{idPath:w},frontmatter:ce,...J}:{kind:"update",entityType:u,id:V.entity.id,frontmatter:ce,baseContentHash:V.entity.contentHash,...J},Fe=P();E.mutate(Se,{onSuccess:async(_e)=>{if(await Promise.all([s.invalidateQueries({queryKey:["studio","groupings"]}),s.invalidateQueries({queryKey:bn.entities(u)}),...f&&f!==u?[s.invalidateQueries({queryKey:bn.entities(f)})]:[],s.invalidateQueries({queryKey:bn.syncStatus()}),...u===El?[s.invalidateQueries({queryKey:["studio","schema"]})]:[],...V.kind==="create"||u===El?[s.invalidateQueries({queryKey:bn.navigation()})]:[]]),Fe!==P())return;let mt="skipped"in _e&&_e.skipped===!0;B(_e.entityId,{kind:"saved",noop:mt})},onError:(_e)=>{if(Fe!==P())return;if(_e instanceof qo&&(_e.status===400||_e.status===409))Promise.all([s.invalidateQueries({queryKey:bn.navigation()}),s.invalidateQueries({queryKey:["studio","schema"]}),s.invalidateQueries({queryKey:["studio","groupings"]})]);if(_e instanceof qo&&_e.issues.length>0)q("details");S({type:"saveFailed",save:_e instanceof qo&&_e.status===409&&V.kind==="edit"?{kind:"conflict",message:$n(_e),..._e.conflictId!==void 0&&{conflictId:_e.conflictId}}:{kind:"error",message:_e instanceof qo&&_e.issues.length>0?_e.message||"Validation failed":$n(_e),..._e instanceof qo?{issues:_e.issues}:{}}})}})},[g,u,f,V,w,v,ve,ue,y,B,A,s,E]),ie=Zo.useCallback(()=>{if(!u||V.kind!=="edit"||C||g?.canDelete!==!0)return;let{id:J}=V.entity;M.mutate({entityType:u,id:J},{onSuccess:async()=>{S({type:"deleteSucceeded"}),s.removeQueries({queryKey:bn.entity(u,J)}),await Promise.all([s.invalidateQueries({queryKey:["studio","groupings"]}),s.invalidateQueries({queryKey:bn.entityLists()}),s.invalidateQueries({queryKey:bn.syncStatus()}),s.invalidateQueries({queryKey:bn.navigation()})]),l.replace(p??`${gi(a,f??u)}${yi(h)}`,void 0,{ignoreBlocker:!0})},onError:(ce)=>{S({type:"deleteFailed",message:$n(ce)})}})},[g,a,u,f,V,C,s,M,l,p,h]);return{runFieldAssist:re,applyFieldAssist:rt,save:W,remove:ie,baselineCommit:U}}var wh=F(yt(),1);function i3(e){let{history:i,queryClient:s,studioBasePath:l,routeTarget:a,routePathname:u,routeSearch:f,entityType:h,activeWorkspaceId:p,types:g,groupings:y,workspaces:v,activeType:S,activeWorkspace:w,entityCollectionQuery:A,entityListOffset:C,entityListTotal:E,declarativeWorkspaceData:M,initialUrlWorkspaceQuery:B,setActiveWorkspaceId:P,setEntityType:q,setLoadError:Q,supersedeOpen:V}=e;wh.useEffect(()=>{if(!h||!S||p||a.kind!=="collection"&&a.kind!=="entity"||a.entityType!==h)return;if(E===void 0)return;let ve=Math.floor(Math.max(0,E-1)/A.limit)*A.limit;if(C>ve)i.replace(`${u}${yi({...A,offset:ve})}`,i.location.state)},[S,p,C,E,A,h,u,a,i]),wh.useEffect(()=>{if(!p||!M?.refreshAfterMs)return;let ve=window.setTimeout(()=>{s.invalidateQueries({queryKey:bn.workspace(p)})},M.refreshAfterMs);return()=>window.clearTimeout(ve)},[p,M,s]),wh.useEffect(()=>{if(w?.urlQuery!==!0||a.kind!=="workspace"||a.workspaceId!==w.id)return;let ve=mi(l,w.id);if(Qa(ve,B)!==`${ve}${f}`)Sy(i,ve,B,window.location.pathname)},[w,l,B,f,a,i]),wh.useEffect(()=>{if(!g)return;if(Q(null),a.kind==="not-found"){V(),Q(`Studio route not found: ${a.pathname}`);return}if(a.kind==="images"){V(),P(null),q(null);return}if(a.kind==="grouping"){if(V(),P(null),q(null),!y.some((U)=>U.key===a.grouping))Q("Collection unavailable for this account.");return}if(a.kind==="workspace"){let U=v.find((fe)=>fe.id===a.workspaceId);if(!U){let fe=t3(l,a.workspaceId,f,v);if(fe){i.replace(fe);return}V(),Q(`Workspace unavailable for this account: ${a.workspaceId}`);return}P(U.id),q(null);return}let ve=a.kind==="collection"||a.kind==="entity"?a.entityType:void 0,ue=g.find((U)=>!U.isSingleton)??g[0];if(a.kind==="home"){let U=n3(l,g,v);if(U!==l){i.replace(U);return}}let Oe=ve??ue?.entityType??null;if(ve!==void 0&&!g.some((U)=>U.entityType===ve)){V(),Q(`Collection unavailable for this account: ${ve}`);return}P(null),q(Oe)},[f,a,i,l,g,y,v])}var Ex=F(yt(),1);function s3(e){let{queryClient:i,workspaces:s,activeWorkspaceId:l,entityType:a,mode:u,declarativeWorkspaceActionMutation:f,openEntity:h}=e,p=Ex.useCallback(async(y)=>{let v=o3(s,y.entityType);if(!v)throw Error("Publishing is unavailable");let S={entityType:y.entityType,entityId:y.entityId,...y.type==="reorder"?{position:y.position}:{}};if(y.type==="publish"&&!y.confirmation){let C=await f.mutateAsync({workspaceId:v.id,action:{actionId:"publish",label:"Publish now",input:S,invocation:{mode:"prepare"}}});if(typeof C!=="object"||C===null||!("kind"in C)||C.kind!=="prepared-confirmation"||!("token"in C)||typeof C.token!=="string"||!("summary"in C)||typeof C.summary!=="string"||!("expiresAt"in C)||typeof C.expiresAt!=="string")throw Error("Publishing confirmation is unavailable");return{needsConfirmation:!0,summary:C.summary,args:{confirmed:!0,confirmationToken:C.token,contentHash:C.token,expiresAt:C.expiresAt}}}let w=await f.mutateAsync({workspaceId:v.id,action:{actionId:y.type,label:y.type,input:S,...y.type==="publish"&&y.confirmation?{invocation:{mode:"execute",token:y.confirmation.confirmationToken}}:{}}});if(typeof w!=="object"||w===null)throw Error("Publishing returned an invalid result");let A="success"in w&&w.success===!1?{success:!1,error:"error"in w&&typeof w.error==="string"?w.error:"Publishing failed",..."code"in w&&typeof w.code==="string"?{code:w.code}:{}}:{success:!0};if(!cx(A)&&!fx(A)){if(await Tx(i,v.id),u.kind==="edit"&&a===y.entityType&&u.entity.id===y.entityId)h(y.entityId)}return A},[a,u,h,i,f,s]),g=Ex.useCallback(async(y)=>{if(!l)throw Error("Declarative workspace is unavailable");try{let v=await f.mutateAsync({workspaceId:l,action:y});return await Tx(i,l),v}finally{f.reset()}},[l,f,i]);return{performPublishingAction:p,performDeclarativeAction:g}}var Qt=F(xe(),1),fI=pt.lazy(()=>vS(async()=>({default:(await import("./studio-chunks/account-view-kkfs676e.js")).AccountApp}))),dI=pt.lazy(()=>vS(async()=>({default:(await import("./studio-chunks/studio-chat-workspace-3gbjq8vn.js")).StudioChatWorkspace}),()=>Qt.jsxDEV(Ga,{message:"Chat could not open.",children:Qt.jsxDEV(bS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)));function hI(e){let i=new URLSearchParams(e).get("session")?.trim();return i&&i.length<=256?i:null}var pI=["public","trusted","admin"];function mI(e,i,s){let l=document.querySelector("[data-studio-root]"),a=l?.getAttribute("data-studio-principal-name")??"Your account",u=l?.getAttribute("data-studio-principal-role"),f=pI.find((v)=>v===u)??"public",h=l?.getAttribute("data-studio-mcp-url")??void 0,p=l?.getAttribute("data-studio-dav-url")??void 0,g=new URLSearchParams(s).get("section")??void 0,y=a3(s);return{displayName:a,role:f,routePath:e,studioPath:i,...h?{mcpUrl:h}:{},...p?{davUrl:p}:{},...g?{initialSection:g}:{},...y?{connect:y}:{}}}function h3(){let e=l3(),i=Ey({select:(qe)=>qe.location.pathname}),s=Ey({select:(qe)=>qe.location.searchStr}),l=Ey({select:(qe)=>qe.location.state}),a=Rs(),u=pt.useMemo(()=>i===pc?{kind:"workspace",workspaceId:Ay}:Fm(i,a),[i,a]),f=pt.useMemo(()=>u.kind==="collection"&&new URLSearchParams(s).get("mode")==="create",[s,u]),h=i,[p,g]=pt.useState(null),[y,v]=pt.useState(null),[S,w]=pt.useState({}),[A,C]=pt.useReducer(c2,Rd),{mode:E}=A,M=Gm(A),[B]=pt.useState(()=>new f3),P=pt.useSyncExternalStore(B.subscribe,B.hasDrafts,B.hasDrafts),[q,Q]=pt.useState({hasDraft:!1,busy:!1}),V=r3({shouldBlockFn:({next:qe})=>M||i===pc&&c3({...q,hasDraft:P},qe.pathname),enableBeforeUnload:M||P||q.busy,withResolver:!0}),[ve,ue]=pt.useState({kind:"idle"}),[Oe,U]=pt.useState("source"),fe=A.mode.kind==="create";pt.useEffect(()=>{if(fe)U("source")},[fe]);let[Y,re]=pt.useState("details"),rt=pt.useRef(null),W=pt.useCallback((qe)=>{rt.current=qe,re(qe)},[]),ie=dc(),J=Jt(),{navigationQuery:ce,types:Se,groupings:Fe,activeType:_e,collectionType:mt,activeCapabilities:et,entityCollectionQuery:ze,entityListOffset:Ce,workspaces:$t,activeWorkspace:zi,activeAccount:to,activeChat:Rl,initialUrlWorkspaceQuery:Wc,workspaceRequestQuery:oe,workspaceQuery:Hn,workspaceData:Wa,workspaceError:Ir,agentTargets:Ur,syncStatus:gt,entityListQuery:Ao,entities:Ya,entityListTotal:Ch,schema:ut,createPath:My,destinationQuery:To,saveEntityMutation:Xa,deleteEntityMutation:_r,declarativeWorkspaceActionMutation:Oy,deleting:Fa,declarativeWorkspaceData:Ka}=Gz({api:J,entityType:y,activeWorkspaceId:p,routeSearch:s,workspaceQueries:S,editor:A}),Ml=$t.find((qe)=>qe.rendererName===Gc),Ah=I2({entityType:y,entities:Ya}),Yc=p2({principalId:document.querySelector("[data-studio-root]")?.getAttribute("data-studio-principal-id")??null,entityType:y,editor:A,hasUnsavedChanges:M,fields:ut?.fields??[],dispatch:C}),qs=u.kind==="grouping"?Fe.find((qe)=>qe.key===u.grouping):void 0,qr=pt.useMemo(()=>pS(s),[s]),$r=u.kind==="entity"?S2(l,a,Fe):null,Xc=$r?.path,Th=pt.useMemo(()=>y?Fe.filter((qe)=>qe.types.includes(y)):[],[Fe,y]),Fc=zz(Th),{openEntity:Za,loadError:Eh,setLoadError:Ja,retryOpen:Ol,supersedeOpen:Jo,currentOpenRequest:Pr,pendingOpenState:$s}=Jz({api:J,queryClient:ie,history:e.history,studioBasePath:a,routeTarget:u,routePathname:i,routeSearch:s,currentStudioPathname:h,createMode:f,entityType:y,collectionType:mt,activeType:_e,entityCollectionQuery:ze,preferredMobilePane:rt,dispatchEditor:C,setMobilePane:re,setBodyMode:U,setFieldAssistState:ue});i3({history:e.history,queryClient:ie,studioBasePath:a,routeTarget:u,routePathname:i,routeSearch:s,entityType:y,activeWorkspaceId:p,types:Se,groupings:Fe,workspaces:$t,activeType:_e,activeWorkspace:zi,entityCollectionQuery:ze,entityListOffset:Ce,entityListTotal:Ch,declarativeWorkspaceData:Ka,initialUrlWorkspaceQuery:Wc,setActiveWorkspaceId:g,setEntityType:v,setLoadError:Ja,supersedeOpen:Jo});let{openWorkspaceEntity:sn,openWorkspaceLaunch:Ps,selectEntityType:es,changeEntityPage:Ll,selectWorkspace:jr,selectFolder:Dh,startCreate:eu,backToList:tu,changeWorkspaceQuery:Eo}=Xz({history:e.history,studioBasePath:a,routeSearch:s,entityType:y,collectionType:mt,entityCollectionQuery:ze,groupReturnPath:Xc,workspaces:$t,schema:ut,activeCapabilities:et,pendingOpenState:$s,setFieldAssistState:ue,setWorkspaceQueries:w}),{runFieldAssist:bi,applyFieldAssist:Rh,save:Ly,remove:Kc,baselineCommit:Mh}=e3({api:J,queryClient:ie,history:e.history,studioBasePath:a,entityType:y,collectionType:mt,entityCollectionQuery:ze,groupReturnPath:Xc,activeCapabilities:et,schema:ut,editor:A,dispatchEditor:C,createPath:My,syncStatus:gt,deleting:Fa,saveEntityMutation:Xa,deleteEntityMutation:_r,openEntity:Za,currentOpenRequest:Pr,setMobilePane:re,setFieldAssistState:ue}),{performPublishingAction:nu,performDeclarativeAction:vi}=s3({queryClient:ie,workspaces:$t,activeWorkspaceId:p,entityType:y,mode:E,declarativeWorkspaceActionMutation:Oy,openEntity:Za}),Do=Eh??(ce.error?Hr(ce.error):Ao.error?Hr(Ao.error):null),iu=()=>{if(Ja(null),ce.error)ce.refetch();if(Ao.error)Ao.refetch();if(Hn.error)Hn.refetch();if(E.kind==="browse")Ol()};if(Do&&!Se)return Qt.jsxDEV(Ga,{message:Do,error:!0,onRetry:iu},void 0,!1,void 0,this);if(!Se)return Qt.jsxDEV(Ga,{message:"Loading…"},void 0,!1,void 0,this);if(to&&zi){let qe=mi(a,Cy);return Qt.jsxDEV(Rz,{types:Se,workspaces:$t,workspaceId:zi.id,selectEntityType:es,selectWorkspace:jr,children:Qt.jsxDEV(pt.Suspense,{fallback:Qt.jsxDEV(he,{children:"Opening Account…"},void 0,!1,void 0,this),children:Qt.jsxDEV(fI,{bootstrap:mI(qe,a,s)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}if(Rl&&zi)return Qt.jsxDEV(Qt.Fragment,{children:[Qt.jsxDEV(pt.Suspense,{fallback:Qt.jsxDEV(Ga,{message:"Opening Chat…"},void 0,!1,void 0,this),children:Qt.jsxDEV(dI,{apiPath:zi.chatApiPath,draftStore:B,onNavigationStateChange:Q,studioBasePath:a,sessionId:hI(s),types:Se,workspaces:$t,handoff:Lz(l),navigate:(qe,Ni)=>{e.history.push(qe,void 0,{ignoreBlocker:Ni?.preserveWork===!0})},selectEntityType:es,selectWorkspace:jr},void 0,!1,void 0,this)},void 0,!1,void 0,this),V.status==="blocked"&&Qt.jsxDEV(vn,{mark:"↩",title:"Leave this conversation?",titleId:"chat-navigation-title",cancelLabel:"Stay",confirmLabel:"Leave",onCancel:()=>V.reset(),onConfirm:()=>V.proceed(),children:Qt.jsxDEV("p",{children:"Your draft stays in this tab. Leaving stops receiving the response, but does not undo completed actions or background jobs."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(p?p!==kh&&!Wa&&!Ir:y&&!ut&&!Do)return Qt.jsxDEV(Ga,{message:"Loading…"},void 0,!1,void 0,this);if(!qs&&u.kind!=="images"&&!p&&(!y||!ut&&!Do))return Qt.jsxDEV(Ga,{message:Do??"No readable collections are available for this account.",error:Boolean(Do),...Do?{onHome:()=>e.history.push(a)}:{}},void 0,!1,void 0,this);return Qt.jsxDEV(Mz,{groupings:{items:Fe,active:qs?.key??$r?.grouping??null,onSelect:(qe)=>e.history.push(fc(a,qe))},images:{active:u.kind==="images",onSelect:()=>e.history.push(u3(a))},imagesView:u.kind==="images"?Qt.jsxDEV(R2,{onOpen:(qe,Ni)=>e.history.push(qn(a,qe,Ni))},void 0,!1,void 0,this):null,homeView:p===kh?Qt.jsxDEV(F2,{chatApiPath:Ml?.chatApiPath,onNavigate:(qe)=>e.history.push(qe),onAsk:(qe)=>{B.update(d3(Ml?.chatApiPath,null),{text:qe}),e.history.push(pc)}},void 0,!1,void 0,this):null,groupReturnLabel:$r?.label,groupingSuggestions:Fc,groupingView:qs?Qt.jsxDEV(A2,{basePath:a,grouping:qs,types:Se,query:qr,onChange:(qe,Ni)=>{let Vr=`${fc(a,qs.key)}${cc(qe)}`,Oh=qe.value!==qr.value||qe.offset!==qr.offset;e.history[Oh&&Ni?.replace!==!0?"push":"replace"](Vr)},onOpen:(qe,Ni)=>{let Vr=qn(a,qe,Ni);$s.current={pathname:Vr,save:{kind:"idle"}},e.history.push(Vr,{studioGroupingPath:`${fc(a,qs.key)}${cc(qr)}`})}},void 0,!1,void 0,this):null,activeWorkspaceId:p,types:Se,workspaces:$t,workspaceError:Ir,readError:Do,onRetryRead:iu,declarativeWorkspaceData:Ka,workspaceQuery:oe,entityType:y,entities:Ya,refineNotice:Ah.notice,onRefineConfirmed:Ah.confirmed,folders:Ao.data?.folders??[],collectionTrail:Ao.data?.trail,collectionPath:mt?gi(a,mt):a,selectFolder:Dh,creationDestination:{data:To.data??null,pending:To.isPending,error:To.error},entityOffset:Ce,entityLimit:ze.limit,entityTotal:Ch??0,collectionQuery:ze,onCollectionQueryChange:(qe)=>{if(!mt)return;e.history.push(`${gi(a,mt)}${yi({...qe,offset:0})}`),window.scrollTo({top:0,left:0})},entityListLoading:Ao.isPending,schema:ut,editor:A,fieldAssistState:ve,bodyMode:Oe,mobilePane:Y,syncStatus:gt,baselineCommit:Mh,agentTargets:Ur,deleting:Fa,hasUnsavedChanges:M,navigationBlocked:V.status==="blocked",dispatchEditor:C,setFieldAssistState:ue,setBodyMode:U,setMobilePane:W,backToList:tu,selectEntityType:es,selectWorkspace:jr,changeEntityPage:Ll,openWorkspaceEntity:sn,openWorkspaceLaunch:Ps,performPublishingAction:nu,performDeclarativeAction:vi,onWorkspaceQueryChange:Eo,startCreate:eu,openEntity:(qe,Ni)=>Za(qe,void 0,Ni),runFieldAssist:bi,applyFieldAssist:Rh,save:Ly,remove:Kc,onNavigationReset:()=>V.reset?.(),draftRecovery:Yc,onNavigationProceed:()=>{Yc.forget(),V.proceed?.()}},void 0,!1,void 0,this)}function m3(){return new p3({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1},mutations:{retry:!1}}})}var Ry=F(xe(),1),Dy=document.querySelector("[data-studio-root]");if(Dy){let e=Dy.getAttribute("data-studio-base-path")??"/studio",i=new v3({basePath:e});Dy.textContent="";let s=m3(),l=b3(e,h3);x3.createRoot(Dy).render(Ry.jsxDEV(g3,{client:s,children:Ry.jsxDEV(S3,{api:i,children:Ry.jsxDEV(y3,{router:l},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this))}
|
|
249
|
+
${l}`:l}}function cI(){let e=window.history.state;return Od(e)?e:{}}function Jz(e){let{api:i,queryClient:s,history:l,studioBasePath:a,routeTarget:u,routePathname:f,routeSearch:h,currentStudioPathname:p,createMode:g,entityType:y,collectionType:v,activeType:S,entityCollectionQuery:w,preferredMobilePane:A,dispatchEditor:C,setMobilePane:E,setBodyMode:M,setFieldAssistState:B}=e,P=S?.capabilities.canCreate===!0,q=S?.hierarchy.nested!==!1,[Q,V]=Li.useState(null),[ve,ue]=Li.useState(0),Oe=Li.useRef(null),U=Li.useRef(0),fe=Li.useRef(y);fe.current=y,Li.useEffect(()=>{if(u.kind==="grouping"){C({type:"collectionChanged"});return}if(!y||u.kind==="workspace"||u.kind==="not-found")return;let ie=u.kind==="entity"&&u.entityType===y?u.id:null,J=++U.current;C({type:"collectionChanged"}),E("details"),B({kind:"idle"});let ce=!0,Se=()=>ce&&J===U.current;return s.fetchQuery({...xy(i,y),staleTime:0}).then(async(Fe)=>{if(!ce||J!==U.current)return;let _e=Dz(Fe,A.current,g&&ie===null);if(E(_e),window.matchMedia("(max-width: 640px)").matches&&_e!=="details")M(_e==="write"?"source":"preview");if(g&&ie===null){if(!P){V(`Creating ${y} is not allowed.`);return}let mt=Kz(window.history.state,y,()=>window.history.replaceState(Fz(cI()),"",window.location.href)),et=Zz(Fe.fields,mt);C({type:"creationStarted",draft:et.draft,body:et.body,...Fe.isSingleton&&{singleton:!0},...mt&&{prefilled:!0},...!mt&&!Fe.isSingleton&&{prefix:q?Vc(h).prefix:null}});return}if(ie!==null)return s.fetchQuery({...Qc(i,y,ie),staleTime:0}).then((mt)=>{if(!ce||J!==U.current)return;let et=Pc(mt),ze=Oe.current,Ce=qn(a,y,ie),$t=ze?.pathname===Ce?ze.save:{kind:"idle"};if(ze?.pathname===Ce)Oe.current=null;C({type:"documentOpened",document:et,save:$t})});if(Fe.isSingleton){let mt=await s.ensureQueryData(ky(i,y,Vc("?scope=collection")));if(!Se())return;let et=mt.entities[0];if(et)return s.fetchQuery({...Qc(i,y,et.id),staleTime:0}).then((ze)=>{if(!ce||J!==U.current)return;let Ce=Pc(ze);C({type:"documentOpened",document:Ce})});C({type:"creationStarted",singleton:!0,draft:Ty(Fe.fields)})}return}).catch((Fe)=>{if(ce&&J===U.current)V(Hr(Fe))}),()=>{ce=!1}},[g,p,y,ve,s,f,h,u,P,q]);let Y=Li.useCallback((ie,J={kind:"idle"},ce=y)=>{if(!ce||!y)return;let Se=qn(a,ce,ie);if(!(ce===y&&u.kind==="entity"&&u.entityType===y&&u.id===ie)){Oe.current={pathname:Se,save:J};let et=`${gi(a,v??y)}${yi(w)}`,ze=g&&J.kind==="saved",Ce=l.location.state,$t=!ze||Od(Ce)&&Ce.studioCollectionPath===et;l[ze?"replace":"push"](`${Se}${yi(w)}`,$t?{studioCollectionPath:et}:void 0,J.kind==="saved"?{ignoreBlocker:!0}:void 0);return}let _e=++U.current,mt=y;s.fetchQuery({...Qc(i,y,ie),staleTime:0}).then((et)=>{if(_e!==U.current||fe.current!==mt)return;let ze=Pc(et);C({type:"documentOpened",document:ze,save:J}),B({kind:"idle"})}).catch((et)=>{if(_e===U.current)V(Hr(et))})},[a,p,u,g,y,v,w,s,l]),re=Li.useCallback(()=>{ue((ie)=>ie+1)},[]),rt=Li.useCallback(()=>{U.current+=1},[]),W=Li.useCallback(()=>U.current,[]);return{openEntity:Y,loadError:Q,setLoadError:V,retryOpen:re,supersedeOpen:rt,currentOpenRequest:W,pendingOpenState:Oe}}var Zo=F(yt(),1);function e3(e){let{api:i,queryClient:s,history:l,studioBasePath:a,entityType:u,collectionType:f,entityCollectionQuery:h,groupReturnPath:p,activeCapabilities:g,schema:y,editor:v,dispatchEditor:S,createPath:w,syncStatus:A,deleting:C,saveEntityMutation:E,deleteEntityMutation:M,openEntity:B,currentOpenRequest:P,setMobilePane:q,setFieldAssistState:Q}=e,{mode:V,draft:ve,body:ue,save:Oe}=v,[U,fe]=Zo.useState(null),Y=Zo.useRef(0);Zo.useEffect(()=>{if(Oe.kind!=="saved"||!A?.git)return;if(ng({save:Oe,git:A.git,baselineCommit:U}).committed==="done")return;if(Date.now()-Y.current>20000)return;let ce=window.setTimeout(()=>{s.invalidateQueries({queryKey:bn.syncStatus()})},900);return()=>window.clearTimeout(ce)},[Oe,A,U,s]);let re=Zo.useCallback((J,ce)=>{if(!u||V.kind!=="edit"||g?.canUpdate!==!0||g.canAssist!==!0||ue.trim().length===0)return;Q({kind:"loading",field:ce,variant:J}),i.requestFieldAssist({variant:J,entityType:u,id:V.entity.id,targetField:ce}).then((Se)=>{let Fe=Se.variant==="summarize"?Se.suggestion:Se.suggestions;Q({kind:"suggested",field:Se.targetField,variant:Se.variant,suggestion:Fe})}).catch((Se)=>{Q({kind:"error",field:ce,message:$n(Se)})})},[g,ue,u,V]),rt=Zo.useCallback((J,ce)=>{S({type:"fieldAssistApplied",field:J,suggestion:ce}),Q({kind:"idle"})},[]),W=Zo.useCallback(()=>{if(!u||V.kind==="browse"||!y||u===El&&!y.groupingDefinitions||Md(v)||(V.kind==="create"&&y.isSingleton||u===El)&&!Gm(v))return;if(V.kind==="create"?g?.canCreate!==!0:g?.canUpdate!==!0)return;Y.current=Date.now(),fe(A?.git?.lastCommit??null),S({type:"saveStarted"});let J=y.hasBody?{body:ue}:{},ce=wy(y.fields,ve),Se=V.kind==="create"?{kind:"create",entityType:u,...w&&{idPath:w},frontmatter:ce,...J}:{kind:"update",entityType:u,id:V.entity.id,frontmatter:ce,baseContentHash:V.entity.contentHash,...J},Fe=P();E.mutate(Se,{onSuccess:async(_e)=>{if(await Promise.all([s.invalidateQueries({queryKey:["studio","groupings"]}),s.invalidateQueries({queryKey:bn.entities(u)}),...f&&f!==u?[s.invalidateQueries({queryKey:bn.entities(f)})]:[],s.invalidateQueries({queryKey:bn.syncStatus()}),...u===El?[s.invalidateQueries({queryKey:["studio","schema"]})]:[],...V.kind==="create"||u===El?[s.invalidateQueries({queryKey:bn.navigation()})]:[]]),Fe!==P())return;let mt="skipped"in _e&&_e.skipped===!0;B(_e.entityId,{kind:"saved",noop:mt})},onError:(_e)=>{if(Fe!==P())return;if(_e instanceof qo&&(_e.status===400||_e.status===409))Promise.all([s.invalidateQueries({queryKey:bn.navigation()}),s.invalidateQueries({queryKey:["studio","schema"]}),s.invalidateQueries({queryKey:["studio","groupings"]})]);if(_e instanceof qo&&_e.issues.length>0)q("details");S({type:"saveFailed",save:_e instanceof qo&&_e.status===409&&V.kind==="edit"?{kind:"conflict",message:$n(_e),..._e.conflictId!==void 0&&{conflictId:_e.conflictId}}:{kind:"error",message:_e instanceof qo&&_e.issues.length>0?_e.message||"Validation failed":$n(_e),..._e instanceof qo?{issues:_e.issues}:{}}})}})},[g,u,f,V,w,v,ve,ue,y,B,A,s,E]),ie=Zo.useCallback(()=>{if(!u||V.kind!=="edit"||C||g?.canDelete!==!0)return;let{id:J}=V.entity;M.mutate({entityType:u,id:J},{onSuccess:async()=>{S({type:"deleteSucceeded"}),s.removeQueries({queryKey:bn.entity(u,J)}),await Promise.all([s.invalidateQueries({queryKey:["studio","groupings"]}),s.invalidateQueries({queryKey:bn.entityLists()}),s.invalidateQueries({queryKey:bn.syncStatus()}),s.invalidateQueries({queryKey:bn.navigation()})]),l.replace(p??`${gi(a,f??u)}${yi(h)}`,void 0,{ignoreBlocker:!0})},onError:(ce)=>{S({type:"deleteFailed",message:$n(ce)})}})},[g,a,u,f,V,C,s,M,l,p,h]);return{runFieldAssist:re,applyFieldAssist:rt,save:W,remove:ie,baselineCommit:U}}var wh=F(yt(),1);function i3(e){let{history:i,queryClient:s,studioBasePath:l,routeTarget:a,routePathname:u,routeSearch:f,entityType:h,activeWorkspaceId:p,types:g,groupings:y,workspaces:v,activeType:S,activeWorkspace:w,entityCollectionQuery:A,entityListOffset:C,entityListTotal:E,declarativeWorkspaceData:M,initialUrlWorkspaceQuery:B,setActiveWorkspaceId:P,setEntityType:q,setLoadError:Q,supersedeOpen:V}=e;wh.useEffect(()=>{if(!h||!S||p||a.kind!=="collection"&&a.kind!=="entity"||a.entityType!==h)return;if(E===void 0)return;let ve=Math.floor(Math.max(0,E-1)/A.limit)*A.limit;if(C>ve)i.replace(`${u}${yi({...A,offset:ve})}`,i.location.state)},[S,p,C,E,A,h,u,a,i]),wh.useEffect(()=>{if(!p||!M?.refreshAfterMs)return;let ve=window.setTimeout(()=>{s.invalidateQueries({queryKey:bn.workspace(p)})},M.refreshAfterMs);return()=>window.clearTimeout(ve)},[p,M,s]),wh.useEffect(()=>{if(w?.urlQuery!==!0||a.kind!=="workspace"||a.workspaceId!==w.id)return;let ve=mi(l,w.id);if(Qa(ve,B)!==`${ve}${f}`)Sy(i,ve,B,window.location.pathname)},[w,l,B,f,a,i]),wh.useEffect(()=>{if(!g)return;if(Q(null),a.kind==="not-found"){V(),Q(`Studio route not found: ${a.pathname}`);return}if(a.kind==="images"){V(),P(null),q(null);return}if(a.kind==="grouping"){if(V(),P(null),q(null),!y.some((U)=>U.key===a.grouping))Q("Collection unavailable for this account.");return}if(a.kind==="workspace"){let U=v.find((fe)=>fe.id===a.workspaceId);if(!U){let fe=t3(l,a.workspaceId,f,v);if(fe){i.replace(fe);return}V(),Q(`Workspace unavailable for this account: ${a.workspaceId}`);return}P(U.id),q(null);return}let ve=a.kind==="collection"||a.kind==="entity"?a.entityType:void 0,ue=g.find((U)=>!U.isSingleton)??g[0];if(a.kind==="home"){let U=n3(l,g,v);if(U!==l){i.replace(U);return}}let Oe=ve??ue?.entityType??null;if(ve!==void 0&&!g.some((U)=>U.entityType===ve)){V(),Q(`Collection unavailable for this account: ${ve}`);return}P(null),q(Oe)},[f,a,i,l,g,y,v])}var Ex=F(yt(),1);function s3(e){let{queryClient:i,workspaces:s,activeWorkspaceId:l,entityType:a,mode:u,declarativeWorkspaceActionMutation:f,openEntity:h}=e,p=Ex.useCallback(async(y)=>{let v=o3(s,y.entityType);if(!v)throw Error("Publishing is unavailable");let S={entityType:y.entityType,entityId:y.entityId,...y.type==="reorder"?{position:y.position}:{}};if(y.type==="publish"&&!y.confirmation){let C=await f.mutateAsync({workspaceId:v.id,action:{actionId:"publish",label:"Publish now",input:S,invocation:{mode:"prepare"}}});if(typeof C!=="object"||C===null||!("kind"in C)||C.kind!=="prepared-confirmation"||!("token"in C)||typeof C.token!=="string"||!("summary"in C)||typeof C.summary!=="string"||!("expiresAt"in C)||typeof C.expiresAt!=="string")throw Error("Publishing confirmation is unavailable");return{needsConfirmation:!0,summary:C.summary,args:{confirmed:!0,confirmationToken:C.token,contentHash:C.token,expiresAt:C.expiresAt}}}let w=await f.mutateAsync({workspaceId:v.id,action:{actionId:y.type,label:y.type,input:S,...y.type==="publish"&&y.confirmation?{invocation:{mode:"execute",token:y.confirmation.confirmationToken}}:{}}});if(typeof w!=="object"||w===null)throw Error("Publishing returned an invalid result");let A="success"in w&&w.success===!1?{success:!1,error:"error"in w&&typeof w.error==="string"?w.error:"Publishing failed",..."code"in w&&typeof w.code==="string"?{code:w.code}:{}}:{success:!0};if(!cx(A)&&!fx(A)){if(await Tx(i,v.id),u.kind==="edit"&&a===y.entityType&&u.entity.id===y.entityId)h(y.entityId)}return A},[a,u,h,i,f,s]),g=Ex.useCallback(async(y)=>{if(!l)throw Error("Declarative workspace is unavailable");try{let v=await f.mutateAsync({workspaceId:l,action:y});return await Tx(i,l),v}finally{f.reset()}},[l,f,i]);return{performPublishingAction:p,performDeclarativeAction:g}}var Qt=F(xe(),1),fI=pt.lazy(()=>vS(async()=>({default:(await import("./studio-chunks/account-view-kkfs676e.js")).AccountApp}))),dI=pt.lazy(()=>vS(async()=>({default:(await import("./studio-chunks/studio-chat-workspace-wy37fxat.js")).StudioChatWorkspace}),()=>Qt.jsxDEV(Ga,{message:"Chat could not open.",children:Qt.jsxDEV(bS,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)));function hI(e){let i=new URLSearchParams(e).get("session")?.trim();return i&&i.length<=256?i:null}var pI=["public","trusted","admin"];function mI(e,i,s){let l=document.querySelector("[data-studio-root]"),a=l?.getAttribute("data-studio-principal-name")??"Your account",u=l?.getAttribute("data-studio-principal-role"),f=pI.find((v)=>v===u)??"public",h=l?.getAttribute("data-studio-mcp-url")??void 0,p=l?.getAttribute("data-studio-dav-url")??void 0,g=new URLSearchParams(s).get("section")??void 0,y=a3(s);return{displayName:a,role:f,routePath:e,studioPath:i,...h?{mcpUrl:h}:{},...p?{davUrl:p}:{},...g?{initialSection:g}:{},...y?{connect:y}:{}}}function h3(){let e=l3(),i=Ey({select:(qe)=>qe.location.pathname}),s=Ey({select:(qe)=>qe.location.searchStr}),l=Ey({select:(qe)=>qe.location.state}),a=Rs(),u=pt.useMemo(()=>i===pc?{kind:"workspace",workspaceId:Ay}:Fm(i,a),[i,a]),f=pt.useMemo(()=>u.kind==="collection"&&new URLSearchParams(s).get("mode")==="create",[s,u]),h=i,[p,g]=pt.useState(null),[y,v]=pt.useState(null),[S,w]=pt.useState({}),[A,C]=pt.useReducer(c2,Rd),{mode:E}=A,M=Gm(A),[B]=pt.useState(()=>new f3),P=pt.useSyncExternalStore(B.subscribe,B.hasDrafts,B.hasDrafts),[q,Q]=pt.useState({hasDraft:!1,busy:!1}),V=r3({shouldBlockFn:({next:qe})=>M||i===pc&&c3({...q,hasDraft:P},qe.pathname),enableBeforeUnload:M||P||q.busy,withResolver:!0}),[ve,ue]=pt.useState({kind:"idle"}),[Oe,U]=pt.useState("source"),fe=A.mode.kind==="create";pt.useEffect(()=>{if(fe)U("source")},[fe]);let[Y,re]=pt.useState("details"),rt=pt.useRef(null),W=pt.useCallback((qe)=>{rt.current=qe,re(qe)},[]),ie=dc(),J=Jt(),{navigationQuery:ce,types:Se,groupings:Fe,activeType:_e,collectionType:mt,activeCapabilities:et,entityCollectionQuery:ze,entityListOffset:Ce,workspaces:$t,activeWorkspace:zi,activeAccount:to,activeChat:Rl,initialUrlWorkspaceQuery:Wc,workspaceRequestQuery:oe,workspaceQuery:Hn,workspaceData:Wa,workspaceError:Ir,agentTargets:Ur,syncStatus:gt,entityListQuery:Ao,entities:Ya,entityListTotal:Ch,schema:ut,createPath:My,destinationQuery:To,saveEntityMutation:Xa,deleteEntityMutation:_r,declarativeWorkspaceActionMutation:Oy,deleting:Fa,declarativeWorkspaceData:Ka}=Gz({api:J,entityType:y,activeWorkspaceId:p,routeSearch:s,workspaceQueries:S,editor:A}),Ml=$t.find((qe)=>qe.rendererName===Gc),Ah=I2({entityType:y,entities:Ya}),Yc=p2({principalId:document.querySelector("[data-studio-root]")?.getAttribute("data-studio-principal-id")??null,entityType:y,editor:A,hasUnsavedChanges:M,fields:ut?.fields??[],dispatch:C}),qs=u.kind==="grouping"?Fe.find((qe)=>qe.key===u.grouping):void 0,qr=pt.useMemo(()=>pS(s),[s]),$r=u.kind==="entity"?S2(l,a,Fe):null,Xc=$r?.path,Th=pt.useMemo(()=>y?Fe.filter((qe)=>qe.types.includes(y)):[],[Fe,y]),Fc=zz(Th),{openEntity:Za,loadError:Eh,setLoadError:Ja,retryOpen:Ol,supersedeOpen:Jo,currentOpenRequest:Pr,pendingOpenState:$s}=Jz({api:J,queryClient:ie,history:e.history,studioBasePath:a,routeTarget:u,routePathname:i,routeSearch:s,currentStudioPathname:h,createMode:f,entityType:y,collectionType:mt,activeType:_e,entityCollectionQuery:ze,preferredMobilePane:rt,dispatchEditor:C,setMobilePane:re,setBodyMode:U,setFieldAssistState:ue});i3({history:e.history,queryClient:ie,studioBasePath:a,routeTarget:u,routePathname:i,routeSearch:s,entityType:y,activeWorkspaceId:p,types:Se,groupings:Fe,workspaces:$t,activeType:_e,activeWorkspace:zi,entityCollectionQuery:ze,entityListOffset:Ce,entityListTotal:Ch,declarativeWorkspaceData:Ka,initialUrlWorkspaceQuery:Wc,setActiveWorkspaceId:g,setEntityType:v,setLoadError:Ja,supersedeOpen:Jo});let{openWorkspaceEntity:sn,openWorkspaceLaunch:Ps,selectEntityType:es,changeEntityPage:Ll,selectWorkspace:jr,selectFolder:Dh,startCreate:eu,backToList:tu,changeWorkspaceQuery:Eo}=Xz({history:e.history,studioBasePath:a,routeSearch:s,entityType:y,collectionType:mt,entityCollectionQuery:ze,groupReturnPath:Xc,workspaces:$t,schema:ut,activeCapabilities:et,pendingOpenState:$s,setFieldAssistState:ue,setWorkspaceQueries:w}),{runFieldAssist:bi,applyFieldAssist:Rh,save:Ly,remove:Kc,baselineCommit:Mh}=e3({api:J,queryClient:ie,history:e.history,studioBasePath:a,entityType:y,collectionType:mt,entityCollectionQuery:ze,groupReturnPath:Xc,activeCapabilities:et,schema:ut,editor:A,dispatchEditor:C,createPath:My,syncStatus:gt,deleting:Fa,saveEntityMutation:Xa,deleteEntityMutation:_r,openEntity:Za,currentOpenRequest:Pr,setMobilePane:re,setFieldAssistState:ue}),{performPublishingAction:nu,performDeclarativeAction:vi}=s3({queryClient:ie,workspaces:$t,activeWorkspaceId:p,entityType:y,mode:E,declarativeWorkspaceActionMutation:Oy,openEntity:Za}),Do=Eh??(ce.error?Hr(ce.error):Ao.error?Hr(Ao.error):null),iu=()=>{if(Ja(null),ce.error)ce.refetch();if(Ao.error)Ao.refetch();if(Hn.error)Hn.refetch();if(E.kind==="browse")Ol()};if(Do&&!Se)return Qt.jsxDEV(Ga,{message:Do,error:!0,onRetry:iu},void 0,!1,void 0,this);if(!Se)return Qt.jsxDEV(Ga,{message:"Loading…"},void 0,!1,void 0,this);if(to&&zi){let qe=mi(a,Cy);return Qt.jsxDEV(Rz,{types:Se,workspaces:$t,workspaceId:zi.id,selectEntityType:es,selectWorkspace:jr,children:Qt.jsxDEV(pt.Suspense,{fallback:Qt.jsxDEV(he,{children:"Opening Account…"},void 0,!1,void 0,this),children:Qt.jsxDEV(fI,{bootstrap:mI(qe,a,s)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}if(Rl&&zi)return Qt.jsxDEV(Qt.Fragment,{children:[Qt.jsxDEV(pt.Suspense,{fallback:Qt.jsxDEV(Ga,{message:"Opening Chat…"},void 0,!1,void 0,this),children:Qt.jsxDEV(dI,{apiPath:zi.chatApiPath,draftStore:B,onNavigationStateChange:Q,studioBasePath:a,sessionId:hI(s),types:Se,workspaces:$t,handoff:Lz(l),navigate:(qe,Ni)=>{e.history.push(qe,void 0,{ignoreBlocker:Ni?.preserveWork===!0})},selectEntityType:es,selectWorkspace:jr},void 0,!1,void 0,this)},void 0,!1,void 0,this),V.status==="blocked"&&Qt.jsxDEV(vn,{mark:"↩",title:"Leave this conversation?",titleId:"chat-navigation-title",cancelLabel:"Stay",confirmLabel:"Leave",onCancel:()=>V.reset(),onConfirm:()=>V.proceed(),children:Qt.jsxDEV("p",{children:"Your draft stays in this tab. Leaving stops receiving the response, but does not undo completed actions or background jobs."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(p?p!==kh&&!Wa&&!Ir:y&&!ut&&!Do)return Qt.jsxDEV(Ga,{message:"Loading…"},void 0,!1,void 0,this);if(!qs&&u.kind!=="images"&&!p&&(!y||!ut&&!Do))return Qt.jsxDEV(Ga,{message:Do??"No readable collections are available for this account.",error:Boolean(Do),...Do?{onHome:()=>e.history.push(a)}:{}},void 0,!1,void 0,this);return Qt.jsxDEV(Mz,{groupings:{items:Fe,active:qs?.key??$r?.grouping??null,onSelect:(qe)=>e.history.push(fc(a,qe))},images:{active:u.kind==="images",onSelect:()=>e.history.push(u3(a))},imagesView:u.kind==="images"?Qt.jsxDEV(R2,{onOpen:(qe,Ni)=>e.history.push(qn(a,qe,Ni))},void 0,!1,void 0,this):null,homeView:p===kh?Qt.jsxDEV(F2,{chatApiPath:Ml?.chatApiPath,onNavigate:(qe)=>e.history.push(qe),onAsk:(qe)=>{B.update(d3(Ml?.chatApiPath,null),{text:qe}),e.history.push(pc)}},void 0,!1,void 0,this):null,groupReturnLabel:$r?.label,groupingSuggestions:Fc,groupingView:qs?Qt.jsxDEV(A2,{basePath:a,grouping:qs,types:Se,query:qr,onChange:(qe,Ni)=>{let Vr=`${fc(a,qs.key)}${cc(qe)}`,Oh=qe.value!==qr.value||qe.offset!==qr.offset;e.history[Oh&&Ni?.replace!==!0?"push":"replace"](Vr)},onOpen:(qe,Ni)=>{let Vr=qn(a,qe,Ni);$s.current={pathname:Vr,save:{kind:"idle"}},e.history.push(Vr,{studioGroupingPath:`${fc(a,qs.key)}${cc(qr)}`})}},void 0,!1,void 0,this):null,activeWorkspaceId:p,types:Se,workspaces:$t,workspaceError:Ir,readError:Do,onRetryRead:iu,declarativeWorkspaceData:Ka,workspaceQuery:oe,entityType:y,entities:Ya,refineNotice:Ah.notice,onRefineConfirmed:Ah.confirmed,folders:Ao.data?.folders??[],collectionTrail:Ao.data?.trail,collectionPath:mt?gi(a,mt):a,selectFolder:Dh,creationDestination:{data:To.data??null,pending:To.isPending,error:To.error},entityOffset:Ce,entityLimit:ze.limit,entityTotal:Ch??0,collectionQuery:ze,onCollectionQueryChange:(qe)=>{if(!mt)return;e.history.push(`${gi(a,mt)}${yi({...qe,offset:0})}`),window.scrollTo({top:0,left:0})},entityListLoading:Ao.isPending,schema:ut,editor:A,fieldAssistState:ve,bodyMode:Oe,mobilePane:Y,syncStatus:gt,baselineCommit:Mh,agentTargets:Ur,deleting:Fa,hasUnsavedChanges:M,navigationBlocked:V.status==="blocked",dispatchEditor:C,setFieldAssistState:ue,setBodyMode:U,setMobilePane:W,backToList:tu,selectEntityType:es,selectWorkspace:jr,changeEntityPage:Ll,openWorkspaceEntity:sn,openWorkspaceLaunch:Ps,performPublishingAction:nu,performDeclarativeAction:vi,onWorkspaceQueryChange:Eo,startCreate:eu,openEntity:(qe,Ni)=>Za(qe,void 0,Ni),runFieldAssist:bi,applyFieldAssist:Rh,save:Ly,remove:Kc,onNavigationReset:()=>V.reset?.(),draftRecovery:Yc,onNavigationProceed:()=>{Yc.forget(),V.proceed?.()}},void 0,!1,void 0,this)}function m3(){return new p3({defaultOptions:{queries:{retry:!1,refetchOnWindowFocus:!1},mutations:{retry:!1}}})}var Ry=F(xe(),1),Dy=document.querySelector("[data-studio-root]");if(Dy){let e=Dy.getAttribute("data-studio-base-path")??"/studio",i=new v3({basePath:e});Dy.textContent="";let s=m3(),l=b3(e,h3);x3.createRoot(Dy).render(Ry.jsxDEV(g3,{client:s,children:Ry.jsxDEV(S3,{api:i,children:Ry.jsxDEV(y3,{router:l},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this))}
|
|
250
250
|
|
|
251
251
|
//# debugId=3629C0DAFF4D17C564756E2164756E21
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 2,
|
|
3
3
|
"entrypoints": {
|
|
4
|
-
"script": "studio-app-
|
|
4
|
+
"script": "studio-app-wft7ba0t.js",
|
|
5
5
|
"stylesheet": "studio-app-9fcce3b7d1414bef1c4d76b166dd2d0e7a9c16491d45e701c1ca12a4cf9cb3e3.css"
|
|
6
6
|
},
|
|
7
7
|
"assets": {
|
|
8
8
|
"studio-app-9fcce3b7d1414bef1c4d76b166dd2d0e7a9c16491d45e701c1ca12a4cf9cb3e3.css": "studio-app-9fcce3b7d1414bef1c4d76b166dd2d0e7a9c16491d45e701c1ca12a4cf9cb3e3.css",
|
|
9
|
-
"studio-app-
|
|
10
|
-
"studio-app-
|
|
9
|
+
"studio-app-wft7ba0t.js": "studio-app-wft7ba0t.js",
|
|
10
|
+
"studio-app-wft7ba0t.js.map": "studio-app-wft7ba0t.js.map",
|
|
11
11
|
"studio-chunks/account-view-kkfs676e.js": "studio-chunks/account-view-kkfs676e.js",
|
|
12
12
|
"studio-chunks/account-view-kkfs676e.js.map": "studio-chunks/account-view-kkfs676e.js.map",
|
|
13
13
|
"studio-chunks/chat-45vnn1n8.js": "studio-chunks/chat-45vnn1n8.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"studio-chunks/main-sf1tftcq.js.map": "studio-chunks/main-sf1tftcq.js.map",
|
|
31
31
|
"studio-chunks/mermaid-GHXKKRXX-p4y3pesq.js": "studio-chunks/mermaid-GHXKKRXX-p4y3pesq.js",
|
|
32
32
|
"studio-chunks/mermaid-GHXKKRXX-p4y3pesq.js.map": "studio-chunks/mermaid-GHXKKRXX-p4y3pesq.js.map",
|
|
33
|
-
"studio-chunks/studio-chat-workspace-
|
|
34
|
-
"studio-chunks/studio-chat-workspace-
|
|
33
|
+
"studio-chunks/studio-chat-workspace-wy37fxat.js": "studio-chunks/studio-chat-workspace-wy37fxat.js",
|
|
34
|
+
"studio-chunks/studio-chat-workspace-wy37fxat.js.map": "studio-chunks/studio-chat-workspace-wy37fxat.js.map"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{Aa as Rt,Ba as Lt,Ca as He,Da as Oe,F as Zt,I as Vt,K as ye,M as Ut,Q as Ue,Ua as Ve,ba as ce,ca as ue,n as Me,nb as Le,ob as te,pb as ee,q as kt,xa as ke,ya as yt,za as Be}from"./main-jch2bj9d.js";import"./main-7qt9yk4m.js";import{Ab as B,Cb as S,Db as pe,Dc as zt,Eb as de,Hb as Ct,Lb as St,Nb as bt,Tc as xt,ac as $e,bc as qe,jc as Ce,lc as he,tc as Pt,uc as jt,vc as Mt,wc as $t,xb as Ft,xc as qt}from"./main-78k6snwb.js";import{Ae as Gt,Be as Ne,Ce as ze,me as Se}from"./main-6t5cpsqt.js";import{De as F}from"./main-sf1tftcq.js";import{jf as v}from"./main-e3v487c0.js";var a={imageTrigger:{k1xSpc:"x1lliihq",kzqmXN:"xh8yej3",kmVPX3:"x1717udv",kMzoRj:"xc342km",kWkggS:"xjbqb8w",kkrTdU:"x1huxd7x",kAzted:"x1gg8mnh",k3Woio:"x16dl9wz",kiEn40:"x7s97pk",$$css:!0},fullImage:{kzqmXN:"xh8yej3",kZKoxP:"xt7dq6l",kskxy:"x6kd6ug",kVIFPx:"x19kjcj4",$$css:!0},toolbar:{k1xSpc:"x78zum5",kGNEyG:"x6s0dn4",kOIVth:"x195vfkc",kmuXW:"x2lah0s",$$css:!0},toolbarButton:{kAzted:"x1gg8mnh",k7Eaqz:"x1nb6za0",kmVPX3:"x1160tuk",kGuDYH:"xfifm61",$$css:!0},details:{k1xSpc:"xrvj5dj",kOIVth:"xou54vl",k7Eaqz:"xeuugli",$$css:!0},composerBar:{k1xSpc:"x78zum5",kjj79g:"x1qughib",kGNEyG:"x6s0dn4",kOIVth:"x167g77z",$$css:!0},userTurn:{koQZXg:"x8x9d4c",ks0D6T:"x1v8xovm",kWkggS:"xbslqsl",kaIpWk:"x1cxwkf3",kmVPX3:"x1j671cp",$$css:!0},source:{khDVqt:"x126k92a",kHjlTd:"xj0a0fe",kVQacm:"xysyzu8",kskxy:"x8ln6o7",kmVPX3:"xc7ga6q",kogj98:"x1ghz6dp",kMv6JI:"xa9opjo",kGuDYH:"xfifm61",kLWn49:"x1dbl2gt",kWkggS:"xbslqsl",$$css:!0},sourceType:{kMv6JI:"xa9opjo",kGuDYH:"xfifm61",kMwMTN:"x1ar3pfp",$$css:!0},uploadStrip:{k1xSpc:"x78zum5",kXHlph:"xw2csxc",kskxy:"x569fbc",kOIVth:"x167g77z",k7Eaqz:"xeuugli",k5wCbM:"x1597r2g",k1K539:"xzueoph",$$css:!0},uploadPreview:{kzqmXN:"x100vrsf",kZKoxP:"x1vqgdyp",kVIFPx:"xl1xv1r",kaIpWk:"x12oqio5",$$css:!0},uploadName:{k7Eaqz:"xeuugli",kUk6DE:"x98rzlu",kHjlTd:"xj0a0fe",kGuDYH:"xfifm61",$$css:!0},sessionControls:{k1xSpc:"xrvj5dj",kOIVth:"x167g77z",k7Eaqz:"xeuugli",k1K539:"xod5an3",kGuDYH:"xfifm61",kMwMTN:"x1ar3pfp",$$css:!0},sessionFilterSelect:{kzqmXN:"xh8yej3",k7Eaqz:"xeuugli",kAzted:"x141feeh x1c4ya5t",kGuDYH:"x4z9k3i xf2x79s",$$css:!0},composerHint:{k1xSpc:"x1lliihq xkaaz9w",keoZOQ:"x1xmf6yo",kGuDYH:"x1j6dyjg",kLWn49:"x37zpob",kMwMTN:"x1ar3pfp",$$css:!0},shell:{k1xSpc:"xrvj5dj",kUk6DE:"x98rzlu",kAzted:"x2lwn1j",k7Eaqz:"xeuugli",kVQacm:"xb3r6kr",$$css:!0},root:{k1xSpc:"x78zum5",kXwgrk:"xdt5ytf",kZKoxP:"xtdtrs8",kskxy:"x1wj9ous",kAzted:"x2lwn1j",k7Eaqz:"xeuugli",kVQacm:"xb3r6kr",$$css:!0},frame:{k1xSpc:"x78zum5",kXwgrk:"xdt5ytf",k7Eaqz:"xeuugli",kAzted:"x2lwn1j",kVQacm:"xb3r6kr",kmVPX3:"x1717udv",kOIVth:"xxhr3t",$$css:!0},room:{k1xSpc:"xrvj5dj",kumcoG:"x1mkdm3x",kOIVth:"xxhr3t",kUk6DE:"x98rzlu",kAzted:"x2lwn1j",k7Eaqz:"xeuugli",kVQacm:"xb3r6kr",$$css:!0},emptyConversation:{kogj98:"x1ghz6dp",$$css:!0},picker:{"--console-text-muted":"x1phc7po",k1xSpc:"xrvj5dj",k9llMU:"x1yn14it",kskxy:"x1j65ot3",kAzted:"x2lwn1j",kVQacm:"xb3r6kr",$$css:!0},thread:{k1xSpc:"x78zum5",kXwgrk:"xdt5ytf",k7Eaqz:"xeuugli",kAzted:"x2lwn1j",kVQacm:"xb3r6kr",$$css:!0},threadHead:{k1xSpc:"x78zum5",kGNEyG:"x6s0dn4",kjj79g:"x1qughib",kOIVth:"x167g77z",k7Eaqz:"xeuugli",kmuXW:"x2lah0s",kAzted:"xt55aet",kmVPX3:"xsoouyo xbqoc8e",kt9PQ7:"xso031l",kfdmCh:"x1q0q8m5",kL6WhQ:"xpqg30t",k1K539:"xat24cr",$$css:!0},title:{kogj98:"x1ghz6dp",kVQacm:"xb3r6kr",kg5iWk:"xlyipyv",khDVqt:"xuxw1ft",k7Eaqz:"xeuugli",kMv6JI:"x5ddh9m",kGuDYH:"x4z9k3i",k63SB2:"xo1l8bm",kLWn49:"x1evy7pa",kMwMTN:"xqvuw85",$$css:!0},headCopy:{k7Eaqz:"xeuugli",kUk6DE:"x98rzlu",$$css:!0},actions:{k1xSpc:"x78zum5",kwnvtZ:"x1a02dak",kGNEyG:"x6s0dn4",kOIVth:"x883omv",$$css:!0},sessionList:{k1xSpc:"xrvj5dj",kfiyM8:"x10ukxgv",kAzted:"x2lwn1j",k7Eaqz:"xeuugli",kORKVm:"x1odjw0f",$$css:!0},session:{k1xSpc:"xrvj5dj",kOIVth:"x17d4w8g",kzqmXN:"xh8yej3",k7Eaqz:"xeuugli",kmVPX3:"x1g8o3q3",kMzoRj:"xc342km",kt9PQ7:"xso031l",ksu8eU:"x1y0btm7",kVAM5u:"xy1lt07",kWkggS:"xjbqb8w",kMwMTN:"xqvuw85",k9WMMc:"xdpxx8g",kkrTdU:"x1ypdohk",kDPRdz:"x1xiaf3t",k3Woio:"x16dl9wz",kiEn40:"x1bqaal",$$css:!0},activeSession:{kMwMTN:"x1q7454x",$$css:!0},sessionTitle:{kMv6JI:"x5ddh9m",kGuDYH:"xif65rj",k63SB2:"xo1l8bm",kLWn49:"xfrs9s4",kHjlTd:"xj0a0fe",k1xSpc:"x104kibb",kgKLqz:"x1ua5tub",kJFfOR:"x1h7i4cw",kVQacm:"xb3r6kr",$$css:!0},timestamp:{kMv6JI:"xa9opjo",kGuDYH:"x1j6dyjg",kLWn49:"xa7kkou",kMwMTN:"x1ar3pfp",kHjlTd:"xj0a0fe",$$css:!0},context:{k7Eaqz:"xeuugli",kt9PQ7:"xso031l",kfdmCh:"x1q0q8m5",kL6WhQ:"xpqg30t",$$css:!0},contextBody:{k1xSpc:"xrvj5dj",kI3sdo:"x16dl9wz",kInvED:"x2ssjo2",kOIVth:"xou54vl",kskxy:"xtgemb3",kORKVm:"x1odjw0f",kGO01o:"x1l90r2v",kg3NbH:"xfn1xvj",k7Eaqz:"xeuugli",$$css:!0},contextItem:{k1xSpc:"xrvj5dj",kOIVth:"x17d4w8g",k7Eaqz:"xeuugli",kmVPX3:"x1b4vry6",kt9PQ7:"xso031l",kfdmCh:"x1q0q8m5",kL6WhQ:"xpqg30t",kMv6JI:"x5ddh9m",kGuDYH:"xfifm61",kLWn49:"x1dbl2gt",$$css:!0},threadScroll:{kUk6DE:"x98rzlu",kI3sdo:"x16dl9wz",kInvED:"x2ssjo2",kAzted:"x2lwn1j",k7Eaqz:"xeuugli",kORKVm:"x1odjw0f",kZeWKH:"xish69e",k5wCbM:"x1597r2g",k6w4Gs:"xgwpcrc",$$css:!0},manuscript:{k7Eaqz:"xeuugli",ks0D6T:"x1ac2792",kUOVxO:"xvueqy4",kmVPX3:"x12mnf9l xvc418b",$$css:!0},turn:{k1xSpc:"xrvj5dj",kumcoG:"x1mkdm3x",kOIVth:"x167g77z",kmVPX3:"x1717udv",k1K539:"x1xka2u1",k7Eaqz:"xeuugli",$$css:!0},speaker:{kLKAdn:"xexx8yu",kMv6JI:"xa9opjo",kGuDYH:"x1j6dyjg",kLWn49:"x1dbl2gt",kMwMTN:"x1ar3pfp",$$css:!0},turnBody:{k1xSpc:"xrvj5dj",kOIVth:"x1v2ro7d",k7Eaqz:"xeuugli",kMv6JI:"x5ddh9m",kGuDYH:"x1j61zf2 x1sgj8az",k63SB2:"xo1l8bm",kLWn49:"x11m8ghp",kMwMTN:"xqvuw85",kHjlTd:"xj0a0fe",$$css:!0},userBody:{k63SB2:"xo1l8bm",$$css:!0},paragraph:{kogj98:"x1ghz6dp",khDVqt:"x126k92a",kHjlTd:"xj0a0fe",$$css:!0},cards:{k1xSpc:"xrvj5dj",kOIVth:"x1v2ro7d",k7Eaqz:"xeuugli",$$css:!0},attachmentPreview:{k1xSpc:"x1lliihq",kzqmXN:"xh8yej3",ks0D6T:"x193iq5w",kZKoxP:"xt7dq6l",kskxy:"x1iuus0c",kVIFPx:"x19kjcj4",kWkggS:"x18s3upu",$$css:!0},card:{k1xSpc:"xrvj5dj",kOIVth:"x883omv",k7Eaqz:"xeuugli",kmVPX3:"x1tamke2",kMzoRj:"xmkeg23",ksu8eU:"x1y0btm7",kVAM5u:"xy1lt07",kaIpWk:"x1sxf85j",kMv6JI:"x5ddh9m",kGuDYH:"xfifm61",k63SB2:"xo1l8bm",kLWn49:"x1dbl2gt",kHjlTd:"xj0a0fe",kXHlph:"xw2csxc",$$css:!0},kicker:{kMv6JI:"xa9opjo",kGuDYH:"x1j6dyjg",kMwMTN:"xgi1xjn",$$css:!0},cardHeading:{kogj98:"x1ghz6dp",$$css:!0},cardText:{kogj98:"x1ghz6dp",kMv6JI:"x5ddh9m",kGuDYH:"xfifm61",kLWn49:"x1dbl2gt",$$css:!0},empty:{kogj98:"xhv1u6h",kMv6JI:"x5ddh9m",kGuDYH:"xfifm61",kLWn49:"x1dbl2gt",kMwMTN:"xgi1xjn",kHjlTd:"xj0a0fe",$$css:!0},error:{kMwMTN:"x1mel2pz",$$css:!0},form:{k1xSpc:"xrvj5dj",kOIVth:"x1jnr06f",k7Eaqz:"xeuugli",kMzoRj:"xmkeg23",ksu8eU:"x1y0btm7",kVAM5u:"x8tuc8h x5nc5hl",kGVxlE:"x1gnnqk1 x79sx2d",kaIpWk:"x4pepcl",kmVPX3:"x1160tuk",kWkggS:"x18s3upu",$$css:!0},composer:{kmuXW:"x2lah0s",k7Eaqz:"xeuugli",kzqmXN:"xh8yej3",ks0D6T:"x1ac2792",kSGwAc:"xamitd3",kmVPX3:"x17udgi5 x1lbfznl",$$css:!0},input:{kzqmXN:"xh8yej3",kB7OPa:"x9f619",k7Eaqz:"xeuugli",kZKoxP:"xn3w4p2",kAzted:"x1gg8mnh",kskxy:"x1hyak1l",kHenm0:"xtt52l0",kmVPX3:"x14odnwx",kMzoRj:"xc342km",ksu8eU:"x1y0btm7",kVAM5u:"xy1lt07",kaIpWk:"x1sxf85j",kWkggS:"xjbqb8w",kMv6JI:"x5ddh9m",kGuDYH:"x1j61zf2",kLWn49:"x1evy7pa",kMwMTN:"xqvuw85",kI3sdo:"x1a2a7pz",$$css:!0},attachButton:{k1xSpc:"x3nfvp2",kGNEyG:"x6s0dn4",kAzted:"x1ba4aug x126n28w",kmVPX3:"x153ncpu",kB7OPa:"x9f619",kMzoRj:"xmkeg23",ksu8eU:"x1y0btm7",kVAM5u:"xy1lt07",kaIpWk:"x1sxf85j",kMv6JI:"x5ddh9m",kGuDYH:"xfifm61",kMwMTN:"xqvuw85",kkrTdU:"x1ypdohk",k8PahR:"xt2bx3g",kfQpEX:"x1fanpfn",$$css:!0},uploadInput:{kVAEAm:"x10l6tqk",kzqmXN:"x1i1rx1s",kZKoxP:"xjm9jq1",kz4h6p:"x1hyvwdk",kVQacm:"xb3r6kr",khDVqt:"xuxw1ft",$$css:!0},uploadList:{k1xSpc:"x78zum5",kwnvtZ:"xozqiw3",kmuXW:"x2lah0s",kOIVth:"x167g77z",kogj98:"x1ghz6dp",kmVPX3:"x1717udv",kH6xsr:"x3ct3a4",$$css:!0},upload:{k1xSpc:"x78zum5",kGNEyG:"x6s0dn4",kOIVth:"x17d4w8g",kmuXW:"x2lah0s",kogj98:"x1ghz6dp",ks0D6T:"x1jkqq1h",kMv6JI:"xa9opjo",kGuDYH:"x1j6dyjg",k63SB2:"xo1l8bm",kMwMTN:"x1ar3pfp",kHjlTd:"xj0a0fe",$$css:!0},button:{kAzted:"x1gg8mnh",kmVPX3:"x153ncpu",kMzoRj:"xmkeg23",ksu8eU:"x1y0btm7",kVAM5u:"xy1lt07",kaIpWk:"x1sxf85j",kWkggS:"xjbqb8w",kMwMTN:"xqvuw85",kMv6JI:"x5ddh9m",kGuDYH:"xfifm61",kkrTdU:"x1ypdohk",k3Woio:"x16dl9wz",kiEn40:"x7s97pk",kWCcOm:"xijokvz",kYPGJ8:"xtgyt42",$$css:!0},primaryButton:{kWkggS:"x15vqgvx",kVAM5u:"xawfzfr",kMwMTN:"xb8ja0n",$$css:!0},subheading:{kogj98:"x1ghz6dp",kLWn49:"x1evy7pa",$$css:!0}};function s(t,...e){return`${t} ${Ft(...e).className??""}`}var mt=v(F(),1);var gt=v(F(),1);var z=v(B(),1);function Qt(t){let{card:e,client:o}=t,n=kt({queryKey:["studio","chat","attachment-job",o.paths.jobStatus,e.jobId],queryFn:()=>o.getJobStatus(e.jobId??""),enabled:Boolean(e.jobId),retry:!1,refetchInterval:(y)=>y.state.data?.status==="pending"||y.state.data?.status==="processing"?2000:!1}),r=n.error instanceof Gt&&n.error.status===404,l=n.isError&&!r,i=qt(e.jobId?$t(n.data?.status):null),c=!e.jobId||r||!n.isError&&n.data!==void 0&&(i.status==="completed"||i.status==="unknown"),u=e.attachment.previewUrl??e.attachment.url,[m,p]=gt.useState(null),[x,k]=gt.useState(!1),[I,g]=gt.useState(null),h=gt.useRef(null),w=l?"Status unavailable":e.jobId&&n.isPending?"Checking generation status":i.label;return z.jsxDEV("section",{className:s("studio-chat-card",a.card),"aria-label":e.title,children:[z.jsxDEV("span",{className:s("studio-chat-card-kicker",a.kicker),children:"Artifact"},void 0,!1,void 0,this),z.jsxDEV("strong",{children:e.title},void 0,!1,void 0,this),z.jsxDEV("span",{role:"status",className:s("studio-chat-card-description",a.cardText),children:w},void 0,!1,void 0,this),e.description?z.jsxDEV("p",{className:s("studio-chat-card-description",a.cardText),children:e.description},void 0,!1,void 0,this):null,c&&e.attachment.mediaType.startsWith("image/")?m===u?z.jsxDEV("p",{role:"status",children:"Image preview unavailable. You can still open or download the file."},void 0,!1,void 0,this):z.jsxDEV("button",{ref:h,type:"button","aria-label":`Enlarge ${e.title}`,className:s("studio-chat-image-trigger",a.imageTrigger),onClick:()=>k(!0),children:z.jsxDEV("img",{className:s("studio-chat-attachment-preview",a.attachmentPreview),src:u,alt:e.title,loading:"lazy",onError:()=>p(u)},void 0,!1,void 0,this)},void 0,!1,void 0,this):null,c?z.jsxDEV("div",{className:s("studio-chat-card-actions",a.actions),children:[z.jsxDEV("a",{className:s("studio-chat-card-action",a.button),href:e.attachment.url,children:"Open"},void 0,!1,void 0,this),z.jsxDEV("a",{className:s("studio-chat-card-action",a.button),href:e.attachment.downloadUrl??e.attachment.url,download:e.attachment.filename??!0,children:"Download"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,z.jsxDEV(Ct,{open:x&&c,onOpenChange:k,children:z.jsxDEV(St,{"aria-describedby":void 0,onCloseAutoFocus:(y)=>{y.preventDefault(),h.current?.focus()},children:[z.jsxDEV(bt,{children:e.title},void 0,!1,void 0,this),I===e.attachment.url?z.jsxDEV("p",{role:"status",children:"Image unavailable. You can still try opening or downloading the file."},void 0,!1,void 0,this):z.jsxDEV("img",{className:s("studio-chat-full-image",a.fullImage),src:e.attachment.url,alt:e.title,onError:()=>g(e.attachment.url)},void 0,!1,void 0,this),z.jsxDEV("a",{href:e.attachment.downloadUrl??e.attachment.url,download:e.attachment.filename??!0,children:"Download image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),l?z.jsxDEV(S,{type:"button",variant:"outline",onClick:()=>void n.refetch(),children:"Check status"},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}function Xt(t){if(t.brain||!t.entityType||!t.entityId)return null;return{type:t.entityType,id:t.entityId}}var Ze=4;function Jt(t,e){let o=Xt(t);if(o)return zt(e,o.type,o.id);return t.url}function ta(t,e){let o=t.slice(0,e);if((o.split("`").length-1)%2===1)return!0;let r=o.lastIndexOf("["),l=o.lastIndexOf("]");return r>l}function Yt(t,e,o){return e.reduce((n,r)=>{let l=r.title?.trim();if(!l||l.length<Ze)return n;let i=Xt(r);if(!i)return n;let c=n.indexOf(l);if(c<0||ta(n,c))return n;let u=zt(o,i.type,i.id);return`${n.slice(0,c)}[${l}](${u})${n.slice(c+l.length)}`},t)}function _t(t){let e=(n)=>t.workspaces.some((r)=>r.endsWith(`:${n}`)),o=[...e("inbox")?["Summarize what is in my inbox this week"]:[],...e("publishing")?["What did I publish last month?"]:[],...t.types.includes("post")?["Draft a post from my recent notes"]:[],...t.types.includes("note")?["What have I been writing about lately?"]:[]].slice(0,4);return o.length>0?o:["What can you help me with?"]}var d=v(B(),1);function ae(t){let e=t.onStart?t.starters??[]:[];return d.jsxDEV("section",{className:s("studio-chat-empty",a.empty,a.emptyConversation),"aria-label":"New conversation",children:[d.jsxDEV("p",{className:s("",a.cardText),children:"No messages yet. Your draft stays in the composer until you send it."},void 0,!1,void 0,this),e.length>0&&d.jsxDEV("div",{"data-studio-chat-starters":"",className:s("studio-chat-actions",a.actions),"aria-label":"Ways to start",children:e.map((o)=>d.jsxDEV("button",{type:"button",onClick:()=>t.onStart?.(o),children:o},o,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function oe(t){return d.jsxDEV("article",{className:s("studio-chat-turn",a.turn,t.message.role==="user"&&a.userTurn),"data-role":t.message.role,children:[d.jsxDEV("span",{className:s("studio-chat-turn-label",a.speaker),children:t.message.role==="user"?"You":"Brain"},void 0,!1,void 0,this),d.jsxDEV("div",{className:s("studio-chat-turn-body",a.turnBody,t.message.role==="user"&&a.userBody),children:[t.message.content?t.message.role==="assistant"?d.jsxDEV(ee,{className:s("studio-chat-prose",a.cards),presentation:"chat",children:Yt(t.message.content,aa(t.message.cards),Ut())},void 0,!1,void 0,this):d.jsxDEV("p",{className:s("studio-chat-text",a.paragraph),children:t.message.content},void 0,!1,void 0,this):null,t.message.attachments?.map((e)=>d.jsxDEV("p",{className:s("studio-chat-upload",a.upload),children:e.filename},`${e.filename}-${e.createdAt}`,!1,void 0,this)),t.message.cards?.length?d.jsxDEV("div",{className:s("studio-chat-cards",a.cards),children:t.message.cards.map((e)=>d.jsxDEV(ea,{card:e,client:t.client,disabled:t.disabled,onAction:t.onAction,onApproval:t.onApproval},`${e.kind}-${e.id}`,!1,void 0,this))},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function ea(t){let{card:e}=t;if(e.kind==="actions")return d.jsxDEV("section",{className:s("studio-chat-card",a.card),children:[d.jsxDEV("span",{className:s("studio-chat-card-kicker",a.kicker),children:"Actions"},void 0,!1,void 0,this),e.title?d.jsxDEV("strong",{children:e.title},void 0,!1,void 0,this):null,d.jsxDEV("div",{className:s("studio-chat-card-actions",a.actions),children:e.actions.map((r)=>d.jsxDEV("button",{className:s("studio-chat-card-action",a.button),type:"button",disabled:t.disabled,onClick:()=>void t.onAction(r),children:r.label},r.id,!1,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(e.kind==="sources")return d.jsxDEV("nav",{className:s("studio-chat-sources",a.card),"aria-label":e.title??"Sources",children:d.jsxDEV("ul",{"data-studio-chat-source-chips":"",children:e.sources.map((r)=>{let l=Jt(r,Ut()),i=r.title??r.source;return d.jsxDEV("li",{children:[l?d.jsxDEV(oa,{href:l,children:i},void 0,!1,void 0,this):i," ",d.jsxDEV("span",{className:s("",a.sourceType),children:r.brain?.name??r.entityType??r.source},void 0,!1,void 0,this)]},r.id,!0,void 0,this)})},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(e.kind==="attachment")return d.jsxDEV(Qt,{card:e,client:t.client},void 0,!1,void 0,this);let o=e.state==="approval-requested",n={approvalId:e.id,toolCallId:e.toolCallId??e.id,toolName:e.toolName,...e.input?{input:e.input}:{},...e.summary?{title:e.summary}:{}};return d.jsxDEV("section",{className:s("studio-chat-card",a.card),children:[d.jsxDEV("span",{className:s("studio-chat-card-kicker",a.kicker),children:o?"Approval required":e.state==="approval-responded"?"Decision received · awaiting result":e.state==="output-available"?"Completed":e.state==="output-denied"?"Declined":"Action failed"},void 0,!1,void 0,this),d.jsxDEV("strong",{children:e.summary},void 0,!1,void 0,this),e.state==="output-available"&&e.completionSummary&&d.jsxDEV("p",{children:e.completionSummary},void 0,!1,void 0,this),e.error!==void 0&&d.jsxDEV("p",{role:"alert",children:e.error},void 0,!1,void 0,this),(e.preview!==void 0||e.input!==void 0)&&d.jsxDEV("details",{children:[d.jsxDEV("summary",{children:"Review exact action"},void 0,!1,void 0,this),d.jsxDEV("pre",{className:s("studio-chat-card-preview",a.source),children:e.preview??JSON.stringify(e.input,null,2)},void 0,!1,void 0,this),e.preview!==void 0&&e.input!==void 0&&d.jsxDEV("details",{children:[d.jsxDEV("summary",{children:"Tool input"},void 0,!1,void 0,this),d.jsxDEV("pre",{className:s("",a.source),children:JSON.stringify(e.input,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d.jsxDEV("p",{className:s("",a.cardText),children:["Tool: ",e.toolName]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),e.output!==void 0&&d.jsxDEV("details",{children:[d.jsxDEV("summary",{children:"Action result"},void 0,!1,void 0,this),d.jsxDEV("pre",{className:s("",a.source),children:typeof e.output==="string"?e.output:JSON.stringify(e.output,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o?d.jsxDEV("div",{className:s("studio-chat-approval-actions",a.actions),children:[d.jsxDEV("button",{className:s("studio-chat-approval-action",a.button),type:"button",disabled:t.disabled,onClick:()=>void t.onApproval(n,!1),children:"Decline"},void 0,!1,void 0,this),d.jsxDEV("button",{className:s("studio-chat-approval-action",a.button,a.primaryButton),"data-primary":"true",type:"button",disabled:t.disabled,onClick:()=>void t.onApproval(n,!0),children:"Approve"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this)}function se(t){return d.jsxDEV("section",{className:s("studio-chat-approval",a.card),children:[d.jsxDEV("span",{className:s("studio-chat-card-kicker",a.kicker),children:"Approval required"},void 0,!1,void 0,this),d.jsxDEV("strong",{children:t.approval.title??t.approval.toolName},void 0,!1,void 0,this),t.approval.input!==void 0&&d.jsxDEV("details",{children:[d.jsxDEV("summary",{children:"Review exact action"},void 0,!1,void 0,this),d.jsxDEV("pre",{className:s("",a.source),children:JSON.stringify(t.approval.input,null,2)},void 0,!1,void 0,this),d.jsxDEV("p",{children:["Tool: ",t.approval.toolName]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),d.jsxDEV("div",{className:s("studio-chat-approval-actions",a.actions),children:[d.jsxDEV("button",{className:s("studio-chat-approval-action",a.button),type:"button",disabled:t.disabled,onClick:()=>void t.onDecision(t.approval,!1),children:"Decline"},void 0,!1,void 0,this),d.jsxDEV("button",{className:s("studio-chat-approval-action",a.button,a.primaryButton),"data-primary":"true",type:"button",disabled:t.disabled,onClick:()=>void t.onDecision(t.approval,!0),children:"Approve"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function aa(t){return(t??[]).flatMap((e)=>e.kind==="sources"?e.sources:[])}function oa(t){let e=te(),o=t.href.startsWith("/");return d.jsxDEV("a",{href:t.href,...o?{}:{target:"_blank",rel:"noopener noreferrer"},onClick:(n)=>{if(!o||!e||!Zt(n))return;n.preventDefault(),e(t.href)},children:t.children},void 0,!1,void 0,this)}var ne=v(F(),1);var At=`Text/Markdown up to ${jt/1000} KB; PNG, JPEG, WebP, GIF or PDF up to ${Mt/1e6} MB.`,H={sessions:["studio","chat","sessions"],messages:(t)=>["studio","chat","messages",t]};var C=v(B(),1);function re(t){let e=(o)=>{if(o.key==="Enter"&&!o.shiftKey&&!o.nativeEvent.isComposing)o.preventDefault(),o.currentTarget.form?.requestSubmit()};return C.jsxDEV("footer",{className:s("studio-chat-composer",a.composer),children:[t.onJumpToLatest&&C.jsxDEV(S,{type:"button",variant:"ghost",onClick:t.onJumpToLatest,children:"Jump to latest ↓"},void 0,!1,void 0,this),C.jsxDEV("form",{className:s("studio-chat-composer-form",a.form),onSubmit:t.onSubmit,children:[(t.uploadAttempts.length>0||t.uploads.length>0)&&C.jsxDEV("div",{className:s("studio-chat-upload-strip",a.uploadStrip),role:"region","aria-label":"Draft attachments",tabIndex:0,children:C.jsxDEV("ul",{className:s("studio-chat-upload-list",a.uploadList),"aria-label":t.uploadAttempts.length>0?"File upload progress":"Attached files",children:[t.uploadAttempts.map((o)=>C.jsxDEV("li",{className:s("studio-chat-upload",a.upload),children:[C.jsxDEV("div",{className:s("",a.uploadName),children:[C.jsxDEV("span",{role:o.status==="failed"?"alert":"status",children:[o.file.name,":"," ",o.status==="uploading"?"Uploading…":o.error??"Upload failed"]},void 0,!0,void 0,this),o.status==="uploading"&&C.jsxDEV("progress",{"aria-label":`Uploading ${o.file.name}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o.status==="failed"&&C.jsxDEV(C.Fragment,{children:[C.jsxDEV(S,{type:"button",variant:"ghost",size:"sm",xstyle:a.toolbarButton,"aria-label":`Retry uploading ${o.file.name}`,disabled:t.uploading||t.sending||t.locked,onClick:()=>t.onRetryUpload(o),children:"Retry"},void 0,!1,void 0,this),C.jsxDEV(S,{type:"button",variant:"ghost",size:"sm",xstyle:a.toolbarButton,"aria-label":`Dismiss failed upload ${o.file.name}`,onClick:()=>t.onDismissUpload(o.id),children:"×"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},o.id,!0,void 0,this)),t.uploads.map((o)=>C.jsxDEV("li",{className:s("studio-chat-upload",a.upload),children:[C.jsxDEV(sa,{upload:o},void 0,!1,void 0,this),C.jsxDEV("span",{className:s("",a.uploadName),children:[o.filename,C.jsxDEV("br",{},void 0,!1,void 0,this),"Ready · draft only"]},void 0,!0,void 0,this),C.jsxDEV(S,{type:"button",variant:"ghost",size:"sm",xstyle:a.toolbarButton,"aria-label":`Remove ${o.filename} from message`,disabled:t.locked,onClick:()=>t.onRemoveUpload(o.id),children:"×"},void 0,!1,void 0,this)]},o.id,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this),C.jsxDEV("textarea",{className:s("studio-chat-message",a.input),"aria-label":"Message","aria-describedby":"studio-chat-composer-hint",placeholder:"Message…",value:t.draft,disabled:t.locked,onChange:(o)=>t.onDraft(o.target.value),onKeyDown:e},void 0,!1,void 0,this),C.jsxDEV("div",{className:s("studio-chat-composer-actions",a.composerBar),children:[C.jsxDEV("label",{className:s("studio-chat-composer-action",a.attachButton),title:At,children:[C.jsxDEV("span",{"aria-hidden":"true",children:"+"},void 0,!1,void 0,this),C.jsxDEV("input",{className:s("studio-chat-upload-input",a.uploadInput),"aria-label":"Attach files",type:"file",accept:Pt,multiple:!0,disabled:t.locked||t.sending||t.uploading,onChange:(o)=>void t.onFiles(o)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),t.uploadAttempts.length>0&&C.jsxDEV("span",{className:s("",a.kicker),children:"Resolve uploads before sending"},void 0,!1,void 0,this),t.locked?C.jsxDEV(S,{type:"button",disabled:!0,children:"Archiving…"},void 0,!1,void 0,this):t.sending?C.jsxDEV(S,{type:"button",variant:"outline",xstyle:a.toolbarButton,onClick:t.onStop,disabled:!t.onStop,title:"Stop receiving the response. Completed actions are not undone.",children:"Stop"},void 0,!1,void 0,this):C.jsxDEV(S,{className:"studio-chat-composer-action",type:"submit",xstyle:a.toolbarButton,"aria-label":"Send message",disabled:t.uploading||t.uploadAttempts.length>0||!t.draft.trim()&&t.uploads.length===0,children:"↑"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),C.jsxDEV("small",{id:"studio-chat-composer-hint",className:s("studio-chat-composer-hint",a.composerHint),children:"Enter to send · Shift+Enter for a new line"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function sa({upload:t}){let[e,o]=ne.useState(!1);if(e||!t.mediaType.startsWith("image/"))return null;return C.jsxDEV("img",{className:s("studio-chat-draft-preview",a.uploadPreview),src:t.url,alt:t.filename,onError:()=>o(!0)},void 0,!1,void 0,this)}var _=v(B(),1),na={stopped:"Stopped",disconnected:"Connection lost",failed:"Response failed"};function ie(t){let{interrupted:e}=t;return _.jsxDEV("section",{className:s("studio-chat-interruption",a.empty),role:e.kind==="stopped"?"status":"alert","aria-atomic":"true",children:[_.jsxDEV("strong",{children:na[e.kind]},void 0,!1,void 0,this),_.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),e.detail&&_.jsxDEV("p",{children:e.detail},void 0,!1,void 0,this),e.retry&&_.jsxDEV(_.Fragment,{children:[_.jsxDEV("p",{children:"Sending again may repeat completed actions. Review the request before sending."},void 0,!1,void 0,this),_.jsxDEV(S,{type:"button",variant:"ghost",disabled:t.restoreBlocked||t.draftPending,onClick:()=>{if(!e.retry||t.draftPending)return;t.onRestore(e.retry)},children:"Review retry in composer"},void 0,!1,void 0,this),t.draftPending&&_.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 Bt=v(F(),1);var T=v(B(),1);function le(t){return T.jsxDEV("aside",{className:s("studio-chat-context",a.contextBody),tabIndex:0,"aria-label":"Conversation sources and attachments",children:T.jsxDEV("div",{className:s("studio-chat-context-list",a.cards),children:[t.session?.contextHandoff?T.jsxDEV("section",{className:s("studio-chat-context-card",a.contextItem),children:[T.jsxDEV("span",{className:s("studio-chat-context-kicker",a.kicker),children:"Linked context"},void 0,!1,void 0,this),T.jsxDEV("h3",{className:s("studio-chat-context-card-title",a.cardHeading,xt.section),children:t.session.contextHandoff.titleSeed},void 0,!1,void 0,this),T.jsxDEV("p",{className:s("studio-chat-context-card-text",a.cardText),children:[t.session.contextHandoff.sourceId," ·"," ",t.session.contextHandoff.itemId]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null,t.cards.length===0&&t.progress.length===0?T.jsxDEV("p",{className:s("studio-chat-empty",a.empty),children:"No sources or attachments in this conversation yet."},void 0,!1,void 0,this):null,t.cards.map((e,o)=>T.jsxDEV("section",{className:s("studio-chat-context-card",a.contextItem),children:[T.jsxDEV("span",{className:s("studio-chat-context-kicker",a.kicker),children:e.kind==="sources"?"Sources":"Artifact"},void 0,!1,void 0,this),T.jsxDEV("h3",{className:s("studio-chat-context-card-title",a.cardHeading,xt.section),children:e.kind==="sources"?e.title??`${e.sources.length} consulted`:e.kind==="attachment"?e.title:"Conversation context"},void 0,!1,void 0,this),e.kind==="sources"?T.jsxDEV(T.Fragment,{children:[T.jsxDEV("ul",{children:e.sources.slice(0,5).map((n)=>T.jsxDEV("li",{children:n.title??n.source},n.id,!1,void 0,this))},void 0,!1,void 0,this),e.sources.length>5?T.jsxDEV("p",{className:s("studio-chat-context-card-text",a.cardText),children:[e.sources.length-5," more sources in the conversation."]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this):e.kind==="attachment"&&e.description?T.jsxDEV("p",{className:s("studio-chat-context-card-text",a.cardText),children:e.description},void 0,!1,void 0,this):null]},`${e.kind}-${e.id}-${o}`,!0,void 0,this)),t.progress.map((e,o)=>T.jsxDEV("section",{className:s("studio-chat-context-card",a.contextItem),children:[T.jsxDEV("span",{className:s("studio-chat-context-kicker",a.kicker),children:"Durable job"},void 0,!1,void 0,this),T.jsxDEV("h3",{className:s("studio-chat-context-card-title",a.cardHeading,xt.section),children:e.operationTarget??e.operationType},void 0,!1,void 0,this),T.jsxDEV("p",{className:s("studio-chat-context-card-text",a.cardText),children:e.message??e.status},void 0,!1,void 0,this)]},`${e.type}-${o}`,!0,void 0,this))]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var M=v(B(),1);function me(t){return M.jsxDEV("aside",{className:s("studio-chat-session-picker",a.picker),"aria-label":"Chat sessions",children:[M.jsxDEV("header",{className:s("studio-chat-sessions-head",a.threadHead),children:[M.jsxDEV("div",{className:s("studio-chat-head-copy",a.headCopy),children:M.jsxDEV("h2",{className:s("studio-chat-sessions-title",a.subheading,xt.section),children:"History"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M.jsxDEV("button",{className:s("studio-chat-new",a.button),type:"button","aria-label":"New conversation",onClick:t.onNew,children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.jsxDEV("div",{className:s("studio-chat-session-controls",a.sessionControls),children:[M.jsxDEV(ce,{label:"Conversation search and filters",searchLabel:"Search conversations",search:t.search,onSearch:t.onSearch,filterLabel:"Filter",filterCount:t.view.archived?1:0,filtered:Boolean(t.view.query)||t.view.archived,onClear:()=>{t.onSearch(""),t.onView({...t.view,query:"",archived:!1,offset:0})},children:M.jsxDEV(de,{"aria-label":"Show conversations",value:t.view.archived?"archived":"active",onChange:(e)=>t.onView({...t.view,archived:e.target.value==="archived",offset:0}),children:[M.jsxDEV("option",{value:"active",children:"Active conversations"},void 0,!1,void 0,this),M.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),(t.view.offset>0||t.sessions.length>0)&&M.jsxDEV(ue,{label:"Conversation pages",offset:t.view.offset,count:t.sessions.length,loading:t.loading,hasNext:t.sessions.length>=25,onPrevious:()=>t.onView({...t.view,offset:Math.max(0,t.view.offset-25)}),onNext:()=>t.onView({...t.view,offset:t.view.offset+25})},void 0,!1,void 0,this),t.error&&M.jsxDEV("p",{role:"alert",children:[t.error," ",M.jsxDEV(S,{type:"button",variant:"ghost",onClick:t.onRetry,children:"Retry sessions"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M.jsxDEV("div",{className:s("studio-chat-session-list",a.sessionList),children:[t.loading?M.jsxDEV("p",{className:s("studio-chat-empty",a.empty),children:"Loading sessions…"},void 0,!1,void 0,this):null,!t.loading&&!t.error&&t.sessions.length===0?M.jsxDEV("p",{className:s("studio-chat-empty",a.empty),children:t.view.query?"No conversations match this search.":t.view.offset>0?"No more conversations.":t.view.archived?"No archived conversations.":"No conversations yet."},void 0,!1,void 0,this):null,t.sessions.map((e)=>M.jsxDEV("button",{className:s("studio-chat-session",a.session,e.id===t.activeSessionId&&a.activeSession),"data-active":e.id===t.activeSessionId?"true":"false",type:"button",onClick:()=>t.onSelect(e.id),children:[M.jsxDEV("strong",{className:s("studio-chat-session-title",a.sessionTitle),children:e.title},void 0,!1,void 0,this),M.jsxDEV("time",{className:s("studio-chat-session-time",a.timestamp),dateTime:e.lastActiveAt,title:e.lastActiveAt,children:ra(e.lastActiveAt)},void 0,!1,void 0,this)]},e.id,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function ra(t){let e=new Date(t);if(Number.isNaN(e.getTime()))return"";return new Intl.DateTimeFormat(void 0,{day:"numeric",year:e.getFullYear()===new Date().getFullYear()?void 0:"numeric",month:"short",timeZoneName:"short",hour:"2-digit",minute:"2-digit"}).format(e)}var Q=v(F(),1);var G=v(B(),1);function fe(t){let[e,o]=Q.useState(!1),[n,r]=Q.useState(t.title),[l,i]=Q.useState(!1),[c,u]=Q.useState(null),m=Q.useRef(!1),p=Q.useRef(!1),x=Q.useRef(null);Q.useEffect(()=>{if(e)x.current?.focus()},[e]);let k=Q.useRef(null);Q.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]);let I=()=>{o(!1),u(null),requestAnimationFrame(()=>k.current?.querySelector("button")?.focus())},g=async()=>{if(p.current||!n.trim())return;p.current=!0,i(!0),u(null);try{if(await t.onRename(n.trim()),m.current)I()}catch(h){if(m.current)u(he(h,"Rename failed. Your proposed title is kept.")||"Rename failed. Your proposed title is kept.")}finally{if(p.current=!1,m.current)i(!1)}};return G.jsxDEV(G.Fragment,{children:[G.jsxDEV("span",{ref:k,children:G.jsxDEV(S,{type:"button",variant:"ghost","aria-expanded":e,disabled:e,onClick:()=>{r(t.title),o(!0)},children:"Rename"},void 0,!1,void 0,this)},void 0,!1,void 0,this),e&&G.jsxDEV("form",{className:s("studio-chat-rename",a.sessionControls),onSubmit:(h)=>{h.preventDefault(),g()},children:[G.jsxDEV("label",{children:["Conversation title",G.jsxDEV(pe,{ref:x,xstyle:a.sessionFilterSelect,value:n,onChange:(h)=>r(h.target.value),required:!0,maxLength:48,disabled:l},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G.jsxDEV("div",{className:s("",a.actions),children:[G.jsxDEV(S,{type:"submit",disabled:l||!n.trim(),children:l?"Renaming…":"Save title"},void 0,!1,void 0,this),G.jsxDEV(S,{type:"button",variant:"ghost",disabled:l,onClick:I,children:"Cancel"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c&&G.jsxDEV("p",{role:"alert",children:c},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var f=v(B(),1);function ge(t){let{currentSession:e,archivedSession:o,sessions:n,sessionControls:r,sessionsLoading:l,navigateToSession:i,sessionPickerOpen:c,setSessionPickerOpen:u,detailsOpen:m,setDetailsOpen:p,renameCurrent:x}=t.sessions,k=Bt.useRef(null),I=Bt.useRef(null);return f.jsxDEV(f.Fragment,{children:[f.jsxDEV("header",{className:s("studio-chat-thread-head",a.threadHead),children:[f.jsxDEV("h1",{className:s("studio-chat-session-heading",a.title),title:e?.title,children:e?.title??(t.sessionId?"Conversation":"New conversation")},void 0,!1,void 0,this),f.jsxDEV("div",{className:s("studio-chat-head-actions",a.toolbar),children:[f.jsxDEV("span",{ref:I,className:"studio-chat-session-picker-trigger",children:f.jsxDEV(S,{type:"button",variant:"ghost",xstyle:a.toolbarButton,"aria-haspopup":"dialog","aria-expanded":c,onClick:()=>u(!0),children:"History"},void 0,!1,void 0,this)},void 0,!1,void 0,this),f.jsxDEV(S,{type:"button",variant:"ghost",xstyle:a.toolbarButton,"aria-label":"New conversation",title:"New conversation",onClick:()=>i(),children:"+"},void 0,!1,void 0,this),f.jsxDEV("span",{ref:k,children:f.jsxDEV(S,{type:"button",variant:"ghost",xstyle:a.toolbarButton,"aria-label":"Conversation details and options","aria-haspopup":"dialog","aria-expanded":m,onClick:()=>p(!0),children:"•••"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),f.jsxDEV(Ct,{open:c,onOpenChange:u,children:f.jsxDEV(St,{"aria-describedby":void 0,onCloseAutoFocus:(g)=>{g.preventDefault(),I.current?.querySelector("button")?.focus()},children:[f.jsxDEV(bt,{children:"Conversations"},void 0,!1,void 0,this),f.jsxDEV(me,{...r,activeSessionId:t.sessionId,loading:l,sessions:n,onNew:()=>i(),onSelect:i},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),f.jsxDEV(Ct,{open:m,onOpenChange:(g)=>{if(p(g),!g)t.deletion.cancelDelete()},children:f.jsxDEV(St,{"aria-describedby":void 0,onCloseAutoFocus:(g)=>{g.preventDefault(),k.current?.querySelector("button")?.focus()},children:[f.jsxDEV(bt,{children:"Conversation details"},void 0,!1,void 0,this),f.jsxDEV("div",{className:s("studio-chat-details",a.details),children:[f.jsxDEV("p",{children:e?.title??"New conversation"},void 0,!1,void 0,this),f.jsxDEV("div",{className:s("studio-chat-session-actions",a.actions),children:[e&&f.jsxDEV(fe,{title:e.title,onRename:x},e.id,!1,void 0,this),o&&f.jsxDEV("p",{role:"status",children:"Archived conversation. New messages here remain archived."},void 0,!1,void 0,this),t.sessionId&&!o?f.jsxDEV(S,{className:"studio-chat-header-action",variant:"ghost",type:"button",onClick:t.onArchive,disabled:t.archiveBlocked,title:t.draftPending?"Send or clear the draft before archiving":void 0,children:t.archiving?"Archiving…":"Archive"},void 0,!1,void 0,this):null,t.sessionId&&(t.deletion.confirming?f.jsxDEV("section",{role:"group","aria-label":"Confirm conversation deletion",children:[f.jsxDEV("p",{children:"Delete this conversation permanently? This cannot be undone."},void 0,!1,void 0,this),f.jsxDEV("p",{children:"Deleting history does not undo completed actions or guarantee that remote work has stopped."},void 0,!1,void 0,this),t.deletion.deleteError&&f.jsxDEV("p",{role:"alert",children:t.deletion.deleteError},void 0,!1,void 0,this),f.jsxDEV(S,{type:"button",variant:"ghost",autoFocus:!0,"aria-label":"Cancel conversation deletion",disabled:t.deletion.deleting,onClick:t.deletion.cancelDelete,children:"Cancel"},void 0,!1,void 0,this),f.jsxDEV(S,{type:"button",variant:"ghost","aria-label":"Permanently delete conversation",disabled:t.archiveBlocked,onClick:()=>void t.deletion.confirmDelete(),children:t.deletion.deleting?"Deleting…":"Delete permanently"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):f.jsxDEV(S,{type:"button",variant:"ghost","aria-label":"Delete conversation",disabled:t.archiveBlocked,title:t.draftPending?"Send or clear the draft before deleting":void 0,onClick:t.deletion.requestDelete,children:"Delete conversation"},void 0,!1,void 0,this))]},void 0,!0,void 0,this),f.jsxDEV("details",{children:[f.jsxDEV("summary",{children:"Sources and attachments"},void 0,!1,void 0,this),f.jsxDEV(le,{cards:t.contextCards,progress:t.progress,session:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f.jsxDEV("details",{children:[f.jsxDEV("summary",{children:"File types and limits"},void 0,!1,void 0,this),f.jsxDEV("p",{id:"studio-chat-upload-guidance",children:At},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 ot=v(F(),1);function xe(t){let[e]=ot.useState(()=>new ke),o=t.draftStore??e,n=yt(t.apiPath,t.sessionId),r=ot.useRef(n);r.current=n;let{text:l,uploads:i}=ot.useSyncExternalStore(o.subscribe,()=>o.read(n),()=>o.read(n)),c=ot.useCallback((m)=>o.update(n,{text:m}),[o,n]),u=ot.useCallback((m)=>o.update(n,{uploads:typeof m==="function"?m(o.read(n).uploads):m}),[o,n]);return{draftStore:o,draftKey:n,currentDraftKey:r,draft:l,uploads:i,setDraft:c,setUploads:u}}var tt=v(F(),1);var ia=250;function ve(t){let{chatClient:e,queryClient:o,sessionId:n,studioBasePath:r,navigate:l}=t,[i,c]=tt.useState(!1),[u,m]=tt.useState(!1),[p,x]=tt.useState(""),[k,I]=tt.useState({query:"",archived:!1,offset:0});tt.useEffect(()=>{let V=window.setTimeout(()=>I((D)=>D.query===p.trim()?D:{...D,query:p.trim(),offset:0}),ia);return()=>window.clearTimeout(V)},[p]);let g=kt({queryKey:[...H.sessions,k],queryFn:()=>e.listSessions(k)}),h=g.data??[],w=h.find((V)=>V.id===n)??o.getQueriesData({queryKey:H.sessions}).flatMap(([,V])=>V??[]).find((V)=>V.id===n),y=tt.useCallback(()=>{c(!1),m(!1)},[]),A=tt.useCallback((V,D=!1)=>{l(ye(r,V),{preserveWork:D}),y()},[l,r,y]),R=async(V)=>{if(!w)return;let D=await e.renameSession(w.id,V);if(!D.renamed)throw Error("The conversation could not be renamed.");o.setQueriesData({queryKey:H.sessions},(rt)=>rt?.map((X)=>X.id===w.id?{...X,title:D.title}:X)),o.invalidateQueries({queryKey:H.sessions})};return{sessions:h,currentSession:w,archivedSession:w?.archived===!0,sessionControls:{search:p,view:k,error:g.error?"Sessions could not be loaded.":null,onRetry:()=>{g.refetch()},onSearch:x,onView:I},sessionsLoading:g.isPending,navigateToSession:A,sessionPickerOpen:i,setSessionPickerOpen:c,detailsOpen:u,setDetailsOpen:m,closeDisclosures:y,renameCurrent:R}}var O=v(F(),1);function be(){return{messageId:"assistant-stream",text:"",cards:[],approvals:[],progress:[],statuses:[],toolInputs:{},finished:!1,error:null}}function Ie(t,e){switch(e.type){case"start":return e.messageId?{...t,messageId:e.messageId}:t;case"text-delta":return{...t,text:`${t.text}${e.delta}`};case"tool-input-available":return{...t,toolInputs:{...t.toolInputs,[e.toolCallId]:{toolCallId:e.toolCallId,toolName:e.toolName,input:e.input,...e.title?{title:e.title}:{}}}};case"tool-approval-request":{let o=t.toolInputs[e.toolCallId],n={approvalId:e.approvalId,toolCallId:e.toolCallId,toolName:o?.toolName??"tool",...Ce(o?.input)?{input:o.input}:{},...o?.title?{title:o.title}:{}};return{...t,approvals:[...t.approvals.filter((r)=>r.approvalId!==e.approvalId),n]}}case"tool-output-available":case"tool-output-error":case"tool-output-denied":return{...t,approvals:t.approvals.filter((o)=>o.toolCallId!==e.toolCallId)};case"data-progress":return{...t,progress:[...t.progress,e.data]};case"data-status":return{...t,statuses:[...t.statuses,e.data]};case"data-actions":case"data-sources":case"data-attachment":return{...t,cards:[...t.cards,e.data]};case"finish":return{...t,finished:!0};case"abort":return{...t,finished:!0,error:e.reason??"Response stopped"};case"error":return{...t,finished:!0,error:e.errorText};default:return t}}function Dt(t){return{id:t.messageId,role:"assistant",content:t.text,...t.cards.length>0?{cards:t.cards}:{}}}function we(t,e){let o={id:t.approvalId,approved:e,toolCallId:t.toolCallId,toolName:t.toolName,...t.input?{input:t.input}:{},...t.title?{title:t.title}:{}};return Se.parse({role:"assistant",parts:[{state:"approval-responded",toolCallId:t.toolCallId,toolName:t.toolName,...t.input?{input:t.input}:{},...t.title?{title:t.title}:{},approval:o}]})}function st(t,e){return t instanceof Error&&t.message?t.message:e}function Ae(t){let{chatClient:e,queryClient:o,sessionId:n,apiPath:r,draftStore:l,draftKey:i,currentDraftKey:c,mountedRef:u,adoptedSessionRef:m,uploads:p,uploading:x,uploadAttemptCount:k,navigateToSession:I}=t,[g,h]=O.useState([]),[w,y]=O.useState(null),[A,R]=O.useState(!1),[V,D]=O.useState(null),[rt,X]=O.useState(null),N=O.useRef(null),J=O.useCallback(()=>N.current!==null,[]),pt=O.useCallback(()=>{N.current?.abort()},[]),it=O.useCallback(()=>{let E=N.current;N.current=null,E?.abort()},[]),wt=O.useCallback(()=>{it(),R(!1),h([]),y(null),D(null),X(null)},[it]),lt=O.useCallback(async(E,L,Y,at)=>{N.current?.abort();let U=new AbortController;N.current=U,R(!0),D(null),X(null);let dt=!1,q={...be(),messageId:crypto.randomUUID()};y(q);let K=!1,ct=!1,ut=()=>{if(ct||!q.text&&q.cards.length===0)return;ct=!0;let Z=Dt(q);h((P)=>[...P,Z]),y({...q,text:"",cards:[]})};try{let Z=await e.streamMessages({id:E,messages:L,trigger:"submit-message"},{signal:U.signal});K=!0,Y?.();for await(let P of Ne(Z)){if(N.current!==U)return K;if(P.type==="abort")dt=!0;q=Ie(q,P),y(q)}if(N.current!==U)return K;if(ut(),U.signal.aborted||dt||q.error!==null||!q.finished)return X({kind:U.signal.aborted||dt?"stopped":q.error!==null?"failed":"disconnected",...q.error?{detail:q.error}:{},...at?{retry:at}:{}}),K;try{let P=await e.getMessages(E);if(N.current!==U)return K;o.setQueryData(H.messages(E),P),h([]),y(null)}catch{}await o.invalidateQueries({queryKey:H.sessions})}catch(Z){if(N.current!==U)return K;ut(),X({kind:U.signal.aborted?"stopped":K?"disconnected":"failed",...!U.signal.aborted?{detail:st(Z,"Chat could not complete the response")}:{},...at?{retry:at}:{}})}finally{if(N.current===U)N.current=null,R(!1)}return K},[e,o]),vt=O.useCallback(async(E)=>{let L=E.trim();if(!L&&p.length===0||A||x||k>0)return;let Y=n??`web-${crypto.randomUUID()}`,at=yt(r,Y),U=crypto.randomUUID(),dt=p.map((P)=>({type:"data-upload",data:{ref:P.ref}})),q=[...L?[{type:"text",text:L}]:[],...dt];h((P)=>[...P,{id:U,role:"user",content:L,cards:p.map((W)=>({kind:"attachment",id:W.id,title:W.filename,attachment:{mediaType:W.mediaType,filename:W.filename,sizeBytes:W.sizeBytes,url:W.url,downloadUrl:W.downloadUrl}}))}]);let K=[...p],ct=l.read(i),ut=ct.text===E;if(ut||K.length>0)l.update(i,{text:ut?"":ct.text,uploads:ct.uploads.filter((P)=>!K.some((W)=>W.id===P.id))});if(!await lt(Y,[{id:U,role:"user",parts:q}],()=>{if(!n&&u.current&&c.current===i)l.adopt(i,at),m.current=Y,I(Y,!0)},{text:E,uploads:[...p]})&&(c.current===at||!n&&c.current===i)){h((ht)=>ht.filter((ft)=>ft.id!==U));let P=c.current,W=l.read(P);l.update(P,{...ut&&!W.text?{text:E}:{},uploads:[...K.filter((ht)=>!W.uploads.some((ft)=>ft.id===ht.id)),...W.uploads]})}},[I,n,r,l,i,c,u,m,lt,A,x,p,k]),Nt=O.useCallback(async(E,L)=>{if(!n||A)return;await lt(n,[we(E,L)])},[n,lt,A]),Et=O.useCallback(async(E)=>{if(E.type==="prompt"){await vt(E.prompt);return}if(!n||A)return;R(!0),D(null);try{let L=await e.runAction({conversationId:n,action:{type:"event",event:E.event,...E.fromState?{fromState:E.fromState}:{}}});if(!u.current||c.current!==i)return;h((Y)=>[...Y,{id:crypto.randomUUID(),role:"assistant",content:L.text,...L.cards?{cards:L.cards}:{}}])}catch(L){if(u.current&&c.current===i)D(st(L,"Chat action failed"))}finally{if(u.current&&c.current===i)R(!1)}},[e,n,A,vt,i,c,u]);return{pendingMessages:g,stream:w,sending:A,error:V,interrupted:rt,setSending:R,setError:D,setPendingMessages:h,runStream:lt,submitPrompt:vt,respondToApproval:Nt,runSuggestedAction:Et,hasActiveStream:J,stopActiveStream:pt,abortActiveStream:it,reset:wt}}var et=v(F(),1);function De(t){let{chatClient:e,draftKey:o,currentDraftKey:n,setUploads:r}=t,[l,i]=et.useState(!1),[c,u]=et.useState([]),m=et.useRef(null),p=et.useCallback(async(g)=>{if(m.current||g.length===0)return;let h=Symbol();if(m.current=h,i(!0),u((w)=>[...w.filter((y)=>!g.some((A)=>A.id===y.id)),...g.map((y)=>({id:y.id,file:y.file,status:"uploading"}))]),await Promise.all(g.map(async(w)=>{try{let y=await e.upload(w.file,w.file.name);if(m.current!==h||n.current!==o)return;r((A)=>[...A,y]),u((A)=>A.filter((R)=>R.id!==w.id))}catch(y){if(m.current!==h||n.current!==o)return;u((A)=>A.map((R)=>R.id===w.id?{...R,status:"failed",error:st(y,"Upload failed")}:R))}})),m.current===h)m.current=null,i(!1)},[e,o,n,r]),x=et.useCallback(async(g)=>{let h=Array.from(g.target.files??[]);g.target.value="",await p(h.map((w)=>({id:crypto.randomUUID(),file:w,status:"uploading"})))},[p]),k=et.useCallback((g)=>{u((h)=>h.filter((w)=>w.id!==g))},[]),I=et.useCallback(()=>{m.current=null,i(!1),u([])},[]);return{uploading:l,uploadAttempts:c,runUploads:p,uploadFiles:x,dismissAttempt:k,reset:I}}var It=v(F(),1);function Te(t){let{chatClient:e,queryClient:o,sessionId:n,draftKey:r,currentDraftKey:l,mountedRef:i,blocked:c,setSending:u,setError:m,navigateToSession:p}=t,[x,k]=It.useState(!1),I=It.useCallback(async()=>{if(!n||c)return;u(!0),k(!0);try{if(await e.archiveSession(n),await o.invalidateQueries({queryKey:H.sessions}),i.current&&l.current===r)p(void 0,!0)}catch(h){if(i.current&&l.current===r)m(st(h,"Conversation could not be archived"))}finally{if(i.current&&l.current===r)u(!1),k(!1)}},[e,o,n,r,l,i,c,u,m,p]),g=It.useCallback(()=>k(!1),[]);return{archiving:x,archiveCurrent:I,reset:g}}var nt=v(F(),1);function Re(t){let{chatClient:e,queryClient:o,sessionId:n,draftKey:r,currentDraftKey:l,mountedRef:i,blocked:c,setSending:u,navigateToSession:m}=t,[p,x]=nt.useState(null),[k,I]=nt.useState(!1),[g,h]=nt.useState(null),w=nt.useRef(0),y=nt.useRef(!1),A=p===r,R=nt.useCallback(()=>{w.current++,y.current=!1,x(null),I(!1),h(null)},[]);return{confirming:A,deleting:k,deleteError:g,requestDelete:()=>{if(!n||c||y.current)return;h(null),x(r)},cancelDelete:()=>{if(!y.current)x(null)},confirmDelete:async()=>{if(!n||!A||c||y.current)return;let X=w.current,N=()=>i.current&&l.current===r&&w.current===X;y.current=!0,I(!0),u(!0),h(null);try{if(!(await e.deleteSession(n)).deleted)throw Error("Deletion was not acknowledged");if(await o.cancelQueries({queryKey:H.messages(n)}),o.removeQueries({queryKey:H.messages(n)}),o.setQueriesData({queryKey:H.sessions},(pt)=>pt?.filter((it)=>it.id!==n)),o.invalidateQueries({queryKey:H.sessions}),N())x(null),m(void 0,!0)}catch{if(N())h("Deletion could not be confirmed. The conversation may already be deleted. Check history before trying again.")}finally{if(N())y.current=!1,I(!1),u(!1)}},reset:R}}var Tt=v(F(),1);function Ee(t){let{chatClient:e,handoff:o,sessionId:n,apiPath:r,draftStore:l,draftKey:i,currentDraftKey:c,mountedRef:u,setDraft:m,setError:p,navigateToSession:x}=t,k=Tt.useRef(null);Tt.useEffect(()=>{if(!o||n)return;let I=`${o.sourceId}\x00${o.itemId}`;if(k.current===I)return;k.current=I,m(o.prompt),p(null);let g=()=>u.current===!0&&c.current===i&&k.current===I;e.openContextSession({version:1,sourceId:o.sourceId,itemId:o.itemId,titleSeed:o.label}).then(({conversationId:h})=>{if(!g())return;l.adopt(i,yt(r,h)),x(h,!0)}).catch((h)=>{if(!g())return;k.current=null,p(st(h,"Context could not be attached"))})},[e,o,n,r,l,i,c,u,m,p,x])}var Ht=v(F(),1);function Pe(t){let{chatClient:e,sessionId:o,sending:n,pendingMessages:r,stream:l}=t,i=kt({queryKey:H.messages(o??""),queryFn:()=>e.getMessages(o??""),enabled:o!==null&&o!==void 0&&!n&&r.length===0}),c=i.data??[],u=Ht.useMemo(()=>{let p=[...c,...r];if(l&&(l.text||l.cards.length>0))p.push(Dt(l));return p},[r,c,l]),m=Ht.useMemo(()=>u.flatMap((p)=>(p.cards??[]).filter((x)=>x.kind==="sources"||x.kind==="attachment")),[u]);return{visibleMessages:u,contextCards:m,historyFailed:i.error!==null,historyOpening:i.isPending,historyReading:i.isFetching,hasStoredHistory:c.length>0,retryHistory:()=>void i.refetch()}}var Ot=v(F(),1);function je(t){let{onChange:e,draft:o,uploadCount:n,uploadAttemptCount:r,sending:l,uploading:i}=t;Ot.useEffect(()=>{e?.({hasDraft:Boolean(o||n||r),busy:l||i})},[o,n,r,l,i,e]),Ot.useEffect(()=>()=>e?.({hasDraft:!1,busy:!1}),[e])}var b=v(B(),1);function ms(t){let e=Me(),o=$e(),n=mt.useMemo(()=>ze({apiPath:t.apiPath,fetch:o}),[t.apiPath,o]),{draftStore:r,draftKey:l,currentDraftKey:i,draft:c,uploads:u,setDraft:m,setUploads:p}=xe({draftStore:t.draftStore,apiPath:t.apiPath,sessionId:t.sessionId}),{uploading:x,uploadAttempts:k,runUploads:I,uploadFiles:g,dismissAttempt:h,reset:w}=De({chatClient:n,draftKey:l,currentDraftKey:i,setUploads:p}),y=Be(),A=ve({chatClient:n,queryClient:e,sessionId:t.sessionId,studioBasePath:t.studioBasePath,navigate:t.navigate}),{navigateToSession:R,closeDisclosures:V}=A,D=mt.useRef(!1),rt=mt.useRef(null),{pendingMessages:X,stream:N,sending:J,error:pt,interrupted:it,setSending:wt,setError:lt,submitPrompt:vt,respondToApproval:Nt,runSuggestedAction:Et,hasActiveStream:E,stopActiveStream:L,abortActiveStream:Y,reset:at}=Ae({chatClient:n,queryClient:e,sessionId:t.sessionId,apiPath:t.apiPath,draftStore:r,draftKey:l,currentDraftKey:i,mountedRef:D,adoptedSessionRef:rt,uploads:u,uploading:x,uploadAttemptCount:k.length,navigateToSession:R});Ee({chatClient:n,handoff:t.handoff,sessionId:t.sessionId,apiPath:t.apiPath,draftStore:r,draftKey:l,currentDraftKey:i,mountedRef:D,setDraft:m,setError:lt,navigateToSession:R});let U=Boolean(c)||u.length>0,dt=U||k.length>0,q=J||x||dt,{archiving:K,archiveCurrent:ct,reset:ut}=Te({chatClient:n,queryClient:e,sessionId:t.sessionId,draftKey:l,currentDraftKey:i,mountedRef:D,blocked:q,setSending:wt,setError:lt,navigateToSession:R}),Z=Re({chatClient:n,queryClient:e,sessionId:t.sessionId,draftKey:l,currentDraftKey:i,mountedRef:D,blocked:q,setSending:wt,navigateToSession:R});mt.useEffect(()=>(D.current=!0,()=>{D.current=!1,Y()}),[Y]),je({onChange:t.onNavigationStateChange,draft:c,uploadCount:u.length,uploadAttemptCount:k.length,sending:J,uploading:x});let{visibleMessages:P,contextCards:W,historyFailed:ht,historyOpening:ft,historyReading:Ke,hasStoredHistory:We,retryHistory:Fe}=Pe({chatClient:n,sessionId:t.sessionId,sending:J,pendingMessages:X,stream:N}),{ref:Kt,onScroll:Ge,awayFromLatest:Qe,jumpToLatest:Xe}=qe({resetKey:t.sessionId,contentKey:`${P.length}:${N?.text.length??-1}`});mt.useEffect(()=>{if(V(),t.sessionId&&rt.current===t.sessionId){rt.current=null;return}at(),w(),ut(),Z.reset()},[t.sessionId]);let Je=(j)=>{j.preventDefault(),vt(c)},Wt=Ve(t.workspaces);return b.jsxDEV(Le,{value:(j)=>t.navigate(j),children:b.jsxDEV("div",{className:s("studio",Ue.frame,a.root),"data-view":"chat","data-studio-shell":"",children:[b.jsxDEV(Oe,{contextLabel:"Chat",navigation:{types:t.types,workspaces:t.workspaces,activeEntityType:null,activeWorkspaceId:Vt,workspaceBadges:Wt,selectEntityType:t.selectEntityType,selectWorkspace:t.selectWorkspace}},void 0,!1,void 0,this),b.jsxDEV("div",{className:Lt("studio-chat-shell",a.shell,Rt.shell,y&&Rt.shellCollapsed),children:[b.jsxDEV("aside",{className:Lt("rail studio-chat-studio-rail",Rt.rail),children:b.jsxDEV(He,{renderMode:"desktop",types:t.types,active:null,onSelect:t.selectEntityType,workspaces:t.workspaces,activeWorkspace:Vt,workspaceBadges:Wt,onSelectWorkspace:t.selectWorkspace},void 0,!1,void 0,this)},void 0,!1,void 0,this),b.jsxDEV("main",{className:s("studio-chat-workspace",a.frame),children:b.jsxDEV("div",{className:s("studio-chat-room",a.room),children:b.jsxDEV("section",{className:s("studio-chat-thread",a.thread),"aria-label":"Conversation",children:[b.jsxDEV(ge,{sessionId:t.sessionId,sessions:A,archiving:K,archiveBlocked:q,draftPending:dt,onArchive:()=>void ct(),deletion:Z,contextCards:W,progress:N?.progress??[]},void 0,!1,void 0,this),b.jsxDEV("div",{ref:Kt,tabIndex:0,role:"region","aria-label":"Conversation messages",onScroll:Ge,className:s("studio-chat-thread-scroll",a.threadScroll),children:b.jsxDEV("div",{className:s("studio-chat-manuscript",a.manuscript),children:[ht&&b.jsxDEV("section",{role:"alert",children:[b.jsxDEV("p",{children:[We?"Showing previously loaded messages. ":"","Conversation could not be loaded."]},void 0,!0,void 0,this),b.jsxDEV(S,{type:"button",variant:"ghost",disabled:Ke,onClick:Fe,children:"Retry conversation"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),ft&&t.sessionId&&P.length===0?b.jsxDEV("p",{className:s("studio-chat-empty",a.empty),children:"Opening conversation…"},void 0,!1,void 0,this):null,!ht&&(!t.sessionId||!ft)&&P.length===0?b.jsxDEV(ae,{starters:_t({types:t.types.map((j)=>j.entityType),workspaces:t.workspaces.map((j)=>j.id)}),onStart:m},void 0,!1,void 0,this):null,P.map((j)=>b.jsxDEV(oe,{message:j,client:n,disabled:J,onAction:Et,onApproval:Nt},j.id,!1,void 0,this)),N?.approvals.map((j)=>b.jsxDEV(se,{approval:j,disabled:J,onDecision:Nt},j.approvalId,!1,void 0,this)),N&&N.progress.length>0&&b.jsxDEV("details",{className:s("studio-chat-progress",a.card),children:[b.jsxDEV("summary",{children:["Activity · ",N.progress.length," updates"]},void 0,!0,void 0,this),b.jsxDEV("pre",{className:s("",a.source),children:JSON.stringify(N.progress,null,2)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J?b.jsxDEV("p",{className:s("studio-chat-stream-status",a.empty),role:"status",children:"Responding…"},void 0,!1,void 0,this):null,it&&b.jsxDEV(ie,{interrupted:it,draftPending:U,restoreBlocked:J||x,onRestore:(j)=>{m(j.text),p([...j.uploads]),Kt.current?.closest(".studio-chat-thread")?.querySelector("textarea")?.focus()}},void 0,!1,void 0,this),pt?b.jsxDEV("p",{className:s("studio-chat-error",a.empty,a.error),role:"alert",children:pt},void 0,!1,void 0,this):null,b.jsxDEV("div",{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b.jsxDEV(re,{onJumpToLatest:Qe?Xe:void 0,draft:c,sending:J,uploading:x,uploads:u,uploadAttempts:k,onRetryUpload:(j)=>void I([j]),onDismissUpload:h,onDraft:m,locked:K||Z.deleting,onRemoveUpload:(j)=>p((Ye)=>Ye.filter((_e)=>_e.id!==j)),onFiles:g,onSubmit:Je,onStop:E()?L:void 0},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,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{ms as StudioChatWorkspace};
|
|
2
|
+
|
|
3
|
+
//# debugId=3550874C830D119C64756E2164756E21
|