@datalayer/agent-runtimes 1.6.62 → 1.6.63

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.
Files changed (66) hide show
  1. package/dist-embed/chunks/ChatView-Bg-IvVbM.js +32 -0
  2. package/dist-embed/datalayer-app-main.js +94 -94
  3. package/lib/apps/agentUiPlugins.d.ts +39 -10
  4. package/lib/apps/agentUiPlugins.js +159 -50
  5. package/lib/apps/apps/AppRenderer.js +3 -1
  6. package/lib/apps/apps/appspec.js +17 -3
  7. package/lib/apps/core/index.d.ts +6 -0
  8. package/lib/apps/core/index.js +6 -0
  9. package/lib/apps/embed/LoopEmbed.js +1 -1
  10. package/lib/apps/plugins/aws-savings/index.d.ts +10 -5
  11. package/lib/apps/plugins/aws-savings/index.js +35 -21
  12. package/lib/apps/plugins/aws-savings-badge/index.d.ts +28 -0
  13. package/lib/apps/plugins/aws-savings-badge/index.js +58 -0
  14. package/lib/apps/plugins/bank-reconciliation/index.d.ts +19 -7
  15. package/lib/apps/plugins/bank-reconciliation/index.js +68 -63
  16. package/lib/apps/plugins/basket-total/index.d.ts +25 -0
  17. package/lib/apps/plugins/basket-total/index.js +41 -0
  18. package/lib/apps/plugins/chat/ChatView.js +4 -1
  19. package/lib/apps/plugins/earth-area/index.d.ts +27 -0
  20. package/lib/apps/plugins/earth-area/index.js +50 -0
  21. package/lib/apps/plugins/earth-index/index.d.ts +8 -3
  22. package/lib/apps/plugins/earth-index/index.js +39 -27
  23. package/lib/apps/plugins/earth-scenes/index.d.ts +8 -3
  24. package/lib/apps/plugins/earth-scenes/index.js +30 -31
  25. package/lib/apps/plugins/linkedin-link/index.d.ts +5 -4
  26. package/lib/apps/plugins/linkedin-link/index.js +7 -16
  27. package/lib/apps/plugins/odoo-context/index.d.ts +30 -0
  28. package/lib/apps/plugins/odoo-context/index.js +54 -0
  29. package/lib/apps/plugins/product-comparison/index.d.ts +7 -1
  30. package/lib/apps/plugins/product-comparison/index.js +37 -30
  31. package/lib/apps/plugins/shopping-basket/index.d.ts +19 -5
  32. package/lib/apps/plugins/shopping-basket/index.js +69 -24
  33. package/lib/apps/plugins/social-accounts/index.d.ts +10 -0
  34. package/lib/apps/plugins/social-accounts/index.js +51 -1
  35. package/lib/apps/plugins/trip-options/index.d.ts +15 -5
  36. package/lib/apps/plugins/trip-options/index.js +67 -21
  37. package/lib/apps/plugins/trip-summary/index.d.ts +26 -0
  38. package/lib/apps/plugins/trip-summary/index.js +59 -0
  39. package/lib/apps/plugins/x-budget/index.d.ts +3 -2
  40. package/lib/apps/plugins/x-budget/index.js +8 -17
  41. package/lib/apps/presets.d.ts +2 -1
  42. package/lib/apps/presets.js +2 -2
  43. package/lib/apps/toolCards/a2uiCard.d.ts +63 -0
  44. package/lib/apps/toolCards/a2uiCard.js +104 -0
  45. package/lib/apps/toolCards/chrome.d.ts +50 -0
  46. package/lib/apps/toolCards/chrome.js +57 -0
  47. package/lib/apps/toolCards/postPreview.d.ts +6 -2
  48. package/lib/apps/toolCards/postPreview.js +28 -18
  49. package/lib/apps/toolCards/toolResults.d.ts +37 -0
  50. package/lib/apps/toolCards/toolResults.js +85 -0
  51. package/lib/chat/Chat.js +47 -36
  52. package/lib/chat/base/ChatBase.js +2 -2
  53. package/lib/chat/messages/ChatMessageList.js +7 -0
  54. package/lib/specs/actions.js +32 -0
  55. package/lib/specs/agents/agents.js +1 -1
  56. package/lib/specs/appspecSchema.js +18 -0
  57. package/lib/specs/backendTools.js +29 -14
  58. package/lib/specs/mcpServers.js +19 -10
  59. package/lib/specs/skills.js +7 -3
  60. package/lib/specs/ui.d.ts +5 -0
  61. package/lib/specs/ui.js +172 -11
  62. package/lib/types/agentspecs.d.ts +8 -0
  63. package/lib/types/chat.d.ts +5 -0
  64. package/package.json +1 -1
  65. package/scripts/codegen/generate_ui.py +2 -0
  66. package/dist-embed/chunks/ChatView-LldnraOq.js +0 -32
@@ -1,32 +0,0 @@
1
- import{a6 as B,fe as so,r as s,j as t,gH as oo,gI as ao,cd as rs,B as h,H as wt,T as z,v as G,du as sn,fu as un,gJ as oe,dn as Ct,y as io,gK as ro,gL as lo,f4 as co,gM as uo,b1 as fo,gN as po,gO as mo,gP as ho,gQ as go,gR as xo,gS as bo,eY as bs,eW as vo,dq as So,eZ as fn,gT as yo,gU as wo,gV as Co,gW as jo,gX as vs,gY as Ss,gZ as ko,L as To,g_ as Ro,e8 as on,I as ys,bk as it,D as ws,g$ as ls,h0 as Io,h1 as Eo,E as Ao,cC as Po,h2 as Mo,h3 as Uo,h4 as Oo,h5 as $o,h6 as Lo,h7 as Fo,a1 as an,h8 as zo,h9 as _o,ha as No,hb as Bo,hc as Vo,hd as Do,he as Ho,hf as Wo,hg as Ko,hh as Go,hi as Yo,hj as Jo,hk as qo,hl as Qo,hm as Zo,hn as Xo,ho as ea,hp as ta,hq as na,hr as sa,hs as rt,ht as oa,hu as aa,hv as ia,hw as ra,hx as cs,hy as la,hz as De,hA as ca,hB as da,cD as jt,hC as ua,hD as fa,hE as ds,hF as pa,hG as ma,hH as ha,hI as ga,hJ as xa,hK as ba,hL as va,hM as Sa,fD as ya,hN as rn,hO as Ue,hP as wa,hQ as Ca,hR as ja,hS as ka,hT as us,hU as Ta,hV as Ra,hW as Ia,hX as Ea,hY as Aa,hZ as Pa,h_ as Ma,h$ as Ua,i0 as Oa,i1 as $a,i2 as La,i3 as Fa,i4 as kt,i5 as za,i6 as _a,i7 as Na,i8 as Ba,i9 as Va,ia as Da,ib as Ha,ic as fs,id as Wa,ie as Ka,ig as Ga,ih as Ya,ii as Ja,ij as pn,ik as qa,il as Qa,fk as ln,im as Za,io as Xa}from"../datalayer-app-main.js";import{S as ei,E as ti,a as ni}from"./SignInIcon-XIbntAUw.js";import{F as si,a as oi,b as ai}from"./LinkedInGreyIcon-eBP5iBjI.js";import{K as ii}from"./KebabHorizontalIcon-D6AY8pIS.js";function Cs(){const n=B(so);return s.useMemo(()=>n.map(o=>o.value),[n])}const cn={github:{name:"github",oauth2CallbackServerRoute:"jupyter_iam/oauth2/callback",oauth2CallbackUIRoute:"/iam/oauth2/github/callback"},google:{name:"google",oauth2CallbackServerRoute:"jupyter_iam/oauth2/callback",oauth2CallbackUIRoute:"/iam/oauth2/google/callback"},linkedin:{name:"linkedin",oauth2CallbackServerRoute:"jupyter_iam/oauth2/callback",oauth2CallbackUIRoute:"/iam/oauth2/linkedin/callback"}},ps=()=>{if(typeof document>"u")return"";const n=document.getElementById("datalayer-config-data");if(!n?.textContent)return"";try{const o=JSON.parse(n.textContent);return String(o?.iamUrl||"").replace(/\/$/,"")}catch{return""}},ri=(n,o="Unable to start social sign-in.")=>{if(n instanceof Error&&n.message)return n.message;if(typeof n=="string"&&n.trim())return n;if(n&&typeof n=="object"&&"message"in n){const i=n.message;if(typeof i=="string"&&i.trim())return i}return o},li=uo`
2
- .signin-input-theme-scope input:-webkit-autofill,
3
- .signin-input-theme-scope input:-webkit-autofill:hover,
4
- .signin-input-theme-scope input:-webkit-autofill:focus,
5
- .signin-input-theme-scope input:-webkit-autofill:active,
6
- .signin-input-theme-scope input:-webkit-autofill:disabled,
7
- .signin-input-theme-scope textarea:-webkit-autofill,
8
- .signin-input-theme-scope textarea:-webkit-autofill:hover,
9
- .signin-input-theme-scope textarea:-webkit-autofill:focus,
10
- .signin-input-theme-scope textarea:-webkit-autofill:active,
11
- .signin-input-theme-scope textarea:-webkit-autofill:disabled {
12
- -webkit-text-fill-color: var(--fgColor-default) !important;
13
- caret-color: var(--fgColor-default) !important;
14
- -webkit-box-shadow: 0 0 0 1000px var(--bgColor-default) inset !important;
15
- box-shadow: 0 0 0 1000px var(--bgColor-default) inset !important;
16
- background-color: var(--bgColor-default) !important;
17
- transition: background-color 9999s ease-in-out 0s !important;
18
- }
19
-
20
- .signin-input-theme-scope input:disabled,
21
- .signin-input-theme-scope textarea:disabled {
22
- -webkit-text-fill-color: var(--fgColor-muted) !important;
23
- -webkit-box-shadow: 0 0 0 1000px var(--bgColor-default) inset !important;
24
- box-shadow: 0 0 0 1000px var(--bgColor-default) inset !important;
25
- background-color: var(--bgColor-default) !important;
26
- opacity: 1 !important;
27
- }
28
- `,ci=({onSignIn:n,onApiKeySignIn:o,loginUrl:i,name:r,title:u="Datalayer OTEL",description:p="Sign in to access the observability dashboard.",icon:v,leadingIcon:c=t.jsx(co,{size:24}),github:f=!1,google:x=!1,linkedin:y=!1,apiKey:d=!1,signUp:pe=!0,socialSignInNavigationTarget:L,asDoc:w=!1,fillHeight:T=!0,hideHero:N=!1,calloutTitle:ve,calloutDescription:M,passwordToggleLabel:Tt="Sign in with a password",signUpTitle:Rt="Don't have an account?",signUpDescription:mn="Create a free Datalayer account with your email address.",signUpLabel:Se="Sign up with email",signUpHref:It="https://datalayer.ai/signup",onSignUp:Q,forgotPasswordHref:me="/password",forgotPasswordLabel:lt="Forgot password?",showForgotPassword:ae=!0,socialButtonMarginTop:Oe=3,actionButtonMaxWidth:ne=320})=>{const ye=w&&!N,C=r??(w&&u==="Datalayer OTEL"?"Datalayer Sign In":u),ct=v??(w?t.jsx(ei,{size:24}):c),we=s.useMemo(()=>{if(i)return i;const m=ps();return m?`${m}/api/iam/v1/login`:"/api/iam/v1/login"},[i]),[Z,Et]=s.useState(""),[I,At]=s.useState(""),[Ce,Pt]=s.useState(!1),[$e,Mt]=s.useState(!1),[U,Le]=s.useState(!1),[X,He]=s.useState(!1),[Fe,We]=s.useState(null),[Y,Ut]=s.useState(null),[ie,Ot]=s.useState(""),[Ke,$t]=s.useState(null),[je,ee]=s.useState(null),{enqueueToast:ke}=oo(),[Te,Re]=s.useState(!1),[he,Ge]=s.useState(""),ge=s.useRef(null),Ye=s.useCallback(m=>ao()?rs.URLExt.join(rs.PageConfig.getBaseUrl(),m.oauth2CallbackServerRoute):`${window.location.protocol}//${window.location.hostname}${window.location.port?`:${window.location.port}`:""}${m.oauth2CallbackUIRoute}`,[]),re=s.useMemo(()=>{if(typeof window>"u")return"/";const m=`${window.location.pathname}${window.location.search}${window.location.hash}`;return m.startsWith("/")?m:"/"},[]),A=s.useCallback(async m=>{if(!X){ee(null),We(m.name),He(!0);try{const O=ps(),V=new URLSearchParams({provider:m.name,callback_uri:Ye(m)}),D=L===void 0?void 0:String(L||"").trim(),qe=D===void 0?re&&re!=="/"?re:void 0:D&&D.startsWith("/")&&!D.startsWith("//")?D:void 0;qe&&V.set("post_auth_redirect",qe);const P=`${O||""}/api/iam/v1/oauth2/authz/url?${V.toString()}`,$=await fetch(P),j=await $.json(),de=j?.autorization_url;if(!$.ok||!de)throw new Error(j?.message||"Unable to start social sign-in.");window.location.assign(de)}catch(O){const V=ri(O);ee(V),ke(V,{variant:"error"}),We(null),He(!1)}}},[Ye,re,ke,X,L]);s.useEffect(()=>{Te&&ge.current?.focus()},[Te]);const le=s.useCallback(()=>{Re(!1),Ge("")},[]),Ie=s.useCallback(()=>{!he.trim()||!o||(o(he.trim()),le())},[he,o,le]),ce=s.useCallback(()=>{if(Q){Q();return}window.location.assign(It)},[Q,It]),dt=s.useCallback(()=>{if(me){if(me.startsWith("http://")||me.startsWith("https://")){window.open(me,"_blank","noopener,noreferrer");return}window.location.assign(me)}},[me]),ze=s.useCallback(async()=>{if(!(w||!Z||!I||U)){Le(!0),ee(null);try{const m=await fetch(we,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({handle:Z,password:I})});if(!m.ok)throw new Error(`HTTP ${m.status}`);const O=await m.json();if(O.success&&O.token){const V=String(O?.user?.id||O?.user?.uid||"").trim();if(!!O?.user?.mfaUrl&&V){Ut(V),$t(O.token),ee(null);return}n&&n(O.token,Z)}else ee(O.message||"Invalid username or password.")}catch(m){ee(m instanceof Error?m.message:String(m))}finally{Le(!1)}}},[w,Z,I,U,we,n]),_e=s.useCallback(async()=>{if(!(w||U||!Y||!ie.trim()||!Ke)){Le(!0),ee(null);try{const m=new URL(we,window.location.origin),O=m.pathname.endsWith("/api/iam/v1/login")?m.href.replace(/\/api\/iam\/v1\/login$/,""):`${m.origin}`,V=await fetch(`${O}/api/iam/v1/users/${Y}/mfa/validate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userUid:Y,code:ie.trim()})}),D=await V.json();if(!V.ok||!D?.success)throw new Error(D?.message||"Failed to validate your MFA code.");n&&n(Ke,Z)}catch(m){const O=m instanceof Error?m.message:String(m);ee(O),ke(O,{variant:"error"})}finally{Le(!1)}}},[w,ke,Z,U,we,ie,Ke,Y,n]),J=s.useCallback(m=>{m.key==="Enter"&&(Y?_e():ze())},[Y,ze,_e]),Je=X||U||w;return t.jsxs(h,{className:"signin-input-theme-scope",display:"flex",alignItems:N||ye||!T?"flex-start":"center",justifyContent:"center",minHeight:N||ye||!T?"auto":"100vh",bg:N?"transparent":"canvas.default",color:"fg.default",py:N?0:ye?2:4,children:[t.jsx(li,{}),t.jsxs(h,{width:"100%",maxWidth:440,p:0,children:[!N&&t.jsxs(t.Fragment,{children:[t.jsxs(h,{display:"flex",alignItems:"center",gap:2,mb:ye?2:3,justifyContent:"center",children:[ct,t.jsx(wt,{sx:{fontSize:3},children:C})]}),t.jsx(z,{as:"p",sx:{fontSize:1,color:"fg.muted",mb:ye?2:3,textAlign:"center"},children:p})]}),(ve||M)&&t.jsxs(h,{mb:3,textAlign:"center",children:[ve&&t.jsx(wt,{as:"h3",sx:{fontSize:2,mb:1},children:ve}),M&&t.jsx(z,{sx:{color:"fg.muted",fontSize:1},children:M})]}),!Y&&(f||x||y)&&t.jsxs(t.Fragment,{children:[f&&t.jsx(G,{block:!0,size:"large",leadingVisual:Fe==="github"?()=>t.jsx(sn,{size:"small"}):si,disabled:Je,onClick:()=>A(cn.github),sx:{mt:Oe,maxWidth:ne,mx:"auto"},children:"Sign in with GitHub"}),x&&t.jsx(G,{block:!0,size:"large",leadingVisual:Fe==="google"?()=>t.jsx(sn,{size:"small"}):oi,disabled:Je,onClick:()=>A(cn.google),sx:{mt:Oe,maxWidth:ne,mx:"auto"},children:"Sign in with Google"}),y&&t.jsx(G,{block:!0,size:"large",leadingVisual:Fe==="linkedin"?()=>t.jsx(sn,{size:"small"}):ai,disabled:Je,onClick:()=>A(cn.linkedin),sx:{mt:Oe,maxWidth:ne,mx:"auto"},children:"Sign in with LinkedIn"})]}),!Y&&!Ce&&t.jsx(h,{mt:3,display:"flex",justifyContent:"center",children:t.jsx(G,{leadingVisual:un,size:"large",block:!0,disabled:w||U||X,onClick:()=>Pt(!0),sx:{maxWidth:ne,mx:"auto"},children:Tt})}),!Y&&Ce&&t.jsxs(h,{mt:4,children:[t.jsxs(oe,{required:!0,sx:{mb:3},children:[t.jsx(oe.Label,{children:"Username"}),t.jsx(Ct,{autoFocus:!0,block:!0,placeholder:"Your username",value:Z,disabled:U||w,onChange:m=>Et(m.target.value),onKeyDown:J})]}),t.jsxs(oe,{required:!0,sx:{mb:3},children:[t.jsx(oe.Label,{children:"Password"}),t.jsx(Ct,{block:!0,placeholder:"Your password",type:$e?"text":"password",value:I,disabled:U||w,onChange:m=>At(m.target.value),onKeyDown:J,trailingAction:t.jsx(Ct.Action,{onClick:()=>Mt(!$e),disabled:U||w,icon:$e?ti:ni,"aria-label":$e?"Hide password":"Show password",sx:{color:"var(--fgColor-muted)"}})})]}),t.jsxs(h,{display:"flex",alignItems:"center",justifyContent:"space-between",mt:3,children:[t.jsx(G,{variant:"primary",disabled:U||w||!Z||!I,onClick:ze,children:U?"Signing in…":"Sign In"}),ae&&t.jsx(io,{as:"button",sx:{fontSize:1,cursor:w?"not-allowed":"pointer",background:"none",border:"none",opacity:w?.6:1},onClick:()=>{w||U||dt()},children:lt})]})]}),Y&&t.jsxs(t.Fragment,{children:[t.jsxs(oe,{required:!0,sx:{mb:3,mt:2},children:[t.jsx(oe.Label,{children:"MFA Code"}),t.jsx(Ct,{autoFocus:!0,block:!0,placeholder:"Your MFA code",value:ie,disabled:U||w,onChange:m=>Ot(m.target.value),onKeyDown:J})]}),t.jsx(G,{variant:"primary",block:!0,disabled:U||w||!ie.trim(),onClick:_e,sx:{maxWidth:ne,mx:"auto"},children:U?"Validating…":"Validate MFA Code"})]}),je&&t.jsx(z,{sx:{color:"danger.fg",fontSize:1,mt:3,display:"block"},children:je}),pe&&t.jsxs(h,{mt:4,pt:4,textAlign:"center",borderTop:"1px solid",borderColor:"border.muted",children:[t.jsx(wt,{as:"h3",sx:{fontSize:2,mb:2},children:Rt}),t.jsx(z,{as:"p",sx:{color:"fg.muted",fontSize:1,mb:3},children:mn}),t.jsx(h,{display:"flex",justifyContent:"center",children:t.jsx(G,{variant:"primary",size:"large",leadingVisual:ro,disabled:w||U,onClick:ce,children:Se})})]}),d&&o&&t.jsxs(t.Fragment,{children:[t.jsxs(h,{display:"flex",alignItems:"center",gap:2,my:3,children:[t.jsx(h,{flex:1,height:"1px",bg:"border.default"}),t.jsx(z,{sx:{fontSize:0,color:"fg.muted"},children:"or"}),t.jsx(h,{flex:1,height:"1px",bg:"border.default"})]}),t.jsx(G,{block:!0,leadingVisual:un,disabled:w||U||X,onClick:()=>Re(!0),sx:{maxWidth:ne,mx:"auto"},children:"Sign in with an API Key"}),Te&&t.jsx(h,{role:"dialog","aria-modal":"true","aria-labelledby":"signin-api-key-title",onKeyDown:m=>{m.key==="Escape"&&le()},onClick:le,position:"fixed",inset:0,zIndex:200,p:3,bg:"canvas.backdrop",display:"flex",alignItems:"center",justifyContent:"center",children:t.jsxs(h,{as:"form",onClick:m=>m.stopPropagation(),onSubmit:m=>{m.preventDefault(),Ie()},width:"min(560px, 100%)",p:3,borderRadius:2,border:"1px solid",borderColor:"border.default",bg:"canvas.overlay",color:"fg.default",boxShadow:"shadow.large",children:[t.jsx(wt,{id:"signin-api-key-title",sx:{fontSize:2,mb:2},children:"Enter your API Key"}),t.jsxs(oe,{required:!0,children:[t.jsx(oe.Label,{children:"API Key"}),t.jsx(lo,{block:!0,required:!0,autoFocus:!0,placeholder:"Paste your API key here",value:he,onInput:m=>Ge(m.currentTarget.value),ref:ge})]}),t.jsxs(h,{mt:3,display:"flex",justifyContent:"flex-end",gap:2,children:[t.jsx(G,{type:"button",onClick:le,children:"Cancel"}),t.jsx(G,{type:"submit",variant:"primary",disabled:!he.trim(),children:"Authenticate"})]})]})})]})]})]})};function di(n){const{agentId:o,instructions:i,model:r,frontendTools:u,inference:p,subagents:v,sharing:c,onSubagentEvent:f,modeEffect:x}=n;return{type:"browser-vercel-ai",endpoint:"",agentId:o,enableConfigQuery:!1,options:{instructions:i,model:r,frontendTools:u,inference:p,subagents:v,sharing:c,onSubagentEvent:f,modeEffect:x}}}const ms=fo((n,o)=>({pending:void 0,suggest:(i,r)=>{const u=i.trim();u&&n({pending:{text:u,submit:r?.submit??!1,nonce:(o().pending?.nonce??0)+1}})},consume:()=>n({pending:void 0})})),ui=({state:n})=>po[n];class fi extends Error{constructor(o,i){super(i),this.status=o,this.name="RuntimeRefusal"}status}function pi({baseUrl:n,getAccessToken:o,fetch:i}){const r=n.replace(/\/+$/,""),u=(f={})=>{const x=o();return{...f,...x?{Authorization:`Bearer ${x}`}:{}}},p=async f=>{throw new fi(f.status,go(f.status,f.statusText,await xo(f)))};return{json:async(f,x="GET",y)=>{const d=await i(`${r}${f}`,{method:x,headers:u({Accept:"application/json",...y===void 0?{}:{"Content-Type":"application/json"}}),...y===void 0?{}:{body:JSON.stringify(y)}});return d.ok?await d.json():p(d)},stream:async(f,x,{onEvent:y,signal:d},pe="POST")=>{const L=await i(`${r}${f}`,{method:pe,headers:u({"Content-Type":"application/json",Accept:"text/event-stream"}),body:JSON.stringify(x),signal:d});if(!L.ok)return p(L);await bo(L,y)},refused:p,headers:u,root:r,fetcher:i}}const K=n=>`/api/v1/apps/sessions/${encodeURIComponent(n)}`;function mi(n){const{json:o,stream:i,fetcher:r,headers:u,refused:p,root:v}=pi(n);return{serverUrl:v,accessToken:()=>n.getAccessToken(),start:(c,f)=>i("/api/v1/apps/sessions",{agent:c.agent,...c.deploymentUid?{deployment_uid:c.deploymentUid}:{},...c.appUid?{app_uid:c.appUid}:{},...c.version?{version:c.version}:{},...c.session?{session:c.session}:{},opener:c.opener},f),message:(c,f,x)=>i(`${K(c)}/messages`,{text:f},x),changeSettings:(c,f,x)=>i(`${K(c)}/settings`,{values:f},x,"PUT"),resume:(c,f,x)=>i(`${K(c)}/resume`,{agent:f},x),stop:c=>o(`${K(c)}/stop`,"POST"),end:c=>o(`${K(c)}/end`,"POST"),describe:c=>o(K(c)),described:async c=>ho(await o(K(c))),list:(c={})=>{const f=new URLSearchParams;for(const[y,d]of Object.entries(c))d!==""&&d!==void 0&&d!==!1&&f.set(y,String(d));const x=f.toString();return o(`/api/v1/apps/sessions${x?`?${x}`:""}`)},swap:(c,f)=>o(`${K(c)}/agent`,"POST",{agent:f}),clone:(c,f={})=>o(`${K(c)}/clone`,"POST",{up_to_turn:f.upToTurn??null,agent:f.agent??null,title:f.title??""}),exportFile:async(c,f="")=>{const x=await r(`${v}${K(c)}/export${f?`?format=${encodeURIComponent(f)}`:""}`,{method:"GET",headers:u()});return x.ok?x.text():p(x)},importFile:async(c,f={})=>{const x=new URLSearchParams;f.agent&&x.set("agent",f.agent),f.format&&x.set("format",f.format);const y=x.toString(),d=await r(`${v}/api/v1/apps/sessions/import${y?`?${y}`:""}`,{method:"POST",headers:u({"Content-Type":"application/x-ndjson"}),body:c});return d.ok?await d.json():p(d)},rename:(c,f)=>o(`${K(c)}/title`,"PUT",{title:f}),archive:(c,f)=>o(`${K(c)}/archived`,"PUT",{archived:f}),messages:async c=>mo((await o(`${K(c)}/messages`)).messages)}}function hi({agentName:n,sandboxStillRuns:o=!1,temporary:i=!0,onSignedIn:r,onSignUp:u}){const{configuration:p}=bs(),v=s.useCallback(c=>{vo.getState().checkIAMToken(c),r?.()},[r]);return t.jsx(h,{height:"100%",minHeight:0,overflowY:"auto",bg:"canvas.default",px:4,py:4,children:t.jsxs(h,{maxWidth:440,mx:"auto",children:[t.jsxs(h,{display:"flex",alignItems:"center",justifyContent:"center",gap:2,color:"attention.fg",mb:2,children:[t.jsx(un,{size:20}),t.jsx(z,{sx:{fontSize:2,fontWeight:"semibold",color:"fg.default"},children:i?"This demo runs on a shared key":"Your key has expired"})]}),t.jsxs(z,{as:"p",sx:{fontSize:1,color:"fg.muted",textAlign:"center",mb:3},children:[i?`${n??"The agent"} has used the time this key allows. Sign in to point your own agent at it, use your own data, and drop the time limit.`:`${n??"The agent"} stopped because your session ran out.`,o?" Your notebook is still running in this page.":""]}),i&&t.jsxs(h,{display:"flex",flexDirection:"column",alignItems:"center",gap:2,mb:3,"data-anonymous-key-refresh":"",children:[t.jsx(z,{sx:{fontSize:1,color:"fg.muted",textAlign:"center"},children:"Or keep trying without an account: refreshing the page gives this demo a new key, and starts the conversation over."}),t.jsx(G,{leadingVisual:So,onClick:()=>{typeof window<"u"&&window.location.reload()},children:"Refresh the page for a new key"})]}),t.jsx(ci,{hideHero:!0,fillHeight:!1,calloutTitle:"Sign in to keep going",github:!0,google:!0,linkedin:!0,socialSignInNavigationTarget:typeof window>"u"?void 0:`${window.location.pathname}${window.location.search}`,loginUrl:p?.iamUrl?`${p.iamUrl}/api/iam/v1/login`:void 0,onSignIn:v,onSignUp:u})]})})}const gi="https://r1.datalayer.run";function xi(n=!0){const{configuration:o}=bs(),i=fn(c=>c.token),r=o?.aiInferenceUrl||gi,u=yo(r,n&&!i),p=i||u.token,v=s.useMemo(()=>({inferenceUrl:r,token:p||void 0}),[r,p]);return{inference:v,needsSignIn:wo(v),anonymous:u,inferenceUrl:r}}const bi={name:"general-purpose",description:"A capable generalist for a task none of the specialists covers: research, reasoning, drafting, checking.",instructions:"You are a capable general-purpose assistant. Carry out the task you are given completely and report the result plainly, saying what you could not do."};function hs(n){const o=n?.subagents;if(!o)return[];const i=(o.subagents??[]).map(r=>{const u=r.ref?Co(r.ref):void 0;return{name:r.name,description:r.description||u?.description||r.name,instructions:r.instructions??u?.systemPrompt,model:r.model??u?.model??o.defaultModel,icon:u?.icon}});return o.includeGeneralPurpose?[...i,bi]:i}function vi(n){return n.replace(/^datalayer_/,"").replace(/_lexical$/,"")}function Si(n){const o=vi(n);return/^executeCodeIn(Notebook|Document)$/.test(o)||/^(read|list)[A-Z]/.test(o)}function yi(n,o){return n.filter(i=>o?.has(i.name)||Si(i.name))}function wi(n,o){const i=r=>o&&r.value.id===`${o}-tools`?0:r.value.id==="notebook-tools"?1:2;return n.map((r,u)=>({entry:r,index:u,rank:i(r)})).sort((r,u)=>r.rank-u.rank||r.index-u.index).map(r=>r.entry)}function Ci(n,o,i){if(!i||!n.endsWith("-tools"))return!1;const r=n.slice(0,-6);return o.has(r)&&r!==i}const ji={type:"object",properties:{}};function ki(n,o){const i=new Set(n.toolset);return n.commands.filter(r=>i.has(r.name)).map(r=>({name:r.name,description:r.description,parameters:r.parameters??ji,location:"frontend",handler:async u=>{if(!o)throw new Error(`${r.name}: the ${n.plugin??n.id} plugin is not mounted on this page.`);const p=Object.keys(u??{}).length>0?u:void 0,v=await o.executeCommand(r.command,p);return v===void 0?{ok:!0,command:r.command,argument:p}:v}}))}function js(n,o){return n.flatMap(i=>ki(i,o))}function Ti(){const n=jo(),o=Cs();return s.useMemo(()=>js(o,n),[o,n])}function Ri(n){const o=n?.app_instance;if(!o||typeof o!="object")return"";const i=o.deployment_uid;return typeof i=="string"?i.trim():""}function Ii(n,o,i){return n||!o?n:{id:i,messages:[]}}function Ei(n){const o=(new URLSearchParams(n).get("session")??"").trim();if(!o)return"";if(!/^[A-Za-z0-9_-]{8,128}$/.test(o))throw new Error(`?session=${o} names no session: a session uid is 8 to 128 letters, digits, hyphens or underscores.`);return o}function Ai({facts:n}){if(!n)return null;const o=ko(n);return t.jsxs(h,{display:"inline-flex",alignItems:"center",gap:2,"data-session-state":n.state,children:[t.jsx(To,{size:"small",variant:n.state==="open"?"accent":n.state==="paused"?"attention":"secondary",children:Ro(n)}),o?t.jsx(z,{sx:{fontSize:0,color:"fg.muted"},"data-session-lineage":"",children:o}):null]})}function Pi({facts:n,turn:o,context:i}){const r=B(vs),u=Ss(r,n,"turn");return!n||u.length===0||o<1?null:t.jsx(h,{display:"inline-flex",gap:1,"data-turn-actions":o,children:u.map(p=>t.jsx(G,{size:"small",variant:"invisible","data-turn-action":p.id,onClick:()=>{Promise.resolve(p.run(n,{...i,atTurn:o})).catch(v=>i.say(String(v.message??v)))},children:p.label},p.id))})}function Mi({uid:n,describe:o,context:i}){const r=B(vs),[u,p]=s.useState(void 0),[v,c]=s.useState(!1),[f,x]=s.useState(""),[y,d]=s.useState(void 0),pe={...i,show:i.show??d,say:T=>{x(T),i.say(T)}},L=s.useCallback(T=>{c(T),T&&n&&o(n).then(p,()=>p(void 0))},[o,n]);if(!n||r.length===0)return null;const w=Ss(r,u);return t.jsxs(t.Fragment,{children:[t.jsxs(on,{open:v,onOpenChange:L,children:[t.jsx(on.Anchor,{children:t.jsx(ys,{icon:ii,"aria-label":"Session actions",variant:"invisible",size:"small","data-testid":"session-actions"})}),t.jsx(on.Overlay,{width:"small",children:t.jsxs(it,{children:[w.length===0?t.jsx(it.Item,{disabled:!0,children:u?"Nothing applies to this session now.":"Reading the session…"}):w.map(T=>t.jsx(it.Item,{"data-session-action":T.id,onSelect:()=>{u&&Promise.resolve(T.run(u,pe)).catch(N=>pe.say(String(N.message??N)))},children:T.label},T.id)),f?t.jsxs(t.Fragment,{children:[t.jsx(it.Divider,{}),t.jsx(it.Item,{disabled:!0,"data-testid":"session-actions-said",children:f})]}):null]})})]}),y?t.jsx(ws,{title:y.title,onClose:()=>d(void 0),width:"large",children:t.jsx(h,{"data-session-panel":"",children:y.render()})}):null]})}const gs={confirm:"Switch",cancel:"Keep it"};function Ui({question:n,onPick:o}){const[i,r]=s.useState(n.options[0]?.id??""),[u,p]=s.useState("");s.useEffect(()=>{let c=!0;if(!n.says||!i){p("");return}return n.says(i).then(f=>c&&p(f),()=>c&&p("")),()=>{c=!1}},[i,n]);const v=n.options.find(c=>c.id===i);return t.jsx(ws,{title:n.title,onClose:()=>o(void 0),width:"medium",footerButtons:[{buttonType:"default",content:gs.cancel,onClick:()=>o(void 0)},{buttonType:"primary",content:gs.confirm,disabled:!i,onClick:()=>o(i||void 0)}],children:t.jsxs(h,{display:"grid",gap:3,"data-session-choose":"",children:[t.jsxs(oe,{children:[t.jsx(oe.Label,{children:n.title}),t.jsx(ls,{value:i,onChange:c=>r(c.target.value),block:!0,children:n.options.map(c=>t.jsx(ls.Option,{value:c.id,children:c.label},c.id))})]}),v?.description?t.jsx(z,{sx:{fontSize:1,color:"fg.muted"},children:v.description}):null,u?t.jsx(z,{as:"p",sx:{m:0,fontSize:1,fontStyle:"italic"},"data-session-choose-says":"",children:u}):null]})})}const Oi="var(--theme-accent)";function ks({face:n,size:o}){return typeof n=="string"?t.jsx(Io,{emoji:n,size:o,label:""}):t.jsx(t.Fragment,{children:n})}function $i({face:n,size:o,state:i}){const r=i==="thinking"||i==="working",u=i==="paused";return t.jsxs(h,{as:"span","aria-hidden":!0,"data-presence":i,position:"relative",display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,flexShrink:0,fontSize:o,lineHeight:1,children:[t.jsx(h,{as:"span",position:"absolute",inset:0,borderRadius:"50%",boxShadow:u?"none":`0 0 0 2px ${Oi}`,border:u?"2px dashed":"none",borderColor:"border.default",opacity:r||i==="waiting"||u?.9:0,transition:"opacity var(--theme-motion-status, 0ms) var(--theme-motion-easing, ease)",animation:r?"loopPresenceBreath 1.8s ease-in-out infinite":"none",reducedMotion:{animation:"none"},sx:{"@keyframes loopPresenceBreath":{"0%, 100%":{transform:"scale(0.92)",opacity:.35},"50%":{transform:"scale(1.06)",opacity:.9}}}}),t.jsx(h,{as:"span",display:"inline-flex",opacity:u?.55:1,filter:u?"grayscale(0.6)":"none",transition:"opacity var(--theme-motion-status, 0ms) var(--theme-motion-easing, ease)",children:t.jsx(ks,{face:n,size:o})})]})}function Li({state:n}){return t.jsx(z,{role:"status","aria-live":"polite","data-presence-line":n,sx:{fontSize:0,color:n==="waiting"?"fg.default":"fg.muted",fontWeight:n==="waiting"?"semibold":"normal",whiteSpace:"nowrap",flexShrink:0},children:ui({state:n})})}const Fi=pn(void 0),zi=pn(""),_i=pn({}),fe="",Ni=1400,xs=parseInt(Za["--loop-face-large"],10),Bi={};function Gi({workspace:n}){const o=Eo(),i=Ao(),r=s.useRef(null),u=s.useRef(void 0),{setViewControls:p}=n,v=s.useRef(n.setThread);v.current=n.setThread;const c=s.useCallback(()=>{const e=r.current?.thread();return e&&v.current?.(e),e},[]),[f,x]=s.useState(null),y=Po(),d=y.getConfig(Mo),pe=d?.placeholder||o.placeholder,L=d?.defaultSurface??"notebook",w=y.getConfig(Uo),[T,N]=s.useState(fe),ve=s.useRef(!1),M=B(Oo),Tt=B($o),Rt=B(Lo),Se=B(Fo)[0]?.value,Q=an(Se?.promptStance??Fi)??Se?.prompt,me=B(zo),lt=_o(me[0]?.value),ae=s.useRef(lt);ae.current=lt;const Oe=s.useRef(""),ne=B(No),ye=s.useMemo(()=>Bo(()=>ne.reduce((e,a)=>({...e,...a.value.extras.value}),{})),[ne]),C=an(ne.length>0?ye:_i),ct=s.useRef(new Set),we=Vo(qa,n),Z=!we.allowed,Et=Z?we.reason??"Chat is unavailable for this sandbox":void 0,[I,At]=s.useState(!1),[Ce,Pt]=s.useState(!1),[$e,Mt]=s.useState(!1),[U,Le]=s.useState({open:!1,pendingApproval:!1}),X=Do(I,U,d?.presence?.paused===!0),He=d?.presence?.onPresence;s.useEffect(()=>{He?.(X),ae.current?.setPresence(X)},[He,X]);const Fe=s.useRef(d?.presence?.onSaying);Fe.current=d?.presence?.onSaying;const We=s.useRef({answering:!1}),Y=s.useCallback(e=>{r.current=e,Pt(!!e)},[]),Ut=s.useCallback(e=>{const{open:a,pendingApproval:l}=Ho(e);Le(Me=>Me.open===a&&Me.pendingApproval===l?Me:{open:a,pendingApproval:l});const b={saying:Ko(e),answering:Wo(e)},g=We.current;(g.saying?.id!==b.saying?.id||g.saying?.text!==b.saying?.text||g.answering!==b.answering)&&(We.current=b,Fe.current?.(b));const q=ae.current;if(!q)return;q.items(e);const F=new Set(["complete","completed","done","error","failed","cancelled","canceled","rejected","denied","stopped"]),se={insertcell:"adding a cell",updatecell:"editing a cell",runcell:"running a cell",deletecells:"removing cells",readallcells:"reading the notebook",readcell:"reading a cell",executecode:"running code",insertblock:"adding a block",updateblock:"editing a block",runblock:"running a block",readdocument:"reading the document"};let S;for(let Me=e.length-1;Me>=0;Me-=1){const yt=e[Me];if(typeof yt.toolName=="string"&&yt.toolCallId){F.has(String(yt.status).toLowerCase())||(S=yt);break}}if(!S){q.activity(void 0);return}const Pe=S.toolName.toLowerCase().replace(/^datalayer_/,"").replace(/_lexical$/,"").replace(/[^a-z]/g,""),no=se[Pe]??`using ${S.toolName}`;q.activity(`${Oe.current||"The agent"} is ${no}…`)},[]),ie=s.useRef(C);ie.current=C;const Ot=s.useCallback(e=>{zs(e),ae.current?.usage(e),ie.current.onUsage?.(e)},[]),Ke=s.useCallback(e=>{At(e),e||ae.current?.end("done")},[]),$t=s.useCallback(e=>{const a=ae.current;if(!a)return;let l=-1;for(let g=e.length-1;g>=0;g-=1)if(e[g].role==="user"){l=g;break}const b=e.slice(l+1).filter(g=>g.role==="assistant").map(Go).filter(g=>g.trim().length>0).join(`
29
-
30
- `);a.assistant(b)},[]),je=s.useRef([]),ee=s.useRef(!1),ke=s.useRef(void 0),Te=s.useRef(void 0),Re=s.useRef(void 0),he=B(Yo),Ge=s.useRef(he);Ge.current=he;const ge=s.useCallback((e,a)=>{if(Te.current)return Te.current;const l=Re.current;Re.current=void 0;const b=Jo(Ge.current.map(F=>F.value),l?{...a??{},voice:l}:a),g=b?.loop;if(ee.current&&g?.files&&g.files.length>0){const F=ke.current;if(!F)return"A file is given to an application running on a runtime: run it on Datalayer or on your machine to give it one.";let se;try{se=g.files.map(S=>({file:Qo(String(S.name??"")),base64:qo(String(S.data_url??""))}))}catch(S){return S instanceof Error?S.message:String(S)}F.execute(Zo(se)).then(S=>{if(!S.success){x(`The files could not be put in the sandbox: ${S.error??"it failed"}.`);return}ge(`${e}
31
-
32
- ${Xo(se.map(Pe=>Pe.file))}`,{...b,loop:Object.fromEntries(Object.entries(g).filter(([Pe])=>Pe!=="files"))})});return}ae.current?.begin(e,c());const q=r.current?.send;if(!q){je.current.push([e,b]);return}q(e,b)},[c]);s.useEffect(()=>{p(Ce?{busy:I,stop:r.current?.stop,newChat:r.current?.newChat,send:ge}:null)},[I,Ce,p,ge]),s.useEffect(()=>()=>p(null),[p]),s.useEffect(()=>n.prompts.subscribe(ge),[n.prompts,ge]),s.useEffect(()=>{if(!Ce||je.current.length===0)return;const e=je.current.splice(0,je.current.length);for(const[a,l]of e)c(),r.current?.send(a,l)},[Ce,c]);const Ye=s.useRef(!1),re=s.useCallback(async e=>{x(null);const a=await ea(ie.current,e);if(a){a.sent?nt(""):x(a.refused);return}Ye.current||(Ye.current=!0,w?.firstPromptHook?.());const l=await n.submit(e);if(!l.handled){x(l.reason??null);return}nt(""),l.result?.content&&x(l.result.content)},[n,w?.firstPromptHook]),A=s.useMemo(()=>M.find(e=>e.value.surfaceId===T)?.value,[M,T]),le=s.useCallback(e=>{ve.current=!0,N(e)},[]);s.useEffect(()=>ta(le),[le]),s.useEffect(()=>{na(M.map(e=>e.value.surfaceId))},[M]),s.useEffect(()=>{sa(T&&T!==fe?T:Xa)},[T]);const Ie=s.useMemo(()=>L===fe||L==="none"?void 0:M.find(e=>e.value.surfaceId===L),[M,L]);s.useEffect(()=>{ve.current||!Ie||rt(Ie.value,n)&&N(L)},[Ie,n,L]);const[ce,dt]=s.useState(null),ze=s.useRef(null),_e=d?.fullScreenTopOffset??0,{fullScreen:J,usingApi:Je,toggle:m,topOffsetPx:O}=oa(ze,{forceOverlay:!!_e,topOffset:_e}),[V,D]=s.useState(!1),qe=s.useRef(!1);s.useEffect(()=>{!I||qe.current||J||(qe.current=!0,D(!0))},[I,J]),s.useEffect(()=>{J&&D(!1)},[J]),s.useEffect(()=>{A&&!rt(A,n)&&(dt(A.surfaceId),N(fe))},[A,n]);const ut=s.useMemo(()=>{if(ce)return M.find(e=>e.value.surfaceId===ce)?.value;if(!ve.current&&T===fe)return Ie?.value},[M,ce,T,Ie]);s.useEffect(()=>{if(!ce||T!==fe)return;const e=M.find(a=>a.value.surfaceId===ce);e&&rt(e.value,n)&&(dt(null),N(ce))},[M,T,ce,n]);const P=n.agentId?.trim()||"default",$=aa(n.sandbox.target??"local");ee.current=$;const j=ia(),de=an(j?.selected??zi),R=j?.members.find(e=>e.id===de),hn=B(ra)[0]?.value,Lt=hn?.specId,E=cs(R?.specId??P)??(Lt?cs(Lt):void 0),Qe=R?void 0:hn,gn=$&&!R?Ja(Lt,E):void 0;Oe.current=R?.name??E?.name??P;const xn=B(la),bn=C.hiddenOpeners,vn=C.hideOpeners,Ft=C.openers,zt=s.useMemo(()=>{if(vn)return[];const e=new Set(bn??[]),a=S=>e.size===0?S:S.filter(Pe=>!e.has(Pe.text));if(Ft)return a(Ft);const l=xn.flatMap(S=>S.value.suggestions);if(l.length>0)return a(l);const b=a(E?.suggestions??[]),g=a(j?.team.suggestions??[]);if(g.length===0)return b;const q=new Set(g.map(S=>S.text)),F=j?.team.name??"Team",se=R?.name??E?.name??P;return[...g.map(S=>({...S,group:F})),...b.filter(S=>!q.has(S.text)).map(S=>({...S,group:se}))]},[xn,j,E,R,P,bn,vn,Ft]),ft=s.useMemo(()=>zt.map(e=>({title:e.summary??e.text,message:e.message??e.text,group:e.group})),[zt]),_t=De(E?.icon),H=d?.presence,Ts=De(j?.team.icon),Sn=B(ca),pt=s.useMemo(()=>{const e=[],a=new Map,l=new Set,b=new Set(M.map(g=>g.value.surfaceId));for(const g of wi(Sn,A?.surfaceId)){if(Ci(g.value.id,b,A?.surfaceId))continue;let q;try{q=g.value.tools(n)}catch(F){console.warn(`[loop] frontend tools from '${g.plugin}' failed:`,F);continue}for(const F of q){const se=a.get(F.name);if(se){console.warn(`[loop] frontend tool '${F.name}' from '${g.plugin}' is shadowed by the one from '${se}'.`);continue}a.set(F.name,g.plugin),e.push(F),g.value.chatView&&l.add(F.name)}}for(const g of C.frontendTools??[])a.has(g.name)||(a.set(g.name,"chat-extras"),e.push(g),l.add(g.name));return A?e:yi(e,l)},[Sn,n.surfaceId,n.agentId,C.frontendTools,A?.surfaceId,M]),Nt=Ti(),Ze=s.useMemo(()=>{if(Nt.length===0)return pt;const e=new Set(pt.map(a=>a.name));return[...pt,...Nt.filter(a=>!e.has(a.name))]},[pt,Nt]),yn=Cs(),Bt=C.agentToolBundles,Rs=s.useMemo(()=>{const e=C.frontendTools??[];if(!Bt?.length)return C.frontendTools;const a=js(yn.filter(b=>Bt.includes(b.id)),y),l=new Set(e.map(b=>b.name));return[...e,...a.filter(b=>!l.has(b.name))]},[C.frontendTools,Bt,yn,y]);ke.current=$&&Ze.some(e=>e.name===da)?y.getOutput(jt)?.sandbox:void 0;const k=ua(n.sandbox,n.serverUrl),Xe=s.useMemo(()=>mi({baseUrl:k??"",getAccessToken:()=>u.current,fetch:(e,a)=>fetch(e,a)}),[k]),wn=B(fa),Is=s.useMemo(()=>wn.filter(e=>e.value.composer).map(e=>({name:e.value.name,description:e.value.description})),[wn]),Es=s.useMemo(()=>{if(!j||!R)return hs(E).map(l=>({name:l.name,description:l.description,icon:De(l.icon)}));const e=j.members.map(l=>({name:l.name,description:l.description,emoji:l.emoji,icon:De(l.icon),disabled:l.id===R.id,disabledReason:l.id===R.id?`You are already talking to ${l.name}`:void 0})),a=ds(j.team,R.id).filter(l=>!j.members.some(b=>b.name===l.name)).map(l=>({name:l.name,description:l.description,icon:De(l.icon)}));return[...e,...a]},[j,R,E]),{inference:Cn,anonymous:As}=xi($),Ps=fn(e=>e.user),Vt=$&&As.status==="expired",jn=!Ps,et=pa();Te.current=et.disabled?et.disableReason||"This conversation is closed here.":void 0;const Dt=k===void 0?ma(n.sandbox,o):void 0,mt=y.getConfig(jt)?.datalayerVisitors,Ht=ha(mt),te=d?.anonymous,Wt=ga(te?.maxTurns),Kt=!!(te&&mt&&!Ht.error&&n.sandbox.state!=="error"&&(!Ht.token||k===void 0)),ht=te?Wt.refused:"",kn=s.useRef(!1),Tn=Wt.take;s.useEffect(()=>{te&&I&&!kn.current&&Tn(),kn.current=I},[te,I,Tn]);const Ms=xa(te??Bi),tt=Kt||!!ht||Z||Vt||!!gn||!!Dt||et.disabled,Rn=Kt?ba.validating:ht||(Vt?jn?o.demoKeyExpired:o.keyExpired:gn??Dt??Et??(et.disabled?et.disableReason:void 0)),[Gt,nt]=s.useState(""),[In]=va(),st=s.useMemo(()=>d?.voice?Sa(d.voice,In):void 0,[d?.voice,In]),[Us,Os]=s.useState(!1),[$s,En]=s.useState(),gt=$s??Qe?.model??E?.model??n.model??"",Ne=ya(),An=s.useRef(Ne),Pn=s.useRef(de),Mn=s.useRef(Ne);Mn.current=Ne,s.useEffect(()=>{Pn.current!==de&&(Pn.current=de,An.current=Mn.current,En(void 0))},[de]);const Ls=Ne&&Ne!==An.current?Ne:null,[Fs,zs]=s.useState(),_s=Ls??Fs??null,Ns=rn(Ue.inpromptMenu),Un=rn(Ue.promptAction),On=rn(Ue.chatHeader),Bs=s.useMemo(()=>j?.members.map(e=>({id:e.id,name:e.name,description:e.description,icon:De(e.icon)}))??[],[j]),Ee=ms(e=>e.pending),[$n,Vs]=s.useState(0);s.useEffect(()=>wa(()=>Vs(e=>e+1)),[]),s.useEffect(()=>{Ee&&(nt(Ee.text),ms.getState().consume(),Ee.submit&&re(Ee.text))},[Ee]);const Ln=y.getConfig(jt)?.datalayerCreatePayload,W=!!(Qe?.createPayload?.app_spec||Ln?.app_spec),Yt=Ri(Ln),Ds=fn(e=>e.token),Hs=y.getConfig(jt)?.embedToken,xe=mt?Ht.token:Hs||Ds;u.current=xe||void 0;const Ws=s.useMemo(()=>Ca(d?.voice,xe||void 0),[d?.voice,xe]),be=!!(Yt||mt);if(be&&!W)throw new Error("A deployment’s page runs its application: its host gave no app_spec.");const[Fn]=s.useState(ja),[Jt,Ks]=s.useMemo(()=>{try{return[Ei(typeof window>"u"?"":window.location.search),""]}catch(e){return["",e instanceof Error?e.message:String(e)]}},[]),[zn,Gs]=s.useState(void 0),_=s.useMemo(()=>zn??Ii(d?.thread??(Jt&&W?{id:Jt,messages:[],fromRuntime:!0}:void 0),Yt,Fn),[zn,d?.thread,Jt,W,Yt,Fn]),[Be,_n]=s.useState(null),Ys=!!(_?.fromRuntime&&Be?.given!==_.id);s.useEffect(()=>{if(!_?.fromRuntime||!W||!k)return;let e=!0;return(async()=>{let a="";for(let l=0;l<4&&e;l+=1)try{const b=await ka({agentBaseUrl:k,agentId:P,uid:_.id,token:xe});e&&_n({given:_.id,thread:{..._,fromRuntime:!1,messages:b}});return}catch(b){a=b instanceof Error?b.message:String(b),await new Promise(g=>setTimeout(g,1500))}e&&_n({given:_.id,thread:{id:Ta(),messages:[],onStarted:_.onStarted},said:us.notOpened(a)})})(),()=>{e=!1}},[_?.id,_?.fromRuntime,W,k,P,xe]);const qt=_?.fromRuntime?Be?.given===_.id?Be.thread:void 0:_,ue=n.thread||qt?.id||"",[Nn,Bn]=s.useState(void 0),[Js,Vn]=s.useState(0),Dn=s.useRef("");s.useEffect(()=>{I&&ue&&(Dn.current=ue)},[I,ue]);const Hn=!!_?.fromRuntime||!!(n.thread&&n.thread===ue)||Dn.current===ue;s.useEffect(()=>{if(!W||!k||!ue||I||!Hn)return;let e=!0;return Xe.described(ue).then(a=>e&&Bn(a),()=>e&&Bn(void 0)),()=>{e=!1}},[W,k,ue,I,Hn,Js,Xe]);const[Wn,Kn]=s.useState(Ks),[Gn,Yn]=s.useState(null),Qt=s.useRef(null),Zt=s.useRef(null),Jn=s.useRef(null),qn=s.useMemo(()=>({client:Xe,say:e=>{Kn(e),Vn(a=>a+1)},openThread:e=>{Gs({id:e,messages:[],fromRuntime:!0}),Vn(a=>a+1)},download:(e,a,l)=>{const b=URL.createObjectURL(new Blob([a],{type:l})),g=document.createElement("a");g.href=b,g.download=e,g.click(),URL.revokeObjectURL(b)},choose:e=>new Promise(a=>{Qt.current=a,Yn(e)}),pickFile:e=>new Promise(a=>{const l=Jn.current;if(!l){a(void 0);return}Zt.current=a,l.accept=e,l.value="",l.click()})}),[Xe]),xt=s.useMemo(()=>$?di({agentId:R?.specId??P,instructions:Ra(E,Qe?.instructions),model:gt||void 0,inference:Cn,frontendTools:Ze,subagents:j&&R?ds(j.team,R.id):hs(E),sharing:j?.sharing,onSubagentEvent:e=>Qa.getState().appendSubagentEvent(e),modeEffect:Qe?.modeEffect}):k!==void 0?{type:"ag-ui",endpoint:W?`${k}/api/v1/apps/agents/${encodeURIComponent(P)}/ag-ui/`:`${k}/api/v1/ag-ui/${P}/`,...W&&xe?{authToken:xe}:{},...W?{uiSocket:`${k.replace(/^http/,"ws")}/api/v1/apps/ui`,uiFiles:`${k}/api/v1/apps/agents/${encodeURIComponent(P)}/files`,appSessions:`${k}/api/v1/apps/sessions`,...be?{ownRoutesOnly:!0}:{}}:{},agentId:P,configEndpoint:`${k}/api/v1/configure`,enableConfigQuery:!0}:void 0,[P,$,Cn,R,Ze,j,E,Qe,gt,k,W,xe,be]),bt=Ia(!$&&xt?.type==="ag-ui",xt?.type==="ag-ui"?xt.configEndpoint:void 0,void 0,P),ot=Ea(),vt=Aa(P),[Qn,Xt]=s.useState(void 0),[qs,Qs]=s.useState(void 0);s.useEffect(()=>{if($||k===void 0)return;const e=Pa(k,P,be);if(!e){Xt([]);return}let a=!1;return fetch(e).then(l=>l.ok?l.json():null).then(l=>{a||(Xt(l?Ma(l):[]),Qs(l?Ua(l):void 0))}).catch(()=>{a||Xt([])}),()=>{a=!0}},[k,P,$,be]);const Zs=s.useMemo(()=>Oa(Qn,()=>Object.values($a).filter(e=>e.available&&La(e)).map(e=>({id:e.id,name:e.name,provider:e.provider}))),[Qn]),Zn=s.useMemo(()=>{const e=bt.data?.builtinTools??[],a=new Set(e.map(l=>l.name));return{runtime:e,frontend:Ze.filter(l=>!a.has(l.name)).map(l=>({id:l.name,name:l.name}))}},[bt.data?.builtinTools,Ze]),Xn=s.useMemo(()=>new Set((ot.data?.skills??[]).filter(e=>e.status==="enabled"||e.status==="loaded").map(e=>e.id)),[ot.data]),Xs=s.useCallback(async e=>{if(be)throw new Error("A deployment’s chat does not switch its runtime’s model.");En(e),!($||k===void 0)&&await fetch(`${k}/api/v1/configure/inference/provider`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({model:e})}).catch(()=>{})},[k,$,be]),es=d?.promptPlacement==="bottom-chat",eo=d?.promptPlacement==="floating",Ve=d?.promptPlacement==="top",at=d?.hidePrompt===!0||C.hidePrompt===!0,en=Rt[0]?.value.Component,tn=!d?.hideHeader&&!!en,nn=s.useMemo(()=>({mcpServers:(E?.mcpServers??[]).map(e=>e.name||e.id),skills:(E?.skills??[]).map(e=>e.name||e.id)}),[E]),Ae=te?{...Wt,refused:ht,config:te,name:H?.name??R?.name??E?.name??"",validating:Kt,headerShown:tn,minutes:Va,disabledMcpServers:nn.mcpServers,disabledSkills:nn.skills,signIn:Ms}:null,to={onSend:()=>{re(Gt)},input:Gt,setInput:nt,focusTrigger:Ee||$n?(Ee?.nonce??0)+$n:void 0,placement:eo||Q==="floating"||Q==="floating-top"||Q==="floating-bottom"?"floating":"docked",floatingAnchor:Q==="floating-top"?"top":"bottom",isLoading:I,onStop:()=>n.viewControls.stop?.(),placeholder:Rn??C.sendInstead?.says??pe,typingSuggestions:zt.map(e=>e.text),suggestions:ft,disableInputPrompt:tt,connectionConfirmed:!tt,interim:Us,padding:Ve||Q==="floating-top"||Q==="floating-bottom"||Q==="docked-top"?2:3,promptVariant:"lexical",autoFocus:d?.autoFocusPrompt??!0,mentionableAgents:Es,promptCommands:Is,headerContent:Ns.length>0?t.jsx(kt,{slot:Ue.inpromptMenu,props:{workspace:n}}):void 0,footerExtras:te||Un.length>0||st&&st.input!=="off"?t.jsxs(t.Fragment,{children:[te?t.jsx(Fa,{}):null,Un.length>0?t.jsx(kt,{slot:Ue.promptAction,props:{workspace:n}}):null,st&&st.input!=="off"?t.jsx(za,{voice:st,input:Gt,setInput:nt,disabled:tt,speaking:$e,onStopSpeaking:()=>r.current?.stopSpeaking?.(),playbackLevel:()=>r.current?.voiceLevel?.()??0,running:I,onStopRun:()=>(r.current?.interrupt??r.current?.stop)?.(),onInterrupted:()=>r.current?.markInterrupted(),onInterimChange:Os,answers:!!(d?.voice?.output&&d.voice.output!=="off"&&d.voice.speechUrl),onSpoken:e=>{Re.current=e},send:(e,a)=>{Re.current=a,re(e)}}):null]}):void 0,showAgentsMenu:!H,showInlineAgentsMenu:!1,agents:Bs,selectedAgentId:de,onSelectAgent:e=>j?.select(e),showTokenUsage:C.showTokenUsage??d?.showTokenUsage??!0,showContextRing:!0,agentUsage:_s??void 0,showModelSelector:!H&&!be,models:Zs,decisions:qs,selectedModel:gt,onModelSelect:e=>{Xs(e)},showToolsMenu:!H,availableTools:Zn.runtime,availableFrontendTools:Zn.frontend,mcpServers:bt.data?.mcpServers??[],mcpStatusData:C.mcpStatusData??void 0,showSkillsMenu:!H,skills:ot.data?.skills??[],skillsLoading:ot.isLoading,enabledSkills:Xn,onToggleSkill:e=>Xn.has(e)?vt.disableSkill(e):vt.enableSkill(e),onToggleAllSkills:(e,a)=>e.forEach(l=>a?vt.enableSkill(l):vt.disableSkill(l)),codemodeEnabled:C.codemodeEnabled??!1,onToggleCodemode:C.onToggleCodemode,isA2AProtocol:!1,hasConfigData:!!bt.data,hasSkillsData:!!ot.data,...te?{anonymousDisabled:nn}:{}},ts=Tt[0]?.value.Component,St=ts?t.jsx(ts,{workspace:n,composer:to}):null,ns=M.length>0&&d?.showSurfaceSelector!==!1?t.jsx(Vi,{surfaces:M.map(e=>e.value),active:A?.surfaceId??ut?.surfaceId??fe,onChange:le,workspace:n}):null,ss=t.jsxs(t.Fragment,{children:[M.map(e=>{const a=e.value,l=A?.surfaceId===a.surfaceId;return l||ct.current.has(a.surfaceId)||rt(a,n)?(ct.current.add(a.surfaceId),t.jsx(h,{sx:l?{flex:"1 1 0",minWidth:0,minHeight:0}:{position:"absolute",inset:0,visibility:"hidden",pointerEvents:"none",zIndex:-1},children:t.jsx(_a,{load:a.load,props:{surfaceId:a.surfaceId,workspace:n},fallback:t.jsxs(dn,{children:["Loading ",a.title,"…"]}),errorFallback:g=>t.jsxs(dn,{children:[a.title," failed to load: ",g.message]})})},a.surfaceId)):null}),!A&&ut?t.jsx(h,{flex:"1 1 0",minWidth:0,minHeight:0,children:t.jsxs(dn,{children:["Starting ",ut.title,"…"]})}):null]}),os=t.jsx(t.Fragment,{children:t.jsxs(h,{flex:Ve&&A?"0 0 34%":"1 1 0",maxWidth:Ve&&A?460:void 0,minWidth:0,minHeight:0,display:"flex",flexDirection:"column",borderLeft:A?"1px solid":void 0,borderColor:"border.default",position:"relative",children:[C.errorBanner?t.jsx(h,{flexShrink:0,px:3,py:2,fontSize:1,borderBottom:"1px solid",bg:C.errorBanner.variant==="warning"?"attention.subtle":"danger.subtle",color:C.errorBanner.variant==="warning"?"attention.fg":"danger.fg",borderColor:C.errorBanner.variant==="warning"?"attention.muted":"danger.muted",children:C.errorBanner.message}):null,Be?.said&&Be.given===_?.id?t.jsx(z,{as:"p",role:"status",sx:{m:0,px:3,py:2,fontSize:1,color:"fg.muted"},children:Be.said}):null,Wn?t.jsxs(h,{display:"flex",alignItems:"baseline",gap:2,px:3,py:2,fontSize:1,color:"fg.muted",role:"status","data-session-said":"",children:[t.jsx(z,{sx:{flex:1},children:Wn}),t.jsx(G,{size:"small",variant:"invisible",onClick:()=>Kn(""),children:"Dismiss"})]}):null,Gn?t.jsx(Ui,{question:Gn,onPick:e=>{Yn(null),Qt.current?.(e),Qt.current=null}}):null,t.jsx("input",{ref:Jn,type:"file",hidden:!0,"data-session-file":"",onChange:async e=>{const a=e.target.files?.[0],l=a?await a.text():void 0;Zt.current?.(l),Zt.current=null}}),t.jsx(h,{flex:"1 1 auto",minHeight:0,display:"flex",children:Ys?t.jsx(z,{as:"p",role:"status",sx:{m:0,p:3,fontSize:1,color:"fg.muted"},children:us.opening}):t.jsx(Na,{themeVariant:d?.themeVariant,themeOverrides:d?.themeOverrides,colorMode:d?.colorMode,thread:qt,voice:Ws,disabled:tt,disableReason:Rn,protocol:xt,frontendTools:$?void 0:Rs,initialModel:gt||void 0,title:H?.name??R?.name??E?.name??P,description:H?.welcome??E?.description,brandIcon:H?.face?t.jsx($i,{face:H.face,size:20,state:X}):t.jsx(_t,{size:20}),headerContent:H&&!Dt?t.jsx(Li,{state:X}):void 0,emptyState:{icon:H?.face?t.jsx("span",{"aria-hidden":!0,style:{fontSize:xs,lineHeight:1},children:t.jsx(ks,{face:H.face,size:xs})}):t.jsx(_t,{size:48}),title:H?.name??R?.name??E?.name??P,...j&&R?{sections:[{group:j.team.name,icon:t.jsx(Ts,{size:48}),title:j.team.name,subtitle:j.team.description},{group:R.name,icon:t.jsx(_t,{size:32}),title:R.name,subtitle:E?.description}]}:null},suggestions:Ve||Se||d?.suggestionLabels===!1?[]:ft,showHeader:tn,headerButtons:{showNewChat:d?.headerButtons?.newChat??!1,showClear:d?.headerButtons?.clear??!1},renderHeader:en?e=>t.jsx(en,{workspace:n,header:n.chatViewModes?{...e,chatViewMode:n.chatViewModes.value,onChatViewModeChange:n.chatViewModes.onChange,offeredViewModes:n.chatViewModes.offered}:e}):void 0,showInformation:!0,headerActions:t.jsxs(h,{display:"inline-flex",alignItems:"center",gap:2,children:[n.chatHeaderActions,Ae&&!Ae.validating&&!Ae.refused?t.jsx(Ba,{state:Ae}):null,W&&k?t.jsxs(t.Fragment,{children:[t.jsx(Ai,{facts:Nn}),t.jsx(Mi,{uid:ue||void 0,describe:e=>Xe.described(e),context:qn})]}):null,On.length>0?t.jsx(kt,{slot:Ue.chatHeader,props:{workspace:n}}):null,t.jsx(ys,{icon:J?Da:Ha,"aria-label":J?"Exit full screen":"Enter full screen",variant:"invisible",size:"small",onClick:()=>{D(!1),m()},sx:V?{"@keyframes dla-fullscreen-hint":{"0%, 100%":{opacity:1},"50%":{opacity:.4}},"&&":{bg:`color-mix(in srgb, ${i.primary} 16%, transparent)`,boxShadow:`inset 0 0 0 1.5px ${i.primary}`,animation:`dla-fullscreen-hint ${Ni}ms ease-in-out infinite`},"@media (prefers-reduced-motion: reduce)":{"&&":{animation:"none"}}}:void 0})]}),showInput:!1,onSendReady:Y,notebookToolSurfacesId:A?void 0:n.surfaceId,showTurnFooter:C.showTokenUsage??d?.showTokenUsage??!0,onContextSnapshot:Ot,onLoadingChange:Ke,renderMessageFooter:W&&k?(e,a)=>e.role==="user"?t.jsx(Pi,{facts:Nn,turn:a.turn,context:qn}):null:void 0,onSpeakingChange:Mt,onItemsChange:$t,onDisplayItemsChange:Ut,enableStreaming:!0},qt?.id)}),!tn&&On.length>0?t.jsx(h,{hidden:!0,children:t.jsx(kt,{slot:Ue.chatHeader,props:{workspace:n}})}):null,es&&!at?St:null]})}),as=d?.suggestionLabels!==!1&&ft.length>0?t.jsx(h,{"aria-label":o.suggestedPrompts,display:"flex",flexWrap:"wrap",gap:2,px:2,pb:"6px",children:ft.map(e=>t.jsx(h,{as:"button",type:"button",title:e.message,disabled:I||tt,onClick:()=>{re(e.message)},appearance:"none",font:"inherit",fontSize:0,fontWeight:"semibold",lineHeight:1.25,px:"10px",py:"5px",width:fs,flex:`0 0 ${fs}px`,borderRadius:"999px",border:"1px solid",bg:"canvas.subtle",whiteSpace:"nowrap",sx:{borderColor:"border.default",color:"fg.default",cursor:"pointer","&:hover:not(:disabled)":{borderColor:"accent.fg",color:"accent.fg"},"&:disabled":{opacity:.5,cursor:"default"}},children:t.jsx(Wa,{title:e.title,maxWidth:"100%",sx:{minWidth:0},children:e.title})},e.title))}):null,is=f?t.jsx(h,{flex:"0 0 auto",px:3,py:2,borderTop:"1px solid",borderColor:"border.default",bg:"canvas.subtle",fontSize:1,maxHeight:"40%",overflowY:"auto",children:f}):null;return t.jsx(Ka,{value:Ae,children:t.jsxs(h,{ref:ze,sx:{height:"100%",minHeight:0,display:"flex",flexDirection:"column",position:"relative",...J?{bg:"canvas.default"}:null,...J&&!Je.current?{position:"fixed",top:O,right:0,bottom:0,left:0,height:"auto",zIndex:1e3}:null},children:[Ae?t.jsx(h,{flex:"0 0 auto",children:t.jsx(Ga,{state:Ae})}):null,Se?t.jsx(Se.Component,{workspace:n,editors:ss,hasEditor:!!A,transcript:os,prompt:at?null:St,chips:at?null:as,picker:ns,transient:is}):t.jsxs(t.Fragment,{children:[Ve&&!at?t.jsxs(h,{flex:"0 0 auto",borderBottom:"1px solid",borderColor:"border.default",children:[St,as]}):null,ns,t.jsxs(h,{flex:"1 1 auto",minHeight:0,display:"flex",position:"relative",children:[ss,os]}),is,es||at||Ve?null:St]}),Vt?t.jsx(h,{position:"absolute",inset:0,zIndex:5,bg:"canvas.default",display:"flex",flexDirection:"column",minHeight:0,children:t.jsx(hi,{agentName:R?.name??E?.name,sandboxStillRuns:$,temporary:jn,onSignedIn:()=>Ya.getState().clear()})}):null]})})}function Vi({surfaces:n,active:o,onChange:i,workspace:r}){const u=[...n].sort((p,v)=>(p.order??100)-(v.order??100));return t.jsxs(h,{flex:"0 0 auto",display:"flex",alignItems:"center",gap:2,px:3,py:2,borderBottom:"1px solid",borderColor:"border.default",children:[t.jsx(z,{sx:{fontSize:0,color:"fg.muted"},children:"Beside the chat"}),t.jsxs(ln,{"aria-label":"Editor beside the chat",size:"small",children:[t.jsx(ln.Button,{selected:o===fe,onClick:()=>i(fe),children:"Chat"}),u.map(p=>{const v=rt(p,r),c=v?void 0:p.unavailableReason?.(r)??"Not available right now";return t.jsx(ln.Button,{selected:o===p.surfaceId,"aria-disabled":!v,title:c??p.title,leadingIcon:p.icon,onClick:()=>{v&&i(p.surfaceId)},children:p.title},p.surfaceId)})]})]})}function dn({children:n}){return t.jsx(h,{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"fg.muted",fontSize:1,px:3,textAlign:"center",children:n})}export{Gi as default};