@datalayer/agent-runtimes 1.6.62 → 1.6.64

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 (67) 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 +22 -4
  7. package/lib/apps/apps/checks.js +9 -0
  8. package/lib/apps/core/index.d.ts +6 -0
  9. package/lib/apps/core/index.js +6 -0
  10. package/lib/apps/embed/LoopEmbed.js +1 -1
  11. package/lib/apps/plugins/aws-savings/index.d.ts +10 -5
  12. package/lib/apps/plugins/aws-savings/index.js +35 -21
  13. package/lib/apps/plugins/aws-savings-badge/index.d.ts +28 -0
  14. package/lib/apps/plugins/aws-savings-badge/index.js +58 -0
  15. package/lib/apps/plugins/bank-reconciliation/index.d.ts +19 -7
  16. package/lib/apps/plugins/bank-reconciliation/index.js +68 -63
  17. package/lib/apps/plugins/basket-total/index.d.ts +25 -0
  18. package/lib/apps/plugins/basket-total/index.js +41 -0
  19. package/lib/apps/plugins/chat/ChatView.js +4 -1
  20. package/lib/apps/plugins/earth-area/index.d.ts +27 -0
  21. package/lib/apps/plugins/earth-area/index.js +50 -0
  22. package/lib/apps/plugins/earth-index/index.d.ts +8 -3
  23. package/lib/apps/plugins/earth-index/index.js +39 -27
  24. package/lib/apps/plugins/earth-scenes/index.d.ts +8 -3
  25. package/lib/apps/plugins/earth-scenes/index.js +30 -31
  26. package/lib/apps/plugins/linkedin-link/index.d.ts +5 -4
  27. package/lib/apps/plugins/linkedin-link/index.js +7 -16
  28. package/lib/apps/plugins/odoo-context/index.d.ts +30 -0
  29. package/lib/apps/plugins/odoo-context/index.js +54 -0
  30. package/lib/apps/plugins/product-comparison/index.d.ts +7 -1
  31. package/lib/apps/plugins/product-comparison/index.js +37 -30
  32. package/lib/apps/plugins/shopping-basket/index.d.ts +19 -5
  33. package/lib/apps/plugins/shopping-basket/index.js +69 -24
  34. package/lib/apps/plugins/social-accounts/index.d.ts +10 -0
  35. package/lib/apps/plugins/social-accounts/index.js +51 -1
  36. package/lib/apps/plugins/trip-options/index.d.ts +15 -5
  37. package/lib/apps/plugins/trip-options/index.js +67 -21
  38. package/lib/apps/plugins/trip-summary/index.d.ts +26 -0
  39. package/lib/apps/plugins/trip-summary/index.js +59 -0
  40. package/lib/apps/plugins/x-budget/index.d.ts +3 -2
  41. package/lib/apps/plugins/x-budget/index.js +8 -17
  42. package/lib/apps/presets.d.ts +2 -1
  43. package/lib/apps/presets.js +2 -2
  44. package/lib/apps/toolCards/a2uiCard.d.ts +63 -0
  45. package/lib/apps/toolCards/a2uiCard.js +104 -0
  46. package/lib/apps/toolCards/chrome.d.ts +50 -0
  47. package/lib/apps/toolCards/chrome.js +57 -0
  48. package/lib/apps/toolCards/postPreview.d.ts +6 -2
  49. package/lib/apps/toolCards/postPreview.js +28 -18
  50. package/lib/apps/toolCards/toolResults.d.ts +37 -0
  51. package/lib/apps/toolCards/toolResults.js +85 -0
  52. package/lib/chat/Chat.js +47 -36
  53. package/lib/chat/base/ChatBase.js +2 -2
  54. package/lib/chat/messages/ChatMessageList.js +7 -0
  55. package/lib/specs/actions.js +32 -0
  56. package/lib/specs/agents/agents.js +1 -1
  57. package/lib/specs/appspecSchema.js +18 -0
  58. package/lib/specs/backendTools.js +29 -14
  59. package/lib/specs/mcpServers.js +19 -10
  60. package/lib/specs/skills.js +7 -3
  61. package/lib/specs/ui.d.ts +5 -0
  62. package/lib/specs/ui.js +172 -11
  63. package/lib/types/agentspecs.d.ts +8 -0
  64. package/lib/types/chat.d.ts +5 -0
  65. package/package.json +1 -1
  66. package/scripts/codegen/generate_ui.py +2 -0
  67. package/dist-embed/chunks/ChatView-LldnraOq.js +0 -32
@@ -0,0 +1,32 @@
1
+ import{a6 as V,fe as oo,r as s,j as t,gH as ao,gI as io,cd as ls,B as h,H as jt,T as z,v as G,du as on,fu as un,gJ as oe,dn as kt,y as ro,gK as lo,gL as co,f4 as uo,gM as fo,b1 as po,gN as mo,gO as ho,gP as go,gQ as xo,gR as bo,gS as vo,eY as vs,eW as So,dq as yo,eZ as fn,gT as Co,gU as wo,gV as jo,gW as ko,gX as Ss,gY as ys,gZ as To,L as Io,g_ as Ro,e8 as an,I as Cs,bk as it,D as ws,g$ as cs,h0 as Eo,h1 as Ao,E as Po,cC as Mo,h2 as Uo,h3 as Oo,h4 as $o,h5 as Lo,h6 as Fo,h7 as zo,a1 as rn,h8 as _o,h9 as No,ha as Bo,hb as Vo,hc as Do,hd as Ho,he as Wo,hf as Ko,hg as Go,hh as Yo,hi as Jo,hj as qo,hk as Qo,hl as Zo,hm as Xo,hn as ea,ho as ta,hp as na,hq as sa,hr as oa,hs as lt,ht as aa,hu as ia,hv as ra,hw as la,hx as ds,hy as ca,hz as De,hA as da,hB as ua,cD as Tt,hC as fa,hD as pa,hE as us,hF as ma,hG as ha,hH as ga,hI as xa,hJ as ba,hK as va,hL as Sa,hM as ya,fD as Ca,hN as It,hO as fe,hP as wa,hQ as ja,hR as ka,hS as Ta,hT as fs,hU as Ia,hV as Ra,hW as Ea,hX as Aa,hY as Pa,hZ as Ma,h_ as Ua,h$ as Oa,i0 as $a,i1 as La,i2 as Fa,i3 as za,i4 as rt,i5 as _a,i6 as Na,i7 as Ba,i8 as Va,i9 as Da,ia as Ha,ib as Wa,ic as ps,id as Ka,ie as Ga,ig as Ya,ih as Ja,ii as qa,ij as pn,ik as Qa,il as Za,fk as ln,im as Xa,io as ei}from"../datalayer-app-main.js";import{S as ti,E as ni,a as si}from"./SignInIcon-XIbntAUw.js";import{F as oi,a as ai,b as ii}from"./LinkedInGreyIcon-eBP5iBjI.js";import{K as ri}from"./KebabHorizontalIcon-D6AY8pIS.js";function js(){const n=V(oo);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"}},ms=()=>{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""}},li=(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},ci=fo`
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
+ `,di=({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(uo,{size:24}),github:f=!1,google:x=!1,linkedin:y=!1,apiKey:d=!1,signUp:me=!0,socialSignInNavigationTarget:L,asDoc:C=!1,fillHeight:T=!0,hideHero:N=!1,calloutTitle:Se,calloutDescription:M,passwordToggleLabel:Rt="Sign in with a password",signUpTitle:Et="Don't have an account?",signUpDescription:mn="Create a free Datalayer account with your email address.",signUpLabel:ye="Sign up with email",signUpHref:At="https://datalayer.ai/signup",onSignUp:Q,forgotPasswordHref:he="/password",forgotPasswordLabel:ct="Forgot password?",showForgotPassword:ae=!0,socialButtonMarginTop:Oe=3,actionButtonMaxWidth:ne=320})=>{const Ce=C&&!N,w=r??(C&&u==="Datalayer OTEL"?"Datalayer Sign In":u),dt=v??(C?t.jsx(ti,{size:24}):c),we=s.useMemo(()=>{if(i)return i;const m=ms();return m?`${m}/api/iam/v1/login`:"/api/iam/v1/login"},[i]),[Z,Pt]=s.useState(""),[R,Mt]=s.useState(""),[je,Ut]=s.useState(!1),[$e,Ot]=s.useState(!1),[U,Le]=s.useState(!1),[X,He]=s.useState(!1),[Fe,We]=s.useState(null),[Y,$t]=s.useState(null),[ie,Lt]=s.useState(""),[Ke,Ft]=s.useState(null),[ke,ee]=s.useState(null),{enqueueToast:Te}=ao(),[Ie,Re]=s.useState(!1),[ge,Ge]=s.useState(""),xe=s.useRef(null),Ye=s.useCallback(m=>io()?ls.URLExt.join(ls.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=ms(),D=new URLSearchParams({provider:m.name,callback_uri:Ye(m)}),H=L===void 0?void 0:String(L||"").trim(),qe=H===void 0?re&&re!=="/"?re:void 0:H&&H.startsWith("/")&&!H.startsWith("//")?H:void 0;qe&&D.set("post_auth_redirect",qe);const P=`${O||""}/api/iam/v1/oauth2/authz/url?${D.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 D=li(O);ee(D),Te(D,{variant:"error"}),We(null),He(!1)}}},[Ye,re,Te,X,L]);s.useEffect(()=>{Ie&&xe.current?.focus()},[Ie]);const le=s.useCallback(()=>{Re(!1),Ge("")},[]),Ee=s.useCallback(()=>{!ge.trim()||!o||(o(ge.trim()),le())},[ge,o,le]),ce=s.useCallback(()=>{if(Q){Q();return}window.location.assign(At)},[Q,At]),ut=s.useCallback(()=>{if(he){if(he.startsWith("http://")||he.startsWith("https://")){window.open(he,"_blank","noopener,noreferrer");return}window.location.assign(he)}},[he]),ze=s.useCallback(async()=>{if(!(C||!Z||!R||U)){Le(!0),ee(null);try{const m=await fetch(we,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({handle:Z,password:R})});if(!m.ok)throw new Error(`HTTP ${m.status}`);const O=await m.json();if(O.success&&O.token){const D=String(O?.user?.id||O?.user?.uid||"").trim();if(!!O?.user?.mfaUrl&&D){$t(D),Ft(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)}}},[C,Z,R,U,we,n]),_e=s.useCallback(async()=>{if(!(C||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}`,D=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()})}),H=await D.json();if(!D.ok||!H?.success)throw new Error(H?.message||"Failed to validate your MFA code.");n&&n(Ke,Z)}catch(m){const O=m instanceof Error?m.message:String(m);ee(O),Te(O,{variant:"error"})}finally{Le(!1)}}},[C,Te,Z,U,we,ie,Ke,Y,n]),J=s.useCallback(m=>{m.key==="Enter"&&(Y?_e():ze())},[Y,ze,_e]),Je=X||U||C;return t.jsxs(h,{className:"signin-input-theme-scope",display:"flex",alignItems:N||Ce||!T?"flex-start":"center",justifyContent:"center",minHeight:N||Ce||!T?"auto":"100vh",bg:N?"transparent":"canvas.default",color:"fg.default",py:N?0:Ce?2:4,children:[t.jsx(ci,{}),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:Ce?2:3,justifyContent:"center",children:[dt,t.jsx(jt,{sx:{fontSize:3},children:w})]}),t.jsx(z,{as:"p",sx:{fontSize:1,color:"fg.muted",mb:Ce?2:3,textAlign:"center"},children:p})]}),(Se||M)&&t.jsxs(h,{mb:3,textAlign:"center",children:[Se&&t.jsx(jt,{as:"h3",sx:{fontSize:2,mb:1},children:Se}),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(on,{size:"small"}):oi,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(on,{size:"small"}):ai,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(on,{size:"small"}):ii,disabled:Je,onClick:()=>A(cn.linkedin),sx:{mt:Oe,maxWidth:ne,mx:"auto"},children:"Sign in with LinkedIn"})]}),!Y&&!je&&t.jsx(h,{mt:3,display:"flex",justifyContent:"center",children:t.jsx(G,{leadingVisual:un,size:"large",block:!0,disabled:C||U||X,onClick:()=>Ut(!0),sx:{maxWidth:ne,mx:"auto"},children:Rt})}),!Y&&je&&t.jsxs(h,{mt:4,children:[t.jsxs(oe,{required:!0,sx:{mb:3},children:[t.jsx(oe.Label,{children:"Username"}),t.jsx(kt,{autoFocus:!0,block:!0,placeholder:"Your username",value:Z,disabled:U||C,onChange:m=>Pt(m.target.value),onKeyDown:J})]}),t.jsxs(oe,{required:!0,sx:{mb:3},children:[t.jsx(oe.Label,{children:"Password"}),t.jsx(kt,{block:!0,placeholder:"Your password",type:$e?"text":"password",value:R,disabled:U||C,onChange:m=>Mt(m.target.value),onKeyDown:J,trailingAction:t.jsx(kt.Action,{onClick:()=>Ot(!$e),disabled:U||C,icon:$e?ni:si,"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||C||!Z||!R,onClick:ze,children:U?"Signing in…":"Sign In"}),ae&&t.jsx(ro,{as:"button",sx:{fontSize:1,cursor:C?"not-allowed":"pointer",background:"none",border:"none",opacity:C?.6:1},onClick:()=>{C||U||ut()},children:ct})]})]}),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(kt,{autoFocus:!0,block:!0,placeholder:"Your MFA code",value:ie,disabled:U||C,onChange:m=>Lt(m.target.value),onKeyDown:J})]}),t.jsx(G,{variant:"primary",block:!0,disabled:U||C||!ie.trim(),onClick:_e,sx:{maxWidth:ne,mx:"auto"},children:U?"Validating…":"Validate MFA Code"})]}),ke&&t.jsx(z,{sx:{color:"danger.fg",fontSize:1,mt:3,display:"block"},children:ke}),me&&t.jsxs(h,{mt:4,pt:4,textAlign:"center",borderTop:"1px solid",borderColor:"border.muted",children:[t.jsx(jt,{as:"h3",sx:{fontSize:2,mb:2},children:Et}),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:lo,disabled:C||U,onClick:ce,children:ye})})]}),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:C||U||X,onClick:()=>Re(!0),sx:{maxWidth:ne,mx:"auto"},children:"Sign in with an API Key"}),Ie&&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(),Ee()},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(jt,{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(co,{block:!0,required:!0,autoFocus:!0,placeholder:"Paste your API key here",value:ge,onInput:m=>Ge(m.currentTarget.value),ref:xe})]}),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:!ge.trim(),children:"Authenticate"})]})]})})]})]})]})};function ui(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 hs=po((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})})),fi=({state:n})=>mo[n];class pi extends Error{constructor(o,i){super(i),this.status=o,this.name="RuntimeRefusal"}status}function mi({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 pi(f.status,xo(f.status,f.statusText,await bo(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},me="POST")=>{const L=await i(`${r}${f}`,{method:me,headers:u({"Content-Type":"application/json",Accept:"text/event-stream"}),body:JSON.stringify(x),signal:d});if(!L.ok)return p(L);await vo(L,y)},refused:p,headers:u,root:r,fetcher:i}}const K=n=>`/api/v1/apps/sessions/${encodeURIComponent(n)}`;function hi(n){const{json:o,stream:i,fetcher:r,headers:u,refused:p,root:v}=mi(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=>go(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=>ho((await o(`${K(c)}/messages`)).messages)}}function gi({agentName:n,sandboxStillRuns:o=!1,temporary:i=!0,onSignedIn:r,onSignUp:u}){const{configuration:p}=vs(),v=s.useCallback(c=>{So.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:yo,onClick:()=>{typeof window<"u"&&window.location.reload()},children:"Refresh the page for a new key"})]}),t.jsx(di,{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 xi="https://r1.datalayer.run";function bi(n=!0){const{configuration:o}=vs(),i=fn(c=>c.token),r=o?.aiInferenceUrl||xi,u=Co(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 vi={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 gs(n){const o=n?.subagents;if(!o)return[];const i=(o.subagents??[]).map(r=>{const u=r.ref?jo(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,vi]:i}function Si(n){return n.replace(/^datalayer_/,"").replace(/_lexical$/,"")}function yi(n){const o=Si(n);return/^executeCodeIn(Notebook|Document)$/.test(o)||/^(read|list)[A-Z]/.test(o)}function Ci(n,o){return n.filter(i=>o?.has(i.name)||yi(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 ji(n,o,i){if(!i||!n.endsWith("-tools"))return!1;const r=n.slice(0,-6);return o.has(r)&&r!==i}const ki={type:"object",properties:{}};function Ti(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??ki,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 ks(n,o){return n.flatMap(i=>Ti(i,o))}function Ii(){const n=ko(),o=js();return s.useMemo(()=>ks(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 Ei(n,o,i){return n||!o?n:{id:i,messages:[]}}function Ai(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 Pi({facts:n}){if(!n)return null;const o=To(n);return t.jsxs(h,{display:"inline-flex",alignItems:"center",gap:2,"data-session-state":n.state,children:[t.jsx(Io,{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 Mi({facts:n,turn:o,context:i}){const r=V(Ss),u=ys(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 Ui({uid:n,describe:o,context:i}){const r=V(Ss),[u,p]=s.useState(void 0),[v,c]=s.useState(!1),[f,x]=s.useState(""),[y,d]=s.useState(void 0),me={...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 C=ys(r,u);return t.jsxs(t.Fragment,{children:[t.jsxs(an,{open:v,onOpenChange:L,children:[t.jsx(an.Anchor,{children:t.jsx(Cs,{icon:ri,"aria-label":"Session actions",variant:"invisible",size:"small","data-testid":"session-actions"})}),t.jsx(an.Overlay,{width:"small",children:t.jsxs(it,{children:[C.length===0?t.jsx(it.Item,{disabled:!0,children:u?"Nothing applies to this session now.":"Reading the session…"}):C.map(T=>t.jsx(it.Item,{"data-session-action":T.id,onSelect:()=>{u&&Promise.resolve(T.run(u,me)).catch(N=>me.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 xs={confirm:"Switch",cancel:"Keep it"};function Oi({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:xs.cancel,onClick:()=>o(void 0)},{buttonType:"primary",content:xs.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(cs,{value:i,onChange:c=>r(c.target.value),block:!0,children:n.options.map(c=>t.jsx(cs.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 $i="var(--theme-accent)";function Ts({face:n,size:o}){return typeof n=="string"?t.jsx(Eo,{emoji:n,size:o,label:""}):t.jsx(t.Fragment,{children:n})}function Li({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 ${$i}`,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(Ts,{face:n,size:o})})]})}function Fi({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:fi({state:n})})}const zi=pn(void 0),_i=pn(""),Ni=pn({}),pe="",Bi=1400,bs=parseInt(Xa["--loop-face-large"],10),Vi={};function Yi({workspace:n}){const o=Ao(),i=Po(),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=Mo(),d=y.getConfig(Uo),me=d?.placeholder||o.placeholder,L=d?.defaultSurface??"notebook",C=y.getConfig(Oo),[T,N]=s.useState(pe),Se=s.useRef(!1),M=V($o),Rt=V(Lo),Et=V(Fo),ye=V(zo)[0]?.value,Q=rn(ye?.promptStance??zi)??ye?.prompt,he=V(_o),ct=No(he[0]?.value),ae=s.useRef(ct);ae.current=ct;const Oe=s.useRef(""),ne=V(Bo),Ce=s.useMemo(()=>Vo(()=>ne.reduce((e,a)=>({...e,...a.value.extras.value}),{})),[ne]),w=rn(ne.length>0?Ce:Ni),dt=s.useRef(new Set),we=Do(Qa,n),Z=!we.allowed,Pt=Z?we.reason??"Chat is unavailable for this sandbox":void 0,[R,Mt]=s.useState(!1),[je,Ut]=s.useState(!1),[$e,Ot]=s.useState(!1),[U,Le]=s.useState({open:!1,pendingApproval:!1}),X=Ho(R,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,Ut(!!e)},[]),$t=s.useCallback(e=>{const{open:a,pendingApproval:l}=Wo(e);Le(Ue=>Ue.open===a&&Ue.pendingApproval===l?Ue:{open:a,pendingApproval:l});const b={saying:Go(e),answering:Ko(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 Ue=e.length-1;Ue>=0;Ue-=1){const wt=e[Ue];if(typeof wt.toolName=="string"&&wt.toolCallId){F.has(String(wt.status).toLowerCase())||(S=wt);break}}if(!S){q.activity(void 0);return}const Me=S.toolName.toLowerCase().replace(/^datalayer_/,"").replace(/_lexical$/,"").replace(/[^a-z]/g,""),so=se[Me]??`using ${S.toolName}`;q.activity(`${Oe.current||"The agent"} is ${so}…`)},[]),ie=s.useRef(w);ie.current=w;const Lt=s.useCallback(e=>{_s(e),ae.current?.usage(e),ie.current.onUsage?.(e)},[]),Ke=s.useCallback(e=>{Mt(e),e||ae.current?.end("done")},[]),Ft=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(Yo).filter(g=>g.trim().length>0).join(`
29
+
30
+ `);a.assistant(b)},[]),ke=s.useRef([]),ee=s.useRef(!1),Te=s.useRef(void 0),Ie=s.useRef(void 0),Re=s.useRef(void 0),ge=V(Jo),Ge=s.useRef(ge);Ge.current=ge;const xe=s.useCallback((e,a)=>{if(Ie.current)return Ie.current;const l=Re.current;Re.current=void 0;const b=qo(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=Te.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:Zo(String(S.name??"")),base64:Qo(String(S.data_url??""))}))}catch(S){return S instanceof Error?S.message:String(S)}F.execute(Xo(se)).then(S=>{if(!S.success){x(`The files could not be put in the sandbox: ${S.error??"it failed"}.`);return}xe(`${e}
31
+
32
+ ${ea(se.map(Me=>Me.file))}`,{...b,loop:Object.fromEntries(Object.entries(g).filter(([Me])=>Me!=="files"))})});return}ae.current?.begin(e,c());const q=r.current?.send;if(!q){ke.current.push([e,b]);return}q(e,b)},[c]);s.useEffect(()=>{p(je?{busy:R,stop:r.current?.stop,newChat:r.current?.newChat,send:xe}:null)},[R,je,p,xe]),s.useEffect(()=>()=>p(null),[p]),s.useEffect(()=>n.prompts.subscribe(xe),[n.prompts,xe]),s.useEffect(()=>{if(!je||ke.current.length===0)return;const e=ke.current.splice(0,ke.current.length);for(const[a,l]of e)c(),r.current?.send(a,l)},[je,c]);const Ye=s.useRef(!1),re=s.useCallback(async e=>{x(null);const a=await ta(ie.current,e);if(a){a.sent?nt(""):x(a.refused);return}Ye.current||(Ye.current=!0,C?.firstPromptHook?.());const l=await n.submit(e);if(!l.handled){x(l.reason??null);return}nt(""),l.result?.content&&x(l.result.content)},[n,C?.firstPromptHook]),A=s.useMemo(()=>M.find(e=>e.value.surfaceId===T)?.value,[M,T]),le=s.useCallback(e=>{Se.current=!0,N(e)},[]);s.useEffect(()=>na(le),[le]),s.useEffect(()=>{sa(M.map(e=>e.value.surfaceId))},[M]),s.useEffect(()=>{oa(T&&T!==pe?T:ei)},[T]);const Ee=s.useMemo(()=>L===pe||L==="none"?void 0:M.find(e=>e.value.surfaceId===L),[M,L]);s.useEffect(()=>{Se.current||!Ee||lt(Ee.value,n)&&N(L)},[Ee,n,L]);const[ce,ut]=s.useState(null),ze=s.useRef(null),_e=d?.fullScreenTopOffset??0,{fullScreen:J,usingApi:Je,toggle:m,topOffsetPx:O}=aa(ze,{forceOverlay:!!_e,topOffset:_e}),[D,H]=s.useState(!1),qe=s.useRef(!1);s.useEffect(()=>{!R||qe.current||J||(qe.current=!0,H(!0))},[R,J]),s.useEffect(()=>{J&&H(!1)},[J]),s.useEffect(()=>{A&&!lt(A,n)&&(ut(A.surfaceId),N(pe))},[A,n]);const ft=s.useMemo(()=>{if(ce)return M.find(e=>e.value.surfaceId===ce)?.value;if(!Se.current&&T===pe)return Ee?.value},[M,ce,T,Ee]);s.useEffect(()=>{if(!ce||T!==pe)return;const e=M.find(a=>a.value.surfaceId===ce);e&&lt(e.value,n)&&(ut(null),N(ce))},[M,T,ce,n]);const P=n.agentId?.trim()||"default",$=ia(n.sandbox.target??"local");ee.current=$;const j=ra(),de=rn(j?.selected??_i),I=j?.members.find(e=>e.id===de),hn=V(la)[0]?.value,zt=hn?.specId,E=ds(I?.specId??P)??(zt?ds(zt):void 0),Qe=I?void 0:hn,gn=$&&!I?qa(zt,E):void 0;Oe.current=I?.name??E?.name??P;const xn=V(ca),bn=w.hiddenOpeners,vn=w.hideOpeners,_t=w.openers,Nt=s.useMemo(()=>{if(vn)return[];const e=new Set(bn??[]),a=S=>e.size===0?S:S.filter(Me=>!e.has(Me.text));if(_t)return a(_t);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=I?.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,I,P,bn,vn,_t]),pt=s.useMemo(()=>Nt.map(e=>({title:e.summary??e.text,message:e.message??e.text,group:e.group})),[Nt]),Bt=De(E?.icon),B=d?.presence,Is=De(j?.team.icon),Sn=V(da),mt=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(ji(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 w.frontendTools??[])a.has(g.name)||(a.set(g.name,"chat-extras"),e.push(g),l.add(g.name));return A?e:Ci(e,l)},[Sn,n.surfaceId,n.agentId,w.frontendTools,A?.surfaceId,M]),Vt=Ii(),Ze=s.useMemo(()=>{if(Vt.length===0)return mt;const e=new Set(mt.map(a=>a.name));return[...mt,...Vt.filter(a=>!e.has(a.name))]},[mt,Vt]),yn=js(),Dt=w.agentToolBundles,Rs=s.useMemo(()=>{const e=w.frontendTools??[];if(!Dt?.length)return w.frontendTools;const a=ks(yn.filter(b=>Dt.includes(b.id)),y),l=new Set(e.map(b=>b.name));return[...e,...a.filter(b=>!l.has(b.name))]},[w.frontendTools,Dt,yn,y]);Te.current=$&&Ze.some(e=>e.name===ua)?y.getOutput(Tt)?.sandbox:void 0;const k=fa(n.sandbox,n.serverUrl),Xe=s.useMemo(()=>hi({baseUrl:k??"",getAccessToken:()=>u.current,fetch:(e,a)=>fetch(e,a)}),[k]),Cn=V(pa),Es=s.useMemo(()=>Cn.filter(e=>e.value.composer).map(e=>({name:e.value.name,description:e.value.description})),[Cn]),As=s.useMemo(()=>{if(!j||!I)return gs(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===I.id,disabledReason:l.id===I.id?`You are already talking to ${l.name}`:void 0})),a=us(j.team,I.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,I,E]),{inference:wn,anonymous:Ps}=bi($),Ms=fn(e=>e.user),Ht=$&&Ps.status==="expired",jn=!Ms,et=ma();Ie.current=et.disabled?et.disableReason||"This conversation is closed here.":void 0;const ht=k===void 0?ha(n.sandbox,o):void 0,gt=y.getConfig(Tt)?.datalayerVisitors,Wt=ga(gt),te=d?.anonymous,Kt=xa(te?.maxTurns),Gt=!!(te&&gt&&!Wt.error&&n.sandbox.state!=="error"&&(!Wt.token||k===void 0)),xt=te?Kt.refused:"",kn=s.useRef(!1),Tn=Kt.take;s.useEffect(()=>{te&&R&&!kn.current&&Tn(),kn.current=R},[te,R,Tn]);const Us=ba(te??Vi),tt=Gt||!!xt||Z||Ht||!!gn||!!ht||et.disabled,In=Gt?va.validating:xt||(Ht?jn?o.demoKeyExpired:o.keyExpired:gn??ht??Pt??(et.disabled?et.disableReason:void 0)),[Yt,nt]=s.useState(""),[Rn]=Sa(),st=s.useMemo(()=>d?.voice?ya(d.voice,Rn):void 0,[d?.voice,Rn]),[Os,$s]=s.useState(!1),[Ls,En]=s.useState(),bt=Ls??Qe?.model??E?.model??n.model??"",Ne=Ca(),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 Fs=Ne&&Ne!==An.current?Ne:null,[zs,_s]=s.useState(),Ns=Fs??zs??null,Bs=It(fe.inpromptMenu),Un=It(fe.promptAction),On=It(fe.chatHeader),$n=It(fe.chatBanner),Vs=s.useMemo(()=>j?.members.map(e=>({id:e.id,name:e.name,description:e.description,icon:De(e.icon)}))??[],[j]),Ae=hs(e=>e.pending),[Ln,Ds]=s.useState(0);s.useEffect(()=>wa(()=>Ds(e=>e+1)),[]),s.useEffect(()=>{Ae&&(nt(Ae.text),hs.getState().consume(),Ae.submit&&re(Ae.text))},[Ae]);const Fn=y.getConfig(Tt)?.datalayerCreatePayload,W=!!(Qe?.createPayload?.app_spec||Fn?.app_spec),Jt=Ri(Fn),Hs=fn(e=>e.token),Ws=y.getConfig(Tt)?.embedToken,be=gt?Wt.token:Ws||Hs;u.current=be||void 0;const Ks=s.useMemo(()=>ja(d?.voice,be||void 0),[d?.voice,be]),ve=!!(Jt||gt);if(ve&&!W)throw new Error("A deployment’s page runs its application: its host gave no app_spec.");const[zn]=s.useState(ka),[qt,Gs]=s.useMemo(()=>{try{return[Ai(typeof window>"u"?"":window.location.search),""]}catch(e){return["",e instanceof Error?e.message:String(e)]}},[]),[_n,Ys]=s.useState(void 0),_=s.useMemo(()=>_n??Ei(d?.thread??(qt&&W?{id:qt,messages:[],fromRuntime:!0}:void 0),Jt,zn),[_n,d?.thread,qt,W,Jt,zn]),[Be,Nn]=s.useState(null),Js=!!(_?.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 Ta({agentBaseUrl:k,agentId:P,uid:_.id,token:be});e&&Nn({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&&Nn({given:_.id,thread:{id:Ia(),messages:[],onStarted:_.onStarted},said:fs.notOpened(a)})})(),()=>{e=!1}},[_?.id,_?.fromRuntime,W,k,P,be]);const Qt=_?.fromRuntime?Be?.given===_.id?Be.thread:void 0:_,ue=n.thread||Qt?.id||"",[Bn,Vn]=s.useState(void 0),[qs,Dn]=s.useState(0),Hn=s.useRef("");s.useEffect(()=>{R&&ue&&(Hn.current=ue)},[R,ue]);const Wn=!!_?.fromRuntime||!!(n.thread&&n.thread===ue)||Hn.current===ue;s.useEffect(()=>{if(!W||!k||!ue||R||!Wn)return;let e=!0;return Xe.described(ue).then(a=>e&&Vn(a),()=>e&&Vn(void 0)),()=>{e=!1}},[W,k,ue,R,Wn,qs,Xe]);const[Kn,Gn]=s.useState(Gs),[Yn,Jn]=s.useState(null),Zt=s.useRef(null),Xt=s.useRef(null),qn=s.useRef(null),Qn=s.useMemo(()=>({client:Xe,say:e=>{Gn(e),Dn(a=>a+1)},openThread:e=>{Ys({id:e,messages:[],fromRuntime:!0}),Dn(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=>{Zt.current=a,Jn(e)}),pickFile:e=>new Promise(a=>{const l=qn.current;if(!l){a(void 0);return}Xt.current=a,l.accept=e,l.value="",l.click()})}),[Xe]),vt=s.useMemo(()=>$?ui({agentId:I?.specId??P,instructions:Ra(E,Qe?.instructions),model:bt||void 0,inference:wn,frontendTools:Ze,subagents:j&&I?us(j.team,I.id):gs(E),sharing:j?.sharing,onSubagentEvent:e=>Za.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&&be?{authToken:be}:{},...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`,...ve?{ownRoutesOnly:!0}:{}}:{},agentId:P,configEndpoint:`${k}/api/v1/configure`,enableConfigQuery:!0}:void 0,[P,$,wn,I,Ze,j,E,Qe,bt,k,W,be,ve]),St=Ea(!$&&vt?.type==="ag-ui",vt?.type==="ag-ui"?vt.configEndpoint:void 0,void 0,P),ot=Aa(),yt=Pa(P),[Zn,en]=s.useState(void 0),[Qs,Zs]=s.useState(void 0);s.useEffect(()=>{if($||k===void 0)return;const e=Ma(k,P,ve);if(!e){en([]);return}let a=!1;return fetch(e).then(l=>l.ok?l.json():null).then(l=>{a||(en(l?Ua(l):[]),Zs(l?Oa(l):void 0))}).catch(()=>{a||en([])}),()=>{a=!0}},[k,P,$,ve]);const Xs=s.useMemo(()=>$a(Zn,()=>Object.values(La).filter(e=>e.available&&Fa(e)).map(e=>({id:e.id,name:e.name,provider:e.provider}))),[Zn]),Xn=s.useMemo(()=>{const e=St.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}))}},[St.data?.builtinTools,Ze]),es=s.useMemo(()=>new Set((ot.data?.skills??[]).filter(e=>e.status==="enabled"||e.status==="loaded").map(e=>e.id)),[ot.data]),eo=s.useCallback(async e=>{if(ve)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,$,ve]),ts=d?.promptPlacement==="bottom-chat",to=d?.promptPlacement==="floating",Ve=d?.promptPlacement==="top",at=d?.hidePrompt===!0||w.hidePrompt===!0,tn=Et[0]?.value.Component,nn=!d?.hideHeader&&!!tn,sn=s.useMemo(()=>({mcpServers:(E?.mcpServers??[]).map(e=>e.name||e.id),skills:(E?.skills??[]).map(e=>e.name||e.id)}),[E]),Pe=te?{...Kt,refused:xt,config:te,name:B?.name??I?.name??E?.name??"",validating:Gt,headerShown:nn,minutes:Da,disabledMcpServers:sn.mcpServers,disabledSkills:sn.skills,signIn:Us}:null,no={onSend:()=>{re(Yt)},input:Yt,setInput:nt,focusTrigger:Ae||Ln?(Ae?.nonce??0)+Ln:void 0,placement:to||Q==="floating"||Q==="floating-top"||Q==="floating-bottom"?"floating":"docked",floatingAnchor:Q==="floating-top"?"top":"bottom",isLoading:R,onStop:()=>n.viewControls.stop?.(),placeholder:In??w.sendInstead?.says??me,typingSuggestions:Nt.map(e=>e.text),suggestions:pt,disableInputPrompt:tt,connectionConfirmed:!tt,interim:Os,padding:Ve||Q==="floating-top"||Q==="floating-bottom"||Q==="docked-top"?2:3,promptVariant:"lexical",autoFocus:d?.autoFocusPrompt??!0,mentionableAgents:As,promptCommands:Es,headerContent:Bs.length>0?t.jsx(rt,{slot:fe.inpromptMenu,props:{workspace:n}}):void 0,footerExtras:te||Un.length>0||st&&st.input!=="off"?t.jsxs(t.Fragment,{children:[te?t.jsx(za,{}):null,Un.length>0?t.jsx(rt,{slot:fe.promptAction,props:{workspace:n}}):null,st&&st.input!=="off"?t.jsx(_a,{voice:st,input:Yt,setInput:nt,disabled:tt,speaking:$e,onStopSpeaking:()=>r.current?.stopSpeaking?.(),playbackLevel:()=>r.current?.voiceLevel?.()??0,running:R,onStopRun:()=>(r.current?.interrupt??r.current?.stop)?.(),onInterrupted:()=>r.current?.markInterrupted(),onInterimChange:$s,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:!B,showInlineAgentsMenu:!1,agents:Vs,selectedAgentId:de,onSelectAgent:e=>j?.select(e),showTokenUsage:w.showTokenUsage??d?.showTokenUsage??!0,showContextRing:!0,agentUsage:Ns??void 0,showModelSelector:!B&&!ve,models:Xs,decisions:Qs,selectedModel:bt,onModelSelect:e=>{eo(e)},showToolsMenu:!B,availableTools:Xn.runtime,availableFrontendTools:Xn.frontend,mcpServers:St.data?.mcpServers??[],mcpStatusData:w.mcpStatusData??void 0,showSkillsMenu:!B,skills:ot.data?.skills??[],skillsLoading:ot.isLoading,enabledSkills:es,onToggleSkill:e=>es.has(e)?yt.disableSkill(e):yt.enableSkill(e),onToggleAllSkills:(e,a)=>e.forEach(l=>a?yt.enableSkill(l):yt.disableSkill(l)),codemodeEnabled:w.codemodeEnabled??!1,onToggleCodemode:w.onToggleCodemode,isA2AProtocol:!1,hasConfigData:!!St.data,hasSkillsData:!!ot.data,...te?{anonymousDisabled:sn}:{}},ns=Rt[0]?.value.Component,Ct=ns?t.jsx(ns,{workspace:n,composer:no}):null,ss=M.length>0&&d?.showSurfaceSelector!==!1?t.jsx(Di,{surfaces:M.map(e=>e.value),active:A?.surfaceId??ft?.surfaceId??pe,onChange:le,workspace:n}):null,os=t.jsxs(t.Fragment,{children:[M.map(e=>{const a=e.value,l=A?.surfaceId===a.surfaceId;return l||dt.current.has(a.surfaceId)||lt(a,n)?(dt.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(Na,{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&&ft?t.jsx(h,{flex:"1 1 0",minWidth:0,minHeight:0,children:t.jsxs(dn,{children:["Starting ",ft.title,"…"]})}):null]}),as=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:[w.errorBanner?t.jsx(h,{flexShrink:0,px:3,py:2,fontSize:1,borderBottom:"1px solid",bg:w.errorBanner.variant==="warning"?"attention.subtle":"danger.subtle",color:w.errorBanner.variant==="warning"?"attention.fg":"danger.fg",borderColor:w.errorBanner.variant==="warning"?"attention.muted":"danger.muted",children:w.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,Kn?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:Kn}),t.jsx(G,{size:"small",variant:"invisible",onClick:()=>Gn(""),children:"Dismiss"})]}):null,Yn?t.jsx(Oi,{question:Yn,onPick:e=>{Jn(null),Zt.current?.(e),Zt.current=null}}):null,t.jsx("input",{ref:qn,type:"file",hidden:!0,"data-session-file":"",onChange:async e=>{const a=e.target.files?.[0],l=a?await a.text():void 0;Xt.current?.(l),Xt.current=null}}),t.jsx(h,{flex:"1 1 auto",minHeight:0,display:"flex",children:Js?t.jsx(z,{as:"p",role:"status",sx:{m:0,p:3,fontSize:1,color:"fg.muted"},children:fs.opening}):t.jsx(Ba,{themeVariant:d?.themeVariant,themeOverrides:d?.themeOverrides,colorMode:d?.colorMode,thread:Qt,voice:Ks,disabled:tt,disableReason:In,protocol:vt,frontendTools:$?void 0:Rs,initialModel:bt||void 0,title:B?.name??I?.name??E?.name??P,description:B?.welcome??E?.description,brandIcon:B?.face?t.jsx(Li,{face:B.face,size:20,state:X}):t.jsx(Bt,{size:20}),headerContent:B&&!ht||$n.length>0?t.jsxs(t.Fragment,{children:[B&&!ht?t.jsx(Fi,{state:X}):null,$n.length>0?t.jsx(rt,{slot:fe.chatBanner,props:{workspace:n}}):null]}):void 0,emptyState:{icon:B?.face?t.jsx("span",{"aria-hidden":!0,style:{fontSize:bs,lineHeight:1},children:t.jsx(Ts,{face:B.face,size:bs})}):t.jsx(Bt,{size:48}),title:B?.name??I?.name??E?.name??P,...j&&I?{sections:[{group:j.team.name,icon:t.jsx(Is,{size:48}),title:j.team.name,subtitle:j.team.description},{group:I.name,icon:t.jsx(Bt,{size:32}),title:I.name,subtitle:E?.description}]}:null},suggestions:Ve||ye||d?.suggestionLabels===!1?[]:pt,showHeader:nn,headerButtons:{showNewChat:d?.headerButtons?.newChat??!1,showClear:d?.headerButtons?.clear??!1},renderHeader:tn?e=>t.jsx(tn,{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,Pe&&!Pe.validating&&!Pe.refused?t.jsx(Va,{state:Pe}):null,W&&k?t.jsxs(t.Fragment,{children:[t.jsx(Pi,{facts:Bn}),t.jsx(Ui,{uid:ue||void 0,describe:e=>Xe.described(e),context:Qn})]}):null,On.length>0?t.jsx(rt,{slot:fe.chatHeader,props:{workspace:n}}):null,t.jsx(Cs,{icon:J?Ha:Wa,"aria-label":J?"Exit full screen":"Enter full screen",variant:"invisible",size:"small",onClick:()=>{H(!1),m()},sx:D?{"@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 ${Bi}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:w.showTokenUsage??d?.showTokenUsage??!0,onContextSnapshot:Lt,onLoadingChange:Ke,renderMessageFooter:W&&k?(e,a)=>e.role==="user"?t.jsx(Mi,{facts:Bn,turn:a.turn,context:Qn}):null:void 0,onSpeakingChange:Ot,onItemsChange:Ft,onDisplayItemsChange:$t,enableStreaming:!0},Qt?.id)}),!nn&&On.length>0?t.jsx(h,{hidden:!0,children:t.jsx(rt,{slot:fe.chatHeader,props:{workspace:n}})}):null,ts&&!at?Ct:null]})}),is=d?.suggestionLabels!==!1&&pt.length>0?t.jsx(h,{"aria-label":o.suggestedPrompts,display:"flex",flexWrap:"wrap",gap:2,px:2,pb:"6px",children:pt.map(e=>t.jsx(h,{as:"button",type:"button",title:e.message,disabled:R||tt,onClick:()=>{re(e.message)},appearance:"none",font:"inherit",fontSize:0,fontWeight:"semibold",lineHeight:1.25,px:"10px",py:"5px",width:ps,flex:`0 0 ${ps}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(Ka,{title:e.title,maxWidth:"100%",sx:{minWidth:0},children:e.title})},e.title))}):null,rs=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(Ga,{value:Pe,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:[Pe?t.jsx(h,{flex:"0 0 auto",children:t.jsx(Ya,{state:Pe})}):null,ye?t.jsx(ye.Component,{workspace:n,editors:os,hasEditor:!!A,transcript:as,prompt:at?null:Ct,chips:at?null:is,picker:ss,transient:rs}):t.jsxs(t.Fragment,{children:[Ve&&!at?t.jsxs(h,{flex:"0 0 auto",borderBottom:"1px solid",borderColor:"border.default",children:[Ct,is]}):null,ss,t.jsxs(h,{flex:"1 1 auto",minHeight:0,display:"flex",position:"relative",children:[os,as]}),rs,ts||at||Ve?null:Ct]}),Ht?t.jsx(h,{position:"absolute",inset:0,zIndex:5,bg:"canvas.default",display:"flex",flexDirection:"column",minHeight:0,children:t.jsx(gi,{agentName:I?.name??E?.name,sandboxStillRuns:$,temporary:jn,onSignedIn:()=>Ja.getState().clear()})}):null]})})}function Di({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===pe,onClick:()=>i(pe),children:"Chat"}),u.map(p=>{const v=lt(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{Yi as default};